diff --git a/src/core/init/core.php b/src/core/init/core.php index f5af85c..5018a07 100644 --- a/src/core/init/core.php +++ b/src/core/init/core.php @@ -7,6 +7,7 @@ } public static function get_post_data(){ + // Gets the POST request into an array $data = []; foreach($_POST as $key=>$value){ $data[$key] = $value; @@ -14,6 +15,7 @@ return $data; } public static function get_get_data(){ + // Gets the GET request into an array $data = []; foreach($_GET as $key=>$value){ $data[$key] = $value; @@ -21,6 +23,7 @@ return $data; } public static function random_string($length = 10) { + // Generates a random string - unused currently $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; @@ -30,6 +33,7 @@ return $randomString; } public static function start_session(){ + // Starts a session, unused currently session_start(); } public static function end_session($redirect = true){ @@ -43,6 +47,7 @@ } } public static function get_current_git_commit( $branch='master' ) { + // Gets the current git commit ID - for testing $gitref = sprintf( self::root_dir().'/../.git/refs/heads/%s', $branch ); if ( file_exists($gitref) && $hash = file_get_contents( $gitref ) ) { return trim($hash); @@ -51,6 +56,7 @@ } } public static function full_url(){ + // Gets the full requested URL if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') { $addr = "https"; } else { diff --git a/src/core/init/errors.php b/src/core/init/errors.php index c3ec731..472b610 100644 --- a/src/core/init/errors.php +++ b/src/core/init/errors.php @@ -3,6 +3,7 @@ class Errors { public function throw_error($err){ header('Content-Type: application/json'); // <-- header declaration $error = false; + // Some Saved error messages - more to be added switch ($err) { case "NotFound": $error = new ErrorMessage("Error","404","Not Found"); @@ -14,6 +15,7 @@ class Errors { $error = new ErrorMessage("Error","500","Internal Error"); break; } + // Output error in JSON format echo json_encode($error, true); // <--- encode } } diff --git a/src/core/init/loader.php b/src/core/init/loader.php index 47ea6f7..ea9bb70 100644 --- a/src/core/init/loader.php +++ b/src/core/init/loader.php @@ -1,11 +1,14 @@ go_to_page(true); } else { @@ -20,6 +23,7 @@ class Loader { default: $p = $this->get_page_name(); if(substr($p,0,1) == "/") { + // Remove first slash if exists Core::$CurrentPage = substr($p,1); } else { Core::$CurrentPage = $p; diff --git a/src/core/init/responder.php b/src/core/init/responder.php index 80614bf..faa7d43 100644 --- a/src/core/init/responder.php +++ b/src/core/init/responder.php @@ -23,6 +23,7 @@ class Responder { case "ms-json": header('Content-Type: application/json'); // Send json encoded response + // This is currently an undocumented file from Microsoft so it's not ready yet echo json_encode($response->content, true); break; case "xml": @@ -35,6 +36,7 @@ class Responder { } private function get_response(){ $resp = false; + // Handle the requested URL, using as many known autoconfiguration urls as possible switch (Core::$CurrentPage){ case "get/test": $resp = $this->dummy_response(); @@ -42,6 +44,7 @@ class Responder { case "get/all": $resp = $this->all_urls(); break; + case "mail/autoconfig.xml": case "mail/config-v1.1.xml": $resp = $this->moz_auto_config(); break; @@ -49,7 +52,7 @@ class Responder { case "Autodiscover/Autodiscover.xml": $resp = $this->ms_autodiscover(); break; - case "autodiscover/autodiscover.json": //?Email=psw%40wilde.cloud&Protocol=Autodiscoverv1&RedirectCount=1" + case "autodiscover/autodiscover.json": case "Autodiscover/Autodiscover.json": $resp = $this->ms_autodiscover_json(); break; @@ -66,7 +69,7 @@ class Responder { } private function all_urls(){ $response = new Response(); - + // Not really useful, unless some lovely app developers want to parse it for their app :) // TODO:: Will work out a better message later $response->message = "All URLs Requested"; @@ -78,18 +81,21 @@ class Responder { return $response; } private function moz_auto_config(){ + // The default Thunderbird or Evolution autoconfig.xml file $response = new Response(); $response->content_type = "xml"; $response->content = "public/autoconfig.php"; return $response; } private function ms_autodiscover(){ + // The default Microsoft Autodiscover.xml file $response = new Response(); $response->content_type = "xml"; $response->content = "public/autodiscover.php"; return $response; } private function ms_autodiscover_json(){ + // The new Microsoft Autodiscover.json file - undocumented $response = new Response(); $response->content_type = "ms-json"; $response->content = new MSAutodiscoverJSONResponse(); @@ -120,6 +126,7 @@ class Response { public $content = array(); public function __construct(){ // add requested page to response. I don't know why, but it could helpful for diagnostics at some point + // Does not happen on autoconfig.xml/autodisocver.xml/autodiscover.json files $this->url = Core::$CurrentPage; if (!Core::$Config["CommitID"]){ $this->version = Core::VERSION; @@ -129,7 +136,13 @@ class Response { } } +class AutoConfig { + public prepare_autoconfig_info(){ + // TODO: Move all the code in autoconfig.php into here + } +} class MSAutodiscoverJSONResponse { + // More work to do - handling of MS Autodiscover.json requests public $Protocol; public $Url; } diff --git a/src/public/autoconfig.php b/src/public/autoconfig.php index 88605d4..0571599 100644 --- a/src/public/autoconfig.php +++ b/src/public/autoconfig.php @@ -1,4 +1,13 @@ (.*?)\<\/EMailAddress\>/", $data, $matches); -//print_r($matches); - // Example POST Request (sent from client) : //