<?php include 'settings.php'?>
<!DOCTYPE html>
<head>
  <title>SYSTEM MONITOR</title>
  <link rel="icon" type="image/png" href="favicon.png">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    a { colorblack; }
    body { font-size:14px; }
  </style>
<?php
  $fn = $_GET['fn']; $fn = htmlspecialchars($fn);
  switch ($fn)
    {
    case "pr":
      echo "</head>\n";
      echo "<body>\n";
      echo "<pre>\n";
      $command = 'date'$output = shell_exec($command); echo "$output";      
      echo "Processes Running: ";
      $command = 'ps -ef | wc -l'$output = shell_exec($command); echo "$output";            
      getit("localhost:8090/mon/lastcnt");
      echo "</pre>\n";
      echo "</body>\n";
      echo "</html>\n";
      break;

    case "monasa":
      echo "</head>\n";
      echo "<body>\n";
      echo "<pre>\n";
      getit("localhost:8090/mon/pm2list");
      echo "</pre>\n";
      echo "</body>\n";
      echo "</html>\n";
      break;

    case "psef":
      echo "</head>\n";
      echo "<body>\n";
      echo "<pre>\n";
      $command = 'ps -ef | grep \'nodejs\|pm2\|mumps\' | grep -ve \'crhvist\'';
      $output = shell_exec($command);
      echo "$output";      
      echo "</pre>\n";
      echo "</body>\n";
      echo "</html>\n";
      break;

    case "hfsdir":
      echo "</head>\n";
      echo "<body>\n";
      echo "<pre>\n";
      echo "<u>Directory: /var/www/html/vista</u>\n";
      $command = 'ls | grep \'\.\'';
      $output = shell_exec($command);
      echo "$output";
      echo "</pre>\n";
      echo "</body>\n";
      echo "</html>\n";
      break;

    default:
      logit("app_monitor");
      echo "  <script type=\"text/javascript\">\n";
      echo "    basecgi='monitor.php?fn='\n";
      echo "    window.setInterval(\"iFramesSource();\", 15000);\n";
      echo "    function iFramesSource()\n";
      echo "      {\n";
      echo "      document.getElementById(\"pr\").src=basecgi + \"pr\";\n";
      echo "      document.getElementById(\"monasa\").src=basecgi + \"monasa\";\n";
      echo "      document.getElementById(\"psef\").src=basecgi + \"psef\";\n";
      echo "      document.getElementById(\"hfsdir\").src=basecgi + \"hfsdir\";\n";
      echo "      }\n";
      echo "  </script>\n";
      echo "</head>\n";
      echo "<body onLoad='iFramesSource()';>\n";
      echo "  <center>\n";
      echo "  <table style=\"width:90%;border-collapse:collapse;\">\n";
      echo "    <tr><td><iframe id=\"pr\" width=\"100%\" height=\"80\"></iframe></td></tr>\n";
      echo "    <tr><td><iframe id=\"monasa\" width=\"100%\" height=\"140\"></iframe></td></tr>\n";
      echo "    <tr><td><iframe id=\"psef\" width=\"100%\" height=\"200\"></iframe></td></tr>\n";
      echo "    <tr><td><iframe id=\"hfsdir\" width=\"100%\" height=\"325\"></iframe></td></tr>\n";
      echo "  </table>\n";
      echo "  </center>\n";
      echo "</body>\n";
      echo "</html>\n";
      break;
    }
?>