c2730615743c65cb532ca544f52c672fa9b61628
[mailer.git] / inc / modules / admin / what-updates.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 01/16/2004 *
4  * ================                             Last change: 05/14/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-updates.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Check for updates                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Prueft nach Updates                              *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 // Init array
44 $ONLINE['code'] = "???";
45
46 // Get response from our server in an array
47 $response = MXCHANGE_OPEN("check-updates2.php");
48
49 if (empty($response[0]) && empty($response[1]) && empty($response[2])) {
50         // Error!
51         $response = array("", "", "");
52 } else {
53         // Analyse header for response code
54         if (eregi("200 OK", $response[0])) {
55                 // Found, kill header
56                 $pos = 0;
57                 foreach($response as $k => $v) {
58                         $v = trim($v);
59                         if (empty($v)) {
60                                 // Header ends here (+1)
61                                 $pos = $k + 1; break;
62                         }
63                 }
64
65                 $response2 = array();
66                 for($i = $pos; $i < count($response); $i++) {
67                         $response2[] = trim($response[$i]);
68                 }
69                 $response = $response2; unset($response2);
70                 unset($pos);
71
72                 // Which is the latest version on server?
73                 $ONLINE = array(
74                         'version' => str_replace("\n", "", $response[0]),
75                         'changed' => str_replace("\n", "", $response[1])
76                 );
77
78                 // Array for available patches
79                 $PATCHES = array(
80                         'fname' => array(),
81                         'fsize' => array(),
82                         'ctime' => array()
83                 );
84
85                 if (($response[2] != "[EOF]") && ($ONLINE['version'] == FULL_VERSION)) {
86                         // We have found new patches (newer than FULL_VERSION)
87                         $max = str_replace("\n", "", $response[sizeof($response) - 2]); $TOTAL_SIZE = "0";
88
89                         // Maximum of available pacthes extracted (above). Now we can get all informations
90                         for ($idx = 0; $idx < $max; $idx++) {
91                                 // List only newer patches
92                                 $TEST = substr(str_replace("\n", "", $response[$idx * 5 + 2]), 0, strlen($_CONFIG['patch_level']));
93
94                                 // I have removed the addional test for the stored timemark in database or you cannot find
95                                 // new updates on my server when you haven't installed it before I upload a patch... :-(
96                                 if (bigintval($TEST) > bigintval($_CONFIG['patch_level'])) {
97                                         // Copy every data from the response array
98                                         $PATCHES['fname'][] = str_replace("\n", "", $response[$idx * 5 + 2]);
99                                         $PATCHES['fsize'][] = str_replace("\n", "", $response[$idx * 5 + 3]);
100                                         $PATCHES['ctime'][] = str_replace("\n", "", $response[$idx * 5 + 4]);
101                                         switch (GET_LANGUAGE()) {
102                                                 case "de": $PATCHES['descr'][] = str_replace("\n", "", $response[$idx * 5 + 5]); break; // Load german description
103                                                 default  : $PATCHES['descr'][] = str_replace("\n", "", $response[$idx * 5 + 6]); break; // Load english description as default
104                                         }
105
106                                         // Add patch's size to total
107                                         $TOTAL_SIZE += $PATCHES['fsize'][$idx];
108                                 }
109                         }
110
111                         array_pk_sort($PATCHES, array("ctime", "fname"));
112
113                         // All done here!
114                         $ONLINE['code'] = "200 OK";
115                 }
116         } else {
117                 // 404 / 403 error from server
118                 $ONLINE['code'] = $response[0];
119         }
120 }
121
122 // Is a newer version available?
123 if (empty($ONLINE['version'])) {
124         // Disconnected?
125         LOAD_TEMPLATE("admin_settings_saved", false, "<FONT class=\"admin_failed\">".ADMIN_CANNOT_CHECK_VERSION." (".$ONLINE['code'].")</FONT>");
126 } elseif ($ONLINE['version'] != FULL_VERSION) {
127         // New full-version available (all previous released patches are included in this version!)
128         define('__ONLINE_VERSION', $ONLINE['version']);
129         define('__ONLINE_CHANGE' , MAKE_DATETIME($ONLINE['changed'], "2"));
130
131         // Load template
132         LOAD_TEMPLATE("admin_update_download");
133 } elseif (sizeof($PATCHES['fname']) > 0) {
134         // Some patches are available
135         $OUT = ""; $SW = "2";
136         foreach ($PATCHES['fname'] as $idx => $file) {
137                 $SIZE = TRANSLATE_COMMA(round($PATCHES['fsize'][$idx]/102.4)/10);
138                 $content = array(
139                         'sw'          => $SW,
140                         'patch_url'   => SERVER_URL."/patches/".$file,
141                         'patch_title' => str_replace("_", " ", str_replace(".zip", "", $file)),
142                         'patch_ctime' => MAKE_DATETIME($PATCHES['ctime'][$idx], "2"),
143                         'patch_size'  => $SIZE,
144                         'patch_desc'  => COMPILE_CODE($PATCHES['descr'][$idx]),
145                 );
146                 // Evaluate descrition code
147                 $eval = "\$content['patch_desc'] = \"".$content['patch_desc']."\";";
148                 eval($eval);
149
150                 // Load template, switch color and count total size up
151                 $OUT .= LOAD_TEMPLATE("admin_patches_row", true, $content);
152                 $SW = 3 - $SW;
153         }
154         define('__PATCH_ROWS', $OUT);
155
156         // Total size
157         define('__TOTAL_SIZE', TRANSLATE_COMMA($TOTAL_SIZE / 1024));
158
159         // Load main template
160         LOAD_TEMPLATE("admin_patches");
161 } else {
162         // You have the latest version!
163         LOAD_TEMPLATE("admin_settings_saved", false, NO_UPDATES_AVAILABLE);
164 }
165
166 //
167 ?>