commit | author | age
|
1390c8
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2010, 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'; |
1390c8
|
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'); |
1390c8
|
37 |
|
T |
38 |
//* This is only allowed for administrators |
|
39 |
if(!$app->auth->is_admin()) die('only allowed for administrators.'); |
|
40 |
|
2af58c
|
41 |
$package_name = $_REQUEST['package']; |
65ea2e
|
42 |
$install_server_id = $app->functions->intval($_REQUEST['server_id']); |
2af58c
|
43 |
$install_key = trim($_REQUEST['install_key']); |
1390c8
|
44 |
|
cc7a82
|
45 |
$package = $app->db->queryOneRecord("SELECT * FROM software_package WHERE package_name = ?", $package_name); |
1390c8
|
46 |
|
T |
47 |
$install_key_verified = false; |
|
48 |
$message_err = ''; |
|
49 |
$message_ok = ''; |
|
50 |
|
|
51 |
//* verify the key |
|
52 |
if($package['package_installable'] == 'key' && $install_key != '') { |
7fe908
|
53 |
|
cc7a82
|
54 |
$repo = $app->db->queryOneRecord("SELECT * FROM software_repo WHERE software_repo_id = ?", $package['software_repo_id']); |
7fe908
|
55 |
|
1390c8
|
56 |
$client = new SoapClient(null, array('location' => $repo['repo_url'], |
7fe908
|
57 |
'uri' => $repo['repo_url'])); |
MC |
58 |
|
1390c8
|
59 |
$install_key_verified = $client->check_installable($package_name, $install_key, $repo['repo_username'], $repo['repo_password']); |
7fe908
|
60 |
|
1390c8
|
61 |
if($install_key_verified == false) { |
T |
62 |
//$install_key = ''; |
|
63 |
$message_err = 'Verification of the key failed.'; |
|
64 |
} else { |
|
65 |
// Store the verified key into the database |
3a11d2
|
66 |
$app->db->datalogUpdate('software_package', array("package_key" => $install_key), 'package_id', $package['package_id']); |
1390c8
|
67 |
} |
T |
68 |
} else { |
|
69 |
$message_ok = 'Please enter the software key for the package.'; |
|
70 |
} |
|
71 |
|
|
72 |
//* Install packages, if all requirements are fullfilled. |
|
73 |
if($install_server_id > 0 && $package_name != '' && ($package['package_installable'] == 'yes' || $install_key_verified == true)) { |
cc7a82
|
74 |
$sql = "SELECT software_update_id, package_name, update_title FROM software_update WHERE type = 'full' AND package_name = ? ORDER BY v1 DESC, v2 DESC, v3 DESC, v4 DESC LIMIT 0,1"; |
MC |
75 |
$tmp = $app->db->queryOneRecord($sql, $package_name); |
1390c8
|
76 |
$software_update_id = $tmp['software_update_id']; |
7fe908
|
77 |
|
1390c8
|
78 |
//* if package requires a DB and there is no data for a db in config, then we create this data now |
T |
79 |
if($package['package_requires_db'] == 'mysql') { |
|
80 |
$app->uses('ini_parser,getconf'); |
7fe908
|
81 |
|
1390c8
|
82 |
$package_config_array = array(); |
T |
83 |
if(trim($package['package_config']) != '') { |
|
84 |
$package_config_array = $app->ini_parser->parse_ini_string(stripslashes($package['package_config'])); |
|
85 |
} |
7fe908
|
86 |
|
1390c8
|
87 |
if(!isset($package_config_array['mysql'])) { |
7fe908
|
88 |
$package_config_array['mysql'] = array( 'database_name' => 'ispapp'.$package['package_id'], |
MC |
89 |
'database_user' => 'ispapp'.$package['package_id'], |
|
90 |
'database_password' => md5(mt_rand()), |
|
91 |
'database_host' => 'localhost'); |
1390c8
|
92 |
$package_config_str = $app->ini_parser->get_ini_string($package_config_array); |
aa3ea2
|
93 |
$package['package_config'] = $package_config_str; |
3a11d2
|
94 |
$app->db->datalogUpdate('software_package', array("package_config" => $package_config_str), 'package_id', $package['package_id']); |
1390c8
|
95 |
} |
T |
96 |
} |
7fe908
|
97 |
|
aa3ea2
|
98 |
//* If the packages requires a remote user |
T |
99 |
if($package['package_remote_functions'] != '') { |
7fe908
|
100 |
|
aa3ea2
|
101 |
if(trim($package['package_config']) != '') { |
T |
102 |
$package_config_array = $app->ini_parser->parse_ini_string(stripslashes($package['package_config'])); |
|
103 |
} |
7fe908
|
104 |
|
aa3ea2
|
105 |
if(!isset($package_config_array['remote_api'])) { |
T |
106 |
$remote_user = 'ispapp'.$package['package_id']; |
|
107 |
$remote_password = md5(mt_rand()); |
2af58c
|
108 |
$remote_functions = $package['package_remote_functions']; |
7fe908
|
109 |
|
aa3ea2
|
110 |
$package_config_array['remote_api'] = array( |
7fe908
|
111 |
'remote_hostname' => $_SERVER['HTTP_HOST'], |
MC |
112 |
'remote_user' => $remote_user, |
|
113 |
'remote_password' => $remote_password |
|
114 |
); |
aa3ea2
|
115 |
|
T |
116 |
$package_config_str = $app->ini_parser->get_ini_string($package_config_array); |
|
117 |
$package['package_config'] = $package_config_str; |
02bf99
|
118 |
$remote_password_md5 = md5($remote_password); |
2af58c
|
119 |
$app->db->datalogUpdate('software_package', array("package_config" => $package_config_str), 'package_id', $package['package_id']); |
7fe908
|
120 |
|
aa3ea2
|
121 |
$sql = "INSERT INTO `remote_user` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `remote_username`, `remote_password`, `remote_functions`) VALUES |
cc7a82
|
122 |
(1, 1, 'riud', 'riud', '', ?, ?, ?)"; |
MC |
123 |
$app->db->query($sql, $remote_user, $remote_password_md5, $remote_functions); |
7fe908
|
124 |
|
aa3ea2
|
125 |
} |
7fe908
|
126 |
|
aa3ea2
|
127 |
} |
7fe908
|
128 |
|
1390c8
|
129 |
//* Add the record to start the install process |
3a11d2
|
130 |
$insert_data = array( |
MC |
131 |
"package_name" => $package_name, |
|
132 |
"server_id" => $install_server_id, |
|
133 |
"software_update_id" => $software_update_id, |
|
134 |
"status" => 'installing' |
|
135 |
); |
1390c8
|
136 |
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id'); |
1b48cf
|
137 |
$message_ok = 'Starting package installation '."<a href=\"#\" onclick=\"ISPConfig.submitForm('pageForm','admin/software_package_list.php');\">".$app->lng('next')."</a>"; |
7fe908
|
138 |
|
1390c8
|
139 |
} |
T |
140 |
|
|
141 |
if(count($_POST) > 2 && $install_key == '') { |
|
142 |
$message_ok = 'Please enter the software key.'; |
|
143 |
} |
|
144 |
|
|
145 |
//* Show key input form |
|
146 |
if($package['package_installable'] == 'key' && !$install_key_verified) { |
|
147 |
$insert_key = true; |
|
148 |
} else { |
|
149 |
$insert_key = false; |
|
150 |
} |
|
151 |
|
|
152 |
// Loading the template |
|
153 |
$app->uses('tpl'); |
|
154 |
$app->tpl->newTemplate("form.tpl.htm"); |
7fe908
|
155 |
$app->tpl->setInclude('content_tpl', 'templates/software_package_install.htm'); |
1390c8
|
156 |
|
7fe908
|
157 |
$app->tpl->setVar('message_ok', $message_ok); |
MC |
158 |
$app->tpl->setVar('message_err', $message_err); |
|
159 |
$app->tpl->setVar('insert_key', $insert_key); |
|
160 |
$app->tpl->setVar('install_key', $install_key); |
|
161 |
$app->tpl->setVar('package_name', $package_name); |
|
162 |
$app->tpl->setVar('server_id', $install_server_id); |
1390c8
|
163 |
|
T |
164 |
|
7fe908
|
165 |
include_once 'lib/lang/en_software_package_install.lng'; |
1390c8
|
166 |
$app->tpl->setVar($wb); |
T |
167 |
|
|
168 |
|
|
169 |
$app->tpl_defaults(); |
|
170 |
$app->tpl->pparse(); |
|
171 |
|
|
172 |
?> |