wernis extension is now alpha code (only listing in admin area is missing), naming...
[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 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
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 if (empty($response[0]) && empty($response[1]) && empty($response[2]))
49 {
50         // Error!
51         $response = array("", "", "");
52 }
53  else
54 {
55         // Analyse header for response code
56         if (ereg("200 OK", $response[0]))
57         {
58                 // Found, kill header
59                 $pos = 0;
60                 foreach($response as $k=>$v)
61                 {
62                         $v = trim($v);
63                         if (empty($v))
64                         {
65                                 // Header ends here (+1)
66                                 $pos = $k + 1; break;
67                         }
68                 }
69                 $response2 = array();
70                 for($i = $pos; $i < count($response); $i++)
71                 {
72                         $response2[] = trim($response[$i]);
73                 }
74                 $response = $response2; unset($response2);
75                 unset($pos);
76
77                 // Which is the latest version on server?
78                 $ONLINE = array(
79                         'version' => str_replace("\n", "", $response[0]),
80                         'changed' => str_replace("\n", "", $response[1])
81                 );
82
83                 // Array for available patches
84                 $PATCHES = array(
85                         'fname' => array(),
86                         'fsize' => array(),
87                         'ctime' => array()
88                 );
89
90                 if (($response[2] != "[EOF]") && ($ONLINE['version'] == FULL_VERSION))
91                 {
92                         // We have found new patches (newer than FULL_VERSION)
93                         $max = str_replace("\n", "", $response[sizeof($response) - 2]); $TOTAL_SIZE = "0";
94
95                         // Maximum of available pacthes extracted (above). Now we can get all informations
96                         for ($idx = 0; $idx < $max; $idx++)
97                         {
98                                 // List only newer patches
99                                 $TEST = substr(str_replace("\n", "", $response[$idx * 5 + 2]), 0, strlen($_CONFIG['patch_level']));
100
101                                 // I have removed the addional test for the stored timemark in database or you cannot find
102                                 // new updates on my server when you haven't installed it before I upload a patch... :-(
103                                 if (bigintval($TEST) > bigintval($_CONFIG['patch_level']))
104                                 {
105                                         // Copy every data from the response array
106                                         $PATCHES['fname'][] = str_replace("\n", "", $response[$idx * 5 + 2]);
107                                         $PATCHES['fsize'][] = str_replace("\n", "", $response[$idx * 5 + 3]);
108                                         $PATCHES['ctime'][] = str_replace("\n", "", $response[$idx * 5 + 4]);
109                                         switch (GET_LANGUAGE())
110                                         {
111                                                 case "de": $PATCHES['descr'][] = str_replace("\n", "", $response[$idx * 5 + 5]); break; // Load german description
112                                                 default  : $PATCHES['descr'][] = str_replace("\n", "", $response[$idx * 5 + 6]); break; // Load english description as default
113                                         }
114
115                                         // Add patch's size to total
116                                         $TOTAL_SIZE += $PATCHES['fsize'][$idx];
117                                 }
118                         }
119                         array_pk_sort($PATCHES, array("ctime", "fname"));
120
121                         // All done here!
122                         $ONLINE['code'] = "200 OK";
123                 }
124         }
125          else
126         {
127                 // 404 / 403 error from server
128                 $ONLINE['code'] = $response[0];
129         }
130 }
131
132 OPEN_TABLE("100%", "admin_content", "center");
133 // Is a newer version available?
134 if (empty($ONLINE['version']))
135 {
136         // Disconnected?
137         LOAD_TEMPLATE("admin_settings_saved", false, "<FONT class=\"admin_failed\">".ADMIN_CANNOT_CHECK_VERSION." (".$ONLINE['code'].")</FONT>");
138 }
139  elseif ($ONLINE['version'] != FULL_VERSION)
140 {
141         // New full-version available (all previous released patches are included in this version!)
142         define('__ONLINE_VERSION', $ONLINE['version']);
143         define('__ONLINE_CHANGE' , MAKE_DATETIME($ONLINE['changed'], "2"));
144
145         // Load template
146         LOAD_TEMPLATE("admin_update_download");
147 }
148  elseif (sizeof($PATCHES['fname']) > 0)
149 {
150         // Some patches are available
151         $OUT = ""; $SW = "2";
152         foreach ($PATCHES['fname'] as $idx=>$file)
153         {
154                 $SIZE = TRANSLATE_COMMA(round($PATCHES['fsize'][$idx]/102.4)/10);
155                 $content = array(
156                         'sw'          => $SW,
157                         'patch_url'   => SERVER_URL."/patches/".$file,
158                         'patch_title' => str_replace("_", " ", str_replace(".zip", "", $file)),
159                         'patch_ctime' => MAKE_DATETIME($PATCHES['ctime'][$idx], "2"),
160                         'patch_size'  => $SIZE,
161                         'patch_desc'  => COMPILE_CODE($PATCHES['descr'][$idx]),
162                 );
163                 // Evaluate descrition code
164                 $eval = "\$content['patch_desc'] = \"".$content['patch_desc']."\";";
165                 eval($eval);
166
167                 // Load template, switch color and count total size up
168                 $OUT .= LOAD_TEMPLATE("admin_patches_row", true, $content);
169                 $SW = 3 - $SW;
170         }
171         define('__PATCH_ROWS', $OUT);
172
173         // Total size
174         define('__TOTAL_SIZE', TRANSLATE_COMMA($TOTAL_SIZE / 1024));
175
176         // Load main template
177         LOAD_TEMPLATE("admin_patches");
178 }
179  else
180 {
181         // You have the latest version!
182         LOAD_TEMPLATE("admin_settings_saved", false, NO_UPDATES_AVAILABLE);
183 }
184 CLOSE_TABLE();
185 //
186 ?>