mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-27 14:39:51 -08:00
Merge branch 'master' into #1059-specify-dns-resolver-port
This commit is contained in:
commit
3c01e8732c
|
@ -48,6 +48,7 @@ module.exports = {
|
||||||
"vue/html-self-closing": "off",
|
"vue/html-self-closing": "off",
|
||||||
"vue/require-component-is": "off", // not allow is="style" https://github.com/vuejs/eslint-plugin-vue/issues/462#issuecomment-430234675
|
"vue/require-component-is": "off", // not allow is="style" https://github.com/vuejs/eslint-plugin-vue/issues/462#issuecomment-430234675
|
||||||
"vue/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly
|
"vue/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly
|
||||||
|
"vue/multi-word-component-names": "off",
|
||||||
"no-multi-spaces": [ "error", {
|
"no-multi-spaces": [ "error", {
|
||||||
ignoreEOLComments: true,
|
ignoreEOLComments: true,
|
||||||
}],
|
}],
|
||||||
|
|
22
.github/workflows/auto-test.yml
vendored
22
.github/workflows/auto-test.yml
vendored
|
@ -16,17 +16,17 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||||
node-version: [14.x, 16.x, 17.x]
|
node: [14, 16, 17]
|
||||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- run: git config --global core.autocrlf false # Mainly for Windows
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node }}
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node }}
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
- run: npm run install-legacy
|
- run: npm run install-legacy
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
@ -34,3 +34,17 @@ jobs:
|
||||||
env:
|
env:
|
||||||
HEADLESS_TEST: 1
|
HEADLESS_TEST: 1
|
||||||
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
|
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
|
||||||
|
check-linters:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Use Node.js LTS
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: 'npm'
|
||||||
|
- run: npm run install-legacy
|
||||||
|
- run: npm run lint
|
||||||
|
|
|
@ -79,7 +79,7 @@ I personally do not like something need to learn so much and need to config so m
|
||||||
- 4 spaces indentation
|
- 4 spaces indentation
|
||||||
- Follow `.editorconfig`
|
- Follow `.editorconfig`
|
||||||
- Follow ESLint
|
- Follow ESLint
|
||||||
- Methods and funtions should be documented with JSDoc
|
- Methods and functions should be documented with JSDoc
|
||||||
|
|
||||||
## Name convention
|
## Name convention
|
||||||
|
|
||||||
|
@ -90,9 +90,10 @@ I personally do not like something need to learn so much and need to config so m
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
- Node.js >= 14
|
- Node.js >= 14
|
||||||
|
- NPM >= 8.5
|
||||||
- Git
|
- Git
|
||||||
- IDE that supports ESLint and EditorConfig (I am using IntelliJ IDEA)
|
- IDE that supports ESLint and EditorConfig (I am using IntelliJ IDEA)
|
||||||
- A SQLite tool (SQLite Expert Personal is suggested)
|
- A SQLite GUI tool (SQLite Expert Personal is suggested)
|
||||||
|
|
||||||
## Install dependencies
|
## Install dependencies
|
||||||
|
|
||||||
|
@ -100,39 +101,45 @@ I personally do not like something need to learn so much and need to config so m
|
||||||
npm ci
|
npm ci
|
||||||
```
|
```
|
||||||
|
|
||||||
## How to start the Backend Dev Server
|
## Dev Server
|
||||||
|
|
||||||
(2021-09-23 Update)
|
(2022-04-26 Update)
|
||||||
|
|
||||||
|
We can start the frontend dev server and the backend dev server in one command.
|
||||||
|
|
||||||
|
Port `3000` and port `3001` will be used.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run start-server-dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
It binds to `0.0.0.0:3001` by default.
|
## Backend Server
|
||||||
|
|
||||||
### Backend Details
|
For development, it binds to `0.0.0.0:3001` by default.
|
||||||
|
For production, it binds to `0.0.0.0:3000` by default.
|
||||||
|
|
||||||
It is mainly a socket.io app + express.js.
|
It is mainly a socket.io app + express.js.
|
||||||
|
|
||||||
express.js is just used for serving the frontend built files (index.html, .js and .css etc.)
|
express.js is used for:
|
||||||
|
- entry point such as redirecting to a status page or the dashboard
|
||||||
|
- serving the frontend built files (index.html, .js and .css etc.)
|
||||||
|
- serving internal APIs of status page
|
||||||
|
|
||||||
|
|
||||||
|
### Structure in /server/
|
||||||
|
|
||||||
- model/ (Object model, auto mapping to the database table name)
|
- model/ (Object model, auto mapping to the database table name)
|
||||||
- modules/ (Modified 3rd-party modules)
|
- modules/ (Modified 3rd-party modules)
|
||||||
- notification-providers/ (individual notification logic)
|
- notification-providers/ (individual notification logic)
|
||||||
- routers/ (Express Routers)
|
- routers/ (Express Routers)
|
||||||
- socket-handler (Socket.io Handlers)
|
- socket-handler (Socket.io Handlers)
|
||||||
- server.js (Server main logic)
|
- server.js (Server entry point and main logic)
|
||||||
|
|
||||||
## How to start the Frontend Dev Server
|
## Frontend Dev Server
|
||||||
|
|
||||||
1. Set the env var `NODE_ENV` to "development".
|
It binds to `0.0.0.0:3000` by default. Frontend dev server is used for development only.
|
||||||
2. Start the frontend dev server by the following command.
|
|
||||||
|
|
||||||
```bash
|
For production, it is not used. It will be compiled to `dist` directory instead.
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
It binds to `0.0.0.0:3000` by default.
|
|
||||||
|
|
||||||
You can use Vue.js devtools Chrome extension for debugging.
|
You can use Vue.js devtools Chrome extension for debugging.
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,7 @@ currently being supported with security updates.
|
||||||
|
|
||||||
### Uptime Kuma Versions
|
### Uptime Kuma Versions
|
||||||
|
|
||||||
| Version | Supported |
|
You should use or upgrade to the latest version of Uptime Kuma. All `1.X.X` versions are upgradable to the lastest version.
|
||||||
| ------- | ------------------ |
|
|
||||||
| 1.9.X | :white_check_mark: |
|
|
||||||
| <= 1.8.X | ❌ |
|
|
||||||
|
|
||||||
### Upgradable Docker Tags
|
### Upgradable Docker Tags
|
||||||
|
|
||||||
|
@ -24,8 +21,8 @@ currently being supported with security updates.
|
||||||
| ------- | ------------------ |
|
| ------- | ------------------ |
|
||||||
| 1 | :white_check_mark: |
|
| 1 | :white_check_mark: |
|
||||||
| 1-debian | :white_check_mark: |
|
| 1-debian | :white_check_mark: |
|
||||||
| 1-alpine | :white_check_mark: |
|
|
||||||
| latest | :white_check_mark: |
|
| latest | :white_check_mark: |
|
||||||
| debian | :white_check_mark: |
|
| debian | :white_check_mark: |
|
||||||
| alpine | :white_check_mark: |
|
| 1-alpine | ⚠️ Deprecated |
|
||||||
|
| alpine | ⚠️ Deprecated |
|
||||||
| All other tags | ❌ |
|
| All other tags | ❌ |
|
||||||
|
|
|
@ -20,6 +20,10 @@ if (! exists) {
|
||||||
// Process package.json
|
// Process package.json
|
||||||
pkg.version = version;
|
pkg.version = version;
|
||||||
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
||||||
|
|
||||||
|
// Also update package-lock.json
|
||||||
|
childProcess.spawnSync("npm", [ "install" ]);
|
||||||
|
|
||||||
commit(version);
|
commit(version);
|
||||||
tag(version);
|
tag(version);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ if (! exists) {
|
||||||
pkg.scripts.setup = pkg.scripts.setup.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`);
|
pkg.scripts.setup = pkg.scripts.setup.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`);
|
||||||
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
||||||
|
|
||||||
|
// Also update package-lock.json
|
||||||
|
childProcess.spawnSync("npm", [ "install" ]);
|
||||||
|
|
||||||
commit(newVersion);
|
commit(newVersion);
|
||||||
tag(newVersion);
|
tag(newVersion);
|
||||||
|
|
||||||
|
|
257
package-lock.json
generated
257
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "uptime-kuma",
|
"name": "uptime-kuma",
|
||||||
"version": "1.15.0-beta.0",
|
"version": "1.15.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "uptime-kuma",
|
"name": "uptime-kuma",
|
||||||
"version": "1.15.0-beta.0",
|
"version": "1.15.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "~1.2.36",
|
"@fortawesome/fontawesome-svg-core": "~1.2.36",
|
||||||
|
@ -81,6 +81,7 @@
|
||||||
"@vue/compiler-sfc": "~3.2.31",
|
"@vue/compiler-sfc": "~3.2.31",
|
||||||
"aedes": "^0.46.3",
|
"aedes": "^0.46.3",
|
||||||
"babel-plugin-rewire": "~1.2.0",
|
"babel-plugin-rewire": "~1.2.0",
|
||||||
|
"concurrently": "^7.1.0",
|
||||||
"core-js": "~3.18.3",
|
"core-js": "~3.18.3",
|
||||||
"cross-env": "~7.0.3",
|
"cross-env": "~7.0.3",
|
||||||
"dns2": "~2.0.1",
|
"dns2": "~2.0.1",
|
||||||
|
@ -95,7 +96,8 @@
|
||||||
"stylelint": "~14.2.0",
|
"stylelint": "~14.2.0",
|
||||||
"stylelint-config-standard": "~24.0.0",
|
"stylelint-config-standard": "~24.0.0",
|
||||||
"typescript": "~4.4.4",
|
"typescript": "~4.4.4",
|
||||||
"vite": "~2.6.14"
|
"vite": "~2.6.14",
|
||||||
|
"wait-on": "^6.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "14.* || >=16.*"
|
"node": "14.* || >=16.*"
|
||||||
|
@ -5246,6 +5248,131 @@
|
||||||
"typedarray": "^0.0.6"
|
"typedarray": "^0.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/concurrently": {
|
||||||
|
"version": "7.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/concurrently/-/concurrently-7.1.0.tgz",
|
||||||
|
"integrity": "sha512-Bz0tMlYKZRUDqJlNiF/OImojMB9ruKUz6GCfmhFnSapXgPe+3xzY4byqoKG9tUZ7L2PGEUjfLPOLfIX3labnmw==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^4.1.0",
|
||||||
|
"date-fns": "^2.16.1",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"rxjs": "^6.6.3",
|
||||||
|
"spawn-command": "^0.0.2-1",
|
||||||
|
"supports-color": "^8.1.0",
|
||||||
|
"tree-kill": "^1.2.2",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"concurrently": "dist/bin/concurrently.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.20.0 || ^14.13.0 || >=16.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/ansi-styles": {
|
||||||
|
"version": "4.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"color-convert": "^2.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/chalk": {
|
||||||
|
"version": "4.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||||
|
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^4.1.0",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/chalk/node_modules/supports-color": {
|
||||||
|
"version": "7.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||||
|
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/color-convert": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"color-name": "~1.1.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=7.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/has-flag": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/rxjs": {
|
||||||
|
"version": "6.6.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz",
|
||||||
|
"integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^1.9.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"npm": ">=2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/supports-color": {
|
||||||
|
"version": "8.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
|
||||||
|
"integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/supports-color?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/tslib": {
|
||||||
|
"version": "1.14.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
|
||||||
|
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/configstore": {
|
"node_modules/configstore": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz",
|
||||||
|
@ -5517,6 +5644,19 @@
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/date-fns": {
|
||||||
|
"version": "2.28.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.28.0.tgz",
|
||||||
|
"integrity": "sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.11"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/date-fns"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/dayjs": {
|
"node_modules/dayjs": {
|
||||||
"version": "1.10.8",
|
"version": "1.10.8",
|
||||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.8.tgz",
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.8.tgz",
|
||||||
|
@ -14706,6 +14846,12 @@
|
||||||
"resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz",
|
"resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz",
|
||||||
"integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA=="
|
"integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA=="
|
||||||
},
|
},
|
||||||
|
"node_modules/spawn-command": {
|
||||||
|
"version": "0.0.2-1",
|
||||||
|
"resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2-1.tgz",
|
||||||
|
"integrity": "sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/spawn-please": {
|
"node_modules/spawn-please": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/spawn-please/-/spawn-please-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/spawn-please/-/spawn-please-1.0.0.tgz",
|
||||||
|
@ -20505,6 +20651,99 @@
|
||||||
"typedarray": "^0.0.6"
|
"typedarray": "^0.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"concurrently": {
|
||||||
|
"version": "7.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/concurrently/-/concurrently-7.1.0.tgz",
|
||||||
|
"integrity": "sha512-Bz0tMlYKZRUDqJlNiF/OImojMB9ruKUz6GCfmhFnSapXgPe+3xzY4byqoKG9tUZ7L2PGEUjfLPOLfIX3labnmw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"chalk": "^4.1.0",
|
||||||
|
"date-fns": "^2.16.1",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"rxjs": "^6.6.3",
|
||||||
|
"spawn-command": "^0.0.2-1",
|
||||||
|
"supports-color": "^8.1.0",
|
||||||
|
"tree-kill": "^1.2.2",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": {
|
||||||
|
"version": "4.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"color-convert": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"chalk": {
|
||||||
|
"version": "4.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||||
|
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"ansi-styles": "^4.1.0",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"supports-color": {
|
||||||
|
"version": "7.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||||
|
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"color-convert": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"color-name": "~1.1.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"has-flag": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"rxjs": {
|
||||||
|
"version": "6.6.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz",
|
||||||
|
"integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"tslib": "^1.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"supports-color": {
|
||||||
|
"version": "8.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
|
||||||
|
"integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tslib": {
|
||||||
|
"version": "1.14.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
|
||||||
|
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"configstore": {
|
"configstore": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz",
|
||||||
|
@ -20719,6 +20958,12 @@
|
||||||
"whatwg-url": "^8.0.0"
|
"whatwg-url": "^8.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"date-fns": {
|
||||||
|
"version": "2.28.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.28.0.tgz",
|
||||||
|
"integrity": "sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"dayjs": {
|
"dayjs": {
|
||||||
"version": "1.10.8",
|
"version": "1.10.8",
|
||||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.8.tgz",
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.8.tgz",
|
||||||
|
@ -27679,6 +27924,12 @@
|
||||||
"resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz",
|
"resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz",
|
||||||
"integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA=="
|
"integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA=="
|
||||||
},
|
},
|
||||||
|
"spawn-command": {
|
||||||
|
"version": "0.0.2-1",
|
||||||
|
"resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2-1.tgz",
|
||||||
|
"integrity": "sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"spawn-please": {
|
"spawn-please": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/spawn-please/-/spawn-please-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/spawn-please/-/spawn-please-1.0.0.tgz",
|
||||||
|
|
26
package.json
26
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "uptime-kuma",
|
"name": "uptime-kuma",
|
||||||
"version": "1.15.0-beta.1",
|
"version": "1.15.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -15,13 +15,15 @@
|
||||||
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
|
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
|
||||||
"lint-fix:js": "eslint --ext \".js,.vue\" --fix --ignore-path .gitignore .",
|
"lint-fix:js": "eslint --ext \".js,.vue\" --fix --ignore-path .gitignore .",
|
||||||
"lint:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore",
|
"lint:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore",
|
||||||
|
"lint-fix:style": "stylelint \"**/*.{vue,css,scss}\" --fix --ignore-path .gitignore",
|
||||||
"lint": "npm run lint:js && npm run lint:style",
|
"lint": "npm run lint:js && npm run lint:style",
|
||||||
"dev": "vite --host --config ./config/vite.config.js",
|
"dev": "concurrently -k -r \"wait-on tcp:3000 && npm run start-server-dev \" \"npm run start-frontend-dev\"",
|
||||||
|
"start-frontend-dev": "cross-env NODE_ENV=development vite --host --config ./config/vite.config.js",
|
||||||
"start": "npm run start-server",
|
"start": "npm run start-server",
|
||||||
"start-server": "node server/server.js",
|
"start-server": "node server/server.js",
|
||||||
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
||||||
"build": "vite build --config ./config/vite.config.js",
|
"build": "vite build --config ./config/vite.config.js",
|
||||||
"test": "npm run lint && node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/ --test",
|
"test": "node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/ --test",
|
||||||
"test-with-build": "npm run build && npm test",
|
"test-with-build": "npm run build && npm test",
|
||||||
"jest": "node test/prepare-jest.js && npm run jest-frontend && npm run jest-backend",
|
"jest": "node test/prepare-jest.js && npm run jest-frontend && npm run jest-backend",
|
||||||
"jest-frontend": "cross-env TEST_FRONTEND=1 jest --config=./config/jest-frontend.config.js",
|
"jest-frontend": "cross-env TEST_FRONTEND=1 jest --config=./config/jest-frontend.config.js",
|
||||||
|
@ -37,7 +39,7 @@
|
||||||
"build-docker-nightly-alpine": "docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly-alpine --target nightly . --push",
|
"build-docker-nightly-alpine": "docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly-alpine --target nightly . --push",
|
||||||
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
|
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
|
||||||
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
|
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
|
||||||
"setup": "git checkout 1.14.1 && npm ci --production && npm run download-dist",
|
"setup": "git checkout 1.15.0 && npm ci --production && npm run download-dist",
|
||||||
"download-dist": "node extra/download-dist.js",
|
"download-dist": "node extra/download-dist.js",
|
||||||
"mark-as-nightly": "node extra/mark-as-nightly.js",
|
"mark-as-nightly": "node extra/mark-as-nightly.js",
|
||||||
"reset-password": "node extra/reset-password.js",
|
"reset-password": "node extra/reset-password.js",
|
||||||
|
@ -122,7 +124,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/github": "~5.0.1",
|
"@actions/github": "~5.0.1",
|
||||||
"@babel/eslint-parser": "~7.15.8",
|
"@babel/eslint-parser": "~7.17.0",
|
||||||
"@babel/preset-env": "^7.15.8",
|
"@babel/preset-env": "^7.15.8",
|
||||||
"@types/bootstrap": "~5.1.9",
|
"@types/bootstrap": "~5.1.9",
|
||||||
"@vitejs/plugin-legacy": "~1.6.4",
|
"@vitejs/plugin-legacy": "~1.6.4",
|
||||||
|
@ -130,20 +132,22 @@
|
||||||
"@vue/compiler-sfc": "~3.2.31",
|
"@vue/compiler-sfc": "~3.2.31",
|
||||||
"aedes": "^0.46.3",
|
"aedes": "^0.46.3",
|
||||||
"babel-plugin-rewire": "~1.2.0",
|
"babel-plugin-rewire": "~1.2.0",
|
||||||
|
"concurrently": "^7.1.0",
|
||||||
"core-js": "~3.18.3",
|
"core-js": "~3.18.3",
|
||||||
"cross-env": "~7.0.3",
|
"cross-env": "~7.0.3",
|
||||||
"dns2": "~2.0.1",
|
"dns2": "~2.0.1",
|
||||||
"eslint": "~7.32.0",
|
"eslint": "~8.14.0",
|
||||||
"eslint-plugin-vue": "~7.18.0",
|
"eslint-plugin-vue": "~8.7.1",
|
||||||
"jest": "~27.2.5",
|
"jest": "~27.2.5",
|
||||||
"jest-puppeteer": "~6.0.3",
|
"jest-puppeteer": "~6.0.3",
|
||||||
"npm-check-updates": "^12.5.5",
|
"npm-check-updates": "^12.5.9",
|
||||||
"postcss-html": "^1.3.1",
|
"postcss-html": "^1.3.1",
|
||||||
"puppeteer": "~13.1.3",
|
"puppeteer": "~13.1.3",
|
||||||
"sass": "~1.42.1",
|
"sass": "~1.42.1",
|
||||||
"stylelint": "~14.2.0",
|
"stylelint": "~14.7.1",
|
||||||
"stylelint-config-standard": "~24.0.0",
|
"stylelint-config-standard": "~25.0.0",
|
||||||
"typescript": "~4.4.4",
|
"typescript": "~4.4.4",
|
||||||
"vite": "~2.6.14"
|
"vite": "~2.6.14",
|
||||||
|
"wait-on": "^6.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,11 @@ const { R } = require("redbean-node");
|
||||||
|
|
||||||
class TwoFA {
|
class TwoFA {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable 2FA for specified user
|
||||||
|
* @param {number} userID ID of user to disable
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async disable2FA(userID) {
|
static async disable2FA(userID) {
|
||||||
return await R.exec("UPDATE `user` SET twofa_status = 0 WHERE id = ? ", [
|
return await R.exec("UPDATE `user` SET twofa_status = 0 WHERE id = ? ", [
|
||||||
userID,
|
userID,
|
||||||
|
|
|
@ -5,10 +5,10 @@ const { setting } = require("./util-server");
|
||||||
const { loginRateLimiter } = require("./rate-limiter");
|
const { loginRateLimiter } = require("./rate-limiter");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Login to web app
|
||||||
* @param username : string
|
* @param {string} username
|
||||||
* @param password : string
|
* @param {string} password
|
||||||
* @returns {Promise<Bean|null>}
|
* @returns {Promise<(Bean|null)>}
|
||||||
*/
|
*/
|
||||||
exports.login = async function (username, password) {
|
exports.login = async function (username, password) {
|
||||||
if (typeof username !== "string" || typeof password !== "string") {
|
if (typeof username !== "string" || typeof password !== "string") {
|
||||||
|
@ -34,11 +34,17 @@ exports.login = async function (username, password) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that checks if a user is logged in.
|
* Callback for myAuthorizer
|
||||||
* @param {string} username The username of the user to check for.
|
* @callback myAuthorizerCB
|
||||||
* @param {function} callback The callback to call when done, with an error and result parameter.
|
* @param {any} err Any error encountered
|
||||||
*
|
* @param {boolean} authorized Is the client authorized?
|
||||||
* Generated by Trelent
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom authorizer for express-basic-auth
|
||||||
|
* @param {string} username
|
||||||
|
* @param {string} password
|
||||||
|
* @param {myAuthorizerCB} callback
|
||||||
*/
|
*/
|
||||||
function myAuthorizer(username, password, callback) {
|
function myAuthorizer(username, password, callback) {
|
||||||
// Login Rate Limit
|
// Login Rate Limit
|
||||||
|
|
|
@ -7,6 +7,7 @@ exports.latestVersion = null;
|
||||||
|
|
||||||
let interval;
|
let interval;
|
||||||
|
|
||||||
|
/** Start 48 hour check interval */
|
||||||
exports.startInterval = () => {
|
exports.startInterval = () => {
|
||||||
let check = async () => {
|
let check = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -42,6 +43,11 @@ exports.startInterval = () => {
|
||||||
interval = setInterval(check, 3600 * 1000 * 48);
|
interval = setInterval(check, 3600 * 1000 * 48);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the check update feature
|
||||||
|
* @param {boolean} value Should the check update feature be enabled?
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
exports.enableCheckUpdate = async (value) => {
|
exports.enableCheckUpdate = async (value) => {
|
||||||
await setSetting("checkUpdate", value);
|
await setSetting("checkUpdate", value);
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,9 @@ const { setting } = require("./util-server");
|
||||||
const checkVersion = require("./check-version");
|
const checkVersion = require("./check-version");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a list of notifications to the user.
|
* Send list of notification providers to client
|
||||||
* @param {Socket} socket The socket object that is connected to the client.
|
* @param {Socket} socket Socket.io socket instance
|
||||||
*
|
* @returns {Promise<Bean[]>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function sendNotificationList(socket) {
|
async function sendNotificationList(socket) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
@ -35,8 +34,11 @@ async function sendNotificationList(socket) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Heartbeat History list to socket
|
* Send Heartbeat History list to socket
|
||||||
* @param toUser True = send to all browsers with the same user id, False = send to the current browser only
|
* @param {Socket} socket Socket.io instance
|
||||||
* @param overwrite Overwrite client-side's heartbeat list
|
* @param {number} monitorID ID of monitor to send heartbeat history
|
||||||
|
* @param {boolean} [toUser=false] True = send to all browsers with the same user id, False = send to the current browser only
|
||||||
|
* @param {boolean} [overwrite=false] Overwrite client-side's heartbeat list
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function sendHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
async function sendHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
@ -62,11 +64,12 @@ async function sendHeartbeatList(socket, monitorID, toUser = false, overwrite =
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Important Heart beat list (aka event list)
|
* Important Heart beat list (aka event list)
|
||||||
* @param socket
|
* @param {Socket} socket Socket.io instance
|
||||||
* @param monitorID
|
* @param {number} monitorID ID of monitor to send heartbeat history
|
||||||
* @param toUser True = send to all browsers with the same user id, False = send to the current browser only
|
* @param {boolean} [toUser=false] True = send to all browsers with the same user id, False = send to the current browser only
|
||||||
* @param overwrite Overwrite client-side's heartbeat list
|
* @param {boolean} [overwrite=false] Overwrite client-side's heartbeat list
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function sendImportantHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
async function sendImportantHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
@ -91,9 +94,8 @@ async function sendImportantHeartbeatList(socket, monitorID, toUser = false, ove
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delivers proxy list
|
* Emit proxy list to client
|
||||||
*
|
* @param {Socket} socket Socket.io socket instance
|
||||||
* @param socket
|
|
||||||
* @return {Promise<Bean[]>}
|
* @return {Promise<Bean[]>}
|
||||||
*/
|
*/
|
||||||
async function sendProxyList(socket) {
|
async function sendProxyList(socket) {
|
||||||
|
@ -109,9 +111,8 @@ async function sendProxyList(socket) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emits the version information to the client.
|
* Emits the version information to the client.
|
||||||
* @param {Socket} socket The socket object that is connected to the client.
|
* @param {Socket} socket Socket.io socket instance
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function sendInfo(socket) {
|
async function sendInfo(socket) {
|
||||||
socket.emit("info", {
|
socket.emit("info", {
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Database {
|
||||||
"patch-monitor-expiry-notification.sql": true,
|
"patch-monitor-expiry-notification.sql": true,
|
||||||
"patch-status-page-footer-css.sql": true,
|
"patch-status-page-footer-css.sql": true,
|
||||||
"patch-added-mqtt-monitor.sql": true,
|
"patch-added-mqtt-monitor.sql": true,
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The final version should be 10 after merged tag feature
|
* The final version should be 10 after merged tag feature
|
||||||
|
@ -68,6 +68,10 @@ class Database {
|
||||||
|
|
||||||
static noReject = true;
|
static noReject = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the database
|
||||||
|
* @param {Object} args Arguments to initialize DB with
|
||||||
|
*/
|
||||||
static init(args) {
|
static init(args) {
|
||||||
// Data Directory (must be end with "/")
|
// Data Directory (must be end with "/")
|
||||||
Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";
|
Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";
|
||||||
|
@ -85,6 +89,15 @@ class Database {
|
||||||
log.info("db", `Data Dir: ${Database.dataDir}`);
|
log.info("db", `Data Dir: ${Database.dataDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to the database
|
||||||
|
* @param {boolean} [testMode=false] Should the connection be
|
||||||
|
* started in test mode?
|
||||||
|
* @param {boolean} [autoloadModels=true] Should models be
|
||||||
|
* automatically loaded?
|
||||||
|
* @param {boolean} [noLog=false] Should logs not be output?
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async connect(testMode = false, autoloadModels = true, noLog = false) {
|
static async connect(testMode = false, autoloadModels = true, noLog = false) {
|
||||||
const acquireConnectionTimeout = 120 * 1000;
|
const acquireConnectionTimeout = 120 * 1000;
|
||||||
|
|
||||||
|
@ -144,6 +157,7 @@ class Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Patch the database */
|
||||||
static async patch() {
|
static async patch() {
|
||||||
let version = parseInt(await setting("database_version"));
|
let version = parseInt(await setting("database_version"));
|
||||||
|
|
||||||
|
@ -189,7 +203,9 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Patch DB using new process
|
||||||
* Call it from patch() only
|
* Call it from patch() only
|
||||||
|
* @private
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch2() {
|
static async patch2() {
|
||||||
|
@ -296,9 +312,12 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Patch database using new patching process
|
||||||
* Used it patch2() only
|
* Used it patch2() only
|
||||||
|
* @private
|
||||||
* @param sqlFilename
|
* @param sqlFilename
|
||||||
* @param databasePatchedFiles
|
* @param databasePatchedFiles
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch2Recursion(sqlFilename, databasePatchedFiles) {
|
static async patch2Recursion(sqlFilename, databasePatchedFiles) {
|
||||||
let value = this.patchList[sqlFilename];
|
let value = this.patchList[sqlFilename];
|
||||||
|
@ -333,12 +352,12 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sadly, multi sql statements is not supported by many sqlite libraries, I have to implement it myself
|
* Load an SQL file and execute it
|
||||||
* @param filename
|
* @param filename Filename of SQL file to import
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async importSQLFile(filename) {
|
static async importSQLFile(filename) {
|
||||||
|
// Sadly, multi sql statements is not supported by many sqlite libraries, I have to implement it myself
|
||||||
await R.getCell("SELECT 1");
|
await R.getCell("SELECT 1");
|
||||||
|
|
||||||
let text = fs.readFileSync(filename).toString();
|
let text = fs.readFileSync(filename).toString();
|
||||||
|
@ -366,6 +385,10 @@ class Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aquire a direct connection to database
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
static getBetterSQLite3Database() {
|
static getBetterSQLite3Database() {
|
||||||
return R.knex.client.acquireConnection();
|
return R.knex.client.acquireConnection();
|
||||||
}
|
}
|
||||||
|
@ -401,7 +424,7 @@ class Database {
|
||||||
/**
|
/**
|
||||||
* One backup one time in this process.
|
* One backup one time in this process.
|
||||||
* Reset this.backupPath if you want to backup again
|
* Reset this.backupPath if you want to backup again
|
||||||
* @param version
|
* @param {string} version Version code of backup
|
||||||
*/
|
*/
|
||||||
static backup(version) {
|
static backup(version) {
|
||||||
if (! this.backupPath) {
|
if (! this.backupPath) {
|
||||||
|
@ -423,9 +446,7 @@ class Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Restore from most recent backup */
|
||||||
*
|
|
||||||
*/
|
|
||||||
static restore() {
|
static restore() {
|
||||||
if (this.backupPath) {
|
if (this.backupPath) {
|
||||||
log.error("db", "Patching the database failed!!! Restoring the backup");
|
log.error("db", "Patching the database failed!!! Restoring the backup");
|
||||||
|
@ -467,6 +488,7 @@ class Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the size of the database */
|
||||||
static getSize() {
|
static getSize() {
|
||||||
log.debug("db", "Database.getSize()");
|
log.debug("db", "Database.getSize()");
|
||||||
let stats = fs.statSync(Database.path);
|
let stats = fs.statSync(Database.path);
|
||||||
|
@ -474,6 +496,10 @@ class Database {
|
||||||
return stats.size;
|
return stats.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink the database
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async shrink() {
|
static async shrink() {
|
||||||
await R.exec("VACUUM");
|
await R.exec("VACUUM");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,12 @@ const { log } = require("../src/util");
|
||||||
let ImageDataURI = (() => {
|
let ImageDataURI = (() => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} dataURI - A string that is a valid Data URI.
|
* Decode the data:image/ URI
|
||||||
* @returns {?Object} An object with properties "imageType" and "dataBase64". The former is the image type, e.g., "png", and the latter is a base64 encoded string of the image's binary data. If it fails to parse, returns null instead of an object.
|
* @param {string} dataURI data:image/ URI to decode
|
||||||
*
|
* @returns {?Object} An object with properties "imageType" and "dataBase64".
|
||||||
* Generated by Trelent
|
* The former is the image type, e.g., "png", and the latter is a base64
|
||||||
|
* encoded string of the image's binary data. If it fails to parse, returns
|
||||||
|
* null instead of an object.
|
||||||
*/
|
*/
|
||||||
function decode(dataURI) {
|
function decode(dataURI) {
|
||||||
if (!/data:image\//.test(dataURI)) {
|
if (!/data:image\//.test(dataURI)) {
|
||||||
|
@ -28,11 +30,11 @@ let ImageDataURI = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Buffer} data - The image data to be encoded.
|
* Endcode an image into data:image/ URI
|
||||||
* @param {String} mediaType - The type of the image, e.g., "image/png".
|
* @param {(Buffer|string)} data Data to encode
|
||||||
* @returns {String|null} A string representing the base64-encoded version of the given Buffer object or null if an error occurred.
|
* @param {string} mediaType Media type of data
|
||||||
*
|
* @returns {(string|null)} A string representing the base64-encoded
|
||||||
* Generated by Trelent
|
* version of the given Buffer object or null if an error occurred.
|
||||||
*/
|
*/
|
||||||
function encode(data, mediaType) {
|
function encode(data, mediaType) {
|
||||||
if (!data || !mediaType) {
|
if (!data || !mediaType) {
|
||||||
|
@ -48,11 +50,10 @@ let ImageDataURI = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a data URI to a file path.
|
* Write data URI to file
|
||||||
* @param {string} dataURI The Data URI of the image.
|
* @param {string} dataURI data:image/ URI
|
||||||
* @param {string} [filePath] The path where the image will be saved, defaults to "./".
|
* @param {string} [filePath] Path to write file to
|
||||||
*
|
* @returns {Promise<string>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
function outputFile(dataURI, filePath) {
|
function outputFile(dataURI, filePath) {
|
||||||
filePath = filePath || "./";
|
filePath = filePath || "./";
|
||||||
|
|
|
@ -10,6 +10,11 @@ const jobs = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize background jobs
|
||||||
|
* @param {Object} args Arguments to pass to workers
|
||||||
|
* @returns {Bree}
|
||||||
|
*/
|
||||||
const initBackgroundJobs = function (args) {
|
const initBackgroundJobs = function (args) {
|
||||||
bree = new Bree({
|
bree = new Bree({
|
||||||
root: path.resolve("server", "jobs"),
|
root: path.resolve("server", "jobs"),
|
||||||
|
|
|
@ -2,12 +2,22 @@ const { parentPort, workerData } = require("worker_threads");
|
||||||
const Database = require("../database");
|
const Database = require("../database");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message to parent process for logging
|
||||||
|
* since worker_thread does not have access to stdout, this is used
|
||||||
|
* instead of console.log()
|
||||||
|
* @param {any} any The message to log
|
||||||
|
*/
|
||||||
const log = function (any) {
|
const log = function (any) {
|
||||||
if (parentPort) {
|
if (parentPort) {
|
||||||
parentPort.postMessage(any);
|
parentPort.postMessage(any);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit the worker process
|
||||||
|
* @param {number} error The status code to exit
|
||||||
|
*/
|
||||||
const exit = function (error) {
|
const exit = function (error) {
|
||||||
if (error && error !== 0) {
|
if (error && error !== 0) {
|
||||||
process.exit(error);
|
process.exit(error);
|
||||||
|
@ -20,6 +30,7 @@ const exit = function (error) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Connects to the database */
|
||||||
const connectDb = async function () {
|
const connectDb = async function () {
|
||||||
const dbPath = path.join(
|
const dbPath = path.join(
|
||||||
process.env.DATA_DIR || workerData["data-dir"] || "./data/"
|
process.env.DATA_DIR || workerData["data-dir"] || "./data/"
|
||||||
|
|
|
@ -3,6 +3,12 @@ const { R } = require("redbean-node");
|
||||||
|
|
||||||
class Group extends BeanModel {
|
class Group extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @param {boolean} [showTags=false] Should the JSON include monitor tags
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
async toPublicJSON(showTags = false) {
|
async toPublicJSON(showTags = false) {
|
||||||
let monitorBeanList = await this.getMonitorList();
|
let monitorBeanList = await this.getMonitorList();
|
||||||
let monitorList = [];
|
let monitorList = [];
|
||||||
|
@ -19,6 +25,10 @@ class Group extends BeanModel {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all monitors
|
||||||
|
* @returns {Bean[]}
|
||||||
|
*/
|
||||||
async getMonitorList() {
|
async getMonitorList() {
|
||||||
return R.convertToBeans("monitor", await R.getAll(`
|
return R.convertToBeans("monitor", await R.getAll(`
|
||||||
SELECT monitor.* FROM monitor, monitor_group
|
SELECT monitor.* FROM monitor, monitor_group
|
||||||
|
|
|
@ -13,6 +13,11 @@ const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
*/
|
*/
|
||||||
class Heartbeat extends BeanModel {
|
class Heartbeat extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toPublicJSON() {
|
toPublicJSON() {
|
||||||
return {
|
return {
|
||||||
status: this.status,
|
status: this.status,
|
||||||
|
@ -22,6 +27,10 @@ class Heartbeat extends BeanModel {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
monitorID: this.monitor_id,
|
monitorID: this.monitor_id,
|
||||||
|
|
|
@ -2,6 +2,11 @@ const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
|
|
||||||
class Incident extends BeanModel {
|
class Incident extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toPublicJSON() {
|
toPublicJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Monitor extends BeanModel {
|
||||||
/**
|
/**
|
||||||
* Return an object that ready to parse to JSON for public
|
* Return an object that ready to parse to JSON for public
|
||||||
* Only show necessary data to public
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
async toPublicJSON(showTags = false) {
|
async toPublicJSON(showTags = false) {
|
||||||
let obj = {
|
let obj = {
|
||||||
|
@ -41,6 +42,7 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an object that ready to parse to JSON
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
async toJSON(includeSensitiveData = true) {
|
async toJSON(includeSensitiveData = true) {
|
||||||
|
|
||||||
|
@ -101,6 +103,10 @@ class Monitor extends BeanModel {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all tags applied to this monitor
|
||||||
|
* @returns {Promise<LooseObject<any>[]>}
|
||||||
|
*/
|
||||||
async getTags() {
|
async getTags() {
|
||||||
return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [ this.id ]);
|
return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [ this.id ]);
|
||||||
}
|
}
|
||||||
|
@ -114,6 +120,10 @@ class Monitor extends BeanModel {
|
||||||
return Buffer.from(user + ":" + pass).toString("base64");
|
return Buffer.from(user + ":" + pass).toString("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the TLS expiry notification enabled?
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
isEnabledExpiryNotification() {
|
isEnabledExpiryNotification() {
|
||||||
return Boolean(this.expiryNotification);
|
return Boolean(this.expiryNotification);
|
||||||
}
|
}
|
||||||
|
@ -134,10 +144,18 @@ class Monitor extends BeanModel {
|
||||||
return Boolean(this.upsideDown);
|
return Boolean(this.upsideDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get accepted status codes
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
getAcceptedStatuscodes() {
|
getAcceptedStatuscodes() {
|
||||||
return JSON.parse(this.accepted_statuscodes_json);
|
return JSON.parse(this.accepted_statuscodes_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start monitor
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
*/
|
||||||
start(io) {
|
start(io) {
|
||||||
let previousBeat = null;
|
let previousBeat = null;
|
||||||
let retries = 0;
|
let retries = 0;
|
||||||
|
@ -497,6 +515,7 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Get a heartbeat and handle errors */
|
||||||
const safeBeat = async () => {
|
const safeBeat = async () => {
|
||||||
try {
|
try {
|
||||||
await beat();
|
await beat();
|
||||||
|
@ -522,6 +541,7 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Stop monitor */
|
||||||
stop() {
|
stop() {
|
||||||
clearTimeout(this.heartbeatInterval);
|
clearTimeout(this.heartbeatInterval);
|
||||||
this.isStop = true;
|
this.isStop = true;
|
||||||
|
@ -529,6 +549,10 @@ class Monitor extends BeanModel {
|
||||||
this.prometheus().remove();
|
this.prometheus().remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a new prometheus instance
|
||||||
|
* @returns {Prometheus}
|
||||||
|
*/
|
||||||
prometheus() {
|
prometheus() {
|
||||||
return new Prometheus(this);
|
return new Prometheus(this);
|
||||||
}
|
}
|
||||||
|
@ -537,7 +561,7 @@ class Monitor extends BeanModel {
|
||||||
* Helper Method:
|
* Helper Method:
|
||||||
* returns URL object for further usage
|
* returns URL object for further usage
|
||||||
* returns null if url is invalid
|
* returns null if url is invalid
|
||||||
* @returns {null|URL}
|
* @returns {(null|URL)}
|
||||||
*/
|
*/
|
||||||
getUrl() {
|
getUrl() {
|
||||||
try {
|
try {
|
||||||
|
@ -550,7 +574,7 @@ class Monitor extends BeanModel {
|
||||||
/**
|
/**
|
||||||
* Store TLS info to database
|
* Store TLS info to database
|
||||||
* @param checkCertificateResult
|
* @param checkCertificateResult
|
||||||
* @returns {Promise<object>}
|
* @returns {Promise<Object>}
|
||||||
*/
|
*/
|
||||||
async updateTlsInfo(checkCertificateResult) {
|
async updateTlsInfo(checkCertificateResult) {
|
||||||
let tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
let tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
||||||
|
@ -592,6 +616,12 @@ class Monitor extends BeanModel {
|
||||||
return checkCertificateResult;
|
return checkCertificateResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send statistics to clients
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {number} monitorID ID of monitor to send
|
||||||
|
* @param {number} userID ID of user to send to
|
||||||
|
*/
|
||||||
static async sendStats(io, monitorID, userID) {
|
static async sendStats(io, monitorID, userID) {
|
||||||
const hasClients = getTotalClientInRoom(io, userID) > 0;
|
const hasClients = getTotalClientInRoom(io, userID) > 0;
|
||||||
|
|
||||||
|
@ -606,8 +636,8 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Send the average ping to user
|
||||||
* @param duration : int Hours
|
* @param {number} duration Hours
|
||||||
*/
|
*/
|
||||||
static async sendAvgPing(duration, io, monitorID, userID) {
|
static async sendAvgPing(duration, io, monitorID, userID) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
@ -627,6 +657,12 @@ class Monitor extends BeanModel {
|
||||||
io.to(userID).emit("avgPing", monitorID, avgPing);
|
io.to(userID).emit("avgPing", monitorID, avgPing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send certificate information to client
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {number} monitorID ID of monitor to send
|
||||||
|
* @param {number} userID ID of user to send to
|
||||||
|
*/
|
||||||
static async sendCertInfo(io, monitorID, userID) {
|
static async sendCertInfo(io, monitorID, userID) {
|
||||||
let tlsInfo = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
let tlsInfo = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
||||||
monitorID,
|
monitorID,
|
||||||
|
@ -640,7 +676,8 @@ class Monitor extends BeanModel {
|
||||||
* Uptime with calculation
|
* Uptime with calculation
|
||||||
* Calculation based on:
|
* Calculation based on:
|
||||||
* https://www.uptrends.com/support/kb/reporting/calculation-of-uptime-and-downtime
|
* https://www.uptrends.com/support/kb/reporting/calculation-of-uptime-and-downtime
|
||||||
* @param duration : int Hours
|
* @param {number} duration Hours
|
||||||
|
* @param {number} monitorID ID of monitor to calculate
|
||||||
*/
|
*/
|
||||||
static async calcUptime(duration, monitorID) {
|
static async calcUptime(duration, monitorID) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
@ -694,7 +731,7 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Handle new monitor with only one beat, because the beat's duration = 0
|
// Handle new monitor with only one beat, because the beat's duration = 0
|
||||||
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [monitorID]));
|
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [ monitorID ]));
|
||||||
|
|
||||||
if (status === UP) {
|
if (status === UP) {
|
||||||
uptime = 1;
|
uptime = 1;
|
||||||
|
@ -706,13 +743,23 @@ class Monitor extends BeanModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Uptime
|
* Send Uptime
|
||||||
* @param duration : int Hours
|
* @param {number} duration Hours
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {number} monitorID ID of monitor to send
|
||||||
|
* @param {number} userID ID of user to send to
|
||||||
*/
|
*/
|
||||||
static async sendUptime(duration, io, monitorID, userID) {
|
static async sendUptime(duration, io, monitorID, userID) {
|
||||||
const uptime = await this.calcUptime(duration, monitorID);
|
const uptime = await this.calcUptime(duration, monitorID);
|
||||||
io.to(userID).emit("uptime", monitorID, duration, uptime);
|
io.to(userID).emit("uptime", monitorID, duration, uptime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has status of monitor changed since last beat?
|
||||||
|
* @param {boolean} isFirstBeat Is this the first beat of this monitor?
|
||||||
|
* @param {const} previousBeatStatus Status of the previous beat
|
||||||
|
* @param {const} currentBeatStatus Status of the current beat
|
||||||
|
* @returns {boolean} True if is an important beat else false
|
||||||
|
*/
|
||||||
static isImportantBeat(isFirstBeat, previousBeatStatus, currentBeatStatus) {
|
static isImportantBeat(isFirstBeat, previousBeatStatus, currentBeatStatus) {
|
||||||
// * ? -> ANY STATUS = important [isFirstBeat]
|
// * ? -> ANY STATUS = important [isFirstBeat]
|
||||||
// UP -> PENDING = not important
|
// UP -> PENDING = not important
|
||||||
|
@ -731,6 +778,12 @@ class Monitor extends BeanModel {
|
||||||
return isImportant;
|
return isImportant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a notification about a monitor
|
||||||
|
* @param {boolean} isFirstBeat Is this beat the first of this monitor?
|
||||||
|
* @param {Monitor} monitor The monitor to send a notificaton about
|
||||||
|
* @param {Bean} bean Status information about monitor
|
||||||
|
*/
|
||||||
static async sendNotification(isFirstBeat, monitor, bean) {
|
static async sendNotification(isFirstBeat, monitor, bean) {
|
||||||
if (!isFirstBeat || bean.status === DOWN) {
|
if (!isFirstBeat || bean.status === DOWN) {
|
||||||
const notificationList = await Monitor.getNotificationList(monitor);
|
const notificationList = await Monitor.getNotificationList(monitor);
|
||||||
|
@ -755,6 +808,11 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of notification providers for a given monitor
|
||||||
|
* @param {Monitor} monitor Monitor to get notification providers for
|
||||||
|
* @returns {Promise<LooseObject<any>[]>}
|
||||||
|
*/
|
||||||
static async getNotificationList(monitor) {
|
static async getNotificationList(monitor) {
|
||||||
let notificationList = await R.getAll("SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id ", [
|
let notificationList = await R.getAll("SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id ", [
|
||||||
monitor.id,
|
monitor.id,
|
||||||
|
@ -762,6 +820,10 @@ class Monitor extends BeanModel {
|
||||||
return notificationList;
|
return notificationList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send notification about a certificate
|
||||||
|
* @param {Object} tlsInfoObject Information about certificate
|
||||||
|
*/
|
||||||
async sendCertNotification(tlsInfoObject) {
|
async sendCertNotification(tlsInfoObject) {
|
||||||
if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
|
if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
|
||||||
const notificationList = await Monitor.getNotificationList(this);
|
const notificationList = await Monitor.getNotificationList(this);
|
||||||
|
@ -773,6 +835,14 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a certificate notification when certificate expires in less
|
||||||
|
* than target days
|
||||||
|
* @param {number} daysRemaining Number of days remaining on certifcate
|
||||||
|
* @param {number} targetDays Number of days to alert after
|
||||||
|
* @param {LooseObject<any>[]} notificationList List of notification providers
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {
|
async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {
|
||||||
|
|
||||||
if (daysRemaining > targetDays) {
|
if (daysRemaining > targetDays) {
|
||||||
|
@ -820,6 +890,11 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of the previous heartbeat
|
||||||
|
* @param {number} monitorID ID of monitor to check
|
||||||
|
* @returns {Promise<LooseObject<any>>}
|
||||||
|
*/
|
||||||
static async getPreviousHeartbeat(monitorID) {
|
static async getPreviousHeartbeat(monitorID) {
|
||||||
return await R.getRow(`
|
return await R.getRow(`
|
||||||
SELECT status, time FROM heartbeat
|
SELECT status, time FROM heartbeat
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
|
|
||||||
class Proxy extends BeanModel {
|
class Proxy extends BeanModel {
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this._id,
|
id: this._id,
|
||||||
|
|
|
@ -6,6 +6,7 @@ class StatusPage extends BeanModel {
|
||||||
static domainMappingList = { };
|
static domainMappingList = { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Loads domain mapping from DB
|
||||||
* Return object like this: { "test-uptime.kuma.pet": "default" }
|
* Return object like this: { "test-uptime.kuma.pet": "default" }
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
|
@ -17,6 +18,12 @@ class StatusPage extends BeanModel {
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send status page list to client
|
||||||
|
* @param {Server} io io Socket server instance
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
* @returns {Promise<Bean[]>}
|
||||||
|
*/
|
||||||
static async sendStatusPageList(io, socket) {
|
static async sendStatusPageList(io, socket) {
|
||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
|
@ -30,6 +37,11 @@ class StatusPage extends BeanModel {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update list of domain names
|
||||||
|
* @param {string[]} domainNameList
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async updateDomainNameList(domainNameList) {
|
async updateDomainNameList(domainNameList) {
|
||||||
|
|
||||||
if (!Array.isArray(domainNameList)) {
|
if (!Array.isArray(domainNameList)) {
|
||||||
|
@ -69,6 +81,10 @@ class StatusPage extends BeanModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of domain names
|
||||||
|
* @returns {Object[]}
|
||||||
|
*/
|
||||||
getDomainNameList() {
|
getDomainNameList() {
|
||||||
let domainList = [];
|
let domainList = [];
|
||||||
for (let domain in StatusPage.domainMappingList) {
|
for (let domain in StatusPage.domainMappingList) {
|
||||||
|
@ -81,6 +97,10 @@ class StatusPage extends BeanModel {
|
||||||
return domainList;
|
return domainList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
async toJSON() {
|
async toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
@ -98,6 +118,11 @@ class StatusPage extends BeanModel {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
async toPublicJSON() {
|
async toPublicJSON() {
|
||||||
return {
|
return {
|
||||||
slug: this.slug,
|
slug: this.slug,
|
||||||
|
@ -113,12 +138,20 @@ class StatusPage extends BeanModel {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert slug to status page ID
|
||||||
|
* @param {string} slug
|
||||||
|
*/
|
||||||
static async slugToID(slug) {
|
static async slugToID(slug) {
|
||||||
return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [
|
return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [
|
||||||
slug
|
slug
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get path to the icon for the page
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
getIcon() {
|
getIcon() {
|
||||||
if (!this.icon) {
|
if (!this.icon) {
|
||||||
return "/icon.svg";
|
return "/icon.svg";
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
|
|
||||||
class Tag extends BeanModel {
|
class Tag extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this._id,
|
id: this._id,
|
||||||
|
|
|
@ -3,12 +3,11 @@ const passwordHash = require("../password-hash");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
|
|
||||||
class User extends BeanModel {
|
class User extends BeanModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Reset user password
|
||||||
* Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
|
* Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
|
||||||
* @param userID
|
* @param {number} userID ID of user to update
|
||||||
* @param newPassword
|
* @param {string} newPassword
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async resetPassword(userID, newPassword) {
|
static async resetPassword(userID, newPassword) {
|
||||||
|
@ -19,8 +18,8 @@ class User extends BeanModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Reset this users password
|
||||||
* @param newPassword
|
* @param {string} newPassword
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async resetPassword(newPassword) {
|
async resetPassword(newPassword) {
|
||||||
|
|
|
@ -13,27 +13,49 @@ let t = {
|
||||||
|
|
||||||
let instances = [];
|
let instances = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a === b
|
||||||
|
* @param {any} a
|
||||||
|
* @returns {function(any): boolean}
|
||||||
|
*/
|
||||||
let matches = function (a) {
|
let matches = function (a) {
|
||||||
return function (b) {
|
return function (b) {
|
||||||
return a === b;
|
return a === b;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a!==b
|
||||||
|
* @param {any} a
|
||||||
|
* @returns {function(any): boolean}
|
||||||
|
*/
|
||||||
let doesntMatch = function (a) {
|
let doesntMatch = function (a) {
|
||||||
return function (b) {
|
return function (b) {
|
||||||
return !matches(a)(b);
|
return !matches(a)(b);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get log duration
|
||||||
|
* @param {number} d Time in ms
|
||||||
|
* @param {string} prefix Prefix for log
|
||||||
|
* @returns {string} Coloured log string
|
||||||
|
*/
|
||||||
let logDuration = function (d, prefix) {
|
let logDuration = function (d, prefix) {
|
||||||
let str = d > 1000 ? (d / 1000).toFixed(2) + "sec" : d + "ms";
|
let str = d > 1000 ? (d / 1000).toFixed(2) + "sec" : d + "ms";
|
||||||
return "\x1b[33m- " + (prefix ? prefix + " " : "") + str + "\x1b[0m";
|
return "\x1b[33m- " + (prefix ? prefix + " " : "") + str + "\x1b[0m";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get safe headers
|
||||||
|
* @param {Object} res Express response object
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
function getSafeHeaders(res) {
|
function getSafeHeaders(res) {
|
||||||
return res.getHeaders ? res.getHeaders() : res._headers;
|
return res.getHeaders ? res.getHeaders() : res._headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Constructor for ApiCache instance */
|
||||||
function ApiCache() {
|
function ApiCache() {
|
||||||
let memCache = new MemoryCache();
|
let memCache = new MemoryCache();
|
||||||
|
|
||||||
|
@ -70,10 +92,10 @@ function ApiCache() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a message to the console if the `DEBUG` environment variable is set.
|
* Logs a message to the console if the `DEBUG` environment variable is set.
|
||||||
* @param {string} a - The first argument to log.
|
* @param {string} a The first argument to log.
|
||||||
* @param {string} b - The second argument to log.
|
* @param {string} b The second argument to log.
|
||||||
* @param {string} c - The third argument to log.
|
* @param {string} c The third argument to log.
|
||||||
* @param {string} d - The fourth argument to log, and so on... (optional)
|
* @param {string} d The fourth argument to log, and so on... (optional)
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
|
@ -90,8 +112,8 @@ function ApiCache() {
|
||||||
* Returns true if the given request and response should be logged.
|
* Returns true if the given request and response should be logged.
|
||||||
* @param {Object} request The HTTP request object.
|
* @param {Object} request The HTTP request object.
|
||||||
* @param {Object} response The HTTP response object.
|
* @param {Object} response The HTTP response object.
|
||||||
*
|
* @param {function(Object, Object):boolean} toggle
|
||||||
* Generated by Trelent
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function shouldCacheResponse(request, response, toggle) {
|
function shouldCacheResponse(request, response, toggle) {
|
||||||
let opt = globalOptions;
|
let opt = globalOptions;
|
||||||
|
@ -116,10 +138,9 @@ function ApiCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a key to the index.
|
* Add key to index array
|
||||||
* @param {string} key The key to add.
|
* @param {string} key Key to add
|
||||||
*
|
* @param {Object} req Express request object
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
function addIndexEntries(key, req) {
|
function addIndexEntries(key, req) {
|
||||||
let groupName = req.apicacheGroup;
|
let groupName = req.apicacheGroup;
|
||||||
|
@ -135,8 +156,11 @@ function ApiCache() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new object containing only the whitelisted headers.
|
* Returns a new object containing only the whitelisted headers.
|
||||||
* @param {Object} headers The original object of header names and values.
|
* @param {Object} headers The original object of header names and
|
||||||
* @param {Array.<string>} globalOptions.headerWhitelist An array of strings representing the whitelisted header names to keep in the output object.
|
* values.
|
||||||
|
* @param {string[]} globalOptions.headerWhitelist An array of
|
||||||
|
* strings representing the whitelisted header names to keep in the
|
||||||
|
* output object.
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
|
@ -152,8 +176,10 @@ function ApiCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Create a cache object
|
||||||
* @param {Object} headers The response headers to filter.
|
* @param {Object} headers The response headers to filter.
|
||||||
* @returns {Object} A new object containing only the whitelisted response headers.
|
* @returns {Object} A new object containing only the whitelisted
|
||||||
|
* response headers.
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
|
@ -170,8 +196,9 @@ function ApiCache() {
|
||||||
/**
|
/**
|
||||||
* Sets a cache value for the given key.
|
* Sets a cache value for the given key.
|
||||||
* @param {string} key The cache key to set.
|
* @param {string} key The cache key to set.
|
||||||
* @param {*} value The cache value to set.
|
* @param {any} value The cache value to set.
|
||||||
* @param {number} duration How long in milliseconds the cached response should be valid for (defaults to 1 hour).
|
* @param {number} duration How long in milliseconds the cached
|
||||||
|
* response should be valid for (defaults to 1 hour).
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
|
@ -199,7 +226,8 @@ function ApiCache() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends content to the response.
|
* Appends content to the response.
|
||||||
* @param {string|Buffer} content The content to append.
|
* @param {Object} res Express response object
|
||||||
|
* @param {(string|Buffer)} content The content to append.
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
|
@ -229,11 +257,15 @@ function ApiCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monkeypatches the response object to add cache control headers and create a cache object.
|
* Monkeypatches the response object to add cache control headers
|
||||||
* @param {Object} req - The request object.
|
* and create a cache object.
|
||||||
* @param {Object} res - The response object.
|
* @param {Object} req Express request object
|
||||||
*
|
* @param {Object} res Express response object
|
||||||
* Generated by Trelent
|
* @param {function} next Function to call next
|
||||||
|
* @param {string} key Key to add response as
|
||||||
|
* @param {number} duration Time to cache response for
|
||||||
|
* @param {string} strDuration Duration in string form
|
||||||
|
* @param {function(Object, Object):boolean} toggle
|
||||||
*/
|
*/
|
||||||
function makeResponseCacheable(req, res, next, key, duration, strDuration, toggle) {
|
function makeResponseCacheable(req, res, next, key, duration, strDuration, toggle) {
|
||||||
// monkeypatch res.end to create cache object
|
// monkeypatch res.end to create cache object
|
||||||
|
@ -302,11 +334,15 @@ function ApiCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Request} request
|
* Send a cached response to client
|
||||||
* @param {Response} response
|
* @param {Request} request Express request object
|
||||||
* @returns {boolean|undefined} true if the request should be cached, false otherwise. If undefined, defaults to true.
|
* @param {Response} response Express response object
|
||||||
*
|
* @param {object} cacheObject Cache object to send
|
||||||
* Generated by Trelent
|
* @param {function(Object, Object):boolean} toggle
|
||||||
|
* @param {function} next Function to call next
|
||||||
|
* @param {number} duration Not used
|
||||||
|
* @returns {boolean|undefined} true if the request should be
|
||||||
|
* cached, false otherwise. If undefined, defaults to true.
|
||||||
*/
|
*/
|
||||||
function sendCachedResponse(request, response, cacheObject, toggle, next, duration) {
|
function sendCachedResponse(request, response, cacheObject, toggle, next, duration) {
|
||||||
if (toggle && !toggle(request, response)) {
|
if (toggle && !toggle(request, response)) {
|
||||||
|
@ -348,12 +384,19 @@ function ApiCache() {
|
||||||
return response.end(data, cacheObject.encoding);
|
return response.end(data, cacheObject.encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sync caching options */
|
||||||
function syncOptions() {
|
function syncOptions() {
|
||||||
for (let i in middlewareOptions) {
|
for (let i in middlewareOptions) {
|
||||||
Object.assign(middlewareOptions[i].options, globalOptions, middlewareOptions[i].localOptions);
|
Object.assign(middlewareOptions[i].options, globalOptions, middlewareOptions[i].localOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear key from cache
|
||||||
|
* @param {string} target Key to clear
|
||||||
|
* @param {boolean} isAutomatic Is the key being cleared automatically
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
this.clear = function (target, isAutomatic) {
|
this.clear = function (target, isAutomatic) {
|
||||||
let group = index.groups[target];
|
let group = index.groups[target];
|
||||||
let redis = globalOptions.redisClient;
|
let redis = globalOptions.redisClient;
|
||||||
|
@ -430,10 +473,11 @@ function ApiCache() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a duration string to an integer number of milliseconds.
|
* Converts a duration string to an integer number of milliseconds.
|
||||||
* @param {string} duration - The string to convert.
|
* @param {(string|number)} duration The string to convert.
|
||||||
* @returns {number} The converted value in milliseconds, or the defaultDuration if it can't be parsed.
|
* @param {number} defaultDuration The default duration to return if
|
||||||
*
|
* can't parse duration
|
||||||
* Generated by Trelent
|
* @returns {number} The converted value in milliseconds, or the
|
||||||
|
* defaultDuration if it can't be parsed.
|
||||||
*/
|
*/
|
||||||
function parseDuration(duration, defaultDuration) {
|
function parseDuration(duration, defaultDuration) {
|
||||||
if (typeof duration === "number") {
|
if (typeof duration === "number") {
|
||||||
|
@ -457,17 +501,24 @@ function ApiCache() {
|
||||||
return defaultDuration;
|
return defaultDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse duration
|
||||||
|
* @param {(number|string)} duration
|
||||||
|
* @returns {number} Duration parsed to a number
|
||||||
|
*/
|
||||||
this.getDuration = function (duration) {
|
this.getDuration = function (duration) {
|
||||||
return parseDuration(duration, globalOptions.defaultDuration);
|
return parseDuration(duration, globalOptions.defaultDuration);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return cache performance statistics (hit rate). Suitable for putting into a route:
|
* Return cache performance statistics (hit rate). Suitable for
|
||||||
|
* putting into a route:
|
||||||
* <code>
|
* <code>
|
||||||
* app.get('/api/cache/performance', (req, res) => {
|
* app.get('/api/cache/performance', (req, res) => {
|
||||||
* res.json(apicache.getPerformance())
|
* res.json(apicache.getPerformance())
|
||||||
* })
|
* })
|
||||||
* </code>
|
* </code>
|
||||||
|
* @returns {any[]}
|
||||||
*/
|
*/
|
||||||
this.getPerformance = function () {
|
this.getPerformance = function () {
|
||||||
return performanceArray.map(function (p) {
|
return performanceArray.map(function (p) {
|
||||||
|
@ -475,6 +526,11 @@ function ApiCache() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get index of a group
|
||||||
|
* @param {string} group
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
this.getIndex = function (group) {
|
this.getIndex = function (group) {
|
||||||
if (group) {
|
if (group) {
|
||||||
return index.groups[group];
|
return index.groups[group];
|
||||||
|
@ -483,6 +539,14 @@ function ApiCache() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Express middleware
|
||||||
|
* @param {(string|number)} strDuration Duration to cache responses
|
||||||
|
* for.
|
||||||
|
* @param {function(Object, Object):boolean} middlewareToggle
|
||||||
|
* @param {Object} localOptions Options for APICache
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
this.middleware = function cache(strDuration, middlewareToggle, localOptions) {
|
this.middleware = function cache(strDuration, middlewareToggle, localOptions) {
|
||||||
let duration = instance.getDuration(strDuration);
|
let duration = instance.getDuration(strDuration);
|
||||||
let opt = {};
|
let opt = {};
|
||||||
|
@ -506,63 +570,72 @@ function ApiCache() {
|
||||||
options(localOptions);
|
options(localOptions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Function for non tracking performance
|
* A Function for non tracking performance
|
||||||
*/
|
*/
|
||||||
function NOOPCachePerformance() {
|
function NOOPCachePerformance() {
|
||||||
this.report = this.hit = this.miss = function () {}; // noop;
|
this.report = this.hit = this.miss = function () {}; // noop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function for tracking and reporting hit rate. These statistics are returned by the getPerformance() call above.
|
* A function for tracking and reporting hit rate. These
|
||||||
*/
|
* statistics are returned by the getPerformance() call above.
|
||||||
|
*/
|
||||||
function CachePerformance() {
|
function CachePerformance() {
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 100 requests.
|
* Tracks the hit rate for the last 100 requests. If there
|
||||||
* If there have been fewer than 100 requests, the hit rate just considers the requests that have happened.
|
* have been fewer than 100 requests, the hit rate just
|
||||||
*/
|
* considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast100 = new Uint8Array(100 / 4); // each hit is 2 bits
|
this.hitsLast100 = new Uint8Array(100 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 1000 requests.
|
* Tracks the hit rate for the last 1000 requests. If there
|
||||||
* If there have been fewer than 1000 requests, the hit rate just considers the requests that have happened.
|
* have been fewer than 1000 requests, the hit rate just
|
||||||
*/
|
* considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast1000 = new Uint8Array(1000 / 4); // each hit is 2 bits
|
this.hitsLast1000 = new Uint8Array(1000 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 10000 requests.
|
* Tracks the hit rate for the last 10000 requests. If there
|
||||||
* If there have been fewer than 10000 requests, the hit rate just considers the requests that have happened.
|
* have been fewer than 10000 requests, the hit rate just
|
||||||
*/
|
* considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast10000 = new Uint8Array(10000 / 4); // each hit is 2 bits
|
this.hitsLast10000 = new Uint8Array(10000 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 100000 requests.
|
* Tracks the hit rate for the last 100000 requests. If
|
||||||
* If there have been fewer than 100000 requests, the hit rate just considers the requests that have happened.
|
* there have been fewer than 100000 requests, the hit rate
|
||||||
*/
|
* just considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast100000 = new Uint8Array(100000 / 4); // each hit is 2 bits
|
this.hitsLast100000 = new Uint8Array(100000 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of calls that have passed through the middleware since the server started.
|
* The number of calls that have passed through the
|
||||||
*/
|
* middleware since the server started.
|
||||||
|
*/
|
||||||
this.callCount = 0;
|
this.callCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The total number of hits since the server started
|
* The total number of hits since the server started
|
||||||
*/
|
*/
|
||||||
this.hitCount = 0;
|
this.hitCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key from the last cache hit. This is useful in identifying which route these statistics apply to.
|
* The key from the last cache hit. This is useful in
|
||||||
*/
|
* identifying which route these statistics apply to.
|
||||||
|
*/
|
||||||
this.lastCacheHit = null;
|
this.lastCacheHit = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key from the last cache miss. This is useful in identifying which route these statistics apply to.
|
* The key from the last cache miss. This is useful in
|
||||||
*/
|
* identifying which route these statistics apply to.
|
||||||
|
*/
|
||||||
this.lastCacheMiss = null;
|
this.lastCacheMiss = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return performance statistics
|
* Return performance statistics
|
||||||
*/
|
* @returns {Object}
|
||||||
|
*/
|
||||||
this.report = function () {
|
this.report = function () {
|
||||||
return {
|
return {
|
||||||
lastCacheHit: this.lastCacheHit,
|
lastCacheHit: this.lastCacheHit,
|
||||||
|
@ -579,10 +652,13 @@ function ApiCache() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes a cache hit rate from an array of hits and misses.
|
* Computes a cache hit rate from an array of hits and
|
||||||
* @param {Uint8Array} array An array representing hits and misses.
|
* misses.
|
||||||
* @returns a number between 0 and 1, or null if the array has no hits or misses
|
* @param {Uint8Array} array An array representing hits and
|
||||||
*/
|
* misses.
|
||||||
|
* @returns {?number} a number between 0 and 1, or null if
|
||||||
|
* the array has no hits or misses
|
||||||
|
*/
|
||||||
this.hitRate = function (array) {
|
this.hitRate = function (array) {
|
||||||
let hits = 0;
|
let hits = 0;
|
||||||
let misses = 0;
|
let misses = 0;
|
||||||
|
@ -608,16 +684,17 @@ function ApiCache() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Record a hit or miss in the given array. It will be recorded at a position determined
|
* Record a hit or miss in the given array. It will be
|
||||||
* by the current value of the callCount variable.
|
* recorded at a position determined by the current value of
|
||||||
* @param {Uint8Array} array An array representing hits and misses.
|
* the callCount variable.
|
||||||
* @param {boolean} hit true for a hit, false for a miss
|
* @param {Uint8Array} array An array representing hits and
|
||||||
* Each element in the array is 8 bits, and encodes 4 hit/miss records.
|
* misses.
|
||||||
* Each hit or miss is encoded as to bits as follows:
|
* @param {boolean} hit true for a hit, false for a miss
|
||||||
* 00 means no hit or miss has been recorded in these bits
|
* Each element in the array is 8 bits, and encodes 4
|
||||||
* 01 encodes a hit
|
* hit/miss records. Each hit or miss is encoded as to bits
|
||||||
* 10 encodes a miss
|
* as follows: 00 means no hit or miss has been recorded in
|
||||||
*/
|
* these bits 01 encodes a hit 10 encodes a miss
|
||||||
|
*/
|
||||||
this.recordHitInArray = function (array, hit) {
|
this.recordHitInArray = function (array, hit) {
|
||||||
let arrayIndex = ~~(this.callCount / 4) % array.length;
|
let arrayIndex = ~~(this.callCount / 4) % array.length;
|
||||||
let bitOffset = (this.callCount % 4) * 2; // 2 bits per record, 4 records per uint8 array element
|
let bitOffset = (this.callCount % 4) * 2; // 2 bits per record, 4 records per uint8 array element
|
||||||
|
@ -627,9 +704,11 @@ function ApiCache() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records the hit or miss in the tracking arrays and increments the call count.
|
* Records the hit or miss in the tracking arrays and
|
||||||
* @param {boolean} hit true records a hit, false records a miss
|
* increments the call count.
|
||||||
*/
|
* @param {boolean} hit true records a hit, false records a
|
||||||
|
* miss
|
||||||
|
*/
|
||||||
this.recordHit = function (hit) {
|
this.recordHit = function (hit) {
|
||||||
this.recordHitInArray(this.hitsLast100, hit);
|
this.recordHitInArray(this.hitsLast100, hit);
|
||||||
this.recordHitInArray(this.hitsLast1000, hit);
|
this.recordHitInArray(this.hitsLast1000, hit);
|
||||||
|
@ -642,18 +721,18 @@ function ApiCache() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records a hit event, setting lastCacheMiss to the given key
|
* Records a hit event, setting lastCacheMiss to the given key
|
||||||
* @param {string} key The key that had the cache hit
|
* @param {string} key The key that had the cache hit
|
||||||
*/
|
*/
|
||||||
this.hit = function (key) {
|
this.hit = function (key) {
|
||||||
this.recordHit(true);
|
this.recordHit(true);
|
||||||
this.lastCacheHit = key;
|
this.lastCacheHit = key;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records a miss event, setting lastCacheMiss to the given key
|
* Records a miss event, setting lastCacheMiss to the given key
|
||||||
* @param {string} key The key that had the cache miss
|
* @param {string} key The key that had the cache miss
|
||||||
*/
|
*/
|
||||||
this.miss = function (key) {
|
this.miss = function (key) {
|
||||||
this.recordHit(false);
|
this.recordHit(false);
|
||||||
this.lastCacheMiss = key;
|
this.lastCacheMiss = key;
|
||||||
|
@ -664,6 +743,13 @@ function ApiCache() {
|
||||||
|
|
||||||
performanceArray.push(perf);
|
performanceArray.push(perf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache a request
|
||||||
|
* @param {Object} req Express request object
|
||||||
|
* @param {Object} res Express response object
|
||||||
|
* @param {function} next Function to call next
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
let cache = function (req, res, next) {
|
let cache = function (req, res, next) {
|
||||||
function bypass() {
|
function bypass() {
|
||||||
debug("bypass detected, skipping cache.");
|
debug("bypass detected, skipping cache.");
|
||||||
|
@ -771,6 +857,11 @@ function ApiCache() {
|
||||||
return cache;
|
return cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process options
|
||||||
|
* @param {Object} options
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
this.options = function (options) {
|
this.options = function (options) {
|
||||||
if (options) {
|
if (options) {
|
||||||
Object.assign(globalOptions, options);
|
Object.assign(globalOptions, options);
|
||||||
|
@ -791,6 +882,7 @@ function ApiCache() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Reset the index */
|
||||||
this.resetIndex = function () {
|
this.resetIndex = function () {
|
||||||
index = {
|
index = {
|
||||||
all: [],
|
all: [],
|
||||||
|
@ -798,6 +890,11 @@ function ApiCache() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of ApiCache
|
||||||
|
* @param {Object} config Config to pass
|
||||||
|
* @returns {ApiCache}
|
||||||
|
*/
|
||||||
this.newInstance = function (config) {
|
this.newInstance = function (config) {
|
||||||
let instance = new ApiCache();
|
let instance = new ApiCache();
|
||||||
|
|
||||||
|
@ -808,6 +905,7 @@ function ApiCache() {
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Clone this instance */
|
||||||
this.clone = function () {
|
this.clone = function () {
|
||||||
return this.newInstance(this.options());
|
return this.newInstance(this.options());
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,15 @@ function MemoryCache() {
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} key Key to store cache as
|
||||||
|
* @param {any} value Value to store
|
||||||
|
* @param {number} time Time to store for
|
||||||
|
* @param {function(any, string)} timeoutCallback Callback to call in
|
||||||
|
* case of timeout
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.add = function (key, value, time, timeoutCallback) {
|
MemoryCache.prototype.add = function (key, value, time, timeoutCallback) {
|
||||||
let old = this.cache[key];
|
let old = this.cache[key];
|
||||||
let instance = this;
|
let instance = this;
|
||||||
|
@ -22,6 +31,11 @@ MemoryCache.prototype.add = function (key, value, time, timeoutCallback) {
|
||||||
return entry;
|
return entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a cache entry
|
||||||
|
* @param {string} key Key to delete
|
||||||
|
* @returns {null}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.delete = function (key) {
|
MemoryCache.prototype.delete = function (key) {
|
||||||
let entry = this.cache[key];
|
let entry = this.cache[key];
|
||||||
|
|
||||||
|
@ -36,18 +50,32 @@ MemoryCache.prototype.delete = function (key) {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value of key
|
||||||
|
* @param {string} key
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.get = function (key) {
|
MemoryCache.prototype.get = function (key) {
|
||||||
let entry = this.cache[key];
|
let entry = this.cache[key];
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value of cache entry
|
||||||
|
* @param {string} key
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.getValue = function (key) {
|
MemoryCache.prototype.getValue = function (key) {
|
||||||
let entry = this.get(key);
|
let entry = this.get(key);
|
||||||
|
|
||||||
return entry && entry.value;
|
return entry && entry.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear cache
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.clear = function () {
|
MemoryCache.prototype.clear = function () {
|
||||||
Object.keys(this.cache).forEach(function (key) {
|
Object.keys(this.cache).forEach(function (key) {
|
||||||
this.delete(key);
|
this.delete(key);
|
||||||
|
|
|
@ -37,6 +37,12 @@ class AliyunSMS extends NotificationProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the SMS notification
|
||||||
|
* @param {BeanModel} notification Notification details
|
||||||
|
* @param {string} msgbody Message template
|
||||||
|
* @returns {boolean} True if successful else false
|
||||||
|
*/
|
||||||
async sendSms(notification, msgbody) {
|
async sendSms(notification, msgbody) {
|
||||||
let params = {
|
let params = {
|
||||||
PhoneNumbers: notification.phonenumber,
|
PhoneNumbers: notification.phonenumber,
|
||||||
|
@ -70,7 +76,12 @@ class AliyunSMS extends NotificationProvider {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Aliyun request sign */
|
/**
|
||||||
|
* Aliyun request sign
|
||||||
|
* @param {Object} param Parameters object to sign
|
||||||
|
* @param {string} AccessKeySecret Secret key to sign parameters with
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
sign(param, AccessKeySecret) {
|
sign(param, AccessKeySecret) {
|
||||||
let param2 = {};
|
let param2 = {};
|
||||||
let data = [];
|
let data = [];
|
||||||
|
@ -93,6 +104,11 @@ class AliyunSMS extends NotificationProvider {
|
||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert status constant to string
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
statusToString(status) {
|
statusToString(status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DOWN:
|
case DOWN:
|
||||||
|
|
|
@ -44,7 +44,12 @@ class Bark extends NotificationProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add additional parameter for better on device styles (iOS 15 optimized)
|
/**
|
||||||
|
* Add additional parameter for better on device styles (iOS 15
|
||||||
|
* optimized)
|
||||||
|
* @param {string} postUrl URL to append parameters to
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
appendAdditionalParameters(postUrl) {
|
appendAdditionalParameters(postUrl) {
|
||||||
// grouping all our notifications
|
// grouping all our notifications
|
||||||
postUrl += "?group=" + barkNotificationGroup;
|
postUrl += "?group=" + barkNotificationGroup;
|
||||||
|
@ -55,7 +60,11 @@ class Bark extends NotificationProvider {
|
||||||
return postUrl;
|
return postUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// thrown if failed to check result, result code should be in range 2xx
|
/**
|
||||||
|
* Check if result is successful
|
||||||
|
* @param {Object} result Axios response object
|
||||||
|
* @throws {Error} The status code is not in range 2xx
|
||||||
|
*/
|
||||||
checkResult(result) {
|
checkResult(result) {
|
||||||
if (result.status == null) {
|
if (result.status == null) {
|
||||||
throw new Error("Bark notification failed with invalid response!");
|
throw new Error("Bark notification failed with invalid response!");
|
||||||
|
@ -65,6 +74,13 @@ class Bark extends NotificationProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the message
|
||||||
|
* @param {string} title Message title
|
||||||
|
* @param {string} subtitle Message
|
||||||
|
* @param {string} endpoint Endpoint to send request to
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
async postNotification(title, subtitle, endpoint) {
|
async postNotification(title, subtitle, endpoint) {
|
||||||
// url encode title and subtitle
|
// url encode title and subtitle
|
||||||
title = encodeURIComponent(title);
|
title = encodeURIComponent(title);
|
||||||
|
|
|
@ -37,6 +37,12 @@ class DingDing extends NotificationProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message to DingDing
|
||||||
|
* @param {BeanModel} notification
|
||||||
|
* @param {Object} params Parameters of message
|
||||||
|
* @returns {boolean} True if successful else false
|
||||||
|
*/
|
||||||
async sendToDingDing(notification, params) {
|
async sendToDingDing(notification, params) {
|
||||||
let timestamp = Date.now();
|
let timestamp = Date.now();
|
||||||
|
|
||||||
|
@ -56,7 +62,12 @@ class DingDing extends NotificationProvider {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** DingDing sign */
|
/**
|
||||||
|
* DingDing sign
|
||||||
|
* @param {Date} timestamp Timestamp of message
|
||||||
|
* @param {string} secretKey Secret key to sign data with
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
sign(timestamp, secretKey) {
|
sign(timestamp, secretKey) {
|
||||||
return Crypto
|
return Crypto
|
||||||
.createHmac("sha256", Buffer.from(secretKey, "utf8"))
|
.createHmac("sha256", Buffer.from(secretKey, "utf8"))
|
||||||
|
@ -64,7 +75,13 @@ class DingDing extends NotificationProvider {
|
||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert status constant to string
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
statusToString(status) {
|
statusToString(status) {
|
||||||
|
// TODO: Move to notification-provider.js to avoid repetition in classes
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DOWN:
|
case DOWN:
|
||||||
return "DOWN";
|
return "DOWN";
|
||||||
|
|
|
@ -7,17 +7,23 @@ class NotificationProvider {
|
||||||
name = undefined;
|
name = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param notification : BeanModel
|
* Send a notification
|
||||||
* @param msg : string General Message
|
* @param {BeanModel} notification
|
||||||
* @param monitorJSON : object Monitor details (For Up/Down only)
|
* @param {string} msg General Message
|
||||||
* @param heartbeatJSON : object Heartbeat details (For Up/Down only)
|
* @param {?Object} monitorJSON Monitor details (For Up/Down only)
|
||||||
|
* @param {?Object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||||
* @returns {Promise<string>} Return Successful Message
|
* @returns {Promise<string>} Return Successful Message
|
||||||
* Throw Error with fail msg
|
* @throws Error with fail msg
|
||||||
*/
|
*/
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
throw new Error("Have to override Notification.send(...)");
|
throw new Error("Have to override Notification.send(...)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws an error
|
||||||
|
* @param {any} error The error to throw
|
||||||
|
* @throws {any} The error specified
|
||||||
|
*/
|
||||||
throwGeneralAxiosError(error) {
|
throwGeneralAxiosError(error) {
|
||||||
let msg = "Error: " + error + " ";
|
let msg = "Error: " + error + " ";
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Slack extends NotificationProvider {
|
||||||
/**
|
/**
|
||||||
* Deprecated property notification.slackbutton
|
* Deprecated property notification.slackbutton
|
||||||
* Set it as primary base url if this is not yet set.
|
* Set it as primary base url if this is not yet set.
|
||||||
|
* @param {string} url The primary base URL to use
|
||||||
*/
|
*/
|
||||||
static async deprecateURL(url) {
|
static async deprecateURL(url) {
|
||||||
let currentPrimaryBaseURL = await setting("primaryBaseURL");
|
let currentPrimaryBaseURL = await setting("primaryBaseURL");
|
||||||
|
|
|
@ -5,6 +5,12 @@ const { DOWN, UP } = require("../../src/util");
|
||||||
class Teams extends NotificationProvider {
|
class Teams extends NotificationProvider {
|
||||||
name = "teams";
|
name = "teams";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the message to send
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @param {string} monitorName Name of monitor
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
_statusMessageFactory = (status, monitorName) => {
|
_statusMessageFactory = (status, monitorName) => {
|
||||||
if (status === DOWN) {
|
if (status === DOWN) {
|
||||||
return `🔴 Application [${monitorName}] went down`;
|
return `🔴 Application [${monitorName}] went down`;
|
||||||
|
@ -14,6 +20,11 @@ class Teams extends NotificationProvider {
|
||||||
return "Notification";
|
return "Notification";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select theme color to use based on status
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @returns {string} Selected color in hex RGB format
|
||||||
|
*/
|
||||||
_getThemeColor = (status) => {
|
_getThemeColor = (status) => {
|
||||||
if (status === DOWN) {
|
if (status === DOWN) {
|
||||||
return "ff0000";
|
return "ff0000";
|
||||||
|
@ -24,6 +35,14 @@ class Teams extends NotificationProvider {
|
||||||
return "008cff";
|
return "008cff";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate payload for notification
|
||||||
|
* @param {const} status The status of the monitor
|
||||||
|
* @param {string} monitorMessage Message to send
|
||||||
|
* @param {string} monitorName Name of monitor affected
|
||||||
|
* @param {string} monitorUrl URL of monitor affected
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
_notificationPayloadFactory = ({
|
_notificationPayloadFactory = ({
|
||||||
status,
|
status,
|
||||||
monitorMessage,
|
monitorMessage,
|
||||||
|
@ -74,10 +93,21 @@ class Teams extends NotificationProvider {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the notification
|
||||||
|
* @param {string} webhookUrl URL to send the request to
|
||||||
|
* @param {Object} payload Payload generated by _notificationPayloadFactory
|
||||||
|
*/
|
||||||
_sendNotification = async (webhookUrl, payload) => {
|
_sendNotification = async (webhookUrl, payload) => {
|
||||||
await axios.post(webhookUrl, payload);
|
await axios.post(webhookUrl, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a general notification
|
||||||
|
* @param {string} webhookUrl URL to send request to
|
||||||
|
* @param {string} msg Message to send
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
_handleGeneralNotification = (webhookUrl, msg) => {
|
_handleGeneralNotification = (webhookUrl, msg) => {
|
||||||
const payload = this._notificationPayloadFactory({
|
const payload = this._notificationPayloadFactory({
|
||||||
monitorMessage: msg
|
monitorMessage: msg
|
||||||
|
|
|
@ -24,6 +24,12 @@ class WeCom extends NotificationProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the message to send
|
||||||
|
* @param {Object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||||
|
* @param {string} msg General message
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
composeMessage(heartbeatJSON, msg) {
|
composeMessage(heartbeatJSON, msg) {
|
||||||
let title;
|
let title;
|
||||||
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ class Notification {
|
||||||
|
|
||||||
providerList = {};
|
providerList = {};
|
||||||
|
|
||||||
|
/** Initialize the notification providers */
|
||||||
static init() {
|
static init() {
|
||||||
log.info("notification", "Prepare Notification Providers");
|
log.info("notification", "Prepare Notification Providers");
|
||||||
|
|
||||||
|
@ -92,13 +93,13 @@ class Notification {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Send a notification
|
||||||
* @param notification : BeanModel
|
* @param {BeanModel} notification
|
||||||
* @param msg : string General Message
|
* @param {string} msg General Message
|
||||||
* @param monitorJSON : object Monitor details (For Up/Down only)
|
* @param {Object} monitorJSON Monitor details (For Up/Down only)
|
||||||
* @param heartbeatJSON : object Heartbeat details (For Up/Down only)
|
* @param {Object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||||
* @returns {Promise<string>} Successful msg
|
* @returns {Promise<string>} Successful msg
|
||||||
* Throw Error with fail msg
|
* @throws Error with fail msg
|
||||||
*/
|
*/
|
||||||
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
if (this.providerList[notification.type]) {
|
if (this.providerList[notification.type]) {
|
||||||
|
@ -108,6 +109,13 @@ class Notification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save a notification
|
||||||
|
* @param {Object} notification Notification to save
|
||||||
|
* @param {?number} notificationID ID of notification to update
|
||||||
|
* @param {number} userID ID of user who adds notification
|
||||||
|
* @returns {Promise<Bean>}
|
||||||
|
*/
|
||||||
static async save(notification, notificationID, userID) {
|
static async save(notification, notificationID, userID) {
|
||||||
let bean;
|
let bean;
|
||||||
|
|
||||||
|
@ -138,6 +146,12 @@ class Notification {
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a notification
|
||||||
|
* @param {number} notificationID ID of notification to delete
|
||||||
|
* @param {number} userID ID of user who created notification
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async delete(notificationID, userID) {
|
static async delete(notificationID, userID) {
|
||||||
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
||||||
notificationID,
|
notificationID,
|
||||||
|
@ -151,6 +165,10 @@ class Notification {
|
||||||
await R.trash(bean);
|
await R.trash(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if apprise exists
|
||||||
|
* @returns {boolean} Does the command apprise exist?
|
||||||
|
*/
|
||||||
static checkApprise() {
|
static checkApprise() {
|
||||||
let commandExistsSync = require("command-exists").sync;
|
let commandExistsSync = require("command-exists").sync;
|
||||||
let exists = commandExistsSync("apprise");
|
let exists = commandExistsSync("apprise");
|
||||||
|
@ -160,11 +178,10 @@ class Notification {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new monitor to the database.
|
* Apply the notification to every monitor
|
||||||
* @param {number} userID The ID of the user that owns this monitor.
|
* @param {number} notificationID ID of notification to apply
|
||||||
* @param {string} name The name of this monitor.
|
* @param {number} userID ID of user who created notification
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function applyNotificationEveryMonitor(notificationID, userID) {
|
async function applyNotificationEveryMonitor(notificationID, userID) {
|
||||||
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
|
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
|
||||||
|
|
|
@ -2,10 +2,21 @@ const passwordHashOld = require("password-hash");
|
||||||
const bcrypt = require("bcryptjs");
|
const bcrypt = require("bcryptjs");
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash a password
|
||||||
|
* @param {string} password
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
exports.generate = function (password) {
|
exports.generate = function (password) {
|
||||||
return bcrypt.hashSync(password, saltRounds);
|
return bcrypt.hashSync(password, saltRounds);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify a password against a hash
|
||||||
|
* @param {string} password
|
||||||
|
* @param {string} hash
|
||||||
|
* @returns {boolean} Does the password match the hash?
|
||||||
|
*/
|
||||||
exports.verify = function (password, hash) {
|
exports.verify = function (password, hash) {
|
||||||
if (isSHA1(hash)) {
|
if (isSHA1(hash)) {
|
||||||
return passwordHashOld.verify(password, hash);
|
return passwordHashOld.verify(password, hash);
|
||||||
|
@ -14,10 +25,19 @@ exports.verify = function (password, hash) {
|
||||||
return bcrypt.compareSync(password, hash);
|
return bcrypt.compareSync(password, hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the hash a SHA1 hash
|
||||||
|
* @param {string} hash
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
function isSHA1(hash) {
|
function isSHA1(hash) {
|
||||||
return (typeof hash === "string" && hash.startsWith("sha1"));
|
return (typeof hash === "string" && hash.startsWith("sha1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the hash need to be rehashed?
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
exports.needRehash = function (hash) {
|
exports.needRehash = function (hash) {
|
||||||
return isSHA1(hash);
|
return isSHA1(hash);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,11 +9,10 @@ const util = require("./util-server");
|
||||||
module.exports = Ping;
|
module.exports = Ping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} host - The host to ping
|
* Constructor for ping class
|
||||||
* @param {object} [options] - Options for the ping command
|
* @param {string} host Host to ping
|
||||||
|
* @param {object} [options] Options for the ping command
|
||||||
* @param {array|string} [options.args] - Arguments to pass to the ping command
|
* @param {array|string} [options.args] - Arguments to pass to the ping command
|
||||||
*
|
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
function Ping(host, options) {
|
function Ping(host, options) {
|
||||||
if (!host) {
|
if (!host) {
|
||||||
|
@ -82,8 +81,17 @@ function Ping(host, options) {
|
||||||
|
|
||||||
Ping.prototype.__proto__ = events.EventEmitter.prototype;
|
Ping.prototype.__proto__ = events.EventEmitter.prototype;
|
||||||
|
|
||||||
// SEND A PING
|
/**
|
||||||
// ===========
|
* Callback for send
|
||||||
|
* @callback pingCB
|
||||||
|
* @param {any} err Any error encountered
|
||||||
|
* @param {number} ms Ping time in ms
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a ping
|
||||||
|
* @param {pingCB} callback Callback to call with results
|
||||||
|
*/
|
||||||
Ping.prototype.send = function (callback) {
|
Ping.prototype.send = function (callback) {
|
||||||
let self = this;
|
let self = this;
|
||||||
callback = callback || function (err, ms) {
|
callback = callback || function (err, ms) {
|
||||||
|
@ -157,8 +165,10 @@ Ping.prototype.send = function (callback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// CALL Ping#send(callback) ON A TIMER
|
/**
|
||||||
// ===================================
|
* Ping every interval
|
||||||
|
* @param {pingCB} callback Callback to call with results
|
||||||
|
*/
|
||||||
Ping.prototype.start = function (callback) {
|
Ping.prototype.start = function (callback) {
|
||||||
let self = this;
|
let self = this;
|
||||||
this._i = setInterval(function () {
|
this._i = setInterval(function () {
|
||||||
|
@ -167,8 +177,7 @@ Ping.prototype.start = function (callback) {
|
||||||
self.send(callback);
|
self.send(callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
// STOP SENDING PINGS
|
/** Stop sending pings */
|
||||||
// ==================
|
|
||||||
Ping.prototype.stop = function () {
|
Ping.prototype.stop = function () {
|
||||||
clearInterval(this._i);
|
clearInterval(this._i);
|
||||||
};
|
};
|
||||||
|
@ -177,7 +186,7 @@ Ping.prototype.stop = function () {
|
||||||
* Try to convert to UTF-8 for Windows, as the ping's output on Windows is not UTF-8 and could be in other languages
|
* Try to convert to UTF-8 for Windows, as the ping's output on Windows is not UTF-8 and could be in other languages
|
||||||
* Thank @pemassi
|
* Thank @pemassi
|
||||||
* https://github.com/louislam/uptime-kuma/issues/570#issuecomment-941984094
|
* https://github.com/louislam/uptime-kuma/issues/570#issuecomment-941984094
|
||||||
* @param data
|
* @param {any} data
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function convertOutput(data) {
|
function convertOutput(data) {
|
||||||
|
|
|
@ -33,8 +33,11 @@ const monitorStatus = new PrometheusClient.Gauge({
|
||||||
});
|
});
|
||||||
|
|
||||||
class Prometheus {
|
class Prometheus {
|
||||||
monitorLabelValues = {}
|
monitorLabelValues = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} monitor Monitor object to monitor
|
||||||
|
*/
|
||||||
constructor(monitor) {
|
constructor(monitor) {
|
||||||
this.monitorLabelValues = {
|
this.monitorLabelValues = {
|
||||||
monitor_name: monitor.name,
|
monitor_name: monitor.name,
|
||||||
|
@ -45,6 +48,11 @@ class Prometheus {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the metrics page
|
||||||
|
* @param {Object} heartbeat Heartbeat details
|
||||||
|
* @param {Object} tlsInfo TLS details
|
||||||
|
*/
|
||||||
update(heartbeat, tlsInfo) {
|
update(heartbeat, tlsInfo) {
|
||||||
|
|
||||||
if (typeof tlsInfo !== "undefined") {
|
if (typeof tlsInfo !== "undefined") {
|
||||||
|
|
|
@ -7,7 +7,7 @@ const { UptimeKumaServer } = require("./uptime-kuma-server");
|
||||||
|
|
||||||
class Proxy {
|
class Proxy {
|
||||||
|
|
||||||
static SUPPORTED_PROXY_PROTOCOLS = [ "http", "https", "socks", "socks5", "socks4" ]
|
static SUPPORTED_PROXY_PROTOCOLS = [ "http", "https", "socks", "socks5", "socks4" ];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves and updates given proxy entity
|
* Saves and updates given proxy entity
|
||||||
|
|
|
@ -2,11 +2,26 @@ const { RateLimiter } = require("limiter");
|
||||||
const { log } = require("../src/util");
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
class KumaRateLimiter {
|
class KumaRateLimiter {
|
||||||
|
/**
|
||||||
|
* @param {Object} config Rate limiter configuration object
|
||||||
|
*/
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.errorMessage = config.errorMessage;
|
this.errorMessage = config.errorMessage;
|
||||||
this.rateLimiter = new RateLimiter(config);
|
this.rateLimiter = new RateLimiter(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for pass
|
||||||
|
* @callback passCB
|
||||||
|
* @param {Object} err Too many requests
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the request be passed through
|
||||||
|
* @param {passCB} callback
|
||||||
|
* @param {number} [num=1] Number of tokens to remove
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
async pass(callback, num = 1) {
|
async pass(callback, num = 1) {
|
||||||
const remainingRequests = await this.removeTokens(num);
|
const remainingRequests = await this.removeTokens(num);
|
||||||
log.info("rate-limit", "remaining requests: " + remainingRequests);
|
log.info("rate-limit", "remaining requests: " + remainingRequests);
|
||||||
|
@ -22,6 +37,11 @@ class KumaRateLimiter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a given number of tokens
|
||||||
|
* @param {number} [num=1] Number of tokens to remove
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
async removeTokens(num = 1) {
|
async removeTokens(num = 1) {
|
||||||
return await this.rateLimiter.removeTokens(num);
|
return await this.rateLimiter.removeTokens(num);
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,6 +196,11 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a 403 response
|
||||||
|
* @param {Object} res Express response object
|
||||||
|
* @param {string} [msg=""] Message to send
|
||||||
|
*/
|
||||||
function send403(res, msg = "") {
|
function send403(res, msg = "") {
|
||||||
res.status(403).json({
|
res.status(403).json({
|
||||||
"status": "fail",
|
"status": "fail",
|
||||||
|
|
|
@ -136,13 +136,6 @@ app.use(function (req, res, next) {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Total WebSocket client connected to server currently, no actual use
|
|
||||||
*
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
let totalClient = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use for decode the auth object
|
* Use for decode the auth object
|
||||||
* @type {null}
|
* @type {null}
|
||||||
|
@ -248,17 +241,11 @@ try {
|
||||||
|
|
||||||
sendInfo(socket);
|
sendInfo(socket);
|
||||||
|
|
||||||
totalClient++;
|
|
||||||
|
|
||||||
if (needSetup) {
|
if (needSetup) {
|
||||||
log.info("server", "Redirect to setup page");
|
log.info("server", "Redirect to setup page");
|
||||||
socket.emit("setup");
|
socket.emit("setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on("disconnect", () => {
|
|
||||||
totalClient--;
|
|
||||||
});
|
|
||||||
|
|
||||||
// ***************************
|
// ***************************
|
||||||
// Public Socket API
|
// Public Socket API
|
||||||
// ***************************
|
// ***************************
|
||||||
|
@ -327,7 +314,7 @@ try {
|
||||||
let user = await login(data.username, data.password);
|
let user = await login(data.username, data.password);
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
if (user.twofa_status == 0) {
|
if (user.twofa_status === 0) {
|
||||||
afterLogin(socket, user);
|
afterLogin(socket, user);
|
||||||
|
|
||||||
log.info("auth", `Successfully logged in user ${data.username}. IP=${getClientIp(socket)}`);
|
log.info("auth", `Successfully logged in user ${data.username}. IP=${getClientIp(socket)}`);
|
||||||
|
@ -340,7 +327,7 @@ try {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.twofa_status == 1 && !data.token) {
|
if (user.twofa_status === 1 && !data.token) {
|
||||||
|
|
||||||
log.info("auth", `2FA token required for user ${data.username}. IP=${getClientIp(socket)}`);
|
log.info("auth", `2FA token required for user ${data.username}. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
|
@ -417,7 +404,7 @@ try {
|
||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (user.twofa_status == 0) {
|
if (user.twofa_status === 0) {
|
||||||
let newSecret = genSecret();
|
let newSecret = genSecret();
|
||||||
let encodedSecret = base32.encode(newSecret);
|
let encodedSecret = base32.encode(newSecret);
|
||||||
|
|
||||||
|
@ -548,7 +535,7 @@ try {
|
||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (user.twofa_status == 1) {
|
if (user.twofa_status === 1) {
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
status: true,
|
status: true,
|
||||||
|
@ -1169,7 +1156,7 @@ try {
|
||||||
let version17x = compareVersions.compare(backupData.version, "1.7.0", ">=");
|
let version17x = compareVersions.compare(backupData.version, "1.7.0", ">=");
|
||||||
|
|
||||||
// If the import option is "overwrite" it'll clear most of the tables, except "settings" and "user"
|
// If the import option is "overwrite" it'll clear most of the tables, except "settings" and "user"
|
||||||
if (importHandle == "overwrite") {
|
if (importHandle === "overwrite") {
|
||||||
// Stops every monitor first, so it doesn't execute any heartbeat while importing
|
// Stops every monitor first, so it doesn't execute any heartbeat while importing
|
||||||
for (let id in server.monitorList) {
|
for (let id in server.monitorList) {
|
||||||
let monitor = server.monitorList[id];
|
let monitor = server.monitorList[id];
|
||||||
|
@ -1193,7 +1180,7 @@ try {
|
||||||
|
|
||||||
for (let i = 0; i < notificationListData.length; i++) {
|
for (let i = 0; i < notificationListData.length; i++) {
|
||||||
// Only starts importing the notification if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
// Only starts importing the notification if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
||||||
if ((importHandle == "skip" && notificationNameListString.includes(notificationListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") {
|
if ((importHandle === "skip" && notificationNameListString.includes(notificationListData[i].name) === false) || importHandle === "keep" || importHandle === "overwrite") {
|
||||||
|
|
||||||
let notification = JSON.parse(notificationListData[i].config);
|
let notification = JSON.parse(notificationListData[i].config);
|
||||||
await Notification.save(notification, null, socket.userID);
|
await Notification.save(notification, null, socket.userID);
|
||||||
|
@ -1228,7 +1215,7 @@ try {
|
||||||
|
|
||||||
for (let i = 0; i < monitorListData.length; i++) {
|
for (let i = 0; i < monitorListData.length; i++) {
|
||||||
// Only starts importing the monitor if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
// Only starts importing the monitor if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
||||||
if ((importHandle == "skip" && monitorNameListString.includes(monitorListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") {
|
if ((importHandle === "skip" && monitorNameListString.includes(monitorListData[i].name) === false) || importHandle === "keep" || importHandle === "overwrite") {
|
||||||
|
|
||||||
// Define in here every new variable for monitors which where implemented after the first version of the Import/Export function (1.6.0)
|
// Define in here every new variable for monitors which where implemented after the first version of the Import/Export function (1.6.0)
|
||||||
// --- Start ---
|
// --- Start ---
|
||||||
|
@ -1325,7 +1312,7 @@ try {
|
||||||
await updateMonitorNotification(bean.id, notificationIDList);
|
await updateMonitorNotification(bean.id, notificationIDList);
|
||||||
|
|
||||||
// If monitor was active start it immediately, otherwise pause it
|
// If monitor was active start it immediately, otherwise pause it
|
||||||
if (monitorListData[i].active == 1) {
|
if (monitorListData[i].active === 1) {
|
||||||
await startMonitor(socket.userID, bean.id);
|
await startMonitor(socket.userID, bean.id);
|
||||||
} else {
|
} else {
|
||||||
await pauseMonitor(socket.userID, bean.id);
|
await pauseMonitor(socket.userID, bean.id);
|
||||||
|
@ -1473,11 +1460,11 @@ try {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds or removes notifications from a monitor.
|
* Update notifications for a given monitor
|
||||||
* @param {number} monitorID The ID of the monitor to add/remove notifications from.
|
* @param {number} monitorID ID of monitor to update
|
||||||
* @param {Array.<number>} notificationIDList An array of IDs for the notifications to add/remove.
|
* @param {number[]} notificationIDList List of new notification
|
||||||
*
|
* providers to add
|
||||||
* Generated by Trelent
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function updateMonitorNotification(monitorID, notificationIDList) {
|
async function updateMonitorNotification(monitorID, notificationIDList) {
|
||||||
await R.exec("DELETE FROM monitor_notification WHERE monitor_id = ? ", [
|
await R.exec("DELETE FROM monitor_notification WHERE monitor_id = ? ", [
|
||||||
|
@ -1495,11 +1482,11 @@ async function updateMonitorNotification(monitorID, notificationIDList) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function checks if the user owns a monitor with the given ID.
|
* Check if a given user owns a specific monitor
|
||||||
* @param {number} monitorID - The ID of the monitor to check ownership for.
|
* @param {number} userID
|
||||||
* @param {number} userID - The ID of the user who is trying to access this data.
|
* @param {number} monitorID
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
* @throws {Error} The specified user does not own the monitor
|
||||||
*/
|
*/
|
||||||
async function checkOwner(userID, monitorID) {
|
async function checkOwner(userID, monitorID) {
|
||||||
let row = await R.getRow("SELECT id FROM monitor WHERE id = ? AND user_id = ? ", [
|
let row = await R.getRow("SELECT id FROM monitor WHERE id = ? AND user_id = ? ", [
|
||||||
|
@ -1513,8 +1500,11 @@ async function checkOwner(userID, monitorID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Function called after user login
|
||||||
* This function is used to send the heartbeat list of a monitor.
|
* This function is used to send the heartbeat list of a monitor.
|
||||||
* @param {Socket} socket - The socket object that will be used to send the data.
|
* @param {Socket} socket Socket.io instance
|
||||||
|
* @param {Object} user User object
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function afterLogin(socket, user) {
|
async function afterLogin(socket, user) {
|
||||||
socket.userID = user.id;
|
socket.userID = user.id;
|
||||||
|
@ -1542,9 +1532,10 @@ async function afterLogin(socket, user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the database and patch it if necessary.
|
* Initialize the database
|
||||||
*
|
* @param {boolean} [testMode=false] Should the connection be
|
||||||
* Generated by Trelent
|
* started in test mode?
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function initDatabase(testMode = false) {
|
async function initDatabase(testMode = false) {
|
||||||
if (! fs.existsSync(Database.path)) {
|
if (! fs.existsSync(Database.path)) {
|
||||||
|
@ -1581,11 +1572,10 @@ async function initDatabase(testMode = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resume a monitor.
|
* Start the specified monitor
|
||||||
* @param {string} userID - The ID of the user who owns the monitor.
|
* @param {number} userID ID of user who owns monitor
|
||||||
* @param {string} monitorID - The ID of the monitor to resume.
|
* @param {number} monitorID ID of monitor to start
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function startMonitor(userID, monitorID) {
|
async function startMonitor(userID, monitorID) {
|
||||||
await checkOwner(userID, monitorID);
|
await checkOwner(userID, monitorID);
|
||||||
|
@ -1609,16 +1599,21 @@ async function startMonitor(userID, monitorID) {
|
||||||
monitor.start(io);
|
monitor.start(io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart a given monitor
|
||||||
|
* @param {number} userID ID of user who owns monitor
|
||||||
|
* @param {number} monitorID ID of monitor to start
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async function restartMonitor(userID, monitorID) {
|
async function restartMonitor(userID, monitorID) {
|
||||||
return await startMonitor(userID, monitorID);
|
return await startMonitor(userID, monitorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pause a monitor.
|
* Pause a given monitor
|
||||||
* @param {string} userID - The ID of the user who owns the monitor.
|
* @param {number} userID ID of user who owns monitor
|
||||||
* @param {string} monitorID - The ID of the monitor to pause.
|
* @param {number} monitorID ID of monitor to start
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function pauseMonitor(userID, monitorID) {
|
async function pauseMonitor(userID, monitorID) {
|
||||||
await checkOwner(userID, monitorID);
|
await checkOwner(userID, monitorID);
|
||||||
|
@ -1635,9 +1630,7 @@ async function pauseMonitor(userID, monitorID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Resume active monitors */
|
||||||
* Resume active monitors
|
|
||||||
*/
|
|
||||||
async function startMonitors() {
|
async function startMonitors() {
|
||||||
let list = await R.find("monitor", " active = 1 ");
|
let list = await R.find("monitor", " active = 1 ");
|
||||||
|
|
||||||
|
@ -1653,10 +1646,10 @@ async function startMonitors() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Shutdown the application
|
||||||
* Stops all monitors and closes the database connection.
|
* Stops all monitors and closes the database connection.
|
||||||
* @param {string} signal The signal that triggered this function to be called.
|
* @param {string} signal The signal that triggered this function to be called.
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function shutdownFunction(signal) {
|
async function shutdownFunction(signal) {
|
||||||
log.info("server", "Shutdown requested");
|
log.info("server", "Shutdown requested");
|
||||||
|
@ -1678,6 +1671,7 @@ function getClientIp(socket) {
|
||||||
return socket.client.conn.remoteAddress.replace(/^.*:/, "");
|
return socket.client.conn.remoteAddress.replace(/^.*:/, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Final function called before application exits */
|
||||||
function finalFunction() {
|
function finalFunction() {
|
||||||
log.info("server", "Graceful shutdown successful!");
|
log.info("server", "Graceful shutdown successful!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,28 @@ const io = UptimeKumaServer.getInstance().io;
|
||||||
const prefix = "cloudflared_";
|
const prefix = "cloudflared_";
|
||||||
const cloudflared = new CloudflaredTunnel();
|
const cloudflared = new CloudflaredTunnel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change running state
|
||||||
|
* @param {string} running Is it running?
|
||||||
|
* @param {string} message Message to pass
|
||||||
|
*/
|
||||||
cloudflared.change = (running, message) => {
|
cloudflared.change = (running, message) => {
|
||||||
io.to("cloudflared").emit(prefix + "running", running);
|
io.to("cloudflared").emit(prefix + "running", running);
|
||||||
io.to("cloudflared").emit(prefix + "message", message);
|
io.to("cloudflared").emit(prefix + "message", message);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit an error message
|
||||||
|
* @param {string} errorMessage
|
||||||
|
*/
|
||||||
cloudflared.error = (errorMessage) => {
|
cloudflared.error = (errorMessage) => {
|
||||||
io.to("cloudflared").emit(prefix + "errorMessage", errorMessage);
|
io.to("cloudflared").emit(prefix + "errorMessage", errorMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for cloudflared
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
module.exports.cloudflaredSocketHandler = (socket) => {
|
module.exports.cloudflaredSocketHandler = (socket) => {
|
||||||
|
|
||||||
socket.on(prefix + "join", async () => {
|
socket.on(prefix + "join", async () => {
|
||||||
|
@ -69,6 +82,10 @@ module.exports.cloudflaredSocketHandler = (socket) => {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically start cloudflared
|
||||||
|
* @param {string} token Cloudflared tunnel token
|
||||||
|
*/
|
||||||
module.exports.autoStart = async (token) => {
|
module.exports.autoStart = async (token) => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
token = await setting("cloudflaredTunnelToken");
|
token = await setting("cloudflaredTunnelToken");
|
||||||
|
@ -85,6 +102,7 @@ module.exports.autoStart = async (token) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Stop cloudflared */
|
||||||
module.exports.stop = async () => {
|
module.exports.stop = async () => {
|
||||||
console.log("Stop cloudflared");
|
console.log("Stop cloudflared");
|
||||||
if (cloudflared) {
|
if (cloudflared) {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
const { checkLogin } = require("../util-server");
|
const { checkLogin } = require("../util-server");
|
||||||
const Database = require("../database");
|
const Database = require("../database");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handlers for database
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
module.exports = (socket) => {
|
module.exports = (socket) => {
|
||||||
|
|
||||||
// Post or edit incident
|
// Post or edit incident
|
||||||
|
|
|
@ -4,6 +4,10 @@ const { sendProxyList } = require("../client");
|
||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
const server = UptimeKumaServer.getInstance();
|
const server = UptimeKumaServer.getInstance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handlers for proxy
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
module.exports.proxySocketHandler = (socket) => {
|
module.exports.proxySocketHandler = (socket) => {
|
||||||
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,6 +8,10 @@ const apicache = require("../modules/apicache");
|
||||||
const StatusPage = require("../model/status_page");
|
const StatusPage = require("../model/status_page");
|
||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Socket handlers for status page
|
||||||
|
* @param {Socket} socket Socket.io instance to add listeners on
|
||||||
|
*/
|
||||||
module.exports.statusPageSocketHandler = (socket) => {
|
module.exports.statusPageSocketHandler = (socket) => {
|
||||||
|
|
||||||
// Post or edit incident
|
// Post or edit incident
|
||||||
|
@ -338,6 +342,7 @@ module.exports.statusPageSocketHandler = (socket) => {
|
||||||
/**
|
/**
|
||||||
* Check slug a-z, 0-9, - only
|
* Check slug a-z, 0-9, - only
|
||||||
* Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
|
* Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
|
||||||
|
* @param {string} slug Slug to test
|
||||||
*/
|
*/
|
||||||
function checkSlug(slug) {
|
function checkSlug(slug) {
|
||||||
if (typeof slug !== "string") {
|
if (typeof slug !== "string") {
|
||||||
|
|
|
@ -37,6 +37,12 @@ exports.initJWTSecret = async () => {
|
||||||
return jwtSecretBean;
|
return jwtSecretBean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send TCP request to specified hostname and port
|
||||||
|
* @param {string} hostname Hostname / address of machine
|
||||||
|
* @param {number} port TCP port to test
|
||||||
|
* @returns {Promise<number>} Maximum time in ms rounded to nearest integer
|
||||||
|
*/
|
||||||
exports.tcping = function (hostname, port) {
|
exports.tcping = function (hostname, port) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
tcpp.ping({
|
tcpp.ping({
|
||||||
|
@ -58,6 +64,11 @@ exports.tcping = function (hostname, port) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ping the specified machine
|
||||||
|
* @param {string} hostname Hostname / address of machine
|
||||||
|
* @returns {Promise<number>} Time for ping in ms rounded to nearest integer
|
||||||
|
*/
|
||||||
exports.ping = async (hostname) => {
|
exports.ping = async (hostname) => {
|
||||||
try {
|
try {
|
||||||
return await exports.pingAsync(hostname);
|
return await exports.pingAsync(hostname);
|
||||||
|
@ -71,6 +82,12 @@ exports.ping = async (hostname) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ping the specified machine
|
||||||
|
* @param {string} hostname Hostname / address of machine to ping
|
||||||
|
* @param {boolean} ipv6 Should IPv6 be used?
|
||||||
|
* @returns {Promise<number>} Time for ping in ms rounded to nearest integer
|
||||||
|
*/
|
||||||
exports.pingAsync = function (hostname, ipv6 = false) {
|
exports.pingAsync = function (hostname, ipv6 = false) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const ping = new Ping(hostname, {
|
const ping = new Ping(hostname, {
|
||||||
|
@ -89,6 +106,15 @@ exports.pingAsync = function (hostname, ipv6 = false) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT Monitor
|
||||||
|
* @param {string} hostname Hostname / address of machine to test
|
||||||
|
* @param {string} topic MQTT topic
|
||||||
|
* @param {string} okMessage Expected result
|
||||||
|
* @param {Object} [options={}] MQTT options. Contains port, username,
|
||||||
|
* password and interval (interval defaults to 20)
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const { port, username, password, interval = 20 } = options;
|
const { port, username, password, interval = 20 } = options;
|
||||||
|
@ -132,7 +158,7 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("message", (messageTopic, message) => {
|
client.on("message", (messageTopic, message) => {
|
||||||
if (messageTopic == topic) {
|
if (messageTopic === topic) {
|
||||||
client.end();
|
client.end();
|
||||||
clearTimeout(timeoutID);
|
clearTimeout(timeoutID);
|
||||||
if (okMessage != null && okMessage !== "" && message.toString() !== okMessage) {
|
if (okMessage != null && okMessage !== "" && message.toString() !== okMessage) {
|
||||||
|
@ -146,6 +172,14 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a given record using the specified DNS server
|
||||||
|
* @param {string} hostname The hostname of the record to lookup
|
||||||
|
* @param {string} resolverServer The DNS server to use
|
||||||
|
* @param {string} resolverPort Port the DNS server is listening on
|
||||||
|
* @param {string} rrtype The type of record to request
|
||||||
|
* @returns {Promise<(string[]|Object[]|Object)>}
|
||||||
|
*/
|
||||||
exports.dnsResolve = function (hostname, resolverServer, resolverPort, rrtype) {
|
exports.dnsResolve = function (hostname, resolverServer, resolverPort, rrtype) {
|
||||||
const resolver = new Resolver();
|
const resolver = new Resolver();
|
||||||
// Remove brackets from IPv6 addresses so we can re-add them to
|
// Remove brackets from IPv6 addresses so we can re-add them to
|
||||||
|
@ -173,6 +207,11 @@ exports.dnsResolve = function (hostname, resolverServer, resolverPort, rrtype) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve value of setting based on key
|
||||||
|
* @param {string} key Key of setting to retrieve
|
||||||
|
* @returns {Promise<Object>} Object representation of setting
|
||||||
|
*/
|
||||||
exports.setting = async function (key) {
|
exports.setting = async function (key) {
|
||||||
let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [
|
let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [
|
||||||
key,
|
key,
|
||||||
|
@ -187,6 +226,13 @@ exports.setting = async function (key) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the specified setting to specifed value
|
||||||
|
* @param {string} key Key of setting to set
|
||||||
|
* @param {any} value Value to set to
|
||||||
|
* @param {?string} type Type of setting
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
exports.setSetting = async function (key, value, type = null) {
|
exports.setSetting = async function (key, value, type = null) {
|
||||||
let bean = await R.findOne("setting", " `key` = ? ", [
|
let bean = await R.findOne("setting", " `key` = ? ", [
|
||||||
key,
|
key,
|
||||||
|
@ -200,6 +246,11 @@ exports.setSetting = async function (key, value, type = null) {
|
||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get settings based on type
|
||||||
|
* @param {?string} type The type of setting
|
||||||
|
* @returns {Promise<Bean>}
|
||||||
|
*/
|
||||||
exports.getSettings = async function (type) {
|
exports.getSettings = async function (type) {
|
||||||
let list = await R.getAll("SELECT `key`, `value` FROM setting WHERE `type` = ? ", [
|
let list = await R.getAll("SELECT `key`, `value` FROM setting WHERE `type` = ? ", [
|
||||||
type,
|
type,
|
||||||
|
@ -218,6 +269,12 @@ exports.getSettings = async function (type) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set settings based on type
|
||||||
|
* @param {?string} type Type of settings to set
|
||||||
|
* @param {Object} data Values of settings
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
exports.setSettings = async function (type, data) {
|
exports.setSettings = async function (type, data) {
|
||||||
let keyList = Object.keys(data);
|
let keyList = Object.keys(data);
|
||||||
|
|
||||||
|
@ -244,12 +301,23 @@ exports.setSettings = async function (type, data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// ssl-checker by @dyaa
|
// ssl-checker by @dyaa
|
||||||
// param: res - response object from axios
|
//https://github.com/dyaa/ssl-checker/blob/master/src/index.ts
|
||||||
// return an object containing the certificate information
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of days between two dates
|
||||||
|
* @param {Date} validFrom Start date
|
||||||
|
* @param {Date} validTo End date
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
const getDaysBetween = (validFrom, validTo) =>
|
const getDaysBetween = (validFrom, validTo) =>
|
||||||
Math.round(Math.abs(+validFrom - +validTo) / 8.64e7);
|
Math.round(Math.abs(+validFrom - +validTo) / 8.64e7);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get days remaining from a time range
|
||||||
|
* @param {Date} validFrom Start date
|
||||||
|
* @param {Date} validTo End date
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
const getDaysRemaining = (validFrom, validTo) => {
|
const getDaysRemaining = (validFrom, validTo) => {
|
||||||
const daysRemaining = getDaysBetween(validFrom, validTo);
|
const daysRemaining = getDaysBetween(validFrom, validTo);
|
||||||
if (new Date(validTo).getTime() < new Date().getTime()) {
|
if (new Date(validTo).getTime() < new Date().getTime()) {
|
||||||
|
@ -258,8 +326,11 @@ const getDaysRemaining = (validFrom, validTo) => {
|
||||||
return daysRemaining;
|
return daysRemaining;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fix certificate Info for display
|
/**
|
||||||
// param: info - the chain obtained from getPeerCertificate()
|
* Fix certificate info for display
|
||||||
|
* @param {Object} info The chain obtained from getPeerCertificate()
|
||||||
|
* @returns {Object} An object representing certificate information
|
||||||
|
*/
|
||||||
const parseCertificateInfo = function (info) {
|
const parseCertificateInfo = function (info) {
|
||||||
let link = info;
|
let link = info;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
@ -299,6 +370,11 @@ const parseCertificateInfo = function (info) {
|
||||||
return info;
|
return info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if certificate is valid
|
||||||
|
* @param {Object} res Response object from axios
|
||||||
|
* @returns {Object} Object containing certificate information
|
||||||
|
*/
|
||||||
exports.checkCertificate = function (res) {
|
exports.checkCertificate = function (res) {
|
||||||
const info = res.request.res.socket.getPeerCertificate(true);
|
const info = res.request.res.socket.getPeerCertificate(true);
|
||||||
const valid = res.request.res.socket.authorized || false;
|
const valid = res.request.res.socket.authorized || false;
|
||||||
|
@ -312,12 +388,13 @@ exports.checkCertificate = function (res) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if the provided status code is within the accepted ranges
|
/**
|
||||||
// Param: status - the status code to check
|
* Check if the provided status code is within the accepted ranges
|
||||||
// Param: accepted_codes - an array of accepted status codes
|
* @param {string} status The status code to check
|
||||||
// Return: true if the status code is within the accepted ranges, false otherwise
|
* @param {string[]} acceptedCodes An array of accepted status codes
|
||||||
// Will throw an error if the provided status code is not a valid range string or code string
|
* @returns {boolean} True if status code within range, false otherwise
|
||||||
|
* @throws {Error} Will throw an error if the provided status code is not a valid range string or code string
|
||||||
|
*/
|
||||||
exports.checkStatusCode = function (status, acceptedCodes) {
|
exports.checkStatusCode = function (status, acceptedCodes) {
|
||||||
if (acceptedCodes == null || acceptedCodes.length === 0) {
|
if (acceptedCodes == null || acceptedCodes.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -341,6 +418,12 @@ exports.checkStatusCode = function (status, acceptedCodes) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get total number of clients in room
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {string} roomName Name of room to check
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
exports.getTotalClientInRoom = (io, roomName) => {
|
exports.getTotalClientInRoom = (io, roomName) => {
|
||||||
|
|
||||||
const sockets = io.sockets;
|
const sockets = io.sockets;
|
||||||
|
@ -364,17 +447,29 @@ exports.getTotalClientInRoom = (io, roomName) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow CORS all origins if development
|
||||||
|
* @param {Object} res Response object from axios
|
||||||
|
*/
|
||||||
exports.allowDevAllOrigin = (res) => {
|
exports.allowDevAllOrigin = (res) => {
|
||||||
if (process.env.NODE_ENV === "development") {
|
if (process.env.NODE_ENV === "development") {
|
||||||
exports.allowAllOrigin(res);
|
exports.allowAllOrigin(res);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow CORS all origins
|
||||||
|
* @param {Object} res Response object from axios
|
||||||
|
*/
|
||||||
exports.allowAllOrigin = (res) => {
|
exports.allowAllOrigin = (res) => {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user is logged in
|
||||||
|
* @param {Socket} socket Socket instance
|
||||||
|
*/
|
||||||
exports.checkLogin = (socket) => {
|
exports.checkLogin = (socket) => {
|
||||||
if (!socket.userID) {
|
if (!socket.userID) {
|
||||||
throw new Error("You are not logged in.");
|
throw new Error("You are not logged in.");
|
||||||
|
@ -383,8 +478,8 @@ exports.checkLogin = (socket) => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For logged-in users, double-check the password
|
* For logged-in users, double-check the password
|
||||||
* @param socket
|
* @param {Socket} socket Socket.io instance
|
||||||
* @param currentPassword
|
* @param {string} currentPassword
|
||||||
* @returns {Promise<Bean>}
|
* @returns {Promise<Bean>}
|
||||||
*/
|
*/
|
||||||
exports.doubleCheckPassword = async (socket, currentPassword) => {
|
exports.doubleCheckPassword = async (socket, currentPassword) => {
|
||||||
|
@ -403,6 +498,7 @@ exports.doubleCheckPassword = async (socket, currentPassword) => {
|
||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Start Unit tests */
|
||||||
exports.startUnitTest = async () => {
|
exports.startUnitTest = async () => {
|
||||||
console.log("Starting unit test...");
|
console.log("Starting unit test...");
|
||||||
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm";
|
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm";
|
||||||
|
@ -423,7 +519,8 @@ exports.startUnitTest = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param body : Buffer
|
* Convert unknown string to UTF8
|
||||||
|
* @param {Uint8Array} body Buffer
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
exports.convertToUTF8 = (body) => {
|
exports.convertToUTF8 = (body) => {
|
||||||
|
@ -440,6 +537,11 @@ try {
|
||||||
});
|
});
|
||||||
} catch (_) { }
|
} catch (_) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write error to log file
|
||||||
|
* @param {any} error The error to write
|
||||||
|
* @param {boolean} outputToConsole Should the error also be output to console?
|
||||||
|
*/
|
||||||
exports.errorLog = (error, outputToConsole = true) => {
|
exports.errorLog = (error, outputToConsole = true) => {
|
||||||
try {
|
try {
|
||||||
if (logFile) {
|
if (logFile) {
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
<script>
|
<script>
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import relativeTime from "dayjs/plugin/relativeTime";
|
import relativeTime from "dayjs/plugin/relativeTime";
|
||||||
import utc from "dayjs/plugin/utc";
|
|
||||||
import timezone from "dayjs/plugin/timezone"; // dependent on utc plugin
|
import timezone from "dayjs/plugin/timezone"; // dependent on utc plugin
|
||||||
|
import utc from "dayjs/plugin/utc";
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
|
@ -47,8 +47,8 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import HeartbeatBar from "../components/HeartbeatBar.vue";
|
import HeartbeatBar from "../components/HeartbeatBar.vue";
|
||||||
import Uptime from "../components/Uptime.vue";
|
|
||||||
import Tag from "../components/Tag.vue";
|
import Tag from "../components/Tag.vue";
|
||||||
|
import Uptime from "../components/Uptime.vue";
|
||||||
import { getMonitorRelativeURL } from "../util.ts";
|
import { getMonitorRelativeURL } from "../util.ts";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -105,7 +105,7 @@ export default {
|
||||||
|
|
||||||
// Simple filter by search text
|
// Simple filter by search text
|
||||||
// finds monitor name, tag name or tag value
|
// finds monitor name, tag name or tag value
|
||||||
if (this.searchText != "") {
|
if (this.searchText !== "") {
|
||||||
const loweredSearchText = this.searchText.toLowerCase();
|
const loweredSearchText = this.searchText.toLowerCase();
|
||||||
result = result.filter(monitor => {
|
result = result.filter(monitor => {
|
||||||
return monitor.name.toLowerCase().includes(loweredSearchText)
|
return monitor.name.toLowerCase().includes(loweredSearchText)
|
||||||
|
@ -170,12 +170,6 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
|
||||||
.footer {
|
|
||||||
// background-color: $dark-bg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 770px) {
|
@media (max-width: 770px) {
|
||||||
.list-header {
|
.list-header {
|
||||||
margin: -20px;
|
margin: -20px;
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { BarController, BarElement, Chart, Filler, LinearScale, LineController, LineElement, PointElement, TimeScale, Tooltip } from "chart.js";
|
import { BarController, BarElement, Chart, Filler, LinearScale, LineController, LineElement, PointElement, TimeScale, Tooltip } from "chart.js";
|
||||||
import dayjs from "dayjs";
|
|
||||||
import utc from "dayjs/plugin/utc";
|
|
||||||
import timezone from "dayjs/plugin/timezone";
|
|
||||||
import "chartjs-adapter-dayjs";
|
import "chartjs-adapter-dayjs";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import timezone from "dayjs/plugin/timezone";
|
||||||
|
import utc from "dayjs/plugin/utc";
|
||||||
import { LineChart } from "vue-chart-3";
|
import { LineChart } from "vue-chart-3";
|
||||||
import { useToast } from "vue-toastification";
|
import { useToast } from "vue-toastification";
|
||||||
import { DOWN } from "../util.ts";
|
import { DOWN } from "../util.ts";
|
||||||
|
@ -217,7 +217,7 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
// Update chart data when the selected chart period changes
|
// Update chart data when the selected chart period changes
|
||||||
chartPeriodHrs: function (newPeriod) {
|
chartPeriodHrs: function (newPeriod) {
|
||||||
if (newPeriod == "0") {
|
if (newPeriod === "0") {
|
||||||
newPeriod = null;
|
newPeriod = null;
|
||||||
this.heartbeatList = null;
|
this.heartbeatList = null;
|
||||||
this.$root.storage().removeItem(`chart-period-${this.monitorId}`);
|
this.$root.storage().removeItem(`chart-period-${this.monitorId}`);
|
||||||
|
@ -241,7 +241,7 @@ export default {
|
||||||
// And mirror latest change to this.heartbeatList
|
// And mirror latest change to this.heartbeatList
|
||||||
this.$watch(() => this.$root.heartbeatList[this.monitorId],
|
this.$watch(() => this.$root.heartbeatList[this.monitorId],
|
||||||
(heartbeatList) => {
|
(heartbeatList) => {
|
||||||
if (this.chartPeriodHrs != 0) {
|
if (this.chartPeriodHrs !== 0) {
|
||||||
const newBeat = heartbeatList.at(-1);
|
const newBeat = heartbeatList.at(-1);
|
||||||
if (newBeat && dayjs.utc(newBeat.time) > dayjs.utc(this.heartbeatList.at(-1)?.time)) {
|
if (newBeat && dayjs.utc(newBeat.time) > dayjs.utc(this.heartbeatList.at(-1)?.time)) {
|
||||||
this.heartbeatList.push(heartbeatList.at(-1));
|
this.heartbeatList.push(heartbeatList.at(-1));
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="tag-wrapper rounded d-inline-flex"
|
<div
|
||||||
:class="{ 'px-3': size == 'normal',
|
class="tag-wrapper rounded d-inline-flex"
|
||||||
'py-1': size == 'normal',
|
:class="{ 'px-3': size == 'normal',
|
||||||
'm-2': size == 'normal',
|
'py-1': size == 'normal',
|
||||||
'px-2': size == 'sm',
|
'm-2': size == 'normal',
|
||||||
'py-0': size == 'sm',
|
'px-2': size == 'sm',
|
||||||
'm-1': size == 'sm',
|
'py-0': size == 'sm',
|
||||||
}"
|
'm-1': size == 'sm',
|
||||||
:style="{ backgroundColor: item.color, fontSize: size == 'sm' ? '0.7em' : '1em' }"
|
}"
|
||||||
|
:style="{ backgroundColor: item.color, fontSize: size == 'sm' ? '0.7em' : '1em' }"
|
||||||
>
|
>
|
||||||
<span class="tag-text">{{ displayText }}</span>
|
<span class="tag-text">{{ displayText }}</span>
|
||||||
<span v-if="remove != null" class="ps-1 btn-remove" @click="remove(item)">
|
<span v-if="remove != null" class="ps-1 btn-remove" @click="remove(item)">
|
||||||
|
@ -34,7 +35,7 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
displayText() {
|
displayText() {
|
||||||
if (this.item.value == "") {
|
if (this.item.value === "") {
|
||||||
return this.item.name;
|
return this.item.name;
|
||||||
} else {
|
} else {
|
||||||
return `${this.item.name}: ${this.item.value}`;
|
return `${this.item.name}: ${this.item.value}`;
|
||||||
|
|
|
@ -34,18 +34,20 @@
|
||||||
label="name"
|
label="name"
|
||||||
>
|
>
|
||||||
<template #option="{ option }">
|
<template #option="{ option }">
|
||||||
<div class="mx-2 py-1 px-3 rounded d-inline-flex"
|
<div
|
||||||
style="margin-top: -5px; margin-bottom: -5px; height: 24px;"
|
class="mx-2 py-1 px-3 rounded d-inline-flex"
|
||||||
:style="{ color: textColor(option), backgroundColor: option.color + ' !important' }"
|
style="margin-top: -5px; margin-bottom: -5px; height: 24px;"
|
||||||
|
:style="{ color: textColor(option), backgroundColor: option.color + ' !important' }"
|
||||||
>
|
>
|
||||||
<span>
|
<span>
|
||||||
{{ option.name }}</span>
|
{{ option.name }}</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #singleLabel="{ option }">
|
<template #singleLabel="{ option }">
|
||||||
<div class="py-1 px-3 rounded d-inline-flex"
|
<div
|
||||||
style="height: 24px;"
|
class="py-1 px-3 rounded d-inline-flex"
|
||||||
:style="{ color: textColor(option), backgroundColor: option.color + ' !important' }"
|
style="height: 24px;"
|
||||||
|
:style="{ color: textColor(option), backgroundColor: option.color + ' !important' }"
|
||||||
>
|
>
|
||||||
<span>{{ option.name }}</span>
|
<span>{{ option.name }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -53,10 +55,11 @@
|
||||||
</vue-multiselect>
|
</vue-multiselect>
|
||||||
<div v-if="newDraftTag.select?.name == null" class="d-flex mb-2">
|
<div v-if="newDraftTag.select?.name == null" class="d-flex mb-2">
|
||||||
<div class="w-50 pe-2">
|
<div class="w-50 pe-2">
|
||||||
<input v-model="newDraftTag.name" class="form-control"
|
<input
|
||||||
:class="{'is-invalid': validateDraftTag.nameInvalid}"
|
v-model="newDraftTag.name" class="form-control"
|
||||||
:placeholder="$t('Name')"
|
:class="{'is-invalid': validateDraftTag.nameInvalid}"
|
||||||
@keydown.enter.prevent="onEnter"
|
:placeholder="$t('Name')"
|
||||||
|
@keydown.enter.prevent="onEnter"
|
||||||
/>
|
/>
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
{{ $t("Tag with this name already exist.") }}
|
{{ $t("Tag with this name already exist.") }}
|
||||||
|
@ -75,17 +78,19 @@
|
||||||
deselect-label=""
|
deselect-label=""
|
||||||
>
|
>
|
||||||
<template #option="{ option }">
|
<template #option="{ option }">
|
||||||
<div class="mx-2 py-1 px-3 rounded d-inline-flex"
|
<div
|
||||||
style="height: 24px; color: white;"
|
class="mx-2 py-1 px-3 rounded d-inline-flex"
|
||||||
:style="{ backgroundColor: option.color + ' !important' }"
|
style="height: 24px; color: white;"
|
||||||
|
:style="{ backgroundColor: option.color + ' !important' }"
|
||||||
>
|
>
|
||||||
<span>{{ option.name }}</span>
|
<span>{{ option.name }}</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #singleLabel="{ option }">
|
<template #singleLabel="{ option }">
|
||||||
<div class="py-1 px-3 rounded d-inline-flex"
|
<div
|
||||||
style="height: 24px; color: white;"
|
class="py-1 px-3 rounded d-inline-flex"
|
||||||
:style="{ backgroundColor: option.color + ' !important' }"
|
style="height: 24px; color: white;"
|
||||||
|
:style="{ backgroundColor: option.color + ' !important' }"
|
||||||
>
|
>
|
||||||
<span>{{ option.name }}</span>
|
<span>{{ option.name }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -94,10 +99,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<input v-model="newDraftTag.value" class="form-control"
|
<input
|
||||||
:class="{'is-invalid': validateDraftTag.valueInvalid}"
|
v-model="newDraftTag.value" class="form-control"
|
||||||
:placeholder="$t('value (optional)')"
|
:class="{'is-invalid': validateDraftTag.valueInvalid}"
|
||||||
@keydown.enter.prevent="onEnter"
|
:placeholder="$t('value (optional)')"
|
||||||
|
@keydown.enter.prevent="onEnter"
|
||||||
/>
|
/>
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
{{ $t("Tag with this value already exist.") }}
|
{{ $t("Tag with this value already exist.") }}
|
||||||
|
@ -123,8 +129,8 @@
|
||||||
<script>
|
<script>
|
||||||
import { Modal } from "bootstrap";
|
import { Modal } from "bootstrap";
|
||||||
import VueMultiselect from "vue-multiselect";
|
import VueMultiselect from "vue-multiselect";
|
||||||
import Tag from "../components/Tag.vue";
|
|
||||||
import { useToast } from "vue-toastification";
|
import { useToast } from "vue-toastification";
|
||||||
|
import Tag from "../components/Tag.vue";
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -159,14 +165,14 @@ export default {
|
||||||
tagOptions() {
|
tagOptions() {
|
||||||
const tagOptions = this.existingTags;
|
const tagOptions = this.existingTags;
|
||||||
for (const tag of this.newTags) {
|
for (const tag of this.newTags) {
|
||||||
if (!tagOptions.find(t => t.name == tag.name && t.color == tag.color)) {
|
if (!tagOptions.find(t => t.name === tag.name && t.color === tag.color)) {
|
||||||
tagOptions.push(tag);
|
tagOptions.push(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tagOptions;
|
return tagOptions;
|
||||||
},
|
},
|
||||||
selectedTags() {
|
selectedTags() {
|
||||||
return this.preSelectedTags.concat(this.newTags).filter(tag => !this.deleteTags.find(monitorTag => monitorTag.id == tag.id));
|
return this.preSelectedTags.concat(this.newTags).filter(tag => !this.deleteTags.find(monitorTag => monitorTag.id === tag.id));
|
||||||
},
|
},
|
||||||
colorOptions() {
|
colorOptions() {
|
||||||
return [
|
return [
|
||||||
|
@ -192,7 +198,7 @@ export default {
|
||||||
let nameInvalid = false;
|
let nameInvalid = false;
|
||||||
let valueInvalid = false;
|
let valueInvalid = false;
|
||||||
let invalid = true;
|
let invalid = true;
|
||||||
if (this.deleteTags.find(tag => tag.name == this.newDraftTag.select?.name && tag.value == this.newDraftTag.value)) {
|
if (this.deleteTags.find(tag => tag.name === this.newDraftTag.select?.name && tag.value === this.newDraftTag.value)) {
|
||||||
// Undo removing a Tag
|
// Undo removing a Tag
|
||||||
nameInvalid = false;
|
nameInvalid = false;
|
||||||
valueInvalid = false;
|
valueInvalid = false;
|
||||||
|
@ -202,9 +208,9 @@ export default {
|
||||||
nameInvalid = true;
|
nameInvalid = true;
|
||||||
invalid = true;
|
invalid = true;
|
||||||
} else if (this.newTags.concat(this.preSelectedTags).filter(tag => (
|
} else if (this.newTags.concat(this.preSelectedTags).filter(tag => (
|
||||||
tag.name == this.newDraftTag.select?.name && tag.value == this.newDraftTag.value
|
tag.name === this.newDraftTag.select?.name && tag.value === this.newDraftTag.value
|
||||||
) || (
|
) || (
|
||||||
tag.name == this.newDraftTag.name && tag.value == this.newDraftTag.value
|
tag.name === this.newDraftTag.name && tag.value === this.newDraftTag.value
|
||||||
)).length > 0) {
|
)).length > 0) {
|
||||||
// Try to add a tag with existing name and value
|
// Try to add a tag with existing name and value
|
||||||
valueInvalid = true;
|
valueInvalid = true;
|
||||||
|
@ -250,7 +256,7 @@ export default {
|
||||||
deleteTag(item) {
|
deleteTag(item) {
|
||||||
if (item.new) {
|
if (item.new) {
|
||||||
// Undo Adding a new Tag
|
// Undo Adding a new Tag
|
||||||
this.newTags = this.newTags.filter(tag => !(tag.name == item.name && tag.value == item.value));
|
this.newTags = this.newTags.filter(tag => !(tag.name === item.name && tag.value === item.value));
|
||||||
} else {
|
} else {
|
||||||
// Remove an Existing Tag
|
// Remove an Existing Tag
|
||||||
this.deleteTags.push(item);
|
this.deleteTags.push(item);
|
||||||
|
@ -266,9 +272,9 @@ export default {
|
||||||
addDraftTag() {
|
addDraftTag() {
|
||||||
console.log("Adding Draft Tag: ", this.newDraftTag);
|
console.log("Adding Draft Tag: ", this.newDraftTag);
|
||||||
if (this.newDraftTag.select != null) {
|
if (this.newDraftTag.select != null) {
|
||||||
if (this.deleteTags.find(tag => tag.name == this.newDraftTag.select.name && tag.value == this.newDraftTag.value)) {
|
if (this.deleteTags.find(tag => tag.name === this.newDraftTag.select.name && tag.value === this.newDraftTag.value)) {
|
||||||
// Undo removing a tag
|
// Undo removing a tag
|
||||||
this.deleteTags = this.deleteTags.filter(tag => !(tag.name == this.newDraftTag.select.name && tag.value == this.newDraftTag.value));
|
this.deleteTags = this.deleteTags.filter(tag => !(tag.name === this.newDraftTag.select.name && tag.value === this.newDraftTag.value));
|
||||||
} else {
|
} else {
|
||||||
// Add an existing Tag
|
// Add an existing Tag
|
||||||
this.newTags.push({
|
this.newTags.push({
|
||||||
|
@ -345,7 +351,7 @@ export default {
|
||||||
tagId = newTagResult.id;
|
tagId = newTagResult.id;
|
||||||
// Assign the new ID to the tags of the same name & color
|
// Assign the new ID to the tags of the same name & color
|
||||||
this.newTags.map(tag => {
|
this.newTags.map(tag => {
|
||||||
if (tag.name == newTag.name && tag.color == newTag.color) {
|
if (tag.name === newTag.name && tag.color === newTag.color) {
|
||||||
tag.id = newTagResult.id;
|
tag.id = newTagResult.id;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -179,7 +179,7 @@ export default {
|
||||||
"Edit Status Page": "Bearbeite Status-Seite",
|
"Edit Status Page": "Bearbeite Status-Seite",
|
||||||
"Go to Dashboard": "Gehe zum Dashboard",
|
"Go to Dashboard": "Gehe zum Dashboard",
|
||||||
"Status Page": "Status-Seite",
|
"Status Page": "Status-Seite",
|
||||||
"Status Pages": "Status-Seite",
|
"Status Pages": "Status-Seiten",
|
||||||
telegram: "Telegram",
|
telegram: "Telegram",
|
||||||
webhook: "Webhook",
|
webhook: "Webhook",
|
||||||
smtp: "E-Mail (SMTP)",
|
smtp: "E-Mail (SMTP)",
|
||||||
|
@ -403,8 +403,8 @@ export default {
|
||||||
"WeCom Bot Key": "WeCom Bot Schlüssel",
|
"WeCom Bot Key": "WeCom Bot Schlüssel",
|
||||||
"Setup Proxy": "Proxy einrichten",
|
"Setup Proxy": "Proxy einrichten",
|
||||||
"Proxy Protocol": "Proxy Protokoll",
|
"Proxy Protocol": "Proxy Protokoll",
|
||||||
"Proxy Server": "Proxy Server",
|
"Proxy Server": "Proxy-Server",
|
||||||
"Proxy server has authentication": "Proxy server hat Authentifizierung",
|
"Proxy server has authentication": "Proxy-Server hat Authentifizierung",
|
||||||
User: "Benutzer",
|
User: "Benutzer",
|
||||||
Installed: "Installiert",
|
Installed: "Installiert",
|
||||||
"Not installed": "Nicht installiert",
|
"Not installed": "Nicht installiert",
|
||||||
|
@ -442,7 +442,14 @@ export default {
|
||||||
"Issuer:": "Aussteller:",
|
"Issuer:": "Aussteller:",
|
||||||
"Fingerprint:": "Fingerabdruck:",
|
"Fingerprint:": "Fingerabdruck:",
|
||||||
"No status pages": "Keine Status-Seiten",
|
"No status pages": "Keine Status-Seiten",
|
||||||
|
"Domain Name Expiry Notification": "Benachrichtigung bei Ablauf des Domainnamens",
|
||||||
Customize: "Anpassen",
|
Customize: "Anpassen",
|
||||||
"Custom Footer": "Eigener Footer",
|
"Custom Footer": "Eigener Footer",
|
||||||
"Custom CSS": "Eigenes CSS",
|
"Custom CSS": "Eigenes CSS",
|
||||||
|
"Footer Text": "Fußzeile",
|
||||||
|
"Show Powered By": "Zeige 'Powered By'",
|
||||||
|
"Date Created": "Erstellt am",
|
||||||
|
"Domain Names": "Domainnamen",
|
||||||
|
signedInDisp: "Angemeldet als {0}",
|
||||||
|
signedInDispDisabled: "Authentifizierung deaktiviert.",
|
||||||
};
|
};
|
||||||
|
|
|
@ -239,6 +239,7 @@ export default {
|
||||||
"rocket.chat": "Rocket.chat",
|
"rocket.chat": "Rocket.chat",
|
||||||
pushover: "Pushover",
|
pushover: "Pushover",
|
||||||
pushy: "Pushy",
|
pushy: "Pushy",
|
||||||
|
PushByTechulus: "Push by Techulus",
|
||||||
octopush: "Octopush",
|
octopush: "Octopush",
|
||||||
promosms: "PromoSMS",
|
promosms: "PromoSMS",
|
||||||
clicksendsms: "ClickSend SMS",
|
clicksendsms: "ClickSend SMS",
|
||||||
|
@ -308,6 +309,10 @@ export default {
|
||||||
"One record": "One record",
|
"One record": "One record",
|
||||||
steamApiKeyDescription: "Để theo dõi các Steam Game Server bạn cần một Steam Web-API key. Bạn có thể đăng ký API key tại đây: ",
|
steamApiKeyDescription: "Để theo dõi các Steam Game Server bạn cần một Steam Web-API key. Bạn có thể đăng ký API key tại đây: ",
|
||||||
"Current User": "User hiện tại",
|
"Current User": "User hiện tại",
|
||||||
|
topic: "Topic",
|
||||||
|
topicExplanation: "MQTT topic to monitor",
|
||||||
|
successMessage: "Success Message",
|
||||||
|
successMessageExplanation: "MQTT message that will be considered as success",
|
||||||
recent: "Gần đây",
|
recent: "Gần đây",
|
||||||
Done: "Hoàn thành",
|
Done: "Hoàn thành",
|
||||||
Info: "Thông tin",
|
Info: "Thông tin",
|
||||||
|
@ -353,6 +358,9 @@ export default {
|
||||||
serwersmsPhoneNumber: "Số điện thoại",
|
serwersmsPhoneNumber: "Số điện thoại",
|
||||||
serwersmsSenderName: "Tên người gửi SMS (Đã đăng ký qua portal)",
|
serwersmsSenderName: "Tên người gửi SMS (Đã đăng ký qua portal)",
|
||||||
"stackfield": "Stackfield",
|
"stackfield": "Stackfield",
|
||||||
|
Customize: "Customize",
|
||||||
|
"Custom Footer": "Custom Footer",
|
||||||
|
"Custom CSS": "Custom CSS",
|
||||||
smtpDkimSettings: "Cài đặt xác thực Email(DKIM)",
|
smtpDkimSettings: "Cài đặt xác thực Email(DKIM)",
|
||||||
smtpDkimDesc: "Xem hướng dẫn tại {0}.",
|
smtpDkimDesc: "Xem hướng dẫn tại {0}.",
|
||||||
documentation: "Nodemailer DKIM",
|
documentation: "Nodemailer DKIM",
|
||||||
|
@ -362,4 +370,98 @@ export default {
|
||||||
smtpDkimHashAlgo: "Hash Algorithm (Tuỳ chọn)",
|
smtpDkimHashAlgo: "Hash Algorithm (Tuỳ chọn)",
|
||||||
smtpDkimheaderFieldNames: "Header Keys to sign (Tuỳ chọn)",
|
smtpDkimheaderFieldNames: "Header Keys to sign (Tuỳ chọn)",
|
||||||
smtpDkimskipFields: "Header Keys not to sign (Tuỳ chọn)",
|
smtpDkimskipFields: "Header Keys not to sign (Tuỳ chọn)",
|
||||||
|
gorush: "Gorush",
|
||||||
|
alerta: "Alerta",
|
||||||
|
alertaApiEndpoint: "API Endpoint",
|
||||||
|
alertaEnvironment: "Environment",
|
||||||
|
alertaApiKey: "API Key",
|
||||||
|
alertaAlertState: "Alert State",
|
||||||
|
alertaRecoverState: "Recover State",
|
||||||
|
deleteStatusPageMsg: "Bạn có chắc chắn muốn xoá trang status này?",
|
||||||
|
Proxies: "Proxies",
|
||||||
|
default: "Mặc định",
|
||||||
|
enabled: "Enabled",
|
||||||
|
setAsDefault: "Set As Default",
|
||||||
|
deleteProxyMsg: "Bạn muốn xoá proxy này cho tất cả monitors?",
|
||||||
|
proxyDescription: "Proxies must be assigned to a monitor to function.",
|
||||||
|
enableProxyDescription: "Proxy này chưa ảnh hưởng tới monitor requests cho tới khi được activated. Bạn có thể tạm thời tắt proxy cho tất cả monitors bằng trạng thái activation.",
|
||||||
|
setAsDefaultProxyDescription: "Proxy này sẽ bật mặc định cho tất cả monitors mới. Bạn có thể tắt riêng lẻ proxy trên mỗi monitor.",
|
||||||
|
"Certificate Chain": "Certificate Chain",
|
||||||
|
Valid: "Hợp lệ",
|
||||||
|
Invalid: "Không hợp lệ",
|
||||||
|
AccessKeyId: "AccessKey ID",
|
||||||
|
SecretAccessKey: "AccessKey Secret",
|
||||||
|
PhoneNumbers: "PhoneNumbers",
|
||||||
|
TemplateCode: "TemplateCode",
|
||||||
|
SignName: "SignName",
|
||||||
|
"Sms template must contain parameters: ": "Sms template must contain parameters: ",
|
||||||
|
"Bark Endpoint": "Bark Endpoint",
|
||||||
|
WebHookUrl: "WebHookUrl",
|
||||||
|
SecretKey: "SecretKey",
|
||||||
|
"For safety, must use secret key": "Để an toàn, hãy dùng secret key",
|
||||||
|
"Device Token": "Device Token",
|
||||||
|
Platform: "Platform",
|
||||||
|
iOS: "iOS",
|
||||||
|
Android: "Android",
|
||||||
|
Huawei: "Huawei",
|
||||||
|
High: "High",
|
||||||
|
Retry: "Retry",
|
||||||
|
Topic: "Topic",
|
||||||
|
"WeCom Bot Key": "WeCom Bot Key",
|
||||||
|
"Setup Proxy": "Setup Proxy",
|
||||||
|
"Proxy Protocol": "Proxy Protocol",
|
||||||
|
"Proxy Server": "Proxy Server",
|
||||||
|
"Proxy server has authentication": "Proxy server has authentication",
|
||||||
|
User: "User",
|
||||||
|
Installed: "Installed",
|
||||||
|
"Not installed": "Not installed",
|
||||||
|
Running: "Running",
|
||||||
|
"Not running": "Not running",
|
||||||
|
"Remove Token": "Remove Token",
|
||||||
|
Start: "Start",
|
||||||
|
Stop: "Stop",
|
||||||
|
"Uptime Kuma": "Uptime Kuma",
|
||||||
|
"Add New Status Page": "Thêm mới Status Page",
|
||||||
|
Slug: "Slug",
|
||||||
|
"Accept characters:": "Accept characters:",
|
||||||
|
startOrEndWithOnly: "Start or end with {0} only",
|
||||||
|
"No consecutive dashes": "No consecutive dashes",
|
||||||
|
Next: "Next",
|
||||||
|
"The slug is already taken. Please choose another slug.": "The slug is already taken. Please choose another slug.",
|
||||||
|
"No Proxy": "No Proxy",
|
||||||
|
"HTTP Basic Auth": "HTTP Basic Auth",
|
||||||
|
"New Status Page": "New Status Page",
|
||||||
|
"Page Not Found": "Page Not Found",
|
||||||
|
"Reverse Proxy": "Reverse Proxy",
|
||||||
|
Backup: "Backup",
|
||||||
|
About: "About",
|
||||||
|
wayToGetCloudflaredURL: "(Download cloudflared from {0})",
|
||||||
|
cloudflareWebsite: "Cloudflare Website",
|
||||||
|
"Message:": "Message:",
|
||||||
|
"Don't know how to get the token? Please read the guide:": "Chưa biết cách lấy token? Xem hướng dẫn tại:",
|
||||||
|
"The current connection may be lost if you are currently connecting via Cloudflare Tunnel. Are you sure want to stop it? Type your current password to confirm it.": "Nếu bạn đang dùng Cloudflare Tunnel, kết nối hiện tại có thể đang bị mất. Bạn có muốn dừng lại? Nhập lại password để xác nhận.",
|
||||||
|
"Other Software": "Phần mềm khác",
|
||||||
|
"For example: nginx, Apache and Traefik.": "Ví dụ: Nginx, Apache hay Traefik.",
|
||||||
|
"Please read": "Hãy xem qua",
|
||||||
|
"Subject:": "Subject:",
|
||||||
|
"Valid To:": "Valid To:",
|
||||||
|
"Days Remaining:": "Số ngày còn lại:",
|
||||||
|
"Issuer:": "Issuer:",
|
||||||
|
"Fingerprint:": "Fingerprint:",
|
||||||
|
"No status pages": "No status pages",
|
||||||
|
"Domain Name Expiry Notification": "Cảnh báo hạn hạn Domain Name",
|
||||||
|
Proxy: "Proxy",
|
||||||
|
"Date Created": "Ngày khởi tạo",
|
||||||
|
onebotHttpAddress: "OneBot HTTP Address",
|
||||||
|
onebotMessageType: "OneBot Message Type",
|
||||||
|
onebotGroupMessage: "Group",
|
||||||
|
onebotPrivateMessage: "Private",
|
||||||
|
onebotUserOrGroupId: "Group/User ID",
|
||||||
|
onebotSafetyTips: "Để đảm bảo an toàn, hãy thiết lập access token",
|
||||||
|
"PushDeer Key": "PushDeer Key",
|
||||||
|
"Footer Text": "Footer Text",
|
||||||
|
"Show Powered By": "Show Powered By",
|
||||||
|
"Domain Names": "Domain Names",
|
||||||
|
signedInDisp: "Signed in as {0}",
|
||||||
|
signedInDispDisabled: "Auth Disabled.",
|
||||||
};
|
};
|
||||||
|
|
|
@ -184,7 +184,7 @@
|
||||||
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' " class="my-3 form-check">
|
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' " class="my-3 form-check">
|
||||||
<input id="expiry-notification" v-model="monitor.expiryNotification" class="form-check-input" type="checkbox">
|
<input id="expiry-notification" v-model="monitor.expiryNotification" class="form-check-input" type="checkbox">
|
||||||
<label class="form-check-label" for="expiry-notification">
|
<label class="form-check-label" for="expiry-notification">
|
||||||
{{ $t("Domain Name Expiry Notification") }}
|
{{ $t("Certificate Expiry Notification") }}
|
||||||
</label>
|
</label>
|
||||||
<div class="form-text">
|
<div class="form-text">
|
||||||
</div>
|
</div>
|
||||||
|
@ -370,13 +370,12 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import VueMultiselect from "vue-multiselect";
|
||||||
|
import { useToast } from "vue-toastification";
|
||||||
|
import CopyableInput from "../components/CopyableInput.vue";
|
||||||
import NotificationDialog from "../components/NotificationDialog.vue";
|
import NotificationDialog from "../components/NotificationDialog.vue";
|
||||||
import ProxyDialog from "../components/ProxyDialog.vue";
|
import ProxyDialog from "../components/ProxyDialog.vue";
|
||||||
import TagsManager from "../components/TagsManager.vue";
|
import TagsManager from "../components/TagsManager.vue";
|
||||||
import CopyableInput from "../components/CopyableInput.vue";
|
|
||||||
|
|
||||||
import { useToast } from "vue-toastification";
|
|
||||||
import VueMultiselect from "vue-multiselect";
|
|
||||||
import { genSecret, isDev } from "../util.ts";
|
import { genSecret, isDev } from "../util.ts";
|
||||||
|
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
@ -558,7 +557,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this.$root.notificationList.length; i++) {
|
for (let i = 0; i < this.$root.notificationList.length; i++) {
|
||||||
if (this.$root.notificationList[i].isDefault == true) {
|
if (this.$root.notificationList[i].isDefault === true) {
|
||||||
this.monitor.notificationIDList[this.$root.notificationList[i].id] = true;
|
this.monitor.notificationIDList[this.$root.notificationList[i].id] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,6 +284,11 @@ describe("Init", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test login
|
||||||
|
* @param {string} username
|
||||||
|
* @param {string} password
|
||||||
|
*/
|
||||||
async function login(username, password) {
|
async function login(username, password) {
|
||||||
await input(page, "#floatingInput", username);
|
await input(page, "#floatingInput", username);
|
||||||
await input(page, "#floatingPassword", password);
|
await input(page, "#floatingPassword", password);
|
||||||
|
@ -291,6 +296,13 @@ async function login(username, password) {
|
||||||
await sleep(5000);
|
await sleep(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Click on an element on the page
|
||||||
|
* @param {Page} page Puppeteer page instance
|
||||||
|
* @param {string} selector
|
||||||
|
* @param {number} elementIndex
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
async function click(page, selector, elementIndex = 0) {
|
async function click(page, selector, elementIndex = 0) {
|
||||||
await page.waitForSelector(selector, {
|
await page.waitForSelector(selector, {
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
|
@ -300,6 +312,12 @@ async function click(page, selector, elementIndex = 0) {
|
||||||
}, selector, elementIndex);
|
}, selector, elementIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Input text into selected field
|
||||||
|
* @param {Page} page Puppeteer page instance
|
||||||
|
* @param {string} selector
|
||||||
|
* @param {string} text Text to input
|
||||||
|
*/
|
||||||
async function input(page, selector, text) {
|
async function input(page, selector, text) {
|
||||||
await page.waitForSelector(selector, {
|
await page.waitForSelector(selector, {
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
|
|
Loading…
Reference in a new issue