mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 04:59:25 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1a8c5c02f | ||
|
|
3ed0ceed70 | ||
|
|
6948d503c0 | ||
|
|
39bca95e62 | ||
|
|
063bc092e6 | ||
|
|
aa97982f6f | ||
|
|
af73ce7af8 | ||
|
|
e46ed828d9 | ||
|
|
f5ec3bba3d | ||
|
|
2f7ec60e89 | ||
|
|
5df4b9ee57 | ||
|
|
71dbfbf5d8 | ||
|
|
93fcdd2e27 | ||
|
|
a725220577 | ||
|
|
783c4ebc60 | ||
|
|
a06db0e8c3 | ||
|
|
d7c4dcda66 | ||
|
|
2866e1a602 | ||
|
|
77e4ee1053 | ||
|
|
7589c14f81 | ||
|
|
4344d774c1 | ||
|
|
4859792096 | ||
|
|
e55c40e973 | ||
|
|
103beb62a4 | ||
|
|
76a34578ad | ||
|
|
f82fdbf939 | ||
|
|
4eaf9eb36c | ||
|
|
9c9f9fc42c | ||
|
|
8301ad6f62 | ||
|
|
d42fb48749 | ||
|
|
fa49a3dbeb | ||
|
|
dd1147c891 | ||
|
|
67b015a50b | ||
|
|
57831168a3 | ||
|
|
f6f7cabddc | ||
|
|
dfec241c3f | ||
|
|
8a78dff571 | ||
|
|
a9486d4fbe | ||
|
|
78d3a091cd | ||
|
|
314005e478 | ||
|
|
55fa911485 | ||
|
|
a72046462c | ||
|
|
0b8fe15b65 | ||
|
|
34f5d12ad9 | ||
|
|
e88544d290 | ||
|
|
a211746de7 | ||
|
|
c417b02844 | ||
|
|
034aaedf48 | ||
|
|
af0ec79072 | ||
|
|
195ccf409e | ||
|
|
7cec26b8a3 | ||
|
|
aacb816b11 | ||
|
|
411798f4bf | ||
|
|
2179db5f8b | ||
|
|
dcced8c0fb | ||
|
|
3e0e42d8a1 | ||
|
|
e5355d3e2f | ||
|
|
0a22e25611 | ||
|
|
5f7a3e5bf6 | ||
|
|
3518548c61 | ||
|
|
08c4b0845d | ||
|
|
8f5fae8e79 | ||
|
|
a151db1c30 | ||
|
|
628c69ed22 | ||
|
|
13bcbc0f3e | ||
|
|
c94838462c | ||
|
|
a147ef6962 | ||
|
|
4ccda15933 | ||
|
|
01074c743d | ||
|
|
0871fa1763 | ||
|
|
aade0ccd98 | ||
|
|
4aed2f91de | ||
|
|
d49dd9f2ac | ||
|
|
cff29194f4 | ||
|
|
ecbfb2500f | ||
|
|
9c43170d4b | ||
|
|
1239a2807f | ||
|
|
1c0a130b49 | ||
|
|
ffb1eb34e0 | ||
|
|
82874d1f7a | ||
|
|
4e05f29fcd | ||
|
|
d5f3b0d442 | ||
|
|
81eec04037 | ||
|
|
5a5dc43e17 | ||
|
|
b4eb2b3192 | ||
|
|
2d1c070e1b | ||
|
|
81364fdfa3 | ||
|
|
9d0d88d465 | ||
|
|
7e2eef8bbf | ||
|
|
8d1315e5be | ||
|
|
fe6a51540e | ||
|
|
6e35683505 | ||
|
|
713c0d1a3c | ||
|
|
8323e0ec73 | ||
|
|
6eae94658f | ||
|
|
07d173d2cf | ||
|
|
23f2b9efac | ||
|
|
9b2ab9276c | ||
|
|
7903e1a286 | ||
|
|
662e05511f | ||
|
|
1f8785acbc | ||
|
|
3eb87cf953 | ||
|
|
124b24885e | ||
|
|
2196983455 | ||
|
|
80a67c4f58 | ||
|
|
ff06f7ef91 | ||
|
|
b16506c8bc | ||
|
|
2d3801dcc0 | ||
|
|
9b83a2ef79 | ||
|
|
6aefa3b7dc | ||
|
|
566fabbf24 | ||
|
|
ea8aa5102b | ||
|
|
b8421d36ae | ||
|
|
24bd8daca0 | ||
|
|
d8047b43fa | ||
|
|
016dde04e7 | ||
|
|
df5d86a883 | ||
|
|
84077de5d1 | ||
|
|
04ed4b180a | ||
|
|
f980dba7ed | ||
|
|
f702f70f89 | ||
|
|
a8e6ee052c | ||
|
|
b3d0a36dcd | ||
|
|
96275303c6 | ||
|
|
0337a1bded | ||
|
|
8bd985fca9 | ||
|
|
b6ef8d1625 | ||
|
|
3dc695508f | ||
|
|
0c769b02e5 | ||
|
|
e289037598 | ||
|
|
63e6a95553 | ||
|
|
8e1d95bf82 | ||
|
|
24fe8b6f5f | ||
|
|
3d366ee774 | ||
|
|
0428956141 | ||
|
|
37747427be | ||
|
|
fb94fb8304 | ||
|
|
65d07d3934 | ||
|
|
5e6ffafeb5 | ||
|
|
572f231fae | ||
|
|
0328dd21e7 | ||
|
|
597d171733 | ||
|
|
745ab9dcd0 | ||
|
|
30323b031c | ||
|
|
f47e6a47df | ||
|
|
0eccebd9da | ||
|
|
0ad5e74fae | ||
|
|
2640ba97c5 | ||
|
|
e5f440ff02 | ||
|
|
7bc9c44ec1 | ||
|
|
9cd74db011 | ||
|
|
5da8e5a7f6 | ||
|
|
4da895b8df | ||
|
|
42eca14168 | ||
|
|
43a3dfd9bd | ||
|
|
794eba4186 | ||
|
|
a4f533acba | ||
|
|
adb3c5250c | ||
|
|
e4226fcdd4 | ||
|
|
d3e9353589 | ||
|
|
757284cdf1 | ||
|
|
58232e10ab | ||
|
|
fde211e026 | ||
|
|
c9a527e487 | ||
|
|
c501efdfac | ||
|
|
80c0bbed71 | ||
|
|
1fb3c30775 | ||
|
|
24ab203770 | ||
|
|
bd0242db2f | ||
|
|
42bf5edd1f | ||
|
|
7b2a011b6a | ||
|
|
76e01201a2 | ||
|
|
16e45cabfc | ||
|
|
c08542ff54 | ||
|
|
5beb76d0b7 | ||
|
|
f16a7e016e | ||
|
|
eb86ac3ee6 | ||
|
|
14c2606532 | ||
|
|
86b8939cb8 | ||
|
|
dd28c1ef56 | ||
|
|
6b24dfc21e | ||
|
|
dc06573125 | ||
|
|
df35e5a780 | ||
|
|
a678d851a0 | ||
|
|
6a706651e4 | ||
|
|
1acdfe4368 | ||
|
|
cae245efca | ||
|
|
238f1e76d8 | ||
|
|
f3a754d1ae | ||
|
|
21aab0573a | ||
|
|
011949ba85 | ||
|
|
f3e7dd1cc0 | ||
|
|
b49d2025eb | ||
|
|
556b0869f2 | ||
|
|
aad6deeb78 | ||
|
|
64601e42c1 | ||
|
|
6555d927ea | ||
|
|
444ff40570 | ||
|
|
7bdcd0ac2b | ||
|
|
6e6a41e6df | ||
|
|
feca2a6d33 | ||
|
|
5e382e7347 | ||
|
|
abc778fb52 | ||
|
|
6b42d35cd4 | ||
|
|
c74a2c9655 | ||
|
|
01543f951a | ||
|
|
d78a5d8f27 | ||
|
|
2a1d759cd2 | ||
|
|
43889f83f7 | ||
|
|
79a0a93959 | ||
|
|
735cf9b872 | ||
|
|
e7c318e560 | ||
|
|
78d03754f6 | ||
|
|
67cc1cac86 | ||
|
|
77ec90980a | ||
|
|
d07b2babfd | ||
|
|
4d9ee94038 | ||
|
|
61479d5db6 | ||
|
|
897c28034d | ||
|
|
b3fef4c104 | ||
|
|
48cec8ee47 | ||
|
|
7c369ef19f | ||
|
|
1411bb1639 | ||
|
|
be875d9d8c | ||
|
|
746dc7ee4d | ||
|
|
ea7ba7d461 | ||
|
|
48ed4156b5 | ||
|
|
ca73d0e280 | ||
|
|
8cef43d9a7 | ||
|
|
75445774a1 | ||
|
|
9b29f19b96 | ||
|
|
1e6655e7f9 | ||
|
|
363656e06c | ||
|
|
a1860bc4fc | ||
|
|
f8ce39bc74 | ||
|
|
969d02ef93 | ||
|
|
a54410df6e | ||
|
|
01e388ea45 | ||
|
|
ef75f22a86 | ||
|
|
97f6b232fd | ||
|
|
2506f5e940 | ||
|
|
dcb23ada41 | ||
|
|
35e1bf048c | ||
|
|
a9e24f8eaf | ||
|
|
2f4ac74f52 | ||
|
|
522122feb6 | ||
|
|
a3c677a926 | ||
|
|
fd1c52530e | ||
|
|
071c690583 | ||
|
|
67c9cd0277 | ||
|
|
61292868ad | ||
|
|
54b2a00b23 | ||
|
|
af6d377664 | ||
|
|
6d55e345b0 | ||
|
|
fab4e68d8d | ||
|
|
8864e91f21 | ||
|
|
f14ce1b66c | ||
|
|
48098efd56 | ||
|
|
04eba8e33f | ||
|
|
89cf7ffafc | ||
|
|
47544520e8 | ||
|
|
bc1fd9a8af | ||
|
|
27efc7ef6e | ||
|
|
47ead816c0 | ||
|
|
31d36182c3 | ||
|
|
c9a58c7ea5 | ||
|
|
a6e59ae37c | ||
|
|
328e1b0ff1 | ||
|
|
f76cc5ceb8 | ||
|
|
d6c74c3f7d | ||
|
|
4f932c36e7 | ||
|
|
0d02d0ebea | ||
|
|
9e207ad4d3 | ||
|
|
f6cfe29956 | ||
|
|
e439111761 | ||
|
|
e576d0b443 | ||
|
|
02e2c42225 | ||
|
|
45dec0a3d6 | ||
|
|
28e2abc829 | ||
|
|
d59c82b7c8 | ||
|
|
32b2158795 | ||
|
|
5a37305c73 | ||
|
|
c043963e8e | ||
|
|
40d755b44e | ||
|
|
00aa791205 | ||
|
|
431b3646af | ||
|
|
910aaa81de | ||
|
|
c4a844cadb | ||
|
|
a88a281175 | ||
|
|
f3f3b1c6bd | ||
|
|
4259ac51cb | ||
|
|
4db1357d3d | ||
|
|
15873e0824 | ||
|
|
dcdb07f76d | ||
|
|
8b70637479 | ||
|
|
c77085fea4 | ||
|
|
a265f3d0d5 | ||
|
|
7ea486cd1d | ||
|
|
0e31e87e28 | ||
|
|
8c621c892e | ||
|
|
32bcae603c | ||
|
|
98ec21446d | ||
|
|
0ee3682502 | ||
|
|
c609d1a012 | ||
|
|
27b1a78879 | ||
|
|
773de840a5 | ||
|
|
91d6ff3c54 | ||
|
|
03376bd42d | ||
|
|
036c5114c2 | ||
|
|
a772e70fde | ||
|
|
53055bbdef | ||
|
|
f81d598fcf | ||
|
|
3530e83bb9 | ||
|
|
1271b2f637 | ||
|
|
2dc6bc7753 | ||
|
|
e52d9e3ea3 | ||
|
|
d8a570e55e | ||
|
|
f4ceaf667b | ||
|
|
958ba16b85 | ||
|
|
73039777bb | ||
|
|
864e4c910c | ||
|
|
4da57405af | ||
|
|
dff638571a | ||
|
|
c7d9ec51cc | ||
|
|
501c575f73 | ||
|
|
0fd966ca65 | ||
|
|
172dde2794 | ||
|
|
78fdc80652 | ||
|
|
01b8c9b8ff | ||
|
|
b840086d4d | ||
|
|
4c73f13f2d | ||
|
|
f31c1aae96 | ||
|
|
5c24a831db | ||
|
|
91d07eebad | ||
|
|
3b51ef2434 | ||
|
|
31c5e42b09 | ||
|
|
b8b3a237ef | ||
|
|
5cb2aefbbc | ||
|
|
19173af3e2 | ||
|
|
3dc493108b | ||
|
|
55af62000b | ||
|
|
a1c8c48761 | ||
|
|
8c3ec0a103 | ||
|
|
5cbde31105 | ||
|
|
04dd94032e | ||
|
|
8a11195b0d | ||
|
|
1eb76baae7 | ||
|
|
2669d6f021 | ||
|
|
6f13a03a2c | ||
|
|
9c97e1c41c | ||
|
|
37245ca1e8 | ||
|
|
f706a8a2ea | ||
|
|
e6af6b2062 | ||
|
|
f5b056c965 | ||
|
|
8c768e8a04 | ||
|
|
1d6f4feccb | ||
|
|
49c32dc9c1 | ||
|
|
17a865c45d | ||
|
|
0090681ab2 | ||
|
|
4d3a6c27f7 | ||
|
|
abf39428fc | ||
|
|
ec11904959 | ||
|
|
d18f16a2b8 | ||
|
|
7fbe421b0c | ||
|
|
81c7929240 | ||
|
|
76c655872b | ||
|
|
7b09776392 | ||
|
|
0b28077e08 | ||
|
|
ccc00e8b5d | ||
|
|
202e04c62d | ||
|
|
01cd35305e | ||
|
|
2f0d7d1d07 | ||
|
|
714af23627 | ||
|
|
0a9eb721c6 | ||
|
|
5e71c20e2a | ||
|
|
3c24d9f9a9 | ||
|
|
78bdcb79c8 | ||
|
|
aaf3389460 | ||
|
|
9f2cb58812 | ||
|
|
c6099fb7ce | ||
|
|
3fb4d88c4a | ||
|
|
f90fec182c | ||
|
|
ba86217a1a | ||
|
|
9a7bcdc1c4 | ||
|
|
43b1f5ed86 | ||
|
|
68ca194c2d | ||
|
|
061eaabe79 | ||
|
|
420e830ed9 | ||
|
|
8e9cba6646 | ||
|
|
e0c183c1ac | ||
|
|
18c59da28d | ||
|
|
71f2d66966 | ||
|
|
abd6cdd738 | ||
|
|
dd7b1707c3 | ||
|
|
1282babb06 | ||
|
|
71770ec406 | ||
|
|
f36495f0fd | ||
|
|
1cc4813c52 | ||
|
|
2ae74d6199 | ||
|
|
92d83bb82d | ||
|
|
f14d55fcc6 | ||
|
|
062de09b3b | ||
|
|
5cbd53a667 | ||
|
|
cf645d1f20 | ||
|
|
5b8cf7bb0a | ||
|
|
f5161bca66 | ||
|
|
5934be02bd | ||
|
|
9e9f10b06f | ||
|
|
0fafeabcf0 | ||
|
|
f98e4db019 | ||
|
|
ec00e9d17e | ||
|
|
b236bd85c9 | ||
|
|
40a8620745 | ||
|
|
0307828a82 | ||
|
|
e7d2eddc20 | ||
|
|
8c41b4c3fa | ||
|
|
3ea67beea9 | ||
|
|
a346da07ad | ||
|
|
067ee597a7 | ||
|
|
aac7704208 | ||
|
|
3a10aa7809 | ||
|
|
1b4582574c | ||
|
|
51b8738cbc | ||
|
|
0dd3c1844e | ||
|
|
0dabfdacbd | ||
|
|
d0166f03bb | ||
|
|
b102d4dd1f | ||
|
|
576f553317 | ||
|
|
31a0903514 | ||
|
|
796c19b5dc | ||
|
|
b7902ae2d0 | ||
|
|
7deaf2822a | ||
|
|
7e78c2dac4 | ||
|
|
f341c80fbe | ||
|
|
b593cc4708 | ||
|
|
7a8c83ee90 | ||
|
|
8c410b272d | ||
|
|
ecacb44df8 | ||
|
|
dcfaa1a6c9 | ||
|
|
c51e50f815 | ||
|
|
84b0fbc8ef | ||
|
|
4d83c44a73 | ||
|
|
4d82835658 | ||
|
|
cf863662e0 | ||
|
|
4a66b76963 | ||
|
|
0da43b6ccb | ||
|
|
c2ad19a4de | ||
|
|
db6538b57c | ||
|
|
535f6ddc77 | ||
|
|
aa3950ccfe | ||
|
|
8a81f8bb83 | ||
|
|
55d987c0bd | ||
|
|
416e9e7cda | ||
|
|
eedaef7eec | ||
|
|
3265deed3d | ||
|
|
1c7db0e2ec | ||
|
|
7872891797 | ||
|
|
8b074090a7 | ||
|
|
50f198e2d3 | ||
|
|
07e017c9a7 | ||
|
|
ca0aed7240 | ||
|
|
0126bcb68c | ||
|
|
7c37df5dec | ||
|
|
33bc6e19e7 | ||
|
|
35d42a5603 | ||
|
|
8a79beab89 | ||
|
|
cafff1d522 | ||
|
|
e266d85c91 | ||
|
|
e873ea8639 | ||
|
|
0cdc23a096 | ||
|
|
2c0231155d | ||
|
|
5583db0c70 | ||
|
|
2eeef4d8bd | ||
|
|
5a93b07968 | ||
|
|
b5195ba685 | ||
|
|
4c05747942 | ||
|
|
3722f57347 | ||
|
|
b7a3c32d3f | ||
|
|
6c0cb42e35 | ||
|
|
a84e7a16a3 | ||
|
|
fab1cb1bbe | ||
|
|
b46d7c1dee | ||
|
|
8f4dda2d65 | ||
|
|
e21d17e342 | ||
|
|
87eab46ed6 | ||
|
|
e0ebed3080 | ||
|
|
372dbc8995 | ||
|
|
33faf1e54c | ||
|
|
47f67275d5 | ||
|
|
e45ebc5f11 | ||
|
|
9ee570e3bb | ||
|
|
cc80ec7839 | ||
|
|
e7174a2111 | ||
|
|
ef6adfd82d | ||
|
|
daf6c9bff8 | ||
|
|
9f02092788 | ||
|
|
b314ebeed3 | ||
|
|
38f8fe9a38 | ||
|
|
c0e1512195 | ||
|
|
b616854baa | ||
|
|
1ad9546ae4 | ||
|
|
fb3aac37ec | ||
|
|
598f964e91 | ||
|
|
d9e46f1065 | ||
|
|
565d011191 | ||
|
|
6ae6e5fafc | ||
|
|
eb1c0efda1 | ||
|
|
98bc816b21 | ||
|
|
85735287c3 | ||
|
|
d59022ae44 | ||
|
|
70a17af9d8 | ||
|
|
09feeb11d2 | ||
|
|
d95e1e68c4 | ||
|
|
6e484babe9 | ||
|
|
d37ff296f6 | ||
|
|
f95d25f080 | ||
|
|
fd35db3dd8 | ||
|
|
f22e10a496 | ||
|
|
52f80ec3b7 | ||
|
|
41fd11c0f4 | ||
|
|
f8a5e7dab5 | ||
|
|
4b71d6b3d7 | ||
|
|
becb7f8c7f | ||
|
|
3da7b57242 | ||
|
|
42e8057356 | ||
|
|
e082baabe8 | ||
|
|
74d565c99a | ||
|
|
750efbf430 | ||
|
|
68112ba978 | ||
|
|
e994375fc8 | ||
|
|
998f677ee7 | ||
|
|
8b1b50938d | ||
|
|
3dbece0b5e | ||
|
|
e9f1e522de | ||
|
|
8a815159c1 | ||
|
|
c8af676d6f | ||
|
|
3bee84a52f | ||
|
|
82828aacf6 | ||
|
|
e4de3cff61 | ||
|
|
4ed7f5d7fd | ||
|
|
7b956c73e4 | ||
|
|
8535dd2306 | ||
|
|
e13df3ae58 | ||
|
|
44fa68f52d | ||
|
|
d72abb1e30 | ||
|
|
aad4343a59 | ||
|
|
6b5717b04f | ||
|
|
655946a467 | ||
|
|
80f3d98162 | ||
|
|
d73be680e2 | ||
|
|
ad9595b3b2 | ||
|
|
8a337fcfd6 | ||
|
|
38b1dba395 | ||
|
|
7195de0418 | ||
|
|
20cb30ba51 | ||
|
|
2a7c96b0f5 | ||
|
|
8503e6ebe9 | ||
|
|
be2c2a2436 | ||
|
|
8a247c93d4 | ||
|
|
b4cdc7fc2d | ||
|
|
cc3f1ed01a | ||
|
|
4db4284362 | ||
|
|
3c2e517c61 | ||
|
|
1d712d1f84 | ||
|
|
f1e1e3c82c | ||
|
|
8e587cf055 | ||
|
|
277b95f74b | ||
|
|
b89b180ee9 | ||
|
|
3e89c35111 | ||
|
|
52f7939b06 | ||
|
|
13d038e855 | ||
|
|
325046d3c2 | ||
|
|
8cb3b578e0 | ||
|
|
3b5a5206fc | ||
|
|
1517d8d2d7 | ||
|
|
ba55477492 | ||
|
|
e363833437 | ||
|
|
6ec51baedb | ||
|
|
0fdf62499b | ||
|
|
1498e23b48 | ||
|
|
106ce839d8 | ||
|
|
eed561dadc | ||
|
|
c97ec1cbba | ||
|
|
29802d8066 | ||
|
|
9a51bc4b4e | ||
|
|
082f697706 | ||
|
|
6e026f2998 | ||
|
|
c647f0c02d | ||
|
|
da99297253 | ||
|
|
4ab982827e | ||
|
|
d3a4db511a | ||
|
|
fa9e4e3b06 | ||
|
|
e7cd941f0f | ||
|
|
c641606ecd | ||
|
|
021a360462 | ||
|
|
9104280ff1 | ||
|
|
0ea0f2d13d | ||
|
|
289e251480 | ||
|
|
ce421cfb89 | ||
|
|
bec41f2c63 | ||
|
|
3a34974ec9 | ||
|
|
a7c9fff283 | ||
|
|
c36cca61a1 | ||
|
|
42edf12d01 | ||
|
|
d6799e89c4 | ||
|
|
4b4006c9da | ||
|
|
33bb042b41 | ||
|
|
be2e91b9ce | ||
|
|
db424f8912 | ||
|
|
bfca2e313a | ||
|
|
1de51747e6 | ||
|
|
8a623b490b | ||
|
|
b5b8ef7e46 | ||
|
|
daa561b6c4 | ||
|
|
9bc30db1ad | ||
|
|
1a9d506d61 | ||
|
|
62b5d812e2 | ||
|
|
433c9ab5ea | ||
|
|
a7a6976204 |
@@ -0,0 +1,5 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: midoks
|
||||
|
||||
custom: https://afdian.net/a/mdserver-web
|
||||
@@ -5,9 +5,9 @@ name: MW APP MySQL55
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
@@ -5,9 +5,9 @@ name: MW APP MySQL56
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
@@ -5,9 +5,9 @@ name: MW APP MySQL57
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
@@ -5,9 +5,9 @@ name: MW APP MySQL80
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
@@ -5,9 +5,9 @@ name: MW APP PHP
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
branches: [ "run_test" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
+6
-2
@@ -122,12 +122,14 @@ data/datadir.pl
|
||||
data/502Task.pl
|
||||
data/default.pl
|
||||
data/backup.pl
|
||||
data/debug.pl
|
||||
data/default_site.pl
|
||||
lib/python*
|
||||
|
||||
bin
|
||||
pyvenv.cfg
|
||||
include
|
||||
share
|
||||
pip-selfcheck.json
|
||||
|
||||
scripts/mdserver-web
|
||||
@@ -140,16 +142,18 @@ data/restart.pl
|
||||
data/ssl.pl
|
||||
data/edate.pl
|
||||
data/osname.pl
|
||||
data/only_netio_counters.pl
|
||||
data/system.db-journal
|
||||
data/hook_*.json
|
||||
|
||||
plugins/l2tp
|
||||
plugins/openlitespeed
|
||||
plugins/gdrive
|
||||
plugins/mtproxy
|
||||
plugins/zimg
|
||||
plugins/bk_demo
|
||||
plugins/mail
|
||||
debug.out
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
### mdserver-web 0.9.5
|
||||
<p align="center">
|
||||
<img alt="logo" src="https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/route/static/logo.png" height="140" />
|
||||
<h3 align="center">mdserver-web</h3>
|
||||
<p align="center">一款简单Linux面板服务</p>
|
||||
</p>
|
||||
|
||||
### 简介
|
||||
|
||||
简单的Linux面板,感谢BT.CN写出如此好的web管理软件。我一看到,就知道这是我一直想要的页面化管理方式。
|
||||
复制了后台管理界面,按照自己想要的方式写了一版。
|
||||
@@ -59,8 +65,23 @@ phpMyAdmin[5.2.0]支持MySQL[8.0]
|
||||
|
||||
PHP[53-72]支持phpMyAdmin[4.4.15]
|
||||
PHP[72-81]支持phpMyAdmin[5.2.0]
|
||||
|
||||
|
||||
```
|
||||
|
||||
# 特别赞助
|
||||
|
||||
- [找资源 - 阿里云盘资源搜索引擎](https://zhaoziyuan.la/)
|
||||
|
||||
# AD - VPS推荐 - 🙏
|
||||
|
||||
- [ZZZ评测](https://www.zzzvps.com/)
|
||||
|
||||
| 服务商 | LOGO | 推广地址 | 优惠码 |
|
||||
| ------------- |----------|-----------|-------|
|
||||
| digitalvirt |[](https://digitalvirt.com/aff.php?aff=154) | https://digitalvirt.com/aff.php?aff=154 | 9SYDY7UH0U |
|
||||
| 搬瓦工 |[](https://bwh81.net/aff.php?aff=54161) | https://bwh81.net/aff.php?aff=54161 | BWH3HYATVBJW |
|
||||
|
||||
# Docker
|
||||
|
||||
- 由[DDSRem](https://github.com/DDSRem)开发维护。
|
||||
@@ -71,14 +92,12 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
|
||||
```
|
||||
|
||||
|
||||
### 版本更新 0.9.5
|
||||
|
||||
* 页面更新优化[2].
|
||||
* 修复maridb的用户管理[2].
|
||||
* Gogs初始化提示更人性.
|
||||
* MySQL&&MariaDB修改密码修复.
|
||||
* MySQL&&MariaDB导入修复.
|
||||
### 版本更新 0.10.2
|
||||
|
||||
* 修复上次更新的UI问题。
|
||||
* `FTP存储空间` 备份数据库修复。
|
||||
* 修复计划任务执行Python脚本的编码问题。
|
||||
* 添加,修改计划任务参数强校验。
|
||||
|
||||
### JSDelivr安装地址
|
||||
|
||||
@@ -94,6 +113,12 @@ curl -fsSL https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/instal
|
||||
curl -fsSL https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/update.sh | bash
|
||||
```
|
||||
|
||||
- 卸载脚本
|
||||
|
||||
```
|
||||
curl -fsSL https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/uninstall.sh | bash
|
||||
```
|
||||
|
||||
### 备用地址
|
||||
|
||||
- 初始安装
|
||||
@@ -109,6 +134,12 @@ curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh | bash
|
||||
```
|
||||
|
||||
- 卸载脚本
|
||||
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/uninstall.sh | bash
|
||||
```
|
||||
|
||||
|
||||
### 通用软件安装[命令行安装]
|
||||
|
||||
@@ -124,16 +155,25 @@ curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/qu
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/install_dev.sh | bash
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh | bash
|
||||
|
||||
|
||||
curl -fsSL https://gitee.com/midoks/mdserver-web/raw/master/scripts/install_dev.sh | bash
|
||||
curl -fsSL https://gitee.com/midoks/mdserver-web/raw/master/scripts/update_dev.sh | bash
|
||||
```
|
||||
|
||||
### 捐赠地址 USDT(TRC20)
|
||||
|
||||
TVbNgrpeGBGZVm5gTLa21ADP7RpnPFhjya
|
||||
|
||||
|
||||
### 微信赞助
|
||||
[](/route/static/img/weixin_zz.jpg)
|
||||
|
||||
[](https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/route/static/img/weixin_zz.jpg)
|
||||
|
||||
|
||||
### 无图不真相
|
||||
|
||||
[](/route/static/mdw.jpg)
|
||||
|
||||
[](https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/route/static/mdw.jpg)
|
||||
|
||||
|
||||
### Stargazers over time
|
||||
@@ -143,7 +183,7 @@ curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/up
|
||||
|
||||
### 感谢开发赞助
|
||||
|
||||
[](https://digitalvirt.com/)
|
||||
[](https://digitalvirt.com/aff.php?aff=154)
|
||||
|
||||
### 授权许可
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ def initInitD():
|
||||
mw.execShell('mkdir -p /etc/init.d')
|
||||
|
||||
# initd
|
||||
if os.path.exists("/etc/init.d"):
|
||||
if os.path.exists('/etc/init.d'):
|
||||
initd_bin = '/etc/init.d/mw'
|
||||
if not os.path.exists(initd_bin):
|
||||
import shutil
|
||||
|
||||
@@ -15,7 +15,7 @@ from flask import request
|
||||
|
||||
class config_api:
|
||||
|
||||
__version = '0.9.5'
|
||||
__version = '0.10.2'
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -207,6 +207,14 @@ class config_api:
|
||||
mw.execShell("chown root.root " + filename)
|
||||
return mw.returnJson(True, '面板已关闭!')
|
||||
|
||||
def openDebugApi(self):
|
||||
filename = 'data/debug.pl'
|
||||
if os.path.exists(filename):
|
||||
os.remove(filename)
|
||||
return mw.returnJson(True, '开发模式关闭!')
|
||||
mw.writeFile(filename, 'True')
|
||||
return mw.returnJson(True, '开发模式开启!')
|
||||
|
||||
def setIpv6StatusApi(self):
|
||||
ipv6_file = 'data/ipv6.pl'
|
||||
if os.path.exists('data/ipv6.pl'):
|
||||
@@ -316,11 +324,17 @@ class config_api:
|
||||
data['admin_path'] = mw.readFile(admin_path_file)
|
||||
|
||||
ipv6_file = 'data/ipv6.pl'
|
||||
if os.path.exists('data/ipv6.pl'):
|
||||
if os.path.exists(ipv6_file):
|
||||
data['ipv6'] = 'checked'
|
||||
else:
|
||||
data['ipv6'] = ''
|
||||
|
||||
debug_file = 'data/debug.pl'
|
||||
if os.path.exists(debug_file):
|
||||
data['debug'] = 'checked'
|
||||
else:
|
||||
data['debug'] = ''
|
||||
|
||||
ssl_file = 'data/ssl.pl'
|
||||
if os.path.exists('data/ssl.pl'):
|
||||
data['ssl'] = 'checked'
|
||||
|
||||
+105
-21
@@ -68,8 +68,8 @@ class crontab_api:
|
||||
_list[i]['where_hour']), str(_list[i]['where_minute'])))
|
||||
data.append(tmp)
|
||||
|
||||
_ret = {}
|
||||
_ret['data'] = data
|
||||
rdata = {}
|
||||
rdata['data'] = data
|
||||
|
||||
count = mw.M('crontab').where('', ()).count()
|
||||
_page = {}
|
||||
@@ -78,9 +78,17 @@ class crontab_api:
|
||||
_page['row'] = psize
|
||||
_page['tojs'] = "getCronData"
|
||||
|
||||
_ret['list'] = mw.getPage(_page)
|
||||
_ret['p'] = p
|
||||
return mw.getJson(_ret)
|
||||
rdata['list'] = mw.getPage(_page)
|
||||
rdata['p'] = p
|
||||
|
||||
# backup hock
|
||||
bh_file = mw.getPanelDataDir() + "/hook_backup.json"
|
||||
if os.path.exists(bh_file):
|
||||
hb_data = mw.readFile(bh_file)
|
||||
hb_data = json.loads(hb_data)
|
||||
rdata['backup_hook'] = hb_data
|
||||
|
||||
return mw.getJson(rdata)
|
||||
|
||||
# 设置计划任务状态
|
||||
def setCronStatusApi(self):
|
||||
@@ -107,6 +115,56 @@ class crontab_api:
|
||||
'id=?', (sid,)).field(self.field).find()
|
||||
return mw.getJson(data)
|
||||
|
||||
# 参数校验
|
||||
def cronCheck(self, params):
|
||||
|
||||
if params['stype'] == 'site' or params['stype'] == 'database' or params['stype'] == 'logs':
|
||||
if params['save'] == '':
|
||||
return False, '保留份数不能为空!'
|
||||
|
||||
if params['type'] == 'day':
|
||||
if params['hour'] == '':
|
||||
return False, '小时不能为空!'
|
||||
if params['minute'] == '':
|
||||
return False, '分钟不能为空!'
|
||||
|
||||
if params['type'] == 'day-n':
|
||||
if params['where1'] == '':
|
||||
return False, '天不能为空!'
|
||||
if params['hour'] == '':
|
||||
return False, '小时不能为空!'
|
||||
if params['minute'] == '':
|
||||
return False, '分钟不能为空!'
|
||||
if params['type'] == 'hour':
|
||||
if params['minute'] == '':
|
||||
return False, '分钟不能为空!'
|
||||
|
||||
if params['type'] == 'hour-n':
|
||||
if params['hour'] == '':
|
||||
return False, '小时不能为空!'
|
||||
if params['minute'] == '':
|
||||
return False, '分钟不能为空!'
|
||||
|
||||
if params['type'] == 'minute-n':
|
||||
if params['minute'] == '':
|
||||
return False, '分钟不能为空!'
|
||||
|
||||
if params['type'] == 'week':
|
||||
if params['hour'] == '':
|
||||
return False, '小时不能为空!'
|
||||
if params['minute'] == '':
|
||||
return False, '分钟不能为空!'
|
||||
|
||||
if params['type'] == 'month':
|
||||
if params['where1'] == '':
|
||||
return False, '日不能为空!'
|
||||
if params['hour'] == '':
|
||||
return False, '小时不能为空!'
|
||||
if params['minute'] == '':
|
||||
return False, '分钟不能为空!'
|
||||
|
||||
return True, 'OK'
|
||||
|
||||
def modifyCrondApi(self):
|
||||
sid = request.form.get('id', '')
|
||||
iname = request.form.get('name', '')
|
||||
@@ -139,6 +197,11 @@ class crontab_api:
|
||||
'sbody': sbody,
|
||||
'urladdress': urladdress,
|
||||
}
|
||||
|
||||
is_check_pass, msg = self.cronCheck(params)
|
||||
if not is_check_pass:
|
||||
return mw.returnJson(is_check_pass, msg)
|
||||
|
||||
cuonConfig, get, name = self.getCrondCycle(params)
|
||||
cronInfo = mw.M('crontab').where(
|
||||
'id=?', (sid,)).field(self.field).find()
|
||||
@@ -167,7 +230,7 @@ class crontab_api:
|
||||
logFile = mw.getServerDir() + '/cron/' + echo['echo'] + '.log'
|
||||
if not os.path.exists(logFile):
|
||||
return mw.returnJson(False, '当前日志为空!')
|
||||
log = mw.getNumLines(logFile, 500)
|
||||
log = mw.getLastLine(logFile, 500)
|
||||
return mw.returnJson(True, log)
|
||||
|
||||
def addApi(self):
|
||||
@@ -202,6 +265,10 @@ class crontab_api:
|
||||
'urladdress': urladdress,
|
||||
}
|
||||
|
||||
is_check_pass, msg = self.cronCheck(params)
|
||||
if not is_check_pass:
|
||||
return mw.returnJson(is_check_pass, msg)
|
||||
|
||||
addData = self.add(params)
|
||||
if addData > 0:
|
||||
return mw.returnJson(True, '添加成功')
|
||||
@@ -295,9 +362,18 @@ class crontab_api:
|
||||
# 取数据列表
|
||||
def getDataListApi(self):
|
||||
stype = request.form.get('type', '')
|
||||
|
||||
bak_data = []
|
||||
|
||||
if stype == 'sites' or stype == 'databases':
|
||||
hookPath = mw.getPanelDataDir() + "/hook_backup.json"
|
||||
if os.path.exists(hookPath):
|
||||
t = mw.readFile(hookPath)
|
||||
bak_data = json.loads(t)
|
||||
|
||||
if stype == 'databases':
|
||||
db_list = {}
|
||||
db_list['orderOpt'] = []
|
||||
db_list['orderOpt'] = bak_data
|
||||
path = mw.getServerDir() + '/mysql'
|
||||
if not os.path.exists(path + '/mysql.db'):
|
||||
db_list['data'] = []
|
||||
@@ -307,8 +383,9 @@ class crontab_api:
|
||||
return mw.getJson(db_list)
|
||||
|
||||
data = {}
|
||||
data['orderOpt'] = bak_data
|
||||
|
||||
data['data'] = mw.M(stype).field('name,ps').select()
|
||||
data['orderOpt'] = []
|
||||
return mw.getJson(data)
|
||||
##### ----- start ----- ###
|
||||
|
||||
@@ -399,28 +476,35 @@ class crontab_api:
|
||||
shell = param.sFile
|
||||
else:
|
||||
head = "#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n"
|
||||
|
||||
source_bin_activate = '''
|
||||
export LANG=en_US.UTF-8
|
||||
MW_PATH=%s/bin/activate
|
||||
if [ -f $MW_PATH ];then
|
||||
source $MW_PATH
|
||||
fi
|
||||
''' % (mw.getRunDir(),)
|
||||
|
||||
head = head + source_bin_activate + "\n"
|
||||
log = '.log'
|
||||
|
||||
script_dir = mw.getServerDir() + "/mdserver-web/scripts"
|
||||
|
||||
wheres = {
|
||||
'path': head + "python " + script_dir + "/backup.py path " + param['sname'] + " " + str(param['save']),
|
||||
'site': head + "python " + script_dir + "/backup.py site " + param['sname'] + " " + str(param['save']),
|
||||
'database': head + "python " + script_dir + "/backup.py database " + param['sname'] + " " + str(param['save']),
|
||||
'logs': head + "python " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
|
||||
'path': head + "python3 " + script_dir + "/backup.py path " + param['sname'] + " " + str(param['save']),
|
||||
'site': head + "python3 " + script_dir + "/backup.py site " + param['sname'] + " " + str(param['save']),
|
||||
'database': head + "python3 " + script_dir + "/backup.py database " + param['sname'] + " " + str(param['save']),
|
||||
'logs': head + "python3 " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
|
||||
'rememory': head + "/bin/bash " + script_dir + '/rememory.sh'
|
||||
}
|
||||
if param['backup_to'] != 'localhost':
|
||||
cfile = mw.getServerDir() + "/mdserver-web/plugin/" + \
|
||||
param['backup_to'] + "/" + param['backup_to'] + "_main.py"
|
||||
if not os.path.exists(cfile):
|
||||
cfile = script_dir + "/backup_" + \
|
||||
param['backup_to'] + ".py"
|
||||
cfile = mw.getPluginDir() + "/" + \
|
||||
param['backup_to'] + "/index.py"
|
||||
wheres = {
|
||||
'path': head + "python " + cfile + " path " + param['sname'] + " " + str(param['save']),
|
||||
'site': head + "python " + cfile + " site " + param['sname'] + " " + str(param['save']),
|
||||
'database': head + "python " + cfile + " database " + param['sname'] + " " + str(param['save']),
|
||||
'logs': head + "python " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
|
||||
'path': head + "python3 " + cfile + " path " + param['sname'] + " " + str(param['save']),
|
||||
'site': head + "python3 " + cfile + " site " + param['sname'] + " " + str(param['save']),
|
||||
'database': head + "python3 " + cfile + " database " + param['sname'] + " " + str(param['save']),
|
||||
'logs': head + "python3 " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
|
||||
'rememory': head + "/bin/bash " + script_dir + '/rememory.sh'
|
||||
}
|
||||
try:
|
||||
|
||||
@@ -36,7 +36,7 @@ class files_api:
|
||||
return mw.returnJson(False, '文件不存在', (path,))
|
||||
|
||||
try:
|
||||
data = mw.getNumLines(path, int(line))
|
||||
data = mw.getLastLine(path, int(line))
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
except Exception as ex:
|
||||
return mw.returnJson(False, u'无法正确读取文件!' + str(ex))
|
||||
@@ -676,8 +676,7 @@ class files_api:
|
||||
data['encoding'] = 'utf-8'
|
||||
if char['encoding'] == 'Big5':
|
||||
data['encoding'] = 'BIG5'
|
||||
if not char['encoding'] in ['GBK', 'utf-8',
|
||||
'BIG5']:
|
||||
if not char['encoding'] in ['GBK', 'utf-8', 'BIG5']:
|
||||
data['encoding'] = 'utf-8'
|
||||
try:
|
||||
if sys.version_info[0] == 2:
|
||||
@@ -759,8 +758,8 @@ class files_api:
|
||||
try:
|
||||
tmps = mw.getRunDir() + '/tmp/panelExec.log'
|
||||
if stype == 'zip':
|
||||
os.system("cd " + path + " && unzip -d '" + dfile +
|
||||
"' '" + sfile + "' > " + tmps + " 2>&1")
|
||||
os.system("cd " + path + " && unzip -o -d '" + dfile +
|
||||
"' '" + sfile + "' > " + tmps + " 2>&1 &")
|
||||
else:
|
||||
sfiles = ''
|
||||
for sfile in sfile.split(','):
|
||||
@@ -768,7 +767,7 @@ class files_api:
|
||||
continue
|
||||
sfiles += " '" + sfile + "'"
|
||||
os.system("cd " + path + " && tar -zxvf " + sfiles +
|
||||
" -C " + dfile + " > " + tmps + " 2>&1")
|
||||
" -C " + dfile + " > " + tmps + " 2>&1 &")
|
||||
self.setFileAccept(dfile)
|
||||
mw.writeLog("文件管理", '文件解压成功!', (sfile, dfile))
|
||||
return mw.returnJson(True, '文件解压成功!')
|
||||
|
||||
@@ -59,22 +59,30 @@ class firewall_api:
|
||||
|
||||
# 添加放行端口
|
||||
def addAcceptPortApi(self):
|
||||
|
||||
if not self.getFwStatus():
|
||||
return mw.returnJson(False, '防火墙启动时,才能添加规则!')
|
||||
|
||||
import re
|
||||
import time
|
||||
port = request.form.get('port', '').strip()
|
||||
ps = request.form.get('ps', '').strip()
|
||||
stype = request.form.get('type', '').strip()
|
||||
|
||||
data = self.addAcceptPortArgs(port, ps, stype)
|
||||
return mw.getJson(data)
|
||||
|
||||
# 添加放行端口
|
||||
def addAcceptPortArgs(self, port, ps, stype):
|
||||
import re
|
||||
import time
|
||||
|
||||
if not self.getFwStatus():
|
||||
self.setFw(0)
|
||||
|
||||
rep = "^\d{1,5}(:\d{1,5})?$"
|
||||
if not re.search(rep, port):
|
||||
return mw.returnJson(False, '端口范围不正确!')
|
||||
return mw.returnData(False, '端口范围不正确!')
|
||||
|
||||
if mw.M('firewall').where("port=?", (port,)).count() > 0:
|
||||
return mw.returnJson(False, '您要放行的端口已存在,无需重复放行!')
|
||||
return mw.returnData(False, '您要放行的端口已存在,无需重复放行!')
|
||||
|
||||
msg = mw.getInfo('放行端口[{1}]成功', (port,))
|
||||
mw.writeLog("防火墙管理", msg)
|
||||
@@ -83,7 +91,7 @@ class firewall_api:
|
||||
|
||||
self.addAcceptPort(port)
|
||||
self.firewallReload()
|
||||
return mw.returnJson(True, '添加放行(' + port + ')端口成功!')
|
||||
return mw.returnData(True, '添加放行(' + port + ')端口成功!')
|
||||
|
||||
# 删除IP屏蔽
|
||||
def delDropAddressApi(self):
|
||||
@@ -241,7 +249,7 @@ class firewall_api:
|
||||
self.firewallReload()
|
||||
# mw.M('firewall').where(
|
||||
# "ps=?", ('SSH远程管理服务',)).setField('port', port)
|
||||
msg = mw.getInfo('改SSH端口为[{1}]成功!', port)
|
||||
msg = "改SSH端口为[{}]成功!".format(port)
|
||||
mw.writeLog("防火墙管理", msg)
|
||||
return mw.returnJson(True, '修改成功!')
|
||||
|
||||
@@ -290,6 +298,9 @@ class firewall_api:
|
||||
return mw.returnJson(True, '开发机不能设置!')
|
||||
|
||||
status = request.form.get('status', '1')
|
||||
return mw.getJson(self.setFw(status))
|
||||
|
||||
def setFw(self, status):
|
||||
if status == '1':
|
||||
if self.__isUfw:
|
||||
mw.execShell('/usr/sbin/ufw disable')
|
||||
@@ -313,7 +324,7 @@ class firewall_api:
|
||||
mw.execShell('/etc/init.d/iptables save')
|
||||
mw.execShell('/etc/init.d/iptables restart')
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
return mw.returnData(True, '设置成功!')
|
||||
|
||||
def delPanelLogsApi(self):
|
||||
mw.M('logs').where('id>?', (0,)).delete()
|
||||
|
||||
+77
-29
@@ -57,10 +57,22 @@ def getPluginDir():
|
||||
return getRunDir() + '/plugins'
|
||||
|
||||
|
||||
def getPanelDataDir():
|
||||
return getRunDir() + '/data'
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return getRootDir() + '/server'
|
||||
|
||||
|
||||
def getLogsDir():
|
||||
return getRootDir() + '/wwwlogs'
|
||||
|
||||
|
||||
def getBackupDir():
|
||||
return getRootDir() + '/backup'
|
||||
|
||||
|
||||
def getWwwDir():
|
||||
file = getRunDir() + '/data/site.pl'
|
||||
if os.path.exists(file):
|
||||
@@ -73,14 +85,6 @@ def setWwwDir(wdir):
|
||||
return writeFile(file, wdir)
|
||||
|
||||
|
||||
def getLogsDir():
|
||||
return getRootDir() + '/wwwlogs'
|
||||
|
||||
|
||||
def getBackupDir():
|
||||
return getRootDir() + '/backup'
|
||||
|
||||
|
||||
def setBackupDir(bdir):
|
||||
file = getRunDir() + '/data/backup.pl'
|
||||
return writeFile(file, bdir)
|
||||
@@ -157,19 +161,24 @@ def isInstalledWeb():
|
||||
|
||||
|
||||
def restartWeb():
|
||||
return opWeb("reload")
|
||||
|
||||
|
||||
def opWeb(method):
|
||||
if not isInstalledWeb():
|
||||
return False
|
||||
|
||||
# systemd
|
||||
systemd = '/lib/systemd/system/openresty.service'
|
||||
if os.path.exists(systemd):
|
||||
execShell('systemctl restart openresty')
|
||||
execShell('systemctl ' + method + ' openresty')
|
||||
return True
|
||||
|
||||
# initd
|
||||
initd = getServerDir() + '/openresty/init.d/openresty'
|
||||
|
||||
if os.path.exists(initd):
|
||||
execShell(initd + ' ' + 'restart')
|
||||
execShell(initd + ' ' + method)
|
||||
return True
|
||||
|
||||
return False
|
||||
@@ -402,6 +411,32 @@ def writeFile(filename, str):
|
||||
return False
|
||||
|
||||
|
||||
def backFile(file, act=None):
|
||||
"""
|
||||
@name 备份配置文件
|
||||
@param file 需要备份的文件
|
||||
@param act 如果存在,则备份一份作为默认配置
|
||||
"""
|
||||
file_type = "_bak"
|
||||
if act:
|
||||
file_type = "_def"
|
||||
|
||||
# print("cp -p {0} {1}".format(file, file + file_type))
|
||||
execShell("cp -p {0} {1}".format(file, file + file_type))
|
||||
|
||||
|
||||
def restoreFile(file, act=None):
|
||||
"""
|
||||
@name 还原配置文件
|
||||
@param file 需要还原的文件
|
||||
@param act 如果存在,则还原默认配置
|
||||
"""
|
||||
file_type = "_bak"
|
||||
if act:
|
||||
file_type = "_def"
|
||||
execShell("cp -p {1} {0}".format(file, file + file_type))
|
||||
|
||||
|
||||
def HttpGet(url, timeout=10):
|
||||
"""
|
||||
发送GET请求
|
||||
@@ -524,7 +559,7 @@ def getSpeed():
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def getLastLine(inputfile, lineNum):
|
||||
def getLastLineBk(inputfile, lineNum):
|
||||
# 读文件指定倒数行数
|
||||
try:
|
||||
fp = open(inputfile, 'rb')
|
||||
@@ -557,7 +592,7 @@ def getLastLine(inputfile, lineNum):
|
||||
# return getMsg('TASK_SLEEP')
|
||||
|
||||
|
||||
def getNumLines(path, num, p=1):
|
||||
def getLastLine(path, num, p=1):
|
||||
pyVersion = sys.version_info[0]
|
||||
try:
|
||||
import html
|
||||
@@ -567,12 +602,14 @@ def getNumLines(path, num, p=1):
|
||||
count = start_line + num
|
||||
fp = open(path, 'rb')
|
||||
buf = ""
|
||||
fp.seek(-1, 2)
|
||||
|
||||
fp.seek(0, 2)
|
||||
if fp.read(1) == "\n":
|
||||
fp.seek(-1, 2)
|
||||
fp.seek(0, 2)
|
||||
data = []
|
||||
b = True
|
||||
n = 0
|
||||
|
||||
for i in range(count):
|
||||
while True:
|
||||
newline_pos = str.rfind(str(buf), "\n")
|
||||
@@ -596,7 +633,7 @@ def getNumLines(path, num, p=1):
|
||||
t_buf = fp.read(to_read)
|
||||
if pyVersion == 3:
|
||||
if type(t_buf) == bytes:
|
||||
t_buf = t_buf.decode('utf-8')
|
||||
t_buf = t_buf.decode("utf-8", "ignore").strip()
|
||||
buf = t_buf + buf
|
||||
fp.seek(-to_read, 1)
|
||||
if pos - to_read == 0:
|
||||
@@ -605,7 +642,7 @@ def getNumLines(path, num, p=1):
|
||||
break
|
||||
fp.close()
|
||||
except Exception as e:
|
||||
return ''
|
||||
return str(e)
|
||||
|
||||
return "\n".join(data)
|
||||
|
||||
@@ -646,16 +683,14 @@ def getLocalIp():
|
||||
try:
|
||||
ipaddress = readFile(filename)
|
||||
if not ipaddress or ipaddress == '127.0.0.1':
|
||||
raise Exception("ip is empty!")
|
||||
cmd = "curl -4 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
||||
ip = execShell(cmd)
|
||||
result = ip[0].strip()
|
||||
if result == '':
|
||||
raise Exception("ipv4 is empty!")
|
||||
writeFile(filename, result)
|
||||
return result
|
||||
return ipaddress
|
||||
except Exception as e:
|
||||
cmd = "curl -4 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
||||
ip = execShell(cmd)
|
||||
result = ip[0].strip()
|
||||
if result == '':
|
||||
raise e
|
||||
writeFile(filename, result)
|
||||
return result
|
||||
except Exception as e:
|
||||
cmd = "curl -6 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
||||
ip = execShell(cmd)
|
||||
@@ -664,6 +699,8 @@ def getLocalIp():
|
||||
return '127.0.0.1'
|
||||
writeFile(filename, result)
|
||||
return result
|
||||
finally:
|
||||
pass
|
||||
return '127.0.0.1'
|
||||
|
||||
|
||||
@@ -689,7 +726,7 @@ def checkIp(ip):
|
||||
|
||||
def checkPort(port):
|
||||
# 检查端口是否合法
|
||||
ports = ['21', '25', '7200', '888']
|
||||
ports = ['21', '25', '443', '888']
|
||||
if port in ports:
|
||||
return False
|
||||
intport = int(port)
|
||||
@@ -710,13 +747,24 @@ def getStrBetween(startStr, endStr, srcStr):
|
||||
|
||||
|
||||
def getCpuType():
|
||||
cpuType = ''
|
||||
if isAppleSystem():
|
||||
cmd = "system_profiler SPHardwareDataType | grep 'Processor Name' | awk -F ':' '{print $2}'"
|
||||
cpuinfo = execShell(cmd)
|
||||
return cpuinfo[0].strip()
|
||||
|
||||
# 取CPU类型
|
||||
cpuinfo = open('/proc/cpuinfo', 'r').read()
|
||||
rep = "model\s+name\s+:\s+(.+)"
|
||||
tmp = re.search(rep, cpuinfo)
|
||||
cpuType = None
|
||||
tmp = re.search(rep, cpuinfo, re.I)
|
||||
if tmp:
|
||||
cpuType = tmp.groups()[0]
|
||||
else:
|
||||
cpuinfo = execShell('LANG="en_US.UTF-8" && lscpu')[0]
|
||||
rep = "Model\s+name:\s+(.+)"
|
||||
tmp = re.search(rep, cpuinfo, re.I)
|
||||
if tmp:
|
||||
cpuType = tmp.groups()[0]
|
||||
return cpuType
|
||||
|
||||
|
||||
@@ -761,7 +809,7 @@ def makeConf():
|
||||
file = getRunDir() + '/data/json/config.json'
|
||||
if not os.path.exists(file):
|
||||
c = {}
|
||||
c['title'] = 'mdserver-web | linux面板'
|
||||
c['title'] = '祖龙面板'
|
||||
c['home'] = 'http://github/midoks/mdserver-web'
|
||||
c['recycle_bin'] = True
|
||||
c['template'] = 'default'
|
||||
|
||||
@@ -114,6 +114,7 @@ class plugins_api:
|
||||
return mw.returnJson(False, '配置文件不存在!', ())
|
||||
|
||||
pluginInfo = json.loads(mw.readFile(infoJsonPos))
|
||||
self.hookInstall(pluginInfo)
|
||||
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
@@ -131,6 +132,55 @@ class plugins_api:
|
||||
mw.triggerTask()
|
||||
return mw.returnJson(True, '已将安装任务添加到队列!')
|
||||
|
||||
def hookInstallFile(self, hook_name, info):
|
||||
hookPath = mw.getPanelDataDir() + "/hook_" + hook_name + ".json"
|
||||
data = []
|
||||
if os.path.exists(hookPath):
|
||||
t = mw.readFile(hookPath)
|
||||
data = json.loads(t)
|
||||
|
||||
isNeedAdd = True
|
||||
for x in range(len(data)):
|
||||
if data[x]['title'] == info['title'] and data[x]['name'] == info['name']:
|
||||
isNeedAdd = False
|
||||
|
||||
if isNeedAdd:
|
||||
tmp = {}
|
||||
tmp['title'] = info['title']
|
||||
tmp['name'] = info['name']
|
||||
data.append(tmp)
|
||||
mw.writeFile(hookPath, json.dumps(data))
|
||||
|
||||
def hookUninstallFile(self, hook_name, info):
|
||||
hookPath = mw.getPanelDataDir() + "/hook_" + hook_name + ".json"
|
||||
data = []
|
||||
if os.path.exists(hookPath):
|
||||
t = mw.readFile(hookPath)
|
||||
data = json.loads(t)
|
||||
|
||||
for idx in range(len(data)):
|
||||
if data[idx]['title'] == info['title'] and data[idx]['name'] == info['name']:
|
||||
data.remove(data[idx])
|
||||
mw.writeFile(hookPath, json.dumps(data))
|
||||
|
||||
def hookInstall(self, info):
|
||||
if 'hook' in info:
|
||||
hooks = info['hook']
|
||||
for x in hooks:
|
||||
if x in ['backup']:
|
||||
self.hookInstallFile(x, info)
|
||||
return True
|
||||
return False
|
||||
|
||||
def hookUninstall(self, info):
|
||||
if 'hook' in info:
|
||||
hooks = info['hook']
|
||||
for x in hooks:
|
||||
if x in ['backup']:
|
||||
self.hookUninstallFile(x, info)
|
||||
return True
|
||||
return False
|
||||
|
||||
def uninstallOldApi(self):
|
||||
rundir = mw.getRunDir()
|
||||
name = request.form.get('name', '')
|
||||
@@ -147,7 +197,6 @@ class plugins_api:
|
||||
return mw.returnJson(False, "配置文件不存在!", ())
|
||||
|
||||
pluginInfo = json.loads(mw.readFile(infoJsonPos))
|
||||
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
+ " uninstall " + version
|
||||
@@ -175,13 +224,13 @@ class plugins_api:
|
||||
return mw.returnJson(False, "配置文件不存在!", ())
|
||||
|
||||
pluginInfo = json.loads(mw.readFile(infoJsonPos))
|
||||
|
||||
self.hookUninstall(pluginInfo)
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
+ " uninstall " + version
|
||||
|
||||
data = mw.execShell(execstr)
|
||||
if mw.isAppleSystem():
|
||||
if mw.isDebugMode():
|
||||
print(execstr)
|
||||
print(data[0], data[1])
|
||||
self.removeIndex(name, version)
|
||||
@@ -793,7 +842,7 @@ class plugins_api:
|
||||
print('getIndexList:', e)
|
||||
|
||||
# 使用gevent模式时,无法使用多进程
|
||||
#plist = self.checkStatusMProcess(plist)
|
||||
# plist = self.checkStatusMProcess(plist)
|
||||
plist = self.checkStatusMThreads(plist)
|
||||
return plist
|
||||
|
||||
|
||||
+40
-25
@@ -340,10 +340,16 @@ class site_api:
|
||||
name = mw.M('sites').where("id=?", (mid,)).getField('name')
|
||||
data = {}
|
||||
data['logs'] = self.getLogsStatus(name)
|
||||
data['runPath'] = self.getSiteRunPath(mid)
|
||||
|
||||
data['userini'] = False
|
||||
if os.path.exists(path + '/.user.ini'):
|
||||
data['userini'] = True
|
||||
data['runPath'] = self.getSiteRunPath(mid)
|
||||
|
||||
if data['runPath']['runPath'] != '/':
|
||||
if os.path.exists(path + data['runPath']['runPath'] + '/.user.ini'):
|
||||
data['userini'] = True
|
||||
|
||||
data['pass'] = self.getHasPwd(name)
|
||||
data['path'] = path
|
||||
data['name'] = name
|
||||
@@ -351,15 +357,18 @@ class site_api:
|
||||
|
||||
def setDirUserIniApi(self):
|
||||
path = request.form.get('path', '')
|
||||
runPath = request.form.get('runPath', '')
|
||||
filename = path + '/.user.ini'
|
||||
self.delUserInI(path)
|
||||
|
||||
if os.path.exists(filename):
|
||||
self.delUserInI(path)
|
||||
mw.execShell("which chattr && chattr -i " + filename)
|
||||
os.remove(filename)
|
||||
return mw.returnJson(True, '已清除防跨站设置!')
|
||||
mw.writeFile(filename, 'open_basedir=' + path +
|
||||
'/:/www/server/php:/tmp/:/proc/')
|
||||
|
||||
self.setDirUserINI(path, runPath)
|
||||
mw.execShell("which chattr && chattr +i " + filename)
|
||||
|
||||
return mw.returnJson(True, '已打开防跨站设置!')
|
||||
|
||||
def logsOpenApi(self):
|
||||
@@ -497,7 +506,7 @@ class site_api:
|
||||
certName = request.form.get('certName', '')
|
||||
siteName = request.form.get('siteName', '')
|
||||
try:
|
||||
path = self.sslDir + siteName
|
||||
path = self.sslDir + siteName.strip()
|
||||
if not os.path.exists(path):
|
||||
return mw.returnJson(False, '证书不存在!')
|
||||
|
||||
@@ -730,11 +739,11 @@ class site_api:
|
||||
if conf.find('ssl_certificate') == -1:
|
||||
return mw.returnJson(False, '当前未开启SSL')
|
||||
to = """#error_page 404/404.html;
|
||||
#HTTP_TO_HTTPS_START
|
||||
# HTTP_TO_HTTPS_START
|
||||
if ($server_port !~ 443){
|
||||
rewrite ^(/.*)$ https://$host$1 permanent;
|
||||
}
|
||||
#HTTP_TO_HTTPS_END"""
|
||||
# HTTP_TO_HTTPS_END"""
|
||||
conf = conf.replace('#error_page 404/404.html;', to)
|
||||
mw.writeFile(file, conf)
|
||||
|
||||
@@ -1095,6 +1104,7 @@ class site_api:
|
||||
sitePath = mw.M('sites').where('id=?', (mid,)).getField('path')
|
||||
|
||||
newPath = sitePath + runPath
|
||||
|
||||
# 处理Nginx
|
||||
filename = self.getHostConf(siteName)
|
||||
if os.path.exists(filename):
|
||||
@@ -1104,8 +1114,7 @@ class site_api:
|
||||
conf = conf.replace(path, newPath)
|
||||
mw.writeFile(filename, conf)
|
||||
|
||||
self.delUserInI(sitePath)
|
||||
self.setDirUserINI(newPath)
|
||||
self.setDirUserINI(sitePath, runPath)
|
||||
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
@@ -1562,7 +1571,7 @@ class site_api:
|
||||
|
||||
# location ~* ^{from}(.*)$ {
|
||||
tpl = """
|
||||
# PROXY-START/
|
||||
#PROXY-START/
|
||||
location ^~ {from} {
|
||||
proxy_pass {to};
|
||||
proxy_set_header Host {host};
|
||||
@@ -1585,7 +1594,7 @@ location ^~ {from} {
|
||||
add_header Cache-Control no-cache;
|
||||
}
|
||||
}
|
||||
# PROXY-END/
|
||||
#PROXY-END/
|
||||
"""
|
||||
|
||||
# replace
|
||||
@@ -1829,13 +1838,13 @@ location ^~ {from} {
|
||||
logPath = mw.getLogsDir() + '/' + siteName + '.log'
|
||||
if not os.path.exists(logPath):
|
||||
return mw.returnJson(False, '日志为空')
|
||||
return mw.returnJson(True, mw.getNumLines(logPath, 100))
|
||||
return mw.returnJson(True, mw.getLastLine(logPath, 100))
|
||||
|
||||
def getErrorLogs(self, siteName):
|
||||
logPath = mw.getLogsDir() + '/' + siteName + '.error.log'
|
||||
if not os.path.exists(logPath):
|
||||
return mw.returnJson(False, '日志为空')
|
||||
return mw.returnJson(True, mw.getNumLines(logPath, 100))
|
||||
return mw.returnJson(True, mw.getLastLine(logPath, 100))
|
||||
|
||||
# 取日志状态
|
||||
def getLogsStatus(self, siteName):
|
||||
@@ -2094,12 +2103,16 @@ location ^~ {from} {
|
||||
return rewriteList
|
||||
|
||||
def createRootDir(self, path):
|
||||
autoInit = False
|
||||
if not os.path.exists(path):
|
||||
autoInit = True
|
||||
os.makedirs(path)
|
||||
if not mw.isAppleSystem():
|
||||
mw.execShell('chown -R www:www ' + path)
|
||||
mw.writeFile(path + '/index.html', 'Work has started!!!')
|
||||
mw.execShell('chmod -R 755 ' + path)
|
||||
|
||||
if autoInit:
|
||||
mw.writeFile(path + '/index.html', 'Work has started!!!')
|
||||
mw.execShell('chmod -R 755 ' + path)
|
||||
|
||||
def nginxAddDomain(self, webname, domain, port):
|
||||
file = self.getHostConf(webname)
|
||||
@@ -2182,19 +2195,16 @@ location ^~ {from} {
|
||||
return mw.returnJson(False, '您添加的域名已存在!')
|
||||
mw.M('domain').where('pid=?', (opid,)).delete()
|
||||
|
||||
self.createRootDir(self.sitePath)
|
||||
self.nginxAddConf()
|
||||
|
||||
# 添加更多域名
|
||||
for domain in siteMenu['domainlist']:
|
||||
sdomain = domain
|
||||
swebname = self.siteName
|
||||
spid = str(pid)
|
||||
self.addDomain(domain, webname, pid)
|
||||
self.addDomain(domain, self.siteName, pid)
|
||||
|
||||
mw.M('domain').add('pid,name,port,addtime',
|
||||
(pid, self.siteName, self.sitePort, mw.getDate()))
|
||||
|
||||
self.createRootDir(self.sitePath)
|
||||
self.nginxAddConf()
|
||||
|
||||
data = {}
|
||||
data['siteStatus'] = False
|
||||
mw.restartWeb()
|
||||
@@ -2350,7 +2360,9 @@ location ^~ {from} {
|
||||
return True
|
||||
|
||||
# 设置目录防御
|
||||
def setDirUserINI(self, newPath):
|
||||
def setDirUserINI(self, sitePath, runPath):
|
||||
newPath = sitePath + runPath
|
||||
|
||||
filename = newPath + '/.user.ini'
|
||||
if os.path.exists(filename):
|
||||
mw.execShell("chattr -i " + filename)
|
||||
@@ -2358,8 +2370,11 @@ location ^~ {from} {
|
||||
return mw.returnJson(True, '已清除防跨站设置!')
|
||||
|
||||
self.delUserInI(newPath)
|
||||
mw.writeFile(filename, 'open_basedir=' +
|
||||
newPath + '/:/www/server/php:/tmp/:/proc/')
|
||||
openPath = 'open_basedir={}/:{}/'.format(newPath, sitePath)
|
||||
if runPath == '/':
|
||||
openPath = 'open_basedir={}/'.format(sitePath)
|
||||
|
||||
mw.writeFile(filename, openPath + ':/www/server/php:/tmp/:/proc/')
|
||||
mw.execShell("chattr +i " + filename)
|
||||
|
||||
return mw.returnJson(True, '已打开防跨站设置!')
|
||||
|
||||
+52
-40
@@ -162,7 +162,7 @@ class system_api:
|
||||
except:
|
||||
port = mw.readFile('data/port.pl')
|
||||
except:
|
||||
port = '8888'
|
||||
port = '7200'
|
||||
domain = ''
|
||||
if os.path.exists('data/domain.conf'):
|
||||
domain = mw.readFile('data/domain.conf')
|
||||
@@ -201,9 +201,9 @@ class system_api:
|
||||
def getLoadAverage(self):
|
||||
c = os.getloadavg()
|
||||
data = {}
|
||||
data['one'] = float(c[0])
|
||||
data['five'] = float(c[1])
|
||||
data['fifteen'] = float(c[2])
|
||||
data['one'] = round(float(c[0]), 2)
|
||||
data['five'] = round(float(c[1]), 2)
|
||||
data['fifteen'] = round(float(c[2]), 2)
|
||||
data['max'] = psutil.cpu_count() * 2
|
||||
data['limit'] = data['max']
|
||||
data['safe'] = data['max'] * 0.75
|
||||
@@ -276,8 +276,17 @@ class system_api:
|
||||
def getCpuInfo(self, interval=1):
|
||||
# 取CPU信息
|
||||
cpuCount = psutil.cpu_count()
|
||||
cpuLogicalNum = psutil.cpu_count(logical=False)
|
||||
used = psutil.cpu_percent(interval=interval)
|
||||
return used, cpuCount
|
||||
|
||||
if os.path.exists('/proc/cpuinfo'):
|
||||
c_tmp = mw.readFile('/proc/cpuinfo')
|
||||
d_tmp = re.findall("physical id.+", c_tmp)
|
||||
cpuLogicalNum = len(set(d_tmp))
|
||||
|
||||
used_all = psutil.cpu_percent(percpu=True)
|
||||
cpu_name = mw.getCpuType() + " * {}".format(cpuLogicalNum)
|
||||
return used, cpuCount, used_all, cpu_name, cpuCount, cpuLogicalNum
|
||||
|
||||
def getMemInfo(self):
|
||||
# 取内存信息
|
||||
@@ -437,12 +446,35 @@ class system_api:
|
||||
os.system('echo > /tmp/panelBoot.pl')
|
||||
return total, count
|
||||
|
||||
def psutilNetIoCounters(self):
|
||||
'''
|
||||
统计网卡流量
|
||||
'''
|
||||
stat_pl = 'data/only_netio_counters.pl'
|
||||
if os.path.exists(stat_pl):
|
||||
local_lo = (0, 0, 0, 0)
|
||||
ioName = psutil.net_io_counters(pernic=True).keys()
|
||||
for x in ioName:
|
||||
|
||||
if x.find("lo") > -1:
|
||||
local_lo = psutil.net_io_counters(
|
||||
pernic=True).get(x)[:4]
|
||||
|
||||
all_io = psutil.net_io_counters()[:4]
|
||||
result_io = tuple([all_io[i] - local_lo[i]
|
||||
for i in range(0, len(all_io))])
|
||||
|
||||
# print(local_lo)
|
||||
# print(all_io)
|
||||
# print(result_io)
|
||||
return result_io
|
||||
return psutil.net_io_counters()[:4]
|
||||
|
||||
def getNetWork(self):
|
||||
# return self.GetNetWorkApi(get);
|
||||
# 取网络流量信息
|
||||
try:
|
||||
# 取网络流量信息
|
||||
networkIo = psutil.net_io_counters()[:4]
|
||||
networkIo = self.psutilNetIoCounters()
|
||||
if not "otime" in session:
|
||||
session['up'] = networkIo[0]
|
||||
session['down'] = networkIo[1]
|
||||
@@ -470,38 +502,7 @@ class system_api:
|
||||
|
||||
return networkInfo
|
||||
except Exception as e:
|
||||
# print(e)
|
||||
return None
|
||||
|
||||
def getNetWorkApi(self):
|
||||
# 取网络流量信息
|
||||
try:
|
||||
tmpfile = 'data/network.temp'
|
||||
networkIo = psutil.net_io_counters()[:4]
|
||||
|
||||
if not os.path.exists(tmpfile):
|
||||
mw.writeFile(tmpfile, str(
|
||||
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
|
||||
|
||||
lastValue = mw.readFile(tmpfile).split('|')
|
||||
|
||||
ntime = time.time()
|
||||
networkInfo = {}
|
||||
networkInfo['upTotal'] = networkIo[0]
|
||||
networkInfo['downTotal'] = networkIo[1]
|
||||
networkInfo['up'] = round(
|
||||
float(networkIo[0] - int(lastValue[0])) / 1024 / (ntime - int(lastValue[2])), 2)
|
||||
networkInfo['down'] = round(
|
||||
float(networkIo[1] - int(lastValue[1])) / 1024 / (ntime - int(lastValue[2])), 2)
|
||||
networkInfo['downPackets'] = networkIo[3]
|
||||
networkInfo['upPackets'] = networkIo[2]
|
||||
|
||||
mw.writeFile(tmpfile, str(
|
||||
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
|
||||
|
||||
# networkInfo['cpu'] = self.GetCpuInfo(0.1)
|
||||
return networkInfo
|
||||
except:
|
||||
print("getNetWork error:", e)
|
||||
return None
|
||||
|
||||
def getNetWorkIoData(self, start, end):
|
||||
@@ -567,14 +568,19 @@ class system_api:
|
||||
def setControl(self, stype, day):
|
||||
|
||||
filename = 'data/control.conf'
|
||||
stat_pl = 'data/only_netio_counters.pl'
|
||||
|
||||
if stype == '0':
|
||||
mw.execShell("rm -f " + filename)
|
||||
mw.execShell("rm -rf " + filename)
|
||||
elif stype == '1':
|
||||
_day = int(day)
|
||||
if _day < 1:
|
||||
return mw.returnJson(False, "设置失败!")
|
||||
mw.writeFile(filename, day)
|
||||
elif stype == '2':
|
||||
mw.execShell("rm -rf " + stat_pl)
|
||||
elif stype == '3':
|
||||
mw.execShell("echo 'True' > " + stat_pl)
|
||||
elif stype == 'del':
|
||||
if not mw.isRestart():
|
||||
return mw.returnJson(False, '请等待所有安装任务完成再执行')
|
||||
@@ -597,6 +603,12 @@ class system_api:
|
||||
else:
|
||||
data['day'] = 30
|
||||
data['status'] = False
|
||||
|
||||
if os.path.exists(stat_pl):
|
||||
data['stat_all_status'] = True
|
||||
else:
|
||||
data['stat_all_status'] = False
|
||||
|
||||
return mw.getJson(data)
|
||||
|
||||
return mw.returnJson(True, "设置成功!")
|
||||
|
||||
@@ -68,6 +68,9 @@ class ORM:
|
||||
def setPort(self, port):
|
||||
self.__DB_PORT = port
|
||||
|
||||
def setUser(self, user):
|
||||
self.__DB_USER = user
|
||||
|
||||
def setPwd(self, pwd):
|
||||
self.__DB_PASS = pwd
|
||||
|
||||
|
||||
@@ -77,6 +77,12 @@ class ORM:
|
||||
def getPwd(self):
|
||||
return self.__DB_PASS
|
||||
|
||||
def setDbName(self, name):
|
||||
self.__DB_NAME = name
|
||||
|
||||
def setUser(self, user):
|
||||
self.__DB_USER = user
|
||||
|
||||
def execute(self, sql):
|
||||
# 执行SQL语句返回受影响行
|
||||
if not self.__Conn():
|
||||
|
||||
@@ -9,7 +9,7 @@ if [ -f bin/activate ];then
|
||||
source bin/activate
|
||||
fi
|
||||
|
||||
# export LC_ALL="en_US.UTF-8"
|
||||
export LC_ALL="en_US.UTF-8"
|
||||
|
||||
|
||||
mw_start_task()
|
||||
|
||||
@@ -13,7 +13,7 @@ service mw [start|stop|reload|restart|status]
|
||||
|
||||
```
|
||||
|
||||
sytemctl [start|stop|reload|restart|status] openresty
|
||||
systemctl [start|stop|reload|restart|status] openresty
|
||||
|
||||
```
|
||||
|
||||
@@ -21,7 +21,7 @@ sytemctl [start|stop|reload|restart|status] openresty
|
||||
|
||||
```
|
||||
|
||||
sytemctl [start|stop|reload|restart|status] mysql
|
||||
systemctl [start|stop|reload|restart|status] mysql
|
||||
|
||||
```
|
||||
|
||||
@@ -29,7 +29,7 @@ sytemctl [start|stop|reload|restart|status] mysql
|
||||
|
||||
```
|
||||
|
||||
sytemctl [start|stop|reload|restart|status] mariadb
|
||||
systemctl [start|stop|reload|restart|status] mariadb
|
||||
|
||||
```
|
||||
|
||||
@@ -37,16 +37,16 @@ sytemctl [start|stop|reload|restart|status] mariadb
|
||||
|
||||
```
|
||||
|
||||
sytemctl [start|stop|reload|restart|status] php[54-81]
|
||||
systemctl [start|stop|reload|restart|status] php[54-81]
|
||||
|
||||
sytemctl start php71
|
||||
systemctl start php71
|
||||
```
|
||||
|
||||
- Redis
|
||||
|
||||
```
|
||||
|
||||
sytemctl [start|stop|reload|restart|status] redis
|
||||
systemctl [start|stop|reload|restart|status] redis
|
||||
|
||||
```
|
||||
|
||||
@@ -54,7 +54,7 @@ sytemctl [start|stop|reload|restart|status] redis
|
||||
|
||||
```
|
||||
|
||||
sytemctl [start|stop|reload|restart|status] memcached
|
||||
systemctl [start|stop|reload|restart|status] memcached
|
||||
|
||||
```
|
||||
|
||||
@@ -63,6 +63,6 @@ sytemctl [start|stop|reload|restart|status] memcached
|
||||
|
||||
```
|
||||
|
||||
sytemctl [start|stop|reload|restart|status] sphinx
|
||||
systemctl [start|stop|reload|restart|status] sphinx
|
||||
|
||||
```
|
||||
|
||||
@@ -46,10 +46,9 @@ CREATE TABLE IF NOT EXISTS `firewall` (
|
||||
|
||||
INSERT INTO `firewall` (`id`, `port`, `ps`, `addtime`) VALUES
|
||||
(1, '80', '网站默认端口', '0000-00-00 00:00:00'),
|
||||
(2, '7200', 'WEB面板', '0000-00-00 00:00:00'),
|
||||
(3, '22', 'SSH远程管理服务', '0000-00-00 00:00:00'),
|
||||
(4, '888', 'phpMyAdmin默认端口', '0000-00-00 00:00:00'),
|
||||
(5, '443', 'HTTPS', '0000-00-00 00:00:00');
|
||||
(2, '22', 'SSH远程管理服务', '0000-00-00 00:00:00'),
|
||||
(3, '443', 'HTTPS', '0000-00-00 00:00:00'),
|
||||
(4, '888', 'phpMyAdmin默认端口', '0000-00-00 00:00:00');
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
server
|
||||
{
|
||||
listen {$PORT};
|
||||
listen [::]:{$PORT};
|
||||
server_name {$SERVER_NAME};
|
||||
index index.php index.html index.htm default.php default.htm default.html;
|
||||
root {$ROOT_DIR};
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
#!/www/server/mdserver-web/bin/python
|
||||
# description: mdserver-web cli tools
|
||||
# ln -s /www/server/mdserver-web/mw-cli /usr/bin/mw-cli
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def mw_start():
|
||||
"""
|
||||
Start mdserver-web
|
||||
"""
|
||||
os.system('systemctl start mw')
|
||||
print("服务已启动")
|
||||
|
||||
|
||||
def mw_stop():
|
||||
"""
|
||||
stop mdserver-web
|
||||
"""
|
||||
os.system('systemctl stop mw')
|
||||
print("服务已停止")
|
||||
|
||||
|
||||
def mw_restart():
|
||||
"""
|
||||
restart mdserver-web
|
||||
"""
|
||||
os.system('systemctl restart mw')
|
||||
print("服务已重启")
|
||||
|
||||
|
||||
def mw_reset_username():
|
||||
"""
|
||||
reset mdserver-web username
|
||||
"""
|
||||
from tools import set_panel_username
|
||||
user_name = input("请输入新的用户名: ")
|
||||
set_panel_username(user_name)
|
||||
|
||||
|
||||
def mw_reset_pwd():
|
||||
"""
|
||||
reset mdserver-web password
|
||||
"""
|
||||
from tools import set_panel_pwd
|
||||
pwd = input("请输入新的密码: ")
|
||||
set_panel_pwd(pwd, True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print("请使用root账户执行该命令.")
|
||||
sys.exit(1)
|
||||
|
||||
os.chdir("/www/server/mdserver-web")
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
|
||||
try:
|
||||
str = '''
|
||||
==== mdserver-web cli tools ====
|
||||
1. 启动服务 2. 停止服务
|
||||
3. 重启服务 4. 修改用户名
|
||||
5. 修改密码
|
||||
=================================
|
||||
'''
|
||||
if len(sys.argv) == 2:
|
||||
sw = sys.argv[1]
|
||||
else:
|
||||
print(str)
|
||||
sw = input("请输入您要进行的操作: ")
|
||||
|
||||
if sw == '1':
|
||||
mw_start()
|
||||
elif sw == '2':
|
||||
mw_stop()
|
||||
elif sw == '3':
|
||||
mw_restart()
|
||||
elif sw == '4':
|
||||
mw_reset_username()
|
||||
elif sw == '5':
|
||||
mw_reset_pwd()
|
||||
else:
|
||||
print("操作不存在")
|
||||
except KeyboardInterrupt:
|
||||
print("\n操作已终止")
|
||||
@@ -0,0 +1,418 @@
|
||||
# coding:utf-8
|
||||
|
||||
'''
|
||||
doc: https://docs.python.org/zh-cn/3/library/ftplib.html
|
||||
'''
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
|
||||
import paramiko
|
||||
import ftplib
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
DEBUG = True
|
||||
BLOCK_SIZE = 1024 * 1024 * 2
|
||||
# BLOCK_SIZE = 50
|
||||
PROGRESS_FILE_NAME = "PROGRESS_FILE_NAME"
|
||||
|
||||
"""
|
||||
=============自定义异常===================
|
||||
"""
|
||||
|
||||
|
||||
class OsError(Exception):
|
||||
"""OS端异常"""
|
||||
|
||||
|
||||
class ObjectNotFound(OsError):
|
||||
"""对象不存在时抛出的异常"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
message = "文件对象不存在。"
|
||||
super(ObjectNotFound, self).__init__(message, *args, **kwargs)
|
||||
|
||||
|
||||
class APIError(Exception):
|
||||
"""API参数错误异常"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
_api_error_msg = 'API资料校验失败,请核实!'
|
||||
super(APIError, self).__init__(_api_error_msg, *args, **kwargs)
|
||||
|
||||
|
||||
class FtpPSClient:
|
||||
_title = "FTP"
|
||||
_name = "ftp"
|
||||
__host = None
|
||||
__port = None
|
||||
__user = None
|
||||
__password = None
|
||||
default_port = 21
|
||||
default_backup_path = "/backup/"
|
||||
config_file = "cfg.json"
|
||||
|
||||
def __init__(self, load_config=True, timeout=10):
|
||||
self.timeout = timeout
|
||||
if load_config:
|
||||
data = self.get_config()
|
||||
self.injection_config(data)
|
||||
|
||||
def get_config(self):
|
||||
default_config = {
|
||||
"ftp_host": '',
|
||||
"ftp_user": '',
|
||||
"ftp_pass": '',
|
||||
"backup_path": self.default_backup_path
|
||||
}
|
||||
|
||||
cfg = mw.getServerDir() + "/backup_ftp/" + self.config_file
|
||||
if os.path.exists(cfg):
|
||||
data = mw.readFile(cfg)
|
||||
return json.loads(data)
|
||||
else:
|
||||
return default_config
|
||||
|
||||
def injection_config(self, data):
|
||||
host = data["ftp_host"].strip()
|
||||
if host.find(':') == -1:
|
||||
self.__port = self.default_port
|
||||
|
||||
self.__host = data['ftp_host'].strip()
|
||||
self.__user = data['ftp_user'].strip()
|
||||
self.__password = data['ftp_pass'].strip()
|
||||
bp = data['backup_path'].strip()
|
||||
if bp:
|
||||
self.backup_path = self.getPath(bp)
|
||||
else:
|
||||
self.backup_path = self.getPath(self.default_backup_path)
|
||||
|
||||
def authorize(self):
|
||||
try:
|
||||
if self.timeout is not None:
|
||||
ftp = ftplib.FTP(timeout=self.timeout)
|
||||
else:
|
||||
ftp = ftplib.FTP()
|
||||
|
||||
debuglevel = 0
|
||||
# if DEBUG:
|
||||
# debuglevel = 3
|
||||
ftp.set_debuglevel(debuglevel)
|
||||
# ftp.set_pasv(True)
|
||||
ftp.connect(self.__host, int(self.__port))
|
||||
ftp.login(self.__user, self.__password)
|
||||
return ftp
|
||||
except Exception as e:
|
||||
raise OsError("无法连接FTP客户端,请检查配置参数是否正确!")
|
||||
|
||||
# 取目录路径
|
||||
def getPath(self, path):
|
||||
if path[-1:] != '/':
|
||||
path += '/'
|
||||
if path[:1] != '/':
|
||||
path = '/' + path
|
||||
return path.replace('//', '/')
|
||||
|
||||
def generateDownloadUrl(self, object_name):
|
||||
|
||||
return 'ftp://' + \
|
||||
self.__user + ':' + \
|
||||
self.__password + '@' + \
|
||||
self.__host + ':' + \
|
||||
"/" + object_name
|
||||
|
||||
def buildDirName(self, data_type, file_name):
|
||||
import re
|
||||
prefix_dict = {
|
||||
"site": "web",
|
||||
"database": "db",
|
||||
"path": "path",
|
||||
}
|
||||
file_regx = prefix_dict.get(data_type) + "_(.+)_20\d+_\d+\."
|
||||
sub_search = re.search(file_regx, file_name)
|
||||
sub_path_name = ""
|
||||
if sub_search:
|
||||
sub_path_name = sub_search.groups()[0]
|
||||
sub_path_name += '/'
|
||||
|
||||
# 构建OS存储路径
|
||||
object_name = self.backup_path + \
|
||||
data_type + '/' + \
|
||||
sub_path_name + \
|
||||
file_name
|
||||
return object_name
|
||||
|
||||
def uploadFile(self, filename, data_type=None, *args, **kwargs):
|
||||
|
||||
client = self.authorize()
|
||||
|
||||
local_file_name = filename
|
||||
filename = os.path.abspath(filename)
|
||||
dirname = os.path.dirname(filename)
|
||||
temp_name = os.path.split(filename)[1]
|
||||
|
||||
object_name = self.buildDirName(data_type, temp_name)
|
||||
|
||||
upload_tmp_dir = os.path.join(dirname, ".upload_tmp")
|
||||
if not os.path.exists(upload_tmp_dir):
|
||||
os.mkdir(upload_tmp_dir)
|
||||
|
||||
print("|-正在上传文件到 {}".format(object_name))
|
||||
|
||||
total_bytes = os.path.getsize(filename)
|
||||
object_md5_name = mw.md5(object_name)
|
||||
pg_file = os.path.join(upload_tmp_dir, object_md5_name + ".pl")
|
||||
|
||||
block_size = BLOCK_SIZE
|
||||
if kwargs.get("block_size"):
|
||||
try:
|
||||
block_size = float(kwargs.get("block_size"))
|
||||
except:
|
||||
pass
|
||||
|
||||
remote_file_size = None
|
||||
if not os.path.exists(pg_file):
|
||||
# import uuid
|
||||
# uid = str(uuid.uuid1())
|
||||
progress_info = {
|
||||
"filename": local_file_name,
|
||||
"total_bytes": total_bytes,
|
||||
"uploaded_bytes": 0,
|
||||
}
|
||||
mw.writeFile(pg_file, json.dumps(progress_info))
|
||||
else:
|
||||
progress_info = json.loads(mw.readFile(pg_file))
|
||||
if total_bytes == progress_info.get("total_bytes"):
|
||||
# 取远程文件大小
|
||||
_max_loop = 10
|
||||
while _max_loop > 0:
|
||||
try:
|
||||
time.sleep(1)
|
||||
remote_file_size = client.size(object_name)
|
||||
if remote_file_size > total_bytes:
|
||||
remote_file_size = None
|
||||
break
|
||||
except Exception as e:
|
||||
if DEBUG:
|
||||
print(type(e))
|
||||
print(e)
|
||||
_max_loop -= 1
|
||||
else:
|
||||
remote_file_size = None
|
||||
|
||||
uploaded_bytes = 0 if remote_file_size is None else remote_file_size
|
||||
|
||||
dir_name = os.path.split(object_name)[0]
|
||||
if dir_name:
|
||||
self.createDirP(dir_name)
|
||||
|
||||
upload_start = time.time()
|
||||
|
||||
try:
|
||||
if total_bytes > 1024 * 1024 * 1024:
|
||||
with open(local_file_name, 'rb') as file_handler:
|
||||
if remote_file_size is not None:
|
||||
file_handler.seek(remote_file_size)
|
||||
|
||||
client.voidcmd("TYPE I")
|
||||
datasock = ''
|
||||
esize = ''
|
||||
|
||||
datasock, esize = client.ntransfercmd(
|
||||
"STOR " + object_name, remote_file_size)
|
||||
|
||||
while True:
|
||||
buf = file_handler.read(block_size)
|
||||
if not len(buf):
|
||||
break
|
||||
datasock.sendall(buf)
|
||||
uploaded_bytes += len(buf)
|
||||
if DEBUG:
|
||||
print('\ruploading %.2f%%' %
|
||||
(float(uploaded_bytes) / total_bytes * 100))
|
||||
|
||||
print("uploaded_bytes", uploaded_bytes)
|
||||
if uploaded_bytes == total_bytes:
|
||||
break
|
||||
datasock.close()
|
||||
|
||||
if DEBUG:
|
||||
print('close data handle')
|
||||
try:
|
||||
client.voidcmd('NOOP')
|
||||
except Exception as e:
|
||||
if DEBUG:
|
||||
print("Send NOOP command error:")
|
||||
print(e)
|
||||
else:
|
||||
if DEBUG:
|
||||
print('keep alive cmd success')
|
||||
client.voidresp()
|
||||
if DEBUG:
|
||||
print('No loop cmd')
|
||||
else:
|
||||
# 小于1G文件直接上传
|
||||
file_handler = open(local_file_name, "rb")
|
||||
client.storbinary('STOR %s' % object_name,
|
||||
file_handler, blocksize=block_size)
|
||||
file_handler.close()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
completed_file_size = None
|
||||
_max_loop = 10
|
||||
while _max_loop > 0:
|
||||
try:
|
||||
time.sleep(1)
|
||||
completed_file_size = client.size(object_name)
|
||||
break
|
||||
except Exception as e:
|
||||
_max_loop -= 1
|
||||
if DEBUG:
|
||||
print("size error:" + str(e))
|
||||
|
||||
# 上传完成
|
||||
if completed_file_size == total_bytes:
|
||||
if DEBUG:
|
||||
upload_completed = time.time()
|
||||
upload_diff = upload_completed - upload_start
|
||||
print("文件上传成功, 耗时: {}s。".format(upload_diff))
|
||||
if os.path.exists(pg_file):
|
||||
os.remove(pg_file)
|
||||
return True
|
||||
else:
|
||||
if os.path.exists(pg_file):
|
||||
os.remove(pg_file)
|
||||
print("文件上传后大小不一致!")
|
||||
|
||||
print("completed_file_size:" + str(completed_file_size))
|
||||
print("total_bytes:", total_bytes)
|
||||
print("object_md5_name:", object_md5_name)
|
||||
print("pg_file:", pg_file)
|
||||
print("filename:", filename)
|
||||
print("dirname:", dirname)
|
||||
print("object_name:", object_name)
|
||||
return False
|
||||
|
||||
def createDirP(self, dir_name):
|
||||
"""创建远程目录
|
||||
|
||||
:param dir_name: 目录名称
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
dirnames = dir_name.split('/')
|
||||
ftp = self.authorize()
|
||||
# ftp.cwd(get.path);
|
||||
for dirname in dirnames:
|
||||
if not dirname or not dirname.strip():
|
||||
continue
|
||||
try:
|
||||
flist = ftp.nlst()
|
||||
if not dirname in flist:
|
||||
ftp.mkd(dirname)
|
||||
except:
|
||||
# print("mlsd mode.")
|
||||
try:
|
||||
flist = list(ftp.mlsd())[1:]
|
||||
for f in flist:
|
||||
if dirname == f[0]:
|
||||
break
|
||||
else:
|
||||
ftp.mkd(dirname)
|
||||
except:
|
||||
return False
|
||||
ftp.cwd(dirname)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def createDir(self, path, name):
|
||||
ftp = self.authorize()
|
||||
path = self.getPath(path)
|
||||
ftp.cwd(path)
|
||||
try:
|
||||
ftp.mkd(name)
|
||||
ftp.close()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
ftp.close()
|
||||
return False
|
||||
|
||||
def deleteDir(self, path, dir_name):
|
||||
try:
|
||||
ftp = self.authorize()
|
||||
ftp.rmd(dir_name)
|
||||
return True
|
||||
except ftplib.error_perm as e:
|
||||
print("deleteDir:" + str(e) + ":" + dir_name)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def deleteFile(self, filename):
|
||||
try:
|
||||
ftp = self.authorize()
|
||||
ftp.delete(filename)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return False
|
||||
|
||||
def getList(self, path="/"):
|
||||
ftp = self.authorize()
|
||||
path = self.getPath(path)
|
||||
ftp.cwd(path)
|
||||
mlsd = False
|
||||
try:
|
||||
files = list(ftp.mlsd())
|
||||
mlsd = True
|
||||
except:
|
||||
try:
|
||||
files = ftp.nlst(path)
|
||||
mlsd = False
|
||||
except:
|
||||
raise RuntimeError("FTP服务器数据返回异常!")
|
||||
ftp.close()
|
||||
# print(files)
|
||||
f_list = []
|
||||
dirs = []
|
||||
data = []
|
||||
default_time = '1971/01/01 01:01:01'
|
||||
for dt in files:
|
||||
# print(dt)
|
||||
if mlsd:
|
||||
dt_name = dt[0]
|
||||
dt_info = dt[1]
|
||||
else:
|
||||
if dt.find("/") >= 0:
|
||||
dt = dt.split("/")[-1]
|
||||
tmp = {}
|
||||
tmp['name'] = dt_name
|
||||
if dt_name == '.' or dt_name == '..':
|
||||
continue
|
||||
|
||||
tmp['time'] = dt_info['modify']
|
||||
try:
|
||||
tmp['size'] = dt_info['size']
|
||||
tmp['type'] = "File"
|
||||
tmp['download'] = self.generateDownloadUrl(path + dt_name)
|
||||
f_list.append(tmp)
|
||||
except:
|
||||
tmp['size'] = dt_info['sizd']
|
||||
tmp['type'] = None
|
||||
tmp['download'] = ''
|
||||
dirs.append(tmp)
|
||||
data = dirs + f_list
|
||||
|
||||
mlist = {}
|
||||
mlist['path'] = path
|
||||
mlist['list'] = data
|
||||
return mlist
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Executable
+101
@@ -0,0 +1,101 @@
|
||||
<style>
|
||||
.upyunCon {
|
||||
height: 428px;
|
||||
}
|
||||
|
||||
.up-place {
|
||||
height: 62px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.up-place .btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.up-place .place-input {
|
||||
background-color: #f3f3f3;
|
||||
border: 1px solid #ccc;
|
||||
height: 30px;
|
||||
line-height: 28px;
|
||||
overflow: hidden;
|
||||
margin: 1px 0 0 -1px;
|
||||
width: 340px;
|
||||
}
|
||||
|
||||
.place-input ul {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.place-input ul li {
|
||||
background: url("/static/img/ico/ico-ltr.png") no-repeat right center;
|
||||
float: left;
|
||||
padding-left: 10px;
|
||||
padding-right: 18px;
|
||||
}
|
||||
|
||||
.place-input ul li a {
|
||||
height: 28px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.upyunlist {
|
||||
height: 516px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.up-bottom {
|
||||
background-color: #fafafa;
|
||||
border-top: 1px solid #eee;
|
||||
bottom: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.up-use {
|
||||
line-height: 50px
|
||||
}
|
||||
|
||||
.list-list .cursor span {
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
.btn-title {
|
||||
margin-top: 1px
|
||||
}
|
||||
|
||||
.tip {
|
||||
font-size: 10px;
|
||||
font-style: oblique;
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<div class="upyunCon">
|
||||
<div class="up-place pd15">
|
||||
<button id="backBtn" class="btn btn-default btn-sm glyphicon glyphicon-arrow-left pull-left" title="后退"></button>
|
||||
<input id="myPath" style="display:none;" type="text" value="">
|
||||
<div class="place-input pull-left">
|
||||
<div style="width:1400px;height:28px"><ul></ul></div>
|
||||
</div>
|
||||
<button class="refreshBtn btn btn-default btn-sm glyphicon glyphicon-refresh pull-left mr20" title="刷新" style="margin-left:-1px;"></button>
|
||||
<button class="btn btn-default btn-sm pull-right btn-title" onclick="upyunApi()">帐户设置</button>
|
||||
<button class="btn btn-default btn-sm pull-right mr20 btn-title" onclick="createDir()">新建文件夹</button>
|
||||
</div>
|
||||
|
||||
<div class="upyunlist pd15">
|
||||
<div class="divtable" style="margin-bottom:15px">
|
||||
<table class="table table-hover">
|
||||
<thead><tr><th>名称</th><th>大小</th><th>更新时间</th><th class="text-right">操作</th></tr></thead>
|
||||
<tbody class="list-list"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=backup_ftp&f=js/backup_ftp.js", function(){
|
||||
osList('/');
|
||||
});
|
||||
</script>
|
||||
Executable
+257
@@ -0,0 +1,257 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
|
||||
# print(sys.platform)
|
||||
if sys.platform != "darwin":
|
||||
os.chdir("/www/server/mdserver-web")
|
||||
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
_ver = sys.version_info
|
||||
is_py2 = (_ver[0] == 2)
|
||||
is_py3 = (_ver[0] == 3)
|
||||
|
||||
DEBUG = False
|
||||
|
||||
if is_py2:
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'backup_ftp'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
from ftp_client import FtpPSClient
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
|
||||
return tmp
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
return 'start'
|
||||
|
||||
|
||||
def getConf():
|
||||
cfg = getServerDir() + "/cfg.json"
|
||||
if not os.path.exists(cfg):
|
||||
return mw.returnJson(False, "未配置", [])
|
||||
data = mw.readFile(cfg)
|
||||
data = json.loads(data)
|
||||
return mw.returnJson(True, "OK", data)
|
||||
|
||||
|
||||
def setConf():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['use_sftp', 'ftp_user',
|
||||
'ftp_pass', 'ftp_host', 'backup_path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
cfg = getServerDir() + "/cfg.json"
|
||||
|
||||
values = ['ftp_user',
|
||||
'ftp_pass',
|
||||
'ftp_host']
|
||||
for v in values:
|
||||
if args[v] == '':
|
||||
return mw.returnJson(False, '必填资料不能为空,请核实!', [])
|
||||
|
||||
if args['backup_path'] == '':
|
||||
args['backup_path'] = "/backup"
|
||||
|
||||
try:
|
||||
ftp = FtpPSClient(load_config=False)
|
||||
ftp.injection_config(args)
|
||||
data = ftp.getList("/")
|
||||
if data:
|
||||
mw.writeFile(cfg, mw.getJson(args))
|
||||
return mw.returnJson(True, '设置成功', [])
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, "FTP校验失败,请核实!\n" + str(e), [])
|
||||
|
||||
|
||||
def getList():
|
||||
cfg = getServerDir() + "/cfg.json"
|
||||
if not os.path.exists(cfg):
|
||||
return mw.returnJson(False, "未配置FTP,请点击`账户设置`", [])
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
try:
|
||||
ftp = FtpPSClient()
|
||||
flist = ftp.getList(args['path'])
|
||||
return mw.returnJson(True, "ok", flist)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, str(e), [])
|
||||
|
||||
|
||||
def createDir():
|
||||
cfg = getServerDir() + "/cfg.json"
|
||||
if not os.path.exists(cfg):
|
||||
return mw.returnJson(False, "未配置FTP,请点击`账户设置`", [])
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['path', 'name'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ftp = FtpPSClient()
|
||||
isok = ftp.createDir(args['path'], args['name'])
|
||||
if isok:
|
||||
return mw.returnJson(True, "创建成功")
|
||||
return mw.returnJson(False, "创建失败")
|
||||
|
||||
|
||||
def deleteDir():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['dir_name', 'path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ftp = FtpPSClient()
|
||||
isok = ftp.deleteDir(args['path'], args['dir_name'])
|
||||
if isok:
|
||||
return mw.returnJson(True, "删除成功")
|
||||
return mw.returnJson(False, "删除失败")
|
||||
|
||||
|
||||
def deleteFile():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['path', 'filename'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ftp = FtpPSClient()
|
||||
isok = ftp.deleteFile(args['path'] + "/" + args['filename'])
|
||||
if isok:
|
||||
return mw.returnJson(True, "删除成功")
|
||||
return mw.returnJson(False, "删除失败")
|
||||
|
||||
|
||||
def backupAllFunc(stype):
|
||||
os.chdir(mw.getRunDir())
|
||||
|
||||
name = sys.argv[2]
|
||||
num = sys.argv[3]
|
||||
|
||||
args = stype + " " + name + " " + num
|
||||
|
||||
cmd = 'python3 ' + mw.getRunDir() + '/scripts/backup.py ' + args
|
||||
os.system(cmd)
|
||||
|
||||
# 开始执行上传信息
|
||||
|
||||
prefix_dict = {
|
||||
"site": "web",
|
||||
"database": "db",
|
||||
"path": "path",
|
||||
}
|
||||
|
||||
find_path = mw.getBackupDir() + '/' + stype + '/' + \
|
||||
prefix_dict[stype] + '_' + name
|
||||
|
||||
find_new_file = "ls " + find_path + \
|
||||
"_* | grep '.gz' | cut -d \ -f 1 | awk 'END {print}'"
|
||||
|
||||
filename = mw.execShell(find_new_file)[0].strip()
|
||||
if filename == "":
|
||||
print("not find upload file!")
|
||||
return False
|
||||
|
||||
ftp = FtpPSClient()
|
||||
ftp.uploadFile(filename, stype)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def backupSite():
|
||||
# 备份站点
|
||||
pass
|
||||
|
||||
|
||||
def in_array(name, arr=[]):
|
||||
for x in arr:
|
||||
if name == x:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def installPreInspection():
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print(status())
|
||||
elif func == 'start':
|
||||
print(start())
|
||||
elif func == 'stop':
|
||||
print(stop())
|
||||
elif func == 'restart':
|
||||
print(restart())
|
||||
elif func == 'reload':
|
||||
print(reload())
|
||||
elif func == 'install_pre_inspection':
|
||||
print(installPreInspection())
|
||||
elif func == 'conf':
|
||||
print(getConf())
|
||||
elif func == 'set_config':
|
||||
print(setConf())
|
||||
elif func == "get_list":
|
||||
print(getList())
|
||||
elif func == "create_dir":
|
||||
print(createDir())
|
||||
elif func == "delete_dir":
|
||||
print(deleteDir())
|
||||
elif func == 'delete_file':
|
||||
print(deleteFile())
|
||||
elif in_array(func, ['site', 'database', 'path']):
|
||||
print(backupAllFunc(func))
|
||||
else:
|
||||
print('error')
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"title":"FTP存储空间",
|
||||
"hook":["backup"],
|
||||
"tip":"soft",
|
||||
"name":"backup_ftp",
|
||||
"type":"运行环境",
|
||||
"ps":"将网站或数据库打包备份到FTP存储空间",
|
||||
"versions":["1.0"],
|
||||
"install_pre_inspection":false,
|
||||
"shell":"install.sh",
|
||||
"checks":"server/backup_ftp",
|
||||
"path": "server/backup_ftp",
|
||||
"author":"midoks",
|
||||
"home":"",
|
||||
"date":"2022-10-23",
|
||||
"pid": "4"
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
sys_os=`uname`
|
||||
|
||||
|
||||
Install_App()
|
||||
{
|
||||
mkdir -p ${serverPath}/backup_ftp
|
||||
echo "${1}" > ${serverPath}/backup_ftp/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
rm -rf ${serverPath}/backup_ftp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App $2
|
||||
else
|
||||
Uninstall_App $2
|
||||
fi
|
||||
Executable
+258
@@ -0,0 +1,258 @@
|
||||
|
||||
|
||||
function bkfPost(method,args,callback){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'backup_ftp', func:method, args:_args}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function getFtpLocalTime(data){
|
||||
var str = data.slice(0,4)+"/"+data.slice(4,6)+"/"+data.slice(6,8)
|
||||
+ " " + data.slice(8,10)+":"+data.slice(10,12)+":"+data.slice(12,14);
|
||||
return str;
|
||||
}
|
||||
|
||||
// 自定义部分
|
||||
var i = null;
|
||||
//设置API
|
||||
function upyunApi(){
|
||||
|
||||
bkfPost('conf', {}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var token = rdata.data;
|
||||
var check_status = token.use_sftp;
|
||||
var sftp_checked = check_status === "true" ? " checked=\"checked\"" : "";
|
||||
|
||||
if (typeof(token.ftp_host) == 'undefined'){
|
||||
token.ftp_host = '';
|
||||
}
|
||||
|
||||
if (typeof(token.ftp_user) == 'undefined'){
|
||||
token.ftp_user = '';
|
||||
}
|
||||
|
||||
if (typeof(token.ftp_pass) == 'undefined'){
|
||||
token.ftp_pass = '';
|
||||
}
|
||||
|
||||
if (typeof(token.backup_path) == 'undefined'){
|
||||
token.backup_path = '';
|
||||
}
|
||||
|
||||
var apicon = '<div class="bingfa mtb15" style="padding-bottom:0px;">\
|
||||
<p>\
|
||||
<span class="span_tit">使用SFTP:</span>\ <input style="width: 20px; vertical-align:middle;" type="checkbox" name="use_sftp"'+sftp_checked+'> 是否使用SFTP进行数据传输 \
|
||||
</p>\
|
||||
<p>\
|
||||
<span class="span_tit">Host:</span>\
|
||||
<input placeholder="请输入主机地址" style="width: 200px;" type="text" name="upyun_service" value="'+token.ftp_host+'"> *服务器地址,FTP默认端口21, SFTP默认端口22\
|
||||
</p>\
|
||||
<p>\
|
||||
<span class="span_tit">用户名:</span>\
|
||||
<input style="width: 200px;" type="text" name="ftp_username" value="'+token.ftp_user+'"> *指定用户名\
|
||||
</p>\
|
||||
<p>\
|
||||
<span class="span_tit">密码:</span>\
|
||||
<input style="width: 200px;" type="password" name="ftp_password" value="'+token.ftp_pass+'"> *登录密码\
|
||||
</p>\
|
||||
<p>\
|
||||
<span class="span_tit">存储位置:</span>\
|
||||
<input placeholder="请输入存储位置" style="width: 200px;" type="text" name="backup_path" value="'+token.backup_path+'"> *相对于根目录的路径,默认是/backup\
|
||||
</p>\
|
||||
</div>';
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: "600px",
|
||||
title: "FTP/SFTP帐户设置",
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
btn: ['确定','取消'],
|
||||
content:apicon,
|
||||
yes:function(index,layero){
|
||||
var data = {
|
||||
use_sftp:$("input[name='use_sftp']").prop('checked'),
|
||||
ftp_user:$("input[name='ftp_username']").val(),
|
||||
ftp_pass:$("input[name='ftp_password']").val(),
|
||||
ftp_host:$("input[name='upyun_service']").val(),
|
||||
backup_path:$("input[name='backup_path']").val()
|
||||
}
|
||||
bkfPost('set_config', data, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
if (rdata.status){
|
||||
showMsg(rdata.msg,function(){
|
||||
layer.close(index);
|
||||
osList("/");
|
||||
},{icon:1},2000);
|
||||
} else{
|
||||
layer.msg(rdata.msg,{icon:2});
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function createDir(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: "400px",
|
||||
title: "创建目录",
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
btn: ['确定','取消'],
|
||||
content:'<div class="bingfa bt-form c6" style="padding-bottom: 10px;">\
|
||||
<p>\
|
||||
<span class="span_tit">目录名称:</span>\
|
||||
<input style="width: 200px;" type="text" name="newPath" value="">\
|
||||
</p>\
|
||||
</div>',
|
||||
success:function(){
|
||||
$("input[name='newPath']").focus().keyup(function(e){
|
||||
if(e.keyCode == 13) $(".layui-layer-btn0").click();
|
||||
});
|
||||
},
|
||||
yes:function(index,layero){
|
||||
var name = $("input[name='newPath']").val();
|
||||
if(name == ''){
|
||||
layer.msg('目录名称不能为空!',{icon:2});
|
||||
return;
|
||||
}
|
||||
var path = $("#myPath").val();
|
||||
var dirname = name;
|
||||
// var loadT = layer.msg('正在创建目录['+dirname+']...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
bkfPost('create_dir', {path:path,name:dirname}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if(rdata.status) {
|
||||
showMsg(rdata.msg, function(){
|
||||
layer.close(index);
|
||||
osList(path);
|
||||
} ,{icon:1}, 2000);
|
||||
} else{
|
||||
layer.msg(rdata.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//删除文件
|
||||
function deleteFile(name, is_dir){
|
||||
if (is_dir === false){
|
||||
safeMessage('删除文件','删除后将无法恢复,真的要删除['+name+']吗?',function(){
|
||||
var path = $("#myPath").val();
|
||||
var filename = name;
|
||||
bkfPost('delete_file', {filename:filename,path:path}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
osList(path);
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
safeMessage('删除文件夹','删除后将无法恢复,真的要删除['+name+']吗?',function(){
|
||||
var path = $("#myPath").val();
|
||||
bkfPost('delete_dir', {dir_name:name,path:path}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
osList(path);
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function osList(path){
|
||||
bkfPost('get_list', {path:path}, function(rdata){
|
||||
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
if(rdata.status === false){
|
||||
showMsg(rdata.msg,function(){
|
||||
upyunApi();
|
||||
},{icon:2},2000);
|
||||
return;
|
||||
}
|
||||
|
||||
var mlist = rdata.data;
|
||||
// console.log(mlist);
|
||||
var listBody = ''
|
||||
var listFiles = ''
|
||||
for(var i=0;i<mlist.list.length;i++){
|
||||
if(mlist.list[i].type == null){
|
||||
listBody += '<tr><td class="cursor" onclick="osList(\''+(path+'/'+mlist.list[i].name).replace('//','/')+'\')"><span class="ico ico-folder"></span>\<span>'+mlist.list[i].name+'</span></td>\
|
||||
<td>-</td>\
|
||||
<td>-</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="deleteFile(\''+mlist.list[i].name+'\', true)">删除</a></td></tr>'
|
||||
}else{
|
||||
listFiles += '<tr><td class="cursor"><span class="ico ico-file"></span>\<span>'+mlist.list[i].name+'</span></td>\
|
||||
<td>'+toSize(mlist.list[i].size)+'</td>\
|
||||
<td>'+getFtpLocalTime(mlist.list[i].time)+'</td>\
|
||||
<td class="text-right"><a target="_blank" href="'+mlist.list[i].download+'" class="btlink">下载</a> | <a class="btlink" onclick="deleteFile(\''+mlist.list[i].name+'\', false)">删除</a></td></tr>'
|
||||
}
|
||||
}
|
||||
listBody += listFiles;
|
||||
|
||||
var pathLi='';
|
||||
var tmp = path.split('/')
|
||||
var pathname = '';
|
||||
var n = 0;
|
||||
for(var i=0;i<tmp.length;i++){
|
||||
if(n > 0 && tmp[i] == '') continue;
|
||||
var dirname = tmp[i];
|
||||
if(dirname == '') {
|
||||
dirname = '根目录';
|
||||
n++;
|
||||
}
|
||||
pathname += '/' + tmp[i];
|
||||
pathname = pathname.replace('//','/');
|
||||
pathLi += '<li><a title="'+pathname+'" onclick="osList(\''+pathname+'\')">'+dirname+'</a></li>';
|
||||
}
|
||||
var um = 1;
|
||||
if(tmp[tmp.length-1] == '') um = 2;
|
||||
var backPath = tmp.slice(0,tmp.length-um).join('/') || '/';
|
||||
$('#myPath').val(path);
|
||||
$(".upyunCon .place-input ul").html(pathLi);
|
||||
$(".upyunlist .list-list").html(listBody);
|
||||
|
||||
upPathLeft();
|
||||
|
||||
$('#backBtn').unbind().click(function() {
|
||||
osList(backPath);
|
||||
});
|
||||
|
||||
$('.upyunCon .refreshBtn').unbind().click(function(){
|
||||
osList(path);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//计算当前目录偏移
|
||||
function upPathLeft(){
|
||||
var UlWidth = $(".place-input ul").width();
|
||||
var SpanPathWidth = $(".place-input").width() - 20;
|
||||
var Ml = UlWidth - SpanPathWidth;
|
||||
if(UlWidth > SpanPathWidth ){
|
||||
$(".place-input ul").css("left",-Ml)
|
||||
}
|
||||
else{
|
||||
$(".place-input ul").css("left",0)
|
||||
}
|
||||
}
|
||||
// $('.layui-layer-page').css('height','670px');
|
||||
@@ -3,6 +3,7 @@
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('clean');">服务</p>
|
||||
<p onclick="pluginConfig('clean');">配置修改</p>
|
||||
<p onclick="pluginLogs('clean',null,'run_log');">运行日志</p>
|
||||
<p onclick="pRead()">说明</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
@@ -16,7 +17,10 @@ pluginService('clean');
|
||||
|
||||
function pRead(){
|
||||
var readme = '<ul class="help-info-text c7">';
|
||||
readme += '<li>cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/clean/index.py clean</li>';
|
||||
readme += '<li>启动后,加入到计划中[2:30]执行。</li>';
|
||||
readme += '<li>【*】代表要删除。</li>';
|
||||
readme += '<li>添加/删除清除日志,可在`配置修改`中添加/删除。</li>';
|
||||
readme += '<li>如果是目录,会寻找【.log】后缀的文件清空。</li>';
|
||||
readme += '</ul>';
|
||||
|
||||
$('.soft-man-con').html(readme);
|
||||
|
||||
+96
-70
@@ -53,34 +53,95 @@ def getArgs():
|
||||
return tmp
|
||||
|
||||
|
||||
def getLockFile():
|
||||
return getServerDir() + "/installed_lock.pl"
|
||||
|
||||
|
||||
def runLog():
|
||||
return getServerDir() + "/clean.log"
|
||||
|
||||
|
||||
def status():
|
||||
if os.path.exists(getConf()):
|
||||
initConf()
|
||||
if os.path.exists(getLockFile()):
|
||||
return "start"
|
||||
return 'stop'
|
||||
|
||||
|
||||
def initConf():
|
||||
conf = getConf()
|
||||
if not os.path.exists(conf):
|
||||
content = ""
|
||||
|
||||
clog = [
|
||||
"/var/log/cron-*",
|
||||
"/var/log/maillog-*",
|
||||
"/var/log/secure-*",
|
||||
"/var/log/spooler-*",
|
||||
"/var/log/yum.log-*",
|
||||
"/var/log/messages-*",
|
||||
"/var/log/btmp-*",
|
||||
"/var/log/audit/audit.log.*",
|
||||
"/var/log/rhsm/rhsm.log-*",
|
||||
"/var/log/rhsm/rhsmcertd.log-*",
|
||||
"/tmp/yum_save_*",
|
||||
"/tmp/tmp.*",
|
||||
]
|
||||
for i in clog:
|
||||
content += i + "\n"
|
||||
|
||||
# 常用日志
|
||||
clogcom = [
|
||||
"/var/log/messages",
|
||||
"/var/log/btmp",
|
||||
"/var/log/wtmp",
|
||||
"/var/log/secure",
|
||||
"/var/log/lastlog",
|
||||
"/var/log/cron",
|
||||
"/www/server/cron"
|
||||
]
|
||||
for i in clogcom:
|
||||
if os.path.exists(i):
|
||||
content += i + "\n"
|
||||
|
||||
# 清理日志
|
||||
rootDir = "/var/log"
|
||||
|
||||
l = os.listdir(rootDir)
|
||||
for x in range(len(l)):
|
||||
abspath = rootDir + "/" + l[x]
|
||||
content += abspath + "\n"
|
||||
mw.writeFile(conf, content)
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
initConf()
|
||||
|
||||
lock_file = getLockFile()
|
||||
if not os.path.exists(lock_file):
|
||||
mw.writeFile(lock_file, "")
|
||||
|
||||
import tool_task
|
||||
tool_task.createBgTask()
|
||||
return 'ok'
|
||||
|
||||
return 'fail'
|
||||
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
initConf()
|
||||
lock_file = getLockFile()
|
||||
if os.path.exists(lock_file):
|
||||
os.remove(lock_file)
|
||||
import tool_task
|
||||
tool_task.removeBgTask()
|
||||
return 'ok'
|
||||
|
||||
return 'fail'
|
||||
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
return 'ok'
|
||||
|
||||
|
||||
def get_filePath_fileName_fileExt(filename):
|
||||
@@ -93,15 +154,20 @@ def cleanFileLog(path):
|
||||
filepath, shotname, extension = get_filePath_fileName_fileExt(path)
|
||||
if extension == ".log":
|
||||
cmd = "echo \"\" > " + path
|
||||
tmp = mw.execShell(cmd)
|
||||
if tmp[1] != "":
|
||||
cmd += " | error:" + tmp[1].strip()
|
||||
print(cmd)
|
||||
print(mw.execShell(cmd))
|
||||
|
||||
|
||||
def cleanSelfFileLog(path):
|
||||
filepath, shotname, extension = get_filePath_fileName_fileExt(path)
|
||||
cmd = "echo \"\" > " + path
|
||||
print(cmd)
|
||||
print(mw.execShell(cmd))
|
||||
if extension == ".log":
|
||||
cmd = "echo \"\" > " + path
|
||||
tmp = mw.execShell(cmd)
|
||||
if tmp[1] != "":
|
||||
cmd += " | error:" + tmp[1].strip()
|
||||
print(cmd)
|
||||
|
||||
|
||||
def cleanDirLog(path):
|
||||
@@ -115,70 +181,28 @@ def cleanDirLog(path):
|
||||
|
||||
|
||||
def cleanLog():
|
||||
# 清理日志
|
||||
rootDir = "/var/log"
|
||||
print("clean start")
|
||||
|
||||
clog = [
|
||||
"rm -rf /var/log/cron-*",
|
||||
"rm -rf /var/log/maillog-*",
|
||||
"rm -rf /var/log/secure-*",
|
||||
"rm -rf /var/log/spooler-*",
|
||||
"rm -rf /var/log/yum.log-*",
|
||||
"rm -rf /var/log/messages-*",
|
||||
"rm -rf /var/log/btmp-*",
|
||||
"rm -rf /var/log/audit/audit.log.*",
|
||||
"rm -rf /var/log/rhsm/rhsm.log-*",
|
||||
"rm -rf /var/log/rhsm/rhsmcertd.log-*",
|
||||
"rm -rf /tmp/yum_save_*",
|
||||
"rm -rf /tmp/tmp.*",
|
||||
]
|
||||
|
||||
for i in clog:
|
||||
print(i)
|
||||
mw.execShell(i)
|
||||
|
||||
# 常用日志
|
||||
clogcom = [
|
||||
"/var/log/messages",
|
||||
"/var/log/btmp",
|
||||
"/var/log/wtmp",
|
||||
"/var/log/secure",
|
||||
"/var/log/lastlog",
|
||||
"/var/log/cron",
|
||||
]
|
||||
for i in clogcom:
|
||||
if os.path.exists(i):
|
||||
mw.execShell("echo \"\" > " + i)
|
||||
|
||||
l = os.listdir(rootDir)
|
||||
for x in range(len(l)):
|
||||
abspath = rootDir + "/" + l[x]
|
||||
if os.path.isfile(abspath):
|
||||
cleanFileLog(abspath)
|
||||
|
||||
if os.path.isdir(abspath):
|
||||
cleanDirLog(abspath)
|
||||
|
||||
print("conf clean")
|
||||
|
||||
confFile = getServerDir()
|
||||
# mw.readFile()
|
||||
confFile = confFile + "/clean.conf"
|
||||
clist = mw.readFile(confFile).strip()
|
||||
conf = getConf()
|
||||
clist = mw.readFile(conf).strip()
|
||||
clist = clist.split("\n")
|
||||
|
||||
for x in clist:
|
||||
abspath = x.strip()
|
||||
|
||||
if abspath.find('*') > 1:
|
||||
cmd = 'rm -rf ' + abspath
|
||||
print(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
# print(data)
|
||||
continue
|
||||
|
||||
if os.path.exists(abspath):
|
||||
if os.path.isfile(abspath):
|
||||
cleanSelfFileLog(abspath)
|
||||
continue
|
||||
|
||||
if os.path.isdir(abspath):
|
||||
cleanDirLog(abspath)
|
||||
print("conf clean end")
|
||||
|
||||
print("clean end")
|
||||
continue
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
@@ -194,6 +218,8 @@ if __name__ == "__main__":
|
||||
print(reload())
|
||||
elif func == 'conf':
|
||||
print(getConf())
|
||||
elif func == 'run_log':
|
||||
print(runLog())
|
||||
elif func == 'clean':
|
||||
cleanLog()
|
||||
else:
|
||||
|
||||
@@ -13,20 +13,24 @@ serverPath=$(dirname "$rootPath")
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=$2
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
|
||||
Install_app()
|
||||
{
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/clean
|
||||
|
||||
echo "" > $serverPath/clean/clean.conf
|
||||
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/clean/index.py start
|
||||
echo "${VERSION}" > $serverPath/clean/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_app()
|
||||
{
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/clean/index.py stop
|
||||
rm -rf $serverPath/clean
|
||||
echo "Uninstall_clean" > $install_tmp
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'clean'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getTaskConf():
|
||||
conf = getServerDir() + "/task_config.json"
|
||||
return conf
|
||||
|
||||
|
||||
def getConfigData():
|
||||
try:
|
||||
return json.loads(mw.readFile(getTaskConf()))
|
||||
except:
|
||||
pass
|
||||
return []
|
||||
|
||||
|
||||
def getConfigTpl():
|
||||
tpl = {
|
||||
"name": "",
|
||||
"task_id": -1,
|
||||
}
|
||||
return tpl
|
||||
|
||||
|
||||
def createBgTask():
|
||||
removeBgTask()
|
||||
args = {
|
||||
"period": "day",
|
||||
"hour": "2",
|
||||
"minute": "30",
|
||||
}
|
||||
createBgTaskByName(getPluginName(), args)
|
||||
|
||||
|
||||
def createBgTaskByName(name, args):
|
||||
cfg = getConfigTpl()
|
||||
_name = "[勿删]日志清理[" + name + "]"
|
||||
res = mw.M("crontab").field("id, name").where("name=?", (_name,)).find()
|
||||
if res:
|
||||
return True
|
||||
|
||||
if "task_id" in cfg.keys() and cfg["task_id"] > 0:
|
||||
res = mw.M("crontab").field("id, name").where(
|
||||
"id=?", (cfg["task_id"],)).find()
|
||||
if res and res["id"] == cfg["task_id"]:
|
||||
print("计划任务已经存在!")
|
||||
return True
|
||||
import crontab_api
|
||||
api = crontab_api.crontab_api()
|
||||
|
||||
period = args['period']
|
||||
_hour = ''
|
||||
_minute = ''
|
||||
_where1 = ''
|
||||
_type_day = "day"
|
||||
if period == 'day':
|
||||
_type_day = 'day'
|
||||
_hour = args['hour']
|
||||
_minute = args['minute']
|
||||
elif period == 'minute-n':
|
||||
_type_day = 'minute-n'
|
||||
_where1 = args['minute-n']
|
||||
_minute = ''
|
||||
|
||||
mw_dir = mw.getRunDir()
|
||||
cmd = '''
|
||||
mw_dir=%s
|
||||
rname=%s
|
||||
plugin_path=%s
|
||||
script_path=%s
|
||||
logs_file=$plugin_path/${rname}.log
|
||||
''' % (mw_dir, name, getServerDir(), getPluginDir())
|
||||
cmd += 'echo "★【`date +"%Y-%m-%d %H:%M:%S"`】 STSRT★" >> $logs_file' + "\n"
|
||||
cmd += 'echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" >> $logs_file' + "\n"
|
||||
cmd += 'echo "python3 $script_path/index.py clean >> $logs_file 2>&1"' + "\n"
|
||||
cmd += 'cd $mw_dir && python3 $script_path/index.py clean >> $logs_file 2>&1' + "\n"
|
||||
cmd += 'echo "【`date +"%Y-%m-%d %H:%M:%S"`】 END★" >> $logs_file' + "\n"
|
||||
cmd += 'echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> $logs_file' + "\n"
|
||||
|
||||
params = {
|
||||
'name': _name,
|
||||
'type': _type_day,
|
||||
'week': "",
|
||||
'where1': _where1,
|
||||
'hour': _hour,
|
||||
'minute': _minute,
|
||||
'save': "",
|
||||
'backup_to': "",
|
||||
'stype': "toShell",
|
||||
'sname': '',
|
||||
'sbody': cmd,
|
||||
'urladdress': '',
|
||||
}
|
||||
|
||||
task_id = api.add(params)
|
||||
if task_id > 0:
|
||||
cfg["task_id"] = task_id
|
||||
cfg["name"] = name
|
||||
|
||||
_dd = getConfigData()
|
||||
_dd.append(cfg)
|
||||
mw.writeFile(getTaskConf(), json.dumps(_dd))
|
||||
|
||||
|
||||
def removeBgTask():
|
||||
cfg_list = getConfigData()
|
||||
for x in range(len(cfg_list)):
|
||||
cfg = cfg_list[x]
|
||||
if "task_id" in cfg.keys() and cfg["task_id"] > 0:
|
||||
res = mw.M("crontab").field("id, name").where(
|
||||
"id=?", (cfg["task_id"],)).find()
|
||||
if res and res["id"] == cfg["task_id"]:
|
||||
import crontab_api
|
||||
api = crontab_api.crontab_api()
|
||||
data = api.delete(cfg["task_id"])
|
||||
if data[0]:
|
||||
cfg["task_id"] = -1
|
||||
cfg_list[x] = cfg
|
||||
mw.writeFile(getTaskConf(), '[]')
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
action = sys.argv[1]
|
||||
if action == "remove":
|
||||
removeBgTask()
|
||||
elif action == "add":
|
||||
createBgTask()
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo `date`
|
||||
|
||||
GITADDR="{$GITROOTURL}/{$USERNAME}/{$PROJECT}.git"
|
||||
GIT_SDIR="{$CODE_DIR}"
|
||||
|
||||
GIT_USER_DIR="${GIT_SDIR}/{$USERNAME}"
|
||||
GIT_PROJECT_DIR="${GIT_USER_DIR}/{$PROJECT}"
|
||||
|
||||
|
||||
git config --global credential.helper store
|
||||
|
||||
# echo $GIT_PROJECT_DIR
|
||||
if [ ! -d $GIT_PROJECT_DIR ];then
|
||||
mkdir -p $GIT_USER_DIR && cd $GIT_USER_DIR
|
||||
git clone $GITADDR
|
||||
fi
|
||||
|
||||
unset GIT_DIR
|
||||
cd $GIT_PROJECT_DIR && git pull
|
||||
|
||||
# func 2
|
||||
# cd $GIT_PROJECT_DIR && env -i git pull origin master
|
||||
|
||||
|
||||
#更新的目的地址
|
||||
WEB_PATH={$WEB_ROOT}/{$USERNAME}/{$PROJECT}
|
||||
mkdir -p $WEB_PATH
|
||||
|
||||
rsync -vauP --delete --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
|
||||
sysName=`uname`
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
USER=$(who | sed -n "2,1p" |awk '{print $1}')
|
||||
chown -R $USER:staff $WEB_PATH
|
||||
else
|
||||
chown -R www:www $WEB_PATH
|
||||
fi
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo `date`
|
||||
|
||||
GITADDR="{$GITROOTURL}/{$USERNAME}/{$PROJECT}"
|
||||
GIT_SDIR="{$CODE_DIR}"
|
||||
|
||||
GIT_USER_DIR="${GIT_SDIR}/{$USERNAME}"
|
||||
GIT_PROJECT_DIR="${GIT_USER_DIR}/{$PROJECT}"
|
||||
|
||||
# echo $GIT_PROJECT_DIR
|
||||
if [ ! -d $GIT_PROJECT_DIR ];then
|
||||
mkdir -p $GIT_USER_DIR && cd $GIT_USER_DIR
|
||||
git clone $GITADDR
|
||||
fi
|
||||
|
||||
unset GIT_DIR
|
||||
cd $GIT_PROJECT_DIR && git pull
|
||||
|
||||
# func 2
|
||||
# cd $GIT_PROJECT_DIR && env -i git pull origin master
|
||||
|
||||
|
||||
|
||||
WEB_PATH={$WEB_ROOT}/{$USERNAME}/{$PROJECT}
|
||||
mkdir -p $WEB_PATH
|
||||
|
||||
rsync -vauP --delete --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
|
||||
sysName=`uname`
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
USER=$(who | sed -n "2,1p" |awk '{print $1}')
|
||||
chown -R $USER:staff $WEB_PATH
|
||||
else
|
||||
chown -R www:www $WEB_PATH
|
||||
fi
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
sh -x {$PATH}/commit 2>{$PATH}/sh.log
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('gitea');">服务</p>
|
||||
<p onclick="pluginInitD('gitea');">自启动</p>
|
||||
<!-- <p onclick="pluginConfig('gitea',null, 'init_conf');">启动配置</p> -->
|
||||
<p onclick="gogsEdit();">手动编辑</p>
|
||||
<p onclick="pluginConfig('gitea',null, 'conf');">配置文件</p>
|
||||
<p onclick="gogsSetConfig();">配置修改</p>
|
||||
<p onclick="giteaUserList();">用户列表</p>
|
||||
<p onclick="pluginLogs('gitea',null,'run_log');">运行日志</p>
|
||||
<p onclick="pluginLogs('gitea',null,'post_receive_log');" title="提交post-receive日志">提交日志</p>
|
||||
<p onclick="giteaRead();">使用说明</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=gitea&f=js/gitea.js",function(){
|
||||
pluginService('gitea');
|
||||
});
|
||||
</script>
|
||||
@@ -11,11 +11,10 @@ sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
|
||||
cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\''
|
||||
info = mw.execShell(cmd)
|
||||
p = "/usr/local/lib/" + info[0].strip() + "/site-packages"
|
||||
sys.path.append(p)
|
||||
import psutil
|
||||
# cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\''
|
||||
# info = mw.execShell(cmd)
|
||||
# p = "/usr/local/lib/" + info[0].strip() + "/site-packages"
|
||||
# sys.path.append(p)
|
||||
|
||||
|
||||
app_debug = False
|
||||
@@ -24,15 +23,12 @@ if mw.isAppleSystem():
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'gogs'
|
||||
return 'gitea'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
import mysqlDb
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
@@ -61,18 +57,28 @@ def getArgs():
|
||||
return tmp
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getInitdConfTpl():
|
||||
path = getPluginDir() + "/init.d/gogs.tpl"
|
||||
path = getPluginDir() + "/init.d/gitea.tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getInitdConf():
|
||||
path = getServerDir() + "/init.d/gogs"
|
||||
path = getServerDir() + "/init.d/gitea"
|
||||
return path
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + "/custom/conf/app.ini"
|
||||
|
||||
if not os.path.exists(path):
|
||||
return mw.returnJson(False, "请先安装初始化!<br/>默认地址:http://" + mw.getLocalIp() + ":3000")
|
||||
return path
|
||||
|
||||
|
||||
@@ -95,7 +101,7 @@ def getHomeDir():
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return '/Users/' + user
|
||||
else:
|
||||
return '/root'
|
||||
return 'git'
|
||||
|
||||
|
||||
def getRunUser():
|
||||
@@ -104,7 +110,7 @@ def getRunUser():
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return user
|
||||
else:
|
||||
return 'root'
|
||||
return 'git'
|
||||
|
||||
__SR = '''#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
@@ -140,13 +146,16 @@ def initDreplace():
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
conf_bin = getConf()
|
||||
if not os.path.exists(conf_bin):
|
||||
mw.execShell('mkdir -p ' + getServerDir() + '/custom/conf')
|
||||
conf_tpl = getConfTpl()
|
||||
content = mw.readFile(conf_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(conf_bin, content)
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/gitea.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/gitea.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
service_path = mw.getServerDir()
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(systemService, se_content)
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
log_path = getServerDir() + '/log'
|
||||
if not os.path.exists(log_path):
|
||||
@@ -159,9 +168,14 @@ def getRootUrl():
|
||||
content = mw.readFile(getConf())
|
||||
rep = 'ROOT_URL\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
if not tmp:
|
||||
return ''
|
||||
return tmp.groups()[0]
|
||||
if tmp:
|
||||
return tmp.groups()[0]
|
||||
|
||||
rep = 'EXTERNAL_URL\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
if tmp:
|
||||
return tmp.groups()[0]
|
||||
return ''
|
||||
|
||||
|
||||
def getSshPort():
|
||||
@@ -192,8 +206,11 @@ def getRootPath():
|
||||
|
||||
|
||||
def getDbConfValue():
|
||||
content = mw.readFile(getConf())
|
||||
conf = getConf()
|
||||
if not os.path.exists(conf):
|
||||
return {}
|
||||
|
||||
content = mw.readFile(conf)
|
||||
rep_scope = "\[database\](.*?)\["
|
||||
tmp = re.findall(rep_scope, content, re.S)
|
||||
|
||||
@@ -207,18 +224,72 @@ def getDbConfValue():
|
||||
return r
|
||||
|
||||
|
||||
def pMysqlDb():
|
||||
conf = getDbConfValue()
|
||||
|
||||
def pMysqlDb(conf):
|
||||
host = conf['HOST'].split(':')
|
||||
conn = mysqlDb.mysqlDb()
|
||||
# pymysql
|
||||
db = mw.getMyORM()
|
||||
# MySQLdb |
|
||||
# db = mw.getMyORMDb()
|
||||
|
||||
conn.setHost(host[0])
|
||||
conn.setUser(conf['USER'])
|
||||
conn.setPwd(conf['PASSWD'])
|
||||
conn.setPort(int(host[1]))
|
||||
conn.setDb(conf['NAME'])
|
||||
return conn
|
||||
db.setPort(int(host[1]))
|
||||
db.setUser(conf['USER'])
|
||||
|
||||
if 'PASSWD' in conf:
|
||||
db.setPwd(conf['PASSWD'])
|
||||
else:
|
||||
db.setPwd(conf['PASSWORD'])
|
||||
|
||||
db.setDbName(conf['NAME'])
|
||||
# db.setSocket(getSocketFile())
|
||||
db.setCharset("utf8")
|
||||
return db
|
||||
|
||||
|
||||
def pSqliteDb(conf):
|
||||
# print(conf)
|
||||
import db
|
||||
psDb = db.Sql()
|
||||
|
||||
# 默认
|
||||
gsdir = getServerDir() + '/data'
|
||||
dbname = 'gitea'
|
||||
if conf['PATH'][0] == '/':
|
||||
# 绝对路径
|
||||
pass
|
||||
else:
|
||||
path = conf['PATH'].split('/')
|
||||
gsdir = getServerDir() + '/' + path[0]
|
||||
dbname = path[1].split('.')[0]
|
||||
|
||||
# print(gsdir, dbname)
|
||||
psDb.dbPos(gsdir, dbname)
|
||||
return psDb
|
||||
|
||||
|
||||
def getGiteaDbType(conf):
|
||||
|
||||
if 'DB_TYPE' in conf:
|
||||
return conf['DB_TYPE']
|
||||
|
||||
if 'TYPE' in conf:
|
||||
return conf['TYPE']
|
||||
|
||||
return 'NONE'
|
||||
|
||||
|
||||
def pQuery(sql):
|
||||
conf = getDbConfValue()
|
||||
gtype = getGiteaDbType(conf)
|
||||
if gtype == 'sqlite3':
|
||||
db = pSqliteDb(conf)
|
||||
data = db.query(sql, []).fetchall()
|
||||
return data
|
||||
elif gtype == 'mysql':
|
||||
db = pMysqlDb(conf)
|
||||
return db.query(sql)
|
||||
|
||||
print("仅支持mysql|sqlite3配置")
|
||||
exit(0)
|
||||
|
||||
|
||||
def isSqlError(mysqlMsg):
|
||||
@@ -244,93 +315,66 @@ def isSqlError(mysqlMsg):
|
||||
return mw.returnData(True, 'OK')
|
||||
|
||||
|
||||
def start():
|
||||
|
||||
is_frist = True
|
||||
conf_bin = getConf()
|
||||
if os.path.exists(conf_bin):
|
||||
is_frist = False
|
||||
|
||||
def appOp(method):
|
||||
file = initDreplace()
|
||||
|
||||
if is_frist:
|
||||
return "第一次启动Gogs,默认使用MySQL连接!<br>可以在配置文件中重新设置,再启动!"
|
||||
if not mw.isAppleSystem():
|
||||
data = mw.execShell('systemctl ' + method + ' ' + getPluginName())
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
conn = pMysqlDb()
|
||||
list_table = conn.query('show tables')
|
||||
data = isSqlError(list_table)
|
||||
if not data['status']:
|
||||
return data['msg']
|
||||
|
||||
data = mw.execShell(__SR + file + ' start')
|
||||
data = mw.execShell(__SR + file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[0]
|
||||
|
||||
|
||||
def start():
|
||||
return appOp('start')
|
||||
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = mw.execShell(__SR + file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
return appOp('stop')
|
||||
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = mw.execShell(__SR + file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
return appOp('restart')
|
||||
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = mw.execShell(__SR + file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
return appOp('reload')
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
shell_cmd = 'systemctl status gitea | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'fail'
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mem_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(mem_bin, initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('systemctl enable gitea')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl disable gitea')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runLog():
|
||||
log_path = getServerDir() + '/log/gogs.log'
|
||||
log_path = getServerDir() + '/log/gitea.log'
|
||||
return log_path
|
||||
|
||||
|
||||
@@ -340,6 +384,10 @@ def postReceiveLog():
|
||||
|
||||
|
||||
def getGogsConf():
|
||||
conf = getConf()
|
||||
if not os.path.exists(conf):
|
||||
return mw.returnJson(False, "请先安装初始化!<br/>默认地址:http://" + mw.getLocalIp() + ":3000")
|
||||
|
||||
gets = [
|
||||
{'name': 'DOMAIN', 'type': -1, 'ps': '服务器域名'},
|
||||
{'name': 'ROOT_URL', 'type': -1, 'ps': '公开的完整URL路径'},
|
||||
@@ -360,7 +408,7 @@ def getGogsConf():
|
||||
{'name': 'SHOW_FOOTER_VERSION', 'type': 2, 'ps': 'Gogs版本信息'},
|
||||
{'name': 'SHOW_FOOTER_TEMPLATE_LOAD_TIME', 'type': 2, 'ps': 'Gogs模板加载时间'},
|
||||
]
|
||||
conf = mw.readFile(getConf())
|
||||
conf = mw.readFile(conf)
|
||||
result = []
|
||||
|
||||
for g in gets:
|
||||
@@ -370,7 +418,7 @@ def getGogsConf():
|
||||
continue
|
||||
g['value'] = tmp.groups()[0]
|
||||
result.append(g)
|
||||
return mw.getJson(result)
|
||||
return mw.returnJson(True, 'OK', result)
|
||||
|
||||
|
||||
def submitGogsConf():
|
||||
@@ -402,18 +450,27 @@ def submitGogsConf():
|
||||
|
||||
|
||||
def userList():
|
||||
|
||||
conf = getConf()
|
||||
if not os.path.exists(conf):
|
||||
return mw.returnJson(False, "请先安装初始化!<br/>默认地址:http://" + mw.getLocalIp() + ":3000")
|
||||
|
||||
conf = getDbConfValue()
|
||||
gtype = getGiteaDbType(conf)
|
||||
if gtype != 'mysql':
|
||||
return mw.returnJson(False, "仅支持mysql数据操作!")
|
||||
|
||||
import math
|
||||
args = getArgs()
|
||||
|
||||
page = 1
|
||||
page_size = 10
|
||||
data = checkArgs(args, ['page', 'page_size'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
page = int(args['page'])
|
||||
page_size = int(args['page_size'])
|
||||
tojs = args['tojs']
|
||||
search = ''
|
||||
if 'page' in args:
|
||||
page = int(args['page'])
|
||||
|
||||
if 'page_size' in args:
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
if 'search' in args:
|
||||
search = args['search']
|
||||
|
||||
@@ -421,17 +478,14 @@ def userList():
|
||||
|
||||
data['root_url'] = getRootUrl()
|
||||
|
||||
pm = pMysqlDb()
|
||||
start = (page - 1) * page_size
|
||||
list_count = pm.query('select count(id) as num from user')
|
||||
count = list_count[0][0]
|
||||
list_count = pQuery('select count(id) as num from user')
|
||||
|
||||
list_data = pm.query(
|
||||
count = list_count[0]["num"]
|
||||
list_data = pQuery(
|
||||
'select id,name,email from user order by id desc limit ' + str(start) + ',' + str(page_size))
|
||||
|
||||
page_info = {'count': count, 'p': page,
|
||||
'row': page_size, 'tojs': 'gogsUserList'}
|
||||
data['list'] = mw.getPage(page_info)
|
||||
data['list'] = mw.getPage(
|
||||
{'count': count, 'p': page, 'row': page_size, 'tojs': tojs})
|
||||
data['page'] = page
|
||||
data['page_size'] = page_size
|
||||
data['page_count'] = int(math.ceil(count / page_size))
|
||||
@@ -556,8 +610,8 @@ def projectScriptLoad():
|
||||
|
||||
cc_content = mw.readFile(commit_tpl)
|
||||
|
||||
sshUrl = 'http://127.0.0.1:' + getHttpPort()
|
||||
cc_content = cc_content.replace('{$GITROOTURL}', sshUrl)
|
||||
gitPath = getRootPath()
|
||||
cc_content = cc_content.replace('{$GITROOTURL}', gitPath)
|
||||
cc_content = cc_content.replace('{$CODE_DIR}', codeDir)
|
||||
cc_content = cc_content.replace('{$USERNAME}', user)
|
||||
cc_content = cc_content.replace('{$PROJECT}', args['name'])
|
||||
@@ -570,11 +624,9 @@ def projectScriptLoad():
|
||||
|
||||
def projectScriptUnload():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return mw.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return mw.returnJson(True, 'project name missing')
|
||||
data = checkArgs(args, ['user', 'name'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
@@ -591,11 +643,10 @@ def projectScriptUnload():
|
||||
|
||||
def projectScriptDebug():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return mw.returnJson(True, 'username missing')
|
||||
data = checkArgs(args, ['user', 'name'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
if not 'name' in args:
|
||||
return mw.returnJson(True, 'project name missing')
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
commit_log = getRootPath() + '/' + user + '/' + name + \
|
||||
@@ -634,14 +685,8 @@ def getTotalStatistics():
|
||||
st = status()
|
||||
data = {}
|
||||
if st.strip() == 'start':
|
||||
pm = pMysqlDb()
|
||||
list_count = pm.query('select count(id) as num from repository')
|
||||
|
||||
if list_count.find("error") > -1:
|
||||
data['status'] = False
|
||||
data['count'] = 0
|
||||
return mw.returnJson(False, 'fail', data)
|
||||
|
||||
list_count = pQuery('select count(id) as num from repository')
|
||||
count = list_count[0]["num"]
|
||||
data['status'] = True
|
||||
data['count'] = count
|
||||
data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip()
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"ps": "Gitea 是一个开源社区驱动的轻量级代码托管解决方案。",
|
||||
"name": "gitea",
|
||||
"title": "Gitea",
|
||||
"versions": ["1.17.2"],
|
||||
"tip": "soft",
|
||||
"checks": "server/gitea",
|
||||
"path":"server/gitea",
|
||||
"author": "gitea",
|
||||
"date": "2022-10-03",
|
||||
"home": "https://dl.gitea.io/",
|
||||
"type": "Git服务器",
|
||||
"shell": "install.sh",
|
||||
"pid": "3",
|
||||
"sort": 7
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
[Unit]
|
||||
Description=Gitea (Git with a cup of tea)
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=simple
|
||||
User=git
|
||||
Group=git
|
||||
WorkingDirectory={$SERVER_PATH}/gitea
|
||||
ExecStart={$SERVER_PATH}/gitea/gitea web
|
||||
Restart=always
|
||||
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
|
||||
RemainAfterExit=yes
|
||||
#AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,110 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# /etc/rc.d/init.d/Gitea
|
||||
#
|
||||
# Runs the Gogs
|
||||
#
|
||||
#
|
||||
# chkconfig: - 85 15
|
||||
#
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: Gitea
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Should-Start: mysql postgresql
|
||||
# Should-Stop: mysql postgresql
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Start Gitea at boot time.
|
||||
# Description: Control Gitea.
|
||||
### END INIT INFO
|
||||
|
||||
# Source function library.
|
||||
if [ -f /etc/init.d/functions ];then
|
||||
. /etc/init.d/functions
|
||||
fi
|
||||
|
||||
if [ -f /etc/rc.d/init.d/functions ];then
|
||||
. /etc/rc.d/init.d/functions
|
||||
fi
|
||||
|
||||
# Default values
|
||||
export HOME={$HOME_DIR}
|
||||
export USER={$RUN_USER}
|
||||
NAME=gitea
|
||||
GOGS_HOME={$SERVER_PATH}/gitea
|
||||
GOGS_PATH=${GOGS_HOME}/$NAME
|
||||
GOGS_USER={$RUN_USER}
|
||||
SERVICENAME="gitea"
|
||||
LOCKFILE=/tmp/gitea.lock
|
||||
LOGPATH=${GOGS_HOME}/log
|
||||
LOGFILE=${LOGPATH}/gitea.log
|
||||
RETVAL=0
|
||||
|
||||
|
||||
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
||||
DAEMON_OPTS="--check $NAME"
|
||||
[ ! -z "$GOGS_USER" ] && DAEMON_OPTS="$DAEMON_OPTS --user=${GOGS_USER}"
|
||||
|
||||
|
||||
status(){
|
||||
isStart=`ps -ef|grep 'gitea web' |grep -v grep|awk '{print $2}'`
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "${SERVICENAME} not running"
|
||||
else
|
||||
echo -e "${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
isStart=`ps -ef|grep 'gitea web' |grep -v grep|awk '{print $2}'`
|
||||
if [ "$isStart" != '' ];then
|
||||
echo "${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
return $RETVAL
|
||||
fi
|
||||
|
||||
cd ${GOGS_HOME}
|
||||
echo -e "Starting ${SERVICENAME}: \c"
|
||||
${GOGS_PATH} web > ${LOGFILE} 2>&1 &
|
||||
RETVAL=$?
|
||||
[ $RETVAL = 0 ] && touch ${LOCKFILE} && echo -e "\033[32mdone\033[0m"
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
||||
pids=`ps -ef|grep 'gitea web' |grep -v grep|awk '{print $2}'`
|
||||
arr=($pids)
|
||||
echo -e "Stopping gitea... \c"
|
||||
for p in ${arr[@]}
|
||||
do
|
||||
kill -9 $p
|
||||
done
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
reload)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: ${NAME} {start|stop|status|restart}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
exit $RETVAL
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
|
||||
URL_DOWNLOAD=https://dl.gitea.io/
|
||||
|
||||
getOs(){
|
||||
os=`uname`
|
||||
if [ "Darwin" == "$os" ];then
|
||||
echo 'darwin'
|
||||
else
|
||||
echo 'linux'
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
getBit(){
|
||||
echo `getconf LONG_BIT`
|
||||
}
|
||||
|
||||
|
||||
Install_App()
|
||||
{
|
||||
mkdir -p $serverPath/source/gitea
|
||||
|
||||
|
||||
if id git &> /dev/null ;then
|
||||
echo "git UID is `id -u git`"
|
||||
echo "git Shell is `grep "^git:" /etc/passwd |cut -d':' -f7 `"
|
||||
else
|
||||
groupadd git
|
||||
useradd -g git git
|
||||
fi
|
||||
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
version=$1
|
||||
os=`getOs`
|
||||
|
||||
git config --global push.default simple
|
||||
|
||||
if [ "darwin" == "$os" ];then
|
||||
file=gitea-${version}-darwin-10.12-amd64
|
||||
else
|
||||
file=gitea-${version}-linux-amd64
|
||||
fi
|
||||
|
||||
file_xz="${file}.xz"
|
||||
echo "wget -O $serverPath/source/gitea/$file_xz ${URL_DOWNLOAD}/gitea/${version}/${file_xz}"
|
||||
if [ ! -f $serverPath/source/gitea/$file_xz ];then
|
||||
wget -O $serverPath/source/gitea/$file_xz ${URL_DOWNLOAD}/gitea/${version}/${file_xz}
|
||||
fi
|
||||
|
||||
cd $serverPath/source/gitea && xz -k -d $file_xz
|
||||
if [ -f $file ];then
|
||||
mkdir -p $serverPath/gitea
|
||||
mv $serverPath/source/gitea/$file $serverPath/gitea/gitea
|
||||
chmod +x $serverPath/gitea/gitea
|
||||
|
||||
chown -R git:git $serverPath/gitea
|
||||
fi
|
||||
|
||||
|
||||
if [ -d $serverPath/gitea ];then
|
||||
echo $version > $serverPath/gitea/version.pl
|
||||
|
||||
cd ${rootPath} && python3 plugins/gitea/index.py start
|
||||
cd ${rootPath} && python3 plugins/gitea/index.py initd_install
|
||||
fi
|
||||
|
||||
echo 'install success' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
|
||||
if [ -f /usr/lib/systemd/system/gitea.service ];then
|
||||
systemctl stop gitea
|
||||
systemctl disable gitea
|
||||
rm -rf /usr/lib/systemd/system/gitea.service
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
if [ -f $serverPath/gitea/initd/gitea ];then
|
||||
$serverPath/gitea/initd/gitea stop
|
||||
fi
|
||||
|
||||
rm -rf $serverPath/gitea
|
||||
echo 'uninstall success' > $install_tmp
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
version=$2
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App $version
|
||||
else
|
||||
Uninstall_App $version
|
||||
fi
|
||||
Executable
+353
@@ -0,0 +1,353 @@
|
||||
|
||||
function str2Obj(str){
|
||||
var data = {};
|
||||
kv = str.split('&');
|
||||
for(i in kv){
|
||||
v = kv[i].split('=');
|
||||
data[v[0]] = v[1];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function gogsPost(method,args,callback, title){
|
||||
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(str2Obj(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
|
||||
var _title = '正在获取...';
|
||||
if (typeof(title) != 'undefined'){
|
||||
_title = title;
|
||||
}
|
||||
|
||||
var loadT = layer.msg(_title, { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'gitea', func:method, args:_args}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function gogsSetConfig(){
|
||||
gogsPost('get_gogs_conf', '', function(data){
|
||||
var rrdata = $.parseJSON(data.data);
|
||||
if (!rrdata.status){
|
||||
layer.msg(rrdata.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
var rdata = rrdata.data;
|
||||
var mlist = '';
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
var w = '140';
|
||||
if (rdata[i].name == 'error_reporting') w = '250';
|
||||
var ibody = '<input style="width: ' + w + 'px;" class="bt-input-text mr5" name="' + rdata[i].name + '" value="' + rdata[i].value + '" type="text" >';
|
||||
switch (rdata[i].type) {
|
||||
case 0:
|
||||
var selected_1 = (rdata[i].value == 1) ? 'selected' : '';
|
||||
var selected_0 = (rdata[i].value == 0) ? 'selected' : '';
|
||||
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\
|
||||
<option value="1" ' + selected_1 + '>开启</option>\
|
||||
<option value="0" ' + selected_0 + '>关闭</option>\
|
||||
</select>';
|
||||
break;
|
||||
case 1:
|
||||
var selected_1 = (rdata[i].value == 'On') ? 'selected' : '';
|
||||
var selected_0 = (rdata[i].value == 'Off') ? 'selected' : '';
|
||||
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\
|
||||
<option value="On" ' + selected_1 + '>开启</option>\
|
||||
<option value="Off" ' + selected_0 + '>关闭</option></select>'
|
||||
break;
|
||||
case 2:
|
||||
var selected_1 = (rdata[i].value == 'true') ? 'selected' : '';
|
||||
var selected_0 = (rdata[i].value == 'false') ? 'selected' : '';
|
||||
ibody = '<select class="bt-input-text mr5" name="' + rdata[i].name + '" style="width: ' + w + 'px;">\
|
||||
<option value="true" ' + selected_1 + '>开启</option>\
|
||||
<option value="false" ' + selected_0 + '>关闭</option></select>'
|
||||
break;
|
||||
}
|
||||
mlist += '<p><span>' + rdata[i].name + '</span>' + ibody + ', <font>' + rdata[i].ps + '</font></p>'
|
||||
}
|
||||
var html = '<style>.conf_p p{margin-bottom: 2px}</style><div class="conf_p" style="margin-bottom:0">\
|
||||
' + mlist + '\
|
||||
<div style="margin-top:10px; padding-right:15px" class="text-right">\
|
||||
<button class="btn btn-success btn-sm mr5" onclick="gogsSetConfig()">刷新</button>\
|
||||
<button class="btn btn-success btn-sm" onclick="submitGogsConf()">保存</button></div>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(html);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//提交PHP配置
|
||||
function submitGogsConf() {
|
||||
var data = {
|
||||
DOMAIN: $("input[name='DOMAIN']").val(),
|
||||
ROOT_URL: $("input[name='ROOT_URL']").val(),
|
||||
HTTP_ADDR: $("select[name='HTTP_ADDR']").val(),
|
||||
HTTP_PORT: $("input[name='HTTP_PORT']").val(),
|
||||
START_SSH_SERVER: $("select[name='START_SSH_SERVER']").val() || 'false',
|
||||
SSH_PORT: $("input[name='SSH_PORT']").val(),
|
||||
REQUIRE_SIGNIN_VIEW: $("select[name='REQUIRE_SIGNIN_VIEW']").val() || 'false',
|
||||
ENABLE_CAPTCHA: $("select[name='ENABLE_CAPTCHA']").val() || 'true',
|
||||
DISABLE_REGISTRATION: $("select[name='DISABLE_REGISTRATION']").val() || 'false',
|
||||
ENABLE_NOTIFY_MAIL: $("select[name='ENABLE_NOTIFY_MAIL']").val() || 'false',
|
||||
FORCE_PRIVATE: $("select[name='FORCE_PRIVATE']").val() || 'false',
|
||||
SHOW_FOOTER_BRANDING: $("select[name='SHOW_FOOTER_BRANDING']").val() || 'false',
|
||||
SHOW_FOOTER_VERSION: $("select[name='SHOW_FOOTER_VERSION']").val() || 'false',
|
||||
SHOW_FOOTER_TEMPLATE_LOAD_TIME: $("select[name='SHOW_FOOTER_TEMPLATE_LOAD_TIME']").val() || 'false',
|
||||
};
|
||||
|
||||
gogsPost('submit_gogs_conf', data, function(ret_data){
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
gogsSetConfig();
|
||||
});
|
||||
}
|
||||
|
||||
function gogsEdit(){
|
||||
|
||||
gogsPost('gogs_edit',{} , function(data){
|
||||
// console.log(data);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var edit = '<p class="status">通用的手动编辑:</p>';
|
||||
edit +='<div class="sfm-opt">\
|
||||
<button class="btn btn-default btn-sm" onclick="onlineEditFile(0,\''+rdata['post_receive']+'\');">post-receive.tpl</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="onlineEditFile(0,\''+rdata['commit']+'\');">commit.tpl</button>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(edit);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function giteaUserList(page, search) {
|
||||
|
||||
var _data = {};
|
||||
if (typeof(page) =='undefined'){
|
||||
var page = 1;
|
||||
}
|
||||
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 10;
|
||||
if(typeof(search) != 'undefined'){
|
||||
_data['search'] = search;
|
||||
}
|
||||
_data['tojs'] = 'giteaUserList';
|
||||
|
||||
gogsPost('user_list', _data, function(data){
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (!rdata.status){
|
||||
layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
content = '<div class="finduser"><input class="bt-input-text mr5 outline_no" type="text" placeholder="查找用户名" id="find_user" style="height: 28px; border-radius: 3px;width: 435px;">';
|
||||
content += '<button class="btn btn-success btn-sm" onclick="userFind();">查找</button></div>';
|
||||
|
||||
content += '<div class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
|
||||
content += '<thead><tr>';
|
||||
content += '<th>序号</th>';
|
||||
content += '<th>用户或组织</th>';
|
||||
content += '<th>邮件地址</th>';
|
||||
content += '<th>操作(<a href="'+rdata['data']['root_url']+'" class="btlink" target="_blank">WEB管理</a>)</th>';
|
||||
content += '</tr></thead>';
|
||||
|
||||
content += '<tbody>';
|
||||
|
||||
ulist = rdata['data']['data'];
|
||||
for (i in ulist){
|
||||
email = ulist[i]["email"] == '' ? '无' : ulist[i]["email"];
|
||||
content += '<tr><td>'+ulist[i]["id"]+'</td>'+
|
||||
'<td>'+ulist[i]["name"]+'</td>'+
|
||||
'<td>'+email+'</td>'+
|
||||
'<td><a class="btlink" onclick="userProjectList(\''+ulist[i]["name"]+'\')">项目管理</a></td>'+
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
content += '</tbody>';
|
||||
content += '</table></div>';
|
||||
|
||||
var page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata['data']['list'];
|
||||
page += '</div></ul></div>';
|
||||
|
||||
content += page;
|
||||
|
||||
$(".soft-man-con").html(content);
|
||||
});
|
||||
}
|
||||
|
||||
function userProjectList(user, search){
|
||||
var req = {};
|
||||
if (!isNaN(user)){
|
||||
req['page'] = user;
|
||||
req['name'] = user = getCookie('gogsUserSelected');
|
||||
} else {
|
||||
req['page'] = 1;
|
||||
req['name'] = user;
|
||||
setCookie('gogsUserSelected', user);
|
||||
}
|
||||
|
||||
req['page_size'] = 5;
|
||||
req['search'] = '';
|
||||
if(typeof(search) != 'undefined'){
|
||||
req['search'] = search;
|
||||
}
|
||||
|
||||
$('.layui-layer-close1').click();
|
||||
gogsPost('user_project_list', req, function(data){
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
} catch(e){}
|
||||
|
||||
if (!rdata['status']){
|
||||
layer.msg(rdata['msg'], { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
var list = '';
|
||||
// console.log(rdata);
|
||||
var project_list = rdata['data']['data'];
|
||||
for (i in project_list) {
|
||||
var name = project_list[i]['name'];
|
||||
list += '<tr><td>'+name+'</td>\
|
||||
<td>\
|
||||
<a class="btlink" target="_blank" href="'+rdata['data']['root_url']+user+'/'+name+'">源码</a> | \
|
||||
<a class="btlink" onclick="projectScript(\''+user+'\',\''+name+'\','+project_list[i]['has_hook']+');">脚本</a>\
|
||||
</td>\
|
||||
</tr>';
|
||||
}
|
||||
|
||||
var page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata['data']['list'];
|
||||
page += '</div></ul></div>';
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '用户('+user+')项目列表',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div>\
|
||||
<div class='divtable' style='margin-top:5px;'>\
|
||||
<table class='table table-hover'>\
|
||||
<thead><tr><th>项目</th><th>操作</th></tr></thead>\
|
||||
<tbody>" + list + "</tbody>\
|
||||
</table>" +
|
||||
page +
|
||||
"</div></div></div>"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function projectScript(user, name,has_hook){
|
||||
// console.log(user,name,has_hook);
|
||||
var html = '';
|
||||
if (has_hook){
|
||||
html += '<button onclick="projectScriptEdit(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">手动编辑</button>';
|
||||
html += '<button onclick="projectScriptDebug(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">调试日志</button>';
|
||||
html += '<button onclick="projectScriptLoad(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">重新加载</button>';
|
||||
html += '<button onclick="projectScriptUnload(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">卸载脚本</button>';
|
||||
} else {
|
||||
html += '<button onclick="projectScriptLoad(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">加载脚本</button>';
|
||||
}
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '['+user+']['+name+']脚本设置',
|
||||
area: '240px',
|
||||
content:'<div class="change-default pd20">'+html+'</div>'
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptEdit(user,name){
|
||||
gogsPost('project_script_edit', {'user':user,'name':name}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata['status']){
|
||||
onlineEditFile(0, rdata['data']['path']);
|
||||
} else {
|
||||
layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptLoad(user,name){
|
||||
gogsPost('project_script_load', {'user':user,'name':name}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
layer.msg('加载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
setTimeout(function(){
|
||||
userProjectList(1);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptUnload(user,name){
|
||||
gogsPost('project_script_unload', {'user':user,'name':name}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
layer.msg('卸载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
setTimeout(function(){
|
||||
userProjectList(1);
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptDebug(user,name){
|
||||
gogsPost('project_script_debug', {'user':user,'name':name}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata['status']){
|
||||
onlineEditFile(0, rdata['path']);
|
||||
} else {
|
||||
layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getRsaPublic(){
|
||||
gogsPost('get_rsa_public', {}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var con = '<div class="tab-con">\
|
||||
<div class="myKeyCon ptb15">\
|
||||
<textarea style="margin:0px;width:580px;height:110px;outline:none;" spellcheck="false">'+rdata.mw+'</textarea>\
|
||||
</div>\
|
||||
<ul class="help-info-text c7 pull-left"></ul>\
|
||||
</div>'
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: "600px",
|
||||
title: '本机公钥',
|
||||
closeBtn: 2,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
content:con
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function giteaRead(){
|
||||
|
||||
var readme = '<ul class="help-info-text c7">';
|
||||
readme += '<li>默认使用MySQL,第一个启动加载各种配置,并修改成正确的数据库配置</li>';
|
||||
readme += '<li>邮件端口使用456,gogs仅支持使用STARTTLS的SMTP协议</li>';
|
||||
readme += '<li>如果使用项目中脚本本地同步,<a target="_blank" href="https://github.com/midoks/mdserver-web/wiki/%E6%8F%92%E4%BB%B6%E7%AE%A1%E7%90%86%5Bgogs%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%5D#%E5%90%AF%E5%8A%A8gogs%E5%90%8E%E5%A6%82%E6%9E%9C%E8%A6%81%E4%BD%BF%E7%94%A8hook%E8%84%9A%E6%9C%AC%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E9%9C%80%E8%A6%81%E5%BC%80%E5%90%AFssh%E7%AB%AF%E5%8F%A3">点击查看</></li>';
|
||||
readme += '<li><a href="#" onclick="getRsaPublic();">点击查看本机公钥</></li>';
|
||||
readme += '</ul>';
|
||||
|
||||
$('.soft-man-con').html(readme);
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
# coding: utf-8
|
||||
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
|
||||
# sys.path.append("/usr/local/lib/python3.6/site-packages")
|
||||
|
||||
|
||||
class mysqlDb:
|
||||
__DB_PASS = None
|
||||
__DB_USER = 'root'
|
||||
__DB_PORT = 3306
|
||||
__DB_HOST = 'localhost'
|
||||
__DB_NAME = 'test'
|
||||
__DB_CONN = None
|
||||
__DB_CUR = None
|
||||
__DB_ERR = None
|
||||
__DB_CNF = '/etc/my.cnf'
|
||||
|
||||
def __Conn(self):
|
||||
'''连接MYSQL数据库'''
|
||||
try:
|
||||
socket = '/www/server/mysql/mysql.sock'
|
||||
try:
|
||||
import MySQLdb
|
||||
except Exception as ex:
|
||||
self.__DB_ERR = ex
|
||||
return False
|
||||
try:
|
||||
self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
|
||||
port=self.__DB_PORT, db=self.__DB_NAME, charset="utf8", connect_timeout=10, unix_socket=socket)
|
||||
except MySQLdb.Error as e:
|
||||
self.__DB_HOST = '127.0.0.1'
|
||||
self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
|
||||
port=self.__DB_PORT, db=self.__DB_NAME, charset="utf8", connect_timeout=10, unix_socket=socket)
|
||||
self.__DB_CUR = self.__DB_CONN.cursor()
|
||||
return True
|
||||
|
||||
except MySQLdb.Error as e:
|
||||
self.__DB_ERR = e
|
||||
return False
|
||||
|
||||
def setHost(self, host):
|
||||
self.__DB_HOST = host
|
||||
|
||||
def setPwd(self, pwd):
|
||||
self.__DB_PASS = pwd
|
||||
|
||||
def setUser(self, user):
|
||||
self.__DB_USER = user
|
||||
|
||||
def setPort(self, port):
|
||||
self.__DB_PORT = port
|
||||
|
||||
def setDb(self, name):
|
||||
self.__DB_NAME = name
|
||||
|
||||
def getPwd(self):
|
||||
return self.__DB_PASS
|
||||
|
||||
def execute(self, sql):
|
||||
# 执行SQL语句返回受影响行
|
||||
if not self.__Conn():
|
||||
return self.__DB_ERR
|
||||
try:
|
||||
result = self.__DB_CUR.execute(sql)
|
||||
self.__DB_CONN.commit()
|
||||
self.__Close()
|
||||
return result
|
||||
except Exception as ex:
|
||||
return ex
|
||||
|
||||
def query(self, sql):
|
||||
# 执行SQL语句返回数据集
|
||||
if not self.__Conn():
|
||||
return self.__DB_ERR
|
||||
try:
|
||||
self.__DB_CUR.execute(sql)
|
||||
result = self.__DB_CUR.fetchall()
|
||||
# 将元组转换成列表
|
||||
# data = map(list, result)
|
||||
self.__Close()
|
||||
return result
|
||||
except Exception as ex:
|
||||
return "error: " + str(ex)
|
||||
|
||||
# 关闭连接
|
||||
def __Close(self):
|
||||
self.__DB_CUR.close()
|
||||
self.__DB_CONN.close()
|
||||
+23
-18
@@ -31,9 +31,6 @@ def getPluginName():
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
import mysqlDb
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
@@ -235,16 +232,24 @@ def getDbConfValue():
|
||||
|
||||
|
||||
def pMysqlDb(conf):
|
||||
|
||||
host = conf['HOST'].split(':')
|
||||
conn = mysqlDb.mysqlDb()
|
||||
# pymysql
|
||||
db = mw.getMyORM()
|
||||
# MySQLdb |
|
||||
# db = mw.getMyORMDb()
|
||||
|
||||
conn.setHost(host[0])
|
||||
conn.setUser(conf['USER'])
|
||||
conn.setPwd(conf['PASSWD'])
|
||||
conn.setPort(int(host[1]))
|
||||
conn.setDb(conf['NAME'])
|
||||
return conn
|
||||
db.setPort(int(host[1]))
|
||||
db.setUser(conf['USER'])
|
||||
|
||||
if 'PASSWD' in conf:
|
||||
db.setPwd(conf['PASSWD'])
|
||||
else:
|
||||
db.setPwd(conf['PASSWORD'])
|
||||
|
||||
db.setDbName(conf['NAME'])
|
||||
# db.setSocket(getSocketFile())
|
||||
db.setCharset("utf8")
|
||||
return db
|
||||
|
||||
|
||||
def pSqliteDb(conf):
|
||||
@@ -457,6 +462,11 @@ def userList():
|
||||
if not os.path.exists(conf):
|
||||
return mw.returnJson(False, "请先安装初始化!<br/>默认地址:http://" + mw.getLocalIp() + ":3000")
|
||||
|
||||
conf = getDbConfValue()
|
||||
gtype = getGogsDbType(conf)
|
||||
if gtype != 'mysql':
|
||||
return mw.returnJson(False, "仅支持mysql数据操作!")
|
||||
|
||||
import math
|
||||
args = getArgs()
|
||||
|
||||
@@ -476,7 +486,7 @@ def userList():
|
||||
|
||||
start = (page - 1) * page_size
|
||||
list_count = pQuery('select count(id) as num from user')
|
||||
count = list_count[0][0]
|
||||
count = list_count[0]["num"]
|
||||
list_data = pQuery(
|
||||
'select id,name,email from user order by id desc limit ' + str(start) + ',' + str(page_size))
|
||||
data['list'] = mw.getPage({'count': count, 'p': page,
|
||||
@@ -681,12 +691,7 @@ def getTotalStatistics():
|
||||
data = {}
|
||||
if st.strip() == 'start':
|
||||
list_count = pQuery('select count(id) as num from repository')
|
||||
|
||||
if list_count.find("error") > -1:
|
||||
data['status'] = False
|
||||
data['count'] = 0
|
||||
return mw.returnJson(False, 'fail', data)
|
||||
|
||||
count = list_count[0]["num"]
|
||||
data['status'] = True
|
||||
data['count'] = count
|
||||
data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip()
|
||||
|
||||
@@ -29,6 +29,7 @@ getBit(){
|
||||
|
||||
Install_gogs()
|
||||
{
|
||||
|
||||
mkdir -p $serverPath/source/gogs
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
@@ -163,11 +163,11 @@ function gogsUserList(page, search) {
|
||||
|
||||
ulist = rdata['data']['data'];
|
||||
for (i in ulist){
|
||||
email = ulist[i][2] == '' ? '无' : ulist[i][2];
|
||||
content += '<tr><td>'+ulist[i][0]+'</td>'+
|
||||
'<td>'+ulist[i][1]+'</td>'+
|
||||
email = ulist[i]["email"] == '' ? '无' : ulist[i]["email"];
|
||||
content += '<tr><td>'+ulist[i]["id"]+'</td>'+
|
||||
'<td>'+ulist[i]["name"]+'</td>'+
|
||||
'<td>'+email+'</td>'+
|
||||
'<td><a class="btlink" onclick="userProjectList(\''+ulist[i][1]+'\')">项目管理</a></td>'+
|
||||
'<td><a class="btlink" onclick="userProjectList(\''+ulist[i]["name"]+'\')">项目管理</a></td>'+
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
global
|
||||
daemon
|
||||
log 127.0.0.1 local0
|
||||
pidfile /tmp/haproxy.pid
|
||||
maxconn 4000
|
||||
user haproxy
|
||||
group haproxy
|
||||
|
||||
|
||||
defaults
|
||||
mode http
|
||||
log global
|
||||
option httplog
|
||||
timeout connect 10s
|
||||
timeout client 15s
|
||||
timeout server 15s
|
||||
|
||||
|
||||
listen stats
|
||||
mode http
|
||||
bind *:10800
|
||||
stats enable
|
||||
stats uri /haproxy
|
||||
stats realm Haproxy\ Statistics
|
||||
stats auth admin:admin
|
||||
|
||||
frontend http-in
|
||||
bind *:1080
|
||||
default_backend servers
|
||||
option forwardfor
|
||||
option httpclose
|
||||
|
||||
backend servers
|
||||
balance roundrobin
|
||||
server web1 0.0.0.0:9090 check
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
Executable
+18
@@ -0,0 +1,18 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('haproxy');">服务</p>
|
||||
<p onclick="pluginInitD('haproxy');">自启动</p>
|
||||
<p onclick="pluginConfigTpl('haproxy');">配置修改</p>
|
||||
<p onclick="pluginLogs('haproxy','','run_log',30);">运行日志</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=haproxy&f=js/haproxy.js", function(){
|
||||
pluginService('haproxy');
|
||||
});
|
||||
</script>
|
||||
Executable
+253
@@ -0,0 +1,253 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import string
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'haproxy'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getConfTpl():
|
||||
path = getPluginDir() + "/conf/haproxy.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + "/haproxy.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
return tmp
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def configTpl():
|
||||
path = getPluginDir() + '/tpl'
|
||||
pathFile = os.listdir(path)
|
||||
tmp = []
|
||||
for one in pathFile:
|
||||
file = path + '/' + one
|
||||
tmp.append(file)
|
||||
return mw.getJson(tmp)
|
||||
|
||||
|
||||
def readConfigTpl():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
content = mw.readFile(args['file'])
|
||||
content = contentReplace(content)
|
||||
return mw.returnJson(True, 'ok', content)
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$SERVER_APP}', service_path + '/haproxy')
|
||||
return content
|
||||
|
||||
|
||||
def status():
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep haproxy |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getInitDTpl()
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
if not os.path.exists(file_bin):
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# config replace
|
||||
conf_bin = getConf()
|
||||
if not os.path.exists(conf_bin):
|
||||
conf_content = mw.readFile(getConfTpl())
|
||||
conf_content = contentReplace(conf_content)
|
||||
mw.writeFile(getServerDir() + '/haproxy.conf', conf_content)
|
||||
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/haproxy.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/haproxy.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
service_path = mw.getServerDir()
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(systemService, se_content)
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def haOp(method):
|
||||
file = initDreplace()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
data = mw.execShell('systemctl ' + method + ' haproxy')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def start():
|
||||
return haOp('start')
|
||||
|
||||
|
||||
def stop():
|
||||
return haOp('stop')
|
||||
|
||||
|
||||
def restart():
|
||||
return haOp('restart')
|
||||
|
||||
|
||||
def reload():
|
||||
return haOp('reload')
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
shell_cmd = 'systemctl status haproxy | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'fail'
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl enable haproxy')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl disable haproxy')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runLog():
|
||||
path = getConf()
|
||||
content = mw.readFile(path)
|
||||
rep = 'log\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
|
||||
|
||||
def getPort():
|
||||
path = getConf()
|
||||
content = mw.readFile(path)
|
||||
rep = 'listen\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print(status())
|
||||
elif func == 'start':
|
||||
print(start())
|
||||
elif func == 'stop':
|
||||
print(stop())
|
||||
elif func == 'restart':
|
||||
print(restart())
|
||||
elif func == 'reload':
|
||||
print(reload())
|
||||
elif func == 'initd_status':
|
||||
print(initdStatus())
|
||||
elif func == 'initd_install':
|
||||
print(initdInstall())
|
||||
elif func == 'initd_uninstall':
|
||||
print(initdUinstall())
|
||||
elif func == 'conf':
|
||||
print(getConf())
|
||||
elif func == 'config_tpl':
|
||||
print(configTpl())
|
||||
elif func == 'read_config_tpl':
|
||||
print(readConfigTpl())
|
||||
elif func == 'run_log':
|
||||
print(runLog())
|
||||
elif func == 'query_log':
|
||||
print(queryLog())
|
||||
else:
|
||||
print('error')
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"sort": 7,
|
||||
"ps": "可靠、高性能的TCP/HTTP负载平衡器",
|
||||
"name": "haproxy",
|
||||
"title": "haproxy",
|
||||
"shell": "install.sh",
|
||||
"versions":["2.6"],
|
||||
"updates":["2.6"],
|
||||
"tip": "soft",
|
||||
"checks": "server/haproxy",
|
||||
"path": "server/haproxy",
|
||||
"display": 1,
|
||||
"author": "midoks",
|
||||
"date": "2022-08-26",
|
||||
"home": "https://www.haproxy.org/",
|
||||
"doc1": "https://www.haproxy.org/",
|
||||
"type": 0,
|
||||
"pid": "4"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=he Reliable, High Performance TCP/HTTP Load Balancer
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStartPre={$SERVER_PATH}/haproxy/sbin/haproxy -c -f {$SERVER_PATH}/haproxy/haproxy.conf
|
||||
ExecStart={$SERVER_PATH}/haproxy/sbin/haproxy -D -f {$SERVER_PATH}/haproxy/haproxy.conf
|
||||
ExecReload={$SERVER_PATH}/haproxy/sbin/haproxy -f {$SERVER_PATH}/haproxy/haproxy.conf -c -q
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# chkconfig: - 85 15
|
||||
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
|
||||
# for high availability environments.
|
||||
# processname: haproxy
|
||||
# config: /etc/haproxy/haproxy.cfg
|
||||
# pidfile: /var/run/haproxy.pid
|
||||
# Script Author: Simon Matter <simon.matter@invoca.ch>
|
||||
# Version: 2004060600
|
||||
# Source function library.
|
||||
|
||||
if [ -f /etc/init.d/functions ]; then
|
||||
. /etc/init.d/functions
|
||||
elif [ -f /etc/rc.d/init.d/functions ] ; then
|
||||
. /etc/rc.d/init.d/functions
|
||||
else
|
||||
echo ".."
|
||||
fi
|
||||
|
||||
# Source networking configuration.
|
||||
if [ -f /etc/sysconfig/network ];then
|
||||
. /etc/sysconfig/network
|
||||
fi
|
||||
|
||||
# Check that networking is up.
|
||||
# [ ${NETWORKING} = "no" ] && exit 0
|
||||
|
||||
HAPROXYDIR={$SERVER_PATH}/haproxy
|
||||
BASENAME=haproxy
|
||||
|
||||
# This is our service name
|
||||
|
||||
#BASENAME=`basename $0`
|
||||
#if [ -L $0 ]; then
|
||||
# BASENAME=`find $0 -name $BASENAME -printf %l`
|
||||
# BASENAME=`basename $BASENAME`
|
||||
#fi
|
||||
|
||||
[ -f $HAPROXYDIR/etc/$BASENAME.conf ] || exit 1
|
||||
|
||||
RETVAL=0
|
||||
|
||||
start() {
|
||||
$HAPROXYDIR/sbin/$BASENAME -c -q -f $HAPROXYDIR/etc/$BASENAME.conf
|
||||
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Errors found in configuration file, check it with '$BASENAME check'."
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -n "Starting $BASENAME: "
|
||||
daemon $HAPROXYDIR/sbin/$BASENAME -D -f $HAPROXYDIR/etc/$BASENAME.conf
|
||||
RETVAL=$?
|
||||
# echo
|
||||
# [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
|
||||
stop() {
|
||||
|
||||
echo -n "Shutting down $BASENAME: "
|
||||
killproc $BASENAME -USR1
|
||||
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASENAME
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/run/$BASENAME.pid
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
restart() {
|
||||
$HAPROXYDIR/sbin/$BASENAME -c -q -f $HAPROXYDIR/etc/$BASENAME.conf
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Errors found in configuration file, check it with '$BASENAME check'."
|
||||
return 1
|
||||
fi
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
reload() {
|
||||
$HAPROXYDIR/sbin/$BASENAME -c -q -f $HAPROXYDIR/etc/$BASENAME.conf
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Errors found in configuration file, check it with '$BASENAME check'."
|
||||
return 1
|
||||
fi
|
||||
$HAPROXYDIR/sbin/$BASENAME -D -f $HAPROXYDIR/$BASENAME.conf -p /var/run/$BASENAME.pid -sf $(cat /var/run/$BASENAME.pid)
|
||||
}
|
||||
|
||||
check() {
|
||||
$HAPROXYDIR/sbin/$BASENAME -c -q -V -f $HAPROXYDIR/etc/$BASENAME.conf
|
||||
}
|
||||
|
||||
rhstatus() {
|
||||
status $BASENAME
|
||||
}
|
||||
|
||||
condrestart() {
|
||||
[ -e /var/lock/subsys/$BASENAME ] && restart || :
|
||||
}
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start) start ;;
|
||||
stop) stop ;;
|
||||
restart) restart;;
|
||||
reload) reload;;
|
||||
condrestart) condrestart ;;
|
||||
status) rhstatus ;;
|
||||
check) check ;;
|
||||
*)
|
||||
echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $?
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
|
||||
action=$1
|
||||
type=$2
|
||||
|
||||
echo $action $type
|
||||
|
||||
if id haproxy &> /dev/null ;then
|
||||
echo "haproxy UID is `id -u haproxy`"
|
||||
echo "haproxy Shell is `grep "^haproxy:" /etc/passwd |cut -d':' -f7 `"
|
||||
else
|
||||
groupadd haproxy
|
||||
useradd -g haproxy haproxy
|
||||
fi
|
||||
|
||||
if [ "${2}" == "" ];then
|
||||
echo '缺少安装脚本...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d $curPath/versions/$2 ];then
|
||||
echo '缺少安装脚本2...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "${action}" == "uninstall" ];then
|
||||
|
||||
if [ -f /usr/lib/systemd/system/haproxy.service ] || [ -f /lib/systemd/system/haproxy.service ];then
|
||||
systemctl stop haproxy
|
||||
systemctl disable haproxy
|
||||
rm -rf /usr/lib/systemd/system/haproxy.service
|
||||
rm -rf /lib/systemd/system/haproxy.service
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
fi
|
||||
|
||||
sh -x $curPath/versions/$2/install.sh $1
|
||||
|
||||
if [ "${action}" == "install" ] && [ -d $serverPath/haproxy ];then
|
||||
#初始化
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/haproxy/index.py start ${type}
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/haproxy/index.py initd_install ${type}
|
||||
fi
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
function spPostMin(method, args, callback){
|
||||
|
||||
var req_data = {};
|
||||
req_data['name'] = 'haproxy';
|
||||
req_data['func'] = method;
|
||||
|
||||
if (typeof(args) != 'undefined' && args!=''){
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/run', req_data, function(data) {
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function spPost(method, args, callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
spPostMin(method,args,function(data){
|
||||
layer.close(loadT);
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function secToTime(s) {
|
||||
var t;
|
||||
if(s > -1){
|
||||
var hour = Math.floor(s/3600);
|
||||
var min = Math.floor(s/60) % 60;
|
||||
var sec = s % 60;
|
||||
if(hour < 10) {
|
||||
t = '0'+ hour + ":";
|
||||
} else {
|
||||
t = hour + ":";
|
||||
}
|
||||
|
||||
if(min < 10){t += "0";}
|
||||
t += min + ":";
|
||||
if(sec < 10){t += "0";}
|
||||
t += sec.toFixed(2);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sysName=`uname`
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
OSNAME_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
|
||||
|
||||
VERSION=2.6.4
|
||||
MIN_VERSION=2.6
|
||||
Install_App()
|
||||
{
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/haproxy
|
||||
|
||||
APP_DIR=${serverPath}/source/haproxy
|
||||
mkdir -p $APP_DIR
|
||||
|
||||
if [ ! -f ${APP_DIR}/haproxy-${VERSION}.tar.gz ];then
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
wget -O ${APP_DIR}/haproxy-${VERSION}.tar.gz https://www.haproxy.org/download/${MIN_VERSION}/src/haproxy-${VERSION}.tar.gz
|
||||
else
|
||||
curl -sSLo ${APP_DIR}/haproxy-${VERSION}.tar.gz https://www.haproxy.org/download/${MIN_VERSION}/src/haproxy-${VERSION}.tar.gz
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f ${APP_DIR}/haproxy-${VERSION}.tar.gz ];then
|
||||
curl -sSLo ${APP_DIR}/haproxy-${VERSION}.tar.gz https://www.haproxy.org/download/${MIN_VERSION}/src/haproxy-${VERSION}.tar.gz
|
||||
fi
|
||||
|
||||
|
||||
cd ${APP_DIR} && tar -zxvf haproxy-${VERSION}.tar.gz
|
||||
|
||||
if [ "$OSNAME" == "macos" ];then
|
||||
cd ${APP_DIR}/haproxy-${VERSION} && make TARGET=osx && make install PREFIX=$serverPath/haproxy
|
||||
else
|
||||
cd ${APP_DIR}/haproxy-${VERSION} && make TARGET=linux-glibc && make install PREFIX=$serverPath/haproxy
|
||||
fi
|
||||
|
||||
echo $MIN_VERSION > $serverPath/haproxy/version.pl
|
||||
echo 'Install_HA' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
if [ -f $serverPath/haproxy/initd/haproxy ];then
|
||||
$serverPath/haproxy/initd/haproxy stop
|
||||
fi
|
||||
|
||||
rm -rf $serverPath/haproxy
|
||||
echo "Uninstall_HA" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
Executable
+20
@@ -0,0 +1,20 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('imail');">服务</p>
|
||||
<p onclick="pluginInitD('imail');">自启动</p>
|
||||
<p onclick="pluginConfig('imail',null, 'conf');">配置文件</p>
|
||||
<p onclick="pluginLogs('imail',null,'run_log', 50);">运行日志</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=imail&f=js/imail.js", function(){
|
||||
mail.init();
|
||||
pluginService('imail');
|
||||
});
|
||||
</script>
|
||||
Executable
+218
@@ -0,0 +1,218 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import socket
|
||||
import json
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
class App:
|
||||
__setupPath = '/www/server/imail'
|
||||
__SR = ''
|
||||
|
||||
def __init__(self):
|
||||
self.__setupPath = self.getServerDir()
|
||||
|
||||
self.__SR = '''#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
export USER=%s
|
||||
export HOME=%s && ''' % ( self.getRunUser(), self.getHomeDir())
|
||||
|
||||
def getArgs(self):
|
||||
args = sys.argv[3:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
|
||||
return tmp
|
||||
|
||||
def __release_port(self, port):
|
||||
from collections import namedtuple
|
||||
try:
|
||||
import firewall_api
|
||||
firewall_api.firewall_api().addAcceptPortArgs(port, 'IMail-Server', 'port')
|
||||
return port
|
||||
except Exception as e:
|
||||
return "Release failed {}".format(e)
|
||||
|
||||
def openPort(self):
|
||||
for i in ["25", "110", "143", "465", "995", "993", "587"]:
|
||||
self.__release_port(i)
|
||||
return True
|
||||
|
||||
def getPluginName(self):
|
||||
return 'imail'
|
||||
|
||||
def getPluginDir(self):
|
||||
return mw.getPluginDir() + '/' + self.getPluginName()
|
||||
|
||||
def getServerDir(self):
|
||||
return mw.getServerDir() + '/' + self.getPluginName()
|
||||
|
||||
def getInitdConfTpl(self):
|
||||
path = self.getPluginDir() + "/init.d/imail.tpl"
|
||||
return path
|
||||
|
||||
def getHomeDir(self):
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return '/Users/' + user
|
||||
else:
|
||||
return '/root'
|
||||
|
||||
def getRunUser(self):
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return user
|
||||
else:
|
||||
return 'root'
|
||||
|
||||
def status(self):
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + self.getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
def contentReplace(self, content):
|
||||
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$RUN_USER}', self.getRunUser())
|
||||
content = content.replace('{$HOME_DIR}', self.getHomeDir())
|
||||
|
||||
return content
|
||||
|
||||
def initDreplace(self):
|
||||
|
||||
file_tpl = self.getInitdConfTpl()
|
||||
service_path = mw.getServerDir()
|
||||
|
||||
initD_path = self.getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
self.openPort()
|
||||
|
||||
file_bin = initD_path + '/' + self.getPluginName()
|
||||
|
||||
if not os.path.exists(file_bin):
|
||||
content = mw.readFile(file_tpl)
|
||||
content = self.contentReplace(content)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/imail.service'
|
||||
systemServiceTpl = self.getPluginDir() + '/init.d/imail.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
service_path = mw.getServerDir()
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(systemService, se_content)
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
log_path = self.getServerDir() + '/logs'
|
||||
if not os.path.exists(log_path):
|
||||
os.mkdir(log_path)
|
||||
|
||||
return file_bin
|
||||
|
||||
def imOp(self, method):
|
||||
file = self.initDreplace()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
cmd = 'systemctl {} {}'.format(method, self.getPluginName())
|
||||
data = mw.execShell(cmd)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
data = mw.execShell(self.__SR + file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[0]
|
||||
|
||||
def start(self):
|
||||
return self.imOp('start')
|
||||
|
||||
def stop(self):
|
||||
return self.imOp('stop')
|
||||
|
||||
def restart(self):
|
||||
return self.imOp('restart')
|
||||
|
||||
def reload(self):
|
||||
return self.imOp('reload')
|
||||
|
||||
def initd_status(self):
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
cmd = 'systemctl status imail | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'fail'
|
||||
return 'ok'
|
||||
|
||||
def initd_install(self):
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl enable imail')
|
||||
return 'ok'
|
||||
|
||||
def initd_uinstall(self):
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl disable imail')
|
||||
return 'ok'
|
||||
|
||||
def conf(self):
|
||||
conf_path = self.getServerDir() + '/custom/conf/app.conf'
|
||||
if not os.path.exists(conf_path):
|
||||
return mw.returnJson(False, "请先安装初始化!<br/>默认地址:http://" + mw.getLocalIp() + ":1080")
|
||||
|
||||
return self.getServerDir() + '/custom/conf/app.conf'
|
||||
|
||||
def run_log(self):
|
||||
ilog = self.getServerDir() + '/logs/imail.log'
|
||||
if not os.path.exists(ilog):
|
||||
return mw.returnJson(False, "请先安装初始化!<br/>默认地址:http://" + mw.getLocalIp() + ":1080")
|
||||
|
||||
return self.getServerDir() + '/logs/imail.log'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
classApp = App()
|
||||
try:
|
||||
data = eval("classApp." + func + "()")
|
||||
print(data)
|
||||
except Exception as e:
|
||||
print('error:' + str(e))
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"sort": 7,
|
||||
"ps": "简单邮件服务[DEV]",
|
||||
"name": "imail",
|
||||
"title": "邮件服务",
|
||||
"shell": "install.sh",
|
||||
"versions":["0.0.17"],
|
||||
"updates":["0.0.17"],
|
||||
"tip": "soft",
|
||||
"checks": "server/imail",
|
||||
"path": "server/imail",
|
||||
"display": 1,
|
||||
"author": "midoks",
|
||||
"date": "2022-09-26",
|
||||
"home": "https://github.com/midoks/mdserver-web",
|
||||
"type": 0,
|
||||
"pid": "5"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Imail Simple Mail Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart={$SERVER_PATH}/imail/init.d/imail start
|
||||
ExecStop={$SERVER_PATH}/imail/init.d/imail stop
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
# chkconfig: 2345 55 25
|
||||
# description: Imail Service
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: bt
|
||||
# Required-Start: $all
|
||||
# Required-Stop: $all
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: starts Imail
|
||||
# Description: starts the Imail
|
||||
### END INIT INFO
|
||||
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
|
||||
# Source function library.
|
||||
if [ -f /etc/init.d/functions ];then
|
||||
. /etc/init.d/functions
|
||||
fi
|
||||
|
||||
if [ -f /etc/rc.d/init.d/functions ];then
|
||||
. /etc/rc.d/init.d/functions
|
||||
fi
|
||||
|
||||
app_path={$SERVER_PATH}/imail
|
||||
SERVICENAME="imail"
|
||||
|
||||
im_start(){
|
||||
isStart=`ps -ef|grep 'imail service' |grep -v grep|awk '{print $2}'`
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "Starting imail... \c"
|
||||
cd $app_path && ${app_path}/imail service &
|
||||
isStart=""
|
||||
while [[ "$isStart" == "" ]];
|
||||
do
|
||||
echo -e ".\c"
|
||||
sleep 0.5
|
||||
isStart=$(lsof -n -P -i:25|grep LISTEN|grep -v grep|awk '{print $2}'|xargs)
|
||||
let n+=1
|
||||
if [ $n -gt 15 ];then
|
||||
break;
|
||||
fi
|
||||
done
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "\033[31mfailed\033[0m"
|
||||
echo '------------------------------------------------------'
|
||||
tail -n 20 ${app_path}/logs/run_away.log
|
||||
echo '------------------------------------------------------'
|
||||
echo -e "\033[31mError: ${SERVICENAME} service startup failed.\033[0m"
|
||||
return;
|
||||
fi
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
else
|
||||
echo "Starting ${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
fi
|
||||
}
|
||||
|
||||
im_stop(){
|
||||
pids=`ps -ef|grep 'imail service' |grep -v grep|awk '{print $2}'`
|
||||
arr=($pids)
|
||||
echo -e "Stopping ${SERVICENAME}... \c"
|
||||
for p in ${arr[@]}
|
||||
do
|
||||
kill -9 $p
|
||||
done
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
}
|
||||
|
||||
im_status(){
|
||||
isStart=`ps -ef|grep 'imail service' |grep -v grep|awk '{print $2}'`
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "${SERVICENAME} not running"
|
||||
else
|
||||
echo -e "${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
'start') im_start;;
|
||||
'stop') im_stop;;
|
||||
'status') im_status;;
|
||||
'reload')
|
||||
im_stop
|
||||
im_start;;
|
||||
'restart')
|
||||
im_stop
|
||||
im_start;;
|
||||
esac
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
action=$1
|
||||
type=$2
|
||||
|
||||
if [ "${2}" == "" ];then
|
||||
echo '缺少安装脚本...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d $curPath/versions/$2 ];then
|
||||
echo '缺少安装脚本2...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sh -x $curPath/versions/$2/install.sh $1
|
||||
Executable
+95
@@ -0,0 +1,95 @@
|
||||
var mail = {
|
||||
plugin_name: 'imail',
|
||||
init: function () {
|
||||
var _this = this;
|
||||
},
|
||||
|
||||
str2Obj:function(str){
|
||||
var data = {};
|
||||
kv = str.split('&');
|
||||
for(i in kv){
|
||||
v = kv[i].split('=');
|
||||
data[v[0]] = v[1];
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
send:function(info){
|
||||
var tips = info['tips'];
|
||||
var method = info['method'];
|
||||
var args = info['data'];
|
||||
var callback = info['success'];
|
||||
|
||||
var loadT = layer.msg(tips, { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var data = {};
|
||||
data['name'] = 'mail';
|
||||
data['func'] = method;
|
||||
data['version'] = $('.plugin_version').attr('version');
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
data['args'] = JSON.stringify(this.str2Obj(args));
|
||||
} else {
|
||||
data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/run', data, function(res) {
|
||||
layer.close(loadT);
|
||||
if (!res.status){
|
||||
layer.msg(res.msg,{icon:2,time:10000});
|
||||
return;
|
||||
}
|
||||
|
||||
var ret_data = $.parseJSON(res.data);
|
||||
console.log("send:",ret_data);
|
||||
// if (!ret_data.status){
|
||||
// layer.msg(ret_data.msg,{icon:2,time:2000});
|
||||
// return;
|
||||
// }
|
||||
|
||||
// console.log("send2:",ret_data);
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(ret_data);
|
||||
}
|
||||
},'json');
|
||||
},
|
||||
postCallback:function(info){
|
||||
var tips = info['tips'];
|
||||
var method = info['method'];
|
||||
var args = info['data'];
|
||||
var callback = info['success'];
|
||||
|
||||
var loadT = layer.msg(tips, { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var data = {};
|
||||
data['name'] = 'mail';
|
||||
data['func'] = method;
|
||||
data['version'] = $('.plugin_version').attr('version');
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
data['args'] = JSON.stringify(this.str2Obj(args));
|
||||
} else {
|
||||
data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/callback', data, function(res) {
|
||||
|
||||
layer.close(loadT);
|
||||
if (!res.status){
|
||||
layer.msg(res.msg,{icon:2,time:10000});
|
||||
return;
|
||||
}
|
||||
|
||||
var ret_data = $.parseJSON(res.data);
|
||||
if (!ret_data.status){
|
||||
layer.msg(ret_data.msg,{icon:2,time:2000});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(res);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
}
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=0.0.17
|
||||
|
||||
# bash install.sh install 0.0.16
|
||||
## cd /www/server/mdserver-web/plugins/imail && bash install.sh install 0.0.16
|
||||
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
OSNAME_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
|
||||
|
||||
ARCH="amd64"
|
||||
|
||||
get_arch() {
|
||||
|
||||
TMP_ARCH=`arch`
|
||||
if [ "$TMP_ARCH" == "x86_64" ];then
|
||||
ARCH="amd64"
|
||||
fi
|
||||
}
|
||||
|
||||
load_vars() {
|
||||
OS=$(uname | tr '[:upper:]' '[:lower:]')
|
||||
TARGET_DIR="$serverPath/imail"
|
||||
}
|
||||
|
||||
get_download_url() {
|
||||
DOWNLOAD_URL="https://github.com/midoks/imail/releases/download/$VERSION/imail_${VERSION}_${OS}_${ARCH}.tar.gz"
|
||||
}
|
||||
|
||||
# download file
|
||||
download_file() {
|
||||
url="${1}"
|
||||
destination="${2}"
|
||||
|
||||
printf "Fetching ${url} \n\n"
|
||||
|
||||
if test -x "$(command -v curl)"; then
|
||||
code=$(curl --connect-timeout 15 -w '%{http_code}' -L "${url}" -o "${destination}")
|
||||
elif test -x "$(command -v wget)"; then
|
||||
code=$(wget -t2 -T15 -O "${destination}" --server-response "${url}" 2>&1 | awk '/^ HTTP/{print $2}' | tail -1)
|
||||
else
|
||||
printf "\e[1;31mNeither curl nor wget was available to perform http requests.\e[0m\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${code}" != 200 ]; then
|
||||
printf "\e[1;31mRequest failed with code %s\e[0m\n" $code
|
||||
exit 1
|
||||
else
|
||||
printf "\n\e[1;33mDownload succeeded\e[0m\n"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Install_App()
|
||||
{
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/source
|
||||
|
||||
load_vars
|
||||
get_arch
|
||||
get_download_url
|
||||
|
||||
DOWNLOAD_FILE="$(mktemp).tar.gz"
|
||||
download_file $DOWNLOAD_URL $DOWNLOAD_FILE
|
||||
|
||||
if [ ! -d "$TARGET_DIR" ]; then
|
||||
mkdir -p "$TARGET_DIR"
|
||||
fi
|
||||
|
||||
tar -C "$TARGET_DIR" -zxf $DOWNLOAD_FILE
|
||||
rm -rf $DOWNLOAD_FILE
|
||||
|
||||
pushd "$TARGET_DIR/scripts" >/dev/null 2>&1
|
||||
bash make.sh
|
||||
|
||||
if [ -d $serverPath/imail ];then
|
||||
echo "$VERSION" > $serverPath/imail/version.pl
|
||||
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/imail/index.py start
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/imail/index.py initd_install
|
||||
fi
|
||||
echo 'install successful' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/imail/index.py initd_uninstall
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/imail/index.py stop
|
||||
rm -rf $serverPath/imail
|
||||
echo "install fail" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
@@ -304,7 +304,7 @@ def getErrorLog():
|
||||
if 'close' in args:
|
||||
mw.writeFile(filename, '')
|
||||
return mw.returnJson(False, '日志已清空')
|
||||
info = mw.getNumLines(filename, 18)
|
||||
info = mw.getLastLine(filename, 18)
|
||||
return mw.returnJson(True, 'OK', info)
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ def initMariaDbPwd():
|
||||
time.sleep(5)
|
||||
|
||||
serverdir = getServerDir()
|
||||
myconf = serverdir + "/etc/my.cnf"
|
||||
pwd = mw.getRandomString(16)
|
||||
|
||||
db_option = "-S " + serverdir + "/mysql.sock"
|
||||
@@ -363,6 +364,16 @@ def initMariaDbPwd():
|
||||
pwd + ' -e "drop database test";'
|
||||
mw.execShell(drop_test_db)
|
||||
|
||||
# 删除冗余账户
|
||||
hostname = mw.execShell('hostname')[0].strip()
|
||||
drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";'
|
||||
mw.execShell(drop_hostname)
|
||||
|
||||
drop_root_hostname = serverdir + '/bin/mysql --defaults-file=' + \
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";'
|
||||
mw.execShell(drop_root_hostname)
|
||||
|
||||
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
|
||||
return True
|
||||
|
||||
@@ -2180,8 +2191,11 @@ def installPreInspection(version):
|
||||
|
||||
|
||||
def uninstallPreInspection(version):
|
||||
# return "请手动删除MySQL[{}]".format(version)
|
||||
return 'ok'
|
||||
stop(version)
|
||||
if mw.isDebugMode():
|
||||
return 'ok'
|
||||
|
||||
return "请手动删除MariaDB[{}]<br/> rm -rf {}".format(version, getServerDir())
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
|
||||
@@ -817,6 +817,7 @@ function openPhpmyadmin(name,username,password){
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请切换模式.',{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
var phpmyadmin_cfg = rdata;
|
||||
|
||||
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'get_home_page'});
|
||||
var rdata = $.parseJSON(data.data);
|
||||
@@ -824,7 +825,10 @@ function openPhpmyadmin(name,username,password){
|
||||
layer.msg(rdata.msg,{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
$("#toPHPMyAdmin").attr('action',rdata.data);
|
||||
|
||||
var home_page = rdata.data;
|
||||
home_page = home_page.replace("http://","http://"+phpmyadmin_cfg['username']+":"+phpmyadmin_cfg['password']+"@");
|
||||
$("#toPHPMyAdmin").attr('action',home_page);
|
||||
|
||||
if($("#toPHPMyAdmin").attr('action').indexOf('phpmyadmin') == -1){
|
||||
layer.msg('请先安装phpMyAdmin',{icon:2,shade: [0.3, '#000']});
|
||||
|
||||
@@ -14,7 +14,7 @@ sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=10.6.8
|
||||
MY_VER=10.6.9
|
||||
|
||||
Install_app()
|
||||
{
|
||||
@@ -57,10 +57,15 @@ Install_app()
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
# https://mirrors.aliyun.com/mariadb/mariadb-10.8.3/source/mariadb-10.8.3.tar.gz
|
||||
if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then
|
||||
# https://mirrors.aliyun.com/mariadb/mariadb-10.8.3/source/mariadb-10.8.3.tar.gz
|
||||
wget -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
# wget -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://downloads.mariadb.org/interstitial/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
|
||||
fi
|
||||
|
||||
# https://downloads.mariadb.org/interstitial/mariadb-10.6.8/source/mariadb-10.6.8.tar.gz
|
||||
if [ "$?" != "0" ];then
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://downloads.mariadb.org/interstitial/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
if [ ! -d ${mariadbDir}/mariadb-${MY_VER} ];then
|
||||
|
||||
@@ -14,7 +14,7 @@ sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=10.7.4
|
||||
MY_VER=10.7.5
|
||||
|
||||
Install_app()
|
||||
{
|
||||
@@ -58,14 +58,16 @@ Install_app()
|
||||
# ----- cpu end ------
|
||||
|
||||
if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then
|
||||
wget -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
# wget -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://downloads.mariadb.org/interstitial/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
if [ "$?" != "0" ];then
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://downloads.mariadb.org/interstitial/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
if [ ! -d ${mariadbDir}/mariadb-${MY_VER} ];then
|
||||
cd ${mariadbDir} && tar -zxvf ${mariadbDir}/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d $serverPath/mariadb ];then
|
||||
cd ${mariadbDir}/mariadb-${MY_VER} && cmake \
|
||||
|
||||
@@ -14,7 +14,7 @@ sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=10.8.3
|
||||
MY_VER=10.8.4
|
||||
|
||||
Install_app()
|
||||
{
|
||||
@@ -58,8 +58,11 @@ Install_app()
|
||||
# ----- cpu end ------
|
||||
|
||||
if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then
|
||||
wget -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
# wget -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://downloads.mariadb.org/interstitial/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
if [ "$?" != "0" ];then
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://downloads.mariadb.org/interstitial/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz
|
||||
fi
|
||||
|
||||
if [ ! -d ${mariadbDir}/mariadb-${MY_VER} ];then
|
||||
|
||||
@@ -21,14 +21,26 @@ OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Install_app_mac()
|
||||
{
|
||||
if [ ! -f $serverPath/source/mongodb-macos-x86_64-${VERSION}.tgz ];then
|
||||
wget -O $serverPath/source/mongodb-macos-x86_64-${VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${VERSION}.tgz
|
||||
mkdir -p $serverPath/mongodb
|
||||
if [ "$VERSION" == "5.0" ];then
|
||||
G_VERSION="5.0.11"
|
||||
elif [[ "$VERSION" == "4.4" ]]; then
|
||||
G_VERSION="4.4.11"
|
||||
fi
|
||||
|
||||
cd $serverPath/source && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
|
||||
cd mongodb-macos-x86_64-${VERSION} && mv ./* $serverPath/mongodb
|
||||
if [ ! -f $serverPath/source/mongodb-macos-x86_64-${G_VERSION}.tgz ];then
|
||||
wget -O $serverPath/source/mongodb-macos-x86_64-${G_VERSION}.tgz https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${G_VERSION}.tgz
|
||||
fi
|
||||
|
||||
cd $serverPath/source && tar -zxvf mongodb-macos-x86_64-${G_VERSION}.tgz
|
||||
cd mongodb-macos-x86_64-${G_VERSION} && mv ./* $serverPath/mongodb
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,107 @@
|
||||
[client]
|
||||
user = root
|
||||
#password = your_password
|
||||
port = 3306
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
|
||||
[mysqld]
|
||||
!include {$SERVER_APP_PATH}/etc/mode/classic.cnf
|
||||
|
||||
pid-file = {$SERVER_APP_PATH}/data/mysql.pid
|
||||
user = mysql
|
||||
port = 3306
|
||||
socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
basedir = {$SERVER_APP_PATH}
|
||||
datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
|
||||
default_storage_engine = InnoDB
|
||||
|
||||
key_buffer_size = 8M
|
||||
max_allowed_packet = 100M
|
||||
|
||||
table_open_cache = 32
|
||||
sort_buffer_size = 256K
|
||||
net_buffer_length = 4K
|
||||
read_buffer_size = 128K
|
||||
read_rnd_buffer_size = 256K
|
||||
myisam_sort_buffer_size = 4M
|
||||
thread_cache_size = 4
|
||||
lower_case_table_names=0
|
||||
query_cache_size = 4M
|
||||
tmp_table_size = 8M
|
||||
|
||||
max_connections = 500
|
||||
max_connect_errors = 100
|
||||
open_files_limit = 65535
|
||||
|
||||
skip-name-resolve=1
|
||||
#skip-grant-tables
|
||||
#skip-networking
|
||||
#skip-external-locking
|
||||
#loose-skip-innodb
|
||||
|
||||
log-bin=mysql-bin
|
||||
binlog_format=mixed
|
||||
slow_query_log=1
|
||||
slow-query-log-file={$SERVER_APP_PATH}/data/mysql-slow.log
|
||||
long_query_time=10
|
||||
#log_queries_not_using_indexes=on
|
||||
#log_slow_admin_statements=1
|
||||
#log_slow_slave_statements=1
|
||||
expire_logs_days=30
|
||||
|
||||
relay-log=mdserver
|
||||
relay-log-index=mdserver
|
||||
|
||||
#master
|
||||
#binlog-do-db
|
||||
binlog-ignore-db = test
|
||||
binlog-ignore-db = mysql
|
||||
binlog-ignore-db = information_schema
|
||||
binlog-ignore-db = performance_schema
|
||||
|
||||
#slave
|
||||
log-slave-updates = 1
|
||||
skip-slave-start = 1
|
||||
#replicate-do-db
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
|
||||
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
innodb_log_group_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_buffer_pool_size = 16M
|
||||
innodb_additional_mem_pool_size = 2M
|
||||
innodb_log_file_size = 5M
|
||||
innodb_log_buffer_size = 8M
|
||||
innodb_flush_log_at_trx_commit = 2
|
||||
innodb_lock_wait_timeout = 120
|
||||
innodb_max_dirty_pages_pct = 90
|
||||
innodb_read_io_threads = 1
|
||||
innodb_write_io_threads = 1
|
||||
innodb_file_per_table=1
|
||||
innodb_large_prefix = 1
|
||||
|
||||
|
||||
secure-file-priv={$SERVER_APP_PATH}/tmp
|
||||
|
||||
[mysqldump]
|
||||
quick
|
||||
max_allowed_packet = 16M
|
||||
|
||||
[mysql]
|
||||
no-auto-rehash
|
||||
|
||||
[myisamchk]
|
||||
key_buffer_size = 20M
|
||||
sort_buffer_size = 20M
|
||||
read_buffer = 2M
|
||||
write_buffer = 2M
|
||||
|
||||
[mysqlhotcopy]
|
||||
interactive-timeout
|
||||
@@ -7,8 +7,8 @@ socket = {$SERVER_APP_PATH}/mysql.sock
|
||||
[mysqld]
|
||||
!include {$SERVER_APP_PATH}/etc/mode/classic.cnf
|
||||
|
||||
;sha256_password_private_key_path=mysql.pem
|
||||
;sha256_password_public_key_path=mysql.pub
|
||||
sha256_password_private_key_path=mysql.pem
|
||||
sha256_password_public_key_path=mysql.pub
|
||||
|
||||
pid-file = {$SERVER_APP_PATH}/data/mysql.pid
|
||||
user = mysql
|
||||
@@ -80,7 +80,8 @@ innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_data_file_path = ibdata1:10M:autoextend
|
||||
innodb_log_group_home_dir = {$SERVER_APP_PATH}/data
|
||||
innodb_buffer_pool_size = 16M
|
||||
innodb_log_file_size = 5M
|
||||
#innodb_log_file_size = 5M
|
||||
innodb_redo_log_capacity=10485760
|
||||
innodb_log_buffer_size = 8M
|
||||
innodb_flush_log_at_trx_commit = 2
|
||||
innodb_lock_wait_timeout = 120
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
.conf_p span {
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
width: 95px;
|
||||
width: 135px;
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
|
||||
+137
-7
@@ -333,7 +333,7 @@ def getErrorLog():
|
||||
if 'close' in args:
|
||||
mw.writeFile(filename, '')
|
||||
return mw.returnJson(False, '日志已清空')
|
||||
info = mw.getNumLines(filename, 18)
|
||||
info = mw.getLastLine(filename, 18)
|
||||
return mw.returnJson(True, 'OK', info)
|
||||
|
||||
|
||||
@@ -404,6 +404,7 @@ def initMysqlPwd():
|
||||
time.sleep(5)
|
||||
|
||||
serverdir = getServerDir()
|
||||
myconf = serverdir + "/etc/my.cnf"
|
||||
pwd = mw.getRandomString(16)
|
||||
# cmd_pass = serverdir + '/bin/mysqladmin -uroot password ' + pwd
|
||||
|
||||
@@ -426,6 +427,17 @@ def initMysqlPwd():
|
||||
pwd + ' -e "drop database test";'
|
||||
mw.execShell(drop_test_db)
|
||||
|
||||
# 删除冗余账户
|
||||
hostname = mw.execShell('hostname')[0].strip()
|
||||
|
||||
drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";'
|
||||
mw.execShell(drop_hostname)
|
||||
|
||||
drop_root_hostname = serverdir + '/bin/mysql --defaults-file=' + \
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";'
|
||||
mw.execShell(drop_root_hostname)
|
||||
|
||||
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
|
||||
return True
|
||||
|
||||
@@ -468,6 +480,17 @@ def initMysql8Pwd():
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop database test";'
|
||||
mw.execShell(drop_test_db)
|
||||
|
||||
# 删除冗余账户
|
||||
hostname = mw.execShell('hostname')[0].strip()
|
||||
|
||||
drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";'
|
||||
mw.execShell(drop_hostname)
|
||||
|
||||
drop_root_hostname = serverdir + '/bin/mysql --defaults-file=' + \
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop user \'root\'@\'' + hostname + '\'";'
|
||||
mw.execShell(drop_root_hostname)
|
||||
|
||||
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
|
||||
|
||||
return True
|
||||
@@ -475,7 +498,7 @@ def initMysql8Pwd():
|
||||
|
||||
def myOp(version, method):
|
||||
# import commands
|
||||
init_file = initDreplace()
|
||||
init_file = initDreplace(version)
|
||||
try:
|
||||
isInited = initMysqlData()
|
||||
if not isInited:
|
||||
@@ -804,6 +827,69 @@ def setDbBackup():
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
def importDbExternal():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file', 'name'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
file = args['file']
|
||||
name = args['name']
|
||||
|
||||
import_dir = mw.getRootDir() + '/backup/import/'
|
||||
|
||||
file_path = import_dir + file
|
||||
if not os.path.exists(file_path):
|
||||
return mw.returnJson(False, '文件突然消失?')
|
||||
|
||||
exts = ['sql', 'gz', 'zip']
|
||||
tmp = file.split('.')
|
||||
ext = tmp[len(tmp) - 1]
|
||||
if ext not in exts:
|
||||
return mw.returnJson(False, '导入数据库格式不对!')
|
||||
|
||||
tmp = file.split('/')
|
||||
tmpFile = tmp[len(tmp) - 1]
|
||||
tmpFile = tmpFile.replace('.sql.' + ext, '.sql')
|
||||
tmpFile = tmpFile.replace('.' + ext, '.sql')
|
||||
tmpFile = tmpFile.replace('tar.', '')
|
||||
|
||||
# print(tmpFile)
|
||||
import_sql = ""
|
||||
if file.find("sql.gz") > -1:
|
||||
cmd = 'cd ' + import_dir + ' && gzip -dc ' + \
|
||||
file + " > " + import_dir + tmpFile
|
||||
info = mw.execShell(cmd)
|
||||
if info[1] == "":
|
||||
import_sql = import_dir + tmpFile
|
||||
|
||||
if file.find(".zip") > -1:
|
||||
cmd = 'cd ' + import_dir + ' && unzip -o ' + file
|
||||
mw.execShell(cmd)
|
||||
import_sql = import_dir + tmpFile
|
||||
|
||||
if file.find("tar.gz") > -1:
|
||||
cmd = 'cd ' + import_dir + ' && tar -zxvf ' + file
|
||||
mw.execShell(cmd)
|
||||
import_sql = import_dir + tmpFile
|
||||
|
||||
if import_sql == "":
|
||||
return mw.returnJson(False, '未找SQL文件')
|
||||
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
|
||||
os.environ["MYSQL_PWD"] = pwd
|
||||
mysql_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + \
|
||||
pwd + ' ' + name + ' < ' + import_sql
|
||||
|
||||
# print(mysql_cmd)
|
||||
os.system(mysql_cmd)
|
||||
os.remove(import_sql)
|
||||
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
def importDbBackup():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file', 'name'])
|
||||
@@ -832,13 +918,17 @@ def importDbBackup():
|
||||
|
||||
def deleteDbBackup():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['filename'])
|
||||
data = checkArgs(args, ['filename', 'path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
path = args['path']
|
||||
full_file = ""
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
|
||||
os.remove(bkDir + '/' + args['filename'])
|
||||
full_file = bkDir + '/' + args['filename']
|
||||
if path != "":
|
||||
full_file = path + "/" + args['filename']
|
||||
os.remove(full_file)
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
@@ -870,6 +960,39 @@ def getDbBackupList():
|
||||
return mw.returnJson(True, 'ok', rr)
|
||||
|
||||
|
||||
def getDbBackupImportList():
|
||||
|
||||
bkImportDir = mw.getRootDir() + '/backup/import'
|
||||
if not os.path.exists(bkImportDir):
|
||||
os.mkdir(bkImportDir)
|
||||
|
||||
blist = os.listdir(bkImportDir)
|
||||
|
||||
rr = []
|
||||
for x in range(0, len(blist)):
|
||||
name = blist[x]
|
||||
p = bkImportDir + '/' + name
|
||||
data = {}
|
||||
data['name'] = name
|
||||
|
||||
rsize = os.path.getsize(p)
|
||||
data['size'] = mw.toSize(rsize)
|
||||
|
||||
t = os.path.getctime(p)
|
||||
t = time.localtime(t)
|
||||
|
||||
data['time'] = time.strftime('%Y-%m-%d %H:%M:%S', t)
|
||||
rr.append(data)
|
||||
|
||||
data['file'] = p
|
||||
|
||||
rdata = {
|
||||
"list": rr,
|
||||
"upload_dir": bkImportDir,
|
||||
}
|
||||
return mw.returnJson(True, 'ok', rdata)
|
||||
|
||||
|
||||
def getDbList():
|
||||
args = getArgs()
|
||||
page = 1
|
||||
@@ -2338,8 +2461,11 @@ def installPreInspection(version):
|
||||
|
||||
|
||||
def uninstallPreInspection(version):
|
||||
# return "请手动删除MySQL[{}]".format(version)
|
||||
return 'ok'
|
||||
stop(version)
|
||||
if mw.isDebugMode():
|
||||
return 'ok'
|
||||
|
||||
return "请手动删除MySQL[{}]<br/> rm -rf {}".format(version, getServerDir())
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
@@ -2401,10 +2527,14 @@ if __name__ == "__main__":
|
||||
print(setDbBackup())
|
||||
elif func == 'import_db_backup':
|
||||
print(importDbBackup())
|
||||
elif func == 'import_db_external':
|
||||
print(importDbExternal())
|
||||
elif func == 'delete_db_backup':
|
||||
print(deleteDbBackup())
|
||||
elif func == 'get_db_backup_list':
|
||||
print(getDbBackupList())
|
||||
elif func == 'get_db_backup_import_list':
|
||||
print(getDbBackupImportList())
|
||||
elif func == 'add_db':
|
||||
print(addDb())
|
||||
elif func == 'del_db':
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"path": "server/mysql/VERSION",
|
||||
"todo_versions":["5.6","5.7","8.0"],
|
||||
"versions":["5.5", "5.6", "5.7","8.0"],
|
||||
"updates":["5.5.62","5.6.50", "5.7.32","8.0.22"],
|
||||
"updates":["5.5.62","5.6.50", "5.7.32","8.0.30"],
|
||||
"shell":"install.sh",
|
||||
"checks":"server/mysql",
|
||||
"path":"server/mysql",
|
||||
|
||||
+217
-79
@@ -1,18 +1,9 @@
|
||||
function str2Obj(str){
|
||||
var data = {};
|
||||
kv = str.split('&');
|
||||
for(i in kv){
|
||||
v = kv[i].split('=');
|
||||
data[v[0]] = v[1];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function myPost(method,args,callback, title){
|
||||
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(str2Obj(args));
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
@@ -40,7 +31,7 @@ function myPostN(method,args,callback, title){
|
||||
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(str2Obj(args));
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
@@ -59,7 +50,7 @@ function myPostN(method,args,callback, title){
|
||||
function myAsyncPost(method,args){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(str2Obj(args));
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
@@ -68,6 +59,26 @@ function myAsyncPost(method,args){
|
||||
return syncPost('/plugins/run', {name:'mysql', func:method, args:_args});
|
||||
}
|
||||
|
||||
function vaildPhpmyadmin(url,username,password){
|
||||
|
||||
console.log("Authorization: Basic " + btoa(username + ":" + password));
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
dataType: 'json',
|
||||
async: false,
|
||||
username:username,
|
||||
password:password,
|
||||
headers: {
|
||||
"Authorization": "Basic " + btoa(username + ":" + password)
|
||||
},
|
||||
data: 'vaild',
|
||||
success: function (){
|
||||
alert('Thanks for your comment!');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function runInfo(){
|
||||
myPost('run_info','',function(data){
|
||||
|
||||
@@ -586,7 +597,7 @@ function setDbAccess(username){
|
||||
yes:function(index){
|
||||
var data = $("#set_db_access").serialize();
|
||||
data = decodeURIComponent(data);
|
||||
var dataObj = str2Obj(data);
|
||||
var dataObj = toArrayObject(data);
|
||||
if(!dataObj['access']){
|
||||
dataObj['access'] = dataObj['dataAccess'];
|
||||
if ( dataObj['dataAccess'] == 'ip'){
|
||||
@@ -652,33 +663,15 @@ function setDbPass(id, username, password){
|
||||
}
|
||||
|
||||
function addDatabase(type){
|
||||
if (type==1){
|
||||
var data = $("#add_db").serialize();
|
||||
data = decodeURIComponent(data);
|
||||
var dataObj = str2Obj(data);
|
||||
if(!dataObj['address']){
|
||||
dataObj['address'] = dataObj['dataAccess'];
|
||||
}
|
||||
myPost('add_db', dataObj, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
dbList();
|
||||
}
|
||||
$('.layui-layer-close1').click();
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
});
|
||||
return;
|
||||
}
|
||||
var index = layer.open({
|
||||
layer.open({
|
||||
type: 1,
|
||||
skin: 'demo-class',
|
||||
area: '500px',
|
||||
title: '添加数据库',
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
content: "<form class='bt-form pd20 pb70' id='add_db'>\
|
||||
btn:["提交","关闭"],
|
||||
content: "<form class='bt-form pd20' id='add_db'>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>数据库名</span>\
|
||||
<div class='info-r'><input name='name' class='bt-input-text mr5' placeholder='新的数据库名称' type='text' style='width:65%' value=''>\
|
||||
@@ -706,28 +699,39 @@ function addDatabase(type){
|
||||
</div>\
|
||||
</div>\
|
||||
<input type='hidden' name='ps' value='' />\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button id='my_mod_close' type='button' class='btn btn-danger btn-sm btn-title'>关闭</button>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title' onclick=\"addDatabase(1)\" >提交</button>\
|
||||
</div>\
|
||||
</form>",
|
||||
});
|
||||
success:function(){
|
||||
$("input[name='name']").keyup(function(){
|
||||
var v = $(this).val();
|
||||
$("input[name='db_user']").val(v);
|
||||
$("input[name='ps']").val(v);
|
||||
});
|
||||
|
||||
$("input[name='name']").keyup(function(){
|
||||
var v = $(this).val();
|
||||
$("input[name='db_user']").val(v);
|
||||
$("input[name='ps']").val(v);
|
||||
});
|
||||
|
||||
$('#my_mod_close').click(function(){
|
||||
$('.layui-layer-close1').click();
|
||||
});
|
||||
$('select[name="dataAccess"]').change(function(){
|
||||
var v = $(this).val();
|
||||
if (v == 'ip'){
|
||||
$(this).after("<input id='dataAccess_subid' class='bt-input-text mr5' type='text' name='address' placeholder='多个IP使用逗号(,)分隔' style='width: 230px; display: inline-block;'>");
|
||||
} else {
|
||||
$('#dataAccess_subid').remove();
|
||||
$('select[name="dataAccess"]').change(function(){
|
||||
var v = $(this).val();
|
||||
if (v == 'ip'){
|
||||
$(this).after("<input id='dataAccess_subid' class='bt-input-text mr5' type='text' name='address' placeholder='多个IP使用逗号(,)分隔' style='width: 230px; display: inline-block;'>");
|
||||
} else {
|
||||
$('#dataAccess_subid').remove();
|
||||
}
|
||||
});
|
||||
},
|
||||
yes:function(index) {
|
||||
var data = $("#add_db").serialize();
|
||||
data = decodeURIComponent(data);
|
||||
var dataObj = toArrayObject(data);
|
||||
if(!dataObj['address']){
|
||||
dataObj['address'] = dataObj['dataAccess'];
|
||||
}
|
||||
myPost('add_db', dataObj, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
layer.close(index);
|
||||
dbList();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -739,7 +743,6 @@ function delDb(id, name){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
dbList();
|
||||
$('.layui-layer-close1').click();
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
});
|
||||
@@ -818,16 +821,19 @@ function openPhpmyadmin(name,username,password){
|
||||
layer.msg('当前为[mariadb]模式,若要使用请切换模式.',{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log(data);
|
||||
|
||||
var phpmyadmin_cfg = rdata;
|
||||
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'get_home_page'});
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (!rdata.status){
|
||||
layer.msg(rdata.msg,{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
$("#toPHPMyAdmin").attr('action',rdata.data);
|
||||
var home_page = rdata.data;
|
||||
|
||||
home_page = home_page.replace("http://","http://"+phpmyadmin_cfg['username']+":"+phpmyadmin_cfg['password']+"@")
|
||||
|
||||
$("#toPHPMyAdmin").attr('action',home_page);
|
||||
if($("#toPHPMyAdmin").attr('action').indexOf('phpmyadmin') == -1){
|
||||
layer.msg('请先安装phpMyAdmin',{icon:2,shade: [0.3, '#000']});
|
||||
setTimeout(function(){ window.location.href = '/soft'; },3000);
|
||||
@@ -836,7 +842,7 @@ function openPhpmyadmin(name,username,password){
|
||||
|
||||
//检查版本
|
||||
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'version'});
|
||||
bigVer = data.data.split('.')[0]
|
||||
bigVer = data.data.split('.')[0];
|
||||
if (bigVer>=4.5){
|
||||
|
||||
setTimeout(function(){
|
||||
@@ -858,8 +864,11 @@ function openPhpmyadmin(name,username,password){
|
||||
}
|
||||
}
|
||||
|
||||
function delBackup(filename,name){
|
||||
myPost('delete_db_backup',{filename:filename},function(){
|
||||
function delBackup(filename,name,path){
|
||||
if(typeof(path) == "undefined"){
|
||||
path = "";
|
||||
}
|
||||
myPost('delete_db_backup',{filename:filename,path:path},function(){
|
||||
layer.msg('执行成功!');
|
||||
setTimeout(function(){
|
||||
$('.layui-layer-close2').click();
|
||||
@@ -879,6 +888,132 @@ function importBackup(file,name){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function importDbExternal(file,name){
|
||||
myPost('import_db_external',{file:file,name:name}, function(data){
|
||||
layer.msg('执行成功!');
|
||||
});
|
||||
}
|
||||
|
||||
function setLocalImport(db_name){
|
||||
|
||||
//上传文件
|
||||
function uploadDbFiles(upload_dir){
|
||||
var up_db = layer.open({
|
||||
type:1,
|
||||
closeBtn: 1,
|
||||
title:"上传导入文件["+upload_dir+']',
|
||||
area: ['500px','300px'],
|
||||
shadeClose:false,
|
||||
content:'<div class="fileUploadDiv">\
|
||||
<input type="hidden" id="input-val" value="'+upload_dir+'" />\
|
||||
<input type="file" id="file_input" multiple="true" autocomplete="off" />\
|
||||
<button type="button" id="opt" autocomplete="off">添加文件</button>\
|
||||
<button type="button" id="up" autocomplete="off" >开始上传</button>\
|
||||
<span id="totalProgress" style="position: absolute;top: 7px;right: 147px;"></span>\
|
||||
<span style="float:right;margin-top: 9px;">\
|
||||
<font>文件编码:</font>\
|
||||
<select id="fileCodeing" >\
|
||||
<option value="byte">二进制</option>\
|
||||
<option value="utf-8">UTF-8</option>\
|
||||
<option value="gb18030">GB2312</option>\
|
||||
</select>\
|
||||
</span>\
|
||||
<button type="button" id="filesClose" autocomplete="off">关闭</button>\
|
||||
<ul id="up_box"></ul>\
|
||||
</div>',
|
||||
success:function(){
|
||||
$('#filesClose').click(function(){
|
||||
layer.close(up_db);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
uploadStart(function(){
|
||||
getList();
|
||||
});
|
||||
}
|
||||
|
||||
function getList(){
|
||||
myPost('get_db_backup_import_list',{}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
|
||||
var file_list = rdata.data.list;
|
||||
var upload_dir = rdata.data.upload_dir;
|
||||
|
||||
var tbody = '';
|
||||
for (var i = 0; i < file_list.length; i++) {
|
||||
tbody += '<tr>\
|
||||
<td><span> ' + file_list[i]['name'] + '</span></td>\
|
||||
<td><span> ' + file_list[i]['size'] + '</span></td>\
|
||||
<td><span> ' + file_list[i]['time'] + '</span></td>\
|
||||
<td style="text-align: right;">\
|
||||
<a class="btlink" onclick="importDbExternal(\'' + file_list[i]['name'] + '\',\'' +db_name+ '\')">导入</a> | \
|
||||
<a class="btlink del" index="'+i+'">删除</a>\
|
||||
</td>\
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$('#import_db_file_list').html(tbody);
|
||||
$('input[name="upload_dir"]').val(upload_dir);
|
||||
|
||||
$("#import_db_file_list .del").on('click',function(){
|
||||
var index = $(this).attr('index');
|
||||
var filename = file_list[index]["name"];
|
||||
myPost('delete_db_backup',{filename:filename,path:upload_dir},function(){
|
||||
showMsg('执行成功!', function(){
|
||||
getList();
|
||||
},{icon:1},2000);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var layerIndex = layer.open({
|
||||
type: 1,
|
||||
title: "从文件导入数据",
|
||||
area: ['600px', '380px'],
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div class="db_list">\
|
||||
<button id="btn_file_upload" class="btn btn-success btn-sm" type="button">从本地上传</button>\
|
||||
</div >\
|
||||
<div class="divtable">\
|
||||
<input type="hidden" name="upload_dir" value=""> \
|
||||
<div id="database_fix" style="height:150px;overflow:auto;border:#ddd 1px solid">\
|
||||
<table class="table table-hover "style="border:none">\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th>文件名称</th>\
|
||||
<th>文件大小</th>\
|
||||
<th>备份时间</th>\
|
||||
<th style="text-align: right;">操作</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id="import_db_file_list" class="gztr"></tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
<ul class="help-info-text c7">\
|
||||
<li>仅支持sql、zip、sql.gz、(tar.gz|gz|tgz)</li>\
|
||||
<li>zip、tar.gz压缩包结构:test.zip或test.tar.gz压缩包内,必需包含test.sql</li>\
|
||||
<li>若文件过大,您还可以使用SFTP工具,将数据库文件上传到/www/backup/import</li>\
|
||||
</ul>\
|
||||
</div>\
|
||||
</div>',
|
||||
success:function(index){
|
||||
$('#btn_file_upload').click(function(){
|
||||
var upload_dir = $('input[name="upload_dir"]').val();
|
||||
uploadDbFiles(upload_dir);
|
||||
});
|
||||
|
||||
getList();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function setBackup(db_name,obj){
|
||||
myPost('get_db_backup_list', {name:db_name}, function(data){
|
||||
|
||||
@@ -891,21 +1026,21 @@ function setBackup(db_name,obj){
|
||||
<td><span> ' + rdata.data[i]['time'] + '</span></td>\
|
||||
<td style="text-align: right;">\
|
||||
<a class="btlink" onclick="importBackup(\'' + rdata.data[i]['name'] + '\',\'' +db_name+ '\')">导入</a> | \
|
||||
<a class="btlink" onclick="downloadBackup(\'' + rdata.data[i]['file'] + '\')">下载</a> | \
|
||||
<a class="btlink" onclick="delBackup(\'' + rdata.data[i]['name'] + '\',\'' +db_name+ '\')">删除</a>\
|
||||
</td>\
|
||||
</tr> ';
|
||||
}
|
||||
|
||||
var s = layer.open({
|
||||
var layerIndex = layer.open({
|
||||
type: 1,
|
||||
title: "数据库备份详情",
|
||||
area: ['600px', '280px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div class="db_list">\
|
||||
<button id="btn_backup" class="btn btn-success btn-sm" type="button">备份</button>\
|
||||
<button id="btn_local_import" class="btn btn-success btn-sm" type="button">外部导入</button>\
|
||||
</div >\
|
||||
<div class="divtable">\
|
||||
<div id="database_fix" style="height:150px;overflow:auto;border:#ddd 1px solid">\
|
||||
@@ -922,18 +1057,21 @@ function setBackup(db_name,obj){
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>'
|
||||
});
|
||||
</div>',
|
||||
success:function(index){
|
||||
$('#btn_backup').click(function(){
|
||||
myPost('set_db_backup',{name:db_name}, function(data){
|
||||
showMsg('执行成功!', function(){
|
||||
layer.close(layerIndex);
|
||||
setBackup(db_name,obj);
|
||||
}, {icon:1}, 2000);
|
||||
});
|
||||
});
|
||||
|
||||
$('#btn_backup').click(function(){
|
||||
myPost('set_db_backup',{name:db_name}, function(data){
|
||||
layer.msg('执行成功!');
|
||||
|
||||
setTimeout(function(){
|
||||
layer.close(s);
|
||||
setBackup(db_name,obj);
|
||||
},2000);
|
||||
});
|
||||
$('#btn_local_import').click(function(){
|
||||
setLocalImport(db_name);
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1214,7 +1352,7 @@ function repTools(db_name, res){
|
||||
type: 1,
|
||||
title: "MySQL工具箱【" + db_name + "】",
|
||||
area: ['780px', '580px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div class="db_list">\
|
||||
@@ -1309,7 +1447,7 @@ function addMasterRepSlaveUser(){
|
||||
yes:function(index){
|
||||
var data = $("#add_master").serialize();
|
||||
data = decodeURIComponent(data);
|
||||
var dataObj = str2Obj(data);
|
||||
var dataObj = toArrayObject(data);
|
||||
if(!dataObj['address']){
|
||||
dataObj['address'] = dataObj['dataAccess'];
|
||||
}
|
||||
@@ -1354,7 +1492,7 @@ function updateMasterRepSlaveUser(username){
|
||||
$('#submit_update_master').click(function(){
|
||||
var data = $("#update_master").serialize();
|
||||
data = decodeURIComponent(data);
|
||||
var dataObj = str2Obj(data);
|
||||
var dataObj = toArrayObject(data);
|
||||
myPost('update_master_rep_slave_user', data, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
@@ -1465,7 +1603,7 @@ function setDbMasterAccess(username){
|
||||
yes:function(index){
|
||||
var data = $("#set_db_access").serialize();
|
||||
data = decodeURIComponent(data);
|
||||
var dataObj = str2Obj(data);
|
||||
var dataObj = toArrayObject(data);
|
||||
if(!dataObj['access']){
|
||||
dataObj['access'] = dataObj['dataAccess'];
|
||||
if ( dataObj['dataAccess'] == 'ip'){
|
||||
|
||||
@@ -74,7 +74,7 @@ Install_mysql()
|
||||
OPENSSL_VERSION=`openssl version|awk '{print $2}'|awk -F '.' '{print $1}'`
|
||||
if [ "${OPENSSL_VERSION}" -ge "3" ];then
|
||||
#openssl version to high
|
||||
cd $serverPath/mdserver-web/plugins/php/lib && /bin/bash openssl.sh
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl/lib/pkgconfig
|
||||
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl"
|
||||
fi
|
||||
|
||||
@@ -17,7 +17,7 @@ sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mysqlDir=${serverPath}/source/mysql
|
||||
|
||||
VERSION="5.7.37"
|
||||
VERSION=5.7.39
|
||||
|
||||
|
||||
Install_mysql()
|
||||
@@ -61,14 +61,14 @@ Install_mysql()
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
cd $serverPath/mdserver-web/plugins/mysql/lib && /bin/bash rpcgen.sh
|
||||
cd ${rootPath}/plugins/mysql/lib && /bin/bash rpcgen.sh
|
||||
|
||||
if [ ! -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-${VERSION}.tar.gz
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-${VERSION}.tar.gz
|
||||
fi
|
||||
|
||||
#检测文件是否损坏.
|
||||
md5_mysql_ok=d0489fc3880248a58759c50bfb286dbb
|
||||
md5_mysql_ok=d949b0ef81c3f52f7ef0874066244221
|
||||
if [ -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
|
||||
md5_mysql=`md5sum ${mysqlDir}/mysql-boost-${VERSION}.tar.gz | awk '{print $1}'`
|
||||
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
|
||||
@@ -76,7 +76,7 @@ Install_mysql()
|
||||
else
|
||||
# 重新下载
|
||||
rm -rf ${mysqlDir}/mysql-${VERSION}
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-${VERSION}.tar.gz
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-${VERSION}.tar.gz
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -89,7 +89,7 @@ Install_mysql()
|
||||
OPENSSL_VERSION=`openssl version|awk '{print $2}'|awk -F '.' '{print $1}'`
|
||||
if [ "${OPENSSL_VERSION}" -ge "3" ];then
|
||||
#openssl version to high
|
||||
cd $serverPath/mdserver-web/plugins/php/lib && /bin/bash openssl.sh
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl/lib/pkgconfig
|
||||
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl"
|
||||
fi
|
||||
|
||||
@@ -57,7 +57,7 @@ fi
|
||||
VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
|
||||
|
||||
VERSION=8.0.28
|
||||
VERSION=8.0.30
|
||||
Install_mysql()
|
||||
{
|
||||
mkdir -p ${mysqlDir}
|
||||
@@ -95,7 +95,7 @@ Install_mysql()
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
cd $serverPath/mdserver-web/plugins/mysql/lib && /bin/bash rpcgen.sh
|
||||
cd ${rootPath}/plugins/mysql/lib && /bin/bash rpcgen.sh
|
||||
|
||||
INSTALL_CMD=cmake
|
||||
# check cmake version
|
||||
@@ -107,11 +107,11 @@ Install_mysql()
|
||||
fi
|
||||
|
||||
if [ ! -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
fi
|
||||
|
||||
#检测文件是否损坏.
|
||||
md5_mysql_ok=362b8141ecaf425b803fe55292e2df98
|
||||
md5_mysql_ok=313d625fcaa932bd87b48f0cf9b40f1c
|
||||
if [ -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
|
||||
md5_mysql=`md5sum ${mysqlDir}/mysql-boost-${VERSION}.tar.gz | awk '{print $1}'`
|
||||
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
|
||||
@@ -119,7 +119,7 @@ Install_mysql()
|
||||
else
|
||||
# 重新下载
|
||||
rm -rf ${mysqlDir}/mysql-${VERSION}
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
wget -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-${VERSION}.tar.gz
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -132,7 +132,7 @@ Install_mysql()
|
||||
OPENSSL_VERSION=`openssl version|awk '{print $2}'|awk -F '.' '{print $1}'`
|
||||
if [ "${OPENSSL_VERSION}" -ge "3" ];then
|
||||
#openssl version to high
|
||||
cd $serverPath/mdserver-web/plugins/php/lib && /bin/bash openssl.sh
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl/lib/pkgconfig
|
||||
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
class luamaker:
|
||||
"""
|
||||
lua 处理器
|
||||
"""
|
||||
@staticmethod
|
||||
def makeLuaTable(table):
|
||||
"""
|
||||
table 转换为 lua table 字符串
|
||||
"""
|
||||
_tableMask = {}
|
||||
_keyMask = {}
|
||||
|
||||
def analysisTable(_table, _indent, _parent):
|
||||
if isinstance(_table, tuple):
|
||||
_table = list(_table)
|
||||
if isinstance(_table, list):
|
||||
_table = dict(zip(range(1, len(_table) + 1), _table))
|
||||
if isinstance(_table, dict):
|
||||
_tableMask[id(_table)] = _parent
|
||||
cell = []
|
||||
thisIndent = _indent + " "
|
||||
for k in _table:
|
||||
if sys.version_info[0] == 2:
|
||||
if type(k) not in [int, float, bool, list, dict, tuple]:
|
||||
k = k.encode()
|
||||
|
||||
if not (isinstance(k, str) or isinstance(k, int) or isinstance(k, float)):
|
||||
return
|
||||
key = isinstance(
|
||||
k, int) and "[" + str(k) + "]" or "[\"" + str(k) + "\"]"
|
||||
if _parent + key in _keyMask.keys():
|
||||
return
|
||||
_keyMask[_parent + key] = True
|
||||
var = None
|
||||
v = _table[k]
|
||||
if sys.version_info[0] == 2:
|
||||
if type(v) not in [int, float, bool, list, dict, tuple]:
|
||||
v = v.encode()
|
||||
if isinstance(v, str):
|
||||
# print("lua", var)
|
||||
v = v.replace("\\", "\\\\")
|
||||
v = v.replace("\"", "\\\"")
|
||||
var = "\"" + v + "\""
|
||||
|
||||
elif isinstance(v, bool):
|
||||
var = v and "true" or "false"
|
||||
elif isinstance(v, int) or isinstance(v, float):
|
||||
var = str(v)
|
||||
else:
|
||||
var = analysisTable(v, thisIndent, _parent + key)
|
||||
|
||||
cell.append(thisIndent + key + " = " + str(var))
|
||||
lineJoin = ",\n"
|
||||
return "{\n" + lineJoin.join(cell) + "\n" + _indent + "}"
|
||||
else:
|
||||
pass
|
||||
return analysisTable(table, "", "root")
|
||||
@@ -0,0 +1,17 @@
|
||||
PRAGMA synchronous = 0;
|
||||
PRAGMA page_size = 4096;
|
||||
PRAGMA journal_mode = wal;
|
||||
PRAGMA journal_size_limit = 1073741824;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `logs` (
|
||||
`time` INTEGER,
|
||||
`ip` TEXT,
|
||||
`domain` TEXT,
|
||||
`server_name` TEXT,
|
||||
`method` TEXT,
|
||||
`status_code` INTEGER,
|
||||
`user_agent` TEXT,
|
||||
`uri` TEXT,
|
||||
`rule_name` TEXT,
|
||||
`reason` TEXT
|
||||
);
|
||||
@@ -1,8 +1,10 @@
|
||||
lua_shared_dict limit 30m;
|
||||
lua_shared_dict drop_ip 30m;
|
||||
lua_shared_dict drop_sum 30m;
|
||||
lua_package_path "{$WAF_PATH}/lua/?.lua;{$ROOT_PATH}/openresty/lualib/?.lua;;";
|
||||
lua_shared_dict waf_limit 30m;
|
||||
lua_shared_dict waf_drop_ip 10m;
|
||||
lua_shared_dict waf_drop_sum 10m;
|
||||
lua_package_path "{$WAF_PATH}/html/?.lua;{$WAF_PATH}/conf/?.lua;{$WAF_PATH}/lua/?.lua;{$ROOT_PATH}/openresty/lualib/?.lua;;";
|
||||
lua_package_cpath "{$WAF_PATH}/conf/?.so;{$ROOT_PATH}/openresty/lualib/?.so;;";
|
||||
|
||||
init_worker_by_lua_file {$WAF_PATH}/lua/init_worker.lua;
|
||||
access_by_lua_file {$WAF_PATH}/lua/init.lua;
|
||||
|
||||
#init_by_lua_file {$WAF_PATH}/lua/init.lua;
|
||||
#access_by_lua_file {$WAF_PATH}/lua/waf.lua;
|
||||
# init_by_lua_file {$WAF_PATH}/lua/init.lua;
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
<style>
|
||||
|
||||
.overflow_hide {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.cur {
|
||||
background-color: #20a53a;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/*waf*/
|
||||
.lib-con-title {
|
||||
height: 26px;
|
||||
@@ -231,8 +245,8 @@
|
||||
<p onclick="wafScreen();">首页</p>
|
||||
<p onclick="wafGloabl();">全局配置</p>
|
||||
<p onclick="wafSite();">站点配置</p>
|
||||
<p onclick="wafHistory();">封锁历史</p>
|
||||
<!-- <p onclick="wafLogs();">操作日志</p> -->
|
||||
<p onclick="wafLogs();">封锁历史</p>
|
||||
<!-- <p onclick="wafOpLogs();">操作日志</p> -->
|
||||
</div>
|
||||
<!-- lib-con -->
|
||||
<div class="bt-w-con pd15">
|
||||
|
||||
+306
-28
@@ -52,11 +52,50 @@ def checkArgs(data, ck=[]):
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
from luamaker import luamaker
|
||||
|
||||
|
||||
def listToLuaFile(path, lists):
|
||||
content = luamaker.makeLuaTable(lists)
|
||||
content = "return " + content
|
||||
mw.writeFile(path, content)
|
||||
|
||||
|
||||
def htmlToLuaFile(path, content):
|
||||
content = "return [[" + content + "]]"
|
||||
mw.writeFile(path, content)
|
||||
|
||||
|
||||
def getConf():
|
||||
path = mw.getServerDir() + "/openresty/nginx/conf/nginx.conf"
|
||||
return path
|
||||
|
||||
|
||||
def pSqliteDb(dbname='logs'):
|
||||
name = "waf"
|
||||
db_dir = getServerDir() + '/logs/'
|
||||
|
||||
if not os.path.exists(db_dir):
|
||||
mw.execShell('mkdir -p ' + db_dir)
|
||||
|
||||
file = db_dir + name + '.db'
|
||||
if not os.path.exists(file):
|
||||
conn = mw.M(dbname).dbPos(db_dir, name)
|
||||
sql = mw.readFile(getPluginDir() + '/conf/init.sql')
|
||||
sql_list = sql.split(';')
|
||||
for index in range(len(sql_list)):
|
||||
conn.execute(sql_list[index])
|
||||
else:
|
||||
conn = mw.M(dbname).dbPos(db_dir, name)
|
||||
|
||||
conn.execute("PRAGMA synchronous = 0")
|
||||
conn.execute("PRAGMA page_size = 4096")
|
||||
conn.execute("PRAGMA journal_mode = wal")
|
||||
conn.execute("PRAGMA journal_size_limit = 1073741824")
|
||||
return conn
|
||||
|
||||
|
||||
def initDomainInfo():
|
||||
data = []
|
||||
path_domains = getJsonPath('domains')
|
||||
@@ -107,11 +146,11 @@ def initSiteInfo():
|
||||
site_contents_new[name] = site_contents[name]
|
||||
else:
|
||||
tmp = {}
|
||||
tmp['cdn'] = False
|
||||
tmp['cdn'] = True
|
||||
tmp['log'] = True
|
||||
tmp['get'] = True
|
||||
tmp['post'] = True
|
||||
tmp['open'] = False
|
||||
tmp['open'] = True
|
||||
|
||||
tmp['cc'] = config_contents['cc']
|
||||
tmp['retry'] = config_contents['retry']
|
||||
@@ -120,9 +159,24 @@ def initSiteInfo():
|
||||
tmp['user-agent'] = config_contents['user-agent']
|
||||
tmp['cookie'] = config_contents['cookie']
|
||||
tmp['scan'] = config_contents['scan']
|
||||
tmp['safe_verify'] = config_contents['safe_verify']
|
||||
|
||||
cdn_header = ['x-forwarded-for',
|
||||
'x-real-ip', 'HTTP_CF_CONNECTING_IP']
|
||||
'x-real-ip',
|
||||
'x-forwarded',
|
||||
'forwarded-for',
|
||||
'forwarded',
|
||||
'true-client-ip',
|
||||
'client-ip',
|
||||
'ali-cdn-real-ip',
|
||||
'cdn-src-ip',
|
||||
'cdn-real-ip',
|
||||
'cf-connecting-ip',
|
||||
'x-cluster-client-ip',
|
||||
'wl-proxy-client-ip',
|
||||
'proxy-client-ip',
|
||||
'true-client-ip',
|
||||
'HTTP_CF_CONNECTING_IP']
|
||||
tmp['cdn_header'] = cdn_header
|
||||
|
||||
disable_upload_ext = ["php", "jsp"]
|
||||
@@ -163,6 +217,9 @@ def initTotalInfo():
|
||||
tmp['get'] = 0
|
||||
tmp['post'] = 0
|
||||
tmp['total'] = 0
|
||||
tmp['path'] = 0
|
||||
tmp['php_path'] = 0
|
||||
tmp['upload_ext'] = 0
|
||||
_name = {}
|
||||
_name[name] = tmp
|
||||
total_contents['sites'] = _name
|
||||
@@ -186,21 +243,110 @@ def status():
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = mw.getServerDir()
|
||||
waf_path = getServerDir() + "/waf"
|
||||
waf_root = getServerDir()
|
||||
waf_path = waf_root + "/waf"
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$WAF_PATH}', waf_path)
|
||||
content = content.replace('{$WAF_ROOT}', waf_root)
|
||||
return content
|
||||
|
||||
|
||||
def autoMakeLuaConfSingle(file):
|
||||
# path = getPluginDir() + "/waf/rule/" + file + ".json"
|
||||
path = getServerDir() + "/waf/rule/" + file + ".json"
|
||||
to_path = getServerDir() + "/waf/conf/rule_" + file + ".lua"
|
||||
content = mw.readFile(path)
|
||||
# print(content)
|
||||
content = json.loads(content)
|
||||
listToLuaFile(to_path, content)
|
||||
|
||||
|
||||
def autoMakeLuaImportSingle(file):
|
||||
path = getServerDir() + "/waf/" + file + ".json"
|
||||
to_path = getServerDir() + "/waf/conf/waf_" + file + ".lua"
|
||||
content = mw.readFile(path)
|
||||
# print(content)
|
||||
content = json.loads(content)
|
||||
listToLuaFile(to_path, content)
|
||||
|
||||
|
||||
def autoMakeLuaHtmlSingle(file):
|
||||
path = getServerDir() + "/waf/html/" + file + ".html"
|
||||
to_path = getServerDir() + "/waf/html/html_" + file + ".lua"
|
||||
content = mw.readFile(path)
|
||||
htmlToLuaFile(to_path, content)
|
||||
|
||||
|
||||
def autoMakeLuaConf():
|
||||
conf_list = ['args', 'cookie', 'ip_black', 'ip_white',
|
||||
'ipv6_black', 'post', 'scan_black', 'url',
|
||||
'url_white', 'user_agent']
|
||||
for x in conf_list:
|
||||
autoMakeLuaConfSingle(x)
|
||||
|
||||
import_list = ['config', 'site', 'domains']
|
||||
for x in import_list:
|
||||
autoMakeLuaImportSingle(x)
|
||||
|
||||
html_list = ['get', 'post', 'safe_js', 'user_agent', 'cookie', 'other']
|
||||
for x in html_list:
|
||||
autoMakeLuaHtmlSingle(x)
|
||||
|
||||
|
||||
def initDefaultInfo():
|
||||
path = getServerDir()
|
||||
djson = path + "/waf/domains.json"
|
||||
default_json = path + "/waf/default.json"
|
||||
if os.path.exists(djson):
|
||||
content = mw.readFile(djson)
|
||||
content = json.loads(content)
|
||||
|
||||
ddata = {}
|
||||
dlist = []
|
||||
for i in content:
|
||||
dlist.append(i["name"])
|
||||
|
||||
dlist.append('unset')
|
||||
ddata["list"] = dlist
|
||||
if len(ddata["list"]) < 1:
|
||||
ddata["default"] = "unset"
|
||||
else:
|
||||
ddata["default"] = dlist[0]
|
||||
|
||||
mw.writeFile(default_json, json.dumps(ddata))
|
||||
|
||||
|
||||
def autoMakeConfig():
|
||||
path = getServerDir()
|
||||
|
||||
initDomainInfo()
|
||||
initSiteInfo()
|
||||
initTotalInfo()
|
||||
autoMakeLuaConf()
|
||||
|
||||
|
||||
def restartWeb():
|
||||
autoMakeConfig()
|
||||
mw.restartWeb()
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
path = getServerDir()
|
||||
if not os.path.exists(path + '/waf'):
|
||||
if not os.path.exists(path + '/waf/lua'):
|
||||
sdir = getPluginDir() + '/waf'
|
||||
cmd = 'cp -rf ' + sdir + ' ' + path
|
||||
mw.execShell(cmd)
|
||||
|
||||
logs_path = path + '/logs'
|
||||
if not os.path.exists(logs_path):
|
||||
mw.execShell('mkdir -p ' + logs_path)
|
||||
|
||||
debug_log = path + '/debug.log'
|
||||
if not os.path.exists(debug_log):
|
||||
mw.execShell('echo "" > ' + debug_log)
|
||||
|
||||
config = path + '/waf/config.json'
|
||||
content = mw.readFile(config)
|
||||
content = json.loads(content)
|
||||
@@ -214,6 +360,16 @@ def initDreplace():
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(config, content)
|
||||
|
||||
config_common = path + "/waf/lua/common.lua"
|
||||
content = mw.readFile(config_common)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(config_common, content)
|
||||
|
||||
init_worker = path + "/waf/lua/init_worker.lua"
|
||||
content = mw.readFile(init_worker)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(init_worker, content)
|
||||
|
||||
waf_conf = mw.getServerDir() + "/openresty/nginx/conf/luawaf.conf"
|
||||
waf_tpl = getPluginDir() + "/conf/luawaf.conf"
|
||||
content = mw.readFile(waf_tpl)
|
||||
@@ -223,6 +379,13 @@ def initDreplace():
|
||||
initDomainInfo()
|
||||
initSiteInfo()
|
||||
initTotalInfo()
|
||||
autoMakeLuaConf()
|
||||
initDefaultInfo()
|
||||
|
||||
pSqliteDb()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
mw.execShell("chown -R www:www " + path)
|
||||
|
||||
|
||||
def start():
|
||||
@@ -233,6 +396,9 @@ def start():
|
||||
conf = conf.replace('#include luawaf.conf;', "include luawaf.conf;")
|
||||
mw.writeFile(path, conf)
|
||||
|
||||
import tool_task
|
||||
tool_task.createBgTask()
|
||||
|
||||
mw.restartWeb()
|
||||
return 'ok'
|
||||
|
||||
@@ -243,6 +409,10 @@ def stop():
|
||||
conf = conf.replace('include luawaf.conf;', "#include luawaf.conf;")
|
||||
|
||||
mw.writeFile(path, conf)
|
||||
|
||||
import tool_task
|
||||
tool_task.removeBgTask()
|
||||
|
||||
mw.restartWeb()
|
||||
return 'ok'
|
||||
|
||||
@@ -254,8 +424,19 @@ def restart():
|
||||
|
||||
def reload():
|
||||
stop()
|
||||
mw.execShell('rm -rf ' + mw.getServerDir() +
|
||||
"/openresty/nginx/logs/error.log")
|
||||
|
||||
path = getServerDir()
|
||||
path_tpl = getPluginDir()
|
||||
|
||||
config = path + "/waf/lua/init.lua"
|
||||
config_tpl = path_tpl + "/waf/lua/init.lua"
|
||||
content = mw.readFile(config_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(config, content)
|
||||
|
||||
errlog = mw.getServerDir() + "/openresty/nginx/logs/error.log"
|
||||
mw.execShell('rm -rf ' + errlog)
|
||||
|
||||
start()
|
||||
return 'ok'
|
||||
|
||||
@@ -306,7 +487,7 @@ def addRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -328,7 +509,7 @@ def removeRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -353,7 +534,7 @@ def setRuleState():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -384,7 +565,7 @@ def modifyRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
@@ -425,6 +606,7 @@ def addSiteRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -460,6 +642,7 @@ def addIpWhite():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -480,6 +663,8 @@ def removeIpWhite():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -515,6 +700,8 @@ def addIpBlack():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -535,6 +722,8 @@ def removeIpBlack():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -553,6 +742,7 @@ def setIpv6Black():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -569,9 +759,10 @@ def delIpv6Black():
|
||||
content = json.loads(content)
|
||||
|
||||
content.remove(addr)
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -594,6 +785,8 @@ def removeSiteRule():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -608,11 +801,13 @@ def setObjStatus():
|
||||
cobj = json.loads(content)
|
||||
|
||||
o = args['obj']
|
||||
status = args['statusCode']
|
||||
status = int(args['statusCode'])
|
||||
cobj[o]['status'] = status
|
||||
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -632,6 +827,32 @@ def setRetry():
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
def setSafeVerify():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['auto', 'time', 'cpu'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
conf = getJsonPath('config')
|
||||
content = mw.readFile(conf)
|
||||
cobj = json.loads(content)
|
||||
|
||||
cobj['safe_verify']['time'] = args['time']
|
||||
cobj['safe_verify']['cpu'] = args['cpu']
|
||||
|
||||
if args['auto'] == '0':
|
||||
cobj['safe_verify']['auto'] = False
|
||||
else:
|
||||
cobj['safe_verify']['auto'] = True
|
||||
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
@@ -642,7 +863,7 @@ def setSiteRetry():
|
||||
def setCcConf():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['siteName', 'cycle', 'limit',
|
||||
'endtime', 'is_open_global', 'increase'])
|
||||
'endtime', 'is_open_global'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
@@ -661,6 +882,8 @@ def setCcConf():
|
||||
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
@@ -677,6 +900,8 @@ def saveScanRule():
|
||||
path = getRuleJsonPath('scan_black')
|
||||
cjson = mw.getJson(args)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
@@ -716,6 +941,26 @@ def getSiteConfig():
|
||||
return mw.returnJson(True, 'ok!', content)
|
||||
|
||||
|
||||
def getSiteListData():
|
||||
path = getServerDir() + "/waf/default.json"
|
||||
data = mw.readFile(path)
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def setDefaultSite(name):
|
||||
path = getServerDir() + "/waf/default.json"
|
||||
data = mw.readFile(path)
|
||||
data = json.loads(data)
|
||||
data['default'] = name
|
||||
mw.writeFile(path, json.dumps(data))
|
||||
return mw.returnJson(True, 'OK')
|
||||
|
||||
|
||||
def getDefaultSite():
|
||||
data = getSiteListData()
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def getSiteConfigByName():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['siteName'])
|
||||
@@ -749,6 +994,8 @@ def addSiteCdnHeader():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '添加成功!')
|
||||
|
||||
|
||||
@@ -768,6 +1015,8 @@ def removeSiteCdnHeader():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
@@ -790,29 +1039,44 @@ def importData():
|
||||
|
||||
path = getRuleJsonPath(args['s_Name'])
|
||||
mw.writeFile(path, args['pdata'])
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def getLogsList():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['siteName'])
|
||||
data = checkArgs(args, ['site', 'page', 'page_size', 'tojs'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
data = []
|
||||
path = mw.getLogsDir() + '/waf'
|
||||
page = int(args['page'])
|
||||
page_size = int(args['page_size'])
|
||||
domain = args['site']
|
||||
tojs = args['tojs']
|
||||
|
||||
if not os.path.exists(path):
|
||||
return mw.returnJson(False, '还未生成!', [])
|
||||
conn = pSqliteDb('logs')
|
||||
|
||||
files = os.listdir(path)
|
||||
for f in files:
|
||||
if f == '.DS_Store':
|
||||
continue
|
||||
f = f.split('_')
|
||||
if f[0] == args['siteName']:
|
||||
fl = f[1].split('.')
|
||||
data.append(fl[0])
|
||||
field = 'time,ip,domain,server_name,method,uri,user_agent,rule_name,reason'
|
||||
limit = str(page_size) + ' offset ' + str(page_size * (page - 1))
|
||||
|
||||
condition = ''
|
||||
conn = conn.field(field)
|
||||
conn = conn.where("1=1", ()).where("domain=?", (domain,))
|
||||
|
||||
clist = conn.limit(limit).order('time desc').inquiry()
|
||||
count_key = "count(*) as num"
|
||||
count = conn.field(count_key).limit('').order('').inquiry()
|
||||
# print(count)
|
||||
count = count[0][count_key]
|
||||
|
||||
data = {}
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['p'] = page
|
||||
_page['row'] = page_size
|
||||
_page['tojs'] = tojs
|
||||
data['page'] = mw.getPage(_page)
|
||||
data['data'] = clist
|
||||
|
||||
return mw.returnJson(True, 'ok!', data)
|
||||
|
||||
@@ -823,7 +1087,7 @@ def getSafeLogs():
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
path = mw.getLogsDir() + '/waf'
|
||||
path = getServerDir() + '/logs'
|
||||
file = path + '/' + args['siteName'] + '_' + args['toDate'] + '.log'
|
||||
if not os.path.exists(file):
|
||||
return mw.returnJson(False, "文件不存在!")
|
||||
@@ -859,6 +1123,7 @@ def setObjOpen():
|
||||
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -888,6 +1153,7 @@ def setSiteObjOpen():
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -908,6 +1174,12 @@ def installPreInspection():
|
||||
return 'ok'
|
||||
|
||||
|
||||
def cleanDropIp():
|
||||
url = "http://127.0.0.1/clean_waf_drop_ip"
|
||||
data = mw.httpGet(url)
|
||||
return mw.returnJson(True, 'ok!', data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
@@ -964,12 +1236,16 @@ if __name__ == "__main__":
|
||||
print(setSiteCcConf())
|
||||
elif func == 'set_retry':
|
||||
print(setRetry())
|
||||
elif func == 'set_safe_verify':
|
||||
print(setSafeVerify())
|
||||
elif func == 'set_site_retry':
|
||||
print(setSiteRetry())
|
||||
elif func == 'save_scan_rule':
|
||||
print(saveScanRule())
|
||||
elif func == 'get_site_config':
|
||||
print(getSiteConfig())
|
||||
elif func == 'get_default_site':
|
||||
print(getDefaultSite())
|
||||
elif func == 'get_site_config_byname':
|
||||
print(getSiteConfigByName())
|
||||
elif func == 'add_site_cdn_header':
|
||||
@@ -990,5 +1266,7 @@ if __name__ == "__main__":
|
||||
print(getWafConf())
|
||||
elif func == 'waf_site':
|
||||
print(getWafSite())
|
||||
elif func == 'clean_drop_ip':
|
||||
print(cleanDropIp())
|
||||
else:
|
||||
print('error')
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"name":"op_waf",
|
||||
"type":"其他插件",
|
||||
"ps":"有效防止sql注入/xss/一句话木马等常见渗透攻击",
|
||||
"install_pre_inspection":true,
|
||||
"shell":"install.sh",
|
||||
"checks":"server/op_waf",
|
||||
"path":"server/op_waf",
|
||||
@@ -11,5 +12,5 @@
|
||||
"home":"https://github.com/loveshell/ngx_lua_waf",
|
||||
"date":"2019-04-21",
|
||||
"pid": "1",
|
||||
"versions": ["0.1"]
|
||||
"versions": ["0.2.3"]
|
||||
}
|
||||
@@ -7,31 +7,99 @@ rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
action=$1
|
||||
version=$2
|
||||
sys_os=`uname`
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
if [ "$sys_os" == "Darwin" ];then
|
||||
BAK='_bak'
|
||||
else
|
||||
BAK=''
|
||||
fi
|
||||
|
||||
|
||||
Install_of(){
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/source/op_waf
|
||||
mkdir -p $serverPath/op_waf
|
||||
|
||||
echo '0.1' > $serverPath/op_waf/version.pl
|
||||
# luarocks
|
||||
if [ ! -f $serverPath/source/op_waf/luarocks-3.5.0.tar.gz ];then
|
||||
wget --no-check-certificate -O $serverPath/source/op_waf/luarocks-3.5.0.tar.gz http://luarocks.org/releases/luarocks-3.5.0.tar.gz
|
||||
fi
|
||||
|
||||
# which luarocks
|
||||
# if [ "$?" != "0" ];then
|
||||
if [ ! -d $serverPath/op_waf/luarocks ];then
|
||||
cd $serverPath/source/op_waf && tar xvf luarocks-3.5.0.tar.gz
|
||||
# cd luarocks-3.9.1 && ./configure && make bootstrap
|
||||
|
||||
cd luarocks-3.5.0 && ./configure --prefix=$serverPath/op_waf/luarocks --with-lua-include=$serverPath/openresty/luajit/include/luajit-2.1 --with-lua-bin=$serverPath/openresty/luajit/bin
|
||||
make -I${serverPath}/openresty/luajit/bin
|
||||
make install
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -f $serverPath/source/op_waf/lsqlite3_fsl09y.zip ];then
|
||||
wget --no-check-certificate -O $serverPath/source/op_waf/lsqlite3_fsl09y.zip http://lua.sqlite.org/index.cgi/zip/lsqlite3_fsl09y.zip?uuid=fsl_9y
|
||||
cd $serverPath/source/op_waf && unzip lsqlite3_fsl09y.zip
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/source/op_waf/lsqlite3_fsl09y ];then
|
||||
cd $serverPath/source/op_waf && unzip lsqlite3_fsl09y.zip
|
||||
fi
|
||||
|
||||
PATH=${serverPath}/openresty/luajit:${serverPath}/openresty/luajit/include/luajit-2.1:$PATH
|
||||
export PATH=$PATH:$serverPath/op_waf/luarocks/bin
|
||||
|
||||
if [ ! -f $serverPath/op_waf/waf/conf/lsqlite3.so ];then
|
||||
if [ "${sys_os}" == "Darwin" ];then
|
||||
cd $serverPath/source/op_waf/lsqlite3_fsl09y
|
||||
find_cfg=`cat Makefile | grep 'SQLITE_DIR'`
|
||||
if [ "$find_cfg" == "" ];then
|
||||
LIB_SQLITE_DIR=`brew info sqlite | grep /usr/local/Cellar/sqlite | cut -d \ -f 1 | awk 'END {print}'`
|
||||
echo $LIB_SQLITE_DIR
|
||||
sed -i $BAK "s#\$(ROCKSPEC)#\$(ROCKSPEC) SQLITE_DIR=${LIB_SQLITE_DIR}#g" Makefile
|
||||
fi
|
||||
make
|
||||
else
|
||||
cd $serverPath/source/op_waf/lsqlite3_fsl09y && make
|
||||
fi
|
||||
fi
|
||||
|
||||
# copy to code path
|
||||
DEFAULT_DIR=$serverPath/op_waf/luarocks/lib/lua/5.1
|
||||
if [ -f ${DEFAULT_DIR}/lsqlite3.so ];then
|
||||
mkdir -p $serverPath/op_waf/waf/conf
|
||||
cp -rf ${DEFAULT_DIR}/lsqlite3.so $serverPath/op_waf/waf/conf/lsqlite3.so
|
||||
fi
|
||||
|
||||
echo "${version}" > $serverPath/op_waf/version.pl
|
||||
echo 'install ok' > $install_tmp
|
||||
|
||||
cd ${rootPath} && python3 plugins/op_waf/index.py start
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py start
|
||||
|
||||
|
||||
|
||||
# cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py restart
|
||||
}
|
||||
|
||||
Uninstall_of(){
|
||||
|
||||
cd ${rootPath} && python3 plugins/op_waf/index.py stop
|
||||
rm -rf $serverPath/op_waf
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py stop
|
||||
if [ "$?" == "0" ];then
|
||||
rm -rf $serverPath/op_waf
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
type=$2
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_of
|
||||
|
||||
+382
-212
@@ -28,7 +28,7 @@ function setRequestCode(ruleName, statusCode){
|
||||
title: "设置响应代码【" + ruleName + "】",
|
||||
area: '300px',
|
||||
shift: 5,
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: true,
|
||||
content: '<div class="bt-form pd20 pb70">\
|
||||
<div class="line">\
|
||||
@@ -69,8 +69,10 @@ function setObjOpen(ruleName){
|
||||
owPost('set_obj_open', {obj:ruleName},function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata.status){
|
||||
layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
wafGloabl();
|
||||
|
||||
showMsg(rdata.msg, function(){
|
||||
wafGloabl();
|
||||
},{icon:1,time:2000,shade: [0.3, '#000']},2000);
|
||||
} else {
|
||||
layer.msg('设置失败!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
@@ -84,7 +86,7 @@ function saveCcRule(siteName,is_open_global, type) {
|
||||
if(type == 2){
|
||||
// set_aicc_open('start');
|
||||
increase = "0";
|
||||
}else{
|
||||
} else {
|
||||
// set_aicc_open('stop');
|
||||
increase = type;
|
||||
}
|
||||
@@ -144,7 +146,7 @@ function setCcRule(cycle, limit, endtime, siteName, increase){
|
||||
type: 1,
|
||||
title: "设置CC规则",
|
||||
area: '540px',
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<form class="bt-form pd20 pb70">\
|
||||
<div class="line">\
|
||||
@@ -164,7 +166,10 @@ function setCcRule(cycle, limit, endtime, siteName, increase){
|
||||
<li>请不要设置过于严格的CC规则,以免影响正常用户体验</li>\
|
||||
<li><font style="color:red;display:'+ (siteName == 'undefined'?'display: inline-block;':'none') +';">全局应用:全局设置当前CC规则,且覆盖当前全部站点的CC规则</font></li>\
|
||||
</ul>\
|
||||
<div class="bt-form-submit-btn"><button type="button" class="btn btn-danger btn-sm btn_cc_all" style="margin-right:10px;display:'+ (siteName == 'undefined'?'display: inline-block;':'none') +';">全局应用</button><button type="button" class="btn btn-success btn-sm btn_cc_present">应用</button></div>\
|
||||
<div class="bt-form-submit-btn">\
|
||||
<button type="button" class="btn btn-danger btn-sm btn_cc_all" style="margin-right:10px;display:'+ (siteName == 'undefined'?'display: inline-block;':'none') +';">全局应用</button>\
|
||||
<button type="button" class="btn btn-success btn-sm btn_cc_present">应用</button>\
|
||||
</div>\
|
||||
</form>',
|
||||
success:function(layero,index){
|
||||
$('.btn_cc_all').click(function(){
|
||||
@@ -184,7 +189,7 @@ function setRetry(retry_cycle, retry, retry_time, siteName) {
|
||||
type: 1,
|
||||
title: "设置恶意容忍规则",
|
||||
area: '500px',
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<form class="bt-form pd20 pb70">\
|
||||
<div class="line">\
|
||||
@@ -201,9 +206,12 @@ function setRetry(retry_cycle, retry, retry_time, siteName) {
|
||||
</div>\
|
||||
<ul class="help-info-text c7 ptb10">\
|
||||
<li><font style="color:red;">'+ retry_cycle + '</font> 秒内累计恶意请求超过 <font style="color:red;">' + retry + '</font> 次,封锁 <font style="color:red;">' + retry_time + '</font> 秒</li>\
|
||||
<li><font style="color:red;">全局应用:全局设置当前恶意容忍规则,且覆盖当前全部站点的恶意容忍规则</li>\
|
||||
<li><font style="color:red;">全局应用:全局设置当前恶意容忍规则,且覆盖当前全部站点的恶意容忍规则</font></li>\
|
||||
</ul>\
|
||||
<div class="bt-form-submit-btn"><button type="button" class="btn btn-danger btn-sm btn_retry_all" style="margin-right:10px;display:'+ (siteName == undefined?'inline-block;':'none') +';">全局应用</button><button type="button" class="btn btn-success btn-sm btn_retry_present">应用</button></div>\
|
||||
<div class="bt-form-submit-btn">\
|
||||
<button type="button" class="btn btn-danger btn-sm btn_retry_all" style="margin-right:10px;display:'+ (siteName == undefined?'inline-block;':'none') +';">全局应用</button>\
|
||||
<button type="button" class="btn btn-success btn-sm btn_retry_present">应用</button>\
|
||||
</div>\
|
||||
</form>',
|
||||
success:function(){
|
||||
$('.btn_retry_all').click(function(){
|
||||
@@ -217,6 +225,65 @@ function setRetry(retry_cycle, retry, retry_time, siteName) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//设置safe_verify规则
|
||||
function setSafeVerify(auto, cpu, time, siteName) {
|
||||
var svlayer = layer.open({
|
||||
type: 1,
|
||||
title: "设置强制安全验证",
|
||||
area: '500px',
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<form class="bt-form pd20 pb70">\
|
||||
<div class="line">\
|
||||
<span class="tname">CPU</span>\
|
||||
<div class="info-r"><input class="bt-input-text" name="cpu" type="number" max-number="100" value="'+ cpu + '" /> %</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">通行时间</span>\
|
||||
<div class="info-r"><input class="bt-input-text" name="time" type="number" value="'+ time + '" /> 秒</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">开启自动</span>\
|
||||
<div class="info-r">\
|
||||
<select class="bt-input-text mr5" style="width:80px" name="auto">\
|
||||
<option value="0" '+(auto==false?"selected=selected":"")+'>关闭</option>\
|
||||
<option value="1" '+(auto==true?"selected=selected":"")+'>开启</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<ul class="help-info-text c7 ptb10">\
|
||||
<li><font style="color:red;">全局设置强制安全验证</font></li>\
|
||||
<li>开启自动后:cpu超过['+cpu+'%]后,强制验证。</li>\
|
||||
</ul>\
|
||||
<div class="bt-form-submit-btn">\
|
||||
<button type="button" class="btn btn-success btn-sm btn_sv_present">应用</button>\
|
||||
</div>\
|
||||
</form>',
|
||||
success:function(index){
|
||||
$('.btn_sv_present').click(function(){
|
||||
var pdata = {
|
||||
siteName: siteName,
|
||||
cpu: $("input[name='cpu']").val(),
|
||||
auto: $("select[name='auto']").val(),
|
||||
time: $("input[name='time']").val(),
|
||||
}
|
||||
var act = 'set_safe_verify';
|
||||
owPost(act, pdata, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg, function() {
|
||||
layer.close(svlayer);
|
||||
wafGloabl();
|
||||
},{ icon: rdata.status ? 1 : 2 },1000);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//保存retry规则
|
||||
function saveRetry(siteName,type) {
|
||||
var pdata = {
|
||||
@@ -253,15 +320,6 @@ function addRule(ruleName) {
|
||||
},1000);
|
||||
}
|
||||
});
|
||||
|
||||
// var loadT = layer.msg('正在添加,请稍候..', { icon: 16, time: 0 });
|
||||
// $.post('/plugin?action=a&name=btwaf&s=add_rule', pdata, function (rdata) {
|
||||
// layer.close(loadT);
|
||||
// layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
// if (rdata.status) {
|
||||
// set_obj_conf(ruleName, 1);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
function modifyRule(index, ruleName) {
|
||||
@@ -339,7 +397,7 @@ function setObjConf(ruleName, type) {
|
||||
type: 1,
|
||||
title: "编辑规则【" + ruleName + "】",
|
||||
area: ['700px', '530px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div style="border-bottom:#ccc 1px solid;margin-bottom:10px;padding-bottom:10px">\
|
||||
@@ -405,7 +463,7 @@ function scanRule() {
|
||||
type: 1,
|
||||
title: "常用扫描器过滤规则",
|
||||
area: '650px',
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<form class="bt-form pd20 pb70">\
|
||||
<div class="line">\
|
||||
@@ -571,7 +629,7 @@ function ipWhite(type) {
|
||||
type: 1,
|
||||
title: "管理IP白名单",
|
||||
area: ['500px', '500px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15 ipv4_list">\
|
||||
<div style="border-bottom:#ccc 1px solid;margin-bottom:10px;padding-bottom:10px">\
|
||||
@@ -633,6 +691,71 @@ function ipWhite(type) {
|
||||
});
|
||||
}
|
||||
|
||||
//IP白名单
|
||||
function urlWhite(type) {
|
||||
|
||||
var ruleName = "url_white";
|
||||
|
||||
if (type == undefined) {
|
||||
create_l = layer.open({
|
||||
type: 1,
|
||||
title: "管理URL白名单",
|
||||
area: ['700px', '530px'],
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div style="border-bottom:#ccc 1px solid;margin-bottom:10px;padding-bottom:10px">\
|
||||
<input class="bt-input-text" name="ruleValue" type="text" value="" style="width:470px;margin-right:12px;" placeholder="规则内容,请使用正则表达式">\
|
||||
<input class="bt-input-text mr5" name="rulePs" type="text" style="width:120px;" placeholder="描述">\
|
||||
<button class="btn btn-success btn-sm va0 pull-right" onclick="addRule(\''+ ruleName + '\');">添加</button>\</div>\
|
||||
<div class="divtable">\
|
||||
<div id="jc-file-table" class="table_head_fix" style="max-height:300px;overflow:auto;border:#ddd 1px solid">\
|
||||
<table class="table table-hover" style="border:none">\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th width="360">规则</th>\
|
||||
<th>说明</th>\
|
||||
<th>操作</th>\
|
||||
<th style="text-align: right;">状态</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id="set_obj_conf_con" class="gztr"></tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
<ul class="help-info-text c7 ptb10">\
|
||||
<li style="color:red;">注意:如果您不了解正则表达式,请不要随意修改规则内容</li>\
|
||||
<li>您可以添加或修改规则内容,但请使用正则表达式</li>\
|
||||
<li>内置规则允许修改,但不可以直接删除,您可以设置规则状态来定义防火墙是否使用此规则</li>\
|
||||
</ul></div>'
|
||||
});
|
||||
tableFixed("jc-file-table");
|
||||
}
|
||||
|
||||
getRuleByName(ruleName, function(data){
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = $.parseJSON(tmp.data);
|
||||
console.log(rdata);
|
||||
var tbody = ''
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
var removeRule = ''
|
||||
if (rdata[i][3] != 0) removeRule = ' | <a class="btlink" onclick="removeRule(\'' + ruleName + '\',' + i + ')">删除</a>';
|
||||
tbody += '<tr>\
|
||||
<td class="rule_body_'+ i + '">' + rdata[i][1] + '</td>\
|
||||
<td class="rule_ps_'+ i + '">' + rdata[i][2] + '</td>\
|
||||
<td class="rule_modify_'+ i + '"><a class="btlink" onclick="modifyRule(' + i + ',\'' + ruleName + '\')">编辑</a>' + removeRule + '</td>\
|
||||
<td class="text-right">\
|
||||
<div class="pull-right">\
|
||||
<input class="btswitch btswitch-ios" id="closeua_'+ i + '" type="checkbox" ' + (rdata[i][0] ? 'checked' : '') + '>\
|
||||
<label class="btswitch-btn" style="width:2.0em;height:1.2em;margin-bottom: 0" for="closeua_'+ i + '" onclick="setRuleState(\'' + ruleName + '\',' + i + ')"></label>\
|
||||
</div>\
|
||||
</td>\
|
||||
</tr>'
|
||||
}
|
||||
$("#set_obj_conf_con").html(tbody);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 获取IPV4黑名单
|
||||
function getIpv4Address(callback){
|
||||
@@ -695,6 +818,23 @@ function addIpBlack() {
|
||||
});
|
||||
}
|
||||
|
||||
function addIpBlackArgs(ip) {
|
||||
var pdata = {
|
||||
start_ip: ip,
|
||||
end_ip: ip,
|
||||
}
|
||||
|
||||
if (pdata['start_ip'].split('.').length < 4 || pdata['end_ip'].split('.').length < 4) {
|
||||
layer.msg('起始IP或结束IP格式不正确!');
|
||||
return;
|
||||
}
|
||||
|
||||
owPost('add_ip_black', pdata, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//从IP黑名单删除IP段
|
||||
function removeIpBlack(index) {
|
||||
@@ -714,7 +854,7 @@ function ipBlack(type) {
|
||||
type: 1,
|
||||
title: "管理IP黑名单",
|
||||
area: ['500px', '500px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="tab_list"><div class="tab_block active">IPv4黑名单</div><div class="tab_block">IPv6黑名单</div></div>\
|
||||
<div class="pd15 ipv4_block">\
|
||||
@@ -820,17 +960,17 @@ function wafScreen(){
|
||||
|
||||
con += '<div class="screen">\
|
||||
<div class="line"><span class="name">POST渗透</span><span class="val">'+rdata.rules.post+'</span></div>\
|
||||
<div class="line"><span class="name">GET渗透</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">GET渗透</span><span class="val">'+rdata.rules.args+'</span></div>\
|
||||
<div class="line"><span class="name">CC攻击</span><span class="val">'+rdata.rules.cc+'</span></div>\
|
||||
<div class="line"><span class="name">恶意User-Agent</span><span class="val">'+rdata.rules.user_agent+'</span></div>\
|
||||
<div class="line"><span class="name">Cookie渗透</span><span class="val">'+rdata.rules.cookie+'</span></div>\
|
||||
<div class="line"><span class="name">恶意扫描</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">恶意扫描</span><span class="val">'+rdata.rules.scan+'</span></div>\
|
||||
<div class="line"><span class="name">恶意HEAD请求</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">URI自定义拦截</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">URI保护</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">恶意文件上传</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">禁止的扩展名</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">禁止PHP脚本</span><span class="val">0</span></div>\
|
||||
<div class="line"><span class="name">URI自定义拦截</span><span class="val">'+rdata.rules.url+'</span></div>\
|
||||
<div class="line"><span class="name">URI保护</span><span class="val">'+rdata.rules.args+'</span></div>\
|
||||
<div class="line"><span class="name">恶意文件上传</span><span class="val">'+rdata.rules.upload_ext+'</span></div>\
|
||||
<div class="line"><span class="name">禁止的扩展名</span><span class="val">'+rdata.rules.path+'</span></div>\
|
||||
<div class="line"><span class="name">禁止PHP脚本</span><span class="val">'+rdata.rules.php_path+'</span></div>\
|
||||
</div>';
|
||||
|
||||
con += '<div style="width:660px;"><ul class="help-info-text c7">\
|
||||
@@ -878,6 +1018,16 @@ function wafGloabl(){
|
||||
<td style="text-align: center;">--</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="setRetry('+ rdata.retry.retry_cycle + ',' + rdata.retry.retry + ',' + rdata.retry.retry_time + ')">初始规则</a></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td>强制安全验证</td>\
|
||||
<td>'+rdata.safe_verify.ps+'</td>\
|
||||
<td>--</td>\
|
||||
<td style="text-align: center;"><div class="ssh-item">\
|
||||
<input class="btswitch btswitch-ios" id="close_safe_verify" type="checkbox" '+(rdata.safe_verify.open ? 'checked' : '')+'>\
|
||||
<label class="btswitch-btn" for="close_safe_verify" onclick="setObjOpen(\'safe_verify\')"></label></div>\
|
||||
</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="setSafeVerify('+ rdata.safe_verify.auto + ',' + rdata.safe_verify.cpu + ',' + rdata.safe_verify.time + ')">设置</a> | <a class="btlink" href="javascript:;" onclick="onlineEditFile(0,\''+rdata['reqfile_path']+'/safe_js.html\')">响应内容</a></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td>GET-URI过滤</td>\
|
||||
<td>'+ rdata.get.ps + '</td>\
|
||||
@@ -918,6 +1068,11 @@ function wafGloabl(){
|
||||
<label class="btswitch-btn" for="closescan" onclick="setObjOpen(\'scan\')"></label>\
|
||||
</div></td><td class="text-right"><a class="btlink" onclick="scanRule()">设置</a></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td>URL白名单</td><td>所有规则对URL白名单无效</td><td style="text-align: center;">--</td>\
|
||||
<td style="text-align: center;">--</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="urlWhite()">设置</a></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td>IP白名单</td><td>所有规则对IP白名单无效</td><td style="text-align: center;">--</td>\
|
||||
<td style="text-align: center;">--</td>\
|
||||
@@ -940,7 +1095,7 @@ function wafGloabl(){
|
||||
|
||||
con += '<div style="width:645px;margin-top:10px;"><ul class="help-info-text c7">\
|
||||
<li>继承: 全局设置将在站点配置中自动继承为默认值</li>\
|
||||
<li>优先级: IP白名单>IP黑名单>URL白名单>URL黑名单>CC防御>禁止国外IP访问>User-Agent>URI过滤>URL参数>Cookie>POST</li>\
|
||||
<li>优先级: IP白名单>IP黑名单>URL白名单>URL黑名单>CC防御>User-Agent>URI过滤>URL参数>Cookie>POST</li>\
|
||||
</ul></div>';
|
||||
$(".soft-man-con").html(con);
|
||||
});
|
||||
@@ -956,146 +1111,6 @@ function back_css(v) {
|
||||
}
|
||||
}
|
||||
|
||||
//查看网站日志
|
||||
function siteWafLog(siteName) {
|
||||
var loadT = layer.msg('正在处理,请稍候..', { icon: 16, time: 0 });
|
||||
owPost('get_logs_list', { siteName: siteName } , function (data) {
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = tmp.data;
|
||||
var selectLogDay = "";
|
||||
var day = rdata[0];
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
selectLogDay += '<option value="' + rdata[i] + '">' + rdata[i] + '</option>';
|
||||
}
|
||||
if (rdata == "") {
|
||||
layer.msg("暂无日志记录", { icon: 6, shade: 0.3, time: 1000 });
|
||||
return
|
||||
}
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: "日志【" + siteName + "】",
|
||||
area: ['880px', '500px'],
|
||||
closeBtn: 2,
|
||||
shadeClose: false,
|
||||
content: '<div class="lib-box pd15 lib-box-log">\
|
||||
<div class="lib-con-title" style="height:40px"><select id="selectLogDay" class="bt-input-text" onchange="siteLogCon(\''+ siteName + '\',this.options[this.options.selectedIndex].value,1)">' + selectLogDay + '</select></div>\
|
||||
<div class="lib-con">\
|
||||
<div class="divtable">\
|
||||
<div id="site_waf_log" style="max-height:400px;overflow:auto;border:#ddd 1px solid">\
|
||||
<table class="table table-hover" style="border:none;">\
|
||||
<thead><tr><th width="150">时间</th><th width="120">用户IP</th><th width="70">类型</th><th>URI地址</th><th class="tdhide">User-Agent</th><th width="60">状态</th><th width="100">过滤器</th><th class="tdhide">过滤规则</th><th width="100" class="text-right">操作</th></tr></thead>\
|
||||
<tbody id="LogDayCon"></tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="page pull-right" id="size_log_page" style="margin-top:10px"></div>\
|
||||
</div>\
|
||||
</div>'
|
||||
});
|
||||
siteLogCon(siteName, day, 1);
|
||||
tableFixed("site_waf_log");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//日志内容
|
||||
function siteLogCon(siteName, day, page) {
|
||||
if (!page) page = 1;
|
||||
var last = page - 1;
|
||||
var next = page + 1;
|
||||
var pagehtml = '';
|
||||
$("#site_waf_log").scrollTop(0);
|
||||
|
||||
owPost('get_safe_logs', { siteName: siteName, toDate: day, p: page }, function(data){
|
||||
var tmp = $.parseJSON(data.data);
|
||||
if (!tmp.status){
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
return;
|
||||
}
|
||||
var rdata = tmp.data;
|
||||
var con = '';
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
con += '<tr>\
|
||||
<td class="td0">'+ escapeHTML(rdata[i][0]) + '</td>\
|
||||
<td class="td1"><a class="btlink" href="javascript:add_log_ip_black(\''+ escapeHTML(rdata[i][1]) + '\');" title="加入黑名单">' + escapeHTML(rdata[i][1]) + '</a></td>\
|
||||
<td class="td2">'+ escapeHTML(rdata[i][2]) + '</td>\
|
||||
<td class="td3"><span class="td3txt">'+ escapeHTML(rdata[i][3]) + '</span></td>\
|
||||
<td class="tdhide td4">'+ escapeHTML(rdata[i][4]) + '</td><td>已拦截</td>\
|
||||
<td class="td5"><span class="filtertext">'+ escapeHTML(rdata[i][5]) + '</span></td>\
|
||||
<td class="tdhide td6">'+ escapeHTML(rdata[i][6]) + '</td>\
|
||||
<td class="text-right"><a href="javascript:;" class="btlink submit_msg" data-index="'+ i +'">误报</a> | <a href="javascript:;" class="btlink btwaf_details" data-index="'+ i +'">详细</a></td>\
|
||||
</tr>'
|
||||
}
|
||||
|
||||
$("#LogDayCon").html(con);
|
||||
pagehtml = '<a class="Pstart" onclick="site_log_con(\'' + siteName + '\',\'' + day + '\',1)">首页</a><a class="prevPage" onclick="site_log_con(\'' + siteName + '\',\'' + day + '\',' + last + ')">上一页</a><a class="nextPage" onclick="site_log_con(\'' + siteName + '\',\'' + day + '\',' + next + ')">下一页</a><a class="Pcount">第 ' + page + ' 页</a>';
|
||||
$("#size_log_page").html(pagehtml);
|
||||
if (rdata.length < 1) $(".nextPage").hide();
|
||||
if (last < 1) $(".prevPage").hide();
|
||||
|
||||
// 发送误报请求
|
||||
$(".submit_msg").click(function () {
|
||||
var _this = $(this);
|
||||
var res = rdata[$(this).attr('data-index')];
|
||||
layer.confirm('是否确定提交误报反馈?', { title: '误报反馈',closeBtn:2,icon:3}, function () {
|
||||
var url_address = res[3];
|
||||
var rule_arry = res[6].split(" >> ");
|
||||
var pdata = { url_rule: url_address };
|
||||
var loadT = layer.msg('正在添加URL白名单..', { icon: 16, time: 0 });
|
||||
$.post('/plugin?action=a&name=btwaf&s=add_url_white', pdata, function (rdata) {
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
layer.close(loadT);
|
||||
if (rule_arry[1] != undefined){ $.get('https://www.bt.cn/Api/add_waf_logs?data=' + rule_arry[1],function(rdata){},'jsonp')}
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
// 详情
|
||||
$(".btwaf_details").click(function () {
|
||||
var res = rdata[$(this).attr('data-index')];
|
||||
var time = res[0]; //时间
|
||||
var ip_address = res[1]; //IP地址
|
||||
var req_type = res[2]; // 请求类型
|
||||
var url_address = res[3]; // 请求类型
|
||||
var user_agent = res[4]; // 请求类型
|
||||
var filters = res[5]; //过滤器
|
||||
var filter_rule = ''; //过滤规则
|
||||
var rule_arry = res[6].split(" >> ");
|
||||
var incoming_value = '',risk_value = ''; //传入值,风险值
|
||||
if(rule_arry.length == 0) filter_rule = rule_arry[0]
|
||||
incoming_value = rule_arry[1] == undefined?'空':rule_arry[1];
|
||||
risk_value = incoming_value.match(new RegExp(rule_arry[0].replace(/\//g,'\\/'),'i'));
|
||||
risk_value = risk_value?risk_value[0]:'空';
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: time + "详情",
|
||||
area: '600px',
|
||||
closeBtn: 2,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15 lib-box">\
|
||||
<table class="table" style="border:#ddd 1px solid; margin-bottom:10px">\
|
||||
<tbody><tr><th>时间</th><td>'+ escapeHTML(time) + '</td><th>用户IP</th><td><a class="btlink" href="javascript:add_log_ip_black(\'' + escapeHTML(ip_address) + '\')" title="加入黑名单">' + escapeHTML(ip_address) + '</a></td></tr><tr><th>类型</th><td>' + escapeHTML(req_type) + '</td><th>过滤器</th><td>' + escapeHTML(filters) + '</td></tr></tbody></table>\
|
||||
<div><b style="margin-left:10px">URI地址</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(url_address) + '</div></div>\
|
||||
<div><b style="margin-left:10px">User-Agent</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(user_agent) + '</div></div>\
|
||||
<div><b style="margin-left:10px">过滤规则</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(rule_arry[0]) + '</div></div>\
|
||||
<div><b style="margin-left:10px">传入值</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(incoming_value) + '</div></div>\
|
||||
<div><b style="margin-left:10px">风险值</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(risk_value) + '</div></div>\
|
||||
</div>'
|
||||
})
|
||||
})
|
||||
$("#LogDayCon td").click(function () {
|
||||
$(this).parents("tr").addClass("active").siblings().removeClass("active");
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function html_encode(value) {
|
||||
return $('<div></div>').html(value).text();
|
||||
}
|
||||
@@ -1190,7 +1205,7 @@ function siteRuleAdmin(siteName, ruleName, type) {
|
||||
type: 1,
|
||||
title: "管理网站过滤规则【" + title + "】",
|
||||
area: ['500px', '500px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div style="border-bottom:#ccc 1px solid;margin-bottom:10px;padding-bottom:10px">\
|
||||
@@ -1237,7 +1252,7 @@ function cdnHeader(siteName, type) {
|
||||
type: 1,
|
||||
title: "管理网站【" + siteName + "】CDN-Headers",
|
||||
area: ['500px', '500px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div style="border-bottom:#ccc 1px solid;margin-bottom:10px;padding-bottom:10px">\
|
||||
@@ -1342,7 +1357,7 @@ function setSiteObjConf(siteName, ruleName, type) {
|
||||
type: 1,
|
||||
title: "编辑网站【" + siteName + "】规则【" + ruleName + "】",
|
||||
area: ['700px', '530px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15">\
|
||||
<div class="divtable">\
|
||||
@@ -1394,7 +1409,7 @@ function siteWafConfig(siteName, type) {
|
||||
type: 1,
|
||||
title: "网站配置【" + siteName + "】",
|
||||
area: ['700px', '500px'],
|
||||
closeBtn: 2,
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div id="s_w_c"></div>'
|
||||
});
|
||||
@@ -1543,7 +1558,6 @@ function siteWafConfig(siteName, type) {
|
||||
|
||||
|
||||
function wafSite(){
|
||||
|
||||
owPost('get_site_config', {}, function(data){
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = $.parseJSON(tmp.data);
|
||||
@@ -1553,32 +1567,20 @@ function wafSite(){
|
||||
i += 1;
|
||||
tbody += '<tr>\
|
||||
<td><a onclick="siteWafConfig(\''+ k + '\')" class="sitename btlink" title="' + k + '">' + k + '</a></td>\
|
||||
<td>\
|
||||
<input onclick="setSiteObjState(\''+ k + '\',\'get\')" type="checkbox" ' + (v.get ? 'checked' : '') + '><span class="' + back_css(v.total[1].value) + '" title="拦截GET渗透次数:' + v.total[1].value + '">' + v.total[1].value + '</span>\
|
||||
</td>\
|
||||
<td>\
|
||||
<input onclick="setSiteObjState(\''+ k + '\',\'post\')" type="checkbox" ' + (v.post ? 'checked' : '') + '><span class="' + back_css(v.total[0].value) + '" title="拦截POST渗透次数:' + v.total[0].value + '">' + v.total[0].value + '</span>\
|
||||
</td>\
|
||||
<td>\
|
||||
<input onclick="setSiteObjState(\''+ k + '\',\'user-agent\')" type="checkbox" ' + (v['user-agent'] ? 'checked' : '') + '><span class="' + back_css(v.total[3].value) + '" title="拦截恶意User-Agent次数:' + v.total[3].value + '">' + v.total[3].value + '</span>\
|
||||
</td>\
|
||||
<td>\
|
||||
<input onclick="setSiteObjState(\''+ k + '\',\'cookie\')" type="checkbox" ' + (v.cookie ? 'checked' : '') + '><span class="' + back_css(v.total[4].value) + '" title="拦截Cookie渗透次数:' + v.total[4].value + '">' + v.total[4].value + '</span>\
|
||||
</td>\
|
||||
<td>\
|
||||
<input onclick="setSiteObjState(\''+ k + '\',\'cdn\')" type="checkbox" ' + (v.cdn ? 'checked' : '') + '>\
|
||||
</td>\
|
||||
<td>\
|
||||
<input onclick="setSiteObjState(\''+ k + '\',\'cc\')" type="checkbox" ' + (v.cc.open ? 'checked' : '') + '><span class="' + back_css(v.total[2].value) + '" title="拦截CC攻击次数:' + v.total[2].value + '">' + v.total[2].value + '</span>\
|
||||
</td>\
|
||||
<td><input onclick="setSiteObjState(\''+ k + '\',\'get\')" type="checkbox" ' + (v.get ? 'checked' : '') + '><span class="' + back_css(v.total[1].value) + '" title="拦截GET渗透次数:' + v.total[1].value + '">' + v.total[1].value + '</span></td>\
|
||||
<td><input onclick="setSiteObjState(\''+ k + '\',\'post\')" type="checkbox" ' + (v.post ? 'checked' : '') + '><span class="' + back_css(v.total[0].value) + '" title="拦截POST渗透次数:' + v.total[0].value + '">' + v.total[0].value + '</span></td>\
|
||||
<td><input onclick="setSiteObjState(\''+ k + '\',\'user-agent\')" type="checkbox" ' + (v['user-agent'] ? 'checked' : '') + '><span class="' + back_css(v.total[3].value) + '" title="拦截恶意User-Agent次数:' + v.total[3].value + '">' + v.total[3].value + '</span></td>\
|
||||
<td><input onclick="setSiteObjState(\''+ k + '\',\'cookie\')" type="checkbox" ' + (v.cookie ? 'checked' : '') + '><span class="' + back_css(v.total[4].value) + '" title="拦截Cookie渗透次数:' + v.total[4].value + '">' + v.total[4].value + '</span></td>\
|
||||
<td><input onclick="setSiteObjState(\''+ k + '\',\'cdn\')" type="checkbox" ' + (v.cdn ? 'checked' : '') + '></td>\
|
||||
<td><input onclick="setSiteObjState(\''+ k + '\',\'cc\')" type="checkbox" ' + (v.cc.open ? 'checked' : '') + '><span class="' + back_css(v.total[2].value) + '" title="拦截CC攻击次数:' + v.total[2].value + '">' + v.total[2].value + '</span></td>\
|
||||
<td>\
|
||||
<div class="ssh-item" style="margin-left:0">\
|
||||
<input class="btswitch btswitch-ios" id="closeget_'+ i + '" type="checkbox" ' + (v.open ? 'checked' : '') + '>\
|
||||
<label class="btswitch-btn" for="closeget_'+ i + '" onclick="setSiteObjState(\'' + k + '\',\'open\')"></label>\
|
||||
</div>\
|
||||
</td>\
|
||||
<td class="text-right"><a onclick="siteWafLog(\''+ k + '\')" class="btlink ' + (v.log_size > 0 ? 'dot' : '') + '">日志</a> | <a onclick="siteWafConfig(\'' + k + '\')" class="btlink">设置</a></td>\
|
||||
</tr>'
|
||||
<td class="text-right"><a onclick="wafLogs(\''+ k + '\')" class="btlink ' + (v.log_size > 0 ? 'dot' : '') + '">日志</a> | <a onclick="siteWafConfig(\'' + k + '\')" class="btlink">设置</a></td>\
|
||||
</tr>';
|
||||
});
|
||||
|
||||
var con = '<div class="lib-box">\
|
||||
@@ -1612,27 +1614,195 @@ function wafSite(){
|
||||
|
||||
|
||||
|
||||
function wafHistory(){
|
||||
|
||||
function wafLogRequest(page){
|
||||
var args = {};
|
||||
args['page'] = page;
|
||||
args['page_size'] = 10;
|
||||
args['site'] = $('select[name="site"]').val();
|
||||
|
||||
var query_date = 'today';
|
||||
if ($('#time_choose').attr("data-name") != ''){
|
||||
query_date = $('#time_choose').attr("data-name");
|
||||
} else {
|
||||
query_date = $('#search_time button.cur').attr("data-name");
|
||||
}
|
||||
|
||||
args['query_date'] = query_date;
|
||||
args['tojs'] = 'wafLogRequest';
|
||||
|
||||
owPost('get_logs_list', args, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var list = '';
|
||||
var data = rdata.data.data;
|
||||
if (data.length > 0){
|
||||
for(i in data){
|
||||
list += '<tr>';
|
||||
list += '<td><span class="overflow_hide" style="width:112px;">' + getLocalTime(data[i]['time'])+'</span></td>';
|
||||
list += '<td><span class="overflow_hide" style="width:50px;">' + data[i]['domain'] +'</span></td>';
|
||||
list += '<td><span class="overflow_hide" style="width:60px;">' + data[i]['ip'] +'</span></td>';
|
||||
list += '<td><span class="overflow_hide" style="width:50px;">' + data[i]['uri'] +'</span></td>';
|
||||
list += '<td><span class="overflow_hide" style="width:50px;">' + data[i]['rule_name'] +'</span></td>';
|
||||
list += '<td><span class="overflow_hide" style="width:200px;">' + data[i]['reason'] +'</span></td>';
|
||||
list += '<td><a data-id="'+i+'" href="javascript:;" class="btlink details" title="详情">详情</a></td>';
|
||||
list += '</tr>';
|
||||
}
|
||||
} else{
|
||||
list += '<tr><td colspan="8" style="text-align:center;">封锁日志为空</td></tr>';
|
||||
}
|
||||
|
||||
var table = '<div class="tablescroll">\
|
||||
<table id="DataBody" class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0" style="border: 0 none;">\
|
||||
<thead><tr>\
|
||||
<th>时间</th>\
|
||||
<th>域名</th>\
|
||||
<th>IP</th>\
|
||||
<th>URI</th>\
|
||||
<th>规则名</th>\
|
||||
<th>原因</th>\
|
||||
<th style="text-align:right;">操作</th></tr></thead>\
|
||||
<tbody>\
|
||||
'+ list +'\
|
||||
</tbody></table>\
|
||||
</div>\
|
||||
<div id="wsPage" class="dataTables_paginate paging_bootstrap page"></div>';
|
||||
$('#ws_table').html(table);
|
||||
$('#wsPage').html(rdata.data.page);
|
||||
|
||||
$(".tablescroll .details").click(function(){
|
||||
var index = $(this).attr('data-id');
|
||||
var res = data[index];
|
||||
var ip = res.ip;
|
||||
var time = getLocalTime(res.time);
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: "【"+res.domain + "】详情",
|
||||
area: '600px',
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="pd15 lib-box">\
|
||||
<table class="table" style="border:#ddd 1px solid; margin-bottom:10px">\
|
||||
<tbody><tr><th>时间</th><td>'+ time + '</td><th>用户IP</th><td><a class="btlink" href="javascript:addIpBlackArgs(\'' + escapeHTML(ip) + '\')" title="加入黑名单">' + escapeHTML(ip) + '</a></td></tr><tr><th>类型</th><td>' + escapeHTML(res.method) + '</td><th>过滤器</th><td>' + escapeHTML(res.rule_name) + '</td></tr></tbody></table>\
|
||||
<div><b style="margin-left:10px">URI地址</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(res.uri) + '</div></div>\
|
||||
<div><b style="margin-left:10px">User-Agent</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(res.user_agent) + '</div></div>\
|
||||
<div><b style="margin-left:10px">过滤规则</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(res.rule_name) + '</div></div>\
|
||||
<div><b style="margin-left:10px">Reason</b></div>\
|
||||
<div class="lib-con pull-left mt10"><div class="divpre">'+ escapeHTML(res.reason) + '</div></div>\
|
||||
</div>'
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function wafLogs(){
|
||||
var randstr = getRandomString(10);
|
||||
|
||||
|
||||
var html = '<div>\
|
||||
<div style="padding-bottom:10px;">\
|
||||
<span>网站: </span>\
|
||||
<select class="bt-input-text" name="site" style="margin-left:4px;width:100px;">\
|
||||
<option value="unset">未设置</option>\
|
||||
</select>\
|
||||
<span style="margin-left:10px">时间: </span>\
|
||||
<div class="input-group" style="margin-left:10px;width:350px;display: inline-table;vertical-align: top;">\
|
||||
<div id="search_time" class="input-group-btn btn-group-sm">\
|
||||
<button data-name="today" type="button" class="btn btn-default">今日</button>\
|
||||
<button data-name="yesterday" type="button" class="btn btn-default">昨日</button>\
|
||||
<button data-name="l7" type="button" class="btn btn-default">近7天</button>\
|
||||
<button data-name="l30" type="button" class="btn btn-default">近30天</button>\
|
||||
</div>\
|
||||
<span class="last-span"><input data-name="" type="text" id="time_choose" lay-key="1000001_'+randstr+'" class="form-control btn-group-sm" autocomplete="off" placeholder="自定义时间" style="display: inline-block;font-size: 12px;padding: 0 10px;height:30px;width: 200px;"></span>\
|
||||
</div>\
|
||||
<div style="float:right;"><button id="UncoverAll" class="btn btn-success btn-sm">解封所有</button></div>\
|
||||
</div>\
|
||||
<div class="divtable mtb10" id="ws_table"></div>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(html);
|
||||
// wafLogRequest(1);
|
||||
|
||||
$("#UncoverAll").click(function(){
|
||||
owPost('clean_drop_ip',{},function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var ndata = $.parseJSON(rdata.data);
|
||||
if (ndata.status == 0){
|
||||
layer.msg("解封所有成功",{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
} else{
|
||||
layer.msg("解封所有异常:"+ndata.msg,{icon:5,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//日期范围
|
||||
laydate.render({
|
||||
elem: '#time_choose',
|
||||
value:'',
|
||||
range:true,
|
||||
done:function(value, startDate, endDate){
|
||||
if(!value){
|
||||
return false;
|
||||
}
|
||||
|
||||
$('#search_time button').each(function(){
|
||||
$(this).removeClass('cur');
|
||||
});
|
||||
|
||||
var timeA = value.split('-');
|
||||
var start = $.trim(timeA[0]+'-'+timeA[1]+'-'+timeA[2])
|
||||
var end = $.trim(timeA[3]+'-'+timeA[4]+'-'+timeA[5])
|
||||
query_txt = toUnixTime(start + " 00:00:00") + "-"+ toUnixTime(end + " 00:00:00")
|
||||
|
||||
$('#time_choose').attr("data-name",query_txt);
|
||||
$('#time_choose').addClass("cur");
|
||||
|
||||
wafLogRequest(1);
|
||||
},
|
||||
});
|
||||
|
||||
$('#search_time button:eq(0)').addClass('cur');
|
||||
$('#search_time button').click(function(){
|
||||
$('#search_time button').each(function(){
|
||||
if ($(this).hasClass('cur')){
|
||||
$(this).removeClass('cur');
|
||||
}
|
||||
});
|
||||
$('#time_choose').attr("data-name",'');
|
||||
$('#time_choose').removeClass("cur");
|
||||
|
||||
$(this).addClass('cur');
|
||||
|
||||
wafLogRequest(1);
|
||||
});
|
||||
|
||||
owPost('get_default_site',{},function(rdata){
|
||||
$('select[name="site"]').html('');
|
||||
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var rdata = rdata.data;
|
||||
var default_site = rdata["default"];
|
||||
var select = '';
|
||||
for (var i = 0; i < rdata["list"].length; i++) {
|
||||
if (default_site == rdata["list"][i]){
|
||||
select += '<option value="'+rdata["list"][i]+'" selected>'+rdata["list"][i]+'</option>';
|
||||
} else{
|
||||
select += '<option value="'+rdata["list"][i]+'">'+rdata["list"][i]+'</option>';
|
||||
}
|
||||
}
|
||||
$('select[name="site"]').html(select);
|
||||
wafLogRequest(1);
|
||||
|
||||
$('select[name="site"]').change(function(){
|
||||
wafLogRequest(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var con = '<button class="btn btn-success btn-sm" onclick="UncoverAll()">解封所有</button>';
|
||||
con += '<div class="divtable mt10">\
|
||||
<table class="table table-hover waftable" style="color:#fff;">\
|
||||
<thead><tr><th width="18%">开始时间</th>\
|
||||
<th width="44%">IP</th>\
|
||||
<th width="10%">站点</th>\
|
||||
<th width="10%">封锁原因</th>\
|
||||
<th width="10%">封锁时长</th>\
|
||||
<th style="text-align: center;" width="10%">状态</th>\
|
||||
</thead>\
|
||||
</table>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(con);
|
||||
}
|
||||
|
||||
|
||||
function wafLogs(){
|
||||
function wafOpLogs(){
|
||||
var con = '<div class="divtable">\
|
||||
<table class="table table-hover waftable" style="color:#fff;">\
|
||||
<thead><tr><th width="18%">名称</th>\
|
||||
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
|
||||
# echo $rootPath
|
||||
|
||||
resty=$rootPath/openresty/bin/resty
|
||||
|
||||
RUN_CMD=$resty
|
||||
if [ ! -f $resty ];then
|
||||
RUN_CMD=/www/server/openresty/bin/resty
|
||||
fi
|
||||
|
||||
|
||||
# test
|
||||
# $RUN_CMD simple.lua
|
||||
# $RUN_CMD test_gsub.lua
|
||||
|
||||
# $RUN_CMD --shdict 'limit 10m' test_find_server_name.lua
|
||||
# $RUN_CMD --stap --shdict 'limit 10m' test_find_server_name.lua
|
||||
|
||||
# $RUN_CMD test_rand.lua
|
||||
$RUN_CMD test_ffi_time.lua
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
local function target()
|
||||
ngx.re.find("hello, world.", [[\w+\.]], "jo")
|
||||
end
|
||||
for i = 1, 100 do
|
||||
target()
|
||||
end
|
||||
|
||||
collectgarbage()
|
||||
|
||||
ngx.update_time()
|
||||
local begin = ngx.now()
|
||||
local N = 1e7
|
||||
for i = 1, N do
|
||||
target()
|
||||
end
|
||||
ngx.update_time()
|
||||
|
||||
ngx.say("elapsed: ", (ngx.now() - begin) / N)
|
||||
@@ -0,0 +1,62 @@
|
||||
local function target()
|
||||
ngx.re.find("hello, world.", [[\w+\.]], "jo")
|
||||
end
|
||||
for i = 1, 100 do
|
||||
target()
|
||||
end
|
||||
|
||||
-- 以上为预热操作
|
||||
collectgarbage()
|
||||
|
||||
local ffi = require("ffi")
|
||||
ffi.cdef[[
|
||||
struct timeval {
|
||||
long int tv_sec;
|
||||
long int tv_usec;
|
||||
};
|
||||
int gettimeofday(struct timeval *tv, void *tz);
|
||||
]];
|
||||
local tm = ffi.new("struct timeval");
|
||||
|
||||
-- 返回微秒级时间戳
|
||||
local function current_time_millis()
|
||||
ffi.C.gettimeofday(tm,nil);
|
||||
local sec = tonumber(tm.tv_sec);
|
||||
local usec = tonumber(tm.tv_usec);
|
||||
return sec + usec * 10^-6;
|
||||
end
|
||||
|
||||
|
||||
ngx.update_time()
|
||||
local begin = ngx.now()
|
||||
local N = 1e7
|
||||
for i = 1, N do
|
||||
target()
|
||||
end
|
||||
ngx.update_time()
|
||||
|
||||
ngx.say("elapsed: ", (ngx.now() - begin) / N)
|
||||
|
||||
|
||||
ngx.update_time()
|
||||
local begin = ngx.now()
|
||||
local N = 1e7
|
||||
for i = 1, N do
|
||||
target()
|
||||
end
|
||||
ngx.update_time()
|
||||
|
||||
ngx.say("elapsed[1]: ", (ngx.now() - begin) / N)
|
||||
|
||||
|
||||
|
||||
|
||||
ngx.update_time()
|
||||
local begin = current_time_millis()
|
||||
local N = 1e7
|
||||
for i = 1, N do
|
||||
target()
|
||||
end
|
||||
ngx.update_time()
|
||||
|
||||
ngx.say("ffi elapsed: ", (current_time_millis() - begin) / N)
|
||||
@@ -0,0 +1,75 @@
|
||||
local function target()
|
||||
ngx.re.find("hello, world.", [[\w+\.]], "jo")
|
||||
end
|
||||
for i = 1, 100 do
|
||||
target()
|
||||
end
|
||||
|
||||
-- 以上为预热操作
|
||||
collectgarbage()
|
||||
|
||||
local config_domains = {
|
||||
[1] = {
|
||||
["name"] = "t1.cn",
|
||||
["path"] = "/www/wwwroot/t1.cn",
|
||||
["domains"] = {
|
||||
[1] = "t1.cn",
|
||||
[2] = "t3.cn"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local function get_server_name(request_name)
|
||||
for _,v in ipairs(config_domains)
|
||||
do
|
||||
for _,cd_name in ipairs(v['domains'])
|
||||
do
|
||||
if request_name == cd_name then
|
||||
return v['name']
|
||||
end
|
||||
end
|
||||
end
|
||||
return request_name
|
||||
end
|
||||
|
||||
|
||||
local function get_server_name_cache(request_name)
|
||||
local cache_name = ngx.shared.limit:get(request_name)
|
||||
if cache_name then return cache_name end
|
||||
|
||||
for _,v in ipairs(config_domains)
|
||||
do
|
||||
for _,cd_name in ipairs(v['domains'])
|
||||
do
|
||||
if request_name == cd_name then
|
||||
ngx.shared.limit:set(cd_name,v['name'],3600)
|
||||
return v['name']
|
||||
end
|
||||
end
|
||||
end
|
||||
return request_name
|
||||
end
|
||||
|
||||
|
||||
ngx.update_time()
|
||||
local begin = ngx.now()
|
||||
local N = 1e7
|
||||
for i = 1, N do
|
||||
get_server_name("t3.cn")
|
||||
end
|
||||
ngx.update_time()
|
||||
|
||||
ngx.say("test get_server_name elapsed: ", (ngx.now() - begin) / N)
|
||||
|
||||
|
||||
|
||||
|
||||
ngx.update_time()
|
||||
local begin = ngx.now()
|
||||
local N = 1e7
|
||||
for i = 1, N do
|
||||
get_server_name_cache("t3.cn")
|
||||
end
|
||||
ngx.update_time()
|
||||
|
||||
ngx.say("test get_server_name_cache elapsed: ", (ngx.now() - begin) / N)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user