Skip to content
mail.inc.php 37.6 KiB
Newer Older
<?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_mail extends remoting {
	//* Get mail domain details
	public function mail_domain_get($session_id, $primary_id)
		global $app;
		if(!$this->checkPerm($session_id, 'mail_domain_get')) {
			throw new ISPConfigRemoteException('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($primary_id);
	}
	//* Add a mail domain
	public function mail_domain_add($session_id, $client_id, $params)
		if(!$this->checkPerm($session_id, 'mail_domain_add')) {
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
		$primary_id = $this->insertQuery('../mail/form/mail_domain.tform.php', $client_id, $params);
		return $primary_id;
	}
	//* Update a mail domain
	public function mail_domain_update($session_id, $client_id, $primary_id, $params)
		if(!$this->checkPerm($session_id, 'mail_domain_update')) {
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php', $client_id, $primary_id, $params);
		return $affected_rows;
	}
	//* Delete a mail domain
	public function mail_domain_delete($session_id, $primary_id)
		if(!$this->checkPerm($session_id, 'mail_domain_delete')) {
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->deleteQuery('../mail/form/mail_domain.tform.php', $primary_id);
		return $affected_rows;
	}
	//* Get alias details
	public function mail_aliasdomain_get($session_id, $primary_id)
		global $app;
		if(!$this->checkPerm($session_id, 'mail_aliasdomain_get')) {
			throw new ISPConfigRemoteException('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_aliasdomain.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
	//* aliasy email
	public function mail_aliasdomain_add($session_id, $client_id, $params)
	{
		if (!$this->checkPerm($session_id, 'mail_aliasdomain_add'))
		{
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->insertQuery('../mail/form/mail_aliasdomain.tform.php', $client_id, $params);
		return $affected_rows;
	}


	public function mail_aliasdomain_update($session_id, $client_id, $primary_id, $params)
	{
		if (!$this->checkPerm($session_id, 'mail_aliasdomain_update'))
		{
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->updateQuery('../mail/form/mail_aliasdomain.tform.php', $client_id, $primary_id, $params);
		return $affected_rows;
	}

	public function mail_aliasdomain_delete($session_id, $primary_id)
	{
		if (!$this->checkPerm($session_id, 'mail_aliasdomain_delete'))
		{
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->deleteQuery('../mail/form/mail_aliasdomain.tform.php', $primary_id);
		return $affected_rows;
	//* Get mail user details
	public function mail_user_get($session_id, $primary_id)
		if(!$this->checkPerm($session_id, 'mail_user_get')) {
			throw new ISPConfigRemoteException('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_user.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
	//* Add mail domain
	public function mail_user_add($session_id, $client_id, $params){
		global $app;
		if (!$this->checkPerm($session_id, 'mail_user_add')){
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
		//* Check if mail domain exists
		$email_parts = explode('@', $params['email']);
		$tmp = $app->db->queryOneRecord("SELECT domain FROM mail_domain WHERE domain = ?", $email_parts[1]);
		if($tmp['domain'] != $email_parts[1]) {
			throw new ISPConfigRemoteException('mail_domain_does_not_exist', 'Mail domain - '.$email_parts[1].' - does not exist.');
Dominik's avatar
Dominik committed
		//* Set a few params to non empty values that will be overwritten by mail_plugin
Dominik's avatar
Dominik committed
		if (!isset($params['uid'])) $params['uid'] = -1;
		if (!isset($params['gid'])) $params['gid'] = -1;
		if (!isset($params['maildir_format'])) $params['maildir_format'] = 'maildir';
Dominik's avatar
Dominik committed

		$mailuser_id = $this->insertQuery('../mail/form/mail_user.tform.php', $client_id, $params);
		return $mailuser_id;
	//* Update mail user
	public function mail_user_update($session_id, $client_id, $primary_id, $params)
	{
		global $app;
		if (!$this->checkPerm($session_id, 'mail_user_update'))
		{
			throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
		//* Check if mail domain exists
		$email_parts = explode('@', $params['email']);
		$tmp = $app->db->queryOneRecord("SELECT domain FROM mail_domain WHERE domain = ?", $email_parts[1]);
		if($tmp['domain'] != $email_parts[1]) {
			throw new ISPConfigRemoteException('mail_domain_does_not_exist', 'Mail domain - '.$email_parts[1].' - does not exist.');
		$affected_rows = $this->updateQuery('../mail/form/mail_user.tform.php', $client_id, $primary_id, $params);
		return $affected_rows;
	}
Loading full blame...