File: 0.04.23a/server/base/screen.inc.php (View as HTML)

  1: <?php // screen.inc.php -- web page screen library
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008 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: $menu=array();
 24: $menu[0]="<a href=http://www.purplepixie.org/freenats/>FreeNATS Homepage</a>";
 25: $menu[1]="<a href=monitor.php>Monitor</a> | <a href=main.php>Main</a> | <a href=pref.php>Settings</a> | ";
 26: $menu[1].="<a href=http://www.purplepixie.org/freenats/support.php target=top>Help</a> | <a href=logout.php>Logout</a>";
 27: $menu[2]=$menu[1]." | <a href=admin.php>Admin</a>";
 28: 
 29: $poplist=array();
 30: 
 31: function Screen_Header($title,$menuindex=0,$alertpane=0,$ah="")
 32: {
 33: global $menu,$NATS,$NATS_Session;
 34: if ($NATS->Cfg->Get("site.enable.interactive")!=1)
 35: 	{
 36: 	echo "Sorry but FreeNATS interactive is disabled.<br>";
 37: 	echo "<i>site.enable.interactive</i> != 1<br><br>";
 38: 	$NATS->Stop();
 39: 	exit();
 40: 	}
 41: if ($menuindex==1) $alertpane=1; // bodge
 42: if ($NATS_Session->userlevel>9) $menuindex=2; // further bodge!
 43: echo "<html><head><title>FreeNATS: ".$title."</title>\n";
 44: echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\">\n";
 45: if ($ah!="") echo $ah;
 46: echo "</head>\n";
 47: echo "<script type=\"text/javascript\" src=\"js/freenats.js\"></script>\n";
 48: echo "<body>";
 49: 
 50: echo "<table width=100% class=\"maintitle\">\n";
 51: echo "<tr><td align=left valign=center>\n";
 52: echo "<b class=\"maintitle\">FreeNATS: ".$title."</b></td>\n";
 53: echo "<td class=\"titlelink\" align=right valign=center>\n";
 54: echo $menu[$menuindex];
 55: echo "</td></tr></table>\n";
 56: 
 57: if ($alertpane==1)
 58: 	{
 59: 	$alerts=$NATS->GetAlerts();
 60: 	if (is_array($alerts))
 61: 		{
 62: 		echo "<div class=\"alertpane\" id=\"fn_alertpane\">";
 63: 		echo "<b><u>NATS Alerts</u></b><br><br>";
 64: 		foreach($alerts as $alert)
 65: 			{
 66: 			echo "&nbsp;<a href=node.php?nodeid=".$alert['nodeid'].">";
 67: 			echo "<b class=\"al".$alert['alertlevel']."\">".$alert['nodeid']."</b></a><br>";
 68: 			}
 69: 		echo "<br>";
 70: 		echo "</div>";
 71: 		}
 72: 	}
 73: 
 74: }
 75: /* -- old table footer
 76: function Screen_Footer()
 77: {
 78: global $NATS,$poplist;
 79: echo "<br><br>\n";
 80: //$NATS->Cfg->DumpToScreen();
 81: echo "<table class=\"nfooter\" width=100%>";
 82: echo "<tr><td align=left><a href=http://www.purplepixie.org/freenats/>FreeNATS</a>; &copy; Copyright 2008 ";
 83: echo "<a href=http://www.purplepixie.org/>PurplePixie Systems</a>";
 84: echo "</td><td align=right>";
 85: echo "Version: ".$NATS->Version;
 86: if ($NATS->Release!="") echo "/".$NATS->Release;
 87: echo "</td></tr>";
 88: echo "</table>";
 89: echo "</div>";
 90: if (ini_get("freenats.rpath")==1)
 91: 	{
 92: 	echo "<i>FreeNATS Virtual Server Powered By <a href=http://www.rpath.org/>rPath</a> LAMP Appliance</i><br>";
 93: 	}
 94: echo "<i>This is alpha-test software - we would very much value your ";
 95: echo "<a href=http://www.purplepixie.org/freenats/feedback.php>feedback</a></i><br>";
 96: 
 97: $t=$NATS->Cfg->Get("freenats.tracker");
 98: if ( ($t!="") && ($t>0) )
 99: 	{
100: 	$sn=explode("/",$_SERVER['SCRIPT_NAME']);
101: 	$script=$sn[count($sn)-1];
102: 	echo "<img src=\"http://www.purplepixie.org/freenats/report/ping.png.php?data=v=".$NATS->Version."+p=".$script."&type=ping\" width=1 height=1>\n";
103: 	}
104: 
105: if ($NATS->Cfg->Get("site.popupmessage")=="1")
106: 	{
107: 	if (count($poplist)>0)
108: 		{
109: 		echo "\n<script type=\"text/javascript\">\n";
110: 		
111: 		foreach($poplist as $pop)
112: 			{
113: 			echo "alert('".$pop."');\n";
114: 			}
115: 			
116: 		echo "</script>\n";
117: 		}
118: 	}
119: echo "\n</body></html>\n";
120: }
121: */
122: function Screen_Footer()
123: {
124: global $NATS,$poplist;
125: echo "<br><br>\n";
126: //$NATS->Cfg->DumpToScreen();
127: echo "<div class=\"nfooter\">";
128: echo "<div align=\"left\" class=\"nfootleft\"><a href=http://www.purplepixie.org/freenats/>FreeNATS</a>; &copy; Copyright 2008 ";
129: echo "<a href=http://www.purplepixie.org/>PurplePixie Systems</a>";
130: echo "</div><div class=\"nfootright\">";
131: echo "Version: ".$NATS->Version;
132: if ($NATS->Release!="") echo "/".$NATS->Release;
133: echo "&nbsp;&nbsp;</div>";
134: echo "</div>";
135: if (ini_get("freenats.rpath")==1)
136: 	{
137: 	echo "<i>FreeNATS Virtual Server Powered By <a href=http://www.rpath.org/>rPath</a> LAMP Appliance</i><br>";
138: 	}
139: //echo "<i>This is alpha-test software - we would very much value your ";
140: //echo "<a href=http://www.purplepixie.org/freenats/feedback.php>feedback</a></i><br>";
141: 
142: $t=$NATS->Cfg->Get("freenats.tracker");
143: if ( ($t!="") && ($t>0) )
144: 	{
145: 	$sn=explode("/",$_SERVER['SCRIPT_NAME']);
146: 	$script=$sn[count($sn)-1];
147: 	echo "<img src=\"http://www.purplepixie.org/freenats/report/ping.png.php?data=v=".$NATS->Version."+p=".$script."&type=ping\" width=1 height=1>\n";
148: 	}
149: 
150: if ($NATS->Cfg->Get("site.popupmessage")=="1")
151: 	{
152: 	if (count($poplist)>0)
153: 		{
154: 		echo "\n<script type=\"text/javascript\">\n";
155: 		
156: 		foreach($poplist as $pop)
157: 			{
158: 			echo "alert('".$pop."');\n";
159: 			}
160: 			
161: 		echo "</script>\n";
162: 		}
163: 	}
164: echo "\n</body></html>\n";
165: }
166: 
167: function UL_Error($task="")
168: {
169: Screen_Header("Insufficient Access");
170: echo "<br>Sorry but your user has insufficient access to perform task (".$task.").<br><br>";
171: echo "<a href=main.php>Please click here to continue.</a><br><br>";
172: Screen_Footer();
173: exit();
174: }
175: 
176: function nicedt($ts)
177: {
178: global $NATS;
179: $form="H:i:s d/m/Y";
180: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y");
181: if ($ts<=0) return "never";
182: return date($form,$ts);
183: }
184: 
185: function enicedt($ts)
186: {
187: echo nicedt($ts);
188: }
189: 
190: function nicediff($diff)
191: {
192: $hr=0;
193: $mn=0;
194: $se=0;
195: if ($diff>59)
196: 	{
197: 	$mn=round($diff/60,0);
198: 	$se=$diff%60;
199: 	if ($mn>59)
200: 		{
201: 		$hr=round($mn/60,0);
202: 		$mn=$mn%60;
203: 		}
204: 	}
205: else $se=$diff;
206: $s="";
207: if ($hr<10) $s="0";
208: $s.=$hr.":";
209: if ($mn<10) $s.="0";
210: $s.=$mn.":";
211: if ($se<10) $s.="0";
212: $s.=$se;
213: return $s;
214: }
215: 
216: function dtago($ts,$sayago=true)
217: {
218: if ($ts<=0) return "never";
219: $now=time();
220: $diff=$now-$ts;
221: $s=nicediff($diff);
222: if ($sayago) $s.=" ago";
223: return $s;
224: }
225: 
226: function edtago($ts)
227: {
228: echo dtago($ts);
229: }
230: 
231: function smartx($x) // smart handling of unixtime x variables
232: {
233: if ($x==0) return time();	// 0 = now
234: else if ($x<0)				// -z = now - z seconds
235: 	return (time()+$x);		// negative number so +
236: else						// positive number so is a unixtime
237: 	return $x;
238: }
239: 
240: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?";
241: 
242: function nices($s)
243: {
244: global $allowed;
245: $o="";
246: for ($a=0; $a<strlen($s); $a++)
247: 	{
248: 	$c=$s[$a];
249: 	if (strpos($allowed,$c)===false)
250: 		{
251: 		// skip it
252: 		}
253: 	else $o.=$c;
254: 	}
255: return $o;
256: }
257: 
258: function ShowIcons()
259: {
260: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
261: $c=0;
262: echo "<table border=0>";
263: $cc=0;
264: for ($a=0; $a<count($fnIcons); $a++)
265: 	{
266: 	if ($cc==0) echo "<tr>";
267: 	echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>";
268: 	if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> ";
269: 	if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>";
270: 	echo "</td>";
271: 	$cc++;
272: 	if ($cc>=5)
273: 		{
274: 		echo "</tr>";
275: 		$cc=0;
276: 		}
277: 	}
278: if ($cc>0) echo "</tr>";
279: echo "</table>";
280: }
281: 
282: 
283: function NodeIcon($nodeid)
284: {
285: global $NATS,$fnIcons,$fnIcon_DefNode;
286: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\"";
287: $r=$NATS->DB->Query($q);
288: if ($row=$NATS->DB->Fetch_Array($r)) 
289: 	{
290: 	if ($row['nodeicon']!="") return $row['nodeicon'];
291: 	}
292: return $fnIcons[$fnIcon_DefNode];
293: }
294: 
295: function GroupIcon($groupid)
296: {
297: global $NATS,$fnIcons,$fnIcon_DefGroup;
298: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\"";
299: $r=$NATS->DB->Query($q);
300: if ($row=$NATS->DB->Fetch_Array($r)) 
301: 	{
302: 	if ($row['groupicon']!="") return $row['groupicon'];
303: 	}
304: return $fnIcons[$fnIcon_DefGroup];
305: }
306: 
307: function np_tiny($nodeid,$text=true,$nodename="")
308: {
309: global $NATS;
310: $al=$NATS->NodeAlertLevel($nodeid);
311: echo "<table class=\"nptiny-al".$al."\">";
312: echo "<tr><td valign=center align=center>";
313: echo "<a href=node.php?nodeid=".$nodeid.">";
314: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>";
315: echo "</a>";
316: if ($text)
317: 	{
318: 	if ($nodename=="") $nodename=$nodeid;
319: 	
320: 	//$words=explode(" ",$nodename);
321: 	
322: 	// messy but there you go...
323: 	
324: 	$max_on_line=7;
325: 	$max_lines=2;
326: 	$len=strlen($nodename);
327: 	$out="";
328: 	$linecount=0;
329: 	$charcount=0;
330: 	for ($a=0; $a<$len; $a++)
331: 		{
332: 			
333: 		$char=$nodename[$a];
334: 		
335: 		if ($char==" ")
336: 			{
337: 			$linecount++;
338: 			$charcount=0;
339: 			}
340: 		else $charcount++;
341: 		
342: 		if ($charcount>=$max_on_line) 
343: 			{
344: 			$a=$len+10;
345: 			$out.="..";
346: 			}
347: 		else if ($linecount>=$max_lines) 
348: 			{
349: 			$a=$len+10;
350: 			$out.="..";
351: 			}
352: 		else $out.=$char;
353: 		
354: 		}
355: 	//if ($a==($len+10)) $out.="..";
356: 	$nodename=$out;
357: 	
358: 	$size=10;
359: 		
360: /* -- size-based	
361: 	$len=strlen($nodename);
362: 	if ($len<9) $size=10;
363: 	else if ($len<15) $size=8;
364: 	else if ($len<20) $size=7;
365: 	else
366: 		{
367: 		$size=6;
368: 		$nodename=substr($nodename,0,18)."..";
369: 		}
370: */
371: 	
372: 	echo "<br><b class=\"al".$al."\" style=\"font-size: ".$size."pt;\">".$nodename."</b>";
373: 	}
374: echo "</td></tr></table>";
375: }
376: 
377: function ng_tiny($groupid,$groupname="",$text=true)
378: {
379: global $NATS;
380: // to do - get groupname if not sent but F--- it for now
381: $al=$NATS->GroupAlertLevel($groupid);
382: echo "<table class=\"nptiny-al".$al."\">";
383: echo "<tr><td valign=center align=center>";
384: echo "<a href=group.php?groupid=".$groupid.">";
385: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>";
386: echo "</a>";
387: if ($text)
388: 	{
389: 	echo "<br><b class=\"al".$al."\">".$groupname."</b>";
390: 	}
391: echo "</td></tr></table>";
392: }
393: 
394: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="")
395: {
396: global $NATS;
397: if ($groupicon=="") $groupicon=GroupIcon($groupid);
398: $al=$NATS->GroupAlertLevel($groupid);
399: echo "<table class=\"npbig-al".$al."\">";
400: echo "<tr><td align=left valign=top>";
401: echo "<table class=\"nicetable\" width=300>";
402: echo "<tr><td align=right>Group Name :";
403: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>";
404: echo "<tr><td align=right>Description :";
405: echo "</td><td align=left>".$groupdesc."</td></tr>";
406: echo "<tr><td align=right>Status :</td><td align=left>";
407: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
408: echo "</table></td>";
409: //echo "<td align=left valign=top align=right width=60>";
410: //echo "<img src=icons/".GroupIcon($groupid).">";
411: //echo "</td>";
412: echo "</tr>";
413: echo "</table>";
414: }
415: 
416: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="")
417: {
418: global $NATS;
419: if ($nodedesc=="") $nodedesc="&nbsp;";
420: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid);
421: $al=$NATS->NodeAlertLevel($nodeid);
422: echo "<table class=\"npbig-al".$al."\">";
423: echo "<tr><td align=left valign=top>";
424: echo "<table class=\"nicetable\" width=300>";
425: echo "<tr><td align=right>Node Name :";
426: if ($nodename=="") $nodename=$nodeid;
427: echo "</td><td align=left><a href=node.php?nodeid=".$nodeid.">".$nodename."</a></td></tr>";
428: echo "<tr><td align=right>Description :";
429: echo "</td><td align=left>".$nodedesc."</td></tr>";
430: echo "<tr><td align=right>Status :</td><td align=left>";
431: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
432: echo "</table></td>";
433: //echo "<td align=left valign=top align=right width=60>";
434: //echo "<img src=icons/".GroupIcon($groupid).">";
435: //echo "</td>";
436: echo "</tr>";
437: echo "</table>";
438: }
439: 
440: function GetAbsolute($filename="")
441: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY!
442: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://";
443: else $uri="http://";
444: $uri.=$_SERVER['HTTP_HOST'];
445: $uri.=$_SERVER['REQUEST_URI'];
446: $pos=strripos($uri,"/");
447: $rdir=substr($uri,0,$pos+1);
448: return $rdir.$filename;
449: }
450: 
451: 
452: ?>