Commit 663caf85 authored by jwarnier's avatar jwarnier
Browse files

- replaced double quotes with single quotes whenever appropriate

- replaced "exec('/etc/init.d/" calls with "exec($conf['init_scripts'] . '/' ."
- fixed output wording (typos and more...)
parent 6f56718f
...@@ -76,7 +76,7 @@ class firewall_plugin { ...@@ -76,7 +76,7 @@ class firewall_plugin {
$tcp_ports = ''; $tcp_ports = '';
$udp_ports = ''; $udp_ports = '';
$ports = explode(',',$data["new"]["tcp_port"]); $ports = explode(',',$data['new']['tcp_port']);
if(is_array($ports)) { if(is_array($ports)) {
foreach($ports as $p) { foreach($ports as $p) {
if(strstr($p,':')) { if(strstr($p,':')) {
...@@ -90,7 +90,7 @@ class firewall_plugin { ...@@ -90,7 +90,7 @@ class firewall_plugin {
} }
$tcp_ports = trim($tcp_ports); $tcp_ports = trim($tcp_ports);
$ports = explode(',',$data["new"]["udp_port"]); $ports = explode(',',$data['new']['udp_port']);
if(is_array($ports)) { if(is_array($ports)) {
foreach($ports as $p) { foreach($ports as $p) {
if(strstr($p,':')) { if(strstr($p,':')) {
...@@ -106,21 +106,21 @@ class firewall_plugin { ...@@ -106,21 +106,21 @@ class firewall_plugin {
$app->load('tpl'); $app->load('tpl');
$tpl = new tpl(); $tpl = new tpl();
$tpl->newTemplate("bastille-firewall.cfg.master"); $tpl->newTemplate('bastille-firewall.cfg.master');
$tpl->setVar("TCP_PUBLIC_SERVICES",$tcp_ports); $tpl->setVar('TCP_PUBLIC_SERVICES',$tcp_ports);
$tpl->setVar("UDP_PUBLIC_SERVICES",$udp_ports); $tpl->setVar('UDP_PUBLIC_SERVICES',$udp_ports);
file_put_contents('/etc/Bastille/bastille-firewall.cfg',$tpl->grab()); file_put_contents('/etc/Bastille/bastille-firewall.cfg',$tpl->grab());
$app->log('Writing firewall configuration /etc/Bastille/bastille-firewall.cfg',LOGLEVEL_DEBUG); $app->log('Writing firewall configuration /etc/Bastille/bastille-firewall.cfg',LOGLEVEL_DEBUG);
unset($tpl); unset($tpl);
if($data["new"]["active"] == 'y') { if($data['new']['active'] == 'y') {
exec('/etc/init.d/bastille-firewall restart'); exec($conf['init_scripts'] . '/' . 'bastille-firewall restart');
if(@is_file('/etc/debian_version')) exec('update-rc.d bastille-firewall defaults'); if(@is_file('/etc/debian_version')) exec('update-rc.d bastille-firewall defaults');
$app->log('Restarting the firewall',LOGLEVEL_DEBUG); $app->log('Restarting the firewall',LOGLEVEL_DEBUG);
} else { } else {
exec('/etc/init.d/bastille-firewall stop'); exec($conf['init_scripts'] . '/' . 'bastille-firewall stop');
if(@is_file('/etc/debian_version')) exec('update-rc.d -f bastille-firewall remove'); if(@is_file('/etc/debian_version')) exec('update-rc.d -f bastille-firewall remove');
$app->log('Stopping the firewall',LOGLEVEL_DEBUG); $app->log('Stopping the firewall',LOGLEVEL_DEBUG);
} }
...@@ -131,7 +131,7 @@ class firewall_plugin { ...@@ -131,7 +131,7 @@ class firewall_plugin {
function delete($event_name,$data) { function delete($event_name,$data) {
global $app, $conf; global $app, $conf;
exec('/etc/init.d/bastille-firewall stop'); exec($conf['init_scripts'] . '/' . 'bastille-firewall stop');
if(@is_file('/etc/debian_version')) exec('update-rc.d -f bastille-firewall remove'); if(@is_file('/etc/debian_version')) exec('update-rc.d -f bastille-firewall remove');
$app->log('Stopping the firewall',LOGLEVEL_DEBUG); $app->log('Stopping the firewall',LOGLEVEL_DEBUG);
...@@ -142,4 +142,4 @@ class firewall_plugin { ...@@ -142,4 +142,4 @@ class firewall_plugin {
} // end class } // end class
?> ?>
\ No newline at end of file
...@@ -80,8 +80,8 @@ class mail_plugin { ...@@ -80,8 +80,8 @@ class mail_plugin {
global $app, $conf; global $app, $conf;
//* get the config //* get the config
$app->uses("getconf,system"); $app->uses('getconf,system');
$mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail'); $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
// convert to lower case - it could cause problems if some directory above has upper case name // convert to lower case - it could cause problems if some directory above has upper case name
// $data['new']['maildir'] = strtolower($data['new']['maildir']); // $data['new']['maildir'] = strtolower($data['new']['maildir']);
...@@ -110,7 +110,7 @@ class mail_plugin { ...@@ -110,7 +110,7 @@ class mail_plugin {
//* When the mail user dir exists but it is not a valid maildir, remove it //* When the mail user dir exists but it is not a valid maildir, remove it
if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) { if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
exec("su -c 'rm -rf ".escapeshellcmd($data['new']['maildir'])."' vmail"); exec("su -c 'rm -rf ".escapeshellcmd($data['new']['maildir'])."' vmail");
$app->log("Removed invalid maildir and rebuild it: ".escapeshellcmd($data['new']['maildir']),LOGLEVEL_WARN); $app->log('Removed invalid maildir and rebuild it: '.escapeshellcmd($data['new']['maildir']),LOGLEVEL_WARN);
} }
//* Create the maildir, if it doesn not exist, set permissions, set quota. //* Create the maildir, if it doesn not exist, set permissions, set quota.
...@@ -120,7 +120,7 @@ class mail_plugin { ...@@ -120,7 +120,7 @@ class mail_plugin {
$app->system->maildirmake($maildomain_path,$mail_config['mailuser_name']); $app->system->maildirmake($maildomain_path,$mail_config['mailuser_name']);
exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir'])); exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
$app->log("Set ownership on ".escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG); $app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG);
//* This is to fix the maildrop quota not being rebuilt after the quota is changed. //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
if($mail_config['pop3_imap_daemon'] != 'dovecot') { if($mail_config['pop3_imap_daemon'] != 'dovecot') {
...@@ -161,8 +161,8 @@ class mail_plugin { ...@@ -161,8 +161,8 @@ class mail_plugin {
global $app, $conf; global $app, $conf;
// get the config // get the config
$app->uses("getconf,system"); $app->uses('getconf,system');
$mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail'); $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
// convert to lower case - it could cause problems if some directory above has upper case name // convert to lower case - it could cause problems if some directory above has upper case name
// $data['new']['maildir'] = strtolower($data['new']['maildir']); // $data['new']['maildir'] = strtolower($data['new']['maildir']);
...@@ -170,8 +170,9 @@ class mail_plugin { ...@@ -170,8 +170,9 @@ class mail_plugin {
// Create the maildir, if it does not exist // Create the maildir, if it does not exist
/* /*
if(!is_dir($data['new']['maildir'])) { if(!is_dir($data['new']['maildir'])) {
exec('mkdir -p '.escapeshellcmd($data['new']['maildir'])); mkdir(escapeshellcmd($data['new']['maildir']), 0, true);
exec('chown '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir'])); chown(escapeshellcmd($data['new']['maildir']), $mail_config['mailuser_name']);
chgrp(escapeshellcmd($data['new']['maildir']), $mail_config['mailuser_group']);
$app->log('Created Maildir: '.$data['new']['maildir'],LOGLEVEL_DEBUG); $app->log('Created Maildir: '.$data['new']['maildir'],LOGLEVEL_DEBUG);
} }
*/ */
...@@ -198,7 +199,7 @@ class mail_plugin { ...@@ -198,7 +199,7 @@ class mail_plugin {
//* When the mail user dir exists but it is not a valid maildir, remove it //* When the mail user dir exists but it is not a valid maildir, remove it
if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) { if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
exec("su -c 'rm -rf ".escapeshellcmd($data['new']['maildir'])."' vmail"); exec("su -c 'rm -rf ".escapeshellcmd($data['new']['maildir'])."' vmail");
$app->log("Removed invalid maildir and rebuild it: ".escapeshellcmd($data['new']['maildir']),LOGLEVEL_WARN); $app->log('Removed invalid maildir and rebuild it: '.escapeshellcmd($data['new']['maildir']),LOGLEVEL_WARN);
} }
//* Create the maildir, if it doesn not exist, set permissions, set quota. //* Create the maildir, if it doesn not exist, set permissions, set quota.
...@@ -208,7 +209,7 @@ class mail_plugin { ...@@ -208,7 +209,7 @@ class mail_plugin {
$app->system->maildirmake($maildomain_path,$mail_config['mailuser_name']); $app->system->maildirmake($maildomain_path,$mail_config['mailuser_name']);
exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir'])); exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
$app->log("Set ownership on ".escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG); $app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG);
//* This is to fix the maildrop quota not being rebuilt after the quota is changed. //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
if($mail_config['pop3_imap_daemon'] != 'dovecot') { if($mail_config['pop3_imap_daemon'] != 'dovecot') {
exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota bug, see debian bug #214911 exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota bug, see debian bug #214911
...@@ -274,7 +275,7 @@ class mail_plugin { ...@@ -274,7 +275,7 @@ class mail_plugin {
// get the config // get the config
$app->uses("getconf"); $app->uses("getconf");
$mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail'); $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
//* Delete maildomain path //* Delete maildomain path
$old_maildomain_path = escapeshellcmd($mail_config['homedir_path'].'/'.$data['old']['domain']); $old_maildomain_path = escapeshellcmd($mail_config['homedir_path'].'/'.$data['old']['domain']);
...@@ -298,7 +299,7 @@ class mail_plugin { ...@@ -298,7 +299,7 @@ class mail_plugin {
function transport_update($event_name,$data) { function transport_update($event_name,$data) {
global $app, $conf; global $app, $conf;
exec('/etc/init.d/postfix reload &> /dev/null'); exec($conf['init_scripts'] . '/' . 'postfix reload &> /dev/null');
$app->log('Postfix config reloaded ',LOGLEVEL_DEBUG); $app->log('Postfix config reloaded ',LOGLEVEL_DEBUG);
} }
...@@ -308,4 +309,4 @@ class mail_plugin { ...@@ -308,4 +309,4 @@ class mail_plugin {
} // end class } // end class
?> ?>
\ No newline at end of file
...@@ -66,16 +66,16 @@ class mysql_clientdb_plugin { ...@@ -66,16 +66,16 @@ class mysql_clientdb_plugin {
} }
function process_host_list($action, $database_name, $database_user, $database_password, $host_list, $link, $database_rename_user = "") { function process_host_list($action, $database_name, $database_user, $database_password, $host_list, $link, $database_rename_user = '') {
global $app; global $app;
$action = strtoupper($action); $action = strtoupper($action);
// set to all hosts if none given // set to all hosts if none given
if(trim($host_list) == "") $host_list = "%"; if(trim($host_list) == '') $host_list = '%';
// process arrays and comma separated strings // process arrays and comma separated strings
if(!is_array($host_list)) $host_list = split(",", $host_list); if(!is_array($host_list)) $host_list = split(',', $host_list);
$success = true; $success = true;
...@@ -85,10 +85,10 @@ class mysql_clientdb_plugin { ...@@ -85,10 +85,10 @@ class mysql_clientdb_plugin {
// check if entry is valid ip address // check if entry is valid ip address
$valid = true; $valid = true;
if($db_host == "%") { if($db_host == '%') {
$valid = true; $valid = true;
} elseif(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $db_host)) { } elseif(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $db_host)) {
$groups = explode(".", $db_host); $groups = explode('.', $db_host);
foreach($groups as $group){ foreach($groups as $group){
if($group<0 OR $group>255) if($group<0 OR $group>255)
$valid=false; $valid=false;
...@@ -99,15 +99,15 @@ class mysql_clientdb_plugin { ...@@ -99,15 +99,15 @@ class mysql_clientdb_plugin {
if($valid == false) continue; if($valid == false) continue;
if($action == "GRANT") { if($action == 'GRANT') {
if(!mysql_query("GRANT ALL ON ".mysql_real_escape_string($database_name,$link).".* TO '".mysql_real_escape_string($database_user,$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($database_password,$link)."';",$link)) $success = false; if(!mysql_query("GRANT ALL ON ".mysql_real_escape_string($database_name,$link).".* TO '".mysql_real_escape_string($database_user,$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($database_password,$link)."';",$link)) $success = false;
} elseif($action == "REVOKE") { } elseif($action == 'REVOKE') {
//mysql_query("REVOKE ALL PRIVILEGES ON ".mysql_real_escape_string($database_name,$link).".* FROM '".mysql_real_escape_string($database_user,$link)."';",$link); //mysql_query("REVOKE ALL PRIVILEGES ON ".mysql_real_escape_string($database_name,$link).".* FROM '".mysql_real_escape_string($database_user,$link)."';",$link);
} elseif($action == "DROP") { } elseif($action == 'DROP') {
if(!mysql_query("DROP USER '".mysql_real_escape_string($database_user,$link)."'@'$db_host';",$link)) $success = false; if(!mysql_query("DROP USER '".mysql_real_escape_string($database_user,$link)."'@'$db_host';",$link)) $success = false;
} elseif($action == "RENAME") { } elseif($action == 'RENAME') {
if(!mysql_query("RENAME USER '".mysql_real_escape_string($database_user,$link)."'@'$db_host' TO '".mysql_real_escape_string($database_rename_user,$link)."'@'$db_host'",$link)) $success = false; if(!mysql_query("RENAME USER '".mysql_real_escape_string($database_user,$link)."'@'$db_host' TO '".mysql_real_escape_string($database_rename_user,$link)."'@'$db_host'",$link)) $success = false;
} elseif($action == "PASSWORD") { } elseif($action == 'PASSWORD') {
if(!mysql_query("SET PASSWORD FOR '".mysql_real_escape_string($database_user,$link)."'@'$db_host' = PASSWORD('".mysql_real_escape_string($database_password,$link)."');",$link)) $success = false; if(!mysql_query("SET PASSWORD FOR '".mysql_real_escape_string($database_user,$link)."'@'$db_host' = PASSWORD('".mysql_real_escape_string($database_password,$link)."');",$link)) $success = false;
} }
} }
...@@ -118,13 +118,13 @@ class mysql_clientdb_plugin { ...@@ -118,13 +118,13 @@ class mysql_clientdb_plugin {
function db_insert($event_name,$data) { function db_insert($event_name,$data) {
global $app, $conf; global $app, $conf;
if($data["new"]["type"] == 'mysql') { if($data['new']['type'] == 'mysql') {
if(!include(ISPC_LIB_PATH.'/mysql_clientdb.conf')) { if(!include(ISPC_LIB_PATH.'/mysql_clientdb.conf')) {
$app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR); $app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR);
return; return;
} }
if($data["new"]["database_user"] == 'root') { if($data['new']['database_user'] == 'root') {
$app->log('User root not allowed for Client databases',LOGLEVEL_WARNING); $app->log('User root not allowed for Client databases',LOGLEVEL_WARNING);
return; return;
} }
...@@ -137,33 +137,33 @@ class mysql_clientdb_plugin { ...@@ -137,33 +137,33 @@ class mysql_clientdb_plugin {
} }
// Charset for the new table // Charset for the new table
if($data["new"]["database_charset"] != '') { if($data['new']['database_charset'] != '') {
$query_charset_table = ' DEFAULT CHARACTER SET '.$data["new"]["database_charset"]; $query_charset_table = ' DEFAULT CHARACTER SET '.$data['new']['database_charset'];
} else { } else {
$query_charset_table = ''; $query_charset_table = '';
} }
//* Create the new database //* Create the new database
if (mysql_query('CREATE DATABASE '.mysql_real_escape_string($data["new"]["database_name"]).$query_charset_table,$link)) { if (mysql_query('CREATE DATABASE '.mysql_real_escape_string($data['new']['database_name']).$query_charset_table,$link)) {
$app->log('Created MySQL database: '.$data["new"]["database_name"],LOGLEVEL_DEBUG); $app->log('Created MySQL database: '.$data['new']['database_name'],LOGLEVEL_DEBUG);
} else { } else {
$app->log('Unable to create the database'.mysql_error($link),LOGLEVEL_WARNING); $app->log('Unable to create the database: '.mysql_error($link),LOGLEVEL_WARNING);
} }
// Create the database user if database is active // Create the database user if database is active
if($data["new"]["active"] == 'y') { if($data['new']['active'] == 'y') {
if($data["new"]["remote_access"] == 'y') { if($data['new']['remote_access'] == 'y') {
$this->process_host_list("GRANT", $data["new"]["database_name"], $data["new"]["database_user"], $data["new"]["database_password"], $data["new"]["remote_ips"], $link); $this->process_host_list('GRANT', $data['new']['database_name'], $data['new']['database_user'], $data['new']['database_password'], $data['new']['remote_ips'], $link);
} }
$db_host = 'localhost'; $db_host = 'localhost';
mysql_query("GRANT ALL ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* TO '".mysql_real_escape_string($data["new"]["database_user"],$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data["new"]["database_password"],$link)."';",$link); mysql_query("GRANT ALL ON ".mysql_real_escape_string($data['new']['database_name'],$link).".* TO '".mysql_real_escape_string($data['new']['database_user'],$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data['new']['database_password'],$link)."';",$link);
} }
mysql_query("FLUSH PRIVILEGES;",$link); mysql_query('FLUSH PRIVILEGES;',$link);
mysql_close($link); mysql_close($link);
} }
} }
...@@ -171,13 +171,13 @@ class mysql_clientdb_plugin { ...@@ -171,13 +171,13 @@ class mysql_clientdb_plugin {
function db_update($event_name,$data) { function db_update($event_name,$data) {
global $app, $conf; global $app, $conf;
if($data["new"]["type"] == 'mysql') { if($data['new']['type'] == 'mysql') {
if(!include(ISPC_LIB_PATH.'/mysql_clientdb.conf')) { if(!include(ISPC_LIB_PATH.'/mysql_clientdb.conf')) {
$app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR); $app->log('Unable to open'.ISPC_LIB_PATH.'/mysql_clientdb.conf',LOGLEVEL_ERROR);
return; return;
} }
if($data["new"]["database_user"] == 'root') { if($data['new']['database_user'] == 'root') {
$app->log('User root not allowed for Client databases',LOGLEVEL_WARNING); $app->log('User root not allowed for Client databases',LOGLEVEL_WARNING);
return; return;
} }
...@@ -185,79 +185,79 @@ class mysql_clientdb_plugin { ...@@ -185,79 +185,79 @@ class mysql_clientdb_plugin {
//* Connect to the database //* Connect to the database
$link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password); $link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password);
if (!$link) { if (!$link) {
$app->log('Unable to connect to the database'.mysql_error($link),LOGLEVEL_ERROR); $app->log('Unable to connect to the database: '.mysql_error($link),LOGLEVEL_ERROR);
return; return;
} }
// Create the database user if database was disabled before // Create the database user if database was disabled before
if($data["new"]["active"] == 'y' && $data["old"]["active"] == 'n') { if($data['new']['active'] == 'y' && $data['old']['active'] == 'n') {
if($data["new"]["remote_access"] == 'y') { if($data['new']['remote_access'] == 'y') {
$this->process_host_list("GRANT", $data["new"]["database_name"], $data["new"]["database_user"], $data["new"]["database_password"], $data["new"]["remote_ips"], $link); $this->process_host_list('GRANT', $data['new']['database_name'], $data['new']['database_user'], $data['new']['database_password'], $data['new']['remote_ips'], $link);
} }
$db_host = 'localhost'; $db_host = 'localhost';
mysql_query("GRANT ALL ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* TO '".mysql_real_escape_string($data["new"]["database_user"],$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data["new"]["database_password"],$link)."';",$link); mysql_query("GRANT ALL ON ".mysql_real_escape_string($data['new']['database_name'],$link).".* TO '".mysql_real_escape_string($data['new']['database_user'],$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data['new']['database_password'],$link)."';",$link);
// mysql_query("GRANT ALL ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* TO '".mysql_real_escape_string($data["new"]["database_user"],$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data["new"]["database_password"],$link)."';",$link); // mysql_query("GRANT ALL ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* TO '".mysql_real_escape_string($data["new"]["database_user"],$link)."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data["new"]["database_password"],$link)."';",$link);
//echo "GRANT ALL ON ".mysql_real_escape_string($data["new"]["database_name"]).".* TO '".mysql_real_escape_string($data["new"]["database_user"])."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data["new"]["database_password"])."';"; //echo "GRANT ALL ON ".mysql_real_escape_string($data["new"]["database_name"]).".* TO '".mysql_real_escape_string($data["new"]["database_user"])."'@'$db_host' IDENTIFIED BY '".mysql_real_escape_string($data["new"]["database_password"])."';";
} }
// Remove database user, if inactive // Remove database user, if inactive
if($data["new"]["active"] == 'n' && $data["old"]["active"] == 'y') { if($data['new']['active'] == 'n' && $data['old']['active'] == 'y') {
if($data["old"]["remote_access"] == 'y') { if($data['old']['remote_access'] == 'y') {
$this->process_host_list("DROP", "", $data["old"]["database_user"], "", $data["old"]["remote_ips"], $link); $this->process_host_list('DROP', '', $data['old']['database_user'], '', $data['old']['remote_ips'], $link);
} }
$db_host = 'localhost'; $db_host = 'localhost';
mysql_query("DROP USER '".mysql_real_escape_string($data["old"]["database_user"],$link)."'@'$db_host';",$link); mysql_query("DROP USER '".mysql_real_escape_string($data['old']['database_user'],$link)."'@'$db_host';",$link);
//mysql_query("REVOKE ALL PRIVILEGES ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* FROM '".mysql_real_escape_string($data["new"]["database_user"],$link)."';",$link); //mysql_query("REVOKE ALL PRIVILEGES ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* FROM '".mysql_real_escape_string($data["new"]["database_user"],$link)."';",$link);
} }
//* Rename User //* Rename User
if($data["new"]["database_user"] != $data["old"]["database_user"]) { if($data['new']['database_user'] != $data['old']['database_user']) {
$db_host = 'localhost'; $db_host = 'localhost';
mysql_query("RENAME USER '".mysql_real_escape_string($data["old"]["database_user"],$link)."'@'$db_host' TO '".mysql_real_escape_string($data["new"]["database_user"],$link)."'@'$db_host'",$link); mysql_query("RENAME USER '".mysql_real_escape_string($data['old']['database_user'],$link)."'@'$db_host' TO '".mysql_real_escape_string($data['new']['database_user'],$link)."'@'$db_host'",$link);
if($data["old"]["remote_access"] == 'y') { if($data['old']['remote_access'] == 'y') {
$this->process_host_list("RENAME", "", $data["new"]["database_user"], "", $data["new"]["remote_ips"], $link, $data["new"]["database_user"]); $this->process_host_list('RENAME', '', $data['new']['database_user'], '', $data['new']['remote_ips'], $link, $data['new']['database_user']);
} }
$app->log('Renaming mysql user: '.$data["old"]["database_user"].' to '.$data["new"]["database_user"],LOGLEVEL_DEBUG); $app->log('Renaming MySQL user: '.$data['old']['database_user'].' to '.$data['new']['database_user'],LOGLEVEL_DEBUG);
} }
//* Remote access option has changed. //* Remote access option has changed.
if($data["new"]["remote_access"] != $data["old"]["remote_access"]) { if($data['new']['remote_access'] != $data['old']['remote_access']) {
//* revoke old priveliges //* revoke old priveliges
//mysql_query("REVOKE ALL PRIVILEGES ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* FROM '".mysql_real_escape_string($data["new"]["database_user"],$link)."';",$link); //mysql_query("REVOKE ALL PRIVILEGES ON ".mysql_real_escape_string($data["new"]["database_name"],$link).".* FROM '".mysql_real_escape_string($data["new"]["database_user"],$link)."';",$link);
//* set new priveliges //* set new priveliges
if($data["new"]["remote_access"] == 'y') { if($data['new']['remote_access'] == 'y') {
$this->process_host_list("GRANT", $data["new"]["database_name"], $data["new"]["database_user"], $data["new"]["database_password"], $data["new"]["remote_ips"], $link); $this->process_host_list('GRANT', $data['new']['database_name'], $data['new']['database_user'], $data['new']['database_password'], $data['new']['remote_ips'], $link);
} else { } else {
$this->process_host_list("DROP", "", $data["old"]["database_user"], "", $data["old"]["remote_ips"], $link); $this->process_host_list('DROP', '', $data['old']['database_user'], '', $data['old']['remote_ips'], $link);
} }
$app->log('Changing mysql remote access priveliges for database: '.$data["new"]["database_name"],LOGLEVEL_DEBUG); $app->log('Changing MySQL remote access privileges for database: '.$data['new']['database_name'],LOGLEVEL_DEBUG);
} elseif($data["new"]["remote_access"] == 'y' && $data["new"]["remote_ips"] != $data["old"]["remote_ips"]) { } elseif($data['new']['remote_access'] == 'y' && $data['new']['remote_ips'] != $data['old']['remote_ips']) {
//* Change remote access list //* Change remote access list
$this->process_host_list("DROP", "", $data["old"]["database_user"], "", $data["old"]["remote_ips"], $link); $this->process_host_list('DROP', '', $data['old']['database_user'], '', $data['old']['remote_ips'], $link);
$this->process_host_list("GRANT", $data["new"]["database_name"], $data["new"]["database_user"], $data["new"]["database_password"], $data["new"]["remote_ips"], $link); $this->process_host_list('GRANT', $data['new']['database_name'], $data['new']['database_user'], $data['new']['database_password'], $data['new']['remote_ips'], $link);
} }
//* Change password //* Change password
if($data["new"]["database_password"] != $data["old"]["database_password"]) { if($data['new']['database_password'] != $data['old']['database_password']) {
$db_host = 'localhost'; $db_host = 'localhost';
mysql_query("SET PASSWORD FOR '".mysql_real_escape_string($data["new"]["database_user"],$link)."'@'$db_host' = PASSWORD('".mysql_real_escape_string($data["new"]["database_password"],$link)."');",$link); mysql_query("SET PASSWORD FOR '".mysql_real_escape_string($data['new']['database_user'],$link)."'@'$db_host' = PASSWORD('".mysql_real_escape_string($data['new']['database_password'],$link)."');",$link);
if($data["new"]["remote_access"] == 'y') { if($data['new']['remote_access'] == 'y') {
$this->process_host_list("PASSWORD", "", $data["new"]["database_user"], $data["new"]["database_password"], $data["new"]["remote_ips"], $link); $this->process_host_list('PASSWORD', '', $data['new']['database_user'], $data['new']['database_password'], $data['new']['remote_ips'], $link);
} }
$app->log('Changing mysql user password for: '.$data["new"]["database_user"],LOGLEVEL_DEBUG); $app->log('Changing MySQL user password for: '.$data['new']['database_user'],LOGLEVEL_DEBUG);
} }
mysql_query("FLUSH PRIVILEGES;",$link); mysql_query('FLUSH PRIVILEGES;',$link);
mysql_close($link); mysql_close($link);
} }
...@@ -266,7 +266,7 @@ class mysql_clientdb_plugin { ...@@ -266,7 +266,7 @@ class mysql_clientdb_plugin {
function db_delete($event_name,$data) { function db_delete($event_name,$data) {
global $app, $conf; global $app, $conf;