7275e6e1ace6aefb0fe85a28bcadb5df29a0663d
[debian/openrocket] / core / web / html / actions / updates.php
1 <?
2 $logfiles = "/home/groups/o/op/openrocket/persistent/logs/access-";
3
4
5 // getallheaders method
6 if (!function_exists('getallheaders')) {
7     function getallheaders() {
8        foreach ($_SERVER as $name => $value) {
9            if (substr($name, 0, 5) == 'HTTP_') {
10                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
11            }
12        }
13        return $headers;
14     }
15 }
16
17
18 // Parse + validate headers
19 $orid = "";
20 $orversion = "";
21 $oros = "";
22 $orjava = "";
23 $orcountry = "";
24 $orcores = "";
25 $orlocale = "";
26 foreach (getallheaders() as $header => $value) {
27     if (preg_match("/^[a-zA-Z0-9 !$%&()*+,.\\/:=?@_~-]{1,40}$/", $value)) {
28         $h = strtolower($header);
29         if ($h == 'x-openrocket-version') {
30             $orversion = $value;
31         } else if ($h == 'x-openrocket-id') {
32             $orid = $value;
33         } else if ($h == 'x-openrocket-os') {
34             $oros = $value;
35         } else if ($h == 'x-openrocket-java') {
36             $orjava = $value;
37         } else if ($h == 'x-openrocket-country') {
38             $orcountry = $value;
39         } else if ($h == 'x-openrocket-cpus') {
40             $orcores = $value;
41         } else if ($h == 'x-openrocket-locale') {
42             $orlocale = $value;
43         }
44     }
45 }
46
47 // Log the request
48 if ((strlen($orversion) > 0 || strlen($orid) > 0 || strlen($oros) > 0
49      || strlen($orjava) > 0 || strlen($orcountry) > 0 
50      || strlen($orcores) > 0 || strlen($orlocale) > 0) &&
51     (strlen($orversion) < 20 && strlen($orid) < 50 && strlen($oros) < 50
52      && strlen($orjava) < 50 && strlen($orcountry) < 50) 
53      && strlen($orcores) < 10 && strlen($orlocale) < 20) {
54
55     $file = $logfiles . gmdate("Y-m");
56     $line = gmdate("Y-m-d H:i:s") . ";" . $orid . ";" . $orversion .
57         ";" . $oros . ";" . $orjava . ";" . $orcountry . ";" . $orcores . 
58         ";" . $orlocale . "\n";
59
60     $fp = fopen($file, 'a');
61     if ($fp != FALSE) {
62         fwrite($fp, $line);
63         fclose($fp);
64     }
65 }
66
67
68 // Set HTTP content-type header
69 // No charset allowed for 0.9.4
70 //header("Content-type: text/plain; charset=utf-8");
71 header("Content-type: text/plain");
72
73 /*
74  * Currently all old versions are handled manually.
75  * Update checking was introduced in OpenRocket 0.9.4
76  *
77  * We ignore "pre" versions, they are handled exacly like
78  * their non-pre counterparts.
79  */
80 $version = $_GET["version"];
81 $updates = "";
82
83 $unstable = "12.03";
84 $stable = "1.0.0";
85
86 if (preg_match("/^1\.1\.9$/", $version)) {
87   $updates = "Version: " . $unstable . "\n" .
88     "8: Writing RKT files\n" .
89     "5: Configurable stage separation\n" .
90     "5: Guided tours\n" .
91     "4: Freeform fin import from images\n" .
92     "4: Translations to Italian and Russian\n" .
93     "";
94 } else if (preg_match("/^1\.1\.8$/", $version)) {
95   $updates = "Version: " . $unstable . "\n" .
96     "8: Writing RKT files\n" .
97     "6: Additional template printing\n" .
98     "5: Geodetic computations\n" .
99     "5: Configurable stage separation\n" .
100     "5: Guided tours\n" .
101     "4: Freeform fin import from images\n" .
102     "4: Translations to Italian and Russian\n" .
103     "4: Bug fixes\n" .
104     "";
105 } else if (preg_match("/^1\.1\.7$/", $version)) {
106   $updates = "Version: " . $unstable . "\n" .
107     "8: Writing RKT files\n" .
108     "6: Additional template printing\n" .
109     "5: Geodetic computations\n" .
110     "5: Configurable stage separation\n" .
111     "5: Guided tours\n" .
112     "4: Freeform fin import from images\n" .
113     "4: Translations to Italian and Russian\n" .
114     "4: Bug fixes\n" .
115     "";
116 } else if (preg_match("/^1\.1\.6$/", $version)) {
117   $updates = "Version: " . $unstable . "\n" .
118     "8: Writing RKT files\n" .
119     "8: Automatic rocket design optimization\n" .
120     "6: Additional template printing\n" .
121     "5: Geodetic computations\n" .
122     "";
123 } else if (preg_match("/^1\.1\.5$/", $version)) {
124   $updates = "Version: " . $unstable . "\n" .
125     "8: Writing RKT files\n" .
126     "8: Automatic rocket design optimization\n" .
127     "6: Initial localization support\n" .
128     "6: Additional template printing\n" .
129     "5: Geodetic computations\n" .
130     "5: Scaling support\n" .
131     "4: Bug fixes\n" .
132     "";
133 } else if (preg_match("/^1\.1\.4$/", $version)) {
134   $updates = "Version: " . $unstable . "\n" .
135     "8: Writing RKT files\n" .
136     "8: Automatic rocket design optimization\n" .
137     "6: Initial localization support\n" .
138     "5: Fixes to printing system\n" .
139     "5: Scaling support\n" .
140     "";
141 } else if (preg_match("/^1\.1\.3$/", $version)) {
142   $updates = "Version: " . $unstable . "\n" .
143     "8: Writing RKT files\n" .
144     "8: Automatic rocket design optimization\n" .
145     "7: Initial printing support\n" .
146     "6: Initial localization support\n" .
147     "5: Scaling support\n" .
148     "4: Bug fixes\n" .
149     "";
150 } else if (preg_match("/^1\.1\.[12]$/", $version)) {
151   $updates = "Version: " . $unstable . "\n" .
152     "8: Writing RKT files\n" .
153     "8: Automatic rocket design optimization\n" .
154     "6: Initial printing support\n" .
155     "5: Initial drag-and-drop support\n" .
156     "5: Initial localization support\n" .
157     "5: Scaling support\n" .
158     "4: Bug fixes\n" .
159     "";
160 } else if (preg_match("/^1\.1\.0$/", $version)) {
161   $updates = "Version: " . $unstable . "\n" .
162     "8: Writing RKT files\n" .
163     "8: Automatic rocket design optimization\n" .
164     "6: Initial printing support\n" .
165     "6: Initial localization support\n" .
166     "6: Enhanced motor selection\n" .
167     "5: Rewritten simulation code\n" .
168     "5: Drag-and-drop support\n" .
169     "4: Bug fixes\n" .
170     "";
171 } else if (preg_match("/^0\.9\.6/", $version)) {
172   $updates = "Version: " . $stable . "\n" .
173     "8: Writing RKT files\n" .
174     "6: Hundreds of new thrustcurves\n" .
175     "5: Bug fixes\n" .
176     "";
177 } else if (preg_match("/^0\.9\.[45]/", $version)) {
178   $updates = "Version: " . $stable . "\n" .
179     "8: Writing RKT files\n" .
180     "7: Hundreds of new thrustcurves\n" .
181     "6: Aerodynamic computation updates\n" .
182     "5: Numerous bug fixes" .
183     "";
184 }
185
186
187 if (strlen($updates) == 0) {
188
189   // No updates available
190   header("HTTP/1.0 204 No Content");
191
192 } else {
193
194   header("HTTP/1.0 200 OK");
195   echo $updates;
196
197 }
198
199 ?>