0.1.1
This commit is contained in:
commit
314eee72f2
10
.babelrc
Normal file
10
.babelrc
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"presets": [
|
||||
["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "5.12.0"
|
||||
}
|
||||
}]
|
||||
],
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
64
.gitignore
vendored
Normal file
64
.gitignore
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# binary out
|
||||
bin
|
||||
|
||||
# VS Code
|
||||
.vscode
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Yige
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
67
check.php
Normal file
67
check.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/*
|
||||
* 版本号比较 by sam 20170412
|
||||
* @param $version1 版本A 如:5.3.2
|
||||
* @param $version2 版本B 如:5.3.0
|
||||
* @return int -1版本A小于版本B , 0版本A等于版本B, 1版本A大于版本B
|
||||
*
|
||||
* 版本号格式注意:
|
||||
* 1.要求只包含:点和大于等于0小于等于2147483646的整数 的组合
|
||||
* 2.boole型 true置1,false置0
|
||||
* 3.不设位默认补0计算,如:版本号5等于版号5.0.0
|
||||
* 4.不包括数字 或 负数 的版本号 ,统一按0处理
|
||||
*
|
||||
* @example:
|
||||
* if (versionCompare('5.2.2','5.3.0')<0) {
|
||||
* echo '版本1小于版本2';
|
||||
* }
|
||||
*/
|
||||
function versionCompare($versionA, $versionB)
|
||||
{
|
||||
if ($versionA > 2147483646 || $versionB > 2147483646) {
|
||||
throw new Exception('版本号,位数太大暂不支持!', '101');
|
||||
}
|
||||
$dm = '.';
|
||||
$verListA = explode($dm, (string) $versionA);
|
||||
$verListB = explode($dm, (string) $versionB);
|
||||
|
||||
$len = max(count($verListA), count($verListB));
|
||||
$i = -1;
|
||||
while ($i++ < $len) {
|
||||
$verListA[$i] = intval(@$verListA[$i]);
|
||||
if ($verListA[$i] < 0) {
|
||||
$verListA[$i] = 0;
|
||||
}
|
||||
$verListB[$i] = intval(@$verListB[$i]);
|
||||
if ($verListB[$i] < 0) {
|
||||
$verListB[$i] = 0;
|
||||
}
|
||||
|
||||
if ($verListA[$i] > $verListB[$i]) {
|
||||
return 1;
|
||||
} else if ($verListA[$i] < $verListB[$i]) {
|
||||
return -1;
|
||||
} else if ($i == ($len - 1)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$version = $_GET['version'];
|
||||
$latestVersion = "0.1.1";
|
||||
|
||||
if (versionCompare($version, $latestVersion) < 0) {
|
||||
$result = [
|
||||
'status' => 1,
|
||||
'downloadURL' => 'https://tool.y-bi.top/server-monitor-xp-' . $latestVersion . '.zip',
|
||||
'newVersion' => $latestVersion,
|
||||
];
|
||||
} else {
|
||||
$result = [
|
||||
'status' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-Type:application/json; charset=utf-8');
|
||||
|
||||
echo json_encode($result, JSON_UNESCAPED_SLASHES);
|
8
config.yml
Normal file
8
config.yml
Normal file
@ -0,0 +1,8 @@
|
||||
version: 0.1.1
|
||||
update-url: 'https://tool.y-bi.top/check.php'
|
||||
node:
|
||||
version: 5.12.0
|
||||
support-old-win: true
|
||||
auto-restart: true
|
||||
report-address:
|
||||
- 'https://www.nodejs.pw'
|
26
dist/app.js
vendored
Normal file
26
dist/app.js
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
var _config = require("./config");
|
||||
|
||||
var _boot = _interopRequireDefault(require("./boot"));
|
||||
|
||||
var _http = _interopRequireDefault(require("http"));
|
||||
|
||||
var server = _http.default.createServer(function (req, res) {
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.end(JSON.stringify({
|
||||
status: 1
|
||||
}));
|
||||
});
|
||||
|
||||
(0, _boot.default)().then(function (r) {
|
||||
// Start boot
|
||||
server.listen(_config.SERVER.port, _config.SERVER.host, function () {
|
||||
console.log(`Server running at http://${_config.SERVER.host}:${_config.SERVER.port}/`);
|
||||
});
|
||||
}).catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
188
dist/boot.js
vendored
Normal file
188
dist/boot.js
vendored
Normal file
@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
||||
|
||||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
||||
|
||||
var _fs = _interopRequireDefault(require("fs"));
|
||||
|
||||
var _axios = _interopRequireDefault(require("axios"));
|
||||
|
||||
var _package = _interopRequireDefault(require("../package.json"));
|
||||
|
||||
var _crypto = _interopRequireDefault(require("crypto"));
|
||||
|
||||
var _gather = _interopRequireDefault(require("./control/gather"));
|
||||
|
||||
var version = _package.default.version;
|
||||
|
||||
var request = _axios.default.create();
|
||||
|
||||
var apiURLs = {
|
||||
apiURL: process.env.API_URL,
|
||||
apiKEY: process.env.API_KEY
|
||||
};
|
||||
var AGENT_VERSION = process.env.AGENT_VERSION;
|
||||
var AGENT_PORT = process.env.AGENT_PORT;
|
||||
var isDev = process.env.NODE_ENV !== 'production'; // 系统配置
|
||||
|
||||
var rebootNodeJS =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
var _ref = (0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee() {
|
||||
var _ref2, data;
|
||||
|
||||
return _regenerator.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
if (!isDev) {
|
||||
_context.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
console.log('当前是开发环境,无法自动重启Node.js');
|
||||
_context.next = 16;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
_context.prev = 4;
|
||||
_context.next = 7;
|
||||
return request.get(`http://127.0.0.1:${AGENT_PORT}/system/cmd?action=restart`);
|
||||
|
||||
case 7:
|
||||
_ref2 = _context.sent;
|
||||
data = _ref2.data;
|
||||
console.log('自动重启Node.js返回数据:', data);
|
||||
_context.next = 16;
|
||||
break;
|
||||
|
||||
case 12:
|
||||
_context.prev = 12;
|
||||
_context.t0 = _context["catch"](4);
|
||||
console.log(_context.t0);
|
||||
console.log('自动重启Node.js失败');
|
||||
|
||||
case 16:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, null, [[4, 12]]);
|
||||
}));
|
||||
|
||||
return function rebootNodeJS() {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}();
|
||||
|
||||
var checkVersion =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
var _ref3 = (0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee2(version) {
|
||||
var apiURL, _ref4, data;
|
||||
|
||||
return _regenerator.default.wrap(function _callee2$(_context2) {
|
||||
while (1) {
|
||||
switch (_context2.prev = _context2.next) {
|
||||
case 0:
|
||||
apiURL = 'https://tool.y-bi.top/check.php?version=' + version;
|
||||
_context2.next = 3;
|
||||
return request.get(apiURL);
|
||||
|
||||
case 3:
|
||||
_ref4 = _context2.sent;
|
||||
data = _ref4.data;
|
||||
|
||||
if (!(data.status === 1)) {
|
||||
_context2.next = 10;
|
||||
break;
|
||||
}
|
||||
|
||||
// 有更新
|
||||
console.log('发现新版系统,正在重启Node.js...');
|
||||
_context2.next = 9;
|
||||
return rebootNodeJS();
|
||||
|
||||
case 9:
|
||||
return _context2.abrupt("return", true);
|
||||
|
||||
case 10:
|
||||
return _context2.abrupt("return", false);
|
||||
|
||||
case 11:
|
||||
case "end":
|
||||
return _context2.stop();
|
||||
}
|
||||
}
|
||||
}, _callee2);
|
||||
}));
|
||||
|
||||
return function checkVersion(_x) {
|
||||
return _ref3.apply(this, arguments);
|
||||
};
|
||||
}();
|
||||
|
||||
var fileIsExists = function fileIsExists(path) {
|
||||
try {
|
||||
_fs.default.accessSync(path);
|
||||
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var checkAndInstallWhoami = function checkAndInstallWhoami() {
|
||||
if (!fileIsExists('C:\\Windows\\system32\\whoami.exe') && !fileIsExists('C:\\Windows\\system32\\whoami.bat')) {
|
||||
console.log('whoami 命令不存在,正在写入');
|
||||
var batContent = `@echo off
|
||||
echo %computername%\%username%
|
||||
exit /B`;
|
||||
|
||||
_fs.default.writeFileSync('C:\\Windows\\system32\\whoami.bat', batContent);
|
||||
}
|
||||
};
|
||||
|
||||
var _default =
|
||||
/*#__PURE__*/
|
||||
(0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee3() {
|
||||
return _regenerator.default.wrap(function _callee3$(_context3) {
|
||||
while (1) {
|
||||
switch (_context3.prev = _context3.next) {
|
||||
case 0:
|
||||
console.log('AGENT_VERSION:', AGENT_VERSION);
|
||||
checkAndInstallWhoami();
|
||||
setInterval(function () {
|
||||
checkVersion(version || '0.0.1'); // sync
|
||||
}, 120000);
|
||||
(0, _gather.default)({
|
||||
version: version || '0.0.1',
|
||||
apiURLs,
|
||||
isDev,
|
||||
AGENT_PORT,
|
||||
AGENT_VERSION
|
||||
}); // sync
|
||||
|
||||
case 4:
|
||||
case "end":
|
||||
return _context3.stop();
|
||||
}
|
||||
}
|
||||
}, _callee3);
|
||||
}));
|
||||
|
||||
exports.default = _default;
|
24
dist/config.js
vendored
Normal file
24
dist/config.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.SERVER = exports.SYSTEM = void 0;
|
||||
|
||||
var pack = require('../package');
|
||||
|
||||
var isDev = process.env.NODE_ENV !== 'production'; // 系统配置
|
||||
|
||||
var SYSTEM = {
|
||||
version: pack.version,
|
||||
sessionKey: process.env.JWT_SECRET || '123',
|
||||
// 生产环境务必随机设置一个值
|
||||
scheme: [isDev ? 'http' : 'https']
|
||||
};
|
||||
exports.SYSTEM = SYSTEM;
|
||||
var SERVER = {
|
||||
port: isDev ? process.env.PORT || '65522' : process.env.PORT || '65522',
|
||||
// API服务器监听的端口号
|
||||
host: '0.0.0.0'
|
||||
};
|
||||
exports.SERVER = SERVER;
|
91
dist/control/gather.js
vendored
Normal file
91
dist/control/gather.js
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
||||
|
||||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
||||
|
||||
var _os = _interopRequireDefault(require("os"));
|
||||
|
||||
var _axios = _interopRequireDefault(require("axios"));
|
||||
|
||||
var _child_process = require("child_process");
|
||||
|
||||
var request = _axios.default.create();
|
||||
|
||||
var _default =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
var _ref = (0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee2(conf) {
|
||||
var gather;
|
||||
return _regenerator.default.wrap(function _callee2$(_context2) {
|
||||
while (1) {
|
||||
switch (_context2.prev = _context2.next) {
|
||||
case 0:
|
||||
gather = function gather(conf) {
|
||||
setTimeout(
|
||||
/*#__PURE__*/
|
||||
(0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee() {
|
||||
var who, version, apiURLs, AGENT_VERSION, _ref3, data;
|
||||
|
||||
return _regenerator.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
who = (0, _child_process.execSync)('whoami');
|
||||
version = conf.version, apiURLs = conf.apiURLs, AGENT_VERSION = conf.AGENT_VERSION;
|
||||
_context.next = 4;
|
||||
return request.put(apiURLs.apiURL + 'gather', {
|
||||
version,
|
||||
AGENT_VERSION,
|
||||
user: who.toString('utf8').trim('\r\n'),
|
||||
arch: _os.default.arch(),
|
||||
type: _os.default.type(),
|
||||
platform: _os.default.platform()
|
||||
});
|
||||
|
||||
case 4:
|
||||
_ref3 = _context.sent;
|
||||
data = _ref3.data;
|
||||
|
||||
if (data.status === 1) {
|
||||
console.log('发现监控系统地址');
|
||||
}
|
||||
|
||||
gather(conf);
|
||||
|
||||
case 8:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee);
|
||||
})), 20000);
|
||||
};
|
||||
|
||||
gather(conf);
|
||||
|
||||
case 2:
|
||||
case "end":
|
||||
return _context2.stop();
|
||||
}
|
||||
}
|
||||
}, _callee2);
|
||||
}));
|
||||
|
||||
return function (_x) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}();
|
||||
|
||||
exports.default = _default;
|
5
dist/dev.js
vendored
Normal file
5
dist/dev.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
require('@babel/register');
|
||||
|
||||
require('./app');
|
44
dist/service/home.js
vendored
Normal file
44
dist/service/home.js
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
||||
|
||||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
||||
|
||||
var _default = {
|
||||
method: 'GET',
|
||||
path: '/',
|
||||
config: {
|
||||
auth: false
|
||||
},
|
||||
|
||||
handler() {
|
||||
return (0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee() {
|
||||
return _regenerator.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
return _context.abrupt("return", {
|
||||
status: 1,
|
||||
massage: 'Please consult the API documentation.'
|
||||
});
|
||||
|
||||
case 1:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee);
|
||||
}))();
|
||||
}
|
||||
|
||||
};
|
||||
exports.default = _default;
|
32
dist/service/index.js
vendored
Normal file
32
dist/service/index.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _fs = _interopRequireDefault(require("fs"));
|
||||
|
||||
var _path = _interopRequireDefault(require("path"));
|
||||
|
||||
var modules = [];
|
||||
|
||||
var files = _fs.default.readdirSync(__dirname).filter(function (file) {
|
||||
return file.match(/\.(json|js)$/);
|
||||
});
|
||||
|
||||
files.forEach(function (key) {
|
||||
if (key === 'index.js') return; // const content = require(path.join(__dirname, key)).default
|
||||
|
||||
var content = require(_path.default.join(__dirname, key)).default;
|
||||
|
||||
if (Array.isArray(content)) {
|
||||
modules.push(...content);
|
||||
} else {
|
||||
modules.push(content);
|
||||
}
|
||||
});
|
||||
var _default = modules;
|
||||
exports.default = _default;
|
48
dist/service/stats.js
vendored
Normal file
48
dist/service/stats.js
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
||||
|
||||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
||||
|
||||
var _Proc = _interopRequireDefault(require("../lib/Proc"));
|
||||
|
||||
var _default = {
|
||||
method: 'GET',
|
||||
path: '/stats',
|
||||
config: {
|
||||
auth: false
|
||||
},
|
||||
|
||||
handler() {
|
||||
return (0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee() {
|
||||
var proc;
|
||||
return _regenerator.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
proc = new _Proc.default();
|
||||
return _context.abrupt("return", {
|
||||
status: 1,
|
||||
result: proc.info
|
||||
});
|
||||
|
||||
case 2:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee);
|
||||
}))();
|
||||
}
|
||||
|
||||
};
|
||||
exports.default = _default;
|
59
dist/service/status.js
vendored
Normal file
59
dist/service/status.js
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
||||
|
||||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
||||
|
||||
var _os = _interopRequireDefault(require("os"));
|
||||
|
||||
var _child_process = require("child_process");
|
||||
|
||||
var _default = {
|
||||
method: 'GET',
|
||||
path: '/status',
|
||||
config: {
|
||||
auth: false
|
||||
},
|
||||
|
||||
handler() {
|
||||
return (0, _asyncToGenerator2.default)(
|
||||
/*#__PURE__*/
|
||||
_regenerator.default.mark(function _callee() {
|
||||
var who;
|
||||
return _regenerator.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
who = (0, _child_process.execSync)('whoami');
|
||||
return _context.abrupt("return", {
|
||||
status: 1,
|
||||
msg: 'running',
|
||||
result: {
|
||||
user: who.toString('utf8').trim('\r\n'),
|
||||
arch: _os.default.arch(),
|
||||
type: _os.default.type(),
|
||||
platform: _os.default.platform(),
|
||||
totalmem: _os.default.totalmem(),
|
||||
freemem: _os.default.freemem(),
|
||||
cups: _os.default.cpus()
|
||||
}
|
||||
});
|
||||
|
||||
case 2:
|
||||
case "end":
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee);
|
||||
}))();
|
||||
}
|
||||
|
||||
};
|
||||
exports.default = _default;
|
56
package.json
Normal file
56
package.json
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "server-monitor-xp",
|
||||
"version": "0.1.1",
|
||||
"description": "Server monitor for windows xp.",
|
||||
"main": "dist/app.js",
|
||||
"scripts": {
|
||||
"dev": "cross-env HOST=0.0.0.0 PORT=65534 nodemon src/dev.js",
|
||||
"build": "babel src -d dist",
|
||||
"start": "cross-env NODE_ENV=production HOST=0.0.0.0 PORT=65522 node dist/app.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/yi-ge/server-monitor-xp.git"
|
||||
},
|
||||
"keywords": [
|
||||
"server",
|
||||
"monitor"
|
||||
],
|
||||
"author": "yi-ge <a@wyr.me>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/yi-ge/server-monitor-xp/issues"
|
||||
},
|
||||
"homepage": "https://github.com/yi-ge/server-monitor-xp#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.5",
|
||||
"axios": "^0.19.0",
|
||||
"cross-env": "^5.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.5.5",
|
||||
"@babel/core": "^7.5.5",
|
||||
"@babel/plugin-transform-runtime": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"@babel/register": "^7.5.5",
|
||||
"nodemon": "^1.19.1"
|
||||
},
|
||||
"nodemonConfig": {
|
||||
"ignore": [
|
||||
".git",
|
||||
"node_modules/**/node_modules"
|
||||
],
|
||||
"delay": "2500",
|
||||
"env": {
|
||||
"NODE_ENV": "development",
|
||||
"AGENT_VERSION": "0.0.1",
|
||||
"AGENT_PORT": "60000",
|
||||
"API_URL": "https://server-0.sercretcore.cn/api/",
|
||||
"API_KEY": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxEUN1DZZ/XU2J6+3EoCX\n6ZQExSyGrJlmcq2s4sxAqThJVGAv4BYqCQjnigUGaLF4+2khGHVXrx4LhwnW54iq\nV3V3Xq59H0Cj3oGGWgKxSOM62xxfizmc1Og/6uAwZTAX4oCsgx5SMaFQbAU5ensM\nVEX9CetXSGhc1bbS23kEHAkjJ0NryRl7DR/ilFKO5pAjTGEzP4aTkF/D3Eu3z15U\nwdkf2WisEsANVTEnNHu2qvdiXGzRSLNF4mVFNO3AsgfnbgXzlN0feQ1HbH+J7Ue5\neHleCGhfS/PGFP3lQ4sA0hB4B/5eZ6ROo8YEuQiNTz+UMFteeGymTgFu2sOwLE10\nwQIDAQAB\n-----END PUBLIC KEY-----"
|
||||
},
|
||||
"ext": "js,json"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 5.12.0"
|
||||
}
|
||||
}
|
BIN
server-monitor-xp-0.1.0.zip
Normal file
BIN
server-monitor-xp-0.1.0.zip
Normal file
Binary file not shown.
BIN
server-monitor-xp-0.1.1.zip
Normal file
BIN
server-monitor-xp-0.1.1.zip
Normal file
Binary file not shown.
21
src/app.js
Normal file
21
src/app.js
Normal file
@ -0,0 +1,21 @@
|
||||
import {
|
||||
SERVER, SYSTEM
|
||||
} from './config'
|
||||
import boot from './boot'
|
||||
import http from 'http'
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.end(JSON.stringify({
|
||||
status: 1
|
||||
}));
|
||||
});
|
||||
|
||||
boot().then(r => { // Start boot
|
||||
server.listen(SERVER.port, SERVER.host, () => {
|
||||
console.log(`Server running at http://${SERVER.host}:${SERVER.port}/`);
|
||||
});
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
81
src/boot.js
Normal file
81
src/boot.js
Normal file
@ -0,0 +1,81 @@
|
||||
import fs from 'fs'
|
||||
import axios from 'axios'
|
||||
import pack from '../package.json'
|
||||
import crypto from 'crypto'
|
||||
import gather from './control/gather'
|
||||
|
||||
const version = pack.version
|
||||
const request = axios.create()
|
||||
const apiURLs = {
|
||||
apiURL: process.env.API_URL,
|
||||
apiKEY: process.env.API_KEY
|
||||
}
|
||||
const AGENT_VERSION = process.env.AGENT_VERSION
|
||||
const AGENT_PORT = process.env.AGENT_PORT
|
||||
const isDev = process.env.NODE_ENV !== 'production' // 系统配置
|
||||
|
||||
const rebootNodeJS = async () => {
|
||||
if (isDev) {
|
||||
console.log('当前是开发环境,无法自动重启Node.js')
|
||||
} else {
|
||||
try {
|
||||
const { data } = await request.get(`http://127.0.0.1:${AGENT_PORT}/system/cmd?action=restart`)
|
||||
console.log('自动重启Node.js返回数据:', data)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
console.log('自动重启Node.js失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const checkVersion = async (version) => {
|
||||
const apiURL = 'https://tool.y-bi.top/check.php?version=' + version
|
||||
|
||||
const { data } = await request.get(apiURL)
|
||||
|
||||
if (data.status === 1) { // 有更新
|
||||
console.log('发现新版系统,正在重启Node.js...')
|
||||
await rebootNodeJS()
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const fileIsExists = (path) => {
|
||||
try {
|
||||
fs.accessSync(path)
|
||||
return true
|
||||
} catch (_) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const checkAndInstallWhoami = () => {
|
||||
if (!fileIsExists('C:\\Windows\\system32\\whoami.exe') && !fileIsExists('C:\\Windows\\system32\\whoami.bat')) {
|
||||
console.log('whoami 命令不存在,正在写入')
|
||||
const batContent = `@echo off
|
||||
echo %computername%\%username%
|
||||
exit /B`
|
||||
|
||||
fs.writeFileSync('C:\\Windows\\system32\\whoami.bat', batContent)
|
||||
}
|
||||
}
|
||||
|
||||
export default async () => {
|
||||
console.log('AGENT_VERSION:', AGENT_VERSION)
|
||||
|
||||
checkAndInstallWhoami()
|
||||
|
||||
setInterval(() => {
|
||||
checkVersion(version || '0.0.1') // sync
|
||||
}, 120000)
|
||||
|
||||
gather({
|
||||
version: version || '0.0.1',
|
||||
apiURLs,
|
||||
isDev,
|
||||
AGENT_PORT,
|
||||
AGENT_VERSION
|
||||
}) // sync
|
||||
}
|
14
src/config.js
Normal file
14
src/config.js
Normal file
@ -0,0 +1,14 @@
|
||||
const pack = require('../package')
|
||||
const isDev = process.env.NODE_ENV !== 'production'
|
||||
|
||||
// 系统配置
|
||||
export const SYSTEM = {
|
||||
version: pack.version,
|
||||
sessionKey: process.env.JWT_SECRET || '123', // 生产环境务必随机设置一个值
|
||||
scheme: [isDev ? 'http' : 'https']
|
||||
}
|
||||
|
||||
export const SERVER = {
|
||||
port: isDev ? process.env.PORT || '65522' : (process.env.PORT || '65522'), // API服务器监听的端口号
|
||||
host: '0.0.0.0'
|
||||
}
|
30
src/control/gather.js
Normal file
30
src/control/gather.js
Normal file
@ -0,0 +1,30 @@
|
||||
import os from 'os'
|
||||
import axios from 'axios'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
const request = axios.create()
|
||||
|
||||
export default async (conf) => {
|
||||
const gather = (conf) => {
|
||||
setTimeout(async () => {
|
||||
const who = execSync('whoami')
|
||||
const { version, apiURLs, AGENT_VERSION } = conf
|
||||
const { data } = await request.put(apiURLs.apiURL + 'gather', {
|
||||
version,
|
||||
AGENT_VERSION,
|
||||
user: who.toString('utf8').trim('\r\n'),
|
||||
arch: os.arch(),
|
||||
type: os.type(),
|
||||
platform: os.platform()
|
||||
})
|
||||
|
||||
if (data.status === 1) {
|
||||
console.log('发现监控系统地址')
|
||||
}
|
||||
|
||||
gather(conf)
|
||||
}, 20000)
|
||||
}
|
||||
|
||||
gather(conf)
|
||||
}
|
2
src/dev.js
Normal file
2
src/dev.js
Normal file
@ -0,0 +1,2 @@
|
||||
require('@babel/register')
|
||||
require('./app')
|
13
src/service/home.js
Normal file
13
src/service/home.js
Normal file
@ -0,0 +1,13 @@
|
||||
export default {
|
||||
method: 'GET',
|
||||
path: '/',
|
||||
config: {
|
||||
auth: false
|
||||
},
|
||||
async handler () {
|
||||
return {
|
||||
status: 1,
|
||||
massage: 'Please consult the API documentation.'
|
||||
}
|
||||
}
|
||||
}
|
19
src/service/index.js
Normal file
19
src/service/index.js
Normal file
@ -0,0 +1,19 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const modules = []
|
||||
|
||||
const files = fs.readdirSync(__dirname).filter((file) => {
|
||||
return file.match(/\.(json|js)$/)
|
||||
})
|
||||
|
||||
files.forEach(key => {
|
||||
if (key === 'index.js') return
|
||||
|
||||
// const content = require(path.join(__dirname, key)).default
|
||||
const content = require(path.join(__dirname, key)).default
|
||||
|
||||
if (Array.isArray(content)) { modules.push(...content) } else { modules.push(content) }
|
||||
})
|
||||
|
||||
export default modules
|
16
src/service/stats.js
Normal file
16
src/service/stats.js
Normal file
@ -0,0 +1,16 @@
|
||||
import Proc from '../lib/Proc'
|
||||
|
||||
export default {
|
||||
method: 'GET',
|
||||
path: '/stats',
|
||||
config: {
|
||||
auth: false
|
||||
},
|
||||
async handler () {
|
||||
const proc = new Proc()
|
||||
return {
|
||||
status: 1,
|
||||
result: proc.info
|
||||
}
|
||||
}
|
||||
}
|
27
src/service/status.js
Normal file
27
src/service/status.js
Normal file
@ -0,0 +1,27 @@
|
||||
import os from 'os'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
export default {
|
||||
method: 'GET',
|
||||
path: '/status',
|
||||
config: {
|
||||
auth: false
|
||||
},
|
||||
async handler () {
|
||||
const who = execSync('whoami')
|
||||
|
||||
return {
|
||||
status: 1,
|
||||
msg: 'running',
|
||||
result: {
|
||||
user: who.toString('utf8').trim('\r\n'),
|
||||
arch: os.arch(),
|
||||
type: os.type(),
|
||||
platform: os.platform(),
|
||||
totalmem: os.totalmem(),
|
||||
freemem: os.freemem(),
|
||||
cups: os.cpus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user