*
* *
* This is Free Software; permission to use, copy, modify, and distribute *
* this software and its documentation for any purpose - with or without fee *
* - is hereby granted, provided that the above copyright information and *
* this permission notice appear in all copies and documentations. This *
* software is provided "as is" without express or implied warranty. For *
* more details, see GNU General Public License as published by the Free *
* Software Foundation. *
* *
\*==========================================================================*/
error_reporting(0);
if ($_SERVER['HTTP_HOST'] != $_SERVER['SERVER_NAME'])
header("Location:http://$_SERVER[SERVER_NAME]$_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]");
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
session_start();
while (list($key) = each($_SESSION)) $GLOBALS[$key] = &$_SESSION[$key];
while (list($key) = each($_COOKIE )) $GLOBALS[$key] = &$_COOKIE [$key];
while (list($key) = each($_POST )) $GLOBALS[$key] = &$_POST [$key];
while (list($key) = each($_GET )) $GLOBALS[$key] = &$_GET [$key];
while (list($key) = each($_SERVER )) $GLOBALS[$key] = &$_SERVER [$key];
while (list($key) = each($_ENV )) $GLOBALS[$key] = &$_ENV [$key];
$_SESSION['hostname'] = &$hostname;
$_SESSION['username'] = &$username;
$_SESSION['altlogin'] = &$altlogin;
$_SESSION['login_as'] = &$login_as;
$_SESSION['security'] = &$security;
$_SESSION['hostlist'] = &$hostlist;
$_SESSION['userlist'] = &$userlist;
$_SESSION['ownrlist'] = &$ownrlist;
$_SESSION['hostsort'] = &$hostsort;
$_SESSION['usersort'] = &$usersort;
$_SESSION['ownrsort'] = &$ownrsort;
$_SESSION['hostview'] = &$hostview;
$_SESSION['userview'] = &$userview;
$_SESSION['ownrview'] = &$ownrview;
$_SESSION['haliview'] = &$haliview;
$_SESSION['ualiview'] = &$ualiview;
session_register('hostname');
session_register('username');
session_register('altlogin');
session_register('login_as');
session_register('security');
session_register('hostlist');
session_register('userlist');
session_register('ownrlist');
session_register('hostsort');
session_register('usersort');
session_register('ownrsort');
session_register('hostview');
session_register('userview');
session_register('ownrview');
session_register('haliview');
session_register('ualiview');
CleanIn();
if ($action == "login") $password = "";
$hostname = $hostname? $hostname : $VHOST_HOSTNAME;
$username = $username? $username : $VHOST_USERNAME;
$altlogin = $altlogin? $altlogin : $VHOST_ALTLOGIN;
$login_as = strlen($login_as)? $login_as : $VHOST_LOGIN_AS;
$security = strlen($security)? $security : $VHOST_SECURITY;
$password = strlen($password)? $password : $VHOST_PASSWORD;
putenv("VHOST_HOSTNAME=".($login_as?$hostname:""));
putenv("VHOST_USERNAME=$username");
putenv("VHOST_PASSWORD=$password");
$time = time();
$vhost = "/usr/sbin/vhost";
$version = chop(`$vhost -v`);
echo "\n\n";
if (!$_SERVER['SERVER_NAME'])
{
echo ''."\n";
exit();
}
if (ini_get("safe_mode"))
{
echo ''."\n";
exit();
}
if (!ereg('^vHost 3', $version))
{
echo ''."\n";
exit();
}
$include = $include == "!" || is_dir($include)? $include : (is_dir($VHOST_INCLUDE)? $VHOST_INCLUDE : "vhost.inc");
$incCmd .= 'if ($include != "!" && is_readable("$include/$incFile") && filesize("$include/$incFile")) '."\n";
$incCmd .= ' include("$include/$incFile");'."\n";
$incCmd .= 'elseif ($include != "!" && is_readable("vhost.inc/$incFile") && filesize("vhost.inc/$incFile")) '."\n";
$incCmd .= ' include("vhost.inc/$incFile");'."\n";
$incCmd .= 'else $incErr = 1;'."\n";
$incFile = "conf.inc"; eval($incCmd); $incErr = 0;
if (!$table0BgColor) $table0BgColor = '#FFFFFF';
if (!$table1BgColor) $table1BgColor = '#FFFFFF';
if (!$table0Style) $table0Style = 'width="100%" border="1" cellspacing="0" cellpadding="0"';
if (!$table1Style) $table1Style = 'width="100%" border="0" cellspacing="1" cellpadding="1"';
if (!$thBgColor) $thBgColor = '#88AACC';
if (!$thHlColor) $thHlColor = '#CCCCAA';
if (!$thTxtStyle) $thTxtStyle = '{color:#444444; font-size:13px; font-family:arial; font-weight:bold;}';
if (!$thLnkStyle) $thLnkStyle = '{color:#444444; font-size:13px; font-family:arial; font-weight:bold; text-decoration:none;}';
if (!$thFrmBgStyle) $thFrmBgStyle = '{background:#88AACC; color:#333399; font-size:13px;}';
if (!$thFrmHlStyle) $thFrmHlStyle = '{background:#CCCCAA; color:#333399; font-size:13px;}';
if (!$thFrmOptionStyle) $thFrmOptionStyle = '{background:#FFFFFF; color:#333399; font-size:13px;}';
if (!$thFrmButtonStyle) $thFrmButtonStyle = '{background:#336699; color:#FFFFFF; font-size:13px; font-weight:bold;}';
if (!$tdBgColor) $tdBgColor = '#EEEECC';
if (!$tdHlColor) $tdHlColor = '#EEEE99';
if (!$tdTxtStyle) $tdTxtStyle = '{color:#000000; font-size:13px; font-family:arial;}';
if (!$tdLnkStyle) $tdLnkStyle = '{color:#333366; font-size:13px; font-family:arial;}';
if (!$tdFrmBgStyle) $tdFrmBgStyle = '{background:#EEEECC; color:#000000; font-size:13px;}';
if (!$tdFrmHlStyle) $tdFrmHlStyle = '{background:#EEEE99; color:#000000; font-size:13px;}';
if (!$tdFrmOptionStyle) $tdFrmOptionStyle = '{background:#FFFFFF; color:#000000; font-size:13px;}';
if (!$tdFrmButtonStyle) $tdFrmButtonStyle = '{background:#336699; color:#FFFFFF; font-size:13px; font-weight:bold;}';
if (!$txBgColor) $txBgColor = '#EEEE99';
if (!$txHlColor) $txHlColor = '#FFFFFF';
if (!$txTxtStyle) $txTxtStyle = '{color:#333399; font-size:13px; font-family:arial;}';
if (!$txLnkStyle) $txLnkStyle = '{color:#333399; font-size:13px; font-family:arial;}';
if (!$txFrmBgStyle) $txFrmBgStyle = '{background:#EEEE99; color:#333399; font-size:13px;}';
if (!$txFrmHlStyle) $txFrmHlStyle = '{background:#FFFFFF; color:#333399; font-size:13px;}';
if (!$txFrmOptionStyle) $txFrmOptionStyle = '{background:#FFFFFF; color:#333399; font-size:13px;}';
if (!$txFrmButtonStyle) $txFrmButtonStyle = '{background:#336699; color:#FFFFFF; font-size:13px; font-weight:bold;}';
if (!strlen($autoPage)) $autoPage = 1;
if (!strlen($emptyRows)) $emptyRows = 3;
if (!strlen($reloadDelay)) $reloadDelay = 3;
if (!strlen($hostview)) $hostview = 2;
if (!strlen($userview)) $userview = 2;
if (!strlen($ownrview)) $ownrview = 2;
if (!strlen($haliview)) $haliview = 2;
if (!strlen($ualiview)) $ualiview = 2;
$hostData = array();
$userData = array();
$ownrData = array();
$haliData = array();
$ualiData = array();
$tableHead .= '
'."\n";
echo <<< ____html____
\n\n
____html____;
$incFile = "head.inc"; eval($incCmd); $incErr = 0;
if ($include != "!")
echo <<< ____html____
\n
____html____;
echo <<< ____html____
\n
____html____;
if (!$username && $action != "logout") EndPage(1);
/// logout ===================================================================
if ($action == "logout")
{
if (ereg('/([^/]+)/(var|home)/[^/]+/[^/]+$', $DOCUMENT_ROOT, $hostName)) $hostName = $hostName[1];
if (!ereg(ereg_replace('\.', '\.', "^$SERVER_NAME."), "$hostName.") &&
!ereg(ereg_replace('\.', '\.', ".$hostName$"), ".$SERVER_NAME") ||
!$hostName) $hostName = strtolower(chop(`$vhost --getvalue '\$HNAM;'`));
$hostName = $hostName? $hostName : strtolower(gethostbyaddr(gethostbyname(chop(`uname -n`))));
$selected[!strlen($login_as)||$login_as?1:0] = "selected";
$incFile = "auth.inc"; eval($incCmd);
if ($incErr)
echo <<< ____html____
\n
____html____;
$incErr = 0;
echo <<< ____html____
\n
____html____;
session_destroy();
EndPage(0);
}
/// login ====================================================================
if ($action == "login")
{
$host_ = escapeshellarg($hostname);
$altlogin = CmdLine("$vhost --getvalue $host_ '\$VUSR{\$USER};'");
$altlogin = chop($altlogin[0]);
$username = chop(`$vhost --getvalue $host_ '\$USER;'`);
$security = chop(`$vhost --getvalue $host_ '\$PERM;'`);
$altlogin = $altlogin? $altlogin : $username;
if ($security == 4) EndPage(1);
echo <<< ____html____
\n
____html____;
JumpTo("$PHP_SELF?action=index");
EndPage(0);
}
/// index ====================================================================
if ($action == "index")
{
if ($security <= 2) HostList();
if ($security == 2) $cellTxt = split('[[:space:]]+|/', chop($hostlist[0]));
if ($cellTxt[14] == 1) $cellTxt = split('[[:space:]]+|/', chop($hostlist[1]), 11);
if (count($cellTxt) == 11) $host = $cellTxt[9];
$display = $security <= 2? ($host && $autoPage? "lsuser&host=$host" : "lshost") : "vuser";
$incFile = $security <= 2? "page.inc" : "user.inc"; eval($incCmd);
if ($incErr) JumpTo("$PHP_SELF?action=$display"); $incErr = 0;
EndPage(0);
}
/// lshost ===================================================================
if ($action == "lshost")
{
HostList();
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// lsuser ===================================================================
if ($action == "lsuser")
{
if ($host) UserList();
if ($host && !$errCode)
{
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$userList
$tableFoot
____html____;
} else {
HostList();
$hostData[9] = $host? $host : ($hostData[9]? $hostData[9] : "host_name");
$onfocus0 = OnFocus("host_name");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
}
EndPage(0);
}
/// lsownr ===================================================================
if ($action == "lsownr")
{
OwnrList();
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$ownrList
$tableFoot
____html____;
EndPage(0);
}
/// addhost ==================================================================
if ($action == "addhost")
{
if ($host && $user && $prof && $go)
{
if ($oz) $oz = "-z";
if ($oi) $oi = "-i";
$host_ = escapeshellarg(DeHtml($host));
$user_ = escapeshellarg(DeHtml($user));
$pass_ = escapeshellarg(DeHtml(posix_getpwnam($user)? "y\n" : "$pass\n"));
$prof_ = escapeshellarg($prof);
$reloadDelay_ = (int)$reloadDelay;
CmdLine("echo $pass_ | $vhost --addhost $host_ $user_ $oz $oi -q -p $prof_");
if (!$errCode && $reloadDelay_ > 0) CmdLine("$vhost --reload -1 &>/dev/null");
if (!$errCode) JumpTo("$PHP_SELF?action=lshost&host=$host", $reloadDelay_);
}
HostList();
$hostData[1] = $pass? $pass : ($security <= 1? "password" : "");
$hostData[0] = $user? $user : ($hostData[0]? $hostData[0] : ($security == 2? $username : "owner_name"));
$hostData[9] = $host? $host : ($hostData[9]? $hostData[9] : "host_name");
$txFrmBg = $security == 2? "txFrmBg" : "txFrmHl";
$readonly = $security == 2? "readonly" : "";
$onfocus0 = $readonly? "" : OnFocus("owner_name");
$onfocus1 = $readonly? "" : OnFocus("password");
$onfocus2 = OnFocus("host_name");
if ($security == 0) $dnsOpt .= ' ';
if ($security == 0) $dnsOpt .= ' z';
if ($security == 0) $dnsOpt .= ' i';
if ($security == 0) $profLst[] = "/etc/vhost.d";
$lineLst = array_slice(CmdLine("$vhost --lsuser"), 1);
foreach ($lineLst as $lineStr)
{
$cellTxt = split('[[:space:]]+|/', chop($lineStr), 10);
$profLst[] = $cellTxt[9];
$ownrData9 = $ownrData9? $ownrData9 : ($prof? $prof : ($cellTxt[0] == $hostData[0]? $cellTxt[9] : ""));
}
$ownrData9 = $ownrData9? $ownrData9 : $profLst[0];
$selected[$ownrData9] = "selected";
foreach (array_unique($profLst) as $profStr)
$profOpt .= " \n";
$s = $dnsOpt? 22 : 24;
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// delhost ==================================================================
if ($action == "delhost")
{
if ($host && $go)
Confirm(DeHtml("Delete host '$host'?"), "$PHP_SELF?action=delhost&host=$host&od=$od");
if ($host && $confirm)
{
$od = $od != "0"? "-d" : "";
$host_ = escapeshellarg(DeHtml($host));
$reloadDelay_ = (int)$reloadDelay;
CmdLine("$vhost --delhost $host_ -q -f $od");
if (!$errCode && $reloadDelay_ > 0) CmdLine("$vhost --reload -1 &>/dev/null");
if (!$errCode) JumpTo("$PHP_SELF?action=lshost&host=$host", $reloadDelay_);
}
HostList();
$hostData[9] = $host? $host : ($hostData[9]? $hostData[9] : "host_name");
$onfocus0 = OnFocus("host_name");
// if ($security == 0) $delOpt .= ' ';
// if ($security == 0) $delOpt .= ' d';
// if ($security >= 1) $od = "-d";
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// addhali ==================================================================
if ($action == "addhali")
{
if ($host && $hali && $go)
{
if ($oz) $oz = "-z";
$host_ = escapeshellarg(DeHtml($host));
$hali_ = escapeshellarg(DeHtml($hali));
$reloadDelay_ = (int)$reloadDelay;
CmdLine("$vhost --addhali $host_ $hali_ $oz -q");
if (!$errCode && $reloadDelay_ > 0) CmdLine("$vhost --reload -1 &>/dev/null");
if (!$errCode) JumpTo("$PHP_SELF?action=lshost&hali=$hali", $reloadDelay_);
}
HostList();
$haliData[0] = $host? $host : ($haliData[0]? $haliData[0] : "host_name");
$haliData[1] = $hali? $hali : ($haliData[1]? $haliData[1] : "host_alias");
$onfocus0 = OnFocus("host_name");
$onfocus1 = OnFocus("host_alias");
if ($security == 0) $dnsOpt .= ' ';
if ($security == 0) $dnsOpt .= ' z';
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// delhali ==================================================================
if ($action == "delhali")
{
if ($hali && $go)
{
$hali_ = escapeshellarg(DeHtml($hali));
$reloadDelay_ = (int)$reloadDelay;
CmdLine("$vhost --delhali $hali_ -q");
if (!$errCode && $reloadDelay_ > 0) CmdLine("$vhost --reload -1 &>/dev/null");
if (!$errCode) JumpTo("$PHP_SELF?action=lshost&hali=$hali", $reloadDelay_);
}
HostList();
$haliData[1] = $hali? $hali : ($haliData[1]? $haliData[1] : "host_alias");
$onfocus0 = OnFocus("host_alias");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// adduser ==================================================================
if ($action == "adduser")
{
if ($host && $user && $ualt && $go)
{
$host_ = escapeshellarg(DeHtml($host));
$user_ = escapeshellarg(DeHtml($user));
$name_ = escapeshellarg(DeHtml($name));
$ualt_ = escapeshellarg(DeHtml("$ualt\n"));
$pass_ = escapeshellarg(DeHtml("$pass\n"));
CmdLine("echo $pass_$ualt_ | $vhost --adduser $host_ $user_ $name_");
if (!$errCode) JumpTo("$PHP_SELF?action=lsuser&host=$host&user=$user");
}
UserList();
$host_ = escapeshellarg(DeHtml($host));
$dotChar = chop(`$vhost --getvalue $host_ '\$dotChar;'`);
$unameLen = chop(`$vhost --getvalue $host_ '\$unameLen;'`);
$dotChar = $dotChar? $dotChar : '.';
$unameLen = $unameLen? $unameLen : 99999;
$host_ = ereg_replace('\.', $dotChar, ".$host");
$userData[1] = $pass? $pass : "password";
$userData[0] = $user? $user : ($userData[0]? $userData[0] : "user_name");
$userData[5] = $name? $name : ($userData[5]? $userData[5] : "full_name");
$userData[4] = $ualt? $ualt : ($userData[4]? $userData[4] : "$userData[0]$host_");
$onfocus0 = OnFocus("user_name");
$onfocus1 = OnFocus("password");
$onfocus2 = OnFocus("full_name");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$userList
$tableFoot
____html____;
EndPage(0);
}
/// deluser ==================================================================
if ($action == "deluser")
{
if ($host && $user && $go)
Confirm(DeHtml("Delete user '$user@$host'?"), "$PHP_SELF?action=deluser&host=$host&user=$user&od=$od");
if ($host && $user && $confirm)
{
$od = $od != "0"? "-d" : "";
$host_ = escapeshellarg(DeHtml($host));
$user_ = escapeshellarg(DeHtml($user));
CmdLine("$vhost --deluser $host_ $user_ -f $od");
if (!$errCode) JumpTo("$PHP_SELF?action=lsuser&host=$host&user=$user");
}
UserList();
$userData[0] = $user? $user : ($userData[0]? $userData[0] : "user_name");
$onfocus0 = OnFocus("user_name");
// if ($security == 0) $delOpt .= ' ';
// if ($security == 0) $delOpt .= ' d';
// if ($security >= 1) $od = "-d";
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$userList
$tableFoot
____html____;
EndPage(0);
}
/// adduali ==================================================================
if ($action == "adduali")
{
if ($host && $uali && $dest && $go)
{
preg_match_all('/(\'[^\']+\'|"[^"]+"|\S+)/', $dest, $var);
foreach ($var[1] as $str) $dest_ .= escapeshellarg(DeHtml($str)) . " ";
$host_ = escapeshellarg(DeHtml($host));
$uali_ = escapeshellarg(DeHtml($uali));
CmdLine("$vhost --adduali $host_ $uali_ $dest_");
if (!$errCode) JumpTo("$PHP_SELF?action=lsuser&host=$host&uali=$uali");
}
UserList();
$ualiData[0] = $uali? $uali : ($ualiData[0]? $ualiData[0] : "user_alias");
$ualiData[1] = $dest? $dest : ($ualiData[1]? $ualiData[1] : "destination(s)");
$onfocus0 = OnFocus("user_alias");
$onfocus1 = OnFocus("destination(s)");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$userList
$tableFoot
____html____;
EndPage(0);
}
/// deluali ==================================================================
if ($action == "deluali")
{
if ($host && $uali && $go)
{
preg_match_all('/(\'[^\']+\'|"[^"]+"|\S+)/', $dest, $var);
foreach ($var[1] as $str) $dest_ .= escapeshellarg(DeHtml($str)) . " ";
$host_ = escapeshellarg(DeHtml($host));
$uali_ = escapeshellarg(DeHtml($uali));
CmdLine("$vhost --deluali $host_ $uali_ $dest_");
if (!$errCode) JumpTo("$PHP_SELF?action=lsuser&host=$host&uali=$uali");
}
UserList();
$ualiData[0] = $uali? $uali : ($ualiData[0]? $ualiData[0] : "user_alias");
$ualiData[1] = $dest? $dest : ($ualiData[1]? $ualiData[1] : "destination(s)");
$onfocus0 = OnFocus("user_alias");
$onfocus1 = OnFocus("destination(s)");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$userList
$tableFoot
____html____;
EndPage(0);
}
/// catch-all ================================================================
if ($action == "catch-all")
{
JumpTo("$PHP_SELF?action=adduali&host=$host&uali=catch-all@");
EndPage(0);
}
/// passwd ===================================================================
if ($action == "passwd")
{
$usr = $host? "user" : "ownr";
$hArg = $host? "&host=$host" : "";
$lsusr = $host? "lsuser" : "lsownr";
$usrname = $host? "user_name" : "owner_name";
if ($$usr && $go)
{
$host_ = escapeshellarg(DeHtml($host));
$user_ = escapeshellarg(DeHtml($$usr));
$pass_ = escapeshellarg(DeHtml("$pass\n"));
CmdLine("echo $pass_ | $vhost --passwd $host_ $user_");
if (!$errCode) JumpTo("$PHP_SELF?action=$lsusr$hArg&$usr=${$usr}");
}
$host? UserList() : OwnrList();
$userList = $host? $userList : $ownrList;
$userData = $host? $userData : $ownrData;
$userData[1] = $pass? $pass : "password";
$userData[0] = $$usr? $$usr : ($userData[0]? $userData[0] : ($security == 2 && !$host? $username : $usrname));
$userData[5] = $host? $userData[5] : $userData[9];
$userData[4] = $host? $userData[4] : "";
$txFrmBg = $security == 2 && !$host? "txFrmBg" : "txFrmHl";
$readonly = $security == 2 && !$host? "readonly" : "";
$onfocus0 = $readonly? "" : OnFocus($usrname);
$onfocus1 = OnFocus("password");
$n = $host? 1 : 5;
$s = $host? 28 : 24;
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$userList
$tableFoot
____html____;
EndPage(0);
}
/// access ===================================================================
if ($action == "access")
{
$usr = $host? "user" : "ownr";
$hArg = $host? "&host=$host" : "";
$lsusr = $host? "lsuser" : "lsownr";
$usrname = $host? "user_name" : "owner_name";
if (strlen($access) && $go)
{
$host_ = escapeshellarg(DeHtml($host));
$user_ = escapeshellarg(DeHtml($$usr));
$access_ = escapeshellarg($access);
CmdLine("$vhost --access $host_ $user_ $access_ -u");
if (!$errCode) JumpTo("$PHP_SELF?action=$lsusr$hArg&$usr=${$usr}");
}
$host? UserList() : OwnrList();
$userList = $host? $userList : $ownrList;
$userData = $host? $userData : $ownrData;
$userData[0] = $$usr? $$usr : ($userData[0]? $userData[0] : ($security == 2 && !$host? $username : $usrname));
$userData[5] = $host? $userData[5] : $userData[9];
$userData[4] = $host? $userData[4] : "";
$txFrmBg = $security == 2 && !$host? "txFrmBg" : "txFrmHl";
$readonly = $security == 2 && !$host? "readonly" : "";
$onfocus0 = $readonly? "" : OnFocus($usrname);
$selected[$userData[1]] = "selected";
$disabled = $host? "disabled" : "";
$n = $host? 1 : 5;
$s = $host? 28 : 24;
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$userList
$tableFoot
____html____;
EndPage(0);
}
/// qhost ====================================================================
if ($action == "qhost")
{
if ($host && $quota && $go)
{
foreach (split('[[:space:]]+', $quota, 3) as $str) $quota_ .= escapeshellarg(DeHtml($str)) . " ";
$host_ = escapeshellarg(DeHtml($host));
CmdLine("$vhost --qhost $host_ $quota_");
if (!$errCode) JumpTo("$PHP_SELF?action=lshost&host=$host");
}
HostList();
$hostData[9] = $host? $host : ($hostData[9]? $hostData[9] : "host_name");
$hostData[8] = $quota? $quota : ("$hostData[3]$hostData[5]$hostData[7]"? "$hostData[3] $hostData[5] $hostData[7]" : "mailbox_size(K/M/G) #user #uali");
$onfocus1 = OnFocus("host_name");
$onfocus0 = OnFocus("mailbox_size(K/M/G) #user #uali");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// quser ====================================================================
if ($action == "quser")
{
if ($ownr && $quota && $go)
{
foreach (split('[[:space:]]+', $quota, 3) as $str) $quota_ .= escapeshellarg(DeHtml($str)) . " ";
$ownr_ = escapeshellarg(DeHtml($ownr));
CmdLine("$vhost --quser $ownr_ $quota_");
if (!$errCode) JumpTo("$PHP_SELF?action=lsownr&ownr=$ownr");
}
OwnrList();
$ownrData[0] = $ownr? $ownr : ($ownrData[0]? $ownrData[0] : "owner_name");
$ownrData[8] = $quota? $quota : ("$ownrData[3]$ownrData[5]$ownrData[7]"? "$ownrData[3] $ownrData[5] $ownrData[7]" : "disk_space(K/M/G) #host #hali");
$onfocus0 = OnFocus("owner_name");
$onfocus1 = OnFocus("disk_space(K/M/G) #host #hali");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$ownrList
$tableFoot
____html____;
EndPage(0);
}
/// addmydb ==================================================================
if ($action == "addmydb")
{
if ($host && $mydb && $go)
{
$host_ = escapeshellarg(DeHtml($host));
$mydb_ = escapeshellarg(DeHtml($mydb));
CmdLine("$vhost --addmydb $host_ $mydb_ -f");
if (!$errCode) JumpTo("$PHP_SELF?action=lshost&host=$host");
}
HostList();
$hostData[8] = $mydb? $mydb : "mydb_name";
$hostData[9] = $host? $host : ($hostData[9]? $hostData[9] : "host_name");
$onfocus0 = OnFocus("mydb_name");
$onfocus1 = OnFocus("host_name");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// delmydb ==================================================================
if ($action == "delmydb")
{
if ($host && $mydb && $go)
Confirm(DeHtml("Delete mydb '$mydb' on $host?"), "$PHP_SELF?action=delmydb&host=$host&mydb=$mydb&od=$od");
if ($host && $mydb && $confirm)
{
$od = $od != "0"? "-d" : "";
$host_ = escapeshellarg(DeHtml($host));
$mydb_ = escapeshellarg(DeHtml($mydb));
CmdLine("$vhost --delmydb $host_ $mydb_ -f $od");
if (!$errCode) JumpTo("$PHP_SELF?action=lshost&host=$host");
}
HostList();
$hostData[8] = $mydb? $mydb : "mydb_name";
$hostData[9] = $host? $host : ($hostData[9]? $hostData[9] : "host_name");
$onfocus0 = OnFocus("mydb_name");
$onfocus1 = OnFocus("host_name");
// if ($security == 0) $delOpt .= ' ';
// if ($security == 0) $delOpt .= ' d';
// if ($security >= 1) $od = "-d";
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
EndPage(0);
}
/// hostlog ==================================================================
if ($action == "hostlog")
{
if ($host && !$error)
{
$host_ = escapeshellarg(DeHtml($host));
CmdLine("$vhost --hostlog $host_ -q");
if ($errCode) JumpTo("$PHP_SELF?action=hostlog&host=$host&error=1");
echo ''."\n";
echo '
'."\n";
if (!$log)
{
echo ''."\n";
for ($i = 1; $i <= $indexMax - 1; $i++) echo $stdOut[$i];
echo ''."\n";
} else {
echo ''."\n";
$log_ = escapeshellarg($log);
passthru("$vhost --hostlog $host_ $log_ 2>/dev/null");
echo ''."\n";
}
} else {
HostList();
$hostData[9] = $host? $host : ($hostData[9]? $hostData[9] : "host_name");
$onfocus0 = OnFocus("host_name");
$inputHead = <<< ____html____
____html____;
echo <<< ____html____
$tableHead
$inputHead
$hostList
$tableFoot
____html____;
} EndPage(0);
}
/// cmdlog ===================================================================
if ($action == "cmdlog")
{
if (!$default)
{
$incFile = "clog.inc"; eval($incCmd);
if (!$incErr) EndPage(0); $incErr = 0;
}
if ($include != "!") JumpTo("$PHP_SELF?action=cmdlog&host=$host&include=!");
echo '[<< back]'."\n
\n";
echo ''."\n";
passthru("$vhost --cmdlog 2>/dev/null");
echo ''."\n";
EndPage(0);
}
/// reload ===================================================================
if ($action == "reload")
{
$reloadDelay_ = (int)$reloadDelay;
if ($reloadDelay_ > 0) CmdLine("$vhost --reload -1 &>/dev/null");
JumpTo("$PHP_SELF?action=lshost&host=$host", $reloadDelay_);
EndPage(0);
}
/// reload -f ================================================================
if ($action == "reload -f")
{
$reloadDelay_ = (int)$reloadDelay;
if ($reloadDelay_ > 0) CmdLine("$vhost --reload -1 -f &>/dev/null");
JumpTo("$PHP_SELF?action=lshost&host=$host", $reloadDelay_);
EndPage(0);
}
/// lshost -f ================================================================
if ($action == "lshost -f")
{
CmdLine("$vhost --lshost -f");
JumpTo("$PHP_SELF?action=lshost&host=$host");
EndPage(0);
}
/// halimenu =================================================================
if ($action == "halimenu")
{
$hostview = $hostview == 2? 0 : 2;
$hArg = $hali? "&hali=$hali" : ($host? "&host=$host" : "");
JumpTo("$PHP_SELF?action=lshost$hArg");
EndPage(0);
}
/// ualimenu =================================================================
if ($action == "ualimenu")
{
$userview = $userview == 2? 0 : 2;
$uArg = $uali? "&uali=$uali" : ($user? "&user=$user" : "");
JumpTo("$PHP_SELF?action=lsuser&host=$host$uArg");
EndPage(0);
}
/// clrhost ==================================================================
if ($action == "clrhost")
{
$hostsort = "";
JumpTo("$PHP_SELF?action=lshost$hArg");
EndPage(0);
}
/// clruser ==================================================================
if ($action == "clruser")
{
$usersort = "";
JumpTo("$PHP_SELF?action=lsuser&host=$host$uArg");
EndPage(0);
}
/// clrownr ==================================================================
if ($action == "clrownr")
{
$ownrsort = "";
JumpTo("$PHP_SELF?action=lsownr$oArg");
EndPage(0);
}
/// webftp ===================================================================
if ($action == "webftp")
{
JumpTo("webftp?");
EndPage(0);
}
/// vuser ====================================================================
if ($action == "vuser")
{
if (($pas0 != DoHtml($password) || $pas1 != $pass) && $go) echo ''."\n";
elseif (strlen($pass) && $go)
{
$host_ = escapeshellarg($hostname);
$user_ = escapeshellarg($username);
$pass_ = escapeshellarg(DeHtml("$pass\n"));
CmdLine("echo $pass_ | $vhost --passwd $host_ $user_");
if (!$errCode) echo ''."\n";
if (!$errCode) EndPage(1);
}
echo <<< ____html____
\n
____html____;
EndPage(0);
}
/// hostlist =================================================================
function HostList()
{
global $PHP_SELF, $vhost, $action, $host, $hali, $sort, $refresh, $time, $stdOut, $stdErr, $errCode,
$security, $hostlist, $hostsort, $hostview, $haliview, $hostList, $hostData, $haliData,
$tdBgColor, $tdHlColor, $thBgColor, $thHlColor, $emptyRows, $autoPage;
if ($sort) $hostsort = (int)$sort;
if ($os || $hostsort) $os = ($hostsort >= 0? "-s" : "-r") . abs($hostsort);
if ($oa) $oa = "-a";
if ($action == "lshost" || !$hostlist || $refresh || $sort) $hostlist = CmdLine("$vhost --lshost -l $oa $os");
$hArg = $hali? "&hali=$hali" : ($host? "&host=$host" : "");
if (chop(`$vhost --getvalue '\$mysql;'`))
$mydbOpt = <<< ____html____
____html____;
$userOpt[0] = <<< ____html____
____html____;
$userOpt[1] = <<< ____html____
____html____;
list($lineNum, $lineStr) = each($hostlist);
$cellTxt = split('[[:space:]]+|/', chop($lineStr));
$hostNum = $cellTxt[14] + 0;
for ($i = 0; $i <= 9; $i++) $ss[$i] = "-";
for ($i = 0; $i <= 9; $i++) $tcBgColor[$i] = $thBgColor;
if ($hostsort) $ss[abs($hostsort)-1] = $hostsort < 0? "+" : "-";
if ($hostview == 2 && $hostsort) $tcBgColor[abs($hostsort)-1] = $thHlColor;
if ($hostview == 0)
{
$showStat = 1;
$showSign = '+';
$haliMenu = "Drop";
}
if ($hostview == 1)
{
$showStat = 2;
$showSign = 'o';
$haliMenu = "Drop";
}
if ($hostview == 2)
{
$showStat = 0;
$showSign = '-';
$haliMenu = "To Top";
}
$hostList .= <<< ____html____
'."\n";
list($lineNum, $lineStr) = each($hostlist);
$cellTxt = split('[[:space:]]+|/', chop($lineStr));
$haliNum = $cellTxt[5] + 0;
for ($i = 0; $i <= 1; $i++) $ss[$i] = "-";
for ($i = 0; $i <= 1; $i++) $tcBgColor[$i] = $thBgColor;
if ($hostsort) $ss[abs($hostsort)-1 != 9? abs($hostsort)-1 : 1] = $hostsort < 0? "+" : "-";
if ($haliview == 2 && $hostsort) $tcBgColor[abs($hostsort)-1 != 9? abs($hostsort)-1 : 1] = $thHlColor;
if ($haliview == 0)
{
$showStat = 1;
$showSign = '+';
}
if ($haliview == 1)
{
$showStat = 2;
$showSign = 'o';
}
if ($haliview == 2)
{
$showStat = 0;
$showSign = '-';
}
$hostList .= <<< ____html____
';
}
/// userlist =================================================================
function UserList()
{
global $PHP_SELF, $vhost, $action, $host, $user, $uali, $sort, $refresh, $time, $stdOut, $stdErr, $errCode,
$security, $userlist, $usersort, $userview, $ualiview, $userList, $userData, $ualiData,
$tdBgColor, $tdHlColor, $thBgColor, $thHlColor, $emptyRows;
if ($sort) $usersort = (int)$sort;
if ($os || $usersort) $os = ($usersort >= 0? "-s" : "-r") . abs($usersort);
$host_ = escapeshellarg(DeHtml($host));
if ($action == "lsuser" || !$userlist || $refresh || $sort) $userlist = CmdLine("$vhost --lsuser $host_ $os -h");
$uArg = $uali? "&uali=$uali" : ($user? "&user=$user" : "");
list($lineNum, $lineStr) = each($userlist);
$cellTxt = split('[[:space:]]+|/', chop($lineStr));
$userNum = $cellTxt[10] + 0;
for ($i = 0; $i <= 5; $i++) $ss[$i] = "-";
for ($i = 0; $i <= 5; $i++) $tcBgColor[$i] = $thBgColor;
if ($usersort) $ss[abs($usersort)-1] = $usersort < 0? "+" : "-";
if ($userview == 2 && $usersort) $tcBgColor[abs($usersort)-1] = $thHlColor;
if ($userview == 0)
{
$showStat = 1;
$showSign = '+';
$ualiMenu = "Drop";
}
if ($userview == 1)
{
$showStat = 2;
$showSign = 'o';
$ualiMenu = "Drop";
}
if ($userview == 2)
{
$showStat = 0;
$showSign = '-';
$ualiMenu = "To Top";
}
$userList .= <<< ____html____
'."\n";
list($lineNum, $lineStr) = each($userlist);
$cellTxt = split('[[:space:]]+|/', chop($lineStr));
$ualiNum = $cellTxt[5] + 0;
for ($i = 0; $i <= 1; $i++) $ss[$i] = "-";
for ($i = 0; $i <= 1; $i++) $tcBgColor[$i] = $thBgColor;
if ($usersort) $ss[abs($usersort)-1 != 5? abs($usersort)-1 : 1] = $usersort < 0? "+" : "-";
if ($ualiview == 2 && $usersort) $tcBgColor[abs($usersort)-1 != 5? abs($usersort)-1 : 1] = $thHlColor;
if ($ualiview == 0)
{
$showStat = 1;
$showSign = '+';
}
if ($ualiview == 1)
{
$showStat = 2;
$showSign = 'o';
}
if ($ualiview == 2)
{
$showStat = 0;
$showSign = '-';
}
$userList .= <<< ____html____
';
}
/// ownrlist =================================================================
function OwnrList()
{
global $PHP_SELF, $vhost, $action, $ownr, $sort, $refresh, $time, $stdOut, $stdErr, $errCode,
$security, $ownrlist, $ownrsort, $ownrview, $ownrList, $ownrData,
$tdBgColor, $tdHlColor, $thBgColor, $thHlColor, $emptyRows;
if ($sort) $ownrsort = (int)$sort;
if ($os || $ownrsort) $os = ($ownrsort >= 0? "-s" : "-r") . abs($ownrsort);
if ($action == "lsownr" || !$ownrlist || $refresh || $sort) $ownrlist = CmdLine("$vhost --lsuser $os");
$oArg = $ownr? "&ownr=$ownr" : "";
$userOpt[0] = <<< ____html____
____html____;
$userOpt[1] = <<< ____html____
____html____;
list($lineNum, $lineStr) = each($ownrlist);
$cellTxt = split('[[:space:]]+|/', chop($lineStr));
$ownrNum = $cellTxt[14] + 0;
for ($i = 0; $i <= 9; $i++) $ss[$i] = "-";
for ($i = 0; $i <= 9; $i++) $tcBgColor[$i] = $thBgColor;
if ($ownrsort) $ss[abs($ownrsort)-1] = $ownrsort < 0? "+" : "-";
if ($ownrview == 2 && $ownrsort) $tcBgColor[abs($ownrsort)-1] = $thHlColor;
if ($ownrview == 0)
{
$showStat = 1;
$showSign = '+';
}
if ($ownrview == 1)
{
$showStat = 2;
$showSign = 'o';
}
if ($ownrview == 2)
{
$showStat = 0;
$showSign = '-';
}
$ownrList .= <<< ____html____
';
}
/// functions ================================================================
function OnFocus($val)
{
return "onfocus=\"if (this.value == '$val') this.value = '';\"";
}
function DoSlash($var)
{
return preg_replace(array('/','/>/'), array('\<','\>'), addslashes($var));
}
function DoHtml($var)
{
return preg_replace(array('/\'/','/"/','/','/>/'), array(''','"','<','>'), $var);
}
function DeHtml($var)
{
return preg_replace(array('/'/','/"/','/</','/>/'), array('\'','"','<','>'), $var);
}
function CleanIn()
{
$vars = array("host", "user", "ownr", "hali", "uali", "ualt", "name", "pass", "pas0", "pas1", "dest", "quota",
"username", "password", "VHOST_PASSWORD", "PHP_SELF");
foreach ($vars as $var) eval("global \$$var;\n");
foreach ($vars as $var) if ($$var && get_magic_quotes_gpc()) $$var = stripslashes($$var);
foreach ($vars as $var) if ($var != "password" && $var != "VHOST_PASSWORD") $$var = DoHtml($$var);
}
function CmdLine($cmd)
{
global $security, $stdOut, $stdErr, $errCode;
$out = tempnam("/tmp", ".out.");
unset($stdErr);
exec("$cmd 2>&1 >$out", $stdErr, $errCode);
if (is_file($out)) $stdOut = file($out);
if (is_file($out)) unlink($out);
while (list($key) = each($stdErr)) $stdErr[$key] = DoSlash($stdErr[$key]);
if ($stdErr) echo ''."\n";
if ($errCode == 127 || $errCode == 1 || $errCode == 3 && ($security >= 3 || !strlen($security))) EndPage(1);
return $stdOut;
}
function Confirm($str, $url)
{
global $time, $include, $incCmd, $incErr;
$incFile = "foot.inc"; eval($incCmd); $incErr = 0;
$str = DoSlash($str);
echo ''."\n";
}
function JumpTo($url, $delay = 0)
{
global $time;
echo <<< ____html____
\n
____html____;
exit();
}
function EndPage($out)
{
global $PHP_SELF, $include, $incCmd, $incErr;
$incFile = "foot.inc"; eval($incCmd); $incErr = 0;
if ($out) JumpTo("$PHP_SELF?action=logout");
exit();
}
EndPage(1);
?>