diff --git a/index.php b/index.php index 911f91e9177c1f1ff4bd6088857eefde5af375b8..65d6c050c4fd45d9b0bec319264c7c1cce79ca7b 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,6 @@ <?php +require __DIR__ . '/vendor/autoload.php'; require_once 'quovadis/quovadis.php'; ?> diff --git a/quovadis/quovadis.php b/quovadis/quovadis.php index b18ef314e14747395b4733f8c9f640ba91918366..466eb1f0e9eca9af0f89d81fa30f098593f6e367 100644 --- a/quovadis/quovadis.php +++ b/quovadis/quovadis.php @@ -1,7 +1,123 @@ <?php +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL); + require_once 'config.php'; -print "<h1> Hello Cruel World </h1>"; +function check_username($username) { + return 1; +} + +function check_api_key($api_key) { + // API keys need to be alpha numeric + return 1; +} + +function check_challenge($challenge) { + // Challenge needs to be alpha numeric (meet DNS requirements) + return 1; +} + +// Instantiate Leaf +$leaf = new Leaf\App; + +// Add routes +$leaf->get('/', function () use($leaf) { + // since the response object is directly tied to the leaf instance + $leaf->response()->markup('<h5>My first Leaf app</h5>'); +}); + +$leaf->post('/register', function () use($leaf) { +// +// ### Register User +// +// POST /register +// +// Params: +// * UCC username +// +// Will email to your UCC email address an API key to use with the service + $username = $leaf->request->get('username'); + + // Check username is valid + if !check_username($username) { + $leaf->response->respond(["message" => $username." not valid"]); + return; + } + + // Generate API key + + // Email API key + + $leaf->response->respond(["message" => $username." has been added and email sent"]); +}); + +$leaf->post('/update-api-key', function () use($leaf) { +// +// ### Update API key +// +// POST /update-api-key +// +// Params: +// * UCC username +// * Old API key +// * New API key +// +// Will update API key +// +// Will email to your UCC email address noting that the API key has been updated + $username = $leaf->request->get('username'); + $api_key = $leaf->request->get('api_key'); + $new_api_key = $leaf->request->get('new_api_key'); + + // Check username is valid + + // Check API key + + + // Encrypt API key + + // Stick API key encrypted into the DNS + + // Email user to let them know API key has updated + +}); + +$leaf->post('/update-challenge', function () use($leaf) { +// +// ### Update Challenge +// +// POST /update-challenge +// +// Params: +// +// * UCC username +// * API key +// * Challenge Handle +// * Challenge TXT +// +// Will update the DNS TXT record at +// +// <ucc username>-<challenge handle>.quovadis.ucc.asn.au +// +// to the contents of Challenge TXT +// + $username = $leaf->request->get('username'); + $api_key = $leaf->request->get('api_key'); + $challenge = $leaf->request->get('challenge'); + $value = $leaf->request->get('value'); + + // Check username is valid + + // Check API key + + // Sanity check challenge text + + // Stick challenge value prefixed by username into DNS +}); + +$leaf->run(); ?>