Till Brehm
2014-08-14 9edea9976bd605071e0694a90d704266c0b7e0f9
commit | author | age
8065e0 1 <?php
T 2
3 /*
4 Copyright (c) 2008, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
7fe908 31 require_once '../../lib/config.inc.php';
MC 32 require_once '../../lib/app.inc.php';
8065e0 33
T 34 //* Check permissions for module
35 $app->auth->check_module_permissions('admin');
9edea9 36 $app->auth->check_security_permissions('admin_allow_software_packages');
8065e0 37
T 38 //* This is only allowed for administrators
39 if(!$app->auth->is_admin()) die('only allowed for administrators.');
40
41 //* Get the latest updates from the repositorys and insert them in the local database
42 $updates_added = 0;
43 $repos = $app->db->queryAllRecords("SELECT software_repo_id, repo_url, repo_username, repo_password FROM software_repo WHERE active = 'y'");
44 if(is_array($repos)) {
45     foreach($repos as $repo) {
7fe908 46
8065e0 47         /*
T 48         SELECT software_package.package_name, v1, v2, v3, v4
49         FROM software_package
50         LEFT JOIN software_update ON ( software_package.package_name = software_update.package_name )
51         LEFT JOIN software_update_inst ON ( software_update.software_update_id = software_update_inst.software_update_id )
52         GROUP BY package_name
53         ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC
54         */
7fe908 55
8065e0 56         $client = new SoapClient(null, array('location' => $repo['repo_url'],
7fe908 57                 'uri'      => $repo['repo_url']));
MC 58
8065e0 59         $packages = $app->db->queryAllRecords("SELECT software_package.package_name, v1, v2, v3, v4 FROM software_package LEFT JOIN software_update ON ( software_package.package_name = software_update.package_name ) GROUP BY package_name ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC");
T 60         if(is_array($packages)) {
61             foreach($packages as $p) {
7fe908 62
8065e0 63                 $version = $p['v1'].'.'.$p['v2'].'.'.$p['v3'].'.'.$p['v4'];
7fe908 64                 $updates = $client->get_updates($p['package_name'], $version, $repo['repo_username'], $repo['repo_password']);
MC 65
8065e0 66                 if(is_array($updates)) {
T 67                     foreach($updates as $u) {
7fe908 68
MC 69                         $version_array = explode('.', $u['version']);
65ea2e 70                         $v1 = $app->functions->intval($version_array[0]);
M 71                         $v2 = $app->functions->intval($version_array[1]);
72                         $v3 = $app->functions->intval($version_array[2]);
73                         $v4 = $app->functions->intval($version_array[3]);
7fe908 74
8065e0 75                         $package_name = $app->db->quote($u['package_name']);
65ea2e 76                         $software_repo_id = $app->functions->intval($repo['software_repo_id']);
8065e0 77                         $update_url = $app->db->quote($u['url']);
T 78                         $update_md5 = $app->db->quote($u['md5']);
79                         $update_dependencies = (isset($u['dependencies']))?$app->db->quote($u['dependencies']):'';
80                         $update_title = $app->db->quote($u['title']);
81                         $type = $app->db->quote($u['type']);
7fe908 82
8065e0 83                         // Check that we do not have this update in the database yet
T 84                         $sql = "SELECT * FROM software_update WHERE package_name = '$package_name' and v1 = '$v1' and v2 = '$v2' and v3 = '$v3' and v4 = '$v4'";
85                         $tmp = $app->db->queryOneRecord($sql);
86                         if(!isset($tmp['software_update_id'])) {
87                             // Insert the update in the datbase
7fe908 88                             $sql = "INSERT INTO software_update (software_repo_id, package_name, update_url, update_md5, update_dependencies, update_title, v1, v2, v3, v4, type)
8065e0 89                             VALUES ($software_repo_id, '$package_name', '$update_url', '$update_md5', '$update_dependencies', '$update_title', '$v1', '$v2', '$v3', '$v4', '$type')";
T 90                             //die($sql);
91                             $app->db->query($sql);
92                         }
7fe908 93
8065e0 94                     }
T 95                 }
96             }
97         }
98     }
99 }
100
101
102 //* Install packages, if GET Request
103 if(isset($_GET['action']) && $_GET['action'] == 'install' && $_GET['package'] != '' && $_GET['server_id'] > 0) {
104     $package_name = $app->db->quote($_GET['package']);
65ea2e 105     $server_id = $app->functions->intval($_GET['server_id']);
M 106     $software_update_id = $app->functions->intval($_GET['id']);
7fe908 107
086696 108     $insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installing')";
M 109     // $insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installed')";
8065e0 110     $app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
7fe908 111
8065e0 112 }
T 113
114
115
116 // Show the list in the interface
117 // Loading the template
118 $app->uses('tpl');
119 $app->tpl->newTemplate("form.tpl.htm");
7fe908 120 $app->tpl->setInclude('content_tpl', 'templates/software_update_list.htm');
8065e0 121
T 122 /*
123 SELECT software_package.package_name, software_package.package_title, software_update.update_title, v1, v2, v3, v4, software_update_inst.status
124         FROM software_package
125         LEFT JOIN software_update ON ( software_package.package_name = software_update.package_name )
126         LEFT JOIN software_update_inst ON ( software_update.software_update_id = software_update_inst.software_update_id )
127 GROUP BY software_update.software_update_id
128         ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC
129 */
130
131
132
133 if(isset($_POST["server_id"]) && $_POST["server_id"] > 0) {
65ea2e 134     $server_id = $app->functions->intval($_POST["server_id"]);
8065e0 135 } else {
T 136     $server_id = 1;
137 }
138
139 $servers = $app->db->queryAllRecords('SELECT server_id, server_name FROM server ORDER BY server_name');
140 foreach($servers as $key => $server) {
141     if($server['server_id'] == $server_id) {
142         $servers[$key]['selected'] = 'selected';
143     } else {
144         $servers[$key]['selected'] = '';
145     }
146 }
147
7fe908 148 $app->tpl->setLoop('servers', $servers);
8065e0 149
T 150 $sql = "SELECT v1, v2, v3, v4, software_update.update_title, software_update.software_update_id, software_update.package_name, v1, v2, v3, v4, software_update_inst.status
151         FROM software_update LEFT JOIN software_update_inst ON ( software_update.software_update_id = software_update_inst.software_update_id )
152         WHERE server_id = $server_id
153         GROUP BY software_update.package_name
154         ORDER BY software_update.package_name ASC, v1 DESC , v2 DESC , v3 DESC , v4 DESC";
155
156 $installed_packages = $app->db->queryAllRecords($sql);
157
158
159 $records_out = array();
160
161 if(is_array($installed_packages)) {
162     foreach($installed_packages as $ip) {
7fe908 163
8065e0 164         // Get version number of the latest installed version
604c0c 165         $sql = "SELECT v1, v2, v3, v4 FROM software_update, software_update_inst WHERE software_update.software_update_id = software_update_inst.software_update_id AND server_id = ".$app->functions->intval($server_id)." ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC LIMIT 0,1";
8065e0 166         $lu = $app->db->queryOneRecord($sql);
7fe908 167
8065e0 168         // Get all installable updates
604c0c 169         $sql = "SELECT * FROM software_update WHERE v1 >= ".$app->functions->intval($lu['v1'])." AND v2 >= ".$app->functions->intval($lu['v2'])." AND v3 >= ".$app->functions->intval($lu['v3'])." AND v4 >= ".$app->functions->intval($lu['v4'])." AND package_name = '".$app->db->quote($ip['package_name'])."' ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC";
8065e0 170         $updates = $app->db->queryAllRecords($sql);
T 171         //die($sql);
7fe908 172
8065e0 173         if(is_array($updates)) {
T 174             // Delete the last record as it is already installed
175             unset($updates[count($updates)-1]);
7fe908 176
8065e0 177             foreach($updates as $key => $u) {
T 178                 $version = $u['v1'].'.'.$u['v2'].'.'.$u['v3'].'.'.$u['v4'];
e27086 179                 $installed_txt = "<a href=\"#\" onclick=\"loadContent('admin/software_update_list.php?action=install&package=".$u["package_name"]."&id=".$u["software_update_id"]."&server_id=".$server_id."');\">Install Update</a><br />";
8065e0 180                 $records_out[] = array('version' => $version, 'update_title' => $u["update_title"], 'installed' => $installed_txt);
7fe908 181
8065e0 182             }
T 183         }
184     }
185 }
186
187 /*
188 $updates = $app->db->queryAllRecords('SELECT software_update.update_title, software_update.software_update_id, software_update.package_name, v1, v2, v3, v4, software_update_inst.status
189         FROM software_update LEFT JOIN software_update_inst ON ( software_update.software_update_id = software_update_inst.software_update_id )
190         WHERE server_id = '.$server_id.'
191         GROUP BY software_update.package_name
192         ORDER BY software_update.package_name ASC, v1 DESC , v2 DESC , v3 DESC , v4 DESC');
193
194 if(is_array($updates)) {
195     foreach($updates as $key => $u) {
196         $installed_txt = '';
7fe908 197
8065e0 198         $version = $u['v1'].'.'.$u['v2'].'.'.$u['v3'].'.'.$u['v4'];
T 199         $updates[$key]['version'] = $version;
200         if($u['status'] == 'installed' || $u['status'] == 'installing' || $u['status'] == 'deleting') {
201             $installed_txt .= "Installed version $version<br />";
202         } else {
e27086 203             $installed_txt .= "<a href=\"#\" onclick=\"loadContent('admin/software_update_list.php?action=install&package=".$u["package_name"]."&id=".$u["software_update_id"]."&server_id=".$server_id."');\">Install now</a><br />";
8065e0 204         }
T 205         $updates[$key]['installed'] = $installed_txt;
7fe908 206
8065e0 207     }
T 208 }
209 */
210
211
212
7fe908 213 $app->tpl->setLoop('records', $records_out);
8065e0 214
615a0a 215 $language = (isset($_SESSION['s']['language']))?$_SESSION['s']['language']:$conf['language'];
7fe908 216 include_once 'lib/lang/'.$language.'_software_update_list.lng';
8065e0 217 $app->tpl->setVar($wb);
T 218
219
220 $app->tpl_defaults();
221 $app->tpl->pparse();
222
223
7fe908 224 ?>