Integration Example
H-Sphere is a popular hosting automation control panel for shared web hosting services. The working example code for H-Sphere is provided below. You can use the following code for your control panel integration.
if ($auth_ref->{auth_ok} == 1 && $auth_ref->{uid} > 500) {
# all hsphere users start above 500, lower numbers are for system services.
$auth_ok = 1;
print "auth_ok:" . $auth_ref->{auth_ok} . "\n";
print "uid:" . $auth_ref->{uid} . "\n";
print "gid:" . $auth_ref->{gid} . "\n";
print "dir:" . $user . ":" . $auth_ref->{homedir} . "\n";
print "end\n";
exit();
}
if ( -d "/hsphere/local/var/vpopmail/bin/") {
# Mail, we check that the users pass against his vpopmail info.
my $emailpass = trim(`/hsphere/local/var/vpopmail/bin/vuserinfo -C $user`);
if ( $pass eq $emailpass ) {
$auth_ok = 1;
print "auth_ok:" . $auth_ok . "\n";
my $maildir = trim(`/hsphere/local/var/vpopmail/bin/vuserinfo -d $user`);
if (-d $maildir) {
print "dir:" . $user . ":" . $maildir . "/Maildir\n";
}
print "end\n";
exit();
}
}
if ( -d "/var/lib/mysql/" ) {
# MySQL, we check if the user can login and if so check that mysql is running.
my $mysqlcheck = trim(`/usr/bin/mysqladmin -u$user -p$pass ping`);
if ( $mysqlcheck eq "mysqld is alive" ) {
$auth_ok = 1;
print "auth_ok:" . $auth_ok . "\n";
my $mysqluser = trim(`grep ^user /var/lib/mysql/.my.cnf | cut -d "=" -f2 | sed 's/ //g'`);
my $mysqlpass = trim(`grep ^password /var/lib/mysql/.my.cnf | cut -d "=" -f2 | sed 's/ //g'`);
my ($dsn) = "DBI:mysql:mysql:localhost";
my ($dbh, $sth);
#my (@mysqldir);
$dbh = DBI->connect ($dsn, $mysqluser, $mysqlpass, { RaiseError => 1 });
my $query = qq{ SELECT Db from db where User = "$user" };
$sth = $dbh->prepare ( $query );
$sth->execute ();
while (my @mysqldir = $sth->fetchrow_array()) {
my $mysqldirname = $mysqldir[0];
$mysqldirname =~ tr///d;
print "dir:". $mysqldirname . ":/var/lib/mysql/" . $mysqldirname . "\n";
}
$sth->finish();
$dbh->disconnect();
print "end\n";
exit();
}
}
if ( -d "/var/lib/pgsql/" ) {
# PgSQL, this one needs some work on user authetication.
my ($dsn1) = "DBI:Pg:dbname=template1";
my ($dbh1, $sth1);
$dbh1 = DBI->connect ($dsn1, $user, $pass);
if ($dbh1) {
$auth_ok = 1;
print "auth_ok:" . $auth_ok . "\n";
my $query1 = "SELECT oid FROM pg_database, pg_user WHERE usename='$user' AND usesysid=datdba";
$sth1 = $dbh1->prepare ( $query1 );
$sth1->execute();
while (my @pgsqldir = $sth1->fetchrow_array()) {
my $pgsqldirname = $pgsqldir[0];
print "dir:". $user . ":/var/lib/pgsql/data/base/" . $pgsqldirname . "\n";
}
$sth1->finish();
$dbh1->disconnect();
print "end\n";
exit();
}
}
Labels:
None