Added support for internal repliaction for ispconfig multiserver setups.
| | |
| | | $conf['mysql']['charset'] = 'utf8'; |
| | | $conf['mysql']['ispconfig_user'] = 'ispconfig'; |
| | | $conf['mysql']['ispconfig_password'] = md5 (uniqid (rand())); |
| | | $conf['mysql']['master_slave_setup'] = 'n'; |
| | | $conf['mysql']['master_host'] = ''; |
| | | $conf['mysql']['master_database'] = 'dbispconfig'; |
| | | $conf['mysql']['master_admin_user'] = 'root'; |
| | | $conf['mysql']['master_admin_password'] = ''; |
| | | $conf['mysql']['master_ispconfig_user'] = ''; |
| | | $conf['mysql']['master_ispconfig_password'] = md5 (uniqid (rand())); |
| | | |
| | | //* Apache |
| | | $conf['apache']['user'] = 'apache'; |
| | |
| | | $conf['mysql']['charset'] = 'utf8'; |
| | | $conf['mysql']['ispconfig_user'] = 'ispconfig'; |
| | | $conf['mysql']['ispconfig_password'] = md5 (uniqid (rand())); |
| | | $conf['mysql']['master_slave_setup'] = 'n'; |
| | | $conf['mysql']['master_host'] = ''; |
| | | $conf['mysql']['master_database'] = 'dbispconfig'; |
| | | $conf['mysql']['master_admin_user'] = 'root'; |
| | | $conf['mysql']['master_admin_password'] = ''; |
| | | $conf['mysql']['master_ispconfig_user'] = ''; |
| | | $conf['mysql']['master_ispconfig_password'] = md5 (uniqid (rand())); |
| | | |
| | | //* Apache |
| | | $conf['apache']['user'] = 'www-data'; |
| | |
| | | $conf['mysql']['charset'] = 'utf8'; |
| | | $conf['mysql']['ispconfig_user'] = 'ispconfig'; |
| | | $conf['mysql']['ispconfig_password'] = md5 (uniqid (rand())); |
| | | $conf['mysql']['master_slave_setup'] = 'n'; |
| | | $conf['mysql']['master_host'] = ''; |
| | | $conf['mysql']['master_database'] = 'dbispconfig'; |
| | | $conf['mysql']['master_admin_user'] = 'root'; |
| | | $conf['mysql']['master_admin_password'] = ''; |
| | | $conf['mysql']['master_ispconfig_user'] = ''; |
| | | $conf['mysql']['master_ispconfig_password'] = md5 (uniqid (rand())); |
| | | |
| | | //* Apache |
| | | $conf['apache']['user'] = 'apache'; |
| | |
| | | $conf['mysql']['charset'] = 'utf8'; |
| | | $conf['mysql']['ispconfig_user'] = 'ispconfig'; |
| | | $conf['mysql']['ispconfig_password'] = md5 (uniqid (rand())); |
| | | $conf['mysql']['master_slave_setup'] = 'n'; |
| | | $conf['mysql']['master_host'] = ''; |
| | | $conf['mysql']['master_database'] = 'dbispconfig'; |
| | | $conf['mysql']['master_admin_user'] = 'root'; |
| | | $conf['mysql']['master_admin_password'] = ''; |
| | | $conf['mysql']['master_ispconfig_user'] = ''; |
| | | $conf['mysql']['master_ispconfig_password'] = md5 (uniqid (rand())); |
| | | |
| | | //* Apache |
| | | $conf['apache']['user'] = 'wwwrun'; |
| | |
| | | $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
| | | $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
| | | |
| | | $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
| | | $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
| | | $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
| | | |
| | | $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
| | | wf("$install_dir/interface/lib/$configfile", $content); |
| | | |
| | |
| | | $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
| | | $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
| | | |
| | | $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
| | | $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
| | | $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
| | | |
| | | $content = str_replace('{server_id}', $conf['server_id'], $content); |
| | | $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
| | | wf("$install_dir/server/lib/$configfile", $content); |
| | |
| | | $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
| | | $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
| | | |
| | | $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
| | | $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
| | | $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
| | | |
| | | $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
| | | wf("$install_dir/interface/lib/$configfile", $content); |
| | | |
| | |
| | | $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
| | | $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
| | | |
| | | $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
| | | $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
| | | $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
| | | |
| | | $content = str_replace('{server_id}', $conf['server_id'], $content); |
| | | $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
| | | wf("$install_dir/server/lib/$configfile", $content); |
| | |
| | | $conf['language'] = $inst->simple_query('Select language', array('en','de'), 'en'); |
| | | |
| | | //** Select installation mode |
| | | $install_mode = $inst->simple_query('Installation mode', array('Standard','Expert'), 'Standard'); |
| | | $install_mode = $inst->simple_query('Installation mode', array('standard','expert'), 'standard'); |
| | | |
| | | |
| | | //** Get the hostname |
| | |
| | | $inst->db = new db(); |
| | | |
| | | //** Begin with standard or expert installation |
| | | if($install_mode == 'Standard') { |
| | | if($install_mode == 'standard') { |
| | | |
| | | //* Create the mysql database |
| | | $inst->configure_database(); |
| | |
| | | // $conf['server_id'] = $inst->free_query('Unique Numeric ID of the server','1'); |
| | | // Server ID is an autoInc value of the mysql database now |
| | | |
| | | if(strtolower($inst->simple_query('Create a new database? (We do not want to join a existing ISPConfig server setup)',array('y','n'),'y')) == 'y') { |
| | | //* Create the mysql database |
| | | $inst->configure_database(); |
| | | //system('/etc/init.d/mysql restart'); |
| | | if(strtolower($inst->simple_query('Shall this server join an existing ISPConfig multiserver setup',array('y','n'),'n')) == 'y') { |
| | | $conf['mysql']['master_slave_setup'] = 'y'; |
| | | |
| | | //** Get MySQL root credentials |
| | | $finished = false; |
| | | do { |
| | | $tmp_mysql_server_host = $inst->free_query('MySQL master server hostname', $conf['mysql']['master_host']); |
| | | $tmp_mysql_server_admin_user = $inst->free_query('MySQL master server root username', $conf['mysql']['master_admin_user']); |
| | | $tmp_mysql_server_admin_password = $inst->free_query('MySQL master server root password', $conf['mysql']['master_admin_password']); |
| | | $tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database']); |
| | | |
| | | //* Initialize the MySQL server connection |
| | | if(@mysql_connect($tmp_mysql_server_host, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) { |
| | | $conf['mysql']['master_host'] = $tmp_mysql_server_host; |
| | | $conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user; |
| | | $conf['mysql']['master_admin_password'] = $tmp_mysql_server_admin_password; |
| | | $conf['mysql']['master_database'] = $tmp_mysql_server_database; |
| | | $finished = true; |
| | | } else { |
| | | swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error()); |
| | | } |
| | | } while ($finished == false); |
| | | unset($finished); |
| | | |
| | | // initialize the connection to the master database |
| | | $inst->dbmaster = new db(); |
| | | if($inst->dbmaster->linkId) $inst->dbmaster->closeConn(); |
| | | $inst->dbmaster->dbHost = $conf['mysql']["master_host"]; |
| | | $inst->dbmaster->dbName = $conf['mysql']["master_database"]; |
| | | $inst->dbmaster->dbUser = $conf['mysql']["master_admin_user"]; |
| | | $inst->dbmaster->dbPass = $conf['mysql']["master_admin_password"]; |
| | | |
| | | } else { |
| | | // the master DB is the same then the slave DB |
| | | $inst->dbmaster = $inst->db; |
| | | } |
| | | |
| | | //* Create the mysql database |
| | | $inst->configure_database(); |
| | | |
| | | //* Insert the Server record into the database |
| | | swriteln('Adding ISPConfig server record to database.'); |
| | |
| | | } |
| | | |
| | | //** Configure Apache |
| | | swriteln("If this server shall run the ispconfig interface, select 'y' in the next option."); |
| | | swriteln("\nHint: If this server shall run the ispconfig interface, select 'y' in the next option.\n"); |
| | | if(strtolower($inst->simple_query('Configure Apache Server',array('y','n'),'y')) == 'y') { |
| | | swriteln('Configuring Apache'); |
| | | $inst->configure_apache(); |
| | |
| | | { |
| | | global $conf; |
| | | |
| | | $cf = $conf['mysql']; // make $conf['mysql'] more accessible |
| | | //** Create the database |
| | | if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$cf['database'].' DEFAULT CHARACTER SET '.$cf['charset'])) { |
| | | $this->error('Unable to create MySQL database: '.$cf['database'].'.'); |
| | | if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$conf['mysql']['database'].' DEFAULT CHARACTER SET '.$conf['mysql']['charset'])) { |
| | | $this->error('Unable to create MySQL database: '.$conf['mysql']['database'].'.'); |
| | | } |
| | | |
| | | //* Set the database name in the DB library |
| | | $this->db->dbName = $cf['database']; |
| | | $this->db->dbName = $conf['mysql']['database']; |
| | | |
| | | //* Load the database dump into the database, if database contains no tables |
| | | $db_tables = $this->db->getTables(); |
| | | if(count($db_tables) > 0) { |
| | | $this->error('Stopped: Database already contains some tables.'); |
| | | } else { |
| | | if($cf['admin_password'] == '') { |
| | | caselog("mysql --default-character-set=".$cf['charset']." -h '".$cf['host']."' -u '".$cf['admin_user']."' '".$cf['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
| | | if($conf['mysql']['admin_password'] == '') { |
| | | caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' '".$conf['mysql']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
| | | __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
| | | } else { |
| | | caselog("mysql --default-character-set=".$cf['charset']." -h '".$cf['host']."' -u '".$cf['admin_user']."' -p'".$cf['admin_password']."' '".$cf['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
| | | caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' '".$conf['mysql']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/ispconfig3.sql' &> /dev/null", |
| | | __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
| | | } |
| | | $db_tables = $this->db->getTables(); |
| | |
| | | |
| | | global $conf; |
| | | |
| | | $cf = $conf['mysql']; // make $conf['mysql'] more accessible |
| | | |
| | | if($cf['host'] == 'localhost') { |
| | | if($conf['mysql']['host'] == 'localhost') { |
| | | $from_host = 'localhost'; |
| | | } else { |
| | | $from_host = $conf['hostname']; |
| | | } |
| | | |
| | | // Delete ISPConfig user, in case that it exists |
| | | $this->db->query("DELETE FROM mysql.user WHERE User = '".$cf['ispconfig_user']."' AND Host = '".$from_host."';"); |
| | | $this->db->query("DELETE FROM mysql.db WHERE Db = '".$cf['database']."' AND Host = '".$from_host."';"); |
| | | // Delete ISPConfig user in the local database, in case that it exists |
| | | $this->db->query("DELETE FROM mysql.user WHERE User = '".$conf['mysql']['ispconfig_user']."' AND Host = '".$from_host."';"); |
| | | $this->db->query("DELETE FROM mysql.db WHERE Db = '".$conf['mysql']['database']."' AND Host = '".$from_host."';"); |
| | | $this->db->query('FLUSH PRIVILEGES;'); |
| | | |
| | | //* Create the ISPConfig database user |
| | | $query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON '.$cf['database'].".* " |
| | | ."TO '".$cf['ispconfig_user']."'@'".$from_host."' " |
| | | ."IDENTIFIED BY '".$cf['ispconfig_password']."';"; |
| | | //* Create the ISPConfig database user in the local database |
| | | $query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON '.$conf['mysql']['database'].".* " |
| | | ."TO '".$conf['mysql']['ispconfig_user']."'@'".$from_host."' " |
| | | ."IDENTIFIED BY '".$conf['mysql']['ispconfig_password']."';"; |
| | | if(!$this->db->query($query)) { |
| | | $this->error('Unable to create database user: '.$cf['ispconfig_user'].' Error: '.$this->db->errorMessage); |
| | | $this->error('Unable to create database user: '.$conf['mysql']['ispconfig_user'].' Error: '.$this->db->errorMessage); |
| | | } |
| | | |
| | | //* Reload database privelages |
| | | $this->db->query('FLUSH PRIVILEGES;'); |
| | | |
| | | //* Set the database name in the DB library |
| | | $this->db->dbName = $cf['database']; |
| | | $this->db->dbName = $conf['mysql']['database']; |
| | | |
| | | $server_ini_content = rf("tpl/server.ini.master"); |
| | | $server_ini_content = mysql_real_escape_string($server_ini_content); |
| | | |
| | | $sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', 1, 1, 1, 1, 1, 1, '$server_ini_content', 0, 1);"; |
| | | $this->db->query($sql); |
| | | $conf['server_id'] = $this->db->insertID(); |
| | | $conf['server_id'] = $conf['server_id']; |
| | | if($conf['mysql']['master_slave_setup'] == 'y') { |
| | | |
| | | //* Insert the server record in master DB |
| | | $sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', 1, 1, 1, 1, 1, 1, '$server_ini_content', 0, 1);"; |
| | | $this->dbmaster->query($sql); |
| | | $conf['server_id'] = $this->dbmaster->insertID(); |
| | | $conf['server_id'] = $conf['server_id']; |
| | | |
| | | //* Insert the same record in the local DB |
| | | $sql = "INSERT INTO `server` (`server_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES ('".$conf['server_id']."',1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', 1, 1, 1, 1, 1, 1, '$server_ini_content', 0, 1);"; |
| | | $this->db->query($sql); |
| | | |
| | | //* insert the ispconfig user in the remote server |
| | | $from_host = $conf['hostname']; |
| | | |
| | | //* username for the ispconfig user |
| | | $conf['mysql']['master_ispconfig_user'] = 'ispconfigserver'.$conf['server_id']; |
| | | |
| | | //* Delete ISPConfig user in the local database, in case that it exists |
| | | $this->dbmaster->query("DELETE FROM mysql.user WHERE User = '".$conf['mysql']['master_ispconfig_user']."' AND Host = '".$from_host."';"); |
| | | $this->dbmaster->query("DELETE FROM mysql.db WHERE Db = '".$conf['mysql']['master_database']."' AND Host = '".$from_host."';"); |
| | | $this->dbmaster->query('FLUSH PRIVILEGES;'); |
| | | |
| | | //* Create the ISPConfig database user in the local database |
| | | $query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON '.$conf['mysql']['master_database'].".* " |
| | | ."TO '".$conf['mysql']['master_ispconfig_user']."'@'".$from_host."' " |
| | | ."IDENTIFIED BY '".$conf['mysql']['master_ispconfig_password']."';"; |
| | | if(!$this->dbmaster->query($query)) { |
| | | $this->error('Unable to create database user in master database: '.$conf['mysql']['master_ispconfig_user'].' Error: '.$this->dbmaster->errorMessage); |
| | | } |
| | | |
| | | } else { |
| | | //* Insert the server, if its not a mster / slave setup |
| | | $sql = "INSERT INTO `server` (`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_name`, `mail_server`, `web_server`, `dns_server`, `file_server`, `db_server`, `vserver_server`, `config`, `updated`, `active`) VALUES (1, 1, 'riud', 'riud', 'r', '".$conf['hostname']."', 1, 1, 1, 1, 1, 1, '$server_ini_content', 0, 1);"; |
| | | $this->db->query($sql); |
| | | $conf['server_id'] = $this->db->insertID(); |
| | | $conf['server_id'] = $conf['server_id']; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
| | | $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
| | | |
| | | $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
| | | $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
| | | $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
| | | |
| | | $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
| | | wf("$install_dir/interface/lib/$configfile", $content); |
| | | |
| | |
| | | $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
| | | $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
| | | |
| | | $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content); |
| | | $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content); |
| | | $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content); |
| | | $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content); |
| | | |
| | | $content = str_replace('{server_id}', $conf['server_id'], $content); |
| | | $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content); |
| | | wf("$install_dir/server/lib/$configfile", $content); |
| | |
| | | if($conf["start_db"] == true) { |
| | | $this->load('db_'.$conf["db_type"]); |
| | | $this->db = new db; |
| | | |
| | | /* |
| | | Initialize the connection to the master DB, |
| | | if we are in a multiserver setup |
| | | */ |
| | | |
| | | if($conf["dbmaster_host"] != '' && $conf["dbmaster_host"] != $conf["db_host"]) { |
| | | $this->dbmaster = new db; |
| | | if($this->dbmaster->linkId) $this->dbmaster->closeConn(); |
| | | $this->dbmaster->dbHost = $conf["dbmaster_host"]; |
| | | $this->dbmaster->dbName = $conf["dbmaster_database"]; |
| | | $this->dbmaster->dbUser = $conf["dbmaster_user"]; |
| | | $this->dbmaster->dbPass = $conf["dbmaster_password"]; |
| | | } else { |
| | | $this->dbmaster = $this->db; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | global $app,$conf; |
| | | |
| | | // TODO: process only new entries. |
| | | $sql = "SELECT * FROM sys_datalog WHERE server_id = ".$conf["server_id"]." ORDER BY datalog_id"; |
| | | $records = $app->db->queryAllRecords($sql); |
| | | foreach($records as $rec) { |
| | | $data = unserialize(stripslashes($rec["data"])); |
| | | $this->raiseTableHook($rec["dbtable"],$rec["action"],$data); |
| | | $app->db->query("DELETE FROM sys_datalog WHERE datalog_id = ".$rec["datalog_id"]); |
| | | $app->log("Deleting sys_datalog ID ".$rec["datalog_id"],LOGLEVEL_DEBUG); |
| | | //* If its a multiserver setup |
| | | if($app->db->dbHost != $app->dbmaster->dbHost) { |
| | | $sql = "SELECT * FROM sys_datalog WHERE server_id = ".$conf["server_id"]." ORDER BY datalog_id"; |
| | | $records = $app->dbmaster->queryAllRecords($sql); |
| | | foreach($records as $d) { |
| | | |
| | | $data = unserialize(stripslashes($d["data"])); |
| | | $replication_error = false; |
| | | |
| | | if($d["action"] == 'i') { |
| | | $idx = explode(":",$d["dbidx"]); |
| | | $tmp_sql1 = ''; |
| | | $tmp_sql2 = ''; |
| | | foreach($data['new'] as $fieldname => $val) { |
| | | $tmp_sql1 .= "$fieldname,"; |
| | | $tmp_sql2 .= "'$val',"; |
| | | } |
| | | $tmp_sql1 = substr($tmp_sql1,0,-1); |
| | | $tmp_sql2 = substr($tmp_sql2,0,-1); |
| | | //$tmp_sql1 .= "$idx[0]"; |
| | | //$tmp_sql2 .= "$idx[1]"; |
| | | $sql = "INSERT INTO $d[dbtable] ($tmp_sql1) VALUES ($tmp_sql2)"; |
| | | $app->db->query($sql); |
| | | if($app->db->errorNumber > 0) { |
| | | $replication_error = true; |
| | | $app->log("Replication failed. Error: ".$app->db->errorMessage,LOGLEVEL_ERROR); |
| | | } |
| | | $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG); |
| | | } |
| | | |
| | | if($d["action"] == 'u') { |
| | | $sql = "UPDATE $d[dbtable] SET "; |
| | | foreach($data['new'] as $fieldname => $val) { |
| | | $sql .= "$fieldname = '$val',"; |
| | | } |
| | | $sql = substr($sql,0,-1); |
| | | $idx = explode(":",$d["dbidx"]); |
| | | $sql .= " WHERE $idx[0] = $idx[1]"; |
| | | $app->db->query($sql); |
| | | if($app->db->errorNumber > 0) { |
| | | $replication_error = true; |
| | | $app->log("Replication failed. Error: ".$app->db->errorMessage,LOGLEVEL_ERROR); |
| | | } |
| | | $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG); |
| | | } |
| | | |
| | | if($d["action"] == 'd') { |
| | | $idx = explode(":",$d["dbidx"]); |
| | | $sql = "DELETE FROM $d[dbtable] SET "; |
| | | $sql .= " WHERE $idx[0] = $idx[1]"; |
| | | $app->db->query($sql); |
| | | if($app->db->errorNumber > 0) { |
| | | $replication_error = true; |
| | | $app->log("Replication failed. Error: ".$app->db->errorMessage,LOGLEVEL_ERROR); |
| | | } |
| | | $app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG); |
| | | } |
| | | |
| | | |
| | | if($replication_error == false) { |
| | | $this->raiseTableHook($d["dbtable"],$d["action"],$data); |
| | | $app->dbmaster->query("DELETE FROM sys_datalog WHERE datalog_id = ".$d["datalog_id"]); |
| | | $app->log("Deleting sys_datalog ID ".$d["datalog_id"],LOGLEVEL_DEBUG); |
| | | } else { |
| | | $app->log("Error in Repliction, changes were not processed.",LOGLEVEL_ERROR); |
| | | } |
| | | } |
| | | |
| | | //* if we have a single server setup |
| | | } else { |
| | | $sql = "SELECT * FROM sys_datalog WHERE server_id = ".$conf["server_id"]." ORDER BY datalog_id"; |
| | | $records = $app->db->queryAllRecords($sql); |
| | | foreach($records as $rec) { |
| | | $data = unserialize(stripslashes($rec["data"])); |
| | | $this->raiseTableHook($rec["dbtable"],$rec["action"],$data); |
| | | $app->db->query("DELETE FROM sys_datalog WHERE datalog_id = ".$rec["datalog_id"]); |
| | | $app->log("Deleting sys_datalog ID ".$rec["datalog_id"],LOGLEVEL_DEBUG); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | function raiseTableHook($table_name,$action,$data) { |
| | |
| | | */ |
| | | |
| | | // Check if there is anything to update |
| | | $tmp_rec = $app->db->queryOneRecord("SELECT count(server_id) as number from sys_datalog WHERE server_id = ".$conf["server_id"]); |
| | | $tmp_rec = $app->dbmaster->queryOneRecord("SELECT count(server_id) as number from sys_datalog WHERE server_id = ".$conf["server_id"]); |
| | | $tmp_num_records = $tmp_rec["number"]; |
| | | unset($tmp_rec); |
| | | |