Till Brehm
2014-08-14 9edea9976bd605071e0694a90d704266c0b7e0f9
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);
6dfc1f 68             if ($section == 'domains'){
V 69                 if (isset($this->dataRecord['use_domain_module'])){
70                     $_SESSION['use_domain_module_old_value'] = $this->dataRecord['use_domain_module'];
71                 }
72             }
eb0645 73         }
7fe908 74
MC 75         $record = $app->tform->getHTML($this->dataRecord, $this->active_tab, 'EDIT');
76
eb0645 77         $record['warning'] = $app->tform->lng('warning');
T 78         $record['id'] = $this->id;
79         $app->tpl->setVar($record);
80     }
7fe908 81
7b47c0 82     function onShowEnd() {
T 83         global $app, $conf;
7fe908 84
7b47c0 85         // available dashlets
T 86         $available_dashlets_txt = '';
7fe908 87         $handle = @opendir(ISPC_WEB_PATH.'/dashboard/dashlets');
MC 88         while ($file = @readdir($handle)) {
7b47c0 89             if ($file != '.' && $file != '..' && !is_dir($file)) {
7fe908 90                 $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 91             }
T 92         }
7fe908 93
7b47c0 94         if($available_dashlets_txt == '') $available_dashlets_txt = '------';
7fe908 95         $app->tpl->setVar("available_dashlets_txt", $available_dashlets_txt);
MC 96
7b47c0 97         parent::onShowEnd();
T 98     }
7fe908 99
MC 100     function onSubmit() {
101         global $app;
102
103         $app->uses('ini_parser,getconf');
104
105         $section = $app->tform->getCurrentTab();
106
7b17e4 107         $server_config_array = $app->getconf->get_global_config();
7fe908 108         $new_config = $app->tform->encode($this->dataRecord, $section);
MC 109         if($section == 'mail') {
110             if($new_config['smtp_pass'] == '') $new_config['smtp_pass'] = $server_config_array['smtp_pass'];
111             if($new_config['smtp_enabled'] == 'y' && ($new_config['admin_mail'] == '' || $new_config['admin_name'] == '')) {
112                 $app->tform->errorMessage .= $app->tform->lng("smtp_missing_admin_mail_txt");
113             }
114         }
115
116         parent::onSubmit();
117     }
118
eb0645 119     function onUpdateSave($sql) {
7fe908 120         global $app, $conf;
MC 121
eb0645 122         if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin priveliges');
T 123         $app->uses('ini_parser,getconf');
7fe908 124
eb0645 125         $section = $app->tform->getCurrentTab();
7fe908 126
d8b8b0 127         $server_config_array = $app->getconf->get_global_config();
7fe908 128
10b4c8 129         foreach($app->tform->formDef['tabs'][$section]['fields'] as $key => $field) {
T 130             if ($field['formtype'] == 'CHECKBOX') {
131                 if($this->dataRecord[$key] == '') {
132                     // if a checkbox is not set, we set it to the unchecked value
133                     $this->dataRecord[$key] = $field['value'][0];
134                 }
135             }
136         }
7fe908 137
10b4c8 138         /*
T 139         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'])){
140             $this->_js_changed = true;
141         }
142         */
143
7fe908 144         $new_config = $app->tform->encode($this->dataRecord, $section);
c951bb 145         if($section == 'sites' && $new_config['vhost_subdomains'] != 'y' && $server_config_array['sites']['vhost_subdomains'] == 'y') {
7fe908 146             // check for existing vhost subdomains, if found the mode cannot be disabled
MC 147             $check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_domain` WHERE `type` = 'vhostsubdomain'");
148             if($check['cnt'] > 0) {
149                 $new_config['vhost_subdomains'] = 'y';
150             }
151         } elseif($section == 'mail') {
c951bb 152             if($new_config['smtp_pass'] == '') $new_config['smtp_pass'] = $server_config_array['mail']['smtp_pass'];
MC 153         } elseif($section == 'misc' && $new_config['session_timeout'] != $server_config_array['misc']['session_timeout']) {
e20f18 154             $app->conf('interface', 'session_timeout', intval($new_config['session_timeout']));
7fe908 155         }
MC 156         $server_config_array[$section] = $new_config;
eb0645 157         $server_config_str = $app->ini_parser->get_ini_string($server_config_array);
7fe908 158
7b47c0 159         //$sql = "UPDATE sys_ini SET config = '".$app->db->quote($server_config_str)."' WHERE sysini_id = 1";
T 160         //if($conf['demo_mode'] != true) $app->db->query($sql);
161         if($conf['demo_mode'] != true) $app->db->datalogUpdate('sys_ini', "config = '".$app->db->quote($server_config_str)."'", 'sysini_id', 1);
6dfc1f 162
V 163         /*
164          * If we should use the domain-module, we have to insert all existing domains into the table
165          * (only the first time!)
166          */
7fe908 167         if (($section == 'domains') &&
MC 168             ($_SESSION['use_domain_module_old_value'] == '') &&
169             ($server_config_array['domains']['use_domain_module'] == 'y')){
6dfc1f 170             $sql = "REPLACE INTO domain (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain ) " .
V 171                 "SELECT sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain " .
172                 "FROM mail_domain";
173             $app->db->query($sql);
174             $sql = "REPLACE INTO domain (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain ) " .
175                 "SELECT sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, domain " .
4e18bd 176                 "FROM web_domain WHERE type NOT IN ('subdomain','vhostsubdomain')";
6dfc1f 177             $app->db->query($sql);
V 178         }
7fe908 179
bf7d95 180         // Maintenance mode
F 181         if($server_config_array['misc']['maintenance_mode'] == 'y'){
182             //print_r($_SESSION);
183             //echo $_SESSION['s']['id'];
604c0c 184             $app->db->query("DELETE FROM sys_session WHERE session_id != '".$app->db->quote($_SESSION['s']['id'])."'");
bf7d95 185         }
eb0645 186     }
7fe908 187
10b4c8 188     /*
T 189     function onAfterUpdate() {
190         if($this->_js_changed == true) {
191             // not the best way, but it works
192             header('Content-Type: text/html');
193             print '<script type="text/javascript">document.location.reload(true);</script>';
194             exit;
195         }
196     }
197     */
7fe908 198
eb0645 199 }
T 200
201 $app->tform_actions = new page_action;
202 $app->tform_actions->onLoad();
203
204
7fe908 205 ?>