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 |
|
2af58c
|
75 |
$package_name = $u['package_name']; |
65ea2e
|
76 |
$software_repo_id = $app->functions->intval($repo['software_repo_id']); |
2af58c
|
77 |
$update_url = $u['url']; |
MC |
78 |
$update_md5 = $u['md5']; |
|
79 |
$update_dependencies = (isset($u['dependencies']))?$u['dependencies']:''; |
|
80 |
$update_title = $u['title']; |
|
81 |
$type = $u['type']; |
7fe908
|
82 |
|
8065e0
|
83 |
// Check that we do not have this update in the database yet |
cc7a82
|
84 |
$sql = "SELECT * FROM software_update WHERE package_name = ? and v1 = ? and v2 = ? and v3 = ? and v4 = ?"; |
MC |
85 |
$tmp = $app->db->queryOneRecord($sql, $package_name, $v1, $v2, $v3, $v4); |
8065e0
|
86 |
if(!isset($tmp['software_update_id'])) { |
T |
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) |
cc7a82
|
89 |
VALUES ($software_repo_id, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
8065e0
|
90 |
//die($sql); |
cc7a82
|
91 |
$app->db->query($sql, $package_name, $update_url, $update_md5, $update_dependencies, $update_title, $v1, $v2, $v3, $v4, $type); |
8065e0
|
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) { |
3a11d2
|
104 |
$package_name = $_GET['package']; |
65ea2e
|
105 |
$server_id = $app->functions->intval($_GET['server_id']); |
M |
106 |
$software_update_id = $app->functions->intval($_GET['id']); |
7fe908
|
107 |
|
3a11d2
|
108 |
$insert_data = array( |
MC |
109 |
"package_name" => $package_name, |
|
110 |
"server_id" => $server_id, |
|
111 |
"software_update_id" => $software_update_id, |
|
112 |
"status" => 'installing' |
|
113 |
); |
8065e0
|
114 |
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id'); |
7fe908
|
115 |
|
8065e0
|
116 |
} |
T |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
// Show the list in the interface |
|
121 |
// Loading the template |
|
122 |
$app->uses('tpl'); |
|
123 |
$app->tpl->newTemplate("form.tpl.htm"); |
7fe908
|
124 |
$app->tpl->setInclude('content_tpl', 'templates/software_update_list.htm'); |
8065e0
|
125 |
|
T |
126 |
/* |
|
127 |
SELECT software_package.package_name, software_package.package_title, software_update.update_title, v1, v2, v3, v4, software_update_inst.status |
|
128 |
FROM software_package |
|
129 |
LEFT JOIN software_update ON ( software_package.package_name = software_update.package_name ) |
|
130 |
LEFT JOIN software_update_inst ON ( software_update.software_update_id = software_update_inst.software_update_id ) |
|
131 |
GROUP BY software_update.software_update_id |
|
132 |
ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC |
|
133 |
*/ |
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
if(isset($_POST["server_id"]) && $_POST["server_id"] > 0) { |
65ea2e
|
138 |
$server_id = $app->functions->intval($_POST["server_id"]); |
8065e0
|
139 |
} else { |
T |
140 |
$server_id = 1; |
|
141 |
} |
|
142 |
|
|
143 |
$servers = $app->db->queryAllRecords('SELECT server_id, server_name FROM server ORDER BY server_name'); |
|
144 |
foreach($servers as $key => $server) { |
|
145 |
if($server['server_id'] == $server_id) { |
|
146 |
$servers[$key]['selected'] = 'selected'; |
|
147 |
} else { |
|
148 |
$servers[$key]['selected'] = ''; |
|
149 |
} |
|
150 |
} |
|
151 |
|
7fe908
|
152 |
$app->tpl->setLoop('servers', $servers); |
8065e0
|
153 |
|
T |
154 |
$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 |
|
155 |
FROM software_update LEFT JOIN software_update_inst ON ( software_update.software_update_id = software_update_inst.software_update_id ) |
|
156 |
WHERE server_id = $server_id |
|
157 |
GROUP BY software_update.package_name |
|
158 |
ORDER BY software_update.package_name ASC, v1 DESC , v2 DESC , v3 DESC , v4 DESC"; |
|
159 |
|
|
160 |
$installed_packages = $app->db->queryAllRecords($sql); |
|
161 |
|
|
162 |
|
|
163 |
$records_out = array(); |
|
164 |
|
|
165 |
if(is_array($installed_packages)) { |
|
166 |
foreach($installed_packages as $ip) { |
7fe908
|
167 |
|
8065e0
|
168 |
// Get version number of the latest installed version |
cc7a82
|
169 |
$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 = ? ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC LIMIT 0,1"; |
MC |
170 |
$lu = $app->db->queryOneRecord($sql, $server_id); |
7fe908
|
171 |
|
8065e0
|
172 |
// Get all installable updates |
cc7a82
|
173 |
$sql = "SELECT * FROM software_update WHERE v1 >= ? AND v2 >= ? AND v3 >= ? AND v4 >= ? AND package_name = ? ORDER BY v1 DESC , v2 DESC , v3 DESC , v4 DESC"; |
MC |
174 |
$updates = $app->db->queryAllRecords($sql, $lu['v1'], $lu['v2'], $lu['v3'], $lu['v4'], $ip['package_name']); |
8065e0
|
175 |
//die($sql); |
7fe908
|
176 |
|
8065e0
|
177 |
if(is_array($updates)) { |
T |
178 |
// Delete the last record as it is already installed |
|
179 |
unset($updates[count($updates)-1]); |
7fe908
|
180 |
|
8065e0
|
181 |
foreach($updates as $key => $u) { |
T |
182 |
$version = $u['v1'].'.'.$u['v2'].'.'.$u['v3'].'.'.$u['v4']; |
9021d7
|
183 |
$installed_txt = "<a href=\"#\" data-load-content=\"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
|
184 |
$records_out[] = array('version' => $version, 'update_title' => $u["update_title"], 'installed' => $installed_txt); |
7fe908
|
185 |
|
8065e0
|
186 |
} |
T |
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
|
|
192 |
|
7fe908
|
193 |
$app->tpl->setLoop('records', $records_out); |
8065e0
|
194 |
|
615a0a
|
195 |
$language = (isset($_SESSION['s']['language']))?$_SESSION['s']['language']:$conf['language']; |
7fe908
|
196 |
include_once 'lib/lang/'.$language.'_software_update_list.lng'; |
8065e0
|
197 |
$app->tpl->setVar($wb); |
T |
198 |
|
|
199 |
|
|
200 |
$app->tpl_defaults(); |
|
201 |
$app->tpl->pparse(); |
|
202 |
|
|
203 |
|
7fe908
|
204 |
?> |