Viewing File server/base/screen.inc.php of 0.02.60a
|
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 " <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: 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>; © 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 UL_Error($task="") 123: { 124: Screen_Header("Insufficient Access"); 125: echo "<br>Sorry but your user has insufficient access to perform task (".$task.").<br><br>"; 126: echo "<a href=main.php>Please click here to continue.</a><br><br>"; 127: Screen_Footer(); 128: exit(); 129: } 130: 131: function nicedt($ts) 132: { 133: if ($ts<=0) return "never"; 134: return date("H:i:s d/m/Y",$ts); 135: } 136: 137: function enicedt($ts) 138: { 139: echo nicedt($ts); 140: } 141: 142: function nicediff($diff) 143: { 144: $hr=0; 145: $mn=0; 146: $se=0; 147: if ($diff>59) 148: { 149: $mn=round($diff/60,0); 150: $se=$diff%60; 151: if ($mn>59) 152: { 153: $hr=round($mn/60,0); 154: $mn=$mn%60; 155: } 156: } 157: else $se=$diff; 158: $s=""; 159: if ($hr<10) $s="0"; 160: $s.=$hr.":"; 161: if ($mn<10) $s.="0"; 162: $s.=$mn.":"; 163: if ($se<10) $s.="0"; 164: $s.=$se; 165: return $s; 166: } 167: 168: function dtago($ts) 169: { 170: if ($ts<=0) return "never"; 171: $now=time(); 172: $diff=$now-$ts; 173: $s=nicediff($diff); 174: $s.=" ago"; 175: return $s; 176: } 177: 178: function edtago($ts) 179: { 180: echo dtago($ts); 181: } 182: 183: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?"; 184: 185: function nices($s) 186: { 187: global $allowed; 188: $o=""; 189: for ($a=0; $a<strlen($s); $a++) 190: { 191: $c=$s[$a]; 192: if (strpos($allowed,$c)===false) 193: { 194: // skip it 195: } 196: else $o.=$c; 197: } 198: return $o; 199: } 200: 201: function ShowIcons() 202: { 203: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup; 204: $c=0; 205: echo "<table border=0>"; 206: $cc=0; 207: for ($a=0; $a<count($fnIcons); $a++) 208: { 209: if ($cc==0) echo "<tr>"; 210: echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>"; 211: if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> "; 212: if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>"; 213: echo "</td>"; 214: $cc++; 215: if ($cc>=5) 216: { 217: echo "</tr>"; 218: $cc=0; 219: } 220: } 221: if ($cc>0) echo "</tr>"; 222: echo "</table>"; 223: } 224: 225: 226: function NodeIcon($nodeid) 227: { 228: global $NATS,$fnIcons,$fnIcon_DefNode; 229: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\""; 230: $r=$NATS->DB->Query($q); 231: if ($row=$NATS->DB->Fetch_Array($r)) 232: { 233: if ($row['nodeicon']!="") return $row['nodeicon']; 234: } 235: return $fnIcons[$fnIcon_DefNode]; 236: } 237: 238: function GroupIcon($groupid) 239: { 240: global $NATS,$fnIcons,$fnIcon_DefGroup; 241: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\""; 242: $r=$NATS->DB->Query($q); 243: if ($row=$NATS->DB->Fetch_Array($r)) 244: { 245: if ($row['groupicon']!="") return $row['groupicon']; 246: } 247: return $fnIcons[$fnIcon_DefGroup]; 248: } 249: 250: function np_tiny($nodeid,$text=true) 251: { 252: global $NATS; 253: $al=$NATS->NodeAlertLevel($nodeid); 254: echo "<table class=\"nptiny-al".$al."\">"; 255: echo "<tr><td valign=center align=center>"; 256: echo "<a href=node.php?nodeid=".$nodeid.">"; 257: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>"; 258: echo "</a>"; 259: if ($text) 260: { 261: echo "<br><b class=\"al".$al."\">".$nodeid."</b>"; 262: } 263: echo "</td></tr></table>"; 264: } 265: 266: function ng_tiny($groupid,$groupname="",$text=true) 267: { 268: global $NATS; 269: // to do - get groupname if not sent but F--- it for now 270: $al=$NATS->GroupAlertLevel($groupid); 271: echo "<table class=\"nptiny-al".$al."\">"; 272: echo "<tr><td valign=center align=center>"; 273: echo "<a href=group.php?groupid=".$groupid.">"; 274: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>"; 275: echo "</a>"; 276: if ($text) 277: { 278: echo "<br><b class=\"al".$al."\">".$groupname."</b>"; 279: } 280: echo "</td></tr></table>"; 281: } 282: 283: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="") 284: { 285: global $NATS; 286: if ($groupicon=="") $groupicon=GroupIcon($groupid); 287: $al=$NATS->GroupAlertLevel($groupid); 288: echo "<table class=\"npbig-al".$al."\">"; 289: echo "<tr><td align=left valign=top>"; 290: echo "<table class=\"nicetable\" width=300>"; 291: echo "<tr><td align=right>Group Name :"; 292: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>"; 293: echo "<tr><td align=right>Description :"; 294: echo "</td><td align=left>".$groupdesc."</td></tr>"; 295: echo "<tr><td align=right>Status :</td><td align=left>"; 296: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>"; 297: echo "</table></td>"; 298: //echo "<td align=left valign=top align=right width=60>"; 299: //echo "<img src=icons/".GroupIcon($groupid).">"; 300: //echo "</td>"; 301: echo "</tr>"; 302: echo "</table>"; 303: } 304: 305: function GetAbsolute($filename="") 306: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY! 307: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://"; 308: else $uri="http://"; 309: $uri.=$_SERVER['HTTP_HOST']; 310: $uri.=$_SERVER['REQUEST_URI']; 311: $pos=strripos($uri,"/"); 312: $rdir=substr($uri,0,$pos+1); 313: return $rdir.$filename; 314: } 315: 316: 317: ?>