Skip to content

Commit eb0645b

Browse files
committed
- Global settings are configurable trough a form under admin > system > Interface Config
- Formatted error messages for better visibility.
1 parent 78f1a64 commit eb0645b

File tree

6 files changed

+570
-295
lines changed

6 files changed

+570
-295
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
/*
4+
Form Definition
5+
6+
Tabledefinition
7+
8+
Datatypes:
9+
- INTEGER (Forces the input to Int)
10+
- DOUBLE
11+
- CURRENCY (Formats the values to currency notation)
12+
- VARCHAR (no format check, maxlength: 255)
13+
- TEXT (no format check)
14+
- DATE (Dateformat, automatic conversion to timestamps)
15+
16+
Formtype:
17+
- TEXT (Textfield)
18+
- TEXTAREA (Textarea)
19+
- PASSWORD (Password textfield, input is not shown when edited)
20+
- SELECT (Select option field)
21+
- RADIO
22+
- CHECKBOX
23+
- CHECKBOXARRAY
24+
- FILE
25+
26+
VALUE:
27+
- Wert oder Array
28+
29+
Hint:
30+
The ID field of the database table is not part of the datafield definition.
31+
The ID field must be always auto incement (int or bigint).
32+
33+
34+
*/
35+
36+
$form["title"] = "System Config";
37+
$form["description"] = "";
38+
$form["name"] = "system_config";
39+
$form["action"] = "system_config_edit.php";
40+
$form["db_table"] = "sys_ini";
41+
$form["db_table_idx"] = "sysini_id";
42+
$form["db_history"] = "yes";
43+
$form["tab_default"] = "sites";
44+
$form["list_default"] = "users_list.php";
45+
$form["auth"] = 'yes'; // yes / no
46+
47+
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
48+
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
49+
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
50+
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
51+
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
52+
53+
$form["tabs"]['sites'] = array (
54+
'title' => "Sites",
55+
'width' => 70,
56+
'template' => "templates/system_config_sites_edit.htm",
57+
'fields' => array (
58+
##################################
59+
# Begin Datatable fields
60+
##################################
61+
'dbname_prefix' => array (
62+
'datatype' => 'VARCHAR',
63+
'formtype' => 'TEXT',
64+
'validators' => array ( 0 => array ( 'type' => 'REGEX',
65+
'regex' => '/^[a-zA-Z0-0\-\_\[\]]{0,50}$/',
66+
'errmsg'=> 'dbname_prefix_error_regex'),
67+
),
68+
'default' => '',
69+
'value' => '',
70+
'width' => '30',
71+
'maxlength' => '255'
72+
),
73+
'dbuser_prefix' => array (
74+
'datatype' => 'VARCHAR',
75+
'formtype' => 'TEXT',
76+
'validators' => array ( 0 => array ( 'type' => 'REGEX',
77+
'regex' => '/^[a-zA-Z0-0\-\_\[\]]{0,50}$/',
78+
'errmsg'=> 'dbuser_prefix_error_regex'),
79+
),
80+
'default' => '',
81+
'value' => '',
82+
'width' => '30',
83+
'maxlength' => '255'
84+
),
85+
'ftpuser_prefix' => array (
86+
'datatype' => 'VARCHAR',
87+
'formtype' => 'TEXT',
88+
'validators' => array ( 0 => array ( 'type' => 'REGEX',
89+
'regex' => '/^[a-zA-Z0-0\-\_\[\]]{0,50}$/',
90+
'errmsg'=> 'ftpuser_prefix_error_regex'),
91+
),
92+
'default' => '',
93+
'value' => '',
94+
'width' => '30',
95+
'maxlength' => '255'
96+
),
97+
'shelluser_prefix' => array (
98+
'datatype' => 'VARCHAR',
99+
'formtype' => 'TEXT',
100+
'validators' => array ( 0 => array ( 'type' => 'REGEX',
101+
'regex' => '/^[a-zA-Z0-0\-\_\[\]]{0,50}$/',
102+
'errmsg'=> 'shelluser_prefix_error_regex'),
103+
),
104+
'default' => '',
105+
'value' => '',
106+
'width' => '30',
107+
'maxlength' => '255'
108+
),
109+
##################################
110+
# ENDE Datatable fields
111+
##################################
112+
)
113+
);
114+
115+
116+
117+
?>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$wb['warning'] = 'Edit these values carefully! Do not remove the prefixes on a systems with more then one client.';
4+
$wb['dbname_prefix_txt'] = 'Database name prefix';
5+
$wb['dbuser_prefix_txt'] = 'Database user prefix';
6+
$wb['shelluser_prefix_txt'] = 'Shell user prefix';
7+
$wb['ftpuser_prefix_txt'] = 'FTP user prefix';
8+
$wb['dbname_prefix_error_regex'] = 'Char not allowed in database name prefix.';
9+
$wb['dbuser_prefix_error_regex'] = 'Char not allowed in database user prefix.';
10+
$wb['ftpuser_prefix_error_regex'] = 'Char not allowed in ftp user prefix.';
11+
$wb['shelluser_prefix_error_regex'] = 'Char not allowed in shell user prefix.';
12+
13+
?>

interface/web/admin/lib/module.conf.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@
6464
'target' => 'content',
6565
'link' => 'admin/server_ip_list.php');
6666

67-
$module['nav'][] = array( 'title' => 'Servers',
67+
68+
$items[] = array( 'title' => 'Interface Config',
69+
'target' => 'content',
70+
'link' => 'admin/system_config_edit.php?id=1');
71+
72+
$module['nav'][] = array( 'title' => 'System',
6873
'open' => 1,
6974
'items' => $items);
7075
// cleanup
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/*
3+
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
4+
All rights reserved.
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+
41+
require_once('../../lib/config.inc.php');
42+
require_once('../../lib/app.inc.php');
43+
44+
//* Check permissions for module
45+
$app->auth->check_module_permissions('admin');
46+
47+
// Loading classes
48+
$app->uses('tpl,tform,tform_actions');
49+
$app->load('tform_actions');
50+
51+
class page_action extends tform_actions {
52+
53+
function onShowEdit() {
54+
global $app, $conf;
55+
56+
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin priveliges');
57+
58+
if($app->tform->errorMessage == '') {
59+
$app->uses('ini_parser,getconf');
60+
61+
$section = $this->active_tab;
62+
$server_id = $this->id;
63+
64+
$this->dataRecord = $app->getconf->get_global_config($section);
65+
}
66+
67+
$record = $app->tform->getHTML($this->dataRecord, $this->active_tab,'EDIT');
68+
69+
$record['warning'] = $app->tform->lng('warning');
70+
$record['id'] = $this->id;
71+
$app->tpl->setVar($record);
72+
}
73+
74+
function onUpdateSave($sql) {
75+
global $app;
76+
77+
if($_SESSION["s"]["user"]["typ"] != 'admin') die('This function needs admin priveliges');
78+
$app->uses('ini_parser,getconf');
79+
80+
$section = $app->tform->getCurrentTab();
81+
$server_id = $this->id;
82+
83+
$server_config_array = $app->getconf->get_global_config($server_id);
84+
$server_config_array[$section] = $app->tform->encode($this->dataRecord,$section);
85+
$server_config_str = $app->ini_parser->get_ini_string($server_config_array);
86+
87+
$sql = "UPDATE sys_ini SET config = '".$app->db->quote($server_config_str)."' WHERE sysini_id = 1";
88+
$app->db->query($sql);
89+
}
90+
91+
}
92+
93+
$app->tform_actions = new page_action;
94+
$app->tform_actions->onLoad();
95+
96+
97+
?>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h2><tmpl_var name="list_head_txt"></h2>
2+
3+
<div class="panel panel_system_config">
4+
5+
<div class="pnl_formsarea">
6+
<fieldset id="wf_area_system_config"><legend>Sites</legend>
7+
<p>{tmpl_var name='warning'}</p>
8+
<span class="wf_oneField">
9+
<label for="dbname_prefix" class="wf_preField">{tmpl_var name='dbname_prefix_txt'}</label>
10+
<input type="text" id="dbname_prefix" name="dbname_prefix" value="{tmpl_var name='dbname_prefix'}" size="30" maxlength="255">
11+
</span>
12+
<span class="wf_oneField">
13+
<label for="dbuser_prefix" class="wf_preField">{tmpl_var name='dbuser_prefix_txt'}</label>
14+
<input type="text" id="dbuser_prefix" name="dbuser_prefix" value="{tmpl_var name='dbuser_prefix'}" size="30" maxlength="255">
15+
</span>
16+
<span class="wf_oneField">
17+
<label for="ftpuser_prefix" class="wf_preField">{tmpl_var name='ftpuser_prefix_txt'}</label>
18+
<input type="text" id="ftpuser_prefix" name="ftpuser_prefix" value="{tmpl_var name='ftpuser_prefix'}" size="30" maxlength="255">
19+
</span>
20+
<span class="wf_oneField">
21+
<label for="shelluser_prefix" class="wf_preField">{tmpl_var name='shelluser_prefix_txt'}</label>
22+
<input type="text" id="shelluser_prefix" name="shelluser_prefix" value="{tmpl_var name='shelluser_prefix'}" size="30" maxlength="255">
23+
</span>
24+
</fieldset>
25+
26+
<input type="hidden" name="id" value="{tmpl_var name='id'}">
27+
28+
<div class="wf_actions buttons">
29+
<button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/system_config_edit.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
30+
<button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/users_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
31+
</div>
32+
</div>
33+
34+
</div>

0 commit comments

Comments
 (0)