Skip to content
Snippets Groups Projects
Commit 34f9db9e authored by Mark Tearle's avatar Mark Tearle
Browse files

Initial working version of get_desec_txt()

parent 55e55f40
No related merge requests found
......@@ -4,7 +4,7 @@ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'config.php';
require_once('config.php');
use Ramsey\Uuid\Uuid;
use RestService\RestService;
......@@ -13,14 +13,35 @@ function check_username($username) {
return is_array(posix_getpwnam($username));
}
function get_desec_txt($name) {
$restService = new RestService();
// $response = $restService
// ->setEndpoint('https://jsonplaceholder.typicode.com')
// ->get('/posts/1');
// curl https://desec.io/api/v1/domains/{name}/rrsets/{subname}/{type}/ \
// --header "Authorization: Token {token}"
/**
* Remove the first and last quote from a quoted string of text
*
* From https://stackoverflow.com/questions/9734758/remove-quotes-from-start-and-end-of-string-in-php/25353877#25353877
* @param mixed $text
* */
function stripQuotes($text) {
return preg_replace('/^(\'(.*)\'|"(.*)")$/', '$2$3', $text);
}
function get_desec_txt($config, $name) {
$restService = new RestService();
$path = "/api/v1/domains/" . $config['QV_DOMAIN'] . "/rrsets/" . $name . "/TXT/";
$auth_string = "Token ". $config['QV_DESEC_API'];
$response = $restService
->setEndpoint('https://desec.io')
->setRequestHeaders([
'Authorization' => $auth_string
])
->get($path, [], [], false);
$result = json_decode($response->getBody(), true);
if (array_key_exists('records', $result)) {
return stripQuotes($result['records'][0]);
} else {
return "";
}
}
function check_api_key($api_key) {
......@@ -72,8 +93,11 @@ $leaf = new Leaf\App;
// Add routes
$leaf->get('/', function () use($leaf) {
$config=get_config();
$r = get_desec_txt($config, "mtearle-test");
// since the response object is directly tied to the leaf instance
$leaf->response()->markup('<h5>My first Leaf app</h5>');
$html = '<h5>My first Leaf app</h5>' . $r;
$leaf->response()->markup($html);
});
$leaf->post('/register', function () use($leaf) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment