View Single Post
  #3  
Old 21st March 2013, 09:35
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 34,586
Thanks: 792
Thanked 4,983 Times in 3,903 Posts
Default

The function is generally fine, just a few minor things:

- The permission check is missing.
- Errors are not returned as soap faults.
- The params array contains only one value if I see it correctly, you should use $action as parameter and not $params array.

About the syntax, please use { ... } in if / else statements.

Here my proposed changes (untested):

Code:
//* Backup download and restoration by Abdi Joseph
	public function sites_web_domain_backup($session_id, $backup_id, $action_type)
    {
		global $app;
		
		if(!$this->checkPerm($session_id, 'sites_web_domain_update')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		
		//*Set variables	
		$backup_record 	= 	$app->db->queryOneRecord("SELECT * FROM `web_backup` WHERE `backup_id`='$backup_id'");		
		$server_id		=	$backup_record['server_id'];

		//*Set default action state
		$action_state	=	"pending";		
		$tstamp			=	time();
		
		//* Basic validation of variables
		if ($server_id <= 0) {
		    $this->server->fault('invalid_backup_id', "Invalid or non existant backup_id $backup_id");
            return false;
		}

		if ($action_type != 'backup_download' and $action_type != 'backup_restore') {
		   $this->server->fault('invalid_action', "Invalid action_type $action_type");
            return false;
		}

		//* Validate instance
		$instance_record	=	$app->db->queryOneRecord("SELECT * FROM `sys_remoteaction` WHERE `action_param`='$backup_id' and `action_type`='$action_type' and `action_state`='pending'");	
		if ($instance_record['action_id'] >= 1) {
		    $this->server->fault('duplicate_action', "There is already a pending $action_type action");
            return false;
		}
		
		//* Save the record
		if ($app->db->query("INSERT INTO `sys_remoteaction` SET 
			`server_id`		=	'$server_id',
			`tstamp`		=	'$tstamp',
 	 		`action_type`	=	'$action_type',
 	 		`action_param`	=	'$backup_id',
			`action_state`	=	'$action_state'")) {
			    return true;
		} else {
		    return false;
		}
	}
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote