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