-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateclient.php
132 lines (99 loc) · 3.79 KB
/
updateclient.php
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
<?php
error_reporting(E_ALL);
date_default_timezone_set('UTC');
function pvs_encode ($orig,$key = 'a') {
$codetable = Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
for ($i = 0; $i < 10; $i++) {
$codetable[] = ''.$i;
}
$codetable[] = '_';
$codetable[] = ':';
$codetable[] = '.';
$codetable[] = ',';
$codetable[] = '+';
$codetable[] = '-';
$codetable[] = '=';
$codetable[] = '|';
$codetable[] = '~';
$codetable[] = '*';
$codetable[] = ';';
$codetable2 = array_flip($codetable);
$keyAtemp = str_split($key);
$origA = str_split($orig); $keyA = $origA;
for ($i = 0; $i < strlen($orig); $i++) {
if (!isset($codetable2[$origA[$i]])) {
$origA[$i] = 62;
} else {
$origA[$i] = $codetable2[$origA[$i]];
}
$j = bcmod($i,strlen($key));
if (!isset($codetable2[$keyAtemp[$j]])) {
$keyA[$i] = 0;
} else {
$keyA[$i] = $codetable2[$keyAtemp[$j]];
}
}
$ret = '';
for ($i = 0; $i < count($origA); $i++) {
$charcode = bcmod(($origA[$i] + $keyA[$i]),count($codetable));
$ret .= $codetable[$charcode];
}
return $ret;
}
$reqDate = getdate($_SERVER['REQUEST_TIME']);
$reqHour = gmmktime($reqDate['hours'],0,0,$reqDate['mon'],$reqDate['mday'],$reqDate['year']).'000';
$protocol = explode('/',$_SERVER['SERVER_PROTOCOL']);
$protocol = $protocol[0];
$protocol = strtolower($protocol);
$auth_compare = pvs_encode(pvs_encode($reqHour,'pvsXHRClient'),$protocol.'://'.$_SERVER['HTTP_HOST']);
$auth_compare2 = pvs_encode(pvs_encode($reqHour,'ResponsepvsXHRClient'),$protocol.'://'.$_SERVER['HTTP_HOST']);
//Der direkte Aufruf ist nicht erwünscht, Aufruf nur über XHR
if (!isset($_GET['auth'])) {
header("HTTP/1.0 403 Forbidden");
die('Connection refused!');
} elseif ($_GET['auth'] != $auth_compare AND $_GET['auth'] != $auth_compare2) {
header("HTTP/1.0 403 Forbidden");
die('Connection refused!');
}
//Stelle sicher, dass wichtige Dateien existieren
if (!is_file('VERSION')) { file_put_contents('VERSION','1.0'); }
if ($_GET['auth'] == $auth_compare) {
$globSet = parse_ini_file('settings.ini');
$school_name = (isset($globSet['school_name']))?$globSet['school_name']:'Musterschule Musterstadt';
$school_address = Array();
if (isset($globSet['school_address'])) {
if (is_array($globSet['school_address'])) {
$school_address = $globSet['school_address'];
} else {
$school_address[] = $globSet['school_address'];
}
} else {
$school_address[] = 'Musterschule Musterstadt, Schule für Unbegabte, Mörikeweg 110, 90432 Musterstadt';
$school_address[] = 'Tel. 09843/55515 - Fax 09843/55516 - EMail [email protected] - Internet ms.musterstadt.de';
}
unset($globSet);
header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
echo '<info>';
echo '<version>'.file_get_contents('VERSION').'</version>';
echo '<sname>'.$school_name.'</sname>';
echo '<saddr>'.implode(' | ',$school_address).'</saddr>';
echo '</info>';
die();
} elseif ($_GET['auth'] == $auth_compare2) {
file_put_contents('./update.zip',convert_uudecode($HTTP_RAW_POST_DATA));
$zip = new ZipArchive();
$zip = new ZipArchive;
if ($zip->open('./update.zip') === TRUE) {
$zip->extractTo('./');
$zip->close();
die('Update erfolgreich ausgeführt!');
} else {
header("HTTP/1.0 500 Internal Server Error");
die('Update fehlgeschlagen!');
}
} else {
header("HTTP/1.0 403 Forbidden");
die('Connection refused!');
}
?>