mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 06:09:25 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6062699074 | ||
|
|
df9d57ba70 | ||
|
|
ffca953539 | ||
|
|
bd4946124f | ||
|
|
8e18c63cee | ||
|
|
d201ca2574 | ||
|
|
b644f91090 | ||
|
|
931f51cf59 | ||
|
|
0909a11fd9 | ||
|
|
2ba2833699 | ||
|
|
20389263fb | ||
|
|
86141ccf3a | ||
|
|
b2fdf84ca0 | ||
|
|
8fbc456e1a | ||
|
|
4e43382496 | ||
|
|
0326d4f112 | ||
|
|
a87c13c5e0 | ||
|
|
5f3720c855 | ||
|
|
f548e020c4 | ||
|
|
7f21781c0b | ||
|
|
680b0f09f2 | ||
|
|
482943a63c | ||
|
|
2871aee18e | ||
|
|
ff46d9b36e | ||
|
|
fd5fcba543 | ||
|
|
fe04e02e88 | ||
|
|
93554332a7 | ||
|
|
b541c7e1b7 | ||
|
|
1dec1a286a | ||
|
|
b17510104d | ||
|
|
c2c8ea0ce6 | ||
|
|
acbdb013ae | ||
|
|
b025f21765 | ||
|
|
1afc8a69e5 | ||
|
|
743fc9e8d3 | ||
|
|
8d692d2b3b | ||
|
|
a0b362e691 | ||
|
|
98e1c2ae8f | ||
|
|
c0e5915285 | ||
|
|
667a0fd0fd | ||
|
|
8ed5f283b0 | ||
|
|
643c370d30 | ||
|
|
4601303065 | ||
|
|
14940d6734 | ||
|
|
fdc2b0f5c4 | ||
|
|
cf0b233f63 | ||
|
|
b3a7ef2206 | ||
|
|
9a3ca3e833 | ||
|
|
9afff8df3f | ||
|
|
ccd0b06223 | ||
|
|
7b495fe9bf | ||
|
|
2c3fb75e8f | ||
|
|
53b606602f | ||
|
|
ecef0cf994 | ||
|
|
3691d41b23 | ||
|
|
1f66457a3e | ||
|
|
8e05beccfd | ||
|
|
35424eae1f | ||
|
|
ed6df6d527 | ||
|
|
4366c4afde | ||
|
|
4bb059f62f | ||
|
|
aa8f618d9c | ||
|
|
dfd753e4c1 | ||
|
|
e38daf3c89 | ||
|
|
535838fc5e | ||
|
|
797853bd61 | ||
|
|
0de3aff045 | ||
|
|
0b7b48ab23 | ||
|
|
5ff0a0bfbc | ||
|
|
9131f44d67 | ||
|
|
6b86bb9d2b | ||
|
|
dc06d6beda | ||
|
|
2c8ea2498e | ||
|
|
6b01173b61 | ||
|
|
883c554850 | ||
|
|
d267da351c | ||
|
|
13a39f4d6a | ||
|
|
cff1d5ee89 | ||
|
|
bf5274c313 | ||
|
|
5623e3efac | ||
|
|
b93bb6c64c | ||
|
|
c9962f169e | ||
|
|
080f343ee2 | ||
|
|
5aeaf13f16 | ||
|
|
528094cfa7 | ||
|
|
ed3e3336b2 | ||
|
|
a75a49c2ae | ||
|
|
1204e72f41 | ||
|
|
13ca5544a5 | ||
|
|
e53fe26d52 | ||
|
|
13772399f6 | ||
|
|
98f11e2662 | ||
|
|
f0b0302f75 | ||
|
|
5b9b466cb9 | ||
|
|
5588a11ea5 | ||
|
|
da05a4ef19 | ||
|
|
34cf899529 | ||
|
|
0d7d67b012 | ||
|
|
5b778bfc0d | ||
|
|
6ce414cecf | ||
|
|
c8160b63e7 | ||
|
|
68d957fd6e | ||
|
|
f09c438500 | ||
|
|
9bc9944a3e | ||
|
|
9e4c2b13d5 | ||
|
|
cd7143047f | ||
|
|
d608ac4d94 | ||
|
|
9fedf9d10d | ||
|
|
9936191da2 | ||
|
|
538eba3acf | ||
|
|
e39ee9a6f7 | ||
|
|
e1820ad5b3 | ||
|
|
22133f1a6c | ||
|
|
0041cbdff3 | ||
|
|
889da3c769 | ||
|
|
d086eb9c61 | ||
|
|
832fa9cd1a | ||
|
|
8c19fb9629 | ||
|
|
a2e4dd6753 | ||
|
|
22ba7dda55 | ||
|
|
2ffa36eecb | ||
|
|
fe5843b35d | ||
|
|
e95acbe947 | ||
|
|
aed8319dd3 | ||
|
|
babe1b885e | ||
|
|
0612f52402 | ||
|
|
db67cea737 | ||
|
|
52cf675843 | ||
|
|
3421bf6ab5 | ||
|
|
2f39bd600b | ||
|
|
acd5ec69e8 | ||
|
|
09878728af | ||
|
|
af82e9f129 | ||
|
|
c74630e738 | ||
|
|
e4e0697b4b | ||
|
|
11b5ac658b | ||
|
|
1306731164 | ||
|
|
bb6c933aee | ||
|
|
d6a93ef1e6 | ||
|
|
6610da402a | ||
|
|
3ace9cf51e | ||
|
|
49c7ec6073 | ||
|
|
8cf526667e | ||
|
|
6c42876411 | ||
|
|
79471e3806 | ||
|
|
cad06425fc | ||
|
|
6f1e11e474 | ||
|
|
59d13e50ce | ||
|
|
5da0746240 | ||
|
|
192ea8b029 | ||
|
|
bfc20b3e42 | ||
|
|
56bee5c752 | ||
|
|
312df5de1f | ||
|
|
4d3640286c | ||
|
|
20930806b6 | ||
|
|
71360b61da | ||
|
|
411645c9e2 | ||
|
|
3de4e1bfff | ||
|
|
34285f6051 | ||
|
|
84f0cda89b | ||
|
|
04012085ce | ||
|
|
9ad00f3ce7 | ||
|
|
609a4ed351 | ||
|
|
5ca74fd312 | ||
|
|
3b1bb06c68 | ||
|
|
b6b7de42d6 | ||
|
|
3aa3b532ac | ||
|
|
290c740ab1 | ||
|
|
23fd4ca1de | ||
|
|
c128a799b2 | ||
|
|
401c103b76 | ||
|
|
6fb88eb428 | ||
|
|
956f20d295 | ||
|
|
03f8578a37 | ||
|
|
265e17beac | ||
|
|
f3d83ad8a5 | ||
|
|
39b376a7cb | ||
|
|
07858794ef | ||
|
|
391473fc14 | ||
|
|
0993adcc5f | ||
|
|
90b1d88111 | ||
|
|
87098cff95 | ||
|
|
e6e64b2a4c | ||
|
|
81436ea81b | ||
|
|
cf7d29190d | ||
|
|
4ff62ec6ad | ||
|
|
dac3ccce8d | ||
|
|
10bd7aa70f | ||
|
|
dec0afc3d3 | ||
|
|
2331853b3b | ||
|
|
b9e063e423 | ||
|
|
52294948b2 | ||
|
|
87bec2b988 | ||
|
|
9ab91ecc93 | ||
|
|
18312a3596 | ||
|
|
8fb35440c8 | ||
|
|
a874934379 | ||
|
|
2c4e4aea3f | ||
|
|
6b115261be | ||
|
|
059ce6228b | ||
|
|
cfa396b4bb | ||
|
|
11e4b377ed | ||
|
|
31fe2aab92 | ||
|
|
19042a9088 | ||
|
|
2eb4543c3b | ||
|
|
e33ccbfc7d | ||
|
|
ed8c9eed0a | ||
|
|
7163a7bbcf | ||
|
|
3f1c23ec8b | ||
|
|
3a6cb0ae2a | ||
|
|
936492d410 | ||
|
|
39d265aae7 | ||
|
|
5a33098dd3 | ||
|
|
c9927c3fb9 | ||
|
|
da90386816 | ||
|
|
6be4c5977b | ||
|
|
bbf93bfd9e | ||
|
|
a2570af5f7 | ||
|
|
77120cf31b | ||
|
|
395f449b93 | ||
|
|
8be5f4aa7b | ||
|
|
3ccebf4f47 | ||
|
|
15d48accad | ||
|
|
d0045d831c | ||
|
|
a7cac3d671 | ||
|
|
7bc7fdecae | ||
|
|
480663e2ad | ||
|
|
2290efd060 | ||
|
|
dece5a0532 | ||
|
|
b0a44d24d4 | ||
|
|
d092d9f5f2 | ||
|
|
944b3e779c | ||
|
|
55dc2715e9 | ||
|
|
84bf3abd5d | ||
|
|
00c9157f9b | ||
|
|
faa95b0d88 | ||
|
|
52d0b3c940 | ||
|
|
0141028d41 | ||
|
|
9e6bf08a72 | ||
|
|
49ff9750cb | ||
|
|
75b2b4dbc2 | ||
|
|
667c60dda0 | ||
|
|
aa6818f953 | ||
|
|
6f884fe60a | ||
|
|
a56d53c672 | ||
|
|
00b1788172 | ||
|
|
cee268fcbc | ||
|
|
40dd929823 | ||
|
|
b59949e181 | ||
|
|
9c5975253a | ||
|
|
62003b987a | ||
|
|
df0a454c3a | ||
|
|
02048c3265 | ||
|
|
65649d171d | ||
|
|
a136da6ec2 | ||
|
|
3b25ca7e60 | ||
|
|
c5cf8f8afb | ||
|
|
89f7d464ab | ||
|
|
4cac6d1921 | ||
|
|
dca5c82d2f | ||
|
|
08988130b5 | ||
|
|
8849001384 | ||
|
|
ae0a6b5079 | ||
|
|
d6c6ae5561 | ||
|
|
a6dc15f22d | ||
|
|
360b962bd2 | ||
|
|
37d37e0f1d | ||
|
|
ddc6da9172 | ||
|
|
ceba7ab673 | ||
|
|
384704b8e5 | ||
|
|
232d0c2f74 | ||
|
|
ef8e6f07f5 | ||
|
|
435e565559 | ||
|
|
ec9d7e337d | ||
|
|
b5c7a2a778 | ||
|
|
72d9c9b761 | ||
|
|
30812e1fba | ||
|
|
c95cb07e8d | ||
|
|
f3f2ea8ef0 | ||
|
|
9e5a5192cb | ||
|
|
271b3d448c | ||
|
|
b7424e7195 | ||
|
|
b607527e1f | ||
|
|
3c42a4e450 | ||
|
|
b11fd9508a | ||
|
|
dc0504cf24 | ||
|
|
1d8b82395f | ||
|
|
39ac55760e | ||
|
|
ef6071956d | ||
|
|
bbbe1c84ce | ||
|
|
064252daad | ||
|
|
3cb63c6265 | ||
|
|
b541abad42 | ||
|
|
547027be0d | ||
|
|
d786b2524a | ||
|
|
abac345628 | ||
|
|
d4290cbdd2 | ||
|
|
cfd2d99e24 | ||
|
|
28437ccfb0 | ||
|
|
43bf755609 | ||
|
|
de225fc8b9 | ||
|
|
44f891f7a3 | ||
|
|
64d1387b03 | ||
|
|
51ccbefb04 | ||
|
|
29e3017e51 | ||
|
|
197e2d80c6 | ||
|
|
b8f04043bc | ||
|
|
2ed70b4b96 | ||
|
|
d056c37be5 | ||
|
|
e75abae4b9 | ||
|
|
3e695770d7 | ||
|
|
7301edbc5a | ||
|
|
704b256408 | ||
|
|
e129051a06 | ||
|
|
d38e9f7ad0 | ||
|
|
c696742866 | ||
|
|
046389df99 | ||
|
|
3e244ed227 | ||
|
|
5016aedb0f | ||
|
|
c1cd45a5f3 | ||
|
|
79c9865a5d | ||
|
|
4082f29424 | ||
|
|
d777a29d8c | ||
|
|
04e43e051e | ||
|
|
dffe9a77e7 | ||
|
|
1b1462586e | ||
|
|
f11d2db761 | ||
|
|
842c16540a | ||
|
|
614cc1032f | ||
|
|
ad46b2050e | ||
|
|
8109989927 | ||
|
|
9d9b39dfe2 | ||
|
|
422514c40a | ||
|
|
632568643b | ||
|
|
a5f29a2a6a | ||
|
|
b02705aa5a | ||
|
|
1f9ab560e3 | ||
|
|
b3970326cd | ||
|
|
f6d008e0b6 | ||
|
|
6f9a49ad7a | ||
|
|
fc3c7d334a | ||
|
|
1030d1b923 | ||
|
|
94d4a90bcc | ||
|
|
da4b872666 | ||
|
|
cf15b19f4b | ||
|
|
aa9cdaada4 | ||
|
|
659c9fe16b | ||
|
|
2b8c6d6e43 | ||
|
|
263f83088f | ||
|
|
374c938ac0 | ||
|
|
6aa73b0cae | ||
|
|
7f731ae06f | ||
|
|
f87aff704c | ||
|
|
be9fa87133 | ||
|
|
de6fc19dee | ||
|
|
3987c6d3dc | ||
|
|
96875052cd | ||
|
|
583de57f96 | ||
|
|
41b7245f03 | ||
|
|
ee3684706f | ||
|
|
07936dfb81 | ||
|
|
5c46202be0 | ||
|
|
7123a15457 | ||
|
|
4aeb45b1d5 | ||
|
|
006a62be22 | ||
|
|
1e91d11125 | ||
|
|
99fb4aa723 | ||
|
|
5c5bbb2da2 | ||
|
|
8b05045901 | ||
|
|
1b73439525 | ||
|
|
ec51ad016a | ||
|
|
a42fae66ac | ||
|
|
b4c635c2e5 | ||
|
|
9802bc5915 | ||
|
|
196fbbdd7d | ||
|
|
fa278abd50 | ||
|
|
f9b2dbcb5e | ||
|
|
a8808be9ae | ||
|
|
4122de13e3 | ||
|
|
4acae8e5f5 | ||
|
|
1abb611c3e | ||
|
|
726f9fa0d2 | ||
|
|
cfb64caadc | ||
|
|
f501dd5150 | ||
|
|
d1fe006e39 | ||
|
|
d4db5dbfac | ||
|
|
efa512a3f6 | ||
|
|
b53436343d | ||
|
|
bb1a634f3c | ||
|
|
acda55cc55 | ||
|
|
0ff0728517 | ||
|
|
c575f55354 | ||
|
|
d58339dbcb | ||
|
|
f6a18fa25f | ||
|
|
3016eff372 | ||
|
|
ca518591f3 | ||
|
|
d2c74f2243 | ||
|
|
71dbf8e359 | ||
|
|
cb2ad0ca82 | ||
|
|
a157db7879 | ||
|
|
fb949f4ee6 | ||
|
|
b91ae3fde2 | ||
|
|
b508e8003b | ||
|
|
0632a4b535 | ||
|
|
397e0b89a5 | ||
|
|
2427bf81cd | ||
|
|
4179bbf580 | ||
|
|
b93c3bb88e | ||
|
|
a52c854afd | ||
|
|
d7e5cf1f45 | ||
|
|
cfb444deac | ||
|
|
78615451ac | ||
|
|
0134643c83 | ||
|
|
70ddd1c86f | ||
|
|
808dc743ef | ||
|
|
e30693f9f2 | ||
|
|
5c97fbe011 | ||
|
|
6419a18525 | ||
|
|
4a804e9243 | ||
|
|
d44526004f | ||
|
|
c1f402b278 | ||
|
|
45a3eec1b5 | ||
|
|
d6f41ceb6a | ||
|
|
a1bc0f6faf | ||
|
|
8420961cf7 | ||
|
|
421594c01d | ||
|
|
ca13e8ad77 | ||
|
|
f161f24253 | ||
|
|
e5ab03951f | ||
|
|
5b45bab36d | ||
|
|
0594d3f9ce | ||
|
|
ad541216c5 | ||
|
|
1adc0c1405 | ||
|
|
b22185b374 | ||
|
|
02f3107e93 | ||
|
|
52fece867d | ||
|
|
2e3578dcf1 | ||
|
|
73b09a7886 | ||
|
|
f33c7e5a5e | ||
|
|
3e90db2c8d | ||
|
|
d599363609 | ||
|
|
ec3167f239 | ||
|
|
2b1099b6e9 | ||
|
|
e55a0760e3 | ||
|
|
5c1353a38f | ||
|
|
f95684b316 | ||
|
|
6fc729ccf9 | ||
|
|
45d0c4fc4a | ||
|
|
6759b9055c | ||
|
|
de694b2465 | ||
|
|
c7b3daca36 | ||
|
|
452769233f | ||
|
|
8d196a3aa1 | ||
|
|
01baf509ad | ||
|
|
d59ee2c843 | ||
|
|
8919d5734e | ||
|
|
bb91b30d6d | ||
|
|
103ab2e099 | ||
|
|
0d33d0db79 | ||
|
|
6d9f4cfa08 | ||
|
|
c88c95ba21 | ||
|
|
a705f6a8e4 | ||
|
|
3f40ed0a01 | ||
|
|
39653896bf | ||
|
|
31d665d962 | ||
|
|
811fa4a40d | ||
|
|
320f58424d | ||
|
|
376f0f0a4e | ||
|
|
0efb700cee | ||
|
|
ff3fcae366 | ||
|
|
22d94ce67c | ||
|
|
042fd7ac6d | ||
|
|
1a48f52dad | ||
|
|
fc5970c65d | ||
|
|
e758698ee2 | ||
|
|
ea03bb056a | ||
|
|
088346fd5e | ||
|
|
cbcb686363 | ||
|
|
628175a8ee | ||
|
|
96d0115257 | ||
|
|
801fdf51a7 | ||
|
|
24fa3a7ca9 | ||
|
|
3dc781498c | ||
|
|
c3afaeb35a | ||
|
|
4390180a89 | ||
|
|
98e22f6eeb | ||
|
|
3bfd0f34f5 | ||
|
|
ec8e46494a | ||
|
|
7cb9b0acec | ||
|
|
f97d2a5987 | ||
|
|
5a50fe70a8 | ||
|
|
4ecb28575e | ||
|
|
07bf8f162c | ||
|
|
19beb1bccc | ||
|
|
33c27d7924 | ||
|
|
a9fb6c9ec9 | ||
|
|
7198a4de95 | ||
|
|
53cb56ddf2 | ||
|
|
e4582f328c | ||
|
|
bb7f1b6a7d | ||
|
|
1781d879d1 | ||
|
|
d89158124f | ||
|
|
bfdad5f9a3 | ||
|
|
165d9ba14d | ||
|
|
ad102aa940 | ||
|
|
1489d15d74 | ||
|
|
2dbda3e6dd | ||
|
|
4775d4f756 | ||
|
|
f57fd600e6 | ||
|
|
bf281107b2 | ||
|
|
083fe59fa5 | ||
|
|
8f36e0ccb2 | ||
|
|
a5b3a650eb | ||
|
|
177a08af91 | ||
|
|
5ef4b3d05d | ||
|
|
ad3d93cf8b | ||
|
|
72643b7776 | ||
|
|
45128636b0 | ||
|
|
7b962335e4 | ||
|
|
c0c67095be | ||
|
|
b3a0f11a80 | ||
|
|
088337765c | ||
|
|
066e7087c9 | ||
|
|
29144595a6 | ||
|
|
45c2b3cdca | ||
|
|
e3ecdfb2b3 | ||
|
|
560d482f31 | ||
|
|
62ffc94b69 | ||
|
|
0cb10cc926 | ||
|
|
fb4eb8747c | ||
|
|
1a26b83a46 | ||
|
|
7c2316f005 | ||
|
|
149baeb1fc | ||
|
|
9714bcb419 | ||
|
|
4e6a54dbad | ||
|
|
18498813c6 | ||
|
|
854e34a90c | ||
|
|
a0898c849e | ||
|
|
3a26b71828 | ||
|
|
f500dcac8b | ||
|
|
3a6e2e6e4b | ||
|
|
1d439e788c | ||
|
|
75a2fcdaaf | ||
|
|
2ca8598671 | ||
|
|
2d42486ac5 | ||
|
|
24f22b5b8c | ||
|
|
68f8638638 | ||
|
|
fe6b16eda4 | ||
|
|
4e35c34854 | ||
|
|
cc51d9501f | ||
|
|
c08cfd4763 | ||
|
|
5fdcb8bf71 | ||
|
|
ce3b232c4b | ||
|
|
ec7ae65f7d | ||
|
|
e4c5212ac4 | ||
|
|
23442accaf | ||
|
|
2e6f5f9add | ||
|
|
110e356fae | ||
|
|
a243d088ee | ||
|
|
365fd466c2 | ||
|
|
d1304de69e | ||
|
|
e51fa2608d | ||
|
|
cbfcd00317 | ||
|
|
7a96d3abc5 | ||
|
|
33a510a5b5 | ||
|
|
e8942128b8 | ||
|
|
7e2bd928e2 | ||
|
|
89185476aa | ||
|
|
f491641ab8 | ||
|
|
8b108d1aff | ||
|
|
2cfa7ec2ab | ||
|
|
d63aae100d | ||
|
|
e8249adc53 | ||
|
|
281427e479 | ||
|
|
af775fc77d | ||
|
|
f328354125 | ||
|
|
1f70f962cf | ||
|
|
414787447e | ||
|
|
979f2174e5 | ||
|
|
84d1c96094 | ||
|
|
0d8d9022a0 | ||
|
|
44d0e9e11c | ||
|
|
771d6e04ba | ||
|
|
87563daa1d | ||
|
|
9fefb285e1 | ||
|
|
b9ca4fc11e | ||
|
|
2646d0565d | ||
|
|
e1f900f1c5 | ||
|
|
908b3341b2 | ||
|
|
5aef2467b1 | ||
|
|
f59114a688 | ||
|
|
363ed8b3ff | ||
|
|
3970feacc3 | ||
|
|
f6c528149e | ||
|
|
8f6b5ddba9 | ||
|
|
ef350b9fd2 | ||
|
|
004dfb5e7d | ||
|
|
3c08d7c159 | ||
|
|
e227204065 | ||
|
|
ce653b7a6a | ||
|
|
a207215775 | ||
|
|
8115b0fb4d | ||
|
|
048bd573e8 | ||
|
|
918ea8d0f9 | ||
|
|
97d2fd5a63 | ||
|
|
617a517048 | ||
|
|
2e7910a84c | ||
|
|
2ee4c4e3fd | ||
|
|
9ae4d32ed4 | ||
|
|
90a7f4ea10 | ||
|
|
d22cb8305d | ||
|
|
a7a78f2103 | ||
|
|
db7ec00c07 | ||
|
|
dd21d25295 | ||
|
|
f7360aa081 | ||
|
|
1d1ba7192a | ||
|
|
0bf540c5e7 | ||
|
|
696797f125 | ||
|
|
fcfad78506 | ||
|
|
4787d6e7bb | ||
|
|
80ef6dbe4c | ||
|
|
78cdad5fb8 | ||
|
|
274f0638ac | ||
|
|
1e97b146db | ||
|
|
fbbc506de9 | ||
|
|
58ec4c2c30 | ||
|
|
a2298ade04 | ||
|
|
d5fc464603 | ||
|
|
c952be4e45 | ||
|
|
17a92518b4 | ||
|
|
c7154eea7b | ||
|
|
7cab1492c0 | ||
|
|
77b6391d9e | ||
|
|
08a91ed0f2 | ||
|
|
b4d090021c | ||
|
|
bf064d89f4 | ||
|
|
7314071634 | ||
|
|
49a606baa2 | ||
|
|
aaabe5628e | ||
|
|
ea03373363 | ||
|
|
515d25648f | ||
|
|
a30792178a | ||
|
|
1c74ce3c58 | ||
|
|
832f3b45eb | ||
|
|
2c3ad7ea99 | ||
|
|
6b3dae6169 | ||
|
|
d387546986 | ||
|
|
6929c5a173 | ||
|
|
d66e9d7fc6 | ||
|
|
17470600e9 | ||
|
|
d1017ddb5c | ||
|
|
67161e62ce | ||
|
|
87ad51f6ad | ||
|
|
2239d178f4 | ||
|
|
4ff95f057c | ||
|
|
f32ba65596 | ||
|
|
d3db79a4ed | ||
|
|
ddc8cde44c | ||
|
|
719ad042c7 | ||
|
|
9134dfb1a9 | ||
|
|
9611834a9d | ||
|
|
8d5cc2e926 | ||
|
|
01b9c51247 | ||
|
|
21ca9d8874 | ||
|
|
d2d5a0e12f | ||
|
|
ad2e9958f8 | ||
|
|
7cf64673f9 | ||
|
|
c49bc6f823 | ||
|
|
24e6c57eec | ||
|
|
a6842f2679 | ||
|
|
42ba0ea285 | ||
|
|
19e6055b7c | ||
|
|
1388c697e0 | ||
|
|
2a97c0f8b3 | ||
|
|
8aa4084373 | ||
|
|
4e16773ed8 | ||
|
|
b4b9b6eb1f | ||
|
|
b35ae736a3 | ||
|
|
ec78197317 | ||
|
|
1558e93f33 | ||
|
|
99a15ffc82 | ||
|
|
2b0b697a6a | ||
|
|
a93953a61d | ||
|
|
1ce68581af | ||
|
|
df5979a4cf | ||
|
|
9197dcbe03 | ||
|
|
4100824c43 | ||
|
|
c22b2b3774 | ||
|
|
0fbd3163e2 | ||
|
|
500171ed66 | ||
|
|
1c6b6f1090 | ||
|
|
fc8a54c4b3 | ||
|
|
4ade42380d | ||
|
|
6b2c21ab47 | ||
|
|
6f5ea82a58 | ||
|
|
73c849931c | ||
|
|
39d76f5621 | ||
|
|
bc435ea848 | ||
|
|
ed82dd3c12 | ||
|
|
0a5a86625f | ||
|
|
53f56c949b | ||
|
|
7e61e37d80 | ||
|
|
c05d0244db | ||
|
|
226d0addc5 | ||
|
|
35cce35ff3 | ||
|
|
9450103c4b | ||
|
|
4478f005e7 | ||
|
|
71be0e3196 | ||
|
|
e6a79216c4 | ||
|
|
3f12d4b8d6 | ||
|
|
683f041b1d | ||
|
|
e08cebd48e | ||
|
|
d02dea3150 | ||
|
|
18bb92c9e2 | ||
|
|
f9b45ee4d9 | ||
|
|
dcbc86ea5c | ||
|
|
300728cb17 | ||
|
|
51aa028f97 | ||
|
|
e30ac33cea | ||
|
|
1c2f3c4378 | ||
|
|
17eadfccff | ||
|
|
b55a6d3bd9 | ||
|
|
48936e7918 | ||
|
|
1a99c53cb6 | ||
|
|
a8b5df25d0 | ||
|
|
73b4be90f5 | ||
|
|
1ecf12ab5c | ||
|
|
758da44141 | ||
|
|
8aa44408cc | ||
|
|
ccf4ab7d81 | ||
|
|
61766a8942 | ||
|
|
ce9ac280c7 | ||
|
|
94bd8cbe8e | ||
|
|
705f2445ee | ||
|
|
bc8d16f2c2 | ||
|
|
fe9eb7dc38 | ||
|
|
94195b5246 | ||
|
|
24009267be | ||
|
|
c28412aea5 | ||
|
|
847b9d569b | ||
|
|
b3c3a4457d | ||
|
|
89a84f5ca0 | ||
|
|
4432fa15cc | ||
|
|
c6a600299d | ||
|
|
082b0ebcc3 | ||
|
|
828436b772 | ||
|
|
658a727fe3 | ||
|
|
bedd6e5409 | ||
|
|
ef8bc8bf57 | ||
|
|
a22f89797a | ||
|
|
eaf341cda6 | ||
|
|
58d69d734d | ||
|
|
e19f7702db | ||
|
|
b546a39f29 | ||
|
|
81b570214a | ||
|
|
44401f5944 | ||
|
|
4ad190586a | ||
|
|
25bca124b4 | ||
|
|
98165bb449 | ||
|
|
6693edb924 | ||
|
|
bae1beec3e | ||
|
|
0682ca4d4d | ||
|
|
5bc10bebd0 | ||
|
|
25df8b430b | ||
|
|
4f8fc31ca3 | ||
|
|
a44f54e719 | ||
|
|
12068046ec | ||
|
|
d6f57e5ea7 |
+12
@@ -151,11 +151,18 @@ data/system.db-journal
|
||||
data/hook_*.json
|
||||
data/letsencrypt.json
|
||||
data/basic_auth.json
|
||||
data/notify.json
|
||||
data/api.json
|
||||
data/bind_domain.pl
|
||||
data/unauthorized_status.pl
|
||||
|
||||
plugins/vip_*
|
||||
plugins/own_*
|
||||
plugins/my_*
|
||||
plugins/l2tp
|
||||
plugins/openlitespeed
|
||||
plugins/tamper_proof
|
||||
plugins/cryptocurrency_trade
|
||||
plugins/gdrive
|
||||
plugins/mtproxy
|
||||
plugins/zimg
|
||||
@@ -164,6 +171,11 @@ plugins/mail
|
||||
plugins/fastdfs
|
||||
plugins/v2ray
|
||||
plugins/frp
|
||||
plugins/file_search
|
||||
debug.out
|
||||
|
||||
|
||||
|
||||
|
||||
mdioks.session-journal
|
||||
*.session
|
||||
|
||||
@@ -29,6 +29,13 @@
|
||||
基本上可以使用,后续会继续优化!欢迎提供意见!
|
||||
|
||||
- 吹水组 - https://t.me/mdserver_web
|
||||
- 交流论坛 - https://bbs.midoks.me
|
||||
|
||||
```
|
||||
如果出现问题,最好私给我面板信息。不要让我猜。如果不提供,不要提出问题,自行解决。 — 座右铭
|
||||
Talk is cheap, show me the code. -- linus
|
||||
```
|
||||
|
||||
- [兼容性测试报告](/compatibility.md)
|
||||
- [常用命令说明](/cmd.md)
|
||||
|
||||
@@ -38,6 +45,7 @@
|
||||
* PHP[53-82] - PHP是世界上最好的编程语言。
|
||||
* MySQL - 一种关系数据库管理系统。
|
||||
* MariaDB - 是MySQL的一个重要分支。
|
||||
* MySQL[APT/YUM] - 一种关系数据库管理系统。
|
||||
* MongoDB - 一种非关系NOSQL数据库管理系统。
|
||||
* phpMyAdmin - 著名Web端MySQL管理工具。
|
||||
* Memcached - 一个高性能的分布式内存对象缓存系统。
|
||||
@@ -66,13 +74,12 @@ phpMyAdmin[4.4.15]支持MySQL[5.5-5.7]
|
||||
phpMyAdmin[5.2.0]支持MySQL[8.0]
|
||||
|
||||
PHP[53-72]支持phpMyAdmin[4.4.15]
|
||||
PHP[72-81]支持phpMyAdmin[5.2.0]
|
||||
PHP[72-82]支持phpMyAdmin[5.2.0]
|
||||
```
|
||||
|
||||
# 特别赞助
|
||||
|
||||
- [找资源 - 阿里云盘资源搜索引擎](https://zhaoziyuan.la/)
|
||||
- [奈飞丝 - 奈飞中国 Netflix MOD首发](https://naifeis.com/index.php#/register?code=k7P7V6Ur)
|
||||
|
||||
# AD - VPS推荐 - 🙏
|
||||
|
||||
@@ -85,42 +92,36 @@ PHP[72-81]支持phpMyAdmin[5.2.0]
|
||||
# Docker
|
||||
|
||||
- 由[DDSRem](https://github.com/DDSRem)开发维护。
|
||||
- https://hub.docker.com/r/ddsderek/mw-server
|
||||
- https://hub.docker.com/r/ddsderek/mw
|
||||
|
||||
```
|
||||
docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:443 -p 888:888 ddsderek/mw-server:latest
|
||||
```
|
||||
|
||||
|
||||
### 版本更新 0.12.1
|
||||
|
||||
* mysql/mariadb/mysql-apt/mysql-yum增加新的同步方式[同步账户]。
|
||||
* pureftp安装时自动放行端口。
|
||||
* 面板ssl,添加【申请Lets证书】功能。
|
||||
* 站点子域名绑定优化。
|
||||
* 修复添加数据库名字判断。
|
||||
* 增加PHP52的隐藏和显示指令。
|
||||
* 各种细节优化。
|
||||
### 版本更新 0.14.3
|
||||
|
||||
* 安装优化,针对oracle中的curl库优化。
|
||||
* PHP的Composer安装优化。
|
||||
|
||||
### JSDelivr安装地址
|
||||
|
||||
- 初始安装
|
||||
|
||||
```
|
||||
curl -fsSL https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/install.sh | bash
|
||||
curl --insecure -fsSL https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/install.sh | bash
|
||||
```
|
||||
|
||||
- 直接更新
|
||||
|
||||
```
|
||||
curl -fsSL https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/update.sh | bash
|
||||
curl --insecure -fsSL https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/update.sh | bash
|
||||
```
|
||||
|
||||
- 卸载脚本
|
||||
|
||||
```
|
||||
wget -O uninstall.sh https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/uninstall.sh && bash uninstall.sh
|
||||
wget --no-check-certificate -O uninstall.sh https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/uninstall.sh && bash uninstall.sh
|
||||
```
|
||||
|
||||
### 备用地址
|
||||
@@ -128,20 +129,20 @@ wget -O uninstall.sh https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scri
|
||||
- 初始安装
|
||||
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/install.sh | bash
|
||||
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/install.sh | bash
|
||||
curl --insecure -fsSL https://code.midoks.me/midoks/mdserver-web/raw/branch/master/scripts/install.sh | bash
|
||||
```
|
||||
|
||||
- 直接更新
|
||||
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh | bash
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh | bash
|
||||
```
|
||||
|
||||
- 卸载脚本
|
||||
|
||||
```
|
||||
wget -O uninstall.sh https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/uninstall.sh && bash uninstall.sh
|
||||
wget --no-check-certificate -O uninstall.sh https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/uninstall.sh && bash uninstall.sh
|
||||
```
|
||||
|
||||
|
||||
@@ -150,22 +151,22 @@ wget -O uninstall.sh https://raw.githubusercontent.com/midoks/mdserver-web/maste
|
||||
- 需已经安装mdserver-web
|
||||
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/quick/app.sh | bash
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/quick/app.sh | bash
|
||||
```
|
||||
|
||||
|
||||
### DEV使用
|
||||
|
||||
```
|
||||
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 --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/install_dev.sh | bash
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh | bash
|
||||
|
||||
wget -O uninstall.sh https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/uninstall.sh && bash uninstall.sh
|
||||
wget --no-check-certificate -O uninstall.sh https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/uninstall.sh && bash uninstall.sh
|
||||
|
||||
curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/quick/debug.sh | bash
|
||||
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/quick/debug.sh | bash
|
||||
|
||||
curl -fsSL https://gitee.com/midoks/mdserver-web/raw/dev/scripts/install_dev.sh | bash
|
||||
curl -fsSL https://gitee.com/midoks/mdserver-web/raw/dev/scripts/update_dev.sh | bash
|
||||
curl --insecure -fsSL https://code.midoks.me/midoks/mdserver-web/raw/branch/dev/scripts/install_dev.sh | bash
|
||||
curl --insecure -fsSL https://code.midoks.me/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash
|
||||
```
|
||||
|
||||
### 捐赠地址 USDT(TRC20)
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from route import app, socketio
|
||||
|
||||
|
||||
@@ -38,12 +40,12 @@ try:
|
||||
PORT = int(f.read())
|
||||
f.close()
|
||||
|
||||
HOST = '0.0.0.0'
|
||||
# HOST = '0.0.0.0'
|
||||
# app.run(host=HOST, port=PORT)
|
||||
|
||||
http_server = WSGIServer(
|
||||
(HOST, PORT), app, handler_class=WebSocketHandler)
|
||||
|
||||
http_server.serve_forever()
|
||||
|
||||
socketio.run(app, host=HOST, port=PORT)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
|
||||
@@ -371,7 +371,8 @@ fi
|
||||
response = urllib.request.urlopen(req, timeout=timeout)
|
||||
return response
|
||||
except Exception as ex:
|
||||
raise Exception("requestsPost: {}".format(str(ex)))
|
||||
# self.getError()
|
||||
raise Exception("requestsPost: {}".format(self.getError(str(ex))))
|
||||
|
||||
def getRequestJson(self, response):
|
||||
try:
|
||||
@@ -1005,7 +1006,7 @@ fi
|
||||
try:
|
||||
result = {}
|
||||
x509 = OpenSSL.crypto.load_certificate(
|
||||
OpenSSL.crypto.FILETYPE_PEM, public.readFile(pem_file))
|
||||
OpenSSL.crypto.FILETYPE_PEM, mw.readFile(pem_file))
|
||||
# 取产品名称
|
||||
issuer = x509.get_issuer()
|
||||
result['issuer'] = ''
|
||||
@@ -1279,16 +1280,16 @@ fullchain.pem 粘贴到证书输入框
|
||||
# 获取当前正在使用此证书的网站目录
|
||||
def getSslUsedSite(self, save_path):
|
||||
pkey_file = '{}/privkey.pem'.format(save_path)
|
||||
pkey = public.readFile(pkey_file)
|
||||
pkey = mw.readFile(pkey_file)
|
||||
if not pkey:
|
||||
return False
|
||||
cert_paths = 'vhost/cert'
|
||||
import panelSite
|
||||
args = public.dict_obj()
|
||||
args = mw.dict_obj()
|
||||
args.siteName = ''
|
||||
for c_name in os.listdir(cert_paths):
|
||||
skey_file = '{}/{}/privkey.pem'.format(cert_paths, c_name)
|
||||
skey = public.readFile(skey_file)
|
||||
skey = mw.readFile(skey_file)
|
||||
if not skey:
|
||||
continue
|
||||
if skey == pkey:
|
||||
@@ -1296,7 +1297,7 @@ fullchain.pem 粘贴到证书输入框
|
||||
run_path = panelSite.panelSite().GetRunPath(args)
|
||||
if not run_path:
|
||||
continue
|
||||
sitePath = public.M('sites').where(
|
||||
sitePath = mw.M('sites').where(
|
||||
'name=?', c_name).getField('path')
|
||||
if not sitePath:
|
||||
continue
|
||||
@@ -1314,7 +1315,7 @@ fullchain.pem 粘贴到证书输入框
|
||||
self.__config['orders'] = {}
|
||||
import panelSite
|
||||
siteObj = panelSite.panelSite()
|
||||
args = public.dict_obj()
|
||||
args = mw.dict_obj()
|
||||
for siteName in os.listdir(cert_path):
|
||||
try:
|
||||
cert_file = '{}/{}/fullchain.pem'.format(cert_path, siteName)
|
||||
@@ -1520,7 +1521,7 @@ fullchain.pem 粘贴到证书输入框
|
||||
self.__config['orders'][i]['auth_to'] = auth_to
|
||||
|
||||
# 是否到了允许重试的时间
|
||||
if 'next_retry_time' in self._config['orders'][i]:
|
||||
if 'next_retry_time' in self.__config['orders'][i]:
|
||||
timeout = self.__config['orders'][i][
|
||||
'next_retry_time'] - int(time.time())
|
||||
if timeout > 0:
|
||||
|
||||
@@ -916,7 +916,7 @@ class cert_request:
|
||||
try:
|
||||
result = {}
|
||||
x509 = OpenSSL.crypto.load_certificate(
|
||||
OpenSSL.crypto.FILETYPE_PEM, public.readFile(pem_file))
|
||||
OpenSSL.crypto.FILETYPE_PEM, mw.readFile(pem_file))
|
||||
# 取产品名称
|
||||
issuer = x509.get_issuer()
|
||||
result['issuer'] = ''
|
||||
@@ -1186,16 +1186,16 @@ fullchain.pem 粘贴到证书输入框
|
||||
# 获取当前正在使用此证书的网站目录
|
||||
def getSslUsedSite(self, save_path):
|
||||
pkey_file = '{}/privkey.pem'.format(save_path)
|
||||
pkey = public.readFile(pkey_file)
|
||||
pkey = mw.readFile(pkey_file)
|
||||
if not pkey:
|
||||
return False
|
||||
cert_paths = 'vhost/cert'
|
||||
import panelSite
|
||||
args = public.dict_obj()
|
||||
args = mw.dict_obj()
|
||||
args.siteName = ''
|
||||
for c_name in os.listdir(cert_paths):
|
||||
skey_file = '{}/{}/privkey.pem'.format(cert_paths, c_name)
|
||||
skey = public.readFile(skey_file)
|
||||
skey = mw.readFile(skey_file)
|
||||
if not skey:
|
||||
continue
|
||||
if skey == pkey:
|
||||
@@ -1203,7 +1203,7 @@ fullchain.pem 粘贴到证书输入框
|
||||
run_path = panelSite.panelSite().GetRunPath(args)
|
||||
if not run_path:
|
||||
continue
|
||||
sitePath = public.M('sites').where(
|
||||
sitePath = mw.M('sites').where(
|
||||
'name=?', c_name).getField('path')
|
||||
if not sitePath:
|
||||
continue
|
||||
@@ -1221,7 +1221,7 @@ fullchain.pem 粘贴到证书输入框
|
||||
self.__config['orders'] = {}
|
||||
import panelSite
|
||||
siteObj = panelSite.panelSite()
|
||||
args = public.dict_obj()
|
||||
args = mw.dict_obj()
|
||||
for siteName in os.listdir(cert_path):
|
||||
try:
|
||||
cert_file = '{}/{}/fullchain.pem'.format(cert_path, siteName)
|
||||
|
||||
+245
-16
@@ -27,7 +27,7 @@ from flask import request
|
||||
|
||||
class config_api:
|
||||
|
||||
__version = '0.12.1'
|
||||
__version = '0.14.3'
|
||||
__api_addr = 'data/api.json'
|
||||
|
||||
def __init__(self):
|
||||
@@ -348,7 +348,23 @@ class config_api:
|
||||
keyPath = 'ssl/private.pem'
|
||||
certPath = 'ssl/cert.pem'
|
||||
if not os.path.exists(certPath):
|
||||
mw.createSSL()
|
||||
# 不再自动生成证书
|
||||
# mw.createSSL()
|
||||
cert['privateKey'] = ''
|
||||
cert['is_https'] = ''
|
||||
cert['certPem'] = ''
|
||||
cert['rep'] = os.path.exists('ssl/input.pl')
|
||||
cert['info'] = {'endtime': 0, 'subject': '无',
|
||||
'notAfter': '无', 'notBefore': '无', 'issuer': '无'}
|
||||
return cert
|
||||
|
||||
panel_ssl = mw.getServerDir() + "/web_conf/nginx/vhost/panel.conf"
|
||||
if not os.path.exists(panel_ssl):
|
||||
cert['is_https'] = ''
|
||||
else:
|
||||
ssl_data = mw.readFile(panel_ssl)
|
||||
if ssl_data.find('$server_port !~ 443') != -1:
|
||||
cert['is_https'] = 'checked'
|
||||
|
||||
cert['privateKey'] = mw.readFile(keyPath)
|
||||
cert['certPem'] = mw.readFile(certPath)
|
||||
@@ -380,13 +396,86 @@ class config_api:
|
||||
mw.writeFile('ssl/input.pl', 'True')
|
||||
return mw.returnJson(True, '证书已保存!')
|
||||
|
||||
# 设置面板SSL证书设置
|
||||
def setPanelHttpToHttpsApi(self):
|
||||
|
||||
bind_domain = 'data/bind_domain.pl'
|
||||
if not os.path.exists(bind_domain):
|
||||
return mw.returnJson(False, '先要绑定域名!')
|
||||
|
||||
keyPath = 'ssl/private.pem'
|
||||
if not os.path.exists(keyPath):
|
||||
return mw.returnJson(False, '未申请SSL证书!')
|
||||
|
||||
is_https = request.form.get('https', '').strip()
|
||||
|
||||
panel_ssl = mw.getServerDir() + "/web_conf/nginx/vhost/panel.conf"
|
||||
if not os.path.exists(panel_ssl):
|
||||
return mw.returnJson(False, '未开启面板SSL!')
|
||||
|
||||
if is_https == 'false':
|
||||
conf = mw.readFile(panel_ssl)
|
||||
if conf:
|
||||
if conf.find('ssl_certificate') == -1:
|
||||
return mw.returnJson(False, '当前未开启SSL')
|
||||
to = "#error_page 404/404.html;\n\
|
||||
#HTTP_TO_HTTPS_START\n\
|
||||
if ($server_port !~ 443){\n\
|
||||
rewrite ^(/.*)$ https://$host$1 permanent;\n\
|
||||
}\n\
|
||||
#HTTP_TO_HTTPS_END"
|
||||
conf = conf.replace('#error_page 404/404.html;', to)
|
||||
mw.writeFile(panel_ssl, conf)
|
||||
else:
|
||||
conf = mw.readFile(panel_ssl)
|
||||
if conf:
|
||||
rep = "\n\s*#HTTP_TO_HTTPS_START(.|\n){1,300}#HTTP_TO_HTTPS_END"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+if.+server_port.+\n.+\n\s+\s*}"
|
||||
conf = re.sub(rep, '', conf)
|
||||
mw.writeFile(panel_ssl, conf)
|
||||
|
||||
mw.restartWeb()
|
||||
|
||||
action = '开启'
|
||||
if is_https == 'true':
|
||||
action = '关闭'
|
||||
return mw.returnJson(True, action + 'HTTPS跳转成功!')
|
||||
|
||||
# 删除面板证书
|
||||
def delPanelSslApi(self):
|
||||
bind_domain = 'data/bind_domain.pl'
|
||||
if not os.path.exists(bind_domain):
|
||||
return mw.returnJson(False, '未绑定域名!')
|
||||
|
||||
siteName = mw.readFile(bind_domain).strip()
|
||||
|
||||
src_letpath = mw.getServerDir() + '/web_conf/letsencrypt/' + siteName
|
||||
|
||||
dst_letpath = mw.getRunDir() + '/ssl'
|
||||
dst_csrpath = dst_letpath + '/cert.pem'
|
||||
dst_keypath = dst_letpath + '/private.pem'
|
||||
|
||||
if os.path.exists(src_letpath) or os.path.exists(dst_csrpath):
|
||||
if os.path.exists(src_letpath):
|
||||
mw.execShell('rm -rf ' + src_letpath)
|
||||
if os.path.exists(dst_csrpath):
|
||||
mw.execShell('rm -rf ' + dst_csrpath)
|
||||
if os.path.exists(dst_keypath):
|
||||
mw.execShell('rm -rf ' + dst_keypath)
|
||||
# mw.restartWeb()
|
||||
return mw.returnJson(True, '已经删除SSL!')
|
||||
|
||||
# mw.restartWeb()
|
||||
return mw.returnJson(False, '已经不存在SSL!')
|
||||
|
||||
# 申请面板let证书
|
||||
def applyPanelLetSslApi(self):
|
||||
|
||||
# check domain is bind?
|
||||
bind_domain = 'data/bind_domain.pl'
|
||||
if not os.path.exists(bind_domain):
|
||||
return mw.returnJson(False, '未绑定域名!')
|
||||
return mw.returnJson(False, '先要绑定域名!')
|
||||
|
||||
siteName = mw.readFile(bind_domain).strip()
|
||||
auth_to = mw.getRunDir() + "/tmp"
|
||||
@@ -404,6 +493,8 @@ class config_api:
|
||||
dst_csrpath = dst_letpath + '/cert.pem'
|
||||
dst_keypath = dst_letpath + '/private.pem'
|
||||
|
||||
is_already_apply = False
|
||||
|
||||
if not os.path.exists(src_letpath):
|
||||
import cert_api
|
||||
data = cert_api.cert_api().applyCertApi(to_args)
|
||||
@@ -415,6 +506,8 @@ class config_api:
|
||||
msg = msg + '<p><span>响应状态:</span>' + str(emsg['status']) + '</p><p><span>错误类型:</span>' + emsg[
|
||||
'type'] + '</p><p><span>错误代码:</span>' + emsg['detail'] + '</p>'
|
||||
return mw.returnJson(data['status'], msg, data['msg'])
|
||||
else:
|
||||
is_already_apply = True
|
||||
|
||||
mw.buildSoftLink(src_csrpath, dst_csrpath, True)
|
||||
mw.buildSoftLink(src_keypath, dst_keypath, True)
|
||||
@@ -426,6 +519,9 @@ class config_api:
|
||||
if os.path.exists(tmp_well_know):
|
||||
mw.execShell('rm -rf ' + tmp_well_know)
|
||||
|
||||
if is_already_apply:
|
||||
return mw.returnJson(True, '重复申请!', data)
|
||||
|
||||
return mw.returnJson(True, '申请成功!', data)
|
||||
|
||||
def setPanelDomainApi(self):
|
||||
@@ -509,8 +605,6 @@ class config_api:
|
||||
return mw.returnJson(True, 'SSL已关闭,请使用http协议访问面板!')
|
||||
else:
|
||||
try:
|
||||
if not os.path.exists('ssl/input.ssl'):
|
||||
mw.createSSL()
|
||||
mw.writeFile(sslConf, 'True')
|
||||
|
||||
keyPath = mw.getRunDir() + '/ssl/private.pem'
|
||||
@@ -647,9 +741,83 @@ class config_api:
|
||||
else:
|
||||
return False, ''
|
||||
|
||||
def setStatusCodeApi(self):
|
||||
status_code = request.form.get('status_code', '').strip()
|
||||
if re.match("^\d+$", status_code):
|
||||
status_code = int(status_code)
|
||||
if status_code != 0:
|
||||
if status_code < 100 or status_code > 999:
|
||||
return mw.returnJson(False, '状态码范围错误!')
|
||||
else:
|
||||
return mw.returnJson(False, '状态码范围错误!')
|
||||
|
||||
mw.writeFile('data/unauthorized_status.pl', str(status_code))
|
||||
mw.writeLog('面板设置', '将未授权响应状态码设置为:{}'.format(status_code))
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
def getNotifyApi(self):
|
||||
# 获取
|
||||
data = mw.getNotifyData(True)
|
||||
return mw.returnData(True, 'ok', data)
|
||||
|
||||
def setNotifyApi(self):
|
||||
tag = request.form.get('tag', '').strip()
|
||||
data = request.form.get('data', '').strip()
|
||||
|
||||
cfg = mw.getNotifyData(False)
|
||||
|
||||
crypt_data = mw.enDoubleCrypt(tag, data)
|
||||
if tag in cfg:
|
||||
cfg[tag]['cfg'] = crypt_data
|
||||
else:
|
||||
t = {'cfg': crypt_data}
|
||||
cfg[tag] = t
|
||||
|
||||
mw.writeNotify(cfg)
|
||||
return mw.returnData(True, '设置成功')
|
||||
|
||||
def setNotifyTestApi(self):
|
||||
# 异步通知验证
|
||||
tag = request.form.get('tag', '').strip()
|
||||
tag_data = request.form.get('data', '').strip()
|
||||
|
||||
if tag == 'tgbot':
|
||||
t = json.loads(tag_data)
|
||||
test_bool = mw.tgbotNotifyTest(t['app_token'], t['chat_id'])
|
||||
if test_bool:
|
||||
return mw.returnData(True, '验证成功')
|
||||
return mw.returnData(False, '验证失败')
|
||||
|
||||
if tag == 'email':
|
||||
t = json.loads(tag_data)
|
||||
test_bool = mw.emailNotifyTest(t)
|
||||
if test_bool:
|
||||
return mw.returnData(True, '验证成功')
|
||||
return mw.returnData(False, '验证失败')
|
||||
|
||||
return mw.returnData(False, '暂时未支持该验证')
|
||||
|
||||
def setNotifyEnableApi(self):
|
||||
# 异步通知验证
|
||||
tag = request.form.get('tag', '').strip()
|
||||
tag_enable = request.form.get('enable', '').strip()
|
||||
|
||||
data = mw.getNotifyData(False)
|
||||
op_enable = True
|
||||
op_action = '开启'
|
||||
if tag_enable != 'true':
|
||||
op_enable = False
|
||||
op_action = '关闭'
|
||||
|
||||
if tag in data:
|
||||
data[tag]['enable'] = op_enable
|
||||
|
||||
mw.writeNotify(data)
|
||||
|
||||
return mw.returnData(True, op_action + '成功')
|
||||
|
||||
def getPanelTokenApi(self):
|
||||
api_file = self.__api_addr
|
||||
|
||||
tmp = mw.readFile(api_file)
|
||||
if not os.path.exists(api_file):
|
||||
ready_data = {"open": False, "token": "", "limit_addr": []}
|
||||
@@ -668,7 +836,7 @@ class config_api:
|
||||
token = mw.getRandomString(32)
|
||||
data['token'] = mw.md5(token)
|
||||
data['token_crypt'] = mw.enCrypt(
|
||||
data['token'], token).decode('utf-8')
|
||||
data['token'], token)
|
||||
mw.writeFile(api_file, json.dumps(data))
|
||||
data['token'] = "***********************************"
|
||||
|
||||
@@ -680,10 +848,6 @@ class config_api:
|
||||
def setPanelTokenApi(self):
|
||||
op_type = request.form.get('op_type', '').strip()
|
||||
|
||||
api_file = self.__api_addr
|
||||
tmp = mw.readFile(api_file)
|
||||
data = json.loads(tmp)
|
||||
|
||||
if op_type == '1':
|
||||
token = mw.getRandomString(32)
|
||||
data['token'] = mw.md5(token)
|
||||
@@ -693,7 +857,14 @@ class config_api:
|
||||
mw.writeFile(api_file, json.dumps(data))
|
||||
return mw.returnJson(True, 'ok', token)
|
||||
|
||||
elif op_type == '2':
|
||||
api_file = self.__api_addr
|
||||
if not os.path.exists(api_file):
|
||||
return mw.returnJson(False, "先在API接口配置")
|
||||
else:
|
||||
tmp = mw.readFile(api_file)
|
||||
data = json.loads(tmp)
|
||||
|
||||
if op_type == '2':
|
||||
data['open'] = not data['open']
|
||||
stats = {True: '开启', False: '关闭'}
|
||||
if not 'token_crypt' in data:
|
||||
@@ -708,12 +879,38 @@ class config_api:
|
||||
return mw.returnJson(not not data['open'], token)
|
||||
|
||||
elif op_type == '3':
|
||||
|
||||
limit_addr = request.form.get('limit_addr', '').strip()
|
||||
data['limit_addr'] = limit_addr.split('\n')
|
||||
mw.writeLog('API配置', '变更IP限制为[%s]' % limit_addr)
|
||||
mw.writeFile(api_file, json.dumps(data))
|
||||
return mw.returnJson(True, '保存成功!')
|
||||
|
||||
def renderUnauthorizedStatus(self, data):
|
||||
cfg_unauth_status = 'data/unauthorized_status.pl'
|
||||
if os.path.exists(cfg_unauth_status):
|
||||
status_code = mw.readFile(cfg_unauth_status)
|
||||
data['status_code'] = status_code
|
||||
data['status_code_msg'] = status_code
|
||||
if status_code == '0':
|
||||
data['status_code_msg'] = "默认-安全入口错误提示"
|
||||
elif status_code == '400':
|
||||
data['status_code_msg'] = "400-客户端请求错误"
|
||||
elif status_code == '401':
|
||||
data['status_code_msg'] = "401-未授权访问"
|
||||
elif status_code == '403':
|
||||
data['status_code_msg'] = "403-拒绝访问"
|
||||
elif status_code == '404':
|
||||
data['status_code_msg'] = "404-页面不存在"
|
||||
elif status_code == '408':
|
||||
data['status_code_msg'] = "408-客户端超时"
|
||||
elif status_code == '416':
|
||||
data['status_code_msg'] = "416-无效的请求"
|
||||
else:
|
||||
data['status_code'] = '0'
|
||||
data['status_code_msg'] = "默认-安全入口错误提示"
|
||||
return data
|
||||
|
||||
def get(self):
|
||||
|
||||
data = {}
|
||||
@@ -766,6 +963,8 @@ class config_api:
|
||||
else:
|
||||
data['bind_domain'] = ''
|
||||
|
||||
data = self.renderUnauthorizedStatus(data)
|
||||
|
||||
api_token = self.__api_addr
|
||||
if os.path.exists(api_token):
|
||||
bac = mw.readFile(api_token)
|
||||
@@ -780,13 +979,43 @@ class config_api:
|
||||
data['username'] = mw.M('users').where(
|
||||
"id=?", (1,)).getField('username')
|
||||
|
||||
# databases hook 获取
|
||||
database_file = 'data/hook_database.json'
|
||||
if os.path.exists(database_file):
|
||||
df = mw.readFile(database_file)
|
||||
data['hook_tag'] = request.args.get('tag', '')
|
||||
|
||||
# databases hook
|
||||
database_hook_file = 'data/hook_database.json'
|
||||
if os.path.exists(database_hook_file):
|
||||
df = mw.readFile(database_hook_file)
|
||||
df = json.loads(df)
|
||||
data['hook_database'] = df
|
||||
else:
|
||||
data['hook_database'] = []
|
||||
|
||||
# menu hook
|
||||
menu_hook_file = 'data/hook_menu.json'
|
||||
if os.path.exists(menu_hook_file):
|
||||
df = mw.readFile(menu_hook_file)
|
||||
df = json.loads(df)
|
||||
data['hook_menu'] = df
|
||||
else:
|
||||
data['hook_menu'] = []
|
||||
|
||||
# global_static hook
|
||||
global_static_hook_file = 'data/hook_global_static.json'
|
||||
if os.path.exists(global_static_hook_file):
|
||||
df = mw.readFile(global_static_hook_file)
|
||||
df = json.loads(df)
|
||||
data['hook_global_static'] = df
|
||||
else:
|
||||
data['hook_global_static'] = []
|
||||
|
||||
# notiy config
|
||||
notify_data = mw.getNotifyData(True)
|
||||
notify_tag_list = ['tgbot', 'email']
|
||||
for tag in notify_tag_list:
|
||||
new_tag = 'notify_' + tag + '_enable'
|
||||
data[new_tag] = ''
|
||||
if tag in notify_data and 'enable' in notify_data[tag]:
|
||||
if notify_data[tag]['enable']:
|
||||
data[new_tag] = 'checked'
|
||||
|
||||
return data
|
||||
|
||||
+1
-1
@@ -348,7 +348,7 @@ class Sql():
|
||||
except Exception as ex:
|
||||
return "error: " + str(ex)
|
||||
|
||||
def query(self, sql, param):
|
||||
def query(self, sql, param=()):
|
||||
# 执行SQL语句返回数据集
|
||||
self.__getConn()
|
||||
try:
|
||||
|
||||
+132
-53
@@ -247,8 +247,8 @@ class files_api:
|
||||
os.remove(task_log)
|
||||
return mw.returnJson(True, '任务已删除!')
|
||||
|
||||
# 上传文件
|
||||
def uploadFileApi(self):
|
||||
# 上传文件
|
||||
from werkzeug.utils import secure_filename
|
||||
from flask import request
|
||||
|
||||
@@ -263,6 +263,8 @@ class files_api:
|
||||
if os.path.exists(filename):
|
||||
s_path = filename
|
||||
p_stat = os.stat(s_path)
|
||||
|
||||
# print(filename)
|
||||
f.save(filename)
|
||||
os.chown(filename, p_stat.st_uid, p_stat.st_gid)
|
||||
os.chmod(filename, p_stat.st_mode)
|
||||
@@ -271,6 +273,86 @@ class files_api:
|
||||
mw.writeLog('文件管理', msg)
|
||||
return mw.returnMsg(True, '上传成功!')
|
||||
|
||||
# 设置文件和目录权限
|
||||
def setMode(self, path):
|
||||
s_path = os.path.dirname(path)
|
||||
p_stat = os.stat(s_path)
|
||||
os.chown(path, p_stat.st_uid, p_stat.st_gid)
|
||||
os.chmod(path, p_stat.st_mode)
|
||||
|
||||
def uploadSegmentApi(self):
|
||||
# 分段上传
|
||||
path = request.form.get('path', '')
|
||||
name = request.form.get('name', '')
|
||||
size = request.form.get('size')
|
||||
start = request.form.get('start')
|
||||
dir_mode = request.form.get('dir_mode', '')
|
||||
file_mode = request.form.get('file_mode', '')
|
||||
|
||||
if not mw.fileNameCheck(name):
|
||||
return mw.returnJson(False, '文件名中不能包含特殊字符!')
|
||||
|
||||
if path == '/':
|
||||
return mw.returnJson(False, '不能直接上传文件到系统根目录!')
|
||||
|
||||
if name.find('./') != -1 or path.find('./') != -1:
|
||||
return mw.returnJson(False, '错误的参数')
|
||||
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path, 493)
|
||||
if not dir_mode != '' or not file_mode != '':
|
||||
mw.setMode(path)
|
||||
|
||||
save_path = os.path.join(
|
||||
path, name + '.' + str(int(size)) + '.upload.tmp')
|
||||
d_size = 0
|
||||
if os.path.exists(save_path):
|
||||
d_size = os.path.getsize(save_path)
|
||||
|
||||
if d_size != int(start):
|
||||
return str(d_size)
|
||||
|
||||
f = open(save_path, 'ab')
|
||||
b64_data = request.form.get('b64_data', '0')
|
||||
if b64_data == '1':
|
||||
import base64
|
||||
b64_data = base64.b64decode(args.b64_data)
|
||||
f.write(b64_data)
|
||||
else:
|
||||
upload_files = request.files.getlist("blob")
|
||||
for tmp_f in upload_files:
|
||||
f.write(tmp_f.read())
|
||||
|
||||
f.close()
|
||||
f_size = os.path.getsize(save_path)
|
||||
if f_size != int(size):
|
||||
return str(f_size)
|
||||
|
||||
new_name = os.path.join(path, name)
|
||||
if os.path.exists(new_name):
|
||||
if new_name.find('.user.ini') != -1:
|
||||
mw.execShell("chattr -i " + new_name)
|
||||
try:
|
||||
os.remove(new_name)
|
||||
except:
|
||||
mw.execShell("rm -f %s" % new_name)
|
||||
|
||||
os.renames(save_path, new_name)
|
||||
|
||||
if dir_mode != '' and dir_mode != '':
|
||||
mode_tmp1 = dir_mode.split(',')
|
||||
mw.setMode(path, mode_tmp1[0])
|
||||
mw.setOwn(path, mode_tmp1[1])
|
||||
mode_tmp2 = file_mode.split(',')
|
||||
mw.setMode(new_name, mode_tmp2[0])
|
||||
mw.setOwn(new_name, mode_tmp2[1])
|
||||
else:
|
||||
self.setMode(new_name)
|
||||
|
||||
msg = mw.getInfo('上传文件[{1}] 到 [{2}]成功!', (new_name, path))
|
||||
mw.writeLog('文件管理', msg)
|
||||
return mw.returnMsg(True, '上传成功!')
|
||||
|
||||
def getRecycleBinApi(self):
|
||||
rPath = self.rPath
|
||||
if not os.path.exists(rPath):
|
||||
@@ -626,7 +708,7 @@ class files_api:
|
||||
return not path in nDirs
|
||||
|
||||
def getDirSize(self, path):
|
||||
if mw.getOs() == 'darwin':
|
||||
if mw.isAppleSystem():
|
||||
tmp = mw.execShell('du -sh ' + path)
|
||||
else:
|
||||
tmp = mw.execShell('du -sbh ' + path)
|
||||
@@ -677,56 +759,29 @@ class files_api:
|
||||
if os.path.getsize(path) > 2097152:
|
||||
return mw.returnJson(False, '不能在线编辑大于2MB的文件!')
|
||||
|
||||
if os.path.isdir(path):
|
||||
return mw.returnJson(False, '这不是一个文件!')
|
||||
|
||||
fp = open(path, 'rb')
|
||||
data = {}
|
||||
data['status'] = True
|
||||
try:
|
||||
if fp:
|
||||
from chardet.universaldetector import UniversalDetector
|
||||
detector = UniversalDetector()
|
||||
srcBody = b""
|
||||
for line in fp.readlines():
|
||||
detector.feed(line)
|
||||
srcBody += line
|
||||
detector.close()
|
||||
char = detector.result
|
||||
data['encoding'] = char['encoding']
|
||||
if char['encoding'] == 'GB2312' or not char['encoding'] or char[
|
||||
'encoding'] == 'TIS-620' or char['encoding'] == 'ISO-8859-9':
|
||||
data['encoding'] = 'GBK'
|
||||
if char['encoding'] == 'ascii' or char[
|
||||
'encoding'] == 'ISO-8859-1':
|
||||
data['encoding'] = 'utf-8'
|
||||
if char['encoding'] == 'Big5':
|
||||
data['encoding'] = 'BIG5'
|
||||
|
||||
if not data['encoding'] in ['GBK', 'utf-8', 'BIG5']:
|
||||
data['encoding'] = 'utf-8'
|
||||
if fp:
|
||||
srcBody = fp.read()
|
||||
fp.close()
|
||||
|
||||
encoding_list = ['utf-8', 'GBK', 'BIG5']
|
||||
for el in encoding_list:
|
||||
try:
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode(
|
||||
data['encoding']).encode('utf-8', errors='ignore')
|
||||
else:
|
||||
data['data'] = srcBody.decode(data['encoding'])
|
||||
except:
|
||||
data['encoding'] = char['encoding']
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode(
|
||||
data['encoding']).encode('utf-8', errors='ignore')
|
||||
else:
|
||||
data['data'] = srcBody.decode(data['encoding'])
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
else:
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode('utf-8').encode('utf-8')
|
||||
else:
|
||||
data['data'] = srcBody.decode('utf-8')
|
||||
data['encoding'] = 'utf-8'
|
||||
data['encoding'] = el
|
||||
data['data'] = srcBody.decode(data['encoding'])
|
||||
break
|
||||
except Exception as ex:
|
||||
if el == 'BIG5':
|
||||
return mw.returnJson(False, '文件编码不被兼容,无法正确读取文件!' + str(ex))
|
||||
else:
|
||||
return mw.returnJson(False, '文件未正常打开!')
|
||||
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
except Exception as ex:
|
||||
return mw.returnJson(False, '文件编码不被兼容,无法正确读取文件!' + str(ex))
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
def saveBody(self, path, data, encoding='utf-8'):
|
||||
if not os.path.exists(path):
|
||||
@@ -734,13 +789,10 @@ class files_api:
|
||||
try:
|
||||
if encoding == 'ascii':
|
||||
encoding = 'utf-8'
|
||||
if sys.version_info[0] == 2:
|
||||
data = data.encode(encoding, errors='ignore')
|
||||
fp = open(path, 'w+')
|
||||
else:
|
||||
data = data.encode(
|
||||
encoding, errors='ignore').decode(encoding)
|
||||
fp = open(path, 'w+', encoding=encoding)
|
||||
|
||||
data = data.encode(
|
||||
encoding, errors='ignore').decode(encoding)
|
||||
fp = open(path, 'w+', encoding=encoding)
|
||||
fp.write(data)
|
||||
fp.close()
|
||||
|
||||
@@ -935,6 +987,33 @@ class files_api:
|
||||
|
||||
return mw.getJson(data)
|
||||
|
||||
def execShellApi(self):
|
||||
# 执行SHELL命令
|
||||
shell = request.form.get('shell', '').strip()
|
||||
path = request.form.get('path', '').strip()
|
||||
disabled = ['vi', 'vim', 'top', 'passwd', 'su']
|
||||
tmp = shell.split(' ')
|
||||
if tmp[0] in disabled:
|
||||
return mw.returnJson(False, '禁止执行[{}]'.format(tmp[0]))
|
||||
shellStr = '''#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
cd %s
|
||||
%s
|
||||
''' % (path, shell)
|
||||
mw.writeFile('/tmp/panelShell.sh', shellStr)
|
||||
mw.execShell(
|
||||
'nohup bash /tmp/panelShell.sh > /tmp/panelShell.pl 2>&1 &')
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
def getExecShellMsgApi(self):
|
||||
# 取SHELL执行结果
|
||||
fileName = '/tmp/panelShell.pl'
|
||||
if not os.path.exists(fileName):
|
||||
return ''
|
||||
status = not mw.processExists('bash', None, '/tmp/panelShell.sh')
|
||||
return mw.returnJson(status, mw.getNumLines(fileName, 200))
|
||||
|
||||
def __get_stats(self, filename, path=None):
|
||||
filename = filename.replace('//', '/')
|
||||
try:
|
||||
|
||||
+65
-63
@@ -28,15 +28,19 @@ from flask import request
|
||||
class firewall_api:
|
||||
|
||||
__isFirewalld = False
|
||||
__isIptables = False
|
||||
__isUfw = False
|
||||
__isMac = False
|
||||
|
||||
def __init__(self):
|
||||
iptables_file = mw.systemdCfgDir() + '/iptables.service'
|
||||
if os.path.exists('/usr/sbin/firewalld'):
|
||||
self.__isFirewalld = True
|
||||
if os.path.exists('/usr/sbin/ufw'):
|
||||
elif os.path.exists('/usr/sbin/ufw'):
|
||||
self.__isUfw = True
|
||||
if mw.isAppleSystem():
|
||||
elif os.path.exists(iptables_file):
|
||||
self.__isIptables = True
|
||||
elif mw.isAppleSystem():
|
||||
self.__isMac = True
|
||||
|
||||
##### ----- start ----- ###
|
||||
@@ -55,13 +59,15 @@ class firewall_api:
|
||||
if self.__isUfw:
|
||||
mw.execShell('ufw deny from ' + address + ' to any')
|
||||
else:
|
||||
if self.__isFirewalld:
|
||||
if self.__isIptables:
|
||||
cmd = 'iptables -I INPUT -s ' + address + ' -j DROP'
|
||||
mw.execShell(cmd)
|
||||
elif self.__isFirewalld:
|
||||
cmd = 'firewall-cmd --permanent --add-rich-rule=\'rule family=ipv4 source address="' + \
|
||||
address + '" drop\''
|
||||
mw.execShell(cmd)
|
||||
else:
|
||||
cmd = 'iptables -I INPUT -s ' + address + ' -j DROP'
|
||||
mw.execShell(cmd)
|
||||
pass
|
||||
|
||||
msg = mw.getInfo('屏蔽IP[{1}]成功!', (address,))
|
||||
mw.writeLog("防火墙管理", msg)
|
||||
@@ -117,15 +123,14 @@ class firewall_api:
|
||||
address = port
|
||||
if self.__isUfw:
|
||||
mw.execShell('ufw delete deny from ' + address + ' to any')
|
||||
elif self.__isFirewalld:
|
||||
mw.execShell(
|
||||
'firewall-cmd --permanent --remove-rich-rule=\'rule family=ipv4 source address="' + address + '" drop\'')
|
||||
elif self.__isIptables:
|
||||
cmd = 'iptables -D INPUT -s ' + address + ' -j DROP'
|
||||
mw.execShell(cmd)
|
||||
else:
|
||||
if self.__isFirewalld:
|
||||
mw.execShell(
|
||||
'firewall-cmd --permanent --remove-rich-rule=\'rule family=ipv4 source address="' + address + '" drop\'')
|
||||
elif self.__isMac:
|
||||
pass
|
||||
else:
|
||||
cmd = 'iptables -D INPUT -s ' + address + ' -j DROP'
|
||||
mw.execShell(cmd)
|
||||
pass
|
||||
|
||||
msg = mw.getInfo('解除IP[{1}]的屏蔽!', (address,))
|
||||
mw.writeLog("防火墙管理", msg)
|
||||
@@ -144,15 +149,17 @@ class firewall_api:
|
||||
return mw.returnJson(False, '失败,不能删除当前面板端口!')
|
||||
if self.__isUfw:
|
||||
mw.execShell('ufw delete allow ' + port + '/tcp')
|
||||
elif self.__isFirewalld:
|
||||
port = port.replace(':', '-')
|
||||
mw.execShell(
|
||||
'firewall-cmd --permanent --zone=public --remove-port=' + port + '/tcp')
|
||||
mw.execShell(
|
||||
'firewall-cmd --permanent --zone=public --remove-port=' + port + '/udp')
|
||||
elif self.__isIptables:
|
||||
mw.execShell(
|
||||
'iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT')
|
||||
else:
|
||||
if self.__isFirewalld:
|
||||
mw.execShell(
|
||||
'firewall-cmd --permanent --zone=public --remove-port=' + port + '/tcp')
|
||||
mw.execShell(
|
||||
'firewall-cmd --permanent --zone=public --remove-port=' + port + '/udp')
|
||||
else:
|
||||
mw.execShell(
|
||||
'iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT')
|
||||
pass
|
||||
msg = mw.getInfo('删除防火墙放行端口[{1}]成功!', (port,))
|
||||
mw.writeLog("防火墙管理", msg)
|
||||
mw.M('firewall').where("id=?", (sid,)).delete()
|
||||
@@ -249,24 +256,15 @@ class firewall_api:
|
||||
conf = re.sub(rep, "Port " + port + "\n", conf)
|
||||
mw.writeFile(file, conf)
|
||||
|
||||
if self.__isFirewalld:
|
||||
mw.execShell('setenforce 0')
|
||||
mw.execShell(
|
||||
'sed -i "s#SELINUX=enforcing#SELINUX=disabled#" /etc/selinux/config')
|
||||
mw.execShell("systemctl restart sshd.service")
|
||||
elif self.__isUfw:
|
||||
mw.execShell('ufw allow ' + port + '/tcp')
|
||||
self.addAcceptPortArgs(port, 'SSH端口修改', 'port')
|
||||
if self.__isUfw:
|
||||
mw.execShell("service ssh restart")
|
||||
else:
|
||||
mw.execShell(
|
||||
'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT')
|
||||
elif self.__isIptables:
|
||||
mw.execShell("/etc/init.d/sshd restart")
|
||||
|
||||
self.firewallReload()
|
||||
# mw.M('firewall').where(
|
||||
# "ps=?", ('SSH远程管理服务',)).setField('port', port)
|
||||
msg = "改SSH端口为[{}]成功!".format(port)
|
||||
mw.writeLog("防火墙管理", msg)
|
||||
elif self.__isFirewalld:
|
||||
mw.execShell("systemctl restart sshd.service")
|
||||
else:
|
||||
return mw.returnJson(False, '修改失败!')
|
||||
return mw.returnJson(True, '修改成功!')
|
||||
|
||||
def setSshStatusApi(self):
|
||||
@@ -349,10 +347,11 @@ class firewall_api:
|
||||
mw.execShell('service iptables stop')
|
||||
else:
|
||||
# 重新导入数据
|
||||
|
||||
_list = mw.M('firewall').field('id,port,ps,addtime').limit(
|
||||
'0,1000').order('id desc').select()
|
||||
|
||||
mw.execShell('iptables -P INPUT DROP')
|
||||
mw.execShell('iptables -P OUTPUT ACCEPT')
|
||||
for x in _list:
|
||||
port = x['port']
|
||||
if mw.isIpAddr(port):
|
||||
@@ -365,26 +364,28 @@ class firewall_api:
|
||||
mw.execShell('service iptables start')
|
||||
|
||||
def setFw(self, status):
|
||||
|
||||
if self.__isIptables:
|
||||
self.setFwIptables(status)
|
||||
return mw.returnData(True, '设置成功!')
|
||||
|
||||
if status == '1':
|
||||
if self.__isUfw:
|
||||
mw.execShell('/usr/sbin/ufw disable')
|
||||
if self.__isFirewalld:
|
||||
|
||||
elif self.__isFirewalld:
|
||||
mw.execShell('systemctl stop firewalld.service')
|
||||
mw.execShell('systemctl disable firewalld.service')
|
||||
elif self.__isMac:
|
||||
pass
|
||||
else:
|
||||
self.setFwIptables(status)
|
||||
pass
|
||||
else:
|
||||
if self.__isUfw:
|
||||
mw.execShell("echo 'y'| ufw enable")
|
||||
if self.__isFirewalld:
|
||||
elif self.__isFirewalld:
|
||||
mw.execShell('systemctl start firewalld.service')
|
||||
mw.execShell('systemctl enable firewalld.service')
|
||||
elif self.__isMac:
|
||||
pass
|
||||
else:
|
||||
self.setFwIptables(status)
|
||||
pass
|
||||
|
||||
return mw.returnData(True, '设置成功!')
|
||||
|
||||
@@ -442,23 +443,24 @@ class firewall_api:
|
||||
port = port.replace(':', '-')
|
||||
cmd = 'firewall-cmd --permanent --zone=public --add-port=' + port + '/tcp'
|
||||
mw.execShell(cmd)
|
||||
elif self.__isMac:
|
||||
pass
|
||||
else:
|
||||
elif self.__isIptables:
|
||||
cmd = 'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT'
|
||||
mw.execShell(cmd)
|
||||
else:
|
||||
pass
|
||||
return True
|
||||
|
||||
def firewallReload(self):
|
||||
if self.__isUfw:
|
||||
mw.execShell('/usr/sbin/ufw reload')
|
||||
return
|
||||
if self.__isFirewalld:
|
||||
mw.execShell('firewall-cmd --reload')
|
||||
elif self.__isMac:
|
||||
pass
|
||||
else:
|
||||
elif self.__isIptables:
|
||||
mw.execShell('service iptables save')
|
||||
mw.execShell('service iptables restart')
|
||||
elif self.__isFirewalld:
|
||||
mw.execShell('firewall-cmd --reload')
|
||||
else:
|
||||
pass
|
||||
|
||||
def getFwStatus(self):
|
||||
if self.__isUfw:
|
||||
@@ -467,17 +469,17 @@ class firewall_api:
|
||||
if data[0].strip() == 'inactive':
|
||||
return False
|
||||
return True
|
||||
if self.__isFirewalld:
|
||||
cmd = "ps -ef|grep firewalld |grep -v grep | awk '{print $2}'"
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return False
|
||||
return True
|
||||
elif self.__isMac:
|
||||
return False
|
||||
else:
|
||||
elif self.__isIptables:
|
||||
cmd = "systemctl status iptables | grep 'inactive'"
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] != '':
|
||||
return False
|
||||
return True
|
||||
elif self.__isFirewalld:
|
||||
cmd = "ps -ef|grep firewalld |grep -v grep | awk '{print $2}'"
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return False
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
+629
-15
@@ -22,10 +22,14 @@ import hashlib
|
||||
import shlex
|
||||
import datetime
|
||||
import subprocess
|
||||
import glob
|
||||
import base64
|
||||
import re
|
||||
import db
|
||||
|
||||
from random import Random
|
||||
|
||||
import db
|
||||
|
||||
|
||||
def execShell(cmdstring, cwd=None, timeout=None, shell=True):
|
||||
|
||||
@@ -80,6 +84,10 @@ def getPanelDataDir():
|
||||
return getRunDir() + '/data'
|
||||
|
||||
|
||||
def getPanelTmp():
|
||||
return getRunDir() + '/tmp'
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return getRootDir() + '/server'
|
||||
|
||||
@@ -123,6 +131,23 @@ def getAcmeDir():
|
||||
return acme
|
||||
|
||||
|
||||
def getAcmeDomainDir(domain):
|
||||
acme_dir = getAcmeDir()
|
||||
acme_domain = acme_dir + '/' + domain
|
||||
acme_domain_ecc = acme_domain + '_ecc'
|
||||
if os.path.exists(acme_domain_ecc):
|
||||
acme_domain = acme_domain_ecc
|
||||
return acme_domain
|
||||
|
||||
|
||||
def fileNameCheck(filename):
|
||||
f_strs = [';', '&', '<', '>']
|
||||
for fs in f_strs:
|
||||
if filename.find(fs) != -1:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def triggerTask():
|
||||
isTask = getRunDir() + '/tmp/panelTask.pl'
|
||||
writeFile(isTask, 'True')
|
||||
@@ -228,6 +253,14 @@ def isIpAddr(ip):
|
||||
return False
|
||||
|
||||
|
||||
def getWebStatus():
|
||||
pid = getServerDir() + '/openresty/nginx/logs/nginx.pid'
|
||||
if os.path.exists(pid):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# ------------------------------ openresty start -----------------------------
|
||||
def restartWeb():
|
||||
return opWeb("reload")
|
||||
|
||||
@@ -252,6 +285,63 @@ def opWeb(method):
|
||||
return False
|
||||
|
||||
|
||||
def opLuaMake(cmd_name):
|
||||
path = getServerDir() + '/web_conf/nginx/lua/lua.conf'
|
||||
root_dir = getServerDir() + '/web_conf/nginx/lua/' + cmd_name
|
||||
dst_path = getServerDir() + '/web_conf/nginx/lua/' + cmd_name + '.lua'
|
||||
def_path = getServerDir() + '/web_conf/nginx/lua/empty.lua'
|
||||
|
||||
if not os.path.exists(root_dir):
|
||||
execShell('mkdir -p ' + root_dir)
|
||||
|
||||
files = []
|
||||
for fl in os.listdir(root_dir):
|
||||
suffix = getFileSuffix(fl)
|
||||
if suffix != 'lua':
|
||||
continue
|
||||
flpath = os.path.join(root_dir, fl)
|
||||
files.append(flpath)
|
||||
|
||||
if len(files) > 0:
|
||||
def_path = dst_path
|
||||
content = ''
|
||||
for f in files:
|
||||
t = readFile(f)
|
||||
f_base = os.path.basename(f)
|
||||
content += '-- ' + '*' * 20 + ' ' + f_base + ' start ' + '*' * 20 + "\n"
|
||||
content += t
|
||||
content += "\n" + '-- ' + '*' * 20 + ' ' + f_base + ' end ' + '*' * 20 + "\n"
|
||||
writeFile(dst_path, content)
|
||||
else:
|
||||
if os.path.exists(dst_path):
|
||||
os.remove(dst_path)
|
||||
|
||||
conf = readFile(path)
|
||||
conf = re.sub(cmd_name + ' (.*);',
|
||||
cmd_name + " " + def_path + ";", conf)
|
||||
writeFile(path, conf)
|
||||
|
||||
|
||||
def opLuaInitFile():
|
||||
opLuaMake('init_by_lua_file')
|
||||
|
||||
|
||||
def opLuaInitWorkerFile():
|
||||
opLuaMake('init_worker_by_lua_file')
|
||||
|
||||
|
||||
def opLuaInitAccessFile():
|
||||
opLuaMake('access_by_lua_file')
|
||||
|
||||
|
||||
def opLuaMakeAll():
|
||||
opLuaInitFile()
|
||||
opLuaInitWorkerFile()
|
||||
opLuaInitAccessFile()
|
||||
|
||||
# ------------------------------ openresty end -----------------------------
|
||||
|
||||
|
||||
def restartMw():
|
||||
import system_api
|
||||
system_api.system_api().restartMw()
|
||||
@@ -454,16 +544,67 @@ def getDate():
|
||||
return time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
|
||||
|
||||
def getDateFromNow(tf_format="%Y-%m-%d %H:%M:%S", time_zone="Asia/Shanghai"):
|
||||
# 取格式时间
|
||||
import time
|
||||
os.environ['TZ'] = time_zone
|
||||
time.tzset()
|
||||
return time.strftime(tf_format, time.localtime())
|
||||
|
||||
|
||||
def getDataFromInt(val):
|
||||
time_format = '%Y-%m-%d %H:%M:%S'
|
||||
time_str = time.localtime(val)
|
||||
return time.strftime(time_format, time_str)
|
||||
|
||||
|
||||
def writeLog(stype, msg, args=()):
|
||||
# 写日志
|
||||
uid = 1
|
||||
try:
|
||||
from flask import session
|
||||
if 'uid' in session:
|
||||
uid = session['uid']
|
||||
except Exception as e:
|
||||
pass
|
||||
# writeFileLog(getTracebackInfo())
|
||||
return writeDbLog(stype, msg, args, uid)
|
||||
|
||||
|
||||
def writeFileLog(msg, path=None, limit_size=50 * 1024 * 1024, save_limit=3):
|
||||
log_file = getServerDir() + '/mdserver-web/logs/debug.log'
|
||||
if path != None:
|
||||
log_file = path
|
||||
|
||||
if os.path.exists(log_file):
|
||||
size = os.path.getsize(log_file)
|
||||
if size > limit_size:
|
||||
log_file_rename = log_file + "_" + \
|
||||
time.strftime("%Y-%m-%d_%H%M%S") + '.log'
|
||||
os.rename(log_file, log_file_rename)
|
||||
logs = sorted(glob.glob(log_file + "_*"))
|
||||
count = len(logs)
|
||||
save_limit = count - save_limit
|
||||
for i in range(count):
|
||||
if i > save_limit:
|
||||
break
|
||||
os.remove(logs[i])
|
||||
# print('|---多余日志[' + logs[i] + ']已删除!')
|
||||
|
||||
f = open(log_file, 'ab+')
|
||||
msg += "\n"
|
||||
if __name__ == '__main__':
|
||||
print(msg)
|
||||
f.write(msg.encode('utf-8'))
|
||||
f.close()
|
||||
return True
|
||||
|
||||
|
||||
def writeDbLog(stype, msg, args=(), uid=1):
|
||||
try:
|
||||
import time
|
||||
import db
|
||||
import json
|
||||
from flask import session
|
||||
uid = 1
|
||||
if 'uid' in session:
|
||||
uid = session['uid']
|
||||
sql = db.Sql()
|
||||
mdate = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
wmsg = getInfo(msg, args)
|
||||
@@ -565,31 +706,205 @@ def dePunycode(domain):
|
||||
def enCrypt(key, strings):
|
||||
# 加密字符串
|
||||
try:
|
||||
import base64
|
||||
_key = key.encode('utf-8')
|
||||
_key = base64.urlsafe_b64encode(_key)
|
||||
|
||||
if type(strings) != bytes:
|
||||
strings = strings.encode('utf-8')
|
||||
import cryptography
|
||||
from cryptography.fernet import Fernet
|
||||
f = Fernet(key)
|
||||
f = Fernet(_key)
|
||||
result = f.encrypt(strings)
|
||||
return result.decode('utf-8')
|
||||
except:
|
||||
# print(get_error_info())
|
||||
writeFileLog(getTracebackInfo())
|
||||
return strings
|
||||
|
||||
|
||||
def deCrypt(key, strings):
|
||||
|
||||
# 解密字符串
|
||||
try:
|
||||
import base64
|
||||
_key = key.encode('utf-8')
|
||||
_key = base64.urlsafe_b64encode(_key)
|
||||
|
||||
if type(strings) != bytes:
|
||||
strings = strings.decode('utf-8')
|
||||
strings = strings.encode('utf-8')
|
||||
from cryptography.fernet import Fernet
|
||||
f = Fernet(key)
|
||||
f = Fernet(_key)
|
||||
result = f.decrypt(strings).decode('utf-8')
|
||||
return result
|
||||
except:
|
||||
# print(get_error_info())
|
||||
writeFileLog(getTracebackInfo())
|
||||
return strings
|
||||
|
||||
|
||||
def enDoubleCrypt(key, strings):
|
||||
# 加密字符串
|
||||
try:
|
||||
import base64
|
||||
_key = md5(key).encode('utf-8')
|
||||
_key = base64.urlsafe_b64encode(_key)
|
||||
|
||||
if type(strings) != bytes:
|
||||
strings = strings.encode('utf-8')
|
||||
import cryptography
|
||||
from cryptography.fernet import Fernet
|
||||
f = Fernet(_key)
|
||||
result = f.encrypt(strings)
|
||||
return result.decode('utf-8')
|
||||
except:
|
||||
writeFileLog(getTracebackInfo())
|
||||
return strings
|
||||
|
||||
|
||||
def deDoubleCrypt(key, strings):
|
||||
# 解密字符串
|
||||
try:
|
||||
import base64
|
||||
_key = md5(key).encode('utf-8')
|
||||
_key = base64.urlsafe_b64encode(_key)
|
||||
|
||||
if type(strings) != bytes:
|
||||
strings = strings.encode('utf-8')
|
||||
from cryptography.fernet import Fernet
|
||||
f = Fernet(_key)
|
||||
result = f.decrypt(strings).decode('utf-8')
|
||||
return result
|
||||
except:
|
||||
writeFileLog(getTracebackInfo())
|
||||
return strings
|
||||
|
||||
|
||||
def aesEncrypt(data, key='ABCDEFGHIJKLMNOP', vi='0102030405060708'):
|
||||
# aes加密
|
||||
# @param data 被加密的数据
|
||||
# @param key 加解密密匙 16位
|
||||
# @param vi 16位
|
||||
|
||||
from cryptography.hazmat.primitives import padding
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
|
||||
if not isinstance(data, bytes):
|
||||
data = data.encode()
|
||||
|
||||
# AES_CBC_KEY = os.urandom(32)
|
||||
# AES_CBC_IV = os.urandom(16)
|
||||
|
||||
AES_CBC_KEY = key.encode()
|
||||
AES_CBC_IV = vi.encode()
|
||||
|
||||
# print("AES_CBC_KEY:", AES_CBC_KEY)
|
||||
# print("AES_CBC_IV:", AES_CBC_IV)
|
||||
|
||||
padder = padding.PKCS7(algorithms.AES.block_size).padder()
|
||||
padded_data = padder.update(data) + padder.finalize()
|
||||
|
||||
cipher = Cipher(algorithms.AES(AES_CBC_KEY),
|
||||
modes.CBC(AES_CBC_IV),
|
||||
backend=default_backend())
|
||||
encryptor = cipher.encryptor()
|
||||
|
||||
edata = encryptor.update(padded_data)
|
||||
|
||||
# print(edata)
|
||||
# print(str(edata))
|
||||
# print(edata.decode())
|
||||
return edata
|
||||
|
||||
|
||||
def aesDecrypt(data, key='ABCDEFGHIJKLMNOP', vi='0102030405060708'):
|
||||
# aes加密
|
||||
# @param data 被解密的数据
|
||||
# @param key 加解密密匙 16位
|
||||
# @param vi 16位
|
||||
|
||||
from cryptography.hazmat.primitives import padding
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
|
||||
from cryptography.hazmat.primitives import padding
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
|
||||
if not isinstance(data, bytes):
|
||||
data = data.encode()
|
||||
|
||||
AES_CBC_KEY = key.encode()
|
||||
AES_CBC_IV = vi.encode()
|
||||
|
||||
cipher = Cipher(algorithms.AES(AES_CBC_KEY),
|
||||
modes.CBC(AES_CBC_IV),
|
||||
backend=default_backend())
|
||||
decryptor = cipher.decryptor()
|
||||
|
||||
ddata = decryptor.update(data)
|
||||
|
||||
unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
|
||||
data = unpadder.update(ddata)
|
||||
|
||||
try:
|
||||
uppadded_data = data + unpadder.finalize()
|
||||
except ValueError:
|
||||
raise Exception('无效的加密信息!')
|
||||
|
||||
return uppadded_data
|
||||
|
||||
|
||||
def aesEncrypt_Crypto(data, key, vi):
|
||||
# 该方法保留,暂时不使用
|
||||
# aes加密
|
||||
# @param data 被加密的数据
|
||||
# @param key 加解密密匙 16位
|
||||
# @param vi 16位
|
||||
|
||||
from Crypto.Cipher import AES
|
||||
cryptor = AES.new(key.encode('utf8'), AES.MODE_CBC, vi.encode('utf8'))
|
||||
# 判断是否含有中文
|
||||
zhmodel = re.compile(u'[\u4e00-\u9fff]')
|
||||
match = zhmodel.search(data)
|
||||
if match == None:
|
||||
# 无中文时
|
||||
add = 16 - len(data) % 16
|
||||
pad = lambda s: s + add * chr(add)
|
||||
data = pad(data)
|
||||
enctext = cryptor.encrypt(data.encode('utf8'))
|
||||
else:
|
||||
# 含有中文时
|
||||
data = data.encode()
|
||||
add = 16 - len(data) % 16
|
||||
data = data + add * (chr(add)).encode()
|
||||
enctext = cryptor.encrypt(data)
|
||||
encodestrs = base64.b64encode(enctext).decode('utf8')
|
||||
return encodestrs
|
||||
|
||||
|
||||
def aesDecrypt_Crypto(data, key, vi):
|
||||
# 该方法保留,暂时不使用
|
||||
# aes加密
|
||||
# @param data 被加密的数据
|
||||
# @param key 加解密密匙 16位
|
||||
# @param vi 16位
|
||||
|
||||
from crypto.Cipher import AES
|
||||
data = data.encode('utf8')
|
||||
encodebytes = base64.urlsafe_b64decode(data)
|
||||
cipher = AES.new(key.encode('utf8'), AES.MODE_CBC, vi.encode('utf8'))
|
||||
text_decrypted = cipher.decrypt(encodebytes)
|
||||
# 判断是否含有中文
|
||||
zhmodel = re.compile(u'[\u4e00-\u9fff]')
|
||||
match = zhmodel.search(text_decrypted)
|
||||
if match == False:
|
||||
# 无中文时补位
|
||||
unpad = lambda s: s[0:-s[-1]]
|
||||
text_decrypted = unpad(text_decrypted)
|
||||
text_decrypted = text_decrypted.decode('utf8').rstrip() # 去掉补位的右侧空格
|
||||
return text_decrypted
|
||||
|
||||
|
||||
def buildSoftLink(src, dst, force=False):
|
||||
'''
|
||||
建立软连接
|
||||
@@ -862,7 +1177,7 @@ def getLocalIp():
|
||||
try:
|
||||
ipaddress = readFile(filename)
|
||||
if not ipaddress or ipaddress == '127.0.0.1':
|
||||
cmd = "curl -4 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
||||
cmd = "curl --insecure -4 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
||||
ip = execShell(cmd)
|
||||
result = ip[0].strip()
|
||||
if result == '':
|
||||
@@ -871,7 +1186,7 @@ def getLocalIp():
|
||||
return result
|
||||
return ipaddress
|
||||
except Exception as e:
|
||||
cmd = "curl -6 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
||||
cmd = "curl --insecure -6 -sS --connect-timeout 5 -m 60 https://v6r.ipip.net/?format=text"
|
||||
ip = execShell(cmd)
|
||||
result = ip[0].strip()
|
||||
if result == '':
|
||||
@@ -996,6 +1311,15 @@ def setOwn(filename, user, group=None):
|
||||
return True
|
||||
|
||||
|
||||
def setMode(filename, mode):
|
||||
# 设置文件权限
|
||||
if not os.path.exists(filename):
|
||||
return False
|
||||
mode = int(str(mode), 8)
|
||||
os.chmod(filename, mode)
|
||||
return True
|
||||
|
||||
|
||||
def checkPort(port):
|
||||
# 检查端口是否合法
|
||||
ports = ['21', '443', '888']
|
||||
@@ -1081,7 +1405,7 @@ def makeConf():
|
||||
file = getRunDir() + '/data/json/config.json'
|
||||
if not os.path.exists(file):
|
||||
c = {}
|
||||
c['title'] = '大圣面板'
|
||||
c['title'] = '金蝉面板'
|
||||
c['home'] = 'http://github/midoks/mdserver-web'
|
||||
c['recycle_bin'] = True
|
||||
c['template'] = 'default'
|
||||
@@ -1267,6 +1591,10 @@ def toSize(size):
|
||||
return str(round(size, 2)) + ' ' + b
|
||||
|
||||
|
||||
def getPathSuffix(path):
|
||||
return os.path.splitext(path)[-1]
|
||||
|
||||
|
||||
def getMacAddress():
|
||||
# 获取mac
|
||||
import uuid
|
||||
@@ -1377,7 +1705,7 @@ def getCertName(certPath):
|
||||
result['notAfter'], "%Y-%m-%d")) - time.time()) / 86400)
|
||||
return result
|
||||
except Exception as e:
|
||||
# print(getTracebackInfo())
|
||||
writeFileLog(getTracebackInfo())
|
||||
return None
|
||||
|
||||
|
||||
@@ -1475,8 +1803,290 @@ def getMyORMDb():
|
||||
o = ormDb.ORM()
|
||||
return o
|
||||
|
||||
##################### notify start #########################################
|
||||
|
||||
|
||||
def initNotifyConfig():
|
||||
p = getNotifyPath()
|
||||
if not os.path.exists(p):
|
||||
writeFile(p, '{}')
|
||||
return True
|
||||
|
||||
|
||||
def getNotifyPath():
|
||||
path = 'data/notify.json'
|
||||
return path
|
||||
|
||||
|
||||
def getNotifyData(is_parse=False):
|
||||
initNotifyConfig()
|
||||
notify_file = getNotifyPath()
|
||||
notify_data = readFile(notify_file)
|
||||
|
||||
data = json.loads(notify_data)
|
||||
|
||||
if is_parse:
|
||||
tag_list = ['tgbot', 'email']
|
||||
for t in tag_list:
|
||||
if t in data and 'cfg' in data[t]:
|
||||
data[t]['data'] = json.loads(deDoubleCrypt(t, data[t]['cfg']))
|
||||
return data
|
||||
|
||||
|
||||
def writeNotify(data):
|
||||
p = getNotifyPath()
|
||||
return writeFile(p, json.dumps(data))
|
||||
|
||||
|
||||
def tgbotNotifyChatID():
|
||||
data = getNotifyData(True)
|
||||
if 'tgbot' in data and 'enable' in data['tgbot']:
|
||||
if data['tgbot']['enable']:
|
||||
t = data['tgbot']['data']
|
||||
return t['chat_id']
|
||||
return ''
|
||||
|
||||
|
||||
def tgbotNotifyObject():
|
||||
data = getNotifyData(True)
|
||||
if 'tgbot' in data and 'enable' in data['tgbot']:
|
||||
if data['tgbot']['enable']:
|
||||
t = data['tgbot']['data']
|
||||
import telebot
|
||||
bot = telebot.TeleBot(app_token)
|
||||
return True, bot
|
||||
return False, None
|
||||
|
||||
|
||||
def tgbotNotifyMessage(app_token, chat_id, msg):
|
||||
import telebot
|
||||
bot = telebot.TeleBot(app_token)
|
||||
try:
|
||||
data = bot.send_message(chat_id, msg)
|
||||
return True
|
||||
except Exception as e:
|
||||
writeFileLog(str(e))
|
||||
return False
|
||||
|
||||
|
||||
def tgbotNotifyHttpPost(app_token, chat_id, msg):
|
||||
try:
|
||||
url = 'https://api.telegram.org/bot' + app_token + '/sendMessage'
|
||||
post_data = {
|
||||
'chat_id': chat_id,
|
||||
'text': msg,
|
||||
}
|
||||
rdata = httpPost(url, post_data)
|
||||
return True
|
||||
except Exception as e:
|
||||
writeFileLog(str(e))
|
||||
return False
|
||||
|
||||
|
||||
def tgbotNotifyTest(app_token, chat_id):
|
||||
msg = 'MW-通知验证测试OK'
|
||||
return tgbotNotifyHttpPost(app_token, chat_id, msg)
|
||||
|
||||
|
||||
def emailNotifyMessage(data):
|
||||
'''
|
||||
邮件通知
|
||||
'''
|
||||
sys.path.append(os.getcwd() + "/class/plugin")
|
||||
import memail
|
||||
try:
|
||||
if data['smtp_ssl'] == 'ssl':
|
||||
memail.sendSSL(data['smtp_host'], data['smtp_port'],
|
||||
data['username'], data['password'],
|
||||
data['to_mail_addr'], data['subject'], data['content'])
|
||||
else:
|
||||
memail.send(data['smtp_host'], data['smtp_port'],
|
||||
data['username'], data['password'],
|
||||
data['to_mail_addr'], data['subject'], data['content'])
|
||||
return True
|
||||
except Exception as e:
|
||||
print(getTracebackInfo())
|
||||
return False
|
||||
|
||||
|
||||
def emailNotifyTest(data):
|
||||
# print(data)
|
||||
data['subject'] = 'MW通知测试'
|
||||
data['content'] = data['mail_test']
|
||||
return emailNotifyMessage(data)
|
||||
|
||||
|
||||
def notifyMessageTry(msg, stype='common', trigger_time=300, is_write_log=True):
|
||||
|
||||
lock_file = getPanelTmp() + '/notify_lock.json'
|
||||
if not os.path.exists(lock_file):
|
||||
writeFile(lock_file, '{}')
|
||||
|
||||
lock_data = json.loads(readFile(lock_file))
|
||||
if stype in lock_data:
|
||||
diff_time = time.time() - lock_data[stype]['do_time']
|
||||
if diff_time >= trigger_time:
|
||||
lock_data[stype]['do_time'] = time.time()
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
lock_data[stype] = {'do_time': time.time()}
|
||||
|
||||
writeFile(lock_file, json.dumps(lock_data))
|
||||
|
||||
if is_write_log:
|
||||
writeLog("通知管理[" + stype + "]", msg)
|
||||
|
||||
data = getNotifyData(True)
|
||||
# tag_list = ['tgbot', 'email']
|
||||
# tagbot
|
||||
do_notify = False
|
||||
if 'tgbot' in data and 'enable' in data['tgbot']:
|
||||
if data['tgbot']['enable']:
|
||||
t = data['tgbot']['data']
|
||||
i = sys.version_info
|
||||
|
||||
# telebot 在python小于3.7无法使用
|
||||
if i[0] < 3 or i[1] < 7:
|
||||
do_notify = tgbotNotifyHttpPost(
|
||||
t['app_token'], t['chat_id'], msg)
|
||||
else:
|
||||
do_notify = tgbotNotifyMessage(
|
||||
t['app_token'], t['chat_id'], msg)
|
||||
|
||||
if 'email' in data and 'enable' in data['email']:
|
||||
if data['email']['enable']:
|
||||
t = data['email']['data']
|
||||
t['subject'] = 'MW通知'
|
||||
t['content'] = msg
|
||||
do_notify = emailNotifyMessage(t)
|
||||
return do_notify
|
||||
|
||||
|
||||
def notifyMessage(msg, stype='common', trigger_time=300, is_write_log=True):
|
||||
try:
|
||||
return notifyMessageTry(msg, stype, trigger_time, is_write_log)
|
||||
except Exception as e:
|
||||
writeFileLog(getTracebackInfo())
|
||||
return False
|
||||
|
||||
|
||||
##################### notify end #########################################
|
||||
|
||||
|
||||
##################### ssh start #########################################
|
||||
def getSshDir():
|
||||
if isAppleSystem():
|
||||
user = execShell("who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return '/Users/' + user + '/.ssh'
|
||||
return '/root/.ssh'
|
||||
|
||||
|
||||
def processExists(pname, exe=None, cmdline=None):
|
||||
# 进程是否存在
|
||||
try:
|
||||
import psutil
|
||||
pids = psutil.pids()
|
||||
for pid in pids:
|
||||
try:
|
||||
p = psutil.Process(pid)
|
||||
if p.name() == pname:
|
||||
if not exe and not cmdline:
|
||||
return True
|
||||
else:
|
||||
if exe:
|
||||
if p.exe() == exe:
|
||||
return True
|
||||
if cmdline:
|
||||
if cmdline in p.cmdline():
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
except:
|
||||
return True
|
||||
|
||||
|
||||
def createRsa():
|
||||
# ssh-keygen -t rsa -P "" -C "midoks@163.com"
|
||||
ssh_dir = getSshDir()
|
||||
# mw.execShell("rm -f /root/.ssh/*")
|
||||
if not os.path.exists(ssh_dir + '/authorized_keys'):
|
||||
execShell('touch ' + ssh_dir + '/authorized_keys')
|
||||
|
||||
if not os.path.exists(ssh_dir + '/id_rsa.pub') and os.path.exists(ssh_dir + '/id_rsa'):
|
||||
execShell('echo y | ssh-keygen -q -t rsa -P "" -f ' +
|
||||
ssh_dir + '/id_rsa')
|
||||
else:
|
||||
execShell('ssh-keygen -q -t rsa -P "" -f ' + ssh_dir + '/id_rsa')
|
||||
|
||||
execShell('cat ' + ssh_dir + '/id_rsa.pub >> ' +
|
||||
ssh_dir + '/authorized_keys')
|
||||
execShell('chmod 600 ' + ssh_dir + '/authorized_keys')
|
||||
|
||||
|
||||
def createSshInfo():
|
||||
ssh_dir = getSshDir()
|
||||
if not os.path.exists(ssh_dir + '/id_rsa') or not os.path.exists(ssh_dir + '/id_rsa.pub'):
|
||||
createRsa()
|
||||
|
||||
# 检查是否写入authorized_keys
|
||||
data = execShell("cat " + ssh_dir + "/id_rsa.pub | awk '{print $3}'")
|
||||
if data[0] != "":
|
||||
cmd = "cat " + ssh_dir + "/authorized_keys | grep " + data[0]
|
||||
ak_data = execShell(cmd)
|
||||
if ak_data[0] == "":
|
||||
cmd = 'cat ' + ssh_dir + '/id_rsa.pub >> ' + ssh_dir + '/authorized_keys'
|
||||
execShell(cmd)
|
||||
execShell('chmod 600 ' + ssh_dir + '/authorized_keys')
|
||||
|
||||
|
||||
def connectSsh():
|
||||
import paramiko
|
||||
ssh = paramiko.SSHClient()
|
||||
createSshInfo()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
port = getSSHPort()
|
||||
try:
|
||||
ssh.connect('127.0.0.1', port, timeout=5)
|
||||
except Exception as e:
|
||||
ssh.connect('localhost', port, timeout=5)
|
||||
except Exception as e:
|
||||
ssh.connect(getHostAddr(), port, timeout=30)
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
shell = ssh.invoke_shell(term='xterm', width=83, height=21)
|
||||
shell.setblocking(0)
|
||||
return shell
|
||||
|
||||
|
||||
def clearSsh():
|
||||
# 服务器IP
|
||||
ip = getHostAddr()
|
||||
sh = '''
|
||||
#!/bin/bash
|
||||
PLIST=`who | grep localhost | awk '{print $2}'`
|
||||
for i in $PLIST
|
||||
do
|
||||
ps -t /dev/$i |grep -v TTY | awk '{print $1}' | xargs kill -9
|
||||
done
|
||||
|
||||
# getHostAddr
|
||||
PLIST=`who | grep "${ip}" | awk '{print $2}'`
|
||||
for i in $PLIST
|
||||
do
|
||||
ps -t /dev/$i |grep -v TTY | awk '{print $1}' | xargs kill -9
|
||||
done
|
||||
'''
|
||||
if not isAppleSystem():
|
||||
info = execShell(sh)
|
||||
print(info[0], info[1])
|
||||
##################### ssh end #########################################
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 打印相关
|
||||
# 打印相关 START
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1495,3 +2105,7 @@ def echoEnd(tag):
|
||||
|
||||
def echoInfo(msg):
|
||||
print("|-{}".format(msg))
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 打印相关 END
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
+88
-19
@@ -27,7 +27,7 @@ import sys
|
||||
import threading
|
||||
import multiprocessing
|
||||
|
||||
|
||||
from flask import render_template
|
||||
from flask import request
|
||||
|
||||
|
||||
@@ -75,12 +75,35 @@ class plugins_api:
|
||||
data = self.getPluginList(sType, int(sPage))
|
||||
return mw.getJson(data)
|
||||
|
||||
def menuGetAbsPath(self, tag, path):
|
||||
if path[0:1] == '/':
|
||||
return path
|
||||
else:
|
||||
return mw.getPluginDir() + '/' + tag + '/' + path
|
||||
|
||||
def menuApi(self):
|
||||
import config_api
|
||||
data = config_api.config_api().get()
|
||||
tag = request.args.get('tag', '')
|
||||
menu_file = 'data/hook_menu.json'
|
||||
content = ''
|
||||
if os.path.exists(menu_file):
|
||||
t = mw.readFile(menu_file)
|
||||
tlist = json.loads(t)
|
||||
for menu_data in tlist:
|
||||
if tag == menu_data['name'] and 'path' in menu_data:
|
||||
tpath = self.menuGetAbsPath(tag, menu_data['path'])
|
||||
content = mw.readFile(tpath)
|
||||
data['plugin_content'] = content
|
||||
return render_template('plugin_menu.html', data=data)
|
||||
|
||||
def fileApi(self):
|
||||
name = request.args.get('name', '')
|
||||
if name.strip() == '':
|
||||
return ''
|
||||
|
||||
f = request.args.get('f', '')
|
||||
|
||||
if f.strip() == '':
|
||||
return ''
|
||||
|
||||
@@ -88,8 +111,16 @@ class plugins_api:
|
||||
if not os.path.exists(file):
|
||||
return ''
|
||||
|
||||
c = open(file, 'rb').read()
|
||||
return c
|
||||
suffix = mw.getPathSuffix(file)
|
||||
if suffix == '.css':
|
||||
content = mw.readFile(file)
|
||||
from flask import Response
|
||||
from flask import make_response
|
||||
v = Response(content, headers={
|
||||
'Content-Type': 'text/css; charset="utf-8"'})
|
||||
return make_response(v)
|
||||
content = open(file, 'rb').read()
|
||||
return content
|
||||
|
||||
def indexListApi(self):
|
||||
data = self.getIndexList()
|
||||
@@ -214,10 +245,7 @@ class plugins_api:
|
||||
isNeedAdd = False
|
||||
|
||||
if isNeedAdd:
|
||||
tmp = {}
|
||||
tmp['title'] = info['title']
|
||||
tmp['name'] = info['name']
|
||||
data.append(tmp)
|
||||
data.append(info)
|
||||
mw.writeFile(hookPath, json.dumps(data))
|
||||
|
||||
def hookUninstallFile(self, hook_name, info):
|
||||
@@ -228,26 +256,45 @@ class plugins_api:
|
||||
data = json.loads(t)
|
||||
|
||||
for idx in range(len(data)):
|
||||
if data[idx]['title'] == info['title'] and data[idx]['name'] == info['name']:
|
||||
if data[idx]['name'] == info['name']:
|
||||
data.remove(data[idx])
|
||||
break
|
||||
mw.writeFile(hookPath, json.dumps(data))
|
||||
|
||||
def hookInstall(self, info):
|
||||
valid_hook = ['backup', 'database']
|
||||
valid_list_hook = ['menu', 'global_static', 'site_cb']
|
||||
if 'hook' in info:
|
||||
hooks = info['hook']
|
||||
for x in hooks:
|
||||
if x in ['backup', 'database']:
|
||||
self.hookInstallFile(x, info)
|
||||
return True
|
||||
for h in hooks:
|
||||
hooks_type = type(h)
|
||||
if hooks_type == dict:
|
||||
tag = h['tag']
|
||||
if tag in valid_list_hook:
|
||||
self.hookInstallFile(tag, h[tag])
|
||||
elif hooks_type == str:
|
||||
for x in hooks:
|
||||
if x in valid_hook:
|
||||
self.hookInstallFile(x, info)
|
||||
return True
|
||||
return False
|
||||
|
||||
def hookUninstall(self, info):
|
||||
valid_hook = ['backup', 'database']
|
||||
valid_list_hook = ['menu', 'global_static', 'site_cb']
|
||||
if 'hook' in info:
|
||||
hooks = info['hook']
|
||||
for x in hooks:
|
||||
if x in ['backup', 'database']:
|
||||
self.hookUninstallFile(x, info)
|
||||
return True
|
||||
for h in hooks:
|
||||
hooks_type = type(h)
|
||||
if hooks_type == dict:
|
||||
tag = h['tag']
|
||||
if tag in valid_list_hook:
|
||||
self.hookUninstallFile(tag, h[tag])
|
||||
elif hooks_type == str:
|
||||
for x in hooks:
|
||||
if x in valid_hook:
|
||||
self.hookUninstallFile(x, info)
|
||||
return True
|
||||
return False
|
||||
|
||||
def uninstallOldApi(self):
|
||||
@@ -618,6 +665,7 @@ class plugins_api:
|
||||
"ps": info['ps'],
|
||||
"dependnet": "",
|
||||
"mutex": "",
|
||||
"icon": "",
|
||||
"path": path,
|
||||
"install_checks": checks,
|
||||
"uninsatll_checks": checks,
|
||||
@@ -632,6 +680,9 @@ class plugins_api:
|
||||
"uninstall_pre_inspection": False,
|
||||
}
|
||||
|
||||
if 'icon' in info:
|
||||
pInfo['icon'] = info['icon']
|
||||
|
||||
if checks.find('VERSION') > -1:
|
||||
pInfo['install_checks'] = checks.replace(
|
||||
'VERSION', info['versions'])
|
||||
@@ -677,6 +728,7 @@ class plugins_api:
|
||||
def makeList(self, data, sType='0'):
|
||||
plugins_info = []
|
||||
|
||||
# 相应类型
|
||||
if (data['pid'] == sType):
|
||||
if type(data['versions']) == list and 'coexist' in data and data['coexist']:
|
||||
tmp_data = self.makeCoexist(data)
|
||||
@@ -687,6 +739,7 @@ class plugins_api:
|
||||
plugins_info.append(pg)
|
||||
return plugins_info
|
||||
|
||||
# 全部
|
||||
if sType == '0':
|
||||
if type(data['versions']) == list and 'coexist' in data and data['coexist']:
|
||||
tmp_data = self.makeCoexist(data)
|
||||
@@ -696,6 +749,18 @@ class plugins_api:
|
||||
pg = self.getPluginInfo(data)
|
||||
plugins_info.append(pg)
|
||||
|
||||
# 已经安装
|
||||
if sType == '-1':
|
||||
if type(data['versions']) == list and 'coexist' in data and data['coexist']:
|
||||
tmp_data = self.makeCoexist(data)
|
||||
for index in range(len(tmp_data)):
|
||||
if tmp_data[index]['setup']:
|
||||
plugins_info.append(tmp_data[index])
|
||||
else:
|
||||
pg = self.getPluginInfo(data)
|
||||
if pg['setup']:
|
||||
plugins_info.append(pg)
|
||||
|
||||
# print plugins_info, data
|
||||
return plugins_info
|
||||
|
||||
@@ -731,7 +796,8 @@ class plugins_api:
|
||||
for index in range(len(tmp_data)):
|
||||
plugins_info.append(tmp_data[index])
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print(json_file)
|
||||
print(mw.getTracebackInfo())
|
||||
|
||||
start = (page - 1) * pageSize
|
||||
end = start + pageSize
|
||||
@@ -950,8 +1016,11 @@ class plugins_api:
|
||||
|
||||
# shell 调用
|
||||
def run(self, name, func, version='', args='', script='index'):
|
||||
path = self.__plugin_dir + \
|
||||
'/' + name + '/' + script + '.py'
|
||||
|
||||
path = self.__plugin_dir + '/' + name + '/' + script + '.py'
|
||||
if not os.path.exists(path):
|
||||
path = self.__plugin_dir + '/' + name + '/' + name + '.py'
|
||||
|
||||
py = 'python3 ' + path
|
||||
|
||||
if args == '':
|
||||
|
||||
+70
-11
@@ -72,6 +72,30 @@ class site_api:
|
||||
mw.execShell("mkdir -p " + self.sslLetsDir +
|
||||
" && chmod -R 755 " + self.sslLetsDir)
|
||||
|
||||
def runHook(self, hook_name, func_name):
|
||||
# 站点操作Hook
|
||||
hook_file = 'data/hook_site_cb.json'
|
||||
hook_cfg = []
|
||||
if os.path.exists(hook_file):
|
||||
t = mw.readFile(hook_file)
|
||||
hook_cfg = json.loads(t)
|
||||
|
||||
hook_num = len(hook_cfg)
|
||||
if hook_num == 0:
|
||||
return
|
||||
|
||||
import plugins_api
|
||||
pa = plugins_api.plugins_api()
|
||||
|
||||
for x in range(hook_num):
|
||||
hook_data = hook_cfg[x]
|
||||
if func_name in hook_data:
|
||||
app_name = hook_data["name"]
|
||||
run_func = hook_data[func_name]['func']
|
||||
# print(app_name, run_func)
|
||||
pa.run(app_name, run_func)
|
||||
return True
|
||||
|
||||
##### ----- start ----- ###
|
||||
def listApi(self):
|
||||
limit = request.form.get('limit', '10')
|
||||
@@ -550,7 +574,7 @@ class site_api:
|
||||
return mw.returnJson(False, '使用中,先关闭再删除')
|
||||
mw.execShell('rm -rf ' + ssl_lets_dir)
|
||||
elif ssl_type == 'acme':
|
||||
ssl_acme_dir = mw.getAcmeDir() + '/' + site_name
|
||||
ssl_acme_dir = mw.getAcmeDomainDir(site_name)
|
||||
csr_acme_path = ssl_acme_dir + '/fullchain.cer' # 生成证书路径
|
||||
if mw.md5(mw.readFile(csr_acme_path)) == mw.md5(mw.readFile(csr_path)):
|
||||
return mw.returnJson(False, '使用中,先关闭再删除')
|
||||
@@ -587,9 +611,9 @@ class site_api:
|
||||
csr_path = self.sslLetsDir + '/' + site_name + '/fullchain.pem' # 生成证书路径
|
||||
key_path = self.sslLetsDir + '/' + site_name + '/privkey.pem' # 密钥文件路径
|
||||
elif ssl_type == 'acme':
|
||||
csr_path = mw.getAcmeDir() + '/' + site_name + '/fullchain.cer' # 生成证书路径
|
||||
key_path = mw.getAcmeDir() + '/' + site_name + '/' + \
|
||||
site_name + '.key' # 密钥文件路径
|
||||
acme_dir = mw.getAcmeDomainDir(site_name)
|
||||
csr_path = acme_dir + '/fullchain.cer' # 生成证书路径
|
||||
key_path = acme_dir + '/' + site_name + '.key' # 密钥文件路径
|
||||
|
||||
key = mw.readFile(key_path)
|
||||
csr = mw.readFile(csr_path)
|
||||
@@ -989,16 +1013,17 @@ class site_api:
|
||||
# print(cmd)
|
||||
result = mw.execShell(cmd)
|
||||
|
||||
src_path = acme_dir + '/' + domains[0]
|
||||
src_path = mw.getAcmeDomainDir(domains[0])
|
||||
src_cert = src_path + '/fullchain.cer'
|
||||
src_key = src_path + '/' + domains[0] + '.key'
|
||||
src_cert.replace("\*", "*")
|
||||
|
||||
msg = '签发失败,您尝试申请证书的失败次数已达上限!<p>1、检查域名是否绑定到对应站点</p>\
|
||||
<p>2、检查域名是否正确解析到本服务器,或解析还未完全生效</p>\
|
||||
<p>3、如果您的站点设置了反向代理,或使用了CDN,请先将其关闭</p>\
|
||||
<p>4、如果您的站点设置了301重定向,请先将其关闭</p>\
|
||||
<p>5、如果以上检查都确认没有问题,请尝试更换DNS服务商</p>'
|
||||
if not os.path.exists(src_cert.replace("\*", "*")):
|
||||
if not os.path.exists(src_cert):
|
||||
data = {}
|
||||
data['err'] = result
|
||||
data['out'] = result[0]
|
||||
@@ -1243,7 +1268,18 @@ class site_api:
|
||||
|
||||
opid = mw.M('domain').where(
|
||||
"name=? AND (port=? OR pid=?)", (domain_name, domain_port, pid,)).getField('pid')
|
||||
if opid > 0:
|
||||
# print(opid)
|
||||
is_bind = False
|
||||
if type(opid) == list and len(opid) > 0:
|
||||
is_bind = True
|
||||
|
||||
if type(opid) == int and opid > 0:
|
||||
is_bind = True
|
||||
|
||||
if type(opid) == str and int(opid) > 0:
|
||||
is_bind = True
|
||||
|
||||
if is_bind:
|
||||
return mw.returnJson(False, '您添加的域名[{}],已绑定!'.format(domain_name))
|
||||
# if mw.M('sites').where('id=?', (opid,)).count():
|
||||
# return mw.returnJson(False, '指定域名已绑定过!')
|
||||
@@ -1260,6 +1296,7 @@ class site_api:
|
||||
mw.M('domain').add('pid,name,port,addtime',
|
||||
(pid, domain_name, domain_port, mw.getDate()))
|
||||
|
||||
self.runHook('site_cb', 'add')
|
||||
return mw.returnJson(True, '域名添加成功!')
|
||||
|
||||
def addDirBindApi(self):
|
||||
@@ -1389,7 +1426,7 @@ class site_api:
|
||||
data['filename'] = filename
|
||||
return mw.getJson(data)
|
||||
|
||||
# 修改物理路径
|
||||
# 修改物理路径
|
||||
def setPathApi(self):
|
||||
mid = request.form.get('id', '')
|
||||
path = request.form.get('path', '')
|
||||
@@ -2518,16 +2555,18 @@ location ^~ {from} {\n\
|
||||
self.createRootDir(self.sitePath)
|
||||
self.nginxAddConf()
|
||||
|
||||
mw.M('domain').add('pid,name,port,addtime',
|
||||
(pid, self.siteName, self.sitePort, mw.getDate()))
|
||||
|
||||
# 添加更多域名
|
||||
for domain in siteMenu['domainlist']:
|
||||
self.addDomain(domain, self.siteName, pid)
|
||||
|
||||
mw.M('domain').add('pid,name,port,addtime',
|
||||
(pid, self.siteName, self.sitePort, mw.getDate()))
|
||||
|
||||
data = {}
|
||||
data['siteStatus'] = False
|
||||
mw.restartWeb()
|
||||
|
||||
self.runHook('site_cb', 'add')
|
||||
return mw.returnJson(True, '添加成功')
|
||||
|
||||
def deleteWSLogs(self, webname):
|
||||
@@ -2577,7 +2616,27 @@ location ^~ {from} {\n\
|
||||
mw.execShell('rm -rf ' + ssl_acme_dir)
|
||||
|
||||
mw.M('sites').where("id=?", (sid,)).delete()
|
||||
mw.M('domain').where("pid=?", (sid,)).delete()
|
||||
mw.M('domain').where("name=?", (webname,)).delete()
|
||||
|
||||
# binding domain delete
|
||||
binding_list = mw.M('binding').field(
|
||||
'id,domain').where("pid=?", (sid,)).select()
|
||||
|
||||
for x in binding_list:
|
||||
wlog = mw.getLogsDir() + "/" + webname + "_" + x['domain'] + ".log"
|
||||
wlog_error = mw.getLogsDir() + "/" + webname + "_" + \
|
||||
x['domain'] + ".error.log"
|
||||
|
||||
if os.path.exists(wlog):
|
||||
mw.execShell('rm -rf ' + wlog)
|
||||
if os.path.exists(wlog_error):
|
||||
mw.execShell('rm -rf ' + wlog_error)
|
||||
|
||||
mw.M('binding').where("pid=?", (sid,)).delete()
|
||||
mw.restartWeb()
|
||||
|
||||
self.runHook('site_cb', 'delete')
|
||||
return mw.returnJson(True, '站点删除成功!')
|
||||
|
||||
def setEndDate(self, sid, edate):
|
||||
|
||||
@@ -0,0 +1,456 @@
|
||||
# coding: utf-8
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# MW-Linux面板
|
||||
# ---------------------------------------------------------------------------------
|
||||
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# SSH终端操作
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import json
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
import threading
|
||||
import re
|
||||
|
||||
from io import BytesIO, StringIO
|
||||
|
||||
import mw
|
||||
import paramiko
|
||||
|
||||
from flask_socketio import SocketIO, emit, send
|
||||
|
||||
|
||||
class ssh_terminal:
|
||||
|
||||
__debug_file = 'logs/terminal.log'
|
||||
__log_type = 'SSH终端'
|
||||
|
||||
# websocketio 唯一标识
|
||||
__sid = ''
|
||||
|
||||
__host = None
|
||||
__type = '0'
|
||||
__port = 22
|
||||
__user = None
|
||||
__pass = None
|
||||
__pkey = None
|
||||
__key_passwd = None
|
||||
|
||||
__rep_ssh_config = False
|
||||
__rep_ssh_service = False
|
||||
__sshd_config_backup = None
|
||||
|
||||
__ssh = None
|
||||
__tp = None
|
||||
__ps = None
|
||||
|
||||
__ssh_list = {}
|
||||
__ssh_last_request_time = {}
|
||||
|
||||
def __init__(self):
|
||||
ht = threading.Thread(target=self.heartbeat)
|
||||
ht.start()
|
||||
|
||||
def debug(self, msg):
|
||||
msg = "{} - {}:{} => {} \n".format(mw.formatDate(),
|
||||
self.__host, self.__port, msg)
|
||||
if not mw.isDebugMode():
|
||||
return
|
||||
mw.writeFile(self.__debug_file, msg, 'a+')
|
||||
|
||||
def returnMsg(self, status, msg):
|
||||
return {'status': status, 'msg': msg}
|
||||
|
||||
def restartSsh(self, act='reload'):
|
||||
'''
|
||||
重启ssh 无参数传递
|
||||
'''
|
||||
version = mw.readFile('/etc/redhat-release')
|
||||
if not os.path.exists('/etc/redhat-release'):
|
||||
mw.execShell('service ssh ' + act)
|
||||
elif version.find(' 7.') != -1 or version.find(' 8.') != -1:
|
||||
mw.execShell("systemctl " + act + " sshd.service")
|
||||
else:
|
||||
mw.execShell("/etc/init.d/sshd " + act)
|
||||
|
||||
def isRunning(self, rep=False):
|
||||
try:
|
||||
if rep and self.__rep_ssh_service:
|
||||
self.restartSsh('stop')
|
||||
return True
|
||||
|
||||
status = self.getSshStatus()
|
||||
if not status:
|
||||
self.restartSsh('start')
|
||||
self.__rep_ssh_service = True
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
def setSshdConfig(self, rep=False):
|
||||
self.isRunning(rep)
|
||||
if rep and not self.__rep_ssh_config:
|
||||
return False
|
||||
|
||||
try:
|
||||
sshd_config_file = '/etc/ssh/sshd_config'
|
||||
if not os.path.exists(sshd_config_file):
|
||||
return False
|
||||
|
||||
sshd_config = mw.readFile(sshd_config_file)
|
||||
if not sshd_config:
|
||||
return False
|
||||
|
||||
if rep:
|
||||
if self.__sshd_config_backup:
|
||||
mw.writeFile(sshd_config_file, self.__sshd_config_backup)
|
||||
self.restartSsh()
|
||||
return True
|
||||
|
||||
pin = r'^\s*PubkeyAuthentication\s+(yes|no)'
|
||||
pubkey_status = re.findall(pin, sshd_config, re.I)
|
||||
if pubkey_status:
|
||||
if pubkey_status[0] == 'yes':
|
||||
pubkey_status = True
|
||||
else:
|
||||
pubkey_status = False
|
||||
|
||||
pin = r'^\s*RSAAuthentication\s+(yes|no)'
|
||||
rsa_status = re.findall(pin, sshd_config, re.I)
|
||||
if rsa_status:
|
||||
if rsa_status[0] == 'yes':
|
||||
rsa_status = True
|
||||
else:
|
||||
rsa_status = False
|
||||
|
||||
self._sshd_config_backup = sshd_config
|
||||
is_write = False
|
||||
if not pubkey_status:
|
||||
sshd_config = re.sub(
|
||||
r'\n#?PubkeyAuthentication\s\w+', '\nPubkeyAuthentication yes', sshd_config)
|
||||
is_write = True
|
||||
if not rsa_status:
|
||||
sshd_config = re.sub(
|
||||
r'\n#?RSAAuthentication\s\w+', '\nRSAAuthentication yes', sshd_config)
|
||||
is_write = True
|
||||
|
||||
if is_write:
|
||||
mw.writeFile(sshd_config_file, sshd_config)
|
||||
self.__rep_ssh_config = True
|
||||
self.restartSsh()
|
||||
else:
|
||||
self.__sshd_config_backup = None
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def setSid(self, sid):
|
||||
self.__sid = sid
|
||||
|
||||
def connect(self, sid):
|
||||
# self.connectBySocket()
|
||||
if self.__host in ['127.0.0.1', 'localhost']:
|
||||
return self.connectLocalSsh(sid)
|
||||
else:
|
||||
return self.connectBySocket(sid)
|
||||
|
||||
def connectLocalSsh(self, sid):
|
||||
mw.createSshInfo()
|
||||
self.__ps = paramiko.SSHClient()
|
||||
self.__ps.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
self.__port = mw.getSSHPort()
|
||||
try:
|
||||
self.__ps.connect(self.__host, self.__port, timeout=60)
|
||||
except Exception as e:
|
||||
self.__ps.connect('127.0.0.1', self.__port)
|
||||
except Exception as e:
|
||||
self.__ps.connect('localhost', self.__port)
|
||||
except Exception as e:
|
||||
self.setSshdConfig(True)
|
||||
self.__ps.close()
|
||||
e = str(e)
|
||||
if e.find('websocket error!') != -1:
|
||||
return self.returnMsg(True, '连接成功')
|
||||
if e.find('Authentication timeout') != -1:
|
||||
self.debug("认证超时{}".format(e))
|
||||
return self.returnMsg(False, '认证超时,请按回车重试!{}'.format(e))
|
||||
if e.find('Connection reset by peer') != -1:
|
||||
self.debug('目标服务器主动拒绝连接')
|
||||
return self.returnMsg(False, '目标服务器主动拒绝连接')
|
||||
if e.find('Error reading SSH protocol banner') != -1:
|
||||
self.debug('协议头响应超时')
|
||||
return self.returnMsg(False, '协议头响应超时,与目标服务器之间的网络质量太糟糕:' + e)
|
||||
if not e:
|
||||
self.debug('SSH协议握手超时')
|
||||
return self.returnMsg(False, "SSH协议握手超时,与目标服务器之间的网络质量太糟糕")
|
||||
err = mw.getTracebackInfo()
|
||||
self.debug(err)
|
||||
return self.returnMsg(False, "未知错误: {}".format(err))
|
||||
|
||||
self.debug('local-ssh:认证成功,正在构建会话通道')
|
||||
ssh = self.__ps.invoke_shell(
|
||||
term='xterm', width=83, height=21)
|
||||
ssh.setblocking(0)
|
||||
self.__ssh_list[sid] = ssh
|
||||
mw.writeLog(self.__log_type, '成功登录到SSH服务器 [{}:{}]'.format(
|
||||
self.__host, self.__port))
|
||||
self.debug('local-ssh:通道已构建')
|
||||
return self.returnMsg(True, '连接成功!')
|
||||
|
||||
def connectBySocket(self, sid):
|
||||
if not self.__host:
|
||||
return self.returnMsg(False, '错误的连接地址')
|
||||
if not self.__user:
|
||||
self.__user = 'root'
|
||||
if not self.__port:
|
||||
self.__port = 22
|
||||
|
||||
self.setSshdConfig(True)
|
||||
num = 0
|
||||
while num < 5:
|
||||
num += 1
|
||||
try:
|
||||
self.debug('正在尝试第{}次连接'.format(num))
|
||||
if self.__rep_ssh_config:
|
||||
time.sleep(0.1)
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(2 + num)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 8192)
|
||||
sock.connect((self.__host, self.__port))
|
||||
break
|
||||
except Exception as e:
|
||||
if num == 5:
|
||||
self.setSshdConfig(True)
|
||||
self.debug('重试连接失败,{}'.format(e))
|
||||
return self.returnMsg(False, '连接目标服务器失败, {}:{}'.format(self.__host, self.__port))
|
||||
else:
|
||||
time.sleep(0.2)
|
||||
|
||||
# print(self.__host, sock)
|
||||
self.__tp = paramiko.Transport(sock)
|
||||
try:
|
||||
self.__tp.start_client()
|
||||
self.__tp.banner_timeout = 60
|
||||
if not self.__pass and not self.__pkey:
|
||||
return self.returnMsg(False, '密码或私钥不能都为空: {}:{}'.format(self.__host, self.__port))
|
||||
|
||||
if self.__pkey != '' and self.__type != '0':
|
||||
self.debug('正在认证私钥')
|
||||
p_file = StringIO(str(self.__pkey.replace('\\n', '\n')))
|
||||
# p_file = "/tmp/t_ssh_pkey.txt"
|
||||
# mw.writeFile(p_file, self.__pkey.replace('\\n', '\n'))
|
||||
# mw.execShell('chmod 600 ' + p_file)
|
||||
try:
|
||||
p_file.seek(0)
|
||||
pkey = paramiko.RSAKey.from_private_key(p_file)
|
||||
except:
|
||||
try:
|
||||
p_file.seek(0) # 重置游标
|
||||
pkey = paramiko.Ed25519Key.from_private_key(
|
||||
p_file)
|
||||
except:
|
||||
try:
|
||||
p_file.seek(0)
|
||||
pkey = paramiko.ECDSAKey.from_private_key(p_file)
|
||||
except:
|
||||
p_file.seek(0)
|
||||
pkey = paramiko.DSSKey.from_private_key(p_file)
|
||||
|
||||
self.__tp.auth_publickey(username=self.__user, key=pkey)
|
||||
else:
|
||||
try:
|
||||
self.__tp.auth_none(self.__user)
|
||||
except Exception as e:
|
||||
e = str(e)
|
||||
if e.find('keyboard-interactive') >= 0:
|
||||
self._auth_interactive()
|
||||
else:
|
||||
self.debug('正在认证密码')
|
||||
self.__tp.auth_password(
|
||||
username=self.__user, password=self.__pass)
|
||||
except Exception as e:
|
||||
self.setSshdConfig(True)
|
||||
self.__tp.close()
|
||||
e = str(e)
|
||||
# print(e)
|
||||
if e.find('Authentication timeout') != -1:
|
||||
self.debug("认证超时{}".format(e))
|
||||
return self.returnMsg(False, '认证超时,请按回车重试!{}'.format(e))
|
||||
if e.find('Authentication failed') != -1:
|
||||
self.debug('认证失败{}'.format(e))
|
||||
return self.returnMsg(False, '帐号或密码错误: {}'.format(e + "," + self.__user + "@" + self.__host + ":" + str(self.__port)))
|
||||
if e.find('Bad authentication type; allowed types') != -1:
|
||||
self.debug('认证失败{}'.format(e))
|
||||
if self.__host in ['127.0.0.1', 'localhost'] and self.__pass == 'none':
|
||||
return self.returnMsg(False, '帐号或密码错误: {}'.format("Authentication failed ," + self.__user + "@" + self.__host + ":" + str(self.__port)))
|
||||
return self.returnMsg(False, '不支持的身份验证类型: {}'.format(e))
|
||||
if e.find('Connection reset by peer') != -1:
|
||||
self.debug('目标服务器主动拒绝连接')
|
||||
return self.returnMsg(False, '目标服务器主动拒绝连接')
|
||||
if e.find('Error reading SSH protocol banner') != -1:
|
||||
self.debug('协议头响应超时')
|
||||
return self.returnMsg(False, '协议头响应超时,与目标服务器之间的网络质量太糟糕:' + e)
|
||||
if not e:
|
||||
self.debug('SSH协议握手超时')
|
||||
return self.returnMsg(False, "SSH协议握手超时,与目标服务器之间的网络质量太糟糕")
|
||||
err = mw.getTracebackInfo()
|
||||
self.debug(err)
|
||||
return self.returnMsg(False, "未知错误: {}".format(err))
|
||||
|
||||
self.debug('认证成功,正在构建会话通道')
|
||||
|
||||
ssh = self.__tp.open_session()
|
||||
ssh.get_pty(term='xterm', width=100, height=34)
|
||||
ssh.invoke_shell()
|
||||
self.__ssh_list[sid] = ssh
|
||||
mw.writeLog(self.__log_type, '成功登录到SSH服务器 [{}:{}]'.format(
|
||||
self.__host, self.__port))
|
||||
self.debug('通道已构建')
|
||||
return self.returnMsg(True, '连接成功.')
|
||||
|
||||
def getSshInfo(self, file):
|
||||
rdata = mw.readFile(file)
|
||||
destr = mw.enDoubleCrypt('mdserver-web', rdata)
|
||||
return json.loads(destr)
|
||||
|
||||
def setAttr(self, sid, info):
|
||||
self.__host = info['host'].strip()
|
||||
|
||||
# 外部连接获取
|
||||
if not self.__host in ['127.0.0.1', 'localhost']:
|
||||
dst_info = mw.getServerDir() + '/webssh/host/' + self.__host + '/info.json'
|
||||
if os.path.exists(dst_info):
|
||||
info = self.getSshInfo(dst_info)
|
||||
|
||||
if 'type' in info:
|
||||
self.__type = info['type']
|
||||
|
||||
if 'port' in info:
|
||||
self.__port = int(info['port'])
|
||||
if 'username' in info:
|
||||
self.__user = info['username']
|
||||
if 'pkey' in info:
|
||||
self.__pkey = info['pkey']
|
||||
if 'password' in info:
|
||||
self.__pass = info['password']
|
||||
if 'pkey_passwd' in info:
|
||||
self.__key_passwd = info['pkey_passwd']
|
||||
|
||||
# print(self.__host, self.__pass, self.__key_passwd)
|
||||
try:
|
||||
result = self.connect(sid)
|
||||
# print(result)
|
||||
except Exception as ex:
|
||||
if str(ex).find("NoneType") == -1:
|
||||
raise ex
|
||||
return result
|
||||
|
||||
def send(self):
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
try:
|
||||
if self.__ssh:
|
||||
self.__ssh.close()
|
||||
if self.__tp: # 关闭宿主服务
|
||||
self.__tp.close()
|
||||
if self.__ps:
|
||||
self.__ps.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
def resize(self, sid, data):
|
||||
try:
|
||||
self.__ssh_list[sid].resize_pty(
|
||||
width=data['cols'], height=data['rows'])
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def wsSend(self, recv):
|
||||
try:
|
||||
t = recv.decode("utf-8")
|
||||
return emit('server_response', {'data': t})
|
||||
except Exception as e:
|
||||
return emit('server_response', {'data': recv})
|
||||
|
||||
def wsSendConnect(self):
|
||||
return emit('connect', {'data': 'ok'})
|
||||
|
||||
def wsSendReConnect(self):
|
||||
return emit('reconnect', {'data': 'ok'})
|
||||
|
||||
def heartbeat(self):
|
||||
# limit_cos = 10
|
||||
while True:
|
||||
time.sleep(3)
|
||||
cur_time = time.time()
|
||||
for x in list(self.__ssh_list.keys()):
|
||||
ssh_last_time = self.__ssh_last_request_time[x]
|
||||
sid_off_cos = cur_time - ssh_last_time
|
||||
|
||||
# print("heartbeat off cos :", x, sid_off_cos)
|
||||
if sid_off_cos > 3:
|
||||
cur_ssh = self.__ssh_list[x]
|
||||
if not cur_ssh:
|
||||
del(self.__ssh_list[x])
|
||||
del(self.__ssh_last_request_time[x])
|
||||
continue
|
||||
|
||||
if cur_ssh.exit_status_ready():
|
||||
del(self.__ssh_list[x])
|
||||
del(self.__ssh_last_request_time[x])
|
||||
continue
|
||||
|
||||
cur_ssh.send("exit\r\n")
|
||||
del(self.__ssh_list[x])
|
||||
del(self.__ssh_last_request_time[x])
|
||||
|
||||
def run(self, sid, info):
|
||||
self.__sid = sid
|
||||
if not self.__sid:
|
||||
return self.wsSend('WebSocketIO无效')
|
||||
|
||||
self.__ssh_last_request_time[sid] = time.time()
|
||||
if not sid in self.__ssh_list:
|
||||
if type(info) == dict and 'host' in info:
|
||||
result = self.setAttr(sid, info)
|
||||
if result['status']:
|
||||
return self.wsSendConnect()
|
||||
else:
|
||||
return self.wsSend(result['msg'])
|
||||
else:
|
||||
return self.wsSendReConnect()
|
||||
|
||||
result = self.returnMsg(False, '')
|
||||
if sid in self.__ssh_list:
|
||||
if 'resize' in info:
|
||||
self.resize(sid, info)
|
||||
result = self.returnMsg(True, '已连接')
|
||||
if result['status']:
|
||||
if type(info) == str:
|
||||
time.sleep(0.1)
|
||||
cur_ssh = self.__ssh_list[sid]
|
||||
if cur_ssh.exit_status_ready():
|
||||
self.wsSend("logout\r\n")
|
||||
del(self.__ssh_list[sid])
|
||||
return
|
||||
cur_ssh.send(info)
|
||||
try:
|
||||
time.sleep(0.005)
|
||||
recv = cur_ssh.recv(8192)
|
||||
return self.wsSend(recv)
|
||||
except Exception as ex:
|
||||
return self.wsSend('')
|
||||
else:
|
||||
return self.wsSend(result['msg'])
|
||||
@@ -166,6 +166,33 @@ class system_api:
|
||||
except:
|
||||
return False
|
||||
|
||||
def getEnvInfoApi(self, get=None):
|
||||
serverInfo = {}
|
||||
serverInfo['status'] = True
|
||||
sdir = mw.getServerDir()
|
||||
|
||||
serverInfo['webserver'] = '未安装'
|
||||
if os.path.exists(sdir + '/openresty/nginx/sbin/nginx'):
|
||||
serverInfo['webserver'] = 'OpenResty'
|
||||
serverInfo['php'] = []
|
||||
phpversions = ['52', '53', '54', '55', '56', '70', '71',
|
||||
'72', '73', '74', '80', '81', '82', '83', '84']
|
||||
phpPath = sdir + '/php/'
|
||||
for pv in phpversions:
|
||||
if not os.path.exists(phpPath + pv + '/bin/php'):
|
||||
continue
|
||||
serverInfo['php'].append(pv)
|
||||
serverInfo['mysql'] = False
|
||||
if os.path.exists(sdir + '/mysql/bin/mysql'):
|
||||
serverInfo['mysql'] = True
|
||||
import psutil
|
||||
try:
|
||||
diskInfo = psutil.disk_usage('/www')
|
||||
except:
|
||||
diskInfo = psutil.disk_usage('/')
|
||||
serverInfo['disk'] = diskInfo[2]
|
||||
return mw.returnJson(True, 'ok', serverInfo)
|
||||
|
||||
def getPanelInfo(self, get=None):
|
||||
# 取面板配置
|
||||
address = mw.GetLocalIp()
|
||||
@@ -724,6 +751,26 @@ class system_api:
|
||||
mw.execShell('rm -rf ' + toPath + '/mdserver-web-' + version)
|
||||
mw.execShell('rm -rf ' + toPath + '/mw.zip')
|
||||
|
||||
update_env = '''
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
|
||||
if [ ! -f /www/server/mdserver-web/bin/activate ];then
|
||||
cd /www/server/mdserver-web && python3 -m venv .
|
||||
cd /www/server/mdserver-web && source /www/server/mdserver-web/bin/activate
|
||||
else
|
||||
cd /www/server/mdserver-web && source /www/server/mdserver-web/bin/activate
|
||||
fi
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
PIPSRC="https://pypi.python.org/simple"
|
||||
if [ ! -z "$cn" ];then
|
||||
PIPSRC="https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
fi
|
||||
|
||||
cd /www/server/mdserver-web && pip3 install -r /www/server/mdserver-web/requirements.txt -i $PIPSRC
|
||||
'''
|
||||
os.system(update_env)
|
||||
self.restartMw()
|
||||
return mw.returnJson(True, '安装更新成功!')
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# coding:utf-8
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# MW-Linux面板
|
||||
# ---------------------------------------------------------------------------------
|
||||
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# VIP用户管理
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import mw
|
||||
|
||||
from flask import request
|
||||
import requests
|
||||
|
||||
|
||||
class vip_api:
|
||||
|
||||
api_url = 'https://wo.midoks.me/api/wp-json/vip'
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def loginApi(self):
|
||||
username = request.form.get('username', '')
|
||||
password = request.form.get('password', '')
|
||||
password = mw.aesEncrypt(password)
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
|
||||
print("name:", str(username))
|
||||
print("pwd:", str(password))
|
||||
args = {
|
||||
'name': username,
|
||||
'pass': password
|
||||
}
|
||||
data = requests.post(self.api_url + '/v1/login',
|
||||
data=args, headers=headers)
|
||||
|
||||
print(data.text)
|
||||
|
||||
return mw.returnJson(False, "测试中!")
|
||||
@@ -0,0 +1,43 @@
|
||||
# coding: utf-8
|
||||
|
||||
import smtplib
|
||||
|
||||
from email import encoders
|
||||
from email.header import Header
|
||||
from email.mime.text import MIMEText
|
||||
from email.utils import parseaddr, formataddr
|
||||
|
||||
|
||||
def _format_addr(s):
|
||||
name, addr = parseaddr(s)
|
||||
return formataddr((Header(name, 'utf-8').encode(), addr))
|
||||
|
||||
|
||||
def send(smtp_host, smtp_port, username, password, to_mail, subject, content):
|
||||
|
||||
smtp = smtplib.SMTP()
|
||||
smtp.connect(smtp_host, port=smtp_port)
|
||||
smtp.login(user=username, password=password)
|
||||
|
||||
msg = MIMEText(content, 'plain', 'utf-8')
|
||||
msg['From'] = _format_addr(username)
|
||||
msg['To'] = _format_addr(to_mail)
|
||||
msg['Subject'] = Header(subject, 'utf-8').encode()
|
||||
|
||||
smtp.sendmail(from_addr=username, to_addrs=to_mail, msg=msg.as_string())
|
||||
return True
|
||||
|
||||
|
||||
def sendSSL(smtp_host, smtp_port, username, password, to_mail, subject, content):
|
||||
|
||||
smtp = smtplib.SMTP_SSL(smtp_host, port=smtp_port)
|
||||
smtp.login(user=username, password=password)
|
||||
|
||||
msg = MIMEText(content, 'plain', 'utf-8')
|
||||
msg['From'] = _format_addr(username)
|
||||
msg['To'] = _format_addr(to_mail)
|
||||
msg['Subject'] = Header(subject, 'utf-8').encode()
|
||||
|
||||
smtp.sendmail(from_addr=username, to_addrs=to_mail, msg=msg.as_string())
|
||||
smtp.quit()
|
||||
return True
|
||||
@@ -65,6 +65,9 @@ class ORM:
|
||||
def setCharset(self, charset):
|
||||
self.__DB_CHARSET = charset
|
||||
|
||||
def setHost(self, host):
|
||||
self.__DB_HOST = host
|
||||
|
||||
def setPort(self, port):
|
||||
self.__DB_PORT = port
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ mw_start_task()
|
||||
sleep 0.3
|
||||
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "\033[31mfailed\033[0m"
|
||||
echo '------------------------------------------------------'
|
||||
tail -n 20 $DIR/logs/task.log
|
||||
echo '------------------------------------------------------'
|
||||
echo -e "\033[31mError: mw-tasks service startup failed.\033[0m"
|
||||
return;
|
||||
echo -e "\033[31mfailed\033[0m"
|
||||
echo '------------------------------------------------------'
|
||||
tail -n 20 $DIR/logs/task.log
|
||||
echo '------------------------------------------------------'
|
||||
echo -e "\033[31mError: mw-tasks service startup failed.\033[0m"
|
||||
return;
|
||||
fi
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
else
|
||||
@@ -43,7 +43,12 @@ mw_start(){
|
||||
|
||||
mw_start_debug(){
|
||||
python3 task.py >> $DIR/logs/task.log 2>&1 &
|
||||
gunicorn -b :7200 -k gevent -w 1 app:app
|
||||
port=7200
|
||||
if [ -f /www/server/mdserver-web/data/port.pl ];then
|
||||
port=$(cat /www/server/mdserver-web/data/port.pl)
|
||||
fi
|
||||
# gunicorn -b :${port} -k gevent -w 1 app:app
|
||||
gunicorn -b :${port} -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
|
||||
}
|
||||
|
||||
mw_start_debug2(){
|
||||
@@ -57,14 +62,14 @@ mw_stop()
|
||||
PLIST=`ps -ef|grep app:app |grep -v grep|awk '{print $2}'`
|
||||
for i in $PLIST
|
||||
do
|
||||
kill -9 $i
|
||||
kill -9 $i > /dev/null 2>&1
|
||||
done
|
||||
|
||||
pids=`ps -ef|grep task.py | grep -v grep |awk '{print $2}'`
|
||||
arr=($pids)
|
||||
for p in ${arr[@]}
|
||||
do
|
||||
kill -9 $p
|
||||
kill -9 $p > /dev/null 2>&1
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
"type":0,
|
||||
"ps":""
|
||||
},
|
||||
{
|
||||
"title":"已安装",
|
||||
"type":-1,
|
||||
"ps":""
|
||||
},
|
||||
{
|
||||
"title":"运行环境",
|
||||
"type":1,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
存放VIP关键数据
|
||||
@@ -194,14 +194,17 @@ def backupAllFunc(stype):
|
||||
'/scripts/backup.py ' + args
|
||||
|
||||
os.system(cmd)
|
||||
# 开始执行上传信息
|
||||
|
||||
bk_prefix = prefix_dict[stype]
|
||||
bk_name = stype
|
||||
# 开始执行上传信息.
|
||||
|
||||
if stype.find('database_') > -1:
|
||||
bk_name = 'database'
|
||||
plugin_name = stype.replace('database_', '')
|
||||
bk_prefix = plugin_name + '/db'
|
||||
stype = 'database'
|
||||
else:
|
||||
bk_prefix = prefix_dict[stype]
|
||||
bk_name = stype
|
||||
|
||||
find_path = mw.getBackupDir() + '/' + bk_name + '/' + bk_prefix + '_' + name
|
||||
find_new_file = "ls " + find_path + \
|
||||
@@ -212,10 +215,10 @@ def backupAllFunc(stype):
|
||||
mw.echoInfo("not find upload file!")
|
||||
return False
|
||||
|
||||
print("|-准备上传文件 {}".format(filename))
|
||||
ftp = FtpPSClient()
|
||||
ftp.uploadFile(filename, stype)
|
||||
|
||||
return True
|
||||
return ''
|
||||
|
||||
|
||||
def backupSite():
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"checks":"server/backup_ftp",
|
||||
"path": "server/backup_ftp",
|
||||
"author":"midoks",
|
||||
"home":"",
|
||||
"home":"https://github.com/midoks/mdserver-web",
|
||||
"date":"2022-10-23",
|
||||
"pid": "4"
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Executable
+20
@@ -0,0 +1,20 @@
|
||||
<div class="bt-form">
|
||||
<div class='plugin_version'></div>
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('docker');">服务</p>
|
||||
<p onclick="pluginInitD('docker');">自启动</p>
|
||||
<p onclick="dockerList();">容器列表</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
resetPluginWinWidth(700);
|
||||
resetPluginWinHeight(400);
|
||||
$.getScript( "/plugins/file?name=docker&f=js/docker.js", function(){
|
||||
pluginService('docker', $('.plugin_version').attr('version'));
|
||||
});
|
||||
</script>
|
||||
Executable
+169
@@ -0,0 +1,169 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'docker'
|
||||
|
||||
|
||||
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 getConf():
|
||||
path = getServerDir() + "/redis.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getConfTpl():
|
||||
path = getPluginDir() + "/config/redis.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[3:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
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 status():
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep dockerd |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
|
||||
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def initDreplace():
|
||||
return ''
|
||||
|
||||
|
||||
def dockerOp(method):
|
||||
file = initDreplace()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
data = mw.execShell('systemctl ' + method + ' docker')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
return 'fail'
|
||||
|
||||
|
||||
def start():
|
||||
return dockerOp('start')
|
||||
|
||||
|
||||
def stop():
|
||||
return dockerOp('stop')
|
||||
|
||||
|
||||
def restart():
|
||||
status = dockerOp('restart')
|
||||
|
||||
log_file = runLog()
|
||||
mw.execShell("echo '' > " + log_file)
|
||||
return status
|
||||
|
||||
|
||||
def reload():
|
||||
return dockerOp('reload')
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
shell_cmd = 'systemctl status ' + \
|
||||
getPluginName() + ' | 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 ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('systemctl disable ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runLog():
|
||||
return getServerDir() + '/data/redis.log'
|
||||
|
||||
|
||||
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 == 'run_log':
|
||||
print(runLog())
|
||||
else:
|
||||
print('error')
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"sort": 7,
|
||||
"ps": "Docker 是一个开源的应用容器引擎(开发测试中)",
|
||||
"name": "docker",
|
||||
"title": "Docker",
|
||||
"shell": "install.sh",
|
||||
"versions":["1.0"],
|
||||
"updates":["1.0"],
|
||||
"tip": "soft",
|
||||
"checks": "server/docker",
|
||||
"path": "server/docker",
|
||||
"display": 1,
|
||||
"author": "Zend",
|
||||
"date": "2017-04-01",
|
||||
"home": "https://docker.io",
|
||||
"type": 0,
|
||||
"pid": "2"
|
||||
}
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/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")
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/docker && /bin/bash install.sh uninstall 1.0
|
||||
# cd /www/server/mdserver-web/plugins/docker && /bin/bash install.sh install 1.0
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=$2
|
||||
|
||||
Install_Docker()
|
||||
{
|
||||
which docker
|
||||
if [ "$?" == "0" ];then
|
||||
echo '安装已经完成docker' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/source
|
||||
|
||||
if [ ! -d $serverPath/docker ];then
|
||||
curl -fsSL https://get.docker.com | bash
|
||||
mkdir -p $serverPath/docker
|
||||
fi
|
||||
|
||||
if [ -d $serverPath/docker ];then
|
||||
echo "${VERSION}" > $serverPath/docker/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/docker/index.py start
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/docker/index.py initd_install
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_Docker()
|
||||
{
|
||||
CMD=yum
|
||||
which apt
|
||||
if [ "$?" == "0" ];then
|
||||
CMD=apt
|
||||
fi
|
||||
|
||||
if [ -f /usr/lib/systemd/system/docker.service ];then
|
||||
systemctl stop docker
|
||||
systemctl disable docker
|
||||
rm -rf /usr/lib/systemd/system/docker.service
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
$CMD remove -y docker docker-ce-cli containerd.io
|
||||
# docker-client \
|
||||
# docker-client-latest \
|
||||
# docker-common \
|
||||
# docker-latest \
|
||||
# docker-latest-logrotate \
|
||||
# docker-logrotate \
|
||||
# docker-selinux \
|
||||
# docker-engine-selinux \
|
||||
# docker-engine \
|
||||
# docker-ce
|
||||
|
||||
rm -rf $serverPath/docker
|
||||
echo "Uninstall_Docker" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_Docker
|
||||
else
|
||||
Uninstall_Docker
|
||||
fi
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
function dPost(method, version, args,callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var req_data = {};
|
||||
req_data['name'] = 'docker';
|
||||
req_data['func'] = method;
|
||||
req_data['version'] = version;
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
req_data['args'] = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/run', req_data, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
//错误展示10S
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function dPostCallbak(method, version, args,callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var req_data = {};
|
||||
req_data['name'] = 'docker';
|
||||
req_data['func'] = method;
|
||||
args['version'] = version;
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
req_data['args'] = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/callback', req_data, 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 dockerList(){
|
||||
$(".soft-man-con").html('');
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,11 @@ if [ ! -d $WEB_PATH ];then
|
||||
mkdir -p $WEB_PATH
|
||||
rsync -vauP --delete --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
else
|
||||
rsync -vauP --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
if [ -f $GIT_PROJECT_DIR/exclude.list ];then
|
||||
rsync -vauP --delete --exclude-from="$GIT_PROJECT_DIR/exclude.list" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
else
|
||||
rsync -vauP --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
fi
|
||||
fi
|
||||
|
||||
sysName=`uname`
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
<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="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">
|
||||
|
||||
@@ -560,7 +560,7 @@ def userProjectList():
|
||||
data['data'] = ret_data
|
||||
data['args'] = args
|
||||
data['list'] = mw.getPage(
|
||||
{'count': dlist_sum, 'p': page, 'row': page_size, 'tojs': 'userProjectList'})
|
||||
{'count': dlist_sum, 'p': page, 'row': page_size, 'tojs': 'userProjectListPost'})
|
||||
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"ps": "Gitea 是一个开源社区驱动的轻量级代码托管解决方案。",
|
||||
"ps": "Gitea是一个开源社区驱动的轻量级代码托管解决方案。",
|
||||
"name": "gitea",
|
||||
"title": "Gitea",
|
||||
"versions": ["1.17.2"],
|
||||
"versions": ["1.17.2","1.18.5"],
|
||||
"tip": "soft",
|
||||
"install_pre_inspection":false,
|
||||
"uninstall_pre_inspection":true,
|
||||
|
||||
@@ -14,7 +14,7 @@ if [ -f ${rootPath}/bin/activate ];then
|
||||
fi
|
||||
|
||||
|
||||
URL_DOWNLOAD=https://dl.gitea.io/
|
||||
URL_DOWNLOAD=https://dl.gitea.com
|
||||
|
||||
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
|
||||
@@ -187,7 +187,7 @@ function userProjectList(user, search){
|
||||
<thead><tr><th>项目</th><th>操作</th></tr></thead>\
|
||||
<tbody></tbody>\
|
||||
</table>\
|
||||
<div class='dataTables_paginate paging_bootstrap pagination' style='margin-top:0px;'><ul id='gitea_page' class='page'></ul></div>\
|
||||
<div class='dataTables_paginate paging_bootstrap pagination' style='margin-top:0px;'><ul class='page'><div class='gitea_page'></div></ul></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>",
|
||||
@@ -230,7 +230,8 @@ function userProjectListPost(user, search){
|
||||
var project_list = rdata['data']['data'];
|
||||
for (i in project_list) {
|
||||
var name = project_list[i]['name'];
|
||||
list += '<tr><td>'+name+'</td>\
|
||||
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>\
|
||||
|
||||
@@ -10,8 +10,8 @@ serverPath=$(dirname "$rootPath")
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=0.0.19
|
||||
|
||||
# bash install.sh install 0.0.16
|
||||
## cd /www/server/mdserver-web/plugins/imail && bash install.sh install 0.0.16
|
||||
# bash install.sh install 0.0.19
|
||||
## cd /www/server/mdserver-web/plugins/imail && bash install.sh install 0.0.19
|
||||
|
||||
bash ${rootPath}/scripts/getos.sh
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
@@ -24,7 +24,7 @@ get_arch() {
|
||||
TMP_ARCH=`arch`
|
||||
if [ "$TMP_ARCH" == "x86_64" ];then
|
||||
ARCH="amd64"
|
||||
else if [ "$TMP_ARCH" == "aarch64" ];then
|
||||
elif [ "$TMP_ARCH" == "aarch64" ];then
|
||||
ARCH="arm64"
|
||||
else
|
||||
echo $ARCH
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"uninstall_pre_inspection":true,
|
||||
"checks": "server/mariadb",
|
||||
"path": "server/mariadb",
|
||||
"versions":["10.6","10.7","10.8","10.9"],
|
||||
"versions":["10.6","10.7","10.8","10.9","10.11","11.0"],
|
||||
"shell":"install.sh",
|
||||
"checks":"server/mariadb",
|
||||
"path":"server/mariadb",
|
||||
|
||||
@@ -797,7 +797,7 @@ function openPhpmyadmin(name,username,password){
|
||||
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'get_cfg'});
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata.choose != 'mariadb'){
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请切换模式.',{icon:2,shade: [0.3, '#000']});
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请修改phpMyAdmin访问切换.',{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
var phpmyadmin_cfg = rdata;
|
||||
@@ -1185,7 +1185,7 @@ function myLogs(){
|
||||
<span class="f14 c6 mr20">二进制日志 </span><span class="f14 c6 mr20">' + toSize(rdata.msg) + '</span>\
|
||||
'+line_status+'\
|
||||
<p class="f14 c6 mtb10" style="border-top:#ddd 1px solid; padding:10px 0">错误日志<button class="btn btn-default btn-clear btn-xs" style="float:right;" >清理日志</button></p>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 440px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 438px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(limitCon);
|
||||
|
||||
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
#https://dev.mysql.com/downloads/mysql/5.5.html#downloads
|
||||
#https://dev.mysql.com/downloads/file/?id=480541
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sysName=`uname`
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=10.11.2
|
||||
|
||||
Install_app()
|
||||
{
|
||||
mkdir -p ${mariadbDir}
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
if id mysql &> /dev/null ;then
|
||||
echo "mysql uid is `id -u www`"
|
||||
echo "mysql shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
|
||||
else
|
||||
groupadd mysql
|
||||
useradd -g mysql mysql
|
||||
fi
|
||||
|
||||
if [ "$sysName" != "Darwin" ];then
|
||||
mkdir -p /var/log/mariadb
|
||||
touch /var/log/mariadb/mariadb.log
|
||||
fi
|
||||
|
||||
# ----- cpu start ------
|
||||
if [ -z "${cpuCore}" ]; then
|
||||
cpuCore="1"
|
||||
fi
|
||||
|
||||
if [ -f /proc/cpuinfo ];then
|
||||
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l`
|
||||
fi
|
||||
|
||||
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}')
|
||||
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then
|
||||
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then
|
||||
cpuCore="${MEM_INFO}"
|
||||
fi
|
||||
else
|
||||
cpuCore="1"
|
||||
fi
|
||||
|
||||
if [ "$cpuCore" -gt "2" ];then
|
||||
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
|
||||
else
|
||||
cpuCore="1"
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
# if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then
|
||||
# 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.9.1/source/mariadb-10.9.1.tar.gz
|
||||
if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://archive.mariadb.org/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 \
|
||||
-DCMAKE_INSTALL_PREFIX=$serverPath/mariadb \
|
||||
-DMYSQL_DATADIR=$serverPath/mariadb/data/ \
|
||||
-DMYSQL_USER=mysql \
|
||||
-DMYSQL_UNIX_ADDR=$serverPath/mariadb/mysql.sock \
|
||||
-DWITH_MYISAM_STORAGE_ENGINE=1 \
|
||||
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
|
||||
-DWITH_MEMORY_STORAGE_ENGINE=1 \
|
||||
-DENABLED_LOCAL_INFILE=1 \
|
||||
-DWITH_PARTITION_STORAGE_ENGINE=1 \
|
||||
-DEXTRA_CHARSETS=all \
|
||||
-DDEFAULT_CHARSET=utf8mb4 \
|
||||
-DDEFAULT_COLLATION=utf8mb4_general_ci \
|
||||
-DCMAKE_C_COMPILER=/usr/bin/gcc \
|
||||
-DCMAKE_CXX_COMPILER=/usr/bin/g++
|
||||
make -j${cpuCore} && make install && make clean
|
||||
|
||||
if [ -d $serverPath/mariadb ];then
|
||||
echo '10.11' > $serverPath/mariadb/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
else
|
||||
echo '安装失败' > $install_tmp
|
||||
echo 'install fail'>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -rf ${mariadbDir}/mariadb-${MY_VER}
|
||||
rm -rf ${mariadbDir}/mariadb-${MY_VER}.tar.gz
|
||||
}
|
||||
|
||||
Uninstall_app()
|
||||
{
|
||||
rm -rf $serverPath/mariadb
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_app
|
||||
else
|
||||
Uninstall_app
|
||||
fi
|
||||
@@ -13,7 +13,7 @@ sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=10.6.9
|
||||
MY_VER=10.6.12
|
||||
|
||||
Install_app()
|
||||
{
|
||||
|
||||
@@ -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.8
|
||||
|
||||
Install_app()
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=10.8.5
|
||||
MY_VER=10.8.7
|
||||
|
||||
Install_app()
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=10.9.2
|
||||
MY_VER=10.9.5
|
||||
|
||||
Install_app()
|
||||
{
|
||||
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
#https://dev.mysql.com/downloads/mysql/5.5.html#downloads
|
||||
#https://dev.mysql.com/downloads/file/?id=480541
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sysName=`uname`
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
mariadbDir=${serverPath}/source/mariadb
|
||||
|
||||
MY_VER=11.0.1
|
||||
|
||||
Install_app()
|
||||
{
|
||||
mkdir -p ${mariadbDir}
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
if id mysql &> /dev/null ;then
|
||||
echo "mysql uid is `id -u www`"
|
||||
echo "mysql shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
|
||||
else
|
||||
groupadd mysql
|
||||
useradd -g mysql mysql
|
||||
fi
|
||||
|
||||
if [ "$sysName" != "Darwin" ];then
|
||||
mkdir -p /var/log/mariadb
|
||||
touch /var/log/mariadb/mariadb.log
|
||||
fi
|
||||
|
||||
# ----- cpu start ------
|
||||
if [ -z "${cpuCore}" ]; then
|
||||
cpuCore="1"
|
||||
fi
|
||||
|
||||
if [ -f /proc/cpuinfo ];then
|
||||
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l`
|
||||
fi
|
||||
|
||||
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}')
|
||||
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then
|
||||
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then
|
||||
cpuCore="${MEM_INFO}"
|
||||
fi
|
||||
else
|
||||
cpuCore="1"
|
||||
fi
|
||||
|
||||
if [ "$cpuCore" -gt "2" ];then
|
||||
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
|
||||
else
|
||||
cpuCore="1"
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
# if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then
|
||||
# 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.9.1/source/mariadb-10.9.1.tar.gz
|
||||
if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then
|
||||
wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://archive.mariadb.org/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 \
|
||||
-DCMAKE_INSTALL_PREFIX=$serverPath/mariadb \
|
||||
-DMYSQL_DATADIR=$serverPath/mariadb/data/ \
|
||||
-DMYSQL_USER=mysql \
|
||||
-DMYSQL_UNIX_ADDR=$serverPath/mariadb/mysql.sock \
|
||||
-DWITH_MYISAM_STORAGE_ENGINE=1 \
|
||||
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
|
||||
-DWITH_MEMORY_STORAGE_ENGINE=1 \
|
||||
-DENABLED_LOCAL_INFILE=1 \
|
||||
-DWITH_PARTITION_STORAGE_ENGINE=1 \
|
||||
-DEXTRA_CHARSETS=all \
|
||||
-DDEFAULT_CHARSET=utf8mb4 \
|
||||
-DDEFAULT_COLLATION=utf8mb4_general_ci \
|
||||
-DCMAKE_C_COMPILER=/usr/bin/gcc \
|
||||
-DCMAKE_CXX_COMPILER=/usr/bin/g++
|
||||
make -j${cpuCore} && make install && make clean
|
||||
|
||||
if [ -d $serverPath/mariadb ];then
|
||||
echo '10.11' > $serverPath/mariadb/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
else
|
||||
echo '安装失败' > $install_tmp
|
||||
echo 'install fail'>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -rf ${mariadbDir}/mariadb-${MY_VER}
|
||||
rm -rf ${mariadbDir}/mariadb-${MY_VER}.tar.gz
|
||||
}
|
||||
|
||||
Uninstall_app()
|
||||
{
|
||||
rm -rf $serverPath/mariadb
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_app
|
||||
else
|
||||
Uninstall_app
|
||||
fi
|
||||
@@ -62,13 +62,16 @@ def getArgs():
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
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
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 478 B |
Executable
+292
@@ -0,0 +1,292 @@
|
||||
<style>
|
||||
.migration_content {
|
||||
position: relative;
|
||||
height: 450px;
|
||||
}
|
||||
.step_head::after {
|
||||
background-color: #ddd;
|
||||
border-top: 2px solid #ccc;
|
||||
content: "";
|
||||
display: block;
|
||||
height: 3px;
|
||||
left: 84px;
|
||||
position: absolute;
|
||||
top: 14px;
|
||||
width: 500px;
|
||||
z-index: -1;
|
||||
}
|
||||
.step_head {
|
||||
margin: 20px 0;
|
||||
}
|
||||
.step_head ul li {
|
||||
width: 24.5%;
|
||||
display: inline-block;
|
||||
}
|
||||
.step_head ul li span {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
display: block;
|
||||
border-radius: 15px;
|
||||
background-color: #ddd;
|
||||
color: #878787;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.step_head ul li p {
|
||||
text-align: center;
|
||||
margin-top: 15px;
|
||||
}
|
||||
.step_head ul li.active span {
|
||||
background-color: #20A53A;
|
||||
color: #fff;
|
||||
}
|
||||
.step_content {
|
||||
text-align: center;
|
||||
}
|
||||
.boxHide {
|
||||
display: none
|
||||
}
|
||||
.step_content .psync_info input {
|
||||
width: 300px;
|
||||
}
|
||||
.step_content .psync_info .panel_setp_span {
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
overflow: hidden;
|
||||
padding-right: 20px;
|
||||
text-align: right;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
width: 130px;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
}
|
||||
.step_content .psync_info .mtb20{
|
||||
padding-left: 40px;
|
||||
text-align: left;
|
||||
}
|
||||
.psync_path .table {
|
||||
text-align: left;
|
||||
}
|
||||
.psync_path .table > tbody > tr > td:nth-child(2n),
|
||||
.psync_path .table > thead > tr > th:nth-child(2n),
|
||||
.terlist .table > thead > tr > th:nth-child(2n),
|
||||
.terlist .table > tbody > tr > td:nth-child(2n),
|
||||
.terlist .table > tbody > tr > td:nth-child(1),
|
||||
.terlist .table > thead > tr > th:nth-child(1) {
|
||||
border-right: #ddd 1px solid;
|
||||
}
|
||||
|
||||
.checkbox_conten {
|
||||
background-color: #f3f3f3;
|
||||
border: #ddd 1px solid;
|
||||
border-radius: 4px;
|
||||
padding: 10px;
|
||||
margin: 0px 50px;
|
||||
}
|
||||
|
||||
.checkbox_item span {
|
||||
display: inline-block;
|
||||
height: 15px;
|
||||
overflow: hidden;
|
||||
text-align: left;
|
||||
display: block;
|
||||
padding-left: 20px;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
width: 152px;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
label.checkbox_label {
|
||||
margin-left: 6px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
label.checkbox_label span {
|
||||
color: #000;
|
||||
}
|
||||
.psync_data {
|
||||
display: none;
|
||||
}
|
||||
.psync_data .checkbox_item input[type="checkbox"] {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
margin-top: -6px;
|
||||
}
|
||||
|
||||
.checkbox_item label {
|
||||
font-weight: normal;
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.psync_data .checkbox_data {
|
||||
margin: 0 5px 5px;
|
||||
display: inline-block;
|
||||
width: 166px;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
|
||||
.psync_data .checkbox_data:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.checkbox_item ul {
|
||||
background-color: #fff;
|
||||
max-height: 174px;
|
||||
overflow: auto;
|
||||
width: 100%;
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.checkbox_item ul li {
|
||||
padding: 0 6px;
|
||||
}
|
||||
|
||||
.psync_data .checkbox_con {
|
||||
display: block
|
||||
}
|
||||
|
||||
.progress {
|
||||
background-color: #e2e2e2;
|
||||
border-radius: 8px;
|
||||
height: 16px;
|
||||
line-height: 16px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
background-color: #5ab76c;
|
||||
border-radius: 8px;
|
||||
height: 16px;
|
||||
max-width: 100%;
|
||||
position: absolute;
|
||||
text-align: right;
|
||||
transition: all 0.3s ease 0s;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
padding: 0 10px;
|
||||
position: static;
|
||||
}
|
||||
|
||||
.qystatus {
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.success {
|
||||
padding: 50px 0 60px;
|
||||
margin-left: -60px;
|
||||
}
|
||||
|
||||
.success p {
|
||||
margin-top: 20px;
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
}
|
||||
.psync_tips{
|
||||
color: red;
|
||||
font-size: 15px;
|
||||
background-color: #fbfbfb;
|
||||
border: 1px solid #eee;
|
||||
line-height: 46px;
|
||||
margin-bottom: 15px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
.psync_tips span{
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
<div class="migration_api pd15">
|
||||
<div class="migration_content">
|
||||
<div class="step_head">
|
||||
<ul>
|
||||
<li class="active"><span>1</span><p>填写信息</p></li>
|
||||
<li><span>2</span><p>检测环境</p></li>
|
||||
<li><span>3</span><p>选择数据</p></li>
|
||||
<li><span>4</span><p>一键迁移</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="step_content">
|
||||
<div class="pd15 psync_info">
|
||||
<div class="psync_tips">
|
||||
<span class="glyphicon glyphicon-alert" style="color: #f39c12; margin-right: 10px;"></span>只需在发送数据服务器安装本软件,请填写<span>『 接收数据服务器 』</span>资料。
|
||||
<a href="#" target="_blank" class="bt-ico-ask" style="cursor: pointer;">?</a>
|
||||
</div>
|
||||
<div class="mtb20">
|
||||
<span class="panel_setp_span">接收数据的面板地址</span>
|
||||
<input type="text" class="bt-input-text" name="sync_url" value="" placeholder="接收数据面板地址,如: http://127.0.0.1:8888">
|
||||
</div>
|
||||
<div class="mtb20">
|
||||
<span class="panel_setp_span">接收数据的面板API</span>
|
||||
<input type="text" class="bt-input-text" name="sync_token" value="" placeholder="接收数据面板API密钥" />
|
||||
<a href="#" target="_blank" class="btlink ml5">获取API秘钥</a>
|
||||
</div>
|
||||
<div class="mtb20">
|
||||
<span class="panel_setp_span">IP白名单</span>
|
||||
<span style="height: 32px;line-height: 32px;">必须将本机器IP加入接收数据服务器API的IP白名单,<a href="#" href="javascript:;" target="_blank" class="btlink">如何添加白名单</a></span>
|
||||
</div>
|
||||
<div class="mtb20" style="text-align: left;margin-left: 130px;">
|
||||
<button class="btn btn-success infoNext">下一步</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pa15 psync_path" style="margin:0 50px;"></div>
|
||||
<div class="pa15 psync_data" style="text-align: left;">
|
||||
<div class="checkbox_conten">
|
||||
<div class="checkbox_data">
|
||||
<div class="checkbox_item">
|
||||
<label class="checkbox_label">
|
||||
<input type="checkbox" id="sites_All" checked>
|
||||
<span>网站</span>
|
||||
</label>
|
||||
<ul id="sites_li"></ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="checkbox_data">
|
||||
<div class="checkbox_item">
|
||||
<label class="checkbox_label">
|
||||
<input type="checkbox" id="db_All" checked>
|
||||
<span>数据库</span>
|
||||
</label>
|
||||
<ul id="db_li"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="line mtb20" style="margin:20px 0 0 50px">
|
||||
<button class="btn btn-default btn-sm mr20 dataBack">上一步</button>
|
||||
<button class="btn btn-success btn-sm dataMigrate">一键迁移</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pa15 psync_migrate"></div>
|
||||
</div>
|
||||
<hr style="margin-top: 5px;" />
|
||||
<div class="step_footer" style="margin: 5px 0 0 20px;text-align: left;">
|
||||
<ul class="help-info-text c7 mlr20" style="margin-top: 0px;">
|
||||
<li>一键迁移过程中是后台执行可以关闭当前窗口</li>
|
||||
<li>一键迁移迁移数据不涉及原来数据的增删(是将原来数据打包发送)</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
resetPluginWinWidth(700);
|
||||
resetPluginWinWidth(700);
|
||||
$.getScript( "/plugins/file?name=migration_api&f=js/app.js", function(){
|
||||
initStep();
|
||||
});
|
||||
</script>
|
||||
Executable
+1090
File diff suppressed because it is too large
Load Diff
Executable
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"sort": 7,
|
||||
"ps": "[<span style='color:red;'>潜龙勿用</span>]一键迁移,仅网站数据和MySQL数据(仅支持源码安装软件)",
|
||||
"name": "migration_api",
|
||||
"title": "一键迁移API",
|
||||
"shell": "install.sh",
|
||||
"versions":["1.0"],
|
||||
"updates":["1.0"],
|
||||
"tip": "soft",
|
||||
"checks": "server/migration_api",
|
||||
"path":"server/migration_api",
|
||||
"display": 1,
|
||||
"author": "midoks",
|
||||
"date": "2022-01-17",
|
||||
"home": "https://github.com/midoks/mdserver-web",
|
||||
"type": 0,
|
||||
"pid": "4"
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/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=1.0
|
||||
|
||||
Install_App(){
|
||||
mkdir -p $serverPath/migration_api
|
||||
echo "${VERSION}" > $serverPath/migration_api/version.pl
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
rm -rf $serverPath/migration_api
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
Executable
+333
@@ -0,0 +1,333 @@
|
||||
|
||||
function maPostNoMsg(method,args,callback){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
$.post('/plugins/run', {name:'migration_api', func:method, args:_args}, 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 maPost(method,args,callback, msg = '正在获取...'){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
|
||||
var loadT = layer.msg(msg, { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'migration_api', 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 maAsyncPost(method,args){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
return syncPost('/plugins/run', {name:'migration_api', func:method, args:_args});
|
||||
}
|
||||
|
||||
|
||||
function maPostCallbak(method, args, callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var req_data = {};
|
||||
req_data['name'] = 'migration_api';
|
||||
req_data['func'] = method;
|
||||
args['version'] = '1.0';
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
req_data['args'] = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/callback', req_data, 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 selectProgress(val){
|
||||
$('.step_head li').removeClass('active');
|
||||
$('.step_head li').each(function(){
|
||||
var v = $(this).find('span').text();
|
||||
if (val == v){
|
||||
$(this).addClass('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initStep1(){
|
||||
var url = $('input[name="sync_url"]').val();
|
||||
var token = $('input[name="sync_token"]').val();
|
||||
maPost('step_one',{url:url,token:token}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
initStep2();
|
||||
}
|
||||
},{ icon: rdata.status ? 1 : 2 });
|
||||
},'API校验中...');
|
||||
}
|
||||
|
||||
function initStep2(){
|
||||
maPost('step_two',{}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
selectProgress(2);
|
||||
$('.psync_info').hide();
|
||||
|
||||
var info = rdata.data;
|
||||
|
||||
var body = '<div class="divtable">\
|
||||
<table class="table table-hover">\
|
||||
<thead>\
|
||||
<tr><th style="border-right:1px solid #ddd">服务</th><th>当前服务器</th><th>远程服务器</th></tr>\
|
||||
</thead>\
|
||||
<tbody>\
|
||||
<tr>\
|
||||
<td style="border-right:1px solid #ddd">网站服务</td>\
|
||||
<td>'+info['local']['webserver']+'</td>\
|
||||
<td>'+info['remote']['webserver']+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td style="border-right:1px solid #ddd">安装MySQL</td>\
|
||||
<td>'+(info['local']['mysql']?'是':'否')+'</td>\
|
||||
<td>'+(info['remote']['mysql']?'是':'否')+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td style="border-right:1px solid #ddd">安装PHP</td>\
|
||||
<td>'+(info['local']['php'].join('/'))+'</td>\
|
||||
<td>'+(info['remote']['php'].join('/')) +'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td style="border-right:1px solid #ddd">可用磁盘</td>\
|
||||
<td>'+info['local']['disk']+'</td>\
|
||||
<td>'+info['remote']['disk'][0]['size'][0]+'</td>\
|
||||
</tr>\
|
||||
</tbody>\
|
||||
</table>\
|
||||
</div>';
|
||||
body += '<div class="line mtb20" style="text-align: left;">\
|
||||
<button class="btn btn-default btn-sm mr20 pathTestting">重新检测</button>\
|
||||
<button class="btn btn-default btn-sm mr20 pathBcak">上一步</button>\
|
||||
<button class="btn btn-success btn-sm psync-next pathNext">下一步</button>\
|
||||
</div>';
|
||||
|
||||
$('.psync_path').html(body);
|
||||
$('.psync_path').show();
|
||||
}
|
||||
},{ icon: rdata.status ? 1 : 2 });
|
||||
},'检测环境中...');
|
||||
}
|
||||
|
||||
function initStep3(){
|
||||
maPost('step_three',{}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
selectProgress(3);
|
||||
var pdata = rdata.data;
|
||||
var site_li = '';
|
||||
for (var i = 0; i < pdata.sites.length; i++) {
|
||||
site_li+='<li>\
|
||||
<label>\
|
||||
<input type="checkbox" data-id="'+i+'" id="sites_'+pdata.sites[i]['name']+'" value="'+pdata.sites[i]['name']+'" name="sites" checked="">\
|
||||
<span title="'+pdata.sites[i]['name']+'">'+pdata.sites[i]['name']+'</span>\
|
||||
</label>\
|
||||
</li>';
|
||||
}
|
||||
|
||||
$('#sites_li').html(site_li);
|
||||
|
||||
|
||||
var db_li = '';
|
||||
for (var i = 0; i < pdata.databases.length; i++) {
|
||||
db_li+='<li>\
|
||||
<label>\
|
||||
<input type="checkbox" data-id="'+i+'" id="sites_'+pdata.databases[i]['name']+'" value="'+pdata.databases[i]['name']+'" name="databases" checked="">\
|
||||
<span title="'+pdata.databases[i]['name']+'">'+pdata.databases[i]['name']+'</span>\
|
||||
</label>\
|
||||
</li>';
|
||||
}
|
||||
$('#db_li').html(db_li);
|
||||
|
||||
$('.psync_path').hide();
|
||||
$('.psync_data').show();
|
||||
}
|
||||
},{ icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
}
|
||||
|
||||
function renderMigrationProgress(){
|
||||
maPostNoMsg('get_speed',{}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
// console.log('speed:',rdata.data);
|
||||
if (rdata.status){
|
||||
if (rdata['data']['action'] == 'True'){
|
||||
var end = '<div class="line">\
|
||||
<div class="success text-center" style="padding: 10px 0 15px;">\
|
||||
<p>数据迁移完成,请务必检查数据完整性!</p>\
|
||||
<p style="font-size: 14px;margin-top:2px;color: #939292;">传输大小: '+toSize(rdata['data']['total_size'])+',耗时: '+rdata['data']['total_time']+',平均速度: '+toSize(rdata['data']['speed'])+'/s</p>\
|
||||
<p class="mtb15">\
|
||||
<button class="btn btn-success btn-sm mr5 okBtn">确定完成</button>\
|
||||
<a class="btn btn-default btn-sm" style="margin-left: 10px;" target="_blank" href="/files/download?filename='+rdata['data']['log_file']+'">迁移日志</a>\
|
||||
</p>\
|
||||
</div>\
|
||||
</div>';
|
||||
$('.psync_migrate').html(end);
|
||||
} else{
|
||||
$('.psync_migrate .action').text(rdata['data']['action']);
|
||||
$('.psync_migrate .done').text(rdata['data']['done']);
|
||||
$('.psync_migrate pre').text(rdata['data']['log']);
|
||||
|
||||
var p = (rdata['data']['all_speed']/rdata['data']['all_total'])*100;
|
||||
if (p>100){
|
||||
p = 100;
|
||||
}
|
||||
$('.psync_migrate .progress_info_bar').width(p+'%');
|
||||
$('.psync_migrate .progress_info').text(p+'%');
|
||||
|
||||
renderMigrationProgress();
|
||||
}
|
||||
} else{
|
||||
layer.msg(rdata.msg,{icon:1});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initStep4(){
|
||||
var site_checked = '';
|
||||
$('input[name="sites"]:checked').each(function(){
|
||||
site_checked += $(this).val()+',';
|
||||
});
|
||||
|
||||
var databases_checked = '';
|
||||
$('input[name="databases"]:checked').each(function(){
|
||||
databases_checked+=$(this).val()+',';
|
||||
});
|
||||
|
||||
maPost('step_four',{sites:site_checked,databases:databases_checked}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
selectProgress(4);
|
||||
|
||||
var progress = '<div style="margin: 0 40px;">\
|
||||
<div class="line">\
|
||||
<div style="text-align:left"><span class="action">--</span>\
|
||||
<span style="margin-left: 20px;" class="done">当前: --</span><img src="/static/img/ing.gif"><a style="position: absolute;right: 40px;" class="btlink psync_close" onclick="migrate.close();">[取消]</a></div>\
|
||||
<div class="bt-progress" style="border-radius:0;height:20px;line-height:19px">\
|
||||
<div class="bt-progress-bar progress_info_bar" style="border-radius: 0px; height: 20px; width: 0%;">\
|
||||
<span class="bt-progress-text progress_info"></span></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<pre style="height: 222px;text-align: left;margin:5px 38px 0;font-size: 12px;line-height: 20px;padding: 10px;background-color: #333;color: #fff;"></pre>\
|
||||
</div>';
|
||||
|
||||
|
||||
$('.psync_data').hide();
|
||||
$('.psync_migrate').html(progress);
|
||||
$('.psync_migrate').show();
|
||||
|
||||
renderMigrationProgress();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function initStep(){
|
||||
maPost('get_conf',{}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
$('input[name="sync_url"]').val(rdata.data['url']);
|
||||
$('input[name="sync_token"]').val(rdata.data['token']);
|
||||
});
|
||||
|
||||
$('.infoNext').click(function(){
|
||||
initStep1();
|
||||
});
|
||||
|
||||
// 重新检测按钮
|
||||
$('.psync_path').on('click', '.pathTestting', function () {
|
||||
initStep2();
|
||||
});
|
||||
|
||||
$('.psync_path').on('click', '.pathBcak', function(){
|
||||
$('.psync_path').hide();
|
||||
$('.psync_info').show();
|
||||
selectProgress(1);
|
||||
});
|
||||
|
||||
$('.psync_path').on('click', '.pathNext', function(){
|
||||
initStep3();
|
||||
});
|
||||
|
||||
|
||||
$('.psync_data').on('click', '.dataBack', function(){
|
||||
$('.psync_data').hide();
|
||||
$('.psync_path').show();
|
||||
selectProgress(2);
|
||||
});
|
||||
|
||||
|
||||
$('.psync_data').on('click', '.dataMigrate', function(){
|
||||
initStep4();
|
||||
});
|
||||
|
||||
$('#sites_All').on('click',function(){
|
||||
var ch = $(this).prop('checked');
|
||||
$('#sites_li input').prop('checked',ch);
|
||||
});
|
||||
|
||||
$('#db_All').on('click',function(){
|
||||
var ch = $(this).prop('checked');
|
||||
$('#db_li input').prop('checked',ch);
|
||||
});
|
||||
|
||||
$('.psync_migrate').on('click', '.okBtn', function(){
|
||||
$('.psync_migrate').hide();
|
||||
$('.psync_info').show();
|
||||
selectProgress(1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -104,14 +104,14 @@ rm -r /var/lib/mongodb
|
||||
Install_Linux_Debian()
|
||||
{
|
||||
##################### debian start #####################
|
||||
if [ "$SYS_VERSION_ID" -ge "11" ]; then
|
||||
if [ "$SYS_VERSION_ID" -eq "11" ] && [ "$VERSION" -eq "4.4" ]; then
|
||||
echo "Not yet supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -f /usr/lib/systemd/system/mongod.service ];then
|
||||
echo 'alreay exist!'
|
||||
echo 'alreay install exist!'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log-slave-updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -62,6 +62,7 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log_replica_updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -411,6 +411,7 @@ def my8cmd(version, method):
|
||||
initDreplace(version)
|
||||
# mysql 8.0 and 5.7
|
||||
try:
|
||||
isInited = True
|
||||
if version == '5.7':
|
||||
isInited = initMysql57Data()
|
||||
elif version == '8.0':
|
||||
@@ -483,7 +484,7 @@ def getMyDbPos():
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def setMyDbPos():
|
||||
def setMyDbPos(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['datadir'])
|
||||
if not data[0]:
|
||||
@@ -498,7 +499,7 @@ def setMyDbPos():
|
||||
mw.execShell('mkdir -p ' + t_datadir)
|
||||
|
||||
# mw.execShell('/etc/init.d/mysqld stop')
|
||||
stop()
|
||||
stop(version)
|
||||
mw.execShell('cp -rf ' + s_datadir + '/* ' + t_datadir + '/')
|
||||
mw.execShell('chown -R mysql mysql ' + t_datadir)
|
||||
mw.execShell('chmod -R 755 ' + t_datadir)
|
||||
@@ -512,7 +513,7 @@ def setMyDbPos():
|
||||
|
||||
mycnf = mycnf.replace(s_datadir, t_datadir)
|
||||
mw.writeFile(myfile, mycnf)
|
||||
start()
|
||||
restart(version)
|
||||
|
||||
result = mw.execShell(
|
||||
'ps aux|grep mysqld| grep -v grep|grep -v python')
|
||||
@@ -2473,7 +2474,8 @@ def doFullSyncUser(version=''):
|
||||
|
||||
if not os.path.exists(bak_file):
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p" + apass + " " + sync_db + " > " + bak_file
|
||||
port + " -u" + user + " -p" + apass + \
|
||||
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
@@ -2681,6 +2683,9 @@ def uninstallPreInspection(version):
|
||||
if mw.isDebugMode():
|
||||
return 'ok'
|
||||
|
||||
import plugins_api
|
||||
plugins_api.plugins_api().removeIndex(getPluginName(), version)
|
||||
|
||||
return "请手动删除MySQL[{}]<br/> rm -rf {}".format(version, getServerDir())
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -2733,7 +2738,7 @@ if __name__ == "__main__":
|
||||
elif func == 'my_db_pos':
|
||||
print(getMyDbPos())
|
||||
elif func == 'set_db_pos':
|
||||
print(setMyDbPos())
|
||||
print(setMyDbPos(version))
|
||||
elif func == 'my_port':
|
||||
print(getMyPort())
|
||||
elif func == 'set_my_port':
|
||||
|
||||
@@ -819,7 +819,7 @@ function openPhpmyadmin(name,username,password){
|
||||
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'get_cfg'});
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata.choose != 'mysql-apt'){
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请切换模式.',{icon:2,shade: [0.3, '#000']});
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请修改phpMyAdmin访问切换.',{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1208,7 +1208,7 @@ function myLogs(){
|
||||
<span class="f14 c6 mr20">二进制日志 </span><span class="f14 c6 mr20">' + toSize(rdata.msg) + '</span>\
|
||||
'+line_status+'\
|
||||
<p class="f14 c6 mtb10" style="border-top:#ddd 1px solid; padding:10px 0">错误日志<button class="btn btn-default btn-clear btn-xs" style="float:right;" >清理日志</button></p>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 440px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 438px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(limitCon);
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log-slave-updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -62,6 +62,7 @@ binlog-ignore-db = performance_schema
|
||||
#slave
|
||||
log_replica_updates
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -397,6 +397,7 @@ def my8cmd(version, method):
|
||||
initDreplace(version)
|
||||
# mysql 8.0 and 5.7
|
||||
try:
|
||||
isInited = True
|
||||
if version == '5.7':
|
||||
isInited = initMysql57Data()
|
||||
elif version == '8.0':
|
||||
@@ -469,7 +470,7 @@ def getMyDbPos():
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def setMyDbPos():
|
||||
def setMyDbPos(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['datadir'])
|
||||
if not data[0]:
|
||||
@@ -484,7 +485,7 @@ def setMyDbPos():
|
||||
mw.execShell('mkdir -p ' + t_datadir)
|
||||
|
||||
# mw.execShell('/etc/init.d/mysqld stop')
|
||||
stop()
|
||||
stop(version)
|
||||
mw.execShell('cp -rf ' + s_datadir + '/* ' + t_datadir + '/')
|
||||
mw.execShell('chown -R mysql mysql ' + t_datadir)
|
||||
mw.execShell('chmod -R 755 ' + t_datadir)
|
||||
@@ -498,17 +499,17 @@ def setMyDbPos():
|
||||
|
||||
mycnf = mycnf.replace(s_datadir, t_datadir)
|
||||
mw.writeFile(myfile, mycnf)
|
||||
start()
|
||||
restart(version)
|
||||
|
||||
result = mw.execShell(
|
||||
'ps aux|grep mysqld| grep -v grep|grep -v python')
|
||||
'ps aux|grep "mysql-apt/bin/usr/sbin/mysqld"| grep -v grep|grep -v python')
|
||||
if len(result[0]) > 10:
|
||||
mw.writeFile('data/datadir.pl', t_datadir)
|
||||
return mw.returnJson(True, '存储目录迁移成功!')
|
||||
else:
|
||||
mw.execShell('pkill -9 mysqld')
|
||||
mw.writeFile(myfile, mw.readFile(path + '/etc/my_backup.cnf'))
|
||||
start()
|
||||
start(version)
|
||||
return mw.returnJson(False, '文件迁移失败!')
|
||||
|
||||
|
||||
@@ -2433,7 +2434,8 @@ def doFullSyncUser(version=''):
|
||||
|
||||
if not os.path.exists(bak_file):
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p" + apass + " " + sync_db + " > " + bak_file
|
||||
port + " -u" + user + " -p" + apass + \
|
||||
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
@@ -2638,6 +2640,9 @@ def uninstallPreInspection(version):
|
||||
if mw.isDebugMode():
|
||||
return 'ok'
|
||||
|
||||
import plugins_api
|
||||
plugins_api.plugins_api().removeIndex(getPluginName(), version)
|
||||
|
||||
return "请手动删除MySQL[{}]<br/> rm -rf {}".format(version, getServerDir())
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -2687,7 +2692,7 @@ if __name__ == "__main__":
|
||||
elif func == 'my_db_pos':
|
||||
print(getMyDbPos())
|
||||
elif func == 'set_db_pos':
|
||||
print(setMyDbPos())
|
||||
print(setMyDbPos(version))
|
||||
elif func == 'my_port':
|
||||
print(getMyPort())
|
||||
elif func == 'set_my_port':
|
||||
|
||||
@@ -819,7 +819,7 @@ function openPhpmyadmin(name,username,password){
|
||||
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'get_cfg'});
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata.choose != 'mysql-yum'){
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请切换模式.',{icon:2,shade: [0.3, '#000']});
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请修改phpMyAdmin访问切换.',{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1208,7 +1208,7 @@ function myLogs(){
|
||||
<span class="f14 c6 mr20">二进制日志 </span><span class="f14 c6 mr20">' + toSize(rdata.msg) + '</span>\
|
||||
'+line_status+'\
|
||||
<p class="f14 c6 mtb10" style="border-top:#ddd 1px solid; padding:10px 0">错误日志<button class="btn btn-default btn-clear btn-xs" style="float:right;" >清理日志</button></p>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 440px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 438px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(limitCon);
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ log-slave-updates = 1
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip-slave-start = 1
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -72,6 +72,7 @@ log-slave-updates = 1
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip-slave-start = 1
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -17,6 +17,7 @@ datadir = {$SERVER_APP_PATH}/data
|
||||
log-error = {$SERVER_APP_PATH}/data/error.log
|
||||
server-id = {$SERVER_ID}
|
||||
|
||||
explicit_defaults_for_timestamp=true
|
||||
default_storage_engine = InnoDB
|
||||
|
||||
|
||||
@@ -73,6 +74,7 @@ binlog-ignore-db = performance_schema
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip-slave-start = 1
|
||||
#replicate-do-db
|
||||
slave_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
@@ -94,7 +96,7 @@ innodb_file_per_table = 1
|
||||
innodb_large_prefix = 1
|
||||
|
||||
secure-file-priv={$SERVER_APP_PATH}/tmp
|
||||
|
||||
#secure-file-priv=disabled
|
||||
[mysqldump]
|
||||
quick
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ log_replica_updates = 1
|
||||
# Prevent replication from starting automatically with MySQL
|
||||
#skip_replica_start = 1
|
||||
#replicate-do-db
|
||||
replica_skip_errors=1062
|
||||
replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<p onclick="masterOrSlaveConf($('.plugin_version').attr('version'))">主从配置</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con" style="height: 530px; overflow: auto;"></div>
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+79
-21
@@ -48,19 +48,20 @@ def getInitDFile():
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
t = args[i].split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
|
||||
return tmp
|
||||
|
||||
|
||||
@@ -382,7 +383,7 @@ def initMysql57Data():
|
||||
myconf = serverdir + "/etc/my.cnf"
|
||||
user = pGetDbUser()
|
||||
cmd = 'cd ' + serverdir + ' && ./bin/mysqld --defaults-file=' + myconf + \
|
||||
' --initialize-insecure --explicit_defaults_for_timestamp'
|
||||
' --initialize-insecure --explicit_defaults_for_timestamp --user=mysql'
|
||||
data = mw.execShell(cmd)
|
||||
# print(data)
|
||||
return False
|
||||
@@ -488,14 +489,14 @@ def initMysql8Pwd():
|
||||
|
||||
# 删除冗余账户
|
||||
hostname = mw.execShell('hostname')[0].strip()
|
||||
if hostname != 'localhost':
|
||||
drop_hostname = serverdir + '/bin/mysql --defaults-file=' + \
|
||||
myconf + ' -uroot -p' + pwd + ' -e "drop user \'\'@\'' + hostname + '\'";'
|
||||
mw.execShell(drop_hostname)
|
||||
|
||||
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)
|
||||
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,))
|
||||
|
||||
@@ -842,12 +843,29 @@ def setDbBackup():
|
||||
return data[1]
|
||||
|
||||
scDir = mw.getRunDir() + '/scripts/backup.py'
|
||||
|
||||
cmd = 'python3 ' + scDir + ' database ' + args['name'] + ' 3'
|
||||
os.system(cmd)
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
# 数据库密码处理
|
||||
def myPass(act, root):
|
||||
conf_file = getConf()
|
||||
mw.execShell("sed -i '/user=root/d' {}".format(conf_file))
|
||||
mw.execShell("sed -i '/password=/d' {}".format(conf_file))
|
||||
if act:
|
||||
mycnf = mw.readFile(conf_file)
|
||||
src_dump = "[mysqldump]\n"
|
||||
sub_dump = src_dump + "user=root\npassword=\"{}\"\n".format(root)
|
||||
if not mycnf:
|
||||
return False
|
||||
mycnf = mycnf.replace(src_dump, sub_dump)
|
||||
if len(mycnf) > 100:
|
||||
mw.writeFile(conf_file, mycnf)
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
def importDbExternal():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file', 'name'])
|
||||
@@ -902,11 +920,16 @@ def importDbExternal():
|
||||
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
|
||||
my_cnf = getConf()
|
||||
|
||||
myPass(True, pwd)
|
||||
mysql_cmd = getServerDir() + '/bin/mysql --defaults-file=' + my_cnf + \
|
||||
' -uroot -p\"' + pwd + '\" -f ' + name + ' < ' + import_sql
|
||||
|
||||
# print(mysql_cmd)
|
||||
rdata = mw.execShell(mysql_cmd)
|
||||
myPass(False, pwd)
|
||||
# print(rdata)
|
||||
if ext != 'sql':
|
||||
os.remove(import_sql)
|
||||
|
||||
@@ -2371,6 +2394,25 @@ def initSlaveStatus(version=''):
|
||||
return initSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def makeSyncUsercmd(u, version=''):
|
||||
mode = recognizeDbMode()
|
||||
sql = ''
|
||||
|
||||
ip = u['ip']
|
||||
port = u['port']
|
||||
username = u['user']
|
||||
password = u['pass']
|
||||
if mode == "gtid":
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
username + "', MASTER_PASSWORD='" + \
|
||||
password + "', MASTER_AUTO_POSITION=1"
|
||||
if version == '8.0':
|
||||
sql = "CHANGE REPLICATION SOURCE TO SOURCE_HOST='" + ip + "', SOURCE_PORT=" + port + ", SOURCE_USER='" + \
|
||||
username + "', SOURCE_PASSWORD='" + \
|
||||
password + "', MASTER_AUTO_POSITION=1"
|
||||
return sql
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
@@ -2393,8 +2435,19 @@ def initSlaveStatusSyncUser(version=''):
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
|
||||
t = db.query(u['cmd'])
|
||||
# print(t)
|
||||
if u['cmd'] == '' and local_mode == 'gtid':
|
||||
sql = makeSyncUsercmd(u, version)
|
||||
# print(sql)
|
||||
t = db.query(sql)
|
||||
else:
|
||||
if u['cmd'] == '':
|
||||
return mw.returnJson(False, '经典模式下,必须手写同步命令!')
|
||||
# print(u['cmd'])
|
||||
t = db.query(u['cmd'])
|
||||
isError = isSqlError(t)
|
||||
if isError:
|
||||
return isError
|
||||
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['user'], u['pass']))
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
@@ -2612,8 +2665,10 @@ def doFullSyncUser(version=''):
|
||||
writeDbSyncStatus({'code': 1, 'msg': '远程导出数据...', 'progress': 20})
|
||||
|
||||
if not os.path.exists(bak_file):
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p" + apass + " " + sync_db + " > " + bak_file
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p\"" + apass + \
|
||||
"\" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
# print(dump_sql_data)
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
@@ -2804,6 +2859,9 @@ def uninstallPreInspection(version):
|
||||
if mw.isDebugMode():
|
||||
return 'ok'
|
||||
|
||||
import plugins_api
|
||||
plugins_api.plugins_api().removeIndex(getPluginName(), version)
|
||||
|
||||
return "请手动删除MySQL[{}]<br/> rm -rf {}".format(version, getServerDir())
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -819,7 +819,7 @@ function openPhpmyadmin(name,username,password){
|
||||
data = syncPost('/plugins/run',{'name':'phpmyadmin','func':'get_cfg'});
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata.choose != 'mysql'){
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请切换模式.',{icon:2,shade: [0.3, '#000']});
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请修改phpMyAdmin访问切换.',{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1208,7 +1208,7 @@ function myLogs(){
|
||||
<span class="f14 c6 mr20">二进制日志 </span><span class="f14 c6 mr20">' + toSize(rdata.msg) + '</span>\
|
||||
'+line_status+'\
|
||||
<p class="f14 c6 mtb10" style="border-top:#ddd 1px solid; padding:10px 0">错误日志<button class="btn btn-default btn-clear btn-xs" style="float:right;" >清理日志</button></p>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 440px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
<textarea readonly style="margin: 0px;width: 100%;height: 438px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(limitCon);
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
## 指定共享内存
|
||||
lua_shared_dict healthcheck 10m;
|
||||
@@ -0,0 +1,64 @@
|
||||
location / {
|
||||
proxy_pass http://{$UPSTREAM_NAME};
|
||||
|
||||
client_max_body_size 10m;
|
||||
client_body_buffer_size 128k;
|
||||
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Host $proxy_host;
|
||||
proxy_connect_timeout 90;
|
||||
proxy_send_timeout 90;
|
||||
proxy_read_timeout 90;
|
||||
proxy_buffer_size 4k;
|
||||
proxy_buffers 4 32k;
|
||||
proxy_busy_buffers_size 64k;
|
||||
proxy_temp_file_write_size 64k;
|
||||
}
|
||||
|
||||
|
||||
#location /upstream_status {
|
||||
# allow 127.0.0.1;
|
||||
# deny all;
|
||||
# access_log off;
|
||||
# default_type text/plain;
|
||||
# content_by_lua_block {
|
||||
# local hc = require "resty.upstream.healthcheck"
|
||||
# ngx.say("OpenResty Worker PID: ", ngx.worker.pid())
|
||||
# ngx.print(hc.status_page())
|
||||
# }
|
||||
#}
|
||||
|
||||
location /upstream_status_{$UPSTREAM_NAME} {
|
||||
allow 127.0.0.1;
|
||||
deny all;
|
||||
access_log off;
|
||||
default_type text/plain;
|
||||
content_by_lua_block {
|
||||
local json = require "cjson"
|
||||
local ok, upstream = pcall(require, "ngx.upstream")
|
||||
if not ok then
|
||||
ngx.print("[]")
|
||||
return
|
||||
end
|
||||
|
||||
local get_primary_peers = upstream.get_primary_peers
|
||||
local get_backup_peers = upstream.get_backup_peers
|
||||
local upstream_name = "{$UPSTREAM_NAME}"
|
||||
|
||||
peers, err = get_primary_peers(upstream_name)
|
||||
if not peers then
|
||||
ngx.print("[]")
|
||||
return
|
||||
end
|
||||
|
||||
peers_backup, err = get_backup_peers(upstream_name)
|
||||
if peers_backup then
|
||||
for k, v in pairs(peers_backup) do
|
||||
table.insert(peers,v)
|
||||
end
|
||||
end
|
||||
|
||||
ngx.print(json.encode(peers))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
upstream {$UPSTREAM_NAME}
|
||||
{
|
||||
{$NODE_ALGO}
|
||||
{$NODE_SERVER_LIST}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 853 B |
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('op_load_balance');">服务</p>
|
||||
<p onclick="loadBalanceList();">负载均衡</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/plugins/file?name=op_load_balance&f=js/app.js"></script>
|
||||
<script type="text/javascript">
|
||||
resetPluginWinWidth(800);
|
||||
resetPluginWinHeight(300);
|
||||
$.getScript( "/plugins/file?name=op_load_balance&f=js/app.js", function(){
|
||||
pluginService('op_load_balance');
|
||||
});
|
||||
</script>
|
||||
Executable
+474
@@ -0,0 +1,474 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
import re
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'op_load_balance'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
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('}')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
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 getConf():
|
||||
path = getServerDir() + "/cfg.json"
|
||||
|
||||
if not os.path.exists(path):
|
||||
mw.writeFile(path, '[]')
|
||||
|
||||
c = mw.readFile(path)
|
||||
return json.loads(c)
|
||||
|
||||
|
||||
def writeConf(data):
|
||||
path = getServerDir() + "/cfg.json"
|
||||
mw.writeFile(path, json.dumps(data))
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$APP_PATH}', app_path)
|
||||
return content
|
||||
|
||||
|
||||
def restartWeb():
|
||||
mw.opWeb('stop')
|
||||
mw.opWeb('start')
|
||||
|
||||
|
||||
def loadBalanceConf():
|
||||
path = mw.getServerDir() + '/web_conf/nginx/vhost/load_balance.conf'
|
||||
return path
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
dst_conf_tpl = getPluginDir() + '/conf/load_balance.conf'
|
||||
dst_conf = loadBalanceConf()
|
||||
|
||||
if not os.path.exists(dst_conf):
|
||||
con = mw.readFile(dst_conf_tpl)
|
||||
mw.writeFile(dst_conf, con)
|
||||
|
||||
|
||||
def status():
|
||||
if not mw.getWebStatus():
|
||||
return 'stop'
|
||||
|
||||
dst_conf = loadBalanceConf()
|
||||
if not os.path.exists(dst_conf):
|
||||
return 'stop'
|
||||
|
||||
return 'start'
|
||||
|
||||
|
||||
def start():
|
||||
initDreplace()
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def stop():
|
||||
dst_conf = loadBalanceConf()
|
||||
os.remove(dst_conf)
|
||||
|
||||
deleteLoadBalanceAllCfg()
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def restart():
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def reload():
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def installPreInspection():
|
||||
check_op = mw.getServerDir() + "/openresty"
|
||||
if not os.path.exists(check_op):
|
||||
return "请先安装OpenResty"
|
||||
return 'ok'
|
||||
|
||||
|
||||
def deleteLoadBalanceAllCfg():
|
||||
cfg = getConf()
|
||||
upstream_dir = mw.getServerDir() + '/web_conf/nginx/upstream'
|
||||
lua_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
|
||||
rewrite_dir = mw.getServerDir() + '/web_conf/nginx/rewrite'
|
||||
vhost_dir = mw.getServerDir() + '/web_conf/nginx/vhost'
|
||||
|
||||
for conf in cfg:
|
||||
upstream_file = upstream_dir + '/' + conf['upstream_name'] + '.conf'
|
||||
if os.path.exists(upstream_file):
|
||||
os.remove(upstream_file)
|
||||
|
||||
lua_file = lua_dir + '/' + conf['upstream_name'] + '.lua'
|
||||
if os.path.exists(lua_file):
|
||||
os.remove(lua_file)
|
||||
|
||||
rewrite_file = rewrite_dir + '/' + conf['domain'] + '.conf'
|
||||
mw.writeFile(rewrite_file, '')
|
||||
|
||||
path = vhost_dir + '/' + conf['domain'] + '.conf'
|
||||
|
||||
content = mw.readFile(path)
|
||||
content = re.sub('include ' + upstream_file + ';' + "\n", '', content)
|
||||
mw.writeFile(path, content)
|
||||
|
||||
mw.opLuaInitWorkerFile()
|
||||
|
||||
|
||||
def makeConfServerList(data):
|
||||
slist = ''
|
||||
for x in data:
|
||||
slist += 'server '
|
||||
slist += x['ip'] + ':' + x['port']
|
||||
|
||||
if x['state'] == '0':
|
||||
slist += ' down;\n\t'
|
||||
continue
|
||||
|
||||
if x['state'] == '2':
|
||||
slist += ' backup;\n\t'
|
||||
continue
|
||||
|
||||
slist += ' weight=' + x['weight']
|
||||
slist += ' max_fails=' + x['max_fails']
|
||||
slist += ' fail_timeout=' + x['fail_timeout'] + "s;\n\t"
|
||||
return slist
|
||||
|
||||
|
||||
def makeLoadBalanceAllCfg(row):
|
||||
# 生成所有配置
|
||||
cfg = getConf()
|
||||
|
||||
upstream_dir = mw.getServerDir() + '/web_conf/nginx/upstream'
|
||||
rewrite_dir = mw.getServerDir() + '/web_conf/nginx/rewrite'
|
||||
vhost_dir = mw.getServerDir() + '/web_conf/nginx/vhost'
|
||||
upstream_tpl = getPluginDir() + '/conf/upstream.tpl.conf'
|
||||
rewrite_tpl = getPluginDir() + '/conf/rewrite.tpl.conf'
|
||||
|
||||
if not os.path.exists(upstream_dir):
|
||||
os.makedirs(upstream_dir)
|
||||
|
||||
conf = cfg[row]
|
||||
|
||||
# replace vhost start
|
||||
vhost_file = vhost_dir + '/' + conf['domain'] + '.conf'
|
||||
vcontent = mw.readFile(vhost_file)
|
||||
|
||||
vhost_find_str = 'upstream/' + conf['upstream_name'] + '.conf'
|
||||
vhead = 'include ' + mw.getServerDir() + '/web_conf/nginx/' + \
|
||||
vhost_find_str + ';'
|
||||
|
||||
vpos = vcontent.find(vhost_find_str)
|
||||
if vpos < 0:
|
||||
vcontent = vhead + "\n" + vcontent
|
||||
mw.writeFile(vhost_file, vcontent)
|
||||
# replace vhost end
|
||||
|
||||
# make upstream start
|
||||
upstream_file = upstream_dir + '/' + conf['upstream_name'] + '.conf'
|
||||
content = ''
|
||||
if len(conf['node_list']) > 0:
|
||||
content = mw.readFile(upstream_tpl)
|
||||
slist = makeConfServerList(conf['node_list'])
|
||||
content = content.replace('{$NODE_SERVER_LIST}', slist)
|
||||
content = content.replace('{$UPSTREAM_NAME}', conf['upstream_name'])
|
||||
if conf['node_algo'] != 'polling':
|
||||
content = content.replace('{$NODE_ALGO}', conf['node_algo'] + ';')
|
||||
else:
|
||||
content = content.replace('{$NODE_ALGO}', '')
|
||||
mw.writeFile(upstream_file, content)
|
||||
# make upstream end
|
||||
|
||||
# make rewrite start
|
||||
rewrite_file = rewrite_dir + '/' + conf['domain'] + '.conf'
|
||||
rcontent = ''
|
||||
if len(conf['node_list']) > 0:
|
||||
rcontent = mw.readFile(rewrite_tpl)
|
||||
rcontent = rcontent.replace('{$UPSTREAM_NAME}', conf['upstream_name'])
|
||||
mw.writeFile(rewrite_file, rcontent)
|
||||
# make rewrite end
|
||||
|
||||
# health check start
|
||||
lua_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
|
||||
lua_init_worker_file = lua_dir + '/' + conf['upstream_name'] + '.lua'
|
||||
if conf['node_health_check'] == 'ok':
|
||||
lua_dir_tpl = getPluginDir() + '/lua/health_check.lua.tpl'
|
||||
content = mw.readFile(lua_dir_tpl)
|
||||
content = content.replace('{$UPSTREAM_NAME}', conf['upstream_name'])
|
||||
content = content.replace('{$DOMAIN}', conf['domain'])
|
||||
mw.writeFile(lua_init_worker_file, content)
|
||||
else:
|
||||
if os.path.exists(lua_init_worker_file):
|
||||
os.remove(lua_init_worker_file)
|
||||
|
||||
mw.opLuaInitWorkerFile()
|
||||
# health check end
|
||||
return True
|
||||
|
||||
|
||||
def add_load_balance(args):
|
||||
|
||||
data = checkArgs(
|
||||
args, ['domain', 'upstream_name', 'node_algo', 'node_list', 'node_health_check'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
domain_json = args['domain']
|
||||
|
||||
tmp = json.loads(domain_json)
|
||||
domain = tmp['domain']
|
||||
|
||||
cfg = getConf()
|
||||
cfg_len = len(cfg)
|
||||
tmp = {}
|
||||
tmp['domain'] = domain
|
||||
tmp['data'] = args['domain']
|
||||
tmp['upstream_name'] = args['upstream_name']
|
||||
tmp['node_algo'] = args['node_algo']
|
||||
tmp['node_list'] = args['node_list']
|
||||
tmp['node_health_check'] = args['node_health_check']
|
||||
cfg.append(tmp)
|
||||
writeConf(cfg)
|
||||
|
||||
import site_api
|
||||
sobj = site_api.site_api()
|
||||
domain_path = mw.getWwwDir() + '/' + domain
|
||||
|
||||
ps = '负载均衡[' + domain + ']'
|
||||
data = sobj.add(domain_json, '80', ps, domain_path, '00')
|
||||
|
||||
makeLoadBalanceAllCfg(cfg_len)
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(True, '添加成功', data)
|
||||
|
||||
|
||||
def edit_load_balance(args):
|
||||
data = checkArgs(
|
||||
args, ['row', 'node_algo', 'node_list', 'node_health_check'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
row = int(args['row'])
|
||||
|
||||
cfg = getConf()
|
||||
tmp = cfg[row]
|
||||
tmp['node_algo'] = args['node_algo']
|
||||
tmp['node_list'] = args['node_list']
|
||||
tmp['node_health_check'] = args['node_health_check']
|
||||
cfg[row] = tmp
|
||||
writeConf(cfg)
|
||||
|
||||
makeLoadBalanceAllCfg(row)
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(True, '修改成功', data)
|
||||
|
||||
|
||||
def loadBalanceList():
|
||||
cfg = getConf()
|
||||
return mw.returnJson(True, 'ok', cfg)
|
||||
|
||||
|
||||
def loadBalanceDelete():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['row'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
row = int(args['row'])
|
||||
|
||||
cfg = getConf()
|
||||
data = cfg[row]
|
||||
|
||||
import site_api
|
||||
sobj = site_api.site_api()
|
||||
|
||||
sid = mw.M('sites').where('name=?', (data['domain'],)).getField('id')
|
||||
|
||||
if type(sid) == list:
|
||||
del(cfg[row])
|
||||
writeConf(cfg)
|
||||
return mw.returnJson(False, '已经删除了!')
|
||||
|
||||
status = sobj.delete(sid, data['domain'], 1)
|
||||
status_data = json.loads(status)
|
||||
|
||||
if status_data['status']:
|
||||
del(cfg[row])
|
||||
writeConf(cfg)
|
||||
|
||||
upstream_dir = mw.getServerDir() + '/web_conf/nginx/upstream'
|
||||
rewrite_dir = mw.getServerDir() + '/web_conf/nginx/rewrite'
|
||||
|
||||
upstream_file = upstream_dir + '/' + data['upstream_name'] + '.conf'
|
||||
if os.path.exists(upstream_file):
|
||||
os.remove(upstream_file)
|
||||
|
||||
rewrite_file = rewrite_dir + '/' + data['domain'] + '.conf'
|
||||
if os.path.exists(rewrite_file):
|
||||
mw.writeFile(rewrite_file, '')
|
||||
|
||||
return mw.returnJson(status_data['status'], status_data['msg'])
|
||||
|
||||
|
||||
def http_get(url):
|
||||
ret = re.search(r'https://', url)
|
||||
if ret:
|
||||
try:
|
||||
from gevent import monkey
|
||||
monkey.patch_ssl()
|
||||
import requests
|
||||
ret = requests.get(url=str(url), verify=False, timeout=10)
|
||||
status = [200, 301, 302, 404, 403]
|
||||
if ret.status_code in status:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
if sys.version_info[0] == 2:
|
||||
import urllib2
|
||||
rec = urllib2.urlopen(url, timeout=3)
|
||||
else:
|
||||
import urllib.request
|
||||
rec = urllib.request.urlopen(url, timeout=3)
|
||||
status = [200, 301, 302, 404, 403]
|
||||
if rec.getcode() in status:
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def checkUrl():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip', 'port', 'path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
port = args['port']
|
||||
path = args['path']
|
||||
|
||||
if port == '443':
|
||||
url = 'https://' + str(ip) + ':' + str(port) + str(path.strip())
|
||||
else:
|
||||
url = 'http://' + str(ip) + ':' + str(port) + str(path.strip())
|
||||
ret = http_get(url)
|
||||
if not ret:
|
||||
return mw.returnJson(False, '访问节点[%s]失败' % url)
|
||||
return mw.returnJson(True, '访问节点[%s]成功' % url)
|
||||
|
||||
|
||||
def getHealthStatus():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['row'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
row = int(args['row'])
|
||||
|
||||
cfg = getConf()
|
||||
data = cfg[row]
|
||||
|
||||
url = 'http://' + data['domain'] + \
|
||||
'/upstream_status_' + data['upstream_name']
|
||||
|
||||
url_data = mw.httpGet(url)
|
||||
return mw.returnJson(True, 'ok', json.loads(url_data))
|
||||
|
||||
|
||||
def getLogs():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['domain'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
domain = args['domain']
|
||||
logs = mw.getLogsDir() + '/' + domain + '.log'
|
||||
return logs
|
||||
|
||||
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 == 'add_load_balance':
|
||||
print(addLoadBalance())
|
||||
elif func == 'load_balance_list':
|
||||
print(loadBalanceList())
|
||||
elif func == 'load_balance_delete':
|
||||
print(loadBalanceDelete())
|
||||
elif func == 'check_url':
|
||||
print(checkUrl())
|
||||
elif func == 'get_logs':
|
||||
print(getLogs())
|
||||
elif func == 'get_health_status':
|
||||
print(getHealthStatus())
|
||||
else:
|
||||
print('error')
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"title":"OP负载均衡",
|
||||
"tip":"soft",
|
||||
"name":"op_load_balance",
|
||||
"type":"其他插件",
|
||||
"install_pre_inspection":true,
|
||||
"ps":"基于OpenResty的负载均衡",
|
||||
"shell":"install.sh",
|
||||
"checks":"server/op_load_balance",
|
||||
"path":"server/op_load_balance",
|
||||
"author":"midoks",
|
||||
"home":"https://github.com/midoks",
|
||||
"date":"2023-02-02",
|
||||
"pid": "1",
|
||||
"versions": ["1.0"]
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/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
|
||||
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_App(){
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/op_load_balance
|
||||
echo "${version}" > $serverPath/op_load_balance/version.pl
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_load_balance/index.py start
|
||||
echo 'install ok' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_App(){
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_load_balance/index.py stop
|
||||
rm -rf $serverPath/op_load_balance
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
@@ -0,0 +1,606 @@
|
||||
function ooPost(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:'op_load_balance', 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 ooAsyncPost(method,args){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
return syncPost('/plugins/run', {name:'op_load_balance', func:method, args:_args});
|
||||
}
|
||||
|
||||
function ooPostCallbak(method, args, callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var req_data = {};
|
||||
req_data['name'] = 'op_load_balance';
|
||||
req_data['func'] = method;
|
||||
args['version'] = '1.0';
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
req_data['args'] = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/callback', req_data, 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 addNode(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['450px','580px'],
|
||||
title: '添加节点',
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
btn:['提交','关闭'],
|
||||
content: "<form class='bt-form pd20'>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>IP地址</span>\
|
||||
<div class='info-r'>\
|
||||
<input name='ip' class='bt-input-text mr5' placeholder='负载名称,可以是英文字母和下划线,不能使用中文' type='text' style='width:250px' value='127.0.0.1'>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>端口</span>\
|
||||
<div class='info-r'>\
|
||||
<input name='port' class='bt-input-text mr5' type='text' style='width:250px' value='80'>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>验证文件路径</span>\
|
||||
<div class='info-r'>\
|
||||
<input name='path' class='bt-input-text mr5' type='text' style='width:250px' value='/'>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>节点状态</span>\
|
||||
<div class='info-r'>\
|
||||
<select name='state'>\
|
||||
<option value='1'>参与者</option>\
|
||||
<option value='2'>备份</option>\
|
||||
<option value='0'>停用</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>权重</span>\
|
||||
<div class='info-r'>\
|
||||
<input name='weight' class='bt-input-text mr5' type='text' style='width:250px' value='1'>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>阈值</span>\
|
||||
<div class='info-r'>\
|
||||
<input name='max_fails' class='bt-input-text mr5' type='text' style='width:250px' value='2'>次\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>恢复时间</span>\
|
||||
<div class='info-r'>\
|
||||
<input name='fail_timeout' class='bt-input-text mr5' type='text' style='width:250px' value='10'>秒\
|
||||
</div>\
|
||||
</div>\
|
||||
<ul style='margin-left:10px' class='help-info-text c7'>\
|
||||
<li>备份状态: 指当其它节点都无法使用时才会使用此节点</li>\
|
||||
<li>参与状态: 正常参与负载均衡,请至少添加1个普通节点</li>\
|
||||
<li>验证文件路径: 用于检查文件路径地址是否可用</li>\
|
||||
<li>IP地址: 仅支持IP地址,否则无法正常参与负载均衡</li>\
|
||||
<li>阈值: 在恢复时间的时间段内,如果OpenResty与节点通信尝试失败的次数达到此值,OpenResty就认为服务器不可用</li>\
|
||||
</ul>\
|
||||
</form>",
|
||||
success:function(){
|
||||
},
|
||||
yes:function(index) {
|
||||
|
||||
var ip = $('input[name="ip"]').val();
|
||||
var port = $('input[name="port"]').val();
|
||||
var path = $('input[name="path"]').val();
|
||||
var state = $('select[name="state"]').val();
|
||||
var weight = $('input[name="weight"]').val();
|
||||
var max_fails = $('input[name="max_fails"]').val();
|
||||
var fail_timeout = $('input[name="fail_timeout"]').val();
|
||||
|
||||
ooPost('check_url', {ip:ip,port:port,path:path},function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg, function(){
|
||||
if (rdata.status){
|
||||
layer.close(index);
|
||||
$('#nodecon .nulltr').hide();
|
||||
|
||||
var tbody = '<tr>';
|
||||
tbody +='<td>'+ip+'</td>';
|
||||
tbody +='<td>'+port+'</td>';
|
||||
tbody +='<td>'+path+'</td>';
|
||||
|
||||
tbody +="<td><select name='state'>";
|
||||
var state_option_list = {
|
||||
'1':'参与者',
|
||||
'2':'备份',
|
||||
'0':'停用',
|
||||
}
|
||||
for (i in state_option_list) {
|
||||
if (i == state){
|
||||
tbody +="<option value='"+i+"' selected>"+state_option_list[i]+"</option>";
|
||||
} else{
|
||||
tbody +="<option value='"+i+"'>"+state_option_list[i]+"</option>";
|
||||
}
|
||||
}
|
||||
tbody +="</select></td>";
|
||||
|
||||
tbody +='<td><input type="number" name="weight" value="'+weight+'" style="width:50px"></td>';
|
||||
tbody +='<td><input type="number" name="max_fails" value="'+max_fails+'" style="width:50px"></td>';
|
||||
tbody +='<td><input type="number" name="fail_timeout" value="'+fail_timeout+'" style="width:50px"></td>';
|
||||
tbody +='<td class="text-right" width="50"><a class="btlink minus delete">删除</a></td>';
|
||||
tbody += '</tr>';
|
||||
$('#nodecon').append(tbody);
|
||||
|
||||
$('#nodecon .delete').click(function(){
|
||||
$(this).parent().parent().remove();
|
||||
if ($('#nodecon tr').length == 1 ){
|
||||
$('#nodecon .nulltr').show();
|
||||
}
|
||||
});
|
||||
}
|
||||
},{ icon: rdata.status ? 1 : 2 }, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addBalance(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['750px','460px'],
|
||||
title: '创建负载',
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
btn:['提交','关闭'],
|
||||
content: "<form class='bt-form pd20'>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>域名</span>\
|
||||
<div class='info-r'><textarea name='load_domain' class='bt-input-text mr5' placeholder='' style='width:95%;resize: none;height:90px;line-height:20px;'></textarea></div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>负载名称</span>\
|
||||
<div class='info-r'>\
|
||||
<input name='upstream_name' class='bt-input-text mr5' placeholder='负载名称,可以是英文字母和下划线,不能使用中文' type='text' style='width:95%' value=''>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>节点调度</span>\
|
||||
<div class='info-r'>\
|
||||
<select name='node_algo'>\
|
||||
<option value='polling'>轮询[默认]</option>\
|
||||
<option value='ip_hash'>ip_hash</option>\
|
||||
<option value='fair'>fair</option>\
|
||||
<option value='url_hash'>url_hash</option>\
|
||||
<option value='least_conn'>least_conn</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>节点健康检查</span>\
|
||||
<div class='info-r'>\
|
||||
<input type='checkbox' name='node_health_check' checked>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>节点</span>\
|
||||
<div class='info-r'>\
|
||||
<div class='table-con divtable' style='max-height:120px;overflow:auto; margin-bottom:8px;width:95%'>\
|
||||
<table class='table table-hover' id='fixTable3'>\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th width='120'>IP地址</th>\
|
||||
<th width='60'>端口</th>\
|
||||
<th width='120'>验证路径</th>\
|
||||
<th width='60'>状态</th>\
|
||||
<th width='60'>权重</th>\
|
||||
<th width='60'>阀值</th>\
|
||||
<th width='120'>恢复时间</th>\
|
||||
<th width='80' class='text-right'>操作</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id='nodecon'>\
|
||||
<tr class='nulltr'>\
|
||||
<td colspan='8' align='center'>当前节点为空,请至少添加一个普通节点</td>\
|
||||
</tr>\
|
||||
</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
<span class='btn btn-success btn-sm add_node' style='vertical-align:0'>添加节点</span>\
|
||||
</div>\
|
||||
</div>\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="load_domain"]').attr('placeholder','每行填写一个域名,默认为80端口。\n泛解析添加方法 *.domain.com\n如另加端口格式为 www.domain.com:88');
|
||||
var rval = getRandomString(6);
|
||||
$('input[name="upstream_name"]').val('load_balance_'+rval);
|
||||
|
||||
$('.add_node').click(function(){
|
||||
addNode();
|
||||
});
|
||||
},
|
||||
yes:function(index) {
|
||||
var data = {};
|
||||
|
||||
var upstream_name = $('input[name="upstream_name"]').val();
|
||||
if (upstream_name == ''){
|
||||
layer.msg('负载名称不能为空!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
var domain = $('textarea[name="load_domain"]').val().replace('http://','').replace('https://','').split("\n");
|
||||
if (domain[0] == ''){
|
||||
layer.msg('域名不能为空!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
var domainlist = '';
|
||||
for(var i=1; i<domain.length; i++){
|
||||
domainlist += '"'+domain[i]+'",';
|
||||
}
|
||||
domain ='{"domain":"'+domain[0]+'","domainlist":['+domainlist+'],"count":'+domain.length+'}';//拼接json
|
||||
data['domain'] = domain;
|
||||
data['upstream_name'] = upstream_name;
|
||||
|
||||
data['node_algo'] = $('select[name="node_algo"]').val();
|
||||
|
||||
data['node_health_check'] = 'fail';
|
||||
if ($('input[name="node_health_check"]').prop('checked')){
|
||||
data['node_health_check'] = 'ok';
|
||||
}
|
||||
|
||||
var node_list = [];
|
||||
$('#nodecon tr').each(function(){
|
||||
|
||||
var ip = $(this).find('td').eq(0).text();
|
||||
var port = $(this).find('td').eq(1).text();
|
||||
|
||||
if (port == ''){return;}
|
||||
|
||||
var path = $(this).find('td').eq(2).text();
|
||||
var state = $(this).find('select[name="state"]').val();
|
||||
var weight = $(this).find('input[name="weight"]').val();
|
||||
var max_fails = $(this).find('input[name="max_fails"]').val();
|
||||
var fail_timeout = $(this).find('input[name="fail_timeout"]').val();
|
||||
|
||||
var tmp = {
|
||||
ip:ip,
|
||||
port:port,
|
||||
path:path,
|
||||
state:state,
|
||||
weight:weight,
|
||||
max_fails:max_fails,
|
||||
fail_timeout:fail_timeout,
|
||||
}
|
||||
node_list.push(tmp);
|
||||
});
|
||||
data['node_list'] = node_list;
|
||||
ooPostCallbak('add_load_balance', data, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg, function(){
|
||||
layer.close(index);
|
||||
loadBalanceListRender();
|
||||
},{ icon: rdata.status ? 1 : 2 }, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function editBalance(data, row){
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['750px','400px'],
|
||||
title: '编辑负载',
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
btn:['提交','关闭'],
|
||||
content: "<form class='bt-form pd20'>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>负载名称</span>\
|
||||
<div class='info-r'><input name='upstream_name' class='bt-input-text mr5' type='text' style='width:95%;background: rgb(238, 238, 238);' value='' readonly></div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>节点调度</span>\
|
||||
<div class='info-r'>\
|
||||
<select name='node_algo'>\
|
||||
<option value='polling'>轮询[默认]</option>\
|
||||
<option value='ip_hash'>ip_hash</option>\
|
||||
<option value='fair'>fair</option>\
|
||||
<option value='url_hash'>url_hash</option>\
|
||||
<option value='least_conn'>least_conn</option>\
|
||||
</select>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>节点健康检查</span>\
|
||||
<div class='info-r'>\
|
||||
<input type='checkbox' name='node_health_check'>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>节点</span>\
|
||||
<div class='info-r'>\
|
||||
<div class='table-con divtable' style='max-height:120px;overflow:auto; margin-bottom:8px;width:95%'>\
|
||||
<table class='table table-hover' id='fixTable3'>\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th width='120'>IP地址</th>\
|
||||
<th width='60'>端口</th>\
|
||||
<th width='120'>验证路径</th>\
|
||||
<th width='60'>状态</th>\
|
||||
<th width='60'>权重</th>\
|
||||
<th width='60'>阀值</th>\
|
||||
<th width='120'>恢复时间</th>\
|
||||
<th width='80' class='text-right'>操作</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id='nodecon'>\
|
||||
<tr class='nulltr'>\
|
||||
<td colspan='8' align='center'>当前节点为空,请至少添加一个普通节点</td>\
|
||||
</tr>\
|
||||
</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
<span class='btn btn-success btn-sm add_node' style='vertical-align:0'>添加节点</span>\
|
||||
</div>\
|
||||
</div>\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('input[name="upstream_name"]').val(data['upstream_name']);
|
||||
$('select[name="node_algo"]').val(data['node_algo']);
|
||||
|
||||
$('input[name="node_health_check"]').prop('checked',false);
|
||||
if (data['node_health_check'] == 'ok'){
|
||||
$('input[name="node_health_check"]').prop('checked',true);
|
||||
}
|
||||
|
||||
var node_list = data['node_list'];
|
||||
if (node_list.length>0){
|
||||
$('#nodecon .nulltr').hide();
|
||||
}
|
||||
|
||||
var state_option_list = {
|
||||
'1':'参与者',
|
||||
'2':'备份',
|
||||
'0':'停用',
|
||||
}
|
||||
|
||||
for (var n in node_list) {
|
||||
|
||||
var tbody = '<tr>';
|
||||
tbody +='<td>'+node_list[n]['ip']+'</td>';
|
||||
tbody +='<td>'+node_list[n]['port']+'</td>';
|
||||
tbody +='<td>'+node_list[n]['path']+'</td>';
|
||||
|
||||
tbody +="<td><select name='state'>";
|
||||
|
||||
for (i in state_option_list) {
|
||||
if (i == node_list[n]['state']){
|
||||
tbody +="<option value='"+i+"' selected>"+state_option_list[i]+"</option>";
|
||||
} else{
|
||||
tbody +="<option value='"+i+"'>"+state_option_list[i]+"</option>";
|
||||
}
|
||||
}
|
||||
tbody +="</select></td>";
|
||||
|
||||
tbody +='<td><input type="number" name="weight" value="'+node_list[n]['weight']+'" style="width:50px"></td>';
|
||||
tbody +='<td><input type="number" name="max_fails" value="'+node_list[n]['max_fails']+'" style="width:50px"></td>';
|
||||
tbody +='<td><input type="number" name="fail_timeout" value="'+node_list[n]['fail_timeout']+'" style="width:50px"></td>';
|
||||
tbody +='<td class="text-right" width="50"><a class="btlink minus delete">删除</a></td>';
|
||||
tbody += '</tr>';
|
||||
$('#nodecon').append(tbody);
|
||||
}
|
||||
|
||||
$('#nodecon .delete').click(function(){
|
||||
$(this).parent().parent().remove();
|
||||
if ($('#nodecon tr').length == 1 ){
|
||||
$('#nodecon .nulltr').show();
|
||||
}
|
||||
});
|
||||
|
||||
$('.add_node').click(function(){
|
||||
addNode();
|
||||
});
|
||||
},
|
||||
yes:function(index) {
|
||||
var data = {};
|
||||
|
||||
data['node_algo'] = $('select[name="node_algo"]').val();
|
||||
data['node_health_check'] = 'fail';
|
||||
if ($('input[name="node_health_check"]').prop('checked')){
|
||||
data['node_health_check'] = 'ok';
|
||||
}
|
||||
|
||||
var node_list = [];
|
||||
$('#nodecon tr').each(function(){
|
||||
|
||||
var ip = $(this).find('td').eq(0).text();
|
||||
var port = $(this).find('td').eq(1).text();
|
||||
|
||||
if (port == ''){return;}
|
||||
|
||||
var path = $(this).find('td').eq(2).text();
|
||||
var state = $(this).find('select[name="state"]').val();
|
||||
var weight = $(this).find('input[name="weight"]').val();
|
||||
var max_fails = $(this).find('input[name="max_fails"]').val();
|
||||
var fail_timeout = $(this).find('input[name="fail_timeout"]').val();
|
||||
|
||||
var tmp = {
|
||||
ip:ip,
|
||||
port:port,
|
||||
path:path,
|
||||
state:state,
|
||||
weight:weight,
|
||||
max_fails:max_fails,
|
||||
fail_timeout:fail_timeout,
|
||||
}
|
||||
node_list.push(tmp);
|
||||
});
|
||||
data['node_list'] = node_list;
|
||||
data['row'] = row;
|
||||
ooPostCallbak('edit_load_balance', data, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg, function(){
|
||||
layer.close(index);
|
||||
loadBalanceListRender();
|
||||
},{ icon: rdata.status ? 1 : 2 }, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadBalanceListRender(){
|
||||
ooPost('load_balance_list', {}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var alist = rdata.data;
|
||||
|
||||
var tbody = '';
|
||||
for (var i = 0; i < alist.length; i++) {
|
||||
tbody += '<tr>';
|
||||
tbody += '<td>'+alist[i]['domain']+'</td>';
|
||||
tbody += '<td>'+alist[i]['upstream_name']+'</td>';
|
||||
tbody += '<td>'+alist[i]['node_list'].length+'</td>';
|
||||
tbody += '<td><a class="btlink log_look" data-row="'+i+'">查看</a></td>';
|
||||
tbody += '<td><a class="btlink health_status" data-row="'+i+'">查看</a></td>';
|
||||
tbody += '<td style="text-align: right;"><a class="btlink edit" data-row="'+i+'">修改</a> | <a class="btlink delete" data-row="'+i+'">删除</a></td>';
|
||||
tbody += '</tr>';
|
||||
}
|
||||
|
||||
$('#nodeTable').html(tbody);
|
||||
$('.nodeTablePage .Pcount').text('共'+alist.length+'条');
|
||||
$('#nodeTable .edit').click(function(){
|
||||
var row = $(this).data('row');
|
||||
editBalance(alist[row],row);
|
||||
});
|
||||
|
||||
$('#nodeTable .log_look').click(function(){
|
||||
var row = $(this).data('row');
|
||||
var args = {'domain':alist[row]['domain']};
|
||||
pluginRollingLogs('op_load_balance','','get_logs',JSON.stringify(args),20);
|
||||
});
|
||||
|
||||
$('#nodeTable .health_status').click(function(){
|
||||
var row = $(this).data('row');
|
||||
ooPost('get_health_status', {row:row}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
var tval = '';
|
||||
for (var i = 0; i < rdata.data.length; i++) {
|
||||
tval += '<tr>';
|
||||
tval += '<td>'+rdata.data[i]['name']+'</td>';
|
||||
|
||||
if (typeof(rdata.data[i]['down']) != 'undefined' && rdata.data[i]['down']){
|
||||
tval += '<td><span style="color:red;">不正常</span></td>';
|
||||
} else{
|
||||
tval += '<td><span class="btlink">正常</span></td>';
|
||||
}
|
||||
tval += '</tr>';
|
||||
}
|
||||
|
||||
var tbody = "<div class='bt-form pd20'>\
|
||||
<div>\
|
||||
<div id='gitea_table' class='divtable' style='margin-top:5px;'>\
|
||||
<table class='table table-hover'>\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th width='120'>地址</th>\
|
||||
<th width='60'>状态</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody>"+tval+"</tbody>\
|
||||
</table>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>";
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['500px','300px'],
|
||||
title: '节点状态',
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
btn:['提交','关闭'],
|
||||
content:tbody,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#nodeTable .delete').click(function(){
|
||||
var row = $(this).data('row');
|
||||
ooPost('load_balance_delete', {row:row}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg, function(){
|
||||
loadBalanceListRender();
|
||||
},{ icon: rdata.status ? 1 : 2 }, 2000);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function loadBalanceList() {
|
||||
var body = '<div class="bt-box active" style="display: block;">\
|
||||
<div class="mb10">\
|
||||
<button class="btn btn-success btn-sm" data-index="0" onclick="addBalance()">添加负载</button>\
|
||||
<div class="divtable mt10">\
|
||||
<table class="table table-hover">\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th>网站</th>\
|
||||
<th>负载名称</th>\
|
||||
<th>节点</th>\
|
||||
<th>日志</th>\
|
||||
<th>状态</th>\
|
||||
<th width="100" style="text-align: right;">操作</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id="nodeTable"></tbody>\
|
||||
</table>\
|
||||
<div class="nodeTablePage page" data-type="nodePage">\
|
||||
<div><span class="Pcount">共0条</span></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(body);
|
||||
loadBalanceListRender();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
local hc = require "resty.upstream.healthcheck"
|
||||
local ok, err = hc.spawn_checker {
|
||||
shm = "healthcheck",
|
||||
type = "http",
|
||||
upstream = "{$UPSTREAM_NAME}",
|
||||
http_req = "GET / HTTP/1.0\r\nHost: {$UPSTREAM_NAME}\r\n\r\n",
|
||||
interval = 2000,
|
||||
timeout = 6000,
|
||||
fall = 3,
|
||||
rise = 2,
|
||||
valid_statuses = {200, 302},
|
||||
concurrency = 20,
|
||||
}
|
||||
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "=======> load balance health checker error: ", err)
|
||||
return
|
||||
end
|
||||
@@ -1,10 +1,3 @@
|
||||
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;
|
||||
lua_shared_dict waf_drop_sum 10m;
|
||||
+131
-64
@@ -6,6 +6,7 @@ import os
|
||||
import time
|
||||
import subprocess
|
||||
import json
|
||||
import re
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
@@ -224,21 +225,13 @@ def initTotalInfo():
|
||||
_name[name] = tmp
|
||||
total_contents['sites'] = _name
|
||||
|
||||
total_contents['start_time'] = str(time.time())
|
||||
cjson = mw.getJson(total_contents)
|
||||
mw.writeFile(path_total, cjson)
|
||||
|
||||
|
||||
def status():
|
||||
path = getConf()
|
||||
if not os.path.exists(path):
|
||||
return 'stop'
|
||||
|
||||
conf = mw.readFile(path)
|
||||
if conf.find("#include luawaf.conf;") != -1:
|
||||
return 'stop'
|
||||
if conf.find("luawaf.conf;") == -1:
|
||||
return 'stop'
|
||||
return 'start'
|
||||
def dstWafConf():
|
||||
return mw.getServerDir() + "/web_conf/nginx/vhost/opwaf.conf"
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
@@ -328,11 +321,45 @@ def autoMakeConfig():
|
||||
|
||||
def restartWeb():
|
||||
autoMakeConfig()
|
||||
mw.restartWeb()
|
||||
mw.opWeb('stop')
|
||||
mw.opWeb('start')
|
||||
|
||||
|
||||
def makeDstLua():
|
||||
root_init_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_by_lua_file'
|
||||
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
|
||||
root_access_dir = mw.getServerDir() + '/web_conf/nginx/lua/access_by_lua_file'
|
||||
path = getServerDir()
|
||||
path_tpl = getPluginDir()
|
||||
|
||||
waf_common_tpl = path_tpl + "/waf/lua/waf_common.lua"
|
||||
waf_common_dst = path + "/waf/lua/waf_common.lua"
|
||||
content = mw.readFile(waf_common_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_common_dst, content)
|
||||
|
||||
waf_init_tpl = path_tpl + "/waf/lua/init_preload.lua"
|
||||
waf_init_dst = root_init_dir + "/waf_init_preload.lua"
|
||||
content = mw.readFile(waf_init_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_init_dst, content)
|
||||
|
||||
init_worker_tpl = path_tpl + "/waf/lua/init_worker.lua"
|
||||
init_worker_dst = root_worker_dir + '/opwaf_init_worker.lua'
|
||||
content = mw.readFile(init_worker_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(init_worker_dst, content)
|
||||
|
||||
access_file_tpl = path_tpl + "/waf/lua/init.lua"
|
||||
access_file_dst = root_access_dir + '/opwaf_init.lua'
|
||||
content = mw.readFile(access_file_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(access_file_dst, content)
|
||||
|
||||
mw.opLuaMakeAll()
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
path = getServerDir()
|
||||
if not os.path.exists(path + '/waf/lua'):
|
||||
sdir = getPluginDir() + '/waf'
|
||||
@@ -355,26 +382,14 @@ def initDreplace():
|
||||
content['reqfile_path'] = wfDir
|
||||
mw.writeFile(config, mw.getJson(content))
|
||||
|
||||
config = path + "/waf/lua/init.lua"
|
||||
content = mw.readFile(config)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(config, content)
|
||||
makeDstLua()
|
||||
|
||||
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)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_conf, content)
|
||||
waf_conf = dstWafConf()
|
||||
if not os.path.exists(waf_conf):
|
||||
waf_tpl = getPluginDir() + "/conf/luawaf.conf"
|
||||
content = mw.readFile(waf_tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(waf_conf, content)
|
||||
|
||||
initDomainInfo()
|
||||
initSiteInfo()
|
||||
@@ -388,56 +403,73 @@ def initDreplace():
|
||||
mw.execShell("chown -R www:www " + path)
|
||||
|
||||
|
||||
def status():
|
||||
path = getConf()
|
||||
if not os.path.exists(path):
|
||||
return 'stop'
|
||||
|
||||
waf_conf = dstWafConf()
|
||||
if not os.path.exists(waf_conf):
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def start():
|
||||
initDreplace()
|
||||
|
||||
path = getConf()
|
||||
conf = mw.readFile(path)
|
||||
conf = conf.replace('#include luawaf.conf;', "include luawaf.conf;")
|
||||
mw.writeFile(path, conf)
|
||||
|
||||
import tool_task
|
||||
tool_task.createBgTask()
|
||||
|
||||
mw.restartWeb()
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def stop():
|
||||
path = getConf()
|
||||
conf = mw.readFile(path)
|
||||
conf = conf.replace('include luawaf.conf;', "#include luawaf.conf;")
|
||||
root_init_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_by_lua_file'
|
||||
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
|
||||
root_access_dir = mw.getServerDir() + '/web_conf/nginx/lua/access_by_lua_file'
|
||||
|
||||
mw.writeFile(path, conf)
|
||||
waf_init_dst = root_init_dir + "/waf_init_preload.lua"
|
||||
if os.path.exists(waf_init_dst):
|
||||
os.remove(waf_init_dst)
|
||||
|
||||
init_worker_dst = root_worker_dir + '/opwaf_init_worker.lua'
|
||||
if os.path.exists(init_worker_dst):
|
||||
os.remove(init_worker_dst)
|
||||
|
||||
access_file_dst = root_access_dir + '/opwaf_init.lua'
|
||||
if os.path.exists(access_file_dst):
|
||||
os.remove(access_file_dst)
|
||||
|
||||
wafconf = dstWafConf()
|
||||
if os.path.exists(wafconf):
|
||||
os.remove(wafconf)
|
||||
|
||||
import tool_task
|
||||
tool_task.removeBgTask()
|
||||
|
||||
mw.restartWeb()
|
||||
mw.opLuaMakeAll()
|
||||
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def restart():
|
||||
mw.restartWeb()
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def reload():
|
||||
stop()
|
||||
|
||||
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)
|
||||
makeDstLua()
|
||||
|
||||
errlog = mw.getServerDir() + "/openresty/nginx/logs/error.log"
|
||||
mw.execShell('rm -rf ' + errlog)
|
||||
|
||||
start()
|
||||
|
||||
restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -1022,24 +1054,41 @@ def removeSiteCdnHeader():
|
||||
|
||||
def outputData():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['s_Name'])
|
||||
data = checkArgs(args, ['sname'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
path = getRuleJsonPath(args['s_Name'])
|
||||
path = getRuleJsonPath(args['sname'])
|
||||
content = mw.readFile(path)
|
||||
return mw.returnJson(True, 'ok', content)
|
||||
|
||||
|
||||
def importData():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['s_Name', 'pdata'])
|
||||
data = checkArgs(args, ['sname', 'pdata'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
path = getRuleJsonPath(args['s_Name'])
|
||||
mw.writeFile(path, args['pdata'])
|
||||
restartWeb()
|
||||
path = getRuleJsonPath(args['sname'])
|
||||
|
||||
source_data = mw.readFile(path)
|
||||
source_data = json.loads(source_data)
|
||||
|
||||
save_data = []
|
||||
save_data.append(source_data[0])
|
||||
pdata = args['pdata'].strip()
|
||||
try:
|
||||
pdata = json.loads(pdata)
|
||||
mw.writeFile(path, json.dumps(pdata))
|
||||
except Exception as e:
|
||||
pdata = pdata.split("\\n")
|
||||
for x in pdata:
|
||||
pval = x.strip()
|
||||
if pval != "":
|
||||
vv = json.loads(pval)
|
||||
save_data.append(vv[0])
|
||||
mw.writeFile(path, json.dumps(save_data))
|
||||
# restartWeb()
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
@@ -1167,6 +1216,28 @@ def getWafConf():
|
||||
return mw.readFile(conf)
|
||||
|
||||
|
||||
def cleanDropIp():
|
||||
url = "http://127.0.0.1/clean_waf_drop_ip"
|
||||
data = mw.httpGet(url)
|
||||
return mw.returnJson(True, 'ok!', data)
|
||||
|
||||
|
||||
def testRun():
|
||||
# args = getArgs()
|
||||
# data = checkArgs(args, ['siteName'])
|
||||
# if not data[0]:
|
||||
# return data[1]
|
||||
|
||||
conf_json = getServerDir() + "/waf/default.json"
|
||||
data = mw.readFile(conf_json)
|
||||
pdata = json.loads(data)
|
||||
default_site = pdata['default']
|
||||
|
||||
url = "http://" + default_site + '/?t=../etc/passwd'
|
||||
returnData = mw.httpGet(url, 10)
|
||||
return mw.returnJson(True, '测试运行成功!', returnData)
|
||||
|
||||
|
||||
def installPreInspection():
|
||||
check_op = mw.getServerDir() + "/openresty"
|
||||
if not os.path.exists(check_op):
|
||||
@@ -1174,12 +1245,6 @@ 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':
|
||||
@@ -1268,5 +1333,7 @@ if __name__ == "__main__":
|
||||
print(getWafSite())
|
||||
elif func == 'clean_drop_ip':
|
||||
print(cleanDropIp())
|
||||
elif func == 'test_run':
|
||||
print(testRun())
|
||||
else:
|
||||
print('error')
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
{
|
||||
"hook":[
|
||||
{
|
||||
"tag":"site_cb",
|
||||
"site_cb": {
|
||||
"title":"网站统计",
|
||||
"name":"op_waf",
|
||||
"add":{"func":"reload"},
|
||||
"update":{"func":"reload"},
|
||||
"delete":{"func":"reload"}
|
||||
}
|
||||
}
|
||||
],
|
||||
"title":"OP防火墙",
|
||||
"tip":"soft",
|
||||
"name":"op_waf",
|
||||
@@ -12,5 +24,5 @@
|
||||
"home":"https://github.com/loveshell/ngx_lua_waf",
|
||||
"date":"2019-04-21",
|
||||
"pid": "1",
|
||||
"versions": ["0.2.3"]
|
||||
"versions": ["0.2.6"]
|
||||
}
|
||||
@@ -24,7 +24,7 @@ else
|
||||
fi
|
||||
|
||||
|
||||
Install_of(){
|
||||
Install_App(){
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/source/op_waf
|
||||
@@ -41,7 +41,9 @@ Install_of(){
|
||||
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
|
||||
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
|
||||
@@ -85,13 +87,10 @@ Install_of(){
|
||||
echo 'install ok' > $install_tmp
|
||||
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py start
|
||||
|
||||
|
||||
|
||||
# cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py restart
|
||||
}
|
||||
|
||||
Uninstall_of(){
|
||||
Uninstall_App(){
|
||||
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py stop
|
||||
if [ "$?" == "0" ];then
|
||||
@@ -102,7 +101,7 @@ Uninstall_of(){
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_of
|
||||
Install_App
|
||||
else
|
||||
Uninstall_of
|
||||
Uninstall_App
|
||||
fi
|
||||
|
||||
+44
-22
@@ -568,14 +568,14 @@ function outputLayer(rdata, name, type) {
|
||||
'<div class="ml0" style="position:relative;" id="focus_tips">' +
|
||||
'<textarea class="bt-input-text mr20 config" name="config" style="width: 300px; height: 250px; line-height: 22px; display: none;" id="lead_data">' + (rdata != '' ? JSON.stringify(rdata) : '') + '</textarea>' +
|
||||
'<div class="placeholder c9" style="top: 15px; left: 15px; display:' + (rdata == "" ? "block;" : "none;") + '">导入格式如下:' +
|
||||
(name == 'ip_white' || name == 'ip_black' ? "[[[127, 0, 0, 1],[127, 0, 0, 255]]]" : "[\"^/test\",\"^/web\"]") +
|
||||
(name == 'ip_white' || name == 'ip_black' ? "[[[127, 0, 0, 1],[127, 0, 0, 255]],[[192, 0, 0, 1],[192, 0, 0, 255]]]" : "[\"^/test\",\"^/web\"]") +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="line "><div class="ml0">' +
|
||||
(type ? '<button name="btn_save_to" class="btn btn-success btn-sm mr5 btn_save_to" >导出配置</button>' : '<button name="btn_save" class="btn btn-success btn-sm mr5 btn_save">保存</button>') +
|
||||
'</div></div>' +
|
||||
'</div>'
|
||||
'</div>',
|
||||
});
|
||||
var lead_error = CodeMirror.fromTextArea(document.getElementById("lead_data"), {
|
||||
mode: 'html',
|
||||
@@ -585,7 +585,10 @@ function outputLayer(rdata, name, type) {
|
||||
});
|
||||
setTimeout(function () {
|
||||
$('.btn_save').on('click', function () {
|
||||
importData(name, lead_error.getValue());
|
||||
importData(name, lead_error.getValue(), function(){
|
||||
layer.close(window.Load_layer);
|
||||
ipWhiteLoadList();
|
||||
});
|
||||
})
|
||||
$('.btn_save_to').on('click', function () {
|
||||
funDownload(lead_error.getValue(), name + '.json');
|
||||
@@ -601,7 +604,7 @@ function outputLayer(rdata, name, type) {
|
||||
function outputData(name, callback) {
|
||||
var loadT = layer.msg('正在导出数据..', { icon: 16, time: 0 });
|
||||
|
||||
owPost('output_data', { s_Name: name } , function(data){
|
||||
owPost('output_data', { sname: name } , function(data){
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = $.parseJSON(tmp.data);
|
||||
if (callback) callback(rdata,res);
|
||||
@@ -611,7 +614,7 @@ function outputData(name, callback) {
|
||||
|
||||
//导入数据
|
||||
function importData(name, pdata, callback) {
|
||||
owPost('import_data', { s_Name: name, pdata: pdata } , function(data){
|
||||
owPost('import_data', { sname: name, pdata: pdata } , function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (callback) callback();
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
@@ -622,6 +625,22 @@ function fileInput(name) {
|
||||
outputLayer('', name, false);
|
||||
}
|
||||
|
||||
|
||||
function ipWhiteLoadList(){
|
||||
getRuleByName('ip_white', function(data){
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = $.parseJSON(tmp.data);
|
||||
var tbody = ''
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
tbody += '<tr>\
|
||||
<td>'+ rdata[i][0].join('.') + '</td>\
|
||||
<td>'+ rdata[i][1].join('.') + '</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="removeIpWhite('+ i + ')">删除</a></td>\
|
||||
</tr>'
|
||||
}
|
||||
$("#ip_white_con").html(tbody);
|
||||
});
|
||||
}
|
||||
//IP白名单
|
||||
function ipWhite(type) {
|
||||
if (type == undefined) {
|
||||
@@ -675,20 +694,7 @@ function ipWhite(type) {
|
||||
});
|
||||
tableFixed("ipWhite");
|
||||
}
|
||||
|
||||
getRuleByName('ip_white', function(data){
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = $.parseJSON(tmp.data);
|
||||
var tbody = ''
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
tbody += '<tr>\
|
||||
<td>'+ rdata[i][0].join('.') + '</td>\
|
||||
<td>'+ rdata[i][1].join('.') + '</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="removeIpWhite('+ i + ')">删除</a></td>\
|
||||
</tr>'
|
||||
}
|
||||
$("#ip_white_con").html(tbody);
|
||||
});
|
||||
ipWhiteLoadList();
|
||||
}
|
||||
|
||||
//IP白名单
|
||||
@@ -955,8 +961,12 @@ function wafScreen(){
|
||||
owPost('waf_srceen', {}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
|
||||
var end_time = Date.now();
|
||||
var cos_time = (end_time/1000) - parseInt(rdata['start_time']);
|
||||
var cos_day = parseInt(parseInt(cos_time)/86400);
|
||||
|
||||
var con = '<div class="wavbox alert alert-success" style="margin-right:16px">总拦截<span>'+rdata.total+'</span>次</div>';
|
||||
con += '<div class="wavbox alert alert-info" style="margin-right:16px">安全防护<span>0</span>天</div>';
|
||||
con += '<div class="wavbox alert alert-info" style="margin-right:16px">安全防护<span>'+cos_day+'</span>天</div>';
|
||||
|
||||
con += '<div class="screen">\
|
||||
<div class="line"><span class="name">POST渗透</span><span class="val">'+rdata.rules.post+'</span></div>\
|
||||
@@ -1712,9 +1722,12 @@ function wafLogs(){
|
||||
<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>\
|
||||
<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: 155px;"></span>\
|
||||
</div>\
|
||||
<div style="float:right;">\
|
||||
<button id="UncoverAll" class="btn btn-success btn-sm" style="padding-left: 5px;padding-right: 5px;">解封所有</button>\
|
||||
<button id="testRun" class="btn btn-default btn-sm" style="padding-left: 5px;padding-right: 5px;">测试</button>\
|
||||
</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>';
|
||||
@@ -1733,6 +1746,15 @@ function wafLogs(){
|
||||
});
|
||||
});
|
||||
|
||||
//测试demo
|
||||
$("#testRun").click(function(){
|
||||
owPost('test_run',{},function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg, function(){
|
||||
wafLogRequest(1);
|
||||
},{icon:1,shade: [0.3, '#000']},2000);
|
||||
});
|
||||
});
|
||||
|
||||
//日期范围
|
||||
laydate.render({
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
DST_DIR=/www/server/op_waf
|
||||
DIS_FILE=${DST_DIR}/cpu.info
|
||||
|
||||
CPU_USAGE=`top -bn 1 | fgrep 'Cpu(s)' | awk '{print 100 -$8}' | awk -F . '{print $1}'`
|
||||
echo $CPU_USAGE
|
||||
echo $CPU_USAGE > $DIS_FILE
|
||||
echo "done success!"
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
DST_DIR=/www/server/op_waf
|
||||
DIS_FILE=${DST_DIR}/cpu.info
|
||||
|
||||
function GetCpuUsage(){
|
||||
cpu_info=`cat /proc/stat | head -n 1`
|
||||
idle_cpu=`echo $cpu_info|awk '{print $2}'`
|
||||
cpu_total_time=0
|
||||
for ci in ${cpu_info[@]}; do
|
||||
if [ "$ci" == "cpu" ];then
|
||||
continue
|
||||
else
|
||||
#echo $ci
|
||||
cpu_total_time=`expr $cpu_total_time + $ci`
|
||||
fi
|
||||
done
|
||||
#echo "idle_cpu:${idle_cpu}"
|
||||
#echo "cpu_total_time:${cpu_total_time}"
|
||||
|
||||
cpu_percet=$(awk "BEGIN{print ((${cpu_total_time}-${idle_cpu})/${cpu_total_time})*100}")
|
||||
echo "${cpu_percet}"
|
||||
return 0
|
||||
}
|
||||
|
||||
# one value detal
|
||||
getOne=`GetCpuUsage`
|
||||
|
||||
CPU_USAGE=`echo $getOne | awk -F . '{print $1}'`
|
||||
echo "cpu usage:${CPU_USAGE}"
|
||||
echo $CPU_USAGE > $DIS_FILE
|
||||
echo "done success!"
|
||||
|
||||
|
||||
# two value compare
|
||||
|
||||
# getOne=`GetCpuUsage`
|
||||
# echo "getOne:$getOne"
|
||||
# sleep 1
|
||||
# getTwo=`GetCpuUsage`
|
||||
# echo "getTwo:$getTwo"
|
||||
|
||||
# cpu_percet_calc=$(awk "BEGIN{print (${getOne}+${getTwo})/2}")
|
||||
# echo "cpu_percet_calc:${cpu_percet_calc}"
|
||||
|
||||
# #echo '0.61212' | awk -F . '{print $1}'
|
||||
# CPU_USAGE=`echo $cpu_percet_calc | awk -F . '{print $1}'`
|
||||
# echo "cpu usage:${CPU_USAGE}"
|
||||
# echo $CPU_USAGE > $DIS_FILE
|
||||
# echo "done success!"
|
||||
@@ -26,4 +26,5 @@ fi
|
||||
# $RUN_CMD --stap --shdict 'limit 10m' test_find_server_name.lua
|
||||
|
||||
# $RUN_CMD test_rand.lua
|
||||
$RUN_CMD test_ffi_time.lua
|
||||
# $RUN_CMD test_ffi_time.lua
|
||||
$RUN_CMD test_get_cpu.lua
|
||||
@@ -0,0 +1,69 @@
|
||||
-- cd /www/server/mdserver-web/plugins/op_waf/t/bench && bash bench.sh
|
||||
|
||||
local function target()
|
||||
ngx.re.find("hello, world.", [[\w+\.]], "jo")
|
||||
end
|
||||
for i = 1, 100 do
|
||||
target()
|
||||
end
|
||||
|
||||
local function file_exists(path)
|
||||
local file = io.open(path, "rb")
|
||||
if file then file:close() end
|
||||
return file ~= nil
|
||||
end
|
||||
|
||||
-- 以上为预热操作
|
||||
collectgarbage()
|
||||
|
||||
local json = require "cjson"
|
||||
local ngx_re = require "ngx.re"
|
||||
|
||||
local function data_split(self, str,reps )
|
||||
local rsList = {}
|
||||
string.gsub(str,'[^'..reps..']+',function(w)
|
||||
table.insert(rsList,w)
|
||||
end)
|
||||
return rsList
|
||||
end
|
||||
|
||||
local function get_cpu_stat()
|
||||
local cpu_total = 0
|
||||
local fp = io.open('/proc/stat','r')
|
||||
local cpu_line = fp:read()
|
||||
fp:close()
|
||||
|
||||
local list = ngx_re.split(cpu_line," ")
|
||||
table.remove(list,1)
|
||||
table.remove(list,1)
|
||||
|
||||
local idie = list[4]
|
||||
for i,v in pairs(list)
|
||||
do
|
||||
cpu_total = cpu_total + v
|
||||
end
|
||||
|
||||
local use_percent = tonumber(100-(idie/cpu_total)*100)
|
||||
|
||||
return cpu_total,idie,use_percent
|
||||
end
|
||||
|
||||
local function get_cpu_percent()
|
||||
local cpu_total,idie,use_percent = get_cpu_stat()
|
||||
ngx.sleep(2)
|
||||
local cpu_total2,idie2,use_percent2 = get_cpu_stat()
|
||||
local cpu_usage_percent = tonumber(100-(((idie2-idie)/(cpu_total2-cpu_total))*100))
|
||||
ngx.say("cpu_usage_percent:"..cpu_usage_percent)
|
||||
return cpu_usage_percent
|
||||
end
|
||||
|
||||
ngx.update_time()
|
||||
local begin = ngx.now()
|
||||
local N = 1e1
|
||||
for i = 1, N do
|
||||
get_cpu_stat()
|
||||
end
|
||||
ngx.update_time()
|
||||
|
||||
ngx.say("test_get_cpu elapsed: ", (ngx.now() - begin))
|
||||
|
||||
@@ -309,12 +309,12 @@ def test_Upload():
|
||||
|
||||
def test_start():
|
||||
# test_OK()
|
||||
# test_Dir()
|
||||
test_Dir()
|
||||
# test_UA()
|
||||
test_Header()
|
||||
# test_Header()
|
||||
# test_UA_for(1000)
|
||||
test_POST()
|
||||
test_scan()
|
||||
# test_POST()
|
||||
# test_scan()
|
||||
# test_CC()
|
||||
# test_url_ext()
|
||||
# test_cdn()
|
||||
@@ -322,6 +322,7 @@ def test_start():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/op_waf && sh install.sh uninstall 0.2.2 && sh install.sh install 0.2.2')
|
||||
os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/ && python3 plugins/openresty/index.py stop && python3 plugins/openresty/index.py start')
|
||||
# os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/op_waf && sh install.sh uninstall 0.2.2 && sh install.sh install 0.2.2')
|
||||
os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/ && python3 /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/op_waf/index.py reload')
|
||||
# os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/ && python3 plugins/openresty/index.py stop && python3 plugins/openresty/index.py start')
|
||||
test_start()
|
||||
|
||||
@@ -1,6 +1,46 @@
|
||||
#!/bin/sh
|
||||
export PATH=$PATH:/opt/stap/bin:/opt/stapxx
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/op_waf/t && bash ngx_debug.sh lua ok
|
||||
# cd /www/server/mdserver-web/plugins/op_waf/t && bash ngx_debug.sh c ok
|
||||
|
||||
|
||||
if [ ${_os} == "Darwin" ]; then
|
||||
OSNAME='macos'
|
||||
elif grep -Eq "openSUSE" /etc/*-release; then
|
||||
OSNAME='opensuse'
|
||||
zypper refresh
|
||||
zypper install cron wget curl zip unzip
|
||||
elif grep -Eq "FreeBSD" /etc/*-release; then
|
||||
OSNAME='freebsd'
|
||||
elif grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
|
||||
OSNAME='rhel'
|
||||
yum install -y wget curl zip unzip tar crontabs
|
||||
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
|
||||
OSNAME='fedora'
|
||||
yum install -y wget curl zip unzip tar crontabs
|
||||
elif grep -Eqi "Rocky" /etc/issue || grep -Eq "Rocky" /etc/*-release; then
|
||||
OSNAME='rhel'
|
||||
yum install -y wget curl zip unzip tar crontabs
|
||||
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; then
|
||||
OSNAME='rhel'
|
||||
yum install -y wget curl zip unzip tar crontabs
|
||||
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eq "Amazon Linux" /etc/*-release; then
|
||||
OSNAME='amazon'
|
||||
yum install -y wget curl zip unzip tar crontabs
|
||||
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/os-release; then
|
||||
OSNAME='debian'
|
||||
apt update -y
|
||||
apt install -y wget curl zip unzip tar cron
|
||||
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/os-release; then
|
||||
OSNAME='ubuntu'
|
||||
apt update -y
|
||||
apt install -y wget curl zip unzip tar cron
|
||||
else
|
||||
OSNAME='unknow'
|
||||
fi
|
||||
|
||||
|
||||
# https://moonbingbing.gitbooks.io/openresty-best-practices/content/flame_graph/install.html
|
||||
# apt install elfutils
|
||||
# sudo apt-get install -y systemtap gcc
|
||||
@@ -23,7 +63,7 @@ then
|
||||
exit
|
||||
fi
|
||||
|
||||
pid=`ps -ef|grep openresty | grep -v grep | awk '{print $2}'`
|
||||
pids=`ps -ef|grep nginx | grep -v grep | awk '{print $2}'`
|
||||
name=$2
|
||||
|
||||
|
||||
@@ -33,7 +73,13 @@ name=$2
|
||||
# apt install -y kernel-debuginfo-common kernel-debuginfo
|
||||
# apt install -y kernel-*
|
||||
|
||||
|
||||
if [ "$OSNAME" == "debian" ];then
|
||||
apt install -y systemtap
|
||||
apt-get install -y build-essential
|
||||
apt-get install -y linux-headers-$(uname -r)
|
||||
elif [ "$OSNAME" == "centos" ];then
|
||||
yum install -y kernel-devel-$(uname -r)
|
||||
fi
|
||||
|
||||
# /opt/stapxx/samples/lj-lua-stacks.sxx --arg time=5 --skip-badvars -x 45266 > tmp.bt
|
||||
|
||||
@@ -58,25 +104,45 @@ if [ ! -d /opt/FlameGraph ];then
|
||||
cd /opt && git clone https://github.com/brendangregg/FlameGraph
|
||||
fi
|
||||
|
||||
if [ $1 == "lua" ]; then
|
||||
# /opt/openresty-systemtap-toolkit/ngx-sample-lua-bt -p 377452 --luajit20 -t 30 >temp.bt
|
||||
/opt/openresty-systemtap-toolkit/ngx-sample-lua-bt -p $pid --luajit20 -t 30 >temp.bt
|
||||
# /opt/openresty-systemtap-toolkit/fix-lua-bt temp.bt >t1.bt
|
||||
/opt/openresty-systemtap-toolkit/fix-lua-bt temp.bt >${name}.bt
|
||||
elif [ $1 == "c" ]; then
|
||||
# /opt/openresty-systemtap-toolkit/sample-bt -p 496435 -t 10 -u > t2.bt
|
||||
/opt/openresty-systemtap-toolkit/sample-bt -p $pid -t 10 -u > ${name}.bt
|
||||
else
|
||||
echo "type is only lua/c"
|
||||
exit
|
||||
fi
|
||||
for pid in ${pids[@]}; do
|
||||
echo "strace:$pid"
|
||||
if [ $1 == "lua" ]; then
|
||||
# --without-luajit-gc64 | lua 模式编译时需要使用此参数
|
||||
/opt/openresty-systemtap-toolkit/ngx-sample-lua-bt -p $pid --luajit20 -t 30 >temp.bt
|
||||
/opt/openresty-systemtap-toolkit/fix-lua-bt temp.bt >${name}_${pid}.bt
|
||||
elif [ $1 == "c" ]; then
|
||||
/opt/openresty-systemtap-toolkit/sample-bt -p $pid -t 10 -u > ${name}_${pid}.bt
|
||||
else
|
||||
echo "type is only lua/c"
|
||||
exit
|
||||
fi
|
||||
|
||||
/opt/FlameGraph/stackcollapse-stap.pl ${name}_${pid}.bt >${name}_${pid}.cbt
|
||||
/opt/FlameGraph/flamegraph.pl ${name}_${pid}.cbt >${name}_${pid}.svg
|
||||
rm -f temp.bt ${name}_${pid}.bt ${name}_${pid}.cbt
|
||||
echo "strace:$pid, end!"
|
||||
echo "${name}_${pid}.svg -- make ok"
|
||||
done
|
||||
|
||||
# if [ $1 == "lua" ]; then
|
||||
# # /opt/openresty-systemtap-toolkit/ngx-sample-lua-bt -p 377452 --luajit20 -t 30 >temp.bt
|
||||
# /opt/openresty-systemtap-toolkit/ngx-sample-lua-bt -p $pid --luajit20 -t 30 >temp.bt
|
||||
# # /opt/openresty-systemtap-toolkit/fix-lua-bt temp.bt >t1.bt
|
||||
# /opt/openresty-systemtap-toolkit/fix-lua-bt temp.bt >${name}.bt
|
||||
# elif [ $1 == "c" ]; then
|
||||
# # /opt/openresty-systemtap-toolkit/sample-bt -p 496435 -t 10 -u > t2.bt
|
||||
# /opt/openresty-systemtap-toolkit/sample-bt -p $pid -t 10 -u > ${name}.bt
|
||||
# else
|
||||
# echo "type is only lua/c"
|
||||
# exit
|
||||
# fi
|
||||
|
||||
|
||||
# # debuginfo-install kernel-3.10.0-1160.80.1.el7.x86_64
|
||||
# # /opt/FlameGraph/stackcollapse-perf.pl perf.unfold &> perf.folded
|
||||
# # /opt/FlameGraph/flamegraph.pl perf.folded > perf.svg
|
||||
|
||||
# /opt/FlameGraph/stackcollapse-perf.pl perf.unfold &> perf.folded
|
||||
# /opt/FlameGraph/flamegraph.pl perf.folded > perf.svg
|
||||
|
||||
/opt/FlameGraph/stackcollapse-stap.pl ${name}.bt >${name}.cbt
|
||||
/opt/FlameGraph/flamegraph.pl ${name}.cbt >${name}.svg
|
||||
rm -f temp.bt ${name}.bt ${name}.cbt
|
||||
# /opt/FlameGraph/stackcollapse-stap.pl ${name}.bt >${name}.cbt
|
||||
# /opt/FlameGraph/flamegraph.pl ${name}.cbt >${name}.svg
|
||||
# rm -f temp.bt ${name}.bt ${name}.cbt
|
||||
|
||||
|
||||
@@ -54,7 +54,9 @@ def createBgTask():
|
||||
"period": "minute-n",
|
||||
"minute-n": "1",
|
||||
}
|
||||
createBgTaskByName(getPluginName(), args)
|
||||
|
||||
if mw.isAppleSystem():
|
||||
createBgTaskByName(getPluginName(), args)
|
||||
|
||||
|
||||
def createBgTaskByName(name, args):
|
||||
@@ -97,8 +99,14 @@ 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 "cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1"' + "\n"
|
||||
cmd += 'cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1' + "\n"
|
||||
|
||||
if mw.isAppleSystem():
|
||||
cmd += 'echo "cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1"' + "\n"
|
||||
cmd += 'cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1' + "\n"
|
||||
else:
|
||||
cmd += 'echo "cd $mw_dir && source bin/activate && bash $script_path/shell/cpu_usage_file.sh >> $logs_file 2>&1"' + "\n"
|
||||
cmd += 'cd $mw_dir && source bin/activate && bash $script_path/shell/cpu_usage.sh >> $logs_file 2>&1' + "\n"
|
||||
|
||||
cmd += 'echo "【`date +"%Y-%m-%d %H:%M:%S"`】 END★" >> $logs_file' + "\n"
|
||||
cmd += 'echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> $logs_file' + "\n"
|
||||
|
||||
@@ -128,6 +136,9 @@ logs_file=$plugin_path/${rname}.log
|
||||
|
||||
|
||||
def removeBgTask():
|
||||
if not mw.isAppleSystem():
|
||||
return False
|
||||
|
||||
cfg_list = getConfigData()
|
||||
for x in range(len(cfg_list)):
|
||||
cfg = cfg_list[x]
|
||||
@@ -147,10 +158,15 @@ def removeBgTask():
|
||||
|
||||
|
||||
def getCpuUsed():
|
||||
import psutil
|
||||
used = psutil.cpu_percent(interval=1)
|
||||
path = getServerDir() + "/cpu.info"
|
||||
mw.writeFile(path, str(int(used)))
|
||||
if mw.isAppleSystem():
|
||||
import psutil
|
||||
used = psutil.cpu_percent(interval=1)
|
||||
mw.writeFile(path, str(int(used)))
|
||||
else:
|
||||
cmd = "top -bn 1 | fgrep 'Cpu(s)' | awk '{print 100 -$8}' | awk -F . '{print $1}'"
|
||||
data = mw.execShell(cmd)
|
||||
mw.writeFile(path, str(int(data[0].strip())))
|
||||
|
||||
|
||||
def run():
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
local json = require "cjson"
|
||||
local ngx_match = ngx.re.find
|
||||
|
||||
local __WAF = require "common"
|
||||
local __WAF = require "waf_common"
|
||||
|
||||
-- print(json.encode(__C))
|
||||
local C = __WAF:getInstance()
|
||||
@@ -11,11 +11,11 @@ local config = require "waf_config"
|
||||
local site_config = require "waf_site"
|
||||
local config_domains = require "waf_domains"
|
||||
|
||||
-- C:D("config:"..C:to_json(config))
|
||||
|
||||
C:setConfData(config, site_config)
|
||||
C:setDebug(true)
|
||||
|
||||
-- C:D("config:"..C:to_json(config))
|
||||
|
||||
local get_html = require "html_get"
|
||||
local post_html = require "html_post"
|
||||
@@ -36,7 +36,8 @@ local url_rules = require "rule_url"
|
||||
local url_white_rules = require "rule_url_white"
|
||||
|
||||
|
||||
local server_name = string.gsub(C:get_sn(config_domains),'_','.')
|
||||
-- local server_name = string.gsub(C:get_sn(config_domains),'_','.')
|
||||
local server_name = C:get_sn(config_domains)
|
||||
|
||||
local function initParams()
|
||||
local data = {}
|
||||
@@ -246,7 +247,8 @@ local function waf_drop_ip()
|
||||
end
|
||||
|
||||
local function waf_cc()
|
||||
if not config['cc']['open'] or not C:is_site_config('cc') then return false end
|
||||
if not config['cc']['open'] then return false end
|
||||
if not C:is_site_config('cc') then return false end
|
||||
|
||||
local ip = params['ip']
|
||||
|
||||
@@ -342,13 +344,22 @@ local function waf_cc_increase()
|
||||
local make_uri = "/"..make_uri_str
|
||||
|
||||
if params['uri_request_args']['token'] then
|
||||
ngx.header.content_type = "application/json"
|
||||
local args_token = params['uri_request_args']['token']
|
||||
if args_token == make_token then
|
||||
ngx.shared.waf_limit:set(cache_token, 1, config['safe_verify']['time'])
|
||||
ngx.shared.waf_limit:set(cache_token, 1, tonumber(config['safe_verify']['time']))
|
||||
local data = get_return_state(0, "ok")
|
||||
ngx.say(json.encode(data))
|
||||
ngx.exit(200)
|
||||
end
|
||||
|
||||
-- C:D("debug[args]:"..tostring(params['uri_request_args']['debug']))
|
||||
-- if params['uri_request_args']['debug'] == 'ok' then
|
||||
-- ngx.header.content_type = "application/json"
|
||||
-- local data = get_return_state(0, "ok")
|
||||
-- ngx.say(json.encode(data))
|
||||
-- ngx.exit(200)
|
||||
-- end
|
||||
end
|
||||
|
||||
local cc_html = ngx.re.gsub(cc_safe_js_html, "{uri}", make_uri_str)
|
||||
@@ -521,43 +532,58 @@ end
|
||||
|
||||
function waf()
|
||||
min_route()
|
||||
|
||||
-- C:D("min_route")
|
||||
-- white ip
|
||||
if waf_ip_white() then return true end
|
||||
-- C:D("waf_ip_white")
|
||||
|
||||
-- url white
|
||||
if waf_url_white() then return true end
|
||||
-- C:D("waf_url_white")
|
||||
|
||||
-- black ip
|
||||
if waf_ip_black() then return true end
|
||||
-- C:D("waf_ip_black")
|
||||
|
||||
-- 封禁ip返回
|
||||
if waf_drop_ip() then return true end
|
||||
-- C:D("waf_drop_ip")
|
||||
|
||||
-- ua check
|
||||
if waf_user_agent() then return true end
|
||||
-- C:D("waf_user_agent")
|
||||
if waf_url() then return true end
|
||||
-- C:D("waf_url")
|
||||
|
||||
-- cc setting
|
||||
if waf_cc_increase() then return true end
|
||||
-- C:D("waf_cc_increase")
|
||||
if waf_cc() then return true end
|
||||
-- C:D("waf_cc")
|
||||
|
||||
-- cookie检查
|
||||
if waf_cookie() then return true end
|
||||
-- C:D("waf_cookie")
|
||||
|
||||
-- args参数拦截
|
||||
if waf_get_args() then return true end
|
||||
-- C:D("waf_get_args")
|
||||
|
||||
-- 扫描软件禁止
|
||||
if waf_scan_black() then return true end
|
||||
|
||||
-- C:D("waf_scan_black")
|
||||
if waf_post() then return true end
|
||||
|
||||
-- C:D("waf_post")
|
||||
|
||||
if site_config[server_name] and site_config[server_name]['open'] then
|
||||
if X_Forwarded() then return true end
|
||||
-- C:D("X_Forwarded")
|
||||
if post_X_Forwarded() then return true end
|
||||
-- C:D("post_X_Forwarded")
|
||||
if url_ext() then return true end
|
||||
-- C:D("url_ext")
|
||||
if post_data() then return true end
|
||||
-- C:D("post_data")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
local waf_root = "{$WAF_ROOT}"
|
||||
local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;"
|
||||
local waf_sopath = waf_root.."/waf/conf/?.so;"
|
||||
|
||||
if not package.path:find(waf_cpath) then
|
||||
package.path = waf_cpath .. package.path
|
||||
end
|
||||
|
||||
if not package.cpath:find(waf_sopath) then
|
||||
package.cpath = waf_sopath .. package.cpath
|
||||
end
|
||||
@@ -1,31 +1,58 @@
|
||||
local waf_root = "{$WAF_ROOT}"
|
||||
|
||||
-- local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;"
|
||||
-- local waf_sopath = waf_root.."/waf/conf/?.so;"
|
||||
-- if not package.path:find(waf_cpath) then
|
||||
-- package.path = waf_cpath .. package.path
|
||||
-- end
|
||||
|
||||
-- if not package.cpath:find(waf_sopath) then
|
||||
-- package.cpath = waf_sopath .. package.cpath
|
||||
-- end
|
||||
|
||||
local json = require "cjson"
|
||||
|
||||
local waf_root = "{$WAF_ROOT}"
|
||||
local cpath = waf_root.."/waf/"
|
||||
local __WAF_C = require "waf_common"
|
||||
local WAF_C = __WAF_C:getInstance()
|
||||
|
||||
local __C = require "common"
|
||||
local C = __C:getInstance()
|
||||
local waf_config = require "waf_config"
|
||||
local waf_site_config = require "waf_site"
|
||||
WAF_C:setConfData(waf_config, waf_site_config)
|
||||
WAF_C:setDebug(true)
|
||||
|
||||
-- C:D("init worker"..tostring(ngx.worker.id()))
|
||||
|
||||
local function timer_stats_total_log(premature)
|
||||
C:timer_stats_total()
|
||||
local function waf_timer_stats_total_log(premature)
|
||||
WAF_C:timer_stats_total()
|
||||
end
|
||||
|
||||
local waf_clean_expire_data = function(premature)
|
||||
WAF_C:clean_log()
|
||||
end
|
||||
|
||||
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
|
||||
function timer_every_get_cpu(premature)
|
||||
local cpu_percent = C:read_file_body(waf_root.."/cpu.info")
|
||||
if cpu_percent then
|
||||
ngx.shared.waf_limit:set("cpu_usage", tonumber(cpu_percent), 10)
|
||||
function waf_timer_every_get_cpu(premature)
|
||||
if WAF_C:file_exists('/proc/stat') then
|
||||
local lua_cpu_percent = WAF_C:get_cpu_percent()
|
||||
-- WAF_C:D("lua_cpu_percent:"..tostring(lua_cpu_percent))
|
||||
ngx.shared.waf_limit:set("cpu_usage", math.floor(lua_cpu_percent), 10)
|
||||
else
|
||||
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
|
||||
local cpu_percent = WAF_C:read_file_body(waf_root.."/cpu.info")
|
||||
-- WAF_C:D("cpu_usage:"..tostring(cpu_percent ))
|
||||
if cpu_percent then
|
||||
ngx.shared.waf_limit:set("cpu_usage", tonumber(cpu_percent), 10)
|
||||
else
|
||||
ngx.shared.waf_limit:set("cpu_usage", 0, 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if 0 == ngx.worker.id() then
|
||||
ngx.timer.every(5, timer_every_get_cpu)
|
||||
if ngx.worker.id() == 0 then
|
||||
|
||||
ngx.timer.every(6, waf_timer_every_get_cpu)
|
||||
-- 异步执行
|
||||
ngx.timer.every(3, timer_stats_total_log)
|
||||
ngx.timer.every(3, waf_timer_stats_total_log)
|
||||
ngx.timer.every(10, waf_clean_expire_data)
|
||||
|
||||
WAF_C:cron()
|
||||
end
|
||||
@@ -1,3 +1,14 @@
|
||||
local waf_root = "{$WAF_ROOT}"
|
||||
local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;"
|
||||
local waf_sopath = waf_root.."/waf/conf/?.so;"
|
||||
|
||||
if not package.path:find(waf_cpath) then
|
||||
package.path = waf_cpath .. package.path
|
||||
end
|
||||
|
||||
if not package.cpath:find(waf_sopath) then
|
||||
package.cpath = waf_sopath .. package.cpath
|
||||
end
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local _M = { _VERSION = '0.02' }
|
||||
@@ -6,10 +17,11 @@ local mt = { __index = _M }
|
||||
local json = require "cjson"
|
||||
local sqlite3 = require "lsqlite3"
|
||||
|
||||
local ngx_re = require "ngx.re"
|
||||
local ngx_match = ngx.re.find
|
||||
|
||||
local debug_mode = false
|
||||
|
||||
local waf_root = "{$WAF_ROOT}"
|
||||
local cpath = waf_root.."/waf/"
|
||||
local log_dir = waf_root.."/logs/"
|
||||
local rpath = cpath.."/rule/"
|
||||
@@ -31,43 +43,26 @@ function _M.new(self)
|
||||
end
|
||||
|
||||
|
||||
function _M.getInstance(self)
|
||||
if rawget(self, "instance") == nil then
|
||||
rawset(self, "instance", self:new())
|
||||
-- function _M.getInstance(self)
|
||||
-- if rawget(self, "instance") == nil then
|
||||
-- rawset(self, "instance", self.new())
|
||||
-- end
|
||||
-- assert(self.instance ~= nil)
|
||||
-- return self.instance
|
||||
-- end
|
||||
|
||||
if 0 == ngx.worker.id() then
|
||||
self:cron()
|
||||
end
|
||||
function _M.getInstance(self)
|
||||
if self.instance == nil then
|
||||
self.instance = self:new()
|
||||
end
|
||||
assert(self.instance ~= nil)
|
||||
return self.instance
|
||||
end
|
||||
|
||||
function _M.initDB(self)
|
||||
local path = log_dir .. "/waf.db"
|
||||
db, err = sqlite3.open(path)
|
||||
|
||||
if err then
|
||||
self:D("initDB err:"..tostring(err))
|
||||
return nil
|
||||
end
|
||||
|
||||
db:exec([[PRAGMA synchronous = 0]])
|
||||
db:exec([[PRAGMA cache_size = 8000]])
|
||||
db:exec([[PRAGMA page_size = 32768]])
|
||||
db:exec([[PRAGMA journal_mode = wal]])
|
||||
db:exec([[PRAGMA journal_size_limit = 1073741824]])
|
||||
return db
|
||||
end
|
||||
|
||||
-- 后台任务
|
||||
function _M.cron(self)
|
||||
local timer_every_get_data = function (premature)
|
||||
self.clean_log()
|
||||
end
|
||||
ngx.timer.every(10, timer_every_get_data)
|
||||
|
||||
local timer_every_import_data = function (premature)
|
||||
|
||||
local timer_every_import_data = function(premature)
|
||||
|
||||
local llen, _ = ngx.shared.waf_limit:llen('waf_limit_logs')
|
||||
if llen == 0 then
|
||||
@@ -81,7 +76,6 @@ function _M.cron(self)
|
||||
local stmt2 = db:prepare[[INSERT INTO logs(time, ip, domain, server_name, method, status_code, uri, user_agent, rule_name, reason)
|
||||
VALUES(:time, :ip, :domain, :server_name, :method, :status_code, :uri, :user_agent, :rule_name, :reason)]]
|
||||
|
||||
|
||||
if not stmt2 then
|
||||
self:D("waf timer db:prepare fail!:"..tostring(stmt2))
|
||||
return false
|
||||
@@ -126,6 +120,22 @@ function _M.cron(self)
|
||||
ngx.timer.every(0.5, timer_every_import_data)
|
||||
end
|
||||
|
||||
function _M.initDB(self)
|
||||
local path = log_dir .. "/waf.db"
|
||||
db, err = sqlite3.open(path)
|
||||
|
||||
if err then
|
||||
self:D("initDB err:"..tostring(err))
|
||||
return nil
|
||||
end
|
||||
|
||||
db:exec([[PRAGMA synchronous = 0]])
|
||||
db:exec([[PRAGMA cache_size = 8000]])
|
||||
db:exec([[PRAGMA page_size = 32768]])
|
||||
db:exec([[PRAGMA journal_mode = wal]])
|
||||
db:exec([[PRAGMA journal_size_limit = 1073741824]])
|
||||
return db
|
||||
end
|
||||
|
||||
function _M.clean_log(self)
|
||||
local db = self:initDB()
|
||||
@@ -382,6 +392,12 @@ function _M.read_file(self, name)
|
||||
return data
|
||||
end
|
||||
|
||||
function _M.file_exists(self,path)
|
||||
local file = io.open(path, "rb")
|
||||
if file then file:close() end
|
||||
return file ~= nil
|
||||
end
|
||||
|
||||
|
||||
function _M.select_rule(self, rules)
|
||||
if not rules then return {} end
|
||||
@@ -751,6 +767,34 @@ function _M.is_key(self, arr, key)
|
||||
return false
|
||||
end
|
||||
|
||||
function _M.get_cpu_stat(self)
|
||||
local cpu_total = 0
|
||||
local fp = io.open('/proc/stat','r')
|
||||
local cpu_line = fp:read()
|
||||
fp:close()
|
||||
|
||||
local list = ngx_re.split(cpu_line," ")
|
||||
table.remove(list,1)
|
||||
table.remove(list,1)
|
||||
|
||||
local idie = list[4]
|
||||
for i,v in pairs(list)
|
||||
do
|
||||
cpu_total = cpu_total + v
|
||||
end
|
||||
|
||||
local use_percent = tonumber(100-(idie/cpu_total)*100)
|
||||
return cpu_total,idie,use_percent
|
||||
end
|
||||
|
||||
function _M.get_cpu_percent(self)
|
||||
local cpu_total,idie,use_percent = self:get_cpu_stat()
|
||||
ngx.sleep(2)
|
||||
local cpu_total2,idie2,use_percent2 = self:get_cpu_stat()
|
||||
local cpu_usage_percent = tonumber(100-(((idie2-idie)/(cpu_total2-cpu_total))*100))
|
||||
return cpu_usage_percent
|
||||
end
|
||||
|
||||
|
||||
function _M.return_post_data(self)
|
||||
if method ~= "POST" then return false end
|
||||
@@ -1 +1 @@
|
||||
[[[127, 0, 0, 1], [127, 0, 0, 255]]]
|
||||
[[[127,0,0,1], [127, 0, 0, 255]]]
|
||||
@@ -0,0 +1,13 @@
|
||||
lua_package_path "{$SERVER_PATH}/web_conf/nginx/lua/?.lua;{$SERVER_PATH}/openresty/lualib/?.lua;;";
|
||||
lua_package_cpath "{$SERVER_PATH}/web_conf/nginx/lua/?.so;{$SERVER_PATH}/openresty/lualib/?.so;;";
|
||||
|
||||
lua_code_cache on;
|
||||
|
||||
#init_by_lua_file
|
||||
init_by_lua_file {$SERVER_PATH}/web_conf/nginx/lua/empty.lua;
|
||||
|
||||
#init_worker_by_lua
|
||||
init_worker_by_lua_file {$SERVER_PATH}/web_conf/nginx/lua/empty.lua;
|
||||
|
||||
#access_by_lua_file
|
||||
access_by_lua_file {$SERVER_PATH}/web_conf/nginx/lua/empty.lua;
|
||||
@@ -16,7 +16,7 @@ http
|
||||
{
|
||||
include mime.types;
|
||||
|
||||
#include luawaf.conf;
|
||||
include {$SERVER_PATH}/web_conf/nginx/lua/lua.conf;
|
||||
#include proxy.conf;
|
||||
|
||||
default_type application/octet-stream;
|
||||
@@ -28,6 +28,7 @@ http
|
||||
server_names_hash_bucket_size 512;
|
||||
client_header_buffer_size 32k;
|
||||
large_client_header_buffers 4 32k;
|
||||
client_body_buffer_size 50m;
|
||||
client_max_body_size 50m;
|
||||
|
||||
sendfile on;
|
||||
|
||||
@@ -131,10 +131,35 @@ def confReplace():
|
||||
content = content.replace('{$OS_USER}', user)
|
||||
content = content.replace('{$OS_USER_GROUP}', user_group)
|
||||
|
||||
# ng_conf_md5 = ''
|
||||
# ng_conf_md5_file = getServerDir() + '/nginx_conf.md5'
|
||||
# if not os.path.exists(ng_conf_md5_file):
|
||||
# ng_conf_md5 = mw.md5(content)
|
||||
# mw.writeFile(ng_conf_md5_file, ng_conf_md5)
|
||||
# else:
|
||||
# ng_conf_md5 = mw.writeFile(ng_conf_md5_file).strip()
|
||||
|
||||
# 主配置文件
|
||||
nconf = getServerDir() + '/nginx/conf/nginx.conf'
|
||||
mw.writeFile(nconf, content)
|
||||
|
||||
# lua配置
|
||||
lua_conf_dir = mw.getServerDir() + '/web_conf/nginx/lua'
|
||||
if not os.path.exists(lua_conf_dir):
|
||||
mw.execShell('mkdir -p ' + lua_conf_dir)
|
||||
|
||||
lua_conf = lua_conf_dir + '/lua.conf'
|
||||
lua_conf_tpl = getPluginDir() + '/conf/lua.conf'
|
||||
lua_content = mw.readFile(lua_conf_tpl)
|
||||
lua_content = lua_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(lua_conf, lua_content)
|
||||
|
||||
empty_lua = lua_conf_dir + '/empty.lua'
|
||||
if not os.path.exists(empty_lua):
|
||||
mw.writeFile(empty_lua, '')
|
||||
|
||||
mw.opLuaMakeAll()
|
||||
|
||||
# 静态配置
|
||||
php_conf = mw.getServerDir() + '/web_conf/php/conf'
|
||||
if not os.path.exists(php_conf):
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/openresty && bash install.sh install 1.21.4.1
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
@@ -57,10 +59,21 @@ Install_openresty()
|
||||
mkdir -p ${openrestyDir}
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
# wget -O openresty-1.21.4.1.tar.gz https://openresty.org/download/openresty-1.21.4.1.tar.gz
|
||||
if [ ! -f ${openrestyDir}/openresty-${VERSION}.tar.gz ];then
|
||||
wget -O ${openrestyDir}/openresty-${VERSION}.tar.gz https://openresty.org/download/openresty-${VERSION}.tar.gz
|
||||
wget --no-check-certificate -O ${openrestyDir}/openresty-${VERSION}.tar.gz https://openresty.org/download/openresty-${VERSION}.tar.gz -T 3
|
||||
fi
|
||||
|
||||
DOWNLOAD_SIZE=`wc -c ${openrestyDir}/openresty-${VERSION}.tar.gz | awk '{print $1}'`
|
||||
if [ "$DOWNLOAD_SIZE" == "0" ];then
|
||||
echo 'download failed, download again'
|
||||
rm -rf ${openrestyDir}/openresty-${VERSION}.tar.gz
|
||||
fi
|
||||
|
||||
# Last Download Method
|
||||
if [ ! -f ${openrestyDir}/openresty-${VERSION}.tar.gz ];then
|
||||
wget --no-check-certificate -O ${openrestyDir}/openresty-${VERSION}.tar.gz https://dl.midoks.me/soft/openresty/openresty-${VERSION}.tar.gz -T 3
|
||||
fi
|
||||
|
||||
cd ${openrestyDir} && tar -zxvf openresty-${VERSION}.tar.gz
|
||||
|
||||
|
||||
@@ -49,15 +49,20 @@ if [ "$OSNAME" == "ubuntu" ];then
|
||||
fi
|
||||
# apt install $(grep-aptavail -S PHP-defaults -s Package -n)
|
||||
|
||||
|
||||
if [ ! -f /etc/apt/sources.list.d/php.list ] && [ "$OSNAME" == "debian" ];then
|
||||
# install php source
|
||||
|
||||
apt update -y
|
||||
apt -y install apt-transport-https lsb-release ca-certificates curl
|
||||
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
|
||||
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
|
||||
apt update -y
|
||||
|
||||
# install php source
|
||||
apt update -y
|
||||
apt -y install apt-transport-https lsb-release ca-certificates curl
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
if [ ! -z "$cn" ];then
|
||||
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://mirror.sjtu.edu.cn/sury/php/apt.gpg
|
||||
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://mirror.sjtu.edu.cn/sury/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
|
||||
else
|
||||
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
|
||||
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
|
||||
fi
|
||||
apt update -y
|
||||
fi
|
||||
|
||||
|
||||
@@ -78,6 +83,7 @@ if [ "${action}" == "install" ] && [ -d ${serverPath}/php-apt/${type} ];then
|
||||
|
||||
# 安装通用扩展
|
||||
echo "install PHP-APT[${type}] extend start"
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install curl
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install gd
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install iconv
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install exif
|
||||
@@ -85,14 +91,16 @@ if [ "${action}" == "install" ] && [ -d ${serverPath}/php-apt/${type} ];then
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install xml
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install mcrypt
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install mysqlnd
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install mysql
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install gettext
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install redis
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install memcached
|
||||
cd ${rootPath}/plugins/php-apt/versions && bash common.sh ${type:0:1}.${type:1:2} install mbstring
|
||||
echo "install PHP-APT[${type}] extend end"
|
||||
|
||||
if [ ! -f /usr/local/bin/composer ];then
|
||||
cd /tmp
|
||||
curl -sS https://getcomposer.org/installer | php
|
||||
curl -sS https://getcomposer.org/installer | /usr/bin/php${type:0:1}.${type:1:2}
|
||||
mv composer.phar /usr/local/bin/composer
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -57,5 +57,4 @@ fi
|
||||
echo "apt install -y php${version}-${extName}"
|
||||
echo "apt remove -y php${version}-${extName}"
|
||||
|
||||
|
||||
|
||||
systemctl restart php${version}-fpm
|
||||
|
||||
@@ -35,6 +35,24 @@
|
||||
"shell": "mysqlnd.sh",
|
||||
"check": "mysqlnd"
|
||||
},
|
||||
{
|
||||
"name": "mysql",
|
||||
"versions": [
|
||||
"56",
|
||||
"70",
|
||||
"71",
|
||||
"72",
|
||||
"73",
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
],
|
||||
"type": "数据库",
|
||||
"msg": "用于使用MySQL数据库的模块!",
|
||||
"shell": "mysql.sh",
|
||||
"check": "mysql"
|
||||
},
|
||||
{
|
||||
"name": "sqlite3",
|
||||
"versions": [
|
||||
@@ -215,6 +233,19 @@
|
||||
"shell": "xml.sh",
|
||||
"check": "xml"
|
||||
},
|
||||
{
|
||||
"name": "curl",
|
||||
"versions": [
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "通用CURL库!",
|
||||
"shell": "curl.sh",
|
||||
"check": "curl"
|
||||
},
|
||||
{
|
||||
"name": "gd",
|
||||
"versions": [
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user