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'); |
|
36 |
|
|
37 |
//* This is only allowed for administrators |
|
38 |
if(!$app->auth->is_admin()) die('only allowed for administrators.'); |
|
39 |
|
|
40 |
//* Get the latest packages from the repositorys and insert them in the local database |
|
41 |
$packages_added = 0; |
|
42 |
$repos = $app->db->queryAllRecords("SELECT software_repo_id, repo_url, repo_username, repo_password FROM software_repo WHERE active = 'y'"); |
1390c8
|
43 |
if(is_array($repos) && isset($_GET['action']) && $_GET['action'] == 'repoupdate' ) { |
8065e0
|
44 |
foreach($repos as $repo) { |
T |
45 |
$client = new SoapClient(null, array('location' => $repo['repo_url'], |
7fe908
|
46 |
'uri' => $repo['repo_url'])); |
MC |
47 |
|
8065e0
|
48 |
$packages = $client->get_packages($repo['repo_username'], $repo['repo_password']); |
T |
49 |
if(is_array($packages)) { |
|
50 |
foreach($packages as $p) { |
2af58c
|
51 |
$package_name = $p['name']; |
cc7a82
|
52 |
$tmp = $app->db->queryOneRecord("SELECT package_id FROM software_package WHERE package_name = ?", $package_name); |
7fe908
|
53 |
|
2af58c
|
54 |
$package_title = $p['title']; |
MC |
55 |
$package_description = $p['description']; |
65ea2e
|
56 |
$software_repo_id = $app->functions->intval($repo['software_repo_id']); |
2af58c
|
57 |
$package_type = $p['type']; |
MC |
58 |
$package_installable = $p['installable']; |
|
59 |
$package_requires_db = $p['requires_db']; |
|
60 |
$package_remote_functions = $p['remote_functions']; |
7fe908
|
61 |
|
8065e0
|
62 |
if(empty($tmp['package_id'])) { |
2af58c
|
63 |
$insert_data = array( |
MC |
64 |
"software_repo_id" => $software_repo_id, |
|
65 |
"package_name" => $package_name, |
|
66 |
"package_title" => $package_title, |
|
67 |
"package_description" => $package_description, |
|
68 |
"package_type" => $package_type, |
|
69 |
"package_installable" => $package_installable, |
|
70 |
"package_requires_db" => $package_requires_db, |
|
71 |
"package_remote_functions" => $package_remote_functions |
|
72 |
); |
1390c8
|
73 |
$app->db->datalogInsert('software_package', $insert_data, 'package_id'); |
8065e0
|
74 |
$packages_added++; |
1390c8
|
75 |
} else { |
2af58c
|
76 |
$update_data = array( |
MC |
77 |
"software_repo_id" => $software_repo_id, |
|
78 |
"package_title" => $package_title, |
|
79 |
"package_description" => $package_description, |
|
80 |
"package_type" => $package_type, |
|
81 |
"package_installable" => $package_installable, |
|
82 |
"package_requires_db" => $package_requires_db, |
|
83 |
"package_remote_functions" => $package_remote_functions |
|
84 |
); |
1390c8
|
85 |
//echo $update_data; |
7fe908
|
86 |
$app->db->datalogUpdate('software_package', $update_data, 'package_id', $tmp['package_id']); |
8065e0
|
87 |
} |
T |
88 |
} |
|
89 |
} |
7fe908
|
90 |
|
MC |
91 |
$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"); |
|
92 |
if(is_array($packages)) { |
|
93 |
foreach($packages as $p) { |
|
94 |
|
|
95 |
$version = $p['v1'].'.'.$p['v2'].'.'.$p['v3'].'.'.$p['v4']; |
|
96 |
$updates = $client->get_updates($p['package_name'], $version, $repo['repo_username'], $repo['repo_password']); |
|
97 |
|
|
98 |
if(is_array($updates)) { |
|
99 |
foreach($updates as $u) { |
|
100 |
|
|
101 |
$version_array = explode('.', $u['version']); |
|
102 |
$v1 = $app->functions->intval($version_array[0]); |
|
103 |
$v2 = $app->functions->intval($version_array[1]); |
|
104 |
$v3 = $app->functions->intval($version_array[2]); |
|
105 |
$v4 = $app->functions->intval($version_array[3]); |
|
106 |
|
3a11d2
|
107 |
$package_name = $u['package_name']; |
7fe908
|
108 |
$software_repo_id = $app->functions->intval($repo['software_repo_id']); |
3a11d2
|
109 |
$update_url = $u['url']; |
MC |
110 |
$update_md5 = $u['md5']; |
|
111 |
$update_dependencies = (isset($u['dependencies']))?$u['dependencies']:''; |
|
112 |
$update_title = $u['title']; |
|
113 |
$type = $u['type']; |
7fe908
|
114 |
|
MC |
115 |
// Check that we do not have this update in the database yet |
cc7a82
|
116 |
$sql = "SELECT * FROM software_update WHERE package_name = ? and v1 = ? and v2 = ? and v3 = ? and v4 = ?"; |
MC |
117 |
$tmp = $app->db->queryOneRecord($sql, $package_name, $v1, $v2, $v3, $v4); |
7fe908
|
118 |
if(!isset($tmp['software_update_id'])) { |
2af58c
|
119 |
$insert_data = array( |
MC |
120 |
"software_repo_id" => $software_repo_id, |
|
121 |
"package_name" => $package_name, |
|
122 |
"update_url" => $update_url, |
|
123 |
"update_md5" => $update_md5, |
|
124 |
"update_dependencies" => $update_dependencies, |
|
125 |
"update_title" => $update_title, |
|
126 |
"v1" => $v1, |
|
127 |
"v2" => $v2, |
|
128 |
"v3" => $v3, |
|
129 |
"v4" => $v4, |
|
130 |
"type" => $type |
|
131 |
); |
1390c8
|
132 |
$app->db->datalogInsert('software_update', $insert_data, 'software_update_id'); |
7fe908
|
133 |
} |
MC |
134 |
|
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
} |
8065e0
|
139 |
} |
T |
140 |
} |
|
141 |
|
|
142 |
// Show the list in the interface |
|
143 |
// Loading the template |
|
144 |
$app->uses('tpl'); |
|
145 |
$app->tpl->newTemplate("form.tpl.htm"); |
7fe908
|
146 |
$app->tpl->setInclude('content_tpl', 'templates/software_package_list.htm'); |
8065e0
|
147 |
|
T |
148 |
|
|
149 |
$servers = $app->db->queryAllRecords('SELECT server_id, server_name FROM server ORDER BY server_name'); |
|
150 |
$packages = $app->db->queryAllRecords('SELECT * FROM software_package'); |
cc6568
|
151 |
if(is_array($packages) && count($packages) > 0) { |
8065e0
|
152 |
foreach($packages as $key => $p) { |
T |
153 |
$installed_txt = ''; |
|
154 |
foreach($servers as $s) { |
cc7a82
|
155 |
$inst = $app->db->queryOneRecord("SELECT * FROM software_update, software_update_inst WHERE software_update_inst.software_update_id = software_update.software_update_id AND software_update_inst.package_name = ? AND server_id = ?", $p["package_name"], $s["server_id"]); |
8065e0
|
156 |
$version = $inst['v1'].'.'.$inst['v2'].'.'.$inst['v3'].'.'.$inst['v4']; |
7fe908
|
157 |
|
8065e0
|
158 |
if($inst['status'] == 'installed') { |
1390c8
|
159 |
$installed_txt .= $s['server_name'].": ".$app->lng("Installed version $version")."<br />"; |
7fe908
|
160 |
} elseif ($inst['status'] == 'installing') { |
MC |
161 |
$installed_txt .= $s['server_name'].": ".$app->lng("Installation in progress")."<br />"; |
|
162 |
} elseif ($inst['status'] == 'failed') { |
|
163 |
$installed_txt .= $s['server_name'].": ".$app->lng("Installation failed")."<br />"; |
8065e0
|
164 |
} elseif ($inst['status'] == 'deleting') { |
1390c8
|
165 |
$installed_txt .= $s['server_name'].": ".$app->lng("Deletion in progress")."<br />"; |
8065e0
|
166 |
} else { |
1390c8
|
167 |
if($p['package_installable'] == 'no') { |
T |
168 |
$installed_txt .= $s['server_name'].": ".$app->lng("Package can not be installed.")."<br />"; |
|
169 |
} else { |
9021d7
|
170 |
$installed_txt .= $s['server_name'].": <a href=\"#\" data-load-content=\"admin/software_package_install.php?package=".$p["package_name"]."&server_id=".$s["server_id"]."\">Install now</a><br />"; |
1390c8
|
171 |
} |
8065e0
|
172 |
} |
T |
173 |
} |
cc6568
|
174 |
$packages[$key]['software_update_inst_id'] = intval($inst['software_update_inst_id']); |
8065e0
|
175 |
$packages[$key]['installed'] = $installed_txt; |
T |
176 |
} |
7fe908
|
177 |
$app->tpl->setVar('has_packages', 1); |
cc6568
|
178 |
} else { |
7fe908
|
179 |
$app->tpl->setVar('has_packages', 0); |
8065e0
|
180 |
} |
T |
181 |
|
|
182 |
|
|
183 |
|
7fe908
|
184 |
$app->tpl->setLoop('records', $packages); |
8065e0
|
185 |
|
615a0a
|
186 |
$language = (isset($_SESSION['s']['language']))?$_SESSION['s']['language']:$conf['language']; |
7fe908
|
187 |
include_once 'lib/lang/'.$language.'_software_package_list.lng'; |
8065e0
|
188 |
$app->tpl->setVar($wb); |
T |
189 |
|
|
190 |
|
|
191 |
$app->tpl_defaults(); |
|
192 |
$app->tpl->pparse(); |
|
193 |
|
|
194 |
|
7fe908
|
195 |
?> |