<?php
$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";
		
        function sab_url_contents($url){
        $crl = curl_init();
        $timeout = 5;
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
        $ret = curl_exec($crl);
        curl_close($crl);
        return $ret;
                }
				
function siteautobackup_ConfigOptions() {
	# Should return an array of the module options for each product - maximum of 24
    $configarray = array(
	 "Disk Quota" => array( "Type" => "text", "Size" => "5", "Description" => "MB" ),
	);
	return $configarray;
}

function siteautobackup_CreateAccount($params) {	
$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";
			
    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
		
	$packageid = $params["packageid"];
		
		$sab_clientpass = $params["password"];
		$configoptions = $params["configoptions"]; # Array of configurable option values for the product

		# Product module option settings from ConfigOptions array above
		$sab_diskquota = $params["configoption1"];
		
$sabparams2 = "resid=$sabresid&reskey=$sabreskey&action=getresdomain";
$sab_resdomain_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams2");
$sab_object2 = simplexml_load_string($sab_resdomain_xml);	
$sab_resdomain = $sab_object2->sabdata->domain;
		
		$sabparams = "resid=$sabresid&reskey=$sabreskey&cid=$sab_clientid&ckey=$sab_clientpass&ds=$sab_diskquota&action=addclient&clientemail=$email";
		$sab_create = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");
		
		$sab_object = simplexml_load_string($sab_create);	
		$sabresult = $sab_object->sabdata->result;
		if($sabresult == 'success'){
			$successful = '1';
			$sql_update_username = "update tblhosting set username='$sabresid.$sab_clientid@$sab_resdomain' where id = $serviceid";
			mysql_query($sql_update_username);
		}
		
	if ($successful) {
		$result = "success";
	} else {
	
		$result = $sab_object->sabdata->message;
	}
	return $result;
}







function siteautobackup_ChangePackage($params) {
$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
		$configoptions = $params["configoptions"]; # Array of configurable option values for the product

		# Product module option settings from ConfigOptions array above
		$sab_diskquota = $params["configoption1"];
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@dataholder.net&action=changepackage&ds=$sab_diskquota";
$sabchange = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");  

$sab_object = simplexml_load_string($sabchange);	
		$sabresult = $sab_object->sabdata->result;
		if($sabresult == 'success'){
			$successful = '1';
		}
		
	if ($successful) {
		$result = "success";
	} else {
	
		$result = $sab_object->sabdata->message;
	}
return $result;
}








function siteautobackup_TerminateAccount($params) {
$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
	
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@dataholder.net&action=terminate";
$sabterminate = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");

$sab_object = simplexml_load_string($sabterminate);	
		$sabresult = $sab_object->sabdata->result;
		if($sabresult == 'success'){
			$successful = '1';
		}
		
	if ($successful) {
		$result = "success";
	} else {
	
		$result = $sab_object->sabdata->message;
	}
return $result;

}








function siteautobackup_SuspendAccount($params) {
$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
	
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@dataholder.net&action=suspend";
$sabsuspend = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");
$sab_object = simplexml_load_string($sabsuspend);	
		$sabresult = $sab_object->sabdata->result;
		if($sabresult == 'success'){
			$successful = '1';
		}
		
	if ($successful) {
		$result = "success";
	} else {
	
		$result = $sab_object->sabdata->message;
	}
return $result;	
}







function siteautobackup_UnsuspendAccount($params) {

$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
	
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@dataholder.net&action=resume";
$sabresume = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");
$sab_object = simplexml_load_string($sabresume);	
		$sabresult = $sab_object->sabdata->result;
		if($sabresult == 'success'){
			$successful = '1';
		}
		
	if ($successful) {
		$result = "success";
	} else {
	
		$result = $sab_object->sabdata->message;
	}
return $result;


}









function siteautobackup_ChangePassword($params) {

$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}

	$sab_clientpass = $params["password"];

$sabparams2 = "resid=$sabresid&reskey=$sabreskey&action=getresdomain";
$sab_resdomain_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams2");
$sab_object2 = simplexml_load_string($sab_resdomain_xml);	
$sab_resdomain = $sab_object2->sabdata->domain;
	
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@$sab_resdomain&action=setclientpw&newcpwd=$sab_clientpass";
$sabpw = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");
$sab_object = simplexml_load_string($sabpw);	
		$sabresult = $sab_object->sabdata->result;
		if($sabresult == 'success'){
			$successful = '1';
		}

    if ($successful) {
		$result = "success";
	} else {
		$result = "$sabpw";
	}
	return $result;
	
}








function siteautobackup_ClientArea($params) {

$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
	
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@dataholder.net&action=getclientpw";
$sabparams2 = "resid=$sabresid&reskey=$sabreskey&action=getresdomain";

$sab_user_pwd_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");
$sab_resdomain_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams2");

$sab_object = simplexml_load_string($sab_user_pwd_xml);	
$sab_user_pwd = $sab_object->sabdata->password;

$sab_object2 = simplexml_load_string($sab_resdomain_xml);	
$sab_resdomain = $sab_object2->sabdata->domain;
		
$code = "
<form target=\"_blank\" action=\"http://$sab_resdomain\" method=\"post\" name=\"frmlogin\" id=\"frmlogin\">
<input type=\"hidden\" name=\"username\" value=\"$sabresid.$sab_clientid@dataholder.net\" />
<input type=\"hidden\" name=\"password\" value=\"$sab_user_pwd\" />
<input type=\"submit\" value=\"Login to Backup Panel\" />
</form>	
	";

	return $code;
}








function siteautobackup_AdminLink($params) {

$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
	
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@dataholder.net&action=getclientpw";
$sabparams2 = "resid=$sabresid&reskey=$sabreskey&action=getresdomain";

$sab_user_pwd_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");
$sab_resdomain_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams2");

$sab_object = simplexml_load_string($sab_user_pwd_xml);	
$sab_user_pwd = $sab_object->sabdata->password;

$sab_object2 = simplexml_load_string($sab_resdomain_xml);	
$sab_resdomain = $sab_object2->sabdata->domain;
		
$code = "
<a href=\"http://$sab_resdomain/?username=$sabresid.$sab_clientid@$sab_resdomain&password=$sab_user_pwd\" target=\"_blank\"><strong>&gt;&gt;&gt; LOGIN TO BACKUP PANEL &lt;&lt;&lt; </strong></a>
	";
	
	print $code;
	
}







function siteautobackup_LoginLink($params) {

$sabreskey = "52C1v6tq7sBkPBrsjfayu6pfHfUKhAMBqdSIggJtJttLydXCfw2lit0ALBHv3pOI";
$sabresid = "4409";

    $serviceid = $params["serviceid"]; # Unique ID of the product/service in the WHMCS Database
    $clientsdetails = $params["clientsdetails"];
	$email = $clientsdetails['email'];
	$sql_getcid = "select id from tblclients where email='$email'";
	$do_getcid = mysql_query($sql_getcid);
	
	while($row = mysql_fetch_array($do_getcid, MYSQL_ASSOC)){
		$sab_clientid = $row['id'];
	}
	
$sabparams = "resid=$sabresid&reskey=$sabreskey&ruser=$sabresid.$sab_clientid@dataholder.net&action=getclientpw";
$sabparams2 = "resid=$sabresid&reskey=$sabreskey&action=getresdomain";

$sab_user_pwd_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams");
$sab_resdomain_xml = sab_url_contents("https://www.siteautobackup.com/api.php?$sabparams2");

$sab_object = simplexml_load_string($sab_user_pwd_xml);	
$sab_user_pwd = $sab_object->sabdata->password;

$sab_object2 = simplexml_load_string($sab_resdomain_xml);	
$sab_resdomain = $sab_object2->sabdata->domain;
		
$code = "
<a href=\"http://$sab_resdomain/?username=$sabresid.$sab_clientid@$sab_resdomain&password=$sab_user_pwd\" target=\"_blank\"><strong>&gt;&gt;&gt; LOGIN TO BACKUP PANEL &lt;&lt;&lt; </strong></a>
	";

	print $code;
}







function siteautobackup_AdminCustomButtonArray() {
	# This function can define additional functions your module supports, the example here is a reboot button and then the reboot function is defined below
    $buttonarray = array(
	 "Reboot Server" => "reboot",
	);
	return $buttonarray;
}


function siteautobackup_reboot($params) {

	# Code to perform action goes here...

    if ($successful) {
		$result = "success";
	} else {
		$result = "Error Message Goes Here...";
	}
	return $result;
}

?>