resync.php 25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/*
Copyright (c) 2014, Florian Schaal, info@schaal-24.de
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.
*/


/******************************************
* Begin Form configuration
******************************************/

$tform_def_file = 'form/resync.tform.php';

/******************************************
* End Form configuration
******************************************/

require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';

//* Check permissions for module
$app->auth->check_module_permissions('admin');

// Loading classes
$app->uses('tpl,tform,tform_actions');
$app->load('tform_actions');

class page_action extends tform_actions {

	//* called during onShowEnd
Florian Schaal's avatar
Florian Schaal committed
54
55
56
57
58
59
60
61
	/*
	* @param array $server_rec
	* @param string $server_type
	* @param string or array $search
	*
	* @return array
	*/

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	private function create_list($server_rec, $server_type, $search) {

		$server_count = 0;

		//* we allow multiple search-pattern - convert string to array
		if (!is_array($search)) {
			$_search = $search;
			$search=array();
			$search[]=$_search;
		}

		foreach ($server_rec as $server) {
			//* check the database for existing records
			$server_data = $this->server_has_data($server_type, $server['server_id']);
			foreach ($search as $needle) 
Florian Schaal's avatar
Florian Schaal committed
77
78
//				if (in_array($needle, $server_data) && strpos($options_servers, $server['server_name']) === false) {
				if (in_array($needle, $server_data)) {
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
					$options_servers .= "<option value='$server[server_id]'>$server[server_name]</option>";
					$server_count++;
				}
		}

		return array($options_servers, $server_count);
	}

	//* called from create_list
	private function server_has_data($type, $server) {

		global $app;

		$server_id = $app->functions->intval($server);

		if($type == 'mail') {
			$server_data = array (
    			'mail_domain' => array (
        			'index_field' => 'domain_id',
        			'server_type' => 'mail',
99
					'server_id' => $server_id,
100
    			),
Florian Schaal's avatar
Florian Schaal committed
101
102
103
104
105
				'mail_get' => array (
					'index_field' =>  'mailget_id',
					'server_type' => 'mail',
					'server_id' => $server_id,
				),
106
107
108
    			'mail_mailinglist' => array (
        			'index_field' =>  'mailinglist_id',
        			'server_type' => 'mail',
109
					'server_id' => $server_id,
110
111
112
113
    			),
    			'mail_user' => array (
        			'index_field' =>  'mailuser_id',
        			'server_type' => 'mail',
114
					'server_id' => $server_id,
Florian Schaal's avatar
Florian Schaal committed
115
				),
116
117
118
119
120
121
122
			);
		}
		if($type == 'mail_filter') {
			$server_data = array (
				'mail_access' => array (
					'index_field' => 'access_id',
        			'server_type' => 'mail',
123
					'server_id' => $server_id,
124
125
126
127
128
129
130
131
132
    			),
				'mail_content_filter' => array (
					'index_field' => 'content_filter_id',
        			'server_type' => 'mail',
    			),
				'mail_user_filter' => array (
					'index_field' => 'filter_id',
        			'server_type' => 'mail',
    			),
Florian Schaal's avatar
Florian Schaal committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
				'spamfilter_policy' => array (
					'index_field' => 'id',
					'server_type' => 'mail',
				),
				'spamfilter_users' => array (
					'index_field' => 'id',
					'server_type' => 'mail',
					'server_id' => $server_id,
				),
				'spamfilter_wblist' => array (
					'index_field' => 'wblist_id',
					'server_type' => 'mail',
					'server_id' => $server_id,
				),
147
148
149
150
151
152
153
			);
		}
		if($type == 'web'  ) {
			$server_data = array (
    			'web_domain' => array (
        			'index_field' => 'domain_id',
        			'server_type' => 'web',
Florian Schaal's avatar
Florian Schaal committed
154
					'server_id' => $server_id,
155
156
157
158
    			),
    			'shell_user' => array (
        			'index_field' => 'shell_user_id',
        			'server_type' => 'web',
159
					'server_id' => $server_id,
160
161
162
163
    			),
    			'cron' => array (
        			'index_field' => 'id',
        			'server_type' => 'cron',
164
					'server_id' => $server_id,
165
166
167
168
    			),
    			'ftp_user' => array (
        			'index_field' => 'ftp_user_id',
        			'server_type' => 'web',
169
					'server_id' => $server_id,
170
171
172
173
174
175
176
177
    			),
			);
		}
		if($type == 'dns' ) {
			$server_data = array (
				'dns_soa' => array (
					'index_field' => 'id',
					'server_type' => 'dns',
178
					'server_id' => $server_id,
179
180
181
182
183
184
185
186
				),
			);
		}
		if($type == 'file' ) {
			$server_data = array (
    			'webdav_user' => array (
        			'index_field' => 'webdav_user_id',
        			'server_type' => 'file',
187
					'server_id' => $server_id,
188
189
190
191
192
193
194
195
    			),
			);
		}
		if($type == 'db' ) {
			$server_data = array (
				'web_database' => array (
					'index_field' => 'web_database_id',
					'server_type' => 'db',
196
					'server_id' => $server_id,
197
198
199
200
201
202
203
204
				),
			);
		}
		if($type == 'vserver' ) {
			$server_data = array (
				'openvz_vm' => array (
					'index_field' => 'vm_id',
					'server_type' => 'vserver',
205
					'server_id' => $server_id,
206
207
208
209
210
211
212
				),
			);
		}
		//* proxy
		//* firewall
		$array_out = array();
		foreach($server_data as $db_table => $data) {
Florian Schaal's avatar
Florian Schaal committed
213
			$sql = @(isset($data['server_id']))?"SELECT * FROM ?? WHERE server_id = ?":"SELECT * FROM ??";
214
			$records = $app->db->queryAllRecords($sql, $db_table, $server_id);
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
			if (!empty($records)) array_push($array_out, $db_table);
		}

		return $array_out;
	}

	function onShowEnd() {
		global $app;

		//* fetch all-server
		$server_rec =  $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE active = 1 AND mirror_server_id = 0 ORDER BY active DESC, server_name");
		$server_count = 0;
		foreach ($server_rec as $server) {
			$options_servers .= "<option value='$server[server_id]'>$server[server_name]</option>";
			$server_count++;
		}
		if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_txt']."</option>" . $options_servers;
		$app->tpl->setVar('all_server_id', $options_servers);
		unset($options_servers);

		//* fetch mail-server
		$mail_server_rec = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE mail_server = 1 AND active = 1 AND mirror_server_id = 0 ORDER BY active DESC, server_name");
		if (!empty($mail_server_rec)) {
			$app->tpl->setVar('mail_server_found', 1);

			//* mail-domain
			$server_list = $this->create_list($mail_server_rec, 'mail', 'mail_domain');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_mail_txt']."</option>" . $options_servers;
				$app->tpl->setVar('mail_server_id', $options_servers);
				$app->tpl->setVar('mail_domain_found', 1);
				unset($options_servers);
			}

Florian Schaal's avatar
Florian Schaal committed
251
252
253
254
255
256
257
258
259
260
261
			//* mail-get
			$server_list = $this->create_list($mail_server_rec, 'mail', 'mail_get');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_mail_txt']."</option>" . $options_servers;
				$app->tpl->setVar('mailget_server_id', $options_servers);
				$app->tpl->setVar('mail_get_found', 1);
				unset($options_servers);
			}

262
263
264
265
266
267
268
269
270
271
272
273
			//* mailbox
			$server_list = $this->create_list($mail_server_rec, 'mail', 'mail_user');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_mail_txt']."</option>" . $options_servers;
				$app->tpl->setVar('mailbox_server_id', $options_servers);
				$app->tpl->setVar('mail_user_found', 1);
				unset($options_servers);
			}

			//* mailfilter
Florian Schaal's avatar
Florian Schaal committed
274
			$server_list = $this->create_list($mail_server_rec, 'mail_filter', array('mail_access', 'mail_content_filter', 'mail_user_filter','spamfilter_users', 'spamfilter_wblist'));
275
276
277
278
279
280
281
282
283
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_mail_txt']."</option>" . $options_servers;
				$app->tpl->setVar('mailfilter_server_id', $options_servers);
				$app->tpl->setVar('mail_filter_found', 1);
				unset($options_servers);
			}

Florian Schaal's avatar
Florian Schaal committed
284
285
286
287
288
289
290
291
292
293
294
			//* mailinglist
			$server_list = $this->create_list($mail_server_rec, 'mail', 'mail_mailinglist');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_mail_txt']."</option>" . $options_servers;
				$app->tpl->setVar('mailinglist_server_id', $options_servers);
				$app->tpl->setVar('mailinglist_found', 1);
				unset($options_servers);
			}

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
		}

		//* fetch web-server
		$web_server_rec = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE web_server = 1 AND active = 1 AND mirror_server_id = 0 ORDER BY active DESC, server_name");
		if (!empty($web_server_rec)) {
			$app->tpl->setVar('web_server_found', 1);

			//* web-domain
			$server_list = $this->create_list($web_server_rec, 'web', 'web_domain');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_web_txt']."</option>" . $options_servers;
				$app->tpl->setVar('web_server_id', $options_servers);
				$app->tpl->setVar('web_domain_found', 1);
				unset($options_servers);
			}

			//* ftp-user
			$server_list = $this->create_list($web_server_rec, 'web', 'ftp_user');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_web_txt']."</option>" . $options_servers;
				$app->tpl->setVar('ftp_server_id', $options_servers);
				$app->tpl->setVar('ftp_user_found', 1);
				unset($options_servers);
			}

			//* shell-user
			$server_list = $this->create_list($web_server_rec, 'web', 'shell_user');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_web_txt']."</option>" . $options_servers;
				$app->tpl->setVar('shell_server_id', $options_servers);
				$app->tpl->setVar('shell_user_found', 1);
				unset($options_servers);
			}

			//* cron
			$server_list = $this->create_list($web_server_rec, 'web', 'cron');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_web_txt']."</option>" . $options_servers;
				$app->tpl->setVar('cron_server_id', $options_servers);
				$app->tpl->setVar('cron_found', 1);
				unset($options_servers);
			}
		}

		//* fetch dns-server
		$dns_server_rec = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE dns_server = 1 AND active = 1 AND mirror_server_id = 0 ORDER BY active DESC, server_name");
		if (!empty($dns_server_rec)) {
			$app->tpl->setVar('dns_server_found', 1);

			$server_list = $this->create_list($dns_server_rec, 'dns', 'dns_soa');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_dns_txt']."</option>" . $options_servers;
				$app->tpl->setVar('dns_server_id', $options_servers);
				$app->tpl->setVar('dns_soa_found', 1);
				unset($options_servers);
			}
		}

		//* fetch webdav-user
		$file_server_rec = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE file_server = 1 AND active = 1 AND mirror_server_id = 0 ORDER BY active DESC, server_name");
		if (!empty($file_server_rec)) {
			$app->tpl->setVar('file_server_found', 1);

			$server_list = $this->create_list($file_server_rec, 'file', 'webdav_user');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_file_txt']."</option>" . $options_servers;
				$app->tpl->setVar('file_server_id', $options_servers);
				$app->tpl->setVar('webdav_user_found', 1);
				unset($options_servers);
			}
		}

		//* fetch database-server
		$db_server_rec = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE db_server = 1 AND active = 1 AND mirror_server_id = 0 ORDER BY active DESC, server_name");
		if (!empty($db_server_rec)) {
			$app->tpl->setVar('db_server_found', 1);

			$server_list = $this->create_list($db_server_rec, 'db', 'web_database');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_db_txt']."</option>" . $options_servers;
				$app->tpl->setVar('db_server_id', $options_servers);
				$app->tpl->setVar('client_db_found', 1);
				unset($options_servers);
			}
		}

		//* fetch vserver
		$v_server_rec = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE vserver_server = 1 AND active = 1 AND mirror_server_id = 0 ORDER BY active DESC, server_name");
		if (!empty($db_server_rec)) {
			$app->tpl->setVar('vserver_server_found', 1);

			$server_list = $this->create_list($v_server_rec, 'vserver', 'openvz_vm');
			$options_servers = $server_list[0];$server_count = $server_list[1];
			unset($server_list);
			if (isset($options_servers)) {	//* server with data found
				if ($server_count > 1) $options_servers = "<option value='0'>".$app->tform->wordbook['all_active_vserver_txt']."</option>" . $options_servers;
				$app->tpl->setVar('vserver_server_id', $options_servers);
				$app->tpl->setVar('vserver_found', 1);
				unset($options_servers);
			}
		}

Marius Cramer's avatar
Marius Cramer committed
411
412
413
414
		$csrf_token = $app->auth->csrf_token_get('tools_resync');
		$app->tpl->setVar('_csrf_id', $csrf_token['csrf_id']);
		$app->tpl->setVar('_csrf_key', $csrf_token['csrf_key']);

415
416
417
418
		parent::onShowEnd();
	}
			
	//* fetch values during do_resync
419
	private function query_server($db_table, $server_id, $server_type, $active=true, $opt='') {
420
421
422
423
		global $app;

		$server_name = array();
		if ( $server_id == 0 ) { //* resync multiple server
424
			$temp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE ?? = 1 AND active = 1 AND mirror_server_id = 0", $server_type."_server");
425
426
427
428
			foreach ($temp as $server) {
				$temp_id .= $server['server_id'].',';
				$server_name[$server['server_id']] = $server['server_name'];
			}
Florian Schaal's avatar
Florian Schaal committed
429
			if ( isset($temp_id) ) $server_id = rtrim($temp_id,',');
430
431
432
433
434
435
		} else {
			$temp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ?", $server_id);
			$server_name[$server_id] = $temp['server_name'];
		}		
		unset($temp);

436
		$sql = "SELECT * FROM ??";
Florian Schaal's avatar
Florian Schaal committed
437
		if ($db_table != "mail_user_filter" && $db_table != "spamfilter_policy") $sql .= " WHERE server_id IN (".$server_id.") ";
438
		$sql .= $opt;
439
		if ($active) $sql .= " AND active = 'y'"; 
440
		$records = $app->db->queryAllRecords($sql, $db_table);
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455

		return array($records, $server_name);
	}			

	private function do_resync($db_table, $index_field, $server_type, $server_id, $msg_field, $wordbook, $active=true) {
        global $app;

		$server_id = $app->functions->intval($server_id);
		$rec = $this->query_server($db_table, $server_id, $server_type, $active);
		$records = $rec[0];
		$server_name = $rec[1];
		$msg = '<b>'.$wordbook.'</b><br>';
		if(!empty($records)) 
			foreach($records as $rec) {
				$app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
456
				if(!empty($rec[$msg_field])) $msg .= '['.$server_name[$rec['server_id']].'] '.$rec[$msg_field].'<br>';
457
458
459
460
461
462
463
464
			}
		else $msg .= $app->tform->wordbook['no_results_txt'].'<br>';

		return $msg.'<br>';
	}

    function onSubmit() {
        global $app;
Marius Cramer's avatar
Marius Cramer committed
465
466
467
468
469
470
		
		if(isset($_POST) && count($_POST) > 1) {
			//* CSRF Check
			$app->auth->csrf_token_check();
		}
		
471
472
473
474
475
476
477
478
479
		//* all services
		if($this->dataRecord['resync_all'] == 1) {
			$this->dataRecord['resync_sites'] = 1;
			$this->dataRecord['resync_ftp'] = 1;
			$this->dataRecord['resync_webdav'] = 1;
			$this->dataRecord['resync_shell'] = 1;
			$this->dataRecord['resync_cron'] = 1;
			$this->dataRecord['resync_db'] = 1;
			$this->dataRecord['resync_mail'] = 1;
Florian Schaal's avatar
Florian Schaal committed
480
			$this->dataRecord['resync_mailget'] = 1;
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
			$this->dataRecord['resync_mailbox'] = 1;
			$this->dataRecord['resync_mailfilter'] = 1;
			$this->dataRecord['resync_mailinglist'] = 1;
			$this->dataRecord['resync_vserver'] = 1;
			$this->dataRecord['resync_dns'] = 1;
			$this->dataRecord['resync_client'] = 1;
			$this->dataRecord['web_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['ftp_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['webdav_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['shell_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['cron_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['db_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['mail_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['mailbox_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['verserver_server_id'] = $this->dataRecord['all_server_id'];
			$this->dataRecord['dns_server_id'] = $this->dataRecord['all_server_id'];
		}

		//* websites
		if($this->dataRecord['resync_sites'] == 1)
			$msg .= $this->do_resync('web_domain', 'domain_id', 'web', $this->dataRecord['web_server_id'], 'domain', $app->tform->wordbook['do_sites_txt']);

		//* ftp
		if($this->dataRecord['resync_ftp'] == 1)
			$msg .= $this->do_resync('ftp_user', 'ftp_user_id', 'web', $this->dataRecord['ftp_server_id'], 'username',  $app->tform->wordbook['do_ftp_txt']);

		//* webdav
		if($this->dataRecord['resync_webdav'] == 1) 
			$msg .= $this->do_resync('webdav_user', 'webdav_user_id', 'file', $this->dataRecord['webdav_server_id'], 'username',  $app->tform->wordbook['do_webdav_txt']);

		//* shell
		if($this->dataRecord['resync_shell'] == 1) 
			$msg .= $this->do_resync('shell_user', 'shell_user_id', 'web', $this->dataRecord['shell_server_id'], 'username',  $app->tform->wordbook['do_shell_txt']);

		//* cron
		if($this->dataRecord['resync_cron'] == 1) 
			$msg .= $this->do_resync('cron', 'id', 'web', $this->dataRecord['cron_server_id'], 'command',  $app->tform->wordbook['do_cron_txt']);

		//* database
		if(isset($this->dataRecord['resync_db']) && $this->dataRecord['resync_db'] == 1) {
Florian Schaal's avatar
Florian Schaal committed
521
			$msg .= $this->do_resync('web_database_user', 'database_user_id', 'db', $this->dataRecord['db_server_id'], 'database_user',  $app->tform->wordbook['do_db_user_txt'], false);
522
523
524
525
			$msg .= $this->do_resync('web_database', 'database_id', 'db', $this->dataRecord['db_server_id'], 'database_name',  $app->tform->wordbook['do_db_txt']);
		}

		//* maildomains
Florian Schaal's avatar
Florian Schaal committed
526
		if($this->dataRecord['resync_mail'] == 1) {
527
			$msg .= $this->do_resync('mail_domain', 'domain_id', 'mail', $this->dataRecord['mail_server_id'], 'domain',  $app->tform->wordbook['do_mail_txt']);
Florian Schaal's avatar
Florian Schaal committed
528
			$msg .= $this->do_resync('spamfilter_policy', 'id', 'mail', $this->dataRecord['mail_server_id'], '',  $app->tform->wordbook['do_mail_spamfilter_policy_txt'], false);
Florian Schaal's avatar
Florian Schaal committed
529
530
531
532
533
534
		}

		//* mailget
		if($this->dataRecord['resync_mailget'] == 1) {
			$msg .= $this->do_resync('mail_get', 'mailget_id', 'mail', $this->dataRecord['mail_server_id'], 'source_username',  $app->tform->wordbook['do_mailget_txt']);
		}
535
536
537
538
539
540
541
542
543
544
545
546

		//* mailbox
		if($this->dataRecord['resync_mailbox'] == 1) {
			$msg .= $this->do_resync('mail_user', 'mailuser_id', 'mail', $this->dataRecord['mailbox_server_id'], 'email',  $app->tform->wordbook['do_mailbox_txt'], false);
			$msg .= $this->do_resync('mail_forwarding', 'forwarding_id', 'mail', $this->dataRecord['mailbox_server_id'], '',  $app->tform->wordbook['do_mail_alias_txt']);
		}

		//* mailfilter
		if($this->dataRecord['resync_mailfilter'] == 1) {
			$msg .= $this->do_resync('mail_access', 'access_id', 'mail', $this->dataRecord['mailbox_server_id'], '',  $app->tform->wordbook['do_mail_access_txt']);
			$msg .= $this->do_resync('mail_content_filter', 'content_filter_id', 'mail', $this->dataRecord['mailbox_server_id'], '',  $app->tform->wordbook['do_mail_contentfilter_txt']);
			$msg .= $this->do_resync('mail_user_filter', 'filter_id', 'mail', $this->dataRecord['mailbox_server_id'], '',  $app->tform->wordbook['do_mail_userfilter_txt'], false);
Florian Schaal's avatar
Florian Schaal committed
547
548
549
			//* spam
			$msg .= $this->do_resync('spamfilter_users', 'id', 'mail', $this->dataRecord['mailbox_server_id'], '',  $app->tform->wordbook['do_mail_spamfilter_txt'], false);
			$msg .= $this->do_resync('spamfilter_wblist', 'wblist_id', 'mail', $this->dataRecord['mailbox_server_id'], '',  $app->tform->wordbook['do_mail_spamfilter_txt']) 	;
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
		}

		//* mailinglists
		if($this->dataRecord['resync_mailinglist'] == 1) 
			$msg .= $this->do_resync('mail_mailinglist', 'mailinglist_id', 'mail', $this->dataRecord['mail_server_id'], 'listname',  $app->tform->wordbook['do_mailinglist_txt'], false);

		//* vserver
		if($this->dataRecord['resync_vserver'] == 1) 
			$msg .= $this->do_resync('openvz_vm', 'vm_id', 'vserver', $this->dataRecord['verserver_server_id'], 'hostname',  $app->tform->wordbook['do_vserver_txt']);

		//* dns
		if($this->dataRecord['resync_dns'] == 1) {
			$rec=$this->query_server('dns_soa', $this->dataRecord['dns_server_id'], 'dns'); 
			$soa_records = $rec[0];
			$server_name = $rec[1];
			unset($rec);
			$msg .= '<b>'.$app->tform->wordbook['do_dns_txt'].'</b><br>';
			if(is_array($soa_records) && !empty($soa_records)) 
				foreach($soa_records as $soa_rec) {
569
					$temp = $this->query_server('dns_rr', $soa_rec['server_id'], 'dns', true, "AND zone = ".$app->functions->intval($soa_rec['id']));
570
571
572
573
					$rr_records = $temp[0];
					if(!empty($rr_records)) {
						foreach($rr_records as $rec) {
							$new_serial = $app->validate_dns->increase_serial($rec['serial']);
574
							$app->db->datalogUpdate('dns_rr', array("serial" => $new_serial), 'id', $rec['id']);
575
576
577
578
579
						}
					} else { 
						$msg .= $app->tform->wordbook['no_results_txt'].'<br>';
					}
					$new_serial = $app->validate_dns->increase_serial($soa_rec['serial']);
580
					$app->db->datalogUpdate('dns_soa', array("serial" => $new_serial), 'id', $soa_rec['id']);
581
					$msg .= '['.$server_name[$soa_rec['server_id']].'] '.$soa_rec['origin'].' ('.count($rr_records).')<br>';
582
583
584
585
586
587
588
589
590
591
				}
			else $msg .= $app->tform->wordbook['no_results_txt'].'<br>'; 

			$msg .= '<br>';
        }

		//* clients
		if($this->dataRecord['resync_client'] == 1) {
        	$db_table = 'client';
        	$index_field = 'client_id';
592
        	$records = $app->db->queryAllRecords("SELECT * FROM ??", $db_table);
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
			$msg .= '<b>'.$app->tform->wordbook['do_clients_txt'].'</b><br>';
			if(!empty($records)) {
	        	$tform_def_file = '../client/form/client.tform.php';
    	    	$app->uses('tpl,tform,tform_actions');
        		$app->load('tform_actions');
				foreach($records as $rec) {
					$app->db->datalogUpdate($db_table, $rec, $index_field, $rec[$index_field], true);
					$tmp = new tform_actions;
					$tmp->id = $rec[$index_field];
					$tmp->dataRecord = $rec;
					$tmp->oldDataRecord = $rec;
					$app->plugin->raiseEvent('client:client:on_after_update', $tmp);
					$msg .= $rec['contact_name'].'<br>';
					unset($tmp);
				}
			} else {
				$msg .= $app->tform->wordbook['no_results_txt'].'<br>'; 
			}
			$msg .= '<br>';
		}

		echo $msg;
    } //* end onSumbmit

}

$page = new page_action;
$page->onLoad();
?>