Compare commits

..

No commits in common. 'master' and 'v1.0.0' have entirely different histories.

@ -1,31 +0,0 @@
name: release
on:
push:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Rename output dir
run: mv build sergate
- name: Make zip file
run: zip -r -9 sergate.zip ./sergate -x .gitignore
- name: Semantic release
run: npx semantic-release
env:
CI: true
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3
.gitignore vendored

@ -10,8 +10,6 @@
# production # production
/build /build
/sergate
/*.zip
# misc # misc
.DS_Store .DS_Store
@ -23,4 +21,3 @@
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
yarn.lock

@ -1 +0,0 @@
registry=https://registry.npmjs.org/

@ -1,33 +0,0 @@
{
"branch": "master",
"ci": "true",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
[
"@semantic-release/github",
{
"assets": {
"path": "sergate.zip",
"name": "sergate-${nextRelease.version}.zip"
}
}
]
],
"publicConfig": "next"
}

@ -1,122 +0,0 @@
## [2.0.3](https://github.com/krwu/ServerStatus-web/compare/v2.0.2...v2.0.3) (2023-03-07)
### Bug Fixes
* http-cache-semantics vulnerable ([dac1abc](https://github.com/krwu/ServerStatus-web/commit/dac1abc1112c6a6388f691e7697bb0dc5fd93558))
## [2.0.2](https://github.com/krwu/ServerStatus-web/compare/v2.0.1...v2.0.2) (2022-09-13)
### Bug Fixes
* **npm:** potential security vulnerabilities ([10db0cb](https://github.com/krwu/ServerStatus-web/commit/10db0cbb2d37d2be7a43e9279c2c60099237c1fa))
## [2.0.1](https://github.com/krwu/ServerStatus-web/compare/v2.0.0...v2.0.1) (2022-07-14)
### Performance Improvements
* clean unnecessary packages ([d5a1dd0](https://github.com/krwu/ServerStatus-web/commit/d5a1dd007cecafe7b4461e98667410ae099b6e3d))
# [2.0.0](https://github.com/krwu/ServerStatus-web/compare/v1.4.0...v2.0.0) (2022-06-14)
### Features
* upgrade dependencies ([eeff4c0](https://github.com/krwu/ServerStatus-web/commit/eeff4c0eaf59122bc984be4ab3970dbaf72164d1))
### BREAKING CHANGES
* - react-scripts upgraded to v5
- semantic-release upgraded to v19
- dropped support for Node <= 15
# [1.4.0](https://github.com/krwu/ServerStatus-web/compare/v1.3.0...v1.4.0) (2022-02-19)
### Features
* upgrade dependencies ([c9a4f11](https://github.com/krwu/ServerStatus-web/commit/c9a4f11286bd6d4788a78853af81104940b62fff))
# [1.3.0](https://github.com/krwu/ServerStatus-web/compare/v1.2.0...v1.3.0) (2021-09-22)
### Features
* bump antd version to 4.0 ([664003d](https://github.com/krwu/ServerStatus-web/commit/664003df1bf2d2f4eed04cc0334dcb22db0baa31))
# [1.2.0](https://github.com/krwu/ServerStatus-web/compare/v1.1.5...v1.2.0) (2021-09-22)
### Bug Fixes
* ignore local registry ([15158f4](https://github.com/krwu/ServerStatus-web/commit/15158f4c8d1523f2d2983a5bbf164660113211be))
* serviceWorker cause building failed ([bc548af](https://github.com/krwu/ServerStatus-web/commit/bc548af585014c29f2621c98599d63c4955c83ee))
### Features
* **ui:** add index for each row ([1c0fbfe](https://github.com/krwu/ServerStatus-web/commit/1c0fbfe86ea034d2bda0c32cc861bef52accac7d))
## [1.1.5](https://github.com/krwu/ServerStatus-web/compare/v1.1.4...v1.1.5) (2020-11-05)
### Bug Fixes
* locale ('1 day' doesn't work), mobile style ('name' item size) ([cf5c3b6](https://github.com/krwu/ServerStatus-web/commit/cf5c3b6638400203f694d1776488057dfbf42e87))
## [1.1.4](https://github.com/krwu/ServerStatus-web/compare/v1.1.3...v1.1.4) (2020-05-05)
### Bug Fixes
* display name with host or name from json ([a19256c](https://github.com/krwu/ServerStatus-web/commit/a19256c9e83345ec18916ce7620e57461228face)), closes [#2](https://github.com/krwu/ServerStatus-web/issues/2)
## [1.1.3](https://github.com/krwu/ServerStatus-web/compare/v1.1.2...v1.1.3) (2020-04-09)
### Bug Fixes
* pull data once page loaded instead of wait 5m ([f244dec](https://github.com/krwu/ServerStatus-web/commit/f244decff163a847ee9da3999b352a33f554c15b))
## [1.1.2](https://github.com/krwu/ServerStatus-web/compare/v1.1.1...v1.1.2) (2020-02-04)
### Performance Improvements
* **data:** improve fetch interval from 2s to 5s ([4bd86e3](https://github.com/krwu/ServerStatus-web/commit/4bd86e3f7b18fd33054cbddeae185bc5cde6338e))
## [1.1.1](https://github.com/krwu/ServerStatus-web/compare/v1.1.0...v1.1.1) (2019-12-22)
### Bug Fixes
* add missed locale entities ([88245b6](https://github.com/krwu/ServerStatus-web/commit/88245b68d90373870cd7b9b000c2dcb85af3fad0))
# [1.1.0](https://github.com/krwu/ServerStatus-web/compare/v1.0.1...v1.1.0) (2019-12-21)
### Features
* add international support ([5391fea](https://github.com/krwu/ServerStatus-web/commit/5391feab9f36d625293b70066cbb9838a7075ea5))
# Changelog
## [1.0.1](https://github.com/krwu/ServerStatus-web/compare/v1.0.0...v1.0.1) (2019-09-16)
### Features
* change footer link target ([f8f73d3](https://github.com/krwu/ServerStatus-web/commit/f8f73d3))
# [1.0.0](https://github.com/krwu/ServerStatus-web/compare/9097c1b...v1.0.0) (2019-08-29)
### Features
* implement web ui development ([9097c1b](https://github.com/krwu/ServerStatus-web/commit/9097c1b))
* update footer ([467de09](https://github.com/krwu/ServerStatus-web/commit/467de09))

@ -1,13 +0,0 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2019 Kairee Wu <kairee@udev.bid>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

@ -1,23 +1,13 @@
# Web UI for ServerStatus # Web UI for ServerStatus
**English** | [简体中文](README.zh_CN.md)
This is a web ui for [BotoX's ServerStatus](https://github.com/BotoX/ServerStatus/). This is a web ui for [BotoX's ServerStatus](https://github.com/BotoX/ServerStatus/).
[![Build Status](https://travis-ci.com/krwu/ServerStatus-web.svg?branch=master)](https://travis-ci.com/krwu/ServerStatus-web)
[![codebeat badge](https://codebeat.co/badges/038ea692-7cec-47dc-add2-2a59b6a5d89c)](https://codebeat.co/projects/github-com-krwu-serverstatus-web-master)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/krwu/serverstatus-web.svg)
[![downloads](https://img.shields.io/github/downloads/krwu/ServerStatus-web/total)](https://github.com/krwu/ServerStatus-web/releases)
[![GitHub](https://img.shields.io/github/license/krwu/ServerStatus-web)](https://github.com/krwu/ServerStatus-web/blob/master/COPYING.txt)
## Live demo: ## Live demo:
[https://udev.bid/sergate/](https://udev.bid/sergate/) [https://udev.bid/sergate/](https://udev.bid/sergate/)
## Useage: ## Useage:
You MUST install and run [BotoX's ServerStatus](https://github.com/BotoX/ServerStatus/) first. This is just a drop-in replacement for its web interface.
### **With release version:** ### **With release version:**
1. Download the latest prebuilt files on the [release page](https://github.com/krwu/ServerStatus-web/releases). 1. Download the latest prebuilt files on the [release page](https://github.com/krwu/ServerStatus-web/releases).
@ -32,20 +22,12 @@ You MUST install and run [BotoX's ServerStatus](https://github.com/BotoX/ServerS
4. Install dependecies with npm / yarn. 4. Install dependecies with npm / yarn.
5. Run `npm run build` to build web files. 5. Run `npm run build` to build web files.
```bash ``` bash
git clone https://github.com/krwu/ServerStatus-web.git git clone https://github.com/krwu/ServerStatus-web.git
cd ./ServerStatus-web/ cd ./ServerStatus-web/
## you can also run "yarn" instead of the next command ## you can also run "yarn" instead of the next command
npm i npm i
npm run build npm run build
``` ```
6. Copy all files in the `build` directory to your web directory of ServerStatus(you can delete all files except `json/status.json` in it, this is recommended). 6. Copy all files in the `build` directory to your web directory of ServerStatus(you can delete all files except `json/status.json` in it, this is recommended).
---
## Special thanks
[![Jetbrains Logo](https://krwu.github.io/img/jetbrains.svg)](https://www.jetbrains.com/?from=WebUiForServerStatus)
Thanks to [Jetbrains](https://www.jetbrains.com/?from=WebUiForServerStatus) for supporting this small open source project! I used WebStorm and PhpStorm for years, they are the best tools!

@ -1,50 +0,0 @@
# Web UI for ServerStatus
[English](README.md) | **简体中文**
本项目是为 [BotoX's ServerStatus](https://github.com/BotoX/ServerStatus/) 开发的前端展示界面.
[![Build Status](https://travis-ci.com/krwu/ServerStatus-web.svg?branch=master)](https://travis-ci.com/krwu/ServerStatus-web)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/krwu/ServerStatus-Web)
[![GitHub All Releases](https://img.shields.io/github/downloads/krwu/ServerStatus-web/total)](https://github.com/krwu/ServerStatus-web/releases)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![GitHub](https://img.shields.io/github/license/krwu/ServerStatus-web)](https://github.com/krwu/ServerStatus-web/blob/master/COPYING.txt)
![GitHub package.json dependency version (prod)](https://img.shields.io/github/package-json/dependency-version/krwu/ServerStatus-Web/react)
## 演示:
[https://udev.bid/sergate/](https://udev.bid/sergate/)
## 使用方法:
你必须首先成功安装和运行 [BotoX's ServerStatus](https://github.com/BotoX/ServerStatus/)。因为这个项目仅仅是一个可以即插即用的可替换的 web 界面。
### **使用预编译版:**
1. 从 [release 页面](https://github.com/krwu/ServerStatus-web/releases)下载最新的预编译压缩包。
2. 解压下载的文件。
3. 把 `sergate` 目录下的所有文件上传到你的 ServerStatus 的 web 目录(推荐操作:你可以先删除**原目录**下除了 `json/status.json` 以外的所有文件)。
### **自己编译:**
1. 你需要安装有 Node.js, npm 或者 yarn.
2. 克隆本项目,或者下载打包的源代码到你的机器。
3. 进入项目根目录(或解压后的文件夹)。
4. 通过 npm(推荐) 或者 yarn 安装依赖项。
5. 执行 `npm run build` 来编译 web 文件:
```bash
git clone https://github.com/krwu/ServerStatus-web.git
cd ./ServerStatus-web/
## 你也可以用 yarn 代替下面的 npm
npm i
npm run build
```
6. 把 `build` 目录下的所有文件上传到你的 ServerStatus 的 web 目录(推荐操作:你可以先删除**原目录**下除了 `json/status.json` 以外的所有文件)。
---
## 特别鸣谢
[![Jetbrains Logo](https://krwu.github.io/img/jetbrains.svg)](https://www.jetbrains.com/?from=WebUiForServerStatus)
非常感谢 [Jetbrains](https://www.jetbrains.com/?from=WebUiForServerStatus) 对这个小小开源项目的支持!我一直是 PhpStorm 和 WebStorm 的死忠粉,它们是最棒的开发工具。

@ -0,0 +1,9 @@
const { override, fixBabelImports } = require('customize-cra');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css',
}),
);

34822
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,5 +1,6 @@
{ {
"name": "serverstatus-webui", "name": "serverstatus-webui",
"version": "1.0.0",
"description": "It's a simple, clean webui for ServerStatus, built with react and Ant Design", "description": "It's a simple, clean webui for ServerStatus, built with react and Ant Design",
"keywords": [ "keywords": [
"ServerStatus", "ServerStatus",
@ -9,40 +10,42 @@
"ant design" "ant design"
], ],
"private": true, "private": true,
"engines": {
"node": ">=18"
},
"homepage": ".", "homepage": ".",
"bugs": { "bugs": {
"url": "https://github.com/krwu/ServerStatus-web/issues" "url": "https://github.com/krwu/ServerStatus-web/issues"
}, },
"license": "WTFPL", "license": "MIT",
"author": "Kairee <kairee@udev.bid> (https://www.ofcss.com/)", "author": "Kairee <kairee@udev.bid> (https://www.ofcss.com/)",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/krwu/ServerStatus-web.git" "url": "https://github.com/krwu/ServerStatus-web.git"
}, },
"dependencies": { "dependencies": {
"@ant-design/icons": "^4.6.4", "@types/jest": "24.0.17",
"antd": "^4.0.0", "@types/node": "12.7.1",
"react": "18", "@types/react": "16.9.1",
"react-dom": "18", "@types/react-dom": "16.8.5",
"react-intl-universal": "^2.5.3" "antd": "^3.21.4",
"babel-plugin-import": "^1.12.0",
"customize-cra": "^0.4.1",
"react": "^16.9.0",
"react-app-rewired": "^2.1.3",
"react-dom": "^16.9.0",
"react-scripts": "3.1.0",
"typescript": "3.5.3"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-app-rewired start",
"build": "react-scripts build", "build": "react-app-rewired build && rm -rf build/json",
"test": "react-app-rewired test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": "react-app"
"react-app",
"react-app/jest"
]
}, },
"browserslist": { "browserslist": {
"production": [ "production": [
">5%", ">0.2%",
"not dead", "not dead",
"not op_mini all" "not op_mini all"
], ],
@ -51,23 +54,5 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"@babel/core": ">=7.0.0-0 <8.0.0",
"@babel/plugin-syntax-flow": "^7.14.5",
"@babel/plugin-transform-react-jsx": "^7.14.9",
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/git": "^10.0.1",
"@svgr/webpack": "^6.2.1",
"@types/node": "^18.14.6",
"@types/react": "18",
"@types/react-dom": "18",
"babel-plugin-import": "^1.13.1",
"react-scripts": "^5.0.1",
"semantic-release": "^20.1.1",
"typescript": "^4.1.2"
},
"overrides": {
"@svgr/webpack": "$@svgr/webpack"
} }
} }

@ -5,7 +5,10 @@
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" /> <meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" /> <link rel="apple-touch-icon" href="logo192.png" />
<!-- <!--
manifest.json provides metadata used when your web app is installed on a manifest.json provides metadata used when your web app is installed on a
@ -21,12 +24,7 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<link <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flag-icon-css@3.3.0/css/flag-icon.min.css" integrity="sha256-NkXMfPcpoih3/xWDcrJcAX78pHpfwxkhNj0bAf8AMTs=" crossorigin="anonymous">
crossorigin="anonymous"
integrity="sha384-jjBocnsQb7zTYSozEemReuje+/6FUtVswDdIPdDMA6SVLBCt51rVkrz/V/sTnKOu"
href="https://lib.baomitu.com/flag-icon-css/3.5.0/css/flag-icon.min.css"
rel="stylesheet"
/>
<title>ServerStatus</title> <title>ServerStatus</title>
</head> </head>
<body> <body>

@ -1,15 +0,0 @@
{
"NAME": "Name",
"TYPE": "Type",
"LOC": "Location",
"UPTIME": "Uptime",
"LOAD": "Load",
"NETWORK": "Network",
"CPU": "CPU",
"RAM": "RAM",
"HDD": "HDD",
"LOADING": "Data loading...",
"WAIT": "Loading data from the server, please wait for a while...",
"LAST_UPDATE": "Last updated: {updatedTime}",
"DAYS": "days"
}

@ -1,15 +0,0 @@
{
"NAME": "名称",
"TYPE": "类型",
"LOC": "地区",
"UPTIME": "运行",
"LOAD": "负载",
"NETWORK": "网络",
"CPU": "CPU",
"RAM": "RAM",
"HDD": "HDD",
"LOADING": "数据加载中...",
"WAIT": "正在首次从服务器端加载监控数据,请稍候...",
"LAST_UPDATE": "数据最后更新时间:{updatedTime}",
"DAYS": "天"
}

@ -1,15 +0,0 @@
{
"NAME": "名稱",
"TYPE": "類型",
"LOC": "地區",
"UPTIME": "運行",
"LOAD": "負載",
"NETWORK": "網絡",
"CPU": "CPU",
"RAM": "RAM",
"HDD": "HDD",
"LOADING": "數據載入中...",
"WAIT": "正在從伺服器載入數據,請稍候...",
"LAST_UPDATE": "數據最後更新時間:{updatedTime}",
"DAYS": "天"
}

@ -1 +0,0 @@
@import '~antd/dist/antd.css';

@ -1,102 +1,52 @@
import "./App.css"; import './App.css';
import intl from "react-intl-universal"; import React, { useState, useEffect } from 'react';
import React, { useState, useEffect } from "react"; import { Layout, Row, Col, Spin } from 'antd';
import { Layout, Row, Col, Spin } from "antd"; import ServerRow from './ServerRow';
import ServerRow from "./ServerRow";
require("intl/locale-data/jsonp/en.js");
require("intl/locale-data/jsonp/zh.js");
const { Header, Footer, Content } = Layout; const { Header, Footer, Content } = Layout;
const App: React.FC = () => { const App: React.FC = () => {
const [serverData, setServerData] = useState({ servers: [], updated: "0" }); const [serverData, setServerData] = useState({servers: [], updated: "0"});
const [isOnline, setIsOnline] = useState(false); const [isOnline, setIsOnline] = useState(false);
useEffect(() => { useEffect(() => {
const fetchData = () => { let fetchData = setInterval(() => {
fetch("json/stats.json") fetch('json/stats.json')
.then((res) => res.json()) .then(res => res.json())
.then((data) => { .then(data => {
setServerData(data); setServerData(data);
setIsOnline(true); setIsOnline(true);
console.log(data);
}) })
.catch((e) => console.log("错误:", e)); .catch(e => console.log('错误:',e))
}; }, 2000);
fetchData();
let itv = setInterval(fetchData, 5000);
return () => { return () => {
clearInterval(itv); clearInterval(fetchData);
}; }
}, []); }, []);
const [initDone, setInitDone] = useState(false);
let currentLocale = navigator.language || "zh-CN";
if (currentLocale === "zh-TW" || currentLocale === "zh-HK") {
currentLocale = "zh-TW";
} else if (currentLocale.startsWith("zh")) {
currentLocale = "zh-CN";
} else {
currentLocale = "en-US";
}
initDone ||
fetch(`locales/${currentLocale}.json`)
.then((res) => res.json())
.then((data) => {
return intl.init({
currentLocale,
locales: {
[currentLocale]: data,
},
});
})
.then(() => {
setInitDone(true);
});
return ( return (
<div className="App"> <div className="App">
<Layout> <Layout>
<Header> <Header>
<div className="logo">ServerStatus</div> <div className="logo">ServerStatus</div>
</Header> </Header>
<Content style={{ background: "#fff" }}> <Content style={{background:'#fff'}}>
<Row justify="center"> <Row type="flex" justify="center">
<Col xs={24} sm={23} md={23} lg={22} xl={20} xxl={16}> <Col xs={24} sm={23} md={23} lg={22} xl={20} xxl={16}>
{initDone ? ( <Spin size="large" spinning={!isOnline} tip="Loading...">
<Spin size="large" spinning={!isOnline} tip="Loading..."> <ServerRow {...serverData} />
<ServerRow {...serverData} /> </Spin>
</Spin>
) : (
<div />
)}
</Col> </Col>
</Row> </Row>
</Content> </Content>
<Footer className="footer"> <Footer className="footer">
<a <a href="https://udev.bid/sergate/" rel="external noopener">WebUI</a> for <a href="https://github.com/BotoX/ServerStatus/" rel="external noopener">ServerStatus</a>, made by <a href="https://www.ofcss.com/" rel="external noopener">Kairee</a>
href="https://github.com/krwu/ServerStatus-web"
rel="external noopener"
>
WebUI
</a>{" "}
for{" "}
<a
href="https://github.com/BotoX/ServerStatus/"
rel="external noopener"
>
ServerStatus
</a>
, made by{" "}
<a href="https://www.ofcss.com/" rel="external noopener">
Kairee
</a>
</Footer> </Footer>
</Layout> </Layout>
</div> </div>
); );
}; }
export default App; export default App;

@ -1,15 +1,5 @@
/* eslint-disable no-param-reassign */
/* eslint-disable no-unused-vars */
/* eslint-disable camelcase */
import intl from 'react-intl-universal';
import React, { ReactNode } from 'react'; import React, { ReactNode } from 'react';
import { import { Row, Col, Tag, Progress, Tooltip, Alert } from 'antd';
Row, Col, Progress, Tooltip, Alert,
} from 'antd';
import {
CheckCircleFilled,
WarningFilled
} from '@ant-design/icons';
interface RawData { interface RawData {
name: string; name: string;
@ -37,155 +27,122 @@ interface SergateData {
updated?: string; updated?: string;
} }
const resGutter = { xs: 8, sm: 16, md: 24, lg: 32 };
function onlineTag(online: boolean, label: string): React.ReactElement { function onlineTag(online: boolean, label: string): React.ReactElement {
//return <Tag color={online ? '#87d068' : '#f50'}>{online ? 'O N' : 'OFF'}</Tag>; return <Tag color={ online ? '#87d068' : '#f50'}>{ online ? 'ON' : 'OFF' }</Tag>
return online ? <CheckCircleFilled /> : <WarningFilled />;
} }
function transUptime(uptime: string): string { function transUptime(uptime: string): string {
uptime = uptime || ''; uptime = uptime || '';
return uptime.replace(/days|day/, intl.get('DAYS')); return uptime.replace('days', '天');
} }
function networkUnit(network: number): string { function networkUnit(network: number): string {
network = network || 0; network = network || 0;
if (network < 1000) { if (network < 1000) {
return `${network.toFixed(0)}B`; return network.toFixed(0) + 'B';
} if (network < 1000 * 1000) { } else if (network < 1000*1000) {
return `${(network / 1000).toFixed(0)}K`; return (network / 1000).toFixed(0) + 'K';
} else {
return (network / 1000 / 1000).toFixed(0) + 'M';
} }
return `${(network / 1000 / 1000).toFixed(0)}M`;
} }
function bytesToSize(bytes: number, precision: number = 1, si: number = 0) { function bytesToSize(bytes: number, precision: number = 1, si: number = 0) {
const kilobyte = si === 0 ? 1024 : 1000; const kilobyte = si === 0 ? 1024 : 1000;
const megabyte = kilobyte * kilobyte; const megabyte = kilobyte * kilobyte;
const gigabyte = megabyte * kilobyte; const gigabyte = megabyte * kilobyte;
const terabyte = gigabyte * kilobyte; const terabyte = gigabyte * kilobyte;
bytes = bytes || 0; bytes = bytes || 0;
bytes *= 1024; bytes *= 1024
if (bytes >= 0 && bytes < kilobyte) { if ( bytes >= 0 && bytes < kilobyte) {
return `${bytes}B`; return bytes + 'B';
} }
if (bytes >= kilobyte && bytes < megabyte) { if (bytes >= kilobyte && bytes < megabyte) {
return `${(bytes / kilobyte).toFixed(precision)}K`; return (bytes / kilobyte).toFixed(precision) + 'K';
} }
if (bytes >= megabyte && bytes < gigabyte) { if (bytes >= megabyte && bytes < gigabyte) {
return `${(bytes / megabyte).toFixed(precision)}M`; return (bytes / megabyte).toFixed(precision) + 'M';
} }
if (bytes >= gigabyte && bytes < terabyte) { if (bytes >= gigabyte && bytes < terabyte) {
return `${(bytes / gigabyte).toFixed(precision)}G`; return (bytes / gigabyte).toFixed(precision) + 'G';
} }
return `${(bytes / terabyte).toFixed(precision)}T`; return (bytes / terabyte).toFixed(precision) + 'T';
} }
function memTips(props: RawData): ReactNode { function memTips(props: RawData): ReactNode {
const { const { memory_used, memory_total, swap_used, swap_total } = props;
memory_used, memory_total, swap_used, swap_total, return (<dl>
} = props; <dt>Mem:</dt>
return ( <dd>{bytesToSize(memory_used)}/{bytesToSize(memory_total)}</dd>
<dl> <dt>Swap:</dt>
<dt>Mem:</dt> <dd>{bytesToSize(swap_used)}/{bytesToSize(swap_total)}</dd>
<dd> </dl>);
{bytesToSize(memory_used)}
/
{bytesToSize(memory_total)}
</dd>
<dt>Swap:</dt>
<dd>
{bytesToSize(swap_used)}
/
{bytesToSize(swap_total)}
</dd>
</dl>
);
} }
function formatDateTime(time: Date) { const Flag: React.FC<{ loc: string}> = ({ loc }) => (
const year = time.getFullYear(); <i className={`flag-icon flag-icon-${loc.toLowerCase()}`}></i>
const month = (`${time.getMonth() + 1}`).padStart(2, '0'); )
const day = (`${time.getDate()}`).padStart(2, '0');
const hour = (`${time.getHours()}`).padStart(2, '0');
const minute = (`${time.getMinutes()}`).padStart(2, '0');
const second = (`${time.getSeconds()}`).padStart(2, '0');
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
}
interface FlagProps {
loc: string
}
const Flag: React.FC<FlagProps> = ({ loc }: FlagProps) => (
<i className={`flag-icon flag-icon-${loc.toLowerCase()}`} />
);
const ServerRow: React.FC<SergateData> = (props: SergateData) => { const ServerRow: React.FC<SergateData> = (props) => {
let { servers, updated } = props; let { servers, updated } = props;
servers = servers || []; servers = servers || [];
updated = updated || '0'; updated = updated || '0';
const updatedInt = parseInt(updated, 10) * 1000; const updatedTime = parseInt(updated) * 1000;
const updatedTime = formatDateTime(new Date(updatedInt));
let idx = 1; return (<div className="sergate">
<Row className="sr-head" type="flex" justify="space-around" gutter={8}>
return ( <Col xs={3} sm={3} md={1} lg={1}>IPv4</Col>
<div className="sergate"> <Col xs={0} sm={0} md={0} lg={1}>IPv6</Col>
<Row className="sr-head" justify="space-around" gutter={10}> <Col xs={3} sm={3} md={3} lg={2}>节点</Col>
<Col xs={3} sm={3} md={1} lg={1}>IPv4</Col> <Col xs={3} sm={3} md={2} lg={2}>类型</Col>
<Col xs={0} sm={0} md={1} lg={1}>IPv6</Col> <Col xs={3} sm={2} md={2} lg={2}>地区</Col>
<Col xs={5} sm={4} md={2} lg={2}>{intl.get('NAME')}</Col> <Col xs={3} sm={4} md={3} lg={2}>运行</Col>
<Col xs={0} sm={2} md={2} lg={2}>{intl.get('TYPE')}</Col> <Col xs={0} sm={0} md={0} lg={2}>负载</Col>
<Col xs={2} sm={2} md={1} lg={1}>{intl.get('LOC')}</Col> <Col xs={0} sm={0} md={4} lg={3}>网络</Col>
<Col xs={4} sm={4} md={3} lg={2}>{intl.get('UPTIME')}</Col> <Col xs={3} sm={3} md={3} lg={3}>CPU</Col>
<Col xs={0} sm={0} md={0} lg={1}>{intl.get('LOAD')}</Col> <Col xs={3} sm={3} md={3} lg={3}>RAM</Col>
<Col xs={0} sm={0} md={5} lg={4}>{intl.get('NETWORK')}</Col> <Col xs={3} sm={3} md={3} lg={3}>HDD</Col>
<Col xs={3} sm={3} md={3} lg={3}>{intl.get('CPU')}</Col> </Row>
<Col xs={3} sm={3} md={3} lg={3}>{intl.get('RAM')}</Col> {servers && servers.length > 0 ? servers.map(server => (
<Col xs={4} sm={3} md={3} lg={3}>{intl.get('HDD')}</Col> <Row key={server.host} className="sr-body" type="flex" justify="center" gutter={resGutter}>
<Col xs={3} sm={3} md={1} lg={1}>{ onlineTag(server.online4, 'IPv4') }</Col>
<Col xs={0} sm={0} md={0} lg={1}>{ onlineTag(server.online6, 'IPv6') }</Col>
<Col xs={3} sm={3} md={3} lg={2}>{ server.host }</Col>
<Col xs={3} sm={3} md={2} lg={2}>{ server.type }</Col>
<Col xs={3} sm={2} md={2} lg={2}><Flag loc={ server.location } /></Col>
<Col xs={3} sm={4} md={3} lg={2}>{ transUptime(server.uptime) }</Col>
<Col xs={0} sm={0} md={0} lg={2}>{ server.load }</Col>
<Col xs={0} sm={0} md={4} lg={3}>{ networkUnit(server.network_rx) }↓ | ↑{ networkUnit(server.network_tx)}</Col>
<Col xs={3} sm={3} md={3} lg={3}>
<Progress strokeWidth={12} percent={server.cpu} status="active" />
</Col>
<Col xs={3} sm={3} md={3} lg={3}>
<Tooltip placement="left" title={memTips(server)}>
<Progress strokeWidth={12} percent={parseFloat((server.memory_used / server.memory_total * 100).toFixed(1))} status="active" />
</Tooltip>
</Col>
<Col xs={3} sm={3} md={3} lg={3}>
<Tooltip placement="left" title={bytesToSize(server.hdd_used*1024) + '/' + bytesToSize(server.hdd_total*1024)}>
<Progress strokeWidth={12} percent={parseFloat((server.hdd_used / server.hdd_total * 100).toFixed(1))} status="active" />
</Tooltip>
</Col>
</Row> </Row>
{servers && servers.length > 0 ? servers.map((server) => ( )) : <Alert
<Row key={server.host} className="sr-body" justify="space-around" gutter={10}> showIcon={true}
<span className="col-num">{idx++}</span> type="info"
<Col xs={3} sm={3} md={1} lg={1}>{onlineTag(server.online4, 'IPv4')}</Col> message="数据加载中"
<Col xs={0} sm={0} md={1} lg={1}>{onlineTag(server.online6, 'IPv6')}</Col> description="正在首次从服务器段加载监控数据,请稍候。"
<Col xs={5} sm={4} md={2} lg={2}>{server.host || server.name}</Col> />}
<Col xs={0} sm={2} md={2} lg={2}>{server.type}</Col> {updatedTime > 0 && <Alert className="lastUpdated" type="info" message={'数据最后更新时间:'+new Date(updatedTime).toISOString()} />}
<Col xs={2} sm={2} md={1} lg={1}><Flag loc={server.location} /></Col> </div>)
<Col xs={4} sm={4} md={3} lg={2}>{transUptime(server.uptime)}</Col> };
<Col xs={0} sm={0} md={0} lg={1}>{server.load}</Col>
<Col xs={0} sm={0} md={5} lg={4}>
{networkUnit(server.network_rx)}
↓ | ↑
{networkUnit(server.network_tx)}
</Col>
<Col xs={3} sm={3} md={3} lg={3}>
<Progress className="sg-progress" strokeLinecap="square" strokeWidth={12} percent={server.cpu} status="active" />
</Col>
<Col xs={3} sm={3} md={3} lg={3}>
<Tooltip placement="left" title={memTips(server)}>
<Progress className="sg-progress" strokeLinecap="square" strokeWidth={12} percent={parseFloat(((server.memory_used / server.memory_total) * 100).toFixed(1))} status="active" />
</Tooltip>
</Col>
<Col xs={4} sm={3} md={3} lg={3}>
<Tooltip placement="left" title={`${bytesToSize(server.hdd_used * 1024)}/${bytesToSize(server.hdd_total * 1024)}`}>
<Progress className="sg-progress" strokeLinecap="square" strokeWidth={12} percent={parseFloat(((server.hdd_used / server.hdd_total) * 100).toFixed(1))} status="active" />
</Tooltip>
</Col>
</Row>
)) : (
<Alert
showIcon
type="info"
message={intl.get('LOADING')}
description={intl.get('WAIT')}
/>
)}
{updatedInt > 0 && <Alert className="lastUpdated" type="info" message={intl.get('LAST_UPDATE', { updatedTime })} />}
</div>
);
};
export default ServerRow; export default ServerRow;

@ -1,6 +1,7 @@
body { body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
'Helvetica Neue', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol';
} }
.logo { .logo {
color: #fff; color: #fff;
@ -10,15 +11,9 @@ body {
.sergate { .sergate {
margin: 16px 0; margin: 16px 0;
} }
.sergate .ant-row {
position: relative;
flex-wrap: nowrap;
}
.sergate .sg-progress .ant-progress-outer {
margin-right: calc(-3em - 8px);
padding-right: calc(3em + 8px);
}
.sr-head { .sr-head {
font-weight: bold;
padding-top: 8px; padding-top: 8px;
padding-bottom: 8px; padding-bottom: 8px;
} }
@ -31,28 +26,12 @@ body {
padding-bottom: 8px; padding-bottom: 8px;
border-top: 1px solid #ebebeb; border-top: 1px solid #ebebeb;
} }
.col-num {
position: absolute;
width: 16px;
line-height: 40px;
left: -16px;
top: 0;
text-align: right;
}
.sergate .lastUpdated { .sergate .lastUpdated {
margin-top: 16px; margin-top: 16px;
text-align: center; text-align: center;
} }
.sergate .anticon-check-circle {
color: #389e0d;
}
.sergate .anticon-warning {
color: #cf1322;
}
.ant-layout .footer { .ant-layout .footer {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
@ -75,29 +54,19 @@ body {
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.logo {
text-align: center;
}
.sr-head { .sr-head {
font-size: 0.8rem; font-size: 0.8rem;
} }
.sr-body .ant-col { .sr-body .ant-col {
font-size: 0.8rem; font-size: 0.8rem;
} }
.sergate .ant-tag {
margin-right: 0;
}
}
@media (max-width: 900px) {
.sergate .ant-col .ant-progress-outer { .sergate .ant-col .ant-progress-outer {
display: none; display: none;
} }
.sergate .ant-col .ant-progress-text { .sergate .ant-col .ant-progress-text {
margin-left: 0; margin-left: 0;
} }
.sergate .ant-tag {
.sr-head { margin-right:0;
font-size: 12px;
} }
} }

@ -1,17 +1,12 @@
import { StrictMode } from 'react'; import React from 'react';
import { createRoot } from 'react-dom/client'; import ReactDOM from 'react-dom';
import './index.css'; import './index.css';
import App from './App'; import App from './App';
// import reportWebVitals from './reportWebVitals'; import * as serviceWorker from './serviceWorker';
const el = document.getElementById('root'); ReactDOM.render(<App />, document.getElementById('root'));
if (el === null) {
throw new Error('root container missing in index.html');
}
const root = createRoot(el);
root.render(<StrictMode><App /></StrictMode>);
// If you want to start measuring performance in your app, pass a function // If you want your app to work offline and load faster, you can change
// to log results (for example: reportWebVitals(console.log)) // unregister() to register() below. Note this comes with some pitfalls.
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals // Learn more about service workers: https://bit.ly/CRA-PWA
// reportWebVitals(); serviceWorker.unregister();

@ -0,0 +1,143 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
type Config = {
onSuccess?: (registration: ServiceWorkerRegistration) => void;
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};
export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
(process as { env: { [key: string]: string } }).env.PUBLIC_URL,
window.location.href
);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl: string, config?: Config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
}

@ -12,13 +12,12 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"strict": true, "strict": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"jsx": "react-jsx" "jsx": "react"
}, },
"include": [ "include": [
"src" "src"

Loading…
Cancel
Save