Till Brehm
2015-06-03 5af0cfd99a13fda9afad3380b0c50a3428acd299
commit | author | age
e94a9f 1 <?php
T 2 /*
3 Copyright (c) 2012, Till Brehm, projektfarm Gmbh, ISPConfig UG
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
7fe908 30 require_once '../../lib/config.inc.php';
MC 31 require_once '../../lib/app.inc.php';
e94a9f 32
T 33 //* Check permissions for module
34 $app->auth->check_module_permissions('admin');
35
36 //* This is only allowed for administrators
37 if(!$app->auth->is_admin()) die('only allowed for administrators.');
38
39 $app->uses('tpl,validate_dns');
40
41 $app->tpl->newTemplate('form.tpl.htm');
42 $app->tpl->setInclude('content_tpl', 'templates/resync.htm');
43 $msg = '';
44 $error = '';
45
46 //* load language file
47 $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_resync.lng';
7fe908 48 include $lng_file;
e94a9f 49 $app->tpl->setVar($wb);
T 50
5af0cf 51 if(isset($_POST) && count($_POST) > 1) {    
TB 52     //* CSRF Check
53     $app->auth->csrf_token_check();
54 }
55
e94a9f 56 //* Resyncing websites
T 57 if(isset($_POST['resync_sites']) && $_POST['resync_sites'] == 1) {
58     $db_table = 'web_domain';
59     $index_field = 'domain_id';
60     $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
61     $records = $app->db->queryAllRecords($sql);
62     if(is_array($records)) {
63         foreach($records as $rec) {
64             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
65             $msg .= "Resynced Website: ".$rec['domain'].'<br />';
66         }
67     }
68 }
69
70 //* Resyncing ftp
71 if(isset($_POST['resync_ftp']) && $_POST['resync_ftp'] == 1) {
72     $db_table = 'ftp_user';
73     $index_field = 'ftp_user_id';
74     $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
75     $records = $app->db->queryAllRecords($sql);
76     if(is_array($records)) {
77         foreach($records as $rec) {
78             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
79             $msg .= "Resynced FTP user: ".$rec['username'].'<br />';
80         }
81     }
82 }
83
84 //* Resyncing shell
85 if(isset($_POST['resync_shell']) && $_POST['resync_shell'] == 1) {
86     $db_table = 'shell_user';
87     $index_field = 'shell_user_id';
88     $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
89     $records = $app->db->queryAllRecords($sql);
90     if(is_array($records)) {
91         foreach($records as $rec) {
92             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
93             $msg .= "Resynced Shell user: ".$rec['username'].'<br />';
94         }
95     }
96 }
97
98 //* Resyncing Cronjobs
99 if(isset($_POST['resync_cron']) && $_POST['resync_cron'] == 1) {
100     $db_table = 'cron';
101     $index_field = 'id';
102     $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
103     $records = $app->db->queryAllRecords($sql);
104     if(is_array($records)) {
105         foreach($records as $rec) {
106             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
107             $msg .= "Resynced Cron: ".$rec['id'].'<br />';
108         }
109     }
110 }
111
112 //* Resyncing Databases
113 if(isset($_POST['resync_db']) && $_POST['resync_db'] == 1) {
85204d 114     $db_table = 'web_database_user';
TB 115     $index_field = 'database_user_id';
116     $sql = "SELECT * FROM ".$db_table." WHERE 1";
117     $records = $app->db->queryAllRecords($sql);
118     if(is_array($records)) {
119         foreach($records as $rec) {
120             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
121             $msg .= "Resynced Database user: ".$rec['database_user'].'<br />';
122         }
123     }
e94a9f 124     $db_table = 'web_database';
T 125     $index_field = 'database_id';
126     $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
127     $records = $app->db->queryAllRecords($sql);
128     if(is_array($records)) {
129         foreach($records as $rec) {
130             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
131             $msg .= "Resynced Database: ".$rec['database_name'].'<br />';
132         }
133     }
134 }
135
7fe908 136 //* Resyncing Mailbox Domains
MC 137 if(isset($_POST['resync_mailbox']) && $_POST['resync_mailbox'] == 1) {
138     $db_table = 'mail_domain';
139     $index_field = 'domain_id';
140     $sql = "SELECT * FROM ".$db_table." WHERE active = 'y'";
141     $records = $app->db->queryAllRecords($sql);
142     if(is_array($records)) {
143         foreach($records as $rec) {
144             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
145             $msg .= "Resynced Mail Domain: ".$rec['domain'].'<br />';
146         }
147     }
26c0fc 148 }
T 149
e94a9f 150 //* Resyncing Mailboxes
T 151 if(isset($_POST['resync_mailbox']) && $_POST['resync_mailbox'] == 1) {
152     $db_table = 'mail_user';
153     $index_field = 'mailuser_id';
26c0fc 154     $sql = "SELECT * FROM ".$db_table;
e94a9f 155     $records = $app->db->queryAllRecords($sql);
T 156     if(is_array($records)) {
157         foreach($records as $rec) {
158             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
159             $msg .= "Resynced Mailbox: ".$rec['email'].'<br />';
160         }
161     }
85204d 162     $db_table = 'mail_forwarding';
TB 163     $index_field = 'forwarding_id';
164     $sql = "SELECT * FROM ".$db_table;
165     $records = $app->db->queryAllRecords($sql);
166     if(is_array($records)) {
167         foreach($records as $rec) {
168             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
169             $msg .= "Resynced Alias: ".$rec['source'].'<br />';
170         }
171     }
e94a9f 172 }
T 173
174 //* Resyncing dns zones
175 if(isset($_POST['resync_dns']) && $_POST['resync_dns'] == 1) {
176     $zones = $app->db->queryAllRecords("SELECT id,origin,serial FROM dns_soa WHERE active = 'Y'");
177     if(is_array($zones) && !empty($zones)) {
178         foreach($zones as $zone) {
179             $records = $app->db->queryAllRecords("SELECT id,serial FROM dns_rr WHERE zone = ".$zone['id']." AND active = 'Y'");
180             if(is_array($records)) {
181                 foreach($records as $rec) {
182                     $new_serial = $app->validate_dns->increase_serial($rec["serial"]);
183                     $app->db->datalogUpdate('dns_rr', "serial = '".$new_serial."'", 'id', $rec['id']);
7fe908 184
e94a9f 185                 }
T 186             }
187             $new_serial = $app->validate_dns->increase_serial($zone["serial"]);
188             $app->db->datalogUpdate('dns_soa', "serial = '".$new_serial."'", 'id', $zone['id']);
189             $msg .= "Resynced DNS zone: ".$zone['origin'].'<br />';
190         }
191     } else {
192         $error .= "No zones found to sync.<br />";
193     }
7fe908 194
e94a9f 195 }
T 196
85204d 197 //* Resyncing Clients
TB 198 if(isset($_POST['resync_client']) && $_POST['resync_client'] == 1) {
199     $tform_def_file = "form/client.tform.php";
200     $app->uses('tpl,tform,tform_actions');
201     $app->load('tform_actions');
202     
203     $db_table = 'client';
204     $index_field = 'client_id';
205     $sql = "SELECT * FROM ".$db_table;
206     $records = $app->db->queryAllRecords($sql);
207     if(is_array($records)) {
208         foreach($records as $rec) {
209             $app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
210             $tmp = new tform_actions;
211             $tmp->id = $rec[$index_field];
212             $tmp->dataRecord = $rec;
213             $tmp->oldDataRecord = $rec;
214             $app->plugin->raiseEvent('client:client:on_after_update', $tmp);
215             $msg .= "Resynced Client: ".$rec['contact_name'].'<br />';
216             unset($tmp);
217         }
218     }
219 }
220
221
7fe908 222 $app->tpl->setVar('msg', $msg);
MC 223 $app->tpl->setVar('error', $error);
e94a9f 224
5af0cf 225 //* SET csrf token
TB 226 $csrf_token = $app->auth->csrf_token_get('tools_resync');
227 $app->tpl->setVar('_csrf_id',$csrf_token['csrf_id']);
228 $app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']);
229
e94a9f 230 $app->tpl_defaults();
T 231 $app->tpl->pparse();
232
233
7fe908 234 ?>