Skip to content

Commit 73c2f2d

Browse files
committed
Added forms to create databases to the interface. The server part is not implemented yet.
1 parent 7848cef commit 73c2f2d

File tree

16 files changed

+785
-3
lines changed

16 files changed

+785
-3
lines changed

install/sql/ispconfig3.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ CREATE TABLE `client` (
6262
`default_dnsserver` int(10) unsigned NOT NULL default '1',
6363
`limit_dns_zone` int(11) NOT NULL default '-1',
6464
`limit_dns_record` int(11) NOT NULL default '-1',
65+
`default_dbserver` int(10) unsigned NOT NULL default '1',
66+
`limit_database` int(11) NOT NULL default '-1',
6567
`limit_client` int(11) NOT NULL default '0',
6668
`parent_client_id` int(10) unsigned NOT NULL default '0',
6769
`username` varchar(255) default NULL,
@@ -896,6 +898,35 @@ CREATE TABLE `web_domain` (
896898
-- Daten für Tabelle `web_domain`
897899
--
898900

901+
-- --------------------------------------------------------
902+
903+
--
904+
-- Tabellenstruktur für Tabelle `web_database`
905+
--
906+
907+
CREATE TABLE `web_database` (
908+
`database_id` bigint(20) NOT NULL auto_increment,
909+
`sys_userid` int(11) NOT NULL default '0',
910+
`sys_groupid` int(11) NOT NULL default '0',
911+
`sys_perm_user` varchar(5) default NULL,
912+
`sys_perm_group` varchar(5) default NULL,
913+
`sys_perm_other` varchar(5) default NULL,
914+
`server_id` int(11) NOT NULL default '0',
915+
`type` varchar(255) NOT NULL default 'y',
916+
`database_name` varchar(255) default NULL,
917+
`database_user` varchar(255) default NULL,
918+
`database_password` varchar(255) default NULL,
919+
`remote_access` varchar(255) NOT NULL default 'y',
920+
`active` varchar(255) NOT NULL default 'y',
921+
PRIMARY KEY (`database_id`)
922+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
923+
924+
--
925+
-- Daten für Tabelle `web_database`
926+
--
927+
928+
-- --------------------------------------------------------
929+
899930
--
900931
-- Table for attempts login
901932
--

interface/lib/classes/listform_tpl_generator.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function buildHTML($listDef,$module = '') {
111111
$lang["page_back_txt"] = 'Back';
112112
$lang["delete_txt"] = 'Delete';
113113
$lang["filter_txt"] = 'Filter';
114+
$lang["add_new_record_txt"] = 'Add new record';
114115

115116
// speichere language Datei
116117
$this->lng_add($lang,$listDef,$module);

interface/web/client/form/client.tform.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,31 @@
594594
'rows' => '',
595595
'cols' => ''
596596
),
597+
'default_dbserver' => array (
598+
'datatype' => 'INTEGER',
599+
'formtype' => 'SELECT',
600+
'default' => '1',
601+
'datasource' => array ( 'type' => 'SQL',
602+
'querystring' => 'SELECT server_id,server_name FROM server WHERE db_server = 1 AND {AUTHSQL} ORDER BY server_name',
603+
'keyfield'=> 'server_id',
604+
'valuefield'=> 'server_name'
605+
),
606+
'value' => ''
607+
),
608+
'limit_database' => array (
609+
'datatype' => 'INTEGER',
610+
'formtype' => 'TEXT',
611+
'validators' => array ( 0 => array ( 'type' => 'ISINT',
612+
'errmsg'=> 'limit_database_error_notint'),
613+
),
614+
'default' => '-1',
615+
'value' => '',
616+
'separator' => '',
617+
'width' => '10',
618+
'maxlength' => '10',
619+
'rows' => '',
620+
'cols' => ''
621+
),
597622
##################################
598623
# END Datatable fields
599624
##################################

interface/web/client/lib/lang/en_client.lng

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ $wb["limit_shell_user_error_notint"] = 'The shell user limit must be a number.';
7777
$wb["limit_dns_zone_error_notint"] = 'The dns zone limit must be a number.';
7878
$wb["limit_dns_zone_error_notint"] = 'The dns record limit must be a number.';
7979
$wb["limit_client_error_notint"] = 'The sub client limit must be a number.';
80-
80+
$wb["default_dbserver_txt"] = 'Default Database Server';
81+
$wb["limit_database_txt"] = 'Max. number of Databases';
82+
$wb["limit_database_error_notint"] = 'The database limit must be a number.';
8183
?>

interface/web/client/templates/client_edit_limits.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@
113113
<td class="frmText11" width="280">{tmpl_var name='limit_dns_record_txt'}:</td>
114114
<td class="frmText11" width="220"><input name="limit_dns_record" type="text" class="text" value="{tmpl_var name='limit_dns_record'}" size="10" maxlength="10"></td>
115115
</tr>
116+
<tr>
117+
<td><h2>Database</h2></td>
118+
</tr>
119+
<tr>
120+
<td class="frmText11">{tmpl_var name='default_dbserver_txt'}:</td>
121+
<td class="frmText11">
122+
<select name="default_dbserver" class="text">
123+
{tmpl_var name='default_dbserver'}
124+
</select>
125+
</td>
126+
</tr>
127+
<tr>
128+
<td class="frmText11" width="280">{tmpl_var name='limit_database_txt'}:</td>
129+
<td class="frmText11" width="220"><input name="limit_database" type="text" class="text" value="{tmpl_var name='limit_database'}" size="10" maxlength="10"></td>
130+
</tr>
116131
<tmpl_if name='is_reseller' op='!=' value='1'>
117132
<tr>
118133
<td><h2>Clients</h2></td>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
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+
/******************************************
32+
* Begin Form configuration
33+
******************************************/
34+
35+
$list_def_file = "list/database.list.php";
36+
$tform_def_file = "form/database.tform.php";
37+
38+
/******************************************
39+
* End Form configuration
40+
******************************************/
41+
42+
require_once('../../lib/config.inc.php');
43+
require_once('../../lib/app.inc.php');
44+
45+
//* Check permissions for module
46+
$app->auth->check_module_permissions('sites');
47+
48+
$app->uses("tform_actions");
49+
$app->tform_actions->onDelete();
50+
51+
?>
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
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/database.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('sites');
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 onShowNew() {
54+
global $app, $conf;
55+
56+
// we will check only users, not admins
57+
if($_SESSION["s"]["user"]["typ"] == 'user') {
58+
59+
// Get the limits of the client
60+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61+
$client = $app->db->queryOneRecord("SELECT limit_database FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62+
63+
// Check if the user may add another database.
64+
if($client["limit_database"] >= 0) {
65+
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
66+
if($tmp["number"] >= $client["limit_database"]) {
67+
$app->error($app->tform->wordbook["limit_database_txt"]);
68+
}
69+
}
70+
}
71+
72+
parent::onShowNew();
73+
}
74+
75+
function onShowEnd() {
76+
global $app, $conf;
77+
78+
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
79+
80+
// Get the limits of the client
81+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
82+
$client = $app->db->queryOneRecord("SELECT default_dbserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
83+
84+
// Set the webserver to the default server of the client
85+
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_dbserver]");
86+
$app->tpl->setVar("server_id","<option value='$client[default_dbserver]'>$tmp[server_name]</option>");
87+
unset($tmp);
88+
89+
} elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
90+
91+
// Get the limits of the client
92+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
93+
$client = $app->db->queryOneRecord("SELECT client_id, default_dbserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
94+
95+
// Set the webserver to the default server of the client
96+
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_dbserver]");
97+
$app->tpl->setVar("server_id","<option value='$client[default_dbserver]'>$tmp[server_name]</option>");
98+
unset($tmp);
99+
100+
// Fill the client select field
101+
$sql = "SELECT groupid, name FROM sys_group, client WHERE sys_group.client_id = client.parent_client_id AND client.parent_client_id = ".$client['client_id'];
102+
$clients = $app->db->queryAllRecords($sql);
103+
$client_select = '';
104+
if(is_array($clients)) {
105+
foreach( $clients as $client) {
106+
$selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
107+
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
108+
}
109+
}
110+
$app->tpl->setVar("client_group_id",$client_select);
111+
112+
} else {
113+
114+
// The user is admin
115+
if($this->id > 0) {
116+
$server_id = $this->dataRecord["server_id"];
117+
} else {
118+
// Get the first server ID
119+
$tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
120+
$server_id = $tmp['server_id'];
121+
}
122+
123+
$sql = "SELECT ip_address FROM server_ip WHERE server_id = $server_id";
124+
$ips = $app->db->queryAllRecords($sql);
125+
$ip_select = "<option value='*'>*</option>";
126+
//$ip_select = "";
127+
if(is_array($ips)) {
128+
foreach( $ips as $ip) {
129+
$selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
130+
$ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
131+
}
132+
}
133+
$app->tpl->setVar("ip_address",$ip_select);
134+
unset($tmp);
135+
unset($ips);
136+
137+
// Fill the client select field
138+
$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0";
139+
$clients = $app->db->queryAllRecords($sql);
140+
$client_select = "<option value='0'></option>";
141+
if(is_array($clients)) {
142+
foreach( $clients as $client) {
143+
$selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
144+
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
145+
}
146+
}
147+
$app->tpl->setVar("client_group_id",$client_select);
148+
149+
}
150+
151+
parent::onShowEnd();
152+
}
153+
154+
function onSubmit() {
155+
global $app, $conf;
156+
157+
if($_SESSION["s"]["user"]["typ"] != 'admin') {
158+
// Get the limits of the client
159+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
160+
$client = $app->db->queryOneRecord("SELECT default_dbserver, limit_database FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
161+
162+
// When the record is updated
163+
if($this->id > 0) {
164+
// restore the server ID if the user is not admin and record is edited
165+
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ".intval($this->id));
166+
$this->dataRecord["server_id"] = $tmp["server_id"];
167+
unset($tmp);
168+
// When the record is inserted
169+
} else {
170+
// set the server ID to the default dbserver of the client
171+
$this->dataRecord["server_id"] = $client["default_dbserver"];
172+
173+
174+
// Check if the user may add another database
175+
if($client["limit_web_domain"] >= 0) {
176+
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
177+
if($tmp["number"] >= $client["limit_database"]) {
178+
$app->error($app->tform->wordbook["limit_database_txt"]);
179+
}
180+
}
181+
182+
}
183+
184+
// Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller
185+
if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
186+
}
187+
188+
189+
parent::onSubmit();
190+
}
191+
192+
function onAfterInsert() {
193+
global $app, $conf;
194+
195+
// make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
196+
// also make sure that the user can not delete domain created by a admin
197+
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
198+
$client_group_id = intval($this->dataRecord["client_group_id"]);
199+
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE database_id = ".$this->id);
200+
}
201+
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
202+
$client_group_id = intval($this->dataRecord["client_group_id"]);
203+
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE database_id = ".$this->id);
204+
}
205+
}
206+
207+
function onAfterUpdate() {
208+
global $app, $conf;
209+
210+
// make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
211+
// also make sure that the user can not delete domain created by a admin
212+
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
213+
$client_group_id = intval($this->dataRecord["client_group_id"]);
214+
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE database_id = ".$this->id);
215+
}
216+
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
217+
$client_group_id = intval($this->dataRecord["client_group_id"]);
218+
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE database_id = ".$this->id);
219+
}
220+
221+
}
222+
223+
}
224+
225+
$page = new page_action;
226+
$page->onLoad();
227+
228+
?>

0 commit comments

Comments
 (0)