Compare commits
No commits in common. "6301cbb5956eaffc72122e78a828c86b8e5ed567" and "aa611b2a1d4eb740ae004fe4e01ddf122ef12f82" have entirely different histories.
6301cbb595
...
aa611b2a1d
7 changed files with 12 additions and 58 deletions
|
@ -7,7 +7,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_post_data(){
|
public static function get_post_data(){
|
||||||
// Gets the POST request into an array
|
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach($_POST as $key=>$value){
|
foreach($_POST as $key=>$value){
|
||||||
$data[$key] = $value;
|
$data[$key] = $value;
|
||||||
|
@ -15,7 +14,6 @@
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
public static function get_get_data(){
|
public static function get_get_data(){
|
||||||
// Gets the GET request into an array
|
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach($_GET as $key=>$value){
|
foreach($_GET as $key=>$value){
|
||||||
$data[$key] = $value;
|
$data[$key] = $value;
|
||||||
|
@ -23,7 +21,6 @@
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
public static function random_string($length = 10) {
|
public static function random_string($length = 10) {
|
||||||
// Generates a random string - unused currently
|
|
||||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
$charactersLength = strlen($characters);
|
$charactersLength = strlen($characters);
|
||||||
$randomString = '';
|
$randomString = '';
|
||||||
|
@ -33,7 +30,6 @@
|
||||||
return $randomString;
|
return $randomString;
|
||||||
}
|
}
|
||||||
public static function start_session(){
|
public static function start_session(){
|
||||||
// Starts a session, unused currently
|
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
public static function end_session($redirect = true){
|
public static function end_session($redirect = true){
|
||||||
|
@ -47,7 +43,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function get_current_git_commit( $branch='master' ) {
|
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 );
|
$gitref = sprintf( self::root_dir().'/../.git/refs/heads/%s', $branch );
|
||||||
if ( file_exists($gitref) && $hash = file_get_contents( $gitref ) ) {
|
if ( file_exists($gitref) && $hash = file_get_contents( $gitref ) ) {
|
||||||
return trim($hash);
|
return trim($hash);
|
||||||
|
@ -56,7 +51,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function full_url(){
|
public static function full_url(){
|
||||||
// Gets the full requested URL
|
|
||||||
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
|
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
|
||||||
$addr = "https";
|
$addr = "https";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,6 @@ class Errors {
|
||||||
public function throw_error($err){
|
public function throw_error($err){
|
||||||
header('Content-Type: application/json'); // <-- header declaration
|
header('Content-Type: application/json'); // <-- header declaration
|
||||||
$error = false;
|
$error = false;
|
||||||
// Some Saved error messages - more to be added
|
|
||||||
switch ($err) {
|
switch ($err) {
|
||||||
case "NotFound":
|
case "NotFound":
|
||||||
$error = new ErrorMessage("Error","404","Not Found");
|
$error = new ErrorMessage("Error","404","Not Found");
|
||||||
|
@ -15,7 +14,6 @@ class Errors {
|
||||||
$error = new ErrorMessage("Error","500","Internal Error");
|
$error = new ErrorMessage("Error","500","Internal Error");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Output error in JSON format
|
|
||||||
echo json_encode($error, true); // <--- encode
|
echo json_encode($error, true); // <--- encode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
// require all necessary files
|
|
||||||
require ("core.php");
|
require ("core.php");
|
||||||
require ("user.php");
|
require ("user.php");
|
||||||
require ("responder.php");
|
require ("responder.php");
|
||||||
require ("errors.php");
|
require ("errors.php");
|
||||||
|
|
||||||
class Loader {
|
class Loader {
|
||||||
public function request_page(){
|
public function request_page(){
|
||||||
// Check if user is authenticated and go to the relevant section
|
// Check if user is authenticated and go to the relevant section
|
||||||
// Currently no authentication is in place so should always be true
|
|
||||||
if (User::is_authenticated()){
|
if (User::is_authenticated()){
|
||||||
$this->go_to_page(true);
|
$this->go_to_page(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +20,6 @@ class Loader {
|
||||||
default:
|
default:
|
||||||
$p = $this->get_page_name();
|
$p = $this->get_page_name();
|
||||||
if(substr($p,0,1) == "/") {
|
if(substr($p,0,1) == "/") {
|
||||||
// Remove first slash if exists
|
|
||||||
Core::$CurrentPage = substr($p,1);
|
Core::$CurrentPage = substr($p,1);
|
||||||
} else {
|
} else {
|
||||||
Core::$CurrentPage = $p;
|
Core::$CurrentPage = $p;
|
||||||
|
|
|
@ -18,13 +18,12 @@ class Responder {
|
||||||
case "json":
|
case "json":
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
// Send json encoded response
|
// Send json encoded response
|
||||||
echo json_encode($response);
|
echo json_encode($response, true);
|
||||||
break;
|
break;
|
||||||
case "ms-json":
|
case "ms-json":
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
// Send json encoded response
|
// Send json encoded response
|
||||||
// This is currently an undocumented file from Microsoft so it's not ready yet
|
echo json_encode($response->content, true);
|
||||||
echo json_encode($response->content, JSON_UNESCAPED_UNICODE);
|
|
||||||
break;
|
break;
|
||||||
case "xml":
|
case "xml":
|
||||||
header('Content-Type: application/xml');
|
header('Content-Type: application/xml');
|
||||||
|
@ -36,7 +35,6 @@ class Responder {
|
||||||
}
|
}
|
||||||
private function get_response(){
|
private function get_response(){
|
||||||
$resp = false;
|
$resp = false;
|
||||||
// Handle the requested URL, using as many known autoconfiguration urls as possible
|
|
||||||
switch (Core::$CurrentPage){
|
switch (Core::$CurrentPage){
|
||||||
case "get/test":
|
case "get/test":
|
||||||
$resp = $this->dummy_response();
|
$resp = $this->dummy_response();
|
||||||
|
@ -44,7 +42,6 @@ class Responder {
|
||||||
case "get/all":
|
case "get/all":
|
||||||
$resp = $this->all_urls();
|
$resp = $this->all_urls();
|
||||||
break;
|
break;
|
||||||
case "mail/autoconfig.xml":
|
|
||||||
case "mail/config-v1.1.xml":
|
case "mail/config-v1.1.xml":
|
||||||
$resp = $this->moz_auto_config();
|
$resp = $this->moz_auto_config();
|
||||||
break;
|
break;
|
||||||
|
@ -52,7 +49,7 @@ class Responder {
|
||||||
case "Autodiscover/Autodiscover.xml":
|
case "Autodiscover/Autodiscover.xml":
|
||||||
$resp = $this->ms_autodiscover();
|
$resp = $this->ms_autodiscover();
|
||||||
break;
|
break;
|
||||||
case "autodiscover/autodiscover.json":
|
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();
|
$resp = $this->ms_autodiscover_json();
|
||||||
break;
|
break;
|
||||||
|
@ -69,7 +66,7 @@ class Responder {
|
||||||
}
|
}
|
||||||
private function all_urls(){
|
private function all_urls(){
|
||||||
$response = new Response();
|
$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
|
// TODO:: Will work out a better message later
|
||||||
$response->message = "All URLs Requested";
|
$response->message = "All URLs Requested";
|
||||||
|
|
||||||
|
@ -81,35 +78,23 @@ class Responder {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
private function moz_auto_config(){
|
private function moz_auto_config(){
|
||||||
// The default Thunderbird or Evolution autoconfig.xml file
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->content_type = "xml";
|
$response->content_type = "xml";
|
||||||
$response->content = "public/autoconfig.php";
|
$response->content = "public/autoconfig.php";
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
private function ms_autodiscover(){
|
private function ms_autodiscover(){
|
||||||
// The default Microsoft Autodiscover.xml file
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->content_type = "xml";
|
$response->content_type = "xml";
|
||||||
$response->content = "public/autodiscover.php";
|
$response->content = "public/autodiscover.php";
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
private function ms_autodiscover_json(){
|
private function ms_autodiscover_json(){
|
||||||
// The new Microsoft Autodiscover.json file - undocumented
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->content_type = "ms-json";
|
$response->content_type = "ms-json";
|
||||||
if (strtolower($_GET['Protocol']) == 'autodiscoverv1') {
|
|
||||||
$response->content = new MSAutodiscoverJSONResponse();
|
$response->content = new MSAutodiscoverJSONResponse();
|
||||||
$response->content->Protocol = "AutodiscoverV1";
|
$response->content->Protocol = "AutodiscoverV1";
|
||||||
$response->content->Url = Core::$Config["BaseURL"] . "/Autodiscover/Autodiscover.xml";
|
$response->content->Url = Core::$Config["BaseURL"] . "/Autodiscover/Autodiscover.xml";
|
||||||
} else {
|
|
||||||
$response->content = new MSAutodiscoverJSONError();
|
|
||||||
http_response_code(400);
|
|
||||||
$response->headers_set = true;
|
|
||||||
$response->content->ErrorCode = "InvalidProtocol";
|
|
||||||
$response->content->ErrorMessage = "The given protocol value '" . $_GET['Protocol'] . "' is invalid. Supported values are 'AutodiscoverV1'";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
private function dummy_response(){
|
private function dummy_response(){
|
||||||
|
@ -124,7 +109,7 @@ class Responder {
|
||||||
private function get_test_working(){
|
private function get_test_working(){
|
||||||
// Generate a dummy response for testing
|
// Generate a dummy response for testing
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->message = "Success! Things are working! Please request a valid URL i.e. /mail/config-v1.1.xml";
|
$response->message = "Success! Things are working! Please request a valid URL i.e. get/all";
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,11 +117,9 @@ class Response {
|
||||||
public $url;
|
public $url;
|
||||||
public $content_type = "json";
|
public $content_type = "json";
|
||||||
public $message;
|
public $message;
|
||||||
public $headers_set = false;
|
|
||||||
public $content = array();
|
public $content = array();
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
// add requested page to response. I don't know why, but it could helpful for diagnostics at some point
|
// 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;
|
$this->url = Core::$CurrentPage;
|
||||||
if (!Core::$Config["CommitID"]){
|
if (!Core::$Config["CommitID"]){
|
||||||
$this->version = Core::VERSION;
|
$this->version = Core::VERSION;
|
||||||
|
@ -146,18 +129,7 @@ class Response {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class AutoConfig {
|
|
||||||
public function prepare_autoconfig_info() {
|
|
||||||
// TODO: Move all the code in autoconfig.php into here
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class MSAutodiscoverJSONResponse {
|
class MSAutodiscoverJSONResponse {
|
||||||
// More work to do - handling of MS Autodiscover.json requests
|
|
||||||
public $Protocol;
|
public $Protocol;
|
||||||
public $Url;
|
public $Url;
|
||||||
}
|
}
|
||||||
class MSAutodiscoverJSONError {
|
|
||||||
public $ErrorCode;
|
|
||||||
public $ErrorMessage;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Errrrrrrrrgh, this is sooooo messy, I'm going to tidy this up
|
|
||||||
// It's basically configuring the format of the email address dependent on
|
|
||||||
// variables set in the config file.
|
|
||||||
// i.e. if the domain isn't required for authentication then it strips the
|
|
||||||
// username back to just the pre-@ part. Or, if the username requires a different
|
|
||||||
// logon domain, then it replaces the email domain with the localdomain
|
|
||||||
//
|
|
||||||
// TODO: TIDY THIS UP!!
|
|
||||||
$conf = Core::$Config["Services"];
|
$conf = Core::$Config["Services"];
|
||||||
$data = Core::get_get_data();
|
$data = Core::get_get_data();
|
||||||
$email_provided = false;
|
$email_provided = false;
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
$conf = Core::$Config["Services"];
|
$conf = Core::$Config["Services"];
|
||||||
//get raw POST data so we can extract the email address
|
//get raw POST data so we can extract the email address
|
||||||
$data = file_get_contents("php://input");
|
$data = file_get_contents("php://input");
|
||||||
|
// file_put_contents(Core::root_dir()."/xmltest", $data);
|
||||||
preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $data, $matches);
|
preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $data, $matches);
|
||||||
|
//print_r($matches);
|
||||||
|
|
||||||
|
|
||||||
// Example POST Request (sent from client) :
|
// Example POST Request (sent from client) :
|
||||||
// <?xml version="1.0" \?\>
|
// <?xml version="1.0" \?\>
|
||||||
|
|
Loading…
Reference in a new issue