Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Froxlor and THT Integration
#1
Hello,

i recently found this thread here where a user offered his Froxlor class for THT, but I don't know how to use it. Could anyone help me?

Code:
<?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>";
}
?>

I just created a new file in /includes/servers called froxlor.php and inserted the whole code there but i doesn't appear in the "add server"-section in THT, what do I have to do?

I would really appreciate it if someone out there could help me.
Sorry for my bad english.

ineedhelp Smile
Reply
#2
That is not a THT compatible class.
Kevin Mark - TheHostingTool Lead Developer
Reply
#3
You'll have to rewrite this code to make it work, as it is not a THT class.
Remote Servers - Shared, Reseller & KVM Hosting Services
Reply
#4
Thanks for your reply.

Is there any class for Froxlor? Where can I get the information to write a class on my own? I know a little bit how to code PHP.
Reply
#5
Not that I know of.
Kevin Mark - TheHostingTool Lead Developer
Reply
#6
Open includes/servers/da.php -- that should give you an idea.
Remote Servers - Shared, Reseller & KVM Hosting Services
Reply
#7
or includes/servers/whm.php will give you a complete implementation
Kevin Mark - TheHostingTool Lead Developer
Reply
#8
Yes, whm.php uses access hashes, da.php uses passwords. More likely da.php would be a better example, but that's just me.
Remote Servers - Shared, Reseller & KVM Hosting Services
Reply
#9
A late answer for the OP but may come in useful for someone else:
That code provided by the OP (froxlor.php) should be added to the froxlor script, not THT. Then you need to modify da.php (in THT) with:

public function signup($server, $reseller, $user = '', $email = '', $pass = '') {

...

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

$cust_id = $testFroxlor->createCustomer(...);

$testFroxlor->createDomain(...);

return true;

}


How to use:
<?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","[email protected]",3,10,3,3,3);

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

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

?>
Reply
#10
Or you can just copy and paste da.php into new file froxler.php and make the edits there. You won't lose that file when you upgrade. Smile
Kevin Mark - TheHostingTool Lead Developer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)