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

  1: <?php
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008-2010 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: 
 27: // Timeskip check - means this page skips timecheck/reset if site.monitor.keepalive is 0
 28: if ($NATS->Cfg->Get("site.monitor.keepalive",1)==0) $timeskip=true;
 29: else $timeskip=false;
 30: 
 31: if (!$NATS_Session->Check($NATS->DB,$timeskip))
 32: 	{
 33: 	header("Location: ./?login_msg=Invalid+Or+Expired+Session");
 34: 	exit();
 35: 	}
 36: if ($NATS_Session->userlevel<1) UL_Error($NATS->Lang->Item("live.monitor"));
 37: 
 38: if (isset($_REQUEST['style']))
 39: 	{
 40: 	$style=$_REQUEST['style'];
 41: 	setcookie("fn_monitorstyle",$style);
 42: 	}
 43: else if (isset($_COOKIE['fn_monitorstyle']))
 44: 	{
 45: 	$style=$_COOKIE['fn_monitorstyle'];
 46: 	}
 47: else $style="standard";
 48: 
 49: if ($style=="") $style="standard";
 50: 
 51: Screen_Header($NATS->Lang->Item("live.monitor"),1,1,"<meta http-equiv=\"refresh\" content=\"60\">");
 52: ?>
 53: <br>
 54: 
 55: <div class="monitorviews" id="monitorviews_div">
 56: <a href="javascript:showMonitorViews()"><?php echo $NATS->Lang->Item("mon.options"); ?></a>
 57: </div>
 58: 
 59: <?php
 60: /*
 61: echo "<style type=\"text/css\">\n";
 62: include("css/monitor.css");
 63: echo "\n</style>\n";
 64: */
 65: ?>
 66: <link rel="stylesheet" type="text/css" href="css/monitor.css" />
 67: <?php
 68: if ($NATS->Cfg->Get("site.monitor.popup",1)==0) $monpopup=false;
 69: else $monpopup=true;
 70: 
 71: if ($monpopup)
 72: {
 73: echo "<div class=\"monitor_popup\" id=\"popup_div\"></div>";
 74: echo "<script type=\"text/javascript\" src=\"js/monitor.popup.js\">\n";
 75: echo "</script>\n";
 76: }
 77: ?>
 78: 
 79: <script type="text/javascript">
 80: var dispOptions=new Array();
 81: var dispLink=new Array();
 82: 
 83: var optCount=0;
 84: dispOptions[optCount]='standard';
 85: dispLink[optCount++]='<?php echo $NATS->Lang->Item("mon.std"); ?>';
 86: dispOptions[optCount]='groups';
 87: dispLink[optCount++]='<?php echo $NATS->Lang->Item("mon.grp"); ?>';
 88: dispOptions[optCount]='nodes';
 89: dispLink[optCount++]='<?php echo $NATS->Lang->Item("mon.nodes"); ?>';
 90: dispOptions[optCount]='alerting';
 91: dispLink[optCount++]='<?php echo $NATS->Lang->Item("mon.alerting"); ?>';
 92: dispOptions[optCount]='list';
 93: dispLink[optCount++]='<?php echo $NATS->Lang->Item("mon.list"); ?>';
 94: 
 95: function showMonitorViews()
 96: {
 97: var content='';
 98: for (var a=0; a<optCount; a++)
 99: 	{
100: 	content=content+'<a href=monitor.php?style='+dispOptions[a]+'>';
101: 	content=content+'<img src=images/monitor_thumb/'+dispOptions[a]+'.png border=0><br>'+dispLink[a]+'</a><br><br>';
102: 	}
103: content=content+'<a href="javascript:hideMonitorViews()"><?php echo $NATS->Lang->Item("mon.hide"); ?></a>';
104: document.getElementById('monitorviews_div').innerHTML=content;
105: }
106: 
107: function hideMonitorViews()
108: {
109: document.getElementById('monitorviews_div').innerHTML='<a href="javascript:showMonitorViews()"><?php echo $NATS->Lang->Item("mon.options"); ?></a>';
110: }
111: 
112: <?php
113:  if (isset($_REQUEST['showviewoption'])) echo "showMonitorViews();\n";
114: ?>
115: </script>
116: 
117: <?php
118: 
119: 
120: ob_end_flush();
121: 
122: if ($style=="standard")
123: {
124: 
125: $q="SELECT * FROM fngroup ORDER BY weight ASC";
126: $r=$NATS->DB->Query($q);
127: 
128: if ($NATS->DB->Num_Rows($r)>0)
129: 	{
130: 	echo "<table border=0>";
131: 	$a=0;
132: 	while ($row=$NATS->DB->Fetch_Array($r))
133: 	{
134: 		if ($NATS->isUserAllowedGroup($NATS_Session->username,$row['groupid']))
135: 		{
136: 			if ($a==0) echo "<tr>";
137: 			echo "<td>";
138: 			ng_big($row['groupid'],$row['groupname'],$row['groupdesc'],$row['groupicon']);
139: 			echo "</td>";
140: 			$a++;
141: 			if ($a==2)
142: 				{
143: 				$a=0;
144: 				echo "</tr>";
145: 				}
146: 		}
147: 	}
148: 	if ($a>0) echo "</tr>";
149: 	echo "</table>";
150: 	echo "<br><br>";
151: 	}
152: 
153: 
154: $NATS->DB->Free($r);
155: 
156: 
157: $q="SELECT * FROM fnnode ORDER BY alertlevel DESC, weight ASC";
158: $r=$NATS->DB->Query($q);
159: 
160: echo "<table border=0>";
161: $a=0;
162: while ($row=$NATS->DB->Fetch_Array($r))
163: {
164: 	if ($NATS->isUserAllowedNode($NATS_Session->username,$row['nodeid']))
165: 	{
166: 		if ($a==0) echo "<tr>";
167: 		echo "<td>";
168: 		np_tiny($row['nodeid'],true,$row['nodename'],$monpopup);
169: 		echo "</td>";
170: 		$a++;
171: 		if ($a==5)
172: 			{
173: 			$a=0;
174: 			echo "</tr>";
175: 			}
176: 	}
177: }
178: if ($a>0) echo "</tr>";
179: echo "</table>";
180: $NATS->DB->Free($r);
181: }
182: 
183: else if ($style=="alerting")
184: {
185: $q="SELECT * FROM fngroup ORDER BY weight ASC";
186: $r=$NATS->DB->Query($q);
187: 
188: echo "<table border=0>";
189: $a=0;
190: while ($row=$NATS->DB->Fetch_Array($r))
191: 	{
192: 		if ($NATS->GroupAlertLevel($row['groupid'])>0 && $NATS->isUserAllowedGroup($NATS_Session->username,$row['groupid']))
193: 		{
194: 		if ($a==0) echo "<tr>";
195: 		echo "<td>";
196: 		ng_big($row['groupid'],$row['groupname'],$row['groupdesc'],$row['groupicon']);
197: 		echo "</td>";
198: 		$a++;
199: 		if ($a==2)
200: 			{
201: 			$a=0;
202: 			echo "</tr>";
203: 			}
204: 		}
205: 	}
206: if ($a>0) echo "</tr>";
207: echo "</table>";
208: 
209: 
210: $NATS->DB->Free($r);
211: 
212: echo "<br><br>";
213: 
214: $q="SELECT * FROM fnnode WHERE alertlevel!=0 ORDER BY alertlevel DESC, weight ASC";
215: $r=$NATS->DB->Query($q);
216: 
217: echo "<table border=0>";
218: $a=0;
219: while ($row=$NATS->DB->Fetch_Array($r))
220: {
221: 	if ($NATS->isUserAllowedNode($NATS_Session->username,$row['nodeid']))
222: 	{
223: 		if ($a==0) echo "<tr>";
224: 		echo "<td>";
225: 		np_tiny($row['nodeid'],true,$row['nodename'],$monpopup);
226: 		echo "</td>";
227: 		$a++;
228: 		if ($a==5)
229: 			{
230: 			$a=0;
231: 			echo "</tr>";
232: 			}
233: 	}
234: }
235: if ($a>0) echo "</tr>";
236: echo "</table>";
237: $NATS->DB->Free($r);
238: }
239: 
240: else if ($style=="groups")
241: {
242: $q="SELECT * FROM fngroup ORDER BY weight ASC";
243: $r=$NATS->DB->Query($q);
244: 
245: echo "<table border=0>";
246: $a=0;
247: while ($row=$NATS->DB->Fetch_Array($r))
248: {
249: 	if ($NATS->isUserAllowedGroup($NATS_Session->username,$row['groupid']))
250: 	{
251: 		if ($a==0) echo "<tr>";
252: 		echo "<td>";
253: 		ng_big($row['groupid'],$row['groupname'],$row['groupdesc'],$row['groupicon'],$monpopup);
254: 		echo "</td>";
255: 		$a++;
256: 		if ($a==2)
257: 			{
258: 			$a=0;
259: 			echo "</tr>";
260: 			}
261: 	}
262: }
263: if ($a>0) echo "</tr>";
264: echo "</table>";
265: 
266: 
267: $NATS->DB->Free($r);
268: }
269: 
270: else if ($style=="nodes")
271: {
272: $q="SELECT * FROM fnnode ORDER BY alertlevel DESC, weight ASC";
273: $r=$NATS->DB->Query($q);
274: 
275: echo "<table border=0>";
276: $a=0;
277: while ($row=$NATS->DB->Fetch_Array($r))
278: {
279: 	if ($NATS->isUserAllowedNode($NATS_Session->username,$row['nodeid']))
280: 	{
281: 		if ($a==0) echo "<tr>";
282: 		echo "<td>";
283: 		np_big($row['nodeid'],$row['nodename'],$row['nodedesc'],$row['nodeicon'],$monpopup);
284: 		echo "</td>";
285: 		$a++;
286: 		if ($a==2)
287: 			{
288: 			$a=0;
289: 			echo "</tr>";
290: 			}
291: 	}
292: }
293: if ($a>0) echo "</tr>";
294: echo "</table>";
295: 
296: 
297: $NATS->DB->Free($r);
298: }
299: else if ($style=="list")
300: {
301: $q="SELECT * FROM fnnode ORDER BY alertlevel DESC, weight ASC";
302: $r=$NATS->DB->Query($q);
303: 
304: echo "<table border=0>";
305: $a=0;
306: while ($row=$NATS->DB->Fetch_Array($r))
307: {
308: 	if ($NATS->isUserAllowedNode($NATS_Session->username,$row['nodeid']))
309: 	{
310: 		if ($a==0) {
311:             echo "<tr>";
312:             echo '<td align="left">'.$NATS->Lang->Item("node.name").'</td><td align="left">'.$NATS->Lang->Item("description").'</td><td align="center">'.$NATS->Lang->Item("status").'</td><td align="center">'.$NATS->Lang->Item("node.enabled").'</td>';
313:             echo "</tr>";
314:         }
315: 		np_list_item($row['nodeid'],$row['nodename'],$row['nodedesc'],$row['nodeenabled'],$monpopup);
316: 		$a++;
317: 	}
318: }
319: echo "</table>";
320: 
321: 
322: $NATS->DB->Free($r);
323: }
324: 
325: else
326: {
327: echo "<b>Sorry - unknown display style type</b><br><br>";
328: }
329: 
330: mt_srand(microtime()*1000000);
331: if (mt_rand(0,100)==50) $track_if_enabled=true;
332: else $track_if_enabled=false;
333: 
334: Screen_Footer($track_if_enabled);
335: ?>
336: