File: 1.19.3a/server/web/summary.test.php (View as HTML)

  1: <?php
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008-2017 PurplePixie Systems
  6: 
  7: FreeNATS is free software: you can redistribute it and/or modify
  8: it under the terms of the GNU General Public License as published by
  9: the Free Software Foundation, either version 3 of the License, or
 10: (at your option) any later version.
 11: 
 12: FreeNATS is distributed in the hope that it will be useful,
 13: but WITHOUT ANY WARRANTY; without even the implied warranty of
 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15: GNU General Public License for more details.
 16: 
 17: You should have received a copy of the GNU General Public License
 18: along with FreeNATS.  If not, see www.gnu.org/licenses
 19: 
 20: For more information see www.purplepixie.org/freenats
 21: -------------------------------------------------------------- */
 22: 
 23: ob_start();
 24: require("include.php");
 25: $NATS->Start();
 26: if (!$NATS_Session->Check($NATS->DB))
 27: 	{
 28: 	header("Location: ./?login_msg=Invalid+Or+Expired+Session");
 29: 	exit();
 30: 	}
 31: if ($NATS_Session->userlevel<1) UL_Error("View Test Summary");
 32: 
 33: if (isset($_REQUEST['nodeid'])) $nodeid=$_REQUEST['nodeid'];
 34: else $nodeid="";
 35: 
 36: 
 37: Screen_Header("Summary for ".$nodeid,1);
 38: ob_end_flush();
 39: 
 40: $td_day=date("d");
 41: $td_mon=date("m");
 42: $td_yr=date("Y");
 43: 
 44: function gtinfo($testid)
 45: {
 46: global $NATS;
 47: $o="Error fetching test";
 48: 
 49: $test=$NATS->GetTest($testid);
 50: if ($test['class']=="L")
 51: 	{
 52: 	$o=lText($test['testtype']);
 53: 	if ($test['testparam']!="") $o.=" (".$test['testparam'].")";
 54: 	
 55: 	if ($test['testname']!="") $o=$test['testname'];
 56: 	
 57: 	$u=lUnit($test['testtype']);
 58: 	if ($u!="") $o.=" (".$u.")";	
 59: 	}
 60: else if ($test['name']!="") $o=$test['name'];
 61: else $o=$test['testtype'];
 62: /*
 63: if ($testid[0]=="L")
 64: 	{ // local test
 65: 	$q="SELECT testtype,testparam,testname FROM fnlocaltest WHERE localtestid=".ss(substr($testid,1,128));
 66: 	$r=$NATS->DB->Query($q);
 67: 	if ($row=$NATS->DB->Fetch_Array($r))
 68: 		{
 69: 		$o=lText($row['testtype']);
 70: 		if ($row['testparam']!="") $o.=" (".$row['testparam'].")";
 71: 		
 72: 		if ($row['testname']!="") $o=$row['testname'];
 73: 		
 74: 		$u=lUnit($row['testtype']);
 75: 		if ($u!="") $o.=" (".$u.")";
 76: 		}
 77: 	else $o="Error fetching test";
 78: 	}
 79: */
 80: return $o;
 81: }
 82: 
 83: function outTime($timex,$name,$start=true,$checked=false)
 84: {
 85: echo "<input type=radio name=";
 86: if ($start) echo "startx";
 87: else echo "finishx";
 88: if ($checked) $c=" checked";
 89: else $c="";
 90: echo " value=".$timex.$c."> ".$name."<br>";
 91: }
 92: 
 93: if (isset($_REQUEST['mode'])&&($_REQUEST['mode']=="custom"))
 94: 	{
 95: 	echo "<br><b class=\"subtitle\">Custom Summary</b><br><br>";
 96: 	echo "<table width=600 border=0>";
 97: 	echo "<form action=summary.test.php method=post>";
 98: 	echo "<input type=hidden name=nodeid value=\" custom\">"; // note the space - invalid normal nodeid
 99: 	echo "<tr><td align=left valign=top>";
100: 	echo "<b>Nodes</b><br><br>";
101: 	$q="SELECT nodeid,nodename FROM fnnode ORDER BY weight ASC";
102: 	$r=$NATS->DB->Query($q);
103: 	while ($row=$NATS->DB->Fetch_Array($r))
104: 	{
105: 		if ($NATS->isUserAllowedNode($NATS_Session->username,$row['nodeid']))
106: 		{
107: 			echo "<input type=checkbox name=nodelist[] value=\"".$row['nodeid']."\"> ";
108: 			if ($row['nodename']=="") echo $row['nodeid'];
109: 			else echo $row['nodename'];
110: 			echo "<br>";
111: 		}
112: 	}
113: 	$NATS->DB->Free($r);
114: 	echo "</td><td align=left valign=top>";
115: 	echo "<b>Start Time</b><br><br>";
116: 	outTime(mktime(0,0,0,$td_mon,$td_day,$td_yr),"0:00 Today",true,true);
117: 	outTime(time()-(60*60*24),"24 Hours Ago");
118: 	outTime(time()-(60*60),"1 Hour Ago");
119: 	
120: 	echo "<br><b>Finish Time</b><br><br>";
121: 	outTime(mktime(23,59,59,$td_mon,$td_day,$td_yr),"23:59:59 Today",false,true);
122: 	outTime(time(),"Now",false);
123: 	
124: 	echo "<br><input type=submit value=\"View Summary\">";
125: 	echo "</td></tr>";
126: 	echo "</form></table>";
127: 	}
128: 
129: if (isset($_REQUEST['startx'])) $startx=$_REQUEST['startx'];
130: else $startx=mktime(0,0,0,$td_mon,$td_day,$td_yr);
131: if (isset($_REQUEST['finishx'])) $finishx=$_REQUEST['finishx'];
132: else $finishx=mktime(23,59,59,$td_mon,$td_day,$td_yr);
133: 
134: echo "<br><b>From </b>".nicedt($startx)." <b>to</b> ".nicedt($finishx)."<br><br>";
135: 
136: if ($nodeid=="*")
137: 	{
138: 	//
139: 	$q="SELECT testid,nodeid FROM fnrecord WHERE recordx>=".ss($startx)." AND recordx<=".ss($finishx);
140: 	$q.=" GROUP BY testid ORDER BY nodeid";
141: 	}
142: else if ($nodeid==" custom") // use nodelist
143: 	{
144: 	$q="SELECT testid,nodeid FROM fnrecord WHERE recordx>=".ss($startx)." AND recordx<=".ss($finishx)." ";
145: 	$q.="AND nodeid IN ( ";
146: 	$first=true;
147: 	foreach($_REQUEST['nodelist'] as $node)
148: 		{
149: 		if ($first) $first=false;
150: 		else $q.=",";
151: 		$q.="\"".ss($node)."\"";
152: 		}
153: 	$q.=" ) GROUP BY testid ORDER BY nodeid";
154: 	//echo $q;
155: 	//exit();
156: 	}
157: else
158: 	{
159: 	$q="SELECT testid,nodeid FROM fnrecord WHERE nodeid=\"".ss($nodeid)."\" AND recordx>=".ss($startx)." AND recordx<=".ss($finishx);
160: 	$q.=" GROUP BY testid";
161: 	}
162: $r=$NATS->DB->Query($q);
163: 
164: 
165: $name="";
166: $first=true;
167: 
168: while ($row=$NATS->DB->Fetch_Array($r))
169: {
170: 	if ($NATS->isUserAllowedNode($NATS_Session->username,$row['nodeid']))
171: 	{
172: 		if ($name!=$row['nodeid'])
173: 		{
174: 			if ($first) $first=false;
175: 			else echo "<br><br>";
176: 			echo "<b class=\"subtitle\">Node: <a href=node.php?nodeid=".$row['nodeid'].">".$row['nodeid']."</a></b><br><br>";
177: 			$name=$row['nodeid'];
178: 		}
179: 		echo "<b>".gtinfo($row['testid'])." on ".$row['nodeid']."</b><br>";
180: 		//echo "img src=\"test.graph.php?testid=".$row['testid']."&startx=".$startx."&finishx=".$finishx."\"<br>";
181: 		echo "<a href=history.test.php?nodeid=".$row['nodeid']."&testid=".$row['testid']."&startx=".$startx."&finishx=".$finishx.">";
182: 		echo "<img src=\"test.graph.php?nodeid=".$row['nodeid']."&testid=".$row['testid']."&startx=".$startx."&finishx=".$finishx."\" border=0>";
183: 		echo "</a>";
184: 		echo "<br><br>&nbsp;<br>";
185: 	}
186: }
187: 	
188: $NATS->DB->Free($r);
189: 
190: Screen_Footer();
191: ?>
192: