Marius Burkard
2016-05-04 c3189ce6c7301c3ec17878fd3918f31d0d3cb18a
commit | author | age
eb0645 1 <?php
T 2 /*
a892b8 3 Copyright (c) 2008-2010, Till Brehm, projektfarm Gmbh
eb0645 4 All rights reserved.
T 5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/system_config.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
7fe908 41 require_once '../../lib/config.inc.php';
MC 42 require_once '../../lib/app.inc.php';
eb0645 43
T 44 //* Check permissions for module
45 $app->auth->check_module_permissions('admin');
9edea9 46 $app->auth->check_security_permissions('admin_allow_system_config');
eb0645 47
T 48 // Loading classes
49 $app->uses('tpl,tform,tform_actions');
50 $app->load('tform_actions');
51
52 class page_action extends tform_actions {
6dfc1f 53
10b4c8 54     //var $_js_changed = false;
6dfc1f 55
eb0645 56     function onShowEdit() {
T 57         global $app, $conf;
7fe908 58
eb0645 59         if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin priveliges');
7fe908 60
eb0645 61         if($app->tform->errorMessage == '') {
T 62             $app->uses('ini_parser,getconf');
7fe908 63
eb0645 64             $section = $this->active_tab;
T 65             $server_id = $this->id;
7fe908 66
eb0645 67             $this->dataRecord = $app->getconf->get_global_config($section);
41d7d1 68             if (is_null($this->dataRecord)) {
SC 69                 $this->dataRecord = array();
70             }
6dfc1f 71             if ($section == 'domains'){
V 72                 if (isset($this->dataRecord['use_domain_module'])){
73                     $_SESSION['use_domain_module_old_value'] = $this->dataRecord['use_domain_module'];
74                 }
75             }
eb0645 76         }
7fe908 77
MC 78         $record = $app->tform->getHTML($this->dataRecord, $this->active_tab, 'EDIT');
79
eb0645 80         $record['warning'] = $app->tform->lng('warning');
T 81         $record['id'] = $this->id;
82         $app->tpl->setVar($record);
83     }
7fe908 84
7b47c0 85     function onShowEnd() {
T 86         global $app, $conf;
7fe908 87
7b47c0 88         // available dashlets
T 89         $available_dashlets_txt = '';
7fe908 90         $handle = @opendir(ISPC_WEB_PATH.'/dashboard/dashlets');
MC 91         while ($file = @readdir($handle)) {
a563d5 92             if ($file != '.' && $file != '..' && !is_dir(ISPC_WEB_PATH.'/dashboard/dashlets/'.$file)) {
7fe908 93                 $available_dashlets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.substr($file, 0, -4).']<pre class="addPlaceholderContent" style="display:none;">['.substr($file, 0, -4).'],</pre></a> ';
7b47c0 94             }
T 95         }
7fe908 96
7b47c0 97         if($available_dashlets_txt == '') $available_dashlets_txt = '------';
7fe908 98         $app->tpl->setVar("available_dashlets_txt", $available_dashlets_txt);
61f1f5 99         
MC 100         // Logo
101         $sys_ini = $app->db->queryOneRecord("SELECT * FROM sys_ini WHERE sysini_id = ?", $this->id);
102         if($sys_ini['custom_logo'] != ''){
103             $logo = '<img src="'.$sys_ini['custom_logo'].'" />&nbsp;&nbsp;<a href="#" class="btn btn-default formbutton-danger formbutton-narrow" style="margin:5px" id="del_custom_logo"><span class="icon icon-delete"></span></a>';
104         } else {
105             $logo = '<img src="'.$sys_ini['default_logo'].'" />';
106         }
107         $default_logo = '<img src="'.$sys_ini['default_logo'].'" />';
108         $app->tpl->setVar("used_logo", $logo);
109         $app->tpl->setVar("default_logo", $default_logo);
7fe908 110
7b47c0 111         parent::onShowEnd();
T 112     }
7fe908 113
MC 114     function onSubmit() {
115         global $app;
116
117         $app->uses('ini_parser,getconf');
118
119         $section = $app->tform->getCurrentTab();
120
7b17e4 121         $server_config_array = $app->getconf->get_global_config();
7fe908 122         $new_config = $app->tform->encode($this->dataRecord, $section);
MC 123         if($section == 'mail') {
124             if($new_config['smtp_pass'] == '') $new_config['smtp_pass'] = $server_config_array['smtp_pass'];
125             if($new_config['smtp_enabled'] == 'y' && ($new_config['admin_mail'] == '' || $new_config['admin_name'] == '')) {
126                 $app->tform->errorMessage .= $app->tform->lng("smtp_missing_admin_mail_txt");
127             }
128         }
129
130         parent::onSubmit();
131     }
132
eb0645 133     function onUpdateSave($sql) {
7fe908 134         global $app, $conf;
MC 135
eb0645 136         if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin priveliges');
T 137         $app->uses('ini_parser,getconf');
7fe908 138
eb0645 139         $section = $app->tform->getCurrentTab();
7fe908 140
d8b8b0 141         $server_config_array = $app->getconf->get_global_config();
7fe908 142
10b4c8 143         foreach($app->tform->formDef['tabs'][$section]['fields'] as $key => $field) {
T 144             if ($field['formtype'] == 'CHECKBOX') {
145                 if($this->dataRecord[$key] == '') {
146                     // if a checkbox is not set, we set it to the unchecked value
147                     $this->dataRecord[$key] = $field['value'][0];
148                 }
149             }
150         }
7fe908 151
10b4c8 152         /*
T 153         if((isset($this->dataRecord['use_loadindicator']) && $this->dataRecord['use_loadindicator'] != $server_config_array[$section]['use_loadindicator']) || (isset($this->dataRecord['use_combobox']) && $this->dataRecord['use_combobox'] != $server_config_array[$section]['use_combobox'])){
154             $this->_js_changed = true;
155         }
156         */
157
7fe908 158         $new_config = $app->tform->encode($this->dataRecord, $section);
c951bb 159         if($section == 'sites' && $new_config['vhost_subdomains'] != 'y' && $server_config_array['sites']['vhost_subdomains'] == 'y') {
7fe908 160             // check for existing vhost subdomains, if found the mode cannot be disabled
MC 161             $check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_domain` WHERE `type` = 'vhostsubdomain'");
162             if($check['cnt'] > 0) {
163                 $new_config['vhost_subdomains'] = 'y';
164             }
511ba5 165         } elseif($section == 'sites' && $new_config['vhost_aliasdomains'] != 'y' && $server_config_array['vhost_aliasdomains'] == 'y') {
DM 166             // check for existing vhost aliasdomains, if found the mode cannot be disabled
167             $check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_domain` WHERE `type` = 'vhostalias'");
168             if($check['cnt'] > 0) {
169                 $new_config['vhost_aliasdomains'] = 'y';
170             }
7fe908 171         } elseif($section == 'mail') {
c951bb 172             if($new_config['smtp_pass'] == '') $new_config['smtp_pass'] = $server_config_array['mail']['smtp_pass'];
MC 173         } elseif($section == 'misc' && $new_config['session_timeout'] != $server_config_array['misc']['session_timeout']) {
e20f18 174             $app->conf('interface', 'session_timeout', intval($new_config['session_timeout']));
7fe908 175         }
MC 176         $server_config_array[$section] = $new_config;
eb0645 177         $server_config_str = $app->ini_parser->get_ini_string($server_config_array);
7fe908 178
2af58c 179         if($conf['demo_mode'] != true) $app->db->datalogUpdate('sys_ini', array("config" => $server_config_str), 'sysini_id', 1);
6dfc1f 180
V 181         /*
182          * If we should use the domain-module, we have to insert all existing domains into the table
183          * (only the first time!)
184          */
7fe908 185         if (($section == 'domains') &&
MC 186             ($_SESSION['use_domain_module_old_value'] == '') &&
187             ($server_config_array['domains']['use_domain_module'] == 'y')){
6dfc1f 188             $sql = "REPLACE INTO domain (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain ) " .
V 189                 "SELECT sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain " .
190                 "FROM mail_domain";
191             $app->db->query($sql);
192             $sql = "REPLACE INTO domain (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain ) " .
193                 "SELECT sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain " .
4e18bd 194                 "FROM web_domain WHERE type NOT IN ('subdomain','vhostsubdomain')";
6dfc1f 195             $app->db->query($sql);
V 196         }
61f1f5 197         
MC 198         //die(print_r($_FILES));
199         // Logo
200         /*
201         if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'])){
202             //print_r($_FILES);
203             
204             $path= $_FILES['file']['tmp_name'];
205             $type = pathinfo($path, PATHINFO_EXTENSION);
206             $data = file_get_contents($path);
207             $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
208             $app->db->query("UPDATE sys_ini SET custom_logo = ? WHERE sysini_id = ?", $base64, $this->id);
fe39f6 209         }*/
7fe908 210
bf7d95 211         // Maintenance mode
F 212         if($server_config_array['misc']['maintenance_mode'] == 'y'){
213             //print_r($_SESSION);
214             //echo $_SESSION['s']['id'];
cc7a82 215             $app->db->query("DELETE FROM sys_session WHERE session_id != ?", $_SESSION['s']['id']);
bf7d95 216         }
eb0645 217     }
T 218 }
219
220 $app->tform_actions = new page_action;
221 $app->tform_actions->onLoad();
222
223
7fe908 224 ?>