summaryrefslogtreecommitdiff
path: root/web/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'web/index.php')
-rw-r--r--web/index.php40
1 files changed, 25 insertions, 15 deletions
diff --git a/web/index.php b/web/index.php
index 41286da..93115f2 100644
--- a/web/index.php
+++ b/web/index.php
@@ -33,25 +33,36 @@ ini_set('error_reporting', E_ALL &~ E_NOTICE);
// use composer's autoloader for both dependencies and local lib
require_once KOLAB_FREEBUSY_ROOT . '/vendor/autoload.php';
+use Kolab\FreeBusy\Utils;
use Kolab\FreeBusy\Config;
use Kolab\FreeBusy\Logger;
use Kolab\FreeBusy\Directory;
+use Kolab\FreeBusy\HTTPAuth;
-#header('Content-type: text/calendar; charset=utf-8', true);
-header('Content-type: text/plain', true);
// load config
$config = Config::getInstance(KOLAB_FREEBUSY_ROOT . '/config');
if ($config->isValid()) {
-# print_r($config);
- $log = Logger::get('service');
- $log->addInfo('Request: ' . $_SERVER['REDIRECT_URL'], array('ip' => $_SERVER['REMOTE_ADDR']));
-
- // check HTTP auth first
- if ($config->httpauth) {
- // TODO: implement this
+ // check for trusted IP first
+ $remote_ip = Utils::remoteIP();
+ $trusted_ip = $config->trustednetworks ? Utils::checkIPRange($remote_ip, $config->trustednetworks['allow']) : false;
+
+ $log = Logger::get('web');
+ $log->addDebug('Request: ' . $_SERVER['REDIRECT_URL'], array('ip' => $remote_ip, 'trusted' => $trusted_ip));
+
+ // check HTTP authentication
+ if (!$trusted_ip && $config->httpauth) {
+ if (!HTTPAuth::check($config->httpauth)) {
+ $log->addDebug("Abort with 401 Unauthorized");
+ header('WWW-Authenticate: Basic realm="Kolab Free/Busy Service"');
+ header($_SERVER['SERVER_PROTOCOL'] . " 401 Unauthorized", true);
+ exit;
+ }
}
+ #header('Content-type: text/calendar; charset=utf-8', true);
+ header('Content-type: text/plain', true);
+
// analyse request
$url = array_filter(explode('/', $_SERVER['REDIRECT_URL']));
$user = strtolower(array_pop($url));
@@ -69,20 +80,19 @@ if ($config->isValid()) {
$log->addDebug("Trying directory $key", $dirconfig);
$directory = Directory::factory($dirconfig);
- if ($fbdata = $directory->getFreeBusyData($user, $extended)) {
- $log->addInfo("Found valid data for user $user");
+ if ($directory && ($fbdata = $directory->getFreeBusyData($user, $extended))) {
+ $log->addInfo("Found valid data for user $user in directory $key");
echo $fbdata;
exit;
}
}
-/*
- if ($_SERVER['REMOTE_ADDR'] is in $config->trustednetworks['allow]) {
+ // return 404 if request was sent from a trusted IP
+ if ($trusted_ip) {
$log->addDebug("Returning '404 Not Found' for user $user");
header($_SERVER['SERVER_PROTOCOL'] . " 404 Not found", true);
}
else {
-*/
$log->addInfo("Returning empty Free/Busy list for user $user");
$now = time();
@@ -110,7 +120,7 @@ if ($config->isValid()) {
print "FREEBUSY:19700101T000000Z/19700101T000000Z\n";
print "END:VFREEBUSY\n";
print "END:VCALENDAR\n";
-// }
+ }
}
// exit with error