File: 1.10.0a/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/>".$NATS->Lang->Item("homepage")."</a>";
 25: $menu[1]="<a href=monitor.php>".$NATS->Lang->Item("live.monitor")."</a>&nbsp; &nbsp;<a href=main.php>".$NATS->Lang->Item("configuration")."</a>&nbsp; &nbsp;";
 26: $menu[1].="<a href=http://www.purplepixie.org/freenats/support.php target=top>".$NATS->Lang->Item("help")."</a>&nbsp; &nbsp;<a href=logout.php>".$NATS->Lang->Item("logout")."</a>";
 27: $menu[2]=$menu[1]."&nbsp; &nbsp;<a href=admin.php>Admin</a>";
 28: 
 29: $menu[3]="<a href=iphone.php>".$NATS->Lang->Item("iphone")."</a>&nbsp;  &nbsp;<a href=http://www.purplepixie.org/freenats/>".$NATS->Lang->Item("homepage")."</a>";
 30: /*
 31: $pagemenu['main']="<a href=main.php?mode=overview>Overview</a>&nbsp; &nbsp;<a href=main.php?mode=nodes>Nodes</a>&nbsp; &nbsp;";
 32: $pagemenu['main'].="<a href=main.php?mode=groups>Groups</a>&nbsp; &nbsp;<a href=main.php?mode=views>Views &amp; Reports</a>&nbsp; &nbsp;";
 33: $pagemenu['main'].="<a href=pref.php>User Options</a>";
 34: */
 35: $pagemenu=array();
 36: $pagemenu['main']=array(
 37: 	array("overview","main.php?mode=overview",$NATS->Lang->Item("overview")),
 38: 	array("nodes","main.php?mode=nodes",$NATS->Lang->Item("nodes")),
 39: 	array("groups","main.php?mode=groups",$NATS->Lang->Item("groups")),
 40: 	array("views","main.php?mode=views",$NATS->Lang->Item("views.reports")),
 41: 	array("pref","pref.php?mode=pref",$NATS->Lang->Item("user.options")),
 42: 	array("admin","admin.php",$NATS->Lang->Item("system.settings")) );
 43: 	
 44: function PageMenu($name,$mode="")
 45: {
 46: global $pagemenu;
 47: if (($mode=="")&&isset($_REQUEST['mode'])) $mode=$_REQUEST['mode'];
 48: $out="";
 49: $first=true;
 50: foreach($pagemenu[$name] as $opt)
 51: 	{
 52: 	if ($first) $first=false;
 53: 	else $out.=" ";
 54: 	if ($mode!=$opt[0]) $out.="&nbsp;<a href=".$opt[1].">";
 55: 	else $out.="<b style=\"background-color: #ffffff;\">&nbsp;<a href=\"".$opt[1]."\" style=\"color: black; text-decoration: none;\">";
 56: 	$out.=$opt[2];
 57: 	if ($mode!=$opt[0]) $out.="</a>&nbsp; ";
 58: 	else $out.="</a>&nbsp;</b>";
 59: 	}
 60: return $out;
 61: }
 62: 	
 63: $poplist=array();
 64: 
 65: function Screen_Header($title,$menuindex=0,$alertpane=0,$ah="",$pagemenu="",$pagemenumode="")
 66: {
 67: global $menu,$NATS,$NATS_Session;
 68: if ($NATS->Cfg->Get("site.enable.interactive")!=1)
 69: 	{
 70: 	echo "Sorry but FreeNATS interactive is disabled.<br>";
 71: 	echo "<i>site.enable.interactive</i> != 1<br><br>";
 72: 	$NATS->Stop();
 73: 	exit();
 74: 	}
 75: if ($menuindex==1) $alertpane=1; // bodge
 76: //if ($NATS_Session->userlevel>9) $menuindex=2; // further bodge!
 77: echo "<html><head><title>FreeNATS: ".$title."</title>\n";
 78: echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\">\n";
 79: /*
 80: echo "<style type=\"text/css\">\n";
 81: require("css/main.css");
 82: echo "\n</style>\n";
 83: */
 84: if ($ah!="") echo $ah;
 85: echo "</head>\n";
 86: echo "<script type=\"text/javascript\" src=\"js/freenats.js\"></script>\n";
 87: echo "<body>";
 88: 
 89: echo "<table class=\"maintitle\" cellspacing=0 cellpadding=0>\n";
 90: echo "<tr><td align=left valign=center class=\"mainleft\">\n";
 91: echo "<b class=\"maintitle\">".$title."</b>";
 92: if ($pagemenu!="") echo "<br>&nbsp;&nbsp;<b>".PageMenu($pagemenu,$pagemenumode)."</b>";
 93: echo "</td>\n";
 94: echo "<td class=\"titlelink\" align=right valign=center>\n";
 95: echo $menu[$menuindex];
 96: echo "&nbsp;</td></tr>\n";
 97: //echo "<tr><td align=left valign=bottom><img src=images/e0e0ff.10px.bl.jpg></td>";
 98: //echo "</tr>\n";
 99: echo "</table>\n";
100: 
101: if ($alertpane==1)
102: 	{
103: 	$alerts=$NATS->GetAlerts();
104: 	if (is_array($alerts))
105: 		{
106: 		echo "<div class=\"alertpane\" id=\"fn_alertpane\">";
107: 		echo "<b><u>".$NATS->Lang->Item("nats.alerts")."</u></b><br><br>";
108: 		foreach($alerts as $alert)
109: 			{
110: 			echo "&nbsp;<a href=node.php?nodeid=".$alert['nodeid'].">";
111: 			echo "<b class=\"al".$alert['alertlevel']."\">".$alert['nodeid']."</b></a><br>";
112: 			}
113: 		echo "<br>";
114: 		echo "</div>";
115: 		}
116: 	}
117: 
118: }
119: 
120: function Start_Round($title,$width="")
121: {
122: if ($width!="") $w=" width=".$width;
123: else $w="";
124: echo "<table border=0".$w." cellspacing=0 cellpadding=0>\n";
125: echo "<tr><td valign=top align=left width=11 style=\"background-color: #e0e0ff;\"><img src=images/e0e0ff.10px.tl.jpg></td>\n";
126: echo "<td align=left valign=center style=\"background-color: #e0e0ff;\">\n";
127: echo $title;
128: echo "\n</td><td align=right valign=top style=\"background-color: #e0e0ff;\"><img src=images/e0e0ff.10px.tr.jpg></td></tr>\n";
129: echo "<tr><td colspan=3 style=\"border-left: solid 1px #e0e0ff; border-bottom: solid 1px #e0e0ff; border-right: solid 1px #e0e0ff; padding: 5px;\">\n";
130: }
131: 
132: function End_Round()
133: {
134: echo "\n</td></tr>\n";
135: 
136: echo "</table>";
137: }
138: 
139: function Screen_Footer($track_if_enabled=true)
140: {
141: global $NATS,$poplist;
142: echo "<br><br>\n";
143: //$NATS->Cfg->DumpToScreen();
144: echo "<div class=\"nfooter\">";
145: echo "<div class=\"bl\"><div class=\"br\"><div class=\"tl\"><div class=\"tr\">";
146: 
147: echo "<div align=\"left\" class=\"nfootleft\"><a href=http://www.purplepixie.org/freenats/>FreeNATS</a>; &copy; ".$NATS->Lang->Item("copyright")." 2008-2010 ";
148: echo "<a href=http://www.purplepixie.org/>PurplePixie Systems</a>";
149: echo "</div><div class=\"nfootright\">";
150: echo $NATS->Lang->Item("version").": ".$NATS->Version;
151: if ($NATS->Release!="") echo "/".$NATS->Release;
152: echo "&nbsp;&nbsp;</div>";
153: 
154: //echo "Hello";
155: echo "</div></div></div></div>";
156: echo "</div>";
157: if (ini_get("freenats.rpath")==1)
158: 	{
159: 	echo "<i>FreeNATS Virtual Server Powered By <a href=http://www.rpath.org/>rPath</a> LAMP Appliance</i><br>";
160: 	}
161: //echo "<i>This is alpha-test software - we would very much value your ";
162: //echo "<a href=http://www.purplepixie.org/freenats/feedback.php>feedback</a></i><br>";
163: if ($track_if_enabled)
164: 	{
165: 	$t=$NATS->Cfg->Get("freenats.tracker");
166: 	if ( ($t!="") && ($t>0) )
167: 		{
168: 		$usid=$NATS->Cfg->Get("freenats.tracker.usid","");
169: 		if ($usid=="")
170: 			{ // generate usid if not already set
171: 			// usid form XYZ-XYZ-XYZ...
172: 			$allow="abcdef0123456789";
173: 			$allow_len=strlen($allow);
174: 			mt_srand(microtime()*1000000);
175: 			$first_set=1;
176: 			for ($a=0; $a<5; $a++) // blocks
177: 				{
178: 				if ($first_set==1) $first_set=0;
179: 				else $usid.="-";
180: 				for ($b=0; $b<10; $b++)
181: 					{
182: 					$c=mt_rand(0,$allow_len-1);
183: 					$usid.=$allow[$c];
184: 					}
185: 				}
186: 			$NATS->Cfg->Set("freenats.tracker.usid",$usid);
187: 			}
188: 			
189: 		// get some more data
190: 		$sn=explode("/",$_SERVER['SCRIPT_NAME']);
191: 		$script=$sn[count($sn)-1];
192: 		
193: 		// show tracking image
194: 		echo "<img src=\"http://www.purplepixie.org/freenats/report/ping.png.php?data=v=".$NATS->Version."+p=".$script."&type=ping&usid=".$usid."\" width=1 height=1>\n";
195: 		}
196: 	}
197: 
198: if ($NATS->Cfg->Get("site.popupmessage")=="1")
199: 	{
200: 	if (count($poplist)>0)
201: 		{
202: 		echo "\n<script type=\"text/javascript\">\n";
203: 		
204: 		foreach($poplist as $pop)
205: 			{
206: 			echo "alert('".$pop."');\n";
207: 			}
208: 			
209: 		echo "</script>\n";
210: 		}
211: 	}
212: echo "\n</body></html>\n";
213: }
214: 
215: function UL_Error($task="")
216: {
217: global $NATS;
218: Screen_Header($NATS->Lang->Item("access.error"));
219: echo "<br>".$NATS->Lang->Item("access.error.detail")." (".$task.").<br><br>";
220: echo "<a href=main.php>".$NATS->Lang->Item("click.continue")."</a><br><br>";
221: Screen_Footer();
222: exit();
223: }
224: 
225: function Session_Error()
226: {
227: global $REQUEST_URI;
228: header("Location: ./?login_msg=Invalid+or+Expired+Session&url=".urlencode($REQUEST_URI));
229: exit();
230: }
231: 
232: function nicedt($ts)
233: {
234: global $NATS;
235: $form="H:i:s d/m/Y";
236: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y");
237: if ($ts<=0) return $NATS->Lang->Item("never");
238: return date($form,$ts);
239: }
240: 
241: function enicedt($ts)
242: {
243: echo nicedt($ts);
244: }
245: 
246: function nicediff($diff)
247: {
248: $hr=0;
249: $mn=0;
250: $se=0;
251: if ($diff>59)
252: 	{
253: 	$mn=round($diff/60,0);
254: 	$se=$diff%60;
255: 	if ($mn>59)
256: 		{
257: 		$hr=round($mn/60,0);
258: 		$mn=$mn%60;
259: 		}
260: 	}
261: else $se=$diff;
262: $s="";
263: if ($hr<10) $s="0";
264: $s.=$hr.":";
265: if ($mn<10) $s.="0";
266: $s.=$mn.":";
267: if ($se<10) $s.="0";
268: $s.=$se;
269: return $s;
270: }
271: 
272: function dtago($ts,$sayago=true)
273: {
274: global $NATS;
275: if ($ts<=0) return $NATS->Lang->Item("never");
276: $now=time();
277: $diff=$now-$ts;
278: $s=nicediff($diff);
279: if ($sayago) $s.=" ".$NATS->Lang->Item("ago");
280: return $s;
281: }
282: 
283: function nicenextx($nextx)
284: {
285: if ($nextx<=0) return "Now";
286: $diff=$nextx-time();
287: if ($diff<0)
288: 	{
289: 	$sign=" ago";
290: 	$diff=0-$diff;
291: 	}
292: else $sign="";
293: return nicediff($diff).$sign;
294: }
295: 
296: function edtago($ts)
297: {
298: echo dtago($ts);
299: }
300: 
301: function smartx($x) // smart handling of unixtime x variables
302: {
303: if ($x==0) return time();	// 0 = now
304: else if ($x<0)				// -z = now - z seconds
305: 	return (time()+$x);		// negative number so +
306: else						// positive number so is a unixtime
307: 	return $x;
308: }
309: 
310: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?$";
311: 
312: function nices($s)
313: {
314: global $allowed;
315: $o="";
316: for ($a=0; $a<strlen($s); $a++)
317: 	{
318: 	$c=$s[$a];
319: 	if (strpos($allowed,$c)===false)
320: 		{
321: 		// skip it
322: 		}
323: 	else $o.=$c;
324: 	}
325: return $o;
326: }
327: /* // Old Static List Function
328: function ShowIcons()
329: {
330: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
331: $c=0;
332: echo "<table border=0>";
333: $cc=0;
334: for ($a=0; $a<count($fnIcons); $a++)
335: 	{
336: 	if ($cc==0) echo "<tr>";
337: 	echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>";
338: 	if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> ";
339: 	if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>";
340: 	echo "</td>";
341: 	$cc++;
342: 	if ($cc>=5)
343: 		{
344: 		echo "</tr>";
345: 		$cc=0;
346: 		}
347: 	}
348: if ($cc>0) echo "</tr>";
349: echo "</table>";
350: }
351: */
352: 
353: function GetIcons()
354: {
355: $iconFiles=glob("icons/{*.gif,*.GIF,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png,*.PNG}", GLOB_BRACE);
356: for($a=0;$a<count($iconFiles);$a++)
357: 	$iconFiles[$a]=substr($iconFiles[$a],6);
358: return $iconFiles;
359: }
360: 
361: 
362: function ShowIcons()
363: {
364: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup,$NATS;
365: $c=0;
366: echo "<table border=0>";
367: $cc=0;
368: $iconFiles=GetIcons();
369: for ($a=0; $a<count($iconFiles); $a++)
370: 	{
371: 	$icon=$iconFiles[$a];
372: 	if ($cc==0) echo "<tr>";
373: 	echo "<td valign=top align=center><img src=icons/".$icon."><br>".$icon."<br>";
374: 	if ($icon==$fnIcons[$fnIcon_DefNode]) echo "<i>".$NATS->Lang->Item("node.default")."</i> ";
375: 	if ($a==$fnIcons[$fnIcon_DefGroup]) echo "<i>".$NATS->Lang->Item("group.default")."</i>";
376: 	echo "</td>";
377: 	$cc++;
378: 	if ($cc>=5)
379: 		{
380: 		echo "</tr>";
381: 		$cc=0;
382: 		}
383: 	}
384: if ($cc>0) echo "</tr>";
385: echo "</table>";
386: }
387: 
388: 
389: 
390: function NodeIcon($nodeid)
391: {
392: global $NATS,$fnIcons,$fnIcon_DefNode;
393: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\"";
394: $r=$NATS->DB->Query($q);
395: if ($row=$NATS->DB->Fetch_Array($r)) 
396: 	{
397: 	if ($row['nodeicon']!="") return $row['nodeicon'];
398: 	}
399: return $fnIcons[$fnIcon_DefNode];
400: }
401: 
402: function GroupIcon($groupid)
403: {
404: global $NATS,$fnIcons,$fnIcon_DefGroup;
405: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\"";
406: $r=$NATS->DB->Query($q);
407: if ($row=$NATS->DB->Fetch_Array($r)) 
408: 	{
409: 	if ($row['groupicon']!="") return $row['groupicon'];
410: 	}
411: return $fnIcons[$fnIcon_DefGroup];
412: }
413: 
414: function np_tiny($nodeid,$text=true,$nodename="",$jslink=false)
415: {
416: global $NATS;
417: $al=$NATS->NodeAlertLevel($nodeid);
418: echo "<table class=\"nptiny-al".$al."\">";
419: echo "<tr><td valign=center align=center>";
420: if ($jslink) echo "<a href=\"javascript:nodeClick('".$nodeid."');\">";
421: else echo "<a href=node.php?nodeid=".$nodeid.">";
422: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>";
423: echo "</a>";
424: if ($text)
425: 	{
426: 	if ($nodename=="") $nodename=$nodeid;
427: 	
428: 	//$words=explode(" ",$nodename);
429: 	
430: 	// messy but there you go...
431: 	
432: 	$max_on_line=7;
433: 	$max_lines=2;
434: 	$len=strlen($nodename);
435: 	$out="";
436: 	$linecount=0;
437: 	$charcount=0;
438: 	for ($a=0; $a<$len; $a++)
439: 		{
440: 			
441: 		$char=$nodename[$a];
442: 		
443: 		if ($char==" ")
444: 			{
445: 			$linecount++;
446: 			$charcount=0;
447: 			}
448: 		else $charcount++;
449: 		
450: 		if ($charcount>=$max_on_line) 
451: 			{
452: 			$a=$len+10;
453: 			$out.="..";
454: 			}
455: 		else if ($linecount>=$max_lines) 
456: 			{
457: 			$a=$len+10;
458: 			$out.="..";
459: 			}
460: 		else $out.=$char;
461: 		
462: 		}
463: 	//if ($a==($len+10)) $out.="..";
464: 	$nodename=$out;
465: 	
466: 	$size=10;
467: 		
468: /* -- size-based	
469: 	$len=strlen($nodename);
470: 	if ($len<9) $size=10;
471: 	else if ($len<15) $size=8;
472: 	else if ($len<20) $size=7;
473: 	else
474: 		{
475: 		$size=6;
476: 		$nodename=substr($nodename,0,18)."..";
477: 		}
478: */
479: 	
480: 	echo "<br><b class=\"al".$al."\" style=\"font-size: ".$size."pt;\">".$nodename."</b>";
481: 	}
482: echo "</td></tr></table>";
483: }
484: 
485: function ng_tiny($groupid,$groupname="",$text=true)
486: {
487: global $NATS;
488: // to do - get groupname if not sent but F--- it for now
489: $al=$NATS->GroupAlertLevel($groupid);
490: echo "<table class=\"nptiny-al".$al."\">";
491: echo "<tr><td valign=center align=center>";
492: echo "<a href=group.php?groupid=".$groupid.">";
493: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>";
494: echo "</a>";
495: if ($text)
496: 	{
497: 	echo "<br><b class=\"al".$al."\">".$groupname."</b>";
498: 	}
499: echo "</td></tr></table>";
500: }
501: 
502: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="")
503: {
504: global $NATS;
505: if ($groupicon=="") $groupicon=GroupIcon($groupid);
506: $al=$NATS->GroupAlertLevel($groupid);
507: echo "<table class=\"npbig-al".$al."\">";
508: echo "<tr><td align=left valign=top>";
509: echo "<table class=\"nicetable\" width=300>";
510: echo "<tr><td align=right>".$NATS->Lang->Item("group.name")." :";
511: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>";
512: echo "<tr><td align=right>".$NATS->Lang->Item("description")." :";
513: echo "</td><td align=left>".$groupdesc."</td></tr>";
514: echo "<tr><td align=right>".$NATS->Lang->Item("status")."</td><td align=left>";
515: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
516: echo "</table></td>";
517: //echo "<td align=left valign=top align=right width=60>";
518: //echo "<img src=icons/".GroupIcon($groupid).">";
519: //echo "</td>";
520: echo "</tr>";
521: echo "</table>";
522: }
523: 
524: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="",$jslink=false)
525: {
526: global $NATS;
527: if ($nodedesc=="") $nodedesc="&nbsp;";
528: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid);
529: $al=$NATS->NodeAlertLevel($nodeid);
530: echo "<table class=\"npbig-al".$al."\">";
531: echo "<tr><td align=left valign=top>";
532: echo "<table class=\"nicetable\" width=300>";
533: echo "<tr><td align=right>".$NATS->Lang->Item("node.name")." :";
534: if ($nodename=="") $nodename=$nodeid;
535: echo "</td><td align=left>";
536: if ($jslink) echo "<a href=\"javascript:nodeClick('".$nodeid."');\">";
537: else echo "<a href=node.php?nodeid=".$nodeid.">";
538: echo $nodename."</a></td></tr>";
539: echo "<tr><td align=right>".$NATS->Lang->Item("description")." :";
540: echo "</td><td align=left>".$nodedesc."</td></tr>";
541: echo "<tr><td align=right>".$NATS->Lang->item("status")." :</td><td align=left>";
542: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
543: echo "</table></td>";
544: //echo "<td align=left valign=top align=right width=60>";
545: //echo "<img src=icons/".GroupIcon($groupid).">";
546: //echo "</td>";
547: echo "</tr>";
548: echo "</table>";
549: }
550: 
551: function GetAbsolute($filename="")
552: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY!
553: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://";
554: else $uri="http://";
555: $uri.=$_SERVER['HTTP_HOST'];
556: $uri.=$_SERVER['REQUEST_URI'];
557: $pos=strripos($uri,"/");
558: $rdir=substr($uri,0,$pos+1);
559: return $rdir.$filename;
560: }
561: 
562: 
563: ?>
564: