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

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008-2017 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: 37: 38: $pagemenu['main']=array( 39: array("overview","main.php?mode=overview",$NATS->Lang->Item("overview"), false), 40: array("nodes","main.php?mode=nodes",$NATS->Lang->Item("nodes"), true), 41: array("groups","main.php?mode=groups",$NATS->Lang->Item("groups"), true), 42: array("views","main.php?mode=views",$NATS->Lang->Item("views.reports"), false), 43: array("pref","pref.php?mode=pref",$NATS->Lang->Item("user.options"), true), 44: array("admin","admin.php",$NATS->Lang->Item("system.settings"),false) ); 45: 46: 47: function PageMenu($name,$mode="") 48: { 49: global $pagemenu,$NATS_Session,$NATS; 50: $restrict = $NATS->isUserRestricted($NATS_Session->username); 51: if (($mode=="")&&isset($_REQUEST['mode'])) $mode=$_REQUEST['mode']; 52: $out=""; 53: $first=true; 54: foreach($pagemenu[$name] as $opt) 55: { 56: if (!$restrict || $opt[3]==true) 57: { 58: if ($first) $first=false; 59: else $out.=" "; 60: if ($mode!=$opt[0]) $out.=" "; 61: else $out.=" "; 62: $out.=$opt[2]; 63: if ($mode!=$opt[0]) $out.="  "; 64: else $out.=" "; 65: } 66: } 67: return $out; 68: } 69: 70: $poplist=array(); 71: 72: function Screen_Header($title,$menuindex=0,$alertpane=0,$ah="",$pagemenu="",$pagemenumode="") 73: { 74: global $menu,$NATS,$NATS_Session; 75: if ($NATS->Cfg->Get("site.enable.interactive")!=1) 76: { 77: echo "Sorry but FreeNATS interactive is disabled.
";
78: echo "site.enable.interactive != 1

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

";
80: $NATS->Stop(); 81: exit(); 82: } 83: if ($menuindex==1) $alertpane=1; // bodge 84: 85: if ( ($menuindex==1) && ($pagemenu=="main") ) $secCheckFirstrun=true; 86: else $secCheckFirstrun=false; // KLUDGE 87: 88: //if ($NATS_Session->userlevel>9) $menuindex=2; // further bodge! 89: echo ""; 90: echo "FreeNATS: ".$title."\n"; 91: echo "\n"; 92: echo "\n"; 93: /* 94: echo "\n"; 97: */ 98: if ($ah!="") echo $ah; 99: echo "\n"; 100: echo "\n"; 101: 102: echo ""; 103: 104: echo "\n"; 105: echo "\n"; 109: echo "\n"; 112: //echo ""; 113: //echo "\n"; 114: echo "
\n"; 106: echo "".$title.""; 107: if ($pagemenu!="") echo "
  ".PageMenu($pagemenu,$pagemenumode)."";
108: echo "
\n"; 110: echo $menu[$menuindex]; 111: echo " 
\n";
115: 116: if ($secCheckFirstrun && ( $NATS->Cfg->Get("site.firstrun.ignore",0) != 1 ) ) 117: { 118: if (file_exists("firstrun.php")) 119: { 120: echo "
"; 121: echo "".$NATS->Lang->Item("sec.firstrun")."
";
122: echo $NATS->Lang->Item("sec.firstrun.text")."
";
123: echo $NATS->Lang->Item("sec.firstrun.ignore")."
";
124: echo "http://www.purplepixie.org/freenats/wiki/Firstrun_Warning"; 125: 126: echo "
";
127: } 128: } 129: 130: if ($NATS->Cfg->Get("site.tester.suspended",0) == 1) 131: { 132: 133: echo "
"; 134: echo "".$NATS->Lang->Item("testing.suspended")."
";
135: echo $NATS->Lang->Item("testing.suspended.explain")."
";
136: echo "".$NATS->Lang->Item("system.settings").""; 137: echo "
";
138: 139: } 140: 141: 142: if ($alertpane==1) 143: { 144: $alerts=$NATS->GetAlerts(); 145: if (is_array($alerts)) 146: { 147: echo "
"; 148: echo "".$NATS->Lang->Item("nats.alerts")."

";
149: foreach($alerts as $alert) 150: { 151: echo " "; 152: echo "".$alert['nodeid']."
"; 153: } 154: echo "
";
155: echo "
";
156: } 157: } 158: 159: } 160: 161: function Start_Round($title,$width="") 162: { 163: if ($width!="") $w=" width=".$width; 164: else $w=""; 165: echo "\n"; 166: echo "\n"; 167: echo "\n"; 170: echo "\n"; 176: 177: echo "
\n"; 168: echo $title; 169: echo "\n
\n"; 171: } 172: 173: function End_Round() 174: { 175: echo "\n
";
178: } 179: 180: function Screen_Footer($track_if_enabled=true) 181: { 182: global $NATS,$poplist; 183: echo "

\n";
184: //$NATS->Cfg->DumpToScreen(); 185: echo "
"; 186: echo "
"; 187: 188: echo "
FreeNATS; © ".$NATS->Lang->Item("copyright")." 2008-2017 "; 189: echo "PurplePixie Systems"; 190: echo "
"; 191: echo $NATS->Lang->Item("version").": ".$NATS->Version; 192: if ($NATS->Release!="") echo "/".$NATS->Release; 193: echo "  
";
194: 195: //echo "Hello"; 196: echo "
";
197: echo "
";
198: if (ini_get("freenats.rpath")==1) 199: { 200: echo "FreeNATS Virtual Server Powered By rPath LAMP Appliance
";
201: } 202: //echo "This is alpha-test software - we would very much value your "; 203: //echo "feedback
"; 204: 205: $autofeedback=false; 206: if ($track_if_enabled) 207: { 208: $t=$NATS->Cfg->Get("freenats.tracker"); 209: if ( ($t!="") && ($t>0) ) 210: { 211: $autofeedback=true; 212: $usid=$NATS->Cfg->Get("freenats.tracker.usid",""); 213: if ($usid=="") 214: { // generate usid if not already set 215: // usid form XYZ-XYZ-XYZ... 216: $allow="abcdef0123456789"; 217: $allow_len=strlen($allow); 218: mt_srand(microtime()*1000000); 219: $first_set=1; 220: for ($a=0; $a<5; $a++) // blocks 221: { 222: if ($first_set==1) $first_set=0; 223: else $usid.="-"; 224: for ($b=0; $b<10; $b++) 225: { 226: $c=mt_rand(0,$allow_len-1); 227: $usid.=$allow[$c]; 228: } 229: } 230: $NATS->Cfg->Set("freenats.tracker.usid",$usid); 231: } 232: 233: // get some more data 234: $sn=explode("/",$_SERVER['SCRIPT_NAME']); 235: $script=$sn[count($sn)-1]; 236: 237: // show tracking image 238: echo "Version."+p=".$script."&type=ping&usid=".$usid."\" width=1 height=1>\n"; 239: } 240: } 241: 242: //$NATS->PageError("fish","swim in the sea"); 243: //$NATS->PageError("dogs","walk on the land"); 244: //$autofeedback=true; 245: 246: if (count($NATS->PageErrors)>0) // page errors reported 247: { 248: echo "
\n"; 249: echo "Errors detected on page: "; 250: $url=""; 251: $counter=0; 252: foreach($NATS->PageErrors as $PageError) 253: { 254: if ($counter>0) $url.="&"; 255: $url.="code[".$counter."]=".urlencode($PageError['code'])."&desc[".$counter."]=".urlencode($PageError['desc']); 256: $counter++; 257: } 258: $url.="&ver=".$NATS->Version; 259: 260: echo ""; 269: 270: echo ""; 271: if ($autofeedback) 272: { 273: echo "Reporting..."; 274: } 275: else 276: { 277: echo "Click to report to PurplePixie | "; 278: //echo "Click to show/hide details"; 279: } 280: echo "  "; 281: echo "Click to show/hide details"; 282: echo "
\n"; 283: foreach($NATS->PageErrors as $PageError) 284: { 285: echo "# ".$PageError['code']." : ".$PageError['desc']."
\n";
286: } 287: echo "
";
288: echo "
\n";
289: 290: if ($autofeedback) 291: { 292: //echo "\n"; 293: echo "\n"; 296: } 297: 298: } 299: 300: if ($NATS->Cfg->Get("site.popupmessage")=="1") 301: { 302: if (count($poplist)>0) 303: { 304: echo "\n\n"; 312: } 313: } 314: echo "\n\n"; 315: } 316: 317: function UL_Error($task="") 318: { 319: global $NATS; 320: Screen_Header($NATS->Lang->Item("access.error")); 321: echo "
".$NATS->Lang->Item("access.error.detail")." (".$task.").

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

";
323: Screen_Footer(); 324: exit(); 325: } 326: 327: function Session_Error() 328: { 329: global $REQUEST_URI; 330: header("Location: ./?login_msg=Invalid+or+Expired+Session&url=".urlencode($REQUEST_URI)); 331: exit(); 332: } 333: 334: function nicedt($ts) 335: { 336: global $NATS; 337: $form="H:i:s d/m/Y"; 338: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y"); 339: if ($ts<=0) return $NATS->Lang->Item("never"); 340: return date($form,$ts); 341: } 342: 343: function enicedt($ts) 344: { 345: echo nicedt($ts); 346: } 347: 348: function nicediff($diff) 349: { 350: $hr=0; 351: $mn=0; 352: $se=0; 353: if ($diff>59) 354: { 355: $mn=round($diff/60,0); 356: $se=$diff%60; 357: if ($mn>59) 358: { 359: $hr=round($mn/60,0); 360: $mn=$mn%60; 361: } 362: } 363: else $se=$diff; 364: $s=""; 365: if ($hr<10) $s="0"; 366: $s.=$hr.":"; 367: if ($mn<10) $s.="0"; 368: $s.=$mn.":"; 369: if ($se<10) $s.="0"; 370: $s.=$se; 371: return $s; 372: } 373: 374: function dtago($ts,$sayago=true) 375: { 376: global $NATS; 377: if ($ts<=0) return $NATS->Lang->Item("never"); 378: $now=time(); 379: $diff=$now-$ts; 380: $s=nicediff($diff); 381: if ($sayago) $s.=" ".$NATS->Lang->Item("ago"); 382: return $s; 383: } 384: 385: function nicenextx($nextx) 386: { 387: if ($nextx<=0) return "Now"; 388: $diff=$nextx-time(); 389: if ($diff<0) 390: { 391: $sign=" ago"; 392: $diff=0-$diff; 393: } 394: else $sign=""; 395: return nicediff($diff).$sign; 396: } 397: 398: function edtago($ts) 399: { 400: echo dtago($ts); 401: } 402: 403: function smartx($x) // smart handling of unixtime x variables 404: { 405: if ($x==0) return time(); // 0 = now 406: else if ($x<0) // -z = now - z seconds 407: return (time()+$x); // negative number so + 408: else // positive number so is a unixtime 409: return $x; 410: } 411: 412: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?$"; 413: 414: function nices($s) 415: { 416: global $allowed; 417: $o=""; 418: for ($a=0; $a419: { 420: $c=$s[$a]; 421: if (strpos($allowed,$c)===false) 422: { 423: // skip it 424: } 425: else $o.=$c; 426: } 427: return $o; 428: } 429: /* // Old Static List Function 430: function ShowIcons() 431: { 432: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup; 433: $c=0; 434: echo ""; 435: $cc=0; 436: for ($a=0; $a437: { 438: if ($cc==0) echo ""; 439: echo ""; 443: $cc++; 444: if ($cc>=5) 445: { 446: echo ""; 447: $cc=0; 448: } 449: } 450: if ($cc>0) echo ""; 451: echo "

".$fnIcons[$a]."
"; 440: if ($a==$fnIcon_DefNode) echo "Node Default "; 441: if ($a==$fnIcon_DefGroup) echo "Group Default"; 442: echo "
";
452: } 453: */ 454: 455: function GetIcons() 456: { 457: $iconFiles=glob("icons/{*.gif,*.GIF,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png,*.PNG}", GLOB_BRACE); 458: for($a=0;$a459: $iconFiles[$a]=substr($iconFiles[$a],6); 460: return $iconFiles; 461: } 462: 463: 464: function ShowIcons() 465: { 466: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup,$NATS; 467: $c=0; 468: echo ""; 469: $cc=0; 470: $iconFiles=GetIcons(); 471: for ($a=0; $a472: { 473: $icon=$iconFiles[$a]; 474: if ($cc==0) echo ""; 475: echo ""; 479: $cc++; 480: if ($cc>=5) 481: { 482: echo ""; 483: $cc=0; 484: } 485: } 486: if ($cc>0) echo ""; 487: echo "

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