This is the code that runs on
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.6 KiB

require_once 'vendor/autoload.php';
use ICal\ICal;
static $DATE_FORMAT = 'd.m.Y H:i';
static $VISITORS_FILE = '/opt/dorf.jetzt_visitors';
static $DORF_IN_LOCKDOWN = true;
static $DORF_VIRTUAL_EVENTS = true;
static $ICAL_URL = '';
$state_map = array(
'closed' => (object) array(
'state_string' => 'Das Dorf ist gerade <em>geschlossen</em>.',
'svg' => 'lock',
'color' => 'red',
'maybe_open' => (object) array(
'state_string' => 'Das Dorf ist gerade <em>vielleicht geöffnet</em>: </p><p>Der Clubraum ist offen, aber es findet keine Veranstaltung statt.</p><p>
Der Status kann sich also kurzfristig ändern.',
'svg' => 'done',
'color' => 'brown',
'open' => (object) array(
'state_string' => 'Das Dorf ist gerade <em>geöffnet</em>.</p><p>
Komm gerne vorbei.',
'svg' => 'done',
'color' => 'green',
'private' => (object) array(
'state_string' => 'Das Dorf ist gerade <em>privat</em>: </p><p>Es sind Leute da, aber der Clubraum ist nicht geöffnet.</p><p>
Komm gerne vorbei (aber frag lieber vorher, wie lange noch Leute da sind).',
'svg' => 'lock',
'color' => 'fdd835',
'unknown' => (object) array(
'state_string' => 'Der Status vom Dorf ist gerade <em>unbekannt</em>',
'svg' => 'warning',
'color' => 'orange',
'error' => (object) array(
'state_string' => 'Der Server konnte den Status vom Dorf nicht abrufen.',
'svg' => 'error',
'color' => 'blue',
$hash_to_state = array(
'bff0167ed8aba031c49122ef4046cf1b' => 'closed',
'd8ec899c69283bc775952a767db9d5f5' => 'maybe_open',
'2c2672c641425e5b2acd6ee74f39ae60' => 'open',
'66aece8ae27ffd3a656d42005fa3efbd' => 'private',
'86c75c0ad413b06ff8291673162d0b64' => 'unknown',
'0' => 'error',
$img = file_get_contents('');
$hash = md5($img);
$state = $hash_to_state[$hash];
$ical = new ICal(false, array(
'defaultSpan' => 2,
'defaultTimeZone' => 'Europe/Berlin',
'defaultWeekStart' => 'MO',
'filterDaysBefore' => '1',
$ical->initUrl($ICAL_URL, $acceptLanguage = 'de');
$events = $ical->eventsFromInterval('2 week');
$first_event = $events[0];
$events = array_slice($events, 1);
$locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
setlocale(LC_TIME, $locale);
function format_event($event): string{
global $DATE_FORMAT, $ical;
$startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]);
$startdate_str = $startdate_loop->format($DATE_FORMAT);
$interval_loop = new DateInterval($event->duration);
if ($interval_loop->d != 0 || $interval_loop->h >= 24){
$enddate_str = $startdate_loop->add($interval_loop)->format($DATE_FORMAT);
$enddate_str = $startdate_loop->add($interval_loop)->format('H:i');
return $startdate_str . ' &ndash; ' . $enddate_str;
$v = file_get_contents($VISITORS_FILE);
<!DOCTYPE html>
<html lang="de">
<title>Was geht im</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link rel="stylesheet" href="assets/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="assets/font/Material-Icons.css" rel="stylesheet">
<meta charset="UTF-8" />
<div class="container">
<nav class="navbar">
<h1 class="text-center">Was geht im</h1><hr />
<?php if($DORF_IN_LOCKDOWN): ?>
<div class="card mb-3 text-center">
<div class="card-body">
<h5 class="card-title">Das Chaosdorf ist geschlossen</h5>
<img src="assets/svg/ic_lock_48px.svg" style="filter:url(assets/css/filter.svg#red);height:16rem;width:auto;" />
<p class="card-text font-weight-normal">Das Chaosdorf öffnet vorsichtig wieder.</p>
<p class="card-text font-weight-normal">Veranstaltungen finden teilweise hybrid oder online-only statt.</p>
<p class="card-text font-weight-normal">Einwählen zu den Veranstaltungen könnt ihr euch hier: <a href="">VirtualSpace</a></p>
<?php else: ?>
<div class="card mb-3 text-center">
<div class="card-body">
<h5 class="card-title">Türstatus</h5>
<img src="assets/svg/ic_<?= $state_map[$state]->svg ?>_48px.svg" style="filter:url(assets/css/filter.svg#<?= $state_map[$state]->color ?>);height:16rem;width:auto;" />
<p class="card-text"><?= $state_map[$state]->state_string ?></p>
<div class="btn-wrapper">
<a href="" class="btn btn-lg btn-block btn-primary">What's this?</a>
<?php endif ?>
<div class="card mb-3 text-center">
<div class="card-body">
<h5 class="card-title">Events</h5>
<?php if (!empty($events)) : ?>
<h6 class="card-subtitle mb-2 text-muted">Nächste Veranstaltung</h6>
<p class="card-text">
<h5 class="font-weight-bold"><?= htmlspecialchars($first_event->summary, ENT_QUOTES, 'UTF-8') ?></h5>
<span class="font-weight-normal"><?= format_event($first_event) ?></span>
<span class="font-weight-normal"><a href="<?= $first_event->url ?>">Details zur Veranstaltung</a></span>
<h5 class="card-title">Danach:</h5>
<table class="table">
<?php foreach ($events as $event) : ?>
<th scope="row"><?=format_event($event)?></th>
<td><?= htmlspecialchars($event->summary) ?></td>
<td><a href="<?= $event->url ?>">Details</a></td>
<?php endforeach ?>
<a href="" class="btn btn-lg btn-block btn-primary">Event-Kalender</a>
<?php else: ?>
<h6 class="card-subtitle mb-2 text-muted">Aktuell keine Veranstaltungen.</h6>
<p class="card-text">
<span class="font-weight-normal">
Es stehen aktuell keine Veranstaltungen an.
<?php endif ?>
<?php endif ?>
<footer class="page-footer font-small text-center">
Du bist Besucher #<?= $v ?>
<a href="">Sieh dir den Code hier an</a>
Melde Fehler bitte an <a href=""></a>
Dies ist kein offizieller Auftritt des <a href="">Chaos Computer Club Düsseldorf / Chaosdorf e.V.</a>.
// These are actually not needed, see
// <script src="assets/js/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
// <script src="" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
// <script src="assets/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
/* Initialising values */
if(!$v) $v=0;
$count_visit = true;
/* List of bots I found in various access logs */
$invalid_uas = array(
foreach ($invalid_uas as $ua){
if(stripos($_SERVER['HTTP_USER_AGENT'], $ua) !== FALSE){
$count_visit = false;
if ($count_visit === TRUE){
file_put_contents($VISITORS_FILE, $v);