Marius Burkard
2016-07-01 49441bdd0f3ff75d5092d5b832b97ea722a66363
commit | author | age
bbc657 1 <?php
MC 2 /*
3 Copyright (c) 2012, ISPConfig UG
4 Contributors: web wack creations,  http://www.web-wack.at
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
b1a6a5 31 require_once '../../lib/config.inc.php';
MC 32 require_once '../../lib/app.inc.php';
bbc657 33 //require_once('classes/class.guicontroller.php');
MC 34 $app->load('aps_guicontroller');
35
36 // Check the module permissions
37 $app->auth->check_module_permissions('sites');
38
39 // Load needed classes
40 $app->uses('tpl,tform');
41 $app->tpl->newTemplate("form.tpl.htm");
42 $app->tpl->setInclude('content_tpl', 'templates/aps_install_package.htm');
43
44 // Load the language file
45 $lngfile = 'lib/lang/'.$_SESSION['s']['language'].'_aps.lng';
b1a6a5 46 require_once $lngfile;
bbc657 47 $app->tpl->setVar($wb);
MC 48 $app->load_language_file('web/sites/'.$lngfile);
49
50 // we will check only users, not admins
b1a6a5 51 if($_SESSION["s"]["user"]["typ"] == 'user') {
bbc657 52     $app->tform->formDef['db_table_idx'] = 'client_id';
MC 53     $app->tform->formDef['db_table'] = 'client';
54     if(!$app->tform->checkClientLimit('limit_aps')) {
55         $app->error($app->lng("limit_aps_txt"));
56     }
57     if(!$app->tform->checkResellerLimit('limit_aps')) {
58         $app->error('Reseller: '.$wb["limit_aps_txt"]);
b1a6a5 59     }
bbc657 60 }
MC 61
62
63 $adminflag = ($_SESSION['s']['user']['typ'] == 'admin') ? true : false;
64 $gui = new ApsGUIController($app);
2af58c 65 $pkg_id = (isset($_GET['id'])) ? $_GET['id'] : '';
bbc657 66
MC 67 // Check if a newer version is available for the current package
68 // Note: It's intended that here is no strict ID check (see below)
69 if(isset($pkg_id))
70 {
b1a6a5 71     $newest_pkg_id = $gui->getNewestPackageID($pkg_id);
MC 72     if($newest_pkg_id != 0) $pkg_id = $newest_pkg_id;
bbc657 73 }
MC 74
75 // Make sure an integer ID is given
76 if(!isset($pkg_id) || !$gui->isValidPackageID($pkg_id, $adminflag))
b1a6a5 77     $app->error($app->lng('Invalid ID'));
bbc657 78
MC 79 // Get package details
80 $details = $gui->getPackageDetails($pkg_id);
81 if(isset($details['error'])) $app->error($details['error']);
82 $settings = $gui->getPackageSettings($pkg_id);
83 if(isset($settings['error'])) $app->error($settings['error']);
84
85 // Get domain list
86 $domains = array();
87 $domain_for_user = '';
cc7a82 88 if(!$adminflag) $domain_for_user = "AND (sys_userid = ? OR sys_groupid = ?)";
MC 89 $domains_assoc = $app->db->queryAllRecords("SELECT domain FROM web_domain WHERE document_root != '' AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND active = 'y' ".$domain_for_user." ORDER BY domain", $_SESSION['s']['user']['userid'], $_SESSION['s']['user']['default_group']);
bbc657 90 if(!empty($domains_assoc)) foreach($domains_assoc as $domain) $domains[] = $domain['domain'];
MC 91
b1a6a5 92     // If data has been submitted, validate it
MC 93     $result['input'] = array();
bbc657 94 if(count($_POST) > 1)
MC 95 {
b1a6a5 96     $result = $gui->validateInstallerInput($_POST, $details, $domains, $settings);
MC 97     if(empty($result['error']))
98     {
99         $gui->createPackageInstance($result['input'], $pkg_id);
100         @header('Location:aps_installedpackages_list.php');
101     }
102     else
103     {
104         $app->tpl->setVar('error', implode('<br />', $result['error']));
105
106         // Set memorized values (license, db password, install location)
107         if(!empty($result['input']))
108             foreach($result['input'] as $key => $value) $app->tpl->setVar('inp_'.$key, $value);
109     }
bbc657 110 }
MC 111 else $app->tpl->setVar('inp_main_database_password', ucfirst(substr(md5(crypt(rand(0, 10))), 0, 16)));
112
113 // Pass the package details to the template
114 foreach($details as $key => $value)
115 {
b1a6a5 116     if(!is_array($value)) $app->tpl->setVar('pkg_'.str_replace(' ', '_', strtolower($key)), $value);
MC 117     else if($key == 'Requirements PHP settings') $app->tpl->setLoop('pkg_requirements_php_settings', $details['Requirements PHP settings']);
bbc657 118 }
MC 119
b1a6a5 120 // Parse the template as far as possible, then do the rest manually
bbc657 121 $app->tpl_defaults();
MC 122 $parsed_tpl = $app->tpl->grab();
123
124
125 // ISPConfig has a very old and functionally limited template engine. We have to style parts on our own...
126
127 // Print the domain list
128 $domains_tpl = '';
129 if(!empty($domains))
130 {
b1a6a5 131     $set = array();
7f16fe 132     $set[] = '<select name="main_domain" id="main_domain" class="form-control" style="width:100%; height:100%; min-width:170px;">';
b1a6a5 133     foreach($domains as $domain)
MC 134     {
135         $selected = '';
136         if((count($_POST) > 1)
137             && (isset($result['input']['main_domain']))
138             && ($result['input']['main_domain'] == $domain))
139             $selected = ' selected ';
140         $set[] = '<option value="'.$domain.'" '.$selected.'>'.$domain.'</option>';
141     }
142     $set[] = '</select>';
143
144     $domains_tpl = implode("\n", $set);
bbc657 145 }
MC 146 $parsed_tpl = str_replace('DOMAIN_LIST_SPACE', $domains_tpl, $parsed_tpl);
147
148 // Print the packgae settings
149 $settings_tpl = '';
150 if(!empty($settings))
151 {
b1a6a5 152     $set = array();
MC 153     $set[] = '<legend>'.$app->lng('package_settings_txt').'</legend>';
154     foreach($settings as $setting)
155     {
2f311b 156         $set[] = '<div class="form-group">';
TB 157         $set[] = '<label for="'.$setting['SettingID'].'" class="col-sm-3 control-label">'.$setting['SettingName'].'</label>';
b1a6a5 158         if($setting['SettingInputType'] == 'string' || $setting['SettingInputType'] == 'password')
MC 159         {
160             $input_type = ($setting['SettingInputType'] == 'string') ? 'text' : 'password';
161
162             $input_value = '';
163             if((count($_POST) > 1)
164                 && (isset($result['input'][$setting['SettingID']])))
165                 $input_value = $result['input'][$setting['SettingID']];
166             else $input_value = @$setting['SettingDefaultValue'];
167
2f311b 168             $set[] = '<div class="col-sm-9"><input type="'.$input_type.'" class="form-control" name="'.$setting['SettingID'].'" maxlength="'.$setting['SettingMaxLength'].'" id="'.$setting['SettingID'].'" value="'.$input_value.'" />
TB 169                 <p class="formHint">'.$setting['SettingDescription'].'</p></div>';
b1a6a5 170         }
MC 171         else if($setting['SettingInputType'] == 'checkbox')
172             {
173                 $checked = '';
174                 if((count($_POST) > 1)
175                     && (isset($result['input'][$setting['SettingID']])
176                         && ($result['input'][$setting['SettingID']] == 'true')))
177                     $checked = 'checked ';
178                 else if($setting['SettingDefaultValue'] == '1') $checked = 'checked ';
179
2f311b 180                     $set[] = '<div class="col-sm-9"><input type="checkbox" id="'.$setting['SettingID'].'" name="'.$setting['SettingID'].'" '.$checked.'/>
TB 181                 <p class="formHint">'.$setting['SettingDescription'].'</p></div>';
b1a6a5 182             }
MC 183         else if($setting['SettingInputType'] == 'select')
184             {
2f311b 185                 $set[] =  '<div class="col-sm-9"><select size="1" class="form-control" name="'.$setting['SettingID'].'">';
b1a6a5 186                 foreach($setting['SettingChoices'] as $choice)
MC 187                 {
188                     $selected = '';
189                     if((count($_POST) > 1)
190                         && (isset($result['input'][$setting['SettingID']])))
191                     {
192                         if($result['input'][$setting['SettingID']] == $choice['EnumID'])
193                             $selected = 'selected ';
194                     }
195                     else if($setting['SettingDefaultValue'] == $choice['EnumID']) $selected = 'selected ';
196
197                         $set[] = '<option value="'.$choice['EnumID'].'" '.$selected.'>'.$choice['EnumName'].'</option>';
198                 }
199                 $set[] = '</select>
2f311b 200                 <p class="formHint">'.$setting['SettingDescription'].'</p></div>';
b1a6a5 201             }
MC 202
203         $set[] = '</div>';
204     }
205     $settings_tpl = implode("\n", $set);
bbc657 206 }
MC 207 $parsed_tpl = str_replace('PKG_SETTINGS_SPACE', $settings_tpl, $parsed_tpl);
208
209 echo $parsed_tpl;
b1a6a5 210 ?>