remoting.inc.php 31.5 KB
Newer Older
1 2
<?php

redray's avatar
redray committed
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
/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 30 31 32 33 34

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

redray's avatar
redray committed
35 36
*/

37 38 39 40 41
class remoting {
	
	//* remote session timeout in seconds
	private $session_timeout = 600;
	
tbrehm's avatar
tbrehm committed
42 43 44 45 46 47 48
	private $server;
	
	/*
	These variables shall stay global. 
	Please do not make them private variables.
    
	private $app;
49
    private $conf;
tbrehm's avatar
tbrehm committed
50
    */
51 52 53

    public function __construct()
    {
tbrehm's avatar
tbrehm committed
54
        global $server;
55
        $this->server = $server;
tbrehm's avatar
tbrehm committed
56
		/*
57 58
        $this->app = $app;
        $this->conf = $conf;
tbrehm's avatar
tbrehm committed
59
		*/
60 61
    }

62
	//* remote login function
pedro_morgan's avatar
pedro_morgan committed
63 64
	public function login($username, $password)
    {
tbrehm's avatar
tbrehm committed
65 66
		global $app, $conf, $server;
		
67
		if(empty($username)) {
68
			$this->server->fault('login_username_empty', 'The login username is empty');
69 70 71 72
			return false;
		}
		
		if(empty($password)) {
73
			$this->server->fault('login_password_empty', 'The login password is empty');
74 75 76
			return false;
		}
		
tbrehm's avatar
tbrehm committed
77 78
		$username = $app->db->quote($username);
		$password = $app->db->quote($password);
79 80
		
		$sql = "SELECT * FROM remote_user WHERE remote_username = '$username' and remote_password = md5('$password')";
tbrehm's avatar
tbrehm committed
81
		$remote_user = $app->db->queryOneRecord($sql);
82 83 84 85 86 87 88
		if($remote_user['remote_userid'] > 0) {
			//* Create a remote user session
			srand ((double)microtime()*1000000);
			$remote_session = md5(rand());
			$remote_userid = $remote_user['remote_userid'];
			$remote_functions = $remote_user['remote_functions'];
			$tstamp = time() + $this->session_timeout;
89 90 91
			$sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp'
                   .') VALUES ('
                   ." '$remote_session',$remote_userid,'$remote_functions',$tstamp)";
tbrehm's avatar
tbrehm committed
92
			$app->db->query($sql);
93 94
			return $remote_session;
		} else {
95
			$this->server->fault('login_failed', 'The login failed. Username or password wrong.');
96 97 98 99 100 101
			return false;
		}
		
	}
	
	//* remote logout function
pedro_morgan's avatar
pedro_morgan committed
102
	public function logout($session_id)
103
    {		
tbrehm's avatar
tbrehm committed
104 105
		global $app;
		
106
		if(empty($session_id)) {
107
			$this->server->fault('session_id_empty', 'The SessionID is empty.');
108 109 110
			return false;
		}
		
tbrehm's avatar
tbrehm committed
111
		$session_id = $app->db->quote($session_id);
112 113
		
		$sql = "DELETE FROM remote_session WHERE remote_session = '$session_id'";
tbrehm's avatar
tbrehm committed
114 115
		$app->db->query($sql);
        return ($app->db->affectedRows() == 1);
116 117
	}
	
tbrehm's avatar
tbrehm committed
118 119 120 121 122 123 124 125 126 127 128
	//* Get mail domain details
	public function mail_domain_get($session_id, $domain_id)
    {
		if(!$this->checkPerm($session_id, 'mail_domain_get')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../mail/form/mail_domain.tform.php');
		return $app->remoting_lib->getDataRecord($domain_id);
	}
tbrehm's avatar
tbrehm committed
129
	
tbrehm's avatar
tbrehm committed
130
	//* Add a mail domain
tbrehm's avatar
tbrehm committed
131
	public function mail_domain_add($session_id, $client_id, $params)
pedro_morgan's avatar
pedro_morgan committed
132 133
    {
		if(!$this->checkPerm($session_id, 'mail_domain_add')) {
134
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
135 136
			return false;
		}
tbrehm's avatar
tbrehm committed
137 138 139 140
		$domain_id = $this->insertQuery('../mail/form/mail_domain.tform.php',$client_id,$params);
		return $domain_id;
	}
	
tbrehm's avatar
tbrehm committed
141
	//* Update a mail domain
tbrehm's avatar
tbrehm committed
142 143 144 145 146 147
	public function mail_domain_update($session_id, $client_id, $domain_id, $params)
    {
		if(!$this->checkPerm($session_id, 'mail_domain_update')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
tbrehm's avatar
tbrehm committed
148 149 150 151 152 153 154 155 156 157 158
		$affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php',$client_id,$domain_id,$params);
		return $affected_rows;
	}
	
	//* Delete a mail domain
	public function mail_domain_delete($session_id, $domain_id)
    {
		if(!$this->checkPerm($session_id, 'mail_domain_delete')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
159 160 161 162 163 164 165 166 167 168
		$affected_rows = $this->deleteQuery('../mail/form/mail_domain.tform.php',$domain_id);
		return $affected_rows;
	}
	//* dodanie uzytkownika email
	public function mail_user_add($session_id,$domain_id, $client_id, $params){
		if (!$this->checkPerm($session_id, 'mail_user_add')){
			$this->server->fault('permission_denied','You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->insertQuery('../mail/form/mail_user.tform.php',$domain_id, $client_id, $params);
tbrehm's avatar
tbrehm committed
169
		return $affected_rows;
170
	}
171 172 173 174 175 176 177 178 179 180 181 182 183

	//* edycja uzytkownika email	
	public function mail_user_update($session_id, $client_id, $domain_id, $params)
	{
		if (!$this->checkPerm($session_id, 'mail_user_update'))
		{
			$this->server->fault('permission_denied','You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->updateQuery('../mail/form/mail_user.tform.php', $client_id, $domain_id, $params);
		return $affected_rows;
	}

184
	
185 186 187 188 189 190 191 192 193 194 195 196
	//*usuniecie uzytkownika emial
	public function mail_user_delete($session_id,$domain_id)
	{
		if (!$this->checkPerm($session_id, 'mail_user_delete'))
		{
			$this->server->fault('permission_denied','You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->deleteQuery('../mail/form/mail_user.tform.php',$domain_id);
		return $affected_rows;
	}

197
	
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
	//* aliasy email
	public function mail_alias_add($session_id,$domain_id, $client_id, $params)
	{
		if (!$this->checkPerm($session_id, 'mail_alias_add'))
		{
			$this->server->fault('permission_denied','You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->insertQuery('../mail/form/mail_alias.tform.php', $domain_id,  $client_id, $params);
		return $affected_rows;
	}


        public function mail_alias_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_alias_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_alias.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }

	public function mail_alias_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_alias_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_alias.tform.php',$domain_id);
                return $affected_rows;
        }


	 //* przekierowania email
        public function mail_forward_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_forward_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/mail_forward.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_forward_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_forward_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_forward.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }
	

	public function mail_forward_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_forward_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_forward.tform.php',$domain_id);
                return $affected_rows;
        }


	//* catchall e-mail
 	public function mail_catchall_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_catchall_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/mail_domain_catchall.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_catchall_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_catchall_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_catchall_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_catchall_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_domain_catchall.tform.php',$domain_id);
                return $affected_rows;
        }

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 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 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 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
	//* przeniesienia e-mail
        public function mail_transport_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_transport_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/mail_transport.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_transport_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_transport_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_transport.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_transport_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_transport_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_transport.tform.php',$domain_id);
                return $affected_rows;
        }


	 //* biała lista e-mail
        public function mail_spamfilter_whitelist_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/spamfilter_whitelist.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_spamfilter_whitelist_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_spamfilter_whitelist_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/spamfilter_whitelist.tform.php',$domain_id);
                return $affected_rows;
        }


	
	 //* czarna lista e-mail
        public function mail_spamfilter_blacklist_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/spamfilter_blacklist.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_spamfilter_blacklist_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_spamfilter_blacklist_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/spamfilter_blacklist.tform.php',$domain_id);
                return $affected_rows;
        }

	
         //* filtr spamu użytkowników e-mail
        public function mail_spamfilter_user_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_user_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/spamfilter_users.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_spamfilter_user_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_user_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/spamfilter_users.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_spamfilter_user_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_spamfilter_user_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/spamfilter_users.tform.php',$domain_id);
                return $affected_rows;
        }


	
	 //* polityki filtrów spamu e-mail
        public function mail_policy_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_policy_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/spamfilter_policy.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_policy_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_policy_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_policy_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_policy_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/spamfilter_policy.tform.php',$domain_id);
                return $affected_rows;
        }


         //* fetchmail
        public function mail_fetchmail_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_fetchmail_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/mail_get.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_fetchmail_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_fetchmail_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_get.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_fetchmail_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_fetchmail_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_get.tform.php',$domain_id);
                return $affected_rows;
        }


         //* wpisy białej listy
        public function mail_whitelist_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_whitelist_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/mail_whitelist.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_whitelist_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_whitelist_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_whitelist.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_whitelist_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_whitelist_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_whitelist.tform.php',$domain_id);
                return $affected_rows;
        }


	//* wpisy białej listy
        public function mail_blacklist_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_blacklist_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/mail_blacklist.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_blacklist_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_blacklist_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_blacklist.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_blacklist_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_blacklist_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_blacklist.tform.php',$domain_id);
                return $affected_rows;
        }


        //* wpisy filtrow e-mail
        public function mail_filter_add($session_id,$domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_filter_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->insertQuery('../mail/form/mail_content_filter.tform.php', $domain_id,  $client_id, $params);
                return $affected_rows;
        }


        public function mail_filter_update($session_id, $domain_id, $client_id, $params)
        {
                if (!$this->checkPerm($session_id, 'mail_filter_update'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->updateQuery('../mail/form/mail_content_filter.tform.php', $client_id, $domain_id, $params);
                return $affected_rows;
        }


        public function mail_filter_delete($session_id,$domain_id)
        {
                if (!$this->checkPerm($session_id, 'mail_filter_delete'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
                $affected_rows = $this->deleteQuery('../mail/form/mail_content_filter.tform.php',$domain_id);
                return $affected_rows;
        }




	/* 
	 * 
	 * 
	 * 
	 * 	 * klient add :)
	 * 
	 * 
	 */

		public function client_add($session_id,$domain_id, $client_id, $params)
        {
        	if (!$this->checkPerm($session_id, 'client_add'))
                {
                        $this->server->fault('permission_denied','You do not have the permissions to access this function.');
                        return false;
                }
            $affected_rows = $this->klientadd('../client/form/client.tform.php',$domain_id, $client_id, $params);
            return $affected_rows;  
                      
        }
  

        


pedro_morgan's avatar
pedro_morgan committed
670
	//** private functions -----------------------------------------------------------------------------------
671
	
tbrehm's avatar
tbrehm committed
672
	
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721


private function klientadd($formdef_file, $client_id, $params)
    {
		global $app, $tform, $remoting_lib;
		$app->uses('remoting_lib');
			
		//* Load the form definition
		$app->remoting_lib->loadFormDef($formdef_file);
		
		//* load the user profile of the client
		$app->remoting_lib->loadUserProfile($client_id);		
		
		//* Get the SQL query
		$sql = $app->remoting_lib->getSQL($params,'INSERT',0);
		if($app->remoting_lib->errorMessage != '') {
			$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
			return false;
		}
		
		$app->db->query($sql);
		
		if($app->db->errorMessage != '') {
			$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
			return false;
		}
		
					
		
		$insert_id = $app->db->insertID();	
		//$app->uses('tform');
		//* Save changes to Datalog
		if($app->remoting_lib->formDef["db_history"] == 'yes') {
			$new_rec = $app->remoting_lib->getDataRecord($insert_id);
			$app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);
			
		$app->remoting_lib->dodaj_usera($params,$insert_id);

		}
		
		
		
		
		return $insert_id;
	}




tbrehm's avatar
tbrehm committed
722
	private function insertQuery($formdef_file, $client_id, $params)
pedro_morgan's avatar
pedro_morgan committed
723
    {
724
		global $app, $tform, $remoting_lib;
tbrehm's avatar
tbrehm committed
725 726 727 728 729 730 731 732 733 734
		
		$app->uses('remoting_lib');
		
		//* Load the form definition
		$app->remoting_lib->loadFormDef($formdef_file);
		
		//* load the user profile of the client
		$app->remoting_lib->loadUserProfile($client_id);
		
		//* Get the SQL query
tbrehm's avatar
tbrehm committed
735
		$sql = $app->remoting_lib->getSQL($params,'INSERT',0);
tbrehm's avatar
tbrehm committed
736 737 738 739 740 741 742 743 744 745 746 747
		if($app->remoting_lib->errorMessage != '') {
			$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
			return false;
		}
		
		$app->db->query($sql);
		
		if($app->db->errorMessage != '') {
			$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
			return false;
		}
		
tbrehm's avatar
tbrehm committed
748
		$insert_id = $app->db->insertID();
tbrehm's avatar
tbrehm committed
749
		
750 751 752
		
	
		//$app->uses('tform');
tbrehm's avatar
tbrehm committed
753 754 755
		//* Save changes to Datalog
		if($app->remoting_lib->formDef["db_history"] == 'yes') {
			$new_rec = $app->remoting_lib->getDataRecord($insert_id);
756 757
			$app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);
			
tbrehm's avatar
tbrehm committed
758
		}
tbrehm's avatar
tbrehm committed
759 760 761
		
		
		
tbrehm's avatar
tbrehm committed
762 763
		
		return $insert_id;
tbrehm's avatar
tbrehm committed
764
	}
765
	
tbrehm's avatar
tbrehm committed
766 767
	
	private function updateQuery($formdef_file, $client_id, $primary_id, $params)
tbrehm's avatar
tbrehm committed
768 769 770 771 772 773 774 775 776 777 778 779
    {
		global $app;
		
		$app->uses('remoting_lib');
		
		//* Load the form definition
		$app->remoting_lib->loadFormDef($formdef_file);
		
		//* load the user profile of the client
		$app->remoting_lib->loadUserProfile($client_id);
		
		//* Get the SQL query
tbrehm's avatar
tbrehm committed
780
		$sql = $app->remoting_lib->getSQL($params,'UPDATE',$primary_id);
tbrehm's avatar
tbrehm committed
781 782 783 784 785
		if($app->remoting_lib->errorMessage != '') {
			$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
			return false;
		}
		
tbrehm's avatar
tbrehm committed
786 787
		$old_rec = $app->remoting_lib->getDataRecord($primary_id);
		
tbrehm's avatar
tbrehm committed
788 789 790 791 792 793 794
		$app->db->query($sql);
		
		if($app->db->errorMessage != '') {
			$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
			return false;
		}
		
tbrehm's avatar
tbrehm committed
795
		$affected_rows = $app->db->affectedRows();
tbrehm's avatar
tbrehm committed
796
		
tbrehm's avatar
tbrehm committed
797 798 799
		//* Save changes to Datalog
		if($app->remoting_lib->formDef["db_history"] == 'yes') {
			$new_rec = $app->remoting_lib->getDataRecord($primary_id);
800
			$app->remoting_lib->datalogSave('UPDATE',$primary_id,$old_rec,$new_rec);
tbrehm's avatar
tbrehm committed
801
		}
tbrehm's avatar
tbrehm committed
802 803 804
		
		
		
tbrehm's avatar
tbrehm committed
805 806 807 808 809 810
		return $affected_rows;
	}
	
	private function deleteQuery($formdef_file, $primary_id)
    {
		global $app;
tbrehm's avatar
tbrehm committed
811
		
tbrehm's avatar
tbrehm committed
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
		$app->uses('remoting_lib');
		
		//* Load the form definition
		$app->remoting_lib->loadFormDef($formdef_file);
		
		//* Get the SQL query
		$sql = $app->remoting_lib->getDeleteSQL($primary_id);
		
		$app->db->query($sql);
		
		if($app->db->errorMessage != '') {
			$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
			return false;
		}
		
		$affected_rows = $app->db->affectedRows();
		
		//* Save changes to Datalog
		if($app->remoting_lib->formDef["db_history"] == 'yes') {
			$rec = $app->remoting_lib->getDataRecord($primary_id);
832
			$app->remoting_lib->datalogSave('DELETE',$primary_id,$rec,array());
tbrehm's avatar
tbrehm committed
833 834 835 836
		}
		
		
		return $affected_rows;
837 838 839
	}
	
	
pedro_morgan's avatar
pedro_morgan committed
840 841
	private function checkPerm($session_id, $function_name)
    {
842 843
	$dobre=Array();
	$session = $this->getSession($session_id);
pedro_morgan's avatar
pedro_morgan committed
844 845 846
        if(!$session){
            return false;
        }
847 848 849
		
		$dobre= str_replace(';',',',$session['remote_functions']);
		return in_array($function_name, explode(',', $dobre) );
850 851 852
	}
	
	
pedro_morgan's avatar
pedro_morgan committed
853
	private function getSession($session_id)
854
    {	
tbrehm's avatar
tbrehm committed
855 856
		global $app;
		
857
		if(empty($session_id)) {
858
			$this->server->fault('session_id_empty','The SessionID is empty.');
859 860 861
			return false;
		}
		
tbrehm's avatar
tbrehm committed
862
		$session_id = $app->db->quote($session_id);
863 864 865
		
		$now = time();
		$sql = "SELECT * FROM remote_session WHERE remote_session = '$session_id' AND tstamp >= $now";
tbrehm's avatar
tbrehm committed
866
		$session = $app->db->queryOneRecord($sql);
867 868 869
		if($session['remote_userid'] > 0) {
			return $session;
		} else {
870
			$this->server->fault('session_does_not_exist','The Session is expired or does not exist.');
871 872 873 874 875
			return false;
		}
	}
}

876
?>