Java Script to generate list of hosting accouts with soho launch installed on a hosting server

Recently I had done a task in which I had to create a list of hosting accounts on a shared only hosting accounts with soho launch installed. Soho Launch, which is also called pro edition. Now not only the accounts but the user names and passwords had also to be collected. The script makes a comma seprated CSV file of useraccounts, soho username and soho password fields.

As the databases created by Soho Launch are always named as sope1. And for each data base on a shared hosting server always a directory is created by the same name of database in the mysql directory located at "/var/lib/mysql". Now the databases on shared hosting servers are always created with names having two words seprated by an underscore( _ ) character. The word before '_' is shared hosting account name and word afterwards is the origional db name.

Now what my script do is read the directory "/var/lib/mysql" for subdirectories having database name part as "_sope1". Then extracted the account name from db name.
e.g. db name is kkpcouk_sope1, the account name will be kkpcouk

Then in same loop for every account I had to get its cpanel user name and password which are always placed in login table of _sope1 db of every account in fields "Username" and "Password" as a single record. So for this at start of script I made the mysql connection with server's root user. And in each loop itration a query fetches out the soho username and password. This all infor then in same itration is written to the file seprated by commas.


S0 following is the PHP script to make csv of hosting accounts with soho launch(pro edition) installed along with soho username and password.


$dbc=@mysql_connect("localhost","root","sqlrootpassword") OR die('Couldn\'t connect to MySql:'.mysql_error());
$path="/var/lib/mysql";
$dary=array();
$dary=scandir($path);
$fh=fopen('sohoDbList.csv','w') or die("can't open file");
$num=count($dary);
$i=0;
$v1=array();
while($i<$num)
{
$Dposs=strpos($dary[$i],".");
if($Dposs===false)
{

$Uposs=strpos($dary[$i],"_");
if($Uposs===false)
{}
else
{
$SLposs=strpos($dary[$i],"sope1");
if($SLposs===false)
{}
else
{
$var=$dary[$i];
$v1=explode("_",$var);
$sopedb=$v1[0]."_sope1";
mysql_select_db($sopedb, $dbc);
$qry="select * from login";
$res=mysql_query($qry);
$resAry=mysql_fetch_array($res);
$username=$resAry['Username'];
$password=$resAry['Password'];
$var=$v1[0].",".$username.",".$password."\n";
fwrite($fh,$var);
}
}

}
$i++;
}
fclose($fh);
echo "\n\ndone\n\n";
?>

Save this script in a php file. Then save it to the server's root folder. And run through shell run it through php 5. e.g. php5 -q filename.php. It will echo done on sucess.

It will make csv file in same directory with name 'sohoDbList.csv'

Posted in |