Looking for an Server status script (HTML)

Discussion in 'Systems Administration' started by zadika, Jun 16, 2018.

  1. I looking for an simple server status script coded in html with 2 images (16x16 px) red for offline, green for online.

    no custum stuff, no text

    i will include it in my serverlist behind the player counter

    [​IMG]
     
    • Funny Funny x 1
  2. Strahan

    Benefactor

    You can't code that in HTML. HTML is just markup. You need a scripting language on the back end like PHP or .NET. It'd be pretty simple to do with PHP. Does your host support that?
     
    • Agree Agree x 2
  3. the wohle homepage is coded in html. and im the host supportet php,html,bootstrap 3-4,ruby, nodejs etc....
     
  4. Strahan

    Benefactor

    Nothing is "coded" in HTML. HTML isn't a programming language. Since you support PHP, use this.

    Here is an example I threw together.

    To get this output:

    [​IMG]

    I used this PHP with that library I linked:

    Code (Text):
    <?php

        use xPaw\MinecraftQuery;
        use xPaw\MinecraftQueryException;
        require __DIR__ . '/src/MinecraftQuery.php';
        require __DIR__ . '/src/MinecraftQueryException.php';

        $servers = array();
        $servers["lioth"]["name"] = "Lioth - Winter's World";
        $servers["lioth"]["host"] = "lioth";
        $servers["lioth"]["port"] = 25565;
        $servers["lioth"]["players"] = 0;
        $servers["lioth"]["maxplayers"] = 0;
        $servers["zaranth"]["name"] = "Local Test Server";
        $servers["zaranth"]["host"] = "zaranth";
        $servers["zaranth"]["port"] = 25565;
        $servers["zaranth"]["players"] = 0;
        $servers["zaranth"]["maxplayers"] = 0;

        $query = new MinecraftQuery( );
        foreach ($servers AS $k=>$v) {
          try {
              $servers[$k]["failed"] = false;
              $query->Connect($v["host"], $v["port"], 1);
          }    catch( MinecraftQueryException $e ) {
              $servers[$k]["failed"] = true;
              continue;
          }

          if (($info = $query->GetInfo()) !== false) {
          foreach ($info AS $a=>$b) {
            $servers[$k][strtolower($a)] = $b;
          }
          $servers[$k]["plugins.count"] = count($info["Plugins"]);
        }

        if (($players = $query->GetPlayers()) !== false ) {
          $servers[$k]["players.online"] = $players;
        } else {
          $servers[$k]["players.online"] = array();
        }
      }

    ?>

    <body>
      <div class=header>Sylvcraft Network Status Monitor</div>
      <div class=container>
        <table>
        <tr><th>Server</th><th>Players</th><th>Max Players</th><th>Status</th></tr>
        <?php
          foreach ($servers AS $k=>$v) echo "<tr><td>{$v["name"]}</td><td>{$v["players"]}</td><td>{$v["maxplayers"]}</td><td><img src='status_" . (($v["failed"])?"0":"1") . ".gif'></td></tr>";
        ?>
        </table>
      </div>
    </body>

    <style type="text/css">
    BODY {
      background-color: #AAA;
      font-family: Arial,sans-serif;
      font-size: 12pt;
    }
    DIV.header {
      margin: 0 auto;
      background-color: #0A0;
      color: #FF0;
      text-align: center;
      font-size: 18pt;
      width: 25%;
      font-weight: bold;
      padding: 15px;
      border: 2px solid #000;
      margin-bottom: 20px;
      -moz-box-shadow: 0px 5px 4px #000;
        -webkit-box-shadow: 0px 5px 4px #000;
        box-shadow: 0px 5px 4px #000;
        -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
        filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
    }
    DIV.container {
      margin: 0 auto;
      background-color: #C0C0FF;
      color: #000;
      width: 25%;
      padding: 15px;
      border: 2px solid #000;
      margin-bottom: 20px;
    }
    DIV.container TABLE {
      border: none;
      margin: 0 auto;
    }
    DIV.container TD {
      vertical-align: top;
      padding-right: 10px;
      text-align: center;
    }
    DIV.container TD:first-child {
      font-weight: bold;
      color: #00F;
    }
    DIV.container TH {
      font-weight: bold;
      padding-right: 10px;
      text-transform: uppercase;
      text-decoration: underline;
    }
    </style>

    You would just need to modify the HTML part. The $servers variable for each index will collect all the info from query, not just the player counts. You can var_dump the variable to see what else it collects.
     
    #4 Strahan, Jun 17, 2018
    Last edited: Jun 17, 2018
    • Agree Agree x 1
  5. https://mcapi.us/server/status?ip=YOUR_IP

    Then just Google about how to parse JSON files and get the online count with PHP. Rather simple. Granted there's a way to do the same using JS, but PHP is just superior with it's its simplicity.
     
    #5 NIKNAIZ, Jun 17, 2018
    Last edited: Jun 17, 2018