From d02193c14c33dd12edb14f000b1c4eb6b7c3f070 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Mon, 23 Apr 2012 09:18:48 -0400
Subject: [PATCH] Implemented: FS#2187 - Add a config resync toll for websites, ftp users, shell users and mailboxes.
---
/dev/null | 31 -----
interface/web/tools/lib/module.conf.php | 2
interface/web/tools/lib/lang/en.lng | 2
interface/web/tools/resync.php | 166 +++++++++++++++++++++++++++
interface/web/tools/templates/resync.htm | 67 +++++++++++
interface/lib/classes/db_mysql.inc.php | 35 +++--
interface/web/tools/lib/lang/en_resync.lng | 13 ++
interface/web/tools/lib/menu.d/resync.menu.php | 4
8 files changed, 268 insertions(+), 52 deletions(-)
diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php
index ae120c9..0319f47 100644
--- a/interface/lib/classes/db_mysql.inc.php
+++ b/interface/lib/classes/db_mysql.inc.php
@@ -1,6 +1,6 @@
<?php
/*
-Copyright (c) 2007, Till Brehm, projektfarm Gmbh
+Copyright (c) 2007-2012, Till Brehm, projektfarm Gmbh, ISPConfig UG
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
@@ -257,29 +257,34 @@
}
//** Function to fill the datalog with a full differential record.
- public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new) {
+ public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false) {
global $app,$conf;
- // Insert backticks only for incomplete table names.
+ //* Insert backticks only for incomplete table names.
if(stristr($db_table,'.')) {
$escape = '';
} else {
$escape = '`';
}
-
- $tmp = $this->diffrec($record_old, $record_new);
- $diffrec_full = $tmp['diff_rec'];
- $diff_num = $tmp['diff_num'];
- unset($tmp);
- // Insert the server_id, if the record has a server_id
+ if($force_update == true) {
+ //* We force a update even if no record has changed
+ $diffrec_full = array('new' => $record_new, 'old' => $record_old);
+ $diff_num = count($record_new);
+ } else {
+ //* get the difference record between old and new record
+ $tmp = $this->diffrec($record_old, $record_new);
+ $diffrec_full = $tmp['diff_rec'];
+ $diff_num = $tmp['diff_num'];
+ unset($tmp);
+ }
+
+ //* Insert the server_id, if the record has a server_id
$server_id = (isset($record_old['server_id']) && $record_old['server_id'] > 0)?$record_old['server_id']:0;
if(isset($record_new['server_id'])) $server_id = $record_new['server_id'];
if($diff_num > 0) {
- //print_r($diff_num);
- //print_r($diffrec_full);
$diffstr = $app->db->quote(serialize($diffrec_full));
$username = $app->db->quote($_SESSION['s']['user']['username']);
$dbidx = $primary_field.':'.$primary_id;
@@ -323,11 +328,7 @@
public function datalogUpdate($tablename, $update_data, $index_field, $index_value, $force_update = false) {
global $app;
- if($force_update == true) {
- $old_rec = array();
- } else {
- $old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
- }
+ $old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
if(is_array($update_data)) {
$update_data_str = '';
@@ -340,7 +341,7 @@
$this->query("UPDATE $tablename SET $update_data_str WHERE $index_field = '$index_value'");
$new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
- $this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec);
+ $this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec, $force_update);
return true;
}
diff --git a/interface/web/tools/dns_resync.php b/interface/web/tools/dns_resync.php
deleted file mode 100644
index c80735d..0000000
--- a/interface/web/tools/dns_resync.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/*
-Copyright (c) 2008, 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.
-*/
-
-require_once('../../lib/config.inc.php');
-require_once('../../lib/app.inc.php');
-
-//* Check permissions for module
-$app->auth->check_module_permissions('admin');
-
-//* This is only allowed for administrators
-if(!$app->auth->is_admin()) die('only allowed for administrators.');
-
-$app->uses('tpl,validate_dns');
-
-$app->tpl->newTemplate('form.tpl.htm');
-$app->tpl->setInclude('content_tpl', 'templates/dns_resync.htm');
-$msg = '';
-$error = '';
-
-// Resyncing dns zones
-if(isset($_POST['resync']) && $_POST['resync'] == 1) {
- $zones = $app->db->queryAllRecords("SELECT id,origin,serial FROM dns_soa WHERE active = 'Y'");
- if(is_array($zones) && !empty($zones)) {
- foreach($zones as $zone) {
- $records = $app->db->queryAllRecords("SELECT id,serial FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");
- if(is_array($records)) {
- foreach($records as $rec) {
- $new_serial = $app->validate_dns->increase_serial($rec["serial"]);
- $app->db->datalogUpdate('dns_rr', "serial = '".$new_serial."'", 'id', $rec['id']);
-
- }
- }
- $new_serial = $app->validate_dns->increase_serial($zone["serial"]);
- $app->db->datalogUpdate('dns_soa', "serial = '".$new_serial."'", 'id', $zone['id']);
- $msg .= "Resynced: ".$zone['origin'].'<br />';
- }
- } else {
- $error .= "No zones found to sync.<br />";
- }
-
-}
-
-$app->tpl->setVar('msg',$msg);
-$app->tpl->setVar('error',$error);
-
-
-//* load language file
-/*
-$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_mailbox_import.lng';
-include($lng_file);
-$app->tpl->setVar($wb);
-*/
-
-$app->tpl_defaults();
-$app->tpl->pparse();
-
-
-?>
\ No newline at end of file
diff --git a/interface/web/tools/lib/lang/en.lng b/interface/web/tools/lib/lang/en.lng
index 1dee19d..0122dcd 100644
--- a/interface/web/tools/lib/lang/en.lng
+++ b/interface/web/tools/lib/lang/en.lng
@@ -4,6 +4,6 @@
$wb['ISPConfig Tools'] = 'ISPConfig Tools';
$wb['Password and Language'] = 'Password and Language';
$wb['ispconfig_tools_note'] = 'This module allows you to change the password and language and to start a resync of the DNS records.';
-$wb['Dns Tools'] = 'Dns Tools';
+$wb['Sync Tools'] = 'Sync Tools';
$wb['Resync'] = 'Resync';
?>
\ No newline at end of file
diff --git a/interface/web/tools/lib/lang/en_resync.lng b/interface/web/tools/lib/lang/en_resync.lng
new file mode 100644
index 0000000..ae87bbd
--- /dev/null
+++ b/interface/web/tools/lib/lang/en_resync.lng
@@ -0,0 +1,13 @@
+<?php
+$wb['head_txt'] = 'Resync Tool';
+$wb['legend_txt'] = 'Resync';
+$wb['resync_sites_txt'] = 'Resync Websites';
+$wb['resync_ftp_txt'] = 'Resync FTP users';
+$wb['resync_shell_txt'] = 'Resync shell users';
+$wb['resync_cron_txt'] = 'Resync cronjobs';
+$wb['resync_db_txt'] = 'Resync database config';
+$wb['resync_mailbox_txt'] = 'Resync Mailboxes';
+$wb['resync_dns_txt'] = 'Resync DNS records';
+$wb['btn_start_txt'] = 'Start';
+$wb['btn_cancel_txt'] = 'Cancel';
+?>
\ No newline at end of file
diff --git a/interface/web/tools/lib/menu.d/dns_resync.menu.php b/interface/web/tools/lib/menu.d/resync.menu.php
similarity index 69%
rename from interface/web/tools/lib/menu.d/dns_resync.menu.php
rename to interface/web/tools/lib/menu.d/resync.menu.php
index f6b6ae0..3ef45fb 100644
--- a/interface/web/tools/lib/menu.d/dns_resync.menu.php
+++ b/interface/web/tools/lib/menu.d/resync.menu.php
@@ -9,10 +9,10 @@
$items[] = array( 'title' => 'Resync',
'target' => 'content',
- 'link' => 'tools/dns_resync.php');
+ 'link' => 'tools/resync.php');
-$module['nav'][] = array( 'title' => 'DNS Tools',
+$module['nav'][] = array( 'title' => 'Sync Tools',
'open' => 1,
'items' => $items);
diff --git a/interface/web/tools/lib/module.conf.php b/interface/web/tools/lib/module.conf.php
index a88aab0..3190d70 100644
--- a/interface/web/tools/lib/module.conf.php
+++ b/interface/web/tools/lib/module.conf.php
@@ -29,7 +29,7 @@
if ($dh = opendir($menu_dir)) {
//** Go through all files in the menu dir
while (($file = readdir($dh)) !== false) {
- if($file != '.' && $file != '..' && substr($file,-9,9) == '.menu.php') {
+ if($file != '.' && $file != '..' && substr($file,-9,9) == '.menu.php' && $file != 'dns_resync.menu.php') {
include_once($menu_dir.'/'.$file);
}
}
diff --git a/interface/web/tools/resync.php b/interface/web/tools/resync.php
new file mode 100644
index 0000000..86ba27d
--- /dev/null
+++ b/interface/web/tools/resync.php
@@ -0,0 +1,166 @@
+<?php
+/*
+Copyright (c) 2012, Till Brehm, projektfarm Gmbh, ISPConfig UG
+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.
+*/
+
+require_once('../../lib/config.inc.php');
+require_once('../../lib/app.inc.php');
+
+//* Check permissions for module
+$app->auth->check_module_permissions('admin');
+
+//* This is only allowed for administrators
+if(!$app->auth->is_admin()) die('only allowed for administrators.');
+
+$app->uses('tpl,validate_dns');
+
+$app->tpl->newTemplate('form.tpl.htm');
+$app->tpl->setInclude('content_tpl', 'templates/resync.htm');
+$msg = '';
+$error = '';
+
+//* load language file
+$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_resync.lng';
+include($lng_file);
+$app->tpl->setVar($wb);
+
+//* Resyncing websites
+if(isset($_POST['resync_sites']) && $_POST['resync_sites'] == 1) {
+ $db_table = 'web_domain';
+ $index_field = 'domain_id';
+ $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
+ $records = $app->db->queryAllRecords($sql);
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
+ $msg .= "Resynced Website: ".$rec['domain'].'<br />';
+ }
+ }
+}
+
+//* Resyncing ftp
+if(isset($_POST['resync_ftp']) && $_POST['resync_ftp'] == 1) {
+ $db_table = 'ftp_user';
+ $index_field = 'ftp_user_id';
+ $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
+ $records = $app->db->queryAllRecords($sql);
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
+ $msg .= "Resynced FTP user: ".$rec['username'].'<br />';
+ }
+ }
+}
+
+//* Resyncing shell
+if(isset($_POST['resync_shell']) && $_POST['resync_shell'] == 1) {
+ $db_table = 'shell_user';
+ $index_field = 'shell_user_id';
+ $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
+ $records = $app->db->queryAllRecords($sql);
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
+ $msg .= "Resynced Shell user: ".$rec['username'].'<br />';
+ }
+ }
+}
+
+//* Resyncing Cronjobs
+if(isset($_POST['resync_cron']) && $_POST['resync_cron'] == 1) {
+ $db_table = 'cron';
+ $index_field = 'id';
+ $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
+ $records = $app->db->queryAllRecords($sql);
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
+ $msg .= "Resynced Cron: ".$rec['id'].'<br />';
+ }
+ }
+}
+
+//* Resyncing Databases
+if(isset($_POST['resync_db']) && $_POST['resync_db'] == 1) {
+ $db_table = 'web_database';
+ $index_field = 'database_id';
+ $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
+ $records = $app->db->queryAllRecords($sql);
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
+ $msg .= "Resynced Database: ".$rec['database_name'].'<br />';
+ }
+ }
+}
+
+//* Resyncing Mailboxes
+if(isset($_POST['resync_mailbox']) && $_POST['resync_mailbox'] == 1) {
+ $db_table = 'mail_user';
+ $index_field = 'mailuser_id';
+ $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
+ $records = $app->db->queryAllRecords($sql);
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
+ $msg .= "Resynced Mailbox: ".$rec['email'].'<br />';
+ }
+ }
+}
+
+
+//* Resyncing dns zones
+if(isset($_POST['resync_dns']) && $_POST['resync_dns'] == 1) {
+ $zones = $app->db->queryAllRecords("SELECT id,origin,serial FROM dns_soa WHERE active = 'Y'");
+ if(is_array($zones) && !empty($zones)) {
+ foreach($zones as $zone) {
+ $records = $app->db->queryAllRecords("SELECT id,serial FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $new_serial = $app->validate_dns->increase_serial($rec["serial"]);
+ $app->db->datalogUpdate('dns_rr', "serial = '".$new_serial."'", 'id', $rec['id']);
+
+ }
+ }
+ $new_serial = $app->validate_dns->increase_serial($zone["serial"]);
+ $app->db->datalogUpdate('dns_soa', "serial = '".$new_serial."'", 'id', $zone['id']);
+ $msg .= "Resynced DNS zone: ".$zone['origin'].'<br />';
+ }
+ } else {
+ $error .= "No zones found to sync.<br />";
+ }
+
+}
+
+$app->tpl->setVar('msg',$msg);
+$app->tpl->setVar('error',$error);
+
+$app->tpl_defaults();
+$app->tpl->pparse();
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/tools/templates/dns_resync.htm b/interface/web/tools/templates/dns_resync.htm
deleted file mode 100644
index 372206a..0000000
--- a/interface/web/tools/templates/dns_resync.htm
+++ /dev/null
@@ -1,31 +0,0 @@
-<h2>DNS Resync</h2>
-<p><tmpl_var name="list_desc_txt"></p>
-
-<div class="panel panel_language_import">
-
- <div class="pnl_formsarea">
- <fieldset class="inlineLabels"><legend>DNS Resync</legend>
- <div class="ctrlHolder">
- <p class="label">Resync DNS Records</p>
- <div class="multiField">
- <input id="resync" type="checkbox" value="1" name="resync" checked/>
- </div>
- </div>
- </fieldset>
-
- <tmpl_if name="msg">
- <div id="OKMsg"><p><tmpl_var name="msg"></p></div>
- </tmpl_if>
- <tmpl_if name="error">
- <div id="errorMsg"><h3>ERROR</h3><ol><tmpl_var name="error"></ol></div>
- </tmpl_if>
-
- <input type="hidden" name="id" value="{tmpl_var name='id'}">
-
- <div class="buttonHolder buttons">
- <button class="positive iconstxt icoPositive" type="button" value="Import" onClick="submitForm('pageForm','tools/dns_resync.php');"><span>Start</span></button>
- <button class="negative iconstxt icoNegative" type="button" value="Cancel" onClick="loadContent('tools/index.php');"><span>Cancel</span></button>
- </div>
- </div>
-
-</div>
diff --git a/interface/web/tools/templates/resync.htm b/interface/web/tools/templates/resync.htm
new file mode 100644
index 0000000..196fb7e
--- /dev/null
+++ b/interface/web/tools/templates/resync.htm
@@ -0,0 +1,67 @@
+<h2>{tmpl_var name="head_txt"}</h2>
+<p><tmpl_var name="list_desc_txt"></p>
+
+<div class="panel panel_language_import">
+
+ <div class="pnl_formsarea">
+ <fieldset class="inlineLabels"><legend>{tmpl_var name="legend_txt"}</legend>
+ <div class="ctrlHolder">
+ <p class="label">{tmpl_var name="resync_sites_txt"}</p>
+ <div class="multiField">
+ <input id="resync_sites" type="checkbox" value="1" name="resync_sites" />
+ </div>
+ </div>
+ <div class="ctrlHolder">
+ <p class="label">{tmpl_var name="resync_ftp_txt"}</p>
+ <div class="multiField">
+ <input id="resync_ftp" type="checkbox" value="1" name="resync_ftp" />
+ </div>
+ </div>
+ <div class="ctrlHolder">
+ <p class="label">{tmpl_var name="resync_shell_txt"}</p>
+ <div class="multiField">
+ <input id="resync_shell" type="checkbox" value="1" name="resync_shell" />
+ </div>
+ </div>
+ <div class="ctrlHolder">
+ <p class="label">{tmpl_var name="resync_cron_txt"}</p>
+ <div class="multiField">
+ <input id="resync_cron" type="checkbox" value="1" name="resync_cron" />
+ </div>
+ </div>
+ <div class="ctrlHolder">
+ <p class="label">{tmpl_var name="resync_db_txt"}</p>
+ <div class="multiField">
+ <input id="resync_db" type="checkbox" value="1" name="resync_db" />
+ </div>
+ </div>
+ <div class="ctrlHolder">
+ <p class="label">{tmpl_var name="resync_mailbox_txt"}</p>
+ <div class="multiField">
+ <input id="resync_mailbox" type="checkbox" value="1" name="resync_mailbox" />
+ </div>
+ </div>
+ <div class="ctrlHolder">
+ <p class="label">{tmpl_var name="resync_dns_txt"}</p>
+ <div class="multiField">
+ <input id="resync_dns" type="checkbox" value="1" name="resync_dns" />
+ </div>
+ </div>
+ </fieldset>
+
+ <tmpl_if name="msg">
+ <div id="OKMsg"><p><tmpl_var name="msg"></p></div>
+ </tmpl_if>
+ <tmpl_if name="error">
+ <div id="errorMsg"><h3>ERROR</h3><ol><tmpl_var name="error"></ol></div>
+ </tmpl_if>
+
+ <input type="hidden" name="id" value="{tmpl_var name='id'}">
+
+ <div class="buttonHolder buttons">
+ <button class="positive iconstxt icoPositive" type="button" value="Import" onClick="submitForm('pageForm','tools/resync.php');"><span>{tmpl_var name="btn_start_txt"}</span></button>
+ <button class="negative iconstxt icoNegative" type="button" value="Cancel" onClick="loadContent('tools/index.php');"><span>{tmpl_var name="btn_cancel_txt"}</span></button>
+ </div>
+ </div>
+
+</div>
--
Gitblit v1.9.1