-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
160 lines (146 loc) · 5.19 KB
/
index.php
File metadata and controls
160 lines (146 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* Created by PhpStorm.
* User: david
* Date: 24.07.2018
* Time: 12:22
*/
namespace Net\Schmithuesen {
use Exception;
use Sabre\VObject\Reader;
require_once __DIR__ . '/vendor/autoload.php';
/**
* @param $body
*
* @return string
*/
function getFullHTML($body): string
{
return getHTMLHead() . $body . getHTMLFooter();
}
/**
* @param string[] $urls
* @return bool[]
*/
function validateIcsLinks(array $urls): array
{
$ret = [];
foreach ($urls as $url) {
try {
$data = @file_get_contents($url);
if ($data === false) {
$ret[$url] = false;
continue;
}
$cal = Reader::read($data, Reader::OPTION_FORGIVING);
// Prüfen, ob es sich um eine VCALENDAR-Komponente handelt
$ret[$url] = $cal->name === 'VCALENDAR';
} catch (Exception) {
$ret[$url] = false;
}
}
return $ret;
}
$task = $_REQUEST["task"] ?? null;
if (!file_exists(__DIR__ . '/database.sqlite')) {
$task = "create";
}
switch ($task) {
case "createDB":
if (file_exists(__DIR__ . '/database.sqlite')) {
echo "Database already exists";
die;
}
$db = new Database();
try {
$db->create();
header("Location: index.php");
} catch (Exception) {
echo getFullHTML("<h1>Create DB</h1> <pre> Could not create database. </pre>");
die;
}
break;
case "store":
$icsLinks = array_filter($_REQUEST[LinkAdministrationView::PRIVATE_ICS_LINK] ?? []);
$validateResults = validateIcsLinks($icsLinks);
if (!in_array(false, $validateResults) && !empty($_REQUEST[LinkAdministrationView::EMAIL_FIELD])) {
$db = new Database();
$publicICS = $db->store($icsLinks,
$_REQUEST[LinkAdministrationView::EMAIL_FIELD]);
$view = new ResultView($publicICS);
echo getFullHTML(
$view);
} else {
$errorMsg = "";
if (empty($_REQUEST[LinkAdministrationView::EMAIL_FIELD]))
$errorMsg .= "<p>Error: The email field is required.</p>\n";
foreach ($validateResults as $url => $valid) {
if (!$valid) {
$errorMsg .= "<p> ICS link <strong>" . htmlspecialchars($url) . "</strong> is not valid</p>\n";
}
}
echo getFullHTML(new ErrorView($errorMsg));
}
break;
case "getPublicIcsFeed":
if (!isset($_REQUEST["secret"])) {
echo getFullHTML(new ErrorView("Wrong URL Format."));
return;
}
$anon = new IcsAnonymizer($_REQUEST["secret"]);
header('Expires: Thu, 01-Jan-70 00:00:01 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/calendar;charset=UTF-8');
echo $anon->getFreeBusyInformation();
break;
case "phpinfo":
//echo phpinfo();
break;
case "serverinfo":
print_r($_SERVER);
break;
default:
$explanationOfTheTool = '
<p>creates an ics feed from your calendar feed where only the following information is kept:</p>
<p><ol>
<li>Start time</li>
<li>end time</li>
<li>booking state</li>
<li>outlook free/busy state</li>
</ol></p>
<p>You get a link to the anonymized feed.</p>
';
$view = new LinkAdministrationView();
echo getFullHTML($explanationOfTheTool . $view);
}
function getBootstrapCode(): string
{
return '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>';
}
function getHTMLHead(): string
{
return '<!DOCTYPE HTML> <html lang="de">
<head>' . getBootstrapCode() . '
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1>ics anonymizer</h1>
';
}
function getHTMLFooter(): string
{
return "
</div>
</div>
</div>
</body>
</html>";
}
}