sites.inc.php 40.5 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
<?php

/*
Copyright (c) 2007 - 2013, 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.

--UPDATED 08.2009--
Full SOAP support for ISPConfig 3.1.4 b
Updated by Arkadiusz Roch & Artur Edelman
Copyright (c) Tri-Plex technology

--UPDATED 08.2013--
Migrated into new remote classes system
by Marius Cramer <m.cramer@pixcept.de>

*/

class remoting_sites extends remoting {
	// Website functions ---------------------------------------------------------------------------------------
43

44
45
	//* Get cron details
	public function sites_cron_get($session_id, $cron_id)
46
	{
47
		global $app;
48

49
50
51
52
53
54
55
56
		if(!$this->checkPerm($session_id, 'sites_cron_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/cron.tform.php');
		return $app->remoting_lib->getDataRecord($cron_id);
	}
57

58
59
	//* Add a cron record
	public function sites_cron_add($session_id, $client_id, $params)
60
	{
61
62
63
64
		if(!$this->checkPerm($session_id, 'sites_cron_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
65
		return $this->insertQuery('../sites/form/cron.tform.php', $client_id, $params);
66
	}
67

68
69
	//* Update cron record
	public function sites_cron_update($session_id, $client_id, $cron_id, $params)
70
	{
71
72
73
74
		if(!$this->checkPerm($session_id, 'sites_cron_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
75
		$affected_rows = $this->updateQuery('../sites/form/cron.tform.php', $client_id, $cron_id, $params);
76
77
		return $affected_rows;
	}
78

79
80
	//* Delete cron record
	public function sites_cron_delete($session_id, $cron_id)
81
	{
82
83
84
85
		if(!$this->checkPerm($session_id, 'sites_cron_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
86
		$affected_rows = $this->deleteQuery('../sites/form/cron.tform.php', $cron_id);
87
88
		return $affected_rows;
	}
89

90
	// ----------------------------------------------------------------------------------------------------------
91

92
93
	//* Get record details
	public function sites_database_get($session_id, $primary_id)
94
	{
95
		global $app;
96

97
98
99
100
101
102
103
104
		if(!$this->checkPerm($session_id, 'sites_database_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
105
106
	
	/* TODO: secure queries! */
107
108
	//* Add a record
	public function sites_database_add($session_id, $client_id, $params)
109
110
111
	{
		global $app;

112
113
114
115
		if(!$this->checkPerm($session_id, 'sites_database_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
116

117
		//* Check for duplicates
118
		$tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ?", $params['database_name'], $params["server_id"]);
119
120
121
122
123
		if($tmp['dbnum'] > 0) {
			throw new SoapFault('database_name_error_unique', 'There is already a database with that name on the same server.');
			return false;
		}

124
125
126
		$sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
		if($sql !== false) {
			$app->uses('sites_database_plugin');
127

128
129
130
			$this->id = 0;
			$this->dataRecord = $params;

131
			$retval = $this->insertQueryExecute($sql, $params);
132
			$app->sites_database_plugin->processDatabaseInsert($this);
133
134
135
136
137
138
139
140
141
142
			
			// set correct values for backup_interval and backup_copies
			if(isset($params['backup_interval']) || isset($params['backup_copies'])){
				$sql_set = array();
				if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
				if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
				$this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
			}
			
			return $retval;
143
144
145
		}

		return false;
146
	}
147

148
149
	//* Update a record
	public function sites_database_update($session_id, $client_id, $primary_id, $params)
150
151
152
	{
		global $app;

153
154
155
156
		if(!$this->checkPerm($session_id, 'sites_database_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
157

158
		$sql = $this->updateQueryPrepare('../sites/form/database.tform.php', $client_id, $primary_id, $params);
159
160
161
162
163
164
		if($sql !== false) {
			$app->uses('sites_database_plugin');

			$this->id = $primary_id;
			$this->dataRecord = $params;
			$app->sites_database_plugin->processDatabaseUpdate($this);
165
166
167
168
169
170
171
172
173
174
175
			$retval = $this->updateQueryExecute($sql, $primary_id, $params);
			
			// set correct values for backup_interval and backup_copies
			if(isset($params['backup_interval']) || isset($params['backup_copies'])){
				$sql_set = array();
				if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
				if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
				$this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$primary_id, $primary_id, $params);
			}
			
			return $retval;
176
177
178
179
180
		}

		return false;
	}

181
182
	//* Delete a record
	public function sites_database_delete($session_id, $primary_id)
183
184
	{
		global $app;
185
186
187
188
		if(!$this->checkPerm($session_id, 'sites_database_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
189
190
191
192
193

		$app->uses('sites_database_plugin');
		$app->sites_database_plugin->processDatabaseDelete($primary_id);

		$affected_rows = $this->deleteQuery('../sites/form/database.tform.php', $primary_id);
194
195
		return $affected_rows;
	}
196

197
	// ----------------------------------------------------------------------------------------------------------
198

199
200
	//* Get record details
	public function sites_database_user_get($session_id, $primary_id)
201
	{
202
		global $app;
203

204
205
206
207
208
209
210
211
		if(!$this->checkPerm($session_id, 'sites_database_user_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/database_user.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
212

213
214
	//* Add a record
	public function sites_database_user_add($session_id, $client_id, $params)
215
	{
216
217
218
219
220
		if(!$this->checkPerm($session_id, 'sites_database_user_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}

221
		return $this->insertQuery('../sites/form/database_user.tform.php', $client_id, $params);
222
	}
223

224
225
	//* Update a record
	public function sites_database_user_update($session_id, $client_id, $primary_id, $params)
226
227
228
	{
		global $app;

229
230
231
232
233
234
		if(!$this->checkPerm($session_id, 'sites_database_user_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/database_user.tform.php');
235
236
		$old_rec = $app->remoting_lib->getDataRecord($primary_id);

237
		$result = $this->updateQuery('../sites/form/database_user.tform.php', $client_id, $primary_id, $params);
238
239
240

		$new_rec = $app->remoting_lib->getDataRecord($primary_id);

241
		$records = $app->db->queryAllRecords("SELECT DISTINCT server_id FROM web_database WHERE database_user_id = ? UNION SELECT DISTINCT server_id FROM web_database WHERE database_ro_user_id = ?", $primary_id, $primary_id);
242
243
244
245
246
247
248
249
250
251
252
253
		foreach($records as $rec) {
			$tmp_rec = $new_rec;
			$tmp_rec['server_id'] = $rec['server_id'];
			$app->remoting_lib->datalogSave('UPDATE', $primary_id, $old_rec, $tmp_rec);
		}
		unset($new_rec);
		unset($old_rec);
		unset($records);

		return $result;
	}

254
255
	//* Delete a record
	public function sites_database_user_delete($session_id, $primary_id)
256
257
258
	{
		global $app;

259
260
261
262
		if(!$this->checkPerm($session_id, 'sites_database_user_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
263

264
		//$app->db->datalogDelete('web_database_user', 'database_user_id', $primary_id);
265
266
		$affected_rows = $this->deleteQuery('../sites/form/database_user.tform.php', $primary_id);

267
		$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_user_id = ?", $primary_id);
268
		foreach($records as $rec) {
269
			$app->db->datalogUpdate('web_database', array('database_user_id' => null), 'database_id', $rec['database_id']);
270
271

		}
272
		$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_ro_user_id = ?", $primary_id);
273
		foreach($records as $rec) {
274
			$app->db->datalogUpdate('web_database', array('database_ro_user_id' => null), 'database_id', $rec['database_id']);
275
276
		}

277
278
		return $affected_rows;
	}
279

280
	// ----------------------------------------------------------------------------------------------------------
281

282
283
	//* Get record details
	public function sites_ftp_user_get($session_id, $primary_id)
284
	{
285
		global $app;
286

287
288
289
290
291
292
293
294
		if(!$this->checkPerm($session_id, 'sites_ftp_user_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/ftp_user.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
295

296
297
	//* Add a record
	public function sites_ftp_user_add($session_id, $client_id, $params)
298
	{
299
300
301
302
		if(!$this->checkPerm($session_id, 'sites_ftp_user_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
303
		return $this->insertQuery('../sites/form/ftp_user.tform.php', $client_id, $params);
304
	}
305

306
307
	//* Update a record
	public function sites_ftp_user_update($session_id, $client_id, $primary_id, $params)
308
	{
309
310
311
312
		if(!$this->checkPerm($session_id, 'sites_ftp_user_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
313
		$affected_rows = $this->updateQuery('../sites/form/ftp_user.tform.php', $client_id, $primary_id, $params);
314
315
		return $affected_rows;
	}
316

317
318
	//* Delete a record
	public function sites_ftp_user_delete($session_id, $primary_id)
319
	{
320
321
322
323
		if(!$this->checkPerm($session_id, 'sites_ftp_user_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
324
		$affected_rows = $this->deleteQuery('../sites/form/ftp_user.tform.php', $primary_id);
325
326
		return $affected_rows;
	}
327

328
329
	//* Get server for an ftp user
	public function sites_ftp_user_server_get($session_id, $ftp_user)
330
	{
331
		global $app;
332

333
334
335
336
		if(!$this->checkPerm($session_id, 'sites_ftp_user_server_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
337

338
		$data = $app->db->queryOneRecord("SELECT server_id FROM ftp_user WHERE username = ?", $ftp_user);
339
		//file_put_contents('/tmp/test.txt', serialize($data));
340
341
342
343
344
		if(!isset($data['server_id'])) return false;

		$server = $this->server_get($session_id, $data['server_id'], 'server');
		//file_put_contents('/tmp/test2.txt', serialize($server));

345
346
		return $server;
	}
347

348
	// ----------------------------------------------------------------------------------------------------------
349

350
351
	//* Get record details
	public function sites_shell_user_get($session_id, $primary_id)
352
	{
353
		global $app;
354

355
356
357
358
359
360
361
362
		if(!$this->checkPerm($session_id, 'sites_shell_user_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/shell_user.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
363

364
365
	//* Add a record
	public function sites_shell_user_add($session_id, $client_id, $params)
366
	{
367
368
369
370
		if(!$this->checkPerm($session_id, 'sites_shell_user_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
371
		return $this->insertQuery('../sites/form/shell_user.tform.php', $client_id, $params);
372
	}
373

374
375
	//* Update a record
	public function sites_shell_user_update($session_id, $client_id, $primary_id, $params)
376
	{
377
378
379
380
		if(!$this->checkPerm($session_id, 'sites_shell_user_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
381
		$affected_rows = $this->updateQuery('../sites/form/shell_user.tform.php', $client_id, $primary_id, $params);
382
383
		return $affected_rows;
	}
384

385
386
	//* Delete a record
	public function sites_shell_user_delete($session_id, $primary_id)
387
	{
388
389
390
391
		if(!$this->checkPerm($session_id, 'sites_shell_user_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
392
		$affected_rows = $this->deleteQuery('../sites/form/shell_user.tform.php', $primary_id);
393
394
		return $affected_rows;
	}
395

396
	// ----------------------------------------------------------------------------------------------------------
397

398
399
	//* Get record details
	public function sites_web_domain_get($session_id, $primary_id)
400
	{
401
		global $app;
402

403
404
405
406
407
		if(!$this->checkPerm($session_id, 'sites_web_domain_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
Marius Cramer's avatar
Marius Cramer committed
408
		$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
409
410
		return $app->remoting_lib->getDataRecord($primary_id);
	}
411

412
413
414
415
416
417
418
419
	//* Add a record
	public function sites_web_domain_add($session_id, $client_id, $params, $readonly = false)
	{
		global $app;
		if(!$this->checkPerm($session_id, 'sites_web_domain_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
420

421
		if(!isset($params['client_group_id']) or (isset($params['client_group_id']) && empty($params['client_group_id']))) {
422
			$rec = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client_id);
423
424
			$params['client_group_id'] = $rec['groupid'];
		}
425

426
427
428
429
		//* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
		if($params['document_root'] == '') $params['document_root'] = '-';
		if($params['system_user'] == '') $params['system_user'] = '-';
		if($params['system_group'] == '') $params['system_group'] = '-';
430
		if($params['log_retention'] == '') $params['log_retention'] = 30;
431

432
433
434
435
436
		//* Set a few defaults for nginx servers
		if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
		if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
		if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
		if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
437

438
		$domain_id = $this->insertQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $params, 'sites:web_vhost_domain:on_after_insert');
439
		if ($readonly === true)
440
			$app->db->query("UPDATE web_domain SET `sys_userid` = '1' WHERE domain_id = ?", $domain_id);
441
442
443
		return $domain_id;
	}

444
445
	//* Update a record
	public function sites_web_domain_update($session_id, $client_id, $primary_id, $params)
446
	{
447
448
449
450
		if(!$this->checkPerm($session_id, 'sites_web_domain_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
451
452
		
		if($params['log_retention'] == '') $params['log_retention'] = 30;
453

454
455
456
457
458
		//* Set a few defaults for nginx servers
		if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
		if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
		if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
		if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
459

Marius Cramer's avatar
Marius Cramer committed
460
		$affected_rows = $this->updateQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $primary_id, $params);
461
462
		return $affected_rows;
	}
463

464
465
	//* Delete a record
	public function sites_web_domain_delete($session_id, $primary_id)
466
	{
467
468
469
470
		if(!$this->checkPerm($session_id, 'sites_web_domain_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
Marius Cramer's avatar
Marius Cramer committed
471
		$affected_rows = $this->deleteQuery('../sites/form/web_vhost_domain.tform.php', $primary_id);
472
473
		return $affected_rows;
	}
474

475
	// ----------------------------------------------------------------------------------------------------------
476

Dominik's avatar
Dominik committed
477
478
479
480
481
	//* Get record details
	public function sites_web_vhost_aliasdomain_get($session_id, $primary_id)
	{
		global $app;

482
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_get')) {
Dominik's avatar
Dominik committed
483
484
485
486
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
487
		$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
Dominik's avatar
Dominik committed
488
489
490
491
492
493
494
		return $app->remoting_lib->getDataRecord($primary_id);
	}

	//* Add a record
	public function sites_web_vhost_aliasdomain_add($session_id, $client_id, $params)
	{
		global $app;
495
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_add')) {
Dominik's avatar
Dominik committed
496
497
498
499
500
501
502
503
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}

		//* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
		if($params['document_root'] == '') $params['document_root'] = '-';
		if($params['system_user'] == '') $params['system_user'] = '-';
		if($params['system_group'] == '') $params['system_group'] = '-';
504
		if($params['log_retention'] == '') $params['log_retention'] = 30;
Dominik's avatar
Dominik committed
505
506
507
508
509
510
511

		//* Set a few defaults for nginx servers
		if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
		if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
		if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
		if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;

512
		$domain_id = $this->insertQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $params, 'sites:web_vhost_aliasdomain:on_after_insert');
Dominik's avatar
Dominik committed
513
514
515
516
517
518
		return $domain_id;
	}

	//* Update a record
	public function sites_web_vhost_aliasdomain_update($session_id, $client_id, $primary_id, $params)
	{
519
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_update')) {
Dominik's avatar
Dominik committed
520
521
522
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
523
524
		
		if($params['log_retention'] == '') $params['log_retention'] = 30;
Dominik's avatar
Dominik committed
525
526
527
528
529
530
531

		//* Set a few defaults for nginx servers
		if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
		if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
		if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
		if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;

532
		$affected_rows = $this->updateQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $primary_id, $params, 'sites:web_vhost_aliasdomain:on_after_insert');
Dominik's avatar
Dominik committed
533
534
535
536
537
538
		return $affected_rows;
	}

	//* Delete a record
	public function sites_web_vhost_aliasdomain_delete($session_id, $primary_id)
	{
539
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_delete')) {
Dominik's avatar
Dominik committed
540
541
542
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
543
		$affected_rows = $this->deleteQuery('../sites/form/web_vhost_domain.tform.php', $primary_id);
Dominik's avatar
Dominik committed
544
545
546
547
548
		return $affected_rows;
	}

	// ----------------------------------------------------------------------------------------------------------

549
550
	//* Get record details
	public function sites_web_vhost_subdomain_get($session_id, $primary_id)
551
	{
552
		global $app;
553

554
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
555
556
557
558
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
559
		$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
560
561
		return $app->remoting_lib->getDataRecord($primary_id);
	}
562

563
564
565
566
	//* Add a record
	public function sites_web_vhost_subdomain_add($session_id, $client_id, $params)
	{
		global $app;
567
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
568
569
570
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
571

572
573
574
575
		//* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
		if($params['document_root'] == '') $params['document_root'] = '-';
		if($params['system_user'] == '') $params['system_user'] = '-';
		if($params['system_group'] == '') $params['system_group'] = '-';
576
		if($params['log_retention'] == '') $params['log_retention'] = 30;
577

578
579
580
581
582
		//* Set a few defaults for nginx servers
		if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
		if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
		if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
		if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
583

584
		$domain_id = $this->insertQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $params, 'sites:web_vhost_subdomain:on_after_insert');
585
586
587
		return $domain_id;
	}

588
589
	//* Update a record
	public function sites_web_vhost_subdomain_update($session_id, $client_id, $primary_id, $params)
590
	{
591
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
592
593
594
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
595
596
		
		if($params['log_retention'] == '') $params['log_retention'] = 30;
597

598
599
600
601
602
		//* Set a few defaults for nginx servers
		if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
		if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
		if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
		if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
603

604
		$affected_rows = $this->updateQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $primary_id, $params, 'sites:web_vhost_subdomain:on_after_insert');
605
606
		return $affected_rows;
	}
607

608
609
	//* Delete a record
	public function sites_web_vhost_subdomain_delete($session_id, $primary_id)
610
	{
611
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
612
613
614
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
615
		$affected_rows = $this->deleteQuery('../sites/form/web_vhost_domain.tform.php', $primary_id);
616
617
		return $affected_rows;
	}
618

619
	// -----------------------------------------------------------------------------------------------
620

621
622
	//* Get record details
	public function sites_web_aliasdomain_get($session_id, $primary_id)
623
	{
624
		global $app;
625

626
627
628
629
630
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
631
		$app->remoting_lib->loadFormDef('../sites/form/web_childdomain.tform.php');
632
633
		return $app->remoting_lib->getDataRecord($primary_id);
	}
634

635
636
	//* Add a record
	public function sites_web_aliasdomain_add($session_id, $client_id, $params)
637
	{
638
639
640
641
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
642
		return $this->insertQuery('../sites/form/web_childdomain.tform.php', $client_id, $params);
643
	}
644

645
646
	//* Update a record
	public function sites_web_aliasdomain_update($session_id, $client_id, $primary_id, $params)
647
	{
648
649
650
651
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
652
		$affected_rows = $this->updateQuery('../sites/form/web_childdomain.tform.php', $client_id, $primary_id, $params);
653
654
		return $affected_rows;
	}
655

656
657
	//* Delete a record
	public function sites_web_aliasdomain_delete($session_id, $primary_id)
658
	{
659
660
661
662
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
663
		$affected_rows = $this->deleteQuery('../sites/form/web_childdomain.tform.php', $primary_id);
664
665
		return $affected_rows;
	}
666

667
	// ----------------------------------------------------------------------------------------------------------
668

669
670
	//* Get record details
	public function sites_web_subdomain_get($session_id, $primary_id)
671
	{
672
		global $app;
673

674
675
676
677
678
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
679
		$app->remoting_lib->loadFormDef('../sites/form/web_childdomain.tform.php');
680
681
		return $app->remoting_lib->getDataRecord($primary_id);
	}
682

683
684
	//* Add a record
	public function sites_web_subdomain_add($session_id, $client_id, $params)
685
	{
686
687
688
689
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
690
		return $this->insertQuery('../sites/form/web_childdomain.tform.php', $client_id, $params);
691
	}
692

693
694
	//* Update a record
	public function sites_web_subdomain_update($session_id, $client_id, $primary_id, $params)
695
	{
696
697
698
699
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
700
		$affected_rows = $this->updateQuery('../sites/form/web_childdomain.tform.php', $client_id, $primary_id, $params);
701
702
		return $affected_rows;
	}
703

704
705
	//* Delete a record
	public function sites_web_subdomain_delete($session_id, $primary_id)
706
	{
707
708
709
710
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
711
		$affected_rows = $this->deleteQuery('../sites/form/web_childdomain.tform.php', $primary_id);
712
713
		return $affected_rows;
	}
714

715
	// ----------------------------------------------------------------------------------------------------------
716

717
718
	//* Get record details
	public function sites_web_folder_get($session_id, $primary_id)
719
	{
720
		global $app;
721

722
723
724
725
726
727
728
729
		if(!$this->checkPerm($session_id, 'sites_web_folder_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/web_folder.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
730

731
732
	//* Add a record
	public function sites_web_folder_add($session_id, $client_id, $params)
733
	{
734
735
736
737
		if(!$this->checkPerm($session_id, 'sites_web_folder_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
738
		return $this->insertQuery('../sites/form/web_folder.tform.php', $client_id, $params);
739
	}
740

741
742
	//* Update a record
	public function sites_web_folder_update($session_id, $client_id, $primary_id, $params)
743
	{
744
745
746
747
		if(!$this->checkPerm($session_id, 'sites_web_folder_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
748
		$affected_rows = $this->updateQuery('../sites/form/web_folder.tform.php', $client_id, $primary_id, $params);
749
750
		return $affected_rows;
	}
751

752
753
	//* Delete a record
	public function sites_web_folder_delete($session_id, $primary_id)
754
	{
755
756
757
758
759
		global $app;
		if(!$this->checkPerm($session_id, 'sites_web_folder_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
760
761

		// Delete all users that belong to this folder. - taken from web_folder_delete.php
762
		$records = $app->db->queryAllRecords("SELECT web_folder_user_id FROM web_folder_user WHERE web_folder_id = ?", $primary_id);
763
		foreach($records as $rec) {
764
			$this->deleteQuery('../sites/form/web_folder_user.tform.php', $rec['web_folder_user_id']);
765
766
767
			//$app->db->datalogDelete('web_folder_user','web_folder_user_id',$rec['web_folder_user_id']);
		}
		unset($records);
768
769

		$affected_rows = $this->deleteQuery('../sites/form/web_folder.tform.php', $primary_id);
770
771
		return $affected_rows;
	}
772

773
	// -----------------------------------------------------------------------------------------------
774

775
776
	//* Get record details
	public function sites_web_folder_user_get($session_id, $primary_id)
777
	{
778
		global $app;
779

780
781
782
783
784
785
786
787
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_get')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../sites/form/web_folder_user.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
788

789
790
	//* Add a record
	public function sites_web_folder_user_add($session_id, $client_id, $params)
791
	{
792
793
794
795
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_add')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
796
		return $this->insertQuery('../sites/form/web_folder_user.tform.php', $client_id, $params);
797
	}
798

799
800
	//* Update a record
	public function sites_web_folder_user_update($session_id, $client_id, $primary_id, $params)
801
	{
802
803
804
805
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_update')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
806
		$affected_rows = $this->updateQuery('../sites/form/web_folder_user.tform.php', $client_id, $primary_id, $params);
807
808
		return $affected_rows;
	}
809

810
811
	//* Delete a record
	public function sites_web_folder_user_delete($session_id, $primary_id)
812
	{
813
814
815
816
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_delete')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
817
		$affected_rows = $this->deleteQuery('../sites/form/web_folder_user.tform.php', $primary_id);
818
819
820
821
822
		return $affected_rows;
	}

	/**
	 * Gets sites by $sys_userid & $sys_groupid
823
824
825
826
827
	 * @param int  session id
	 * @param int  user id
	 * @param array list of groups
	 * @return mixed array with sites by user
	 * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
828
	 */
829
830


831
	public function client_get_sites_by_user($session_id, $sys_userid, $sys_groupid) {
832
833
834
835
836
837
838
839
840
		global $app;
		if(!$this->checkPerm($session_id, 'client_get_sites_by_user')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$sys_userid  = $app->functions->intval($sys_userid);
		$sys_groupid = explode(',', $sys_groupid);
		$new_group = array();
		foreach($sys_groupid as $group_id) {
841
			$new_group[] = $app->functions->intval( $group_id);
842
843
		}
		$group_list = implode(',', $new_group);
844
		$sql ="SELECT domain, domain_id, document_root, active FROM web_domain WHERE ( (sys_userid = $sys_userid  AND sys_perm_user LIKE '%r%') OR (sys_groupid IN ($group_list) AND sys_perm_group LIKE '%r%') OR  sys_perm_other LIKE '%r%') AND type = 'vhost'";
845
846
		$result = $app->db->queryAllRecords($sql);
		if(isset($result)) {
847
			return $result;
848
		} else {
849
850
			throw new SoapFault('no_client_found', 'There is no site for this user');
			return false;
851
852
853
854
855
856
857
858
859
860
861
862
		}
	}



	/**
	 * Change domains status
	 * @param int  session id
	 * @param int  site id
	 * @param string active or inactive string
	 * @return mixed false if error
	 * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
863
	 */
864
865
866
867
868
869
870
871
872
873
874
875
	public function sites_web_domain_set_status($session_id, $primary_id, $status) {
		global $app;
		if(!$this->checkPerm($session_id, 'sites_web_domain_set_status')) {
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		if(in_array($status, array('active', 'inactive'))) {
			if ($status == 'active') {
				$status = 'y';
			} else {
				$status = 'n';
			}
Marius Cramer's avatar
Marius Cramer committed
876
			$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
877
878
879
			$params = $app->remoting_lib->getDataRecord($primary_id);
			$params['active'] = $status;
			
Marius Cramer's avatar
Marius Cramer committed
880
			$affected_rows = $this->updateQuery('../sites/form/web_vhost_domain.tform.php', 0, $primary_id, $params);
881
			return $affected_rows;
882
		} else {
883
884
			throw new SoapFault('status_undefined', 'The status is not available');
			return false;
885
		}
886
887
	}

888
889
890
891
	/**
	 * Get all databases by user
	 * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
	 */
892
	public function sites_database_get_all_by_user($session_id, $client_id)
893
894
	{
		global $app;
895
		if(!$this->checkPerm($session_id, 'sites_database_get')) {
896
897
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
898
		}
899
		$client_id = $app->functions->intval($client_id);
900
901
		$sql = "SELECT d.database_id, d.database_name, d.database_user_id, d.database_ro_user_id, du.database_user, du.database_password FROM web_database d LEFT JOIN web_database_user du ON (du.database_user_id = d.database_user_id) INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = ?";
		$all = $app->db->queryAllRecords($sql, $client_id);
902
		return $all;
903
	}
904
905
906
907
908
909
910
	
	//** backup functions -----------------------------------------------------------------------------------
	public function sites_web_domain_backup_list($session_id, $site_id = null)
	{
		global $app;
	
		if(!$this->checkPerm($session_id, 'sites_web_domain_backup')) {
911
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
912
913
914
			return false;
		}
		
915
		$result = $app->db->queryAllRecords("SELECT * FROM web_backup".(($site_id != null)?' WHERE parent_domain_id = ?':''), $site_id);
916
917
918
919
920
921
922
923
924
		return $result;
	}
	
	//* Backup download and restoration by Abdi Joseph
	public function sites_web_domain_backup($session_id, $primary_id, $action_type)
	{
		global $app;
	
		if(!$this->checkPerm($session_id, 'sites_web_domain_backup')) {
925
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
926
927
928
929
930
931
932
933
934
935
936
937
938
			return false;
		}
	
		//*Set variables
		$backup_record = $app->db->queryOneRecord("SELECT * FROM `web_backup` WHERE `backup_id`= ?", $primary_id);
		$server_id = $backup_record['server_id'];
	
		//*Set default action state
		$action_state = "pending";
		$tstamp = time();
	
		//* Basic validation of variables
		if ($server_id <= 0) {
939
			throw new SoapFault('invalid_backup_id', "Invalid or non existant backup_id $primary_id");
940
941
942
			return false;
		}
	
Dominik's avatar
Dominik committed
943
		if ($action_type != 'backup_download' and $action_type != 'backup_restore' and $action_type != 'backup_delete') {
944
			throw new SoapFault('invalid_action', "Invalid action_type $action_type");
945
946
947
948
949
950
			return false;
		}
	
		//* Validate instance
		$instance_record = $app->db->queryOneRecord("SELECT * FROM `sys_remoteaction` WHERE `action_param`= ? and `action_type`= ? and `action_state`= ?", $primary_id, $action_type, 'pending');
		if ($instance_record['action_id'] >= 1) {
951
			throw new SoapFault('duplicate_action', "There is already a pending $action_type action");
952
953
954
955
956
957
958
959
960
961
962
			return false;
		}
	
		//* Save the record
		if ($app->db->query("INSERT INTO `sys_remoteaction` SET `server_id` = ?, `tstamp` = ?, `action_type` = ?, `action_param` = ?, `action_state` = ?", $server_id, $tstamp, $action_type, $primary_id, $action_state)) {
			return true;
		} else {
			return false;
		}
	}
	
963
	//** quota functions -----------------------------------------------------------------------------------
964
	public function quota_get_by_user($session_id, $client_id)
965
966
967
968
969
	{
		global $app;
		$app->uses('quota_lib');
	
		if(!$this->checkPerm($session_id, 'quota_get_by_user')) {
970
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
971
972
973
			return false;
		}
	
974
		return $app->quota_lib->get_quota_data($client_id, false);
975
976
	}
	
977
978
979
980
981
982
	public function trafficquota_get_by_user($session_id, $client_id, $lastdays = 0)
	{
		global $app;
		$app->uses('quota_lib');
		
		if(!$this->checkPerm($session_id, 'trafficquota_get_by_user')) {
983
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
984
985
986
987
988
989
990
991
			return false;
		}
		if ($client_id != null)
			$client_id = $app->functions->intval($client_id);
		
		return $app->quota_lib->get_trafficquota_data($client_id, $lastdays);
	}
	
Cédric's avatar
Cédric committed
992
993
994
995
996
997
	public function ftptrafficquota_data($session_id, $client_id, $lastdays = 0)
	{
		global $app;
		$app->uses('quota_lib');
		
		if(!$this->checkPerm($session_id, 'trafficquota_get_by_user')) {
998
			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
Cédric's avatar
Cédric committed
999
1000
			return false;
		}
For faster browsing, not all history is shown. View entire blame