Merge branch 'master' of github.com:stv0g/snippets

Conflicts:
	php/google_statistics.php
This commit is contained in:
Steffen Vogel 2012-08-15 00:16:09 +02:00
commit 2a0246ce0c
9 changed files with 278 additions and 75 deletions

BIN
php/cocal.db Normal file

Binary file not shown.

212
php/cocal.php Normal file
View file

@ -0,0 +1,212 @@
<?php
/* Constants */
$baseUrl = 'https://www.campus.rwth-aachen.de/office/';
$homePath = 'default.asp';
$loginPath = 'views/campus/redirect.asp';
$calPath = 'views/calendar/iCalExport.asp';
$logoutPath = 'system/login/logoff.asp';
/* Functions */
function curl_fixcookie($cookieFile) {
$contents = file_get_contents($cookieFile);
$lines = explode("\n", $contents);
foreach ($lines as $i => $line) {
if (strpos($line, "#HttpOnly_") === 0) {
$lines[$i] = substr($line, strlen("#HttpOnly_"));
}
}
$contents = implode("\n", $lines);
file_put_contents($cookieFile, $contents);
}
function curl_request($method, $url, $cookieFile = false, $params = array()) {
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true
);
if ($cookieFile) {
$options[CURLOPT_COOKIEFILE] = $cookieFile;
$options[CURLOPT_COOKIEJAR] = $cookieFile;
}
array_walk($params, function(&$value, $key) { $value = $key . '=' . $value; });
if ($params && strtolower($method) == 'post') {
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = implode("&", $params);
}
else if ($params) { /* assuming default mehtod: GET */
$options[CURLOPT_URL] .= '?' . implode('&', $params);
}
curl_setopt_array($ch, $options);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function get_address($db, $room) {
$result = sqlite_query($db, 'SELECT address FROM rooms WHERE name = "' . sqlite_escape_string($room). '";');
return ($result && sqlite_valid($result)) ? sqlite_fetch_string($result) : false;
}
function set_address($db, $room, $address) {
sqlite_exec($db, 'INSERT INTO rooms VALUES ("' . sqlite_escape_string($room) . '", "' . sqlite_escape_string($address) . '");', $error);
}
function crawl_address($room) {
$response = curl_request('GET', 'http://www.campus.rwth-aachen.de/rwth/all/room.asp?room=' . urlencode($room));
$matches = array();
$r = preg_match("/<td class=\"default\">Geb.udeanschrift<\/td><td class=\"default\">([^<]*)<\/td>/", $response, $matches);
return ($r > 0) ? $matches[1] : false;
}
/* Code */
if (!empty($_GET['p']) && !empty($_GET['u'])) {
/* perform login to get session cookie */
$cookieFile = tempnam('/tmp', 'campus_');
/* open database */
$db = sqlite_open('cocal.db');
$result = sqlite_query($db, "SELECT name FROM sqlite_master WHERE type='table' AND name='rooms';");
if (!sqlite_valid($result)) {
sqlite_exec($db, 'CREATE TABLE rooms (name VARCHAR(255), address VARCHAR(255));');
}
curl_request('GET', $baseUrl . $homePath, $cookieFile);
curl_fixcookie($cookieFile);
$loginParams = array(
'login' => urlencode('> Login'),
'p' => urlencode($_GET['p']),
'u' => urlencode($_GET['u'])
);
curl_request('POST', $baseUrl . $loginPath, $cookieFile, $loginParams);
curl_fixcookie($cookieFile);
/* request calendar */
$calParams = array(
'startdt' => strftime('%d.%m.%Y'),
'enddt' => strftime('%d.%m.%Y', time() + 6*31*24*60*60) /* halbes Jahr == ein Semester */
);
$response = curl_request('GET', $baseUrl . $calPath, $cookieFile, $calParams);
curl_fixcookie($cookieFile);
/* filter some changes */
list($headers, $body) = explode("\r\n\r\n", $response, 2);
/* header pass through */
$headers = array_slice(explode("\r\n", $headers), 1);
foreach ($headers as $header) {
list($key, $value) = explode(": ", $header);
switch($key) {
case 'Content-Disposition':
$value = 'attachment; filename=campus_office_' . $_GET['u'] . '.ics';
break;
case 'Content-Type':
$value .= '; charset=utf-8';
break;
}
if ($key != 'Content-Disposition') {
header($key . ': ' . $value);
}
}
$location = '';
$lines = explode("\r\n", $body);
foreach ($lines as $line) {
if ($line) {
list($key, $value) = explode(":", $line);
switch ($key) {
case 'LOCATION':
$location = $value;
$room = strtok($location, " ");
$address = get_address($db, $room);
if ($address === false) {
$address = preg_replace('/[ ]{2,}/sm', ' ', utf8_encode(crawl_address($room)));
set_address($db, $room, $address);
$crawled = true;
}
$value = $address . ', Aachen';
break;
case 'DESCRIPTION':
if ($value) $value .= '\n';
$value .= $location;
break;
}
echo $key . ':' . $value;
}
echo "\r\n";
}
/* cleanup */
unlink($cookieFile);
sqlite_close($db);
}
else {
echo '<?xml version="1.0" ?>';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>/dev/nulll - CampusOffice to Google Sync</title>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="scripts.js" type="text/javascript"></script>
<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">
<header>
<a href="http://0l.de"><img src="http://0l.de/_media/nulll_small.png" alt="0l" /></a>
<h1>CampusOffice to Google Sync</h1>
</header>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<table style="width: 330px; margin: 10px auto;">
<tr>
<td><label for="matrnr">Matrikel-Nr:</label></td>
<td><input id="matrnr" type="text" name="u" /></td>
</tr>
<tr>
<td><label for="password">Passwort:</label></td>
<td><input id="password" type="password" name="p" /></td>
</tr>
</table>
<input type="submit" value="Get Calendar!" />
</form>
<footer>
<p>by <a href="http://www.steffenvogel.de">Steffen Vogel</a> - <a href="http://0l.de/tools/campus">help</a></p>
</footer>
</div>
</body>
</html>
<?php
}
?>

View file

@ -142,7 +142,6 @@ echo '<?xml version="1.0" ?>';
<iframe name="ifr" id="ifr"></iframe>
<footer>
<p>by <a href="http://www.michaschwab.de">Micha Schwab</a> - <a href="http://0l.de/tools/contactimg">help</a></p>

View file

@ -31,6 +31,10 @@ $ghPassword = 'yourpassword';
$files = scandir($rootDir);
if (!isset($_ENV['TERM'])) {
die('This script is intended to be used from the command line!');
}
if (file_exists('gitweb.projects')) {
$public = file('gitweb.projects', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}

View file

@ -1,47 +0,0 @@
<?php
//header('Content-type: image/png');
function gd_graph($data) {
$im = imagecreate(count($data), max($data));
echo 'Breite: ' . count($data) . 'Hoehe: ' . max($data);
$linecol = imagecolorallocate($im, 0, 0, 255);
foreach($data as $x => $y) {
imageline($im, $x, $height, $x, $y, $linecol);
}
return $im;
}
$url = 'http://www.google.com/search?num=1&q=';
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$reffer = 'http://www.google.de';
$prefix['de'] = 'von ungefaer <b>';
$prefix['en'] = 'of about <b>';
$from = ($_GET['from']) ? (int) $_GET['from'] : 0;
$to = ($_GET['to']) ? (int) $_GET['to'] : 3;
$lang = ($_GET['lang']) ? $_GET['lang'] : 'en';
for ($i = $from; $i < $to + 1; $i++) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url . $i);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$count[$p] = curl_exec($ch);
curl_close($ch);
$count[$p] = substr($count[$p], strpos($count[$p], $prefix[$lang]) + strlen($prefix[$lang]));
$count[$p] = substr($count[$p], 0, strpos($count[$p], '</b>'));
$count[$p] = (int) str_replace(',', '', $count[$p]);
$p++;
}
ImagePNG(gd_graph($count));
?>

4
php/jquery-1.7.2.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -13,24 +13,24 @@ h1 {
}
#content {
margin: auto;
width: 800px;
text-align: center
margin: auto;
width: 800px;
text-align: center
}
dl {
width: 300px;
margin: auto;
width: 300px;
margin: auto;
}
dt {
float: left;
float: left;
}
dt a {
color: #555
color: #555
}
dd {
text-align: right;
padding-bottom: 4px
text-align: right;
padding-bottom: 4px
}
table {
@ -39,8 +39,7 @@ table {
}
td, th {
padding: 2px 5px 2px 5px;
border: 1px solid grey;
border: 0;
}
a img {
@ -48,14 +47,14 @@ a img {
}
footer {
opacity: 0;
alpha(opacity=0);
display: block;
margin-top: 50px;
opacity: 0;
alpha(opacity=0);
display: block;
margin-top: 50px;
}
iframe{
border: 0;
height: 300px;
width: 700px;
margin: 0;
border: 0;
height: 300px;
width: 700px;
margin: 0;
}

View file

@ -74,7 +74,7 @@ function show_form() {
echo '<form name="sms_frm" onsubmit="return send(this);" action="' . $_SERVER['PHP_SELF'] . '" method="post">
<table>
<!-- <tr><td><span class="head">An:</span> <span id="number">++' . $config['recipient'] . '</span></td></tr> --!>
<!-- <tr><td><span class="head">An:</span> <span id="number">++' . $config['recipient'] . '</span></td></tr> -->
<tr><td><textarea onfocus="update_length(this);" onkeyup="update_length(this);" name="message" cols="40" rows="5">' . $message . '</textarea></td></tr>
<tr><td><span class="head">Zeichen:</span> <span id="length">' . strlen($message) . '</span> (&uuml;brig: <span id="left" style="color: green;">' . (160 - strlen($message)) . '</span>)</td></tr>
</table>

View file

@ -1,7 +1,7 @@
html, body {
padding: 0;
margin: 0;
color: #666666;
color: #777;
}
* {
@ -22,7 +22,39 @@ span.number {
}
textarea {
width: 165px;
height: 165px;
input {
-moz-border-bottom-colors: none;
-moz-border-image: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background: -moz-linear-gradient(center top , rgba(255, 255, 255, 0.2) 0%, rgba(0, 0, 0, 0.2) 100%) repeat scroll 0 0 #EEEEEE;
border-color: #CCCCCC #AAAAAA #AAAAAA #CCCCCC;
border-radius: 3px 3px 3px 3px;
border-right: 1px solid #AAAAAA;
border-style: solid;
border-width: 1px;
color: #444444;
cursor: pointer;
display: inline-block;
font-family: "HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 11px;
font-weight: bold;
line-height: 21px;
padding: 4px 12px;
text-decoration: none;
text-shadow: 0 1px rgba(255, 255, 255, 0.75);
}
textarea {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #CCCCCC;
border-radius: 2px 2px 2px 2px;
color: #777777;
display: block;
font: 13px "HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif;
max-width: 100%;
outline: medium none;
padding: 6px 4px;
width: 165px;
}