File: 0.02.36a/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> | <a href=logout.php>Logout</a>";
 26: $menu[2]=$menu[1]." | <a href=admin.php>Administrator</a>";
 27: 
 28: $poplist=array();
 29: 
 30: function Screen_Header($title,$menuindex=0,$alertpane=0,$ah="")
 31: {
 32: global $menu,$NATS,$NATS_Session;
 33: if ($NATS->Cfg->Get("site.enable.interactive")!=1)
 34: 	{
 35: 	echo "Sorry but FreeNATS interactive is disabled.<br>";
 36: 	echo "<i>site.enable.interactive</i> != 1<br><br>";
 37: 	$NATS->Stop();
 38: 	exit();
 39: 	}
 40: if ($menuindex==1) $alertpane=1; // bodge
 41: if ($NATS_Session->userlevel>9) $menuindex=2; // further bodge!
 42: echo "<html><head><title>FreeNATS: ".$title."</title>\n";
 43: echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\">\n";
 44: if ($ah!="") echo $ah;
 45: echo "</head>\n";
 46: echo "<script type=\"text/javascript\" src=\"js/freenats.js\"></script>\n";
 47: echo "<body>";
 48: 
 49: echo "<table width=100% class=\"maintitle\">\n";
 50: echo "<tr><td align=left valign=center>\n";
 51: echo "<b class=\"maintitle\">FreeNATS: ".$title."</b></td>\n";
 52: echo "<td class=\"titlelink\" align=right valign=center>\n";
 53: echo $menu[$menuindex];
 54: echo "</td></tr></table>\n";
 55: 
 56: if ($alertpane==1)
 57: 	{
 58: 	$alerts=$NATS->GetAlerts();
 59: 	if (is_array($alerts))
 60: 		{
 61: 		echo "<div class=\"alertpane\" id=\"fn_alertpane\">";
 62: 		echo "<b><u>NATS Alerts</u></b><br><br>";
 63: 		foreach($alerts as $alert)
 64: 			{
 65: 			echo "&nbsp;<a href=node.php?nodeid=".$alert['nodeid'].">";
 66: 			echo "<b class=\"al".$alert['alertlevel']."\">".$alert['nodeid']."</b></a><br>";
 67: 			}
 68: 		echo "<br>";
 69: 		echo "</div>";
 70: 		}
 71: 	}
 72: 
 73: }
 74: 
 75: function Screen_Footer()
 76: {
 77: global $NATS,$poplist;
 78: echo "<br><br>\n";
 79: //$NATS->Cfg->DumpToScreen();
 80: echo "<table class=\"nfooter\" width=100%>";
 81: echo "<tr><td align=left><a href=http://www.purplepixie.org/freenats/>FreeNATS</a>; &copy; Copyright 2008 ";
 82: echo "<a href=http://www.purplepixie.org/>PurplePixie Systems</a>";
 83: echo "</td><td align=right>";
 84: echo "Version: ".$NATS->Version;
 85: if ($NATS->Release!="") echo "/".$NATS->Release;
 86: echo "</td></tr>";
 87: echo "</table>";
 88: echo "</div>";
 89: if (ini_get("freenats.rpath")==1)
 90: 	{
 91: 	echo "<i>FreeNATS Virtual Server Powered By <a href=http://www.rpath.org/>rPath</a> LAMP Appliance</i><br>";
 92: 	}
 93: echo "<i>This is alpha-test software - we would very much value your ";
 94: echo "<a href=http://www.purplepixie.org/freenats/feedback.php>feedback</a></i><br>";
 95: 
 96: if ($NATS->Cfg->Get("site.popupmessage")=="1")
 97: 	{
 98: 	if (count($poplist)>0)
 99: 		{
100: 		echo "\n<script type=\"text/javascript\">\n";
101: 		
102: 		foreach($poplist as $pop)
103: 			{
104: 			echo "alert('".$pop."');\n";
105: 			}
106: 			
107: 		echo "</script>\n";
108: 		}
109: 	}
110: echo "\n</body></html>\n";
111: }
112: 
113: function UL_Error($task="")
114: {
115: Screen_Header("Insufficient Access");
116: echo "<br>Sorry but your user has insufficient access to perform task (".$task.").<br><br>";
117: echo "<a href=main.php>Please click here to continue.</a><br><br>";
118: Screen_Footer();
119: exit();
120: }
121: 
122: function nicedt($ts)
123: {
124: if ($ts<=0) return "never";
125: return date("H:i:s d/m/Y",$ts);
126: }
127: 
128: function enicedt($ts)
129: {
130: echo nicedt($ts);
131: }
132: 
133: function nicediff($diff)
134: {
135: $hr=0;
136: $mn=0;
137: $se=0;
138: if ($diff>59)
139: 	{
140: 	$mn=round($diff/60,0);
141: 	$se=$diff%60;
142: 	if ($mn>59)
143: 		{
144: 		$hr=round($mn/60,0);
145: 		$mn=$mn%60;
146: 		}
147: 	}
148: else $se=$diff;
149: $s="";
150: if ($hr<10) $s="0";
151: $s.=$hr.":";
152: if ($mn<10) $s.="0";
153: $s.=$mn.":";
154: if ($se<10) $s.="0";
155: $s.=$se;
156: return $s;
157: }
158: 
159: function dtago($ts)
160: {
161: if ($ts<=0) return "never";
162: $now=time();
163: $diff=$now-$ts;
164: $s=nicediff($diff);
165: $s.=" ago";
166: return $s;
167: }
168: 
169: function edtago($ts)
170: {
171: echo dtago($ts);
172: }
173: 
174: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,";
175: 
176: function nices($s)
177: {
178: global $allowed;
179: $o="";
180: for ($a=0; $a<strlen($s); $a++)
181: 	{
182: 	$c=$s[$a];
183: 	if (strpos($allowed,$c)===false)
184: 		{
185: 		// skip it
186: 		}
187: 	else $o.=$c;
188: 	}
189: return $o;
190: }
191: 
192: function ShowIcons()
193: {
194: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
195: $c=0;
196: echo "<table border=0>";
197: $cc=0;
198: for ($a=0; $a<count($fnIcons); $a++)
199: 	{
200: 	if ($cc==0) echo "<tr>";
201: 	echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>";
202: 	if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> ";
203: 	if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>";
204: 	echo "</td>";
205: 	$cc++;
206: 	if ($cc>=5)
207: 		{
208: 		echo "</tr>";
209: 		$cc=0;
210: 		}
211: 	}
212: if ($cc>0) echo "</tr>";
213: echo "</table>";
214: }
215: 
216: 
217: function NodeIcon($nodeid)
218: {
219: global $NATS,$fnIcons,$fnIcon_DefNode;
220: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\"";
221: $r=$NATS->DB->Query($q);
222: if ($row=$NATS->DB->Fetch_Array($r)) 
223: 	{
224: 	if ($row['nodeicon']!="") return $row['nodeicon'];
225: 	}
226: return $fnIcons[$fnIcon_DefNode];
227: }
228: 
229: function GroupIcon($groupid)
230: {
231: global $NATS,$fnIcons,$fnIcon_DefGroup;
232: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\"";
233: $r=$NATS->DB->Query($q);
234: if ($row=$NATS->DB->Fetch_Array($r)) 
235: 	{
236: 	if ($row['groupicon']!="") return $row['groupicon'];
237: 	}
238: return $fnIcons[$fnIcon_DefGroup];
239: }
240: 
241: function np_tiny($nodeid,$text=true)
242: {
243: global $NATS;
244: $al=$NATS->NodeAlertLevel($nodeid);
245: echo "<table class=\"nptiny-al".$al."\">";
246: echo "<tr><td valign=center align=center>";
247: echo "<a href=node.php?nodeid=".$nodeid.">";
248: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>";
249: echo "</a>";
250: if ($text)
251: 	{
252: 	echo "<br><b class=\"al".$al."\">".$nodeid."</b>";
253: 	}
254: echo "</td></tr></table>";
255: }
256: 
257: function ng_tiny($groupid,$groupname="",$text=true)
258: {
259: global $NATS;
260: // to do - get groupname if not sent but F--- it for now
261: $al=$NATS->GroupAlertLevel($groupid);
262: echo "<table class=\"nptiny-al".$al."\">";
263: echo "<tr><td valign=center align=center>";
264: echo "<a href=group.php?groupid=".$groupid.">";
265: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>";
266: echo "</a>";
267: if ($text)
268: 	{
269: 	echo "<br><b class=\"al".$al."\">".$groupname."</b>";
270: 	}
271: echo "</td></tr></table>";
272: }
273: 
274: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="")
275: {
276: global $NATS;
277: if ($groupicon=="") $groupicon=GroupIcon($groupid);
278: $al=$NATS->GroupAlertLevel($groupid);
279: echo "<table class=\"npbig-al".$al."\">";
280: echo "<tr><td align=left valign=top>";
281: echo "<table class=\"nicetable\" width=300>";
282: echo "<tr><td align=right>Group Name :";
283: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>";
284: echo "<tr><td align=right>Description :";
285: echo "</td><td align=left>".$groupdesc."</td></tr>";
286: echo "<tr><td align=right>Status :</td><td align=left>";
287: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
288: echo "</table></td>";
289: //echo "<td align=left valign=top align=right width=60>";
290: //echo "<img src=icons/".GroupIcon($groupid).">";
291: //echo "</td>";
292: echo "</tr>";
293: echo "</table>";
294: }
295: 
296: 
297: 
298: 
299: ?>