Repository navigation
Expand file tree
/
Copy pathpatch_unix.php
More file actions
166 lines (143 loc) · 5.61 KB
/
Copy pathpatch_unix.php
File metadata and controls
166 lines (143 loc) · 5.61 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
161
162
163
164
165
166
<?php
/*The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is patch.php.
The Initial Developer of the Original Code is
Mats 'Afr0' Vederhus. All Rights Reserved.
Contributor(s): ______________________________________.
*/
include 'createzip.php';
if(isset($_GET['Version']))
{
$ClientVersion = intval(htmlspecialchars($_GET['Version']));
$NewManifest = "";
if($handle = opendir(realpath('./patches/')))
{
//Find out if there are any manifests newer than the client's version.
while (false !== ($entry = readdir($handle)))
{
if(intval(str_replace('.manifest', '', $entry)) > $ClientVersion)
{
$NewManifest = realpath('./patches') . '/' . $entry . '.manifest';
break;
}
}
if(empty($NewManifest) || strcmp($NewManifest, realpath('./patches')) == 0)
{
header('Content-Description: No New Manifest');
header('Content-Type: text/html; charset=utf-8');
echo('<html><body><p>No new manifest!</p></body></html>');
}
else
{
//Open the new manifest and check if it has a child, which means an
//incremental update needs to take place...
$FileHandle = fopen($NewManifest, 'r');
$Parent = fgets($FileHandle);
$CurrentChild = fgets($FileHandle);
$Path = realpath('./patches');
$Parent = str_replace('Parent=', '', $Parent);
$Parent = str_replace('"', '', $Parent);
$Parent = trim($Parent);
$CurrentChild = str_replace('Child=', '', $CurrentChild);
$CurrentChild = str_replace('"', '', $CurrentChild);
$CurrentChild = trim($CurrentChild);
fclose($FileHandle);
//This is a compromise. Instead of checking for all childs, just check for the first one,
//and let the client handle the other children (if any).
if(empty($CurrentChild) !== true && empty($Parent) !== true)
{
$Parent = $Path . '/' . $Parent;
$CurrentChild = $Path . '/' . $CurrentChild;
$FilesToZip = array($CurrentChild, $NewManifest);
$ZipName = './' . strval(rand()) . '.zip';
create_zip($FilesToZip, $ZipName);
//Client should check the Content-Description header to figure out what to expect.
header('Content-Description: Zipped File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($ZipName));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($ZipName));
ob_clean();
flush();
readfile($ZipName);
unlink($ZipName);
exit();
}
//There was a child, but no parent.
else if(empty($CurrentChild) !== true && empty($Parent) == true)
{
$CurrentChild = $Path . '/' . $CurrentChild;
$FilesToZip = array($CurrentChild, $NewManifest);
$ZipName = './' . strval(rand()) . '.zip';
create_zip($FilesToZip, $ZipName);
//Client should check the Content-Description header to figure out what to expect.
header('Content-Description: Zipped File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($ZipName));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($ZipName));
ob_clean();
flush();
readfile($ZipName);
unlink($ZipName);
exit();
}
//There was a parent, but no child.
else if(empty($Parent) !== true && empty($CurrentChild) == true)
{
$Parent = $Path . '/' . $Parent;
$FilesToZip = array($Parent, $NewManifest);
$ZipName = './' . strval(rand()) . '.zip';
create_zip($FilesToZip, $ZipName);
//Client should check the Content-Description header to figure out what to expect.
header('Content-Description: Zipped File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($ZipName));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($ZipName));
ob_clean();
flush();
readfile($ZipName);
unlink($ZipName);
exit();
}
//There was neither a parent nor a child. This should really never occur.
else
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($NewManifest));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($NewManifest));
ob_clean();
flush();
readfile($NewManifest);
exit();
}
}
}
}
else
{
header('Content-Description: Invalid Request');
header('Content-Type: text/html; charset=utf-8');
echo('<html><body><p>Invalid request!</p></body></html>');
}
?>