mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-09-13 23:17:00 +08:00
Compare commits
168 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
751924b335 | ||
|
edec1024b5 | ||
|
5f9f29f527 | ||
|
13a3dd91bb | ||
|
d9c5a7812c | ||
|
484d4a20ab | ||
|
3582e99770 | ||
|
2197b98444 | ||
|
e6a1719ab4 | ||
|
7d5e7a577d | ||
|
630bb03d9c | ||
|
f1c83bb838 | ||
|
303a226ab7 | ||
|
d3f0bdb440 | ||
|
e56ac7b03b | ||
|
aafcbaf098 | ||
|
4d4d04adbd | ||
|
f8c9472ea2 | ||
|
4e28ad4ac2 | ||
|
06f326e49e | ||
|
07c0801ad5 | ||
|
8cefc96c78 | ||
|
b326a69838 | ||
|
a391576285 | ||
|
e0966e55c8 | ||
|
59d9891105 | ||
|
f8f19d8dc5 | ||
|
a3d79a93e9 | ||
|
bdc23a3f57 | ||
|
7c13b1b6cb | ||
|
10f6a3c4f5 | ||
|
cd7c2beca6 | ||
|
8ee99760ec | ||
|
cb55e23718 | ||
|
200fdfb808 | ||
|
29d2d95c71 | ||
|
b782b25e17 | ||
|
919393cac9 | ||
|
18925293fb | ||
|
17d4003e5c | ||
|
cefb5bb60a | ||
|
9bf3b3a0f4 | ||
|
e2c45f93bf | ||
|
addf75daa7 | ||
|
359a490ae3 | ||
|
cd38dd3f68 | ||
|
f712fe85e5 | ||
|
c28b90feb4 | ||
|
ceba096f3e | ||
|
2a248ad73f | ||
|
5fa62a888c | ||
|
e6a8a84278 | ||
|
47c72192e1 | ||
|
d71c086447 | ||
|
46e1a628a7 | ||
|
cd3dfd3146 | ||
|
572f2b9838 | ||
|
8eb83394f7 | ||
|
1bc01d1077 | ||
|
4e6ddc8880 | ||
|
07c474db0b | ||
|
8d8c38b1a8 | ||
|
03bcf5c766 | ||
|
136fdf3768 | ||
|
e34420368b | ||
|
566133e350 | ||
|
30e113755e | ||
|
083e8355b7 | ||
|
64a0e1aa9b | ||
|
b1c7915bc1 | ||
|
b7aebceaab | ||
|
0302fdbc96 | ||
|
84a50f058f | ||
|
9ec652639b | ||
|
0c40e32d75 | ||
|
6f99d7577b | ||
|
1417b6eacf | ||
|
1baee42cf5 | ||
|
fb0064082e | ||
|
93c51504f9 | ||
|
fb059f5e91 | ||
|
2e3414135f | ||
|
e44699216e | ||
|
fd8cba1dad | ||
|
03dd02fd38 | ||
|
d0b5f147e2 | ||
|
ddf8a7a692 | ||
|
bd9df09f87 | ||
|
4656ab3d57 | ||
|
0a5db0cecb | ||
|
60b44c2cdd | ||
|
16b61dba27 | ||
|
2b0c184a88 | ||
|
2642e70fc8 | ||
|
8d0446dc38 | ||
|
3436e26ed4 | ||
|
649f3106e1 | ||
|
6f72ca481f | ||
|
670ea415b2 | ||
|
17dcf6d3a2 | ||
|
e9ce1433cd | ||
|
f5d006add8 | ||
|
4df147786d | ||
|
27861f0d14 | ||
|
5aa747a301 | ||
|
81de2eedfb | ||
|
4a6d7207ef | ||
|
4053b9db1f | ||
|
772d009f43 | ||
|
ae54d9c011 | ||
|
5ca606fe99 | ||
|
6179f6c982 | ||
|
94770cf865 | ||
|
9ec29c1bc4 | ||
|
279e2eb3f6 | ||
|
88604845e6 | ||
|
a7e1a78ea9 | ||
|
97a5b400db | ||
|
ca89f84b9a | ||
|
0345719e53 | ||
|
22256dfcd2 | ||
|
227bbdea2f | ||
|
6272514820 | ||
|
1c8407a433 | ||
|
32ec4beda0 | ||
|
9462646ad3 | ||
|
482b3f9233 | ||
|
6014ed1156 | ||
|
bfee63452d | ||
|
076d6bdbb6 | ||
|
0bbe157099 | ||
|
0053a29d10 | ||
|
2c8d5d28e9 | ||
|
3d6c52fbea | ||
|
9ee591417d | ||
|
4118de6d53 | ||
|
3a12e209da | ||
|
2c2a824f97 | ||
|
931ca6a3ef | ||
|
d3c90df8a8 | ||
|
38f8a8ac2f | ||
|
e684712a77 | ||
|
5afc6a41e3 | ||
|
dcc7856b5d | ||
|
c9b0a81cdc | ||
|
2f97f44086 | ||
|
a13bdaac84 | ||
|
e3745da986 | ||
|
35da8c78f4 | ||
|
7179c6cc4c | ||
|
ed96757b24 | ||
|
3306f4a8e0 | ||
|
a2de9e4e36 | ||
|
3f5133d1ba | ||
|
6f2dcc6dd7 | ||
|
57bed4d672 | ||
|
df36a4bb3c | ||
|
e5913c5abc | ||
|
d21f7971b5 | ||
|
bdcdf47e52 | ||
|
f55350bebc | ||
|
3721d11259 | ||
|
149015556b | ||
|
2bcbeba384 | ||
|
d5d07da4ee | ||
|
2d802585ff | ||
|
6828e8ef6d | ||
|
670754b697 |
59
.eslintrc.js
59
.eslintrc.js
@@ -1,4 +1,9 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
ignorePatterns: [
|
||||||
|
"test/*",
|
||||||
|
"server/modules/apicache/*",
|
||||||
|
"src/util.js"
|
||||||
|
],
|
||||||
root: true,
|
root: true,
|
||||||
env: {
|
env: {
|
||||||
browser: true,
|
browser: true,
|
||||||
@@ -17,39 +22,47 @@ module.exports = {
|
|||||||
requireConfigFile: false,
|
requireConfigFile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
"linebreak-style": ["error", "unix"],
|
"yoda": "error",
|
||||||
"camelcase": ["warn", {
|
eqeqeq: [ "warn", "smart" ],
|
||||||
|
"linebreak-style": [ "error", "unix" ],
|
||||||
|
"camelcase": [ "warn", {
|
||||||
"properties": "never",
|
"properties": "never",
|
||||||
"ignoreImports": true
|
"ignoreImports": true
|
||||||
}],
|
}],
|
||||||
// override/add rules settings here, such as:
|
"no-unused-vars": [ "warn", {
|
||||||
// 'vue/no-unused-vars': 'error'
|
"args": "none"
|
||||||
"no-unused-vars": "warn",
|
}],
|
||||||
indent: [
|
indent: [
|
||||||
"error",
|
"error",
|
||||||
4,
|
4,
|
||||||
{
|
{
|
||||||
ignoredNodes: ["TemplateLiteral"],
|
ignoredNodes: [ "TemplateLiteral" ],
|
||||||
SwitchCase: 1,
|
SwitchCase: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
quotes: ["warn", "double"],
|
quotes: [ "error", "double" ],
|
||||||
semi: "warn",
|
semi: "error",
|
||||||
"vue/html-indent": ["warn", 4], // default: 2
|
"vue/html-indent": [ "error", 4 ], // default: 2
|
||||||
"vue/max-attributes-per-line": "off",
|
"vue/max-attributes-per-line": "off",
|
||||||
"vue/singleline-html-element-content-newline": "off",
|
"vue/singleline-html-element-content-newline": "off",
|
||||||
"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/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly
|
"vue/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly
|
||||||
"no-multi-spaces": ["error", {
|
"no-multi-spaces": [ "error", {
|
||||||
ignoreEOLComments: true,
|
ignoreEOLComments: true,
|
||||||
}],
|
}],
|
||||||
"space-before-function-paren": ["error", {
|
"array-bracket-spacing": [ "warn", "always", {
|
||||||
|
"singleValue": true,
|
||||||
|
"objectsInArrays": false,
|
||||||
|
"arraysInArrays": false
|
||||||
|
}],
|
||||||
|
"space-before-function-paren": [ "error", {
|
||||||
"anonymous": "always",
|
"anonymous": "always",
|
||||||
"named": "never",
|
"named": "never",
|
||||||
"asyncArrow": "always"
|
"asyncArrow": "always"
|
||||||
}],
|
}],
|
||||||
"curly": "error",
|
"curly": "error",
|
||||||
"object-curly-spacing": ["error", "always"],
|
"object-curly-spacing": [ "error", "always" ],
|
||||||
"object-curly-newline": "off",
|
"object-curly-newline": "off",
|
||||||
"object-property-newline": "error",
|
"object-property-newline": "error",
|
||||||
"comma-spacing": "error",
|
"comma-spacing": "error",
|
||||||
@@ -59,37 +72,37 @@ module.exports = {
|
|||||||
"keyword-spacing": "warn",
|
"keyword-spacing": "warn",
|
||||||
"space-infix-ops": "warn",
|
"space-infix-ops": "warn",
|
||||||
"arrow-spacing": "warn",
|
"arrow-spacing": "warn",
|
||||||
"no-trailing-spaces": "warn",
|
"no-trailing-spaces": "error",
|
||||||
"no-constant-condition": ["error", {
|
"no-constant-condition": [ "error", {
|
||||||
"checkLoops": false,
|
"checkLoops": false,
|
||||||
}],
|
}],
|
||||||
"space-before-blocks": "warn",
|
"space-before-blocks": "warn",
|
||||||
//'no-console': 'warn',
|
//'no-console': 'warn',
|
||||||
"no-extra-boolean-cast": "off",
|
"no-extra-boolean-cast": "off",
|
||||||
"no-multiple-empty-lines": ["warn", {
|
"no-multiple-empty-lines": [ "warn", {
|
||||||
"max": 1,
|
"max": 1,
|
||||||
"maxBOF": 0,
|
"maxBOF": 0,
|
||||||
}],
|
}],
|
||||||
"lines-between-class-members": ["warn", "always", {
|
"lines-between-class-members": [ "warn", "always", {
|
||||||
exceptAfterSingleLine: true,
|
exceptAfterSingleLine: true,
|
||||||
}],
|
}],
|
||||||
"no-unneeded-ternary": "error",
|
"no-unneeded-ternary": "error",
|
||||||
"array-bracket-newline": ["error", "consistent"],
|
"array-bracket-newline": [ "error", "consistent" ],
|
||||||
"eol-last": ["error", "always"],
|
"eol-last": [ "error", "always" ],
|
||||||
//'prefer-template': 'error',
|
//'prefer-template': 'error',
|
||||||
"comma-dangle": ["warn", "only-multiline"],
|
"comma-dangle": [ "warn", "only-multiline" ],
|
||||||
"no-empty": ["error", {
|
"no-empty": [ "error", {
|
||||||
"allowEmptyCatch": true
|
"allowEmptyCatch": true
|
||||||
}],
|
}],
|
||||||
"no-control-regex": "off",
|
"no-control-regex": "off",
|
||||||
"one-var": ["error", "never"],
|
"one-var": [ "error", "never" ],
|
||||||
"max-statements-per-line": ["error", { "max": 1 }]
|
"max-statements-per-line": [ "error", { "max": 1 }]
|
||||||
},
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"files": [ "src/languages/*.js", "src/icon.js" ],
|
"files": [ "src/languages/*.js", "src/icon.js" ],
|
||||||
"rules": {
|
"rules": {
|
||||||
"comma-dangle": ["error", "always-multiline"],
|
"comma-dangle": [ "error", "always-multiline" ],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -20,6 +20,7 @@ Please delete any options that are not relevant.
|
|||||||
- [ ] I ran ESLint and other linters for modified files
|
- [ ] I ran ESLint and other linters for modified files
|
||||||
- [ ] I have performed a self-review of my own code and tested it
|
- [ ] I have performed a self-review of my own code and tested it
|
||||||
- [ ] I have commented my code, particularly in hard-to-understand areas
|
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||||
|
(including JSDoc for methods)
|
||||||
- [ ] My changes generate no new warnings
|
- [ ] My changes generate no new warnings
|
||||||
- [ ] My code needed automated testing. I have added them (this is optional task)
|
- [ ] My code needed automated testing. I have added them (this is optional task)
|
||||||
|
|
||||||
|
3
.github/workflows/auto-test.yml
vendored
3
.github/workflows/auto-test.yml
vendored
@@ -20,7 +20,8 @@ jobs:
|
|||||||
# 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:
|
||||||
- uses: actions/checkout@v2
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
|
@@ -1,9 +1,13 @@
|
|||||||
{
|
{
|
||||||
"extends": "stylelint-config-standard",
|
"extends": "stylelint-config-standard",
|
||||||
|
"customSyntax": "postcss-html",
|
||||||
"rules": {
|
"rules": {
|
||||||
"indentation": 4,
|
"indentation": 4,
|
||||||
"no-descending-specificity": null,
|
"no-descending-specificity": null,
|
||||||
"selector-list-comma-newline-after": null,
|
"selector-list-comma-newline-after": null,
|
||||||
"declaration-empty-line-before": null
|
"declaration-empty-line-before": null,
|
||||||
|
"alpha-value-notation": "number",
|
||||||
|
"color-function-notation": "legacy",
|
||||||
|
"shorthand-property-no-redundant-values": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -79,6 +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
|
||||||
|
|
||||||
## Name convention
|
## Name convention
|
||||||
|
|
||||||
|
18
README.md
18
README.md
@@ -25,12 +25,15 @@ VPS is sponsored by Uptime Kuma sponsors on [Open Collective](https://opencollec
|
|||||||
|
|
||||||
* Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / Ping / DNS Record / Push / Steam Game Server.
|
* Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / Ping / DNS Record / Push / Steam Game Server.
|
||||||
* Fancy, Reactive, Fast UI/UX.
|
* Fancy, Reactive, Fast UI/UX.
|
||||||
* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [70+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications).
|
* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications).
|
||||||
* 20 second intervals.
|
* 20 second intervals.
|
||||||
* [Multi Languages](https://github.com/louislam/uptime-kuma/tree/master/src/languages)
|
* [Multi Languages](https://github.com/louislam/uptime-kuma/tree/master/src/languages)
|
||||||
* Simple Status Page
|
* Multiple Status Pages
|
||||||
|
* Map Status Page to Domain
|
||||||
* Ping Chart
|
* Ping Chart
|
||||||
* Certificate Info
|
* Certificate Info
|
||||||
|
* Proxy Support
|
||||||
|
* 2FA available
|
||||||
|
|
||||||
## 🔧 How to Install
|
## 🔧 How to Install
|
||||||
|
|
||||||
@@ -154,10 +157,17 @@ https://www.reddit.com/r/UptimeKuma/
|
|||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
|
|
||||||
|
### Beta Version
|
||||||
|
|
||||||
|
Check out the latest beta release here: https://github.com/louislam/uptime-kuma/releases
|
||||||
|
|
||||||
|
### Bug Reports / Feature Requests
|
||||||
If you want to report a bug or request a new feature. Free feel to open a [new issue](https://github.com/louislam/uptime-kuma/issues).
|
If you want to report a bug or request a new feature. Free feel to open a [new issue](https://github.com/louislam/uptime-kuma/issues).
|
||||||
|
|
||||||
|
### Translations
|
||||||
If you want to translate Uptime Kuma into your language, please read: https://github.com/louislam/uptime-kuma/tree/master/src/languages
|
If you want to translate Uptime Kuma into your language, please read: https://github.com/louislam/uptime-kuma/tree/master/src/languages
|
||||||
|
|
||||||
If you want to modify Uptime Kuma, this guideline may be useful for you: https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md
|
Feel free to correct my grammar in this README, source code, or wiki, as my mother language is not English and my grammar is not that great.
|
||||||
|
|
||||||
Unfortunately, English proofreading is needed too because my grammar is not that great. Feel free to correct my grammar in this README, source code, or wiki.
|
### Pull Requests
|
||||||
|
If you want to modify Uptime Kuma, this guideline may be useful for you: https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md
|
||||||
|
@@ -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 | ❌ |
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
const config = {};
|
const config = {};
|
||||||
|
|
||||||
if (process.env.TEST_FRONTEND) {
|
if (process.env.TEST_FRONTEND) {
|
||||||
config.presets = ["@babel/preset-env"];
|
config.presets = [ "@babel/preset-env" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.TEST_BACKEND) {
|
if (process.env.TEST_BACKEND) {
|
||||||
config.plugins = ["babel-plugin-rewire"];
|
config.plugins = [ "babel-plugin-rewire" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
@@ -10,15 +10,15 @@ export default defineConfig({
|
|||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
legacy({
|
legacy({
|
||||||
targets: ["ie > 11"],
|
targets: [ "ie > 11" ],
|
||||||
additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
|
additionalLegacyPolyfills: [ "regenerator-runtime/runtime" ]
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
css: {
|
css: {
|
||||||
postcss: {
|
postcss: {
|
||||||
"parser": postCssScss,
|
"parser": postCssScss,
|
||||||
"map": false,
|
"map": false,
|
||||||
"plugins": [postcssRTLCSS]
|
"plugins": [ postcssRTLCSS ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
16
db/patch-added-mqtt-monitor.sql
Normal file
16
db/patch-added-mqtt-monitor.sql
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD mqtt_topic TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD mqtt_success_message VARCHAR(255);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD mqtt_username VARCHAR(255);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD mqtt_password VARCHAR(255);
|
||||||
|
|
||||||
|
COMMIT;
|
6
db/patch-status-page-footer-css.sql
Normal file
6
db/patch-status-page-footer-css.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
ALTER TABLE status_page ADD footer_text TEXT;
|
||||||
|
ALTER TABLE status_page ADD custom_css TEXT;
|
||||||
|
ALTER TABLE status_page ADD show_powered_by BOOLEAN NOT NULL DEFAULT 1;
|
||||||
|
COMMIT;
|
@@ -4,5 +4,5 @@ WORKDIR /app
|
|||||||
|
|
||||||
# Install apprise, iputils for non-root ping, setpriv
|
# Install apprise, iputils for non-root ping, setpriv
|
||||||
RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib && \
|
RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib && \
|
||||||
pip3 --no-cache-dir install apprise==0.9.7 && \
|
pip3 --no-cache-dir install apprise==0.9.8 && \
|
||||||
rm -rf /root/.cache
|
rm -rf /root/.cache
|
||||||
|
@@ -11,7 +11,7 @@ WORKDIR /app
|
|||||||
RUN apt update && \
|
RUN apt update && \
|
||||||
apt --yes --no-install-recommends install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib \
|
apt --yes --no-install-recommends install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib \
|
||||||
sqlite3 iputils-ping util-linux dumb-init && \
|
sqlite3 iputils-ping util-linux dumb-init && \
|
||||||
pip3 --no-cache-dir install apprise==0.9.7 && \
|
pip3 --no-cache-dir install apprise==0.9.8 && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install cloudflared
|
# Install cloudflared
|
||||||
|
@@ -11,3 +11,4 @@ services:
|
|||||||
- ./uptime-kuma:/app/data
|
- ./uptime-kuma:/app/data
|
||||||
ports:
|
ports:
|
||||||
- 3001:3001
|
- 3001:3001
|
||||||
|
restart: always
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [{
|
apps: [{
|
||||||
name: "uptime-kuma",
|
name: "uptime-kuma",
|
||||||
script: "./server/server.js",
|
script: "./server/server.js",
|
||||||
}]
|
}]
|
||||||
}
|
};
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
const pkg = require("../../package.json");
|
const pkg = require("../../package.json");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const child_process = require("child_process");
|
const childProcess = require("child_process");
|
||||||
const util = require("../../src/util");
|
const util = require("../../src/util");
|
||||||
|
|
||||||
util.polyfill();
|
util.polyfill();
|
||||||
|
|
||||||
const oldVersion = pkg.version;
|
|
||||||
const version = process.env.VERSION;
|
const version = process.env.VERSION;
|
||||||
|
|
||||||
console.log("Beta Version: " + version);
|
console.log("Beta Version: " + version);
|
||||||
@@ -21,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);
|
||||||
|
|
||||||
@@ -32,7 +35,7 @@ if (! exists) {
|
|||||||
function commit(version) {
|
function commit(version) {
|
||||||
let msg = "Update to " + version;
|
let msg = "Update to " + version;
|
||||||
|
|
||||||
let res = child_process.spawnSync("git", ["commit", "-m", msg, "-a"]);
|
let res = childProcess.spawnSync("git", [ "commit", "-m", msg, "-a" ]);
|
||||||
let stdout = res.stdout.toString().trim();
|
let stdout = res.stdout.toString().trim();
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
|
|
||||||
@@ -40,15 +43,15 @@ function commit(version) {
|
|||||||
throw new Error("commit error");
|
throw new Error("commit error");
|
||||||
}
|
}
|
||||||
|
|
||||||
res = child_process.spawnSync("git", ["push", "origin", "master"]);
|
res = childProcess.spawnSync("git", [ "push", "origin", "master" ]);
|
||||||
console.log(res.stdout.toString().trim());
|
console.log(res.stdout.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
function tag(version) {
|
function tag(version) {
|
||||||
let res = child_process.spawnSync("git", ["tag", version]);
|
let res = childProcess.spawnSync("git", [ "tag", version ]);
|
||||||
console.log(res.stdout.toString().trim());
|
console.log(res.stdout.toString().trim());
|
||||||
|
|
||||||
res = child_process.spawnSync("git", ["push", "origin", version]);
|
res = childProcess.spawnSync("git", [ "push", "origin", version ]);
|
||||||
console.log(res.stdout.toString().trim());
|
console.log(res.stdout.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,15 +60,7 @@ function tagExists(version) {
|
|||||||
throw new Error("invalid version");
|
throw new Error("invalid version");
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = child_process.spawnSync("git", ["tag", "-l", version]);
|
let res = childProcess.spawnSync("git", [ "tag", "-l", version ]);
|
||||||
|
|
||||||
return res.stdout.toString().trim() === version;
|
return res.stdout.toString().trim() === version;
|
||||||
}
|
}
|
||||||
|
|
||||||
function safeDelete(dir) {
|
|
||||||
if (fs.existsSync(dir)) {
|
|
||||||
fs.rmdirSync(dir, {
|
|
||||||
recursive: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -29,7 +29,7 @@ const github = require("@actions/github");
|
|||||||
owner: issue.owner,
|
owner: issue.owner,
|
||||||
repo: issue.repo,
|
repo: issue.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
labels: ["invalid-format"]
|
labels: [ "invalid-format" ]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add the issue closing comment
|
// Add the issue closing comment
|
||||||
|
@@ -12,6 +12,12 @@ const filename = "dist.tar.gz";
|
|||||||
const url = `https://github.com/louislam/uptime-kuma/releases/download/${version}/${filename}`;
|
const url = `https://github.com/louislam/uptime-kuma/releases/download/${version}/${filename}`;
|
||||||
download(url);
|
download(url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the latest version of the dist from a GitHub release.
|
||||||
|
* @param {string} url The URL to download from.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function download(url) {
|
function download(url) {
|
||||||
console.log(url);
|
console.log(url);
|
||||||
|
|
||||||
|
@@ -4,21 +4,21 @@ const util = require("../src/util");
|
|||||||
|
|
||||||
util.polyfill();
|
util.polyfill();
|
||||||
|
|
||||||
const oldVersion = pkg.version
|
const oldVersion = pkg.version;
|
||||||
const newVersion = oldVersion + "-nightly"
|
const newVersion = oldVersion + "-nightly";
|
||||||
|
|
||||||
console.log("Old Version: " + oldVersion)
|
console.log("Old Version: " + oldVersion);
|
||||||
console.log("New Version: " + newVersion)
|
console.log("New Version: " + newVersion);
|
||||||
|
|
||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
// Process package.json
|
// Process package.json
|
||||||
pkg.version = newVersion
|
pkg.version = newVersion;
|
||||||
pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion)
|
pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion);
|
||||||
pkg.scripts["build-docker"] = pkg.scripts["build-docker"].replaceAll(oldVersion, newVersion)
|
pkg.scripts["build-docker"] = pkg.scripts["build-docker"].replaceAll(oldVersion, newVersion);
|
||||||
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n")
|
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
||||||
|
|
||||||
// Process README.md
|
// Process README.md
|
||||||
if (fs.existsSync("README.md")) {
|
if (fs.existsSync("README.md")) {
|
||||||
fs.writeFileSync("README.md", fs.readFileSync("README.md", "utf8").replaceAll(oldVersion, newVersion))
|
fs.writeFileSync("README.md", fs.readFileSync("README.md", "utf8").replaceAll(oldVersion, newVersion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ const Database = require("../server/database");
|
|||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const readline = require("readline");
|
const readline = require("readline");
|
||||||
const { initJWTSecret } = require("../server/util-server");
|
const { initJWTSecret } = require("../server/util-server");
|
||||||
|
const User = require("../server/model/user");
|
||||||
const args = require("args-parser")(process.argv);
|
const args = require("args-parser")(process.argv);
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
@@ -30,7 +31,7 @@ const main = async () => {
|
|||||||
let confirmPassword = await question("Confirm New Password: ");
|
let confirmPassword = await question("Confirm New Password: ");
|
||||||
|
|
||||||
if (password === confirmPassword) {
|
if (password === confirmPassword) {
|
||||||
await user.resetPassword(password);
|
await User.resetPassword(user.id, password);
|
||||||
|
|
||||||
// Reset all sessions by reset jwt secret
|
// Reset all sessions by reset jwt secret
|
||||||
await initJWTSecret();
|
await initJWTSecret();
|
||||||
|
@@ -26,7 +26,7 @@ server.on("request", (request, send, rinfo) => {
|
|||||||
ttl: 300,
|
ttl: 300,
|
||||||
address: "1.2.3.4"
|
address: "1.2.3.4"
|
||||||
});
|
});
|
||||||
} if (question.type === Packet.TYPE.AAAA) {
|
} else if (question.type === Packet.TYPE.AAAA) {
|
||||||
response.answers.push({
|
response.answers.push({
|
||||||
name: question.name,
|
name: question.name,
|
||||||
type: question.type,
|
type: question.type,
|
||||||
|
50
extra/simple-mqtt-server.js
Normal file
50
extra/simple-mqtt-server.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
|
const mqttUsername = "louis1";
|
||||||
|
const mqttPassword = "!@#$LLam";
|
||||||
|
|
||||||
|
class SimpleMqttServer {
|
||||||
|
aedes = require("aedes")();
|
||||||
|
server = require("net").createServer(this.aedes.handle);
|
||||||
|
|
||||||
|
constructor(port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
this.server.listen(this.port, () => {
|
||||||
|
console.log("server started and listening on port ", this.port);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let server1 = new SimpleMqttServer(10000);
|
||||||
|
|
||||||
|
server1.aedes.authenticate = function (client, username, password, callback) {
|
||||||
|
if (username && password) {
|
||||||
|
console.log(password.toString("utf-8"));
|
||||||
|
callback(null, username === mqttUsername && password.toString("utf-8") === mqttPassword);
|
||||||
|
} else {
|
||||||
|
callback(null, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
server1.aedes.on("subscribe", (subscriptions, client) => {
|
||||||
|
console.log(subscriptions);
|
||||||
|
|
||||||
|
for (let s of subscriptions) {
|
||||||
|
if (s.topic === "test") {
|
||||||
|
server1.aedes.publish({
|
||||||
|
topic: "test",
|
||||||
|
payload: Buffer.from("ok"),
|
||||||
|
}, (error) => {
|
||||||
|
if (error) {
|
||||||
|
log.error("mqtt_server", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
server1.start();
|
@@ -1,7 +1,6 @@
|
|||||||
const pkg = require("../package.json");
|
const pkg = require("../package.json");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const rmSync = require("./fs-rmSync.js");
|
const childProcess = require("child_process");
|
||||||
const child_process = require("child_process");
|
|
||||||
const util = require("../src/util");
|
const util = require("../src/util");
|
||||||
|
|
||||||
util.polyfill();
|
util.polyfill();
|
||||||
@@ -26,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);
|
||||||
|
|
||||||
@@ -33,10 +35,16 @@ if (! exists) {
|
|||||||
console.log("version exists");
|
console.log("version exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the version number in package.json and commits it to git.
|
||||||
|
* @param {string} version - The new version number
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function commit(version) {
|
function commit(version) {
|
||||||
let msg = "Update to " + version;
|
let msg = "Update to " + version;
|
||||||
|
|
||||||
let res = child_process.spawnSync("git", ["commit", "-m", msg, "-a"]);
|
let res = childProcess.spawnSync("git", [ "commit", "-m", msg, "-a" ]);
|
||||||
let stdout = res.stdout.toString().trim();
|
let stdout = res.stdout.toString().trim();
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
|
|
||||||
@@ -46,16 +54,22 @@ function commit(version) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function tag(version) {
|
function tag(version) {
|
||||||
let res = child_process.spawnSync("git", ["tag", version]);
|
let res = childProcess.spawnSync("git", [ "tag", version ]);
|
||||||
console.log(res.stdout.toString().trim());
|
console.log(res.stdout.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a given version is already tagged in the git repository.
|
||||||
|
* @param {string} version - The version to check for.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function tagExists(version) {
|
function tagExists(version) {
|
||||||
if (! version) {
|
if (! version) {
|
||||||
throw new Error("invalid version");
|
throw new Error("invalid version");
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = child_process.spawnSync("git", ["tag", "-l", version]);
|
let res = childProcess.spawnSync("git", [ "tag", "-l", version ]);
|
||||||
|
|
||||||
return res.stdout.toString().trim() === version;
|
return res.stdout.toString().trim() === version;
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
const child_process = require("child_process");
|
const childProcess = require("child_process");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
const newVersion = process.env.VERSION;
|
const newVersion = process.env.VERSION;
|
||||||
@@ -16,23 +16,23 @@ function updateWiki(newVersion) {
|
|||||||
|
|
||||||
safeDelete(wikiDir);
|
safeDelete(wikiDir);
|
||||||
|
|
||||||
child_process.spawnSync("git", ["clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir]);
|
childProcess.spawnSync("git", [ "clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir ]);
|
||||||
let content = fs.readFileSync(howToUpdateFilename).toString();
|
let content = fs.readFileSync(howToUpdateFilename).toString();
|
||||||
|
|
||||||
// Replace the version: https://regex101.com/r/hmj2Bc/1
|
// Replace the version: https://regex101.com/r/hmj2Bc/1
|
||||||
content = content.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`);
|
content = content.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`);
|
||||||
fs.writeFileSync(howToUpdateFilename, content);
|
fs.writeFileSync(howToUpdateFilename, content);
|
||||||
|
|
||||||
child_process.spawnSync("git", ["add", "-A"], {
|
childProcess.spawnSync("git", [ "add", "-A" ], {
|
||||||
cwd: wikiDir,
|
cwd: wikiDir,
|
||||||
});
|
});
|
||||||
|
|
||||||
child_process.spawnSync("git", ["commit", "-m", `Update to ${newVersion}`], {
|
childProcess.spawnSync("git", [ "commit", "-m", `Update to ${newVersion}` ], {
|
||||||
cwd: wikiDir,
|
cwd: wikiDir,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Pushing to Github");
|
console.log("Pushing to Github");
|
||||||
child_process.spawnSync("git", ["push"], {
|
childProcess.spawnSync("git", [ "push" ], {
|
||||||
cwd: wikiDir,
|
cwd: wikiDir,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
2252
package-lock.json
generated
2252
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "uptime-kuma",
|
"name": "uptime-kuma",
|
||||||
"version": "1.14.0",
|
"version": "1.15.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
"install-legacy": "npm install --legacy-peer-deps",
|
"install-legacy": "npm install --legacy-peer-deps",
|
||||||
"update-legacy": "npm update --legacy-peer-deps",
|
"update-legacy": "npm update --legacy-peer-deps",
|
||||||
"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:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore",
|
"lint:style": "stylelint \"**/*.{vue,css,scss}\" --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": "vite --host --config ./config/vite.config.js",
|
||||||
@@ -20,7 +21,7 @@
|
|||||||
"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": "node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/ --test",
|
"test": "npm run lint && 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",
|
||||||
@@ -36,7 +37,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.0 && 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",
|
||||||
@@ -48,6 +49,7 @@
|
|||||||
"test-install-script-ubuntu1604": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1604.dockerfile .",
|
"test-install-script-ubuntu1604": "npm run compile-install-script && docker build --progress plain -f test/test_install_script/ubuntu1604.dockerfile .",
|
||||||
"test-nodejs16": "docker build --progress plain -f test/ubuntu-nodejs16.dockerfile .",
|
"test-nodejs16": "docker build --progress plain -f test/ubuntu-nodejs16.dockerfile .",
|
||||||
"simple-dns-server": "node extra/simple-dns-server.js",
|
"simple-dns-server": "node extra/simple-dns-server.js",
|
||||||
|
"simple-mqtt-server": "node extra/simple-mqtt-server.js",
|
||||||
"update-language-files-with-base-lang": "cd extra/update-language-files && node index.js %npm_config_base_lang% && eslint ../../src/languages/**.js --fix",
|
"update-language-files-with-base-lang": "cd extra/update-language-files && node index.js %npm_config_base_lang% && eslint ../../src/languages/**.js --fix",
|
||||||
"update-language-files": "cd extra/update-language-files && node index.js && eslint ../../src/languages/**.js --fix",
|
"update-language-files": "cd extra/update-language-files && node index.js && eslint ../../src/languages/**.js --fix",
|
||||||
"ncu-patch": "npm-check-updates -u -t patch",
|
"ncu-patch": "npm-check-updates -u -t patch",
|
||||||
@@ -60,7 +62,7 @@
|
|||||||
"@fortawesome/free-regular-svg-icons": "~5.15.4",
|
"@fortawesome/free-regular-svg-icons": "~5.15.4",
|
||||||
"@fortawesome/free-solid-svg-icons": "~5.15.4",
|
"@fortawesome/free-solid-svg-icons": "~5.15.4",
|
||||||
"@fortawesome/vue-fontawesome": "~3.0.0-5",
|
"@fortawesome/vue-fontawesome": "~3.0.0-5",
|
||||||
"@louislam/sqlite3": "~6.0.1",
|
"@louislam/sqlite3": "~15.0.3",
|
||||||
"@popperjs/core": "~2.10.2",
|
"@popperjs/core": "~2.10.2",
|
||||||
"args-parser": "~1.3.0",
|
"args-parser": "~1.3.0",
|
||||||
"axios": "~0.26.1",
|
"axios": "~0.26.1",
|
||||||
@@ -85,12 +87,14 @@
|
|||||||
"jsonwebtoken": "~8.5.1",
|
"jsonwebtoken": "~8.5.1",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"limiter": "^2.1.0",
|
"limiter": "^2.1.0",
|
||||||
|
"mqtt": "^4.2.8",
|
||||||
"node-cloudflared-tunnel": "~1.0.9",
|
"node-cloudflared-tunnel": "~1.0.9",
|
||||||
"nodemailer": "~6.6.5",
|
"nodemailer": "~6.6.5",
|
||||||
"notp": "~2.0.3",
|
"notp": "~2.0.3",
|
||||||
"password-hash": "~1.2.2",
|
"password-hash": "~1.2.2",
|
||||||
"postcss-rtlcss": "~3.4.1",
|
"postcss-rtlcss": "~3.4.1",
|
||||||
"postcss-scss": "~4.0.3",
|
"postcss-scss": "~4.0.3",
|
||||||
|
"prismjs": "^1.27.0",
|
||||||
"prom-client": "~13.2.0",
|
"prom-client": "~13.2.0",
|
||||||
"prometheus-api-metrics": "~3.2.1",
|
"prometheus-api-metrics": "~3.2.1",
|
||||||
"qrcode": "~1.5.0",
|
"qrcode": "~1.5.0",
|
||||||
@@ -110,6 +114,7 @@
|
|||||||
"vue-i18n": "~9.1.9",
|
"vue-i18n": "~9.1.9",
|
||||||
"vue-image-crop-upload": "~3.0.3",
|
"vue-image-crop-upload": "~3.0.3",
|
||||||
"vue-multiselect": "~3.0.0-alpha.2",
|
"vue-multiselect": "~3.0.0-alpha.2",
|
||||||
|
"vue-prism-editor": "^2.0.0-alpha.2",
|
||||||
"vue-qrcode": "~1.0.0",
|
"vue-qrcode": "~1.0.0",
|
||||||
"vue-router": "~4.0.14",
|
"vue-router": "~4.0.14",
|
||||||
"vue-toastification": "~2.0.0-rc.5",
|
"vue-toastification": "~2.0.0-rc.5",
|
||||||
@@ -123,6 +128,7 @@
|
|||||||
"@vitejs/plugin-legacy": "~1.6.4",
|
"@vitejs/plugin-legacy": "~1.6.4",
|
||||||
"@vitejs/plugin-vue": "~1.9.4",
|
"@vitejs/plugin-vue": "~1.9.4",
|
||||||
"@vue/compiler-sfc": "~3.2.31",
|
"@vue/compiler-sfc": "~3.2.31",
|
||||||
|
"aedes": "^0.46.3",
|
||||||
"babel-plugin-rewire": "~1.2.0",
|
"babel-plugin-rewire": "~1.2.0",
|
||||||
"core-js": "~3.18.3",
|
"core-js": "~3.18.3",
|
||||||
"cross-env": "~7.0.3",
|
"cross-env": "~7.0.3",
|
||||||
@@ -132,6 +138,7 @@
|
|||||||
"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.5",
|
||||||
|
"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.2.0",
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
const { checkLogin } = require("./util-server");
|
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
|
|
||||||
class TwoFA {
|
class TwoFA {
|
||||||
|
@@ -2,7 +2,6 @@ const basicAuth = require("express-basic-auth");
|
|||||||
const passwordHash = require("./password-hash");
|
const passwordHash = require("./password-hash");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { setting } = require("./util-server");
|
const { setting } = require("./util-server");
|
||||||
const { debug } = require("../src/util");
|
|
||||||
const { loginRateLimiter } = require("./rate-limiter");
|
const { loginRateLimiter } = require("./rate-limiter");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,6 +33,13 @@ exports.login = async function (username, password) {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that checks if a user is logged in.
|
||||||
|
* @param {string} username The username of the user to check for.
|
||||||
|
* @param {function} callback The callback to call when done, with an error and result parameter.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function myAuthorizer(username, password, callback) {
|
function myAuthorizer(username, password, callback) {
|
||||||
// Login Rate Limit
|
// Login Rate Limit
|
||||||
loginRateLimiter.pass(null, 0).then((pass) => {
|
loginRateLimiter.pass(null, 0).then((pass) => {
|
||||||
|
@@ -3,10 +3,17 @@
|
|||||||
*/
|
*/
|
||||||
const { TimeLogger } = require("../src/util");
|
const { TimeLogger } = require("../src/util");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { io } = require("./server");
|
const { UptimeKumaServer } = require("./uptime-kuma-server");
|
||||||
|
const io = UptimeKumaServer.getInstance().io;
|
||||||
const { setting } = require("./util-server");
|
const { setting } = require("./util-server");
|
||||||
const checkVersion = require("./check-version");
|
const checkVersion = require("./check-version");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a list of notifications to the user.
|
||||||
|
* @param {Socket} socket The socket object that is connected to the client.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
async function sendNotificationList(socket) {
|
async function sendNotificationList(socket) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
|
||||||
@@ -92,7 +99,7 @@ async function sendImportantHeartbeatList(socket, monitorID, toUser = false, ove
|
|||||||
async function sendProxyList(socket) {
|
async function sendProxyList(socket) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
|
||||||
const list = await R.find("proxy", " user_id = ? ", [socket.userID]);
|
const list = await R.find("proxy", " user_id = ? ", [ socket.userID ]);
|
||||||
io.to(socket.userID).emit("proxyList", list.map(bean => bean.export()));
|
io.to(socket.userID).emit("proxyList", list.map(bean => bean.export()));
|
||||||
|
|
||||||
timeLogger.print("Send Proxy List");
|
timeLogger.print("Send Proxy List");
|
||||||
@@ -100,6 +107,12 @@ async function sendProxyList(socket) {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits the version information to the client.
|
||||||
|
* @param {Socket} socket The socket object that is connected to the client.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
async function sendInfo(socket) {
|
async function sendInfo(socket) {
|
||||||
socket.emit("info", {
|
socket.emit("info", {
|
||||||
version: checkVersion.version,
|
version: checkVersion.version,
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { setSetting, setting } = require("./util-server");
|
const { setSetting, setting } = require("./util-server");
|
||||||
const { debug, sleep } = require("../src/util");
|
const { log, sleep } = require("../src/util");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
const knex = require("knex");
|
const knex = require("knex");
|
||||||
|
|
||||||
@@ -56,6 +56,8 @@ class Database {
|
|||||||
"patch-status-page.sql": true,
|
"patch-status-page.sql": true,
|
||||||
"patch-proxy.sql": true,
|
"patch-proxy.sql": true,
|
||||||
"patch-monitor-expiry-notification.sql": true,
|
"patch-monitor-expiry-notification.sql": true,
|
||||||
|
"patch-status-page-footer-css.sql": true,
|
||||||
|
"patch-added-mqtt-monitor.sql": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,7 +82,7 @@ class Database {
|
|||||||
fs.mkdirSync(Database.uploadDir, { recursive: true });
|
fs.mkdirSync(Database.uploadDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Data Dir: ${Database.dataDir}`);
|
log.info("db", `Data Dir: ${Database.dataDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async connect(testMode = false, autoloadModels = true, noLog = false) {
|
static async connect(testMode = false, autoloadModels = true, noLog = false) {
|
||||||
@@ -135,10 +137,10 @@ class Database {
|
|||||||
await R.exec("PRAGMA synchronous = FULL");
|
await R.exec("PRAGMA synchronous = FULL");
|
||||||
|
|
||||||
if (!noLog) {
|
if (!noLog) {
|
||||||
console.log("SQLite config:");
|
log.info("db", "SQLite config:");
|
||||||
console.log(await R.getAll("PRAGMA journal_mode"));
|
log.info("db", await R.getAll("PRAGMA journal_mode"));
|
||||||
console.log(await R.getAll("PRAGMA cache_size"));
|
log.info("db", await R.getAll("PRAGMA cache_size"));
|
||||||
console.log("SQLite Version: " + await R.getCell("SELECT sqlite_version()"));
|
log.info("db", "SQLite Version: " + await R.getCell("SELECT sqlite_version()"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,15 +151,15 @@ class Database {
|
|||||||
version = 0;
|
version = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info("Your database version: " + version);
|
log.info("db", "Your database version: " + version);
|
||||||
console.info("Latest database version: " + this.latestVersion);
|
log.info("db", "Latest database version: " + this.latestVersion);
|
||||||
|
|
||||||
if (version === this.latestVersion) {
|
if (version === this.latestVersion) {
|
||||||
console.info("Database patch not needed");
|
log.info("db", "Database patch not needed");
|
||||||
} else if (version > this.latestVersion) {
|
} else if (version > this.latestVersion) {
|
||||||
console.info("Warning: Database version is newer than expected");
|
log.info("db", "Warning: Database version is newer than expected");
|
||||||
} else {
|
} else {
|
||||||
console.info("Database patch is needed");
|
log.info("db", "Database patch is needed");
|
||||||
|
|
||||||
this.backup(version);
|
this.backup(version);
|
||||||
|
|
||||||
@@ -165,17 +167,17 @@ class Database {
|
|||||||
try {
|
try {
|
||||||
for (let i = version + 1; i <= this.latestVersion; i++) {
|
for (let i = version + 1; i <= this.latestVersion; i++) {
|
||||||
const sqlFile = `./db/patch${i}.sql`;
|
const sqlFile = `./db/patch${i}.sql`;
|
||||||
console.info(`Patching ${sqlFile}`);
|
log.info("db", `Patching ${sqlFile}`);
|
||||||
await Database.importSQLFile(sqlFile);
|
await Database.importSQLFile(sqlFile);
|
||||||
console.info(`Patched ${sqlFile}`);
|
log.info("db", `Patched ${sqlFile}`);
|
||||||
await setSetting("database_version", i);
|
await setSetting("database_version", i);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
await Database.close();
|
await Database.close();
|
||||||
|
|
||||||
console.error(ex);
|
log.error("db", ex);
|
||||||
console.error("Start Uptime-Kuma failed due to issue patching the database");
|
log.error("db", "Start Uptime-Kuma failed due to issue patching the database");
|
||||||
console.error("Please submit a bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
log.error("db", "Please submit a bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
||||||
|
|
||||||
this.restore();
|
this.restore();
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@@ -191,15 +193,15 @@ class Database {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch2() {
|
static async patch2() {
|
||||||
console.log("Database Patch 2.0 Process");
|
log.info("db", "Database Patch 2.0 Process");
|
||||||
let databasePatchedFiles = await setting("databasePatchedFiles");
|
let databasePatchedFiles = await setting("databasePatchedFiles");
|
||||||
|
|
||||||
if (! databasePatchedFiles) {
|
if (! databasePatchedFiles) {
|
||||||
databasePatchedFiles = {};
|
databasePatchedFiles = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Patched files:");
|
log.debug("db", "Patched files:");
|
||||||
debug(databasePatchedFiles);
|
log.debug("db", databasePatchedFiles);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (let sqlFilename in this.patchList) {
|
for (let sqlFilename in this.patchList) {
|
||||||
@@ -207,15 +209,15 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.patched) {
|
if (this.patched) {
|
||||||
console.log("Database Patched Successfully");
|
log.info("db", "Database Patched Successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
await Database.close();
|
await Database.close();
|
||||||
|
|
||||||
console.error(ex);
|
log.error("db", ex);
|
||||||
console.error("Start Uptime-Kuma failed due to issue patching the database");
|
log.error("db", "Start Uptime-Kuma failed due to issue patching the database");
|
||||||
console.error("Please submit the bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
log.error("db", "Please submit the bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
||||||
|
|
||||||
this.restore();
|
this.restore();
|
||||||
|
|
||||||
@@ -302,16 +304,16 @@ class Database {
|
|||||||
let value = this.patchList[sqlFilename];
|
let value = this.patchList[sqlFilename];
|
||||||
|
|
||||||
if (! value) {
|
if (! value) {
|
||||||
console.log(sqlFilename + " skip");
|
log.info("db", sqlFilename + " skip");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if patched
|
// Check if patched
|
||||||
if (! databasePatchedFiles[sqlFilename]) {
|
if (! databasePatchedFiles[sqlFilename]) {
|
||||||
console.log(sqlFilename + " is not patched");
|
log.info("db", sqlFilename + " is not patched");
|
||||||
|
|
||||||
if (value.parents) {
|
if (value.parents) {
|
||||||
console.log(sqlFilename + " need parents");
|
log.info("db", sqlFilename + " need parents");
|
||||||
for (let parentSQLFilename of value.parents) {
|
for (let parentSQLFilename of value.parents) {
|
||||||
await this.patch2Recursion(parentSQLFilename, databasePatchedFiles);
|
await this.patch2Recursion(parentSQLFilename, databasePatchedFiles);
|
||||||
}
|
}
|
||||||
@@ -319,14 +321,14 @@ class Database {
|
|||||||
|
|
||||||
this.backup(dayjs().format("YYYYMMDDHHmmss"));
|
this.backup(dayjs().format("YYYYMMDDHHmmss"));
|
||||||
|
|
||||||
console.log(sqlFilename + " is patching");
|
log.info("db", sqlFilename + " is patching");
|
||||||
this.patched = true;
|
this.patched = true;
|
||||||
await this.importSQLFile("./db/" + sqlFilename);
|
await this.importSQLFile("./db/" + sqlFilename);
|
||||||
databasePatchedFiles[sqlFilename] = true;
|
databasePatchedFiles[sqlFilename] = true;
|
||||||
console.log(sqlFilename + " was patched successfully");
|
log.info("db", sqlFilename + " was patched successfully");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
debug(sqlFilename + " is already patched, skip");
|
log.debug("db", sqlFilename + " is already patched, skip");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +380,7 @@ class Database {
|
|||||||
};
|
};
|
||||||
process.addListener("unhandledRejection", listener);
|
process.addListener("unhandledRejection", listener);
|
||||||
|
|
||||||
console.log("Closing the database");
|
log.info("db", "Closing the database");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Database.noReject = true;
|
Database.noReject = true;
|
||||||
@@ -388,10 +390,10 @@ class Database {
|
|||||||
if (Database.noReject) {
|
if (Database.noReject) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
console.log("Waiting to close the database");
|
log.info("db", "Waiting to close the database");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("SQLite closed");
|
log.info("db", "SQLite closed");
|
||||||
|
|
||||||
process.removeListener("unhandledRejection", listener);
|
process.removeListener("unhandledRejection", listener);
|
||||||
}
|
}
|
||||||
@@ -403,7 +405,7 @@ class Database {
|
|||||||
*/
|
*/
|
||||||
static backup(version) {
|
static backup(version) {
|
||||||
if (! this.backupPath) {
|
if (! this.backupPath) {
|
||||||
console.info("Backing up the database");
|
log.info("db", "Backing up the database");
|
||||||
this.backupPath = this.dataDir + "kuma.db.bak" + version;
|
this.backupPath = this.dataDir + "kuma.db.bak" + version;
|
||||||
fs.copyFileSync(Database.path, this.backupPath);
|
fs.copyFileSync(Database.path, this.backupPath);
|
||||||
|
|
||||||
@@ -426,7 +428,7 @@ class Database {
|
|||||||
*/
|
*/
|
||||||
static restore() {
|
static restore() {
|
||||||
if (this.backupPath) {
|
if (this.backupPath) {
|
||||||
console.error("Patching the database failed!!! Restoring the backup");
|
log.error("db", "Patching the database failed!!! Restoring the backup");
|
||||||
|
|
||||||
const shmPath = Database.path + "-shm";
|
const shmPath = Database.path + "-shm";
|
||||||
const walPath = Database.path + "-wal";
|
const walPath = Database.path + "-wal";
|
||||||
@@ -445,7 +447,7 @@ class Database {
|
|||||||
fs.unlinkSync(walPath);
|
fs.unlinkSync(walPath);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Restore failed; you may need to restore the backup manually");
|
log.error("db", "Restore failed; you may need to restore the backup manually");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,14 +463,14 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("Nothing to restore");
|
log.info("db", "Nothing to restore");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSize() {
|
static getSize() {
|
||||||
debug("Database.getSize()");
|
log.debug("db", "Database.getSize()");
|
||||||
let stats = fs.statSync(Database.path);
|
let stats = fs.statSync(Database.path);
|
||||||
debug(stats);
|
log.debug("db", stats);
|
||||||
return stats.size;
|
return stats.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,12 +3,19 @@
|
|||||||
Modified with 0 dependencies
|
Modified with 0 dependencies
|
||||||
*/
|
*/
|
||||||
let fs = require("fs");
|
let fs = require("fs");
|
||||||
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
let ImageDataURI = (() => {
|
let ImageDataURI = (() => {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} dataURI - A string that is a valid Data 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.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function decode(dataURI) {
|
function decode(dataURI) {
|
||||||
if (!/data:image\//.test(dataURI)) {
|
if (!/data:image\//.test(dataURI)) {
|
||||||
console.log("ImageDataURI :: Error :: It seems that it is not an Image Data URI. Couldn't match \"data:image/\"");
|
log.error("image-data-uri", "It seems that it is not an Image Data URI. Couldn't match \"data:image/\"");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,9 +27,16 @@ let ImageDataURI = (() => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Buffer} data - The image data to be encoded.
|
||||||
|
* @param {String} mediaType - The type of the image, e.g., "image/png".
|
||||||
|
* @returns {String|null} A string representing the base64-encoded version of the given Buffer object or null if an error occurred.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function encode(data, mediaType) {
|
function encode(data, mediaType) {
|
||||||
if (!data || !mediaType) {
|
if (!data || !mediaType) {
|
||||||
console.log("ImageDataURI :: Error :: Missing some of the required params: data, mediaType ");
|
log.error("image-data-uri", "Missing some of the required params: data, mediaType");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +47,13 @@ let ImageDataURI = (() => {
|
|||||||
return dataImgBase64;
|
return dataImgBase64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a data URI to a file path.
|
||||||
|
* @param {string} dataURI The Data URI of the image.
|
||||||
|
* @param {string} [filePath] The path where the image will be saved, defaults to "./".
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function outputFile(dataURI, filePath) {
|
function outputFile(dataURI, filePath) {
|
||||||
filePath = filePath || "./";
|
filePath = filePath || "./";
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const Bree = require("bree");
|
const Bree = require("bree");
|
||||||
const { SHARE_ENV } = require("worker_threads");
|
const { SHARE_ENV } = require("worker_threads");
|
||||||
|
const { log } = require("../src/util");
|
||||||
let bree;
|
let bree;
|
||||||
const jobs = [
|
const jobs = [
|
||||||
{
|
{
|
||||||
@@ -18,7 +19,7 @@ const initBackgroundJobs = function (args) {
|
|||||||
workerData: args,
|
workerData: args,
|
||||||
},
|
},
|
||||||
workerMessageHandler: (message) => {
|
workerMessageHandler: (message) => {
|
||||||
console.log("[Background Job]:", message);
|
log.info("jobs", message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ const DEFAULT_KEEP_PERIOD = 180;
|
|||||||
try {
|
try {
|
||||||
await R.exec(
|
await R.exec(
|
||||||
"DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
|
"DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
|
||||||
[parsedPeriod]
|
[ parsedPeriod ]
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(`Failed to clear old data: ${e.message}`);
|
log(`Failed to clear old data: ${e.message}`);
|
||||||
|
@@ -9,7 +9,7 @@ const log = function (any) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const exit = function (error) {
|
const exit = function (error) {
|
||||||
if (error && error != 0) {
|
if (error && error !== 0) {
|
||||||
process.exit(error);
|
process.exit(error);
|
||||||
} else {
|
} else {
|
||||||
if (parentPort) {
|
if (parentPort) {
|
||||||
|
@@ -6,8 +6,8 @@ dayjs.extend(utc);
|
|||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { Prometheus } = require("../prometheus");
|
const { Prometheus } = require("../prometheus");
|
||||||
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util");
|
const { log, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util");
|
||||||
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, errorLog } = require("../util-server");
|
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, errorLog, mqttAsync } = require("../util-server");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
const { Notification } = require("../notification");
|
const { Notification } = require("../notification");
|
||||||
@@ -42,7 +42,7 @@ class Monitor extends BeanModel {
|
|||||||
/**
|
/**
|
||||||
* Return an object that ready to parse to JSON
|
* Return an object that ready to parse to JSON
|
||||||
*/
|
*/
|
||||||
async toJSON() {
|
async toJSON(includeSensitiveData = true) {
|
||||||
|
|
||||||
let notificationIDList = {};
|
let notificationIDList = {};
|
||||||
|
|
||||||
@@ -56,15 +56,11 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
const tags = await this.getTags();
|
const tags = await this.getTags();
|
||||||
|
|
||||||
return {
|
let data = {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: this.method,
|
method: this.method,
|
||||||
body: this.body,
|
|
||||||
headers: this.headers,
|
|
||||||
basic_auth_user: this.basic_auth_user,
|
|
||||||
basic_auth_pass: this.basic_auth_pass,
|
|
||||||
hostname: this.hostname,
|
hostname: this.hostname,
|
||||||
port: this.port,
|
port: this.port,
|
||||||
maxretries: this.maxretries,
|
maxretries: this.maxretries,
|
||||||
@@ -82,15 +78,31 @@ class Monitor extends BeanModel {
|
|||||||
dns_resolve_type: this.dns_resolve_type,
|
dns_resolve_type: this.dns_resolve_type,
|
||||||
dns_resolve_server: this.dns_resolve_server,
|
dns_resolve_server: this.dns_resolve_server,
|
||||||
dns_last_result: this.dns_last_result,
|
dns_last_result: this.dns_last_result,
|
||||||
pushToken: this.pushToken,
|
|
||||||
proxyId: this.proxy_id,
|
proxyId: this.proxy_id,
|
||||||
notificationIDList,
|
notificationIDList,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
|
mqttUsername: this.mqttUsername,
|
||||||
|
mqttPassword: this.mqttPassword,
|
||||||
|
mqttTopic: this.mqttTopic,
|
||||||
|
mqttSuccessMessage: this.mqttSuccessMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (includeSensitiveData) {
|
||||||
|
data = {
|
||||||
|
...data,
|
||||||
|
headers: this.headers,
|
||||||
|
body: this.body,
|
||||||
|
basic_auth_user: this.basic_auth_user,
|
||||||
|
basic_auth_pass: this.basic_auth_pass,
|
||||||
|
pushToken: this.pushToken,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,7 +163,7 @@ class Monitor extends BeanModel {
|
|||||||
// undefined if not https
|
// undefined if not https
|
||||||
let tlsInfo = undefined;
|
let tlsInfo = undefined;
|
||||||
|
|
||||||
if (! previousBeat) {
|
if (!previousBeat) {
|
||||||
previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
|
previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
|
||||||
this.id,
|
this.id,
|
||||||
]);
|
]);
|
||||||
@@ -169,7 +181,7 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Duration
|
// Duration
|
||||||
if (! isFirstBeat) {
|
if (!isFirstBeat) {
|
||||||
bean.duration = dayjs(bean.time).diff(dayjs(previousBeat.time), "second");
|
bean.duration = dayjs(bean.time).diff(dayjs(previousBeat.time), "second");
|
||||||
} else {
|
} else {
|
||||||
bean.duration = 0;
|
bean.duration = 0;
|
||||||
@@ -193,7 +205,7 @@ class Monitor extends BeanModel {
|
|||||||
rejectUnauthorized: !this.getIgnoreTls(),
|
rejectUnauthorized: !this.getIgnoreTls(),
|
||||||
};
|
};
|
||||||
|
|
||||||
debug(`[${this.name}] Prepare Options for axios`);
|
log.debug("monitor", `[${this.name}] Prepare Options for axios`);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
@@ -230,8 +242,8 @@ class Monitor extends BeanModel {
|
|||||||
options.httpsAgent = new https.Agent(httpsAgentOptions);
|
options.httpsAgent = new https.Agent(httpsAgentOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(`[${this.name}] Axios Options: ${JSON.stringify(options)}`);
|
log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
|
||||||
debug(`[${this.name}] Axios Request`);
|
log.debug("monitor", `[${this.name}] Axios Request`);
|
||||||
|
|
||||||
let res = await axios.request(options);
|
let res = await axios.request(options);
|
||||||
bean.msg = `${res.status} - ${res.statusText}`;
|
bean.msg = `${res.status} - ${res.statusText}`;
|
||||||
@@ -240,29 +252,30 @@ class Monitor extends BeanModel {
|
|||||||
// Check certificate if https is used
|
// Check certificate if https is used
|
||||||
let certInfoStartTime = dayjs().valueOf();
|
let certInfoStartTime = dayjs().valueOf();
|
||||||
if (this.getUrl()?.protocol === "https:") {
|
if (this.getUrl()?.protocol === "https:") {
|
||||||
debug(`[${this.name}] Check cert`);
|
log.debug("monitor", `[${this.name}] Check cert`);
|
||||||
try {
|
try {
|
||||||
let tlsInfoObject = checkCertificate(res);
|
let tlsInfoObject = checkCertificate(res);
|
||||||
tlsInfo = await this.updateTlsInfo(tlsInfoObject);
|
tlsInfo = await this.updateTlsInfo(tlsInfoObject);
|
||||||
|
|
||||||
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
||||||
debug(`[${this.name}] call sendCertNotification`);
|
log.debug("monitor", `[${this.name}] call sendCertNotification`);
|
||||||
await this.sendCertNotification(tlsInfoObject);
|
await this.sendCertNotification(tlsInfoObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.message !== "No TLS certificate in response") {
|
if (e.message !== "No TLS certificate in response") {
|
||||||
console.error(e.message);
|
log.error("monitor", "Caught error");
|
||||||
|
log.error("monitor", e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.TIMELOGGER === "1") {
|
if (process.env.TIMELOGGER === "1") {
|
||||||
debug("Cert Info Query Time: " + (dayjs().valueOf() - certInfoStartTime) + "ms");
|
log.debug("monitor", "Cert Info Query Time: " + (dayjs().valueOf() - certInfoStartTime) + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID == this.id) {
|
if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID === this.id) {
|
||||||
console.log(res.data);
|
log.info("monitor", res.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.type === "http") {
|
if (this.type === "http") {
|
||||||
@@ -301,24 +314,24 @@ class Monitor extends BeanModel {
|
|||||||
let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type);
|
let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type);
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
|
|
||||||
if (this.dns_resolve_type == "A" || this.dns_resolve_type == "AAAA" || this.dns_resolve_type == "TXT") {
|
if (this.dns_resolve_type === "A" || this.dns_resolve_type === "AAAA" || this.dns_resolve_type === "TXT") {
|
||||||
dnsMessage += "Records: ";
|
dnsMessage += "Records: ";
|
||||||
dnsMessage += dnsRes.join(" | ");
|
dnsMessage += dnsRes.join(" | ");
|
||||||
} else if (this.dns_resolve_type == "CNAME" || this.dns_resolve_type == "PTR") {
|
} else if (this.dns_resolve_type === "CNAME" || this.dns_resolve_type === "PTR") {
|
||||||
dnsMessage = dnsRes[0];
|
dnsMessage = dnsRes[0];
|
||||||
} else if (this.dns_resolve_type == "CAA") {
|
} else if (this.dns_resolve_type === "CAA") {
|
||||||
dnsMessage = dnsRes[0].issue;
|
dnsMessage = dnsRes[0].issue;
|
||||||
} else if (this.dns_resolve_type == "MX") {
|
} else if (this.dns_resolve_type === "MX") {
|
||||||
dnsRes.forEach(record => {
|
dnsRes.forEach(record => {
|
||||||
dnsMessage += `Hostname: ${record.exchange} - Priority: ${record.priority} | `;
|
dnsMessage += `Hostname: ${record.exchange} - Priority: ${record.priority} | `;
|
||||||
});
|
});
|
||||||
dnsMessage = dnsMessage.slice(0, -2);
|
dnsMessage = dnsMessage.slice(0, -2);
|
||||||
} else if (this.dns_resolve_type == "NS") {
|
} else if (this.dns_resolve_type === "NS") {
|
||||||
dnsMessage += "Servers: ";
|
dnsMessage += "Servers: ";
|
||||||
dnsMessage += dnsRes.join(" | ");
|
dnsMessage += dnsRes.join(" | ");
|
||||||
} else if (this.dns_resolve_type == "SOA") {
|
} else if (this.dns_resolve_type === "SOA") {
|
||||||
dnsMessage += `NS-Name: ${dnsRes.nsname} | Hostmaster: ${dnsRes.hostmaster} | Serial: ${dnsRes.serial} | Refresh: ${dnsRes.refresh} | Retry: ${dnsRes.retry} | Expire: ${dnsRes.expire} | MinTTL: ${dnsRes.minttl}`;
|
dnsMessage += `NS-Name: ${dnsRes.nsname} | Hostmaster: ${dnsRes.hostmaster} | Serial: ${dnsRes.serial} | Refresh: ${dnsRes.refresh} | Retry: ${dnsRes.retry} | Expire: ${dnsRes.expire} | MinTTL: ${dnsRes.minttl}`;
|
||||||
} else if (this.dns_resolve_type == "SRV") {
|
} else if (this.dns_resolve_type === "SRV") {
|
||||||
dnsRes.forEach(record => {
|
dnsRes.forEach(record => {
|
||||||
dnsMessage += `Name: ${record.name} | Port: ${record.port} | Priority: ${record.priority} | Weight: ${record.weight} | `;
|
dnsMessage += `Name: ${record.name} | Port: ${record.port} | Priority: ${record.priority} | Weight: ${record.weight} | `;
|
||||||
});
|
});
|
||||||
@@ -342,7 +355,7 @@ class Monitor extends BeanModel {
|
|||||||
time
|
time
|
||||||
]);
|
]);
|
||||||
|
|
||||||
debug("heartbeatCount" + heartbeatCount + " " + time);
|
log.debug("monitor", "heartbeatCount" + heartbeatCount + " " + time);
|
||||||
|
|
||||||
if (heartbeatCount <= 0) {
|
if (heartbeatCount <= 0) {
|
||||||
// Fix #922, since previous heartbeat could be inserted by api, it should get from database
|
// Fix #922, since previous heartbeat could be inserted by api, it should get from database
|
||||||
@@ -373,7 +386,7 @@ class Monitor extends BeanModel {
|
|||||||
},
|
},
|
||||||
httpsAgent: new https.Agent({
|
httpsAgent: new https.Agent({
|
||||||
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
||||||
rejectUnauthorized: ! this.getIgnoreTls(),
|
rejectUnauthorized: !this.getIgnoreTls(),
|
||||||
}),
|
}),
|
||||||
maxRedirects: this.maxredirects,
|
maxRedirects: this.maxredirects,
|
||||||
validateStatus: (status) => {
|
validateStatus: (status) => {
|
||||||
@@ -395,7 +408,14 @@ class Monitor extends BeanModel {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error("Server not found on Steam");
|
throw new Error("Server not found on Steam");
|
||||||
}
|
}
|
||||||
|
} else if (this.type === "mqtt") {
|
||||||
|
bean.msg = await mqttAsync(this.hostname, this.mqttTopic, this.mqttSuccessMessage, {
|
||||||
|
port: this.port,
|
||||||
|
username: this.mqttUsername,
|
||||||
|
password: this.mqttPassword,
|
||||||
|
interval: this.interval,
|
||||||
|
});
|
||||||
|
bean.status = UP;
|
||||||
} else {
|
} else {
|
||||||
bean.msg = "Unknown Monitor Type";
|
bean.msg = "Unknown Monitor Type";
|
||||||
bean.status = PENDING;
|
bean.status = PENDING;
|
||||||
@@ -426,7 +446,7 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(`[${this.name}] Check isImportant`);
|
log.debug("monitor", `[${this.name}] Check isImportant`);
|
||||||
let isImportant = Monitor.isImportantBeat(isFirstBeat, previousBeat?.status, bean.status);
|
let isImportant = Monitor.isImportantBeat(isFirstBeat, previousBeat?.status, bean.status);
|
||||||
|
|
||||||
// Mark as important if status changed, ignore pending pings,
|
// Mark as important if status changed, ignore pending pings,
|
||||||
@@ -434,11 +454,11 @@ class Monitor extends BeanModel {
|
|||||||
if (isImportant) {
|
if (isImportant) {
|
||||||
bean.important = true;
|
bean.important = true;
|
||||||
|
|
||||||
debug(`[${this.name}] sendNotification`);
|
log.debug("monitor", `[${this.name}] sendNotification`);
|
||||||
await Monitor.sendNotification(isFirstBeat, this, bean);
|
await Monitor.sendNotification(isFirstBeat, this, bean);
|
||||||
|
|
||||||
// Clear Status Page Cache
|
// Clear Status Page Cache
|
||||||
debug(`[${this.name}] apicache clear`);
|
log.debug("monitor", `[${this.name}] apicache clear`);
|
||||||
apicache.clear();
|
apicache.clear();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -446,33 +466,33 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bean.status === UP) {
|
if (bean.status === UP) {
|
||||||
console.info(`Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${beatInterval} seconds | Type: ${this.type}`);
|
log.info("monitor", `Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${beatInterval} seconds | Type: ${this.type}`);
|
||||||
} else if (bean.status === PENDING) {
|
} else if (bean.status === PENDING) {
|
||||||
if (this.retryInterval > 0) {
|
if (this.retryInterval > 0) {
|
||||||
beatInterval = this.retryInterval;
|
beatInterval = this.retryInterval;
|
||||||
}
|
}
|
||||||
console.warn(`Monitor #${this.id} '${this.name}': Pending: ${bean.msg} | Max retries: ${this.maxretries} | Retry: ${retries} | Retry Interval: ${beatInterval} seconds | Type: ${this.type}`);
|
log.warn("monitor", `Monitor #${this.id} '${this.name}': Pending: ${bean.msg} | Max retries: ${this.maxretries} | Retry: ${retries} | Retry Interval: ${beatInterval} seconds | Type: ${this.type}`);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type}`);
|
log.warn("monitor", `Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(`[${this.name}] Send to socket`);
|
log.debug("monitor", `[${this.name}] Send to socket`);
|
||||||
io.to(this.user_id).emit("heartbeat", bean.toJSON());
|
io.to(this.user_id).emit("heartbeat", bean.toJSON());
|
||||||
Monitor.sendStats(io, this.id, this.user_id);
|
Monitor.sendStats(io, this.id, this.user_id);
|
||||||
|
|
||||||
debug(`[${this.name}] Store`);
|
log.debug("monitor", `[${this.name}] Store`);
|
||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
|
|
||||||
debug(`[${this.name}] prometheus.update`);
|
log.debug("monitor", `[${this.name}] prometheus.update`);
|
||||||
prometheus.update(bean, tlsInfo);
|
prometheus.update(bean, tlsInfo);
|
||||||
|
|
||||||
previousBeat = bean;
|
previousBeat = bean;
|
||||||
|
|
||||||
if (! this.isStop) {
|
if (! this.isStop) {
|
||||||
debug(`[${this.name}] SetTimeout for next check.`);
|
log.debug("monitor", `[${this.name}] SetTimeout for next check.`);
|
||||||
this.heartbeatInterval = setTimeout(safeBeat, beatInterval * 1000);
|
this.heartbeatInterval = setTimeout(safeBeat, beatInterval * 1000);
|
||||||
} else {
|
} else {
|
||||||
console.log(`[${this.name}] isStop = true, no next check.`);
|
log.info("monitor", `[${this.name}] isStop = true, no next check.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -483,10 +503,10 @@ class Monitor extends BeanModel {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.trace(e);
|
console.trace(e);
|
||||||
errorLog(e, false);
|
errorLog(e, false);
|
||||||
console.error("Please report to https://github.com/louislam/uptime-kuma/issues");
|
log.error("monitor", "Please report to https://github.com/louislam/uptime-kuma/issues");
|
||||||
|
|
||||||
if (! this.isStop) {
|
if (! this.isStop) {
|
||||||
console.log("Try to restart the monitor");
|
log.info("monitor", "Try to restart the monitor");
|
||||||
this.heartbeatInterval = setTimeout(safeBeat, this.interval * 1000);
|
this.heartbeatInterval = setTimeout(safeBeat, this.interval * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -533,41 +553,41 @@ class Monitor extends BeanModel {
|
|||||||
* @returns {Promise<object>}
|
* @returns {Promise<object>}
|
||||||
*/
|
*/
|
||||||
async updateTlsInfo(checkCertificateResult) {
|
async updateTlsInfo(checkCertificateResult) {
|
||||||
let tls_info_bean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
let tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
||||||
this.id,
|
this.id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (tls_info_bean == null) {
|
if (tlsInfoBean == null) {
|
||||||
tls_info_bean = R.dispense("monitor_tls_info");
|
tlsInfoBean = R.dispense("monitor_tls_info");
|
||||||
tls_info_bean.monitor_id = this.id;
|
tlsInfoBean.monitor_id = this.id;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Clear sent history if the cert changed.
|
// Clear sent history if the cert changed.
|
||||||
try {
|
try {
|
||||||
let oldCertInfo = JSON.parse(tls_info_bean.info_json);
|
let oldCertInfo = JSON.parse(tlsInfoBean.info_json);
|
||||||
|
|
||||||
let isValidObjects = oldCertInfo && oldCertInfo.certInfo && checkCertificateResult && checkCertificateResult.certInfo;
|
let isValidObjects = oldCertInfo && oldCertInfo.certInfo && checkCertificateResult && checkCertificateResult.certInfo;
|
||||||
|
|
||||||
if (isValidObjects) {
|
if (isValidObjects) {
|
||||||
if (oldCertInfo.certInfo.fingerprint256 !== checkCertificateResult.certInfo.fingerprint256) {
|
if (oldCertInfo.certInfo.fingerprint256 !== checkCertificateResult.certInfo.fingerprint256) {
|
||||||
debug("Resetting sent_history");
|
log.debug("monitor", "Resetting sent_history");
|
||||||
await R.exec("DELETE FROM notification_sent_history WHERE type = 'certificate' AND monitor_id = ?", [
|
await R.exec("DELETE FROM notification_sent_history WHERE type = 'certificate' AND monitor_id = ?", [
|
||||||
this.id
|
this.id
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
debug("No need to reset sent_history");
|
log.debug("monitor", "No need to reset sent_history");
|
||||||
debug(oldCertInfo.certInfo.fingerprint256);
|
log.debug("monitor", oldCertInfo.certInfo.fingerprint256);
|
||||||
debug(checkCertificateResult.certInfo.fingerprint256);
|
log.debug("monitor", checkCertificateResult.certInfo.fingerprint256);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug("Not valid object");
|
log.debug("monitor", "Not valid object");
|
||||||
}
|
}
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tls_info_bean.info_json = JSON.stringify(checkCertificateResult);
|
tlsInfoBean.info_json = JSON.stringify(checkCertificateResult);
|
||||||
await R.store(tls_info_bean);
|
await R.store(tlsInfoBean);
|
||||||
|
|
||||||
return checkCertificateResult;
|
return checkCertificateResult;
|
||||||
}
|
}
|
||||||
@@ -581,7 +601,7 @@ class Monitor extends BeanModel {
|
|||||||
await Monitor.sendUptime(24 * 30, io, monitorID, userID);
|
await Monitor.sendUptime(24 * 30, io, monitorID, userID);
|
||||||
await Monitor.sendCertInfo(io, monitorID, userID);
|
await Monitor.sendCertInfo(io, monitorID, userID);
|
||||||
} else {
|
} else {
|
||||||
debug("No clients in the room, no need to send stats");
|
log.debug("monitor", "No clients in the room, no need to send stats");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,11 +628,11 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async sendCertInfo(io, monitorID, userID) {
|
static async sendCertInfo(io, monitorID, userID) {
|
||||||
let tls_info = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
let tlsInfo = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
||||||
monitorID,
|
monitorID,
|
||||||
]);
|
]);
|
||||||
if (tls_info != null) {
|
if (tlsInfo != null) {
|
||||||
io.to(userID).emit("certInfo", monitorID, tls_info.info_json);
|
io.to(userID).emit("certInfo", monitorID, tlsInfo.info_json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,7 +694,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;
|
||||||
@@ -726,10 +746,10 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
for (let notification of notificationList) {
|
for (let notification of notificationList) {
|
||||||
try {
|
try {
|
||||||
await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(), bean.toJSON());
|
await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), bean.toJSON());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Cannot send notification to " + notification.name);
|
log.error("monitor", "Cannot send notification to " + notification.name);
|
||||||
console.log(e);
|
log.error("monitor", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -746,7 +766,7 @@ class Monitor extends BeanModel {
|
|||||||
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);
|
||||||
|
|
||||||
debug("call sendCertNotificationByTargetDays");
|
log.debug("monitor", "call sendCertNotificationByTargetDays");
|
||||||
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 21, notificationList);
|
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 21, notificationList);
|
||||||
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 14, notificationList);
|
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 14, notificationList);
|
||||||
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 7, notificationList);
|
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 7, notificationList);
|
||||||
@@ -756,7 +776,7 @@ class Monitor extends BeanModel {
|
|||||||
async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {
|
async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {
|
||||||
|
|
||||||
if (daysRemaining > targetDays) {
|
if (daysRemaining > targetDays) {
|
||||||
debug(`No need to send cert notification. ${daysRemaining} > ${targetDays}`);
|
log.debug("monitor", `No need to send cert notification. ${daysRemaining} > ${targetDays}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,21 +790,21 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
// Sent already, no need to send again
|
// Sent already, no need to send again
|
||||||
if (row) {
|
if (row) {
|
||||||
debug("Sent already, no need to send again");
|
log.debug("monitor", "Sent already, no need to send again");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sent = false;
|
let sent = false;
|
||||||
debug("Send certificate notification");
|
log.debug("monitor", "Send certificate notification");
|
||||||
|
|
||||||
for (let notification of notificationList) {
|
for (let notification of notificationList) {
|
||||||
try {
|
try {
|
||||||
debug("Sending to " + notification.name);
|
log.debug("monitor", "Sending to " + notification.name);
|
||||||
await Notification.send(JSON.parse(notification.config), `[${this.name}][${this.url}] Certificate will be expired in ${daysRemaining} days`);
|
await Notification.send(JSON.parse(notification.config), `[${this.name}][${this.url}] Certificate will be expired in ${daysRemaining} days`);
|
||||||
sent = true;
|
sent = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Cannot send cert notification to " + notification.name);
|
log.error("monitor", "Cannot send cert notification to " + notification.name);
|
||||||
console.error(e);
|
log.error("monitor", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,7 +816,7 @@ class Monitor extends BeanModel {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug("No notification, no need to send cert notification");
|
log.debug("monitor", "No notification, no need to send cert notification");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -92,6 +92,9 @@ class StatusPage extends BeanModel {
|
|||||||
published: !!this.published,
|
published: !!this.published,
|
||||||
showTags: !!this.show_tags,
|
showTags: !!this.show_tags,
|
||||||
domainNameList: this.getDomainNameList(),
|
domainNameList: this.getDomainNameList(),
|
||||||
|
customCSS: this.custom_css,
|
||||||
|
footerText: this.footer_text,
|
||||||
|
showPoweredBy: !!this.show_powered_by,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +107,9 @@ class StatusPage extends BeanModel {
|
|||||||
theme: this.theme,
|
theme: this.theme,
|
||||||
published: !!this.published,
|
published: !!this.published,
|
||||||
showTags: !!this.show_tags,
|
showTags: !!this.show_tags,
|
||||||
|
customCSS: this.custom_css,
|
||||||
|
footerText: this.footer_text,
|
||||||
|
showPoweredBy: !!this.show_powered_by,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,17 +5,29 @@ const { R } = require("redbean-node");
|
|||||||
class User extends BeanModel {
|
class User extends BeanModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct execute, no need R.store()
|
*
|
||||||
|
* Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
|
||||||
|
* @param userID
|
||||||
|
* @param newPassword
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async resetPassword(userID, newPassword) {
|
||||||
|
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
||||||
|
passwordHash.generate(newPassword),
|
||||||
|
userID
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
* @param newPassword
|
* @param newPassword
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async resetPassword(newPassword) {
|
async resetPassword(newPassword) {
|
||||||
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
await User.resetPassword(this.id, newPassword);
|
||||||
passwordHash.generate(newPassword),
|
|
||||||
this.id
|
|
||||||
]);
|
|
||||||
this.password = newPassword;
|
this.password = newPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = User;
|
module.exports = User;
|
||||||
|
@@ -68,6 +68,15 @@ function ApiCache() {
|
|||||||
instances.push(this);
|
instances.push(this);
|
||||||
this.id = instances.length;
|
this.id = instances.length;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a message to the console if the `DEBUG` environment variable is set.
|
||||||
|
* @param {string} a - The first argument to log.
|
||||||
|
* @param {string} b - The second argument to log.
|
||||||
|
* @param {string} c - The third argument to log.
|
||||||
|
* @param {string} d - The fourth argument to log, and so on... (optional)
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function debug(a, b, c, d) {
|
function debug(a, b, c, d) {
|
||||||
let arr = ["\x1b[36m[apicache]\x1b[0m", a, b, c, d].filter(function (arg) {
|
let arr = ["\x1b[36m[apicache]\x1b[0m", a, b, c, d].filter(function (arg) {
|
||||||
return arg !== undefined;
|
return arg !== undefined;
|
||||||
@@ -77,6 +86,13 @@ function ApiCache() {
|
|||||||
return (globalOptions.debug || debugEnv) && console.log.apply(null, arr);
|
return (globalOptions.debug || debugEnv) && console.log.apply(null, arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given request and response should be logged.
|
||||||
|
* @param {Object} request The HTTP request object.
|
||||||
|
* @param {Object} response The HTTP response object.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function shouldCacheResponse(request, response, toggle) {
|
function shouldCacheResponse(request, response, toggle) {
|
||||||
let opt = globalOptions;
|
let opt = globalOptions;
|
||||||
let codes = opt.statusCodes;
|
let codes = opt.statusCodes;
|
||||||
@@ -99,6 +115,12 @@ function ApiCache() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a key to the index.
|
||||||
|
* @param {string} key The key to add.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function addIndexEntries(key, req) {
|
function addIndexEntries(key, req) {
|
||||||
let groupName = req.apicacheGroup;
|
let groupName = req.apicacheGroup;
|
||||||
|
|
||||||
@@ -111,6 +133,13 @@ function ApiCache() {
|
|||||||
index.all.unshift(key);
|
index.all.unshift(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new object containing only the whitelisted headers.
|
||||||
|
* @param {Object} headers The original object of header names and values.
|
||||||
|
* @param {Array.<string>} globalOptions.headerWhitelist An array of strings representing the whitelisted header names to keep in the output object.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function filterBlacklistedHeaders(headers) {
|
function filterBlacklistedHeaders(headers) {
|
||||||
return Object.keys(headers)
|
return Object.keys(headers)
|
||||||
.filter(function (key) {
|
.filter(function (key) {
|
||||||
@@ -122,6 +151,12 @@ function ApiCache() {
|
|||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} headers The response headers to filter.
|
||||||
|
* @returns {Object} A new object containing only the whitelisted response headers.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function createCacheObject(status, headers, data, encoding) {
|
function createCacheObject(status, headers, data, encoding) {
|
||||||
return {
|
return {
|
||||||
status: status,
|
status: status,
|
||||||
@@ -132,6 +167,14 @@ function ApiCache() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a cache value for the given key.
|
||||||
|
* @param {string} key The cache key to set.
|
||||||
|
* @param {*} value The cache value to set.
|
||||||
|
* @param {number} duration How long in milliseconds the cached response should be valid for (defaults to 1 hour).
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function cacheResponse(key, value, duration) {
|
function cacheResponse(key, value, duration) {
|
||||||
let redis = globalOptions.redisClient;
|
let redis = globalOptions.redisClient;
|
||||||
let expireCallback = globalOptions.events.expire;
|
let expireCallback = globalOptions.events.expire;
|
||||||
@@ -154,6 +197,12 @@ function ApiCache() {
|
|||||||
}, Math.min(duration, 2147483647));
|
}, Math.min(duration, 2147483647));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends content to the response.
|
||||||
|
* @param {string|Buffer} content The content to append.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function accumulateContent(res, content) {
|
function accumulateContent(res, content) {
|
||||||
if (content) {
|
if (content) {
|
||||||
if (typeof content == "string") {
|
if (typeof content == "string") {
|
||||||
@@ -179,6 +228,13 @@ function ApiCache() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monkeypatches the response object to add cache control headers and create a cache object.
|
||||||
|
* @param {Object} req - The request object.
|
||||||
|
* @param {Object} res - The response object.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
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
|
||||||
res._apicache = {
|
res._apicache = {
|
||||||
@@ -245,6 +301,13 @@ function ApiCache() {
|
|||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Request} request
|
||||||
|
* @param {Response} response
|
||||||
|
* @returns {boolean|undefined} true if the request should be cached, false otherwise. If undefined, defaults to true.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
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)) {
|
||||||
return next();
|
return next();
|
||||||
@@ -365,6 +428,13 @@ function ApiCache() {
|
|||||||
return this.getIndex();
|
return this.getIndex();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a duration string to an integer number of milliseconds.
|
||||||
|
* @param {string} duration - The string to convert.
|
||||||
|
* @returns {number} The converted value in milliseconds, or the defaultDuration if it can't be parsed.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function parseDuration(duration, defaultDuration) {
|
function parseDuration(duration, defaultDuration) {
|
||||||
if (typeof duration === "number") {
|
if (typeof duration === "number") {
|
||||||
return duration;
|
return duration;
|
||||||
|
@@ -40,17 +40,17 @@ class Alerta extends NotificationProvider {
|
|||||||
await axios.post(alertaUrl, postData, config);
|
await axios.post(alertaUrl, postData, config);
|
||||||
} else {
|
} else {
|
||||||
let datadup = Object.assign( {
|
let datadup = Object.assign( {
|
||||||
correlate: ["service_up", "service_down"],
|
correlate: [ "service_up", "service_down" ],
|
||||||
event: monitorJSON["type"],
|
event: monitorJSON["type"],
|
||||||
group: "uptimekuma-" + monitorJSON["type"],
|
group: "uptimekuma-" + monitorJSON["type"],
|
||||||
resource: monitorJSON["name"],
|
resource: monitorJSON["name"],
|
||||||
}, data );
|
}, data );
|
||||||
|
|
||||||
if (heartbeatJSON["status"] == DOWN) {
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
datadup.severity = notification.alertaAlertState; // critical
|
datadup.severity = notification.alertaAlertState; // critical
|
||||||
datadup.text = "Service " + monitorJSON["type"] + " is down.";
|
datadup.text = "Service " + monitorJSON["type"] + " is down.";
|
||||||
await axios.post(alertaUrl, datadup, config);
|
await axios.post(alertaUrl, datadup, config);
|
||||||
} else if (heartbeatJSON["status"] == UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
datadup.severity = notification.alertaRecoverState; // cleaned
|
datadup.severity = notification.alertaRecoverState; // cleaned
|
||||||
datadup.text = "Service " + monitorJSON["type"] + " is up.";
|
datadup.text = "Service " + monitorJSON["type"] + " is up.";
|
||||||
await axios.post(alertaUrl, datadup, config);
|
await axios.post(alertaUrl, datadup, config);
|
||||||
|
@@ -64,7 +64,7 @@ class AliyunSMS extends NotificationProvider {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = await axios(config);
|
let result = await axios(config);
|
||||||
if (result.data.Message == "OK") {
|
if (result.data.Message === "OK") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const child_process = require("child_process");
|
const childProcess = require("child_process");
|
||||||
|
|
||||||
class Apprise extends NotificationProvider {
|
class Apprise extends NotificationProvider {
|
||||||
|
|
||||||
name = "apprise";
|
name = "apprise";
|
||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
let s = child_process.spawnSync("apprise", [ "-vv", "-b", msg, notification.appriseURL])
|
let s = childProcess.spawnSync("apprise", [ "-vv", "-b", msg, notification.appriseURL ]);
|
||||||
|
|
||||||
let output = (s.stdout) ? s.stdout.toString() : "ERROR: maybe apprise not found";
|
let output = (s.stdout) ? s.stdout.toString() : "ERROR: maybe apprise not found";
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ class Apprise extends NotificationProvider {
|
|||||||
return "Sent Successfully";
|
return "Sent Successfully";
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(output)
|
throw new Error(output);
|
||||||
} else {
|
} else {
|
||||||
return "No output from apprise";
|
return "No output from apprise";
|
||||||
}
|
}
|
||||||
|
@@ -21,31 +21,26 @@ class Bark extends NotificationProvider {
|
|||||||
name = "Bark";
|
name = "Bark";
|
||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
try {
|
let barkEndpoint = notification.barkEndpoint;
|
||||||
var barkEndpoint = notification.barkEndpoint;
|
|
||||||
|
|
||||||
// check if the endpoint has a "/" suffix, if so, delete it first
|
// check if the endpoint has a "/" suffix, if so, delete it first
|
||||||
if (barkEndpoint.endsWith("/")) {
|
if (barkEndpoint.endsWith("/")) {
|
||||||
barkEndpoint = barkEndpoint.substring(0, barkEndpoint.length - 1);
|
barkEndpoint = barkEndpoint.substring(0, barkEndpoint.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == UP) {
|
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||||
let title = "UptimeKuma Monitor Up";
|
let title = "UptimeKuma Monitor Up";
|
||||||
return await this.postNotification(title, msg, barkEndpoint);
|
return await this.postNotification(title, msg, barkEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == DOWN) {
|
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
||||||
let title = "UptimeKuma Monitor Down";
|
let title = "UptimeKuma Monitor Down";
|
||||||
return await this.postNotification(title, msg, barkEndpoint);
|
return await this.postNotification(title, msg, barkEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
let title = "UptimeKuma Message";
|
let title = "UptimeKuma Message";
|
||||||
return await this.postNotification(title, msg, barkEndpoint);
|
return await this.postNotification(title, msg, barkEndpoint);
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@ class ClickSendSMS extends NotificationProvider {
|
|||||||
let config = {
|
let config = {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": "Basic " + Buffer.from(notification.clicksendsmsLogin + ":" + notification.clicksendsmsPassword).toString('base64'),
|
"Authorization": "Basic " + Buffer.from(notification.clicksendsmsLogin + ":" + notification.clicksendsmsPassword).toString("base64"),
|
||||||
"Accept": "text/json",
|
"Accept": "text/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -50,7 +50,7 @@ class DingDing extends NotificationProvider {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = await axios(config);
|
let result = await axios(config);
|
||||||
if (result.data.errmsg == "ok") {
|
if (result.data.errmsg === "ok") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -17,8 +17,8 @@ class Discord extends NotificationProvider {
|
|||||||
let discordtestdata = {
|
let discordtestdata = {
|
||||||
username: discordDisplayName,
|
username: discordDisplayName,
|
||||||
content: msg,
|
content: msg,
|
||||||
}
|
};
|
||||||
await axios.post(notification.discordWebhookUrl, discordtestdata)
|
await axios.post(notification.discordWebhookUrl, discordtestdata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ class Discord extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
||||||
if (heartbeatJSON["status"] == DOWN) {
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
let discorddowndata = {
|
let discorddowndata = {
|
||||||
username: discordDisplayName,
|
username: discordDisplayName,
|
||||||
embeds: [{
|
embeds: [{
|
||||||
@@ -61,16 +61,16 @@ class Discord extends NotificationProvider {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
}
|
};
|
||||||
|
|
||||||
if (notification.discordPrefixMessage) {
|
if (notification.discordPrefixMessage) {
|
||||||
discorddowndata.content = notification.discordPrefixMessage;
|
discorddowndata.content = notification.discordPrefixMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
await axios.post(notification.discordWebhookUrl, discorddowndata)
|
await axios.post(notification.discordWebhookUrl, discorddowndata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
|
||||||
} else if (heartbeatJSON["status"] == UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
let discordupdata = {
|
let discordupdata = {
|
||||||
username: discordDisplayName,
|
username: discordDisplayName,
|
||||||
embeds: [{
|
embeds: [{
|
||||||
@@ -96,17 +96,17 @@ class Discord extends NotificationProvider {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
}
|
};
|
||||||
|
|
||||||
if (notification.discordPrefixMessage) {
|
if (notification.discordPrefixMessage) {
|
||||||
discordupdata.content = notification.discordPrefixMessage;
|
discordupdata.content = notification.discordPrefixMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
await axios.post(notification.discordWebhookUrl, discordupdata)
|
await axios.post(notification.discordWebhookUrl, discordupdata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ class Feishu extends NotificationProvider {
|
|||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heartbeatJSON["status"] == DOWN) {
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
let downdata = {
|
let downdata = {
|
||||||
msg_type: "post",
|
msg_type: "post",
|
||||||
content: {
|
content: {
|
||||||
@@ -48,7 +48,7 @@ class Feishu extends NotificationProvider {
|
|||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heartbeatJSON["status"] == UP) {
|
if (heartbeatJSON["status"] === UP) {
|
||||||
let updata = {
|
let updata = {
|
||||||
msg_type: "post",
|
msg_type: "post",
|
||||||
content: {
|
content: {
|
||||||
|
@@ -13,11 +13,11 @@ class GoogleChat extends NotificationProvider {
|
|||||||
try {
|
try {
|
||||||
// Google Chat message formatting: https://developers.google.com/chat/api/guides/message-formats/basic
|
// Google Chat message formatting: https://developers.google.com/chat/api/guides/message-formats/basic
|
||||||
|
|
||||||
let textMsg = ''
|
let textMsg = "";
|
||||||
if (heartbeatJSON && heartbeatJSON.status === UP) {
|
if (heartbeatJSON && heartbeatJSON.status === UP) {
|
||||||
textMsg = `✅ Application is back online\n`;
|
textMsg = "✅ Application is back online\n";
|
||||||
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
|
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
|
||||||
textMsg = `🔴 Application went down\n`;
|
textMsg = "🔴 Application went down\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitorJSON && monitorJSON.name) {
|
if (monitorJSON && monitorJSON.name) {
|
||||||
|
@@ -18,7 +18,7 @@ class Gorush extends NotificationProvider {
|
|||||||
let data = {
|
let data = {
|
||||||
"notifications": [
|
"notifications": [
|
||||||
{
|
{
|
||||||
"tokens": [notification.gorushDeviceToken],
|
"tokens": [ notification.gorushDeviceToken ],
|
||||||
"platform": platformMapping[notification.gorushPlatform],
|
"platform": platformMapping[notification.gorushPlatform],
|
||||||
"message": msg,
|
"message": msg,
|
||||||
// Optional
|
// Optional
|
||||||
|
@@ -15,7 +15,7 @@ class Gotify extends NotificationProvider {
|
|||||||
"message": msg,
|
"message": msg,
|
||||||
"priority": notification.gotifyPriority || 8,
|
"priority": notification.gotifyPriority || 8,
|
||||||
"title": "Uptime-Kuma",
|
"title": "Uptime-Kuma",
|
||||||
})
|
});
|
||||||
|
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
|
||||||
|
@@ -25,9 +25,9 @@ class Line extends NotificationProvider {
|
|||||||
"text": "Test Successful!"
|
"text": "Test Successful!"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
await axios.post(lineAPIUrl, testMessage, config)
|
await axios.post(lineAPIUrl, testMessage, config);
|
||||||
} else if (heartbeatJSON["status"] == DOWN) {
|
} else if (heartbeatJSON["status"] === DOWN) {
|
||||||
let downMessage = {
|
let downMessage = {
|
||||||
"to": notification.lineUserID,
|
"to": notification.lineUserID,
|
||||||
"messages": [
|
"messages": [
|
||||||
@@ -36,9 +36,9 @@ class Line extends NotificationProvider {
|
|||||||
"text": "UptimeKuma Alert: [🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
"text": "UptimeKuma Alert: [🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
await axios.post(lineAPIUrl, downMessage, config)
|
await axios.post(lineAPIUrl, downMessage, config);
|
||||||
} else if (heartbeatJSON["status"] == UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
let upMessage = {
|
let upMessage = {
|
||||||
"to": notification.lineUserID,
|
"to": notification.lineUserID,
|
||||||
"messages": [
|
"messages": [
|
||||||
@@ -47,12 +47,12 @@ class Line extends NotificationProvider {
|
|||||||
"text": "UptimeKuma Alert: [✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
"text": "UptimeKuma Alert: [✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
await axios.post(lineAPIUrl, upMessage, config)
|
await axios.post(lineAPIUrl, upMessage, config);
|
||||||
}
|
}
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,38 +8,38 @@ class LunaSea extends NotificationProvider {
|
|||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
let okMsg = "Sent Successfully.";
|
let okMsg = "Sent Successfully.";
|
||||||
let lunaseadevice = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice
|
let lunaseadevice = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (heartbeatJSON == null) {
|
if (heartbeatJSON == null) {
|
||||||
let testdata = {
|
let testdata = {
|
||||||
"title": "Uptime Kuma Alert",
|
"title": "Uptime Kuma Alert",
|
||||||
"body": "Testing Successful.",
|
"body": "Testing Successful.",
|
||||||
}
|
};
|
||||||
await axios.post(lunaseadevice, testdata)
|
await axios.post(lunaseadevice, testdata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heartbeatJSON["status"] == DOWN) {
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
let downdata = {
|
let downdata = {
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
||||||
}
|
};
|
||||||
await axios.post(lunaseadevice, downdata)
|
await axios.post(lunaseadevice, downdata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heartbeatJSON["status"] == UP) {
|
if (heartbeatJSON["status"] === UP) {
|
||||||
let updata = {
|
let updata = {
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
||||||
}
|
};
|
||||||
await axios.post(lunaseadevice, updata)
|
await axios.post(lunaseadevice, updata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const Crypto = require("crypto");
|
const Crypto = require("crypto");
|
||||||
const { debug } = require("../../src/util");
|
const { log } = require("../../src/util");
|
||||||
|
|
||||||
class Matrix extends NotificationProvider {
|
class Matrix extends NotificationProvider {
|
||||||
name = "matrix";
|
name = "matrix";
|
||||||
@@ -17,11 +17,11 @@ class Matrix extends NotificationProvider {
|
|||||||
.slice(0, size)
|
.slice(0, size)
|
||||||
);
|
);
|
||||||
|
|
||||||
debug("Random String: " + randomString);
|
log.debug("notification", "Random String: " + randomString);
|
||||||
|
|
||||||
const roomId = encodeURIComponent(notification.internalRoomId);
|
const roomId = encodeURIComponent(notification.internalRoomId);
|
||||||
|
|
||||||
debug("Matrix Room ID: " + roomId);
|
log.debug("notification", "Matrix Room ID: " + roomId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let config = {
|
let config = {
|
||||||
|
@@ -29,7 +29,7 @@ class Mattermost extends NotificationProvider {
|
|||||||
const mattermostIconEmoji = notification.mattermosticonemo;
|
const mattermostIconEmoji = notification.mattermosticonemo;
|
||||||
const mattermostIconUrl = notification.mattermosticonurl;
|
const mattermostIconUrl = notification.mattermosticonurl;
|
||||||
|
|
||||||
if (heartbeatJSON["status"] == DOWN) {
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
let mattermostdowndata = {
|
let mattermostdowndata = {
|
||||||
username: mattermostUserName,
|
username: mattermostUserName,
|
||||||
text: "Uptime Kuma Alert",
|
text: "Uptime Kuma Alert",
|
||||||
@@ -73,7 +73,7 @@ class Mattermost extends NotificationProvider {
|
|||||||
mattermostdowndata
|
mattermostdowndata
|
||||||
);
|
);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} else if (heartbeatJSON["status"] == UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
let mattermostupdata = {
|
let mattermostupdata = {
|
||||||
username: mattermostUserName,
|
username: mattermostUserName,
|
||||||
text: "Uptime Kuma Alert",
|
text: "Uptime Kuma Alert",
|
||||||
|
@@ -25,11 +25,11 @@ class NotificationProvider {
|
|||||||
if (typeof error.response.data === "string") {
|
if (typeof error.response.data === "string") {
|
||||||
msg += error.response.data;
|
msg += error.response.data;
|
||||||
} else {
|
} else {
|
||||||
msg += JSON.stringify(error.response.data)
|
msg += JSON.stringify(error.response.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(msg)
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ class Octopush extends NotificationProvider {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Default - V2
|
// Default - V2
|
||||||
if (notification.octopushVersion == 2 || !notification.octopushVersion) {
|
if (notification.octopushVersion === 2 || !notification.octopushVersion) {
|
||||||
let config = {
|
let config = {
|
||||||
headers: {
|
headers: {
|
||||||
"api-key": notification.octopushAPIKey,
|
"api-key": notification.octopushAPIKey,
|
||||||
@@ -30,14 +30,14 @@ class Octopush extends NotificationProvider {
|
|||||||
"purpose": "alert",
|
"purpose": "alert",
|
||||||
"sender": notification.octopushSenderName
|
"sender": notification.octopushSenderName
|
||||||
};
|
};
|
||||||
await axios.post("https://api.octopush.com/v1/public/sms-campaign/send", data, config)
|
await axios.post("https://api.octopush.com/v1/public/sms-campaign/send", data, config);
|
||||||
} else if (notification.octopushVersion == 1) {
|
} else if (notification.octopushVersion === 1) {
|
||||||
let data = {
|
let data = {
|
||||||
"user_login": notification.octopushDMLogin,
|
"user_login": notification.octopushDMLogin,
|
||||||
"api_key": notification.octopushDMAPIKey,
|
"api_key": notification.octopushDMAPIKey,
|
||||||
"sms_recipients": notification.octopushDMPhoneNumber,
|
"sms_recipients": notification.octopushDMPhoneNumber,
|
||||||
"sms_sender": notification.octopushDMSenderName,
|
"sms_sender": notification.octopushDMSenderName,
|
||||||
"sms_type": (notification.octopushDMSMSType == "sms_premium") ? "FR" : "XXX",
|
"sms_type": (notification.octopushDMSMSType === "sms_premium") ? "FR" : "XXX",
|
||||||
"transactional": "1",
|
"transactional": "1",
|
||||||
//octopush not supporting non ascii char
|
//octopush not supporting non ascii char
|
||||||
"sms_text": msg.replace(/[^\x00-\x7F]/g, ""),
|
"sms_text": msg.replace(/[^\x00-\x7F]/g, ""),
|
||||||
@@ -49,7 +49,7 @@ class Octopush extends NotificationProvider {
|
|||||||
},
|
},
|
||||||
params: data
|
params: data
|
||||||
};
|
};
|
||||||
await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config)
|
await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unknown Octopush version!");
|
throw new Error("Unknown Octopush version!");
|
||||||
}
|
}
|
||||||
|
45
server/notification-providers/onebot.js
Normal file
45
server/notification-providers/onebot.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class OneBot extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "OneBot";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
let httpAddr = notification.httpAddr;
|
||||||
|
if (!httpAddr.startsWith("http")) {
|
||||||
|
httpAddr = "http://" + httpAddr;
|
||||||
|
}
|
||||||
|
if (!httpAddr.endsWith("/")) {
|
||||||
|
httpAddr += "/";
|
||||||
|
}
|
||||||
|
let onebotAPIUrl = httpAddr + "send_msg";
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": "Bearer " + notification.accessToken,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let pushText = "UptimeKuma Alert: " + msg;
|
||||||
|
let data = {
|
||||||
|
"auto_escape": true,
|
||||||
|
"message": pushText,
|
||||||
|
};
|
||||||
|
if (notification.msgType === "group") {
|
||||||
|
data["message_type"] = "group";
|
||||||
|
data["group_id"] = notification.recieverId;
|
||||||
|
} else {
|
||||||
|
data["message_type"] = "private";
|
||||||
|
data["user_id"] = notification.recieverId;
|
||||||
|
}
|
||||||
|
await axios.post(onebotAPIUrl, data, config);
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = OneBot;
|
@@ -12,7 +12,7 @@ class PromoSMS extends NotificationProvider {
|
|||||||
let config = {
|
let config = {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString('base64'),
|
"Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString("base64"),
|
||||||
"Accept": "text/json",
|
"Accept": "text/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -30,7 +30,7 @@ class PromoSMS extends NotificationProvider {
|
|||||||
let error = "Something gone wrong. Api returned " + resp.data.response.status + ".";
|
let error = "Something gone wrong. Api returned " + resp.data.response.status + ".";
|
||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
|
@@ -23,26 +23,26 @@ class Pushbullet extends NotificationProvider {
|
|||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "Uptime Kuma Alert",
|
"title": "Uptime Kuma Alert",
|
||||||
"body": "Testing Successful.",
|
"body": "Testing Successful.",
|
||||||
}
|
};
|
||||||
await axios.post(pushbulletUrl, testdata, config)
|
await axios.post(pushbulletUrl, testdata, config);
|
||||||
} else if (heartbeatJSON["status"] == DOWN) {
|
} else if (heartbeatJSON["status"] === DOWN) {
|
||||||
let downdata = {
|
let downdata = {
|
||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
||||||
}
|
};
|
||||||
await axios.post(pushbulletUrl, downdata, config)
|
await axios.post(pushbulletUrl, downdata, config);
|
||||||
} else if (heartbeatJSON["status"] == UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
let updata = {
|
let updata = {
|
||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
||||||
}
|
};
|
||||||
await axios.post(pushbulletUrl, updata, config)
|
await axios.post(pushbulletUrl, updata, config);
|
||||||
}
|
}
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
server/notification-providers/pushdeer.js
Normal file
52
server/notification-providers/pushdeer.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { DOWN, UP } = require("../../src/util");
|
||||||
|
|
||||||
|
class PushDeer extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "PushDeer";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
let pushdeerlink = "https://api2.pushdeer.com/message/push";
|
||||||
|
|
||||||
|
let valid = msg != null && monitorJSON != null && heartbeatJSON != null;
|
||||||
|
|
||||||
|
let title;
|
||||||
|
if (valid && heartbeatJSON.status === UP) {
|
||||||
|
title = "## Uptime Kuma: " + monitorJSON.name + " up";
|
||||||
|
} else if (valid && heartbeatJSON.status === DOWN) {
|
||||||
|
title = "## Uptime Kuma: " + monitorJSON.name + " down";
|
||||||
|
} else {
|
||||||
|
title = "## Uptime Kuma Message";
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
"pushkey": notification.pushdeerKey,
|
||||||
|
"text": title,
|
||||||
|
"desp": msg.replace(/\n/g, "\n\n"),
|
||||||
|
"type": "markdown",
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
let res = await axios.post(pushdeerlink, data);
|
||||||
|
|
||||||
|
if ("error" in res.data) {
|
||||||
|
let error = res.data.error;
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
if (res.data.content.result.length === 0) {
|
||||||
|
let error = "Invalid PushDeer key";
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
} else if (JSON.parse(res.data.content.result[0]).success !== "ok") {
|
||||||
|
let error = "Unknown error";
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = PushDeer;
|
@@ -19,10 +19,10 @@ class Pushy extends NotificationProvider {
|
|||||||
"badge": 1,
|
"badge": 1,
|
||||||
"sound": "ping.aiff"
|
"sound": "ping.aiff"
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ const NotificationProvider = require("./notification-provider");
|
|||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const Slack = require("./slack");
|
const Slack = require("./slack");
|
||||||
const { setting } = require("../util-server");
|
const { setting } = require("../util-server");
|
||||||
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
|
const { getMonitorRelativeURL, DOWN } = require("../../src/util");
|
||||||
|
|
||||||
class RocketChat extends NotificationProvider {
|
class RocketChat extends NotificationProvider {
|
||||||
|
|
||||||
|
@@ -16,10 +16,10 @@ class Signal extends NotificationProvider {
|
|||||||
};
|
};
|
||||||
let config = {};
|
let config = {};
|
||||||
|
|
||||||
await axios.post(notification.signalURL, data, config)
|
await axios.post(notification.signalURL, data, config);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
const nodemailer = require("nodemailer");
|
const nodemailer = require("nodemailer");
|
||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const { DOWN, UP } = require("../../src/util");
|
const { DOWN } = require("../../src/util");
|
||||||
|
|
||||||
class SMTP extends NotificationProvider {
|
class SMTP extends NotificationProvider {
|
||||||
|
|
||||||
|
@@ -12,10 +12,10 @@ class TechulusPush extends NotificationProvider {
|
|||||||
await axios.post(`https://push.techulus.com/api/v1/notify/${notification.pushAPIKey}`, {
|
await axios.post(`https://push.techulus.com/api/v1/notify/${notification.pushAPIKey}`, {
|
||||||
"title": "Uptime-Kuma",
|
"title": "Uptime-Kuma",
|
||||||
"body": msg,
|
"body": msg,
|
||||||
})
|
});
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,12 +14,12 @@ class Telegram extends NotificationProvider {
|
|||||||
chat_id: notification.telegramChatID,
|
chat_id: notification.telegramChatID,
|
||||||
text: msg,
|
text: msg,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let msg = (error.response.data.description) ? error.response.data.description : "Error without description"
|
let msg = (error.response.data.description) ? error.response.data.description : "Error without description";
|
||||||
throw new Error(msg)
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,17 +24,17 @@ class Webhook extends NotificationProvider {
|
|||||||
|
|
||||||
config = {
|
config = {
|
||||||
headers: finalData.getHeaders(),
|
headers: finalData.getHeaders(),
|
||||||
}
|
};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
finalData = data;
|
finalData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
await axios.post(notification.webhookURL, finalData, config)
|
await axios.post(notification.webhookURL, finalData, config);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,10 +26,10 @@ class WeCom extends NotificationProvider {
|
|||||||
|
|
||||||
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) {
|
||||||
title = "UptimeKuma Monitor Up";
|
title = "UptimeKuma Monitor Up";
|
||||||
}
|
}
|
||||||
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == DOWN) {
|
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
||||||
title = "UptimeKuma Monitor Down";
|
title = "UptimeKuma Monitor Down";
|
||||||
}
|
}
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
|
@@ -24,19 +24,22 @@ const Feishu = require("./notification-providers/feishu");
|
|||||||
const AliyunSms = require("./notification-providers/aliyun-sms");
|
const AliyunSms = require("./notification-providers/aliyun-sms");
|
||||||
const DingDing = require("./notification-providers/dingding");
|
const DingDing = require("./notification-providers/dingding");
|
||||||
const Bark = require("./notification-providers/bark");
|
const Bark = require("./notification-providers/bark");
|
||||||
|
const { log } = require("../src/util");
|
||||||
const SerwerSMS = require("./notification-providers/serwersms");
|
const SerwerSMS = require("./notification-providers/serwersms");
|
||||||
const Stackfield = require("./notification-providers/stackfield");
|
const Stackfield = require("./notification-providers/stackfield");
|
||||||
const WeCom = require("./notification-providers/wecom");
|
const WeCom = require("./notification-providers/wecom");
|
||||||
const GoogleChat = require("./notification-providers/google-chat");
|
const GoogleChat = require("./notification-providers/google-chat");
|
||||||
const Gorush = require("./notification-providers/gorush");
|
const Gorush = require("./notification-providers/gorush");
|
||||||
const Alerta = require("./notification-providers/alerta");
|
const Alerta = require("./notification-providers/alerta");
|
||||||
|
const OneBot = require("./notification-providers/onebot");
|
||||||
|
const PushDeer = require("./notification-providers/pushdeer");
|
||||||
|
|
||||||
class Notification {
|
class Notification {
|
||||||
|
|
||||||
providerList = {};
|
providerList = {};
|
||||||
|
|
||||||
static init() {
|
static init() {
|
||||||
console.log("Prepare Notification Providers");
|
log.info("notification", "Prepare Notification Providers");
|
||||||
|
|
||||||
this.providerList = {};
|
this.providerList = {};
|
||||||
|
|
||||||
@@ -72,6 +75,8 @@ class Notification {
|
|||||||
new GoogleChat(),
|
new GoogleChat(),
|
||||||
new Gorush(),
|
new Gorush(),
|
||||||
new Alerta(),
|
new Alerta(),
|
||||||
|
new OneBot(),
|
||||||
|
new PushDeer(),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let item of list) {
|
for (let item of list) {
|
||||||
@@ -104,27 +109,27 @@ class Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async save(notification, notificationID, userID) {
|
static async save(notification, notificationID, userID) {
|
||||||
let bean
|
let bean;
|
||||||
|
|
||||||
if (notificationID) {
|
if (notificationID) {
|
||||||
bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
||||||
notificationID,
|
notificationID,
|
||||||
userID,
|
userID,
|
||||||
])
|
]);
|
||||||
|
|
||||||
if (! bean) {
|
if (! bean) {
|
||||||
throw new Error("notification not found")
|
throw new Error("notification not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bean = R.dispense("notification")
|
bean = R.dispense("notification");
|
||||||
}
|
}
|
||||||
|
|
||||||
bean.name = notification.name;
|
bean.name = notification.name;
|
||||||
bean.user_id = userID;
|
bean.user_id = userID;
|
||||||
bean.config = JSON.stringify(notification);
|
bean.config = JSON.stringify(notification);
|
||||||
bean.is_default = notification.isDefault || false;
|
bean.is_default = notification.isDefault || false;
|
||||||
await R.store(bean)
|
await R.store(bean);
|
||||||
|
|
||||||
if (notification.applyExisting) {
|
if (notification.applyExisting) {
|
||||||
await applyNotificationEveryMonitor(bean.id, userID);
|
await applyNotificationEveryMonitor(bean.id, userID);
|
||||||
@@ -137,13 +142,13 @@ class Notification {
|
|||||||
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
||||||
notificationID,
|
notificationID,
|
||||||
userID,
|
userID,
|
||||||
])
|
]);
|
||||||
|
|
||||||
if (! bean) {
|
if (! bean) {
|
||||||
throw new Error("notification not found")
|
throw new Error("notification not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
await R.trash(bean)
|
await R.trash(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
static checkApprise() {
|
static checkApprise() {
|
||||||
@@ -154,6 +159,13 @@ class Notification {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new monitor to the database.
|
||||||
|
* @param {number} userID The ID of the user that owns this monitor.
|
||||||
|
* @param {string} name The name of this monitor.
|
||||||
|
*
|
||||||
|
* 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 = ?", [
|
||||||
userID
|
userID
|
||||||
@@ -163,17 +175,17 @@ async function applyNotificationEveryMonitor(notificationID, userID) {
|
|||||||
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
|
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
|
||||||
monitors[i].id,
|
monitors[i].id,
|
||||||
notificationID,
|
notificationID,
|
||||||
])
|
]);
|
||||||
|
|
||||||
if (! checkNotification) {
|
if (! checkNotification) {
|
||||||
let relation = R.dispense("monitor_notification");
|
let relation = R.dispense("monitor_notification");
|
||||||
relation.monitor_id = monitors[i].id;
|
relation.monitor_id = monitors[i].id;
|
||||||
relation.notification_id = notificationID;
|
relation.notification_id = notificationID;
|
||||||
await R.store(relation)
|
await R.store(relation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Notification,
|
Notification,
|
||||||
}
|
};
|
||||||
|
@@ -4,20 +4,20 @@ const saltRounds = 10;
|
|||||||
|
|
||||||
exports.generate = function (password) {
|
exports.generate = function (password) {
|
||||||
return bcrypt.hashSync(password, saltRounds);
|
return bcrypt.hashSync(password, saltRounds);
|
||||||
}
|
};
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bcrypt.compareSync(password, hash);
|
return bcrypt.compareSync(password, hash);
|
||||||
}
|
};
|
||||||
|
|
||||||
function isSHA1(hash) {
|
function isSHA1(hash) {
|
||||||
return (typeof hash === "string" && hash.startsWith("sha1"))
|
return (typeof hash === "string" && hash.startsWith("sha1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.needRehash = function (hash) {
|
exports.needRehash = function (hash) {
|
||||||
return isSHA1(hash);
|
return isSHA1(hash);
|
||||||
}
|
};
|
||||||
|
@@ -8,6 +8,13 @@ const util = require("./util-server");
|
|||||||
|
|
||||||
module.exports = Ping;
|
module.exports = Ping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} host - The host to ping
|
||||||
|
* @param {object} [options] - Options for 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) {
|
||||||
throw new Error("You must specify a host to ping!");
|
throw new Error("You must specify a host to ping!");
|
||||||
@@ -125,6 +132,11 @@ Ping.prototype.send = function (callback) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Function} callback
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
function onEnd() {
|
function onEnd() {
|
||||||
let stdout = this.stdout._stdout;
|
let stdout = this.stdout._stdout;
|
||||||
let stderr = this.stderr._stderr;
|
let stderr = this.stderr._stderr;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
const PrometheusClient = require("prom-client");
|
const PrometheusClient = require("prom-client");
|
||||||
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
const commonLabels = [
|
const commonLabels = [
|
||||||
"monitor_name",
|
"monitor_name",
|
||||||
@@ -8,24 +9,24 @@ const commonLabels = [
|
|||||||
"monitor_port",
|
"monitor_port",
|
||||||
];
|
];
|
||||||
|
|
||||||
const monitor_cert_days_remaining = new PrometheusClient.Gauge({
|
const monitorCertDaysRemaining = new PrometheusClient.Gauge({
|
||||||
name: "monitor_cert_days_remaining",
|
name: "monitor_cert_days_remaining",
|
||||||
help: "The number of days remaining until the certificate expires",
|
help: "The number of days remaining until the certificate expires",
|
||||||
labelNames: commonLabels
|
labelNames: commonLabels
|
||||||
});
|
});
|
||||||
|
|
||||||
const monitor_cert_is_valid = new PrometheusClient.Gauge({
|
const monitorCertIsValid = new PrometheusClient.Gauge({
|
||||||
name: "monitor_cert_is_valid",
|
name: "monitor_cert_is_valid",
|
||||||
help: "Is the certificate still valid? (1 = Yes, 0= No)",
|
help: "Is the certificate still valid? (1 = Yes, 0= No)",
|
||||||
labelNames: commonLabels
|
labelNames: commonLabels
|
||||||
});
|
});
|
||||||
const monitor_response_time = new PrometheusClient.Gauge({
|
const monitorResponseTime = new PrometheusClient.Gauge({
|
||||||
name: "monitor_response_time",
|
name: "monitor_response_time",
|
||||||
help: "Monitor Response Time (ms)",
|
help: "Monitor Response Time (ms)",
|
||||||
labelNames: commonLabels
|
labelNames: commonLabels
|
||||||
});
|
});
|
||||||
|
|
||||||
const monitor_status = new PrometheusClient.Gauge({
|
const monitorStatus = new PrometheusClient.Gauge({
|
||||||
name: "monitor_status",
|
name: "monitor_status",
|
||||||
help: "Monitor Status (1 = UP, 0= DOWN)",
|
help: "Monitor Status (1 = UP, 0= DOWN)",
|
||||||
labelNames: commonLabels
|
labelNames: commonLabels
|
||||||
@@ -48,50 +49,54 @@ class Prometheus {
|
|||||||
|
|
||||||
if (typeof tlsInfo !== "undefined") {
|
if (typeof tlsInfo !== "undefined") {
|
||||||
try {
|
try {
|
||||||
let is_valid = 0;
|
let isValid;
|
||||||
if (tlsInfo.valid == true) {
|
if (tlsInfo.valid === true) {
|
||||||
is_valid = 1;
|
isValid = 1;
|
||||||
} else {
|
} else {
|
||||||
is_valid = 0;
|
isValid = 0;
|
||||||
}
|
}
|
||||||
monitor_cert_is_valid.set(this.monitorLabelValues, is_valid);
|
monitorCertIsValid.set(this.monitorLabelValues, isValid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (tlsInfo.certInfo != null) {
|
if (tlsInfo.certInfo != null) {
|
||||||
monitor_cert_days_remaining.set(this.monitorLabelValues, tlsInfo.certInfo.daysRemaining);
|
monitorCertDaysRemaining.set(this.monitorLabelValues, tlsInfo.certInfo.daysRemaining);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
monitor_status.set(this.monitorLabelValues, heartbeat.status);
|
monitorStatus.set(this.monitorLabelValues, heartbeat.status);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (typeof heartbeat.ping === "number") {
|
if (typeof heartbeat.ping === "number") {
|
||||||
monitor_response_time.set(this.monitorLabelValues, heartbeat.ping);
|
monitorResponseTime.set(this.monitorLabelValues, heartbeat.ping);
|
||||||
} else {
|
} else {
|
||||||
// Is it good?
|
// Is it good?
|
||||||
monitor_response_time.set(this.monitorLabelValues, -1);
|
monitorResponseTime.set(this.monitorLabelValues, -1);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
log.error("prometheus", "Caught error");
|
||||||
|
log.error("prometheus", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
try {
|
try {
|
||||||
monitor_cert_days_remaining.remove(this.monitorLabelValues);
|
monitorCertDaysRemaining.remove(this.monitorLabelValues);
|
||||||
monitor_cert_is_valid.remove(this.monitorLabelValues);
|
monitorCertIsValid.remove(this.monitorLabelValues);
|
||||||
monitor_response_time.remove(this.monitorLabelValues);
|
monitorResponseTime.remove(this.monitorLabelValues);
|
||||||
monitor_status.remove(this.monitorLabelValues);
|
monitorStatus.remove(this.monitorLabelValues);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
@@ -3,11 +3,11 @@ const HttpProxyAgent = require("http-proxy-agent");
|
|||||||
const HttpsProxyAgent = require("https-proxy-agent");
|
const HttpsProxyAgent = require("https-proxy-agent");
|
||||||
const SocksProxyAgent = require("socks-proxy-agent");
|
const SocksProxyAgent = require("socks-proxy-agent");
|
||||||
const { debug } = require("../src/util");
|
const { debug } = require("../src/util");
|
||||||
const server = require("./server");
|
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
|
||||||
@@ -21,7 +21,7 @@ class Proxy {
|
|||||||
let bean;
|
let bean;
|
||||||
|
|
||||||
if (proxyID) {
|
if (proxyID) {
|
||||||
bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [proxyID, userID]);
|
bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [ proxyID, userID ]);
|
||||||
|
|
||||||
if (!bean) {
|
if (!bean) {
|
||||||
throw new Error("proxy not found");
|
throw new Error("proxy not found");
|
||||||
@@ -71,14 +71,14 @@ class Proxy {
|
|||||||
* @return {Promise<void>}
|
* @return {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async delete(proxyID, userID) {
|
static async delete(proxyID, userID) {
|
||||||
const bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [proxyID, userID]);
|
const bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [ proxyID, userID ]);
|
||||||
|
|
||||||
if (!bean) {
|
if (!bean) {
|
||||||
throw new Error("proxy not found");
|
throw new Error("proxy not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete removed proxy from monitors if exists
|
// Delete removed proxy from monitors if exists
|
||||||
await R.exec("UPDATE monitor SET proxy_id = null WHERE proxy_id = ?", [proxyID]);
|
await R.exec("UPDATE monitor SET proxy_id = null WHERE proxy_id = ?", [ proxyID ]);
|
||||||
|
|
||||||
// Delete proxy from list
|
// Delete proxy from list
|
||||||
await R.trash(bean);
|
await R.trash(bean);
|
||||||
@@ -151,6 +151,8 @@ class Proxy {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async reloadProxy() {
|
static async reloadProxy() {
|
||||||
|
const server = UptimeKumaServer.getInstance();
|
||||||
|
|
||||||
let updatedList = await R.getAssoc("SELECT id, proxy_id FROM monitor");
|
let updatedList = await R.getAssoc("SELECT id, proxy_id FROM monitor");
|
||||||
|
|
||||||
for (let monitorID in server.monitorList) {
|
for (let monitorID in server.monitorList) {
|
||||||
@@ -172,12 +174,12 @@ class Proxy {
|
|||||||
*/
|
*/
|
||||||
async function applyProxyEveryMonitor(proxyID, userID) {
|
async function applyProxyEveryMonitor(proxyID, userID) {
|
||||||
// Find all monitors with id and proxy id
|
// Find all monitors with id and proxy id
|
||||||
const monitors = await R.getAll("SELECT id, proxy_id FROM monitor WHERE user_id = ?", [userID]);
|
const monitors = await R.getAll("SELECT id, proxy_id FROM monitor WHERE user_id = ?", [ userID ]);
|
||||||
|
|
||||||
// Update proxy id not match with given proxy id
|
// Update proxy id not match with given proxy id
|
||||||
for (const monitor of monitors) {
|
for (const monitor of monitors) {
|
||||||
if (monitor.proxy_id !== proxyID) {
|
if (monitor.proxy_id !== proxyID) {
|
||||||
await R.exec("UPDATE monitor SET proxy_id = ? WHERE id = ?", [proxyID, monitor.id]);
|
await R.exec("UPDATE monitor SET proxy_id = ? WHERE id = ?", [ proxyID, monitor.id ]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
const { RateLimiter } = require("limiter");
|
const { RateLimiter } = require("limiter");
|
||||||
const { debug } = require("../src/util");
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
class KumaRateLimiter {
|
class KumaRateLimiter {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
@@ -9,7 +9,7 @@ class KumaRateLimiter {
|
|||||||
|
|
||||||
async pass(callback, num = 1) {
|
async pass(callback, num = 1) {
|
||||||
const remainingRequests = await this.removeTokens(num);
|
const remainingRequests = await this.removeTokens(num);
|
||||||
debug("Rate Limit (remainingRequests):" + remainingRequests);
|
log.info("rate-limit", "remaining requests: " + remainingRequests);
|
||||||
if (remainingRequests < 0) {
|
if (remainingRequests < 0) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback({
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
let express = require("express");
|
let express = require("express");
|
||||||
const { allowDevAllOrigin, getSettings, setting } = require("../util-server");
|
const { allowDevAllOrigin } = require("../util-server");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const server = require("../server");
|
|
||||||
const apicache = require("../modules/apicache");
|
const apicache = require("../modules/apicache");
|
||||||
const Monitor = require("../model/monitor");
|
const Monitor = require("../model/monitor");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
const { UP, flipStatus, debug } = require("../../src/util");
|
const { UP, flipStatus, log } = require("../../src/util");
|
||||||
const StatusPage = require("../model/status_page");
|
const StatusPage = require("../model/status_page");
|
||||||
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
let cache = apicache.middleware;
|
let cache = apicache.middleware;
|
||||||
|
const server = UptimeKumaServer.getInstance();
|
||||||
let io = server.io;
|
let io = server.io;
|
||||||
|
|
||||||
router.get("/api/entry-page", async (request, response) => {
|
router.get("/api/entry-page", async (request, response) => {
|
||||||
@@ -62,8 +63,8 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
|||||||
duration = dayjs(bean.time).diff(dayjs(previousHeartbeat.time), "second");
|
duration = dayjs(bean.time).diff(dayjs(previousHeartbeat.time), "second");
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("PreviousStatus: " + previousStatus);
|
log.debug("router", "PreviousStatus: " + previousStatus);
|
||||||
debug("Current Status: " + status);
|
log.debug("router", "Current Status: " + status);
|
||||||
|
|
||||||
bean.important = Monitor.isImportantBeat(isFirstBeat, previousStatus, status);
|
bean.important = Monitor.isImportantBeat(isFirstBeat, previousStatus, status);
|
||||||
bean.monitor_id = monitor.id;
|
bean.monitor_id = monitor.id;
|
||||||
@@ -124,7 +125,7 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons
|
|||||||
// Public Group List
|
// Public Group List
|
||||||
const publicGroupList = [];
|
const publicGroupList = [];
|
||||||
const showTags = !!statusPage.show_tags;
|
const showTags = !!statusPage.show_tags;
|
||||||
debug("Show Tags???" + showTags);
|
|
||||||
const list = await R.find("group", " public = 1 AND status_page_id = ? ORDER BY weight ", [
|
const list = await R.find("group", " public = 1 AND status_page_id = ? ORDER BY weight ", [
|
||||||
statusPage.id
|
statusPage.id
|
||||||
]);
|
]);
|
||||||
@@ -195,14 +196,6 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Default is published
|
|
||||||
* @returns {Promise<boolean>}
|
|
||||||
*/
|
|
||||||
async function isPublished() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function send403(res, msg = "") {
|
function send403(res, msg = "") {
|
||||||
res.status(403).json({
|
res.status(403).json({
|
||||||
"status": "fail",
|
"status": "fail",
|
||||||
|
316
server/server.js
316
server/server.js
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Uptime Kuma Server
|
||||||
|
* node "server/server.js"
|
||||||
|
* DO NOT require("./server") in other modules, it likely creates circular dependency!
|
||||||
|
*/
|
||||||
console.log("Welcome to Uptime Kuma");
|
console.log("Welcome to Uptime Kuma");
|
||||||
|
|
||||||
// Check Node.js Version
|
// Check Node.js Version
|
||||||
@@ -11,81 +16,63 @@ if (nodeVersion < requiredVersion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const args = require("args-parser")(process.argv);
|
const args = require("args-parser")(process.argv);
|
||||||
const { sleep, debug, getRandomInt, genSecret } = require("../src/util");
|
const { sleep, log, getRandomInt, genSecret, debug, isDev } = require("../src/util");
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
|
|
||||||
debug(args);
|
log.info("server", "Welcome to Uptime Kuma");
|
||||||
|
log.debug("server", "Arguments");
|
||||||
|
log.debug("server", args);
|
||||||
|
|
||||||
if (! process.env.NODE_ENV) {
|
if (! process.env.NODE_ENV) {
|
||||||
process.env.NODE_ENV = "production";
|
process.env.NODE_ENV = "production";
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Node Env: " + process.env.NODE_ENV);
|
log.info("server", "Node Env: " + process.env.NODE_ENV);
|
||||||
|
|
||||||
console.log("Importing Node libraries");
|
log.info("server", "Importing Node libraries");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const http = require("http");
|
|
||||||
const https = require("https");
|
|
||||||
|
|
||||||
console.log("Importing 3rd-party libraries");
|
log.info("server", "Importing 3rd-party libraries");
|
||||||
debug("Importing express");
|
log.debug("server", "Importing express");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
debug("Importing socket.io");
|
log.debug("server", "Importing redbean-node");
|
||||||
const { Server } = require("socket.io");
|
|
||||||
debug("Importing redbean-node");
|
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
debug("Importing jsonwebtoken");
|
log.debug("server", "Importing jsonwebtoken");
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
debug("Importing http-graceful-shutdown");
|
log.debug("server", "Importing http-graceful-shutdown");
|
||||||
const gracefulShutdown = require("http-graceful-shutdown");
|
const gracefulShutdown = require("http-graceful-shutdown");
|
||||||
debug("Importing prometheus-api-metrics");
|
log.debug("server", "Importing prometheus-api-metrics");
|
||||||
const prometheusAPIMetrics = require("prometheus-api-metrics");
|
const prometheusAPIMetrics = require("prometheus-api-metrics");
|
||||||
debug("Importing compare-versions");
|
log.debug("server", "Importing compare-versions");
|
||||||
const compareVersions = require("compare-versions");
|
const compareVersions = require("compare-versions");
|
||||||
const { passwordStrength } = require("check-password-strength");
|
const { passwordStrength } = require("check-password-strength");
|
||||||
|
|
||||||
debug("Importing 2FA Modules");
|
log.debug("server", "Importing 2FA Modules");
|
||||||
const notp = require("notp");
|
const notp = require("notp");
|
||||||
const base32 = require("thirty-two");
|
const base32 = require("thirty-two");
|
||||||
|
|
||||||
/**
|
const { UptimeKumaServer } = require("./uptime-kuma-server");
|
||||||
* `module.exports` (alias: `server`) should be inside this class, in order to avoid circular dependency issue.
|
const server = UptimeKumaServer.getInstance(args);
|
||||||
* @type {UptimeKumaServer}
|
const io = module.exports.io = server.io;
|
||||||
*/
|
const app = server.app;
|
||||||
class UptimeKumaServer {
|
|
||||||
/**
|
|
||||||
* Main monitor list
|
|
||||||
* @type {{}}
|
|
||||||
*/
|
|
||||||
monitorList = {};
|
|
||||||
entryPage = "dashboard";
|
|
||||||
|
|
||||||
async sendMonitorList(socket) {
|
log.info("server", "Importing this project modules");
|
||||||
let list = await getMonitorJSONList(socket.userID);
|
log.debug("server", "Importing Monitor");
|
||||||
io.to(socket.userID).emit("monitorList", list);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = module.exports = new UptimeKumaServer();
|
|
||||||
|
|
||||||
console.log("Importing this project modules");
|
|
||||||
debug("Importing Monitor");
|
|
||||||
const Monitor = require("./model/monitor");
|
const Monitor = require("./model/monitor");
|
||||||
debug("Importing Settings");
|
log.debug("server", "Importing Settings");
|
||||||
const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, errorLog, doubleCheckPassword } = require("./util-server");
|
const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, errorLog, doubleCheckPassword } = require("./util-server");
|
||||||
|
|
||||||
debug("Importing Notification");
|
log.debug("server", "Importing Notification");
|
||||||
const { Notification } = require("./notification");
|
const { Notification } = require("./notification");
|
||||||
Notification.init();
|
Notification.init();
|
||||||
|
|
||||||
debug("Importing Proxy");
|
log.debug("server", "Importing Proxy");
|
||||||
const { Proxy } = require("./proxy");
|
const { Proxy } = require("./proxy");
|
||||||
|
|
||||||
debug("Importing Database");
|
log.debug("server", "Importing Database");
|
||||||
const Database = require("./database");
|
const Database = require("./database");
|
||||||
|
|
||||||
debug("Importing Background Jobs");
|
log.debug("server", "Importing Background Jobs");
|
||||||
const { initBackgroundJobs, stopBackgroundJobs } = require("./jobs");
|
const { initBackgroundJobs, stopBackgroundJobs } = require("./jobs");
|
||||||
const { loginRateLimiter, twoFaRateLimiter } = require("./rate-limiter");
|
const { loginRateLimiter, twoFaRateLimiter } = require("./rate-limiter");
|
||||||
|
|
||||||
@@ -94,31 +81,27 @@ const { login } = require("./auth");
|
|||||||
const passwordHash = require("./password-hash");
|
const passwordHash = require("./password-hash");
|
||||||
|
|
||||||
const checkVersion = require("./check-version");
|
const checkVersion = require("./check-version");
|
||||||
console.info("Version: " + checkVersion.version);
|
log.info("server", "Version: " + checkVersion.version);
|
||||||
|
|
||||||
// If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise.
|
// If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise.
|
||||||
// Dual-stack support for (::)
|
// Dual-stack support for (::)
|
||||||
let hostname = process.env.UPTIME_KUMA_HOST || args.host;
|
|
||||||
|
|
||||||
// Also read HOST if not FreeBSD, as HOST is a system environment variable in FreeBSD
|
// Also read HOST if not FreeBSD, as HOST is a system environment variable in FreeBSD
|
||||||
if (!hostname && !FBSD) {
|
let hostEnv = FBSD ? null : process.env.HOST;
|
||||||
hostname = process.env.HOST;
|
let hostname = args.host || process.env.UPTIME_KUMA_HOST || hostEnv;
|
||||||
}
|
|
||||||
|
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
console.log("Custom hostname: " + hostname);
|
log.info("server", "Custom hostname: " + hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const port = parseInt(process.env.UPTIME_KUMA_PORT || process.env.PORT || args.port || 3001);
|
const port = [ args.port, process.env.UPTIME_KUMA_PORT, process.env.PORT, 3001 ]
|
||||||
|
.map(portValue => parseInt(portValue))
|
||||||
|
.find(portValue => !isNaN(portValue));
|
||||||
|
|
||||||
// SSL
|
|
||||||
const sslKey = process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || args["ssl-key"] || undefined;
|
|
||||||
const sslCert = process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || args["ssl-cert"] || undefined;
|
|
||||||
const disableFrameSameOrigin = !!process.env.UPTIME_KUMA_DISABLE_FRAME_SAMEORIGIN || args["disable-frame-sameorigin"] || false;
|
const disableFrameSameOrigin = !!process.env.UPTIME_KUMA_DISABLE_FRAME_SAMEORIGIN || args["disable-frame-sameorigin"] || false;
|
||||||
const cloudflaredToken = args["cloudflared-token"] || process.env.UPTIME_KUMA_CLOUDFLARED_TOKEN || undefined;
|
const cloudflaredToken = args["cloudflared-token"] || process.env.UPTIME_KUMA_CLOUDFLARED_TOKEN || undefined;
|
||||||
|
|
||||||
// 2FA / notp verification defaults
|
// 2FA / notp verification defaults
|
||||||
const twofa_verification_opts = {
|
const twoFAVerifyOptions = {
|
||||||
"window": 1,
|
"window": 1,
|
||||||
"time": 30
|
"time": 30
|
||||||
};
|
};
|
||||||
@@ -130,28 +113,9 @@ const twofa_verification_opts = {
|
|||||||
const testMode = !!args["test"] || false;
|
const testMode = !!args["test"] || false;
|
||||||
|
|
||||||
if (config.demoMode) {
|
if (config.demoMode) {
|
||||||
console.log("==== Demo Mode ====");
|
log.info("server", "==== Demo Mode ====");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Creating express and socket.io instance");
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
let httpServer;
|
|
||||||
|
|
||||||
if (sslKey && sslCert) {
|
|
||||||
console.log("Server Type: HTTPS");
|
|
||||||
httpServer = https.createServer({
|
|
||||||
key: fs.readFileSync(sslKey),
|
|
||||||
cert: fs.readFileSync(sslCert)
|
|
||||||
}, app);
|
|
||||||
} else {
|
|
||||||
console.log("Server Type: HTTP");
|
|
||||||
httpServer = http.createServer(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
const io = new Server(httpServer);
|
|
||||||
module.exports.io = io;
|
|
||||||
|
|
||||||
// Must be after io instantiation
|
// Must be after io instantiation
|
||||||
const { sendNotificationList, sendHeartbeatList, sendImportantHeartbeatList, sendInfo, sendProxyList } = require("./client");
|
const { sendNotificationList, sendHeartbeatList, sendImportantHeartbeatList, sendInfo, sendProxyList } = require("./client");
|
||||||
const { statusPageSocketHandler } = require("./socket-handlers/status-page-socket-handler");
|
const { statusPageSocketHandler } = require("./socket-handlers/status-page-socket-handler");
|
||||||
@@ -174,6 +138,7 @@ app.use(function (req, res, next) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Total WebSocket client connected to server currently, no actual use
|
* Total WebSocket client connected to server currently, no actual use
|
||||||
|
*
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
let totalClient = 0;
|
let totalClient = 0;
|
||||||
@@ -201,7 +166,7 @@ try {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// "dist/index.html" is not necessary for development
|
// "dist/index.html" is not necessary for development
|
||||||
if (process.env.NODE_ENV !== "development") {
|
if (process.env.NODE_ENV !== "development") {
|
||||||
console.error("Error: Cannot find 'dist/index.html', did you install correctly?");
|
log.error("server", "Error: Cannot find 'dist/index.html', did you install correctly?");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,7 +178,7 @@ try {
|
|||||||
exports.entryPage = await setting("entryPage");
|
exports.entryPage = await setting("entryPage");
|
||||||
await StatusPage.loadDomainMappingList();
|
await StatusPage.loadDomainMappingList();
|
||||||
|
|
||||||
console.log("Adding route");
|
log.info("server", "Adding route");
|
||||||
|
|
||||||
// ***************************
|
// ***************************
|
||||||
// Normal Router here
|
// Normal Router here
|
||||||
@@ -233,6 +198,13 @@ try {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
|
app.post("/test-webhook", async (request, response) => {
|
||||||
|
log.debug("test", request.body);
|
||||||
|
response.send("OK");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Robots.txt
|
// Robots.txt
|
||||||
app.get("/robots.txt", async (_request, response) => {
|
app.get("/robots.txt", async (_request, response) => {
|
||||||
let txt = "User-agent: *\nDisallow:";
|
let txt = "User-agent: *\nDisallow:";
|
||||||
@@ -271,7 +243,7 @@ try {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Adding socket handler");
|
log.info("server", "Adding socket handler");
|
||||||
io.on("connection", async (socket) => {
|
io.on("connection", async (socket) => {
|
||||||
|
|
||||||
sendInfo(socket);
|
sendInfo(socket);
|
||||||
@@ -279,7 +251,7 @@ try {
|
|||||||
totalClient++;
|
totalClient++;
|
||||||
|
|
||||||
if (needSetup) {
|
if (needSetup) {
|
||||||
console.log("Redirect to setup page");
|
log.info("server", "Redirect to setup page");
|
||||||
socket.emit("setup");
|
socket.emit("setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,33 +264,40 @@ try {
|
|||||||
// ***************************
|
// ***************************
|
||||||
|
|
||||||
socket.on("loginByToken", async (token, callback) => {
|
socket.on("loginByToken", async (token, callback) => {
|
||||||
|
log.info("auth", `Login by token. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let decoded = jwt.verify(token, jwtSecret);
|
let decoded = jwt.verify(token, jwtSecret);
|
||||||
|
|
||||||
console.log("Username from JWT: " + decoded.username);
|
log.info("auth", "Username from JWT: " + decoded.username);
|
||||||
|
|
||||||
let user = await R.findOne("user", " username = ? AND active = 1 ", [
|
let user = await R.findOne("user", " username = ? AND active = 1 ", [
|
||||||
decoded.username,
|
decoded.username,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
debug("afterLogin");
|
log.debug("auth", "afterLogin");
|
||||||
|
|
||||||
afterLogin(socket, user);
|
afterLogin(socket, user);
|
||||||
|
log.debug("auth", "afterLogin ok");
|
||||||
|
|
||||||
debug("afterLogin ok");
|
log.info("auth", `Successfully logged in user ${decoded.username}. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
log.info("auth", `Inactive or deleted user ${decoded.username}. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: "The user is inactive or deleted.",
|
msg: "The user is inactive or deleted.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
log.error("auth", `Invalid token. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: "Invalid token.",
|
msg: "Invalid token.",
|
||||||
@@ -328,7 +307,7 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("login", async (data, callback) => {
|
socket.on("login", async (data, callback) => {
|
||||||
console.log("Login");
|
log.info("auth", `Login by username + password. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
// Checking
|
// Checking
|
||||||
if (typeof callback !== "function") {
|
if (typeof callback !== "function") {
|
||||||
@@ -341,6 +320,7 @@ try {
|
|||||||
|
|
||||||
// Login Rate Limit
|
// Login Rate Limit
|
||||||
if (! await loginRateLimiter.pass(callback)) {
|
if (! await loginRateLimiter.pass(callback)) {
|
||||||
|
log.info("auth", `Too many failed requests for user ${data.username}. IP=${getClientIp(socket)}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,6 +329,9 @@ try {
|
|||||||
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)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
token: jwt.sign({
|
token: jwt.sign({
|
||||||
@@ -358,13 +341,16 @@ 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)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
tokenRequired: true,
|
tokenRequired: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.token) {
|
if (data.token) {
|
||||||
let verify = notp.totp.verify(data.token, user.twofa_secret, twofa_verification_opts);
|
let verify = notp.totp.verify(data.token, user.twofa_secret, twoFAVerifyOptions);
|
||||||
|
|
||||||
if (user.twofa_last_token !== data.token && verify) {
|
if (user.twofa_last_token !== data.token && verify) {
|
||||||
afterLogin(socket, user);
|
afterLogin(socket, user);
|
||||||
@@ -374,6 +360,8 @@ try {
|
|||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
log.info("auth", `Successfully logged in user ${data.username}. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
token: jwt.sign({
|
token: jwt.sign({
|
||||||
@@ -381,6 +369,9 @@ try {
|
|||||||
}, jwtSecret),
|
}, jwtSecret),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
log.warn("auth", `Invalid token provided for user ${data.username}. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: "Invalid Token!",
|
msg: "Invalid Token!",
|
||||||
@@ -388,6 +379,9 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
log.warn("auth", `Incorrect username or password for user ${data.username}. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: "Incorrect username or password.",
|
msg: "Incorrect username or password.",
|
||||||
@@ -470,11 +464,16 @@ try {
|
|||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
log.info("auth", `Saved 2FA token. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
msg: "2FA Enabled.",
|
msg: "2FA Enabled.",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
log.error("auth", `Error changing 2FA token. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: error.message,
|
msg: error.message,
|
||||||
@@ -492,11 +491,16 @@ try {
|
|||||||
await doubleCheckPassword(socket, currentPassword);
|
await doubleCheckPassword(socket, currentPassword);
|
||||||
await TwoFA.disable2FA(socket.userID);
|
await TwoFA.disable2FA(socket.userID);
|
||||||
|
|
||||||
|
log.info("auth", `Disabled 2FA token. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
msg: "2FA Disabled.",
|
msg: "2FA Disabled.",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
log.error("auth", `Error disabling 2FA token. IP=${getClientIp(socket)}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: error.message,
|
msg: error.message,
|
||||||
@@ -513,7 +517,7 @@ try {
|
|||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let verify = notp.totp.verify(token, user.twofa_secret, twofa_verification_opts);
|
let verify = notp.totp.verify(token, user.twofa_secret, twoFAVerifyOptions);
|
||||||
|
|
||||||
if (user.twofa_last_token !== token && verify) {
|
if (user.twofa_last_token !== token && verify) {
|
||||||
callback({
|
callback({
|
||||||
@@ -623,6 +627,8 @@ try {
|
|||||||
await server.sendMonitorList(socket);
|
await server.sendMonitorList(socket);
|
||||||
await startMonitor(socket.userID, bean.id);
|
await startMonitor(socket.userID, bean.id);
|
||||||
|
|
||||||
|
log.info("monitor", `Added Monitor: ${monitor.id} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
msg: "Added Successfully.",
|
msg: "Added Successfully.",
|
||||||
@@ -630,6 +636,9 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
|
log.error("monitor", `Error adding Monitor: ${monitor.id} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: e.message,
|
msg: e.message,
|
||||||
@@ -674,6 +683,10 @@ try {
|
|||||||
bean.dns_resolve_server = monitor.dns_resolve_server;
|
bean.dns_resolve_server = monitor.dns_resolve_server;
|
||||||
bean.pushToken = monitor.pushToken;
|
bean.pushToken = monitor.pushToken;
|
||||||
bean.proxyId = Number.isInteger(monitor.proxyId) ? monitor.proxyId : null;
|
bean.proxyId = Number.isInteger(monitor.proxyId) ? monitor.proxyId : null;
|
||||||
|
bean.mqttUsername = monitor.mqttUsername;
|
||||||
|
bean.mqttPassword = monitor.mqttPassword;
|
||||||
|
bean.mqttTopic = monitor.mqttTopic;
|
||||||
|
bean.mqttSuccessMessage = monitor.mqttSuccessMessage;
|
||||||
|
|
||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
|
|
||||||
@@ -692,7 +705,7 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
log.error("monitor", e);
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: e.message,
|
msg: e.message,
|
||||||
@@ -708,7 +721,7 @@ try {
|
|||||||
ok: true,
|
ok: true,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
log.error("monitor", e);
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: e.message,
|
msg: e.message,
|
||||||
@@ -720,7 +733,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
console.log(`Get Monitor: ${monitorID} User ID: ${socket.userID}`);
|
log.info("monitor", `Get Monitor: ${monitorID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
let bean = await R.findOne("monitor", " id = ? AND user_id = ? ", [
|
let bean = await R.findOne("monitor", " id = ? AND user_id = ? ", [
|
||||||
monitorID,
|
monitorID,
|
||||||
@@ -744,7 +757,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
console.log(`Get Monitor Beats: ${monitorID} User ID: ${socket.userID}`);
|
log.info("monitor", `Get Monitor Beats: ${monitorID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
if (period == null) {
|
if (period == null) {
|
||||||
throw new Error("Invalid period.");
|
throw new Error("Invalid period.");
|
||||||
@@ -815,7 +828,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
console.log(`Delete Monitor: ${monitorID} User ID: ${socket.userID}`);
|
log.info("manage", `Delete Monitor: ${monitorID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
if (monitorID in server.monitorList) {
|
if (monitorID in server.monitorList) {
|
||||||
server.monitorList[monitorID].stop();
|
server.monitorList[monitorID].stop();
|
||||||
@@ -1147,7 +1160,7 @@ try {
|
|||||||
|
|
||||||
let backupData = JSON.parse(uploadedJSON);
|
let backupData = JSON.parse(uploadedJSON);
|
||||||
|
|
||||||
console.log(`Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`);
|
log.info("manage", `Importing Backup, User ID: ${socket.userID}, Version: ${backupData.version}`);
|
||||||
|
|
||||||
let notificationListData = backupData.notificationList;
|
let notificationListData = backupData.notificationList;
|
||||||
let proxyListData = backupData.proxyList;
|
let proxyListData = backupData.proxyList;
|
||||||
@@ -1190,7 +1203,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only starts importing if the backup file contains at least one proxy
|
// Only starts importing if the backup file contains at least one proxy
|
||||||
if (proxyListData.length >= 1) {
|
if (proxyListData && proxyListData.length >= 1) {
|
||||||
const proxies = await R.findAll("proxy");
|
const proxies = await R.findAll("proxy");
|
||||||
|
|
||||||
// Loop over proxy list and save proxies
|
// Loop over proxy list and save proxies
|
||||||
@@ -1198,7 +1211,7 @@ try {
|
|||||||
const exists = proxies.find(item => item.id === proxy.id);
|
const exists = proxies.find(item => item.id === proxy.id);
|
||||||
|
|
||||||
// Do not process when proxy already exists in import handle is skip and keep
|
// Do not process when proxy already exists in import handle is skip and keep
|
||||||
if (["skip", "keep"].includes(importHandle) && !exists) {
|
if ([ "skip", "keep" ].includes(importHandle) && !exists) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1342,7 +1355,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
console.log(`Clear Events Monitor: ${monitorID} User ID: ${socket.userID}`);
|
log.info("manage", `Clear Events Monitor: ${monitorID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
await R.exec("UPDATE heartbeat SET msg = ?, important = ? WHERE monitor_id = ? ", [
|
await R.exec("UPDATE heartbeat SET msg = ?, important = ? WHERE monitor_id = ? ", [
|
||||||
"",
|
"",
|
||||||
@@ -1368,7 +1381,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
console.log(`Clear Heartbeats Monitor: ${monitorID} User ID: ${socket.userID}`);
|
log.info("manage", `Clear Heartbeats Monitor: ${monitorID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
await R.exec("DELETE FROM heartbeat WHERE monitor_id = ?", [
|
await R.exec("DELETE FROM heartbeat WHERE monitor_id = ?", [
|
||||||
monitorID
|
monitorID
|
||||||
@@ -1392,7 +1405,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
console.log(`Clear Statistics User ID: ${socket.userID}`);
|
log.info("manage", `Clear Statistics User ID: ${socket.userID}`);
|
||||||
|
|
||||||
await R.exec("DELETE FROM heartbeat");
|
await R.exec("DELETE FROM heartbeat");
|
||||||
|
|
||||||
@@ -1414,35 +1427,35 @@ try {
|
|||||||
databaseSocketHandler(socket);
|
databaseSocketHandler(socket);
|
||||||
proxySocketHandler(socket);
|
proxySocketHandler(socket);
|
||||||
|
|
||||||
debug("added all socket handlers");
|
log.debug("server", "added all socket handlers");
|
||||||
|
|
||||||
// ***************************
|
// ***************************
|
||||||
// Better do anything after added all socket handlers here
|
// Better do anything after added all socket handlers here
|
||||||
// ***************************
|
// ***************************
|
||||||
|
|
||||||
debug("check auto login");
|
log.debug("auth", "check auto login");
|
||||||
if (await setting("disableAuth")) {
|
if (await setting("disableAuth")) {
|
||||||
console.log("Disabled Auth: auto login to admin");
|
log.info("auth", "Disabled Auth: auto login to admin");
|
||||||
afterLogin(socket, await R.findOne("user"));
|
afterLogin(socket, await R.findOne("user"));
|
||||||
socket.emit("autoLogin");
|
socket.emit("autoLogin");
|
||||||
} else {
|
} else {
|
||||||
debug("need auth");
|
log.debug("auth", "need auth");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Init the server");
|
log.info("server", "Init the server");
|
||||||
|
|
||||||
httpServer.once("error", async (err) => {
|
server.httpServer.once("error", async (err) => {
|
||||||
console.error("Cannot listen: " + err.message);
|
console.error("Cannot listen: " + err.message);
|
||||||
await shutdownFunction();
|
await shutdownFunction();
|
||||||
});
|
});
|
||||||
|
|
||||||
httpServer.listen(port, hostname, () => {
|
server.httpServer.listen(port, hostname, () => {
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
console.log(`Listening on ${hostname}:${port}`);
|
log.info("server", `Listening on ${hostname}:${port}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Listening on ${port}`);
|
log.info("server", `Listening on ${port}`);
|
||||||
}
|
}
|
||||||
startMonitors();
|
startMonitors();
|
||||||
checkVersion.startInterval();
|
checkVersion.startInterval();
|
||||||
@@ -1459,6 +1472,13 @@ try {
|
|||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds or removes notifications from a monitor.
|
||||||
|
* @param {number} monitorID The ID of the monitor to add/remove notifications from.
|
||||||
|
* @param {Array.<number>} notificationIDList An array of IDs for the notifications to add/remove.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
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 = ? ", [
|
||||||
monitorID,
|
monitorID,
|
||||||
@@ -1474,6 +1494,13 @@ async function updateMonitorNotification(monitorID, notificationIDList) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function checks if the user owns a monitor with the given ID.
|
||||||
|
* @param {number} monitorID - The ID of the monitor to check ownership for.
|
||||||
|
* @param {number} userID - The ID of the user who is trying to access this data.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
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 = ? ", [
|
||||||
monitorID,
|
monitorID,
|
||||||
@@ -1485,6 +1512,10 @@ async function checkOwner(userID, monitorID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
async function afterLogin(socket, user) {
|
async function afterLogin(socket, user) {
|
||||||
socket.userID = user.id;
|
socket.userID = user.id;
|
||||||
socket.join(user.id);
|
socket.join(user.id);
|
||||||
@@ -1510,29 +1541,20 @@ async function afterLogin(socket, user) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMonitorJSONList(userID) {
|
/**
|
||||||
let result = {};
|
* Connect to the database and patch it if necessary.
|
||||||
|
*
|
||||||
let monitorList = await R.find("monitor", " user_id = ? ORDER BY weight DESC, name", [
|
* Generated by Trelent
|
||||||
userID,
|
*/
|
||||||
]);
|
|
||||||
|
|
||||||
for (let monitor of monitorList) {
|
|
||||||
result[monitor.id] = await monitor.toJSON();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function initDatabase(testMode = false) {
|
async function initDatabase(testMode = false) {
|
||||||
if (! fs.existsSync(Database.path)) {
|
if (! fs.existsSync(Database.path)) {
|
||||||
console.log("Copying Database");
|
log.info("server", "Copying Database");
|
||||||
fs.copyFileSync(Database.templatePath, Database.path);
|
fs.copyFileSync(Database.templatePath, Database.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Connecting to the Database");
|
log.info("server", "Connecting to the Database");
|
||||||
await Database.connect(testMode);
|
await Database.connect(testMode);
|
||||||
console.log("Connected");
|
log.info("server", "Connected");
|
||||||
|
|
||||||
// Patch the database
|
// Patch the database
|
||||||
await Database.patch();
|
await Database.patch();
|
||||||
@@ -1542,26 +1564,33 @@ async function initDatabase(testMode = false) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (! jwtSecretBean) {
|
if (! jwtSecretBean) {
|
||||||
console.log("JWT secret is not found, generate one.");
|
log.info("server", "JWT secret is not found, generate one.");
|
||||||
jwtSecretBean = await initJWTSecret();
|
jwtSecretBean = await initJWTSecret();
|
||||||
console.log("Stored JWT secret into database");
|
log.info("server", "Stored JWT secret into database");
|
||||||
} else {
|
} else {
|
||||||
console.log("Load JWT secret from database.");
|
log.info("server", "Load JWT secret from database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no record in user table, it is a new Uptime Kuma instance, need to setup
|
// If there is no record in user table, it is a new Uptime Kuma instance, need to setup
|
||||||
if ((await R.count("user")) === 0) {
|
if ((await R.count("user")) === 0) {
|
||||||
console.log("No user, need setup");
|
log.info("server", "No user, need setup");
|
||||||
needSetup = true;
|
needSetup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
jwtSecret = jwtSecretBean.value;
|
jwtSecret = jwtSecretBean.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resume a monitor.
|
||||||
|
* @param {string} userID - The ID of the user who owns the monitor.
|
||||||
|
* @param {string} monitorID - The ID of the monitor to resume.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
async function startMonitor(userID, monitorID) {
|
async function startMonitor(userID, monitorID) {
|
||||||
await checkOwner(userID, monitorID);
|
await checkOwner(userID, monitorID);
|
||||||
|
|
||||||
console.log(`Resume Monitor: ${monitorID} User ID: ${userID}`);
|
log.info("manage", `Resume Monitor: ${monitorID} User ID: ${userID}`);
|
||||||
|
|
||||||
await R.exec("UPDATE monitor SET active = 1 WHERE id = ? AND user_id = ? ", [
|
await R.exec("UPDATE monitor SET active = 1 WHERE id = ? AND user_id = ? ", [
|
||||||
monitorID,
|
monitorID,
|
||||||
@@ -1584,10 +1613,17 @@ async function restartMonitor(userID, monitorID) {
|
|||||||
return await startMonitor(userID, monitorID);
|
return await startMonitor(userID, monitorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause a monitor.
|
||||||
|
* @param {string} userID - The ID of the user who owns the monitor.
|
||||||
|
* @param {string} monitorID - The ID of the monitor to pause.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
async function pauseMonitor(userID, monitorID) {
|
async function pauseMonitor(userID, monitorID) {
|
||||||
await checkOwner(userID, monitorID);
|
await checkOwner(userID, monitorID);
|
||||||
|
|
||||||
console.log(`Pause Monitor: ${monitorID} User ID: ${userID}`);
|
log.info("manage", `Pause Monitor: ${monitorID} User ID: ${userID}`);
|
||||||
|
|
||||||
await R.exec("UPDATE monitor SET active = 0 WHERE id = ? AND user_id = ? ", [
|
await R.exec("UPDATE monitor SET active = 0 WHERE id = ? AND user_id = ? ", [
|
||||||
monitorID,
|
monitorID,
|
||||||
@@ -1616,11 +1652,17 @@ async function startMonitors() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops all monitors and closes the database connection.
|
||||||
|
* @param {string} signal The signal that triggered this function to be called.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
async function shutdownFunction(signal) {
|
async function shutdownFunction(signal) {
|
||||||
console.log("Shutdown requested");
|
log.info("server", "Shutdown requested");
|
||||||
console.log("Called signal: " + signal);
|
log.info("server", "Called signal: " + signal);
|
||||||
|
|
||||||
console.log("Stopping all monitors");
|
log.info("server", "Stopping all monitors");
|
||||||
for (let id in server.monitorList) {
|
for (let id in server.monitorList) {
|
||||||
let monitor = server.monitorList[id];
|
let monitor = server.monitorList[id];
|
||||||
monitor.stop();
|
monitor.stop();
|
||||||
@@ -1632,11 +1674,15 @@ async function shutdownFunction(signal) {
|
|||||||
await cloudflaredStop();
|
await cloudflaredStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
function finalFunction() {
|
function getClientIp(socket) {
|
||||||
console.log("Graceful shutdown successful!");
|
return socket.client.conn.remoteAddress.replace(/^.*:/, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
gracefulShutdown(httpServer, {
|
function finalFunction() {
|
||||||
|
log.info("server", "Graceful shutdown successful!");
|
||||||
|
}
|
||||||
|
|
||||||
|
gracefulShutdown(server.httpServer, {
|
||||||
signals: "SIGINT SIGTERM",
|
signals: "SIGINT SIGTERM",
|
||||||
timeout: 30000, // timeout: 30 secs
|
timeout: 30000, // timeout: 30 secs
|
||||||
development: false, // not in dev mode
|
development: false, // not in dev mode
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
const { checkLogin, setSetting, setting, doubleCheckPassword } = require("../util-server");
|
const { checkLogin, setSetting, setting, doubleCheckPassword } = require("../util-server");
|
||||||
const { CloudflaredTunnel } = require("node-cloudflared-tunnel");
|
const { CloudflaredTunnel } = require("node-cloudflared-tunnel");
|
||||||
const { io } = require("../server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
const io = UptimeKumaServer.getInstance().io;
|
||||||
|
|
||||||
const prefix = "cloudflared_";
|
const prefix = "cloudflared_";
|
||||||
const cloudflared = new CloudflaredTunnel();
|
const cloudflared = new CloudflaredTunnel();
|
||||||
@@ -86,5 +87,7 @@ module.exports.autoStart = async (token) => {
|
|||||||
|
|
||||||
module.exports.stop = async () => {
|
module.exports.stop = async () => {
|
||||||
console.log("Stop cloudflared");
|
console.log("Stop cloudflared");
|
||||||
cloudflared.stop();
|
if (cloudflared) {
|
||||||
|
cloudflared.stop();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
const { checkLogin } = require("../util-server");
|
const { checkLogin } = require("../util-server");
|
||||||
const { Proxy } = require("../proxy");
|
const { Proxy } = require("../proxy");
|
||||||
const { sendProxyList } = require("../client");
|
const { sendProxyList } = require("../client");
|
||||||
const server = require("../server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
const server = UptimeKumaServer.getInstance();
|
||||||
|
|
||||||
module.exports.proxySocketHandler = (socket) => {
|
module.exports.proxySocketHandler = (socket) => {
|
||||||
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { checkLogin, setSettings, setSetting } = require("../util-server");
|
const { checkLogin, setSetting } = require("../util-server");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
const { debug } = require("../../src/util");
|
const { log } = require("../../src/util");
|
||||||
const ImageDataURI = require("../image-data-uri");
|
const ImageDataURI = require("../image-data-uri");
|
||||||
const Database = require("../database");
|
const Database = require("../database");
|
||||||
const apicache = require("../modules/apicache");
|
const apicache = require("../modules/apicache");
|
||||||
const StatusPage = require("../model/status_page");
|
const StatusPage = require("../model/status_page");
|
||||||
const server = require("../server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
|
||||||
module.exports.statusPageSocketHandler = (socket) => {
|
module.exports.statusPageSocketHandler = (socket) => {
|
||||||
|
|
||||||
@@ -155,6 +155,9 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
//statusPage.search_engine_index = ;
|
//statusPage.search_engine_index = ;
|
||||||
statusPage.show_tags = config.showTags;
|
statusPage.show_tags = config.showTags;
|
||||||
//statusPage.password = null;
|
//statusPage.password = null;
|
||||||
|
statusPage.footer_text = config.footerText;
|
||||||
|
statusPage.custom_css = config.customCSS;
|
||||||
|
statusPage.show_powered_by = config.showPoweredBy;
|
||||||
statusPage.modified_date = R.isoDateTime();
|
statusPage.modified_date = R.isoDateTime();
|
||||||
|
|
||||||
await R.store(statusPage);
|
await R.store(statusPage);
|
||||||
@@ -202,8 +205,8 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
group.id = groupBean.id;
|
group.id = groupBean.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete groups that not in the list
|
// Delete groups that are not in the list
|
||||||
debug("Delete groups that not in the list");
|
log.debug("socket", "Delete groups that are not in the list");
|
||||||
const slots = groupIDList.map(() => "?").join(",");
|
const slots = groupIDList.map(() => "?").join(",");
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
@@ -212,6 +215,8 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
];
|
];
|
||||||
await R.exec(`DELETE FROM \`group\` WHERE id NOT IN (${slots}) AND status_page_id = ?`, data);
|
await R.exec(`DELETE FROM \`group\` WHERE id NOT IN (${slots}) AND status_page_id = ?`, data);
|
||||||
|
|
||||||
|
const server = UptimeKumaServer.getInstance();
|
||||||
|
|
||||||
// Also change entry page to new slug if it is the default one, and slug is changed.
|
// Also change entry page to new slug if it is the default one, and slug is changed.
|
||||||
if (server.entryPage === "statusPage-" + slug && statusPage.slug !== slug) {
|
if (server.entryPage === "statusPage-" + slug && statusPage.slug !== slug) {
|
||||||
server.entryPage = "statusPage-" + statusPage.slug;
|
server.entryPage = "statusPage-" + statusPage.slug;
|
||||||
@@ -226,7 +231,7 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
log.error("socket", error);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -281,6 +286,8 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
|
|
||||||
// Delete a status page
|
// Delete a status page
|
||||||
socket.on("deleteStatusPage", async (slug, callback) => {
|
socket.on("deleteStatusPage", async (slug, callback) => {
|
||||||
|
const server = UptimeKumaServer.getInstance();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
|
90
server/uptime-kuma-server.js
Normal file
90
server/uptime-kuma-server.js
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const https = require("https");
|
||||||
|
const fs = require("fs");
|
||||||
|
const http = require("http");
|
||||||
|
const { Server } = require("socket.io");
|
||||||
|
const { R } = require("redbean-node");
|
||||||
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `module.exports` (alias: `server`) should be inside this class, in order to avoid circular dependency issue.
|
||||||
|
* @type {UptimeKumaServer}
|
||||||
|
*/
|
||||||
|
class UptimeKumaServer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @type {UptimeKumaServer}
|
||||||
|
*/
|
||||||
|
static instance = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main monitor list
|
||||||
|
* @type {{}}
|
||||||
|
*/
|
||||||
|
monitorList = {};
|
||||||
|
entryPage = "dashboard";
|
||||||
|
app = undefined;
|
||||||
|
httpServer = undefined;
|
||||||
|
io = undefined;
|
||||||
|
|
||||||
|
static getInstance(args) {
|
||||||
|
if (UptimeKumaServer.instance == null) {
|
||||||
|
UptimeKumaServer.instance = new UptimeKumaServer(args);
|
||||||
|
}
|
||||||
|
return UptimeKumaServer.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(args) {
|
||||||
|
// SSL
|
||||||
|
const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined;
|
||||||
|
const sslCert = args["ssl-cert"] || process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined;
|
||||||
|
|
||||||
|
log.info("server", "Creating express and socket.io instance");
|
||||||
|
this.app = express();
|
||||||
|
|
||||||
|
if (sslKey && sslCert) {
|
||||||
|
log.info("server", "Server Type: HTTPS");
|
||||||
|
this.httpServer = https.createServer({
|
||||||
|
key: fs.readFileSync(sslKey),
|
||||||
|
cert: fs.readFileSync(sslCert)
|
||||||
|
}, this.app);
|
||||||
|
} else {
|
||||||
|
log.info("server", "Server Type: HTTP");
|
||||||
|
this.httpServer = http.createServer(this.app);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.io = new Server(this.httpServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendMonitorList(socket) {
|
||||||
|
let list = await this.getMonitorJSONList(socket.userID);
|
||||||
|
this.io.to(socket.userID).emit("monitorList", list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of monitors for the given user.
|
||||||
|
* @param {string} userID - The ID of the user to get monitors for.
|
||||||
|
* @returns {Promise<Object>} A promise that resolves to an object with monitor IDs as keys and monitor objects as values.
|
||||||
|
*
|
||||||
|
* Generated by Trelent
|
||||||
|
*/
|
||||||
|
async getMonitorJSONList(userID) {
|
||||||
|
let result = {};
|
||||||
|
|
||||||
|
let monitorList = await R.find("monitor", " user_id = ? ORDER BY weight DESC, name", [
|
||||||
|
userID,
|
||||||
|
]);
|
||||||
|
|
||||||
|
for (let monitor of monitorList) {
|
||||||
|
result[monitor.id] = await monitor.toJSON();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
UptimeKumaServer
|
||||||
|
};
|
@@ -1,14 +1,15 @@
|
|||||||
const tcpp = require("tcp-ping");
|
const tcpp = require("tcp-ping");
|
||||||
const Ping = require("./ping-lite");
|
const Ping = require("./ping-lite");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { debug, genSecret } = require("../src/util");
|
const { log, genSecret } = require("../src/util");
|
||||||
const passwordHash = require("./password-hash");
|
const passwordHash = require("./password-hash");
|
||||||
const { Resolver } = require("dns");
|
const { Resolver } = require("dns");
|
||||||
const child_process = require("child_process");
|
const childProcess = require("child_process");
|
||||||
const iconv = require("iconv-lite");
|
const iconv = require("iconv-lite");
|
||||||
const chardet = require("chardet");
|
const chardet = require("chardet");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const nodeJsUtil = require("util");
|
const nodeJsUtil = require("util");
|
||||||
|
const mqtt = require("mqtt");
|
||||||
|
|
||||||
// From ping-lite
|
// From ping-lite
|
||||||
exports.WIN = /^win/.test(process.platform);
|
exports.WIN = /^win/.test(process.platform);
|
||||||
@@ -26,7 +27,7 @@ exports.initJWTSecret = async () => {
|
|||||||
"jwtSecret",
|
"jwtSecret",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (! jwtSecretBean) {
|
if (!jwtSecretBean) {
|
||||||
jwtSecretBean = R.dispense("setting");
|
jwtSecretBean = R.dispense("setting");
|
||||||
jwtSecretBean.key = "jwtSecret";
|
jwtSecretBean.key = "jwtSecret";
|
||||||
}
|
}
|
||||||
@@ -88,11 +89,68 @@ exports.pingAsync = function (hostname, ipv6 = false) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.dnsResolve = function (hostname, resolver_server, rrtype) {
|
exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
||||||
const resolver = new Resolver();
|
|
||||||
resolver.setServers([resolver_server]);
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (rrtype == "PTR") {
|
const { port, username, password, interval = 20 } = options;
|
||||||
|
|
||||||
|
// Adds MQTT protocol to the hostname if not already present
|
||||||
|
if (!/^(?:http|mqtt)s?:\/\//.test(hostname)) {
|
||||||
|
hostname = "mqtt://" + hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeoutID = setTimeout(() => {
|
||||||
|
log.debug("mqtt", "MQTT timeout triggered");
|
||||||
|
client.end();
|
||||||
|
reject(new Error("Timeout"));
|
||||||
|
}, interval * 1000 * 0.8);
|
||||||
|
|
||||||
|
log.debug("mqtt", "MQTT connecting");
|
||||||
|
|
||||||
|
let client = mqtt.connect(hostname, {
|
||||||
|
port,
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on("connect", () => {
|
||||||
|
log.debug("mqtt", "MQTT connected");
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.debug("mqtt", "MQTT subscribe topic");
|
||||||
|
client.subscribe(topic);
|
||||||
|
} catch (e) {
|
||||||
|
client.end();
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
reject(new Error("Cannot subscribe topic"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on("error", (error) => {
|
||||||
|
client.end();
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on("message", (messageTopic, message) => {
|
||||||
|
if (messageTopic == topic) {
|
||||||
|
client.end();
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
if (okMessage != null && okMessage !== "" && message.toString() !== okMessage) {
|
||||||
|
reject(new Error(`Message Mismatch - Topic: ${messageTopic}; Message: ${message.toString()}`));
|
||||||
|
} else {
|
||||||
|
resolve(`Topic: ${messageTopic}; Message: ${message.toString()}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.dnsResolve = function (hostname, resolverServer, rrtype) {
|
||||||
|
const resolver = new Resolver();
|
||||||
|
resolver.setServers([ resolverServer ]);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (rrtype === "PTR") {
|
||||||
resolver.reverse(hostname, (err, records) => {
|
resolver.reverse(hostname, (err, records) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -119,7 +177,7 @@ exports.setting = async function (key) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const v = JSON.parse(value);
|
const v = JSON.parse(value);
|
||||||
debug(`Get Setting: ${key}: ${v}`);
|
log.debug("util", `Get Setting: ${key}: ${v}`);
|
||||||
return v;
|
return v;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return value;
|
return value;
|
||||||
@@ -206,7 +264,7 @@ const parseCertificateInfo = function (info) {
|
|||||||
const existingList = {};
|
const existingList = {};
|
||||||
|
|
||||||
while (link) {
|
while (link) {
|
||||||
debug(`[${i}] ${link.fingerprint}`);
|
log.debug("cert", `[${i}] ${link.fingerprint}`);
|
||||||
|
|
||||||
if (!link.valid_from || !link.valid_to) {
|
if (!link.valid_from || !link.valid_to) {
|
||||||
break;
|
break;
|
||||||
@@ -221,7 +279,7 @@ const parseCertificateInfo = function (info) {
|
|||||||
if (link.issuerCertificate == null) {
|
if (link.issuerCertificate == null) {
|
||||||
break;
|
break;
|
||||||
} else if (link.issuerCertificate.fingerprint in existingList) {
|
} else if (link.issuerCertificate.fingerprint in existingList) {
|
||||||
debug(`[Last] ${link.issuerCertificate.fingerprint}`);
|
log.debug("cert", `[Last] ${link.issuerCertificate.fingerprint}`);
|
||||||
link.issuerCertificate = null;
|
link.issuerCertificate = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -242,7 +300,7 @@ 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;
|
||||||
|
|
||||||
debug("Parsing Certificate Info");
|
log.debug("cert", "Parsing Certificate Info");
|
||||||
const parsedInfo = parseCertificateInfo(info);
|
const parsedInfo = parseCertificateInfo(info);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -257,19 +315,19 @@ exports.checkCertificate = function (res) {
|
|||||||
// Return: true if the status code is within the accepted ranges, false otherwise
|
// Return: true if the status code is within the accepted ranges, false otherwise
|
||||||
// Will throw an error if the provided status code is not a valid range string or code string
|
// Will throw an error if the provided status code is not a valid range string or code string
|
||||||
|
|
||||||
exports.checkStatusCode = function (status, accepted_codes) {
|
exports.checkStatusCode = function (status, acceptedCodes) {
|
||||||
if (accepted_codes == null || accepted_codes.length === 0) {
|
if (acceptedCodes == null || acceptedCodes.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const code_range of accepted_codes) {
|
for (const codeRange of acceptedCodes) {
|
||||||
const code_range_split = code_range.split("-").map(string => parseInt(string));
|
const codeRangeSplit = codeRange.split("-").map(string => parseInt(string));
|
||||||
if (code_range_split.length === 1) {
|
if (codeRangeSplit.length === 1) {
|
||||||
if (status === code_range_split[0]) {
|
if (status === codeRangeSplit[0]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (code_range_split.length === 2) {
|
} else if (codeRangeSplit.length === 2) {
|
||||||
if (status >= code_range_split[0] && status <= code_range_split[1]) {
|
if (status >= codeRangeSplit[0] && status <= codeRangeSplit[1]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -284,13 +342,13 @@ exports.getTotalClientInRoom = (io, roomName) => {
|
|||||||
|
|
||||||
const sockets = io.sockets;
|
const sockets = io.sockets;
|
||||||
|
|
||||||
if (! sockets) {
|
if (!sockets) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const adapter = sockets.adapter;
|
const adapter = sockets.adapter;
|
||||||
|
|
||||||
if (! adapter) {
|
if (!adapter) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +373,7 @@ exports.allowAllOrigin = (res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -345,7 +403,7 @@ exports.doubleCheckPassword = async (socket, currentPassword) => {
|
|||||||
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";
|
||||||
const child = child_process.spawn(npm, ["run", "jest"]);
|
const child = childProcess.spawn(npm, [ "run", "jest" ]);
|
||||||
|
|
||||||
child.stdout.on("data", (data) => {
|
child.stdout.on("data", (data) => {
|
||||||
console.log(data.toString());
|
console.log(data.toString());
|
||||||
@@ -367,7 +425,6 @@ exports.startUnitTest = async () => {
|
|||||||
*/
|
*/
|
||||||
exports.convertToUTF8 = (body) => {
|
exports.convertToUTF8 = (body) => {
|
||||||
const guessEncoding = chardet.detect(body);
|
const guessEncoding = chardet.detect(body);
|
||||||
//debug("Guess Encoding: " + guessEncoding);
|
|
||||||
const str = iconv.decode(body, guessEncoding);
|
const str = iconv.decode(body, guessEncoding);
|
||||||
return str.toString();
|
return str.toString();
|
||||||
};
|
};
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<router-view />
|
<router-view />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { setPageLocale } from "./util-frontend";
|
import { setPageLocale } from "./util-frontend";
|
||||||
export default {
|
export default {
|
||||||
created() {
|
created() {
|
||||||
setPageLocale();
|
setPageLocale();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -469,6 +469,10 @@ textarea.form-control {
|
|||||||
color: $primary;
|
color: $primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.prism-editor__textarea {
|
||||||
|
outline: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
// Localization
|
// Localization
|
||||||
|
|
||||||
@import "localization.scss";
|
@import "localization.scss";
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Modal } from "bootstrap"
|
import { Modal } from "bootstrap";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -42,19 +42,20 @@ export default {
|
|||||||
default: "No",
|
default: "No",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: [ "yes" ],
|
||||||
data: () => ({
|
data: () => ({
|
||||||
modal: null,
|
modal: null,
|
||||||
}),
|
}),
|
||||||
mounted() {
|
mounted() {
|
||||||
this.modal = new Modal(this.$refs.modal)
|
this.modal = new Modal(this.$refs.modal);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
show() {
|
show() {
|
||||||
this.modal.show()
|
this.modal.show();
|
||||||
},
|
},
|
||||||
yes() {
|
yes() {
|
||||||
this.$emit("yes");
|
this.$emit("yes");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -57,6 +57,7 @@ export default {
|
|||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: [ "update:modelValue" ],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
visibility: "password",
|
visibility: "password",
|
||||||
|
@@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
import { sleep } from "../util.ts"
|
import { sleep } from "../util.ts";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: [String, Number],
|
value: [ String, Number ],
|
||||||
time: {
|
time: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0.3,
|
default: 0.3,
|
||||||
@@ -25,12 +25,12 @@ export default {
|
|||||||
return {
|
return {
|
||||||
output: "",
|
output: "",
|
||||||
frameDuration: 30,
|
frameDuration: 30,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
isNum() {
|
isNum() {
|
||||||
return typeof this.value === "number"
|
return typeof this.value === "number";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
for (let i = 1; i < frames; i++) {
|
for (let i = 1; i < frames; i++) {
|
||||||
this.output += step;
|
this.output += step;
|
||||||
await sleep(15)
|
await sleep(15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,5 +59,5 @@ export default {
|
|||||||
|
|
||||||
methods: {},
|
methods: {},
|
||||||
|
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
<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 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
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone);
|
||||||
dayjs.extend(relativeTime)
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -29,5 +29,5 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -38,7 +38,7 @@ export default {
|
|||||||
beatMargin: 4,
|
beatMargin: 4,
|
||||||
move: false,
|
move: false,
|
||||||
maxBeat: -1,
|
maxBeat: -1,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
||||||
@@ -69,12 +69,12 @@ export default {
|
|||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
// Add empty placeholder
|
// Add empty placeholder
|
||||||
for (let i = start; i < 0; i++) {
|
for (let i = start; i < 0; i++) {
|
||||||
placeholders.push(0)
|
placeholders.push(0);
|
||||||
}
|
}
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return placeholders.concat(this.beatList.slice(start))
|
return placeholders.concat(this.beatList.slice(start));
|
||||||
},
|
},
|
||||||
|
|
||||||
wrapStyle() {
|
wrapStyle() {
|
||||||
@@ -84,7 +84,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
padding: `${topBottom}px ${leftRight}px`,
|
padding: `${topBottom}px ${leftRight}px`,
|
||||||
width: "100%",
|
width: "100%",
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
barStyle() {
|
barStyle() {
|
||||||
@@ -94,12 +94,12 @@ export default {
|
|||||||
return {
|
return {
|
||||||
transition: "all ease-in-out 0.25s",
|
transition: "all ease-in-out 0.25s",
|
||||||
transform: `translateX(${width}px)`,
|
transform: `translateX(${width}px)`,
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
transform: "translateX(0)",
|
transform: "translateX(0)",
|
||||||
}
|
};
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ export default {
|
|||||||
height: this.beatHeight + "px",
|
height: this.beatHeight + "px",
|
||||||
margin: this.beatMargin + "px",
|
margin: this.beatMargin + "px",
|
||||||
"--hover-scale": this.hoverScale,
|
"--hover-scale": this.hoverScale,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -120,7 +120,7 @@ export default {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.move = false;
|
this.move = false;
|
||||||
}, 300)
|
}, 300);
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
},
|
},
|
||||||
@@ -162,15 +162,15 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
resize() {
|
resize() {
|
||||||
if (this.$refs.wrap) {
|
if (this.$refs.wrap) {
|
||||||
this.maxBeat = Math.floor(this.$refs.wrap.clientWidth / (this.beatWidth + this.beatMargin * 2))
|
this.maxBeat = Math.floor(this.$refs.wrap.clientWidth / (this.beatWidth + this.beatMargin * 2));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getBeatTitle(beat) {
|
getBeatTitle(beat) {
|
||||||
return `${this.$root.datetime(beat.time)}` + ((beat.msg) ? ` - ${beat.msg}` : ``);
|
return `${this.$root.datetime(beat.time)}` + ((beat.msg) ? ` - ${beat.msg}` : "");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
@@ -48,18 +48,19 @@ export default {
|
|||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: [ "update:modelValue" ],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
visibility: "password",
|
visibility: "password",
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
model: {
|
model: {
|
||||||
get() {
|
get() {
|
||||||
return this.modelValue
|
return this.modelValue;
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
this.$emit("update:modelValue", value)
|
this.$emit("update:modelValue", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -74,5 +75,5 @@ export default {
|
|||||||
this.visibility = "password";
|
this.visibility = "password";
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<router-link v-for="(item, index) in sortedMonitorList" :key="index" :to="monitorURL(item.id)" class="item" :class="{ 'disabled': ! item.active }">
|
<router-link v-for="(item, index) in sortedMonitorList" :key="index" :to="monitorURL(item.id)" class="item" :class="{ 'disabled': ! item.active }">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-9 col-md-8 small-padding" :class="{ 'monitorItem': $root.userHeartbeatBar == 'bottom' || $root.userHeartbeatBar == 'none' }">
|
<div class="col-9 col-md-8 small-padding" :class="{ 'monitor-item': $root.userHeartbeatBar == 'bottom' || $root.userHeartbeatBar == 'none' }">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<Uptime :monitor="item" type="24" :pill="true" />
|
<Uptime :monitor="item" type="24" :pill="true" />
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
@@ -172,7 +172,7 @@ export default {
|
|||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
.footer {
|
.footer {
|
||||||
// background-color: $dark-bg;
|
// background-color: $dark-bg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ export default {
|
|||||||
max-width: 15em;
|
max-width: 15em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.monitorItem {
|
.monitor-item {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -69,7 +69,6 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Modal } from "bootstrap";
|
import { Modal } from "bootstrap";
|
||||||
import { ucfirst } from "../util.ts";
|
|
||||||
|
|
||||||
import Confirm from "./Confirm.vue";
|
import Confirm from "./Confirm.vue";
|
||||||
import NotificationFormList from "./notifications";
|
import NotificationFormList from "./notifications";
|
||||||
@@ -79,7 +78,7 @@ export default {
|
|||||||
Confirm,
|
Confirm,
|
||||||
},
|
},
|
||||||
props: {},
|
props: {},
|
||||||
emits: ["added"],
|
emits: [ "added" ],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
model: null,
|
model: null,
|
||||||
|
@@ -24,7 +24,7 @@ import timezone from "dayjs/plugin/timezone";
|
|||||||
import "chartjs-adapter-dayjs";
|
import "chartjs-adapter-dayjs";
|
||||||
import { LineChart } from "vue-chart-3";
|
import { LineChart } from "vue-chart-3";
|
||||||
import { useToast } from "vue-toastification";
|
import { useToast } from "vue-toastification";
|
||||||
import { UP, DOWN, PENDING } from "../util.ts";
|
import { DOWN } from "../util.ts";
|
||||||
|
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
@@ -220,6 +220,7 @@ export default {
|
|||||||
if (newPeriod == "0") {
|
if (newPeriod == "0") {
|
||||||
newPeriod = null;
|
newPeriod = null;
|
||||||
this.heartbeatList = null;
|
this.heartbeatList = null;
|
||||||
|
this.$root.storage().removeItem(`chart-period-${this.monitorId}`);
|
||||||
} else {
|
} else {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
@@ -228,6 +229,7 @@ export default {
|
|||||||
toast.error(res.msg);
|
toast.error(res.msg);
|
||||||
} else {
|
} else {
|
||||||
this.heartbeatList = res.data;
|
this.heartbeatList = res.data;
|
||||||
|
this.$root.storage()[`chart-period-${this.monitorId}`] = newPeriod;
|
||||||
}
|
}
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
@@ -248,6 +250,12 @@ export default {
|
|||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Load chart period from storage if saved
|
||||||
|
let period = this.$root.storage()[`chart-period-${this.monitorId}`];
|
||||||
|
if (period != null) {
|
||||||
|
this.chartPeriodHrs = Math.min(period, 6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -278,7 +286,7 @@ export default {
|
|||||||
|
|
||||||
.dropdown-item {
|
.dropdown-item {
|
||||||
border-radius: 0.3rem;
|
border-radius: 0.3rem;
|
||||||
padding: 2px 16px 4px 16px;
|
padding: 2px 16px 4px;
|
||||||
|
|
||||||
.dark & {
|
.dark & {
|
||||||
background: $dark-bg;
|
background: $dark-bg;
|
||||||
@@ -286,6 +294,7 @@ export default {
|
|||||||
|
|
||||||
.dark &:hover {
|
.dark &:hover {
|
||||||
background: $dark-font-color;
|
background: $dark-font-color;
|
||||||
|
color: $dark-font-color2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
<label for="proxy-host" class="form-label">{{ $t("Proxy Server") }}</label>
|
<label for="proxy-host" class="form-label">{{ $t("Proxy Server") }}</label>
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<input id="proxy-host" v-model="proxy.host" type="text" class="form-control" required :placeholder="$t('Server Address')">
|
<input id="proxy-host" v-model="proxy.host" type="text" class="form-control" required :placeholder="$t('Server Address')">
|
||||||
<input v-model="proxy.port" type="number" class="form-control ms-2" style="width: 100px" required min="1" max="65535" :placeholder="$t('Port')">
|
<input v-model="proxy.port" type="number" class="form-control ms-2" style="width: 100px;" required min="1" max="65535" :placeholder="$t('Port')">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ export default {
|
|||||||
Confirm,
|
Confirm,
|
||||||
},
|
},
|
||||||
props: {},
|
props: {},
|
||||||
emits: ["added"],
|
emits: [ "added" ],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
model: null,
|
model: null,
|
||||||
|
@@ -145,7 +145,7 @@ export default {
|
|||||||
|
|
||||||
.mobile {
|
.mobile {
|
||||||
.item {
|
.item {
|
||||||
padding: 13px 0 10px 0;
|
padding: 13px 0 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
@@ -49,7 +49,7 @@ export default {
|
|||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import "../assets/vars.scss";
|
@import "../assets/vars.scss";
|
||||||
|
|
||||||
h5:after {
|
h5::after {
|
||||||
content: "";
|
content: "";
|
||||||
display: block;
|
display: block;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
|
@@ -46,7 +46,7 @@
|
|||||||
<input v-model="token" type="text" maxlength="6" class="form-control">
|
<input v-model="token" type="text" maxlength="6" class="form-control">
|
||||||
<button class="btn btn-outline-primary" type="button" @click="verifyToken()">{{ $t("Verify Token") }}</button>
|
<button class="btn btn-outline-primary" type="button" @click="verifyToken()">{{ $t("Verify Token") }}</button>
|
||||||
</div>
|
</div>
|
||||||
<p v-show="tokenValid" class="mt-2" style="color: green">{{ $t("tokenValidSettingsMsg") }}</p>
|
<p v-show="tokenValid" class="mt-2" style="color: green;">{{ $t("tokenValidSettingsMsg") }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -22,33 +22,33 @@ export default {
|
|||||||
return Math.round(this.$root.uptimeList[key] * 10000) / 100 + "%";
|
return Math.round(this.$root.uptimeList[key] * 10000) / 100 + "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.$t("notAvailableShort")
|
return this.$t("notAvailableShort");
|
||||||
},
|
},
|
||||||
|
|
||||||
color() {
|
color() {
|
||||||
if (this.lastHeartBeat.status === 0) {
|
if (this.lastHeartBeat.status === 0) {
|
||||||
return "danger"
|
return "danger";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lastHeartBeat.status === 1) {
|
if (this.lastHeartBeat.status === 1) {
|
||||||
return "primary"
|
return "primary";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lastHeartBeat.status === 2) {
|
if (this.lastHeartBeat.status === 2) {
|
||||||
return "warning"
|
return "warning";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "secondary"
|
return "secondary";
|
||||||
},
|
},
|
||||||
|
|
||||||
lastHeartBeat() {
|
lastHeartBeat() {
|
||||||
if (this.monitor.id in this.$root.lastHeartbeatList && this.$root.lastHeartbeatList[this.monitor.id]) {
|
if (this.monitor.id in this.$root.lastHeartbeatList && this.$root.lastHeartbeatList[this.monitor.id]) {
|
||||||
return this.$root.lastHeartbeatList[this.monitor.id]
|
return this.$root.lastHeartbeatList[this.monitor.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: -1,
|
status: -1,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
className() {
|
className() {
|
||||||
@@ -59,7 +59,7 @@ export default {
|
|||||||
return "";
|
return "";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@@ -28,5 +28,5 @@ export default {
|
|||||||
this.$parent.notification.gotifyPriority = 8;
|
this.$parent.notification.gotifyPriority = 8;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="mattermost-webhook-url" class="form-label">{{ $t("Webhook URL") }}<span style="color:red;"><sup>*</sup></span></label>
|
<label for="mattermost-webhook-url" class="form-label">{{ $t("Webhook URL") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
<input id="mattermost-webhook-url" v-model="$parent.notification.mattermostWebhookUrl" type="text" class="form-control" required>
|
<input id="mattermost-webhook-url" v-model="$parent.notification.mattermostWebhookUrl" type="text" class="form-control" required>
|
||||||
<label for="mattermost-username" class="form-label">{{ $t("Username") }}</label>
|
<label for="mattermost-username" class="form-label">{{ $t("Username") }}</label>
|
||||||
<input id="mattermost-username" v-model="$parent.notification.mattermostusername" type="text" class="form-control">
|
<input id="mattermost-username" v-model="$parent.notification.mattermostusername" type="text" class="form-control">
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<label for="mattermost-channel" class="form-label">{{ $t("Channel Name") }}</label>
|
<label for="mattermost-channel" class="form-label">{{ $t("Channel Name") }}</label>
|
||||||
<input id="mattermost-channel-name" v-model="$parent.notification.mattermostchannel" type="text" class="form-control">
|
<input id="mattermost-channel-name" v-model="$parent.notification.mattermostchannel" type="text" class="form-control">
|
||||||
<div class="form-text">
|
<div class="form-text">
|
||||||
<span style="color:red;"><sup>*</sup></span>{{ $t("Required") }}
|
<span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}
|
||||||
<i18n-t tag="p" keypath="aboutWebhooks" style="margin-top: 8px;">
|
<i18n-t tag="p" keypath="aboutWebhooks" style="margin-top: 8px;">
|
||||||
<a href="https://docs.mattermost.com/developer/webhooks-incoming.html" target="_blank">https://docs.mattermost.com/developer/webhooks-incoming.html</a>
|
<a href="https://docs.mattermost.com/developer/webhooks-incoming.html" target="_blank">https://docs.mattermost.com/developer/webhooks-incoming.html</a>
|
||||||
</i18n-t>
|
</i18n-t>
|
||||||
|
34
src/components/notifications/OneBot.vue
Normal file
34
src/components/notifications/OneBot.vue
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="onebot-http-addr" class="form-label">{{ $t("onebotHttpAddress") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<input id="HttpUrl" v-model="$parent.notification.httpAddr" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="onebot-access-token" class="form-label">AccessToken<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<input id="HttpUrl" v-model="$parent.notification.accessToken" type="text" class="form-control" required>
|
||||||
|
<div class="form-text">
|
||||||
|
<p>{{ $t("onebotSafetyTips") }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="onebot-msg-type" class="form-label">{{ $t("onebotMessageType") }}</label>
|
||||||
|
<select id="onebot-msg-type" v-model="$parent.notification.msgType" class="form-select">
|
||||||
|
<option value="group">{{ $t("onebotGroupMessage") }}</option>
|
||||||
|
<option value="private">{{ $t("onebotPrivateMessage") }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="onebot-reciever-id" class="form-label">{{ $t("onebotUserOrGroupId") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<input id="secretKey" v-model="$parent.notification.recieverId" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-text">
|
||||||
|
<i18n-t tag="p" keypath="Read more:">
|
||||||
|
<a href="https://github.com/botuniverse/onebot-11" target="_blank">https://github.com/botuniverse/onebot-11</a>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user