diff --git a/php/cocal.db b/php/cocal.db
index e49e99b..1453e19 100644
Binary files a/php/cocal.db and b/php/cocal.db differ
diff --git a/php/cocal.php b/php/cocal.php
index 0ef56f2..f572729 100644
--- a/php/cocal.php
+++ b/php/cocal.php
@@ -1,6 +1,8 @@
$line) {
@@ -51,6 +53,10 @@ function curl_request($method, $url, $cookieFile = false, $params = array()) {
$output = curl_exec($ch);
curl_close($ch);
+ if ($cookieFile) {
+ curl_fixcookie($cookieFile);
+ }
+
return $output;
}
@@ -72,9 +78,39 @@ function crawl_address($room) {
return ($r > 0) ? $matches[1] : false;
}
+function error() {
+ global $scriptUrl;
+
+ header("HTTP/1.0 500 Internal Server Error");
+ echo '
+
+
+
+
+
+
+
+
+
+ Sorry an error occured!
Check your credentials and try again!
+
+ ';
+ die();
+}
/* Code */
-if (!empty($_GET['p']) && !empty($_GET['u'])) {
+if (!empty($_GET['hash'])) {
+ $cipher = base64_decode($_GET['hash']);
+ if (strpos($cipher, ':')) {
+ list($matrnr, $passwd) = explode(':', $cipher);
+ }
+}
+else if (!empty($_GET['u']) && !empty($_GET['p'])) {
+ $matrnr = $_GET['u'];
+ $passwd = $_GET['p'];
+}
+
+if (isset($matrnr) && isset($passwd)) {
/* perform login to get session cookie */
$cookieFile = tempnam('/tmp', 'campus_');
@@ -86,16 +122,14 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
}
curl_request('GET', $baseUrl . $homePath, $cookieFile);
- curl_fixcookie($cookieFile);
$loginParams = array(
'login' => urlencode('> Login'),
- 'p' => urlencode($_GET['p']),
- 'u' => urlencode($_GET['u'])
+ 'p' => urlencode($passwd),
+ 'u' => urlencode($matrnr)
);
curl_request('POST', $baseUrl . $loginPath, $cookieFile, $loginParams);
- curl_fixcookie($cookieFile);
/* request calendar */
$calParams = array(
@@ -104,11 +138,13 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
);
$response = curl_request('GET', $baseUrl . $calPath, $cookieFile, $calParams);
- curl_fixcookie($cookieFile);
/* filter some changes */
list($headers, $body) = explode("\r\n\r\n", $response, 2);
+ if (substr($body, 0, strlen("BEGIN:VCALENDAR")) != "BEGIN:VCALENDAR") {
+ error();
+ }
/* header pass through */
$headers = array_slice(explode("\r\n", $headers), 1);
@@ -117,14 +153,14 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
switch($key) {
case 'Content-Disposition':
- $value = 'attachment; filename=campus_office_' . $_GET['u'] . '.ics';
+ $value = 'attachment; filename=campus_office_' . $matrnr . '.ics';
break;
case 'Content-Type':
$value .= '; charset=utf-8';
break;
}
- if ($key != 'Content-Disposition') {
+ if ($key != 'Content-Length') { // ignore old length
header($key . ': ' . $value);
}
}
@@ -135,6 +171,11 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
if ($line) {
list($key, $value) = explode(":", $line);
switch ($key) {
+ case 'END':
+ if ($value == 'VEVENT') flush();
+ unset($location);
+ break;
+
case 'LOCATION':
$location = $value;
$room = strtok($location, " ");
@@ -153,6 +194,7 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
$value .= $location;
break;
}
+
echo $key . ':' . $value;
}
echo "\r\n";
@@ -172,6 +214,50 @@ else {
/dev/nulll - CampusOffice to Google Sync
+
+
@@ -185,20 +271,23 @@ else {
CampusOffice to Google Sync
-
+
+
+
+ Das ist der fertige Link:
+
+