Skip to content

Commit 381520c

Browse files
author
mcramer
committed
Implemented FS#1448 - one database user name and multiple databases
Bugfix on db-Class (datalog Update)
1 parent 307b030 commit 381520c

31 files changed

+1244
-183
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- --------------------------------------------------------
2+
3+
--
4+
-- Tabellenstruktur für Tabelle `web_database_user`
5+
--
6+
7+
CREATE TABLE IF NOT EXISTS `web_database_user` (
8+
`database_user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
9+
`sys_userid` int(11) unsigned NOT NULL DEFAULT '0',
10+
`sys_groupid` int(11) unsigned NOT NULL DEFAULT '0',
11+
`sys_perm_user` varchar(5) DEFAULT NULL,
12+
`sys_perm_group` varchar(5) DEFAULT NULL,
13+
`sys_perm_other` varchar(5) DEFAULT NULL,
14+
`server_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
15+
`database_user` varchar(64) DEFAULT NULL,
16+
`database_password` varchar(64) DEFAULT NULL,
17+
PRIMARY KEY (`database_user_id`)
18+
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
19+
20+
-- --------------------------------------------------------
21+
22+
ALTER TABLE `web_database` ADD `database_user_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL AFTER `database_password` ,
23+
ADD `database_ro_user_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL AFTER `database_user_id`,
24+
ADD INDEX ( `database_user_id` ),
25+
ADD INDEX ( `database_ro_user_id` ) ;
26+
27+
-- --------------------------------------------------------
28+
29+
UPDATE `web_database`, `web_database_user` SET `web_database`.`database_user_id` = `web_database_user`.`database_user_id` WHERE `web_database_user`.`database_user` = `web_database`.`database_user`;
30+
31+
-- --------------------------------------------------------
32+
33+
ALTER TABLE `web_database`
34+
DROP `database_user`,
35+
DROP `database_password`;
36+

install/sql/ispconfig3.sql

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,19 +1616,39 @@ CREATE TABLE `web_database` (
16161616
`parent_domain_id` int(11) unsigned NOT NULL DEFAULT '0',
16171617
`type` varchar(16) NOT NULL DEFAULT 'y',
16181618
`database_name` varchar(64) DEFAULT NULL,
1619-
`database_user` varchar(64) DEFAULT NULL,
1620-
`database_password` varchar(64) DEFAULT NULL,
1619+
`database_user_id` int(11) unsigned DEFAULT NULL,
1620+
`database_ro_user_id` int(11) unsigned DEFAULT NULL,
16211621
`database_charset` varchar(64) DEFAULT NULL,
16221622
`remote_access` enum('n','y') NOT NULL DEFAULT 'y',
16231623
`remote_ips` text NOT NULL,
16241624
`backup_interval` VARCHAR( 255 ) NOT NULL DEFAULT 'none',
16251625
`backup_copies` INT NOT NULL DEFAULT '1',
16261626
`active` enum('n','y') NOT NULL DEFAULT 'y',
1627-
PRIMARY KEY (`database_id`)
1627+
PRIMARY KEY (`database_id`),
1628+
KEY `database_user_id` (`database_user_id`),
1629+
KEY `database_ro_user_id` (`database_ro_user_id`)
16281630
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
16291631

16301632
-- --------------------------------------------------------
16311633

1634+
--
1635+
-- Tabellenstruktur für Tabelle `web_database_user`
1636+
--
1637+
1638+
CREATE TABLE IF NOT EXISTS `web_database_user` (
1639+
`database_user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
1640+
`sys_userid` int(11) unsigned NOT NULL DEFAULT '0',
1641+
`sys_groupid` int(11) unsigned NOT NULL DEFAULT '0',
1642+
`sys_perm_user` varchar(5) DEFAULT NULL,
1643+
`sys_perm_group` varchar(5) DEFAULT NULL,
1644+
`sys_perm_other` varchar(5) DEFAULT NULL,
1645+
`database_user` varchar(64) DEFAULT NULL,
1646+
`database_password` varchar(64) DEFAULT NULL,
1647+
PRIMARY KEY (`database_user_id`)
1648+
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
1649+
1650+
-- --------------------------------------------------------
1651+
16321652
--
16331653
-- Table structure for table `web_domain`
16341654
--

interface/lib/classes/db_mysql.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public function datalogUpdate($tablename, $update_data, $index_field, $index_val
299299
$update_data_str = $update_data;
300300
}
301301

302-
$this->query("UPDATE $tablename SET $update_data WHERE $index_field = '$index_value'");
302+
$this->query("UPDATE $tablename SET $update_data_str WHERE $index_field = '$index_value'");
303303
$new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
304304
$this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec, $force_update);
305305

interface/web/sites/database_del.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,41 @@
4646
$app->auth->check_module_permissions('sites');
4747

4848
$app->uses("tform_actions");
49-
$app->tform_actions->onDelete();
49+
class page_action extends tform_actions {
50+
function onBeforeDelete() {
51+
global $app; $conf;
52+
if($app->tform->checkPerm($this->id,'d') == false) $app->error($app->lng('error_no_delete_permission'));
53+
54+
$old_record = $app->tform->getDataRecord($this->id);
55+
if($old_record['database_user_id']) {
56+
// check if any database on the server still uses this one
57+
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($old_record['server_id']) . "' AND (`database_user_id` = '" . intval($old_record['database_user_id']) . "' OR `database_ro_user_id` = '" . intval($old_record['database_user_id']) . "') AND `sys_groupid` = '" . intval($old_record['sys_groupid']) . "' AND `database_id` != '" . intval($this->id) . "'");
58+
if($check['cnt'] < 1) {
59+
// send a datalog delete
60+
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($old_record['database_user_id']) . "' AND `sys_groupid` = '" . intval($old_record['sys_groupid']) . "'");
61+
if($db_user) {
62+
$db_user['server_id'] = $old_record['server_id'];
63+
$app->db->datalogSave('web_database_user', 'DELETE', 'database_user_id', $db_user['database_user_id'], $db_user, array());
64+
}
65+
}
66+
}
67+
if($old_record['database_ro_user_id']) {
68+
// check if any database on the server still uses this one
69+
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($old_record['server_id']) . "' AND (`database_user_id` = '" . intval($old_record['database_ro_user_id']) . "' OR `database_ro_user_id` = '" . intval($old_record['database_ro_user_id']) . "') AND `sys_groupid` = '" . intval($old_record['sys_groupid']) . "' AND `database_id` != '" . intval($this->id) . "'");
70+
if($check['cnt'] < 1) {
71+
// send a datalog delete
72+
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($old_record['database_ro_user_id']) . "' AND `sys_groupid` = '" . intval($old_record['sys_groupid']) . "'");
73+
if($db_user) {
74+
$db_user['server_id'] = $old_record['server_id'];
75+
$app->db->datalogSave('web_database_user', 'DELETE', 'database_user_id', $db_user['database_user_id'], $db_user, array());
76+
}
77+
}
78+
}
79+
80+
}
81+
}
82+
83+
$page = new page_action;
84+
$page->onDelete();
5085

5186
?>

0 commit comments

Comments
 (0)