Till Brehm
2014-08-14 9edea9976bd605071e0694a90d704266c0b7e0f9
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
41 $package_name = $app->db->quote($_REQUEST['package']);
65ea2e 42 $install_server_id = $app->functions->intval($_REQUEST['server_id']);
1390c8 43 $install_key = $app->db->quote(trim($_REQUEST['install_key']));
T 44
45 $package = $app->db->queryOneRecord("SELECT * FROM software_package WHERE package_name = '$package_name'");
46
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
604c0c 54     $repo = $app->db->queryOneRecord("SELECT * FROM software_repo WHERE software_repo_id = ".$app->db->quote($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
604c0c 66         $app->db->datalogUpdate('software_package', "package_key = '".$app->db->quote($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)) {
604c0c 74     $sql = "SELECT software_update_id, package_name, update_title FROM software_update WHERE type = 'full' AND package_name = '".$app->db->quote($package_name)."' ORDER BY v1 DESC, v2 DESC, v3 DESC, v4 DESC LIMIT 0,1";
1390c8 75     $tmp = $app->db->queryOneRecord($sql);
T 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;
7fe908 94             $app->db->datalogUpdate('software_package', "package_config = '".$app->db->quote($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());
108             $remote_functions = $app->db->quote($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);
7fe908 119             $app->db->datalogUpdate('software_package', "package_config = '".$app->db->quote($package_config_str)."'", 'package_id', $package['package_id']);
MC 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
604c0c 122                     (1, 1, 'riud', 'riud', '', '".$app->db->quote($remote_user)."', '".$app->db->quote($remote_password_md5)."', '".$app->db->quote($remote_functions)."');";
7fe908 123
aa3ea2 124             $app->db->query($sql);
7fe908 125
aa3ea2 126         }
7fe908 127
aa3ea2 128     }
7fe908 129
1390c8 130     //* Add the record to start the install process
604c0c 131     $insert_data = "(package_name, server_id, software_update_id, status) VALUES ('".$app->db->quote($package_name)."', '".$app->db->quote($install_server_id)."', '".$app->db->quote($software_update_id)."','installing')";
1390c8 132     $app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
e27086 133     $message_ok = 'Starting package installation '."<a href=\"#\" onclick=\"submitForm('pageForm','admin/software_package_list.php');\">".$app->lng('next')."</a>";
7fe908 134
1390c8 135 }
T 136
137 if(count($_POST) > 2 && $install_key == '') {
138     $message_ok = 'Please enter the software key.';
139 }
140
141 //* Show key input form
142 if($package['package_installable'] == 'key' && !$install_key_verified) {
143     $insert_key = true;
144 } else {
145     $insert_key = false;
146 }
147
148 // Loading the template
149 $app->uses('tpl');
150 $app->tpl->newTemplate("form.tpl.htm");
7fe908 151 $app->tpl->setInclude('content_tpl', 'templates/software_package_install.htm');
1390c8 152
7fe908 153 $app->tpl->setVar('message_ok', $message_ok);
MC 154 $app->tpl->setVar('message_err', $message_err);
155 $app->tpl->setVar('insert_key', $insert_key);
156 $app->tpl->setVar('install_key', $install_key);
157 $app->tpl->setVar('package_name', $package_name);
158 $app->tpl->setVar('server_id', $install_server_id);
1390c8 159
T 160
7fe908 161 include_once 'lib/lang/en_software_package_install.lng';
1390c8 162 $app->tpl->setVar($wb);
T 163
164
165 $app->tpl_defaults();
166 $app->tpl->pparse();
167
168 ?>