File: 1.10.2a/server/base/screen.inc.php (View as Code)

1: 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]="".$NATS->Lang->Item("homepage").""; 25: $menu[1]="".$NATS->Lang->Item("live.monitor")."   ".$NATS->Lang->Item("configuration")."   "; 26: $menu[1].="".$NATS->Lang->Item("help")."   ".$NATS->Lang->Item("logout").""; 27: $menu[2]=$menu[1]."   Admin"; 28: 29: $menu[3]="".$NATS->Lang->Item("iphone")."   ".$NATS->Lang->Item("homepage").""; 30: /* 31: $pagemenu['main']="Overview   Nodes   "; 32: $pagemenu['main'].="Groups   Views & Reports   "; 33: $pagemenu['main'].="User Options"; 34: */ 35: $pagemenu=array(); 36: $pagemenu['main']=array( 37: array("overview","main.php?mode=overview",$NATS->Lang->Item("overview")), 38: array("nodes","main.php?mode=nodes",$NATS->Lang->Item("nodes")), 39: array("groups","main.php?mode=groups",$NATS->Lang->Item("groups")), 40: array("views","main.php?mode=views",$NATS->Lang->Item("views.reports")), 41: array("pref","pref.php?mode=pref",$NATS->Lang->Item("user.options")), 42: array("admin","admin.php",$NATS->Lang->Item("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.=" "; 55: else $out.=" "; 56: $out.=$opt[2]; 57: if ($mode!=$opt[0]) $out.="  "; 58: else $out.=" "; 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.
";
71: echo "site.enable.interactive != 1

";
72: echo "To resolve this issue your system administrator needs to set the FreeNATS system variable site.enable.interactive to 1.

";
73: $NATS->Stop(); 74: exit(); 75: } 76: if ($menuindex==1) $alertpane=1; // bodge 77: 78: if ( ($menuindex==1) && ($pagemenu=="main") ) $secCheckFirstrun=true; 79: else $secCheckFirstrun=false; // KLUDGE 80: 81: //if ($NATS_Session->userlevel>9) $menuindex=2; // further bodge! 82: echo "FreeNATS: ".$title."\n"; 83: echo "\n"; 84: /* 85: echo "\n"; 88: */ 89: if ($ah!="") echo $ah; 90: echo "\n"; 91: echo "\n"; 92: echo ""; 93: 94: echo "\n"; 95: echo "\n"; 99: echo "\n"; 102: //echo ""; 103: //echo "\n"; 104: echo "
\n"; 96: echo "".$title.""; 97: if ($pagemenu!="") echo "
  ".PageMenu($pagemenu,$pagemenumode)."";
98: echo "
\n"; 100: echo $menu[$menuindex]; 101: echo " 
\n";
105: 106: if ($secCheckFirstrun && ( $NATS->Cfg->Get("site.firstrun.ignore",0) != 1 ) ) 107: { 108: if (file_exists("firstrun.php")) 109: { 110: echo "
"; 111: echo "".$NATS->Lang->Item("sec.firstrun")."
";
112: echo $NATS->Lang->Item("sec.firstrun.text")."
";
113: echo $NATS->Lang->Item("sec.firstrun.ignore")."
";
114: echo "http://www.purplepixie.org/freenats/wiki/Firstrun_Warning"; 115: 116: echo "
";
117: } 118: } 119: 120: 121: if ($alertpane==1) 122: { 123: $alerts=$NATS->GetAlerts(); 124: if (is_array($alerts)) 125: { 126: echo "
"; 127: echo "".$NATS->Lang->Item("nats.alerts")."

";
128: foreach($alerts as $alert) 129: { 130: echo " "; 131: echo "".$alert['nodeid']."
"; 132: } 133: echo "
";
134: echo "
";
135: } 136: } 137: 138: } 139: 140: function Start_Round($title,$width="") 141: { 142: if ($width!="") $w=" width=".$width; 143: else $w=""; 144: echo "\n"; 145: echo "\n"; 146: echo "\n"; 149: echo "\n"; 155: 156: echo "
\n"; 147: echo $title; 148: echo "\n
\n"; 150: } 151: 152: function End_Round() 153: { 154: echo "\n
";
157: } 158: 159: function Screen_Footer($track_if_enabled=true) 160: { 161: global $NATS,$poplist; 162: echo "

\n";
163: //$NATS->Cfg->DumpToScreen(); 164: echo "
"; 165: echo "
"; 166: 167: echo "
FreeNATS; © ".$NATS->Lang->Item("copyright")." 2008-2010 "; 168: echo "PurplePixie Systems"; 169: echo "
"; 170: echo $NATS->Lang->Item("version").": ".$NATS->Version; 171: if ($NATS->Release!="") echo "/".$NATS->Release; 172: echo "  
";
173: 174: //echo "Hello"; 175: echo "
";
176: echo "
";
177: if (ini_get("freenats.rpath")==1) 178: { 179: echo "FreeNATS Virtual Server Powered By rPath LAMP Appliance
";
180: } 181: //echo "This is alpha-test software - we would very much value your "; 182: //echo "feedback
"; 183: $autofeedback=false; 184: if ($track_if_enabled) 185: { 186: $t=$NATS->Cfg->Get("freenats.tracker"); 187: if ( ($t!="") && ($t>0) ) 188: { 189: $autofeedback=true; 190: $usid=$NATS->Cfg->Get("freenats.tracker.usid",""); 191: if ($usid=="") 192: { // generate usid if not already set 193: // usid form XYZ-XYZ-XYZ... 194: $allow="abcdef0123456789"; 195: $allow_len=strlen($allow); 196: mt_srand(microtime()*1000000); 197: $first_set=1; 198: for ($a=0; $a<5; $a++) // blocks 199: { 200: if ($first_set==1) $first_set=0; 201: else $usid.="-"; 202: for ($b=0; $b<10; $b++) 203: { 204: $c=mt_rand(0,$allow_len-1); 205: $usid.=$allow[$c]; 206: } 207: } 208: $NATS->Cfg->Set("freenats.tracker.usid",$usid); 209: } 210: 211: // get some more data 212: $sn=explode("/",$_SERVER['SCRIPT_NAME']); 213: $script=$sn[count($sn)-1]; 214: 215: // show tracking image 216: echo "Version."+p=".$script."&type=ping&usid=".$usid."\" width=1 height=1>\n"; 217: } 218: } 219: 220: //$NATS->PageError("fish","swim in the sea"); 221: //$NATS->PageError("dogs","walk on the land"); 222: //$autofeedback=true; 223: 224: if (count($NATS->PageErrors)>0) // page errors reported 225: { 226: echo "
\n"; 227: echo "Errors detected on page: "; 228: $url=""; 229: $counter=0; 230: foreach($NATS->PageErrors as $PageError) 231: { 232: if ($counter>0) $url.="&"; 233: $url.="code[".$counter."]=".urlencode($PageError['code'])."&desc[".$counter."]=".urlencode($PageError['desc']); 234: $counter++; 235: } 236: 237: echo ""; 246: 247: echo ""; 248: if ($autofeedback) 249: { 250: echo "Reporting..."; 251: } 252: else 253: { 254: echo "Click to report to PurplePixie | "; 255: echo "Click to show/hide details"; 256: } 257: echo ""; 258: echo "
\n"; 259: foreach($NATS->PageErrors as $PageError) 260: { 261: echo "# ".$PageError['code']." : ".$PageError['desc']."
\n";
262: } 263: echo "
";
264: echo "
\n";
265: if ($autofeedback) 266: { 267: //echo "\n"; 268: echo "\n"; 271: } 272: 273: } 274: 275: if ($NATS->Cfg->Get("site.popupmessage")=="1") 276: { 277: if (count($poplist)>0) 278: { 279: echo "\n\n"; 287: } 288: } 289: echo "\n\n"; 290: } 291: 292: function UL_Error($task="") 293: { 294: global $NATS; 295: Screen_Header($NATS->Lang->Item("access.error")); 296: echo "
".$NATS->Lang->Item("access.error.detail")." (".$task.").

";
297: echo "".$NATS->Lang->Item("click.continue")."

";
298: Screen_Footer(); 299: exit(); 300: } 301: 302: function Session_Error() 303: { 304: global $REQUEST_URI; 305: header("Location: ./?login_msg=Invalid+or+Expired+Session&url=".urlencode($REQUEST_URI)); 306: exit(); 307: } 308: 309: function nicedt($ts) 310: { 311: global $NATS; 312: $form="H:i:s d/m/Y"; 313: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y"); 314: if ($ts<=0) return $NATS->Lang->Item("never"); 315: return date($form,$ts); 316: } 317: 318: function enicedt($ts) 319: { 320: echo nicedt($ts); 321: } 322: 323: function nicediff($diff) 324: { 325: $hr=0; 326: $mn=0; 327: $se=0; 328: if ($diff>59) 329: { 330: $mn=round($diff/60,0); 331: $se=$diff%60; 332: if ($mn>59) 333: { 334: $hr=round($mn/60,0); 335: $mn=$mn%60; 336: } 337: } 338: else $se=$diff; 339: $s=""; 340: if ($hr<10) $s="0"; 341: $s.=$hr.":"; 342: if ($mn<10) $s.="0"; 343: $s.=$mn.":"; 344: if ($se<10) $s.="0"; 345: $s.=$se; 346: return $s; 347: } 348: 349: function dtago($ts,$sayago=true) 350: { 351: global $NATS; 352: if ($ts<=0) return $NATS->Lang->Item("never"); 353: $now=time(); 354: $diff=$now-$ts; 355: $s=nicediff($diff); 356: if ($sayago) $s.=" ".$NATS->Lang->Item("ago"); 357: return $s; 358: } 359: 360: function nicenextx($nextx) 361: { 362: if ($nextx<=0) return "Now"; 363: $diff=$nextx-time(); 364: if ($diff<0) 365: { 366: $sign=" ago"; 367: $diff=0-$diff; 368: } 369: else $sign=""; 370: return nicediff($diff).$sign; 371: } 372: 373: function edtago($ts) 374: { 375: echo dtago($ts); 376: } 377: 378: function smartx($x) // smart handling of unixtime x variables 379: { 380: if ($x==0) return time(); // 0 = now 381: else if ($x<0) // -z = now - z seconds 382: return (time()+$x); // negative number so + 383: else // positive number so is a unixtime 384: return $x; 385: } 386: 387: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?$"; 388: 389: function nices($s) 390: { 391: global $allowed; 392: $o=""; 393: for ($a=0; $a394: { 395: $c=$s[$a]; 396: if (strpos($allowed,$c)===false) 397: { 398: // skip it 399: } 400: else $o.=$c; 401: } 402: return $o; 403: } 404: /* // Old Static List Function 405: function ShowIcons() 406: { 407: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup; 408: $c=0; 409: echo ""; 410: $cc=0; 411: for ($a=0; $a412: { 413: if ($cc==0) echo ""; 414: echo ""; 418: $cc++; 419: if ($cc>=5) 420: { 421: echo ""; 422: $cc=0; 423: } 424: } 425: if ($cc>0) echo ""; 426: echo "

".$fnIcons[$a]."
"; 415: if ($a==$fnIcon_DefNode) echo "Node Default "; 416: if ($a==$fnIcon_DefGroup) echo "Group Default"; 417: echo "
";
427: } 428: */ 429: 430: function GetIcons() 431: { 432: $iconFiles=glob("icons/{*.gif,*.GIF,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png,*.PNG}", GLOB_BRACE); 433: for($a=0;$a434: $iconFiles[$a]=substr($iconFiles[$a],6); 435: return $iconFiles; 436: } 437: 438: 439: function ShowIcons() 440: { 441: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup,$NATS; 442: $c=0; 443: echo ""; 444: $cc=0; 445: $iconFiles=GetIcons(); 446: for ($a=0; $a447: { 448: $icon=$iconFiles[$a]; 449: if ($cc==0) echo ""; 450: echo ""; 454: $cc++; 455: if ($cc>=5) 456: { 457: echo ""; 458: $cc=0; 459: } 460: } 461: if ($cc>0) echo ""; 462: echo "

".$icon."
"; 451: if ($icon==$fnIcons[$fnIcon_DefNode]) echo "".$NATS->Lang->Item("node.default")." "; 452: if ($a==$fnIcons[$fnIcon_DefGroup]) echo "".$NATS->Lang->Item("group.default").""; 453: echo "
";
463: } 464: 465: 466: 467: function NodeIcon($nodeid) 468: { 469: global $NATS,$fnIcons,$fnIcon_DefNode; 470: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\""; 471: $r=$NATS->DB->Query($q); 472: if ($row=$NATS->DB->Fetch_Array($r)) 473: { 474: if ($row['nodeicon']!="") return $row['nodeicon']; 475: } 476: return $fnIcons[$fnIcon_DefNode]; 477: } 478: 479: function GroupIcon($groupid) 480: { 481: global $NATS,$fnIcons,$fnIcon_DefGroup; 482: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\""; 483: $r=$NATS->DB->Query($q); 484: if ($row=$NATS->DB->Fetch_Array($r)) 485: { 486: if ($row['groupicon']!="") return $row['groupicon']; 487: } 488: return $fnIcons[$fnIcon_DefGroup]; 489: } 490: 491: function np_tiny($nodeid,$text=true,$nodename="",$jslink=false) 492: { 493: global $NATS; 494: $al=$NATS->NodeAlertLevel($nodeid); 495: echo ""; 496: echo "
"; 497: if ($jslink) echo ""; 498: else echo ""; 499: echo ""; 500: echo ""; 501: if ($text) 502: { 503: if ($nodename=="") $nodename=$nodeid; 504: 505: //$words=explode(" ",$nodename); 506: 507: // messy but there you go... 508: 509: $max_on_line=7; 510: $max_lines=2; 511: $len=strlen($nodename); 512: $out=""; 513: $linecount=0; 514: $charcount=0; 515: for ($a=0; $a<$len; $a++) 516: { 517: 518: $char=$nodename[$a]; 519: 520: if ($char==" ") 521: { 522: $linecount++; 523: $charcount=0; 524: } 525: else $charcount++; 526: 527: if ($charcount>=$max_on_line) 528: { 529: $a=$len+10; 530: $out.=".."; 531: } 532: else if ($linecount>=$max_lines) 533: { 534: $a=$len+10; 535: $out.=".."; 536: } 537: else $out.=$char; 538: 539: } 540: //if ($a==($len+10)) $out.=".."; 541: $nodename=$out; 542: 543: $size=10; 544: 545: /* -- size-based 546: $len=strlen($nodename); 547: if ($len<9) $size=10; 548: else if ($len<15) $size=8; 549: else if ($len<20) $size=7; 550: else 551: { 552: $size=6; 553: $nodename=substr($nodename,0,18).".."; 554: } 555: */ 556: 557: echo "
".$nodename."";
558: } 559: echo "
";
560: } 561: 562: function ng_tiny($groupid,$groupname="",$text=true) 563: { 564: global $NATS; 565: // to do - get groupname if not sent but F--- it for now 566: $al=$NATS->GroupAlertLevel($groupid); 567: echo ""; 568: echo "
"; 569: echo ""; 570: echo ""; 571: echo ""; 572: if ($text) 573: { 574: echo "
".$groupname."";
575: } 576: echo "
";
577: } 578: 579: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="") 580: { 581: global $NATS; 582: if ($groupicon=="") $groupicon=GroupIcon($groupid); 583: $al=$NATS->GroupAlertLevel($groupid); 584: echo ""; 585: echo ""; 594: //echo ""; 597: echo ""; 598: echo "
"; 586: echo ""; 587: echo ""; 589: echo ""; 591: echo ""; 593: echo "
".$NATS->Lang->Item("group.name")." :"; 588: echo "".$groupname."
".$NATS->Lang->Item("description")." :"; 590: echo "".$groupdesc."
".$NATS->Lang->Item("status").""; 592: echo "".oText($al)."
"; 595: //echo ""; 596: //echo "
";
599: } 600: 601: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="",$jslink=false) 602: { 603: global $NATS; 604: if ($nodedesc=="") $nodedesc=" "; 605: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid); 606: $al=$NATS->NodeAlertLevel($nodeid); 607: echo ""; 608: echo ""; 621: //echo ""; 624: echo ""; 625: echo "
"; 609: echo ""; 610: echo ""; 616: echo ""; 618: echo ""; 620: echo "
".$NATS->Lang->Item("node.name")." :"; 611: if ($nodename=="") $nodename=$nodeid; 612: echo ""; 613: if ($jslink) echo ""; 614: else echo ""; 615: echo $nodename."
".$NATS->Lang->Item("description")." :"; 617: echo "".$nodedesc."
".$NATS->Lang->item("status")." :"; 619: echo "".oText($al)."
"; 622: //echo ""; 623: //echo "
";
626: } 627: 628: function GetAbsolute($filename="") 629: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY! 630: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://"; 631: else $uri="http://"; 632: $uri.=$_SERVER['HTTP_HOST']; 633: $uri.=$_SERVER['REQUEST_URI']; 634: $pos=strripos($uri,"/"); 635: $rdir=substr($uri,0,$pos+1); 636: return $rdir.$filename; 637: } 638: 639: 640: ?> 641: