updated cocal with hashing and url-shortener
This commit is contained in:
parent
abe76c7337
commit
30d7517b54
3 changed files with 113 additions and 26 deletions
BIN
php/cocal.db
BIN
php/cocal.db
Binary file not shown.
115
php/cocal.php
115
php/cocal.php
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/* Constants */
|
/* Constants */
|
||||||
|
$salt = '8D896ww348lDSd1';
|
||||||
|
$scriptUrl = ((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
|
||||||
$baseUrl = 'https://www.campus.rwth-aachen.de/office/';
|
$baseUrl = 'https://www.campus.rwth-aachen.de/office/';
|
||||||
$homePath = 'default.asp';
|
$homePath = 'default.asp';
|
||||||
$loginPath = 'views/campus/redirect.asp';
|
$loginPath = 'views/campus/redirect.asp';
|
||||||
|
@ -51,6 +53,10 @@ function curl_request($method, $url, $cookieFile = false, $params = array()) {
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($cookieFile) {
|
||||||
|
curl_fixcookie($cookieFile);
|
||||||
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +78,39 @@ function crawl_address($room) {
|
||||||
return ($r > 0) ? $matches[1] : false;
|
return ($r > 0) ? $matches[1] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function error() {
|
||||||
|
global $scriptUrl;
|
||||||
|
|
||||||
|
header("HTTP/1.0 500 Internal Server Error");
|
||||||
|
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="REFRESH" content="5;url=' . $scriptUrl . '">
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<link rel="shortcut icon" href="/favicon.png" type="image/png">
|
||||||
|
<link rel="icon" href="/favicon.png" type="image/png">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="content"><h2>Sorry an error occured!<br />Check your credentials and try again!</h2></div>
|
||||||
|
</body>
|
||||||
|
</html>';
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
/* Code */
|
/* 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 */
|
/* perform login to get session cookie */
|
||||||
$cookieFile = tempnam('/tmp', 'campus_');
|
$cookieFile = tempnam('/tmp', 'campus_');
|
||||||
|
|
||||||
|
@ -86,16 +122,14 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_request('GET', $baseUrl . $homePath, $cookieFile);
|
curl_request('GET', $baseUrl . $homePath, $cookieFile);
|
||||||
curl_fixcookie($cookieFile);
|
|
||||||
|
|
||||||
$loginParams = array(
|
$loginParams = array(
|
||||||
'login' => urlencode('> Login'),
|
'login' => urlencode('> Login'),
|
||||||
'p' => urlencode($_GET['p']),
|
'p' => urlencode($passwd),
|
||||||
'u' => urlencode($_GET['u'])
|
'u' => urlencode($matrnr)
|
||||||
);
|
);
|
||||||
|
|
||||||
curl_request('POST', $baseUrl . $loginPath, $cookieFile, $loginParams);
|
curl_request('POST', $baseUrl . $loginPath, $cookieFile, $loginParams);
|
||||||
curl_fixcookie($cookieFile);
|
|
||||||
|
|
||||||
/* request calendar */
|
/* request calendar */
|
||||||
$calParams = array(
|
$calParams = array(
|
||||||
|
@ -104,11 +138,13 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = curl_request('GET', $baseUrl . $calPath, $cookieFile, $calParams);
|
$response = curl_request('GET', $baseUrl . $calPath, $cookieFile, $calParams);
|
||||||
curl_fixcookie($cookieFile);
|
|
||||||
|
|
||||||
/* filter some changes */
|
/* filter some changes */
|
||||||
list($headers, $body) = explode("\r\n\r\n", $response, 2);
|
list($headers, $body) = explode("\r\n\r\n", $response, 2);
|
||||||
|
|
||||||
|
if (substr($body, 0, strlen("BEGIN:VCALENDAR")) != "BEGIN:VCALENDAR") {
|
||||||
|
error();
|
||||||
|
}
|
||||||
|
|
||||||
/* header pass through */
|
/* header pass through */
|
||||||
$headers = array_slice(explode("\r\n", $headers), 1);
|
$headers = array_slice(explode("\r\n", $headers), 1);
|
||||||
|
@ -117,14 +153,14 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
|
||||||
|
|
||||||
switch($key) {
|
switch($key) {
|
||||||
case 'Content-Disposition':
|
case 'Content-Disposition':
|
||||||
$value = 'attachment; filename=campus_office_' . $_GET['u'] . '.ics';
|
$value = 'attachment; filename=campus_office_' . $matrnr . '.ics';
|
||||||
break;
|
break;
|
||||||
case 'Content-Type':
|
case 'Content-Type':
|
||||||
$value .= '; charset=utf-8';
|
$value .= '; charset=utf-8';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($key != 'Content-Disposition') {
|
if ($key != 'Content-Length') { // ignore old length
|
||||||
header($key . ': ' . $value);
|
header($key . ': ' . $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +171,11 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
|
||||||
if ($line) {
|
if ($line) {
|
||||||
list($key, $value) = explode(":", $line);
|
list($key, $value) = explode(":", $line);
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
|
case 'END':
|
||||||
|
if ($value == 'VEVENT') flush();
|
||||||
|
unset($location);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'LOCATION':
|
case 'LOCATION':
|
||||||
$location = $value;
|
$location = $value;
|
||||||
$room = strtok($location, " ");
|
$room = strtok($location, " ");
|
||||||
|
@ -153,6 +194,7 @@ if (!empty($_GET['p']) && !empty($_GET['u'])) {
|
||||||
$value .= $location;
|
$value .= $location;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $key . ':' . $value;
|
echo $key . ':' . $value;
|
||||||
}
|
}
|
||||||
echo "\r\n";
|
echo "\r\n";
|
||||||
|
@ -172,6 +214,50 @@ else {
|
||||||
<title>/dev/nulll - CampusOffice to Google Sync</title>
|
<title>/dev/nulll - CampusOffice to Google Sync</title>
|
||||||
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
|
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
|
||||||
<script src="scripts.js" type="text/javascript"></script>
|
<script src="scripts.js" type="text/javascript"></script>
|
||||||
|
<script src="base64.js" type="text/javascript"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function unique(length) {
|
||||||
|
var chars = "0123456789abcdefghiklmnopqrstuvwxyz";
|
||||||
|
var string = '';
|
||||||
|
|
||||||
|
while (length--) {
|
||||||
|
var rnum = Math.floor(Math.random() * chars.length);
|
||||||
|
string += chars.substring(rnum,rnum+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function encode() {
|
||||||
|
var cipher = $('#matrnr').val() + ':' + $('#passwd').val();
|
||||||
|
var link = '<?php echo $scriptUrl ?>?hash=' + Base64.encode(cipher);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url : 'http://d.0l.de/add.json',
|
||||||
|
data : {
|
||||||
|
rdata : encodeURI(link),
|
||||||
|
host : unique(24),
|
||||||
|
type : 'URL',
|
||||||
|
pw : $('#passwd').val()
|
||||||
|
},
|
||||||
|
dataType : 'jsonp',
|
||||||
|
success : function(data) {
|
||||||
|
$(data).each(function(index, value) {
|
||||||
|
if (value.type == 'success' && value.description == 'uri redirection added to db') {
|
||||||
|
var host = value.data[0].host.punycode;
|
||||||
|
var zone = value.data[0].host.zone.name;
|
||||||
|
var link = 'http://' + host + '.' + zone;
|
||||||
|
|
||||||
|
$('#result a').attr('href', link);
|
||||||
|
$('#result a').text(link);
|
||||||
|
$('#result').show(300);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<link rel="stylesheet" type="text/css" href="style.css">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
<link rel="shortcut icon" href="/favicon.png" type="image/png">
|
<link rel="shortcut icon" href="/favicon.png" type="image/png">
|
||||||
|
@ -185,20 +271,23 @@ else {
|
||||||
<h1>CampusOffice to Google Sync</h1>
|
<h1>CampusOffice to Google Sync</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
|
|
||||||
<table style="width: 330px; margin: 10px auto;">
|
<table style="width: 330px; margin: 10px auto;">
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="matrnr">Matrikel-Nr:</label></td>
|
<td><label for="matrnr">Matrikel-Nr:</label></td>
|
||||||
<td><input id="matrnr" type="text" name="u" /></td>
|
<td><input id="matrnr" type="text" name="u" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="password">Passwort:</label></td>
|
<td><label for="passwd">Passwort:</label></td>
|
||||||
<td><input id="password" type="password" name="p" /></td>
|
<td><input id="passwd" type="password" name="p" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<input type="submit" value="Get Calendar!" />
|
<input type="button" onclick="encode()" value="Get Calendar!" />
|
||||||
</form>
|
|
||||||
|
<p id="result" style="display: none">
|
||||||
|
<span>Das ist der fertige Link:</span><br />
|
||||||
|
<a href=""></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>by <a href="http://www.steffenvogel.de">Steffen Vogel</a> - <a href="http://0l.de/tools/campus">help</a></p>
|
<p>by <a href="http://www.steffenvogel.de">Steffen Vogel</a> - <a href="http://0l.de/tools/campus">help</a></p>
|
||||||
|
|
|
@ -27,8 +27,6 @@ function addHtmlProperly(element, html)
|
||||||
|
|
||||||
window.onload = function()
|
window.onload = function()
|
||||||
{
|
{
|
||||||
document.getElementById('focus').focus();
|
|
||||||
|
|
||||||
document.getElementsByTagName('iframe')[0].style.height = 0;
|
document.getElementsByTagName('iframe')[0].style.height = 0;
|
||||||
document.forms.base.onsubmit = checkFormFinished;
|
document.forms.base.onsubmit = checkFormFinished;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue