<?
//require_once( "inc/session.php" );
require_once( "inc/db_pgsql.inc" );
$serviceType = isset($_GET['service_type']) ? $_GET['service_type'] : $_POST['service_type'];	
if($serviceType == "") $serviceType = 1;

header("Content-type: text/html; charset=euc-kr");	
?>
<html>
<head>
<title>######## SYSTEM-HOSTING SERVICE STATUS ######## </title>
<STYLE type=text/css>
TD { FONT-SIZE: 9pt; COLOR: #000000; FONT-FAMILY: 'ARIAL,굴림체'; TEXT-DECORATION: none; }
TR { FONT-SIZE: 9pt; COLOR: #000000; FONT-FAMILY: 'ARIAL,굴림체'; TEXT-DECORATION: none; }
TABLE { FONT-SIZE: 9pt; COLOR: #000000; FONT-FAMILY: 'ARIAL,굴림체'; TEXT-DECORATION: none; line-height : 120%}
INPUT { FONT-SIZE: 9pt; COLOR: #000000; FONT-FAMILY: 'ARIAL,굴림체'; TEXT-DECORATION: none; line-height : 120%}
}
</STYLE>
<meta http-equiv="Cache-Control" content="no-cache"/> 
<meta http-equiv="Expires" content="0"/> 
<meta http-equiv="Pragma" content="no-cache"/> 
<link rel="stylesheet" href="clockstyle.css" type="text/css">
<style type="text/css">
.box {width:147px; height:81px; font-size:9pt; font-family:"돋움체",FC1487; color:ffffff; background-image:url('./image/talk.gif'); padding:5;}
</style>
<style type="text/css">
#tooltip {position:absolute;
	top:5;
left:5;
border:solid 3 ffccff;
background:ffffcc;
color:660066;
	  font-size:9pt;
width:580;
height:20;
padding:2;
overflow:hidden;
		 z-index:10;
display:none;
}
</style>
<? require "layer.js";?>
<script language="javascript1.2"  type="text/javascript" src="clock.js" ></script>
<script language="JScript">
var n = (document.layers) ? 1:0;
var ie = (document.all) ? 1:0;

function overTip(boxObj, userid) {
	if (ie) {
		var mailaddr = userid;
		boxObj.innerHTML = mailaddr + " 가 클립보드로 복사 되었습니다.";
		boxObj.style.pixelTop=event.y+document.body.scrollTop - 85;
		boxObj.style.pixelLeft=event.x+document.body.scrollLeft - 20;
		boxObj.style.visibility = "visible";
		boxObj.filters.item(0).stop();
		window.clipboardData.setData("Text", mailaddr);
	}
}

function outTip(boxObj) {
	if (ie) {
		//      boxObj.style.visibility = "visible";
		boxObj.filters.item(0).transition = 23;
		boxObj.filters.item(0).apply();
		boxObj.style.visibility = "hidden";
		boxObj.filters.item(0).play();
	}
}
</script>
</head>

<body onLoad="UpdateClocks()">
<form name="frm" action=<?=$_SERVER['PHP_SELF']?> method=POST>
<input type="hidden" name="service_type" value="<?= $serviceType ?>">
<table border="0" cellspacing="0" width="100%" background="images/topbg.gif">
<tr class="ratNavText">
<td ID="Clock0" width="25%" >   </td>
<td ID="Clock1" width="25%" >   </td>
<td ID="Clock2" width="25%" >   </td>
<td ID="Clock3" width="25%" >   </td>
</tr>
<tr class="ratNavText">
<td ID="Clock4" width="25%" >   </td>
<td ID="Clock5" width="25%" >   </td>
<td ID="Clock6" width="25%" >   </td>
<td ID="Clock7" width="25%" >   </td>
</tr>
</table>
<br>
<table border="0" cellspacing="1" width="530" align="center">
<tr align="center">
<td> <h3>######## ICS STATUS ########<br>(sh.solbox.com)</h3></td>
</tr>
</table>
<div id="tooltip" name="tooltip" width=400></div>
<div id="clboard" class="box" style="position:absolute; z-index:20; filter:revealTrans(duration=0); visibility:hidden;"></div>
<?
$server_addr[0][0] = "127.0.0.1";
$server_addr[0][1] = "30001";
$server_addr[0][2] = "KT-IDC";

$tot = count($server_addr);
//echo "total server :".$tot."<br>";
for($i=0; $i < $tot; $i++){
	//echo "server_addr = ".$server_addr[$i][0]."<br>";
	//echo "server_port = ".$server_addr[$i][1]."<br>";
	if($i%3 == 0) echo "<table align=\"center\"><tr>";

	$fp = @fsockopen("udp://{$server_addr[$i][0]}", $server_addr[$i][1], $errno, $errstr);
	if (!$fp) {
		echo "ERROR: $errno - $errstr<br>\n";
		continue;
	} else {
		fwrite($fp,"GET_SERVSTATUS", 15);
		while(1) {
			$test2 = fread($fp, 2048);
			$test .= trim($test2);
			$j = strlen($test2);
			if($j < 1024) break;
		}
		fclose($fp);
	}
	//echo "Received Message Length : ".strlen($test);
	echo "<!-- TEST : $test -->";
	?>
		<td valign=top>
		<?
		$domain_name = "";
	$pt = new parsePipe();
	$test = $pt->nullTrim($test);
	$tmpArr = $pt->textArr($test);
	$serviceName = $pt->serviceName($test);
	$result = $pt->parseIt($tmpArr[$serviceType]);
	$tot_tr = $pt->countIt();

	// get rc_list to Database
	$objConn = new DB_Sql;
	$strSQL = " SELECT " .
		" rcid, rc_name, arrange, reg_datetime, update_datetime " .
		" FROM t_rms_rc_index " .
		" WHERE deleted_yn = 'N' ";
	$objConn->query( $strSQL );

	$rc_list;

	if( $objConn->nf() != 0 )
	{
		while( $objConn->next_record() )
		{
			$rc_list[$objConn->f("rcid")] = $objConn->f("rc_name");
		}
	}

	$objConn->close();

	echo "			<table border=0 cellpadding=2 cellspacing=2 bgcolor='93c53d'>\n";
	echo "				<tr align=center bgcolor='eff4e6'>\n";
	for($k=0; $k<sizeof($serviceName); $k++) {
		echo "				<td width='100' height='35'>\n";
		//echo "				<font size='1'>";

		if($serviceName[$k][1] != "dead") {
			echo "<img src=images/bu14.gif width=11 height=11>";
		} else {
			echo "<img src=images/bu15.gif width=11 height=11>";
		}
		echo "<a href='".$_SERVER['PHP_SELF']."?service_type=".$k."'>";
		if($serviceType==$k) echo "<b>";

		echo $rc_list[$serviceName[$k][0]];
		echo "<br>(".$serviceName[$k][0].")";

		/*
		   switch($serviceName[$k][0]){
		   case 'INCOK' : 
		   echo "TRINEX";
		//$domain_name = $serviceName[$k][2];
		break;
		case 'BD05' : echo "P-PLANT"; break;
		case 'bd08' : echo "YH-NEWS(BD)"; break;
		case 'bd10' : echo "KOFICICS"; break;
		case 'BD03' : echo "SBFS-1"; break;
		//case 'BD12' : echo "BD12"; break;
		case 'NS02' : echo "YH-NEWS(NS)"; break;
		case 'MYON' : echo "DUAL-1"; break;
		case 'FREEZONE' : echo "FREE"; break;
		default :
		echo $serviceName[$k][0];
		//$domain_name = $serviceName[$k][2];
		}

		if($serviceType==$k) echo "</b>";
		echo "				</a>";
		//echo "					</font>";
		switch($serviceName[$k][0]){
		case 'HI-LIVING' : echo "<br>(BD-RC01)"; break;
		case 'SORIBADA' : echo "<br>(BD-RC02)"; break;
		case 'BD03' : echo "<br>(BD-RC03)"; break;
		case 'BD12' : echo "<br>(BD-RC12)"; break;
		case 'THINKWARE' : echo "<br>(BD-RC04)"; break;
		case 'MYON' : echo "<br>(BD-RC07)"; break;
		case 'BD05' : echo "<br>(BD-RC05)"; break;
		case 'NCSOFT' : echo "<br>(BD-RC08)"; break;
		case 'KTINSIDE' : echo "<br>(BD-RC06)"; break;
		case 'FREEZONE' : echo "<br>(NS-RC01)"; break;
		case 'CACHE' : echo "<br>(BD-RC04)"; break;
		case 'CACHE2' : echo "(NS-RC02)"; break;
		case 'TC-SILVER' : echo "(NS-RC03)"; break;
		case 'GAMPLE' : echo "<br>(NS-RC04)"; break;
		case 'NS02' : echo "<br>(NS-RC02)"; break;
		case 'TOTODISK-BD' : echo "<br>(BD-RC09)"; break;
		case 'bd08' : echo "<br>(BD-RC08)"; break;
		case 'SBFS' : echo "<br>(BD-RC04)"; break;
		case 'CPM' : echo "<br>(NS-RC05)"; break;
		case 'bd10' : echo "<br>(BD-RC10)"; break;
		case 'MOV' : echo "<br>(BD-RC11)"; break;
		default : 
		}
		 */
		echo "				</td>\n";	
	}
	echo "				</tr>\n";
	echo "			</table>\n";
	?>		
		<table border=0 cellpadding=3 cellspacing=1 bgcolor="b2b2b2">
		<tr height="60">
		<td colspan="14" bgcolor="FFFFFF">
		<center><b>
		<font color="#000066" size="5">
		<?
		/*
		   switch($serviceName[$serviceType][0]){
		   case 'BD05' : echo "P-PLANT <br><br>(BD05)"; break;
		   case 'bd08' : echo "YH-NEWS(BD) <br><br>(BD08)"; break;
		   case 'bd10' : echo "KOFICICS <br><br>(BD10)"; break;
		   case 'MOV' : echo "MOV <br><br>(BD11)"; break;
		   case 'NS02' : echo "YH-NEWS(NS) <br><br>(NS02)"; break;
		   case 'FREEZONE' : echo "FREE <br><br>(NS01)"; break;
		   case 'TOTODISK-BD' : echo "TOTODISK-BD <br><br>(BD09)"; break;
		   case 'MYON' : echo "DUAL-1 <br><br>(BD07)"; break;
		   case 'BD03' : echo "SBFS-1 <br><br>(BD03)"; break;
		   case 'BD12' : echo "BD12 <br><br>(BD12)"; break;
		   case 'SORIBADA' : echo "SORIBADA <br><br>(BD02)"; break;
		   case 'HI-LIVING' : echo "HI-LIVING <br><br>(BD01)"; break;
		   case 'KTINSIDE' : echo "KTINSIDE <br><br>(BD06)"; break;
		   default : 
		   echo $serviceName[$serviceType][0];
		   }
		 */

		echo "<br>".$rc_list[$serviceName[$serviceType][0]];
	echo "<br><br>(".$serviceName[$serviceType][0].")";
	?>
		<br><br>
		</font>
		<font color="#000066" size="4">
		MNG SERVER IP: <?=$server_addr[$i][0]?>,&nbsp;&nbsp;  PORT: <?=$server_addr[$i][1]?> 
		(<?=$server_addr[$i][2]?>)
		</font>
		</b>
		</center>
		</td>
		</tr>
		<tr align="center">
		<td width="75" bgcolor="efefef" align="left"><b><font color="#000066">Name</font>
		<img src="images/bu14.gif" width=11 height=11>norm<br>
		<img src="images/bu77.gif" width=11 height=11>nomon<br>
		<img src="images/bu15.gif" width=11 height=11>fail<br>
		</b></td>
		<td width="90" bgcolor="efefef"><center><b><font color="#000066">Server IP</font></b></center></td>
		<td width="25" bgcolor="efefef"><center><b><font color="#000066">Port</font></b></center></td>
		<td width="85" bgcolor="efefef"><center><b><font color="#000066">Status<br>Changed</font></b></center></td>
		<td width="85" bgcolor="efefef"><center><b><font color="#000066">Disk<br>Checked</font></b></center></td>
		<td width="110" bgcolor="efefef"><center><b><font color="#000066">Domain<br>(<?=$serviceName[$serviceType][2] ?>)</font></b></center></td>
		<td width="65" bgcolor="efefef"><center><b><font color="#000066">Total Disk</font></b></center></td>
		<td width="65" bgcolor="efefef"><center><b><font color="#000066">Used</font></b></center></td>
		<td width="65" bgcolor="efefef"><center><b><font color="#000066">Free</font></b></center></td>
		<td width="25" bgcolor="efefef"><center><b><font color="#000066">Upload</font>
		<img src="images/bu14.gif" width=11 height=11>norm<br>
		<img src="images/bu16_1.gif" width=11 height=11>disb<br>
		<img src="images/bu15.gif" width=11 height=11>fsck<br>
		</b>
		</center>
		</td>
		<td width="50" bgcolor="efefef"><center><b><font color="#000066">Disk Busy(Lq)</font></b></center></td>
		<td width="100" bgcolor="efefef"><center><b><font color="#000066">Traffic INB(Packets)</font></b></center></td>
		<td width="100" bgcolor="efefef"><center><b><font color="#000066">Traffic OUTB(Packets)</font></b></center></td>
		<td width="50" bgcolor="efefef"><center><b><font color="#000066">Conn EASTAB(TOT)</font></b></center></td>
		</tr>
		<?	

		$totalDisk = 0;
	$freeDisk = 0;
	$usedDisk = 0;
	$totalRTSCount = 0;
	$totalTrafficINB = 0;
	$totalPacketsINB = 0;
	$totalTrafficOUTB = 0;
	$totalPacketsOUTB = 0;
	$totalConnEstab = 0;
	$totalConnAll = 0;
	for($j=0; $j<$tot_tr; $j++){
		$add_alt = "";
		if (!strcmp($result[$j][20], "99FFFF")) {
			$add_alt = " (UPLOAD TARGET)";
		} else if ($result[$j][10] == 1) {
			$add_alt = " (UPLOAD MANUALLY DISABLED)";
		} else if ($result[$j][10] == 2) {
			$add_alt = " (FSCK RUNNING)";
		} else {
			$add_alt = "";
		}
		$alt_str =
			"[NAME] : ".
			$result[$j][2].
			" [STATUS] : ".
			$pt->translateIt($result[$j][0], 2).$add_alt.
			" [TYPE] : ".
			$pt->translateIt($result[$j][1], 0);
		$totalDisk += $result[$j][8];
		$freeDisk += $result[$j][9];
		$usedDisk += ($result[$j][8] - $result[$j][9]);

		$result_used = 0;
		$result_used = $result[$j][8] - $result[$j][9];
		if ($result_used == 0)
			$result_used = "-";

		if ($result[$j][1] == 2) {
			$totalRTSCount += 1;
		}

		/* Packets INB */
		if ($result[$j][16] != '-') {
			$totalPacketsINB += $result[$j][16];
		}
		/* Traffic INB */
		if ($result[$j][17] != '-') {
			$totalTrafficINB += $result[$j][17];
		}
		/* Packets OUTB */
		if ($result[$j][18] != '-') {
			$totalPacketsOUTB += $result[$j][18];
		}
		/* Traffic OUTB */
		if ($result[$j][19] != '-') {
			$totalTrafficOUTB += $result[$j][19];
		}
		/* Connection Estblished */
		if ($result[$j][14] != '-') {
			$totalConnEstab += $result[$j][14];
		}
		/* Connection All */
		if ($result[$j][15] != '-') {
			$totalConnAll += $result[$j][15];
		}
		?>
			<span onmouseover="showtip('<?=$alt_str?>');" onmouseout="hidetip();">
			<tr>
			<?php
			if ($result[$j][0] == 2) {
				$bgcolor = "#FAC1C1";
				$free_bgcolor = "#FAC1C1";
			}
			else {
				$bgcolor = "#FFFFFF";
				$free_bgcolor = $pt->translateIt($result[$j][20],100);
			}
		?>								
			<td bgcolor="<?=$bgcolor?>"><?=$pt->translateIt($result[$j][0],1)?>&nbsp;<? /* =$pt->translateIt($result[$j][1],999) */ ?>&nbsp;<?=$pt->tailer($result[$j][2])?></td>
			<td align="center" bgcolor="<?=$bgcolor?>"><span class="txt03" onMouseDown="overTip(clboard, '<?=$result[$j][3]?>')" onMouseOut="outTip(clboard)"><?=$result[$j][3]?></span></td>
			<td align="center" bgcolor="<?=$bgcolor?>"><?=$pt->translateIt($result[$j][4],4)?></td>
			<td align="center" bgcolor="<?=$bgcolor?>"><?=$pt->noYear(date("Y-m-d H:i:s", $result[$j][5]))?></td>
			<td align="center" bgcolor="<?=$bgcolor?>">
			<?
			if ($result[$j][6] == "-" || $result[$j][6] == "") {
				echo "-";
			} else {
				echo $pt->noYear(date("Y-m-d H:i:s", $result[$j][6]));
			}
		?></td>
			<td align="center" bgcolor="<?=$bgcolor?>"><span class="txt03" onMouseDown="overTip(clboard, '<?=$pt->translateIt($result[$j][7],7)?>')" onMouseOut="outTip(clboard)">
			<? echo str_replace(".".$serviceName[$serviceType][2], "", $pt->translateIt($result[$j][7],7)); ?></span></td>
			<td align="center" bgcolor="<?=$bgcolor?>"><?=$pt->translateIt($result[$j][8],8)?></td>
			<td align="center" bgcolor="<?=$bgcolor?>"><?=$pt->translateIt($result_used,8)?></td>
			<td align="center" bgcolor="<?=$free_bgcolor?>"><?=$pt->translateIt(trim($result[$j][9]), 8)?></td>
			<td align="center" bgcolor="<?=$bgcolor?>">
			<?	if ($result[$j][10] == '-') {
				echo "-";
			} else if ($result[$j][10] == 0 &&
					$result[$j][11] == 0 &&
					$result[$j][12] == 0 &&
					$result[$j][13] == 0 &&
					$result[$j][14] == 0 &&
					$result[$j][15] == 0 &&
					$result[$j][16] == 0 &&
					$result[$j][17] == 0 &&
					$result[$j][18] == 0 &&
					$result[$j][19] == 0) {
				echo "-";
			} else {
				?>
					<?=$pt->translateIt($result[$j][10],10)?>
					<?
					if ($result[$j][11] > 2) {
						echo "<font color=\"red\"><b>";
					} else if ($result[$j][11] == 2) {
						echo "<font color=\"blue\"><b>";
					} else if ($result[$j][11] == 1) {
						echo "<font color=\"black\"><b>";
					} else {
						echo "<font color=\"black\">";
					}
				?>
					<?=$result[$j][11]?>
					</font>
					<? } ?>
					<td align="center" bgcolor="<?=$bgcolor?>">
					<?	if ($result[$j][12] == '-') {
						echo "-";
					} else if ($result[$j][10] == 0 &&
							$result[$j][11] == 0 &&
							$result[$j][12] == 0 &&
							$result[$j][13] == 0 &&
							$result[$j][14] == 0 &&
							$result[$j][15] == 0 &&
							$result[$j][16] == 0 &&
							$result[$j][17] == 0 &&
							$result[$j][18] == 0 &&
							$result[$j][19] == 0) {
						echo "-";
					} else {
						?>
							<?
							if ($result[$j][12] >= 20) {
								echo "<font color=\"red\"><b>";
							} else if ($result[$j][12] >= 10) {
								echo "<font color=\"blue\"><b>";
							} else {
								echo "<font color=\"black\">";
							}
						?>
							<?=$result[$j][13]?>%(<?=$result[$j][12]?>)</td>
							<?
							echo "</font>";
						?>
							<? } ?>
							<td align="center" bgcolor="<?=$bgcolor?>">
							<?	if ($result[$j][17] == '-') {
								echo "-";
							} else if ($result[$j][10] == 0 &&
									$result[$j][11] == 0 &&
									$result[$j][12] == 0 &&
									$result[$j][13] == 0 &&
									$result[$j][14] == 0 &&
									$result[$j][15] == 0 &&
									$result[$j][16] == 0 &&
									$result[$j][17] == 0 &&
									$result[$j][18] == 0 &&
									$result[$j][19] == 0) {
								echo "-";
							} else {
								?>
									<?=$pt->translateIt($result[$j][17],3)?>(<?=$result[$j][16]?>)</td>
									<? } ?>
									<td align="center" bgcolor="<?=$bgcolor?>">
									<?	if ($result[$j][19] == '-') {
										echo "-";
									} else if ($result[$j][10] == 0 &&
											$result[$j][11] == 0 &&
											$result[$j][12] == 0 &&
											$result[$j][13] == 0 &&
											$result[$j][14] == 0 &&
											$result[$j][15] == 0 &&
											$result[$j][16] == 0 &&
											$result[$j][17] == 0 &&
											$result[$j][18] == 0 &&
											$result[$j][19] == 0) {
										echo "-";
									} else {
										?>
											<?=$pt->translateIt($result[$j][19],3)?>(<?=$result[$j][18]?>)</td>
											<? } ?>
											<td align="center" bgcolor="<?=$bgcolor?>">
											<?	if ($result[$j][14] == '-') {
												echo "-";
											} else if ($result[$j][10] == 0 &&
													$result[$j][11] == 0 &&
													$result[$j][12] == 0 &&
													$result[$j][13] == 0 &&
													$result[$j][14] == 0 &&
													$result[$j][15] == 0 &&
													$result[$j][16] == 0 &&
													$result[$j][17] == 0 &&
													$result[$j][18] == 0 &&
													$result[$j][19] == 0) {
												echo "-";
											} else {
												?>
													<?
													if ($result[$j][14] >= 100) {
														echo "<font color=\"red\"><b>";
													} else if ($result[$j][14] >= 50) {
														echo "<font color=\"blue\"><b>";
													} else {
														echo "<font color=\"black\">";
													}
												?>
													<?=$result[$j][14]?>(<?=$result[$j][15]?>)
													<?
													echo "</font>";
												?>
													<? } ?>
													</td>
													</tr>
													</span>
													<?
	}
	?>
		<tr>
		<td align="center" colspan="4" bgcolor="FFFFFF">&nbsp;</b></td>
		<td align="center" colspan="1" bgcolor="FFFFFF"><b>Storage Total</b></td>
		<td align="center" colspan="1" bgcolor="FFFFFF"><b>RTS Total : <?=$totalRTSCount?></b></td>
		<td align="center" bgcolor="FFFFFF"><?= ($totalDisk == "") ? "-" : $pt->translateIt($totalDisk, 9)?></td>
		<td align="center" bgcolor="FFFFFF"><?= ($totalDisk == "") ? "-" : $pt->translateIt($usedDisk, 9)?></td>
		<td align="center" bgcolor="FFFFFF"><?= ($totalDisk == "") ? "-" : $pt->translateIt($freeDisk, 9)?></td>
		<td align="center" colspan="2" bgcolor="FFFFFF"><b>Network Total</b></td>
		<td align="center" colspan="1" bgcolor="FFFFFF">
		<? if ($totalTrafficINB > 0) { ?>
			<?=$pt->translateIt($totalTrafficINB,30)?>B(<?=$pt->translateIt($totalPacketsINB,30)?>p)
				<? } else { ?>
					-
						<? } ?>
						</td>
						<td align="center" colspan="1" bgcolor="FFFFFF">
						<? if ($totalTrafficOUTB > 0) { ?>
							<?=$pt->translateIt($totalTrafficOUTB,30)?>B(<?=$pt->translateIt($totalPacketsOUTB,30)?>p)
								<? } else { ?>
									-
										<? } ?>
										</td>
										<td align="center" colspan="1" bgcolor="FFFFFF">
										<? if ($totalConnEstab > 0) { ?>
											<?=$totalConnEstab?>(<?=$totalConnAll?>)
												<? } else { ?>
													-
														<? } ?>
														</td>
														</tr>

														</table></td>
														<?
														if($i%3 == 2) echo "</table></tr>"; //
}
?>
<table>
</table>
<?

////////////////////
//Print REFRESHER
////////////////////

extract($_POST);

$refresh_rate = $_REQUEST['refresh_rate'];

if($refresh_rate<1 || $refresh_rate>1000)
	$refresh_rate = 60;

	?>
	<br>
	<table align="center">
	<tr>
	<td>

	Refresh Rate :
	<input type=text name=refresh_rate value=<?=$refresh_rate?>>
	<input type=submit value=SET>
(MIN : 1, MAX : 1000)
	<input type="hidden" name="chk" value="0">
	</form>
	</td>
	</tr><tr>
	<td align=right>
	<form action=<?=$_SERVER['PHP_SELF']?> method=POST>
	<input type="hidden" name="service_type" value="<?= $serviceType?>">
	<input type=hidden name=refresh_rate value=30>
	<input type=submit value=RESET(30)>
	</form>
	</td>
	</tr>
	</table>
	<script language="javascript"  type="text/javascript" src="tooltip.js" ></script>
	<script language=javascript>
	function showtip(text) {
		tooltip.innerText=text; 
		tooltip.style.display="inline";
	}
function hidetip() {
	tooltip.style.display="none";
}
function movetip() {
	tooltip.style.pixelTop=event.y+document.body.scrollTop; 
	tooltip.style.pixelLeft=event.x+document.body.scrollLeft + 10;
}
document.onmousemove=movetip;
</script>
</body>
</html>
<META http-equiv="refresh" content="<?=$refresh_rate?>; url=<?=$PHP_SELF?>?refresh_rate=<?=$refresh_rate?>&service_type=<?= $serviceType ?>"> 
<?
########
#CLASSES
########
class parsePipe {
	var $tot_line;

	function parseIt($givenText){
		$cnt = 0;
		$minValue = 0;
		$maxValue = 0;
		$minLevel = 1000;
		$tmp_arr = array();
		$temp_arr = explode("\r\n", $givenText);
		$result_arr[$i][9] = "";
		$this->tot_line = count($temp_arr) == 1 ? 0 : count($temp_arr) - 1;
		for($i=0; $i < $this->tot_line; $i++){
			if($temp_arr[$i]!='') {
				$result_arr[$i] = explode("|", $temp_arr[$i]);
				$result_arr[$i][20] = "";
				$tmp_arr[$i] = ($result_arr[$i][9] == '' || $result_arr[$i][9] == '-') ? 0 : $this->nullTrim($result_arr[$i][9]);
				$result_arr[$i][8] = $this->nullTrim($result_arr[$i][8]);
				$result_arr[$i][9] = $this->nullTrim($result_arr[$i][9]);
				$result_arr[$i][10] = $this->nullTrim($result_arr[$i][10]);

				/*
				   if($result_arr[$i][9] != '-' && $result_arr[$i] != '' && $result_arr[$i] != 0) {
				   if($cnt == 0) {
				   $minValue = $result_arr[$i][9];
				   $cnt++;
				   }
				   if($minValue > $result_arr[$i][9]) {
				   $minValue = $result_arr[$i][9];
				   }
				   }
				 */
				if ($result_arr[$i][11] != '-' && $result_arr[$i] != '' && $result_arr[$i] != 0) {
					if ($minLevel > $result_arr[$i][11]) {
						$minLevel = $result_arr[$i][11];
					}
				}
			}
		}

		for ($i = 0; $i < $tot_tr; $i++) {
			if ($result_arr[$i][11] != '-' && $result_arr[$i] != '' && $result_arr[$i] != 0 && $result_arr[$i][11] <= $minLevel) {
				if($result_arr[$i][9] != '-' && $result_arr[$i] != '' && $result_arr[$i] != 0) {
					if($cnt == 0) {
						$minValue = $result_arr[$i][9];
						$cnt++;
					}
					if($minValue > $result_arr[$i][9]) {
						$minValue = $result_arr[$i][9];
					}
				}
			}
		}


		//echo "minLevel $minLevel minValue $minValue<br>";
		$cnt = 0;
		arsort($tmp_arr);
		reset($tmp_arr);

		while (list ($key, $val) = each ($tmp_arr)) {
			//echo "$key = $val<br>";
			if($val != 0) {
				if($cnt == 0) {
					if ($minLevel < $result_arr[$key][11] ||
							$result_arr[$key][10] > 0) {
						$result_arr[$key][20] = "yellow";//$maxValue;
					} else {
						//echo "11 ".$result_arr[$key][11]." 10 ".$result_arr[$key][10]."<br>";
						$maxValue = $val;
						$result_arr[$key][20] = "99FFFF";
						$cnt++;
					}
				} else {
					//if($minValue == $val) {
					if($val < (2 * 1024 * 1024 * 1024 * 10)) {
						$result_arr[$key][20] = "#FAC1C1";
					} else if(($maxValue - $val) < (1024 * 1024 * 1024) &&
							$minLevel == $result_arr[$key][11]) {
						//echo "1GB Highed<br>";
						//echo "minLevel $minLevel maxValue $maxValue<br>";
						$result_arr[$key][20] = "99FFFF";
					} else {
						//echo "1GB Lowed<br>";
						$result_arr[$key][20] = "yellow";//$maxValue;
					}
				}
				} else {
					$result_arr[$key][20] = "white";
				}
			}
			return $result_arr;
		}

		function countIt(){
			return $this->tot_line;
		}

		function translateIt($parsedText, $type){
			if($parsedText == '') return;

			$eServerType = array('RC', 'STAT', 'RTS', 'RCTS', 'RCDB', 'WWW', 'CCDB');
			/*$eStatus = array('<img src=images/bu16_1.gif width=11 height=11>UNKNOWN',
			  '<img src=images/bu14.gif width=11 height=11>ALIVE',
			  '<img src=images/bu15.gif width=11 height=11>DEAD');*/

			$eStatus = array('<img src=images/bu16_1.gif width=11 height=11>',
					'<img src=images/bu14.gif width=11 height=11>',
					'<img src=images/bu15.gif width=11 height=11>',
					'<img src=images/bu77.gif width=11 height=11 border=0>');
			$eStatusUP = array('<img src=images/bu14.gif width=11 height=11>',
					'<img src=images/bu16_1.gif width=11 height=11>',
					'<img src=images/bu15.gif width=11 height=11>');
			$eStatusChar = array('UNKNOWN', 'ALIVE', 'DEAD', 'NO MONITORING');
			switch($type){
				case 0:
					return $eServerType[$parsedText];
					return '';
				case 1:
					return $eStatus[$parsedText];
				case 2:
					return $eStatusChar[$parsedText];
				case 3:
					if(trim($parsedText) == "-" || $parsedText == "" ) return "-";
					else {
						if (trim($parsedText) / 1024 / 1024 > 1024) {
							return sprintf("<b>%.2fGB</b>",
									trim($parsedText) / 1024 / 1024 / 1024 );
						} else  {
							if (trim($parsedText) / 1024 > 1024) {
								if (trim($parsedText) / 1024 / 1024 > 10) {
									return sprintf("<font color=\"blue\"><b>%.2fMB</b></font>",
											trim($parsedText) / 1024 / 1024 );
								} else {
									return sprintf("<b>%.2fMB</b>",
											trim($parsedText) / 1024 / 1024 );
								}
							} else {
								if (trim($parsedText) > 1024) {
									return sprintf("%.2fKB",
											trim($parsedText) / 1024 );
								} else {
									return sprintf("%dB",
											trim($parsedText));
								}
							}
						}
					}
				case 8:			
					if(trim($parsedText) == "-" || $parsedText == "") return "-";
					else return sprintf("%.2lfG", (trim($parsedText) / 1024) / 1024 / 1024);
				case 9:
					if(trim($parsedText) == "-" || $parsedText == "" ) return "-";
					else {
						if (trim($parsedText) / 1024 / 1024 / 1024 > 1024) {
							return sprintf("%.2fT", trim($parsedText) / 1024 / 1024 / 1024 / 1024);
						} else 
							return sprintf("%.2fG", trim($parsedText) / 1024 / 1024 / 1024);
					}
				case 10:
					return $eStatusUP[$parsedText];
				case 30:
					if(trim($parsedText) == "-" || $parsedText == "" ) return "-";
					else {
						if (trim($parsedText) / 1024 / 1024 > 1024) {
							return sprintf("%.2fG",
									trim($parsedText) / 1024 / 1024 / 1024 );
						} else  {
							if (trim($parsedText) / 1024 > 1024) {
								return sprintf("%.2fM",
										trim($parsedText) / 1024 / 1024 );
							} else {
								if (trim($parsedText) > 1024) {
									return sprintf("%.2fK",
											trim($parsedText) / 1024 );
								} else {
									return sprintf("%d",
											trim($parsedText));
								}
							}
						}
					}
				default:
					return $parsedText;
			}
		}

		function nullTrim($tmp_str)
		{
			$return_str = "";
			$maxLength = strlen($tmp_str);

			for($i=0 ; $i < $maxLength ; $i++) {
				if(ord(substr($tmp_str, $i, 1)) != 0 || $tmp_str != " ") {
					$return_str .= substr($tmp_str, $i, 1);
				}
			}
			return $return_str;
		}

		function textArr($text)
		{		
			$cnt = -1;
			$tmp_cnt = 0;
			$str_arr = array();
			$tmp_search_str = "";
			$temp_arr = explode("\r\n", $text);		

			for($i=0; $i<sizeof($temp_arr); $i++) {
				$split_str = explode("|", $temp_arr[$i]);						
				$search_str = explode("_", $split_str[2]);

				// added by roolu 090224 : reason AION is ICS20
				if (substr_count($split_str[2], "AION") >= 1)
					continue;
				if($tmp_search_str != $search_str[0]) {
					$tmp_search_str = $search_str[0];															
					//$str_arr[$cnt][30] = $search_str[0];
					//echo $str_arr[$cnt][0]."<br>".$tmp_search_str."->".$cnt."<-"."<br>";
					$cnt++;
				}
				$str_arr[$cnt] .= $temp_arr[$i]."\r\n";

			}			
			return $str_arr;
		}

		function serviceName($text)
		{		
			$cnt = -1;
			$tmp_cnt = 0;
			$str_arr = array();
			$tmp_search_str = "";
			$temp_arr = explode("\r\n", $text);

			for($i=0; $i<sizeof($temp_arr); $i++) {
				$split_str = explode("|", $temp_arr[$i]);
				$search_str = explode("_", $split_str[2]);

				// added by roolu 090224 : reason AION is ICS20
				if (substr_count($split_str[2], "AION") >= 1)
					continue;

				if(($tmp_search_str != $search_str[0])) {
					$tmp_search_str = $search_str[0];
					$cnt++;
				}
				$str_arr[$cnt][0] = $tmp_search_str;

				if(($tmp_search_str == $search_str[0]) && $split_str[7] != "-") {
					$a = explode(".",  $split_str[7]);
					if(!strncmp($a[3], "kr", 2)) {
						$b = $a[1].".".$a[2]."."."kr";
					} else if(!strncmp($a[2], "com", 3)) {
						$b = $a[1]."."."com";
					}
					$str_arr[$cnt][2] = $b;
				}
				if($split_str[0] == 2) {
					$str_arr[$cnt][1] = "dead";
				}
				//	$str_arr[4][1] = "dead";
				//	$str_arr[1][1] = "dead";
			}	
			return $str_arr;
		}

		function tailer($name)
		{
			$temp_arr = explode("_", $name);		
			$temp_arr2 = substr($name, strlen($temp_arr[0]) + 1, strlen($name));
			return $temp_arr2;
		}

		function noYear($date)
		{
			$date = substr($date, 5, 14);

			return $date;
		}
	}

	?>
