tbrehm
2013-02-22 526b997c9891a796b152cdbab8e329b356b1f596
commit | author | age
477d4e 1 <?php
T 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
31 require_once('../../lib/config.inc.php');
32 require_once('../../lib/app.inc.php');
33 //require_once('classes/class.guicontroller.php');
34 $app->load('aps_guicontroller');
35
36 // Check the module permissions
37 $app->auth->check_module_permissions('sites');
38
39 // Load needed classes
526b99 40 $app->uses('tpl,tform');
477d4e 41 $app->tpl->newTemplate("form.tpl.htm");
T 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';
46 require_once($lngfile);
47 $app->tpl->setVar($wb);
48 $app->load_language_file('web/sites/'.$lngfile);
526b99 49
T 50 // we will check only users, not admins
51 if($_SESSION["s"]["user"]["typ"] == 'user') {        
52     $app->tform->formDef['db_table_idx'] = 'client_id';
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"]);
59     }        
60 }
61
477d4e 62
T 63 $adminflag = ($_SESSION['s']['user']['typ'] == 'admin') ? true : false;
64 $gui = new ApsGUIController($app);
65 $pkg_id = (isset($_GET['id'])) ? $app->db->quote($_GET['id']) : '';
66
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 {
71     $newest_pkg_id = $gui->getNewestPackageID($pkg_id);
72     if($newest_pkg_id != 0) $pkg_id = $newest_pkg_id;
73 }
74
75 // Make sure an integer ID is given
76 if(!isset($pkg_id) || !$gui->isValidPackageID($pkg_id, $adminflag))
77     $app->error($app->lng('Invalid ID'));
78
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 = '';
88 if(!$adminflag) $domain_for_user = "AND (sys_userid = '".$app->db->quote($_SESSION['s']['user']['userid'])."' 
89     OR sys_groupid = '".$app->db->quote($_SESSION['s']['user']['userid'])."' )";
526b99 90 $domains_assoc = $app->db->queryAllRecords("SELECT domain FROM web_domain WHERE document_root != '' AND (type = 'vhost' OR type = 'vhostsubdomain') AND active = 'y' ".$domain_for_user." ORDER BY domain;");
477d4e 91 if(!empty($domains_assoc)) foreach($domains_assoc as $domain) $domains[] = $domain['domain'];
T 92
93 // If data has been submitted, validate it
94 $result['input'] = array();
95 if(count($_POST) > 1)
96 {
97     $result = $gui->validateInstallerInput($_POST, $details, $domains, $settings);
98     if(empty($result['error']))
99     {
100         $gui->createPackageInstance($result['input'], $pkg_id);
101         @header('Location:aps_installedpackages_list.php');
102     }
103     else
104     {
105         $app->tpl->setVar('error', implode('<br />', $result['error']));
106         
107         // Set memorized values (license, db password, install location)
108         if(!empty($result['input']))
109             foreach($result['input'] as $key => $value) $app->tpl->setVar('inp_'.$key, $value);
110     }
111 }
112 else $app->tpl->setVar('inp_main_database_password', ucfirst(substr(md5(crypt(rand(0, 10))), 0, 16)));
113
114 // Pass the package details to the template
115 foreach($details as $key => $value)
116 {
117     if(!is_array($value)) $app->tpl->setVar('pkg_'.str_replace(' ', '_', strtolower($key)), $value);
118     else if($key == 'Requirements PHP settings') $app->tpl->setLoop('pkg_requirements_php_settings', $details['Requirements PHP settings']);
119 }
120
121 // Parse the template as far as possible, then do the rest manually 
122 $app->tpl_defaults();
123 $parsed_tpl = $app->tpl->grab();
124
125
126 // ISPConfig has a very old and functionally limited template engine. We have to style parts on our own...
127
128 // Print the domain list
129 $domains_tpl = '';
130 if(!empty($domains))
131 {
132     $set = array();
133     $set[] = '<select name="main_domain" id="main_domain" class="selectInput">';
134     foreach($domains as $domain)
135     {
136         $selected = '';
137         if((count($_POST) > 1)
138         && (isset($result['input']['main_domain']))
139         && ($result['input']['main_domain'] == $domain))
140             $selected = ' selected ';
141         $set[] = '<option value="'.$domain.'" '.$selected.'>'.$domain.'</option>';
142     }
143     $set[] = '</select>';
144     
145     $domains_tpl = implode("\n", $set);
146 }
147 $parsed_tpl = str_replace('DOMAIN_LIST_SPACE', $domains_tpl, $parsed_tpl);
148
149 // Print the packgae settings
150 $settings_tpl = '';
151 if(!empty($settings))
152 {
153     $set = array();
154     $set[] = '<legend>'.$app->lng('package_settings_txt').'</legend>';
155     foreach($settings as $setting)
156     {
157         $set[] = '<div class="ctrlHolder">';
158         $set[] = '<label for="'.$setting['SettingID'].'">'.$setting['SettingName'].'</label>';
159         if($setting['SettingInputType'] == 'string' || $setting['SettingInputType'] == 'password')
160         {
161             $input_type = ($setting['SettingInputType'] == 'string') ? 'text' : 'password';
162               
163             $input_value = '';
164             if((count($_POST) > 1) 
165             && (isset($result['input'][$setting['SettingID']]))) 
166                 $input_value = $result['input'][$setting['SettingID']];
167             else $input_value = @$setting['SettingDefaultValue'];
168             
169             $set[] = '<input type="'.$input_type.'" class="textInput" name="'.$setting['SettingID'].'" maxlength="'.$setting['SettingMaxLength'].'" id="'.$setting['SettingID'].'" value="'.$input_value.'" />
170                 <p class="formHint">'.$setting['SettingDescription'].'</p>';
171         }
172         else if($setting['SettingInputType'] == 'checkbox')
173         {
174             $checked = '';
175             if((count($_POST) > 1) 
176             && (isset($result['input'][$setting['SettingID']]) 
177             && ($result['input'][$setting['SettingID']] == 'true'))) 
178                 $checked = 'checked ';
179             else if($setting['SettingDefaultValue'] == '1') $checked = 'checked ';
180             
181             $set[] = '<input type="checkbox" id="'.$setting['SettingID'].'" name="'.$setting['SettingID'].'" '.$checked.'/>
182                 <p class="formHint">'.$setting['SettingDescription'].'</p>';
183         }
184         else if($setting['SettingInputType'] == 'select')
185         {
186             $set[] =  '<select size="1" class="selectInput" name="'.$setting['SettingID'].'">';
187             foreach($setting['SettingChoices'] as $choice)
188             {
189                 $selected = '';
190                 if((count($_POST) > 1)
191                 && (isset($result['input'][$setting['SettingID']])))
192                 { 
193                     if($result['input'][$setting['SettingID']] == $choice['EnumID'])
194                         $selected = 'selected ';
195                 }
196                 else if($setting['SettingDefaultValue'] == $choice['EnumID']) $selected = 'selected ';
197                 
198                 $set[] = '<option value="'.$choice['EnumID'].'" '.$selected.'>'.$choice['EnumName'].'</option>';
199             }
200             $set[] = '</select>
201                 <p class="formHint">'.$setting['SettingDescription'].'</p>';
202         }
203         
204         $set[] = '</div>';
205     }
206     $settings_tpl = implode("\n", $set);
207 }
208 $parsed_tpl = str_replace('PKG_SETTINGS_SPACE', $settings_tpl, $parsed_tpl);
209
210 echo $parsed_tpl;
211 ?>