install/sql/incremental/upd_0055.sql
New file @@ -0,0 +1,2 @@ ALTER TABLE `web_backup` CHANGE `backup_type` `backup_type` enum('web','mongodb','mysql') NOT NULL DEFAULT 'web'; ALTER TABLE `web_database_user` ADD `database_password_mongo` varchar(32) DEFAULT NULL AFTER `database_password`; install/sql/ispconfig3.sql
@@ -1632,7 +1632,7 @@ `backup_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `server_id` int(10) unsigned NOT NULL, `parent_domain_id` int(10) unsigned NOT NULL, `backup_type` enum('web','mysql') NOT NULL DEFAULT 'web', `backup_type` enum('web','mongodb','mysql') NOT NULL DEFAULT 'web', `backup_mode` varchar(64) NOT NULL DEFAULT '', `tstamp` int(10) unsigned NOT NULL, `filename` varchar(255) NOT NULL, @@ -1688,6 +1688,7 @@ `database_user` varchar(64) DEFAULT NULL, `database_user_prefix` varchar(50) NOT NULL default '', `database_password` varchar(64) DEFAULT NULL, `database_password_mongo` varchar(32) DEFAULT NULL, PRIMARY KEY (`database_user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; interface/lib/classes/tform.inc.php
interface/lib/classes/tools_monitor.inc.php
@@ -453,6 +453,40 @@ return $html; } function showMongoDB() { global $app; /* fetch the Data from the DB */ $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'log_mongodb' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); if(isset($record['data'])) { $html = '<div class="systemmonitor-state state-'.$record['state'].'"> <div class="systemmonitor-content icons32 ico-'.$record['state'].'">'; /* * First, we have to detect, if there is any monitoring-data. * If not (because mongodb is not installed) show this. */ $data = unserialize($record['data']); if ($data == '') { $html .= '<p>'. 'MongoDB is not installed at this server.<br />' . 'See more (for debian) <a href="http://www.howtoforge.com/fail2ban_debian_etch" target="htf">here...</a>'. '</p>'; } else { $html .= nl2br($data); } $html .= '</div></div>'; } else { $html = '<p>There is no data available at the moment.</p>'; } return $html; } function showIPTables() { global $app; $record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'iptables_rules' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc"); interface/lib/shelluser_blacklist
@@ -32,3 +32,4 @@ ispconfig courier dovecot mongodb interface/web/admin/form/server_config.tform.php
@@ -1301,6 +1301,12 @@ 'value' => array(0 => 'n', 1 => 'y') ), 'do_not_try_rescue_httpd' => array( 'datatype' => 'VARCHAR', 'formtype' => 'CHECKBOX', 'default' => 'n', 'value' => array(0 => 'n', 1 => 'y') ), 'do_not_try_rescue_mongodb' => array( 'datatype' => 'VARCHAR', 'formtype' => 'CHECKBOX', 'default' => 'n', interface/web/admin/lib/lang/de_server_config.lng
@@ -146,6 +146,7 @@ $wb['fastcgi_config_syntax_txt'] = 'FastCGI Konfigurations Syntax'; $wb['try_rescue_txt'] = 'Aktiviere Service Monitoring und Neustart bei Unerreichbarkeit'; $wb['do_not_try_rescue_httpd_txt'] = 'Deaktiviere HTTPD Monitoring'; $wb['do_not_try_rescue_mongodb_txt'] = 'Deaktiviere MongoDB Monitoring'; $wb['do_not_try_rescue_mysql_txt'] = 'Deaktiviere MySQL Monitoring'; $wb['do_not_try_rescue_mail_txt'] = 'Deaktiviere E-Mail Monitoring'; $wb['rescue_description_txt'] = '<b>Information:</b> Falls Sie MySQL stoppen möchten, wählen Sie die Funktion \'Deaktiviere MySQL Monitoring\' und warten Sie 2 bis 3 Minuten. Wenn Sie nicht 2 bis 3 Miunten warten wird ISPConfig versuchen MySQL wieder zu starten.'; interface/web/admin/lib/lang/en_server_config.lng
@@ -151,6 +151,7 @@ $wb["php_fpm_socket_dir_error_empty"] = 'PHP-FPM socket directory is empty.'; $wb["try_rescue_txt"] = 'Enable service monitoring and restart on failure'; $wb["do_not_try_rescue_httpd_txt"] = 'Disable HTTPD monitoring'; $wb["do_not_try_rescue_mongodb_txt"] = 'Disable MongoDB monitoring'; $wb["do_not_try_rescue_mysql_txt"] = 'Disable MySQL monitoring'; $wb["do_not_try_rescue_mail_txt"] = 'Disable Email monitoring'; $wb["rescue_description_txt"] = '<b>Information:</b> If you want to shut down mysql you have to select the "Disable MySQL monitor" checkbox and then wait 2-3 minutes.<br>If you do not wait 2-3 minutes, rescue will try to restart mysql!'; interface/web/admin/templates/server_config_rescue_edit.htm
@@ -18,6 +18,12 @@ </div> </div> <div class="ctrlHolder"> <p class="label" style="width:300px">{tmpl_var name='do_not_try_rescue_mongodb_txt'}</p> <div class="multiField" style="width:100px"> {tmpl_var name='do_not_try_rescue_mongodb'} </div> </div> <div class="ctrlHolder"> <p class="label" style="width:300px">{tmpl_var name='do_not_try_rescue_mysql_txt'}</p> <div class="multiField" style="width:100px"> {tmpl_var name='do_not_try_rescue_mysql'} interface/web/monitor/lib/lang/de.lng
@@ -122,6 +122,7 @@ $wb['monitor_services_pop_txt'] = 'POP3 Server:'; $wb['monitor_services_imap_txt'] = 'IMAP Server:'; $wb['monitor_services_mydns_txt'] = 'DNS Server:'; $wb['monitor_services_mongodb_txt'] = 'MongoDB Server:'; $wb['monitor_services_mysql_txt'] = 'MySQL Server:'; $wb['monitor_settings_datafromdate_txt'] = 'Daten vom: '; $wb['monitor_settings_datetimeformat_txt'] = 'd.m.Y H:i'; @@ -134,6 +135,7 @@ $wb['monitor_title_rkhunterlog_txt'] = 'RKHunter Protokoll'; $wb['monitor_updates_nosupport_txt'] = 'Ihre Distribution wird für die Überwachung nicht unterstützt'; $wb['monitor_title_fail2ban_txt'] = 'Fail2Ban Protokoll'; $wb['monitor_title_mongodb_txt'] = 'MongoDB Protokoll'; $wb['monitor_nosupportedraid1_txt'] = 'At the moment, we support mdadm or mpt-status for monitoring the RAID.<br>We cant find any of them at your server.<br><br>This means we can not support your RAID yet.'; $wb['monitor_serverstate_beancounterok_txt'] = 'The beancounter is ok'; $wb['monitor_serverstate_beancounterinfo_txt'] = 'There are vew failure in the beancounter'; @@ -144,6 +146,7 @@ $wb['monitor_beancounter_nosupport_txt'] = 'This server is not a OpenVz VE and has no beancounter information'; $wb['monitor_title_iptables_txt'] = 'IPTables Regeln'; $wb['Show fail2ban-Log'] = 'Fail2ban Protokoll anzeigen'; $wb['Show MongoDB-Log'] = 'MongoDB Protokoll anzeigen'; $wb['Show IPTables'] = 'IPTables anzeigen'; $wb['Show OpenVz VE BeanCounter'] = 'OpenVz VE BeanCounter anzeigen'; $wb['Show Monit'] = 'Monit anzeigen'; interface/web/monitor/lib/lang/en.lng
@@ -46,6 +46,7 @@ $wb['Show RKHunter-Log'] = 'Show RKHunter-Log'; $wb['Show Jobqueue'] = 'Show Jobqueue'; $wb['Show fail2ban-Log'] = 'Show fail2ban-Log'; $wb['Show MongoDB-Log'] = 'Show MongoDB-Log'; $wb['Show IPTables'] = 'Show IPTables'; $wb['Show OpenVz VE BeanCounter'] = 'Show OpenVz VE BeanCounter'; $wb['monitor_general_serverstate_txt'] = 'Server State'; @@ -131,6 +132,7 @@ $wb['monitor_services_pop_txt'] = 'POP3-Server:'; $wb['monitor_services_imap_txt'] = 'IMAP-Server:'; $wb['monitor_services_mydns_txt'] = 'DNS-Server:'; $wb['monitor_services_mongodb_txt'] = 'MongoDB-Server:'; $wb['monitor_services_mysql_txt'] = 'mySQL-Server:'; $wb['monitor_settings_datafromdate_txt'] = 'Data from: '; $wb['monitor_settings_datetimeformat_txt'] = 'Y-m-d H:i'; @@ -142,6 +144,7 @@ $wb['monitor_title_raidstate_txt'] = 'RAID Status'; $wb['monitor_title_rkhunterlog_txt'] = 'RKHunter Log'; $wb['monitor_title_fail2ban_txt'] = 'Fail2Ban Log'; $wb['monitor_title_mongodb_txt'] = 'MongoDB Log'; $wb['monitor_title_iptables_txt'] = 'IPTables Rules'; $wb['monitor_title_beancounter_txt'] = 'OpenVz VE BeanCounter'; $wb['monitor_updates_nosupport_txt'] = 'Your distribution is not supported for this monitoring'; interface/web/monitor/lib/module.conf.php
@@ -190,6 +190,11 @@ 'link' => 'monitor/show_data.php?type=fail2ban', 'html_id' => 'fai2ban'); $items[] = array( 'title' => "Show MongoDB-Log", 'target' => 'content', 'link' => 'monitor/show_data.php?type=mongodb', 'html_id' => 'mongodb'); $items[] = array( 'title' => "Show IPTables", 'target' => 'content', 'link' => 'monitor/show_data.php?type=iptables', interface/web/monitor/show_data.php
@@ -124,6 +124,13 @@ $title = $app->lng("monitor_title_fail2ban_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'mongodb': $template = 'templates/show_data.htm'; $output .= $app->tools_monitor->showMongoDB(); $time = $app->tools_monitor->getDataTime('log_mongodb'); $title = $app->lng("monitor_title_mongodb_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')'; $description = ''; break; case 'iptables': $template = 'templates/show_data.htm'; $output .= $app->tools_monitor->showIPTables(); interface/web/sites/database_user_edit.php
@@ -147,6 +147,11 @@ $this->dataRecord['database_user'] = substr($dbuser_prefix . $this->dataRecord['database_user'], 0, 16); } /* prepare password for MongoDB */ // TODO: this still doens't work as when only the username changes we have no database_password. // taking the one from oldData doesn't work as it's encrypted...shit! $this->dataRecord['database_password_mongo'] = $this->dataRecord['database_user'].":mongo:".$this->dataRecord['database_password']; $this->dataRecord['server_id'] = 0; // we need this on all servers parent::onBeforeUpdate(); @@ -181,6 +186,9 @@ $this->dataRecord['server_id'] = 0; // we need this on all servers /* prepare password for MongoDB */ $this->dataRecord['database_password_mongo'] = $this->dataRecord['database_user'].":mongo:".$this->dataRecord['database_password']; parent::onBeforeInsert(); } interface/web/sites/form/database.tform.php
@@ -89,7 +89,10 @@ 'datatype' => 'VARCHAR', 'formtype' => 'SELECT', 'default' => 'y', 'value' => array('mysql' => 'MySQL') 'value' => array( 'mongo' => 'MongoDB', 'mysql' => 'MySQL' ) ), 'database_name' => array ( 'datatype' => 'VARCHAR', interface/web/sites/form/database_user.tform.php
@@ -103,6 +103,14 @@ 'datatype' => 'VARCHAR', 'formtype' => 'PASSWORD', 'encryption' => 'MYSQL', 'default' => '', 'value' => '', 'width' => '30', 'maxlength' => '255' ), 'database_password_mongo' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'PASSWORD', 'default' => '', 'value' => '', 'width' => '30', interface/web/sites/lib/lang/de_database_admin_list.lng
@@ -2,6 +2,7 @@ $wb['list_head_txt'] = 'Datenbank'; $wb['active_txt'] = 'Aktiv'; $wb['remote_access_txt'] = 'Remotezugriff'; $wb['type_txt'] = 'Typ'; $wb['server_id_txt'] = 'Server'; $wb['database_user_txt'] = 'Datenbank Benutzer'; $wb['database_name_txt'] = 'Datenbankname'; interface/web/sites/lib/lang/de_database_list.lng
@@ -2,6 +2,7 @@ $wb['list_head_txt'] = 'Datenbank'; $wb['active_txt'] = 'Aktiv'; $wb['remote_access_txt'] = 'Remotezugriff'; $wb['type_txt'] = 'Typ'; $wb['server_id_txt'] = 'Server'; $wb['database_name_txt'] = 'Datenbankname'; $wb['add_new_record_txt'] = 'Neue Datenbank hinzufügen'; interface/web/sites/lib/lang/de_web_backup_list.lng
@@ -10,6 +10,7 @@ $wb['restore_confirm_txt'] = 'Die Wiederherstellung wird existierende Dateien in Ihrer Website überschreiben. Möchten Sie dieses Backup wirklich zurückspielen?'; $wb['download_pending_txt'] = 'Es liegt bereits ein Backup Download Job an.'; $wb['restore_pending_txt'] = 'Es liegt bereits ein Backup Wiederherstellungs Job an.'; $wb['backup_type_mongodb'] = 'MongoDB Datenbank'; $wb['backup_type_mysql'] = 'MySQL Datenbank'; $wb['backup_type_web'] = 'Webseiten Dateien'; ?> interface/web/sites/lib/lang/en_database_admin_list.lng
@@ -2,6 +2,7 @@ $wb["list_head_txt"] = 'Database'; $wb["active_txt"] = 'Active'; $wb["remote_access_txt"] = 'Remote Access'; $wb['type_txt'] = 'Type'; $wb["server_id_txt"] = 'Server'; $wb["database_user_txt"] = 'Database user'; $wb["database_name_txt"] = 'Database name'; interface/web/sites/lib/lang/en_database_list.lng
@@ -2,6 +2,7 @@ $wb["list_head_txt"] = 'Database'; $wb["active_txt"] = 'Active'; $wb["remote_access_txt"] = 'Remote Access'; $wb['type_txt'] = 'Type'; $wb["server_id_txt"] = 'Server'; $wb["database_user_txt"] = 'Database user'; $wb["database_name_txt"] = 'Database name'; interface/web/sites/lib/lang/en_web_backup_list.lng
@@ -11,6 +11,7 @@ $wb['restore_confirm_txt'] = 'Restoring will overwrite existing files in your website. Do you really want to restore this backup?'; $wb['download_pending_txt'] = 'There is already a pending backup download job.'; $wb['restore_pending_txt'] = 'There is already a pending backup restore job.'; $wb['backup_type_mongodb'] = 'MongoDB Database'; $wb['backup_type_mysql'] = 'MySQL Database'; $wb['backup_type_web'] = 'Website files'; interface/web/sites/list/database.list.php
@@ -70,6 +70,19 @@ 'width' => "", 'value' => array('y' => "<div id=\"ir-Yes\" class=\"swap\"><span>Yes</span></div>",'n' => "<div class=\"swap\" id=\"ir-No\"><span>No</span></div>")); $liste["item"][] = array( 'field' => "type", 'datatype' => "VARCHAR", 'formtype' => "SELECT", 'op' => "=", 'prefix' => "", 'suffix' => "", 'width' => "", 'value' => array( 'mongo' => "MongoDB", 'mysql' => "MySQL" ) ); if($_SESSION['s']['user']['typ'] == 'admin') { $liste["item"][] = array( 'field' => "sys_groupid", 'datatype' => "INTEGER", interface/web/sites/templates/database_admin_list.htm
@@ -19,6 +19,7 @@ <tr class="caption"> <th class="tbl_col_active" scope="col"><tmpl_var name="active_txt"></th> <th class="tbl_col_remote_access" scope="col"><tmpl_var name="remote_access_txt"></th> <th class="tbl_col_type" scope="col"><tmpl_var name="type_txt"></th> <th class="tbl_col_sys_groupid" scope="col"><tmpl_var name="sys_groupid_txt"></th> <th class="tbl_col_server_id" scope="col"><tmpl_var name="server_id_txt"></th> <th class="tbl_col_database_user_id" scope="col"><tmpl_var name="database_user_txt"></th> @@ -28,6 +29,7 @@ <tr class="filter"> <td class="tbl_col_active"><select name="search_active">{tmpl_var name='search_active'}</select></td> <td class="tbl_col_remote_access"><select name="search_remote_access">{tmpl_var name='search_remote_access'}</select></td> <td class="tbl_col_type"><select name="search_type">{tmpl_var name='search_type'}</select></td> <td class="tbl_col_sys_groupid"><select name="search_sys_groupid">{tmpl_var name='search_sys_groupid'}</select></td> <td class="tbl_col_server_id"><select name="search_server_id">{tmpl_var name='search_server_id'}</select></td> <td class="tbl_col_database_user"><select name="search_database_user_id">{tmpl_var name='search_database_user_id'}</select></td> @@ -42,6 +44,7 @@ <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>"> <td class="tbl_col_active"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="active"}</a></td> <td class="tbl_col_remote_access"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="remote_access"}</a></td> <td class="tbl_col_type"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="type"}</a></td> <td class="tbl_col_sys_groupid"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="sys_groupid"}</a></td> <td class="tbl_col_server_id"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="server_id"}</a></td> <td class="tbl_col_database_user"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="database_user_id"}</a></td> @@ -51,19 +54,19 @@ <a class="button icons16 icoDbAdmin" href="sites/database_phpmyadmin.php?id={tmpl_var name='id'}" target="phpmyadmin"><span>{tmpl_var name='admin_txt'}</span></a> </tmpl_if> <a class="button icons16 icoEdit" href="javascript: loadContent('sites/database_edit.php?id={tmpl_var name='id'}');"><span>{tmpl_var name='edit_txt'}</span></a> <a class="button icons16 icoDelete" href="javascript: del_record('sites/database_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a> <a class="button icons16 icoDelete" href="javascript: del_record('sites/database_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a> </td> </tr> </tmpl_loop> <tmpl_unless name="records"> <tr class="tbl_row_noresults tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>"> <td colspan="7">{tmpl_var name='globalsearch_noresults_text_txt'}</td> <td colspan="8">{tmpl_var name='globalsearch_noresults_text_txt'}</td> </tr> </tmpl_unless> </tbody> <tfoot> <tr> <td class="tbl_footer tbl_paging" colspan="7"><tmpl_var name="paging"></td> <td class="tbl_footer tbl_paging" colspan="8"><tmpl_var name="paging"></td> </tr> </tfoot> </table> interface/web/sites/templates/database_list.htm
@@ -36,6 +36,7 @@ <tr class="caption"> <th class="tbl_col_active" scope="col"><tmpl_var name="active_txt"></th> <th class="tbl_col_remote_access" scope="col"><tmpl_var name="remote_access_txt"></th> <th class="tbl_col_type" scope="col"><tmpl_var name="type_txt"></th> <th class="tbl_col_server_id" scope="col"><tmpl_var name="server_id_txt"></th> <th class="tbl_col_database_user_id" scope="col"><tmpl_var name="database_user_txt"></th> <th class="tbl_col_database_name" scope="col"><tmpl_var name="database_name_txt"></th> @@ -44,6 +45,7 @@ <tr class="filter"> <td class="tbl_col_active"><select name="search_active">{tmpl_var name='search_active'}</select></td> <td class="tbl_col_remote_access"><select name="search_remote_access">{tmpl_var name='search_remote_access'}</select></td> <td class="tbl_col_type"><select name="search_type">{tmpl_var name='search_type'}</select></td> <td class="tbl_col_server_id"><select name="search_server_id">{tmpl_var name='search_server_id'}</select></td> <td class="tbl_col_database_user_id"><select name="search_database_user_id">{tmpl_var name='search_database_user_id'}</select></td> <td class="tbl_col_database_name"><input type="text" name="search_database_name" value="{tmpl_var name='search_database_name'}"/></td> @@ -57,6 +59,7 @@ <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>"> <td class="tbl_col_active"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="active"}</a></td> <td class="tbl_col_remote_access"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="remote_access"}</a></td> <td class="tbl_col_type"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="type"}</a></td> <td class="tbl_col_server_id"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="server_id"}</a></td> <td class="tbl_col_database_user"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="database_user_id"}</a></td> <td class="tbl_col_database_name"><a href="#" onclick="loadContent('sites/database_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="database_name"}</a></td> @@ -65,19 +68,19 @@ <a class="button icons16 icoDbAdmin" href="sites/database_phpmyadmin.php?id={tmpl_var name='id'}" target="phpmyadmin"><span>{tmpl_var name='admin_txt'}</span></a> </tmpl_if> <a class="button icons16 icoEdit" href="javascript: loadContent('sites/database_edit.php?id={tmpl_var name='id'}');"><span>{tmpl_var name='edit_txt'}</span></a> <a class="button icons16 icoDelete" href="javascript: del_record('sites/database_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a> <a class="button icons16 icoDelete" href="javascript: del_record('sites/database_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a> </td> </tr> </tmpl_loop> <tmpl_unless name="records"> <tr class="tbl_row_noresults tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>"> <td colspan="6">{tmpl_var name='globalsearch_noresults_text_txt'}</td> <td colspan="7">{tmpl_var name='globalsearch_noresults_text_txt'}</td> </tr> </tmpl_unless> </tbody> <tfoot> <tr> <td class="tbl_footer tbl_paging" colspan="6"><tmpl_var name="paging"></td> <td class="tbl_footer tbl_paging" colspan="7"><tmpl_var name="paging"></td> </tr> </tfoot> </table> server/cron_daily.php
@@ -764,7 +764,6 @@ send_notification_email('web_traffic_notification', $placeholders, $recipients); } } else { //* unlock the website, if traffic is lower then quota if($rec['traffic_quota_lock'] == 'y') { @@ -1232,9 +1231,11 @@ chown($db_backup_dir, 'root'); chgrp($db_backup_dir, 'root'); //* Do the mysql database backup with mysqldump //* Do the mysql database backup with mysqldump or mongodump $db_id = $rec['database_id']; $db_name = $rec['database_name']; if ($rec['type'] == 'mysql') { $db_backup_file = 'db_'.$db_name.'_'.date('Y-m-d_H-i').'.sql'; $command = "mysqldump -h '".escapeshellcmd($clientdb_host)."' -u '".escapeshellcmd($clientdb_user)."' -p'".escapeshellcmd($clientdb_password)."' -c --add-drop-table --create-options --quick --result-file='".$db_backup_dir.'/'.$db_backup_file."' '".$db_name."'"; exec($command, $tmp_output, $retval); @@ -1259,6 +1260,43 @@ } //* Remove the uncompressed file if(is_file($db_backup_dir.'/'.$db_backup_file)) unlink($db_backup_dir.'/'.$db_backup_file); } else if ($rec['type'] == 'mongo') { $db_backup_file = 'db_'.$db_name.'_'.date('Y-m-d_H-i'); try { $connection = new MongoClient("mongodb://root:123456@127.0.0.1:27017/admin"); $db = $connection->selectDB($db_name); // exclude not supported by mongodump, only get user collections $collections = $db->getCollectionNames(false); foreach ($collections as $collection) { // mongodump -h 127.0.0.1 --port 27017 -u root -p 123456 --authenticationDatabase admin -d <db> -c <table> -o /tmp/test $command = "mongodump -h 127.0.0.1 --port 27017 -u root -p 123456 --authenticationDatabase admin -d ".escapeshellcmd($db_name)." -c ".escapeshellcmd($collection)." -o ".escapeshellcmd($db_backup_dir.'/'.$db_backup_file); exec($command); } if (is_dir(escapeshellcmd($db_backup_dir.'/'.$db_backup_file))) { //* Compress the backup with gzip exec("cd ".escapeshellcmd($db_backup_dir)." && tar -pczf ".escapeshellcmd($db_backup_dir.'/'.$db_backup_file).".tar.gz ".escapeshellcmd($db_backup_file)); chmod($db_backup_dir.'/'.$db_backup_file.'.tar.gz', 0750); chown($db_backup_dir.'/'.$db_backup_file.'.tar.gz', fileowner($db_backup_dir)); chgrp($db_backup_dir.'/'.$db_backup_file.'.tar.gz', filegroup($db_backup_dir)); //* Insert web backup record in database $sql = "INSERT INTO web_backup (server_id,parent_domain_id,backup_type,backup_mode,tstamp,filename) VALUES (".$conf['server_id'].",$web_id,'mongodb','rootgz',".time().",'".$app->db->quote($db_backup_file).".tar.gz')"; $app->db->query($sql); if ($app->db->dbHost != $app->dbmaster->dbHost) { $app->dbmaster->query($sql); } //* Remove the uncompressed file exec("rm -rf ".escapeshellcmd($db_backup_dir.'/'.$db_backup_file)); } } catch (MongoConnnectionException $e) { // connecting to MongoDB failed - cannot create backup } } //* Remove old backups $backup_copies = intval($rec['backup_copies']); @@ -1266,7 +1304,7 @@ $dir_handle = dir($db_backup_dir); $files = array(); while (false !== ($entry = $dir_handle->read())) { if($entry != '.' && $entry != '..' && preg_match('/^db_(.*?)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}\.sql.gz$/', $entry, $matches) && is_file($db_backup_dir.'/'.$entry)) { if($entry != '.' && $entry != '..' && (preg_match('/^db_(.*?)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}\.sql.gz$/', $entry, $matches) || preg_match('/^db_(.*?)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}\.tar.gz$/', $entry, $matches)) && is_file($db_backup_dir.'/'.$entry)) { if(array_key_exists($matches[1], $files) == false) $files[$matches[1]] = array(); $files[$matches[1]][] = $entry; } server/lib/classes/monitor_tools.inc.php
@@ -755,6 +755,13 @@ $data['mysqlserver'] = 0; $state = 'error'; // because service is down } if ($this->_checkTcp('localhost', 27017)) { $data['mongodbserver'] = 1; } else { $data['mongodbserver'] = 0; $state = 'error'; // because service is down } } /* @@ -1299,6 +1306,51 @@ return $res; } public function monitorMongoDB() { global $conf; /* the id of the server as int */ $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_mongodb'; /* This monitoring is only available if MongoDB is installed */ system('which mongod', $retval); // Debian, Ubuntu, Fedora if ($retval !== 0) system('which mongod', $retval); // CentOS if ($retval === 0) { /* Get the data of the log */ $data = $this->_getLogData($type); /* * At this moment, there is no state (maybe later) */ $state = 'no_state'; } else { /* * MongoDB is not installed, so there is no data and no state * * no_state, NOT unknown, because "unknown" is shown as state * inside the GUI. no_state is hidden. * * We have to write NO DATA inside the DB, because the GUI * could not know, if there is any dat, or not... */ $state = 'no_state'; $data = ''; } /* * Return the Result */ $res['server_id'] = $server_id; $res['type'] = $type; $res['data'] = $data; $res['state'] = $state; return $res; } public function monitorIPTables() { global $conf; @@ -1745,6 +1797,9 @@ $logfile = '/var/log/fail2ban.log'; } break; case 'log_mongodb': $logfile = '/var/log/mongodb/mongodb.log'; break; case 'log_ispconfig': if ($dist == 'debian') { $logfile = $conf['ispconfig_log_dir'] . '/ispconfig.log'; server/mods-available/monitor_core_module.inc.php
@@ -117,6 +117,7 @@ $this->_monitorRaid(); $this->_monitorRkHunter(); $this->_monitorFail2ban(); $this->_monitorMongoDB(); $this->_monitorIPTables(); $this->_monitorSysLog(); } @@ -554,6 +555,31 @@ $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMongoDB() { global $app; /* * First we get the Monitoring-data from the tools */ $res = $this->_tools->monitorMongoDB(); /* * Insert the data into the database */ $sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . 'VALUES (' . $res['server_id'] . ', ' . "'" . $app->dbmaster->quote($res['type']) . "', " . 'UNIX_TIMESTAMP(), ' . "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . "'" . $res['state'] . "'" . ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorIPTables() { global $app; server/mods-available/rescue_core_module.inc.php
@@ -89,6 +89,11 @@ $this->_rescueData = $this->_getRescueData(); /* * rescue MongoDB if needed */ $this->_rescueMongoDB(); /* * rescue mysql if needed (maybe httpd depends on mysql, so try this first!) */ $this->_rescueMySql(); @@ -290,6 +295,72 @@ } /** * restarts MongoDB, if needed */ private function _rescueMongoDB(){ global $app, $conf; /* * do nothing, if it is not allowed to rescue mysql */ if ((isset($conf['serverconfig']['rescue']['do_not_try_rescue_mongodb']) && ($conf['serverconfig']['rescue']['do_not_try_rescue_mongodb']) == 'y')){ return; } /* * if the service is up and running, or the service is not installed there is nothing to do... */ if ($this->_monitoringData[0][0]['data']['mongodbserver'] != 0){ /* Clear the try counter, because we do not have to try to rescue the service */ $this->_rescueData['mongodbserver']['try_counter'] = 0; return; } /* * OK, the service is installed and down. * Maybe this is because of a restart of the service by the admin. * This means, we check the data 1 minute ago */ if ((!isset($this->_monitoringData[1][0]['data']['mongodbserver'])) || ((isset($this->_monitoringData[1][0]['data']['mongodbserver'])) && ($this->_monitoringData[1][0]['data']['mongodbserver'] != 0))){ /* * We do NOT have this data or we have this data, but the webserver was not down 1 minute ago. * This means, it could be, that the admin is restarting the server. * We wait one more minute... */ return; } /*##### * The service is down and it was down 1 minute ago. * We try to rescue it *#####*/ /* Get the try counter */ $tryCount = (!isset($this->_rescueData['mongodbserver']['try_counter']))? 1 : $this->_rescueData['mongodbserver']['try_counter'] + 1; /* Set the new try counter */ $this->_rescueData['mongodbserver']['try_counter'] = $tryCount; /* if 5 times will not work, we have to give up... */ if ($tryCount > 5){ $app->log('MongoDB is down! Rescue will not help!', LOGLEVEL_ERROR); return; } $app->log('MongoDB is down! Try rescue MongoDB (try:' . $tryCount . ')...', LOGLEVEL_WARN); if(is_file($conf['init_scripts'] . '/' . 'mongodb')) { $daemon = 'mongodb'; } else { $daemon = 'mongodb'; } $this->_rescueDaemon($daemon); } /** * restarts mysql, if needed */ private function _rescueMySql(){ server/plugins-available/backup_plugin.inc.php
@@ -81,6 +81,32 @@ } } //* Restore a MongoDB backup if($action_name == 'backup_restore' && $backup['backup_type'] == 'mongodb') { if(file_exists($backup_dir.'/'.$backup['filename'])) { //$parts = explode('_',$backup['filename']); //$db_name = $parts[1]; preg_match('@^db_(.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}\.tar\.gz$@', $backup['filename'], $matches); $db_name = $matches[1]; // extract tar.gz archive $dump_directory = str_replace(".tar.gz", "", $backup['filename']); $extracted = "/usr/local/ispconfig/server/temp"; exec("tar -xzvf ".escapeshellarg($backup_dir.'/'.$backup['filename'])." --directory=".escapeshellarg($extracted)); $restore_directory = $extracted."/".$dump_directory."/".$db_name; // mongorestore -h 127.0.0.1 -u root -p 123456 --authenticationDatabase admin -d c1debug --drop ./toRestore $command = "mongorestore -h 127.0.0.1 --port 27017 -u root -p 123456 --authenticationDatabase admin -d ".$db_name." --drop ".escapeshellarg($restore_directory); exec($command); exec("rm -rf ".escapeshellarg($extracted."/".$dump_directory)); } unset($clientdb_host); unset($clientdb_user); unset($clientdb_password); $app->log('Restored MongoDB backup '.$backup_dir.'/'.$backup['filename'],LOGLEVEL_DEBUG); } //* Restore a mysql backup if($action_name == 'backup_restore' && $backup['backup_type'] == 'mysql') { //* Load sql dump into db server/plugins-available/mongo_clientdb_plugin.inc.php
New file @@ -0,0 +1,820 @@ <?php /* Copyright (c) 2007, Till Brehm, projektfarm Gmbh All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of ISPConfig nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * The MongoDB client plugin is used by ISPConfig to control the management of MongoDB. * If handles everything from creating DBs/Users, update them or delete them. */ class mongo_clientdb_plugin { /** * ISPConfig internal identifiers. */ var $plugin_name = 'mongo_clientdb_plugin'; var $class_name = 'mongo_clientdb_plugin'; /** * This function is called during ISPConfig installation. * It determines if a symlink shall be created for this plugin. * * @return bool true if symlink should be created */ function onInstall() { global $conf; return (bool) $conf['services']['db']; } /** * This function is called when the plugin is loaded. * Each plugin/module needs to register itself to ISPConfig events from which * it want to receive changes/get notified. * * Since this is a MongoDB plugin we are interested in DB changes and everything related * to it, like users. */ function onLoad() { global $app; //* Databases $app->plugins->registerEvent('database_insert',$this->plugin_name,'db_insert'); $app->plugins->registerEvent('database_update',$this->plugin_name,'db_update'); $app->plugins->registerEvent('database_delete',$this->plugin_name,'db_delete'); //* Database users $app->plugins->registerEvent('database_user_insert',$this->plugin_name,'db_user_insert'); $app->plugins->registerEvent('database_user_update',$this->plugin_name,'db_user_update'); $app->plugins->registerEvent('database_user_delete',$this->plugin_name,'db_user_delete'); } /** * MongoDB * ------------------------------------------------------------------------ * The following needs to be done before using this plugin: * - 1. install MongoDB server from 10gen sources (or another one with >= 2.4) * - 2. install php5-dev package (apt-get install php5-dev) * - 3. install mongo PECL extension (pecl install mongo) * - 4. enable mongo (echo "extension=mongo.so" > /etc/php5/mods-available/mongo.ini && php5enmod mongo) * - 5. create administrative user manager in Mongo (mongo -> use admin -> db.addUser({user: "root", pwd: "123456", roles: [ "userAdminAnyDatabase", "readWriteAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin" ]})) * - 6. enable auth for Mongo (nano /etc/mongodb.conf -> auth = true) * - 7. restart MongoDB (service mongodb restart) * * Unlike MySQL, MongoDB manages users per database. * Therefor we cannot use one user for multiple databases. Instead, we have to add him each time via the admin user. */ /** * Stores the MongoDB connection. * @var object */ private $_connection = null; /** * Stores the MongoDB admin user. * @var string */ const USER = "root"; /** * Stores the MongoDB admin password. * @var string */ const PW = "123456"; /** * Stores the MongoDB host address. * @var string */ const HOST = "127.0.0.1"; /** * Stores the MongoDB port. * @var int */ const PORT = 27017; /** * Adds the user to given database. * If no connection exists, the user already exists or the database doesn't exist, * null is returned. * * @param string $db the database to use * @param array $user the user to add * @return bool true if user added */ private function addUser($db, $user) { if ($this->isConnected() && !$this->userExists($db, $user)) { $roles = ""; foreach ($user['roles'] as $index => $role) { $roles .= "\"".$role."\""; if ($index !== count($user['roles']) - 1) { $roles .= ", "; } } return $this->exec($db, "db.system.users.insert({ user: \"".$user['username']."\", pwd: \"".$user['password']."\", roles: [ ".$roles." ] })"); //return $this->exec($db, "db.addUser({ user: \"".$user['username']."\", pwd: \"".$user['password']."\", roles: [ ".$roles." ] })"); } return null; } /** * Changes the users password in given DB. * If no connection exists, the user doesn't exist or the DB doesn't exist, * null is returned. * * @param string $db the database name * @param string $user the user to change * @param string $password the new password * @return bool true if password changes */ private function changePassword($db, $user, $password) { if ($this->isConnected() && $this->dbExists($db) && $this->userExists($db, $user)) { $old_user = $this->getUser($db, $user); if ($this->dropUser($user, $db)) { return $this->addUser($db, array( 'username' => $user, 'password' => $password, 'roles' => $old_user['roles'] )); } return false; } return null; } /** * Connects to the server and authentificates. * If the authentificaten goes wrong or another error encounters, * false is returned. * If we already have an open connection we try to disconnect and connect again. * If this fails, false is returned. * * @return object $connection the MongoDB connection */ private function connect() { try { if ($this->isConnected() && !$this->disconnect()) { return false; } $this->_connection = new MongoClient("mongodb://".self::USER.":".self::PW."@".self::HOST.":".self::PORT."/admin"); return $this->_connection; } catch (MongoConnnectionException $e) { $app->log('Unable to connect to MongoDB: '.$e, LOGLEVEL_ERROR); $this->_connection = null; return false; } } /** * Checks if the database exists. * If no connection exists, * null is returned. * * @param string $db the database name * @return bool true if exists */ private function dbExists($db) { if ($this->isConnected()) { return in_array($db, $this->getDBs()); } return null; } /** * Closes the MongoDB connection. * If no connection exists and nothing is done, * null is returned. * * @return bool true if closed */ private function disconnect() { if ($this->isConnected()) { $status = $this->_connection->close(); if ($status) { $this->_connection = null; } return $status; } return null; } /** * Drops the given database. * If no connection exists or the database doesn't exist, * null is returned. * * @param string $db the database's to drop name */ private function dropDB($db) { if ($this->isConnected() && $this->dbExists($db)) { return (bool) $this->_connection->dropDB($db)['ok']; } return null; } /** * Drops the given user from database. * If no DB is defined, the user is dropped from all databases. * If there's an error when dropping the user from all DBs, an array containing the * names of the failed DBs is returned. * If no connection exists, the database doesn't exist or the user is not in DB, * null is returned. * * @param string $user the user to drop * @param string $db the database name * @return bool true if dropped */ private function dropUser($user, $db = null) { if ($this->isConnected()) { if ($db !== null && $this->dbExists($db) && $this->userExists($db, $user)) { return $this->exec($db, "db.removeUser(\"".$user."\")"); } else { $dbs = $this->getDBs(); if ((bool) $dbs) { $failures = array(); foreach ($dbs as $db) { $exists = $this->userExists($db, $user); if ($exists) { if (!$this->dropUser($user, $db)) { $failures[] = $db; } } } } return (bool) $failures ? $failures : true; } } return null; } /** * Executed the command on the MongoDB server. * If no connection exists and thus nothing can be done, * null is returned. * * @param string $db the database to query * @param string $query the command to execute * @return array the result of the query */ private function exec($db, $query) { if ($this->isConnected()) { $db = $this->selectDB($db); $result = $db->execute($query); if ((bool) $result['ok']) { return $result; } return false; } return null; } /** * Checks if the connection exists. * * @return true if connected */ private function isConnected() { return $this->_connection !== null; } /** * Generates a MongoDB compatible password. * * @param string $user the username * @param string $password the user password * @return string the MD5 string */ private function generatePassword($user, $password) { return md5($user.":mongo:".$password); } /** * Returns the databases found on connection. * If no connection exists and therefor no DBs can be found, * null is returned. * * @return array $names the databases's name */ private function getDBs() { if ($this->isConnected()) { $dbs = $this->_connection->listDBs(); if ((bool) $dbs && isset($dbs['databases'])) { $names = array(); foreach ($dbs['databases'] as $db) { $names[] = $db['name']; } return $names; } } return null; } /** * Returns the user entry for given database. * If no connection exists, the database doesn't exist or the user doesn't exist * null is returned. * * @param string $db the database name * @param string $user the user to return * @return array $user the user in DB */ private function getUser($db, $user) { if ($this->isConnected() && $this->dbExists($db) && $this->userExists($db, $user)) { $result = $this->selectDB($db)->selectCollection("system.users")->find(array( 'user' => $user )); // ugly fix to return user foreach ($result as $user) { return $user; } } return null; } /** * Returns the users for given database. * If no connection exists or the database doesn't exist, * null is returned. * * @param string $db the database name * @return array $users the users in DB */ private function getUsers($db) { if ($this->isConnected() && $this->dbExists($db)) { $result = $this->selectDB($db)->selectCollection("system.users")->find(); $users = array(); foreach ($result as $record) { $users[] = $record['user']; } return $users; } return null; } /** * Checks if the given user exists in given database. * If no connection exists or the given database doesn't exist * null is returned. * * @param string $db the database name * @param string $user the user to check * @return bool true if user exists */ private function userExists($db, $user) { if ($this->isConnected() && $this->dbExists($db)) { $users = $this->getUsers($db); return in_array($user, $users); } return null; } /** * Renames the MongoDB database to provided name. * If no connection exists, the source DB doesn't exist or the target DB already exists, * null is returned. * * @param string $old_name the old database name * @param string $new_name the new database name * @return bool true if renamed */ private function renameDB($old_name, $new_name) { if ($this->isConnected() && $this->dbExists($old_name) && !$this->dbExists($new_name)) { if ($this->exec($old_name, "db.copyDatabase(\"".$old_name."\", \"".$new_name."\", \"".self::HOST."\", \"".self::USER."\", \"".self::PW."\")")) { $this->dropDB($old_name); return true; } return false; } return null; } /** * Switched the selected database. * MongoDB acts on a per-DB level (user management) and we always need to * ensure we have the right DB selected. * If no connection exists and thus nothing is done, * null is returned. * * @param string $db the database to use * @return object the MongoDB database object */ private function selectDB($db) { if ($this->isConnected()) { return $this->_connection->selectDB($db); } return null; } /** * This function is called when a DB is created from within the ISPConfig3 interface. * We need to create the DB and allow all users to connect to it that are choosen. * Since MongoDB doesn't create a DB before any data is stored in it, it's important * to store the users so it contains data -> is created. * * @param string $event_name the name of the event (insert, update, delete) * @param array $data the event data (old and new) * @return only if something is wrong */ function db_insert($event_name, $data) { global $app, $conf; // beside checking for MongoDB we also check if the DB is active because only then we add users // -> MongoDB needs users to create the DB if ($data['new']['type'] == 'mongo' && $data['new']['active'] == 'y') { if ($this->connect() === false) { $app->log("Unable to connect to MongoDB: Connecting using connect() failed.", LOGLEVEL_ERROR); return; } $db_user = $app->db->queryOneRecord("SELECT `database_user`, `database_password_mongo` FROM `web_database_user` WHERE `database_user_id` = '" . intval($data['new']['database_user_id']) . "'"); $db_ro_user = $app->db->queryOneRecord("SELECT `database_user`, `database_password_mongo` FROM `web_database_user` WHERE `database_user_id` = '" . intval($data['new']['database_ro_user_id']) . "'"); $user = $db_user['database_user']; $password = $db_user['database_password_mongo']; $ro_user = $db_ro_user['database_user']; $ro_password = $db_ro_user['database_password_mongo']; $db = $data['new']['database_name']; if ((bool) $db_user) { if ($user == 'root') { $app->log("User root not allowed for client databases", LOGLEVEL_WARNING); } else { if (!$this->addUser($db, array( 'username' => $user, 'password' => $password, 'roles' => array( "readWrite", "dbAdmin" ) ))) { $app->log("Error while adding user: ".$user." to DB: ".$db, LOGLEVEL_WARNING); } } } if ($db_ro_user && $data['new']['database_user_id'] != $data['new']['database_ro_user_id']) { if ($user == 'root') { $app->log("User root not allowed for client databases", LOGLEVEL_WARNING); } else { if (!$this->addUser($db, array( 'username' => $ro_user, 'password' => $ro_password, 'roles' => array( "read" ) ))) { $app->log("Error while adding read-only user: ".$user." to DB: ".$db, LOGLEVEL_WARNING); } } } $this->disconnect(); } } /** * This function is called when a DB is updated from within the ISPConfig interface. * Updating the DB needs a lot of changes. First, we need to recheck all users that * have permissions to access the DB. Maybe we also need to rename the DB and change * it's type (MySQL, MongoDB etc.)...hard work here :) * * @param string $event_name the name of the event (insert, update, delete) * @param array $data the event data (old and new) * @return only if something is wrong */ function db_update($event_name,$data) { global $app, $conf; if ($data['old']['active'] == 'n' && $data['new']['active'] == 'n') { return; } // currently switching from MongoDB <-> MySQL isn't supported if ($data['old']['type'] == 'mongo' && $data['new']['type'] == 'mongo') { if ($this->connect() === false) { $app->log("Unable to connect to MongoDB: Connecting using connect() failed.", LOGLEVEL_ERROR); return; } $db_user = $app->db->queryOneRecord("SELECT `database_user`, `database_password_mongo` FROM `web_database_user` WHERE `database_user_id` = '" . intval($data['new']['database_user_id']) . "'"); $db_ro_user = $app->db->queryOneRecord("SELECT `database_user`, `database_password_mongo` FROM `web_database_user` WHERE `database_user_id` = '" . intval($data['new']['database_ro_user_id']) . "'"); $user = $db_user['database_user']; $password = $db_user['database_password_mongo']; $ro_user = $db_ro_user['database_user']; $ro_password = $db_ro_user['database_password_mongo']; $db = $data['new']['database_name']; // create the database user if database was disabled before if ($data['new']['active'] == 'y' && $data['old']['active'] == 'n') { // since MongoDB creates DBs on-the-fly we can use the db_insert method which takes care of adding // users to a given DB $this->db_insert($event_name, $data); } else if ($data['new']['active'] == 'n' && $data['old']['active'] == 'y') { $users = $this->getUsers($db); if ((bool) $users) { foreach ($users as $user) { $this->dropUser($user, $db); } } } else { // selected user has changed -> drop old one if ($data['new']['database_user_id'] != $data['old']['database_user_id']) { $old_db_user = $app->db->queryOneRecord("SELECT `database_user`, `database_password_mongo` FROM `web_database_user` WHERE `database_user_id` = '" . intval($data['old']['database_user_id']) . "'"); if ((bool) $old_db_user) { if ($old_db_user['database_user'] == 'root') { $app->log("User root not allowed for client databases", LOGLEVEL_WARNING); } else { $this->dropUser($old_db_user['database_user'], $db); } } } // selected read-only user has changed -> drop old one if ($data['new']['database_ro_user_id'] != $data['old']['database_ro_user_id']) { $old_db_user = $app->db->queryOneRecord("SELECT `database_user`, `database_password_mongo` FROM `web_database_user` WHERE `database_user_id` = '" . intval($data['old']['database_ro_user_id']) . "'"); if ((bool) $old_db_user) { if ($old_db_user['database_user'] == 'root') { $app->log("User root not allowed for client databases",LOGLEVEL_WARNING); } else { $this->dropUser($old_db_user['database_user'], $db); } } } // selected user has changed -> add new one if ($data['new']['database_user_id'] != $data['old']['database_user_id']) { if ((bool) $db_user) { if ($user == 'root') { $app->log("User root not allowed for client databases", LOGLEVEL_WARNING); } else { $this->addUser($db, array( 'username' => $user, 'password' => $password, 'roles' => array( "readWrite", "dbAdmin" ) )); } } } // selected read-only user has changed -> add new one if ($data['new']['database_ro_user_id'] != $data['old']['database_ro_user_iduser_id']) { if ((bool) $db_ro_user && $data['new']['database_user_id'] != $data['new']['database_ro_user_id']) { if ($ro_user == 'root') { $app->log("User root not allowed for client databases", LOGLEVEL_WARNING); } else { $this->addUser($db, array( 'username' => $ro_user, 'password' => $ro_password, 'roles' => array( "read" ) )); } } } // renamed? /* if ($data['old']['database_name'] != $data['new']['database_name']) { $old_name = $data['old']['database_name']; $new_name = $data['new']['database_name']; if ($this->renameDB($oldName, $newName)) { $app->log("Renamed MongoDB database: ".$old_name." -> ".$new_name, LOGLEVEL_DEBUG); } else { $app->log("Renaming MongoDB database failed: ".$old_name." -> ".$new_name, LOGLEVEL_WARNING); } } */ } // switching from MySQL <-> Mongo isn't supported // no idea what we should do here...would be best to permit in interface? // remote access isn't supported by MongoDB (limiting to IP), // we therefor don't listen for it's changes } $this->disconnect(); } /** * This function is called when a DB is deleted from within the ISPConfig interface. * All we need to do is to delete the database. * * @param string $event_name the name of the event (insert, update, delete) * @param array $data the event data (old and new) * @return only if something is wrong */ function db_delete($event_name,$data) { global $app, $conf; if ($data['old']['type'] == 'mongo') { if ($this->connect() === false) { $app->log("Unable to connect to MongoDB: Connecting using connect() failed.", LOGLEVEL_ERROR); return; } $db_to_drop = $data['old']['database_name']; if ($this->dropDB($db_to_drop)) { $app->log("Dropping MongoDB database: ".$db_to_drop, LOGLEVEL_DEBUG); } else { $app->log("Error while dropping MongoDB database: ".$db_to_drop, LOGLEVEL_WARNING); } $this->disconnect(); } } /** * This function is called when a user is inserted from within the ISPConfig interface. * Since users are separated from databases we don't do anything here. * As soon as an user is associated to a DB, we add him there. * * @param string $event_name the name of the event (insert, update, delete) * @param array $data the event data (old and new) */ function db_user_insert($event_name,$data) {} /** * This function is called when a user is updated from within the ISPConfig interface. * The only thing we need to listen for here are password changes. * We than need to change those in all databases the user uses. * * @param string $event_name the name of the event (insert, update, delete) * @param array $data the event data (old and new) * @return only if something is wrong */ function db_user_update($event_name,$data) { global $app, $conf; if ($data['old']['database_user'] == $data['new']['database_user'] && ($data['old']['database_password'] == $data['new']['database_password'] || $data['new']['database_password'] == '')) { return; } if ($this->connect() === false) { $app->log("Unable to connect to MongoDB: Connecting using connect() failed.", LOGLEVEL_ERROR); return; } if ($data['old']['database_user'] != $data['new']['database_user']) { // username has changed $dbs = $this->getDBs(); if ((bool) $dbs) { foreach ($dbs as $db) { if ($this->userExists($db, $data['old']['database_user'])) { if (!$this->userExists($db, $data['new']['database_user'])) { $user = $this->getUser($db, $data['old']['database_user']); if ($this->dropUser($data['old']['database_user'], $db)) { if ($this->addUser($db, array( 'username' => $data['new']['database_user'], 'password' => md5($data['new']['database_password_mongo']), 'roles' => $user['roles'] ))) { $app->log("Created user: ".$data['new']['database_user']." in DB: ".$db, LOGLEVEL_DEBUG); } else { $app->log("Couldn't create user: ".$data['new']['database_user']." in DB: ".$db, LOGLEVEL_WARNING); } } else { $app->log("Couldn't drop user: ".$data['old']['database_user']." in DB: ".$db, LOGLEVEL_WARNING); } } else { $app->log("User: ".$data['new']['database_user']." already exists in DB: ".$db, LOGLEVEL_WARNING); } } } } } if ($data['old']['database_password'] != $data['new']['database_password'] || $data['old']['database_user'] != $data['new']['database_user']) { // password only has changed $dbs = $this->getDBs(); if ((bool) $dbs) { foreach ($dbs as $db) { if ($this->userExists($db, $data['new']['database_user'])) { if ($this->changePassword($db, $data['new']['database_user'], md5($data['new']['database_password_mongo']))) { $app->log("Changed user's: ".$data['new']['database_user']." password in DB: ".$db, LOGLEVEL_DEBUG); } else { $app->log("Couldn't change user's: ".$data['new']['database_user']." password in DB: ".$db, LOGLEVEL_WARNING); } } } } } $this->disconnect(); } /** * This function is called when a user is deleted from within the ISPConfig interface. * Since MongoDB uses per-DB user management, we have to find every database where the user is * activated and delete him there. * * @param string $event_name the name of the event (insert, update, delete) * @param array $data the event data (old and new) * @return only if something is wrong */ function db_user_delete($event_name, $data) { global $app, $conf; if ($this->connect() === false) { $app->log("Unable to connect to MongoDB: Connecting using connect() failed.", LOGLEVEL_ERROR); return; } if ($this->dropUser($data['old']['database_user']) === true) { $app->log("Dropped MongoDB user: ".$data['old']['database_user'], LOGLEVEL_DEBUG); } else { $app->log("Error while dropping MongoDB user: ".$data['old']['database_user'], LOGLEVEL_WARNING); } $this->disconnect(); } }