Changeset View
Changeset View
Standalone View
Standalone View
lib/AutodiscoverMicrosoft.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | //return; | ||||
if (empty($post)) { | if (empty($post)) { | ||||
$this->error("Invalid input"); | $this->error("Invalid input"); | ||||
} | } | ||||
// parse XML | // parse XML | ||||
try { | try { | ||||
$xml = new SimpleXMLElement($post); | $xml = new SimpleXMLElement($post); | ||||
if ($email = $xml->xpath('/Autodiscover/Request/EMailAddress')) { | $namespaces = $xml->getNamespaces(true); | ||||
if(isset($namespaces[""])) { // if you have a default namespace | |||||
// register a prefix for that default namespace: | |||||
$xml->registerXPathNamespace("default", $namespaces[""]); | |||||
// and use that prefix in all of your xpath expressions: | |||||
$xpath = "/default:"; | |||||
Log::debug('namespace [default]: ' . $namespaces[""]); | |||||
} else { | |||||
$xpath = ""; | |||||
} | |||||
if ($email = $xml->xpath('/' . $xpath . 'Autodiscover/' . $xpath . 'Request/' . $xpath . 'EMailAddress')) { | |||||
Log::debug('Request [EMailAddress]: ' . $email); | |||||
$this->email = (string) array_shift($email); | $this->email = (string) array_shift($email); | ||||
} | } | ||||
if ($schema = $xml->xpath('/Autodiscover/Request/AcceptableResponseSchema')) { | if ($schema = $xml->xpath('/' . $xpath . 'Autodiscover/' . $xpath . 'Request/' . $xpath . 'AcceptableResponseSchema')) { | ||||
Log::debug('Request [AcceptableResponseSchema]: ' . $schema); | |||||
$schema = (string) array_shift($schema); | $schema = (string) array_shift($schema); | ||||
if (strpos($schema, 'mobilesync')) { | if (strpos($schema, 'mobilesync')) { | ||||
$this->type = 'mobilesync'; | $this->type = 'mobilesync'; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
catch (Exception $e) { | catch (Exception $e) { | ||||
Show All 31 Lines | protected function mobilesync_response() | ||||
if (!preg_match('/^https?:/i', $this->config['activesync'])) { | if (!preg_match('/^https?:/i', $this->config['activesync'])) { | ||||
$this->config['activesync'] = 'https://' . $this->config['activesync'] . '/Microsoft-Server-ActiveSync'; | $this->config['activesync'] = 'https://' . $this->config['activesync'] . '/Microsoft-Server-ActiveSync'; | ||||
} | } | ||||
$xml = new DOMDocument('1.0', Autodiscover::CHARSET); | $xml = new DOMDocument('1.0', Autodiscover::CHARSET); | ||||
// create main elements (tree) | // create main elements (tree) | ||||
$doc = $xml->createElementNS(self::MOBILESYNC_NS, 'Autodiscover'); | $doc = $xml->createElementNS(self::NS, 'Autodiscover'); | ||||
$doc = $xml->appendChild($doc); | $doc = $xml->appendChild($doc); | ||||
$response = $xml->createElement('Response'); | $response = $xml->createElementNS(self::MOBILESYNC_NS, 'Response'); | ||||
$response = $doc->appendChild($response); | $response = $doc->appendChild($response); | ||||
$user = $xml->createElement('User'); | $user = $xml->createElement('User'); | ||||
$user = $response->appendChild($user); | $user = $response->appendChild($user); | ||||
$action = $xml->createElement('Action'); | $action = $xml->createElement('Action'); | ||||
$action = $response->appendChild($action); | $action = $response->appendChild($action); | ||||
$settings = $xml->createElement('Settings'); | $settings = $xml->createElement('Settings'); | ||||
$settings = $action->appendChild($settings); | $settings = $action->appendChild($settings); | ||||
$server = $xml->createElement('Server'); | $server = $xml->createElement('Server'); | ||||
$server = $settings->appendChild($server); | $server = $settings->appendChild($server); | ||||
// configuration | // configuration | ||||
/* | |||||
$dispname = $xml->createElement('DisplayName'); | $dispname = $xml->createElement('DisplayName'); | ||||
$dispname = $user->appendChild($dispname); | $dispname = $user->appendChild($dispname); | ||||
$dispname->appendChild($xml->createTextNode($this->config['user'])); | $dispname->appendChild($xml->createTextNode($this->config['username'])); | ||||
*/ | |||||
$email = $xml->createElement('EMailAddress'); | $email = $xml->createElement('EMailAddress'); | ||||
$email = $user->appendChild($email); | $email = $user->appendChild($email); | ||||
$email->appendChild($xml->createTextNode($this->config['email'])); | $email->appendChild($xml->createTextNode($this->config['login'] ?: $this->config['email'])); | ||||
$element = $xml->createElement('Type'); | $element = $xml->createElement('Type'); | ||||
$element = $server->appendChild($element); | $element = $server->appendChild($element); | ||||
$element->appendChild($xml->createTextNode('MobileSync')); | $element->appendChild($xml->createTextNode('MobileSync')); | ||||
$element = $xml->createElement('Url'); | $element = $xml->createElement('Url'); | ||||
$element = $server->appendChild($element); | $element = $server->appendChild($element); | ||||
$element->appendChild($xml->createTextNode($this->config['activesync'])); | $element->appendChild($xml->createTextNode($this->config['activesync'])); | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |