Viewing File server/base/screen.inc.php of 1.01.8a
|
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 nicedt($ts) 201: { 202: global $NATS; 203: $form="H:i:s d/m/Y"; 204: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y"); 205: if ($ts<=0) return "never"; 206: return date($form,$ts); 207: } 208: 209: function enicedt($ts) 210: { 211: echo nicedt($ts); 212: } 213: 214: function nicediff($diff) 215: { 216: $hr=0; 217: $mn=0; 218: $se=0; 219: if ($diff>59) 220: { 221: $mn=round($diff/60,0); 222: $se=$diff%60; 223: if ($mn>59) 224: { 225: $hr=round($mn/60,0); 226: $mn=$mn%60; 227: } 228: } 229: else $se=$diff; 230: $s=""; 231: if ($hr<10) $s="0"; 232: $s.=$hr.":"; 233: if ($mn<10) $s.="0"; 234: $s.=$mn.":"; 235: if ($se<10) $s.="0"; 236: $s.=$se; 237: return $s; 238: } 239: 240: function dtago($ts,$sayago=true) 241: { 242: if ($ts<=0) return "never"; 243: $now=time(); 244: $diff=$now-$ts; 245: $s=nicediff($diff); 246: if ($sayago) $s.=" ago"; 247: return $s; 248: } 249: 250: function nicenextx($nextx) 251: { 252: if ($nextx<=0) return "Now"; 253: $diff=$nextx-time(); 254: if ($diff<0) 255: { 256: $sign=" ago"; 257: $diff=0-$diff; 258: } 259: else $sign=""; 260: return nicediff($diff).$sign; 261: } 262: 263: function edtago($ts) 264: { 265: echo dtago($ts); 266: } 267: 268: function smartx($x) // smart handling of unixtime x variables 269: { 270: if ($x==0) return time(); // 0 = now 271: else if ($x<0) // -z = now - z seconds 272: return (time()+$x); // negative number so + 273: else // positive number so is a unixtime 274: return $x; 275: } 276: 277: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?"; 278: 279: function nices($s) 280: { 281: global $allowed; 282: $o=""; 283: for ($a=0; $a<strlen($s); $a++) 284: { 285: $c=$s[$a]; 286: if (strpos($allowed,$c)===false) 287: { 288: // skip it 289: } 290: else $o.=$c; 291: } 292: return $o; 293: } 294: 295: function ShowIcons() 296: { 297: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup; 298: $c=0; 299: echo "<table border=0>"; 300: $cc=0; 301: for ($a=0; $a<count($fnIcons); $a++) 302: { 303: if ($cc==0) echo "<tr>"; 304: echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>"; 305: if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> "; 306: if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>"; 307: echo "</td>"; 308: $cc++; 309: if ($cc>=5) 310: { 311: echo "</tr>"; 312: $cc=0; 313: } 314: } 315: if ($cc>0) echo "</tr>"; 316: echo "</table>"; 317: } 318: 319: 320: function NodeIcon($nodeid) 321: { 322: global $NATS,$fnIcons,$fnIcon_DefNode; 323: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\""; 324: $r=$NATS->DB->Query($q); 325: if ($row=$NATS->DB->Fetch_Array($r)) 326: { 327: if ($row['nodeicon']!="") return $row['nodeicon']; 328: } 329: return $fnIcons[$fnIcon_DefNode]; 330: } 331: 332: function GroupIcon($groupid) 333: { 334: global $NATS,$fnIcons,$fnIcon_DefGroup; 335: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\""; 336: $r=$NATS->DB->Query($q); 337: if ($row=$NATS->DB->Fetch_Array($r)) 338: { 339: if ($row['groupicon']!="") return $row['groupicon']; 340: } 341: return $fnIcons[$fnIcon_DefGroup]; 342: } 343: 344: function np_tiny($nodeid,$text=true,$nodename="") 345: { 346: global $NATS; 347: $al=$NATS->NodeAlertLevel($nodeid); 348: echo "<table class=\"nptiny-al".$al."\">"; 349: echo "<tr><td valign=center align=center>"; 350: echo "<a href=node.php?nodeid=".$nodeid.">"; 351: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>"; 352: echo "</a>"; 353: if ($text) 354: { 355: if ($nodename=="") $nodename=$nodeid; 356: 357: //$words=explode(" ",$nodename); 358: 359: // messy but there you go... 360: 361: $max_on_line=7; 362: $max_lines=2; 363: $len=strlen($nodename); 364: $out=""; 365: $linecount=0; 366: $charcount=0; 367: for ($a=0; $a<$len; $a++) 368: { 369: 370: $char=$nodename[$a]; 371: 372: if ($char==" ") 373: { 374: $linecount++; 375: $charcount=0; 376: } 377: else $charcount++; 378: 379: if ($charcount>=$max_on_line) 380: { 381: $a=$len+10; 382: $out.=".."; 383: } 384: else if ($linecount>=$max_lines) 385: { 386: $a=$len+10; 387: $out.=".."; 388: } 389: else $out.=$char; 390: 391: } 392: //if ($a==($len+10)) $out.=".."; 393: $nodename=$out; 394: 395: $size=10; 396: 397: /* -- size-based 398: $len=strlen($nodename); 399: if ($len<9) $size=10; 400: else if ($len<15) $size=8; 401: else if ($len<20) $size=7; 402: else 403: { 404: $size=6; 405: $nodename=substr($nodename,0,18).".."; 406: } 407: */ 408: 409: echo "<br><b class=\"al".$al."\" style=\"font-size: ".$size."pt;\">".$nodename."</b>"; 410: } 411: echo "</td></tr></table>"; 412: } 413: 414: function ng_tiny($groupid,$groupname="",$text=true) 415: { 416: global $NATS; 417: // to do - get groupname if not sent but F--- it for now 418: $al=$NATS->GroupAlertLevel($groupid); 419: echo "<table class=\"nptiny-al".$al."\">"; 420: echo "<tr><td valign=center align=center>"; 421: echo "<a href=group.php?groupid=".$groupid.">"; 422: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>"; 423: echo "</a>"; 424: if ($text) 425: { 426: echo "<br><b class=\"al".$al."\">".$groupname."</b>"; 427: } 428: echo "</td></tr></table>"; 429: } 430: 431: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="") 432: { 433: global $NATS; 434: if ($groupicon=="") $groupicon=GroupIcon($groupid); 435: $al=$NATS->GroupAlertLevel($groupid); 436: echo "<table class=\"npbig-al".$al."\">"; 437: echo "<tr><td align=left valign=top>"; 438: echo "<table class=\"nicetable\" width=300>"; 439: echo "<tr><td align=right>Group Name :"; 440: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>"; 441: echo "<tr><td align=right>Description :"; 442: echo "</td><td align=left>".$groupdesc."</td></tr>"; 443: echo "<tr><td align=right>Status :</td><td align=left>"; 444: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>"; 445: echo "</table></td>"; 446: //echo "<td align=left valign=top align=right width=60>"; 447: //echo "<img src=icons/".GroupIcon($groupid).">"; 448: //echo "</td>"; 449: echo "</tr>"; 450: echo "</table>"; 451: } 452: 453: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="") 454: { 455: global $NATS; 456: if ($nodedesc=="") $nodedesc=" "; 457: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid); 458: $al=$NATS->NodeAlertLevel($nodeid); 459: echo "<table class=\"npbig-al".$al."\">"; 460: echo "<tr><td align=left valign=top>"; 461: echo "<table class=\"nicetable\" width=300>"; 462: echo "<tr><td align=right>Node Name :"; 463: if ($nodename=="") $nodename=$nodeid; 464: echo "</td><td align=left><a href=node.php?nodeid=".$nodeid.">".$nodename."</a></td></tr>"; 465: echo "<tr><td align=right>Description :"; 466: echo "</td><td align=left>".$nodedesc."</td></tr>"; 467: echo "<tr><td align=right>Status :</td><td align=left>"; 468: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>"; 469: echo "</table></td>"; 470: //echo "<td align=left valign=top align=right width=60>"; 471: //echo "<img src=icons/".GroupIcon($groupid).">"; 472: //echo "</td>"; 473: echo "</tr>"; 474: echo "</table>"; 475: } 476: 477: function GetAbsolute($filename="") 478: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY! 479: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://"; 480: else $uri="http://"; 481: $uri.=$_SERVER['HTTP_HOST']; 482: $uri.=$_SERVER['REQUEST_URI']; 483: $pos=strripos($uri,"/"); 484: $rdir=substr($uri,0,$pos+1); 485: return $rdir.$filename; 486: } 487: 488: 489: ?>