Viewing File server/base/screen.inc.php of 1.02.2a
|
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: $menu[3]="<a href=iphone.php>iPhone Interface</a> <a href=http://www.purplepixie.org/freenats/>FreeNATS Homepage</a>"; 30: 31: $pagemenu['main']="<a href=main.php?mode=overview>Overview</a> <a href=main.php?mode=nodes>Nodes</a> "; 32: $pagemenu['main'].="<a href=main.php?mode=groups>Groups</a> <a href=main.php?mode=views>Views & Reports</a> "; 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","Overview"), 38: array("nodes","main.php?mode=nodes","Nodes"), 39: array("groups","main.php?mode=groups","Groups"), 40: array("views","main.php?mode=views","Views & Reports"), 41: array("pref","pref.php?mode=pref","User Options"), 42: array("admin","admin.php","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.=" <a href=".$opt[1].">"; 55: else $out.="<b style=\"background-color: #ffffff;\"> <a href=\"".$opt[1]."\" style=\"color: black; text-decoration: none;\">"; 56: $out.=$opt[2]; 57: if ($mode!=$opt[0]) $out.="</a> "; 58: else $out.="</a> </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> <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 " </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 Alerts</u></b><br><br>"; 108: foreach($alerts as $alert) 109: { 110: echo " <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>; © Copyright 2008 "; 148: echo "<a href=http://www.purplepixie.org/>PurplePixie Systems</a>"; 149: echo "</div><div class=\"nfootright\">"; 150: echo "Version: ".$NATS->Version; 151: if ($NATS->Release!="") echo "/".$NATS->Release; 152: echo " </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: $sn=explode("/",$_SERVER['SCRIPT_NAME']); 169: $script=$sn[count($sn)-1]; 170: 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"; 171: } 172: } 173: 174: if ($NATS->Cfg->Get("site.popupmessage")=="1") 175: { 176: if (count($poplist)>0) 177: { 178: echo "\n<script type=\"text/javascript\">\n"; 179: 180: foreach($poplist as $pop) 181: { 182: echo "alert('".$pop."');\n"; 183: } 184: 185: echo "</script>\n"; 186: } 187: } 188: echo "\n</body></html>\n"; 189: } 190: 191: function UL_Error($task="") 192: { 193: Screen_Header("Insufficient Access"); 194: echo "<br>Sorry but your user has insufficient access to perform task (".$task.").<br><br>"; 195: echo "<a href=main.php>Please click here to continue.</a><br><br>"; 196: Screen_Footer(); 197: exit(); 198: } 199: 200: function Session_Error() 201: { 202: global $REQUEST_URI; 203: header("Location: ./?login_msg=Invalid+or+Expired+Session&url=".urlencode($REQUEST_URI)); 204: exit(); 205: } 206: 207: function nicedt($ts) 208: { 209: global $NATS; 210: $form="H:i:s d/m/Y"; 211: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y"); 212: if ($ts<=0) return "never"; 213: return date($form,$ts); 214: } 215: 216: function enicedt($ts) 217: { 218: echo nicedt($ts); 219: } 220: 221: function nicediff($diff) 222: { 223: $hr=0; 224: $mn=0; 225: $se=0; 226: if ($diff>59) 227: { 228: $mn=round($diff/60,0); 229: $se=$diff%60; 230: if ($mn>59) 231: { 232: $hr=round($mn/60,0); 233: $mn=$mn%60; 234: } 235: } 236: else $se=$diff; 237: $s=""; 238: if ($hr<10) $s="0"; 239: $s.=$hr.":"; 240: if ($mn<10) $s.="0"; 241: $s.=$mn.":"; 242: if ($se<10) $s.="0"; 243: $s.=$se; 244: return $s; 245: } 246: 247: function dtago($ts,$sayago=true) 248: { 249: if ($ts<=0) return "never"; 250: $now=time(); 251: $diff=$now-$ts; 252: $s=nicediff($diff); 253: if ($sayago) $s.=" ago"; 254: return $s; 255: } 256: 257: function nicenextx($nextx) 258: { 259: if ($nextx<=0) return "Now"; 260: $diff=$nextx-time(); 261: if ($diff<0) 262: { 263: $sign=" ago"; 264: $diff=0-$diff; 265: } 266: else $sign=""; 267: return nicediff($diff).$sign; 268: } 269: 270: function edtago($ts) 271: { 272: echo dtago($ts); 273: } 274: 275: function smartx($x) // smart handling of unixtime x variables 276: { 277: if ($x==0) return time(); // 0 = now 278: else if ($x<0) // -z = now - z seconds 279: return (time()+$x); // negative number so + 280: else // positive number so is a unixtime 281: return $x; 282: } 283: 284: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?"; 285: 286: function nices($s) 287: { 288: global $allowed; 289: $o=""; 290: for ($a=0; $a<strlen($s); $a++) 291: { 292: $c=$s[$a]; 293: if (strpos($allowed,$c)===false) 294: { 295: // skip it 296: } 297: else $o.=$c; 298: } 299: return $o; 300: } 301: /* // Old Static List Function 302: function ShowIcons() 303: { 304: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup; 305: $c=0; 306: echo "<table border=0>"; 307: $cc=0; 308: for ($a=0; $a<count($fnIcons); $a++) 309: { 310: if ($cc==0) echo "<tr>"; 311: echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>"; 312: if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> "; 313: if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>"; 314: echo "</td>"; 315: $cc++; 316: if ($cc>=5) 317: { 318: echo "</tr>"; 319: $cc=0; 320: } 321: } 322: if ($cc>0) echo "</tr>"; 323: echo "</table>"; 324: } 325: */ 326: 327: function GetIcons() 328: { 329: $iconFiles=glob("icons/{*.gif,*.GIF,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png,*.PNG}", GLOB_BRACE); 330: for($a=0;$a<count($iconFiles);$a++) 331: $iconFiles[$a]=substr($iconFiles[$a],6); 332: return $iconFiles; 333: } 334: 335: 336: function ShowIcons() 337: { 338: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup; 339: $c=0; 340: echo "<table border=0>"; 341: $cc=0; 342: $iconFiles=GetIcons(); 343: for ($a=0; $a<count($iconFiles); $a++) 344: { 345: $icon=$iconFiles[$a]; 346: if ($cc==0) echo "<tr>"; 347: echo "<td valign=top align=center><img src=icons/".$icon."><br>".$icon."<br>"; 348: if ($icon==$fnIcons[$fnIcon_DefNode]) echo "<i>Node Default</i> "; 349: if ($a==$fnIcons[$fnIcon_DefGroup]) echo "<i>Group Default</i>"; 350: echo "</td>"; 351: $cc++; 352: if ($cc>=5) 353: { 354: echo "</tr>"; 355: $cc=0; 356: } 357: } 358: if ($cc>0) echo "</tr>"; 359: echo "</table>"; 360: } 361: 362: 363: 364: function NodeIcon($nodeid) 365: { 366: global $NATS,$fnIcons,$fnIcon_DefNode; 367: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\""; 368: $r=$NATS->DB->Query($q); 369: if ($row=$NATS->DB->Fetch_Array($r)) 370: { 371: if ($row['nodeicon']!="") return $row['nodeicon']; 372: } 373: return $fnIcons[$fnIcon_DefNode]; 374: } 375: 376: function GroupIcon($groupid) 377: { 378: global $NATS,$fnIcons,$fnIcon_DefGroup; 379: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\""; 380: $r=$NATS->DB->Query($q); 381: if ($row=$NATS->DB->Fetch_Array($r)) 382: { 383: if ($row['groupicon']!="") return $row['groupicon']; 384: } 385: return $fnIcons[$fnIcon_DefGroup]; 386: } 387: 388: function np_tiny($nodeid,$text=true,$nodename="") 389: { 390: global $NATS; 391: $al=$NATS->NodeAlertLevel($nodeid); 392: echo "<table class=\"nptiny-al".$al."\">"; 393: echo "<tr><td valign=center align=center>"; 394: echo "<a href=node.php?nodeid=".$nodeid.">"; 395: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>"; 396: echo "</a>"; 397: if ($text) 398: { 399: if ($nodename=="") $nodename=$nodeid; 400: 401: //$words=explode(" ",$nodename); 402: 403: // messy but there you go... 404: 405: $max_on_line=7; 406: $max_lines=2; 407: $len=strlen($nodename); 408: $out=""; 409: $linecount=0; 410: $charcount=0; 411: for ($a=0; $a<$len; $a++) 412: { 413: 414: $char=$nodename[$a]; 415: 416: if ($char==" ") 417: { 418: $linecount++; 419: $charcount=0; 420: } 421: else $charcount++; 422: 423: if ($charcount>=$max_on_line) 424: { 425: $a=$len+10; 426: $out.=".."; 427: } 428: else if ($linecount>=$max_lines) 429: { 430: $a=$len+10; 431: $out.=".."; 432: } 433: else $out.=$char; 434: 435: } 436: //if ($a==($len+10)) $out.=".."; 437: $nodename=$out; 438: 439: $size=10; 440: 441: /* -- size-based 442: $len=strlen($nodename); 443: if ($len<9) $size=10; 444: else if ($len<15) $size=8; 445: else if ($len<20) $size=7; 446: else 447: { 448: $size=6; 449: $nodename=substr($nodename,0,18).".."; 450: } 451: */ 452: 453: echo "<br><b class=\"al".$al."\" style=\"font-size: ".$size."pt;\">".$nodename."</b>"; 454: } 455: echo "</td></tr></table>"; 456: } 457: 458: function ng_tiny($groupid,$groupname="",$text=true) 459: { 460: global $NATS; 461: // to do - get groupname if not sent but F--- it for now 462: $al=$NATS->GroupAlertLevel($groupid); 463: echo "<table class=\"nptiny-al".$al."\">"; 464: echo "<tr><td valign=center align=center>"; 465: echo "<a href=group.php?groupid=".$groupid.">"; 466: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>"; 467: echo "</a>"; 468: if ($text) 469: { 470: echo "<br><b class=\"al".$al."\">".$groupname."</b>"; 471: } 472: echo "</td></tr></table>"; 473: } 474: 475: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="") 476: { 477: global $NATS; 478: if ($groupicon=="") $groupicon=GroupIcon($groupid); 479: $al=$NATS->GroupAlertLevel($groupid); 480: echo "<table class=\"npbig-al".$al."\">"; 481: echo "<tr><td align=left valign=top>"; 482: echo "<table class=\"nicetable\" width=300>"; 483: echo "<tr><td align=right>Group Name :"; 484: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>"; 485: echo "<tr><td align=right>Description :"; 486: echo "</td><td align=left>".$groupdesc."</td></tr>"; 487: echo "<tr><td align=right>Status :</td><td align=left>"; 488: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>"; 489: echo "</table></td>"; 490: //echo "<td align=left valign=top align=right width=60>"; 491: //echo "<img src=icons/".GroupIcon($groupid).">"; 492: //echo "</td>"; 493: echo "</tr>"; 494: echo "</table>"; 495: } 496: 497: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="") 498: { 499: global $NATS; 500: if ($nodedesc=="") $nodedesc=" "; 501: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid); 502: $al=$NATS->NodeAlertLevel($nodeid); 503: echo "<table class=\"npbig-al".$al."\">"; 504: echo "<tr><td align=left valign=top>"; 505: echo "<table class=\"nicetable\" width=300>"; 506: echo "<tr><td align=right>Node Name :"; 507: if ($nodename=="") $nodename=$nodeid; 508: echo "</td><td align=left><a href=node.php?nodeid=".$nodeid.">".$nodename."</a></td></tr>"; 509: echo "<tr><td align=right>Description :"; 510: echo "</td><td align=left>".$nodedesc."</td></tr>"; 511: echo "<tr><td align=right>Status :</td><td align=left>"; 512: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>"; 513: echo "</table></td>"; 514: //echo "<td align=left valign=top align=right width=60>"; 515: //echo "<img src=icons/".GroupIcon($groupid).">"; 516: //echo "</td>"; 517: echo "</tr>"; 518: echo "</table>"; 519: } 520: 521: function GetAbsolute($filename="") 522: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY! 523: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://"; 524: else $uri="http://"; 525: $uri.=$_SERVER['HTTP_HOST']; 526: $uri.=$_SERVER['REQUEST_URI']; 527: $pos=strripos($uri,"/"); 528: $rdir=substr($uri,0,$pos+1); 529: return $rdir.$filename; 530: } 531: 532: 533: ?>