Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Developers' Forum

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 20th March 2013, 09:24
abdi abdi is offline
Senior Member
 
Join Date: Sep 2012
Posts: 118
Thanks: 0
Thanked 10 Times in 6 Posts
Lightbulb My first step to contributing

Hello Till,

Let this be my first thread to understanding ISPConfig3 code structure so that I can contribute. My first contribution is add a new API function for downloading and restoring of backup files through API.

Please help as much as possible in this thread to achieve that goal. Then I can hit more complex functions.

Will keep you updated along the way ..

Joseph
Reply With Quote
Sponsored Links
  #2  
Old 20th March 2013, 19:52
abdi abdi is offline
Senior Member
 
Join Date: Sep 2012
Posts: 118
Thanks: 0
Thanked 10 Times in 6 Posts
Lightbulb Complete

Hello Till,

Here is the backup download / restore API function. I have tested it and it works. You may however advice on the code formats and if any suggestions especially in the area of reporting errors.

Code:
	//* Backup download and restoration by Abdi Joseph
	public function sites_web_domain_backup($session_id, $backup_id, $params)
    {
		global $app;
		
		//*Set variables
		$action_type	=	$params['action_type'];		
		$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) return "Invalid or non existant backup_id $backup_id";
		if ($action_type != 'backup_download' and $action_type != 'backup_restore') return "Invalid action_type $action_type";
		
		//* 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) return "There is already a pending $action_type action";
		
		//* 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;
	}
To test drive it you can use the following:

Code:
try 
{ 
	$session_id = $client->login($username,$password);
	
	//* Set the function parameters.
	$backup_id 		= 	2;
	$action_type	=	"backup_restore";
	$params = array(
			'action_type' 	=> $action_type
			);
	
	print_r($client->sites_web_domain_backup($session_id, $backup_id, $params));
} catch (SoapFault $e) { echo $client->__getLastResponse(); die('SOAP Error: '.$e->getMessage()); }
If everything is fine, let me so that I can work on the documentation as well ...

I will attach the finel remoting.inc.php file on your approval.
Reply With Quote
The Following User Says Thank You to abdi For This Useful Post:
till (21st March 2013)
  #3  
Old 21st March 2013, 10:35
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,495
Thanks: 835
Thanked 5,535 Times in 4,353 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
  #4  
Old 21st March 2013, 13:55
abdi abdi is offline
Senior Member
 
Join Date: Sep 2012
Posts: 118
Thanks: 0
Thanked 10 Times in 6 Posts
Default

Thanks for that information Till,

I have made the changes accordingly and tested it and yes it works fine!

What is the way forward in this regard now to have this function added to the future versions?

First I guess I need to prepare the API documenation and example file, right?

Joseph
Reply With Quote
  #5  
Old 21st March 2013, 22:23
abdi abdi is offline
Senior Member
 
Join Date: Sep 2012
Posts: 118
Thanks: 0
Thanked 10 Times in 6 Posts
Lightbulb Finel Changes

Hello Till,

Please find attached my entire changes ...
The attachment includes:

1. /interface/lib/classes/remoting.inc
2. API documentation (sites_web_domain_backup.html)
3. API navigation file (navigation.html)
4. API example file (sites_web_domain_backup.php)

I have tested these API changes on my production server and everything works fine.

I just made a slight change to the proposed code though:

Instead of return true, I changed to return SUCCESS
and Instead of return false, I changed to return FAIL

Let me know if there any comments or suggestions ..

Joseph
Attached Files
File Type: zip ISPConfig3.0.5 API Changes.zip (19.7 KB, 43 views)
Reply With Quote
The Following 5 Users Say Thank You to abdi For This Useful Post:
florian030 (22nd March 2013), markc (25th March 2013), till (25th March 2013), zapyahoo (23rd March 2013), zool (26th March 2013)
  #6  
Old 25th March 2013, 17:35
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,495
Thanks: 835
Thanked 5,535 Times in 4,353 Posts
Default

Thanks for your contribution. I've added it to the bugtracker as proposed for inclusion.

Quote:
Instead of return true, I changed to return SUCCESS
and Instead of return false, I changed to return FAIL
Thats inconsistent with the other api functions, so I will have to change that to true/false before we can include your code.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #7  
Old 25th March 2013, 22:21
abdi abdi is offline
Senior Member
 
Join Date: Sep 2012
Posts: 118
Thanks: 0
Thanked 10 Times in 6 Posts
Default

Hello Till,

Please find attached ALL new changes applied with return being to TRUE and FALSE.

Changes include in

1. remoting.inc.php
2. sites_web_domain_backup.html (API documentation file)
3. sites_web_domain_backup.php (API example file)

Joseph
Attached Files
File Type: zip ISPConfig3.0.5 API -new- Changes.zip (19.6 KB, 50 views)

Last edited by abdi; 26th March 2013 at 03:19.
Reply With Quote
The Following User Says Thank You to abdi For This Useful Post:
till (27th March 2013)
  #8  
Old 26th March 2013, 16:11
zool zool is offline
Junior Member
 
Join Date: Apr 2012
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi,

and Thanx for nice Job.
Reply With Quote
  #9  
Old 26th March 2013, 16:13
abdi abdi is offline
Senior Member
 
Join Date: Sep 2012
Posts: 118
Thanks: 0
Thanked 10 Times in 6 Posts
Default

Your welcome

Have you tested it?
Reply With Quote
  #10  
Old 27th March 2013, 10:29
zool zool is offline
Junior Member
 
Join Date: Apr 2012
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
 
Default

Hi
i Code today get function for this Backup method.

greetz
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Horde Groupware Webmail Edition ByteMe Networking Tips/Tricks/Mods 17 20th December 2012 11:12
Migrating to ISPConfig - step by step (postfixadmin + Anti-Spam-Solution + roundcube) osterhase Installation/Configuration 2 30th July 2011 21:10
Companion Script #2 for The Perfect Server - Fedora 13 x86_64 [ISPConfig 3]" MrCompTech Tips/Tricks/Mods 0 10th July 2010 06:11
CentOS 4.4 (64-bit) Installation Script Bailx Tips/Tricks/Mods 10 22nd February 2008 02:20
Step by Step add site gecew Installation/Configuration 7 16th October 2007 12:00


All times are GMT +2. The time now is 11:37.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.