mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-09-12 22:47:00 +08:00
Compare commits
698 Commits
1.15.0-bet
...
1.18.3
Author | SHA1 | Date | |
---|---|---|---|
|
60460442f8 | ||
|
959ecc65ff | ||
|
c24b64921d | ||
|
c28d8ddff9 | ||
|
528a615fb2 | ||
|
b993859926 | ||
|
a5c102e750 | ||
|
64ba2dce24 | ||
|
e5145a209a | ||
|
12696dd53e | ||
|
d565320f74 | ||
|
f1a9046193 | ||
|
afbc283423 | ||
|
16b2cf0e89 | ||
|
c538983b87 | ||
|
0686757160 | ||
|
25ea99a436 | ||
|
c2c3f981bc | ||
|
2c237e9c03 | ||
|
3e85893bdd | ||
|
543a74ecab | ||
|
62ad2f9bb4 | ||
|
7672057319 | ||
|
0f99d49a27 | ||
|
d93f7b33be | ||
|
894aeaea0a | ||
|
97dc8eba13 | ||
|
d39a4770e0 | ||
|
f6ac09b751 | ||
|
9c1ad4f8c6 | ||
|
8595824b5d | ||
|
da34685019 | ||
|
0cf28c2025 | ||
|
ed7bc0e6d1 | ||
|
6a3eccf6a6 | ||
|
97de3959cd | ||
|
63e408f4f2 | ||
|
a3b1123e82 | ||
|
2e54dee817 | ||
|
ceeb47bf82 | ||
|
929d238106 | ||
|
bef9cb6a5f | ||
|
4157c7d546 | ||
|
c3eef28443 | ||
|
443235b20b | ||
|
35810e299d | ||
|
b03624b7e3 | ||
|
dcbd9c12cf | ||
|
83ca74eba7 | ||
|
c6cf600722 | ||
|
22ef8ff751 | ||
|
565e9233fe | ||
|
9a7c2d562a | ||
|
c4cb825fef | ||
|
3193533a60 | ||
|
1f1825dbff | ||
|
e4e47c3976 | ||
|
1c4e97439c | ||
|
d23085cddc | ||
|
f96bad1629 | ||
|
38c45a3fe3 | ||
|
e815e51608 | ||
|
bec3b0d2dc | ||
|
2d5096317f | ||
|
1c3da995e3 | ||
|
db6fdf5e26 | ||
|
fce175cad6 | ||
|
b673cfbe94 | ||
|
0ae8010156 | ||
|
527e479f2d | ||
|
d63022676a | ||
|
08fdbeaa75 | ||
|
0dd858d516 | ||
|
104d521633 | ||
|
839183aa85 | ||
|
e83ff0d679 | ||
|
80c1054877 | ||
|
f503488618 | ||
|
7577477ae8 | ||
|
3ea57600ba | ||
|
b22176d218 | ||
|
7f9e291206 | ||
|
197d44981f | ||
|
97e9bc7705 | ||
|
87b72191e5 | ||
|
8827176390 | ||
|
42969d11ee | ||
|
7b8f9c7655 | ||
|
e90a4f1f34 | ||
|
1e5376d80b | ||
|
dad2ec1164 | ||
|
676e64c77d | ||
|
0244507a07 | ||
|
6601e9bbba | ||
|
9589fcfdef | ||
|
ce3fe9f0a6 | ||
|
995276badc | ||
|
9e62a6ec7d | ||
|
75deab2cc5 | ||
|
50f7b39672 | ||
|
6a802bf68c | ||
|
be8caa0d1e | ||
|
d1aa9cfbcc | ||
|
808efb267f | ||
|
252d6ea9c9 | ||
|
7d12cd0d42 | ||
|
cf10e26aff | ||
|
53135641f3 | ||
|
c0fe2d54f9 | ||
|
d8303f1f4d | ||
|
ee14ab6751 | ||
|
fd2df562b1 | ||
|
87e45b21fa | ||
|
626accedee | ||
|
b890812411 | ||
|
cbc0b9c553 | ||
|
c2472bf750 | ||
|
e0cdc3e7c5 | ||
|
84fad93555 | ||
|
b9b00050dd | ||
|
064fe50e38 | ||
|
a8ea76e8a1 | ||
|
2975204a0a | ||
|
31150642cd | ||
|
3c5c49c16d | ||
|
584d52517a | ||
|
82dd9a7c16 | ||
|
d44663c57c | ||
|
e557545c97 | ||
|
055948d1b9 | ||
|
4ac80cfc02 | ||
|
af89c4d8ae | ||
|
40b9d9ed17 | ||
|
65e6921a41 | ||
|
04fc124928 | ||
|
5c25354682 | ||
|
2aad2510b7 | ||
|
fac2f1cbc6 | ||
|
8bc3651a7d | ||
|
684d0a7eb8 | ||
|
b3712ee1cc | ||
|
af94424283 | ||
|
728e811969 | ||
|
a6007adce3 | ||
|
30b72d81cf | ||
|
de6e1e7ddd | ||
|
2af754b5e8 | ||
|
3b3763351b | ||
|
9a488d6968 | ||
|
aca395cea1 | ||
|
a49faf09b9 | ||
|
d0d1e0de28 | ||
|
70aa8fe453 | ||
|
19d8761305 | ||
|
d6a113396a | ||
|
fb3fe17c28 | ||
|
71d62ee151 | ||
|
82b9bfc5a0 | ||
|
f016caa513 | ||
|
6e29feffd3 | ||
|
2389b604fe | ||
|
a3b1612938 | ||
|
a07f54f35b | ||
|
b777c0c3e4 | ||
|
bea8679788 | ||
|
f091e92c70 | ||
|
a0843745f9 | ||
|
16d6885a88 | ||
|
4d975a5bd5 | ||
|
96ec46765b | ||
|
96971f6776 | ||
|
ffb1a948fe | ||
|
4e4156285a | ||
|
1223b56205 | ||
|
8ced61697a | ||
|
f3322398e5 | ||
|
b76ca59dfe | ||
|
554b0d2bc3 | ||
|
4575f31094 | ||
|
df7f0b078d | ||
|
d8253405b4 | ||
|
56c6c0c6f1 | ||
|
b16cb6a337 | ||
|
694b4cadb3 | ||
|
75f6ff8b58 | ||
|
1062e629c5 | ||
|
13f7db655b | ||
|
60e7824ff0 | ||
|
fb3b407577 | ||
|
d54c652d26 | ||
|
f1bcecb0c6 | ||
|
88afd662db | ||
|
e356d5f623 | ||
|
0d098b0958 | ||
|
239611a016 | ||
|
2ccf1fe41b | ||
|
77340cf0d2 | ||
|
c412c66aeb | ||
|
c4a2ce4e78 | ||
|
a382f811f4 | ||
|
986c03aecd | ||
|
31c388a6e3 | ||
|
9a8b484ee8 | ||
|
17ed051401 | ||
|
8f7b7e74c9 | ||
|
9cd060c6c3 | ||
|
1999541802 | ||
|
65d71e5db0 | ||
|
2073f0c284 | ||
|
25d711e683 | ||
|
77a7801992 | ||
|
525607f49e | ||
|
8613d3ffa9 | ||
|
d44d984a46 | ||
|
d362372b05 | ||
|
3fa5dfc873 | ||
|
6ce012c9a1 | ||
|
f33b6de157 | ||
|
e0a2ed2523 | ||
|
a78cb7ab42 | ||
|
278d9f5689 | ||
|
2ad79a68b9 | ||
|
d29955f3ba | ||
|
c4125a8334 | ||
|
0a368ff553 | ||
|
27dbc021b4 | ||
|
1b120f8a6f | ||
|
6f57c4195a | ||
|
baa592bce3 | ||
|
42e30de209 | ||
|
624678826d | ||
|
e8c3807594 | ||
|
4d8e755400 | ||
|
9b92a02968 | ||
|
6418f99f1a | ||
|
93ac4e1b96 | ||
|
f65bef686c | ||
|
2f26864892 | ||
|
a802f7ebed | ||
|
e5e8db6c38 | ||
|
303738b7c2 | ||
|
dddd2c0042 | ||
|
515095ecfb | ||
|
83284b6d2c | ||
|
1af6d33fcd | ||
|
e36b65c2df | ||
|
8542e6cbb9 | ||
|
5dd197374d | ||
|
f84ae82983 | ||
|
9650418ef7 | ||
|
b546c846ae | ||
|
b5cbc6f5f6 | ||
|
f8def5aa6f | ||
|
6f01a448ad | ||
|
5dd3d32d77 | ||
|
ff8bba6863 | ||
|
ed1f88a852 | ||
|
0ecaa2cbd7 | ||
|
3c3dc05621 | ||
|
1f5466a3e8 | ||
|
d5da5af174 | ||
|
c36d9a4b8b | ||
|
a7063b8aca | ||
|
0a8046c98e | ||
|
7ba717ee55 | ||
|
ea400ac35f | ||
|
15db2c060d | ||
|
89717495dc | ||
|
7b710af12c | ||
|
5b278ca500 | ||
|
f1d24782f8 | ||
|
b97019eea8 | ||
|
d65abe5b8c | ||
|
c4e2d67d17 | ||
|
bcd616a4d0 | ||
|
7533041696 | ||
|
7b0deb5e20 | ||
|
b4a4171178 | ||
|
012be23509 | ||
|
dd09351c8e | ||
|
ffad990ca4 | ||
|
47e82ed83a | ||
|
e1f766756f | ||
|
4b2a465c94 | ||
|
edcdedcaae | ||
|
f7afe121e3 | ||
|
945288f0c0 | ||
|
ac27e6e2af | ||
|
869a040011 | ||
|
42848bcd2e | ||
|
a3b94aa532 | ||
|
fdbdf83a0d | ||
|
81d5360520 | ||
|
8f1e193de3 | ||
|
ac449ec1c2 | ||
|
da91317760 | ||
|
bef0febede | ||
|
7d63b700e1 | ||
|
0223f86a2a | ||
|
c170b1edd0 | ||
|
5943514a92 | ||
|
62acd2edb1 | ||
|
483cbfb636 | ||
|
660005b143 | ||
|
98f3c126e5 | ||
|
6995a29980 | ||
|
cf2ca71dee | ||
|
0bd1c42080 | ||
|
9b21b86e70 | ||
|
f723930d11 | ||
|
e425e408a2 | ||
|
c690d1c3a1 | ||
|
8abbc9fd15 | ||
|
af7c905b44 | ||
|
0e8f6d2f85 | ||
|
d16be6fb7d | ||
|
f25ca96308 | ||
|
6682839ec8 | ||
|
817f6db4fd | ||
|
dc2302244f | ||
|
7a27d3752a | ||
|
f0e8f34aeb | ||
|
54b9698a05 | ||
|
69273a6c41 | ||
|
6424fe77ab | ||
|
fa60672cce | ||
|
6e43ef1dd3 | ||
|
f4f2b8ddb8 | ||
|
436bc13aeb | ||
|
b72a279361 | ||
|
a28ef56553 | ||
|
7f432bd916 | ||
|
f570d41142 | ||
|
1c4ddaeddf | ||
|
d4485fe62f | ||
|
e1681ce370 | ||
|
69d6633e6d | ||
|
55a6e5af42 | ||
|
252709ff49 | ||
|
774fe58ddc | ||
|
5f347b10ba | ||
|
f442507cab | ||
|
a23ab9d1de | ||
|
404923b7c8 | ||
|
a41023ca2a | ||
|
817c941489 | ||
|
5f6347d277 | ||
|
fbfa5a33ed | ||
|
04e22f17a9 | ||
|
aa398948da | ||
|
11243a6ca1 | ||
|
54548e34ed | ||
|
87428231ad | ||
|
a68d945cdc | ||
|
2c0180f323 | ||
|
4fdaa1abb6 | ||
|
6ee7b3696a | ||
|
cc258dce14 | ||
|
fb420fa1b1 | ||
|
a707b51053 | ||
|
a927f5cd15 | ||
|
0e28707307 | ||
|
c94dcf1533 | ||
|
b0476cfb5b | ||
|
2170229031 | ||
|
213aca4fc3 | ||
|
2b42c3c828 | ||
|
d939d03690 | ||
|
07888e43f1 | ||
|
c6c1bb5b5c | ||
|
3210264e28 | ||
|
54e948c2ca | ||
|
80094ec4e1 | ||
|
091158cfe7 | ||
|
abb6ce2366 | ||
|
e4ad8cbfc8 | ||
|
a674caa520 | ||
|
179e3569b5 | ||
|
43527f2f40 | ||
|
26ff6f45a0 | ||
|
c095767f4a | ||
|
ffb7ba176c | ||
|
857e88b27e | ||
|
90fe25e8ad | ||
|
46a593534b | ||
|
7a4b54f4ee | ||
|
ea10d89f51 | ||
|
7f46223d68 | ||
|
df4ce811d9 | ||
|
30858ab038 | ||
|
e25d406fa5 | ||
|
10e16782b1 | ||
|
107a44885c | ||
|
ef9f66fad9 | ||
|
e9e78c26e5 | ||
|
46dae99695 | ||
|
edd9bf3887 | ||
|
ab4edf2092 | ||
|
334cb57fed | ||
|
cfa5b551a5 | ||
|
46ee149b70 | ||
|
0a8c922abf | ||
|
058e5442af | ||
|
ea1725737f | ||
|
5566b038c8 | ||
|
5830f1e0b5 | ||
|
35b8e89457 | ||
|
d892b2c549 | ||
|
f23baf9c22 | ||
|
54184350a4 | ||
|
14dbe7c334 | ||
|
122e6a842b | ||
|
77ef22bdb4 | ||
|
59f983d506 | ||
|
71f031c14e | ||
|
6ae2a48584 | ||
|
7373747906 | ||
|
9d87f8d390 | ||
|
73b965c867 | ||
|
751e5ac477 | ||
|
93e5023ead | ||
|
32cfd411f8 | ||
|
a9f3142cee | ||
|
b7ba6330db | ||
|
4c3aa20eb0 | ||
|
f779c6286a | ||
|
da99a57560 | ||
|
42d68edab0 | ||
|
019d638767 | ||
|
9fc5a3329f | ||
|
23c4ece2a5 | ||
|
175556f9fc | ||
|
398219f847 | ||
|
7a50f0e3f3 | ||
|
4178b003a2 | ||
|
8ede6d888f | ||
|
cec0521834 | ||
|
73b603dd10 | ||
|
92a43e1f30 | ||
|
0cf395dfc3 | ||
|
749ca6f4a8 | ||
|
ef73af391f | ||
|
44f6fca945 | ||
|
23ce7c6623 | ||
|
c346ea7864 | ||
|
f0ad32a252 | ||
|
5720017fb4 | ||
|
b7dc8e3ef8 | ||
|
5bba19f866 | ||
|
e198f2f1ab | ||
|
f91e5b98f9 | ||
|
87f933df4f | ||
|
332b9ab248 | ||
|
7cc89979f0 | ||
|
398ecb7666 | ||
|
668e97c5a9 | ||
|
90473e7924 | ||
|
fdd781b081 | ||
|
373bd9b962 | ||
|
66971deaf4 | ||
|
59be9bb971 | ||
|
8077744c60 | ||
|
c5faf709b8 | ||
|
7da9f139c1 | ||
|
7acbfd2474 | ||
|
9f493bbec7 | ||
|
5bf58cc6c4 | ||
|
d344914ca0 | ||
|
201a25c659 | ||
|
b680371746 | ||
|
e488e2dc0a | ||
|
4e3258579d | ||
|
aa8ea6d398 | ||
|
cd3fbc80b4 | ||
|
bb7d67f717 | ||
|
8b0813ceff | ||
|
91178ce6a5 | ||
|
429ad384d0 | ||
|
24e52726b2 | ||
|
e0a0a5db4c | ||
|
93050208bb | ||
|
98ee9caf2c | ||
|
8e99cbf426 | ||
|
cbfecab850 | ||
|
25cc54bf72 | ||
|
3700b16c5b | ||
|
4b9dc2890d | ||
|
f9004bcbed | ||
|
bc174c3325 | ||
|
4c2753af46 | ||
|
c6ba5b621c | ||
|
96536ae391 | ||
|
ba46544772 | ||
|
5c852db1cf | ||
|
069d3765f0 | ||
|
15820c6937 | ||
|
000cbeb0ce | ||
|
e118d59ac8 | ||
|
39aa0a7f07 | ||
|
a12dffd1bc | ||
|
410805052e | ||
|
02a8147f22 | ||
|
d962ab7a1c | ||
|
63c8d24d6f | ||
|
254a6bfd36 | ||
|
29f3cbe8c6 | ||
|
53b98ad3e4 | ||
|
dbd7c087e0 | ||
|
d0546afe71 | ||
|
272956025c | ||
|
db50ba91cc | ||
|
42ea3fb412 | ||
|
9f8b3151d8 | ||
|
73e38a13d2 | ||
|
f4515ad8c5 | ||
|
369477b4b9 | ||
|
2347a01f7c | ||
|
c114c053d6 | ||
|
ae2c49a729 | ||
|
b9e72b9645 | ||
|
5a069b278d | ||
|
65ea2e6aeb | ||
|
e82fc1df61 | ||
|
7dd5f5ea0d | ||
|
45da7c5431 | ||
|
26230a3d3a | ||
|
82aa52b330 | ||
|
fa7d15cf64 | ||
|
d7f16908d8 | ||
|
bddd5de22b | ||
|
6333231f1b | ||
|
60538036c6 | ||
|
0ba5d031d0 | ||
|
66e4c89897 | ||
|
d210548ae8 | ||
|
023db1450d | ||
|
824c16a07c | ||
|
09fdef9bdc | ||
|
7078b06272 | ||
|
d3bd2976c5 | ||
|
db646aa40b | ||
|
3c01e8732c | ||
|
b50f1bb7e8 | ||
|
a3baa3c149 | ||
|
2adb142ae2 | ||
|
752415dae6 | ||
|
1687de163c | ||
|
245b13d3c8 | ||
|
d6c3fdb6fb | ||
|
372bf57e9f | ||
|
39df4eea92 | ||
|
03e6f0a6c8 | ||
|
dcec53a755 | ||
|
ce17ed163e | ||
|
3019d5dd64 | ||
|
dcdbb7be8b | ||
|
b874ea8b28 | ||
|
1e595eaa76 | ||
|
5fbfacf5ce | ||
|
d39dc94496 | ||
|
94ada36dfa | ||
|
4114f43b48 | ||
|
4c8da89c36 | ||
|
db3ef3805b | ||
|
751924b335 | ||
|
edec1024b5 | ||
|
5f9f29f527 | ||
|
13a3dd91bb | ||
|
d1a3cd047a | ||
|
d9c5a7812c | ||
|
484d4a20ab | ||
|
3582e99770 | ||
|
2197b98444 | ||
|
b641c8a878 | ||
|
9130b3762c | ||
|
587faecf87 | ||
|
46da5e51be | ||
|
1eecdec2d9 | ||
|
e6a1719ab4 | ||
|
7d5e7a577d | ||
|
64a33d7455 | ||
|
09e61d9d63 | ||
|
9996ba1636 | ||
|
c2f6c5b42e | ||
|
0083485d4c | ||
|
630bb03d9c | ||
|
7ed8ae9f7c | ||
|
4ddbf71920 | ||
|
068b920553 | ||
|
f1c83bb838 | ||
|
303a226ab7 | ||
|
c7ec9a07e2 | ||
|
052fde5a24 | ||
|
d6b591a513 | ||
|
3d04befc1f | ||
|
d3f0bdb440 | ||
|
6d22ebedca | ||
|
19933bbd99 | ||
|
60f8ab7285 | ||
|
b7e2489d22 | ||
|
e56ac7b03b | ||
|
aafcbaf098 | ||
|
4d4d04adbd | ||
|
03b2d8d521 | ||
|
f8c9472ea2 | ||
|
4e28ad4ac2 | ||
|
06f326e49e | ||
|
07c0801ad5 | ||
|
8cefc96c78 | ||
|
b326a69838 | ||
|
e103ac8335 | ||
|
a391576285 | ||
|
e0966e55c8 | ||
|
59d9891105 | ||
|
f8f19d8dc5 | ||
|
a3d79a93e9 | ||
|
bdc23a3f57 | ||
|
7c13b1b6cb | ||
|
10f6a3c4f5 | ||
|
cd7c2beca6 | ||
|
8ee99760ec | ||
|
cb55e23718 | ||
|
200fdfb808 | ||
|
29d2d95c71 | ||
|
b782b25e17 | ||
|
919393cac9 | ||
|
18925293fb | ||
|
17d4003e5c | ||
|
cefb5bb60a | ||
|
9bf3b3a0f4 | ||
|
e2c45f93bf | ||
|
addf75daa7 | ||
|
359a490ae3 | ||
|
cd38dd3f68 | ||
|
f712fe85e5 | ||
|
45f44b183d | ||
|
5a209c74e1 | ||
|
60c63cc18e | ||
|
6fb66728e6 | ||
|
a680331dd7 | ||
|
288ed1e3ca | ||
|
8c8eeaf627 | ||
|
b893d50e45 | ||
|
361e44ad6a | ||
|
0765f05090 | ||
|
2638d68c97 | ||
|
e38742a2d0 | ||
|
1b1e0f6dd9 | ||
|
0961c6d9b3 | ||
|
ce7d8c38c5 | ||
|
af44b0beab | ||
|
84a0b24448 | ||
|
a4be651118 | ||
|
d8013f31e8 | ||
|
91366ff565 | ||
|
88604845e6 | ||
|
454c1687cf | ||
|
244a7b3671 | ||
|
28be32fc68 | ||
|
97a5b400db | ||
|
ca89f84b9a | ||
|
ee90d2713f | ||
|
d446a57d42 | ||
|
855b12f435 | ||
|
f390a8caf1 | ||
|
30ce53f57c | ||
|
8c4ab9d652 | ||
|
f931e709e6 | ||
|
11e9eee09d | ||
|
65fc71e485 | ||
|
b69a8b8493 | ||
|
1ac904d6d6 | ||
|
dd3992063e | ||
|
29df70949d | ||
|
0313acd4c5 | ||
|
cd19b9fc49 | ||
|
c57b2c4d28 | ||
|
3dda5938f2 | ||
|
4818bb67d6 | ||
|
9619d31a05 | ||
|
c5cc42272f | ||
|
b0259b5592 | ||
|
f00ec4dfef | ||
|
43f8fc701c | ||
|
499042504f | ||
|
faf6719e7c | ||
|
a9d264ccfc | ||
|
df8f93f0c2 | ||
|
28c0e16a0c | ||
|
6acc9546a0 | ||
|
f455e3a454 | ||
|
7abbf421d0 | ||
|
3625915a85 | ||
|
d74404e106 | ||
|
1c5bce8afa | ||
|
8b5997691e | ||
|
35360e2069 | ||
|
3d002b3ce9 |
@@ -1,6 +1,7 @@
|
|||||||
/.idea
|
/.idea
|
||||||
/node_modules
|
/node_modules
|
||||||
/data
|
/data
|
||||||
|
/cypress
|
||||||
/out
|
/out
|
||||||
/test
|
/test
|
||||||
/kubernetes
|
/kubernetes
|
||||||
|
@@ -40,14 +40,15 @@ module.exports = {
|
|||||||
SwitchCase: 1,
|
SwitchCase: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
quotes: [ "warn", "double" ],
|
quotes: [ "error", "double" ],
|
||||||
semi: "error",
|
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/require-component-is": "off", // not allow is="style" https://github.com/vuejs/eslint-plugin-vue/issues/462#issuecomment-430234675
|
||||||
"vue/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly
|
"vue/attribute-hyphenation": "off", // This change noNL to "no-n-l" unexpectedly
|
||||||
|
"vue/multi-word-component-names": "off",
|
||||||
"no-multi-spaces": [ "error", {
|
"no-multi-spaces": [ "error", {
|
||||||
ignoreEOLComments: true,
|
ignoreEOLComments: true,
|
||||||
}],
|
}],
|
||||||
@@ -72,7 +73,7 @@ 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,
|
||||||
}],
|
}],
|
||||||
|
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,3 +1,9 @@
|
|||||||
|
⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
|
||||||
|
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma
|
||||||
|
|
||||||
|
Tick the checkbox if you understand [x]:
|
||||||
|
- [ ] I have read and understand the pull request rules.
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
Fixes #(issue)
|
Fixes #(issue)
|
||||||
@@ -20,6 +26,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)
|
||||||
|
|
||||||
|
44
.github/workflows/auto-test.yml
vendored
44
.github/workflows/auto-test.yml
vendored
@@ -11,26 +11,58 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
auto-test:
|
auto-test:
|
||||||
|
needs: [ check-linters ]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||||
node-version: [14.x, 16.x, 17.x]
|
node: [ 14, 16, 17, 18 ]
|
||||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- run: git config --global core.autocrlf false # Mainly for Windows
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node }}
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node }}
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
- run: npm run install-legacy
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm test
|
- run: npm test
|
||||||
env:
|
env:
|
||||||
HEADLESS_TEST: 1
|
HEADLESS_TEST: 1
|
||||||
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
|
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
|
||||||
|
check-linters:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Use Node.js 14
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
cache: 'npm'
|
||||||
|
- run: npm install
|
||||||
|
- run: npm run lint
|
||||||
|
|
||||||
|
e2e-tests:
|
||||||
|
needs: [ check-linters ]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Use Node.js 14
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
cache: 'npm'
|
||||||
|
- run: npm install
|
||||||
|
- run: npm run build
|
||||||
|
- run: npm run cy:test
|
||||||
|
24
.github/workflows/stale-bot.yml
vendored
Normal file
24
.github/workflows/stale-bot.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: 'Automatically close stale issues and PRs'
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 */6 * * *'
|
||||||
|
#Run every 6 hours
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
stale:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v5
|
||||||
|
with:
|
||||||
|
stale-issue-message: 'We are clearing up our old issues and your ticket has been open for 3 months with no activity. Remove stale label or comment or this will be closed in 2 days.'
|
||||||
|
stale-pr-message: 'We are clearing up our old Pull Requests and yours has been open for 3 months with no activity. Remove stale label or comment or this will be closed in 2 days.'
|
||||||
|
close-issue-message: 'This issue was closed because it has been stalled for 2 days with no activity.'
|
||||||
|
close-pr-message: 'This PR was closed because it has been stalled for 2 days with no activity.'
|
||||||
|
days-before-stale: 90
|
||||||
|
days-before-close: 2
|
||||||
|
exempt-issue-labels: 'News,Medium,High,discussion,bug,doc,feature-request'
|
||||||
|
exempt-pr-labels: 'awaiting-approval,work-in-progress,enhancement,feature-request'
|
||||||
|
exempt-issue-assignees: 'louislam'
|
||||||
|
exempt-pr-assignees: 'louislam'
|
||||||
|
operations-per-run: 200
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,3 +13,6 @@ dist-ssr
|
|||||||
/out
|
/out
|
||||||
/tmp
|
/tmp
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
cypress/videos
|
||||||
|
cypress/screenshots
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
"declaration-empty-line-before": null,
|
"declaration-empty-line-before": null,
|
||||||
"alpha-value-notation": "number",
|
"alpha-value-notation": "number",
|
||||||
"color-function-notation": "legacy",
|
"color-function-notation": "legacy",
|
||||||
"shorthand-property-no-redundant-values": null
|
"shorthand-property-no-redundant-values": null,
|
||||||
|
"color-hex-length": null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,24 +27,37 @@ The frontend code build into "dist" directory. The server (express.js) exposes t
|
|||||||
|
|
||||||
## Can I create a pull request for Uptime Kuma?
|
## Can I create a pull request for Uptime Kuma?
|
||||||
|
|
||||||
⚠️ 2022-03-02 Update:
|
Yes or no, it depends on what you will try to do. Since I don't want to waste your time, be sure to **create an empty draft pull request or open an issue, so we can discuss first**. Especially for a large pull request or you don't know it will be merged or not.
|
||||||
|
|
||||||
Since I found that merging pull requests is a pretty heavy task for me, I try to rearrange it.
|
Here are some references:
|
||||||
|
|
||||||
✅ Accept:
|
✅ Usually Accept:
|
||||||
- Bug/Security fix
|
- Bug/Security fix
|
||||||
- Translations
|
- Translations
|
||||||
- Adding notification providers
|
- Adding notification providers
|
||||||
|
|
||||||
❌ Avoid:
|
⚠️ Discussion First
|
||||||
- Large pull requests
|
- Large pull requests
|
||||||
- New big features
|
- New features
|
||||||
|
|
||||||
|
❌ Won't Merge
|
||||||
|
- Do not pass auto test
|
||||||
|
- Any breaking changes
|
||||||
|
- Duplicated pull request
|
||||||
|
- Buggy
|
||||||
|
- UI/UX is not close to Uptime Kuma
|
||||||
|
- Existing logic is completely modified or deleted for no reason
|
||||||
|
- A function that is completely out of scope
|
||||||
|
- Unnecessary large code changes (Hard to review, causes code conflicts to other pull requests)
|
||||||
|
|
||||||
|
I will mark your pull request in the [milestones](https://github.com/louislam/uptime-kuma/milestones), if I am plan to review and merge it.
|
||||||
|
|
||||||
|
Also, please don't rush or ask for ETA, because I have to understand the pull request, make sure it is no breaking changes and stick to my vision of this project, especially for large pull requests.
|
||||||
|
|
||||||
My long story here: https://www.reddit.com/r/UptimeKuma/comments/t1t6or/comment/hynyijx/
|
|
||||||
|
|
||||||
### Recommended Pull Request Guideline
|
### Recommended Pull Request Guideline
|
||||||
|
|
||||||
Before deep into coding, disscussion first is preferred. Creating an empty pull request for disscussion would be recommended.
|
Before deep into coding, discussion first is preferred. Creating an empty pull request for discussion would be recommended.
|
||||||
|
|
||||||
1. Fork the project
|
1. Fork the project
|
||||||
1. Clone your fork repo to local
|
1. Clone your fork repo to local
|
||||||
@@ -57,41 +70,36 @@ Before deep into coding, disscussion first is preferred. Creating an empty pull
|
|||||||
1. Click "Change to draft"
|
1. Click "Change to draft"
|
||||||
1. Discussion
|
1. Discussion
|
||||||
|
|
||||||
#### ❌ Won't Merge
|
|
||||||
|
|
||||||
- Any breaking changes
|
|
||||||
- Duplicated pull request
|
|
||||||
- Buggy
|
|
||||||
- Existing logic is completely modified or deleted
|
|
||||||
- A function that is completely out of scope
|
|
||||||
|
|
||||||
## Project Styles
|
## Project Styles
|
||||||
|
|
||||||
I personally do not like something need to learn so much and need to config so much before you can finally start the app.
|
I personally do not like something need to learn so much and need to config so much before you can finally start the app.
|
||||||
|
|
||||||
- Easy to install for non-Docker users, no native build dependency is needed (at least for x86_64), no extra config, no extra effort to get it run
|
- Easy to install for non-Docker users, no native build dependency is needed (at least for x86_64), no extra config, no extra effort to get it run
|
||||||
- Single container for Docker users, no very complex docker-compose file. Just map the volume and expose the port, then good to go
|
- Single container for Docker users, no very complex docker-compose file. Just map the volume and expose the port, then good to go
|
||||||
- Settings should be configurable in the frontend. Env var is not encouraged.
|
- Settings should be configurable in the frontend. Environment variable is not encouraged, unless it is related to startup such as `DATA_DIR`.
|
||||||
- Easy to use
|
- Easy to use
|
||||||
|
- The web UI styling should be consistent and nice.
|
||||||
|
|
||||||
## Coding Styles
|
## Coding Styles
|
||||||
|
|
||||||
- 4 spaces indentation
|
- 4 spaces indentation
|
||||||
- Follow `.editorconfig`
|
- Follow `.editorconfig`
|
||||||
- Follow ESLint
|
- Follow ESLint
|
||||||
|
- Methods and functions should be documented with JSDoc
|
||||||
|
|
||||||
## Name convention
|
## Name convention
|
||||||
|
|
||||||
- Javascript/Typescript: camelCaseType
|
- Javascript/Typescript: camelCaseType
|
||||||
- SQLite: underscore_type
|
- SQLite: snake_case (Underscore)
|
||||||
- CSS/SCSS: dash-type
|
- CSS/SCSS: kebab-case (Dash)
|
||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
- Node.js >= 14
|
- Node.js >= 14
|
||||||
|
- NPM >= 8.5
|
||||||
- Git
|
- Git
|
||||||
- IDE that supports ESLint and EditorConfig (I am using IntelliJ IDEA)
|
- IDE that supports ESLint and EditorConfig (I am using IntelliJ IDEA)
|
||||||
- A SQLite tool (SQLite Expert Personal is suggested)
|
- A SQLite GUI tool (SQLite Expert Personal is suggested)
|
||||||
|
|
||||||
## Install dependencies
|
## Install dependencies
|
||||||
|
|
||||||
@@ -99,39 +107,45 @@ I personally do not like something need to learn so much and need to config so m
|
|||||||
npm ci
|
npm ci
|
||||||
```
|
```
|
||||||
|
|
||||||
## How to start the Backend Dev Server
|
## Dev Server
|
||||||
|
|
||||||
(2021-09-23 Update)
|
(2022-04-26 Update)
|
||||||
|
|
||||||
|
We can start the frontend dev server and the backend dev server in one command.
|
||||||
|
|
||||||
|
Port `3000` and port `3001` will be used.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run start-server-dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Backend Server
|
||||||
|
|
||||||
It binds to `0.0.0.0:3001` by default.
|
It binds to `0.0.0.0:3001` by default.
|
||||||
|
|
||||||
### Backend Details
|
|
||||||
|
|
||||||
It is mainly a socket.io app + express.js.
|
It is mainly a socket.io app + express.js.
|
||||||
|
|
||||||
express.js is just used for serving the frontend built files (index.html, .js and .css etc.)
|
express.js is used for:
|
||||||
|
- entry point such as redirecting to a status page or the dashboard
|
||||||
|
- serving the frontend built files (index.html, .js and .css etc.)
|
||||||
|
- serving internal APIs of status page
|
||||||
|
|
||||||
|
|
||||||
|
### Structure in /server/
|
||||||
|
|
||||||
- model/ (Object model, auto mapping to the database table name)
|
- model/ (Object model, auto mapping to the database table name)
|
||||||
- modules/ (Modified 3rd-party modules)
|
- modules/ (Modified 3rd-party modules)
|
||||||
- notification-providers/ (individual notification logic)
|
- notification-providers/ (individual notification logic)
|
||||||
- routers/ (Express Routers)
|
- routers/ (Express Routers)
|
||||||
- socket-handler (Socket.io Handlers)
|
- socket-handler (Socket.io Handlers)
|
||||||
- server.js (Server main logic)
|
- server.js (Server entry point and main logic)
|
||||||
|
|
||||||
## How to start the Frontend Dev Server
|
## Frontend Dev Server
|
||||||
|
|
||||||
1. Set the env var `NODE_ENV` to "development".
|
It binds to `0.0.0.0:3000` by default. Frontend dev server is used for development only.
|
||||||
2. Start the frontend dev server by the following command.
|
|
||||||
|
|
||||||
```bash
|
For production, it is not used. It will be compiled to `dist` directory instead.
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
It binds to `0.0.0.0:3000` by default.
|
|
||||||
|
|
||||||
You can use Vue.js devtools Chrome extension for debugging.
|
You can use Vue.js devtools Chrome extension for debugging.
|
||||||
|
|
||||||
@@ -167,7 +181,18 @@ npm test
|
|||||||
|
|
||||||
By default, the Chromium window will be shown up during the test. Specifying `HEADLESS_TEST=1` for terminal environments.
|
By default, the Chromium window will be shown up during the test. Specifying `HEADLESS_TEST=1` for terminal environments.
|
||||||
|
|
||||||
## Update Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
Both frontend and backend share the same package.json. However, the frontend dependencies are eventually not used in the production environment, because it is usually also baked into dist files. So:
|
||||||
|
|
||||||
|
- Frontend dependencies = "devDependencies"
|
||||||
|
- Examples: vue, chart.js
|
||||||
|
- Backend dependencies = "dependencies"
|
||||||
|
- Examples: socket.io, sqlite3
|
||||||
|
- Development dependencies = "devDependencies"
|
||||||
|
- Examples: eslint, sass
|
||||||
|
|
||||||
|
### Update Dependencies
|
||||||
|
|
||||||
Install `ncu`
|
Install `ncu`
|
||||||
https://github.com/raineorshine/npm-check-updates
|
https://github.com/raineorshine/npm-check-updates
|
||||||
|
42
README.md
42
README.md
@@ -15,22 +15,24 @@ It is a self-hosted monitoring tool like "Uptime Robot".
|
|||||||
|
|
||||||
Try it!
|
Try it!
|
||||||
|
|
||||||
https://demo.uptime.kuma.pet
|
- Tokyo Demo Server: https://demo.uptime.kuma.pet (Sponsored by [Uptime Kuma Sponsors](https://github.com/louislam/uptime-kuma#%EF%B8%8F-sponsors))
|
||||||
|
- Europe Demo Server: https://demo.uptime-kuma.karimi.dev:27000 (Provided by [@mhkarimi1383](https://github.com/mhkarimi1383))
|
||||||
|
|
||||||
It is a temporary live demo, all data will be deleted after 10 minutes. The server is located in Tokyo, so if you live far from there, it may affect your experience. I suggest that you should install and try it out for the best demo experience.
|
It is a temporary live demo, all data will be deleted after 10 minutes. Use the one that is closer to you, but I suggest that you should install and try it out for the best demo experience.
|
||||||
|
|
||||||
VPS is sponsored by Uptime Kuma sponsors on [Open Collective](https://opencollective.com/uptime-kuma)! Thank you so much!
|
|
||||||
|
|
||||||
## ⭐ Features
|
## ⭐ Features
|
||||||
|
|
||||||
* 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 / Docker Containers.
|
||||||
* 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
|
||||||
|
|
||||||
@@ -103,7 +105,7 @@ https://github.com/louislam/uptime-kuma/milestones
|
|||||||
|
|
||||||
Project Plan:
|
Project Plan:
|
||||||
|
|
||||||
https://github.com/louislam/uptime-kuma/projects/1
|
https://github.com/users/louislam/projects/4/views/1
|
||||||
|
|
||||||
## ❤️ Sponsors
|
## ❤️ Sponsors
|
||||||
|
|
||||||
@@ -148,16 +150,30 @@ You can discuss or ask for help in [issues](https://github.com/louislam/uptime-k
|
|||||||
|
|
||||||
### Subreddit
|
### Subreddit
|
||||||
|
|
||||||
My Reddit account: louislamlam
|
My Reddit account: [u/louislamlam](https://reddit.com/u/louislamlam).
|
||||||
You can mention me if you ask a question on Reddit.
|
You can mention me if you ask a question on Reddit.
|
||||||
https://www.reddit.com/r/UptimeKuma/
|
[r/Uptime kuma](https://www.reddit.com/r/UptimeKuma/)
|
||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
|
|
||||||
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).
|
### Test Pull Requests
|
||||||
|
|
||||||
|
There are a lot of pull requests right now, but I don't have time to test them all.
|
||||||
|
|
||||||
|
If you want to help, you can check this:
|
||||||
|
https://github.com/louislam/uptime-kuma/wiki/Test-Pull-Requests
|
||||||
|
|
||||||
|
### Test 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, feel free 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.
|
### Create Pull Requests
|
||||||
|
If you want to modify Uptime Kuma, please read this guide and follow the rules here: https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md
|
||||||
|
12
SECURITY.md
12
SECURITY.md
@@ -8,15 +8,9 @@ Do not use the issue tracker or discuss it in the public as it will cause more d
|
|||||||
|
|
||||||
## Supported Versions
|
## Supported Versions
|
||||||
|
|
||||||
Use this section to tell people about which versions of your project are
|
|
||||||
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 +18,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 | ❌ |
|
||||||
|
28
config/cypress.config.js
Normal file
28
config/cypress.config.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const { defineConfig } = require("cypress");
|
||||||
|
|
||||||
|
module.exports = defineConfig({
|
||||||
|
projectId: "vyjuem",
|
||||||
|
e2e: {
|
||||||
|
experimentalStudio: true,
|
||||||
|
setupNodeEvents(on, config) {
|
||||||
|
|
||||||
|
},
|
||||||
|
fixturesFolder: "test/cypress/fixtures",
|
||||||
|
screenshotsFolder: "test/cypress/screenshots",
|
||||||
|
videosFolder: "test/cypress/videos",
|
||||||
|
downloadsFolder: "test/cypress/downloads",
|
||||||
|
supportFile: "test/cypress/support/e2e.js",
|
||||||
|
baseUrl: "http://localhost:3002",
|
||||||
|
defaultCommandTimeout: 10000,
|
||||||
|
pageLoadTimeout: 60000,
|
||||||
|
viewportWidth: 1920,
|
||||||
|
viewportHeight: 1080,
|
||||||
|
specPattern: [
|
||||||
|
"test/cypress/e2e/setup.cy.js",
|
||||||
|
"test/cypress/e2e/**/*.js"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
env: {
|
||||||
|
baseUrl: "http://localhost:3002",
|
||||||
|
},
|
||||||
|
});
|
@@ -1,33 +0,0 @@
|
|||||||
const PuppeteerEnvironment = require("jest-environment-puppeteer");
|
|
||||||
const util = require("util");
|
|
||||||
|
|
||||||
class DebugEnv extends PuppeteerEnvironment {
|
|
||||||
async handleTestEvent(event, state) {
|
|
||||||
const ignoredEvents = [
|
|
||||||
"setup",
|
|
||||||
"add_hook",
|
|
||||||
"start_describe_definition",
|
|
||||||
"add_test",
|
|
||||||
"finish_describe_definition",
|
|
||||||
"run_start",
|
|
||||||
"run_describe_start",
|
|
||||||
"test_start",
|
|
||||||
"hook_start",
|
|
||||||
"hook_success",
|
|
||||||
"test_fn_start",
|
|
||||||
"test_fn_success",
|
|
||||||
"test_done",
|
|
||||||
"run_describe_finish",
|
|
||||||
"run_finish",
|
|
||||||
"teardown",
|
|
||||||
"test_fn_failure",
|
|
||||||
];
|
|
||||||
if (!ignoredEvents.includes(event.name)) {
|
|
||||||
console.log(
|
|
||||||
new Date().toString() + ` Unhandled event [${event.name}] ` + util.inspect(event)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = DebugEnv;
|
|
@@ -1,5 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
"rootDir": "..",
|
|
||||||
"testRegex": "./test/frontend.spec.js",
|
|
||||||
};
|
|
||||||
|
|
@@ -1,20 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
"launch": {
|
|
||||||
"dumpio": true,
|
|
||||||
"slowMo": 500,
|
|
||||||
"headless": process.env.HEADLESS_TEST || false,
|
|
||||||
"userDataDir": "./data/test-chrome-profile",
|
|
||||||
args: [
|
|
||||||
"--disable-setuid-sandbox",
|
|
||||||
"--disable-gpu",
|
|
||||||
"--disable-dev-shm-usage",
|
|
||||||
"--no-default-browser-check",
|
|
||||||
"--no-experiments",
|
|
||||||
"--no-first-run",
|
|
||||||
"--no-pings",
|
|
||||||
"--no-sandbox",
|
|
||||||
"--no-zygote",
|
|
||||||
"--single-process",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
};
|
|
@@ -1,12 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
"verbose": true,
|
|
||||||
"preset": "jest-puppeteer",
|
|
||||||
"globals": {
|
|
||||||
"__DEV__": true
|
|
||||||
},
|
|
||||||
"testRegex": "./test/e2e.spec.js",
|
|
||||||
"testEnvironment": "./config/jest-debug-env.js",
|
|
||||||
"rootDir": "..",
|
|
||||||
"testTimeout": 30000,
|
|
||||||
};
|
|
||||||
|
|
@@ -1,18 +1,38 @@
|
|||||||
import legacy from "@vitejs/plugin-legacy";
|
import legacy from "@vitejs/plugin-legacy";
|
||||||
import vue from "@vitejs/plugin-vue";
|
import vue from "@vitejs/plugin-vue";
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
|
import visualizer from "rollup-plugin-visualizer";
|
||||||
|
import viteCompression from "vite-plugin-compression";
|
||||||
|
|
||||||
const postCssScss = require("postcss-scss");
|
const postCssScss = require("postcss-scss");
|
||||||
const postcssRTLCSS = require("postcss-rtlcss");
|
const postcssRTLCSS = require("postcss-rtlcss");
|
||||||
|
|
||||||
|
const viteCompressionFilter = /\.(js|mjs|json|css|html|svg)$/i;
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
server: {
|
||||||
|
port: 3000,
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
"FRONTEND_VERSION": JSON.stringify(process.env.npm_package_version),
|
||||||
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
legacy({
|
legacy({
|
||||||
targets: [ "ie > 11" ],
|
targets: [ "since 2015" ],
|
||||||
additionalLegacyPolyfills: [ "regenerator-runtime/runtime" ]
|
}),
|
||||||
})
|
visualizer({
|
||||||
|
filename: "tmp/dist-stats.html"
|
||||||
|
}),
|
||||||
|
viteCompression({
|
||||||
|
algorithm: "gzip",
|
||||||
|
filter: viteCompressionFilter,
|
||||||
|
}),
|
||||||
|
viteCompression({
|
||||||
|
algorithm: "brotliCompress",
|
||||||
|
filter: viteCompressionFilter,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
css: {
|
css: {
|
||||||
postcss: {
|
postcss: {
|
||||||
@@ -21,4 +41,13 @@ export default defineConfig({
|
|||||||
"plugins": [ postcssRTLCSS ]
|
"plugins": [ postcssRTLCSS ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
build: {
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
manualChunks(id, { getModuleInfo, getModuleIds }) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
5
db/patch-add-clickable-status-page-link.sql
Normal file
5
db/patch-add-clickable-status-page-link.sql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
ALTER TABLE monitor_group
|
||||||
|
ADD send_url BOOLEAN DEFAULT 0 NOT NULL;
|
||||||
|
COMMIT;
|
18
db/patch-add-docker-columns.sql
Normal file
18
db/patch-add-docker-columns.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
CREATE TABLE docker_host (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INT NOT NULL,
|
||||||
|
docker_daemon VARCHAR(255),
|
||||||
|
docker_type VARCHAR(255),
|
||||||
|
name VARCHAR(255)
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD docker_host INTEGER REFERENCES docker_host(id);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD docker_container VARCHAR(255);
|
||||||
|
|
||||||
|
COMMIT;
|
18
db/patch-add-other-auth.sql
Normal file
18
db/patch-add-other-auth.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD auth_method VARCHAR(250);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD auth_domain TEXT;
|
||||||
|
ALTER TABLE monitor
|
||||||
|
|
||||||
|
ADD auth_workstation TEXT;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
UPDATE monitor
|
||||||
|
SET auth_method = 'basic'
|
||||||
|
WHERE basic_auth_user is not null;
|
||||||
|
COMMIT;
|
18
db/patch-add-radius-monitor.sql
Normal file
18
db/patch-add-radius-monitor.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD radius_username VARCHAR(255);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD radius_password VARCHAR(255);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD radius_calling_station_id VARCHAR(50);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD radius_called_station_id VARCHAR(50);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD radius_secret VARCHAR(255);
|
||||||
|
|
||||||
|
COMMIT
|
10
db/patch-add-sqlserver-monitor.sql
Normal file
10
db/patch-add-sqlserver-monitor.sql
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD database_connection_string VARCHAR(2000);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD database_query TEXT;
|
||||||
|
|
||||||
|
|
||||||
|
COMMIT
|
10
db/patch-monitor-add-resend-interval.sql
Normal file
10
db/patch-monitor-add-resend-interval.sql
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD resend_interval INTEGER default 0 not null;
|
||||||
|
|
||||||
|
ALTER TABLE heartbeat
|
||||||
|
ADD down_count INTEGER default 0 not null;
|
||||||
|
|
||||||
|
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==1.0.0 && \
|
||||||
rm -rf /root/.cache
|
rm -rf /root/.cache
|
||||||
|
@@ -11,8 +11,9 @@ 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==1.0.0 && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
apt --yes autoremove
|
||||||
|
|
||||||
# Install cloudflared
|
# Install cloudflared
|
||||||
# dpkg --add-architecture arm: cloudflared do not provide armhf, this is workaround. Read more: https://github.com/cloudflare/cloudflared/issues/583
|
# dpkg --add-architecture arm: cloudflared do not provide armhf, this is workaround. Read more: https://github.com/cloudflare/cloudflared/issues/583
|
||||||
@@ -22,5 +23,6 @@ RUN node ./extra/download-cloudflared.js $TARGETPLATFORM && \
|
|||||||
apt update && \
|
apt update && \
|
||||||
apt --yes --no-install-recommends install ./cloudflared.deb && \
|
apt --yes --no-install-recommends install ./cloudflared.deb && \
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
rm -f cloudflared.deb
|
rm -f cloudflared.deb && \
|
||||||
|
apt --yes autoremove
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Simple docker-composer.yml
|
# Simple docker-compose.yml
|
||||||
# You can change your port or volume location
|
# You can change your port or volume location
|
||||||
|
|
||||||
version: '3.3'
|
version: '3.3'
|
||||||
@@ -8,7 +8,7 @@ services:
|
|||||||
image: louislam/uptime-kuma:1
|
image: louislam/uptime-kuma:1
|
||||||
container_name: uptime-kuma
|
container_name: uptime-kuma
|
||||||
volumes:
|
volumes:
|
||||||
- ./uptime-kuma:/app/data
|
- ./uptime-kuma-data:/app/data
|
||||||
ports:
|
ports:
|
||||||
- 3001:3001
|
- 3001:3001 # <Host Port>:<Container Port>
|
||||||
restart: always
|
restart: always
|
||||||
|
@@ -24,6 +24,36 @@ CMD ["node", "server/server.js"]
|
|||||||
FROM release AS nightly
|
FROM release AS nightly
|
||||||
RUN npm run mark-as-nightly
|
RUN npm run mark-as-nightly
|
||||||
|
|
||||||
|
# Build an image for testing pr
|
||||||
|
FROM louislam/uptime-kuma:base-debian AS pr-test
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
|
||||||
|
|
||||||
|
## Install Git
|
||||||
|
RUN apt update \
|
||||||
|
&& apt --yes --no-install-recommends install curl \
|
||||||
|
&& curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||||
|
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||||
|
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
|
||||||
|
&& apt update \
|
||||||
|
&& apt --yes --no-install-recommends install git
|
||||||
|
|
||||||
|
## Empty the directory, because we have to clone the Git repo.
|
||||||
|
RUN rm -rf ./* && chown node /app
|
||||||
|
|
||||||
|
USER node
|
||||||
|
RUN git config --global user.email "no-reply@no-reply.com"
|
||||||
|
RUN git config --global user.name "PR Tester"
|
||||||
|
RUN git clone https://github.com/louislam/uptime-kuma.git .
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
EXPOSE 3000 3001
|
||||||
|
VOLUME ["/app/data"]
|
||||||
|
HEALTHCHECK --interval=60s --timeout=30s --start-period=180s --retries=5 CMD node extra/healthcheck.js
|
||||||
|
CMD ["npm", "run", "start-pr-test"]
|
||||||
|
|
||||||
|
|
||||||
# Upload the artifact to Github
|
# Upload the artifact to Github
|
||||||
FROM louislam/uptime-kuma:base-debian AS upload-artifact
|
FROM louislam/uptime-kuma:base-debian AS upload-artifact
|
||||||
|
@@ -20,6 +20,10 @@ if (! exists) {
|
|||||||
// Process package.json
|
// Process package.json
|
||||||
pkg.version = version;
|
pkg.version = version;
|
||||||
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
||||||
|
|
||||||
|
// Also update package-lock.json
|
||||||
|
childProcess.spawnSync("npm", [ "install" ]);
|
||||||
|
|
||||||
commit(version);
|
commit(version);
|
||||||
tag(version);
|
tag(version);
|
||||||
|
|
||||||
|
33
extra/checkout-pr.js
Normal file
33
extra/checkout-pr.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const childProcess = require("child_process");
|
||||||
|
|
||||||
|
if (!process.env.UPTIME_KUMA_GH_REPO) {
|
||||||
|
console.error("Please set a repo to the environment variable 'UPTIME_KUMA_GH_REPO' (e.g. mhkarimi1383:goalert-notification)");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let inputArray = process.env.UPTIME_KUMA_GH_REPO.split(":");
|
||||||
|
|
||||||
|
if (inputArray.length !== 2) {
|
||||||
|
console.error("Invalid format. Please set a repo to the environment variable 'UPTIME_KUMA_GH_REPO' (e.g. mhkarimi1383:goalert-notification)");
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = inputArray[0];
|
||||||
|
let branch = inputArray[1];
|
||||||
|
|
||||||
|
console.log("Checkout pr");
|
||||||
|
|
||||||
|
// Checkout the pr
|
||||||
|
let result = childProcess.spawnSync("git", [ "remote", "add", name, `https://github.com/${name}/uptime-kuma` ]);
|
||||||
|
|
||||||
|
console.log(result.stdout.toString());
|
||||||
|
console.error(result.stderr.toString());
|
||||||
|
|
||||||
|
result = childProcess.spawnSync("git", [ "fetch", name, branch ]);
|
||||||
|
|
||||||
|
console.log(result.stdout.toString());
|
||||||
|
console.error(result.stderr.toString());
|
||||||
|
|
||||||
|
result = childProcess.spawnSync("git", [ "checkout", `${name}/${branch}`, "--force" ]);
|
||||||
|
|
||||||
|
console.log(result.stdout.toString());
|
||||||
|
console.error(result.stderr.toString());
|
@@ -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();
|
||||||
|
@@ -25,6 +25,9 @@ if (! exists) {
|
|||||||
pkg.scripts.setup = pkg.scripts.setup.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`);
|
pkg.scripts.setup = pkg.scripts.setup.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`);
|
||||||
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
|
||||||
|
|
||||||
|
// Also update package-lock.json
|
||||||
|
childProcess.spawnSync("npm", [ "install" ]);
|
||||||
|
|
||||||
commit(newVersion);
|
commit(newVersion);
|
||||||
tag(newVersion);
|
tag(newVersion);
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@ function updateWiki(newVersion) {
|
|||||||
|
|
||||||
function safeDelete(dir) {
|
function safeDelete(dir) {
|
||||||
if (fs.existsSync(dir)) {
|
if (fs.existsSync(dir)) {
|
||||||
fs.rmdirSync(dir, {
|
fs.rm(dir, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
17693
package-lock.json
generated
17693
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
133
package.json
133
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "uptime-kuma",
|
"name": "uptime-kuma",
|
||||||
"version": "1.15.0-beta.0",
|
"version": "1.18.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -10,22 +10,22 @@
|
|||||||
"node": "14.* || >=16.*"
|
"node": "14.* || >=16.*"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install-legacy": "npm install --legacy-peer-deps",
|
"install-legacy": "npm install",
|
||||||
"update-legacy": "npm update --legacy-peer-deps",
|
"update-legacy": "npm update",
|
||||||
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
|
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
|
||||||
"lint-fix:js": "eslint --ext \".js,.vue\" --fix --ignore-path .gitignore .",
|
"lint-fix:js": "eslint --ext \".js,.vue\" --fix --ignore-path .gitignore .",
|
||||||
"lint:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore",
|
"lint:style": "stylelint \"**/*.{vue,css,scss}\" --ignore-path .gitignore",
|
||||||
|
"lint-fix:style": "stylelint \"**/*.{vue,css,scss}\" --fix --ignore-path .gitignore",
|
||||||
"lint": "npm run lint:js && npm run lint:style",
|
"lint": "npm run lint:js && npm run lint:style",
|
||||||
"dev": "vite --host --config ./config/vite.config.js",
|
"dev": "concurrently -k -r \"wait-on tcp:3000 && npm run start-server-dev \" \"npm run start-frontend-dev\"",
|
||||||
|
"start-frontend-dev": "cross-env NODE_ENV=development vite --host --config ./config/vite.config.js",
|
||||||
"start": "npm run start-server",
|
"start": "npm run start-server",
|
||||||
"start-server": "node server/server.js",
|
"start-server": "node server/server.js",
|
||||||
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
||||||
"build": "vite build --config ./config/vite.config.js",
|
"build": "vite build --config ./config/vite.config.js",
|
||||||
"test": "npm run lint && node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/ --test",
|
"test": "node test/prepare-test-server.js && npm run jest-backend",
|
||||||
"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-backend": "cross-env TEST_BACKEND=1 jest --runInBand --detectOpenHandles --forceExit --config=./config/jest-backend.config.js",
|
||||||
"jest-frontend": "cross-env TEST_FRONTEND=1 jest --config=./config/jest-frontend.config.js",
|
|
||||||
"jest-backend": "cross-env TEST_BACKEND=1 jest --config=./config/jest-backend.config.js",
|
|
||||||
"tsc": "tsc",
|
"tsc": "tsc",
|
||||||
"vite-preview-dist": "vite preview --host --config ./config/vite.config.js",
|
"vite-preview-dist": "vite preview --host --config ./config/vite.config.js",
|
||||||
"build-docker": "npm run build && npm run build-docker-debian && npm run build-docker-alpine",
|
"build-docker": "npm run build && npm run build-docker-debian && npm run build-docker-alpine",
|
||||||
@@ -36,8 +36,9 @@
|
|||||||
"build-docker-nightly": "npm run build && docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --target nightly . --push",
|
"build-docker-nightly": "npm run build && docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --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-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",
|
||||||
|
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test --target pr-test . --push",
|
||||||
"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.18.3 && 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",
|
||||||
@@ -55,30 +56,33 @@
|
|||||||
"ncu-patch": "npm-check-updates -u -t patch",
|
"ncu-patch": "npm-check-updates -u -t patch",
|
||||||
"release-final": "node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js",
|
"release-final": "node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js",
|
||||||
"release-beta": "node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts",
|
"release-beta": "node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts",
|
||||||
"git-remove-tag": "git tag -d"
|
"git-remove-tag": "git tag -d",
|
||||||
|
"build-dist-and-restart": "npm run build && npm run start-server-dev",
|
||||||
|
"start-pr-test": "node extra/checkout-pr.js && npm install && npm run dev",
|
||||||
|
"cy:test": "node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/ --e2e",
|
||||||
|
"cy:run": "npx cypress run --browser chrome --headless --config-file ./config/cypress.config.js",
|
||||||
|
"cypress-open": "concurrently -k -r \"node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/\" \"cypress open --config-file ./config/cypress.config.js\""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "~1.2.36",
|
"@louislam/sqlite3": "~15.0.6",
|
||||||
"@fortawesome/free-regular-svg-icons": "~5.15.4",
|
|
||||||
"@fortawesome/free-solid-svg-icons": "~5.15.4",
|
|
||||||
"@fortawesome/vue-fontawesome": "~3.0.0-5",
|
|
||||||
"@louislam/sqlite3": "~6.0.1",
|
|
||||||
"@popperjs/core": "~2.10.2",
|
|
||||||
"args-parser": "~1.3.0",
|
"args-parser": "~1.3.0",
|
||||||
"axios": "~0.26.1",
|
"axios": "~0.27.0",
|
||||||
|
"axios-ntlm": "^1.3.0",
|
||||||
|
"badge-maker": "^3.3.1",
|
||||||
"bcryptjs": "~2.4.3",
|
"bcryptjs": "~2.4.3",
|
||||||
"bootstrap": "5.1.3",
|
|
||||||
"bree": "~7.1.5",
|
"bree": "~7.1.5",
|
||||||
|
"cacheable-lookup": "~6.0.4",
|
||||||
"chardet": "^1.3.0",
|
"chardet": "^1.3.0",
|
||||||
"chart.js": "~3.6.2",
|
|
||||||
"chartjs-adapter-dayjs": "~1.0.0",
|
|
||||||
"check-password-strength": "^2.0.5",
|
"check-password-strength": "^2.0.5",
|
||||||
|
"cheerio": "^1.0.0-rc.10",
|
||||||
|
"chroma-js": "^2.1.2",
|
||||||
"command-exists": "~1.2.9",
|
"command-exists": "~1.2.9",
|
||||||
"compare-versions": "~3.6.0",
|
"compare-versions": "~3.6.0",
|
||||||
"dayjs": "~1.10.8",
|
"compression": "^1.7.4",
|
||||||
|
"dayjs": "^1.11.0",
|
||||||
"express": "~4.17.3",
|
"express": "~4.17.3",
|
||||||
"express-basic-auth": "~1.2.1",
|
"express-basic-auth": "~1.2.1",
|
||||||
"favico.js": "^0.3.10",
|
"express-static-gzip": "^2.1.7",
|
||||||
"form-data": "~4.0.0",
|
"form-data": "~4.0.0",
|
||||||
"http-graceful-shutdown": "~3.1.7",
|
"http-graceful-shutdown": "~3.1.7",
|
||||||
"http-proxy-agent": "^5.0.0",
|
"http-proxy-agent": "^5.0.0",
|
||||||
@@ -88,25 +92,67 @@
|
|||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"limiter": "^2.1.0",
|
"limiter": "^2.1.0",
|
||||||
"mqtt": "^4.2.8",
|
"mqtt": "^4.2.8",
|
||||||
|
"mssql": "^8.1.0",
|
||||||
"node-cloudflared-tunnel": "~1.0.9",
|
"node-cloudflared-tunnel": "~1.0.9",
|
||||||
|
"node-radius-client": "^1.0.0",
|
||||||
"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",
|
"pg": "^8.7.3",
|
||||||
"postcss-scss": "~4.0.3",
|
"pg-connection-string": "^2.5.0",
|
||||||
"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",
|
"redbean-node": "0.1.4",
|
||||||
"redbean-node": "0.1.3",
|
|
||||||
"socket.io": "~4.4.1",
|
"socket.io": "~4.4.1",
|
||||||
"socket.io-client": "~4.4.1",
|
"socket.io-client": "~4.4.1",
|
||||||
"socks-proxy-agent": "^6.1.1",
|
"socks-proxy-agent": "6.1.1",
|
||||||
"tar": "^6.1.11",
|
"tar": "^6.1.11",
|
||||||
"tcp-ping": "~0.1.1",
|
"tcp-ping": "~0.1.1",
|
||||||
"thirty-two": "~1.0.2",
|
"thirty-two": "~1.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@actions/github": "~5.0.1",
|
||||||
|
"@babel/eslint-parser": "~7.17.0",
|
||||||
|
"@babel/preset-env": "^7.15.8",
|
||||||
|
"@fortawesome/fontawesome-svg-core": "~1.2.36",
|
||||||
|
"@fortawesome/free-regular-svg-icons": "~5.15.4",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "~5.15.4",
|
||||||
|
"@fortawesome/vue-fontawesome": "~3.0.0-5",
|
||||||
|
"@popperjs/core": "~2.10.2",
|
||||||
|
"@types/bootstrap": "~5.1.9",
|
||||||
|
"@vitejs/plugin-legacy": "~2.1.0",
|
||||||
|
"@vitejs/plugin-vue": "~3.1.0",
|
||||||
|
"@vue/compiler-sfc": "~3.2.36",
|
||||||
|
"aedes": "^0.46.3",
|
||||||
|
"babel-plugin-rewire": "~1.2.0",
|
||||||
|
"bootstrap": "5.1.3",
|
||||||
|
"chart.js": "~3.6.2",
|
||||||
|
"chartjs-adapter-dayjs": "~1.0.0",
|
||||||
|
"concurrently": "^7.1.0",
|
||||||
|
"core-js": "~3.18.3",
|
||||||
|
"cross-env": "~7.0.3",
|
||||||
|
"cypress": "^10.1.0",
|
||||||
|
"delay": "^5.0.0",
|
||||||
|
"dns2": "~2.0.1",
|
||||||
|
"eslint": "~8.14.0",
|
||||||
|
"eslint-plugin-vue": "~8.7.1",
|
||||||
|
"favico.js": "^0.3.10",
|
||||||
|
"jest": "~27.2.5",
|
||||||
|
"postcss-html": "~1.5.0",
|
||||||
|
"postcss-rtlcss": "~3.7.2",
|
||||||
|
"postcss-scss": "~4.0.4",
|
||||||
|
"prismjs": "^1.27.0",
|
||||||
|
"qrcode": "~1.5.0",
|
||||||
|
"rollup-plugin-visualizer": "^5.6.0",
|
||||||
|
"sass": "~1.42.1",
|
||||||
|
"stylelint": "~14.7.1",
|
||||||
|
"stylelint-config-standard": "~25.0.0",
|
||||||
|
"terser": "^5.15.0",
|
||||||
"timezones-list": "~3.0.1",
|
"timezones-list": "~3.0.1",
|
||||||
|
"typescript": "~4.4.4",
|
||||||
"v-pagination-3": "~0.1.7",
|
"v-pagination-3": "~0.1.7",
|
||||||
|
"vite": "~3.1.0",
|
||||||
|
"vite-plugin-compression": "^0.5.1",
|
||||||
"vue": "next",
|
"vue": "next",
|
||||||
"vue-chart-3": "3.0.9",
|
"vue-chart-3": "3.0.9",
|
||||||
"vue-confirm-dialog": "~1.0.2",
|
"vue-confirm-dialog": "~1.0.2",
|
||||||
@@ -118,32 +164,7 @@
|
|||||||
"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",
|
||||||
"vuedraggable": "~4.1.0"
|
"vuedraggable": "~4.1.0",
|
||||||
},
|
"wait-on": "^6.0.1"
|
||||||
"devDependencies": {
|
|
||||||
"@actions/github": "~5.0.1",
|
|
||||||
"@babel/eslint-parser": "~7.15.8",
|
|
||||||
"@babel/preset-env": "^7.15.8",
|
|
||||||
"@types/bootstrap": "~5.1.9",
|
|
||||||
"@vitejs/plugin-legacy": "~1.6.4",
|
|
||||||
"@vitejs/plugin-vue": "~1.9.4",
|
|
||||||
"@vue/compiler-sfc": "~3.2.31",
|
|
||||||
"aedes": "^0.46.3",
|
|
||||||
"babel-plugin-rewire": "~1.2.0",
|
|
||||||
"core-js": "~3.18.3",
|
|
||||||
"cross-env": "~7.0.3",
|
|
||||||
"dns2": "~2.0.1",
|
|
||||||
"eslint": "~7.32.0",
|
|
||||||
"eslint-plugin-vue": "~7.18.0",
|
|
||||||
"jest": "~27.2.5",
|
|
||||||
"jest-puppeteer": "~6.0.3",
|
|
||||||
"npm-check-updates": "^12.5.5",
|
|
||||||
"postcss-html": "^1.3.1",
|
|
||||||
"puppeteer": "~13.1.3",
|
|
||||||
"sass": "~1.42.1",
|
|
||||||
"stylelint": "~14.2.0",
|
|
||||||
"stylelint-config-standard": "~24.0.0",
|
|
||||||
"typescript": "~4.4.4",
|
|
||||||
"vite": "~2.6.14"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 893 B |
@@ -2,6 +2,11 @@ const { R } = require("redbean-node");
|
|||||||
|
|
||||||
class TwoFA {
|
class TwoFA {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable 2FA for specified user
|
||||||
|
* @param {number} userID ID of user to disable
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async disable2FA(userID) {
|
static async disable2FA(userID) {
|
||||||
return await R.exec("UPDATE `user` SET twofa_status = 0 WHERE id = ? ", [
|
return await R.exec("UPDATE `user` SET twofa_status = 0 WHERE id = ? ", [
|
||||||
userID,
|
userID,
|
||||||
|
@@ -5,10 +5,10 @@ const { setting } = require("./util-server");
|
|||||||
const { loginRateLimiter } = require("./rate-limiter");
|
const { loginRateLimiter } = require("./rate-limiter");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Login to web app
|
||||||
* @param username : string
|
* @param {string} username
|
||||||
* @param password : string
|
* @param {string} password
|
||||||
* @returns {Promise<Bean|null>}
|
* @returns {Promise<(Bean|null)>}
|
||||||
*/
|
*/
|
||||||
exports.login = async function (username, password) {
|
exports.login = async function (username, password) {
|
||||||
if (typeof username !== "string" || typeof password !== "string") {
|
if (typeof username !== "string" || typeof password !== "string") {
|
||||||
@@ -34,11 +34,17 @@ exports.login = async function (username, password) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that checks if a user is logged in.
|
* Callback for myAuthorizer
|
||||||
* @param {string} username The username of the user to check for.
|
* @callback myAuthorizerCB
|
||||||
* @param {function} callback The callback to call when done, with an error and result parameter.
|
* @param {any} err Any error encountered
|
||||||
*
|
* @param {boolean} authorized Is the client authorized?
|
||||||
* Generated by Trelent
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom authorizer for express-basic-auth
|
||||||
|
* @param {string} username
|
||||||
|
* @param {string} password
|
||||||
|
* @param {myAuthorizerCB} callback
|
||||||
*/
|
*/
|
||||||
function myAuthorizer(username, password, callback) {
|
function myAuthorizer(username, password, callback) {
|
||||||
// Login Rate Limit
|
// Login Rate Limit
|
||||||
|
54
server/cacheable-dns-http-agent.js
Normal file
54
server/cacheable-dns-http-agent.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
const https = require("https");
|
||||||
|
const http = require("http");
|
||||||
|
const CacheableLookup = require("cacheable-lookup");
|
||||||
|
|
||||||
|
class CacheableDnsHttpAgent {
|
||||||
|
|
||||||
|
static cacheable = new CacheableLookup();
|
||||||
|
|
||||||
|
static httpAgentList = {};
|
||||||
|
static httpsAgentList = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register cacheable to global agents
|
||||||
|
*/
|
||||||
|
static registerGlobalAgent() {
|
||||||
|
this.cacheable.install(http.globalAgent);
|
||||||
|
this.cacheable.install(https.globalAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
static install(agent) {
|
||||||
|
this.cacheable.install(agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var {https.AgentOptions} agentOptions
|
||||||
|
* @return {https.Agent}
|
||||||
|
*/
|
||||||
|
static getHttpsAgent(agentOptions) {
|
||||||
|
let key = JSON.stringify(agentOptions);
|
||||||
|
if (!(key in this.httpsAgentList)) {
|
||||||
|
this.httpsAgentList[key] = new https.Agent(agentOptions);
|
||||||
|
this.cacheable.install(this.httpsAgentList[key]);
|
||||||
|
}
|
||||||
|
return this.httpsAgentList[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var {http.AgentOptions} agentOptions
|
||||||
|
* @return {https.Agents}
|
||||||
|
*/
|
||||||
|
static getHttpAgent(agentOptions) {
|
||||||
|
let key = JSON.stringify(agentOptions);
|
||||||
|
if (!(key in this.httpAgentList)) {
|
||||||
|
this.httpAgentList[key] = new http.Agent(agentOptions);
|
||||||
|
this.cacheable.install(this.httpAgentList[key]);
|
||||||
|
}
|
||||||
|
return this.httpAgentList[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
CacheableDnsHttpAgent,
|
||||||
|
};
|
@@ -7,6 +7,7 @@ exports.latestVersion = null;
|
|||||||
|
|
||||||
let interval;
|
let interval;
|
||||||
|
|
||||||
|
/** Start 48 hour check interval */
|
||||||
exports.startInterval = () => {
|
exports.startInterval = () => {
|
||||||
let check = async () => {
|
let check = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -42,6 +43,11 @@ exports.startInterval = () => {
|
|||||||
interval = setInterval(check, 3600 * 1000 * 48);
|
interval = setInterval(check, 3600 * 1000 * 48);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the check update feature
|
||||||
|
* @param {boolean} value Should the check update feature be enabled?
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
exports.enableCheckUpdate = async (value) => {
|
exports.enableCheckUpdate = async (value) => {
|
||||||
await setSetting("checkUpdate", value);
|
await setSetting("checkUpdate", value);
|
||||||
|
|
||||||
|
@@ -3,15 +3,15 @@
|
|||||||
*/
|
*/
|
||||||
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.
|
* Send list of notification providers to client
|
||||||
* @param {Socket} socket The socket object that is connected to the client.
|
* @param {Socket} socket Socket.io socket instance
|
||||||
*
|
* @returns {Promise<Bean[]>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function sendNotificationList(socket) {
|
async function sendNotificationList(socket) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
@@ -22,7 +22,10 @@ async function sendNotificationList(socket) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
for (let bean of list) {
|
for (let bean of list) {
|
||||||
result.push(bean.export());
|
let notificationObject = bean.export();
|
||||||
|
notificationObject.isDefault = (notificationObject.isDefault === 1);
|
||||||
|
notificationObject.active = (notificationObject.active === 1);
|
||||||
|
result.push(notificationObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
io.to(socket.userID).emit("notificationList", result);
|
io.to(socket.userID).emit("notificationList", result);
|
||||||
@@ -34,8 +37,11 @@ async function sendNotificationList(socket) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Heartbeat History list to socket
|
* Send Heartbeat History list to socket
|
||||||
* @param toUser True = send to all browsers with the same user id, False = send to the current browser only
|
* @param {Socket} socket Socket.io instance
|
||||||
* @param overwrite Overwrite client-side's heartbeat list
|
* @param {number} monitorID ID of monitor to send heartbeat history
|
||||||
|
* @param {boolean} [toUser=false] True = send to all browsers with the same user id, False = send to the current browser only
|
||||||
|
* @param {boolean} [overwrite=false] Overwrite client-side's heartbeat list
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function sendHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
async function sendHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
@@ -61,11 +67,12 @@ async function sendHeartbeatList(socket, monitorID, toUser = false, overwrite =
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Important Heart beat list (aka event list)
|
* Important Heart beat list (aka event list)
|
||||||
* @param socket
|
* @param {Socket} socket Socket.io instance
|
||||||
* @param monitorID
|
* @param {number} monitorID ID of monitor to send heartbeat history
|
||||||
* @param toUser True = send to all browsers with the same user id, False = send to the current browser only
|
* @param {boolean} [toUser=false] True = send to all browsers with the same user id, False = send to the current browser only
|
||||||
* @param overwrite Overwrite client-side's heartbeat list
|
* @param {boolean} [overwrite=false] Overwrite client-side's heartbeat list
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function sendImportantHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
async function sendImportantHeartbeatList(socket, monitorID, toUser = false, overwrite = false) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
@@ -90,9 +97,8 @@ async function sendImportantHeartbeatList(socket, monitorID, toUser = false, ove
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delivers proxy list
|
* Emit proxy list to client
|
||||||
*
|
* @param {Socket} socket Socket.io socket instance
|
||||||
* @param socket
|
|
||||||
* @return {Promise<Bean[]>}
|
* @return {Promise<Bean[]>}
|
||||||
*/
|
*/
|
||||||
async function sendProxyList(socket) {
|
async function sendProxyList(socket) {
|
||||||
@@ -108,9 +114,8 @@ async function sendProxyList(socket) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Emits the version information to the client.
|
* Emits the version information to the client.
|
||||||
* @param {Socket} socket The socket object that is connected to the client.
|
* @param {Socket} socket Socket.io socket instance
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function sendInfo(socket) {
|
async function sendInfo(socket) {
|
||||||
socket.emit("info", {
|
socket.emit("info", {
|
||||||
@@ -120,10 +125,35 @@ async function sendInfo(socket) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send list of docker hosts to client
|
||||||
|
* @param {Socket} socket Socket.io socket instance
|
||||||
|
* @returns {Promise<Bean[]>}
|
||||||
|
*/
|
||||||
|
async function sendDockerHostList(socket) {
|
||||||
|
const timeLogger = new TimeLogger();
|
||||||
|
|
||||||
|
let result = [];
|
||||||
|
let list = await R.find("docker_host", " user_id = ? ", [
|
||||||
|
socket.userID,
|
||||||
|
]);
|
||||||
|
|
||||||
|
for (let bean of list) {
|
||||||
|
result.push(bean.toJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
io.to(socket.userID).emit("dockerHostList", result);
|
||||||
|
|
||||||
|
timeLogger.print("Send Docker Host List");
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sendNotificationList,
|
sendNotificationList,
|
||||||
sendImportantHeartbeatList,
|
sendImportantHeartbeatList,
|
||||||
sendHeartbeatList,
|
sendHeartbeatList,
|
||||||
sendProxyList,
|
sendProxyList,
|
||||||
sendInfo,
|
sendInfo,
|
||||||
|
sendDockerHostList
|
||||||
};
|
};
|
||||||
|
@@ -1,7 +1,20 @@
|
|||||||
const args = require("args-parser")(process.argv);
|
const args = require("args-parser")(process.argv);
|
||||||
const demoMode = args["demo"] || false;
|
const demoMode = args["demo"] || false;
|
||||||
|
|
||||||
|
const badgeConstants = {
|
||||||
|
naColor: "#999",
|
||||||
|
defaultUpColor: "#66c20a",
|
||||||
|
defaultDownColor: "#c2290a",
|
||||||
|
defaultPingColor: "blue", // as defined by badge-maker / shields.io
|
||||||
|
defaultStyle: "flat",
|
||||||
|
defaultPingValueSuffix: "ms",
|
||||||
|
defaultPingLabelSuffix: "h",
|
||||||
|
defaultUptimeValueSuffix: "%",
|
||||||
|
defaultUptimeLabelSuffix: "h",
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
args,
|
args,
|
||||||
demoMode
|
demoMode,
|
||||||
|
badgeConstants,
|
||||||
};
|
};
|
||||||
|
@@ -53,12 +53,18 @@ class Database {
|
|||||||
"patch-2fa-invalidate-used-token.sql": true,
|
"patch-2fa-invalidate-used-token.sql": true,
|
||||||
"patch-notification_sent_history.sql": true,
|
"patch-notification_sent_history.sql": true,
|
||||||
"patch-monitor-basic-auth.sql": true,
|
"patch-monitor-basic-auth.sql": true,
|
||||||
|
"patch-add-docker-columns.sql": true,
|
||||||
"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-status-page-footer-css.sql": true,
|
||||||
"patch-added-mqtt-monitor.sql": true,
|
"patch-added-mqtt-monitor.sql": true,
|
||||||
}
|
"patch-add-clickable-status-page-link.sql": true,
|
||||||
|
"patch-add-sqlserver-monitor.sql": true,
|
||||||
|
"patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] },
|
||||||
|
"patch-add-radius-monitor.sql": true,
|
||||||
|
"patch-monitor-add-resend-interval.sql": true,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The final version should be 10 after merged tag feature
|
* The final version should be 10 after merged tag feature
|
||||||
@@ -68,6 +74,10 @@ class Database {
|
|||||||
|
|
||||||
static noReject = true;
|
static noReject = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the database
|
||||||
|
* @param {Object} args Arguments to initialize DB with
|
||||||
|
*/
|
||||||
static init(args) {
|
static init(args) {
|
||||||
// Data Directory (must be end with "/")
|
// Data Directory (must be end with "/")
|
||||||
Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";
|
Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";
|
||||||
@@ -85,6 +95,15 @@ class Database {
|
|||||||
log.info("db", `Data Dir: ${Database.dataDir}`);
|
log.info("db", `Data Dir: ${Database.dataDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to the database
|
||||||
|
* @param {boolean} [testMode=false] Should the connection be
|
||||||
|
* started in test mode?
|
||||||
|
* @param {boolean} [autoloadModels=true] Should models be
|
||||||
|
* automatically loaded?
|
||||||
|
* @param {boolean} [noLog=false] Should logs not be output?
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async connect(testMode = false, autoloadModels = true, noLog = false) {
|
static async connect(testMode = false, autoloadModels = true, noLog = false) {
|
||||||
const acquireConnectionTimeout = 120 * 1000;
|
const acquireConnectionTimeout = 120 * 1000;
|
||||||
|
|
||||||
@@ -131,6 +150,9 @@ class Database {
|
|||||||
await R.exec("PRAGMA cache_size = -12000");
|
await R.exec("PRAGMA cache_size = -12000");
|
||||||
await R.exec("PRAGMA auto_vacuum = FULL");
|
await R.exec("PRAGMA auto_vacuum = FULL");
|
||||||
|
|
||||||
|
// Avoid error "SQLITE_BUSY: database is locked" by allowing SQLITE to wait up to 5 seconds to do a write
|
||||||
|
await R.exec("PRAGMA busy_timeout = 5000");
|
||||||
|
|
||||||
// This ensures that an operating system crash or power failure will not corrupt the database.
|
// This ensures that an operating system crash or power failure will not corrupt the database.
|
||||||
// FULL synchronous is very safe, but it is also slower.
|
// FULL synchronous is very safe, but it is also slower.
|
||||||
// Read more: https://sqlite.org/pragma.html#pragma_synchronous
|
// Read more: https://sqlite.org/pragma.html#pragma_synchronous
|
||||||
@@ -144,6 +166,7 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Patch the database */
|
||||||
static async patch() {
|
static async patch() {
|
||||||
let version = parseInt(await setting("database_version"));
|
let version = parseInt(await setting("database_version"));
|
||||||
|
|
||||||
@@ -161,7 +184,13 @@ class Database {
|
|||||||
} else {
|
} else {
|
||||||
log.info("db", "Database patch is needed");
|
log.info("db", "Database patch is needed");
|
||||||
|
|
||||||
this.backup(version);
|
try {
|
||||||
|
this.backup(version);
|
||||||
|
} catch (e) {
|
||||||
|
log.error("db", e);
|
||||||
|
log.error("db", "Unable to create a backup before patching the database. Please make sure you have enough space and permission.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Try catch anything here, if gone wrong, restore the backup
|
// Try catch anything here, if gone wrong, restore the backup
|
||||||
try {
|
try {
|
||||||
@@ -189,7 +218,9 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Patch DB using new process
|
||||||
* Call it from patch() only
|
* Call it from patch() only
|
||||||
|
* @private
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch2() {
|
static async patch2() {
|
||||||
@@ -296,9 +327,12 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Patch database using new patching process
|
||||||
* Used it patch2() only
|
* Used it patch2() only
|
||||||
|
* @private
|
||||||
* @param sqlFilename
|
* @param sqlFilename
|
||||||
* @param databasePatchedFiles
|
* @param databasePatchedFiles
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch2Recursion(sqlFilename, databasePatchedFiles) {
|
static async patch2Recursion(sqlFilename, databasePatchedFiles) {
|
||||||
let value = this.patchList[sqlFilename];
|
let value = this.patchList[sqlFilename];
|
||||||
@@ -333,12 +367,12 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sadly, multi sql statements is not supported by many sqlite libraries, I have to implement it myself
|
* Load an SQL file and execute it
|
||||||
* @param filename
|
* @param filename Filename of SQL file to import
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async importSQLFile(filename) {
|
static async importSQLFile(filename) {
|
||||||
|
// Sadly, multi sql statements is not supported by many sqlite libraries, I have to implement it myself
|
||||||
await R.getCell("SELECT 1");
|
await R.getCell("SELECT 1");
|
||||||
|
|
||||||
let text = fs.readFileSync(filename).toString();
|
let text = fs.readFileSync(filename).toString();
|
||||||
@@ -366,6 +400,10 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aquire a direct connection to database
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
static getBetterSQLite3Database() {
|
static getBetterSQLite3Database() {
|
||||||
return R.knex.client.acquireConnection();
|
return R.knex.client.acquireConnection();
|
||||||
}
|
}
|
||||||
@@ -401,7 +439,7 @@ class Database {
|
|||||||
/**
|
/**
|
||||||
* One backup one time in this process.
|
* One backup one time in this process.
|
||||||
* Reset this.backupPath if you want to backup again
|
* Reset this.backupPath if you want to backup again
|
||||||
* @param version
|
* @param {string} version Version code of backup
|
||||||
*/
|
*/
|
||||||
static backup(version) {
|
static backup(version) {
|
||||||
if (! this.backupPath) {
|
if (! this.backupPath) {
|
||||||
@@ -420,12 +458,27 @@ class Database {
|
|||||||
this.backupWalPath = walPath + ".bak" + version;
|
this.backupWalPath = walPath + ".bak" + version;
|
||||||
fs.copyFileSync(walPath, this.backupWalPath);
|
fs.copyFileSync(walPath, this.backupWalPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Double confirm if all files actually backup
|
||||||
|
if (!fs.existsSync(this.backupPath)) {
|
||||||
|
throw new Error("Backup failed! " + this.backupPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(shmPath)) {
|
||||||
|
if (!fs.existsSync(this.backupShmPath)) {
|
||||||
|
throw new Error("Backup failed! " + this.backupShmPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(walPath)) {
|
||||||
|
if (!fs.existsSync(this.backupWalPath)) {
|
||||||
|
throw new Error("Backup failed! " + this.backupWalPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Restore from most recent backup */
|
||||||
*
|
|
||||||
*/
|
|
||||||
static restore() {
|
static restore() {
|
||||||
if (this.backupPath) {
|
if (this.backupPath) {
|
||||||
log.error("db", "Patching the database failed!!! Restoring the backup");
|
log.error("db", "Patching the database failed!!! Restoring the backup");
|
||||||
@@ -467,6 +520,7 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the size of the database */
|
||||||
static getSize() {
|
static getSize() {
|
||||||
log.debug("db", "Database.getSize()");
|
log.debug("db", "Database.getSize()");
|
||||||
let stats = fs.statSync(Database.path);
|
let stats = fs.statSync(Database.path);
|
||||||
@@ -474,6 +528,10 @@ class Database {
|
|||||||
return stats.size;
|
return stats.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink the database
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async shrink() {
|
static async shrink() {
|
||||||
await R.exec("VACUUM");
|
await R.exec("VACUUM");
|
||||||
}
|
}
|
||||||
|
118
server/docker.js
Normal file
118
server/docker.js
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
const axios = require("axios");
|
||||||
|
const { R } = require("redbean-node");
|
||||||
|
const version = require("../package.json").version;
|
||||||
|
const https = require("https");
|
||||||
|
|
||||||
|
class DockerHost {
|
||||||
|
/**
|
||||||
|
* Save a docker host
|
||||||
|
* @param {Object} dockerHost Docker host to save
|
||||||
|
* @param {?number} dockerHostID ID of the docker host to update
|
||||||
|
* @param {number} userID ID of the user who adds the docker host
|
||||||
|
* @returns {Promise<Bean>}
|
||||||
|
*/
|
||||||
|
static async save(dockerHost, dockerHostID, userID) {
|
||||||
|
let bean;
|
||||||
|
|
||||||
|
if (dockerHostID) {
|
||||||
|
bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
|
||||||
|
|
||||||
|
if (!bean) {
|
||||||
|
throw new Error("docker host not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
bean = R.dispense("docker_host");
|
||||||
|
}
|
||||||
|
|
||||||
|
bean.user_id = userID;
|
||||||
|
bean.docker_daemon = dockerHost.dockerDaemon;
|
||||||
|
bean.docker_type = dockerHost.dockerType;
|
||||||
|
bean.name = dockerHost.name;
|
||||||
|
|
||||||
|
await R.store(bean);
|
||||||
|
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a Docker host
|
||||||
|
* @param {number} dockerHostID ID of the Docker host to delete
|
||||||
|
* @param {number} userID ID of the user who created the Docker host
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async delete(dockerHostID, userID) {
|
||||||
|
let bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
|
||||||
|
|
||||||
|
if (!bean) {
|
||||||
|
throw new Error("docker host not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete removed proxy from monitors if exists
|
||||||
|
await R.exec("UPDATE monitor SET docker_host = null WHERE docker_host = ?", [ dockerHostID ]);
|
||||||
|
|
||||||
|
await R.trash(bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the amount of containers on the Docker host
|
||||||
|
* @param {Object} dockerHost Docker host to check for
|
||||||
|
* @returns {number} Total amount of containers on the host
|
||||||
|
*/
|
||||||
|
static async testDockerHost(dockerHost) {
|
||||||
|
const options = {
|
||||||
|
url: "/containers/json?all=true",
|
||||||
|
headers: {
|
||||||
|
"Accept": "*/*",
|
||||||
|
"User-Agent": "Uptime-Kuma/" + version
|
||||||
|
},
|
||||||
|
httpsAgent: new https.Agent({
|
||||||
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dockerHost.dockerType === "socket") {
|
||||||
|
options.socketPath = dockerHost.dockerDaemon;
|
||||||
|
} else if (dockerHost.dockerType === "tcp") {
|
||||||
|
options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon);
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = await axios.request(options);
|
||||||
|
|
||||||
|
if (Array.isArray(res.data)) {
|
||||||
|
|
||||||
|
if (res.data.length > 1) {
|
||||||
|
|
||||||
|
if ("ImageID" in res.data[0]) {
|
||||||
|
return res.data.length;
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid Docker response, is it Docker really a daemon?");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return res.data.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid Docker response, is it Docker really a daemon?");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Since axios 0.27.X, it does not accept `tcp://` protocol.
|
||||||
|
* Change it to `http://` on the fly in order to fix it. (https://github.com/louislam/uptime-kuma/issues/2165)
|
||||||
|
*/
|
||||||
|
static patchDockerURL(url) {
|
||||||
|
if (typeof url === "string") {
|
||||||
|
// Replace the first occurrence only with g
|
||||||
|
return url.replace(/tcp:\/\//g, "http://");
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
DockerHost,
|
||||||
|
};
|
@@ -8,10 +8,12 @@ const { log } = require("../src/util");
|
|||||||
let ImageDataURI = (() => {
|
let ImageDataURI = (() => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} dataURI - A string that is a valid Data URI.
|
* Decode the data:image/ URI
|
||||||
* @returns {?Object} An object with properties "imageType" and "dataBase64". The former is the image type, e.g., "png", and the latter is a base64 encoded string of the image's binary data. If it fails to parse, returns null instead of an object.
|
* @param {string} dataURI data:image/ URI to decode
|
||||||
*
|
* @returns {?Object} An object with properties "imageType" and "dataBase64".
|
||||||
* Generated by Trelent
|
* The former is the image type, e.g., "png", and the latter is a base64
|
||||||
|
* encoded string of the image's binary data. If it fails to parse, returns
|
||||||
|
* null instead of an object.
|
||||||
*/
|
*/
|
||||||
function decode(dataURI) {
|
function decode(dataURI) {
|
||||||
if (!/data:image\//.test(dataURI)) {
|
if (!/data:image\//.test(dataURI)) {
|
||||||
@@ -28,11 +30,11 @@ let ImageDataURI = (() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Buffer} data - The image data to be encoded.
|
* Endcode an image into data:image/ URI
|
||||||
* @param {String} mediaType - The type of the image, e.g., "image/png".
|
* @param {(Buffer|string)} data Data to encode
|
||||||
* @returns {String|null} A string representing the base64-encoded version of the given Buffer object or null if an error occurred.
|
* @param {string} mediaType Media type of data
|
||||||
*
|
* @returns {(string|null)} A string representing the base64-encoded
|
||||||
* Generated by Trelent
|
* version of the given Buffer object or null if an error occurred.
|
||||||
*/
|
*/
|
||||||
function encode(data, mediaType) {
|
function encode(data, mediaType) {
|
||||||
if (!data || !mediaType) {
|
if (!data || !mediaType) {
|
||||||
@@ -48,11 +50,10 @@ let ImageDataURI = (() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a data URI to a file path.
|
* Write data URI to file
|
||||||
* @param {string} dataURI The Data URI of the image.
|
* @param {string} dataURI data:image/ URI
|
||||||
* @param {string} [filePath] The path where the image will be saved, defaults to "./".
|
* @param {string} [filePath] Path to write file to
|
||||||
*
|
* @returns {Promise<string>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
function outputFile(dataURI, filePath) {
|
function outputFile(dataURI, filePath) {
|
||||||
filePath = filePath || "./";
|
filePath = filePath || "./";
|
||||||
|
@@ -10,6 +10,11 @@ const jobs = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize background jobs
|
||||||
|
* @param {Object} args Arguments to pass to workers
|
||||||
|
* @returns {Bree}
|
||||||
|
*/
|
||||||
const initBackgroundJobs = function (args) {
|
const initBackgroundJobs = function (args) {
|
||||||
bree = new Bree({
|
bree = new Bree({
|
||||||
root: path.resolve("server", "jobs"),
|
root: path.resolve("server", "jobs"),
|
||||||
|
@@ -2,12 +2,22 @@ const { parentPort, workerData } = require("worker_threads");
|
|||||||
const Database = require("../database");
|
const Database = require("../database");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message to parent process for logging
|
||||||
|
* since worker_thread does not have access to stdout, this is used
|
||||||
|
* instead of console.log()
|
||||||
|
* @param {any} any The message to log
|
||||||
|
*/
|
||||||
const log = function (any) {
|
const log = function (any) {
|
||||||
if (parentPort) {
|
if (parentPort) {
|
||||||
parentPort.postMessage(any);
|
parentPort.postMessage(any);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit the worker process
|
||||||
|
* @param {number} error The status code to exit
|
||||||
|
*/
|
||||||
const exit = function (error) {
|
const exit = function (error) {
|
||||||
if (error && error !== 0) {
|
if (error && error !== 0) {
|
||||||
process.exit(error);
|
process.exit(error);
|
||||||
@@ -20,6 +30,7 @@ const exit = function (error) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Connects to the database */
|
||||||
const connectDb = async function () {
|
const connectDb = async function () {
|
||||||
const dbPath = path.join(
|
const dbPath = path.join(
|
||||||
process.env.DATA_DIR || workerData["data-dir"] || "./data/"
|
process.env.DATA_DIR || workerData["data-dir"] || "./data/"
|
||||||
|
19
server/model/docker_host.js
Normal file
19
server/model/docker_host.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
|
|
||||||
|
class DockerHost extends BeanModel {
|
||||||
|
/**
|
||||||
|
* Returns an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
toJSON() {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
userID: this.user_id,
|
||||||
|
dockerDaemon: this.docker_daemon,
|
||||||
|
dockerType: this.docker_type,
|
||||||
|
name: this.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = DockerHost;
|
@@ -3,6 +3,12 @@ const { R } = require("redbean-node");
|
|||||||
|
|
||||||
class Group extends BeanModel {
|
class Group extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @param {boolean} [showTags=false] Should the JSON include monitor tags
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
async toPublicJSON(showTags = false) {
|
async toPublicJSON(showTags = false) {
|
||||||
let monitorBeanList = await this.getMonitorList();
|
let monitorBeanList = await this.getMonitorList();
|
||||||
let monitorList = [];
|
let monitorList = [];
|
||||||
@@ -19,9 +25,13 @@ class Group extends BeanModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all monitors
|
||||||
|
* @returns {Bean[]}
|
||||||
|
*/
|
||||||
async getMonitorList() {
|
async getMonitorList() {
|
||||||
return R.convertToBeans("monitor", await R.getAll(`
|
return R.convertToBeans("monitor", await R.getAll(`
|
||||||
SELECT monitor.* FROM monitor, monitor_group
|
SELECT monitor.*, monitor_group.send_url FROM monitor, monitor_group
|
||||||
WHERE monitor.id = monitor_group.monitor_id
|
WHERE monitor.id = monitor_group.monitor_id
|
||||||
AND group_id = ?
|
AND group_id = ?
|
||||||
ORDER BY monitor_group.weight
|
ORDER BY monitor_group.weight
|
||||||
|
@@ -13,6 +13,11 @@ const { BeanModel } = require("redbean-node/dist/bean-model");
|
|||||||
*/
|
*/
|
||||||
class Heartbeat extends BeanModel {
|
class Heartbeat extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toPublicJSON() {
|
toPublicJSON() {
|
||||||
return {
|
return {
|
||||||
status: this.status,
|
status: this.status,
|
||||||
@@ -22,6 +27,10 @@ class Heartbeat extends BeanModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
monitorID: this.monitor_id,
|
monitorID: this.monitor_id,
|
||||||
|
@@ -2,6 +2,11 @@ const { BeanModel } = require("redbean-node/dist/bean-model");
|
|||||||
|
|
||||||
class Incident extends BeanModel {
|
class Incident extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toPublicJSON() {
|
toPublicJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
@@ -7,7 +7,7 @@ dayjs.extend(timezone);
|
|||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { Prometheus } = require("../prometheus");
|
const { Prometheus } = require("../prometheus");
|
||||||
const { log, 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, mqttAsync } = require("../util-server");
|
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mqttAsync, setSetting, httpNtlm, radius } = 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");
|
||||||
@@ -15,6 +15,9 @@ const { Proxy } = require("../proxy");
|
|||||||
const { demoMode } = require("../config");
|
const { demoMode } = require("../config");
|
||||||
const version = require("../../package.json").version;
|
const version = require("../../package.json").version;
|
||||||
const apicache = require("../modules/apicache");
|
const apicache = require("../modules/apicache");
|
||||||
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
const { CacheableDnsHttpAgent } = require("../cacheable-dns-http-agent");
|
||||||
|
const { DockerHost } = require("../docker");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* status:
|
* status:
|
||||||
@@ -27,12 +30,19 @@ class Monitor extends BeanModel {
|
|||||||
/**
|
/**
|
||||||
* Return an object that ready to parse to JSON for public
|
* Return an object that ready to parse to JSON for public
|
||||||
* Only show necessary data to public
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
async toPublicJSON(showTags = false) {
|
async toPublicJSON(showTags = false) {
|
||||||
let obj = {
|
let obj = {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
|
sendUrl: this.sendUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.sendUrl) {
|
||||||
|
obj.url = this.url;
|
||||||
|
}
|
||||||
|
|
||||||
if (showTags) {
|
if (showTags) {
|
||||||
obj.tags = await this.getTags();
|
obj.tags = await this.getTags();
|
||||||
}
|
}
|
||||||
@@ -41,6 +51,7 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an object that ready to parse to JSON
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
async toJSON(includeSensitiveData = true) {
|
async toJSON(includeSensitiveData = true) {
|
||||||
|
|
||||||
@@ -69,6 +80,7 @@ class Monitor extends BeanModel {
|
|||||||
type: this.type,
|
type: this.type,
|
||||||
interval: this.interval,
|
interval: this.interval,
|
||||||
retryInterval: this.retryInterval,
|
retryInterval: this.retryInterval,
|
||||||
|
resendInterval: this.resendInterval,
|
||||||
keyword: this.keyword,
|
keyword: this.keyword,
|
||||||
expiryNotification: this.isEnabledExpiryNotification(),
|
expiryNotification: this.isEnabledExpiryNotification(),
|
||||||
ignoreTls: this.getIgnoreTls(),
|
ignoreTls: this.getIgnoreTls(),
|
||||||
@@ -78,13 +90,26 @@ 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,
|
||||||
|
docker_container: this.docker_container,
|
||||||
|
docker_host: this.docker_host,
|
||||||
proxyId: this.proxy_id,
|
proxyId: this.proxy_id,
|
||||||
notificationIDList,
|
notificationIDList,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
mqttUsername: this.mqttUsername,
|
mqttUsername: this.mqttUsername,
|
||||||
mqttPassword: this.mqttPassword,
|
mqttPassword: this.mqttPassword,
|
||||||
mqttTopic: this.mqttTopic,
|
mqttTopic: this.mqttTopic,
|
||||||
mqttSuccessMessage: this.mqttSuccessMessage
|
mqttSuccessMessage: this.mqttSuccessMessage,
|
||||||
|
databaseConnectionString: this.databaseConnectionString,
|
||||||
|
databaseQuery: this.databaseQuery,
|
||||||
|
authMethod: this.authMethod,
|
||||||
|
authWorkstation: this.authWorkstation,
|
||||||
|
authDomain: this.authDomain,
|
||||||
|
radiusUsername: this.radiusUsername,
|
||||||
|
radiusPassword: this.radiusPassword,
|
||||||
|
radiusCalledStationId: this.radiusCalledStationId,
|
||||||
|
radiusCallingStationId: this.radiusCallingStationId,
|
||||||
|
radiusSecret: this.radiusSecret,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (includeSensitiveData) {
|
if (includeSensitiveData) {
|
||||||
@@ -101,6 +126,10 @@ class Monitor extends BeanModel {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all tags applied to this monitor
|
||||||
|
* @returns {Promise<LooseObject<any>[]>}
|
||||||
|
*/
|
||||||
async getTags() {
|
async getTags() {
|
||||||
return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [ this.id ]);
|
return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [ this.id ]);
|
||||||
}
|
}
|
||||||
@@ -114,6 +143,10 @@ class Monitor extends BeanModel {
|
|||||||
return Buffer.from(user + ":" + pass).toString("base64");
|
return Buffer.from(user + ":" + pass).toString("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the TLS expiry notification enabled?
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
isEnabledExpiryNotification() {
|
isEnabledExpiryNotification() {
|
||||||
return Boolean(this.expiryNotification);
|
return Boolean(this.expiryNotification);
|
||||||
}
|
}
|
||||||
@@ -134,10 +167,18 @@ class Monitor extends BeanModel {
|
|||||||
return Boolean(this.upsideDown);
|
return Boolean(this.upsideDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get accepted status codes
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
getAcceptedStatuscodes() {
|
getAcceptedStatuscodes() {
|
||||||
return JSON.parse(this.accepted_statuscodes_json);
|
return JSON.parse(this.accepted_statuscodes_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start monitor
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
*/
|
||||||
start(io) {
|
start(io) {
|
||||||
let previousBeat = null;
|
let previousBeat = null;
|
||||||
let retries = 0;
|
let retries = 0;
|
||||||
@@ -163,7 +204,7 @@ class Monitor extends BeanModel {
|
|||||||
// undefined if not https
|
// undefined if not https
|
||||||
let tlsInfo = undefined;
|
let tlsInfo = undefined;
|
||||||
|
|
||||||
if (!previousBeat) {
|
if (!previousBeat || this.type === "push") {
|
||||||
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,
|
||||||
]);
|
]);
|
||||||
@@ -173,8 +214,9 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
let bean = R.dispense("heartbeat");
|
let bean = R.dispense("heartbeat");
|
||||||
bean.monitor_id = this.id;
|
bean.monitor_id = this.id;
|
||||||
bean.time = R.isoDateTime(dayjs.utc());
|
bean.time = R.isoDateTimeMillis(dayjs.utc());
|
||||||
bean.status = DOWN;
|
bean.status = DOWN;
|
||||||
|
bean.downCount = previousBeat?.downCount || 0;
|
||||||
|
|
||||||
if (this.isUpsideDown()) {
|
if (this.isUpsideDown()) {
|
||||||
bean.status = flipStatus(bean.status);
|
bean.status = flipStatus(bean.status);
|
||||||
@@ -194,7 +236,7 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
// HTTP basic auth
|
// HTTP basic auth
|
||||||
let basicAuthHeader = {};
|
let basicAuthHeader = {};
|
||||||
if (this.basic_auth_user) {
|
if (this.auth_method === "basic") {
|
||||||
basicAuthHeader = {
|
basicAuthHeader = {
|
||||||
"Authorization": "Basic " + this.encodeBase64(this.basic_auth_user, this.basic_auth_pass),
|
"Authorization": "Basic " + this.encodeBase64(this.basic_auth_user, this.basic_auth_pass),
|
||||||
};
|
};
|
||||||
@@ -245,7 +287,21 @@ class Monitor extends BeanModel {
|
|||||||
log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
|
log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
|
||||||
log.debug("monitor", `[${this.name}] Axios Request`);
|
log.debug("monitor", `[${this.name}] Axios Request`);
|
||||||
|
|
||||||
let res = await axios.request(options);
|
let res;
|
||||||
|
if (this.auth_method === "ntlm") {
|
||||||
|
options.httpsAgent.keepAlive = true;
|
||||||
|
|
||||||
|
res = await httpNtlm(options, {
|
||||||
|
username: this.basic_auth_user,
|
||||||
|
password: this.basic_auth_pass,
|
||||||
|
domain: this.authDomain,
|
||||||
|
workstation: this.authWorkstation ? this.authWorkstation : undefined
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
res = await axios.request(options);
|
||||||
|
}
|
||||||
|
|
||||||
bean.msg = `${res.status} - ${res.statusText}`;
|
bean.msg = `${res.status} - ${res.statusText}`;
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
|
|
||||||
@@ -293,7 +349,11 @@ class Monitor extends BeanModel {
|
|||||||
bean.msg += ", keyword is found";
|
bean.msg += ", keyword is found";
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(bean.msg + ", but keyword is not found");
|
data = data.replace(/<[^>]*>?|[\n\r]|\s+/gm, " ");
|
||||||
|
if (data.length > 50) {
|
||||||
|
data = data.substring(0, 47) + "...";
|
||||||
|
}
|
||||||
|
throw new Error(bean.msg + ", but keyword is not in [" + data + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -311,7 +371,7 @@ class Monitor extends BeanModel {
|
|||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
let dnsMessage = "";
|
let dnsMessage = "";
|
||||||
|
|
||||||
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.port, 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") {
|
||||||
@@ -348,25 +408,33 @@ class Monitor extends BeanModel {
|
|||||||
bean.msg = dnsMessage;
|
bean.msg = dnsMessage;
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
} else if (this.type === "push") { // Type: Push
|
} else if (this.type === "push") { // Type: Push
|
||||||
const time = R.isoDateTime(dayjs.utc().subtract(this.interval, "second"));
|
log.debug("monitor", `[${this.name}] Checking monitor at ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
||||||
|
const bufferTime = 1000; // 1s buffer to accommodate clock differences
|
||||||
|
|
||||||
let heartbeatCount = await R.count("heartbeat", " monitor_id = ? AND time > ? ", [
|
if (previousBeat) {
|
||||||
this.id,
|
const msSinceLastBeat = dayjs.utc().valueOf() - dayjs.utc(previousBeat.time).valueOf();
|
||||||
time
|
|
||||||
]);
|
|
||||||
|
|
||||||
log.debug("monitor", "heartbeatCount" + heartbeatCount + " " + time);
|
log.debug("monitor", `[${this.name}] msSinceLastBeat = ${msSinceLastBeat}`);
|
||||||
|
|
||||||
if (heartbeatCount <= 0) {
|
// If the previous beat was down or pending we use the regular
|
||||||
// Fix #922, since previous heartbeat could be inserted by api, it should get from database
|
// beatInterval/retryInterval in the setTimeout further below
|
||||||
previousBeat = await Monitor.getPreviousHeartbeat(this.id);
|
if (previousBeat.status !== (this.isUpsideDown() ? DOWN : UP) || msSinceLastBeat > beatInterval * 1000 + bufferTime) {
|
||||||
|
throw new Error("No heartbeat in the time window");
|
||||||
throw new Error("No heartbeat in the time window");
|
} else {
|
||||||
|
let timeout = beatInterval * 1000 - msSinceLastBeat;
|
||||||
|
if (timeout < 0) {
|
||||||
|
timeout = bufferTime;
|
||||||
|
} else {
|
||||||
|
timeout += bufferTime;
|
||||||
|
}
|
||||||
|
// No need to insert successful heartbeat for push type, so end here
|
||||||
|
retries = 0;
|
||||||
|
log.debug("monitor", `[${this.name}] timeout = ${timeout}`);
|
||||||
|
this.heartbeatInterval = setTimeout(beat, timeout);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// No need to insert successful heartbeat for push type, so end here
|
throw new Error("No heartbeat in the time window");
|
||||||
retries = 0;
|
|
||||||
this.heartbeatInterval = setTimeout(beat, beatInterval * 1000);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (this.type === "steam") {
|
} else if (this.type === "steam") {
|
||||||
@@ -384,10 +452,13 @@ class Monitor extends BeanModel {
|
|||||||
"Accept": "*/*",
|
"Accept": "*/*",
|
||||||
"User-Agent": "Uptime-Kuma/" + version,
|
"User-Agent": "Uptime-Kuma/" + version,
|
||||||
},
|
},
|
||||||
httpsAgent: new https.Agent({
|
httpsAgent: CacheableDnsHttpAgent.getHttpsAgent({
|
||||||
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(),
|
||||||
}),
|
}),
|
||||||
|
httpAgent: CacheableDnsHttpAgent.getHttpAgent({
|
||||||
|
maxCachedSessions: 0,
|
||||||
|
}),
|
||||||
maxRedirects: this.maxredirects,
|
maxRedirects: this.maxredirects,
|
||||||
validateStatus: (status) => {
|
validateStatus: (status) => {
|
||||||
return checkStatusCode(status, this.getAcceptedStatuscodes());
|
return checkStatusCode(status, this.getAcceptedStatuscodes());
|
||||||
@@ -408,6 +479,35 @@ 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 === "docker") {
|
||||||
|
log.debug(`[${this.name}] Prepare Options for Axios`);
|
||||||
|
|
||||||
|
const dockerHost = await R.load("docker_host", this.docker_host);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
url: `/containers/${this.docker_container}/json`,
|
||||||
|
headers: {
|
||||||
|
"Accept": "*/*",
|
||||||
|
"User-Agent": "Uptime-Kuma/" + version,
|
||||||
|
},
|
||||||
|
httpsAgent: new https.Agent({
|
||||||
|
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
|
||||||
|
rejectUnauthorized: ! this.getIgnoreTls(),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dockerHost._dockerType === "socket") {
|
||||||
|
options.socketPath = dockerHost._dockerDaemon;
|
||||||
|
} else if (dockerHost._dockerType === "tcp") {
|
||||||
|
options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug(`[${this.name}] Axios Request`);
|
||||||
|
let res = await axios.request(options);
|
||||||
|
if (res.data.State.Running) {
|
||||||
|
bean.status = UP;
|
||||||
|
bean.msg = "";
|
||||||
|
}
|
||||||
} else if (this.type === "mqtt") {
|
} else if (this.type === "mqtt") {
|
||||||
bean.msg = await mqttAsync(this.hostname, this.mqttTopic, this.mqttSuccessMessage, {
|
bean.msg = await mqttAsync(this.hostname, this.mqttTopic, this.mqttSuccessMessage, {
|
||||||
port: this.port,
|
port: this.port,
|
||||||
@@ -416,6 +516,46 @@ class Monitor extends BeanModel {
|
|||||||
interval: this.interval,
|
interval: this.interval,
|
||||||
});
|
});
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
|
} else if (this.type === "sqlserver") {
|
||||||
|
let startTime = dayjs().valueOf();
|
||||||
|
|
||||||
|
await mssqlQuery(this.databaseConnectionString, this.databaseQuery);
|
||||||
|
|
||||||
|
bean.msg = "";
|
||||||
|
bean.status = UP;
|
||||||
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
|
} else if (this.type === "postgres") {
|
||||||
|
let startTime = dayjs().valueOf();
|
||||||
|
|
||||||
|
await postgresQuery(this.databaseConnectionString, this.databaseQuery);
|
||||||
|
|
||||||
|
bean.msg = "";
|
||||||
|
bean.status = UP;
|
||||||
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
|
} else if (this.type === "radius") {
|
||||||
|
let startTime = dayjs().valueOf();
|
||||||
|
try {
|
||||||
|
const resp = await radius(
|
||||||
|
this.hostname,
|
||||||
|
this.radiusUsername,
|
||||||
|
this.radiusPassword,
|
||||||
|
this.radiusCalledStationId,
|
||||||
|
this.radiusCallingStationId,
|
||||||
|
this.radiusSecret
|
||||||
|
);
|
||||||
|
if (resp.code) {
|
||||||
|
bean.msg = resp.code;
|
||||||
|
}
|
||||||
|
bean.status = UP;
|
||||||
|
} catch (error) {
|
||||||
|
bean.status = DOWN;
|
||||||
|
if (error.response?.code) {
|
||||||
|
bean.msg = error.response.code;
|
||||||
|
} else {
|
||||||
|
bean.msg = error.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
} else {
|
} else {
|
||||||
bean.msg = "Unknown Monitor Type";
|
bean.msg = "Unknown Monitor Type";
|
||||||
bean.status = PENDING;
|
bean.status = PENDING;
|
||||||
@@ -457,23 +597,38 @@ class Monitor extends BeanModel {
|
|||||||
log.debug("monitor", `[${this.name}] sendNotification`);
|
log.debug("monitor", `[${this.name}] sendNotification`);
|
||||||
await Monitor.sendNotification(isFirstBeat, this, bean);
|
await Monitor.sendNotification(isFirstBeat, this, bean);
|
||||||
|
|
||||||
|
// Reset down count
|
||||||
|
bean.downCount = 0;
|
||||||
|
|
||||||
// Clear Status Page Cache
|
// Clear Status Page Cache
|
||||||
log.debug("monitor", `[${this.name}] apicache clear`);
|
log.debug("monitor", `[${this.name}] apicache clear`);
|
||||||
apicache.clear();
|
apicache.clear();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bean.important = false;
|
bean.important = false;
|
||||||
|
|
||||||
|
if (bean.status === DOWN && this.resendInterval > 0) {
|
||||||
|
++bean.downCount;
|
||||||
|
if (bean.downCount >= this.resendInterval) {
|
||||||
|
// Send notification again, because we are still DOWN
|
||||||
|
log.debug("monitor", `[${this.name}] sendNotification again: Down Count: ${bean.downCount} | Resend Interval: ${this.resendInterval}`);
|
||||||
|
await Monitor.sendNotification(isFirstBeat, this, bean);
|
||||||
|
|
||||||
|
// Reset down count
|
||||||
|
bean.downCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bean.status === UP) {
|
if (bean.status === UP) {
|
||||||
log.info("monitor", `Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${beatInterval} seconds | Type: ${this.type}`);
|
log.debug("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;
|
||||||
}
|
}
|
||||||
log.warn("monitor", `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 {
|
||||||
log.warn("monitor", `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} | Down Count: ${bean.downCount} | Resend Interval: ${this.resendInterval}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("monitor", `[${this.name}] Send to socket`);
|
log.debug("monitor", `[${this.name}] Send to socket`);
|
||||||
@@ -497,12 +652,13 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Get a heartbeat and handle errors */
|
||||||
const safeBeat = async () => {
|
const safeBeat = async () => {
|
||||||
try {
|
try {
|
||||||
await beat();
|
await beat();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.trace(e);
|
console.trace(e);
|
||||||
errorLog(e, false);
|
UptimeKumaServer.errorLog(e, false);
|
||||||
log.error("monitor", "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) {
|
||||||
@@ -522,6 +678,7 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Stop monitor */
|
||||||
stop() {
|
stop() {
|
||||||
clearTimeout(this.heartbeatInterval);
|
clearTimeout(this.heartbeatInterval);
|
||||||
this.isStop = true;
|
this.isStop = true;
|
||||||
@@ -529,6 +686,10 @@ class Monitor extends BeanModel {
|
|||||||
this.prometheus().remove();
|
this.prometheus().remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a new prometheus instance
|
||||||
|
* @returns {Prometheus}
|
||||||
|
*/
|
||||||
prometheus() {
|
prometheus() {
|
||||||
return new Prometheus(this);
|
return new Prometheus(this);
|
||||||
}
|
}
|
||||||
@@ -537,7 +698,7 @@ class Monitor extends BeanModel {
|
|||||||
* Helper Method:
|
* Helper Method:
|
||||||
* returns URL object for further usage
|
* returns URL object for further usage
|
||||||
* returns null if url is invalid
|
* returns null if url is invalid
|
||||||
* @returns {null|URL}
|
* @returns {(null|URL)}
|
||||||
*/
|
*/
|
||||||
getUrl() {
|
getUrl() {
|
||||||
try {
|
try {
|
||||||
@@ -550,7 +711,7 @@ class Monitor extends BeanModel {
|
|||||||
/**
|
/**
|
||||||
* Store TLS info to database
|
* Store TLS info to database
|
||||||
* @param checkCertificateResult
|
* @param checkCertificateResult
|
||||||
* @returns {Promise<object>}
|
* @returns {Promise<Object>}
|
||||||
*/
|
*/
|
||||||
async updateTlsInfo(checkCertificateResult) {
|
async updateTlsInfo(checkCertificateResult) {
|
||||||
let tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
let tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
||||||
@@ -592,6 +753,12 @@ class Monitor extends BeanModel {
|
|||||||
return checkCertificateResult;
|
return checkCertificateResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send statistics to clients
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {number} monitorID ID of monitor to send
|
||||||
|
* @param {number} userID ID of user to send to
|
||||||
|
*/
|
||||||
static async sendStats(io, monitorID, userID) {
|
static async sendStats(io, monitorID, userID) {
|
||||||
const hasClients = getTotalClientInRoom(io, userID) > 0;
|
const hasClients = getTotalClientInRoom(io, userID) > 0;
|
||||||
|
|
||||||
@@ -606,8 +773,8 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Send the average ping to user
|
||||||
* @param duration : int Hours
|
* @param {number} duration Hours
|
||||||
*/
|
*/
|
||||||
static async sendAvgPing(duration, io, monitorID, userID) {
|
static async sendAvgPing(duration, io, monitorID, userID) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
@@ -627,6 +794,12 @@ class Monitor extends BeanModel {
|
|||||||
io.to(userID).emit("avgPing", monitorID, avgPing);
|
io.to(userID).emit("avgPing", monitorID, avgPing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send certificate information to client
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {number} monitorID ID of monitor to send
|
||||||
|
* @param {number} userID ID of user to send to
|
||||||
|
*/
|
||||||
static async sendCertInfo(io, monitorID, userID) {
|
static async sendCertInfo(io, monitorID, userID) {
|
||||||
let tlsInfo = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
let tlsInfo = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
||||||
monitorID,
|
monitorID,
|
||||||
@@ -640,7 +813,8 @@ class Monitor extends BeanModel {
|
|||||||
* Uptime with calculation
|
* Uptime with calculation
|
||||||
* Calculation based on:
|
* Calculation based on:
|
||||||
* https://www.uptrends.com/support/kb/reporting/calculation-of-uptime-and-downtime
|
* https://www.uptrends.com/support/kb/reporting/calculation-of-uptime-and-downtime
|
||||||
* @param duration : int Hours
|
* @param {number} duration Hours
|
||||||
|
* @param {number} monitorID ID of monitor to calculate
|
||||||
*/
|
*/
|
||||||
static async calcUptime(duration, monitorID) {
|
static async calcUptime(duration, monitorID) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
@@ -694,7 +868,7 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Handle new monitor with only one beat, because the beat's duration = 0
|
// Handle new monitor with only one beat, because the beat's duration = 0
|
||||||
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [monitorID]));
|
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [ monitorID ]));
|
||||||
|
|
||||||
if (status === UP) {
|
if (status === UP) {
|
||||||
uptime = 1;
|
uptime = 1;
|
||||||
@@ -706,13 +880,23 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Uptime
|
* Send Uptime
|
||||||
* @param duration : int Hours
|
* @param {number} duration Hours
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {number} monitorID ID of monitor to send
|
||||||
|
* @param {number} userID ID of user to send to
|
||||||
*/
|
*/
|
||||||
static async sendUptime(duration, io, monitorID, userID) {
|
static async sendUptime(duration, io, monitorID, userID) {
|
||||||
const uptime = await this.calcUptime(duration, monitorID);
|
const uptime = await this.calcUptime(duration, monitorID);
|
||||||
io.to(userID).emit("uptime", monitorID, duration, uptime);
|
io.to(userID).emit("uptime", monitorID, duration, uptime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has status of monitor changed since last beat?
|
||||||
|
* @param {boolean} isFirstBeat Is this the first beat of this monitor?
|
||||||
|
* @param {const} previousBeatStatus Status of the previous beat
|
||||||
|
* @param {const} currentBeatStatus Status of the current beat
|
||||||
|
* @returns {boolean} True if is an important beat else false
|
||||||
|
*/
|
||||||
static isImportantBeat(isFirstBeat, previousBeatStatus, currentBeatStatus) {
|
static isImportantBeat(isFirstBeat, previousBeatStatus, currentBeatStatus) {
|
||||||
// * ? -> ANY STATUS = important [isFirstBeat]
|
// * ? -> ANY STATUS = important [isFirstBeat]
|
||||||
// UP -> PENDING = not important
|
// UP -> PENDING = not important
|
||||||
@@ -731,6 +915,12 @@ class Monitor extends BeanModel {
|
|||||||
return isImportant;
|
return isImportant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a notification about a monitor
|
||||||
|
* @param {boolean} isFirstBeat Is this beat the first of this monitor?
|
||||||
|
* @param {Monitor} monitor The monitor to send a notificaton about
|
||||||
|
* @param {Bean} bean Status information about monitor
|
||||||
|
*/
|
||||||
static async sendNotification(isFirstBeat, monitor, bean) {
|
static async sendNotification(isFirstBeat, monitor, bean) {
|
||||||
if (!isFirstBeat || bean.status === DOWN) {
|
if (!isFirstBeat || bean.status === DOWN) {
|
||||||
const notificationList = await Monitor.getNotificationList(monitor);
|
const notificationList = await Monitor.getNotificationList(monitor);
|
||||||
@@ -755,6 +945,11 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of notification providers for a given monitor
|
||||||
|
* @param {Monitor} monitor Monitor to get notification providers for
|
||||||
|
* @returns {Promise<LooseObject<any>[]>}
|
||||||
|
*/
|
||||||
static async getNotificationList(monitor) {
|
static async getNotificationList(monitor) {
|
||||||
let notificationList = await R.getAll("SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id ", [
|
let notificationList = await R.getAll("SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id ", [
|
||||||
monitor.id,
|
monitor.id,
|
||||||
@@ -762,17 +957,38 @@ class Monitor extends BeanModel {
|
|||||||
return notificationList;
|
return notificationList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send notification about a certificate
|
||||||
|
* @param {Object} tlsInfoObject Information about certificate
|
||||||
|
*/
|
||||||
async sendCertNotification(tlsInfoObject) {
|
async sendCertNotification(tlsInfoObject) {
|
||||||
if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
|
if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
|
||||||
const notificationList = await Monitor.getNotificationList(this);
|
const notificationList = await Monitor.getNotificationList(this);
|
||||||
|
|
||||||
log.debug("monitor", "call sendCertNotificationByTargetDays");
|
let notifyDays = await setting("tlsExpiryNotifyDays");
|
||||||
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 21, notificationList);
|
if (notifyDays == null || !Array.isArray(notifyDays)) {
|
||||||
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 14, notificationList);
|
// Reset Default
|
||||||
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 7, notificationList);
|
setSetting("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general");
|
||||||
|
notifyDays = [ 7, 14, 21 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notifyDays != null && Array.isArray(notifyDays)) {
|
||||||
|
for (const day of notifyDays) {
|
||||||
|
log.debug("monitor", "call sendCertNotificationByTargetDays", day);
|
||||||
|
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, day, notificationList);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a certificate notification when certificate expires in less
|
||||||
|
* than target days
|
||||||
|
* @param {number} daysRemaining Number of days remaining on certifcate
|
||||||
|
* @param {number} targetDays Number of days to alert after
|
||||||
|
* @param {LooseObject<any>[]} notificationList List of notification providers
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {
|
async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {
|
||||||
|
|
||||||
if (daysRemaining > targetDays) {
|
if (daysRemaining > targetDays) {
|
||||||
@@ -820,6 +1036,11 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of the previous heartbeat
|
||||||
|
* @param {number} monitorID ID of monitor to check
|
||||||
|
* @returns {Promise<LooseObject<any>>}
|
||||||
|
*/
|
||||||
static async getPreviousHeartbeat(monitorID) {
|
static async getPreviousHeartbeat(monitorID) {
|
||||||
return await R.getRow(`
|
return await R.getRow(`
|
||||||
SELECT status, time FROM heartbeat
|
SELECT status, time FROM heartbeat
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
|
|
||||||
class Proxy extends BeanModel {
|
class Proxy extends BeanModel {
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this._id,
|
id: this._id,
|
||||||
|
@@ -1,11 +1,111 @@
|
|||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
|
const cheerio = require("cheerio");
|
||||||
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
|
||||||
class StatusPage extends BeanModel {
|
class StatusPage extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like this: { "test-uptime.kuma.pet": "default" }
|
||||||
|
* @type {{}}
|
||||||
|
*/
|
||||||
static domainMappingList = { };
|
static domainMappingList = { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* @param {Response} response
|
||||||
|
* @param {string} indexHTML
|
||||||
|
* @param {string} slug
|
||||||
|
*/
|
||||||
|
static async handleStatusPageResponse(response, indexHTML, slug) {
|
||||||
|
let statusPage = await R.findOne("status_page", " slug = ? ", [
|
||||||
|
slug
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (statusPage) {
|
||||||
|
response.send(await StatusPage.renderHTML(indexHTML, statusPage));
|
||||||
|
} else {
|
||||||
|
response.status(404).send(UptimeKumaServer.getInstance().indexHTML);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SSR for status pages
|
||||||
|
* @param {string} indexHTML
|
||||||
|
* @param {StatusPage} statusPage
|
||||||
|
*/
|
||||||
|
static async renderHTML(indexHTML, statusPage) {
|
||||||
|
const $ = cheerio.load(indexHTML);
|
||||||
|
const description155 = statusPage.description?.substring(0, 155);
|
||||||
|
|
||||||
|
$("title").text(statusPage.title);
|
||||||
|
$("meta[name=description]").attr("content", description155);
|
||||||
|
|
||||||
|
if (statusPage.icon) {
|
||||||
|
$("link[rel=icon]")
|
||||||
|
.attr("href", statusPage.icon)
|
||||||
|
.removeAttr("type");
|
||||||
|
|
||||||
|
$("link[rel=apple-touch-icon]").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
const head = $("head");
|
||||||
|
|
||||||
|
// OG Meta Tags
|
||||||
|
head.append(`<meta property="og:title" content="${statusPage.title}" />`);
|
||||||
|
head.append(`<meta property="og:description" content="${description155}" />`);
|
||||||
|
|
||||||
|
// Preload data
|
||||||
|
const json = JSON.stringify(await StatusPage.getStatusPageData(statusPage));
|
||||||
|
head.append(`
|
||||||
|
<script>
|
||||||
|
window.preloadData = ${json}
|
||||||
|
</script>
|
||||||
|
`);
|
||||||
|
|
||||||
|
// manifest.json
|
||||||
|
$("link[rel=manifest]").attr("href", `/api/status-page/${statusPage.slug}/manifest.json`);
|
||||||
|
|
||||||
|
return $.root().html();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all status page data in one call
|
||||||
|
* @param {StatusPage} statusPage
|
||||||
|
*/
|
||||||
|
static async getStatusPageData(statusPage) {
|
||||||
|
// Incident
|
||||||
|
let incident = await R.findOne("incident", " pin = 1 AND active = 1 AND status_page_id = ? ", [
|
||||||
|
statusPage.id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (incident) {
|
||||||
|
incident = incident.toPublicJSON();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public Group List
|
||||||
|
const publicGroupList = [];
|
||||||
|
const showTags = !!statusPage.show_tags;
|
||||||
|
|
||||||
|
const list = await R.find("group", " public = 1 AND status_page_id = ? ORDER BY weight ", [
|
||||||
|
statusPage.id
|
||||||
|
]);
|
||||||
|
|
||||||
|
for (let groupBean of list) {
|
||||||
|
let monitorGroup = await groupBean.toPublicJSON(showTags);
|
||||||
|
publicGroupList.push(monitorGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response
|
||||||
|
return {
|
||||||
|
config: await statusPage.toPublicJSON(),
|
||||||
|
incident,
|
||||||
|
publicGroupList
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads domain mapping from DB
|
||||||
* Return object like this: { "test-uptime.kuma.pet": "default" }
|
* Return object like this: { "test-uptime.kuma.pet": "default" }
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
@@ -17,6 +117,12 @@ class StatusPage extends BeanModel {
|
|||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send status page list to client
|
||||||
|
* @param {Server} io io Socket server instance
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
* @returns {Promise<Bean[]>}
|
||||||
|
*/
|
||||||
static async sendStatusPageList(io, socket) {
|
static async sendStatusPageList(io, socket) {
|
||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
@@ -30,6 +136,11 @@ class StatusPage extends BeanModel {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update list of domain names
|
||||||
|
* @param {string[]} domainNameList
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async updateDomainNameList(domainNameList) {
|
async updateDomainNameList(domainNameList) {
|
||||||
|
|
||||||
if (!Array.isArray(domainNameList)) {
|
if (!Array.isArray(domainNameList)) {
|
||||||
@@ -69,6 +180,10 @@ class StatusPage extends BeanModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of domain names
|
||||||
|
* @returns {Object[]}
|
||||||
|
*/
|
||||||
getDomainNameList() {
|
getDomainNameList() {
|
||||||
let domainList = [];
|
let domainList = [];
|
||||||
for (let domain in StatusPage.domainMappingList) {
|
for (let domain in StatusPage.domainMappingList) {
|
||||||
@@ -81,6 +196,10 @@ class StatusPage extends BeanModel {
|
|||||||
return domainList;
|
return domainList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
async toJSON() {
|
async toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
@@ -98,6 +217,11 @@ class StatusPage extends BeanModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON for public
|
||||||
|
* Only show necessary data to public
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
async toPublicJSON() {
|
async toPublicJSON() {
|
||||||
return {
|
return {
|
||||||
slug: this.slug,
|
slug: this.slug,
|
||||||
@@ -113,12 +237,20 @@ class StatusPage extends BeanModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert slug to status page ID
|
||||||
|
* @param {string} slug
|
||||||
|
*/
|
||||||
static async slugToID(slug) {
|
static async slugToID(slug) {
|
||||||
return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [
|
return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [
|
||||||
slug
|
slug
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get path to the icon for the page
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
getIcon() {
|
getIcon() {
|
||||||
if (!this.icon) {
|
if (!this.icon) {
|
||||||
return "/icon.svg";
|
return "/icon.svg";
|
||||||
|
@@ -1,6 +1,11 @@
|
|||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
|
|
||||||
class Tag extends BeanModel {
|
class Tag extends BeanModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an object that ready to parse to JSON
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this._id,
|
id: this._id,
|
||||||
|
@@ -3,19 +3,30 @@ const passwordHash = require("../password-hash");
|
|||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
|
|
||||||
class User extends BeanModel {
|
class User extends BeanModel {
|
||||||
|
/**
|
||||||
|
* Reset user password
|
||||||
|
* Fix #1510, as in the context reset-password.js, there is no auto model mapping. Call this static function instead.
|
||||||
|
* @param {number} userID ID of user to update
|
||||||
|
* @param {string} newPassword
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async resetPassword(userID, newPassword) {
|
||||||
|
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
|
||||||
|
passwordHash.generate(newPassword),
|
||||||
|
userID
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct execute, no need R.store()
|
* Reset this users password
|
||||||
* @param newPassword
|
* @param {string} 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;
|
||||||
|
@@ -13,27 +13,49 @@ let t = {
|
|||||||
|
|
||||||
let instances = [];
|
let instances = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a === b
|
||||||
|
* @param {any} a
|
||||||
|
* @returns {function(any): boolean}
|
||||||
|
*/
|
||||||
let matches = function (a) {
|
let matches = function (a) {
|
||||||
return function (b) {
|
return function (b) {
|
||||||
return a === b;
|
return a === b;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a!==b
|
||||||
|
* @param {any} a
|
||||||
|
* @returns {function(any): boolean}
|
||||||
|
*/
|
||||||
let doesntMatch = function (a) {
|
let doesntMatch = function (a) {
|
||||||
return function (b) {
|
return function (b) {
|
||||||
return !matches(a)(b);
|
return !matches(a)(b);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get log duration
|
||||||
|
* @param {number} d Time in ms
|
||||||
|
* @param {string} prefix Prefix for log
|
||||||
|
* @returns {string} Coloured log string
|
||||||
|
*/
|
||||||
let logDuration = function (d, prefix) {
|
let logDuration = function (d, prefix) {
|
||||||
let str = d > 1000 ? (d / 1000).toFixed(2) + "sec" : d + "ms";
|
let str = d > 1000 ? (d / 1000).toFixed(2) + "sec" : d + "ms";
|
||||||
return "\x1b[33m- " + (prefix ? prefix + " " : "") + str + "\x1b[0m";
|
return "\x1b[33m- " + (prefix ? prefix + " " : "") + str + "\x1b[0m";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get safe headers
|
||||||
|
* @param {Object} res Express response object
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
function getSafeHeaders(res) {
|
function getSafeHeaders(res) {
|
||||||
return res.getHeaders ? res.getHeaders() : res._headers;
|
return res.getHeaders ? res.getHeaders() : res._headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Constructor for ApiCache instance */
|
||||||
function ApiCache() {
|
function ApiCache() {
|
||||||
let memCache = new MemoryCache();
|
let memCache = new MemoryCache();
|
||||||
|
|
||||||
@@ -70,10 +92,10 @@ function ApiCache() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a message to the console if the `DEBUG` environment variable is set.
|
* Logs a message to the console if the `DEBUG` environment variable is set.
|
||||||
* @param {string} a - The first argument to log.
|
* @param {string} a The first argument to log.
|
||||||
* @param {string} b - The second argument to log.
|
* @param {string} b The second argument to log.
|
||||||
* @param {string} c - The third argument to log.
|
* @param {string} c The third argument to log.
|
||||||
* @param {string} d - The fourth argument to log, and so on... (optional)
|
* @param {string} d The fourth argument to log, and so on... (optional)
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
@@ -90,8 +112,8 @@ function ApiCache() {
|
|||||||
* Returns true if the given request and response should be logged.
|
* Returns true if the given request and response should be logged.
|
||||||
* @param {Object} request The HTTP request object.
|
* @param {Object} request The HTTP request object.
|
||||||
* @param {Object} response The HTTP response object.
|
* @param {Object} response The HTTP response object.
|
||||||
*
|
* @param {function(Object, Object):boolean} toggle
|
||||||
* Generated by Trelent
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function shouldCacheResponse(request, response, toggle) {
|
function shouldCacheResponse(request, response, toggle) {
|
||||||
let opt = globalOptions;
|
let opt = globalOptions;
|
||||||
@@ -116,10 +138,9 @@ function ApiCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a key to the index.
|
* Add key to index array
|
||||||
* @param {string} key The key to add.
|
* @param {string} key Key to add
|
||||||
*
|
* @param {Object} req Express request object
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
function addIndexEntries(key, req) {
|
function addIndexEntries(key, req) {
|
||||||
let groupName = req.apicacheGroup;
|
let groupName = req.apicacheGroup;
|
||||||
@@ -135,8 +156,11 @@ function ApiCache() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new object containing only the whitelisted headers.
|
* Returns a new object containing only the whitelisted headers.
|
||||||
* @param {Object} headers The original object of header names and values.
|
* @param {Object} headers The original object of header names and
|
||||||
* @param {Array.<string>} globalOptions.headerWhitelist An array of strings representing the whitelisted header names to keep in the output object.
|
* values.
|
||||||
|
* @param {string[]} globalOptions.headerWhitelist An array of
|
||||||
|
* strings representing the whitelisted header names to keep in the
|
||||||
|
* output object.
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
@@ -152,8 +176,10 @@ function ApiCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Create a cache object
|
||||||
* @param {Object} headers The response headers to filter.
|
* @param {Object} headers The response headers to filter.
|
||||||
* @returns {Object} A new object containing only the whitelisted response headers.
|
* @returns {Object} A new object containing only the whitelisted
|
||||||
|
* response headers.
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
@@ -170,8 +196,9 @@ function ApiCache() {
|
|||||||
/**
|
/**
|
||||||
* Sets a cache value for the given key.
|
* Sets a cache value for the given key.
|
||||||
* @param {string} key The cache key to set.
|
* @param {string} key The cache key to set.
|
||||||
* @param {*} value The cache value to set.
|
* @param {any} value The cache value to set.
|
||||||
* @param {number} duration How long in milliseconds the cached response should be valid for (defaults to 1 hour).
|
* @param {number} duration How long in milliseconds the cached
|
||||||
|
* response should be valid for (defaults to 1 hour).
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
@@ -199,7 +226,8 @@ function ApiCache() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends content to the response.
|
* Appends content to the response.
|
||||||
* @param {string|Buffer} content The content to append.
|
* @param {Object} res Express response object
|
||||||
|
* @param {(string|Buffer)} content The content to append.
|
||||||
*
|
*
|
||||||
* Generated by Trelent
|
* Generated by Trelent
|
||||||
*/
|
*/
|
||||||
@@ -229,11 +257,15 @@ function ApiCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monkeypatches the response object to add cache control headers and create a cache object.
|
* Monkeypatches the response object to add cache control headers
|
||||||
* @param {Object} req - The request object.
|
* and create a cache object.
|
||||||
* @param {Object} res - The response object.
|
* @param {Object} req Express request object
|
||||||
*
|
* @param {Object} res Express response object
|
||||||
* Generated by Trelent
|
* @param {function} next Function to call next
|
||||||
|
* @param {string} key Key to add response as
|
||||||
|
* @param {number} duration Time to cache response for
|
||||||
|
* @param {string} strDuration Duration in string form
|
||||||
|
* @param {function(Object, Object):boolean} toggle
|
||||||
*/
|
*/
|
||||||
function makeResponseCacheable(req, res, next, key, duration, strDuration, toggle) {
|
function makeResponseCacheable(req, res, next, key, duration, strDuration, toggle) {
|
||||||
// monkeypatch res.end to create cache object
|
// monkeypatch res.end to create cache object
|
||||||
@@ -302,11 +334,15 @@ function ApiCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Request} request
|
* Send a cached response to client
|
||||||
* @param {Response} response
|
* @param {Request} request Express request object
|
||||||
* @returns {boolean|undefined} true if the request should be cached, false otherwise. If undefined, defaults to true.
|
* @param {Response} response Express response object
|
||||||
*
|
* @param {object} cacheObject Cache object to send
|
||||||
* Generated by Trelent
|
* @param {function(Object, Object):boolean} toggle
|
||||||
|
* @param {function} next Function to call next
|
||||||
|
* @param {number} duration Not used
|
||||||
|
* @returns {boolean|undefined} true if the request should be
|
||||||
|
* cached, false otherwise. If undefined, defaults to true.
|
||||||
*/
|
*/
|
||||||
function sendCachedResponse(request, response, cacheObject, toggle, next, duration) {
|
function sendCachedResponse(request, response, cacheObject, toggle, next, duration) {
|
||||||
if (toggle && !toggle(request, response)) {
|
if (toggle && !toggle(request, response)) {
|
||||||
@@ -348,12 +384,19 @@ function ApiCache() {
|
|||||||
return response.end(data, cacheObject.encoding);
|
return response.end(data, cacheObject.encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sync caching options */
|
||||||
function syncOptions() {
|
function syncOptions() {
|
||||||
for (let i in middlewareOptions) {
|
for (let i in middlewareOptions) {
|
||||||
Object.assign(middlewareOptions[i].options, globalOptions, middlewareOptions[i].localOptions);
|
Object.assign(middlewareOptions[i].options, globalOptions, middlewareOptions[i].localOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear key from cache
|
||||||
|
* @param {string} target Key to clear
|
||||||
|
* @param {boolean} isAutomatic Is the key being cleared automatically
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
this.clear = function (target, isAutomatic) {
|
this.clear = function (target, isAutomatic) {
|
||||||
let group = index.groups[target];
|
let group = index.groups[target];
|
||||||
let redis = globalOptions.redisClient;
|
let redis = globalOptions.redisClient;
|
||||||
@@ -430,10 +473,11 @@ function ApiCache() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a duration string to an integer number of milliseconds.
|
* Converts a duration string to an integer number of milliseconds.
|
||||||
* @param {string} duration - The string to convert.
|
* @param {(string|number)} duration The string to convert.
|
||||||
* @returns {number} The converted value in milliseconds, or the defaultDuration if it can't be parsed.
|
* @param {number} defaultDuration The default duration to return if
|
||||||
*
|
* can't parse duration
|
||||||
* Generated by Trelent
|
* @returns {number} The converted value in milliseconds, or the
|
||||||
|
* defaultDuration if it can't be parsed.
|
||||||
*/
|
*/
|
||||||
function parseDuration(duration, defaultDuration) {
|
function parseDuration(duration, defaultDuration) {
|
||||||
if (typeof duration === "number") {
|
if (typeof duration === "number") {
|
||||||
@@ -457,17 +501,24 @@ function ApiCache() {
|
|||||||
return defaultDuration;
|
return defaultDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse duration
|
||||||
|
* @param {(number|string)} duration
|
||||||
|
* @returns {number} Duration parsed to a number
|
||||||
|
*/
|
||||||
this.getDuration = function (duration) {
|
this.getDuration = function (duration) {
|
||||||
return parseDuration(duration, globalOptions.defaultDuration);
|
return parseDuration(duration, globalOptions.defaultDuration);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return cache performance statistics (hit rate). Suitable for putting into a route:
|
* Return cache performance statistics (hit rate). Suitable for
|
||||||
|
* putting into a route:
|
||||||
* <code>
|
* <code>
|
||||||
* app.get('/api/cache/performance', (req, res) => {
|
* app.get('/api/cache/performance', (req, res) => {
|
||||||
* res.json(apicache.getPerformance())
|
* res.json(apicache.getPerformance())
|
||||||
* })
|
* })
|
||||||
* </code>
|
* </code>
|
||||||
|
* @returns {any[]}
|
||||||
*/
|
*/
|
||||||
this.getPerformance = function () {
|
this.getPerformance = function () {
|
||||||
return performanceArray.map(function (p) {
|
return performanceArray.map(function (p) {
|
||||||
@@ -475,6 +526,11 @@ function ApiCache() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get index of a group
|
||||||
|
* @param {string} group
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
this.getIndex = function (group) {
|
this.getIndex = function (group) {
|
||||||
if (group) {
|
if (group) {
|
||||||
return index.groups[group];
|
return index.groups[group];
|
||||||
@@ -483,6 +539,14 @@ function ApiCache() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Express middleware
|
||||||
|
* @param {(string|number)} strDuration Duration to cache responses
|
||||||
|
* for.
|
||||||
|
* @param {function(Object, Object):boolean} middlewareToggle
|
||||||
|
* @param {Object} localOptions Options for APICache
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
this.middleware = function cache(strDuration, middlewareToggle, localOptions) {
|
this.middleware = function cache(strDuration, middlewareToggle, localOptions) {
|
||||||
let duration = instance.getDuration(strDuration);
|
let duration = instance.getDuration(strDuration);
|
||||||
let opt = {};
|
let opt = {};
|
||||||
@@ -506,63 +570,72 @@ function ApiCache() {
|
|||||||
options(localOptions);
|
options(localOptions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Function for non tracking performance
|
* A Function for non tracking performance
|
||||||
*/
|
*/
|
||||||
function NOOPCachePerformance() {
|
function NOOPCachePerformance() {
|
||||||
this.report = this.hit = this.miss = function () {}; // noop;
|
this.report = this.hit = this.miss = function () {}; // noop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function for tracking and reporting hit rate. These statistics are returned by the getPerformance() call above.
|
* A function for tracking and reporting hit rate. These
|
||||||
*/
|
* statistics are returned by the getPerformance() call above.
|
||||||
|
*/
|
||||||
function CachePerformance() {
|
function CachePerformance() {
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 100 requests.
|
* Tracks the hit rate for the last 100 requests. If there
|
||||||
* If there have been fewer than 100 requests, the hit rate just considers the requests that have happened.
|
* have been fewer than 100 requests, the hit rate just
|
||||||
*/
|
* considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast100 = new Uint8Array(100 / 4); // each hit is 2 bits
|
this.hitsLast100 = new Uint8Array(100 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 1000 requests.
|
* Tracks the hit rate for the last 1000 requests. If there
|
||||||
* If there have been fewer than 1000 requests, the hit rate just considers the requests that have happened.
|
* have been fewer than 1000 requests, the hit rate just
|
||||||
*/
|
* considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast1000 = new Uint8Array(1000 / 4); // each hit is 2 bits
|
this.hitsLast1000 = new Uint8Array(1000 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 10000 requests.
|
* Tracks the hit rate for the last 10000 requests. If there
|
||||||
* If there have been fewer than 10000 requests, the hit rate just considers the requests that have happened.
|
* have been fewer than 10000 requests, the hit rate just
|
||||||
*/
|
* considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast10000 = new Uint8Array(10000 / 4); // each hit is 2 bits
|
this.hitsLast10000 = new Uint8Array(10000 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks the hit rate for the last 100000 requests.
|
* Tracks the hit rate for the last 100000 requests. If
|
||||||
* If there have been fewer than 100000 requests, the hit rate just considers the requests that have happened.
|
* there have been fewer than 100000 requests, the hit rate
|
||||||
*/
|
* just considers the requests that have happened.
|
||||||
|
*/
|
||||||
this.hitsLast100000 = new Uint8Array(100000 / 4); // each hit is 2 bits
|
this.hitsLast100000 = new Uint8Array(100000 / 4); // each hit is 2 bits
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of calls that have passed through the middleware since the server started.
|
* The number of calls that have passed through the
|
||||||
*/
|
* middleware since the server started.
|
||||||
|
*/
|
||||||
this.callCount = 0;
|
this.callCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The total number of hits since the server started
|
* The total number of hits since the server started
|
||||||
*/
|
*/
|
||||||
this.hitCount = 0;
|
this.hitCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key from the last cache hit. This is useful in identifying which route these statistics apply to.
|
* The key from the last cache hit. This is useful in
|
||||||
*/
|
* identifying which route these statistics apply to.
|
||||||
|
*/
|
||||||
this.lastCacheHit = null;
|
this.lastCacheHit = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key from the last cache miss. This is useful in identifying which route these statistics apply to.
|
* The key from the last cache miss. This is useful in
|
||||||
*/
|
* identifying which route these statistics apply to.
|
||||||
|
*/
|
||||||
this.lastCacheMiss = null;
|
this.lastCacheMiss = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return performance statistics
|
* Return performance statistics
|
||||||
*/
|
* @returns {Object}
|
||||||
|
*/
|
||||||
this.report = function () {
|
this.report = function () {
|
||||||
return {
|
return {
|
||||||
lastCacheHit: this.lastCacheHit,
|
lastCacheHit: this.lastCacheHit,
|
||||||
@@ -579,10 +652,13 @@ function ApiCache() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes a cache hit rate from an array of hits and misses.
|
* Computes a cache hit rate from an array of hits and
|
||||||
* @param {Uint8Array} array An array representing hits and misses.
|
* misses.
|
||||||
* @returns a number between 0 and 1, or null if the array has no hits or misses
|
* @param {Uint8Array} array An array representing hits and
|
||||||
*/
|
* misses.
|
||||||
|
* @returns {?number} a number between 0 and 1, or null if
|
||||||
|
* the array has no hits or misses
|
||||||
|
*/
|
||||||
this.hitRate = function (array) {
|
this.hitRate = function (array) {
|
||||||
let hits = 0;
|
let hits = 0;
|
||||||
let misses = 0;
|
let misses = 0;
|
||||||
@@ -608,16 +684,17 @@ function ApiCache() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Record a hit or miss in the given array. It will be recorded at a position determined
|
* Record a hit or miss in the given array. It will be
|
||||||
* by the current value of the callCount variable.
|
* recorded at a position determined by the current value of
|
||||||
* @param {Uint8Array} array An array representing hits and misses.
|
* the callCount variable.
|
||||||
* @param {boolean} hit true for a hit, false for a miss
|
* @param {Uint8Array} array An array representing hits and
|
||||||
* Each element in the array is 8 bits, and encodes 4 hit/miss records.
|
* misses.
|
||||||
* Each hit or miss is encoded as to bits as follows:
|
* @param {boolean} hit true for a hit, false for a miss
|
||||||
* 00 means no hit or miss has been recorded in these bits
|
* Each element in the array is 8 bits, and encodes 4
|
||||||
* 01 encodes a hit
|
* hit/miss records. Each hit or miss is encoded as to bits
|
||||||
* 10 encodes a miss
|
* as follows: 00 means no hit or miss has been recorded in
|
||||||
*/
|
* these bits 01 encodes a hit 10 encodes a miss
|
||||||
|
*/
|
||||||
this.recordHitInArray = function (array, hit) {
|
this.recordHitInArray = function (array, hit) {
|
||||||
let arrayIndex = ~~(this.callCount / 4) % array.length;
|
let arrayIndex = ~~(this.callCount / 4) % array.length;
|
||||||
let bitOffset = (this.callCount % 4) * 2; // 2 bits per record, 4 records per uint8 array element
|
let bitOffset = (this.callCount % 4) * 2; // 2 bits per record, 4 records per uint8 array element
|
||||||
@@ -627,9 +704,11 @@ function ApiCache() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records the hit or miss in the tracking arrays and increments the call count.
|
* Records the hit or miss in the tracking arrays and
|
||||||
* @param {boolean} hit true records a hit, false records a miss
|
* increments the call count.
|
||||||
*/
|
* @param {boolean} hit true records a hit, false records a
|
||||||
|
* miss
|
||||||
|
*/
|
||||||
this.recordHit = function (hit) {
|
this.recordHit = function (hit) {
|
||||||
this.recordHitInArray(this.hitsLast100, hit);
|
this.recordHitInArray(this.hitsLast100, hit);
|
||||||
this.recordHitInArray(this.hitsLast1000, hit);
|
this.recordHitInArray(this.hitsLast1000, hit);
|
||||||
@@ -642,18 +721,18 @@ function ApiCache() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records a hit event, setting lastCacheMiss to the given key
|
* Records a hit event, setting lastCacheMiss to the given key
|
||||||
* @param {string} key The key that had the cache hit
|
* @param {string} key The key that had the cache hit
|
||||||
*/
|
*/
|
||||||
this.hit = function (key) {
|
this.hit = function (key) {
|
||||||
this.recordHit(true);
|
this.recordHit(true);
|
||||||
this.lastCacheHit = key;
|
this.lastCacheHit = key;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records a miss event, setting lastCacheMiss to the given key
|
* Records a miss event, setting lastCacheMiss to the given key
|
||||||
* @param {string} key The key that had the cache miss
|
* @param {string} key The key that had the cache miss
|
||||||
*/
|
*/
|
||||||
this.miss = function (key) {
|
this.miss = function (key) {
|
||||||
this.recordHit(false);
|
this.recordHit(false);
|
||||||
this.lastCacheMiss = key;
|
this.lastCacheMiss = key;
|
||||||
@@ -664,6 +743,13 @@ function ApiCache() {
|
|||||||
|
|
||||||
performanceArray.push(perf);
|
performanceArray.push(perf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache a request
|
||||||
|
* @param {Object} req Express request object
|
||||||
|
* @param {Object} res Express response object
|
||||||
|
* @param {function} next Function to call next
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
let cache = function (req, res, next) {
|
let cache = function (req, res, next) {
|
||||||
function bypass() {
|
function bypass() {
|
||||||
debug("bypass detected, skipping cache.");
|
debug("bypass detected, skipping cache.");
|
||||||
@@ -771,6 +857,11 @@ function ApiCache() {
|
|||||||
return cache;
|
return cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process options
|
||||||
|
* @param {Object} options
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
this.options = function (options) {
|
this.options = function (options) {
|
||||||
if (options) {
|
if (options) {
|
||||||
Object.assign(globalOptions, options);
|
Object.assign(globalOptions, options);
|
||||||
@@ -791,6 +882,7 @@ function ApiCache() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Reset the index */
|
||||||
this.resetIndex = function () {
|
this.resetIndex = function () {
|
||||||
index = {
|
index = {
|
||||||
all: [],
|
all: [],
|
||||||
@@ -798,6 +890,11 @@ function ApiCache() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of ApiCache
|
||||||
|
* @param {Object} config Config to pass
|
||||||
|
* @returns {ApiCache}
|
||||||
|
*/
|
||||||
this.newInstance = function (config) {
|
this.newInstance = function (config) {
|
||||||
let instance = new ApiCache();
|
let instance = new ApiCache();
|
||||||
|
|
||||||
@@ -808,6 +905,7 @@ function ApiCache() {
|
|||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Clone this instance */
|
||||||
this.clone = function () {
|
this.clone = function () {
|
||||||
return this.newInstance(this.options());
|
return this.newInstance(this.options());
|
||||||
};
|
};
|
||||||
|
@@ -3,6 +3,15 @@ function MemoryCache() {
|
|||||||
this.size = 0;
|
this.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} key Key to store cache as
|
||||||
|
* @param {any} value Value to store
|
||||||
|
* @param {number} time Time to store for
|
||||||
|
* @param {function(any, string)} timeoutCallback Callback to call in
|
||||||
|
* case of timeout
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.add = function (key, value, time, timeoutCallback) {
|
MemoryCache.prototype.add = function (key, value, time, timeoutCallback) {
|
||||||
let old = this.cache[key];
|
let old = this.cache[key];
|
||||||
let instance = this;
|
let instance = this;
|
||||||
@@ -22,6 +31,11 @@ MemoryCache.prototype.add = function (key, value, time, timeoutCallback) {
|
|||||||
return entry;
|
return entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a cache entry
|
||||||
|
* @param {string} key Key to delete
|
||||||
|
* @returns {null}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.delete = function (key) {
|
MemoryCache.prototype.delete = function (key) {
|
||||||
let entry = this.cache[key];
|
let entry = this.cache[key];
|
||||||
|
|
||||||
@@ -36,18 +50,32 @@ MemoryCache.prototype.delete = function (key) {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value of key
|
||||||
|
* @param {string} key
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.get = function (key) {
|
MemoryCache.prototype.get = function (key) {
|
||||||
let entry = this.cache[key];
|
let entry = this.cache[key];
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value of cache entry
|
||||||
|
* @param {string} key
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.getValue = function (key) {
|
MemoryCache.prototype.getValue = function (key) {
|
||||||
let entry = this.get(key);
|
let entry = this.get(key);
|
||||||
|
|
||||||
return entry && entry.value;
|
return entry && entry.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear cache
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
MemoryCache.prototype.clear = function () {
|
MemoryCache.prototype.clear = function () {
|
||||||
Object.keys(this.cache).forEach(function (key) {
|
Object.keys(this.cache).forEach(function (key) {
|
||||||
this.delete(key);
|
this.delete(key);
|
||||||
|
50
server/notification-providers/alertnow.js
Normal file
50
server/notification-providers/alertnow.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { setting } = require("../util-server");
|
||||||
|
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
|
||||||
|
|
||||||
|
class AlertNow extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "AlertNow";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
let textMsg = "";
|
||||||
|
let status = "open";
|
||||||
|
let eventType = "ERROR";
|
||||||
|
let eventId = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
||||||
|
|
||||||
|
if (heartbeatJSON && heartbeatJSON.status === UP) {
|
||||||
|
textMsg = `[${heartbeatJSON.name}] ✅ Application is back online`;
|
||||||
|
status = "close";
|
||||||
|
eventType = "INFO";
|
||||||
|
eventId += `_${heartbeatJSON.name.replace(/\s/g, "")}`;
|
||||||
|
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
|
||||||
|
textMsg = `[${heartbeatJSON.name}] 🔴 Application went down`;
|
||||||
|
}
|
||||||
|
|
||||||
|
textMsg += ` - ${msg}`;
|
||||||
|
|
||||||
|
const baseURL = await setting("primaryBaseURL");
|
||||||
|
if (baseURL && monitorJSON) {
|
||||||
|
textMsg += ` >> ${baseURL + getMonitorRelativeURL(monitorJSON.id)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
"summary": textMsg,
|
||||||
|
"status": status,
|
||||||
|
"event_type": eventType,
|
||||||
|
"event_id": eventId,
|
||||||
|
};
|
||||||
|
|
||||||
|
await axios.post(notification.alertNowWebhookURL, data);
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = AlertNow;
|
@@ -37,6 +37,12 @@ class AliyunSMS extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the SMS notification
|
||||||
|
* @param {BeanModel} notification Notification details
|
||||||
|
* @param {string} msgbody Message template
|
||||||
|
* @returns {boolean} True if successful else false
|
||||||
|
*/
|
||||||
async sendSms(notification, msgbody) {
|
async sendSms(notification, msgbody) {
|
||||||
let params = {
|
let params = {
|
||||||
PhoneNumbers: notification.phonenumber,
|
PhoneNumbers: notification.phonenumber,
|
||||||
@@ -70,7 +76,12 @@ class AliyunSMS extends NotificationProvider {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Aliyun request sign */
|
/**
|
||||||
|
* Aliyun request sign
|
||||||
|
* @param {Object} param Parameters object to sign
|
||||||
|
* @param {string} AccessKeySecret Secret key to sign parameters with
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
sign(param, AccessKeySecret) {
|
sign(param, AccessKeySecret) {
|
||||||
let param2 = {};
|
let param2 = {};
|
||||||
let data = [];
|
let data = [];
|
||||||
@@ -82,8 +93,23 @@ class AliyunSMS extends NotificationProvider {
|
|||||||
param2[key] = param[key];
|
param2[key] = param[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Escape more characters than encodeURIComponent does.
|
||||||
|
// For generating Aliyun signature, all characters except A-Za-z0-9~-._ are encoded.
|
||||||
|
// See https://help.aliyun.com/document_detail/315526.html
|
||||||
|
// This encoding methods as known as RFC 3986 (https://tools.ietf.org/html/rfc3986)
|
||||||
|
let moreEscapesTable = function (m) {
|
||||||
|
return {
|
||||||
|
"!": "%21",
|
||||||
|
"*": "%2A",
|
||||||
|
"'": "%27",
|
||||||
|
"(": "%28",
|
||||||
|
")": "%29"
|
||||||
|
}[m];
|
||||||
|
};
|
||||||
|
|
||||||
for (let key in param2) {
|
for (let key in param2) {
|
||||||
data.push(`${encodeURIComponent(key)}=${encodeURIComponent(param2[key])}`);
|
let value = encodeURIComponent(param2[key]).replace(/[!*'()]/g, moreEscapesTable);
|
||||||
|
data.push(`${encodeURIComponent(key)}=${value}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let StringToSign = `POST&${encodeURIComponent("/")}&${encodeURIComponent(data.join("&"))}`;
|
let StringToSign = `POST&${encodeURIComponent("/")}&${encodeURIComponent(data.join("&"))}`;
|
||||||
@@ -93,6 +119,11 @@ class AliyunSMS extends NotificationProvider {
|
|||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert status constant to string
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
statusToString(status) {
|
statusToString(status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DOWN:
|
case DOWN:
|
||||||
|
@@ -6,9 +6,14 @@ 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 = childProcess.spawnSync("apprise", [ "-vv", "-b", msg, notification.appriseURL ]);
|
const args = [ "-vv", "-b", msg, notification.appriseURL ];
|
||||||
|
if (notification.title) {
|
||||||
|
args.push("-t");
|
||||||
|
args.push(notification.title);
|
||||||
|
}
|
||||||
|
const s = childProcess.spawnSync("apprise", args);
|
||||||
|
|
||||||
let output = (s.stdout) ? s.stdout.toString() : "ERROR: maybe apprise not found";
|
const output = (s.stdout) ? s.stdout.toString() : "ERROR: maybe apprise not found";
|
||||||
|
|
||||||
if (output) {
|
if (output) {
|
||||||
|
|
||||||
|
@@ -12,9 +12,7 @@ const { default: axios } = require("axios");
|
|||||||
|
|
||||||
// bark is an APN bridge that sends notifications to Apple devices.
|
// bark is an APN bridge that sends notifications to Apple devices.
|
||||||
|
|
||||||
const barkNotificationGroup = "UptimeKuma";
|
|
||||||
const barkNotificationAvatar = "https://github.com/louislam/uptime-kuma/raw/master/public/icon.png";
|
const barkNotificationAvatar = "https://github.com/louislam/uptime-kuma/raw/master/public/icon.png";
|
||||||
const barkNotificationSound = "telegraph";
|
|
||||||
const successMessage = "Successes!";
|
const successMessage = "Successes!";
|
||||||
|
|
||||||
class Bark extends NotificationProvider {
|
class Bark extends NotificationProvider {
|
||||||
@@ -30,32 +28,51 @@ class Bark extends NotificationProvider {
|
|||||||
|
|
||||||
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(notification, 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(notification, 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(notification, title, msg, barkEndpoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add additional parameter for better on device styles (iOS 15 optimized)
|
/**
|
||||||
appendAdditionalParameters(postUrl) {
|
* Add additional parameter for better on device styles (iOS 15
|
||||||
// grouping all our notifications
|
* optimized)
|
||||||
postUrl += "?group=" + barkNotificationGroup;
|
* @param {string} postUrl URL to append parameters to
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
appendAdditionalParameters(notification, postUrl) {
|
||||||
// set icon to uptime kuma icon, 11kb should be fine
|
// set icon to uptime kuma icon, 11kb should be fine
|
||||||
postUrl += "&icon=" + barkNotificationAvatar;
|
postUrl += "?icon=" + barkNotificationAvatar;
|
||||||
|
// grouping all our notifications
|
||||||
|
if (notification.barkGroup != null) {
|
||||||
|
postUrl += "&group=" + notification.barkGroup;
|
||||||
|
} else {
|
||||||
|
// default name
|
||||||
|
postUrl += "&group=" + "UptimeKuma";
|
||||||
|
}
|
||||||
// picked a sound, this should follow system's mute status when arrival
|
// picked a sound, this should follow system's mute status when arrival
|
||||||
postUrl += "&sound=" + barkNotificationSound;
|
if (notification.barkSound != null) {
|
||||||
|
postUrl += "&sound=" + notification.barkSound;
|
||||||
|
} else {
|
||||||
|
// default sound
|
||||||
|
postUrl += "&sound=" + "telegraph";
|
||||||
|
}
|
||||||
return postUrl;
|
return postUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// thrown if failed to check result, result code should be in range 2xx
|
/**
|
||||||
|
* Check if result is successful
|
||||||
|
* @param {Object} result Axios response object
|
||||||
|
* @throws {Error} The status code is not in range 2xx
|
||||||
|
*/
|
||||||
checkResult(result) {
|
checkResult(result) {
|
||||||
if (result.status == null) {
|
if (result.status == null) {
|
||||||
throw new Error("Bark notification failed with invalid response!");
|
throw new Error("Bark notification failed with invalid response!");
|
||||||
@@ -65,12 +82,19 @@ class Bark extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async postNotification(title, subtitle, endpoint) {
|
/**
|
||||||
|
* Send the message
|
||||||
|
* @param {string} title Message title
|
||||||
|
* @param {string} subtitle Message
|
||||||
|
* @param {string} endpoint Endpoint to send request to
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
async postNotification(notification, title, subtitle, endpoint) {
|
||||||
// url encode title and subtitle
|
// url encode title and subtitle
|
||||||
title = encodeURIComponent(title);
|
title = encodeURIComponent(title);
|
||||||
subtitle = encodeURIComponent(subtitle);
|
subtitle = encodeURIComponent(subtitle);
|
||||||
let postUrl = endpoint + "/" + title + "/" + subtitle;
|
let postUrl = endpoint + "/" + title + "/" + subtitle;
|
||||||
postUrl = this.appendAdditionalParameters(postUrl);
|
postUrl = this.appendAdditionalParameters(notification, postUrl);
|
||||||
let result = await axios.get(postUrl);
|
let result = await axios.get(postUrl);
|
||||||
this.checkResult(result);
|
this.checkResult(result);
|
||||||
if (result.statusText != null) {
|
if (result.statusText != null) {
|
||||||
|
@@ -37,6 +37,12 @@ class DingDing extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message to DingDing
|
||||||
|
* @param {BeanModel} notification
|
||||||
|
* @param {Object} params Parameters of message
|
||||||
|
* @returns {boolean} True if successful else false
|
||||||
|
*/
|
||||||
async sendToDingDing(notification, params) {
|
async sendToDingDing(notification, params) {
|
||||||
let timestamp = Date.now();
|
let timestamp = Date.now();
|
||||||
|
|
||||||
@@ -56,7 +62,12 @@ class DingDing extends NotificationProvider {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** DingDing sign */
|
/**
|
||||||
|
* DingDing sign
|
||||||
|
* @param {Date} timestamp Timestamp of message
|
||||||
|
* @param {string} secretKey Secret key to sign data with
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
sign(timestamp, secretKey) {
|
sign(timestamp, secretKey) {
|
||||||
return Crypto
|
return Crypto
|
||||||
.createHmac("sha256", Buffer.from(secretKey, "utf8"))
|
.createHmac("sha256", Buffer.from(secretKey, "utf8"))
|
||||||
@@ -64,7 +75,13 @@ class DingDing extends NotificationProvider {
|
|||||||
.digest("base64");
|
.digest("base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert status constant to string
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
statusToString(status) {
|
statusToString(status) {
|
||||||
|
// TODO: Move to notification-provider.js to avoid repetition in classes
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DOWN:
|
case DOWN:
|
||||||
return "DOWN";
|
return "DOWN";
|
||||||
|
@@ -22,16 +22,23 @@ class Discord extends NotificationProvider {
|
|||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url;
|
let address;
|
||||||
|
|
||||||
if (monitorJSON["type"] === "port") {
|
switch (monitorJSON["type"]) {
|
||||||
url = monitorJSON["hostname"];
|
case "ping":
|
||||||
if (monitorJSON["port"]) {
|
address = monitorJSON["hostname"];
|
||||||
url += ":" + monitorJSON["port"];
|
break;
|
||||||
}
|
case "port":
|
||||||
|
case "dns":
|
||||||
} else {
|
case "steam":
|
||||||
url = monitorJSON["url"];
|
address = monitorJSON["hostname"];
|
||||||
|
if (monitorJSON["port"]) {
|
||||||
|
address += ":" + monitorJSON["port"];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
address = monitorJSON["url"];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
||||||
@@ -48,8 +55,8 @@ class Discord extends NotificationProvider {
|
|||||||
value: monitorJSON["name"],
|
value: monitorJSON["name"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Service URL",
|
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
||||||
value: url,
|
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Time (UTC)",
|
name: "Time (UTC)",
|
||||||
@@ -83,8 +90,8 @@ class Discord extends NotificationProvider {
|
|||||||
value: monitorJSON["name"],
|
value: monitorJSON["name"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Service URL",
|
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
||||||
value: url.startsWith("http") ? "[Visit Service](" + url + ")" : url,
|
value: monitorJSON["type"] === "push" ? "Heartbeat" : address.startsWith("http") ? "[Visit Service](" + address + ")" : address,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Time (UTC)",
|
name: "Time (UTC)",
|
||||||
@@ -92,7 +99,7 @@ class Discord extends NotificationProvider {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Ping",
|
name: "Ping",
|
||||||
value: heartbeatJSON["ping"] + "ms",
|
value: heartbeatJSON["ping"] == null ? "N/A" : heartbeatJSON["ping"] + " ms",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
|
24
server/notification-providers/freemobile.js
Normal file
24
server/notification-providers/freemobile.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class FreeMobile extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "FreeMobile";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
await axios.post(`https://smsapi.free-mobile.fr/sendmsg?msg=${encodeURIComponent(msg.replace("🔴", "⛔️"))}`, {
|
||||||
|
"user": notification.freemobileUser,
|
||||||
|
"pass": notification.freemobilePass,
|
||||||
|
});
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = FreeMobile;
|
35
server/notification-providers/goalert.js
Normal file
35
server/notification-providers/goalert.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { UP } = require("../../src/util");
|
||||||
|
|
||||||
|
class GoAlert extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "GoAlert";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
let closeAction = "close";
|
||||||
|
let data = {
|
||||||
|
summary: msg,
|
||||||
|
};
|
||||||
|
if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||||
|
data["action"] = closeAction;
|
||||||
|
}
|
||||||
|
let headers = {
|
||||||
|
"Content-Type": "multipart/form-data",
|
||||||
|
};
|
||||||
|
let config = {
|
||||||
|
headers: headers
|
||||||
|
};
|
||||||
|
await axios.post(`${notification.goAlertBaseURL}/api/v2/generic/incoming?token=${notification.goAlertToken}`, data, config);
|
||||||
|
return okMsg;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
let msg = (error.response.data) ? error.response.data : "Error without response";
|
||||||
|
throw new Error(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = GoAlert;
|
38
server/notification-providers/home-assistant.js
Normal file
38
server/notification-providers/home-assistant.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
const defaultNotificationService = "notify";
|
||||||
|
|
||||||
|
class HomeAssistant extends NotificationProvider {
|
||||||
|
name = "HomeAssistant";
|
||||||
|
|
||||||
|
async send(notification, message, monitor = null, heartbeat = null) {
|
||||||
|
const notificationService = notification?.notificationService || defaultNotificationService;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios.post(
|
||||||
|
`${notification.homeAssistantUrl}/api/services/notify/${notificationService}`,
|
||||||
|
{
|
||||||
|
title: "Uptime Kuma",
|
||||||
|
message,
|
||||||
|
...(notificationService !== "persistent_notification" && { data: {
|
||||||
|
name: monitor?.name,
|
||||||
|
status: heartbeat?.status,
|
||||||
|
} }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${notification.longLivedAccessToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return "Sent Successfully.";
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = HomeAssistant;
|
43
server/notification-providers/linenotify.js
Normal file
43
server/notification-providers/linenotify.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const qs = require("qs");
|
||||||
|
const { DOWN, UP } = require("../../src/util");
|
||||||
|
|
||||||
|
class LineNotify extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "LineNotify";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
let lineAPIUrl = "https://notify-api.line.me/api/notify";
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Authorization": "Bearer " + notification.lineNotifyAccessToken
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (heartbeatJSON == null) {
|
||||||
|
let testMessage = {
|
||||||
|
"message": msg,
|
||||||
|
};
|
||||||
|
await axios.post(lineAPIUrl, qs.stringify(testMessage), config);
|
||||||
|
} else if (heartbeatJSON["status"] === DOWN) {
|
||||||
|
let downMessage = {
|
||||||
|
"message": "\n[🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
||||||
|
};
|
||||||
|
await axios.post(lineAPIUrl, qs.stringify(downMessage), config);
|
||||||
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
|
let upMessage = {
|
||||||
|
"message": "\n[✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
||||||
|
};
|
||||||
|
await axios.post(lineAPIUrl, qs.stringify(upMessage), config);
|
||||||
|
}
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = LineNotify;
|
@@ -14,7 +14,7 @@ class LunaSea extends NotificationProvider {
|
|||||||
if (heartbeatJSON == null) {
|
if (heartbeatJSON == null) {
|
||||||
let testdata = {
|
let testdata = {
|
||||||
"title": "Uptime Kuma Alert",
|
"title": "Uptime Kuma Alert",
|
||||||
"body": "Testing Successful.",
|
"body": msg,
|
||||||
};
|
};
|
||||||
await axios.post(lunaseadevice, testdata);
|
await axios.post(lunaseadevice, testdata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
@@ -7,17 +7,23 @@ class NotificationProvider {
|
|||||||
name = undefined;
|
name = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param notification : BeanModel
|
* Send a notification
|
||||||
* @param msg : string General Message
|
* @param {BeanModel} notification
|
||||||
* @param monitorJSON : object Monitor details (For Up/Down only)
|
* @param {string} msg General Message
|
||||||
* @param heartbeatJSON : object Heartbeat details (For Up/Down only)
|
* @param {?Object} monitorJSON Monitor details (For Up/Down only)
|
||||||
|
* @param {?Object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||||
* @returns {Promise<string>} Return Successful Message
|
* @returns {Promise<string>} Return Successful Message
|
||||||
* Throw Error with fail msg
|
* @throws Error with fail msg
|
||||||
*/
|
*/
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
throw new Error("Have to override Notification.send(...)");
|
throw new Error("Have to override Notification.send(...)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws an error
|
||||||
|
* @param {any} error The error to throw
|
||||||
|
* @throws {any} The error specified
|
||||||
|
*/
|
||||||
throwGeneralAxiosError(error) {
|
throwGeneralAxiosError(error) {
|
||||||
let msg = "Error: " + error + " ";
|
let msg = "Error: " + error + " ";
|
||||||
|
|
||||||
|
33
server/notification-providers/ntfy.js
Normal file
33
server/notification-providers/ntfy.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class Ntfy extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "ntfy";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
let headers = {};
|
||||||
|
if (notification.ntfyusername) {
|
||||||
|
headers = {
|
||||||
|
"Authorization": "Basic " + Buffer.from(notification.ntfyusername + ":" + notification.ntfypassword).toString("base64"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let data = {
|
||||||
|
"topic": notification.ntfytopic,
|
||||||
|
"message": msg,
|
||||||
|
"priority": notification.ntfyPriority || 4,
|
||||||
|
"title": "Uptime-Kuma",
|
||||||
|
};
|
||||||
|
await axios.post(`${notification.ntfyserverurl}`, data, { headers: headers });
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Ntfy;
|
@@ -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,
|
||||||
@@ -31,7 +31,7 @@ class Octopush extends NotificationProvider {
|
|||||||
"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,
|
||||||
@@ -49,7 +49,15 @@ class Octopush extends NotificationProvider {
|
|||||||
},
|
},
|
||||||
params: data
|
params: data
|
||||||
};
|
};
|
||||||
await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config);
|
|
||||||
|
// V1 API returns 200 even on error so we must check
|
||||||
|
// response data
|
||||||
|
let response = await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config);
|
||||||
|
if ("error_code" in response.data) {
|
||||||
|
if (response.data.error_code !== "000") {
|
||||||
|
this.throwGeneralAxiosError(`Octopush error ${JSON.stringify(response.data)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unknown Octopush version!");
|
throw new Error("Unknown Octopush version!");
|
||||||
}
|
}
|
||||||
|
113
server/notification-providers/pagerduty.js
Normal file
113
server/notification-providers/pagerduty.js
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
|
||||||
|
const { setting } = require("../util-server");
|
||||||
|
let successMessage = "Sent Successfully.";
|
||||||
|
|
||||||
|
class PagerDuty extends NotificationProvider {
|
||||||
|
name = "PagerDuty";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
try {
|
||||||
|
if (heartbeatJSON == null) {
|
||||||
|
const title = "Uptime Kuma Alert";
|
||||||
|
const monitor = {
|
||||||
|
type: "ping",
|
||||||
|
url: "Uptime Kuma Test Button",
|
||||||
|
};
|
||||||
|
return this.postNotification(notification, title, msg, monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON.status === UP) {
|
||||||
|
const title = "Uptime Kuma Monitor ✅ Up";
|
||||||
|
const eventAction = notification.pagerdutyAutoResolve || null;
|
||||||
|
|
||||||
|
return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, eventAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON.status === DOWN) {
|
||||||
|
const title = "Uptime Kuma Monitor 🔴 Down";
|
||||||
|
return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, "trigger");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if result is successful, result code should be in range 2xx
|
||||||
|
* @param {Object} result Axios response object
|
||||||
|
* @throws {Error} The status code is not in range 2xx
|
||||||
|
*/
|
||||||
|
checkResult(result) {
|
||||||
|
if (result.status == null) {
|
||||||
|
throw new Error("PagerDuty notification failed with invalid response!");
|
||||||
|
}
|
||||||
|
if (result.status < 200 || result.status >= 300) {
|
||||||
|
throw new Error("PagerDuty notification failed with status code " + result.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the message
|
||||||
|
* @param {BeanModel} notification Message title
|
||||||
|
* @param {string} title Message title
|
||||||
|
* @param {string} body Message
|
||||||
|
* @param {Object} monitorInfo Monitor details (For Up/Down only)
|
||||||
|
* @param {?string} eventAction Action event for PagerDuty (trigger, acknowledge, resolve)
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
async postNotification(notification, title, body, monitorInfo, eventAction = "trigger") {
|
||||||
|
|
||||||
|
if (eventAction == null) {
|
||||||
|
return "No action required";
|
||||||
|
}
|
||||||
|
|
||||||
|
let monitorUrl;
|
||||||
|
if (monitorInfo.type === "port") {
|
||||||
|
monitorUrl = monitorInfo.hostname;
|
||||||
|
if (monitorInfo.port) {
|
||||||
|
monitorUrl += ":" + monitorInfo.port;
|
||||||
|
}
|
||||||
|
} else if (monitorInfo.hostname != null) {
|
||||||
|
monitorUrl = monitorInfo.hostname;
|
||||||
|
} else {
|
||||||
|
monitorUrl = monitorInfo.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: "POST",
|
||||||
|
url: notification.pagerdutyIntegrationUrl,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
data: {
|
||||||
|
payload: {
|
||||||
|
summary: `[${title}] [${monitorInfo.name}] ${body}`,
|
||||||
|
severity: notification.pagerdutyPriority || "warning",
|
||||||
|
source: monitorUrl,
|
||||||
|
},
|
||||||
|
routing_key: notification.pagerdutyIntegrationKey,
|
||||||
|
event_action: eventAction,
|
||||||
|
dedup_key: "Uptime Kuma/" + monitorInfo.id,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const baseURL = await setting("primaryBaseURL");
|
||||||
|
if (baseURL && monitorInfo) {
|
||||||
|
options.client = "Uptime Kuma";
|
||||||
|
options.client_url = baseURL + getMonitorRelativeURL(monitorInfo.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = await axios.request(options);
|
||||||
|
this.checkResult(result);
|
||||||
|
if (result.statusText != null) {
|
||||||
|
return "PagerDuty notification succeed: " + result.statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return successMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = PagerDuty;
|
36
server/notification-providers/serverchan.js
Normal file
36
server/notification-providers/serverchan.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { DOWN, UP } = require("../../src/util");
|
||||||
|
|
||||||
|
class ServerChan extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "ServerChan";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
await axios.post(`https://sctapi.ftqq.com/${notification.serverChanSendKey}.send`, {
|
||||||
|
"title": this.checkStatus(heartbeatJSON, monitorJSON),
|
||||||
|
"desp": msg,
|
||||||
|
});
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkStatus(heartbeatJSON, monitorJSON) {
|
||||||
|
let title = "UptimeKuma Message";
|
||||||
|
if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||||
|
title = "UptimeKuma Monitor Up " + monitorJSON["name"];
|
||||||
|
}
|
||||||
|
if (heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
||||||
|
title = "UptimeKuma Monitor Down " + monitorJSON["name"];
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ServerChan;
|
@@ -10,6 +10,7 @@ class Slack extends NotificationProvider {
|
|||||||
/**
|
/**
|
||||||
* Deprecated property notification.slackbutton
|
* Deprecated property notification.slackbutton
|
||||||
* Set it as primary base url if this is not yet set.
|
* Set it as primary base url if this is not yet set.
|
||||||
|
* @param {string} url The primary base URL to use
|
||||||
*/
|
*/
|
||||||
static async deprecateURL(url) {
|
static async deprecateURL(url) {
|
||||||
let currentPrimaryBaseURL = await setting("primaryBaseURL");
|
let currentPrimaryBaseURL = await setting("primaryBaseURL");
|
||||||
|
25
server/notification-providers/smsmanager.js
Normal file
25
server/notification-providers/smsmanager.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class SMSManager extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "SMSManager";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
try {
|
||||||
|
let data = {
|
||||||
|
apikey: notification.smsmanagerApiKey,
|
||||||
|
endpoint: "https://http-api.smsmanager.cz/Send",
|
||||||
|
message: msg.replace(/[^\x00-\x7F]/g, ""),
|
||||||
|
to: notification.numbers,
|
||||||
|
messageType: notification.messageType,
|
||||||
|
};
|
||||||
|
await axios.get(`${data.endpoint}?apikey=${data.apikey}&message=${data.message}&number=${data.to}&gateway=${data.messageType}`);
|
||||||
|
return "SMS sent sucessfully.";
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = SMSManager;
|
76
server/notification-providers/squadcast.js
Normal file
76
server/notification-providers/squadcast.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { DOWN } = require("../../src/util");
|
||||||
|
|
||||||
|
class Squadcast extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "squadcast";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
let config = {};
|
||||||
|
let data = {
|
||||||
|
message: msg,
|
||||||
|
description: "",
|
||||||
|
tags: {},
|
||||||
|
heartbeat: heartbeatJSON,
|
||||||
|
source: "uptime-kuma"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (heartbeatJSON !== null) {
|
||||||
|
data.description = heartbeatJSON["msg"];
|
||||||
|
data.event_id = heartbeatJSON["monitorID"];
|
||||||
|
|
||||||
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
|
data.message = `${monitorJSON["name"]} is DOWN`;
|
||||||
|
data.status = "trigger";
|
||||||
|
} else {
|
||||||
|
data.message = `${monitorJSON["name"]} is UP`;
|
||||||
|
data.status = "resolve";
|
||||||
|
}
|
||||||
|
|
||||||
|
let address;
|
||||||
|
switch (monitorJSON["type"]) {
|
||||||
|
case "ping":
|
||||||
|
address = monitorJSON["hostname"];
|
||||||
|
break;
|
||||||
|
case "port":
|
||||||
|
case "dns":
|
||||||
|
case "steam":
|
||||||
|
address = monitorJSON["hostname"];
|
||||||
|
if (monitorJSON["port"]) {
|
||||||
|
address += ":" + monitorJSON["port"];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
address = monitorJSON["url"];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.tags["AlertAddress"] = address;
|
||||||
|
|
||||||
|
monitorJSON["tags"].forEach(tag => {
|
||||||
|
data.tags[tag["name"]] = {
|
||||||
|
value: tag["value"]
|
||||||
|
};
|
||||||
|
if (tag["color"] !== null) {
|
||||||
|
data.tags[tag["name"]]["color"] = tag["color"];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await axios.post(notification.squadcastWebhookURL, data, config);
|
||||||
|
return okMsg;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Squadcast;
|
@@ -5,6 +5,12 @@ const { DOWN, UP } = require("../../src/util");
|
|||||||
class Teams extends NotificationProvider {
|
class Teams extends NotificationProvider {
|
||||||
name = "teams";
|
name = "teams";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the message to send
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @param {string} monitorName Name of monitor
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
_statusMessageFactory = (status, monitorName) => {
|
_statusMessageFactory = (status, monitorName) => {
|
||||||
if (status === DOWN) {
|
if (status === DOWN) {
|
||||||
return `🔴 Application [${monitorName}] went down`;
|
return `🔴 Application [${monitorName}] went down`;
|
||||||
@@ -14,6 +20,11 @@ class Teams extends NotificationProvider {
|
|||||||
return "Notification";
|
return "Notification";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select theme color to use based on status
|
||||||
|
* @param {const} status The status constant
|
||||||
|
* @returns {string} Selected color in hex RGB format
|
||||||
|
*/
|
||||||
_getThemeColor = (status) => {
|
_getThemeColor = (status) => {
|
||||||
if (status === DOWN) {
|
if (status === DOWN) {
|
||||||
return "ff0000";
|
return "ff0000";
|
||||||
@@ -24,6 +35,14 @@ class Teams extends NotificationProvider {
|
|||||||
return "008cff";
|
return "008cff";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate payload for notification
|
||||||
|
* @param {const} status The status of the monitor
|
||||||
|
* @param {string} monitorMessage Message to send
|
||||||
|
* @param {string} monitorName Name of monitor affected
|
||||||
|
* @param {string} monitorUrl URL of monitor affected
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
_notificationPayloadFactory = ({
|
_notificationPayloadFactory = ({
|
||||||
status,
|
status,
|
||||||
monitorMessage,
|
monitorMessage,
|
||||||
@@ -44,7 +63,7 @@ class Teams extends NotificationProvider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitorUrl) {
|
if (monitorUrl && monitorUrl !== "https://") {
|
||||||
facts.push({
|
facts.push({
|
||||||
name: "URL",
|
name: "URL",
|
||||||
value: monitorUrl,
|
value: monitorUrl,
|
||||||
@@ -74,10 +93,21 @@ class Teams extends NotificationProvider {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the notification
|
||||||
|
* @param {string} webhookUrl URL to send the request to
|
||||||
|
* @param {Object} payload Payload generated by _notificationPayloadFactory
|
||||||
|
*/
|
||||||
_sendNotification = async (webhookUrl, payload) => {
|
_sendNotification = async (webhookUrl, payload) => {
|
||||||
await axios.post(webhookUrl, payload);
|
await axios.post(webhookUrl, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a general notification
|
||||||
|
* @param {string} webhookUrl URL to send request to
|
||||||
|
* @param {string} msg Message to send
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
_handleGeneralNotification = (webhookUrl, msg) => {
|
_handleGeneralNotification = (webhookUrl, msg) => {
|
||||||
const payload = this._notificationPayloadFactory({
|
const payload = this._notificationPayloadFactory({
|
||||||
monitorMessage: msg
|
monitorMessage: msg
|
||||||
@@ -97,13 +127,17 @@ class Teams extends NotificationProvider {
|
|||||||
|
|
||||||
let url;
|
let url;
|
||||||
|
|
||||||
if (monitorJSON["type"] === "port") {
|
switch (monitorJSON["type"]) {
|
||||||
url = monitorJSON["hostname"];
|
case "http":
|
||||||
if (monitorJSON["port"]) {
|
case "keywork":
|
||||||
url += ":" + monitorJSON["port"];
|
url = monitorJSON["url"];
|
||||||
}
|
break;
|
||||||
} else {
|
case "docker":
|
||||||
url = monitorJSON["url"];
|
url = monitorJSON["docker_host"];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
url = monitorJSON["hostname"];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = this._notificationPayloadFactory({
|
const payload = this._notificationPayloadFactory({
|
||||||
|
@@ -24,6 +24,12 @@ class WeCom extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the message to send
|
||||||
|
* @param {Object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||||
|
* @param {string} msg General message
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
composeMessage(heartbeatJSON, msg) {
|
composeMessage(heartbeatJSON, msg) {
|
||||||
let title;
|
let title;
|
||||||
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||||
|
@@ -1,82 +1,103 @@
|
|||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
|
const { log } = require("../src/util");
|
||||||
|
const Alerta = require("./notification-providers/alerta");
|
||||||
|
const AlertNow = require("./notification-providers/alertnow");
|
||||||
|
const AliyunSms = require("./notification-providers/aliyun-sms");
|
||||||
const Apprise = require("./notification-providers/apprise");
|
const Apprise = require("./notification-providers/apprise");
|
||||||
const Discord = require("./notification-providers/discord");
|
const Bark = require("./notification-providers/bark");
|
||||||
const Gotify = require("./notification-providers/gotify");
|
|
||||||
const Line = require("./notification-providers/line");
|
|
||||||
const LunaSea = require("./notification-providers/lunasea");
|
|
||||||
const Mattermost = require("./notification-providers/mattermost");
|
|
||||||
const Matrix = require("./notification-providers/matrix");
|
|
||||||
const Octopush = require("./notification-providers/octopush");
|
|
||||||
const PromoSMS = require("./notification-providers/promosms");
|
|
||||||
const ClickSendSMS = require("./notification-providers/clicksendsms");
|
const ClickSendSMS = require("./notification-providers/clicksendsms");
|
||||||
|
const DingDing = require("./notification-providers/dingding");
|
||||||
|
const Discord = require("./notification-providers/discord");
|
||||||
|
const Feishu = require("./notification-providers/feishu");
|
||||||
|
const FreeMobile = require("./notification-providers/freemobile");
|
||||||
|
const GoogleChat = require("./notification-providers/google-chat");
|
||||||
|
const Gorush = require("./notification-providers/gorush");
|
||||||
|
const Gotify = require("./notification-providers/gotify");
|
||||||
|
const HomeAssistant = require("./notification-providers/home-assistant");
|
||||||
|
const Line = require("./notification-providers/line");
|
||||||
|
const LineNotify = require("./notification-providers/linenotify");
|
||||||
|
const LunaSea = require("./notification-providers/lunasea");
|
||||||
|
const Matrix = require("./notification-providers/matrix");
|
||||||
|
const Mattermost = require("./notification-providers/mattermost");
|
||||||
|
const Ntfy = require("./notification-providers/ntfy");
|
||||||
|
const Octopush = require("./notification-providers/octopush");
|
||||||
|
const OneBot = require("./notification-providers/onebot");
|
||||||
|
const PagerDuty = require("./notification-providers/pagerduty");
|
||||||
|
const PromoSMS = require("./notification-providers/promosms");
|
||||||
const Pushbullet = require("./notification-providers/pushbullet");
|
const Pushbullet = require("./notification-providers/pushbullet");
|
||||||
|
const PushDeer = require("./notification-providers/pushdeer");
|
||||||
const Pushover = require("./notification-providers/pushover");
|
const Pushover = require("./notification-providers/pushover");
|
||||||
const Pushy = require("./notification-providers/pushy");
|
const Pushy = require("./notification-providers/pushy");
|
||||||
const TechulusPush = require("./notification-providers/techulus-push");
|
|
||||||
const RocketChat = require("./notification-providers/rocket-chat");
|
const RocketChat = require("./notification-providers/rocket-chat");
|
||||||
|
const SerwerSMS = require("./notification-providers/serwersms");
|
||||||
const Signal = require("./notification-providers/signal");
|
const Signal = require("./notification-providers/signal");
|
||||||
const Slack = require("./notification-providers/slack");
|
const Slack = require("./notification-providers/slack");
|
||||||
const SMTP = require("./notification-providers/smtp");
|
const SMTP = require("./notification-providers/smtp");
|
||||||
|
const Squadcast = require("./notification-providers/squadcast");
|
||||||
|
const Stackfield = require("./notification-providers/stackfield");
|
||||||
const Teams = require("./notification-providers/teams");
|
const Teams = require("./notification-providers/teams");
|
||||||
|
const TechulusPush = require("./notification-providers/techulus-push");
|
||||||
const Telegram = require("./notification-providers/telegram");
|
const Telegram = require("./notification-providers/telegram");
|
||||||
const Webhook = require("./notification-providers/webhook");
|
const Webhook = require("./notification-providers/webhook");
|
||||||
const Feishu = require("./notification-providers/feishu");
|
|
||||||
const AliyunSms = require("./notification-providers/aliyun-sms");
|
|
||||||
const DingDing = require("./notification-providers/dingding");
|
|
||||||
const Bark = require("./notification-providers/bark");
|
|
||||||
const { log } = require("../src/util");
|
|
||||||
const SerwerSMS = require("./notification-providers/serwersms");
|
|
||||||
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 GoAlert = require("./notification-providers/goalert");
|
||||||
const Gorush = require("./notification-providers/gorush");
|
const SMSManager = require("./notification-providers/smsmanager");
|
||||||
const Alerta = require("./notification-providers/alerta");
|
const ServerChan = require("./notification-providers/serverchan");
|
||||||
const OneBot = require("./notification-providers/onebot");
|
|
||||||
const PushDeer = require("./notification-providers/pushdeer");
|
|
||||||
|
|
||||||
class Notification {
|
class Notification {
|
||||||
|
|
||||||
providerList = {};
|
providerList = {};
|
||||||
|
|
||||||
|
/** Initialize the notification providers */
|
||||||
static init() {
|
static init() {
|
||||||
log.info("notification", "Prepare Notification Providers");
|
log.info("notification", "Prepare Notification Providers");
|
||||||
|
|
||||||
this.providerList = {};
|
this.providerList = {};
|
||||||
|
|
||||||
const list = [
|
const list = [
|
||||||
new Apprise(),
|
new Alerta(),
|
||||||
|
new AlertNow(),
|
||||||
new AliyunSms(),
|
new AliyunSms(),
|
||||||
|
new Apprise(),
|
||||||
|
new Bark(),
|
||||||
|
new ClickSendSMS(),
|
||||||
new DingDing(),
|
new DingDing(),
|
||||||
new Discord(),
|
new Discord(),
|
||||||
new Teams(),
|
|
||||||
new Gotify(),
|
|
||||||
new Line(),
|
|
||||||
new LunaSea(),
|
|
||||||
new Feishu(),
|
new Feishu(),
|
||||||
new Mattermost(),
|
new FreeMobile(),
|
||||||
new Matrix(),
|
|
||||||
new Octopush(),
|
|
||||||
new PromoSMS(),
|
|
||||||
new ClickSendSMS(),
|
|
||||||
new Pushbullet(),
|
|
||||||
new Pushover(),
|
|
||||||
new Pushy(),
|
|
||||||
new TechulusPush(),
|
|
||||||
new RocketChat(),
|
|
||||||
new Signal(),
|
|
||||||
new Slack(),
|
|
||||||
new SMTP(),
|
|
||||||
new Telegram(),
|
|
||||||
new Webhook(),
|
|
||||||
new Bark(),
|
|
||||||
new SerwerSMS(),
|
|
||||||
new Stackfield(),
|
|
||||||
new WeCom(),
|
|
||||||
new GoogleChat(),
|
new GoogleChat(),
|
||||||
new Gorush(),
|
new Gorush(),
|
||||||
new Alerta(),
|
new Gotify(),
|
||||||
|
new HomeAssistant(),
|
||||||
|
new Line(),
|
||||||
|
new LineNotify(),
|
||||||
|
new LunaSea(),
|
||||||
|
new Matrix(),
|
||||||
|
new Mattermost(),
|
||||||
|
new Ntfy(),
|
||||||
|
new Octopush(),
|
||||||
new OneBot(),
|
new OneBot(),
|
||||||
|
new PagerDuty(),
|
||||||
|
new PromoSMS(),
|
||||||
|
new Pushbullet(),
|
||||||
new PushDeer(),
|
new PushDeer(),
|
||||||
|
new Pushover(),
|
||||||
|
new Pushy(),
|
||||||
|
new RocketChat(),
|
||||||
|
new ServerChan(),
|
||||||
|
new SerwerSMS(),
|
||||||
|
new Signal(),
|
||||||
|
new SMSManager(),
|
||||||
|
new Slack(),
|
||||||
|
new SMTP(),
|
||||||
|
new Squadcast(),
|
||||||
|
new Stackfield(),
|
||||||
|
new Teams(),
|
||||||
|
new TechulusPush(),
|
||||||
|
new Telegram(),
|
||||||
|
new Webhook(),
|
||||||
|
new WeCom(),
|
||||||
|
new GoAlert(),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let item of list) {
|
for (let item of list) {
|
||||||
@@ -92,13 +113,13 @@ class Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Send a notification
|
||||||
* @param notification : BeanModel
|
* @param {BeanModel} notification
|
||||||
* @param msg : string General Message
|
* @param {string} msg General Message
|
||||||
* @param monitorJSON : object Monitor details (For Up/Down only)
|
* @param {Object} monitorJSON Monitor details (For Up/Down only)
|
||||||
* @param heartbeatJSON : object Heartbeat details (For Up/Down only)
|
* @param {Object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||||
* @returns {Promise<string>} Successful msg
|
* @returns {Promise<string>} Successful msg
|
||||||
* Throw Error with fail msg
|
* @throws Error with fail msg
|
||||||
*/
|
*/
|
||||||
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
if (this.providerList[notification.type]) {
|
if (this.providerList[notification.type]) {
|
||||||
@@ -108,6 +129,13 @@ class Notification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save a notification
|
||||||
|
* @param {Object} notification Notification to save
|
||||||
|
* @param {?number} notificationID ID of notification to update
|
||||||
|
* @param {number} userID ID of user who adds notification
|
||||||
|
* @returns {Promise<Bean>}
|
||||||
|
*/
|
||||||
static async save(notification, notificationID, userID) {
|
static async save(notification, notificationID, userID) {
|
||||||
let bean;
|
let bean;
|
||||||
|
|
||||||
@@ -138,6 +166,12 @@ class Notification {
|
|||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a notification
|
||||||
|
* @param {number} notificationID ID of notification to delete
|
||||||
|
* @param {number} userID ID of user who created notification
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async delete(notificationID, userID) {
|
static async delete(notificationID, userID) {
|
||||||
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
|
||||||
notificationID,
|
notificationID,
|
||||||
@@ -151,6 +185,10 @@ class Notification {
|
|||||||
await R.trash(bean);
|
await R.trash(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if apprise exists
|
||||||
|
* @returns {boolean} Does the command apprise exist?
|
||||||
|
*/
|
||||||
static checkApprise() {
|
static checkApprise() {
|
||||||
let commandExistsSync = require("command-exists").sync;
|
let commandExistsSync = require("command-exists").sync;
|
||||||
let exists = commandExistsSync("apprise");
|
let exists = commandExistsSync("apprise");
|
||||||
@@ -160,11 +198,10 @@ class Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new monitor to the database.
|
* Apply the notification to every monitor
|
||||||
* @param {number} userID The ID of the user that owns this monitor.
|
* @param {number} notificationID ID of notification to apply
|
||||||
* @param {string} name The name of this monitor.
|
* @param {number} userID ID of user who created notification
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function applyNotificationEveryMonitor(notificationID, userID) {
|
async function applyNotificationEveryMonitor(notificationID, userID) {
|
||||||
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
|
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
|
||||||
|
@@ -2,10 +2,21 @@ const passwordHashOld = require("password-hash");
|
|||||||
const bcrypt = require("bcryptjs");
|
const bcrypt = require("bcryptjs");
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash a password
|
||||||
|
* @param {string} password
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
exports.generate = function (password) {
|
exports.generate = function (password) {
|
||||||
return bcrypt.hashSync(password, saltRounds);
|
return bcrypt.hashSync(password, saltRounds);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify a password against a hash
|
||||||
|
* @param {string} password
|
||||||
|
* @param {string} hash
|
||||||
|
* @returns {boolean} Does the password match the hash?
|
||||||
|
*/
|
||||||
exports.verify = function (password, hash) {
|
exports.verify = function (password, hash) {
|
||||||
if (isSHA1(hash)) {
|
if (isSHA1(hash)) {
|
||||||
return passwordHashOld.verify(password, hash);
|
return passwordHashOld.verify(password, hash);
|
||||||
@@ -14,10 +25,19 @@ exports.verify = function (password, hash) {
|
|||||||
return bcrypt.compareSync(password, hash);
|
return bcrypt.compareSync(password, hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the hash a SHA1 hash
|
||||||
|
* @param {string} hash
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
function isSHA1(hash) {
|
function isSHA1(hash) {
|
||||||
return (typeof hash === "string" && hash.startsWith("sha1"));
|
return (typeof hash === "string" && hash.startsWith("sha1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the hash need to be rehashed?
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
exports.needRehash = function (hash) {
|
exports.needRehash = function (hash) {
|
||||||
return isSHA1(hash);
|
return isSHA1(hash);
|
||||||
};
|
};
|
||||||
|
@@ -9,11 +9,10 @@ const util = require("./util-server");
|
|||||||
module.exports = Ping;
|
module.exports = Ping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} host - The host to ping
|
* Constructor for ping class
|
||||||
* @param {object} [options] - Options for the ping command
|
* @param {string} host Host to ping
|
||||||
|
* @param {object} [options] Options for the ping command
|
||||||
* @param {array|string} [options.args] - Arguments to pass to the ping command
|
* @param {array|string} [options.args] - Arguments to pass to the ping command
|
||||||
*
|
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
function Ping(host, options) {
|
function Ping(host, options) {
|
||||||
if (!host) {
|
if (!host) {
|
||||||
@@ -82,8 +81,17 @@ function Ping(host, options) {
|
|||||||
|
|
||||||
Ping.prototype.__proto__ = events.EventEmitter.prototype;
|
Ping.prototype.__proto__ = events.EventEmitter.prototype;
|
||||||
|
|
||||||
// SEND A PING
|
/**
|
||||||
// ===========
|
* Callback for send
|
||||||
|
* @callback pingCB
|
||||||
|
* @param {any} err Any error encountered
|
||||||
|
* @param {number} ms Ping time in ms
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a ping
|
||||||
|
* @param {pingCB} callback Callback to call with results
|
||||||
|
*/
|
||||||
Ping.prototype.send = function (callback) {
|
Ping.prototype.send = function (callback) {
|
||||||
let self = this;
|
let self = this;
|
||||||
callback = callback || function (err, ms) {
|
callback = callback || function (err, ms) {
|
||||||
@@ -97,7 +105,7 @@ Ping.prototype.send = function (callback) {
|
|||||||
let _exited;
|
let _exited;
|
||||||
let _errored;
|
let _errored;
|
||||||
|
|
||||||
this._ping = spawn(this._bin, this._args); // spawn the binary
|
this._ping = spawn(this._bin, this._args, { windowsHide: true }); // spawn the binary
|
||||||
|
|
||||||
this._ping.on("error", function (err) { // handle binary errors
|
this._ping.on("error", function (err) { // handle binary errors
|
||||||
_errored = true;
|
_errored = true;
|
||||||
@@ -157,8 +165,10 @@ Ping.prototype.send = function (callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// CALL Ping#send(callback) ON A TIMER
|
/**
|
||||||
// ===================================
|
* Ping every interval
|
||||||
|
* @param {pingCB} callback Callback to call with results
|
||||||
|
*/
|
||||||
Ping.prototype.start = function (callback) {
|
Ping.prototype.start = function (callback) {
|
||||||
let self = this;
|
let self = this;
|
||||||
this._i = setInterval(function () {
|
this._i = setInterval(function () {
|
||||||
@@ -167,8 +177,7 @@ Ping.prototype.start = function (callback) {
|
|||||||
self.send(callback);
|
self.send(callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
// STOP SENDING PINGS
|
/** Stop sending pings */
|
||||||
// ==================
|
|
||||||
Ping.prototype.stop = function () {
|
Ping.prototype.stop = function () {
|
||||||
clearInterval(this._i);
|
clearInterval(this._i);
|
||||||
};
|
};
|
||||||
@@ -177,7 +186,7 @@ Ping.prototype.stop = function () {
|
|||||||
* Try to convert to UTF-8 for Windows, as the ping's output on Windows is not UTF-8 and could be in other languages
|
* Try to convert to UTF-8 for Windows, as the ping's output on Windows is not UTF-8 and could be in other languages
|
||||||
* Thank @pemassi
|
* Thank @pemassi
|
||||||
* https://github.com/louislam/uptime-kuma/issues/570#issuecomment-941984094
|
* https://github.com/louislam/uptime-kuma/issues/570#issuecomment-941984094
|
||||||
* @param data
|
* @param {any} data
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function convertOutput(data) {
|
function convertOutput(data) {
|
||||||
|
@@ -33,8 +33,11 @@ const monitorStatus = new PrometheusClient.Gauge({
|
|||||||
});
|
});
|
||||||
|
|
||||||
class Prometheus {
|
class Prometheus {
|
||||||
monitorLabelValues = {}
|
monitorLabelValues = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} monitor Monitor object to monitor
|
||||||
|
*/
|
||||||
constructor(monitor) {
|
constructor(monitor) {
|
||||||
this.monitorLabelValues = {
|
this.monitorLabelValues = {
|
||||||
monitor_name: monitor.name,
|
monitor_name: monitor.name,
|
||||||
@@ -45,6 +48,11 @@ class Prometheus {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the metrics page
|
||||||
|
* @param {Object} heartbeat Heartbeat details
|
||||||
|
* @param {Object} tlsInfo TLS details
|
||||||
|
*/
|
||||||
update(heartbeat, tlsInfo) {
|
update(heartbeat, tlsInfo) {
|
||||||
|
|
||||||
if (typeof tlsInfo !== "undefined") {
|
if (typeof tlsInfo !== "undefined") {
|
||||||
|
@@ -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
|
||||||
@@ -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) {
|
||||||
|
@@ -2,11 +2,26 @@ const { RateLimiter } = require("limiter");
|
|||||||
const { log } = require("../src/util");
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
class KumaRateLimiter {
|
class KumaRateLimiter {
|
||||||
|
/**
|
||||||
|
* @param {Object} config Rate limiter configuration object
|
||||||
|
*/
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.errorMessage = config.errorMessage;
|
this.errorMessage = config.errorMessage;
|
||||||
this.rateLimiter = new RateLimiter(config);
|
this.rateLimiter = new RateLimiter(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for pass
|
||||||
|
* @callback passCB
|
||||||
|
* @param {Object} err Too many requests
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the request be passed through
|
||||||
|
* @param {passCB} callback
|
||||||
|
* @param {number} [num=1] Number of tokens to remove
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
async pass(callback, num = 1) {
|
async pass(callback, num = 1) {
|
||||||
const remainingRequests = await this.removeTokens(num);
|
const remainingRequests = await this.removeTokens(num);
|
||||||
log.info("rate-limit", "remaining requests: " + remainingRequests);
|
log.info("rate-limit", "remaining requests: " + remainingRequests);
|
||||||
@@ -22,6 +37,11 @@ class KumaRateLimiter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a given number of tokens
|
||||||
|
* @param {number} [num=1] Number of tokens to remove
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
async removeTokens(num = 1) {
|
async removeTokens(num = 1) {
|
||||||
return await this.rateLimiter.removeTokens(num);
|
return await this.rateLimiter.removeTokens(num);
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,19 @@
|
|||||||
let express = require("express");
|
let express = require("express");
|
||||||
const { allowDevAllOrigin } = require("../util-server");
|
const { allowDevAllOrigin, allowAllOrigin, percentageToColor, filterAndJoin, send403 } = 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, log } = require("../../src/util");
|
const { UP, DOWN, flipStatus, log } = require("../../src/util");
|
||||||
const StatusPage = require("../model/status_page");
|
const StatusPage = require("../model/status_page");
|
||||||
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
const { makeBadge } = require("badge-maker");
|
||||||
|
const { badgeConstants } = require("../config");
|
||||||
|
|
||||||
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) => {
|
||||||
@@ -33,6 +37,8 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
|||||||
let pushToken = request.params.pushToken;
|
let pushToken = request.params.pushToken;
|
||||||
let msg = request.query.msg || "OK";
|
let msg = request.query.msg || "OK";
|
||||||
let ping = request.query.ping || null;
|
let ping = request.query.ping || null;
|
||||||
|
let statusString = request.query.status || "up";
|
||||||
|
let status = (statusString === "up") ? UP : DOWN;
|
||||||
|
|
||||||
let monitor = await R.findOne("monitor", " push_token = ? AND active = 1 ", [
|
let monitor = await R.findOne("monitor", " push_token = ? AND active = 1 ", [
|
||||||
pushToken
|
pushToken
|
||||||
@@ -44,7 +50,6 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
|||||||
|
|
||||||
const previousHeartbeat = await Monitor.getPreviousHeartbeat(monitor.id);
|
const previousHeartbeat = await Monitor.getPreviousHeartbeat(monitor.id);
|
||||||
|
|
||||||
let status = UP;
|
|
||||||
if (monitor.isUpsideDown()) {
|
if (monitor.isUpsideDown()) {
|
||||||
status = flipStatus(status);
|
status = flipStatus(status);
|
||||||
}
|
}
|
||||||
@@ -54,7 +59,7 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
|||||||
let duration = 0;
|
let duration = 0;
|
||||||
|
|
||||||
let bean = R.dispense("heartbeat");
|
let bean = R.dispense("heartbeat");
|
||||||
bean.time = R.isoDateTime(dayjs.utc());
|
bean.time = R.isoDateTimeMillis(dayjs.utc());
|
||||||
|
|
||||||
if (previousHeartbeat) {
|
if (previousHeartbeat) {
|
||||||
isFirstBeat = false;
|
isFirstBeat = false;
|
||||||
@@ -62,6 +67,7 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("router", `/api/push/ called at ${dayjs().format("YYYY-MM-DD HH:mm:ss.SSS")}`);
|
||||||
log.debug("router", "PreviousStatus: " + previousStatus);
|
log.debug("router", "PreviousStatus: " + previousStatus);
|
||||||
log.debug("router", "Current Status: " + status);
|
log.debug("router", "Current Status: " + status);
|
||||||
|
|
||||||
@@ -86,120 +92,188 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
response.json({
|
response.status(404).json({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: e.message
|
msg: e.message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Status page config, incident, monitor list
|
router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response) => {
|
||||||
router.get("/api/status-page/:slug", cache("5 minutes"), async (request, response) => {
|
allowAllOrigin(response);
|
||||||
allowDevAllOrigin(response);
|
|
||||||
let slug = request.params.slug;
|
|
||||||
|
|
||||||
// Get Status Page
|
const {
|
||||||
let statusPage = await R.findOne("status_page", " slug = ? ", [
|
label,
|
||||||
slug
|
upLabel = "Up",
|
||||||
]);
|
downLabel = "Down",
|
||||||
|
upColor = badgeConstants.defaultUpColor,
|
||||||
if (!statusPage) {
|
downColor = badgeConstants.defaultDownColor,
|
||||||
response.statusCode = 404;
|
style = badgeConstants.defaultStyle,
|
||||||
response.json({
|
value, // for demo purpose only
|
||||||
msg: "Not Found"
|
} = request.query;
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Incident
|
const requestedMonitorId = parseInt(request.params.id, 10);
|
||||||
let incident = await R.findOne("incident", " pin = 1 AND active = 1 AND status_page_id = ? ", [
|
const overrideValue = value !== undefined ? parseInt(value) : undefined;
|
||||||
statusPage.id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (incident) {
|
let publicMonitor = await R.getRow(`
|
||||||
incident = incident.toPublicJSON();
|
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
|
||||||
|
WHERE monitor_group.group_id = \`group\`.id
|
||||||
|
AND monitor_group.monitor_id = ?
|
||||||
|
AND public = 1
|
||||||
|
`,
|
||||||
|
[ requestedMonitorId ]
|
||||||
|
);
|
||||||
|
|
||||||
|
const badgeValues = { style };
|
||||||
|
|
||||||
|
if (!publicMonitor) {
|
||||||
|
// return a "N/A" badge in naColor (grey), if monitor is not public / not available / non exsitant
|
||||||
|
|
||||||
|
badgeValues.message = "N/A";
|
||||||
|
badgeValues.color = badgeConstants.naColor;
|
||||||
|
} else {
|
||||||
|
const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
|
||||||
|
const state = overrideValue !== undefined ? overrideValue : heartbeat.status === 1;
|
||||||
|
|
||||||
|
badgeValues.label = label ? label : "";
|
||||||
|
badgeValues.color = state ? upColor : downColor;
|
||||||
|
badgeValues.message = label ?? state ? upLabel : downLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Group List
|
// build the svg based on given values
|
||||||
const publicGroupList = [];
|
const svg = makeBadge(badgeValues);
|
||||||
const showTags = !!statusPage.show_tags;
|
|
||||||
|
|
||||||
const list = await R.find("group", " public = 1 AND status_page_id = ? ORDER BY weight ", [
|
|
||||||
statusPage.id
|
|
||||||
]);
|
|
||||||
|
|
||||||
for (let groupBean of list) {
|
|
||||||
let monitorGroup = await groupBean.toPublicJSON(showTags);
|
|
||||||
publicGroupList.push(monitorGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response
|
|
||||||
response.json({
|
|
||||||
config: await statusPage.toPublicJSON(),
|
|
||||||
incident,
|
|
||||||
publicGroupList
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
send403(response, error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Status Page Polling Data
|
|
||||||
// Can fetch only if published
|
|
||||||
router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (request, response) => {
|
|
||||||
allowDevAllOrigin(response);
|
|
||||||
|
|
||||||
try {
|
|
||||||
let heartbeatList = {};
|
|
||||||
let uptimeList = {};
|
|
||||||
|
|
||||||
let slug = request.params.slug;
|
|
||||||
let statusPageID = await StatusPage.slugToID(slug);
|
|
||||||
|
|
||||||
let monitorIDList = await R.getCol(`
|
|
||||||
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
|
|
||||||
WHERE monitor_group.group_id = \`group\`.id
|
|
||||||
AND public = 1
|
|
||||||
AND \`group\`.status_page_id = ?
|
|
||||||
`, [
|
|
||||||
statusPageID
|
|
||||||
]);
|
|
||||||
|
|
||||||
for (let monitorID of monitorIDList) {
|
|
||||||
let list = await R.getAll(`
|
|
||||||
SELECT * FROM heartbeat
|
|
||||||
WHERE monitor_id = ?
|
|
||||||
ORDER BY time DESC
|
|
||||||
LIMIT 50
|
|
||||||
`, [
|
|
||||||
monitorID,
|
|
||||||
]);
|
|
||||||
|
|
||||||
list = R.convertToBeans("heartbeat", list);
|
|
||||||
heartbeatList[monitorID] = list.reverse().map(row => row.toPublicJSON());
|
|
||||||
|
|
||||||
const type = 24;
|
|
||||||
uptimeList[`${monitorID}_${type}`] = await Monitor.calcUptime(type, monitorID);
|
|
||||||
}
|
|
||||||
|
|
||||||
response.json({
|
|
||||||
heartbeatList,
|
|
||||||
uptimeList
|
|
||||||
});
|
|
||||||
|
|
||||||
|
response.type("image/svg+xml");
|
||||||
|
response.send(svg);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
send403(response, error.message);
|
send403(response, error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function send403(res, msg = "") {
|
router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (request, response) => {
|
||||||
res.status(403).json({
|
allowAllOrigin(response);
|
||||||
"status": "fail",
|
|
||||||
"msg": msg,
|
const {
|
||||||
});
|
label,
|
||||||
}
|
labelPrefix,
|
||||||
|
labelSuffix = badgeConstants.defaultUptimeLabelSuffix,
|
||||||
|
prefix,
|
||||||
|
suffix = badgeConstants.defaultUptimeValueSuffix,
|
||||||
|
color,
|
||||||
|
labelColor,
|
||||||
|
style = badgeConstants.defaultStyle,
|
||||||
|
value, // for demo purpose only
|
||||||
|
} = request.query;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const requestedMonitorId = parseInt(request.params.id, 10);
|
||||||
|
// if no duration is given, set value to 24 (h)
|
||||||
|
const requestedDuration = request.params.duration !== undefined ? parseInt(request.params.duration, 10) : 24;
|
||||||
|
const overrideValue = value && parseFloat(value);
|
||||||
|
|
||||||
|
let publicMonitor = await R.getRow(`
|
||||||
|
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
|
||||||
|
WHERE monitor_group.group_id = \`group\`.id
|
||||||
|
AND monitor_group.monitor_id = ?
|
||||||
|
AND public = 1
|
||||||
|
`,
|
||||||
|
[ requestedMonitorId ]
|
||||||
|
);
|
||||||
|
|
||||||
|
const badgeValues = { style };
|
||||||
|
|
||||||
|
if (!publicMonitor) {
|
||||||
|
// return a "N/A" badge in naColor (grey), if monitor is not public / not available / non exsitant
|
||||||
|
badgeValues.message = "N/A";
|
||||||
|
badgeValues.color = badgeConstants.naColor;
|
||||||
|
} else {
|
||||||
|
const uptime = overrideValue ?? await Monitor.calcUptime(
|
||||||
|
requestedDuration,
|
||||||
|
requestedMonitorId
|
||||||
|
);
|
||||||
|
|
||||||
|
// limit the displayed uptime percentage to four (two, when displayed as percent) decimal digits
|
||||||
|
const cleanUptime = parseFloat(uptime.toPrecision(4));
|
||||||
|
|
||||||
|
// use a given, custom color or calculate one based on the uptime value
|
||||||
|
badgeValues.color = color ?? percentageToColor(uptime);
|
||||||
|
// use a given, custom labelColor or use the default badge label color (defined by badge-maker)
|
||||||
|
badgeValues.labelColor = labelColor ?? "";
|
||||||
|
// build a lable string. If a custom label is given, override the default one (requestedDuration)
|
||||||
|
badgeValues.label = filterAndJoin([ labelPrefix, label ?? requestedDuration, labelSuffix ]);
|
||||||
|
badgeValues.message = filterAndJoin([ prefix, `${cleanUptime * 100}`, suffix ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// build the SVG based on given values
|
||||||
|
const svg = makeBadge(badgeValues);
|
||||||
|
|
||||||
|
response.type("image/svg+xml");
|
||||||
|
response.send(svg);
|
||||||
|
} catch (error) {
|
||||||
|
send403(response, error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/api/badge/:id/ping/:duration?", cache("5 minutes"), async (request, response) => {
|
||||||
|
allowAllOrigin(response);
|
||||||
|
|
||||||
|
const {
|
||||||
|
label,
|
||||||
|
labelPrefix,
|
||||||
|
labelSuffix = badgeConstants.defaultPingLabelSuffix,
|
||||||
|
prefix,
|
||||||
|
suffix = badgeConstants.defaultPingValueSuffix,
|
||||||
|
color = badgeConstants.defaultPingColor,
|
||||||
|
labelColor,
|
||||||
|
style = badgeConstants.defaultStyle,
|
||||||
|
value, // for demo purpose only
|
||||||
|
} = request.query;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const requestedMonitorId = parseInt(request.params.id, 10);
|
||||||
|
|
||||||
|
// Default duration is 24 (h) if not defined in queryParam, limited to 720h (30d)
|
||||||
|
const requestedDuration = Math.min(request.params.duration ? parseInt(request.params.duration, 10) : 24, 720);
|
||||||
|
const overrideValue = value && parseFloat(value);
|
||||||
|
|
||||||
|
const publicAvgPing = parseInt(await R.getCell(`
|
||||||
|
SELECT AVG(ping) FROM monitor_group, \`group\`, heartbeat
|
||||||
|
WHERE monitor_group.group_id = \`group\`.id
|
||||||
|
AND heartbeat.time > DATETIME('now', ? || ' hours')
|
||||||
|
AND heartbeat.ping IS NOT NULL
|
||||||
|
AND public = 1
|
||||||
|
AND heartbeat.monitor_id = ?
|
||||||
|
`,
|
||||||
|
[ -requestedDuration, requestedMonitorId ]
|
||||||
|
));
|
||||||
|
|
||||||
|
const badgeValues = { style };
|
||||||
|
|
||||||
|
if (!publicAvgPing) {
|
||||||
|
// return a "N/A" badge in naColor (grey), if monitor is not public / not available / non exsitant
|
||||||
|
|
||||||
|
badgeValues.message = "N/A";
|
||||||
|
badgeValues.color = badgeConstants.naColor;
|
||||||
|
} else {
|
||||||
|
const avgPing = parseInt(overrideValue ?? publicAvgPing);
|
||||||
|
|
||||||
|
badgeValues.color = color;
|
||||||
|
// use a given, custom labelColor or use the default badge label color (defined by badge-maker)
|
||||||
|
badgeValues.labelColor = labelColor ?? "";
|
||||||
|
// build a lable string. If a custom label is given, override the default one (requestedDuration)
|
||||||
|
badgeValues.label = filterAndJoin([ labelPrefix, label ?? requestedDuration, labelSuffix ]);
|
||||||
|
badgeValues.message = filterAndJoin([ prefix, avgPing, suffix ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// build the SVG based on given values
|
||||||
|
const svg = makeBadge(badgeValues);
|
||||||
|
|
||||||
|
response.type("image/svg+xml");
|
||||||
|
response.send(svg);
|
||||||
|
} catch (error) {
|
||||||
|
send403(response, error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
148
server/routers/status-page-router.js
Normal file
148
server/routers/status-page-router.js
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
let express = require("express");
|
||||||
|
const apicache = require("../modules/apicache");
|
||||||
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
const StatusPage = require("../model/status_page");
|
||||||
|
const { allowDevAllOrigin, send403 } = require("../util-server");
|
||||||
|
const { R } = require("redbean-node");
|
||||||
|
const Monitor = require("../model/monitor");
|
||||||
|
|
||||||
|
let router = express.Router();
|
||||||
|
|
||||||
|
let cache = apicache.middleware;
|
||||||
|
const server = UptimeKumaServer.getInstance();
|
||||||
|
|
||||||
|
router.get("/status/:slug", cache("5 minutes"), async (request, response) => {
|
||||||
|
let slug = request.params.slug;
|
||||||
|
await StatusPage.handleStatusPageResponse(response, server.indexHTML, slug);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/status", cache("5 minutes"), async (request, response) => {
|
||||||
|
let slug = "default";
|
||||||
|
await StatusPage.handleStatusPageResponse(response, server.indexHTML, slug);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/status-page", cache("5 minutes"), async (request, response) => {
|
||||||
|
let slug = "default";
|
||||||
|
await StatusPage.handleStatusPageResponse(response, server.indexHTML, slug);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Status page config, incident, monitor list
|
||||||
|
router.get("/api/status-page/:slug", cache("5 minutes"), async (request, response) => {
|
||||||
|
allowDevAllOrigin(response);
|
||||||
|
let slug = request.params.slug;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get Status Page
|
||||||
|
let statusPage = await R.findOne("status_page", " slug = ? ", [
|
||||||
|
slug
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!statusPage) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let statusPageData = await StatusPage.getStatusPageData(statusPage);
|
||||||
|
|
||||||
|
if (!statusPageData) {
|
||||||
|
response.statusCode = 404;
|
||||||
|
response.json({
|
||||||
|
msg: "Not Found"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response
|
||||||
|
response.json(statusPageData);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
send403(response, error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Status Page Polling Data
|
||||||
|
// Can fetch only if published
|
||||||
|
router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (request, response) => {
|
||||||
|
allowDevAllOrigin(response);
|
||||||
|
|
||||||
|
try {
|
||||||
|
let heartbeatList = {};
|
||||||
|
let uptimeList = {};
|
||||||
|
|
||||||
|
let slug = request.params.slug;
|
||||||
|
let statusPageID = await StatusPage.slugToID(slug);
|
||||||
|
|
||||||
|
let monitorIDList = await R.getCol(`
|
||||||
|
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
|
||||||
|
WHERE monitor_group.group_id = \`group\`.id
|
||||||
|
AND public = 1
|
||||||
|
AND \`group\`.status_page_id = ?
|
||||||
|
`, [
|
||||||
|
statusPageID
|
||||||
|
]);
|
||||||
|
|
||||||
|
for (let monitorID of monitorIDList) {
|
||||||
|
let list = await R.getAll(`
|
||||||
|
SELECT * FROM heartbeat
|
||||||
|
WHERE monitor_id = ?
|
||||||
|
ORDER BY time DESC
|
||||||
|
LIMIT 50
|
||||||
|
`, [
|
||||||
|
monitorID,
|
||||||
|
]);
|
||||||
|
|
||||||
|
list = R.convertToBeans("heartbeat", list);
|
||||||
|
heartbeatList[monitorID] = list.reverse().map(row => row.toPublicJSON());
|
||||||
|
|
||||||
|
const type = 24;
|
||||||
|
uptimeList[`${monitorID}_${type}`] = await Monitor.calcUptime(type, monitorID);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.json({
|
||||||
|
heartbeatList,
|
||||||
|
uptimeList
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
send403(response, error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Status page's manifest.json
|
||||||
|
router.get("/api/status-page/:slug/manifest.json", cache("1440 minutes"), async (request, response) => {
|
||||||
|
allowDevAllOrigin(response);
|
||||||
|
let slug = request.params.slug;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get Status Page
|
||||||
|
let statusPage = await R.findOne("status_page", " slug = ? ", [
|
||||||
|
slug
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!statusPage) {
|
||||||
|
response.statusCode = 404;
|
||||||
|
response.json({
|
||||||
|
msg: "Not Found"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response
|
||||||
|
response.json({
|
||||||
|
"name": statusPage.title,
|
||||||
|
"start_url": "/status/" + statusPage.slug,
|
||||||
|
"display": "standalone",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": statusPage.icon,
|
||||||
|
"sizes": "128x128",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
send403(response, error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
311
server/server.js
311
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,7 +16,7 @@ if (nodeVersion < requiredVersion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const args = require("args-parser")(process.argv);
|
const args = require("args-parser")(process.argv);
|
||||||
const { sleep, log, getRandomInt, genSecret, debug, isDev } = require("../src/util");
|
const { sleep, log, getRandomInt, genSecret, isDev } = require("../src/util");
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
|
|
||||||
log.info("server", "Welcome to Uptime Kuma");
|
log.info("server", "Welcome to Uptime Kuma");
|
||||||
@@ -26,14 +31,11 @@ log.info("server", "Node Env: " + process.env.NODE_ENV);
|
|||||||
|
|
||||||
log.info("server", "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");
|
|
||||||
|
|
||||||
log.info("server", "Importing 3rd-party libraries");
|
log.info("server", "Importing 3rd-party libraries");
|
||||||
log.debug("server", "Importing express");
|
log.debug("server", "Importing express");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
log.debug("server", "Importing socket.io");
|
const expressStaticGzip = require("express-static-gzip");
|
||||||
const { Server } = require("socket.io");
|
|
||||||
log.debug("server", "Importing redbean-node");
|
log.debug("server", "Importing redbean-node");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
log.debug("server", "Importing jsonwebtoken");
|
log.debug("server", "Importing jsonwebtoken");
|
||||||
@@ -50,32 +52,16 @@ 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) {
|
|
||||||
let list = await getMonitorJSONList(socket.userID);
|
|
||||||
io.to(socket.userID).emit("monitorList", list);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = module.exports = new UptimeKumaServer();
|
|
||||||
|
|
||||||
log.info("server", "Importing this project modules");
|
log.info("server", "Importing this project modules");
|
||||||
log.debug("server", "Importing Monitor");
|
log.debug("server", "Importing Monitor");
|
||||||
const Monitor = require("./model/monitor");
|
const Monitor = require("./model/monitor");
|
||||||
log.debug("server", "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, doubleCheckPassword, startE2eTests } = require("./util-server");
|
||||||
|
|
||||||
log.debug("server", "Importing Notification");
|
log.debug("server", "Importing Notification");
|
||||||
const { Notification } = require("./notification");
|
const { Notification } = require("./notification");
|
||||||
@@ -112,10 +98,7 @@ const port = [ args.port, process.env.UPTIME_KUMA_PORT, process.env.PORT, 3001 ]
|
|||||||
.map(portValue => parseInt(portValue))
|
.map(portValue => parseInt(portValue))
|
||||||
.find(portValue => !isNaN(portValue));
|
.find(portValue => !isNaN(portValue));
|
||||||
|
|
||||||
// SSL
|
const disableFrameSameOrigin = !!process.env.UPTIME_KUMA_DISABLE_FRAME_SAMEORIGIN || args["disable-frame-sameorigin"] || false;
|
||||||
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;
|
|
||||||
const disableFrameSameOrigin = args["disable-frame-sameorigin"] || !!process.env.UPTIME_KUMA_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
|
||||||
@@ -129,38 +112,21 @@ const twoFAVerifyOptions = {
|
|||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
const testMode = !!args["test"] || false;
|
const testMode = !!args["test"] || false;
|
||||||
|
const e2eTestMode = !!args["e2e"] || false;
|
||||||
|
|
||||||
if (config.demoMode) {
|
if (config.demoMode) {
|
||||||
log.info("server", "==== Demo Mode ====");
|
log.info("server", "==== Demo Mode ====");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("server", "Creating express and socket.io instance");
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
let httpServer;
|
|
||||||
|
|
||||||
if (sslKey && sslCert) {
|
|
||||||
log.info("server", "Server Type: HTTPS");
|
|
||||||
httpServer = https.createServer({
|
|
||||||
key: fs.readFileSync(sslKey),
|
|
||||||
cert: fs.readFileSync(sslCert)
|
|
||||||
}, app);
|
|
||||||
} else {
|
|
||||||
log.info("server", "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, sendDockerHostList } = require("./client");
|
||||||
const { statusPageSocketHandler } = require("./socket-handlers/status-page-socket-handler");
|
const { statusPageSocketHandler } = require("./socket-handlers/status-page-socket-handler");
|
||||||
const databaseSocketHandler = require("./socket-handlers/database-socket-handler");
|
const databaseSocketHandler = require("./socket-handlers/database-socket-handler");
|
||||||
const TwoFA = require("./2fa");
|
const TwoFA = require("./2fa");
|
||||||
const StatusPage = require("./model/status_page");
|
const StatusPage = require("./model/status_page");
|
||||||
const { cloudflaredSocketHandler, autoStart: cloudflaredAutoStart, stop: cloudflaredStop } = require("./socket-handlers/cloudflared-socket-handler");
|
const { cloudflaredSocketHandler, autoStart: cloudflaredAutoStart, stop: cloudflaredStop } = require("./socket-handlers/cloudflared-socket-handler");
|
||||||
const { proxySocketHandler } = require("./socket-handlers/proxy-socket-handler");
|
const { proxySocketHandler } = require("./socket-handlers/proxy-socket-handler");
|
||||||
|
const { dockerSocketHandler } = require("./socket-handlers/docker-socket-handler");
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
@@ -173,13 +139,6 @@ app.use(function (req, res, next) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Total WebSocket client connected to server currently, no actual use
|
|
||||||
*
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
let totalClient = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use for decode the auth object
|
* Use for decode the auth object
|
||||||
* @type {null}
|
* @type {null}
|
||||||
@@ -192,22 +151,6 @@ let jwtSecret = null;
|
|||||||
*/
|
*/
|
||||||
let needSetup = false;
|
let needSetup = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache Index HTML
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
let indexHTML = "";
|
|
||||||
|
|
||||||
try {
|
|
||||||
indexHTML = fs.readFileSync("./dist/index.html").toString();
|
|
||||||
} catch (e) {
|
|
||||||
// "dist/index.html" is not necessary for development
|
|
||||||
if (process.env.NODE_ENV !== "development") {
|
|
||||||
log.error("server", "Error: Cannot find 'dist/index.html', did you install correctly?");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
Database.init(args);
|
Database.init(args);
|
||||||
await initDatabase(testMode);
|
await initDatabase(testMode);
|
||||||
@@ -223,13 +166,25 @@ try {
|
|||||||
|
|
||||||
// Entry Page
|
// Entry Page
|
||||||
app.get("/", async (request, response) => {
|
app.get("/", async (request, response) => {
|
||||||
debug(`Request Domain: ${request.hostname}`);
|
let hostname = request.hostname;
|
||||||
|
if (await setting("trustProxy")) {
|
||||||
|
const proxy = request.headers["x-forwarded-host"];
|
||||||
|
if (proxy) {
|
||||||
|
hostname = proxy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("entry", `Request Domain: ${hostname}`);
|
||||||
|
|
||||||
|
if (hostname in StatusPage.domainMappingList) {
|
||||||
|
log.debug("entry", "This is a status page domain");
|
||||||
|
|
||||||
|
let slug = StatusPage.domainMappingList[hostname];
|
||||||
|
await StatusPage.handleStatusPageResponse(response, server.indexHTML, slug);
|
||||||
|
|
||||||
if (request.hostname in StatusPage.domainMappingList) {
|
|
||||||
debug("This is a status page domain");
|
|
||||||
response.send(indexHTML);
|
|
||||||
} else if (exports.entryPage && exports.entryPage.startsWith("statusPage-")) {
|
} else if (exports.entryPage && exports.entryPage.startsWith("statusPage-")) {
|
||||||
response.redirect("/status/" + exports.entryPage.replace("statusPage-", ""));
|
response.redirect("/status/" + exports.entryPage.replace("statusPage-", ""));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
response.redirect("/dashboard");
|
response.redirect("/dashboard");
|
||||||
}
|
}
|
||||||
@@ -258,7 +213,9 @@ try {
|
|||||||
// With Basic Auth using the first user's username/password
|
// With Basic Auth using the first user's username/password
|
||||||
app.get("/metrics", basicAuth, prometheusAPIMetrics());
|
app.get("/metrics", basicAuth, prometheusAPIMetrics());
|
||||||
|
|
||||||
app.use("/", express.static("dist"));
|
app.use("/", expressStaticGzip("dist", {
|
||||||
|
enableBrotli: true,
|
||||||
|
}));
|
||||||
|
|
||||||
// ./data/upload
|
// ./data/upload
|
||||||
app.use("/upload", express.static(Database.uploadDir));
|
app.use("/upload", express.static(Database.uploadDir));
|
||||||
@@ -271,12 +228,16 @@ try {
|
|||||||
const apiRouter = require("./routers/api-router");
|
const apiRouter = require("./routers/api-router");
|
||||||
app.use(apiRouter);
|
app.use(apiRouter);
|
||||||
|
|
||||||
|
// Status Page Router
|
||||||
|
const statusPageRouter = require("./routers/status-page-router");
|
||||||
|
app.use(statusPageRouter);
|
||||||
|
|
||||||
// Universal Route Handler, must be at the end of all express routes.
|
// Universal Route Handler, must be at the end of all express routes.
|
||||||
app.get("*", async (_request, response) => {
|
app.get("*", async (_request, response) => {
|
||||||
if (_request.originalUrl.startsWith("/upload/")) {
|
if (_request.originalUrl.startsWith("/upload/")) {
|
||||||
response.status(404).send("File not found.");
|
response.status(404).send("File not found.");
|
||||||
} else {
|
} else {
|
||||||
response.send(indexHTML);
|
response.send(server.indexHTML);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -285,23 +246,19 @@ try {
|
|||||||
|
|
||||||
sendInfo(socket);
|
sendInfo(socket);
|
||||||
|
|
||||||
totalClient++;
|
|
||||||
|
|
||||||
if (needSetup) {
|
if (needSetup) {
|
||||||
log.info("server", "Redirect to setup page");
|
log.info("server", "Redirect to setup page");
|
||||||
socket.emit("setup");
|
socket.emit("setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on("disconnect", () => {
|
|
||||||
totalClient--;
|
|
||||||
});
|
|
||||||
|
|
||||||
// ***************************
|
// ***************************
|
||||||
// Public Socket API
|
// Public Socket API
|
||||||
// ***************************
|
// ***************************
|
||||||
|
|
||||||
socket.on("loginByToken", async (token, callback) => {
|
socket.on("loginByToken", async (token, callback) => {
|
||||||
log.info("auth", `Login by token. IP=${getClientIp(socket)}`);
|
const clientIP = await server.getClientIP(socket);
|
||||||
|
|
||||||
|
log.info("auth", `Login by token. IP=${clientIP}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let decoded = jwt.verify(token, jwtSecret);
|
let decoded = jwt.verify(token, jwtSecret);
|
||||||
@@ -317,14 +274,14 @@ try {
|
|||||||
afterLogin(socket, user);
|
afterLogin(socket, user);
|
||||||
log.debug("auth", "afterLogin ok");
|
log.debug("auth", "afterLogin ok");
|
||||||
|
|
||||||
log.info("auth", `Successfully logged in user ${decoded.username}. IP=${getClientIp(socket)}`);
|
log.info("auth", `Successfully logged in user ${decoded.username}. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
log.info("auth", `Inactive or deleted user ${decoded.username}. IP=${getClientIp(socket)}`);
|
log.info("auth", `Inactive or deleted user ${decoded.username}. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -333,7 +290,7 @@ try {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
log.error("auth", `Invalid token. IP=${getClientIp(socket)}`);
|
log.error("auth", `Invalid token. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -344,7 +301,9 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("login", async (data, callback) => {
|
socket.on("login", async (data, callback) => {
|
||||||
log.info("auth", `Login by username + password. IP=${getClientIp(socket)}`);
|
const clientIP = await server.getClientIP(socket);
|
||||||
|
|
||||||
|
log.info("auth", `Login by username + password. IP=${clientIP}`);
|
||||||
|
|
||||||
// Checking
|
// Checking
|
||||||
if (typeof callback !== "function") {
|
if (typeof callback !== "function") {
|
||||||
@@ -357,17 +316,17 @@ 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)}`);
|
log.info("auth", `Too many failed requests for user ${data.username}. IP=${clientIP}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await login(data.username, data.password);
|
let user = await login(data.username, data.password);
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
if (user.twofa_status == 0) {
|
if (user.twofa_status === 0) {
|
||||||
afterLogin(socket, user);
|
afterLogin(socket, user);
|
||||||
|
|
||||||
log.info("auth", `Successfully logged in user ${data.username}. IP=${getClientIp(socket)}`);
|
log.info("auth", `Successfully logged in user ${data.username}. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -377,9 +336,9 @@ try {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.twofa_status == 1 && !data.token) {
|
if (user.twofa_status === 1 && !data.token) {
|
||||||
|
|
||||||
log.info("auth", `2FA token required for user ${data.username}. IP=${getClientIp(socket)}`);
|
log.info("auth", `2FA token required for user ${data.username}. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
tokenRequired: true,
|
tokenRequired: true,
|
||||||
@@ -397,7 +356,7 @@ try {
|
|||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
log.info("auth", `Successfully logged in user ${data.username}. IP=${getClientIp(socket)}`);
|
log.info("auth", `Successfully logged in user ${data.username}. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -407,7 +366,7 @@ try {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
log.warn("auth", `Invalid token provided for user ${data.username}. IP=${getClientIp(socket)}`);
|
log.warn("auth", `Invalid token provided for user ${data.username}. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -417,7 +376,7 @@ try {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
log.warn("auth", `Incorrect username or password for user ${data.username}. IP=${getClientIp(socket)}`);
|
log.warn("auth", `Incorrect username or password for user ${data.username}. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -454,7 +413,7 @@ try {
|
|||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (user.twofa_status == 0) {
|
if (user.twofa_status === 0) {
|
||||||
let newSecret = genSecret();
|
let newSecret = genSecret();
|
||||||
let encodedSecret = base32.encode(newSecret);
|
let encodedSecret = base32.encode(newSecret);
|
||||||
|
|
||||||
@@ -489,6 +448,8 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("save2FA", async (currentPassword, callback) => {
|
socket.on("save2FA", async (currentPassword, callback) => {
|
||||||
|
const clientIP = await server.getClientIP(socket);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (! await twoFaRateLimiter.pass(callback)) {
|
if (! await twoFaRateLimiter.pass(callback)) {
|
||||||
return;
|
return;
|
||||||
@@ -501,7 +462,7 @@ try {
|
|||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
log.info("auth", `Saved 2FA token. IP=${getClientIp(socket)}`);
|
log.info("auth", `Saved 2FA token. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -509,7 +470,7 @@ try {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
log.error("auth", `Error changing 2FA token. IP=${getClientIp(socket)}`);
|
log.error("auth", `Error changing 2FA token. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -519,6 +480,8 @@ try {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("disable2FA", async (currentPassword, callback) => {
|
socket.on("disable2FA", async (currentPassword, callback) => {
|
||||||
|
const clientIP = await server.getClientIP(socket);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (! await twoFaRateLimiter.pass(callback)) {
|
if (! await twoFaRateLimiter.pass(callback)) {
|
||||||
return;
|
return;
|
||||||
@@ -528,7 +491,7 @@ 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)}`);
|
log.info("auth", `Disabled 2FA token. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -536,7 +499,7 @@ try {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
log.error("auth", `Error disabling 2FA token. IP=${getClientIp(socket)}`);
|
log.error("auth", `Error disabling 2FA token. IP=${clientIP}`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -585,7 +548,7 @@ try {
|
|||||||
socket.userID,
|
socket.userID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (user.twofa_status == 1) {
|
if (user.twofa_status === 1) {
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
status: true,
|
status: true,
|
||||||
@@ -707,9 +670,10 @@ try {
|
|||||||
bean.basic_auth_pass = monitor.basic_auth_pass;
|
bean.basic_auth_pass = monitor.basic_auth_pass;
|
||||||
bean.interval = monitor.interval;
|
bean.interval = monitor.interval;
|
||||||
bean.retryInterval = monitor.retryInterval;
|
bean.retryInterval = monitor.retryInterval;
|
||||||
|
bean.resendInterval = monitor.resendInterval;
|
||||||
bean.hostname = monitor.hostname;
|
bean.hostname = monitor.hostname;
|
||||||
bean.maxretries = monitor.maxretries;
|
bean.maxretries = monitor.maxretries;
|
||||||
bean.port = monitor.port;
|
bean.port = parseInt(monitor.port);
|
||||||
bean.keyword = monitor.keyword;
|
bean.keyword = monitor.keyword;
|
||||||
bean.ignoreTls = monitor.ignoreTls;
|
bean.ignoreTls = monitor.ignoreTls;
|
||||||
bean.expiryNotification = monitor.expiryNotification;
|
bean.expiryNotification = monitor.expiryNotification;
|
||||||
@@ -719,10 +683,23 @@ try {
|
|||||||
bean.dns_resolve_type = monitor.dns_resolve_type;
|
bean.dns_resolve_type = monitor.dns_resolve_type;
|
||||||
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.docker_container = monitor.docker_container;
|
||||||
|
bean.docker_host = monitor.docker_host;
|
||||||
bean.proxyId = Number.isInteger(monitor.proxyId) ? monitor.proxyId : null;
|
bean.proxyId = Number.isInteger(monitor.proxyId) ? monitor.proxyId : null;
|
||||||
bean.mqttUsername = monitor.mqttUsername;
|
bean.mqttUsername = monitor.mqttUsername;
|
||||||
|
bean.mqttPassword = monitor.mqttPassword;
|
||||||
bean.mqttTopic = monitor.mqttTopic;
|
bean.mqttTopic = monitor.mqttTopic;
|
||||||
bean.mqttSuccessMessage = monitor.mqttSuccessMessage;
|
bean.mqttSuccessMessage = monitor.mqttSuccessMessage;
|
||||||
|
bean.databaseConnectionString = monitor.databaseConnectionString;
|
||||||
|
bean.databaseQuery = monitor.databaseQuery;
|
||||||
|
bean.authMethod = monitor.authMethod;
|
||||||
|
bean.authWorkstation = monitor.authWorkstation;
|
||||||
|
bean.authDomain = monitor.authDomain;
|
||||||
|
bean.radiusUsername = monitor.radiusUsername;
|
||||||
|
bean.radiusPassword = monitor.radiusPassword;
|
||||||
|
bean.radiusCalledStationId = monitor.radiusCalledStationId;
|
||||||
|
bean.radiusCallingStationId = monitor.radiusCallingStationId;
|
||||||
|
bean.radiusSecret = monitor.radiusSecret;
|
||||||
|
|
||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
|
|
||||||
@@ -1096,7 +1073,13 @@ try {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
if (data.disableAuth) {
|
// If currently is disabled auth, don't need to check
|
||||||
|
// Disabled Auth + Want to Disable Auth => No Check
|
||||||
|
// Disabled Auth + Want to Enable Auth => No Check
|
||||||
|
// Enabled Auth + Want to Disable Auth => Check!!
|
||||||
|
// Enabled Auth + Want to Enable Auth => No Check
|
||||||
|
const currentDisabledAuth = await setting("disableAuth");
|
||||||
|
if (!currentDisabledAuth && data.disableAuth) {
|
||||||
await doubleCheckPassword(socket, currentPassword);
|
await doubleCheckPassword(socket, currentPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1205,7 +1188,7 @@ try {
|
|||||||
let version17x = compareVersions.compare(backupData.version, "1.7.0", ">=");
|
let version17x = compareVersions.compare(backupData.version, "1.7.0", ">=");
|
||||||
|
|
||||||
// If the import option is "overwrite" it'll clear most of the tables, except "settings" and "user"
|
// If the import option is "overwrite" it'll clear most of the tables, except "settings" and "user"
|
||||||
if (importHandle == "overwrite") {
|
if (importHandle === "overwrite") {
|
||||||
// Stops every monitor first, so it doesn't execute any heartbeat while importing
|
// Stops every monitor first, so it doesn't execute any heartbeat while importing
|
||||||
for (let id in server.monitorList) {
|
for (let id in server.monitorList) {
|
||||||
let monitor = server.monitorList[id];
|
let monitor = server.monitorList[id];
|
||||||
@@ -1229,7 +1212,7 @@ try {
|
|||||||
|
|
||||||
for (let i = 0; i < notificationListData.length; i++) {
|
for (let i = 0; i < notificationListData.length; i++) {
|
||||||
// Only starts importing the notification if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
// Only starts importing the notification if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
||||||
if ((importHandle == "skip" && notificationNameListString.includes(notificationListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") {
|
if ((importHandle === "skip" && notificationNameListString.includes(notificationListData[i].name) === false) || importHandle === "keep" || importHandle === "overwrite") {
|
||||||
|
|
||||||
let notification = JSON.parse(notificationListData[i].config);
|
let notification = JSON.parse(notificationListData[i].config);
|
||||||
await Notification.save(notification, null, socket.userID);
|
await Notification.save(notification, null, socket.userID);
|
||||||
@@ -1264,7 +1247,7 @@ try {
|
|||||||
|
|
||||||
for (let i = 0; i < monitorListData.length; i++) {
|
for (let i = 0; i < monitorListData.length; i++) {
|
||||||
// Only starts importing the monitor if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
// Only starts importing the monitor if the import option is "overwrite", "keep" or "skip" but the notification doesn't exists
|
||||||
if ((importHandle == "skip" && monitorNameListString.includes(monitorListData[i].name) == false) || importHandle == "keep" || importHandle == "overwrite") {
|
if ((importHandle === "skip" && monitorNameListString.includes(monitorListData[i].name) === false) || importHandle === "keep" || importHandle === "overwrite") {
|
||||||
|
|
||||||
// Define in here every new variable for monitors which where implemented after the first version of the Import/Export function (1.6.0)
|
// Define in here every new variable for monitors which where implemented after the first version of the Import/Export function (1.6.0)
|
||||||
// --- Start ---
|
// --- Start ---
|
||||||
@@ -1290,10 +1273,14 @@ try {
|
|||||||
method: monitorListData[i].method || "GET",
|
method: monitorListData[i].method || "GET",
|
||||||
body: monitorListData[i].body,
|
body: monitorListData[i].body,
|
||||||
headers: monitorListData[i].headers,
|
headers: monitorListData[i].headers,
|
||||||
|
authMethod: monitorListData[i].authMethod,
|
||||||
basic_auth_user: monitorListData[i].basic_auth_user,
|
basic_auth_user: monitorListData[i].basic_auth_user,
|
||||||
basic_auth_pass: monitorListData[i].basic_auth_pass,
|
basic_auth_pass: monitorListData[i].basic_auth_pass,
|
||||||
|
authWorkstation: monitorListData[i].authWorkstation,
|
||||||
|
authDomain: monitorListData[i].authDomain,
|
||||||
interval: monitorListData[i].interval,
|
interval: monitorListData[i].interval,
|
||||||
retryInterval: retryInterval,
|
retryInterval: retryInterval,
|
||||||
|
resendInterval: monitorListData[i].resendInterval || 0,
|
||||||
hostname: monitorListData[i].hostname,
|
hostname: monitorListData[i].hostname,
|
||||||
maxretries: monitorListData[i].maxretries,
|
maxretries: monitorListData[i].maxretries,
|
||||||
port: monitorListData[i].port,
|
port: monitorListData[i].port,
|
||||||
@@ -1361,7 +1348,7 @@ try {
|
|||||||
await updateMonitorNotification(bean.id, notificationIDList);
|
await updateMonitorNotification(bean.id, notificationIDList);
|
||||||
|
|
||||||
// If monitor was active start it immediately, otherwise pause it
|
// If monitor was active start it immediately, otherwise pause it
|
||||||
if (monitorListData[i].active == 1) {
|
if (monitorListData[i].active === 1) {
|
||||||
await startMonitor(socket.userID, bean.id);
|
await startMonitor(socket.userID, bean.id);
|
||||||
} else {
|
} else {
|
||||||
await pauseMonitor(socket.userID, bean.id);
|
await pauseMonitor(socket.userID, bean.id);
|
||||||
@@ -1462,6 +1449,7 @@ try {
|
|||||||
cloudflaredSocketHandler(socket);
|
cloudflaredSocketHandler(socket);
|
||||||
databaseSocketHandler(socket);
|
databaseSocketHandler(socket);
|
||||||
proxySocketHandler(socket);
|
proxySocketHandler(socket);
|
||||||
|
dockerSocketHandler(socket);
|
||||||
|
|
||||||
log.debug("server", "added all socket handlers");
|
log.debug("server", "added all socket handlers");
|
||||||
|
|
||||||
@@ -1482,12 +1470,12 @@ try {
|
|||||||
|
|
||||||
log.info("server", "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) {
|
||||||
log.info("server", `Listening on ${hostname}:${port}`);
|
log.info("server", `Listening on ${hostname}:${port}`);
|
||||||
} else {
|
} else {
|
||||||
@@ -1499,6 +1487,10 @@ try {
|
|||||||
if (testMode) {
|
if (testMode) {
|
||||||
startUnitTest();
|
startUnitTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e2eTestMode) {
|
||||||
|
startE2eTests();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
initBackgroundJobs(args);
|
initBackgroundJobs(args);
|
||||||
@@ -1509,11 +1501,11 @@ try {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds or removes notifications from a monitor.
|
* Update notifications for a given monitor
|
||||||
* @param {number} monitorID The ID of the monitor to add/remove notifications from.
|
* @param {number} monitorID ID of monitor to update
|
||||||
* @param {Array.<number>} notificationIDList An array of IDs for the notifications to add/remove.
|
* @param {number[]} notificationIDList List of new notification
|
||||||
*
|
* providers to add
|
||||||
* Generated by Trelent
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function updateMonitorNotification(monitorID, notificationIDList) {
|
async function updateMonitorNotification(monitorID, notificationIDList) {
|
||||||
await R.exec("DELETE FROM monitor_notification WHERE monitor_id = ? ", [
|
await R.exec("DELETE FROM monitor_notification WHERE monitor_id = ? ", [
|
||||||
@@ -1531,11 +1523,11 @@ async function updateMonitorNotification(monitorID, notificationIDList) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function checks if the user owns a monitor with the given ID.
|
* Check if a given user owns a specific monitor
|
||||||
* @param {number} monitorID - The ID of the monitor to check ownership for.
|
* @param {number} userID
|
||||||
* @param {number} userID - The ID of the user who is trying to access this data.
|
* @param {number} monitorID
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
* @throws {Error} The specified user does not own the monitor
|
||||||
*/
|
*/
|
||||||
async function checkOwner(userID, monitorID) {
|
async function checkOwner(userID, monitorID) {
|
||||||
let row = await R.getRow("SELECT id FROM monitor WHERE id = ? AND user_id = ? ", [
|
let row = await R.getRow("SELECT id FROM monitor WHERE id = ? AND user_id = ? ", [
|
||||||
@@ -1549,8 +1541,11 @@ async function checkOwner(userID, monitorID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Function called after user login
|
||||||
* This function is used to send the heartbeat list of a monitor.
|
* This function is used to send the heartbeat list of a monitor.
|
||||||
* @param {Socket} socket - The socket object that will be used to send the data.
|
* @param {Socket} socket Socket.io instance
|
||||||
|
* @param {Object} user User object
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function afterLogin(socket, user) {
|
async function afterLogin(socket, user) {
|
||||||
socket.userID = user.id;
|
socket.userID = user.id;
|
||||||
@@ -1559,6 +1554,7 @@ async function afterLogin(socket, user) {
|
|||||||
let monitorList = await server.sendMonitorList(socket);
|
let monitorList = await server.sendMonitorList(socket);
|
||||||
sendNotificationList(socket);
|
sendNotificationList(socket);
|
||||||
sendProxyList(socket);
|
sendProxyList(socket);
|
||||||
|
sendDockerHostList(socket);
|
||||||
|
|
||||||
await sleep(500);
|
await sleep(500);
|
||||||
|
|
||||||
@@ -1578,30 +1574,10 @@ async function afterLogin(socket, user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of monitors for the given user.
|
* Initialize the database
|
||||||
* @param {string} userID - The ID of the user to get monitors for.
|
* @param {boolean} [testMode=false] Should the connection be
|
||||||
* @returns {Promise<Object>} A promise that resolves to an object with monitor IDs as keys and monitor objects as values.
|
* started in test mode?
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
|
||||||
async function 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connect to the database and patch it if necessary.
|
|
||||||
*
|
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function initDatabase(testMode = false) {
|
async function initDatabase(testMode = false) {
|
||||||
if (! fs.existsSync(Database.path)) {
|
if (! fs.existsSync(Database.path)) {
|
||||||
@@ -1638,11 +1614,10 @@ async function initDatabase(testMode = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resume a monitor.
|
* Start the specified monitor
|
||||||
* @param {string} userID - The ID of the user who owns the monitor.
|
* @param {number} userID ID of user who owns monitor
|
||||||
* @param {string} monitorID - The ID of the monitor to resume.
|
* @param {number} monitorID ID of monitor to start
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function startMonitor(userID, monitorID) {
|
async function startMonitor(userID, monitorID) {
|
||||||
await checkOwner(userID, monitorID);
|
await checkOwner(userID, monitorID);
|
||||||
@@ -1666,16 +1641,21 @@ async function startMonitor(userID, monitorID) {
|
|||||||
monitor.start(io);
|
monitor.start(io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart a given monitor
|
||||||
|
* @param {number} userID ID of user who owns monitor
|
||||||
|
* @param {number} monitorID ID of monitor to start
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async function restartMonitor(userID, monitorID) {
|
async function restartMonitor(userID, monitorID) {
|
||||||
return await startMonitor(userID, monitorID);
|
return await startMonitor(userID, monitorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pause a monitor.
|
* Pause a given monitor
|
||||||
* @param {string} userID - The ID of the user who owns the monitor.
|
* @param {number} userID ID of user who owns monitor
|
||||||
* @param {string} monitorID - The ID of the monitor to pause.
|
* @param {number} monitorID ID of monitor to start
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function pauseMonitor(userID, monitorID) {
|
async function pauseMonitor(userID, monitorID) {
|
||||||
await checkOwner(userID, monitorID);
|
await checkOwner(userID, monitorID);
|
||||||
@@ -1692,9 +1672,7 @@ async function pauseMonitor(userID, monitorID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Resume active monitors */
|
||||||
* Resume active monitors
|
|
||||||
*/
|
|
||||||
async function startMonitors() {
|
async function startMonitors() {
|
||||||
let list = await R.find("monitor", " active = 1 ");
|
let list = await R.find("monitor", " active = 1 ");
|
||||||
|
|
||||||
@@ -1710,10 +1688,10 @@ async function startMonitors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Shutdown the application
|
||||||
* Stops all monitors and closes the database connection.
|
* Stops all monitors and closes the database connection.
|
||||||
* @param {string} signal The signal that triggered this function to be called.
|
* @param {string} signal The signal that triggered this function to be called.
|
||||||
*
|
* @returns {Promise<void>}
|
||||||
* Generated by Trelent
|
|
||||||
*/
|
*/
|
||||||
async function shutdownFunction(signal) {
|
async function shutdownFunction(signal) {
|
||||||
log.info("server", "Shutdown requested");
|
log.info("server", "Shutdown requested");
|
||||||
@@ -1731,15 +1709,12 @@ async function shutdownFunction(signal) {
|
|||||||
await cloudflaredStop();
|
await cloudflaredStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClientIp(socket) {
|
/** Final function called before application exits */
|
||||||
return socket.client.conn.remoteAddress.replace(/^.*:/, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function finalFunction() {
|
function finalFunction() {
|
||||||
log.info("server", "Graceful shutdown successful!");
|
log.info("server", "Graceful shutdown successful!");
|
||||||
}
|
}
|
||||||
|
|
||||||
gracefulShutdown(httpServer, {
|
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
|
||||||
@@ -1751,6 +1726,6 @@ gracefulShutdown(httpServer, {
|
|||||||
// Catch unexpected errors here
|
// Catch unexpected errors here
|
||||||
process.addListener("unhandledRejection", (error, promise) => {
|
process.addListener("unhandledRejection", (error, promise) => {
|
||||||
console.trace(error);
|
console.trace(error);
|
||||||
errorLog(error, false);
|
UptimeKumaServer.errorLog(error, false);
|
||||||
console.error("If you keep encountering errors, please report to https://github.com/louislam/uptime-kuma/issues");
|
console.error("If you keep encountering errors, please report to https://github.com/louislam/uptime-kuma/issues");
|
||||||
});
|
});
|
||||||
|
165
server/settings.js
Normal file
165
server/settings.js
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
const { R } = require("redbean-node");
|
||||||
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example:
|
||||||
|
* {
|
||||||
|
* key1: {
|
||||||
|
* value: "value2",
|
||||||
|
* timestamp: 12345678
|
||||||
|
* },
|
||||||
|
* key2: {
|
||||||
|
* value: 2,
|
||||||
|
* timestamp: 12345678
|
||||||
|
* },
|
||||||
|
* }
|
||||||
|
* @type {{}}
|
||||||
|
*/
|
||||||
|
static cacheList = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static cacheCleaner = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve value of setting based on key
|
||||||
|
* @param {string} key Key of setting to retrieve
|
||||||
|
* @returns {Promise<any>} Value
|
||||||
|
*/
|
||||||
|
static async get(key) {
|
||||||
|
|
||||||
|
// Start cache clear if not started yet
|
||||||
|
if (!Settings.cacheCleaner) {
|
||||||
|
Settings.cacheCleaner = setInterval(() => {
|
||||||
|
log.debug("settings", "Cache Cleaner is just started.");
|
||||||
|
for (key in Settings.cacheList) {
|
||||||
|
if (Date.now() - Settings.cacheList[key].timestamp > 60 * 1000) {
|
||||||
|
log.debug("settings", "Cache Cleaner deleted: " + key);
|
||||||
|
delete Settings.cacheList[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query from cache
|
||||||
|
if (key in Settings.cacheList) {
|
||||||
|
const v = Settings.cacheList[key].value;
|
||||||
|
log.debug("settings", `Get Setting (cache): ${key}: ${v}`);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [
|
||||||
|
key,
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const v = JSON.parse(value);
|
||||||
|
log.debug("settings", `Get Setting: ${key}: ${v}`);
|
||||||
|
|
||||||
|
Settings.cacheList[key] = {
|
||||||
|
value: v,
|
||||||
|
timestamp: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
return v;
|
||||||
|
} catch (e) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the specified setting to specified value
|
||||||
|
* @param {string} key Key of setting to set
|
||||||
|
* @param {any} value Value to set to
|
||||||
|
* @param {?string} type Type of setting
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async set(key, value, type = null) {
|
||||||
|
|
||||||
|
let bean = await R.findOne("setting", " `key` = ? ", [
|
||||||
|
key,
|
||||||
|
]);
|
||||||
|
if (!bean) {
|
||||||
|
bean = R.dispense("setting");
|
||||||
|
bean.key = key;
|
||||||
|
}
|
||||||
|
bean.type = type;
|
||||||
|
bean.value = JSON.stringify(value);
|
||||||
|
await R.store(bean);
|
||||||
|
|
||||||
|
Settings.deleteCache([ key ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get settings based on type
|
||||||
|
* @param {string} type The type of setting
|
||||||
|
* @returns {Promise<Bean>}
|
||||||
|
*/
|
||||||
|
static async getSettings(type) {
|
||||||
|
let list = await R.getAll("SELECT `key`, `value` FROM setting WHERE `type` = ? ", [
|
||||||
|
type,
|
||||||
|
]);
|
||||||
|
|
||||||
|
let result = {};
|
||||||
|
|
||||||
|
for (let row of list) {
|
||||||
|
try {
|
||||||
|
result[row.key] = JSON.parse(row.value);
|
||||||
|
} catch (e) {
|
||||||
|
result[row.key] = row.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set settings based on type
|
||||||
|
* @param {string} type Type of settings to set
|
||||||
|
* @param {Object} data Values of settings
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async setSettings(type, data) {
|
||||||
|
let keyList = Object.keys(data);
|
||||||
|
|
||||||
|
let promiseList = [];
|
||||||
|
|
||||||
|
for (let key of keyList) {
|
||||||
|
let bean = await R.findOne("setting", " `key` = ? ", [
|
||||||
|
key
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (bean == null) {
|
||||||
|
bean = R.dispense("setting");
|
||||||
|
bean.type = type;
|
||||||
|
bean.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bean.type === type) {
|
||||||
|
bean.value = JSON.stringify(data[key]);
|
||||||
|
promiseList.push(R.store(bean));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promiseList);
|
||||||
|
|
||||||
|
Settings.deleteCache(keyList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string[]} keyList
|
||||||
|
*/
|
||||||
|
static deleteCache(keyList) {
|
||||||
|
for (let key of keyList) {
|
||||||
|
delete Settings.cacheList[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Settings,
|
||||||
|
};
|
@@ -1,19 +1,33 @@
|
|||||||
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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change running state
|
||||||
|
* @param {string} running Is it running?
|
||||||
|
* @param {string} message Message to pass
|
||||||
|
*/
|
||||||
cloudflared.change = (running, message) => {
|
cloudflared.change = (running, message) => {
|
||||||
io.to("cloudflared").emit(prefix + "running", running);
|
io.to("cloudflared").emit(prefix + "running", running);
|
||||||
io.to("cloudflared").emit(prefix + "message", message);
|
io.to("cloudflared").emit(prefix + "message", message);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit an error message
|
||||||
|
* @param {string} errorMessage
|
||||||
|
*/
|
||||||
cloudflared.error = (errorMessage) => {
|
cloudflared.error = (errorMessage) => {
|
||||||
io.to("cloudflared").emit(prefix + "errorMessage", errorMessage);
|
io.to("cloudflared").emit(prefix + "errorMessage", errorMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for cloudflared
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
module.exports.cloudflaredSocketHandler = (socket) => {
|
module.exports.cloudflaredSocketHandler = (socket) => {
|
||||||
|
|
||||||
socket.on(prefix + "join", async () => {
|
socket.on(prefix + "join", async () => {
|
||||||
@@ -49,7 +63,10 @@ module.exports.cloudflaredSocketHandler = (socket) => {
|
|||||||
socket.on(prefix + "stop", async (currentPassword, callback) => {
|
socket.on(prefix + "stop", async (currentPassword, callback) => {
|
||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
await doubleCheckPassword(socket, currentPassword);
|
const disabledAuth = await setting("disableAuth");
|
||||||
|
if (!disabledAuth) {
|
||||||
|
await doubleCheckPassword(socket, currentPassword);
|
||||||
|
}
|
||||||
cloudflared.stop();
|
cloudflared.stop();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
callback({
|
callback({
|
||||||
@@ -68,6 +85,10 @@ module.exports.cloudflaredSocketHandler = (socket) => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically start cloudflared
|
||||||
|
* @param {string} token Cloudflared tunnel token
|
||||||
|
*/
|
||||||
module.exports.autoStart = async (token) => {
|
module.exports.autoStart = async (token) => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
token = await setting("cloudflaredTunnelToken");
|
token = await setting("cloudflaredTunnelToken");
|
||||||
@@ -84,7 +105,10 @@ module.exports.autoStart = async (token) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Stop cloudflared */
|
||||||
module.exports.stop = async () => {
|
module.exports.stop = async () => {
|
||||||
console.log("Stop cloudflared");
|
console.log("Stop cloudflared");
|
||||||
cloudflared.stop();
|
if (cloudflared) {
|
||||||
|
cloudflared.stop();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
const { checkLogin } = require("../util-server");
|
const { checkLogin } = require("../util-server");
|
||||||
const Database = require("../database");
|
const Database = require("../database");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handlers for database
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
module.exports = (socket) => {
|
module.exports = (socket) => {
|
||||||
|
|
||||||
// Post or edit incident
|
// Post or edit incident
|
||||||
|
79
server/socket-handlers/docker-socket-handler.js
Normal file
79
server/socket-handlers/docker-socket-handler.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
const { sendDockerHostList } = require("../client");
|
||||||
|
const { checkLogin } = require("../util-server");
|
||||||
|
const { DockerHost } = require("../docker");
|
||||||
|
const { log } = require("../../src/util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handlers for docker hosts
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
|
module.exports.dockerSocketHandler = (socket) => {
|
||||||
|
socket.on("addDockerHost", async (dockerHost, dockerHostID, callback) => {
|
||||||
|
try {
|
||||||
|
checkLogin(socket);
|
||||||
|
|
||||||
|
let dockerHostBean = await DockerHost.save(dockerHost, dockerHostID, socket.userID);
|
||||||
|
await sendDockerHostList(socket);
|
||||||
|
|
||||||
|
callback({
|
||||||
|
ok: true,
|
||||||
|
msg: "Saved",
|
||||||
|
id: dockerHostBean.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
callback({
|
||||||
|
ok: false,
|
||||||
|
msg: e.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("deleteDockerHost", async (dockerHostID, callback) => {
|
||||||
|
try {
|
||||||
|
checkLogin(socket);
|
||||||
|
|
||||||
|
await DockerHost.delete(dockerHostID, socket.userID);
|
||||||
|
await sendDockerHostList(socket);
|
||||||
|
|
||||||
|
callback({
|
||||||
|
ok: true,
|
||||||
|
msg: "Deleted",
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
callback({
|
||||||
|
ok: false,
|
||||||
|
msg: e.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("testDockerHost", async (dockerHost, callback) => {
|
||||||
|
try {
|
||||||
|
checkLogin(socket);
|
||||||
|
|
||||||
|
let amount = await DockerHost.testDockerHost(dockerHost);
|
||||||
|
let msg;
|
||||||
|
|
||||||
|
if (amount >= 1) {
|
||||||
|
msg = "Connected Successfully. Amount of containers: " + amount;
|
||||||
|
} else {
|
||||||
|
msg = "Connected Successfully, but there are no containers?";
|
||||||
|
}
|
||||||
|
|
||||||
|
callback({
|
||||||
|
ok: true,
|
||||||
|
msg,
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
log.error("docker", e);
|
||||||
|
|
||||||
|
callback({
|
||||||
|
ok: false,
|
||||||
|
msg: e.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
@@ -1,8 +1,13 @@
|
|||||||
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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handlers for proxy
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
module.exports.proxySocketHandler = (socket) => {
|
module.exports.proxySocketHandler = (socket) => {
|
||||||
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
socket.on("addProxy", async (proxy, proxyID, callback) => {
|
||||||
try {
|
try {
|
||||||
|
@@ -6,8 +6,12 @@ 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");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Socket handlers for status page
|
||||||
|
* @param {Socket} socket Socket.io instance to add listeners on
|
||||||
|
*/
|
||||||
module.exports.statusPageSocketHandler = (socket) => {
|
module.exports.statusPageSocketHandler = (socket) => {
|
||||||
|
|
||||||
// Post or edit incident
|
// Post or edit incident
|
||||||
@@ -198,6 +202,11 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
relationBean.weight = monitorOrder++;
|
relationBean.weight = monitorOrder++;
|
||||||
relationBean.group_id = groupBean.id;
|
relationBean.group_id = groupBean.id;
|
||||||
relationBean.monitor_id = monitor.id;
|
relationBean.monitor_id = monitor.id;
|
||||||
|
|
||||||
|
if (monitor.sendUrl !== undefined) {
|
||||||
|
relationBean.send_url = monitor.sendUrl;
|
||||||
|
}
|
||||||
|
|
||||||
await R.store(relationBean);
|
await R.store(relationBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +224,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;
|
||||||
@@ -284,6 +295,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);
|
||||||
|
|
||||||
@@ -334,6 +347,7 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
/**
|
/**
|
||||||
* Check slug a-z, 0-9, - only
|
* Check slug a-z, 0-9, - only
|
||||||
* Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
|
* Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
|
||||||
|
* @param {string} slug Slug to test
|
||||||
*/
|
*/
|
||||||
function checkSlug(slug) {
|
function checkSlug(slug) {
|
||||||
if (typeof slug !== "string") {
|
if (typeof slug !== "string") {
|
||||||
|
154
server/uptime-kuma-server.js
Normal file
154
server/uptime-kuma-server.js
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
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");
|
||||||
|
const Database = require("./database");
|
||||||
|
const util = require("util");
|
||||||
|
const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent");
|
||||||
|
const { Settings } = require("./settings");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache Index HTML
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
indexHTML = "";
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||||
|
} catch (e) {
|
||||||
|
// "dist/index.html" is not necessary for development
|
||||||
|
if (process.env.NODE_ENV !== "development") {
|
||||||
|
log.error("server", "Error: Cannot find 'dist/index.html', did you install correctly?");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheableDnsHttpAgent.registerGlobalAgent();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write error to log file
|
||||||
|
* @param {any} error The error to write
|
||||||
|
* @param {boolean} outputToConsole Should the error also be output to console?
|
||||||
|
*/
|
||||||
|
static errorLog(error, outputToConsole = true) {
|
||||||
|
const errorLogStream = fs.createWriteStream(Database.dataDir + "/error.log", {
|
||||||
|
flags: "a"
|
||||||
|
});
|
||||||
|
|
||||||
|
errorLogStream.on("error", () => {
|
||||||
|
log.info("", "Cannot write to error.log");
|
||||||
|
});
|
||||||
|
|
||||||
|
if (errorLogStream) {
|
||||||
|
const dateTime = R.isoDateTime();
|
||||||
|
errorLogStream.write(`[${dateTime}] ` + util.format(error) + "\n");
|
||||||
|
|
||||||
|
if (outputToConsole) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errorLogStream.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getClientIP(socket) {
|
||||||
|
let clientIP = socket.client.conn.remoteAddress;
|
||||||
|
|
||||||
|
if (clientIP === undefined) {
|
||||||
|
clientIP = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await Settings.get("trustProxy")) {
|
||||||
|
const forwardedFor = socket.client.conn.request.headers["x-forwarded-for"];
|
||||||
|
|
||||||
|
return (typeof forwardedFor === "string" ? forwardedFor.split(",")[0].trim() : null)
|
||||||
|
|| socket.client.conn.request.headers["x-real-ip"]
|
||||||
|
|| clientIP.replace(/^.*:/, "");
|
||||||
|
} else {
|
||||||
|
return clientIP.replace(/^.*:/, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
UptimeKumaServer
|
||||||
|
};
|
@@ -7,9 +7,20 @@ const { Resolver } = require("dns");
|
|||||||
const childProcess = 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 nodeJsUtil = require("util");
|
|
||||||
const mqtt = require("mqtt");
|
const mqtt = require("mqtt");
|
||||||
|
const chroma = require("chroma-js");
|
||||||
|
const { badgeConstants } = require("./config");
|
||||||
|
const mssql = require("mssql");
|
||||||
|
const { Client } = require("pg");
|
||||||
|
const postgresConParse = require("pg-connection-string").parse;
|
||||||
|
const { NtlmClient } = require("axios-ntlm");
|
||||||
|
const { Settings } = require("./settings");
|
||||||
|
const radiusClient = require("node-radius-client");
|
||||||
|
const {
|
||||||
|
dictionaries: {
|
||||||
|
rfc2865: { file, attributes },
|
||||||
|
},
|
||||||
|
} = require("node-radius-utils");
|
||||||
|
|
||||||
// From ping-lite
|
// From ping-lite
|
||||||
exports.WIN = /^win/.test(process.platform);
|
exports.WIN = /^win/.test(process.platform);
|
||||||
@@ -37,6 +48,12 @@ exports.initJWTSecret = async () => {
|
|||||||
return jwtSecretBean;
|
return jwtSecretBean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send TCP request to specified hostname and port
|
||||||
|
* @param {string} hostname Hostname / address of machine
|
||||||
|
* @param {number} port TCP port to test
|
||||||
|
* @returns {Promise<number>} Maximum time in ms rounded to nearest integer
|
||||||
|
*/
|
||||||
exports.tcping = function (hostname, port) {
|
exports.tcping = function (hostname, port) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
tcpp.ping({
|
tcpp.ping({
|
||||||
@@ -58,6 +75,11 @@ exports.tcping = function (hostname, port) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ping the specified machine
|
||||||
|
* @param {string} hostname Hostname / address of machine
|
||||||
|
* @returns {Promise<number>} Time for ping in ms rounded to nearest integer
|
||||||
|
*/
|
||||||
exports.ping = async (hostname) => {
|
exports.ping = async (hostname) => {
|
||||||
try {
|
try {
|
||||||
return await exports.pingAsync(hostname);
|
return await exports.pingAsync(hostname);
|
||||||
@@ -71,6 +93,12 @@ exports.ping = async (hostname) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ping the specified machine
|
||||||
|
* @param {string} hostname Hostname / address of machine to ping
|
||||||
|
* @param {boolean} ipv6 Should IPv6 be used?
|
||||||
|
* @returns {Promise<number>} Time for ping in ms rounded to nearest integer
|
||||||
|
*/
|
||||||
exports.pingAsync = function (hostname, ipv6 = false) {
|
exports.pingAsync = function (hostname, ipv6 = false) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const ping = new Ping(hostname, {
|
const ping = new Ping(hostname, {
|
||||||
@@ -89,6 +117,15 @@ exports.pingAsync = function (hostname, ipv6 = false) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT Monitor
|
||||||
|
* @param {string} hostname Hostname / address of machine to test
|
||||||
|
* @param {string} topic MQTT topic
|
||||||
|
* @param {string} okMessage Expected result
|
||||||
|
* @param {Object} [options={}] MQTT options. Contains port, username,
|
||||||
|
* password and interval (interval defaults to 20)
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const { port, username, password, interval = 20 } = options;
|
const { port, username, password, interval = 20 } = options;
|
||||||
@@ -132,13 +169,13 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on("message", (messageTopic, message) => {
|
client.on("message", (messageTopic, message) => {
|
||||||
if (messageTopic == topic) {
|
if (messageTopic === topic) {
|
||||||
client.end();
|
client.end();
|
||||||
clearTimeout(timeoutID);
|
clearTimeout(timeoutID);
|
||||||
if (message.toString() === okMessage) {
|
if (okMessage != null && okMessage !== "" && message.toString() !== okMessage) {
|
||||||
resolve(`Topic: ${messageTopic}; Message: ${message.toString()}`);
|
reject(new Error(`Message Mismatch - Topic: ${messageTopic}; Message: ${message.toString()}`));
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(`Error; Topic: ${messageTopic}; Message: ${message.toString()}`));
|
resolve(`Topic: ${messageTopic}; Message: ${message.toString()}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -146,9 +183,40 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.dnsResolve = function (hostname, resolverServer, rrtype) {
|
/**
|
||||||
|
* Use NTLM Auth for a http request.
|
||||||
|
* @param {Object} options The http request options
|
||||||
|
* @param {Object} ntlmOptions The auth options
|
||||||
|
* @returns {Promise<(string[]|Object[]|Object)>}
|
||||||
|
*/
|
||||||
|
exports.httpNtlm = function (options, ntlmOptions) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let client = NtlmClient(ntlmOptions);
|
||||||
|
|
||||||
|
client(options)
|
||||||
|
.then((resp) => {
|
||||||
|
resolve(resp);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a given record using the specified DNS server
|
||||||
|
* @param {string} hostname The hostname of the record to lookup
|
||||||
|
* @param {string} resolverServer The DNS server to use
|
||||||
|
* @param {string} resolverPort Port the DNS server is listening on
|
||||||
|
* @param {string} rrtype The type of record to request
|
||||||
|
* @returns {Promise<(string[]|Object[]|Object)>}
|
||||||
|
*/
|
||||||
|
exports.dnsResolve = function (hostname, resolverServer, resolverPort, rrtype) {
|
||||||
const resolver = new Resolver();
|
const resolver = new Resolver();
|
||||||
resolver.setServers([ resolverServer ]);
|
// Remove brackets from IPv6 addresses so we can re-add them to
|
||||||
|
// prevent issues with ::1:5300 (::1 port 5300)
|
||||||
|
resolverServer = resolverServer.replace("[", "").replace("]", "");
|
||||||
|
resolver.setServers([ `[${resolverServer}]:${resolverPort}` ]);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (rrtype === "PTR") {
|
if (rrtype === "PTR") {
|
||||||
resolver.reverse(hostname, (err, records) => {
|
resolver.reverse(hostname, (err, records) => {
|
||||||
@@ -170,83 +238,141 @@ exports.dnsResolve = function (hostname, resolverServer, rrtype) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a query on SQL Server
|
||||||
|
* @param {string} connectionString The database connection string
|
||||||
|
* @param {string} query The query to validate the database with
|
||||||
|
* @returns {Promise<(string[]|Object[]|Object)>}
|
||||||
|
*/
|
||||||
|
exports.mssqlQuery = function (connectionString, query) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
mssql.connect(connectionString).then(pool => {
|
||||||
|
return pool.request()
|
||||||
|
.query(query);
|
||||||
|
}).then(result => {
|
||||||
|
resolve(result);
|
||||||
|
}).catch(err => {
|
||||||
|
reject(err);
|
||||||
|
}).finally(() => {
|
||||||
|
mssql.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a query on Postgres
|
||||||
|
* @param {string} connectionString The database connection string
|
||||||
|
* @param {string} query The query to validate the database with
|
||||||
|
* @returns {Promise<(string[]|Object[]|Object)>}
|
||||||
|
*/
|
||||||
|
exports.postgresQuery = function (connectionString, query) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const config = postgresConParse(connectionString);
|
||||||
|
|
||||||
|
if (config.password === "") {
|
||||||
|
// See https://github.com/brianc/node-postgres/issues/1927
|
||||||
|
return reject(new Error("Password is undefined."));
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new Client({ connectionString });
|
||||||
|
|
||||||
|
client.connect();
|
||||||
|
|
||||||
|
return client.query(query)
|
||||||
|
.then(res => {
|
||||||
|
resolve(res);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
client.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.radius = function (
|
||||||
|
hostname,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
calledStationId,
|
||||||
|
callingStationId,
|
||||||
|
secret,
|
||||||
|
) {
|
||||||
|
const client = new radiusClient({
|
||||||
|
host: hostname,
|
||||||
|
dictionaries: [ file ],
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.accessRequest({
|
||||||
|
secret: secret,
|
||||||
|
attributes: [
|
||||||
|
[ attributes.USER_NAME, username ],
|
||||||
|
[ attributes.USER_PASSWORD, password ],
|
||||||
|
[ attributes.CALLING_STATION_ID, callingStationId ],
|
||||||
|
[ attributes.CALLED_STATION_ID, calledStationId ],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve value of setting based on key
|
||||||
|
* @param {string} key Key of setting to retrieve
|
||||||
|
* @returns {Promise<any>} Value
|
||||||
|
* @deprecated Use await Settings.get(key)
|
||||||
|
*/
|
||||||
exports.setting = async function (key) {
|
exports.setting = async function (key) {
|
||||||
let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [
|
return await Settings.get(key);
|
||||||
key,
|
|
||||||
]);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const v = JSON.parse(value);
|
|
||||||
log.debug("util", `Get Setting: ${key}: ${v}`);
|
|
||||||
return v;
|
|
||||||
} catch (e) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the specified setting to specifed value
|
||||||
|
* @param {string} key Key of setting to set
|
||||||
|
* @param {any} value Value to set to
|
||||||
|
* @param {?string} type Type of setting
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
exports.setSetting = async function (key, value, type = null) {
|
exports.setSetting = async function (key, value, type = null) {
|
||||||
let bean = await R.findOne("setting", " `key` = ? ", [
|
await Settings.set(key, value, type);
|
||||||
key,
|
|
||||||
]);
|
|
||||||
if (!bean) {
|
|
||||||
bean = R.dispense("setting");
|
|
||||||
bean.key = key;
|
|
||||||
}
|
|
||||||
bean.type = type;
|
|
||||||
bean.value = JSON.stringify(value);
|
|
||||||
await R.store(bean);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get settings based on type
|
||||||
|
* @param {string} type The type of setting
|
||||||
|
* @returns {Promise<Bean>}
|
||||||
|
*/
|
||||||
exports.getSettings = async function (type) {
|
exports.getSettings = async function (type) {
|
||||||
let list = await R.getAll("SELECT `key`, `value` FROM setting WHERE `type` = ? ", [
|
return await Settings.getSettings(type);
|
||||||
type,
|
|
||||||
]);
|
|
||||||
|
|
||||||
let result = {};
|
|
||||||
|
|
||||||
for (let row of list) {
|
|
||||||
try {
|
|
||||||
result[row.key] = JSON.parse(row.value);
|
|
||||||
} catch (e) {
|
|
||||||
result[row.key] = row.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set settings based on type
|
||||||
|
* @param {string} type Type of settings to set
|
||||||
|
* @param {Object} data Values of settings
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
exports.setSettings = async function (type, data) {
|
exports.setSettings = async function (type, data) {
|
||||||
let keyList = Object.keys(data);
|
await Settings.setSettings(type, data);
|
||||||
|
|
||||||
let promiseList = [];
|
|
||||||
|
|
||||||
for (let key of keyList) {
|
|
||||||
let bean = await R.findOne("setting", " `key` = ? ", [
|
|
||||||
key
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (bean == null) {
|
|
||||||
bean = R.dispense("setting");
|
|
||||||
bean.type = type;
|
|
||||||
bean.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bean.type === type) {
|
|
||||||
bean.value = JSON.stringify(data[key]);
|
|
||||||
promiseList.push(R.store(bean));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(promiseList);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ssl-checker by @dyaa
|
// ssl-checker by @dyaa
|
||||||
// param: res - response object from axios
|
//https://github.com/dyaa/ssl-checker/blob/master/src/index.ts
|
||||||
// return an object containing the certificate information
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of days between two dates
|
||||||
|
* @param {Date} validFrom Start date
|
||||||
|
* @param {Date} validTo End date
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
const getDaysBetween = (validFrom, validTo) =>
|
const getDaysBetween = (validFrom, validTo) =>
|
||||||
Math.round(Math.abs(+validFrom - +validTo) / 8.64e7);
|
Math.round(Math.abs(+validFrom - +validTo) / 8.64e7);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get days remaining from a time range
|
||||||
|
* @param {Date} validFrom Start date
|
||||||
|
* @param {Date} validTo End date
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
const getDaysRemaining = (validFrom, validTo) => {
|
const getDaysRemaining = (validFrom, validTo) => {
|
||||||
const daysRemaining = getDaysBetween(validFrom, validTo);
|
const daysRemaining = getDaysBetween(validFrom, validTo);
|
||||||
if (new Date(validTo).getTime() < new Date().getTime()) {
|
if (new Date(validTo).getTime() < new Date().getTime()) {
|
||||||
@@ -255,8 +381,11 @@ const getDaysRemaining = (validFrom, validTo) => {
|
|||||||
return daysRemaining;
|
return daysRemaining;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fix certificate Info for display
|
/**
|
||||||
// param: info - the chain obtained from getPeerCertificate()
|
* Fix certificate info for display
|
||||||
|
* @param {Object} info The chain obtained from getPeerCertificate()
|
||||||
|
* @returns {Object} An object representing certificate information
|
||||||
|
*/
|
||||||
const parseCertificateInfo = function (info) {
|
const parseCertificateInfo = function (info) {
|
||||||
let link = info;
|
let link = info;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
@@ -296,6 +425,11 @@ const parseCertificateInfo = function (info) {
|
|||||||
return info;
|
return info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if certificate is valid
|
||||||
|
* @param {Object} res Response object from axios
|
||||||
|
* @returns {Object} Object containing certificate information
|
||||||
|
*/
|
||||||
exports.checkCertificate = function (res) {
|
exports.checkCertificate = function (res) {
|
||||||
const info = res.request.res.socket.getPeerCertificate(true);
|
const info = res.request.res.socket.getPeerCertificate(true);
|
||||||
const valid = res.request.res.socket.authorized || false;
|
const valid = res.request.res.socket.authorized || false;
|
||||||
@@ -309,12 +443,13 @@ exports.checkCertificate = function (res) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if the provided status code is within the accepted ranges
|
/**
|
||||||
// Param: status - the status code to check
|
* Check if the provided status code is within the accepted ranges
|
||||||
// Param: accepted_codes - an array of accepted status codes
|
* @param {number} status The status code to check
|
||||||
// Return: true if the status code is within the accepted ranges, false otherwise
|
* @param {string[]} acceptedCodes An array of accepted status codes
|
||||||
// Will throw an error if the provided status code is not a valid range string or code string
|
* @returns {boolean} True if status code within range, false otherwise
|
||||||
|
* @throws {Error} Will throw an error if the provided status code is not a valid range string or code string
|
||||||
|
*/
|
||||||
exports.checkStatusCode = function (status, acceptedCodes) {
|
exports.checkStatusCode = function (status, acceptedCodes) {
|
||||||
if (acceptedCodes == null || acceptedCodes.length === 0) {
|
if (acceptedCodes == null || acceptedCodes.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -338,6 +473,12 @@ exports.checkStatusCode = function (status, acceptedCodes) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get total number of clients in room
|
||||||
|
* @param {Server} io Socket server instance
|
||||||
|
* @param {string} roomName Name of room to check
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
exports.getTotalClientInRoom = (io, roomName) => {
|
exports.getTotalClientInRoom = (io, roomName) => {
|
||||||
|
|
||||||
const sockets = io.sockets;
|
const sockets = io.sockets;
|
||||||
@@ -361,17 +502,29 @@ exports.getTotalClientInRoom = (io, roomName) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow CORS all origins if development
|
||||||
|
* @param {Object} res Response object from axios
|
||||||
|
*/
|
||||||
exports.allowDevAllOrigin = (res) => {
|
exports.allowDevAllOrigin = (res) => {
|
||||||
if (process.env.NODE_ENV === "development") {
|
if (process.env.NODE_ENV === "development") {
|
||||||
exports.allowAllOrigin(res);
|
exports.allowAllOrigin(res);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow CORS all origins
|
||||||
|
* @param {Object} res Response object from axios
|
||||||
|
*/
|
||||||
exports.allowAllOrigin = (res) => {
|
exports.allowAllOrigin = (res) => {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user is logged in
|
||||||
|
* @param {Socket} socket Socket instance
|
||||||
|
*/
|
||||||
exports.checkLogin = (socket) => {
|
exports.checkLogin = (socket) => {
|
||||||
if (!socket.userID) {
|
if (!socket.userID) {
|
||||||
throw new Error("You are not logged in.");
|
throw new Error("You are not logged in.");
|
||||||
@@ -380,8 +533,8 @@ exports.checkLogin = (socket) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* For logged-in users, double-check the password
|
* For logged-in users, double-check the password
|
||||||
* @param socket
|
* @param {Socket} socket Socket.io instance
|
||||||
* @param currentPassword
|
* @param {string} currentPassword
|
||||||
* @returns {Promise<Bean>}
|
* @returns {Promise<Bean>}
|
||||||
*/
|
*/
|
||||||
exports.doubleCheckPassword = async (socket, currentPassword) => {
|
exports.doubleCheckPassword = async (socket, currentPassword) => {
|
||||||
@@ -400,10 +553,31 @@ exports.doubleCheckPassword = async (socket, currentPassword) => {
|
|||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Start Unit tests */
|
||||||
exports.startUnitTest = async () => {
|
exports.startUnitTest = async () => {
|
||||||
console.log("Starting unit test...");
|
console.log("Starting unit test...");
|
||||||
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm";
|
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm";
|
||||||
const child = childProcess.spawn(npm, [ "run", "jest" ]);
|
const child = childProcess.spawn(npm, [ "run", "jest-backend" ]);
|
||||||
|
|
||||||
|
child.stdout.on("data", (data) => {
|
||||||
|
console.log(data.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
child.stderr.on("data", (data) => {
|
||||||
|
console.log(data.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on("close", function (code) {
|
||||||
|
console.log("Jest exit code: " + code);
|
||||||
|
process.exit(code);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Start end-to-end tests */
|
||||||
|
exports.startE2eTests = async () => {
|
||||||
|
console.log("Starting unit test...");
|
||||||
|
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm";
|
||||||
|
const child = childProcess.spawn(npm, [ "run", "cy:run" ]);
|
||||||
|
|
||||||
child.stdout.on("data", (data) => {
|
child.stdout.on("data", (data) => {
|
||||||
console.log(data.toString());
|
console.log(data.toString());
|
||||||
@@ -420,7 +594,8 @@ exports.startUnitTest = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param body : Buffer
|
* Convert unknown string to UTF8
|
||||||
|
* @param {Uint8Array} body Buffer
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
exports.convertToUTF8 = (body) => {
|
exports.convertToUTF8 = (body) => {
|
||||||
@@ -429,23 +604,44 @@ exports.convertToUTF8 = (body) => {
|
|||||||
return str.toString();
|
return str.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
let logFile;
|
/**
|
||||||
|
* Returns a color code in hex format based on a given percentage:
|
||||||
try {
|
* 0% => hue = 10 => red
|
||||||
logFile = fs.createWriteStream("./data/error.log", {
|
* 100% => hue = 90 => green
|
||||||
flags: "a"
|
*
|
||||||
});
|
* @param {number} percentage float, 0 to 1
|
||||||
} catch (_) { }
|
* @param {number} maxHue
|
||||||
|
* @param {number} minHue, int
|
||||||
exports.errorLog = (error, outputToConsole = true) => {
|
* @returns {string}, hex value
|
||||||
|
*/
|
||||||
|
exports.percentageToColor = (percentage, maxHue = 90, minHue = 10) => {
|
||||||
|
const hue = percentage * (maxHue - minHue) + minHue;
|
||||||
try {
|
try {
|
||||||
if (logFile) {
|
return chroma(`hsl(${hue}, 90%, 40%)`).hex();
|
||||||
const dateTime = R.isoDateTime();
|
} catch (err) {
|
||||||
logFile.write(`[${dateTime}] ` + nodeJsUtil.format(error) + "\n");
|
return badgeConstants.naColor;
|
||||||
|
}
|
||||||
if (outputToConsole) {
|
};
|
||||||
console.error(error);
|
|
||||||
}
|
/**
|
||||||
}
|
* Joins and array of string to one string after filtering out empty values
|
||||||
} catch (_) { }
|
*
|
||||||
|
* @param {string[]} parts
|
||||||
|
* @param {string} connector
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.filterAndJoin = (parts, connector = "") => {
|
||||||
|
return parts.filter((part) => !!part && part !== "").join(connector);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a 403 response
|
||||||
|
* @param {Object} res Express response object
|
||||||
|
* @param {string} [msg=""] Message to send
|
||||||
|
*/
|
||||||
|
module.exports.send403 = (res, msg = "") => {
|
||||||
|
res.status(403).json({
|
||||||
|
"status": "fail",
|
||||||
|
"msg": msg,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@@ -34,6 +34,25 @@ textarea.form-control {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// optgroup
|
||||||
|
optgroup {
|
||||||
|
color: #b1b1b1;
|
||||||
|
option {
|
||||||
|
color: #212529;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
optgroup {
|
||||||
|
color: #535864;
|
||||||
|
option {
|
||||||
|
color: $dark-font-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scrollbar
|
||||||
::-webkit-scrollbar-thumb {
|
::-webkit-scrollbar-thumb {
|
||||||
background: #ccc;
|
background: #ccc;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
@@ -364,6 +383,12 @@ textarea.form-control {
|
|||||||
height: calc(100% - 65px);
|
height: calc(100% - 65px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 770px) {
|
||||||
|
&.scrollbar {
|
||||||
|
height: calc(100% - 40px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.item {
|
.item {
|
||||||
display: block;
|
display: block;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
@@ -378,7 +403,6 @@ textarea.form-control {
|
|||||||
.info {
|
.info {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
@@ -473,6 +497,14 @@ textarea.form-control {
|
|||||||
outline: none !important;
|
outline: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h5.settings-subheading::after {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
width: 50%;
|
||||||
|
padding-top: 8px;
|
||||||
|
border-bottom: 1px solid $dark-border-color;
|
||||||
|
}
|
||||||
|
|
||||||
// Localization
|
// Localization
|
||||||
|
|
||||||
@import "localization.scss";
|
@import "localization.scss";
|
||||||
|
86
src/components/ActionInput.vue
Normal file
86
src/components/ActionInput.vue
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<template>
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<input
|
||||||
|
ref="input"
|
||||||
|
v-model="model"
|
||||||
|
class="form-control"
|
||||||
|
:type="type"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="!enabled"
|
||||||
|
>
|
||||||
|
<a class="btn btn-outline-primary" @click="action()">
|
||||||
|
<font-awesome-icon :icon="icon" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Generic input field with a customizable action on the right.
|
||||||
|
* Action is passed in as a function.
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
/**
|
||||||
|
* The value of the input field.
|
||||||
|
*/
|
||||||
|
modelValue: {
|
||||||
|
type: String,
|
||||||
|
default: ""
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Whether the input field is enabled / disabled.
|
||||||
|
*/
|
||||||
|
enabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Placeholder text for the input field.
|
||||||
|
*/
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: ""
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* The icon displayed in the right button of the input field.
|
||||||
|
* Accepts a Font Awesome icon string identifier.
|
||||||
|
* @example "plus"
|
||||||
|
*/
|
||||||
|
icon: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* The input type of the input field.
|
||||||
|
* @example "email"
|
||||||
|
*/
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: "text",
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* The action to be performed when the button is clicked.
|
||||||
|
* Action is passed in as a function.
|
||||||
|
*/
|
||||||
|
action: {
|
||||||
|
type: Function,
|
||||||
|
default: () => {},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: [ "update:modelValue" ],
|
||||||
|
computed: {
|
||||||
|
/**
|
||||||
|
* Send value update to parent on change.
|
||||||
|
*/
|
||||||
|
model: {
|
||||||
|
get() {
|
||||||
|
return this.modelValue;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
this.$emit("update:modelValue", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
@@ -25,10 +25,12 @@ export default {
|
|||||||
CertificateInfoRow,
|
CertificateInfoRow,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
/** Object representing certificate */
|
||||||
certInfo: {
|
certInfo: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
/** Is the TLS certificate valid? */
|
||||||
valid: {
|
valid: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: true,
|
required: true,
|
||||||
|
@@ -56,12 +56,19 @@ export default {
|
|||||||
Datetime,
|
Datetime,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
/** Object representing certificate */
|
||||||
cert: {
|
cert: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
/**
|
||||||
|
* Format the subject of the certificate
|
||||||
|
* @param {Object} subject Object representing the certificates
|
||||||
|
* subject
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
formatSubject(subject) {
|
formatSubject(subject) {
|
||||||
if (subject.O && subject.CN && subject.C) {
|
if (subject.O && subject.CN && subject.C) {
|
||||||
return `${subject.CN} - ${subject.O} (${subject.C})`;
|
return `${subject.CN} - ${subject.O} (${subject.C})`;
|
||||||
|
@@ -29,14 +29,17 @@ import { Modal } from "bootstrap";
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
/** Style of button */
|
||||||
btnStyle: {
|
btnStyle: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "btn-primary",
|
default: "btn-primary",
|
||||||
},
|
},
|
||||||
|
/** Text to use as yes */
|
||||||
yesText: {
|
yesText: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "Yes", // TODO: No idea what to translate this
|
default: "Yes", // TODO: No idea what to translate this
|
||||||
},
|
},
|
||||||
|
/** Text to use as no */
|
||||||
noText: {
|
noText: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "No",
|
default: "No",
|
||||||
@@ -50,9 +53,13 @@ export default {
|
|||||||
this.modal = new Modal(this.$refs.modal);
|
this.modal = new Modal(this.$refs.modal);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
/** Show the confirm dialog */
|
||||||
show() {
|
show() {
|
||||||
this.modal.show();
|
this.modal.show();
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* @emits string "yes" Notify the parent when Yes is pressed
|
||||||
|
*/
|
||||||
yes() {
|
yes() {
|
||||||
this.$emit("yes");
|
this.$emit("yes");
|
||||||
},
|
},
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user