Even more rewritten
[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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 // Init array
49 $ONLINE['code'] = "???";
50
51 // Get response from our server in an array
52 $response = GET_URL("check-updates3.php");
53
54 if (empty($response[0]) && empty($response[1]) && empty($response[2]) && empty($response[3])) {
55         // Error!
56         $response = array("", '', '');
57 } else {
58         // Analyse header for response code
59         if (eregi("200 OK", $response[0])) {
60                 // Found, kill header
61                 $pos = 0;
62                 foreach($response as $k => $v) {
63                         $v = trim($v);
64                         if (empty($v)) {
65                                 // Header ends here (+1)
66                                 $pos = $k + 1; break;
67                         }
68                 }
69
70                 $response2 = array();
71                 for($i = $pos; $i < count($response); $i++) {
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                         'revision' => str_replace("\n", '', $response[2]),
82                 );
83
84                 // Array for available patches
85                 $PATCHES = array(
86                         'fname' => array(),
87                         'fsize' => array(),
88                         'ctime' => array()
89                 );
90
91                 if (($response[3] != "[EOF]") && ($ONLINE['version'] == constant('FULL_VERSION'))) {
92                         // We have found new patches (newer than FULL_VERSION)
93                         $max = str_replace("\n", '', $response[count($response) - 2]); $totalSize = 0;
94
95                         // Maximum of available pacthes extracted (above). Now we can get all informations
96                         for ($idx = 0; $idx < $max; $idx++) {
97                                 // List only newer patches
98                                 $TEST = substr(str_replace("\n", '', $response[$idx * 5 + 2]), 0, strlen(getConfig('patch_level')));
99
100                                 // I have removed the addional test for the stored timemark in database or you cannot find
101                                 // new updates on my server when you haven't installed it before I upload a patch... :-(
102                                 if (bigintval($TEST) > getConfig(('patch_level'))) {
103                                         // Copy every data from the response array
104                                         $PATCHES['fname'][] = str_replace("\n", '', $response[$idx * 5 + 2]);
105                                         $PATCHES['fsize'][] = str_replace("\n", '', $response[$idx * 5 + 3]);
106                                         $PATCHES['ctime'][] = str_replace("\n", '', $response[$idx * 5 + 4]);
107                                         switch (GET_LANGUAGE()) {
108                                                 case "de": $PATCHES['descr'][] = str_replace("\n", '', $response[$idx * 5 + 5]); break; // Load german description
109                                                 default  : $PATCHES['descr'][] = str_replace("\n", '', $response[$idx * 5 + 6]); break; // Load english description as default
110                                         }
111
112                                         // Add patch's size to total
113                                         $totalSize += $PATCHES['fsize'][$idx];
114                                 }
115                         }
116
117                         array_pk_sort($PATCHES, array("ctime", "fname"));
118
119                         // All done here!
120                         $ONLINE['code'] = "200 OK";
121                 }
122         } else {
123                 // 404 / 403 error from server
124                 $ONLINE['code'] = $response[0];
125         }
126 }
127
128 // Is a newer version available?
129 if (empty($ONLINE['version'])) {
130         // Disconnected?
131         LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"admin_failed\">{--ADMIN_CANNOT_CHECK_VERSION--} (".$ONLINE['code'].")</div>");
132 } elseif (($ONLINE['version'] != constant('FULL_VERSION')) || ($ONLINE['revision'] != constant('CURR_SVN_REVISION'))) {
133         // New full-version available (all previous released patches are included in this version!)
134         define('__ONLINE_VERSION', $ONLINE['version']);
135         define('__ONLINE_CHANGE' , MAKE_DATETIME($ONLINE['changed'], "2"));
136         define('__ONLINE_REVISION', $ONLINE['revision']);
137
138         // Load template
139         LOAD_TEMPLATE("admin_update_download");
140 } else {
141         // You have the latest version!
142         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('NO_UPDATES_AVAILABLE'));
143 }
144
145 //
146 ?>