Skip to content

Commit

Permalink
Merge pull request #6 from LittleJake/develop
Browse files Browse the repository at this point in the history
Feature
  • Loading branch information
LittleJake authored Nov 27, 2023
2 parents f92a614 + 4234c92 commit 1988903
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 30 deletions.
3 changes: 1 addition & 2 deletions application/admin/validate/LoginTokenValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class LoginTokenValidate extends Validate
{
protected $rule = [
'g-recaptcha-response|Captcha' => ['require', 'checkCaptcha'],
'token|Token' => ['require', 'length' => 64, 'alphaNum', 'checkToken'],
'token|Token' => ['require', 'alphaNum', 'checkToken'],
];

protected $message = [
'g-recaptcha-response.require' => 'Captcha invalid.',
'token.require' => 'Token not empty.',
'token.alphaNum' => 'Wrong Token format.',
'token.length' => 'Wrong Token format.',
];

protected function checkCaptcha($value, $rule, $data = []){
Expand Down
1 change: 0 additions & 1 deletion application/common/lib/SystemMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ static public function fetchIPInfo($ip){
if($data == null) throw new Exception("Failed to query country code");
return $data;
}, 24*60*60);
Log::info($ip_without_cidr_24);
}
catch (Exception $e){
Log::error($e->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions application/common/view/exception/common.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<meta charset="UTF-8">
<title>Oops! Error!</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.4.6/css/flag-icon.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdui/0.4.3/css/mdui.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdui/1.0.2/css/mdui.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style>
/* Base */
Expand Down Expand Up @@ -517,7 +517,7 @@ <h2>Environment Variables</h2>
<p class="mdui-text-color-white-secondary">Licensed under the Apache License, Version 2.0</p>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdui/0.4.3/js/mdui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdui/1.0.2/js/mdui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</body>
</html>
25 changes: 18 additions & 7 deletions application/index/controller/Index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace app\index\controller;

use app\common\lib\SystemMonitor;
Expand All @@ -9,7 +10,7 @@ class Index extends Base
{
protected $middleware = [
'FlowControl',
'CheckUUID' => ['only'=> ['info']]
'CheckUUID' => ['only' => ['info']]
];

public function index()
Expand All @@ -19,15 +20,24 @@ public function index()
$uuids_online = [];
$uuids_offline = [];
$time = time();

foreach ($uuids as $uuid => $ip) {
$uuid_temp = [
'IP' => SystemMonitor::fetchIPInfo($ip),
'IP' => [],
'INFO' => SystemMonitor::getInfo($uuid)
];
if (empty($uuid_temp['INFO'])) continue;
if (empty($uuid_temp["IP"]['countryCode']))
$uuid_temp["IP"]["country"] = "Private";

if (!empty($uuid_temp['INFO']['Country']) && !empty($uuid_temp['INFO']['Country Code']))
$uuid_temp['IP'] = [
'country' => $uuid_temp['INFO']['Country'],
"countryCode" => $uuid_temp['INFO']['Country Code']
];
else {
$uuid_temp['IP'] = SystemMonitor::fetchIPInfo($ip);
if (empty($uuid_temp["IP"]['countryCode']))
$uuid_temp["IP"]["country"] = "Private";
}

if (($time - intval($uuid_temp['INFO']['Update Time'])) > 500)
$uuids_offline[$uuid] = $uuid_temp;
Expand All @@ -42,7 +52,8 @@ public function index()
return $this->fetch();
}

public function info($uuid = ''){
public function info($uuid = '')
{
$latest = json_decode(SystemMonitor::getLatest($uuid), TRUE);
$info = SystemMonitor::getInfo($uuid);
// $uptime_str = SystemMonitor::timeFormat(intval($info['Uptime']));
Expand All @@ -52,7 +63,7 @@ public function info($uuid = ''){
$this->assign("info", $info);
$this->assign("uuid", $uuid);
$this->assign("ip", $ip);
if($this->request->isAjax())
if ($this->request->isAjax())
return $this->fetch("index/info_ajax");

return $this->fetch();
Expand Down
9 changes: 6 additions & 3 deletions application/index/view/index/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<body class="mdui-drawer-body-left mdui-appbar-with-toolbar mdui-theme-primary-indigo">
<div class="mdui-appbar mdui-appbar-fixed">
<div class="mdui-toolbar mdui-color-theme">
<span class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white" mdui-drawer="{target:'#drawer',swipe:true}">
<span class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white" mdui-drawer="{target:'#drawer', swipe:true, overlay: false}">
<i class="mdui-icon material-icons">menu</i>
</span>
<a href="{:url('/')}" class="mdui-typo-headline">{:lang("Server Monitor")}</a>
Expand Down Expand Up @@ -121,12 +121,15 @@ <h2>Server Monitor</h2>
}

$('.ajax-load').on('click',function () {
var url = $(this).attr('data-href'), drawer = new mdui.Drawer('#drawer');
var url = $(this).attr('data-href'), drawer = new mdui.Drawer('#drawer', {swipe: true});
$('#loading').removeClass("mdui-hidden");
$.ajax({
'url': url,
'success': function(data){
$('#loading').addClass("mdui-hidden");$('#ajax').html(data);mdui.mutation();drawer.close();
$('#loading').addClass("mdui-hidden");
$('#ajax').html(data);
drawer.close();
mdui.mutation();
$('#refresh').attr("data-src", url);
},
'error': function () {window.location = url;}
Expand Down
2 changes: 1 addition & 1 deletion application/index/view/index/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>Info</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.4.6/css/flag-icon.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdui/0.4.3/css/mdui.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdui/1.0.2/css/mdui.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body class="mdui-appbar-with-toolbar mdui-theme-primary-indigo">
Expand Down
33 changes: 20 additions & 13 deletions application/index/view/index/info_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ <h4>{:lang("Update Time")}</h4>
</div>
<div class="mdui-col-xs-12 mdui-col-md-6">
<h4>{:lang("Process")}</h4>
<p>{$info['Process']}</p>
<p>{$info['Process']|default="N/A"}</p>
<h4>{:lang("Connection")}</h4>
<p>{$info['Connection']}</p>
<p>{$info['Connection']|default="N/A"}</p>
<h4>{:lang("Throughput")}</h4>
<p>{$info['Throughput']|default="Undefined"}</p>
<h4>{:lang("Uptime")}</h4>
<p>{$info['Uptime']}</p>
<p>{$info['Uptime']|default="N/A"}</p>
<h4>{:lang("Country")}</h4>
<p class="mdui-valign"><span class="mdui-list-item-icon flag-icon flag-icon-{:empty($ip['countryCode'])?'none':strtolower($ip['countryCode'])}"></span>{$ip['country']}</p>
</div>
Expand Down Expand Up @@ -177,7 +179,7 @@ <h4>{:lang('Swap')}</h4>
title: {text:"Network RX & TX", left: 'center'},
tooltip: {trigger: 'axis', axisPointer: {type: 'cross', label: {backgroundColor: '#6a7985'}}},
legend: {bottom: 50, data: ['RX Packets (k)', 'RX Throughput (MB)', 'TX Packets (k)', 'TX Throughput (MB)',]},
grid: [{height: '30%'}, {top: '45%', height: '30%'}],
grid: [{height: '60%'}, {height: '60%'}],
axisPointer: {link: {xAxisIndex: 'all'}},
dataZoom: [{show: true, realtime: true, start: 70, end: 100, xAxisIndex: [0, 1]}, {type: 'inside', realtime: true, start: 70, end: 100, xAxisIndex: [0, 1]}],
xAxis: [
Expand All @@ -187,19 +189,24 @@ <h4>{:lang('Swap')}</h4>
yAxis: [{
type: 'value',
name: 'Packets',
axisLabel: {formatter: '{value} k'}
axisLabel: {formatter: '{value} k'},
position: 'right',
axisLine: {show: true},
splitLine: {show: false},
}, {
gridIndex: 1,
type: 'value',
name: 'Throughput',
axisLabel: {formatter: '{value} MB'},
inverse: true
position: 'left',
axisLine: {show: true},
splitLine: {show: false},
}],
series: [
{name: 'RX Packets (k)',symbol: 'none', type: 'line', areaStyle: {}, data: e.RX.packets},
{name: 'TX Packets (k)',symbol: 'none', type: 'line', areaStyle: {}, data: e.TX.packets},
{name: 'RX Throughput (MB)',symbol: 'none', xAxisIndex: 1, yAxisIndex: 1, type: 'line', areaStyle: {}, data: e.RX.megabytes},
{name: 'TX Throughput (MB)',symbol: 'none', xAxisIndex: 1, yAxisIndex: 1, type: 'line', areaStyle: {}, data: e.TX.megabytes},
{name: 'RX Packets (k)',symbol: 'none', type: 'line', areaStyle: {}, data: e.RX.packets,},
{name: 'TX Packets (k)',symbol: 'none', type: 'line', areaStyle: {}, data: e.TX.packets,},
{name: 'RX Throughput (MB)',symbol: 'none', xAxisIndex: 1, yAxisIndex: 1, type: 'line', areaStyle: {}, data: e.RX.megabytes,},
{name: 'TX Throughput (MB)',symbol: 'none', xAxisIndex: 1, yAxisIndex: 1, type: 'line', areaStyle: {}, data: e.TX.megabytes,},
]
};

Expand All @@ -220,7 +227,7 @@ <h4>{:lang('Swap')}</h4>
xAxis: {type: 'category', boundaryGap: false, data: e.time},
yAxis: {
type: 'value',
axisLabel: {formatter: '{value} MB'}
axisLabel: {formatter: '{value} MB'},
},
dataZoom: [{type: 'inside', start: 70, end: 100}, {
start: 90, end: 100, handleSize: '80%',
Expand Down Expand Up @@ -254,7 +261,7 @@ <h4>{:lang('Swap')}</h4>
xAxis: {type: 'category', boundaryGap: false, data: e.time},
yAxis: {
type: 'value',
axisLabel: {formatter: '{value} MB'}
axisLabel: {formatter: '{value} MB'},
},
dataZoom: [{type: 'inside', start: 70, end: 100}, {
start: 90, end: 100, handleSize: '80%',
Expand Down Expand Up @@ -341,7 +348,7 @@ <h4>{:lang('Swap')}</h4>
Object.keys(e.value).forEach(function(k){
option.series.push({
name: k, type: 'line', smooth: true, symbol: 'none', sampling: 'average',
areaStyle: {}, data: e.value[k]
areaStyle: {}, data: e.value[k],
});
});

Expand Down
2 changes: 1 addition & 1 deletion application/index/view/index/js_template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdui/1.0.2/js/mdui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/progressbar.js/1.1.0/progressbar.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.1/echarts.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>

0 comments on commit 1988903

Please sign in to comment.