Page MenuHomePhorge

AutodiscoverJson.php
No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None

AutodiscoverJson.php

<?php
/**
+--------------------------------------------------------------------------+
| Kolab Autodiscover Service |
| |
| Copyright (C) 2011-2014, Kolab Systems AG <contact@kolabsys.com> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program. If not, see http://www.gnu.org/licenses/. |
+--------------------------------------------------------------------------+
| Author: Daniel Hoffend <dh@dotlan.net> |
+--------------------------------------------------------------------------+
*/
/**
* Autodiscover Service class for Microsoft Autodiscover V2
*/
class AutodiscoverJson extends Autodiscover
{
/**
* process incoming request
*/
public function handle_request()
{
Log::debug('Request [json]: ' . $_SERVER['REQUEST_URI']);
// check protocol (at this state we don't know if autodiscover is configured)
$allowedProtocols = ['activesync', 'autodiscoverv1'];
if (empty($_GET['Protocol'])) {
$this->error(
"A valid value must be provided for the query parameter 'Protocol'",
'MandatoryParameterMissing'
);
}
elseif (!in_array(strtolower($_GET['Protocol']), $allowedProtocols)) {
$this->error(
sprintf(
"The given protocol value '%s' is invalid. Supported values are '%s'",
$_GET['Protocol'],
implode(",", $allowedProtocols)
),
'InvalidProtocol'
);
}
// check email
if (preg_match('|autodiscover.json/v1.0/([^\?]+)|', $_SERVER['REQUEST_URI'], $regs)) {
$this->email = $regs[1];
}
elseif (!empty($_GET['Email'])) {
$this->email = $_GET['Email'];
}
elseif (!empty($_GET['email'])) {
$this->email = $_GET['email'];
}
if (empty($this->email) || !strpos($this->email, '@')) {
$this->error(
'A valid smtp address must be provided',
'MandatoryParameterMissing'
);
}
}
/**
* Generates JSON response
*/
protected function handle_response()
{
if (strtolower($_GET['Protocol']) == 'activesync') {
// throw error if activesync is disabled
if (empty($this->config['activesync'])) {
$this->error(
sprintf(
"The given protocol value '%s' is invalid. Supported values are '%s'",
$_GET['Protocol'], 'autodiscoverv1'
),
'InvalidProtocol'
);
}
if (!preg_match('/^https?:/i', $this->config['activesync'])) {
$this->config['activesync'] = 'https://' . $this->config['activesync'] . '/Microsoft-Server-ActiveSync';
}
$json = array(
'Protocol' => 'ActiveSync',
'Url' => $this->config['activesync']
);
}
elseif (strtolower($_GET['Protocol']) == 'autodiscoverv1') {
$json = array(
'Protocol' => 'AutodiscoverV1',
'Url' => 'https://' . $_SERVER['HTTP_HOST'] . '/Autodiscover/Autodiscover.xml'
);
}
$response = json_encode($json, JSON_PRETTY_PRINT | JSON_HEX_APOS | JSON_HEX_QUOT);
Log::debug('Response [json]: ' . $response);
header('Content-Type: application/json; charset=' . Autodiscover::CHARSET);
echo $response;
exit;
}
/**
* Send error to the client and exit
*/
protected function error($msg, $code="InternalServerError")
{
http_response_code(400);
$json = array(
'ErrorCode' => $code,
'ErrorMessage' => $msg
);
$response = json_encode($json, JSON_PRETTY_PRINT | JSON_HEX_APOS | JSON_HEX_QUOT);
Log::debug('Error [json]: ' . $response);
header('Content-Type: application/json; charset=' . Autodiscover::CHARSET);
echo $response;
exit;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Apr 5, 9:47 PM (3 w, 3 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18831298
Default Alt Text
AutodiscoverJson.php (5 KB)

Event Timeline