A-A+

最特别的VPS小鸡流量统计网页:方便不用进每个小鸡面板分别查看,直接调用API

2023年07月12日 VPS评价 等您评论

说明:
适用于RN、greencloud、vir、ddp等使用solusVM控制面板商家。程序直接调用的solusVM面板的API,获取代码参考网上现存的,用GPT美化了下,这样就方便不用进每个小鸡面板分别查看了。

预览:

使用方法:
进入面板获取API

在35行处进行替换修改
在164行修改为自己的哪吒探针地址
注意保护好自己的API,有重装小鸡系统权限!

如果是多账号不建议使用:
@zybep #4 发布于2023/7/12 11:27:16,编辑于2023/7/12 11:30:09
前排警告,会触发vir多号警报,其他家也可以通过相同的手段查到多号。

VPS全科网【http://vpsqk.com】提示,代码如下:

<!DOCTYPE html>
<head>
  <title>服务器流量状态</title>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
  <style>
    .table {
      width: 100%;
    }

    .table th,
    .table td {
      vertical-align: middle;
    }

    .progress {
      height: 20px;
    }
  </style>
</head>

<body>
  <div style="width: 90%; max-width: 800px; margin: 0 auto;">
    <h1>服务器流量状态</h1>
    <hr />

    <?php
    $lists = array(
      array("XXXXX-XXXXX-XXXXX", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "https://cp.greencloudvps.com/", "LA-2222"),
      array("XXXXX-XXXXX-XXXXX", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "https://cp.greencloudvps.com/", "JP-2222"),
      array("XXXXX-XXXXX-XXXXX", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "https://nerdvm.racknerd.com/", "Racknerd"),
      array("XXXXX-XXXXX-XXXXX", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "https://manage.dedicontrol.com/", "DDP")
      // 多个可以拷贝上面,最后一个不加逗号,其他加即可
    );

    $result = array();

    foreach ($lists as $key) {
      $result[] = post($key[0], $key[1], $key[2], $key[3]);
    }

    function humanFileSize($size, $unit = "")
    {
      if ((!$unit && $size >= 1 << 30) || $unit == "GB")
        return number_format($size / (1 << 30), 2) . " GB";
      if ((!$unit && $size >= 1 << 20) || $unit == "MB")
        return number_format($size / (1 << 20), 2) . " MB";
      if ((!$unit && $size >= 1 << 10) || $unit == "KB")
        return number_format($size / (1 << 10), 2) . " KB";
      return number_format($size) . " bytes";
    }

    function post($keys, $hashs, $naserurls, $beizhu)
    {

      $postfields["key"] = $keys;
      $postfields["hash"] = $hashs;
      $postfields["action"] = "info";
      $masterurl = $naserurls;
      $postfields["status"] = "true";
      $postfields["hdd"] = "true";
      $postfields["mem"] = "true";
      $postfields["bw"] = "true";

      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, "{$masterurl}/api/client/command.php");
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect: "));
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

      // Execute the request

      $data = curl_exec($ch);

      $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

      if ($code != 200) {
        $return['error'] = 1;

        if ($code == 405) {
          $return['message'] = "Incorrect API credentials.";
          return $return;
        }

        $return['message'] = "Invalid status code.";

        return $return;
      }

      // Close the Curl handle

      curl_close($ch);

      if (!$data) {
        $return['error'] = 1;
        $return['message'] = "Error connecting to API.";

        return $return;
      }

      // Extract the data

      preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $match);

      $result = array();
      $result['bz'] = $beizhu;
      foreach ($match[1] as $x => $y) {
        $result[$y] = $match[2][$x];
      }
      //获取出错
      if ($result['status'] == "error") {
        $result['error'] = 1;
        $result['message'] = $result['statusmsg'];

        return $result;
      }
      //获取正常
      $result['error'] = 0;

      $result['hdd'] = explode(",", $result['hdd']);
      $result['mem'] = explode(",", $result['mem']);
      $result['bw'] = explode(",", $result['bw']);
      return $result;
    }

    ?>

    <table class="table table-striped">
      <thead>
        <tr>
          <th>备注</th>
          <th>带宽</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($result as $key) { ?>
          <tr>
            <td><?php echo $key['bz']; ?></td>
            <td>
              <div class="progress">
                <div class="progress-bar <?php echo ($key['bw'][3] >= 90) ? 'bg-danger' : (($key['bw'][3] >= 75) ? 'bg-warning' : 'bg-success'); ?>" role="progressbar" style="width: <?php echo $key['bw'][3]; ?>%;" aria-valuenow="<?php echo $key['bw'][3]; ?>" aria-valuemin="0" aria-valuemax="100">
                  <?php echo $key['bw'][3]; ?>%
                </div>
              </div>
              <small>已用 <?php echo humanFileSize($key['bw'][1]); ?> / 总量 <?php echo humanFileSize($key['bw'][0]); ?></small>
            </td>
          </tr>
        <?php } ?>
      </tbody>
    </table>

    <a class="btn btn-primary" href="https://status.xxxxxx.xyz" role="button">返回哪吒探针</a>
  </div>
</body>

</html>

本文来自:http://vpsqk.com/post/4155.html

给我留言