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