Viewing File server/base/screen.inc.php of 0.04.04a
|
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: global $NATS; 134: $form="H:i:s d/m/Y"; 135: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y"); 136: if ($ts<=0) return "never"; 137: return date($form,$ts); 138: } 139: 140: function enicedt($ts) 141: { 142: echo nicedt($ts); 143: } 144: 145: function nicediff($diff) 146: { 147: $hr=0; 148: $mn=0; 149: $se=0; 150: if ($diff>59) 151: { 152: $mn=round($diff/60,0); 153: $se=$diff%60; 154: if ($mn>59) 155: { 156: $hr=round($mn/60,0); 157: $mn=$mn%60; 158: } 159: } 160: else $se=$diff; 161: $s=""; 162: if ($hr<10) $s="0"; 163: $s.=$hr.":"; 164: if ($mn<10) $s.="0"; 165: $s.=$mn.":"; 166: if ($se<10) $s.="0"; 167: $s.=$se; 168: return $s; 169: } 170: 171: function dtago($ts) 172: { 173: if ($ts<=0) return "never"; 174: $now=time(); 175: $diff=$now-$ts; 176: $s=nicediff($diff); 177: $s.=" ago"; 178: return $s; 179: } 180: 181: function edtago($ts) 182: { 183: echo dtago($ts); 184: } 185: 186: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?"; 187: 188: function nices($s) 189: { 190: global $allowed; 191: $o=""; 192: for ($a=0; $a<strlen($s); $a++) 193: { 194: $c=$s[$a]; 195: if (strpos($allowed,$c)===false) 196: { 197: // skip it 198: } 199: else $o.=$c; 200: } 201: return $o; 202: } 203: 204: function ShowIcons() 205: { 206: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup; 207: $c=0; 208: echo "<table border=0>"; 209: $cc=0; 210: for ($a=0; $a<count($fnIcons); $a++) 211: { 212: if ($cc==0) echo "<tr>"; 213: echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>"; 214: if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> "; 215: if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>"; 216: echo "</td>"; 217: $cc++; 218: if ($cc>=5) 219: { 220: echo "</tr>"; 221: $cc=0; 222: } 223: } 224: if ($cc>0) echo "</tr>"; 225: echo "</table>"; 226: } 227: 228: 229: function NodeIcon($nodeid) 230: { 231: global $NATS,$fnIcons,$fnIcon_DefNode; 232: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\""; 233: $r=$NATS->DB->Query($q); 234: if ($row=$NATS->DB->Fetch_Array($r)) 235: { 236: if ($row['nodeicon']!="") return $row['nodeicon']; 237: } 238: return $fnIcons[$fnIcon_DefNode]; 239: } 240: 241: function GroupIcon($groupid) 242: { 243: global $NATS,$fnIcons,$fnIcon_DefGroup; 244: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\""; 245: $r=$NATS->DB->Query($q); 246: if ($row=$NATS->DB->Fetch_Array($r)) 247: { 248: if ($row['groupicon']!="") return $row['groupicon']; 249: } 250: return $fnIcons[$fnIcon_DefGroup]; 251: } 252: 253: function np_tiny($nodeid,$text=true,$nodename="") 254: { 255: global $NATS; 256: $al=$NATS->NodeAlertLevel($nodeid); 257: echo "<table class=\"nptiny-al".$al."\">"; 258: echo "<tr><td valign=center align=center>"; 259: echo "<a href=node.php?nodeid=".$nodeid.">"; 260: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>"; 261: echo "</a>"; 262: if ($text) 263: { 264: if ($nodename=="") $nodename=$nodeid; 265: 266: //$words=explode(" ",$nodename); 267: 268: // messy but there you go... 269: 270: $max_on_line=7; 271: $max_lines=2; 272: $len=strlen($nodename); 273: $out=""; 274: $linecount=0; 275: $charcount=0; 276: for ($a=0; $a<$len; $a++) 277: { 278: 279: $char=$nodename[$a]; 280: 281: if ($char==" ") 282: { 283: $linecount++; 284: $charcount=0; 285: } 286: else $charcount++; 287: 288: if ($charcount>=$max_on_line) 289: { 290: $a=$len+10; 291: $out.=".."; 292: } 293: else if ($linecount>=$max_lines) 294: { 295: $a=$len+10; 296: $out.=".."; 297: } 298: else $out.=$char; 299: 300: } 301: //if ($a==($len+10)) $out.=".."; 302: $nodename=$out; 303: 304: $size=10; 305: 306: /* -- size-based 307: $len=strlen($nodename); 308: if ($len<9) $size=10; 309: else if ($len<15) $size=8; 310: else if ($len<20) $size=7; 311: else 312: { 313: $size=6; 314: $nodename=substr($nodename,0,18).".."; 315: } 316: */ 317: 318: echo "<br><b class=\"al".$al."\" style=\"font-size: ".$size."pt;\">".$nodename."</b>"; 319: } 320: echo "</td></tr></table>"; 321: } 322: 323: function ng_tiny($groupid,$groupname="",$text=true) 324: { 325: global $NATS; 326: // to do - get groupname if not sent but F--- it for now 327: $al=$NATS->GroupAlertLevel($groupid); 328: echo "<table class=\"nptiny-al".$al."\">"; 329: echo "<tr><td valign=center align=center>"; 330: echo "<a href=group.php?groupid=".$groupid.">"; 331: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>"; 332: echo "</a>"; 333: if ($text) 334: { 335: echo "<br><b class=\"al".$al."\">".$groupname."</b>"; 336: } 337: echo "</td></tr></table>"; 338: } 339: 340: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="") 341: { 342: global $NATS; 343: if ($groupicon=="") $groupicon=GroupIcon($groupid); 344: $al=$NATS->GroupAlertLevel($groupid); 345: echo "<table class=\"npbig-al".$al."\">"; 346: echo "<tr><td align=left valign=top>"; 347: echo "<table class=\"nicetable\" width=300>"; 348: echo "<tr><td align=right>Group Name :"; 349: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>"; 350: echo "<tr><td align=right>Description :"; 351: echo "</td><td align=left>".$groupdesc."</td></tr>"; 352: echo "<tr><td align=right>Status :</td><td align=left>"; 353: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>"; 354: echo "</table></td>"; 355: //echo "<td align=left valign=top align=right width=60>"; 356: //echo "<img src=icons/".GroupIcon($groupid).">"; 357: //echo "</td>"; 358: echo "</tr>"; 359: echo "</table>"; 360: } 361: 362: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="") 363: { 364: global $NATS; 365: if ($nodedesc=="") $nodedesc=" "; 366: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid); 367: $al=$NATS->NodeAlertLevel($nodeid); 368: echo "<table class=\"npbig-al".$al."\">"; 369: echo "<tr><td align=left valign=top>"; 370: echo "<table class=\"nicetable\" width=300>"; 371: echo "<tr><td align=right>Node Name :"; 372: if ($nodename=="") $nodename=$nodeid; 373: echo "</td><td align=left><a href=node.php?nodeid=".$nodeid.">".$nodename."</a></td></tr>"; 374: echo "<tr><td align=right>Description :"; 375: echo "</td><td align=left>".$nodedesc."</td></tr>"; 376: echo "<tr><td align=right>Status :</td><td align=left>"; 377: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>"; 378: echo "</table></td>"; 379: //echo "<td align=left valign=top align=right width=60>"; 380: //echo "<img src=icons/".GroupIcon($groupid).">"; 381: //echo "</td>"; 382: echo "</tr>"; 383: echo "</table>"; 384: } 385: 386: function GetAbsolute($filename="") 387: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY! 388: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://"; 389: else $uri="http://"; 390: $uri.=$_SERVER['HTTP_HOST']; 391: $uri.=$_SERVER['REQUEST_URI']; 392: $pos=strripos($uri,"/"); 393: $rdir=substr($uri,0,$pos+1); 394: return $rdir.$filename; 395: } 396: 397: 398: ?>