Monthly Archives: November 2011

OpenBH Installer Part 1

Posted by admin on November 14, 2011
Blackhat, OpenBH, PHP Code / 17 Comments

I wanted to give OpenBH a try by installing it on a lot of subdomains. There is no way that I am going to waste a few days by copying and pasting the OpenBH files and then installing each one by hand.

Let’s see…

As OpenBH is made for Cpanel, I will also create a Cpanel installer.

A quick summary of what the installer is going to do:

  • Create FTP account
  • Create subdomain
  • Upload a zip with the OpenBH files
  • Unzip
  • Finish the OpenBH installations (keywords etc)
  • Clean up

Sadly I couldn’t find a way to unzip the zip into another directory. If there is a way to do this, please leave a comment as it would save a ton of wasted bandwidth and time.

First we will have to grab OpenBH here: https://www.syndk8.com/openbh

Make sure you create a custom zipfile because otherwise it will just install into a subfolder.

I was quite glad when I found out that Cpanel offers an API. I didn’t like the thought of having to write a scraper for the admin interface that might even break depending on the selected design.

First, let’s grab the xmlapi-php from Cpanel’s github: https://github.com/CpanelInc/xmlapi-php

Then create another php file with the following script in the same folder. Put the openbh.zip in the same folder as well.

Please note that this will only create a single subdomain and upload an unzip openbh.zip. I will talk about the OpenBH installation and automation of multiple installs in a later post. Of course this script can be used for anything else as well. Get creative.

<?php

/*
   OpenBH Cpanel Installer
   by hehejo
   14.11.2011
*/

$username      = 'PWUSERNAME';
$password      = 'CPPASSWORD';
$server        = 'CPDOMAIN';
$domain        = 'ADDONDOMAIN';

$ftplogin      = 'installerftp@' . $server;
$ftppassword   = 'abcd1234';

$subdomain = 'SUBDOMAIN';

set_time_limit(300);

/*
   Load xmlapi
   xmlapi settings
*/
require_once('xmlapi.php');
$xmlapi = new xmlapi($server);
$xmlapi->set_port(2082);
$xmlapi->password_auth($username,$password);
$xmlapi->set_debug(1);
$xmlapi->set_output('xml');

/*
   Create FTP account for file uploads
*/
$args = array(
  'user'=>$ftplogin,
  'pass'=>$ftppassword,
  'homedir'=>'/public_html/',
  'quota'=>'unlimited'
);
$res = $xmlapi->api2_query($username, 'Ftp', 'addftp', $args);

/*
   Open FTP connection
*/
$ftp = ftp_connect('ftp.' . $server);
$login_result = ftp_login($ftp, $ftplogin, $ftppassword);  

/*
   Create Subdomain
*/
$args = array($subdomain,$domain,0,0,'/public_html/' . $subdomain . '.' . $domain);
$res = $xmlapi->api1_query($username,'SubDomain','addsubdomain', $args);

/*
   Upload openbh.zip to subdomain folder
*/

$upload = ftp_put($ftp,$subdomain . '.' . $domain . '/openbh.zip', 'openbh.zip', FTP_BINARY);

/*
   Unzip openbh.zip into subdomain folder
*/
$args = array('/public_html/' . $subdomain . '.' . $domain,'openbh.zip');
$res = $xmlapi->api1_query($username, 'Fileman', 'extractfile', $args);  

/*
   Delete openbh.zip
   Close FTP connection
*/
ftp_delete($ftp,$subdomain . '.' . $domain . '/openbh.zip');
ftp_close($ftp);

/*
   Delete installer ftp account
*/
$args = array(
  'user'=>$ftplogin,
);
$res = $xmlapi->api2_query($username, 'Ftp', 'delftp', $args);

Tags: , , , ,