<?php
require_once('include/s_cli.php');
ob_start();
$now = getdate();
$nowyear = $now['year'];

if (!ini_get("register_globals")) {
	    import_request_variables('GPC');
}

//$bgcolor = "#F3F4FF";
$bgcolor1 = "#002200";
$bgcolor2 = "#002222";
$cwfont = "Arial, Verdana, Helvetica Sans-Serif";
$cwcolor = "#000000";
$cwsize = "-1";
$mhcolor = "#efefef";
$small_logo = "60_years.png";
$base_site = "127.0.0.1";
$modestr = "";

$d_str = "";
for($i=0;$i<$depth;$i++)
    $d_str .= "../";
$str2 = $d_str."include/navbar.php";
require_once($str2);

function addtcell($text, $href, $total=7) {
    $pct = 100/$total;
    echo "<td align=\"center\" width=\"$pct%\" style=\"color:#0077ff\">";
	if($href <> "")
		echo "<a href=\"$href\" id=\"topnavbar\">$text</a>";
	else
		echo $text;
	echo "</td>\n";
}

function addicell($img, $mo_img, $href, $id, $alt, $total=7, $width=120, $height=48) {
    $pct = 100/$total;
    echo "<td align=\"center\" width=\"$pct%\">";
	if($href != "")
		echo "<a href=\"$href\">";
	echo "<img ID=\"$id\" border=\"0\" src=\"$img\" alt=\"$alt\" width=\"$width\" height=\"$height\"";
	echo "	onmouseover='document.getElementById(\"$id\").src=\"$mo_img\"'";
	echo "	onmouseout='document.getElementById(\"$id\").src=\"$img\"'>";
	if($href != "")
		echo "</a>";
	echo "</td>\n";
}

function HeadOpen() {
    echo "<head>\n";
}

function HeadClose() {
    echo "</head>\n";
}

function BodyOpen() {
    echo "<body onLoad=\"document.forms[0].reset()\">\n<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"center\">\n";
}

function BodyClose() {
    echo "</td>\n</tr>\n</table>\n</body>\n";
}

function Meta(){
    echo "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\n";
    echo "<META NAME=\"RESOURCE-TYPE\" CONTENT=\"DOCUMENT\">\n";
    echo "<META NAME=\"DISTRIBUTION\" CONTENT=\"GLOBAL\">\n";
    echo "<META NAME=\"AUTHOR\" CONTENT=\"$sitename\">\n";
    echo "<META NAME=\"COPYRIGHT\" CONTENT=\"Copyright (c) by $sitename\">\n";
    echo "<META NAME=\"KEYWORDS\" CONTENT=\"hosting, streaming, shoutcast, host, stream, SHOUTcast, servers, dedicated, news, new, technology, discount, headlines, linux, windows, software, download, downloads, free, community, mp3, bulletin, board, boards, php, survey, kernel, portal, linux, mysql, plan, plans, database, suse, kde, interactive, programming, game, games, website, weblog, guru\">\n";
    echo "<META NAME=\"DESCRIPTION\" CONTENT=\"$description\">\n";
    echo "<META NAME=\"ROBOTS\" CONTENT=\"INDEX, FOLLOW\">\n";
    echo "<META NAME=\"REVISIT-AFTER\" CONTENT=\"1 DAYS\">\n";
    echo "<META NAME=\"RATING\" CONTENT=\"GENERAL\">\n";
	// This is the first part of the Microsoft no-cache workaround.
	// See the HC() code for more.
	echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
	echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\">\n";
	// This is for Mozilla
	echo "<META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\">\n";
	// This is the pop-up window code for the help windows
	echo "<SCRIPT LANGUAGE=\"JavaScript\">\n";
	echo "<!-- Begin\n";
	echo "function smallwindow(mytitle, mytext) {\n";
	echo "  mywin = window.open('','','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,top=100,left=100,width=350,height=200');\n";
	echo "  if (!mywin.opener)\n";
	echo "    mywin.opener = self;\n";
	echo "  with (mywin.document) {\n";
	echo "    open();\n";
	echo "    write('<html>');\n";
	echo "    write('<body bgcolor=\"#efffff\" text=\"#000000\" onLoad=\"document.form.box.focus()\"><center><table border=\"0\" cellpadding=\"8\" cellspacing=\"4\" width=\"100%\" align=\"left\"><tr><td><b>'+mytitle+'</b><br><br><form name=form>'+mytext+'<br><br>');\n";
	echo "    write('<input type=button value=\"Click here to close\" onClick=window.close()>');\n";
	echo "    write('</form></td></tr></table></center></body></html>');\n";
	echo "    close();\n";
	echo "  }\n";
	echo "}\n";
	echo "// End -->\n";
	echo "</SCRIPT>\n";
}

function Links() {
    echo "<link rel=\"StyleSheet\"  href=\"style/style.css\" type=\"text/css\" />\n";
    echo "<link rel=\"icon\" href=\"images/favicon.ico\" />\n";
    echo "<title>$site_name</title>\n";
}

function HO() {
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    echo "<!DOCTYPE html \n";
    echo "	PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n";
    echo "	\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
    echo "<html>\n";
    HeadOpen();
    Meta();
    Links();
    HeadClose();
    BodyOpen();
}

function HC() {
    BodyClose();
	// This is so Windows won't buffer us into using cache
	// It is a Microsoft suggestion
	echo "<head>\n";
	echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
	echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\">\n";
	echo "</head>\n";
    echo "</html>\n";
    ob_end_flush();
}

function CO() {
    echo "<center>\n";
}

function CC() {
    echo "</center>\n";
}

function TO($border=0,$width="100%",$padding=0,$spacing=0,$bgcolor="#ffffff") {
    echo "<table border=\"$border\" cellpadding=\"$padding\" cellspacing=\"$spacing\" width=\"$width\">\n";
    echo "  <tr>\n";
    echo "    <td align=\"center\" valign=\"top\" bgcolor=\"$bgcolor\"><div class=\"simplebox\">\n";
}

function TC() {
    echo "    </div></td>\n";
    echo "  </tr>\n";
    echo "</table>\n";
}

function padlines($pad) {
    for($i=0;$i<$pad;$i++) {
        echo "<br>";
    }
    echo "\n";
}

function send_header($relative_url) {
    header("Location: http://" . $_SERVER['HTTP_HOST']
                          . dirname($_SERVER['PHP_SELF'])
                          . "/" . $relative_url);
}

function masthead() {
    global $depth, $description, $logo, $site_name, $base_site, $site_desc, $mhcolor;
    $server = $_SERVER['HTTP_HOST'];
    TO(0, "100%");
        $str = "";
        if(strcmp($site_name,$base_site))
            $d = $depth - 1;
        else
            $d = $depth;
        for($i=0;$i<$d;$i++)
            $str .= "../";
        $str .= "images/".$logo;
        echo "<img src=\"$str\">";
    TC();
}


function copyright($border=0) {
    global $startyear, $nowyear, $copyrighter, $cwfont, $cwcolor, $cwsize, $small_logo;

	TO($border,"100%",0,0,"#efffff");
    padlines(1);
    echo "<img src=\"images/$small_logo\" border=\"0\"><br>\n";
	if($startyear < $nowyear)
	    echo "<font face=\"$cwfont\" color=\"$cwcolor\" size=\"$cwsize\">Copyright $startyear - $nowyear by $copyrighter.<br>\n";
	else
	    echo "<font face=\"$cwfont\" color=\"$cwcolor\" size=\"$cwsize\">Copyright $startyear by $copyrighter.<br>\n";
    echo "All rights reserved.</font><br>\n";
    padlines(1);
    TC();
}

function is_admin($admin) { 
    global $mm_magic;
    $c = $_COOKIE;
    $time = time();
//print_r($c);
//print_r(" - ");
//print_r($c['mm']);
//print_r(" - ");
    $d = round(exp(base64_decode($c['mm'])) - $mm_magic);
//print_r($d);
//print_r(" - ");
//print_r(time());
    return (($d > $time)&&($d - $time <= 3600));
}

function is_user($user) { 
    global $db, $user_prefix; 
    static $userSave; 
    if (isset($userSave)) return ($userSave); 
    if (!is_array($user)) { 
        $user = base64_decode($user); 
        $user = explode(":", $user); 
    } 
    $uid = $user[0]; 
    $pwd = $user[2]; 
    $uid = intval($uid); 
    if ($uid != "" AND $pwd != "") { 
        $sql = "SELECT user_password FROM ".$user_prefix."_users WHERE user_id='$uid'"; 
        $result = $db->sql_query($sql); 
        $row = $db->sql_fetchrow($result); 
        $pass = $row['user_password']; 
        if ($pass == $pwd && $pass != "") { 
            return $userSave = 1; 
        } 
    } 
    return $userSave = 0; 
}

function Title($title, $width="20%") {
	$str = "    <td align=\"left\" valign=\"top\" width=\"".$width."\">".$title."</td>\n";
	echo $str;
}

function Info($info, $width="80%") {
	$str = "    <td align=\"left\" width=\"".$width."\">".$info."</td>\n";
	echo $str;
}

function Title2($title, $width="20%") {
	$str = "    <td align=\"left\" valign=\"top\" width=\"".$width."\">".$title."</td>\n";
	echo $str;
}

function Info2($info, $width="80%") {
	$str = "    <td align=\"left\" width=\"".$width."\">".$info."</td>\n";
	echo $str;
}

function Show($title, $width="", $colspan=0, $color="#0077ff") {
	$str = "<td align=\"left\" valign=\"top\"";
	if($colspan)
		$str .= " colspan=\"".$colspan."\"";
	if($width != "")
		$str .= " width=\"".$width."\"";
	$str .= " style=\"color:".$color."\">".$title."</td>\n";
	echo $str;
}

function maybeShow($cmd, $title) {
	$res = ssh_exec($cmd);
	if($res != "" && (FALSE === stristr($res, "error"))) {
		echo "</tr><tr><td align=\"left\">&nbsp;</td>\n";
		Show("$title", "30%");
		Show($res, "60%");
	}
}

function Select($title, $name, $a, $style="") {
	$selected = GetMode($name);
	$str = "<select name=\"".$name."\"";
	if($style <> "")
		$str .= " style=\"".$style."\"";
	$str .= ">\n";
	$count = count($a["name"]);
	for($i=0; $i<$count; $i++) {
		$str .= "<option name=\"".$a["name"][$i]."\" value=\"".$a["value"][$i]."\"";
	    if($selected == $a["value"][$i])
			$str .= " selected";
		$str .= ">".$a["text"][$i]."</option>\n";
	}
	$str .= "</select>\n";
	$str .= "<td align=\"center\"><a href=\"javascript:smallwindow('".$title."','".GetModeHelp($name)."');\" border=\"0\"><img border=\"0\" src=\"images/question.gif\" alt=\"Help\" width=\"15\" height=\"15\"></td>";
	return $str;
}

function InputText($title, $name, $size, $maxlength, $value, $style, $helpstr="") {
	$str = "<input type=\"text\" name=\"".$name."\"";
	if($size != "")
		$str .= " size=\"".$size."\"";
	if($maxlength != "")
		$str .= " maxlength=\"".$maxlength."\"";
	if($value != "")
		$str .= " value=\"".$value."\"";
	if($style != "")
		$str .= " style=\"".$style."\"";
	$str .= ">";
	if($helpstr == "")
		$str .= "<td align=\"center\"><a href=\"javascript:smallwindow('".$title."','".GetModeHelp($name)."');\" border=\"0\"><img border=\"0\" src=\"images/question.gif\" alt=\"Help\" width=\"15\" height=\"15\"></td>";
	else
		$str .= "<td align=\"center\"><a href=\"javascript:smallwindow('".$title."','".$helpstr."');\" border=\"0\"><img border=\"0\" src=\"images/question.gif\" alt=\"Help\" width=\"15\" height=\"15\"></td>";

	return $str;
}

function InputHidden($name, $value) {
	$str = "<input type=\"hidden\" name=\"".$name."\"";
	if($value != "")
		$str .= " value=\"".$value."\"";
	$str .= ">\n";
	return $str;
}

function InputRadio($title, $name, $value, $selected, $style) {
	$str = "<input type=\"radio\" name=\"".$name."\"";
	if($value != "")
		$str .= " value=\"".$value."\"";
	if($style != "")
		$str .= " style=\"".$style."\"";
	if($selected == 1)
		$str .= " selected";
	$str .= ">\n";
	return $str;
}

function InputSubmit($value, $style) {
	$str = "<input type=\"submit\"";
	if($value != "")
		$str .= " value=\"".$value."\"";
	if($style != "")
		$str .= " style=\"".$style."\"";
	$str .= ">\n";
	return $str;
}

function InputImageSubmit($type, $src, $name, $border, $alt, $style) {
	$str = "<input type=\"image\" src=\"".$src."\"";
	if($name != "")
		$str .= " name=\"".$name."\"";
	if($border != "")
		$str .= "border=\"".$border."\"";
	if($alt != "")
		$str .= "alt=\"".$alt."\"";
	if($style != "")
		$str .= "style=\"".$style."\"";
	$str .= ">\n";
	return $str;
}

function TrueFalse($value) {
	if(strcmp($value, "TRUE")==0)
		$str = 1;
	else
		$str = 0;
	return $str;
}

function MaybeGetModestr() {
	global $address, $modestr;
	if(!strlen($modestr)) {
		$str = "modeset -v ".$address;
		$modestr = shell_exec($str);
	}
}

function GetModeHelp($mode) {
	global $address, $modestr;
	MaybeGetModestr();
	$str2 = stristr($modestr, $mode);
	$str3 = explode("\n", $str2);
	$res = trim(stristr($str3[0],"\t"));
	$res = htmlentities($res);
	return $res;
}

function GetModeWidth($mode) {
	global $address, $modestr;
	MaybeGetModestr();
	$mode2 = $mode."=";
	$str2 = stristr($modestr, $mode2);
	$str3 = explode("\t", $str2);
	$str4 = explode("=", $str3[0]);
	$test = $str4[1];
	$val = 0;
	if(strstr($test,"BOOLEAN"))			// TRUE or FALSE as strings
		$val = 5;
	else if(strstr($test,"NUMBER"))	// 32-bits, anyway
		$val = 10;
	else if(strstr($test,"STRING")) {
		$val_a = explode(",", $test);
		$val = trim($val_a[1]);
		if($val == 0)
			$val = 255;
	}
	return $val;
}

function GetMode($mode) {
	global $address, $modestr;
	$str = "modeset -g".$mode." ".$address;
	$str2 = stristr(shell_exec($str), $mode);
	list($name, $value) = explode('=', $str2);
	return trim($value, " \t\n\r\0\x0b\"");
}

function ShowMode($title, $mode) {
	echo "<tr>";
	Title($title);
	Info(GetMode($mode));
	echo "</tr>";
}

function ShowInputText($title, $name, $style="") {
	global $inputtextfieldwidth;
	echo "<tr>";
	$size = GetModeWidth($name);
	$value = GetMode($name);
	$help = GetModeHelp($name);
    Title($title, "35%");
	Info(InputText($title, $name, $inputtextfieldwidth, $size, $value, $style), "65%");
	echo "</tr>";
}

function ShowInputTextNoMode($title, $name, $style="", $size, $helptext) {
	global $inputtextfieldwidth;
	echo "<tr>";
    Title($title, "35%");
	Info(InputText($title, $name, $inputtextfieldwidth, $size, $value, $style, $helptext), "65%");
	echo "</tr>";
}

function ShowInputFileNoMode($title, $name, $style="", $size, $helptext) {
	global $inputtextfieldwidth;
	echo "<tr>";
    Title($title, "35%");
	$str = "<input name=\"".$name."\" size=\"".$inputtextfieldwidth."\" maxlength=\"80\" type=\"file\">\n";
	$str .= "<td align=\"center\"><a href=\"javascript:smallwindow('".$title."','".$helptext."');\" border=\"0\"><img border=\"0\" src=\"images/question.gif\" alt=\"Help\" width=\"15\" height=\"15\"></td>";
	Info($str, "65%");
	echo "</tr>";
}

function ShowInputHidden($name) {
	$value = GetMode($name);
	echo InputHidden($name, $value);
}

function AddScanvue($title,$val) {
	$str  = "  <tr>\n";
	$str .= "    <td align=\"left\" width=\"35%\">".$title."</td>\n";
	$str .= "    <td align=\"left\" width=\"65%\">".$val."</td>\n";
	$str .= "  </tr>\n";
	return $str;
}

function Update($name, $val) {
	global	$address;
	$name = trim($name);
	if(strlen($val)) {
		$val = trim($val);
		$val = str_replace(" ", "\\ ", $val);
		$val = str_replace("(", "\\(", $val);
		$val = str_replace(")", "\\)", $val);
	}
	$str = "modeset -i".$name."=".$val." ".$address;
//	echo $str."<br>";
	shell_exec($str);
}

function ssh_exec($cmd) {
	global $address;
	if($address == '127.0.0.1')
		$res = shell_exec($cmd);
	else
		$res =  send_ssh($address, $cmd);
	return trim($res);
}

?>
