Jump to content
Froxlor Forum
  • 0

Integration


AltruHost

Question

Hey All,

 

I'm in the process of starting a hosting company in which we are going to be offering shared hosting and openvz vps's initially and later kvm vps's. I've written a billing application along with our own custom control panel for openvz... which vzctl makes that so simple. Anyways, we're running Gentoo on our servers and because of the types of guys we are we would love to be able to offer nginx/php-fpm shared hosting which is when I stumbled on to your CP which I find to be a great fit for what we are trying to offer. So in order to do this I will be integrating our billing application with froxlor... I have looked at your db schema and it seems pretty straight forward if I want to push directly into the db to create the accounts and the auto-login will be easy to generate the posts for... my questions are: 1) should I be pushing directly into the db or do you have a preferred method for your integration such as a soap or cli api? 2) is there anything special that I should know about that may throw me for a loop in this process?

 

Thanks for any direction...

 

Austin

AltruHost, LLC

http://www.altruhost.com

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

So I finally got around to writing the integration class and debugging it... so here it is, if anyone wants to critique feel free, if anyone wants to use it feel free however you'll have to modify it for your logging purposes... also as you can see I'll be adding some stuff as there is an empty function... oh and don't forget to create the config files or just hard code the values in somewhere...

 


<?php

class altruFroxlor {
private $logWriter;
private $froxlorDB;
private $admin_id;
private $ip_id;
private $ssl_ip_id;
private $docroot_path;

function __construct($ip,$port,$frox_db_username,$frox_db_password,$frox_db_name){
	include_once("config/config.inc.php");
	include_once("config/froxlor.inc.php");
	include_once("classes/altrulog.class.php");
	require_once('MDB2.php');

	$this->logWriter = new altruLogging($error_log,$debug_log,$debug);		

	$this->admin_id = $froxlor_admin_id;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - admin_id = $this->admin_id");
	$this->ip_id = $froxlor_ip_id;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - ip_id = $this->ip_id");
	$this->ssl_ip_id = $froxlor_ssl_ip_id;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - ssl_ip_id = $this->ssl_ip_id");
	$this->docroot_path = $froxlor_docroot_path;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - docroot_path = $this->docroot_path");

	$strFroxlorDB = "mysql://$frox_db_username:$frox_db_password@$ip:$port/$frox_db_name";
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - using db connection string: $strFroxlorDB");
	$this->froxlorDB = MDB2::connect($strFroxlorDB);
	if (MDB2::isError($this->froxlorDB)) {
		$this->logWriter->writelog("altrufroxlor.class.php - __Construct - Error openning DB: " . 
		MDB2::errorMessage($this->froxlorDB));
		die();
	}
	//$this->froxlorDB->loadModule('Extended');
}

public function createCustomer($uid,$pwd,$hdd,$transfer,$name,$firstname,$eml,$dbqty,
	$emlqty,$ftpqty,$domqty,$apsqty){
	$cust_qry = "INSERT INTO  panel_customers (`adminid`, `loginname`, `password`, `name`, 
	`firstname`, `company`, `street`, `zipcode`, `city`, `phone`, `fax`, `email`, 
	`customernumber`, `def_language`, `documentroot`, `guid`, `diskspace`, `traffic`, 
	`subdomains`, `emails`, `email_accounts`, `email_forwarders`, `email_quota`, `ftps`, 
	`tickets`, `mysqls`, `standardsubdomain`, `phpenabled`, `imap`, `pop3`, `aps_packages`, 
	`perlenabled`, `email_autoresponder`) VALUES (?,?,?,?,?,'','','','','','',?,'',
	'English',?,'',?,?,?,?,?,?,?,?,0,?,0,1,1,1,?,1,0)";
	$values = array($this->admin_id,$uid,md5($pwd),$name,$firstname,$eml,$this->docroot_path.$uid,$hdd*1024,
	$transfer,$domqty,$emlqty,$emlqty,$emlqty,"100",$ftpqty,$dbqty,$apsqty);
	$cust_ps = $this->froxlorDB->prepare($cust_qry);
	if (MDB2::isError($cust_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error preparing cust_qry: " . 
		MDB2::errorMessage($cust_ps));
		die();
	}
	$cust_rslt = $cust_ps->execute($values);
	if (MDB2::isError($cust_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing cust_qry: " . 
		MDB2::errorMessage($cust_rslt). "\n" . $cust_rslt->getDebugInfo());
		die();
	}
	$cust_id = mysql_insert_id();
	$gid = $cust_id + 10000;
	$cust_gid_qry = "Update panel_customers set guid = $gid where customerid = $cust_id";
	$cust_gid_rslt = $this->froxlorDB->query($cust_gid_qry);
	if (MDB2::isError($cust_gid_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing cust_gid_qry: " . 
		MDB2::errorMessage($cust_gid_rslt));
		die();
	}
	$ftp_qry = "INSERT INTO ftp_users (`customerid`, `username`, `password`, `homedir`, 
	`login_enabled`, `uid`, `gid`) " . "VALUES (?,?,ENCRYPT(?),?,'Y',?,?)";
	$values = array($cust_id,$uid,$pwd,$this->docroot_path.$uid,$gid,$gid);
	$ftp_ps = $this->froxlorDB->prepare($ftp_qry);
	if (MDB2::isError($ftp_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error preparing ftp_qry: " . 
		MDB2::errorMessage($ftp_ps));
		die();
	}
	$ftp_rslt = $ftp_ps->execute($values);
	if (MDB2::isError($ftp_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing ftp_qry: " . 
		MDB2::errorMessage($ftp_rslt));
		die();
	}	
	return $cust_id;		
}

public function createDomain($cust_id, $domain, $uid){
	$dom_qry = "Insert into `panel_domains` (`domain`,`adminid`,`customerid`,`documentroot`,`ipandport`,`isbinddomain`,
	`isemaildomain`,`ssl`,`ssl_redirect`,`ssl_ipandport`) Values(?,?,?,?,?,1,1,1,1,?)";
	$values = array($domain,$this->admin_id,$cust_id,$this->docroot_path.$uid,$this->ip_id,
	$this->ssl_ip_id);
	$dom_ps = $this->froxlorDB->prepare($dom_qry);
	if (MDB2::isError($dom_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createDomain - error preparing dom_qry: " . 
		MDB2::errorMessage($dom_ps));
		die();
	}
	$dom_rslt = $dom_ps->execute($values);
	if (MDB2::isError($dom_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing dom_qry: " . 
		MDB2::errorMessage($dom_rslt));
		die();
	}
}

public function addAPSInstall(){
}

public function renderOpenCP($uid,$pwd,$server,$bAutoClick=false,$bNewWindow=true){
	if ($bAutoClick) {
		echo "<body onLoad=\"document.forms['loginform'].submit();\">\n";
	}
	echo "<form ";
	if ($bNewWindow) {
		echo "target=_blank ";
	}
	echo "action=\"$server/index.php\" method=\"post\" name=\"loginform\">
	<input type=\"hidden\" name=\"loginname\" value=\"$uid\">
	<input type=\"hidden\" name=\"password\" value=\"$pwd\">
	<input type=\"hidden\" name=\"language\" value=\"profile\">
	<input type=\"hidden\" name=\"send\" value=\"send\">
	<input type=\"hidden\" name=\"action\" value=\"login\">
	<input type=\"submit\" value=\"Froxlor CP\" title=\"Open Froxlor Control Panel\" class=\"stnd_btn\">
	</form>";
}
}
?>

 

example of how to use it:

 


<?php

include_once ("classes/altrufroxlor.class.php");

$testFroxlor = new altruFroxlor("127.0.0.1","3306","froxlor","supersecretpassword","froxlor");

$cust_id = $testFroxlor->createCustomer("testclass","testpassword","2048","10","test user",
       "test","test@test.com",3,10,3,3,3);

$testFroxlor->createDomain($cust_id,"testdomain.com","testclass");

$testFroxlor->renderOpenCP("testclass","testpassword","https://localhost",true,true);

?>


Link to comment
Share on other sites

looks interesting, but the included files are missing, you may want to create a wiki-page in the /contrib/ section for that (using your forum-account iirc)

 

well, one of the dependencies just writes logs... then two are just config variables... the final, MDB2 is self explanitory for php programmers, for those that don't know its just a Pear library

I actually finished the aps install function yesterday... we're going to be offering free wordpress blogs and I'm going to use froxlor to manage the resources and the setup(end user will never see froxlor for these though)...

 

I will create a wiki page if anybody is actually interested in using this and I'll include the config file examples and the new aps function as well as my log writing function... it might not be until next week... I'll post a link here when I've done so...

Link to comment
Share on other sites

Hello.

 

I'm also looking for a way to integrate a billing solution with Froxlor.

0.9.x doesn't have an API yet, so a few days ago I was (also) thinking about a solution using direct database write, using NuSOAP or using PHP SOAP.

 

If you already have some code, do you mind sharing it ?

 

An API would be a great improvement to Froxlor ;)

 

Regards,

/Sorin

Link to comment
Share on other sites

d00p: thanks, I didn't think there was any sort of integration system in place... did look around but figured I'd ask just in case

 

frontline: no code yet, still digging through froxlor itself seeing how it all ties together... I want to make sure I fully understand froxlor before I write something to tie to it... when people don't take the time to understand the entire picture is when you get epic failure... I expect to start working on an integration class though this week, it will be written in php using PEAR:MDB2 libraries, really doesn't look like there will be a whole lot of logic to it just basically some functions to facilitate pushes to the db but i'd be happy to post it on here when have it working...

Link to comment
Share on other sites

well apparently I goofed and didn't setup the ftp group which will cause failure with php-fpm (via pam mysql auth)...

anyways here it is with the additional insert and also the aps install function... tested and appears to be working...

we will be offering some beta testers the chance to test it all out within a week or so...

probably 10 free wordpress users with the accounts managed by froxlor(user never sees froxlor) and 10 shared hosting testers (be like a dollar or two for shared hosting beta testers)...

wiki coming soon with include examples

 

Edit: during more testing found that I was missing a couple trailing slashes in URL's that only appeared to be problematic with APS... fixed that... also, this is now in use on our AltruHost's Public Beta https://beta-redmine.altruhost.com/projects/altrubeta

 

<?php

class altruFroxlor {
private $logWriter;
private $froxlorDB;
private $admin_id;
private $ip_id;
private $ssl_ip_id;
private $docroot_path;

function __construct($ip,$port,$frox_db_username,$frox_db_password,$frox_db_name){
	include("config/config.inc.php");
	include("config/froxlor.inc.php");
	include_once("classes/altrulog.class.php");
	require_once('MDB2.php');

	//global $error_log;
	//global $debug_log;
	//global $debug;
	$this->logWriter = new altruLogging($error_log,$debug_log,$debug);		

	$this->admin_id = $froxlor_admin_id;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - admin_id = $this->admin_id");
	$this->ip_id = $froxlor_ip_id;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - ip_id = $this->ip_id");
	$this->ssl_ip_id = $froxlor_ssl_ip_id;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - ssl_ip_id = $this->ssl_ip_id");
	$this->docroot_path = $froxlor_docroot_path;
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - docroot_path = $this->docroot_path");

	$strFroxlorDB = "mysql://$frox_db_username:$frox_db_password@$ip:$port/$frox_db_name";
	$this->logWriter->debugwrite("altrufroxlor.class.php - __Construct - using db connection string: $strFroxlorDB");
	$this->froxlorDB = MDB2::connect($strFroxlorDB);
	if (MDB2::isError($this->froxlorDB)) {
		$this->logWriter->writelog("altrufroxlor.class.php - __Construct - Error openning DB: " . 
		MDB2::errorMessage($this->froxlorDB));
		die();
	}
	//$this->froxlorDB->loadModule('Extended');
}

public function createCustomer($uid,$pwd,$hdd,$transfer,$name,$firstname,$eml,$dbqty,
	$emlqty,$ftpqty,$domqty,$apsqty){
	$cust_qry = "INSERT INTO  panel_customers (`adminid`, `loginname`, `password`, `name`, 
	`firstname`, `company`, `street`, `zipcode`, `city`, `phone`, `fax`, `email`, 
	`customernumber`, `def_language`, `documentroot`, `guid`, `diskspace`, `traffic`, 
	`subdomains`, `emails`, `email_accounts`, `email_forwarders`, `email_quota`, `ftps`, 
	`tickets`, `mysqls`, `standardsubdomain`, `phpenabled`, `imap`, `pop3`, `aps_packages`, 
	`perlenabled`, `email_autoresponder`) VALUES (?,?,?,?,?,'','','','','','',?,'',
	'English',?,'',?,?,?,?,?,?,?,?,0,?,0,1,1,1,?,1,0)";
	$values = array($this->admin_id,$uid,md5($pwd),$name,$firstname,$eml,$this->docroot_path.$uid."/",$hdd*1024,
	$transfer*1024*1024,$domqty,$emlqty,$emlqty,$emlqty,"100",$ftpqty,$dbqty,$apsqty);
	$cust_ps = $this->froxlorDB->prepare($cust_qry);
	if (MDB2::isError($cust_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error preparing cust_qry: " . 
		MDB2::errorMessage($cust_ps));
		die();
	}
	$cust_rslt = $cust_ps->execute($values);
	if (MDB2::isError($cust_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing cust_qry: " . 
		MDB2::errorMessage($cust_rslt). "\n" . $cust_rslt->getDebugInfo());
		die();
	}
	$cust_id = mysql_insert_id();
	$gid = $cust_id + 10000;
	$cust_gid_qry = "Update panel_customers set guid = $gid where customerid = $cust_id";
	$cust_gid_rslt = $this->froxlorDB->query($cust_gid_qry);
	if (MDB2::isError($cust_gid_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing cust_gid_qry: " . 
		MDB2::errorMessage($cust_gid_rslt));
		die();
	}
	$ftp_qry = "INSERT INTO ftp_users (`customerid`, `username`, `password`, `homedir`, 
	`login_enabled`, `uid`, `gid`) " . "VALUES (?,?,ENCRYPT(?),?,'Y',?,?)";
	$values = array($cust_id,$uid,$pwd,$this->docroot_path.$uid,$gid,$gid);
	$ftp_ps = $this->froxlorDB->prepare($ftp_qry);
	if (MDB2::isError($ftp_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error preparing ftp_qry: " . 
		MDB2::errorMessage($ftp_ps));
		die();
	}
	$ftp_rslt = $ftp_ps->execute($values);
	if (MDB2::isError($ftp_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing ftp_qry: " . 
		MDB2::errorMessage($ftp_rslt));
		die();
	}	
	$ftp_grp_qry = "INSERT INTO ftp_groups (`groupname`,`gid`,`members`,`customerid`) Values(?,?,?,?)";
	$values = array($uid,$gid,$uid,$cust_id);
	$ftp_grp_ps = $this->froxlorDB->prepare($ftp_grp_qry);
	if (MDB2::isError($ftp_grp_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error preparing ftp_grp_qry: " . 
		MDB2::errorMessage($ftp_grp_ps));
		die();
	}
	$ftp_grp_rslt = $ftp_grp_ps->execute($values);
	if (MDB2::isError($ftp_grp_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing ftp_grp_qry: " . 
		MDB2::errorMessage($ftp_grp_rslt));
		die();
	}	
	$add_cron_task = "Insert into panel_tasks (type) Values(5)";
	$rslt_qry = $this->froxlorDB->query($add_cron_task);
	$add_cron_task = "Insert into panel_tasks (type) Values(4)";
	$rslt_qry = $this->froxlorDB->query($add_cron_task);
	$add_cron_task = "Insert into panel_tasks (type) Values(1)";
	$rslt_qry = $this->froxlorDB->query($add_cron_task);
	return $cust_id;		
}

public function createDomain($cust_id, $domain, $uid){
	$dom_qry = "Insert into `panel_domains` (`domain`,`adminid`,`customerid`,`documentroot`,`ipandport`,`isbinddomain`,
	`isemaildomain`,`ssl`,`ssl_redirect`,`ssl_ipandport`) Values(?,?,?,?,?,1,1,1,0,?)";
	$values = array($domain,$this->admin_id,$cust_id,$this->docroot_path.$uid,$this->ip_id,
	$this->ssl_ip_id);
	$dom_ps = $this->froxlorDB->prepare($dom_qry);
	if (MDB2::isError($dom_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createDomain - error preparing dom_qry: " . 
		MDB2::errorMessage($dom_ps));
		die();
	}
	$dom_rslt = $dom_ps->execute($values);
	if (MDB2::isError($dom_rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - createCustomer - error executing dom_qry: " . 
		MDB2::errorMessage($dom_rslt));
		//die();
	}
	$dom_id = mysql_insert_id();
	return $dom_id;
}
public function addAPSInstall($cust_id,$package_id,$settings){
	$instance_qry = "Insert into aps_instances (CustomerID,PackageID,Status)
		Values(?,?,1)";
	$values = array($cust_id,$package_id);
	$instance_ps = $this->froxlorDB->prepare($instance_qry);
	if (MDB2::isError($instance_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - addAPSInstall - error preparing instance_qry: " . 
		MDB2::errorMessage($instance_ps));
		die();
	}
	$rslt = $instance_ps->execute($values);
	if (MDB2::isError($rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - addAPSInstall - error executing instance_qry: " . 
		MDB2::errorMessage($rslt));
		die();
	}
	$instance_id = mysql_insert_id();

	$settings_qry = "Insert into aps_settings (InstanceID,Name,Value)
		Values(?,?,?)";
	$settings_ps = $this->froxlorDB->prepare($settings_qry);
	if (MDB2::isError($settings_ps)) {
		$this->logWriter->writelog("altrufroxlor.class.php - addAPSInstall - error preparing settings_qry: " . 
		MDB2::errorMessage($settings_ps));
		die();
	}
	foreach ($settings as $name => $value) {
           $values = array ($instance_id,$name,$value);
           $rslt = $settings_ps->execute($values);
		if (MDB2::isError($rslt)) {
			$this->logWriter->writelog("altrufroxlor.class.php - addAPSInstall - error executing settings_qry: " . 
			MDB2::errorMessage($rslt));
			$this->logWriter->writelog("Name: $name, Value: $value");
			die();
		}	
       }

       $task_qry = "Insert into aps_tasks (InstanceID,Task)
		Values($instance_id,1)";
	$rslt = $this->froxlorDB->query($task_qry);
	if (MDB2::isError($rslt)) {
		$this->logWriter->writelog("altrufroxlor.class.php - addAPSInstall - error executing task_qry: " . 
		MDB2::errorMessage($rslt));
		die();
	}
}
}
function renderOpenCP($uid,$pwd,$server,$bAutoClick=false,$bNewWindow=true){
if ($bAutoClick) {
	echo "<body onLoad=\"document.forms['loginform'].submit();\">\n";
}
echo "<form ";
if ($bNewWindow) {
	echo "target=_blank ";
}
echo "action=\"https://$server/index.php\" method=\"post\" name=\"loginform\">
<input type=\"hidden\" name=\"loginname\" value=\"$uid\">
<input type=\"hidden\" name=\"password\" value=\"$pwd\">
<input type=\"hidden\" name=\"language\" value=\"profile\">
<input type=\"hidden\" name=\"send\" value=\"send\">
<input type=\"hidden\" name=\"action\" value=\"login\">
<input type=\"submit\" value=\"Froxlor CP\" title=\"Open Froxlor Control Panel\" class=\"stnd_btn\">
</form>";
}
?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...