mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 06:09:25 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
869d7795a6 | ||
|
|
0a3d976c6a | ||
|
|
c4d39ef9fb | ||
|
|
8e5b499601 | ||
|
|
e6dff6094c | ||
|
|
47dec45a27 | ||
|
|
4706af7423 | ||
|
|
1bc458eb8f | ||
|
|
dc3f872592 | ||
|
|
3d48289329 | ||
|
|
6126539929 | ||
|
|
cff5df6d13 | ||
|
|
23a0b74f9d | ||
|
|
5927a3abab | ||
|
|
4b176ad702 | ||
|
|
577103506d | ||
|
|
18f8d2b905 | ||
|
|
3a6b5339d2 | ||
|
|
c25d4305f7 | ||
|
|
b6ef87e97b | ||
|
|
4335668cd4 | ||
|
|
0fc2ab011d | ||
|
|
683035e6b7 | ||
|
|
f2dfa7ad48 | ||
|
|
2ae2c188e7 | ||
|
|
b5cd0564cb | ||
|
|
2f274ce202 | ||
|
|
0a67932473 | ||
|
|
7b7cb215c4 | ||
|
|
f6e98ae286 | ||
|
|
5958f6e067 | ||
|
|
6dadfb1019 | ||
|
|
f5aeb5664b | ||
|
|
ca1080937d | ||
|
|
1dd934ea3f | ||
|
|
a34512d057 | ||
|
|
575c1e48ae | ||
|
|
9f3ee4997b | ||
|
|
cfaa2d9f25 | ||
|
|
aded1fc731 | ||
|
|
4a6e847743 | ||
|
|
24fac51538 | ||
|
|
148b32fed3 | ||
|
|
fff19d2c4a | ||
|
|
a5e0332179 | ||
|
|
1349655570 | ||
|
|
b9e617bf0f | ||
|
|
f65d10e1e4 | ||
|
|
6d9ec087ce | ||
|
|
bfb9da0471 | ||
|
|
8a95a68c81 | ||
|
|
d9d81ded3d | ||
|
|
403660c980 | ||
|
|
ac06cfc83c | ||
|
|
c50012b9b5 | ||
|
|
baeb0ddc8f | ||
|
|
83f8c99275 | ||
|
|
2d2b454a31 | ||
|
|
aad41ce14b | ||
|
|
ebf8c82d33 | ||
|
|
d25100fec3 | ||
|
|
fe658d9009 | ||
|
|
f37c2c9bc6 | ||
|
|
a1550765aa | ||
|
|
b020f23161 | ||
|
|
4afe2061e2 | ||
|
|
ab64c01981 | ||
|
|
8a97734700 | ||
|
|
16b4c64aa5 | ||
|
|
df2a5919af | ||
|
|
40a81b794c | ||
|
|
8fc7ab3abf | ||
|
|
ca4205c89a | ||
|
|
c89b15a645 | ||
|
|
7a863c4544 | ||
|
|
5d81406fdf | ||
|
|
cce59c0521 | ||
|
|
0a5c5aae12 | ||
|
|
7478426206 | ||
|
|
c0ed736edb | ||
|
|
313eb25ccd | ||
|
|
f58595755b | ||
|
|
18a892a576 | ||
|
|
03d558092f | ||
|
|
3cffa9223a | ||
|
|
c0d5aff2f5 | ||
|
|
3fa4c7804b | ||
|
|
22acce8bc0 | ||
|
|
e53e5cd672 | ||
|
|
a7d861de22 | ||
|
|
ddeef3c17e | ||
|
|
af733ac28a | ||
|
|
148e2021dc | ||
|
|
50c3fe58f4 | ||
|
|
5ed3728d4f | ||
|
|
9bf06c9d21 | ||
|
|
08b3738cfd | ||
|
|
a04f59a3aa | ||
|
|
155b8d2b4c | ||
|
|
039d2794ab | ||
|
|
0d2721523c | ||
|
|
f042665c05 | ||
|
|
0118548c24 | ||
|
|
1ba6625525 | ||
|
|
293f8ab0af | ||
|
|
dc68868883 | ||
|
|
30f835b6b8 | ||
|
|
4d90fdfe4f | ||
|
|
bb4067aa6b | ||
|
|
5dbf89b872 | ||
|
|
cc244a8ea5 | ||
|
|
975cb988f7 | ||
|
|
5a11d1bff9 | ||
|
|
bab3501722 | ||
|
|
872d68e0f1 | ||
|
|
9a5878a90c | ||
|
|
e5e226b57a | ||
|
|
5d12218a3e | ||
|
|
7b3bbc8bdd | ||
|
|
67030e91f6 | ||
|
|
c03eb0aa40 | ||
|
|
2b5aaba0b7 | ||
|
|
c7a01b8c52 | ||
|
|
9bfb72ada5 | ||
|
|
5ab8936f6b | ||
|
|
43c5161085 | ||
|
|
7d90a6e99f | ||
|
|
9ba8028944 | ||
|
|
36fa3d7630 | ||
|
|
b6a2d7e3e8 | ||
|
|
99e73d1bda | ||
|
|
1083b46078 | ||
|
|
8bd081804d | ||
|
|
2536a79481 | ||
|
|
eab11680e5 | ||
|
|
651b7d6d1b | ||
|
|
75e181116e | ||
|
|
c0a981b5a1 | ||
|
|
61dc601d48 | ||
|
|
415a2a1f8f | ||
|
|
7c06a85ac7 | ||
|
|
7c8329bb78 | ||
|
|
5c8a50429f | ||
|
|
300bdc1eb1 | ||
|
|
a8a9e9033e | ||
|
|
77425dfc48 | ||
|
|
52eae4625f | ||
|
|
dafcf60633 | ||
|
|
79c1e81d2c | ||
|
|
b779a18de6 | ||
|
|
45f22d239a | ||
|
|
f7b688d6bf | ||
|
|
6f069c715a | ||
|
|
98ed286b50 | ||
|
|
e931fa526f | ||
|
|
ff17610732 | ||
|
|
13bbe07ac5 | ||
|
|
5380cd805c | ||
|
|
c0b056c18d | ||
|
|
e287086b36 | ||
|
|
8647300e16 | ||
|
|
636f7af8ef | ||
|
|
87cf208dfc | ||
|
|
579a84c6f1 | ||
|
|
54b90f4484 | ||
|
|
ebdaf5d395 | ||
|
|
1e5ecabbd1 | ||
|
|
0596dc243e | ||
|
|
7fa6ec7cd3 | ||
|
|
c21d8eed8b | ||
|
|
326f9f0e6b | ||
|
|
60c94f120e | ||
|
|
55c08a8916 | ||
|
|
cf944fb976 | ||
|
|
cda1ea93a8 | ||
|
|
46f02cae0d | ||
|
|
034d00a262 | ||
|
|
fe1a68208b | ||
|
|
f364cc4e2d | ||
|
|
5b35b5f38c | ||
|
|
2151b2c597 | ||
|
|
4f8e95210f | ||
|
|
b31297b47f | ||
|
|
e492a87160 | ||
|
|
47d6eb7993 | ||
|
|
3ddccea897 | ||
|
|
069d594e49 | ||
|
|
7c49609a2b | ||
|
|
70d260dd5a | ||
|
|
58503722c0 | ||
|
|
0a98b4dc09 | ||
|
|
5ab0f493e4 | ||
|
|
30580874fd | ||
|
|
26327d958c | ||
|
|
522eddd393 | ||
|
|
935df8d4d1 | ||
|
|
15b4ba9cbb | ||
|
|
c005e1f56d | ||
|
|
edbca430ee | ||
|
|
f8fedb8285 | ||
|
|
d9472709fd | ||
|
|
79bf1eae07 | ||
|
|
fab6df7097 | ||
|
|
b9416d58f9 | ||
|
|
96d86ce49e | ||
|
|
46f2d9f029 | ||
|
|
9d5fb77123 | ||
|
|
d0c903bf11 | ||
|
|
3c1b0e6708 | ||
|
|
340b72591a | ||
|
|
8f6a194a02 | ||
|
|
7e65993978 | ||
|
|
ca27a2d49d | ||
|
|
b941c9c71b | ||
|
|
e68c7b0346 | ||
|
|
c7c3d8fdb9 | ||
|
|
de383e0584 | ||
|
|
048463cf9d | ||
|
|
0c118613d5 | ||
|
|
aa8e9f173b | ||
|
|
c21c54198c | ||
|
|
e8ad9995d7 | ||
|
|
7a0b6be401 | ||
|
|
8b2a127ceb | ||
|
|
8a23fb18ff | ||
|
|
234eca3729 | ||
|
|
9c74eb6a77 | ||
|
|
0093af2661 | ||
|
|
482d9bdd86 | ||
|
|
d8f9b179ad | ||
|
|
d179328976 | ||
|
|
9aaa5e2a65 | ||
|
|
821a9ce2d1 | ||
|
|
7b39b28dcd | ||
|
|
c881ad7d18 | ||
|
|
82da5c2649 | ||
|
|
315ba990ec | ||
|
|
992fcb7e6f | ||
|
|
d7337239f5 | ||
|
|
224b91fe0b | ||
|
|
589dfe6da2 | ||
|
|
b1b47c3c38 | ||
|
|
106f5d897d | ||
|
|
c856d09b3b | ||
|
|
6bf8792bb6 | ||
|
|
75edb074b2 | ||
|
|
4a5df99f06 | ||
|
|
2c7536a138 | ||
|
|
a758fc2264 | ||
|
|
0d94fe2d26 | ||
|
|
630bdd5f96 | ||
|
|
411fc670fc | ||
|
|
cab35c7c28 | ||
|
|
b3c8a6365f | ||
|
|
b64f02ff2f | ||
|
|
7e9df9640e | ||
|
|
6c478be4df | ||
|
|
e919fac1d5 | ||
|
|
4854142f9a | ||
|
|
f37de275ba | ||
|
|
0c8f777452 | ||
|
|
9235affadf | ||
|
|
2001a3b5dc | ||
|
|
6ba1e4c19c | ||
|
|
231048a4a3 | ||
|
|
6b9aab3759 | ||
|
|
e8a152b1a3 | ||
|
|
1cf8e4ecb7 | ||
|
|
aa04235446 | ||
|
|
3acbc36297 | ||
|
|
85aba4f1ce | ||
|
|
f33f80cf34 | ||
|
|
1868b3197d | ||
|
|
b8e1fb2ca2 | ||
|
|
9aa9c4f799 | ||
|
|
344603f1b2 | ||
|
|
71b43e9f2f | ||
|
|
adba50bfc1 | ||
|
|
d917fa76f6 | ||
|
|
32971ccead | ||
|
|
c7a3481b95 | ||
|
|
8915b672e5 | ||
|
|
e472d104d1 | ||
|
|
48ee5574c7 | ||
|
|
706afbd681 | ||
|
|
70ca6d0459 | ||
|
|
f344a32fa7 | ||
|
|
e6123000ac | ||
|
|
b94361c59f | ||
|
|
4a7efb67d4 | ||
|
|
536b7ac997 | ||
|
|
0f5b055aeb | ||
|
|
7d81a59c8f | ||
|
|
2540cd1308 | ||
|
|
5358cd2d38 | ||
|
|
c4bb20ed54 | ||
|
|
7f2f307131 | ||
|
|
7a8ef9fe00 | ||
|
|
e1abc66179 | ||
|
|
8bda20c3d0 | ||
|
|
3c01838df1 | ||
|
|
3b459e0349 | ||
|
|
d3e7684f04 | ||
|
|
b2e6e7f256 | ||
|
|
ca6812561a | ||
|
|
44e8079db6 | ||
|
|
9bd063cc1d | ||
|
|
1b0044e28a | ||
|
|
9b752cf24f | ||
|
|
cf5f98958c | ||
|
|
c46872dab5 | ||
|
|
b57edb7b87 | ||
|
|
595cc30c6f | ||
|
|
4b6f5a5f4e | ||
|
|
741da10906 | ||
|
|
9965786976 | ||
|
|
f083696131 | ||
|
|
dd2105d9ab | ||
|
|
c1574f3430 | ||
|
|
6394ead5b8 | ||
|
|
2861f7f995 | ||
|
|
10d6fa2d47 | ||
|
|
16e5b4ae73 | ||
|
|
aca89d7d5e | ||
|
|
ffefe96f1f | ||
|
|
e1e1e81a90 | ||
|
|
502295125a | ||
|
|
85258dd80b | ||
|
|
ff0cb6eb31 | ||
|
|
e4e1945ea5 | ||
|
|
e7f74a482f | ||
|
|
dd27af9ede | ||
|
|
4aeffd2aa6 | ||
|
|
8924957e7f | ||
|
|
c013db9d41 | ||
|
|
e492abf354 | ||
|
|
f84cab9e98 | ||
|
|
eb5be2842d | ||
|
|
06e99096cf | ||
|
|
93f1129c0f | ||
|
|
46bc94946c | ||
|
|
0857c6aed7 | ||
|
|
fdcdd27f8e | ||
|
|
d1810606db | ||
|
|
68f5f4c6cb | ||
|
|
d40665c0f8 | ||
|
|
9d1ebba509 | ||
|
|
d0113840a3 | ||
|
|
43c287132b | ||
|
|
deb3a40fb7 | ||
|
|
88196175f4 | ||
|
|
217ba2d14e | ||
|
|
7af7e2321a | ||
|
|
20b39cbb70 | ||
|
|
66ff690bae | ||
|
|
99e8e63917 | ||
|
|
a4dfe26254 | ||
|
|
15c0ef390e | ||
|
|
a2b9658b2e | ||
|
|
5bcb0fb739 | ||
|
|
6278c9588b | ||
|
|
19d4456e2e | ||
|
|
807cb8fe98 | ||
|
|
ba2df01084 | ||
|
|
d82b0dbe9f | ||
|
|
acc18cf571 | ||
|
|
f69dd139c0 | ||
|
|
ab6f860bde | ||
|
|
febe56f430 | ||
|
|
0962e5aab8 | ||
|
|
5ea062862f | ||
|
|
cce5598f2f | ||
|
|
d88962eb56 | ||
|
|
b44e24df0d | ||
|
|
f36e540a59 | ||
|
|
992e7445f6 | ||
|
|
066729e8d9 | ||
|
|
be3e57a905 | ||
|
|
bc7a569ae9 |
@@ -11,8 +11,7 @@ Debian x, Centos x, Centos x stream, Ubuntu x?
|
||||
|
||||
Ex:
|
||||
```bash
|
||||
................start mw success
|
||||
bash: line 149: ./scripts/init.d/mw: No such file or directory
|
||||
一个issue,一个问题。多余问题,视情况而答。
|
||||
```
|
||||
|
||||
## 错误截图 ?
|
||||
|
||||
+18
-1
@@ -106,6 +106,7 @@ venv.bak/
|
||||
.idea/*.iml
|
||||
tmp/*
|
||||
*.swp
|
||||
*.pem
|
||||
*.zip
|
||||
logs/*
|
||||
data/*.db
|
||||
@@ -116,13 +117,15 @@ data/json/config.json
|
||||
data/site.pl
|
||||
data/admin_path.pl
|
||||
data/close.pl
|
||||
ssl/input.pl
|
||||
data/datadir.pl
|
||||
data/502Task.pl
|
||||
data/default.pl
|
||||
data/backup.pl
|
||||
data/debug.pl
|
||||
data/default_site.pl
|
||||
|
||||
ssl/input.pl
|
||||
|
||||
lib/python*
|
||||
|
||||
bin
|
||||
@@ -148,10 +151,21 @@ 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/system_safe
|
||||
plugins/tamper_proof
|
||||
plugins/tamper_proof_*
|
||||
plugins/cryptocurrency_trade
|
||||
plugins/op_load_balance
|
||||
plugins/gdrive
|
||||
plugins/mtproxy
|
||||
plugins/zimg
|
||||
@@ -160,6 +174,9 @@ plugins/mail
|
||||
plugins/fastdfs
|
||||
plugins/v2ray
|
||||
plugins/frp
|
||||
plugins/file_search
|
||||
debug.out
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<img alt="logo" src="https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/route/static/logo.png" height="140" />
|
||||
<h3 align="center">mdserver-web</h3>
|
||||
<p align="center">一款简单Linux面板服务</p>
|
||||
<p align="center">强烈推荐系统:debian</p>
|
||||
</p>
|
||||
|
||||
### 简介
|
||||
@@ -10,10 +11,11 @@
|
||||
复制了后台管理界面,按照自己想要的方式写了一版。
|
||||
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
[](https://github.com/midoks/mdserver-web/wiki)
|
||||
[](https://www.jsdelivr.com/package/gh/midoks/mdserver-web)
|
||||
@@ -27,6 +29,13 @@
|
||||
基本上可以使用,后续会继续优化!欢迎提供意见!
|
||||
|
||||
- 吹水组 - https://t.me/mdserver_web
|
||||
- 交流论坛 - https://bbs.midoks.me
|
||||
|
||||
```
|
||||
如果出现问题,最好私给我面板信息。不要让我猜。如果不提供,不要提出问题,自行解决。 — 座右铭
|
||||
Talk is cheap, show me the code. -- linus
|
||||
```
|
||||
|
||||
- [兼容性测试报告](/compatibility.md)
|
||||
- [常用命令说明](/cmd.md)
|
||||
|
||||
@@ -36,6 +45,7 @@
|
||||
* PHP[53-82] - PHP是世界上最好的编程语言。
|
||||
* MySQL - 一种关系数据库管理系统。
|
||||
* MariaDB - 是MySQL的一个重要分支。
|
||||
* MySQL[APT/YUM] - 一种关系数据库管理系统。
|
||||
* MongoDB - 一种非关系NOSQL数据库管理系统。
|
||||
* phpMyAdmin - 著名Web端MySQL管理工具。
|
||||
* Memcached - 一个高性能的分布式内存对象缓存系统。
|
||||
@@ -64,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推荐 - 🙏
|
||||
|
||||
@@ -79,28 +88,22 @@ PHP[72-81]支持phpMyAdmin[5.2.0]
|
||||
| 服务商 | LOGO | 推广地址 | 优惠码 |
|
||||
| ------------- |----------|-----------|-------|
|
||||
| digitalvirt |[](https://digitalvirt.com/aff.php?aff=154) | https://digitalvirt.com/aff.php?aff=154 | mdserver-web |
|
||||
| 搬瓦工 |[](https://bwh81.net/aff.php?aff=54161) | https://bwh81.net/aff.php?aff=54161 | BWH3HYATVBJW |
|
||||
|
||||
# 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.11.1
|
||||
|
||||
* 提供面板API接口访问的支持。
|
||||
* rockylinux系统安装优化。
|
||||
* 网站统计记录POST请求原文优化。
|
||||
* 针对mysql下载速度优化。
|
||||
* mysql初始化默认参数优化。
|
||||
* OP防火墙安全设置BUG解决。
|
||||
* Gitea优化。
|
||||
### 版本更新 0.13.3
|
||||
|
||||
* tgbot插件[增加扩展功能]。
|
||||
* ssl功能优化。
|
||||
* 网站统计-计划任务归档优化。
|
||||
|
||||
### JSDelivr安装地址
|
||||
|
||||
@@ -128,7 +131,7 @@ 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://gitee.com/midoks/mdserver-web/raw/master/scripts/install.sh | bash
|
||||
```
|
||||
|
||||
- 直接更新
|
||||
@@ -161,7 +164,9 @@ curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/up
|
||||
|
||||
wget -O uninstall.sh https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/uninstall.sh && bash uninstall.sh
|
||||
|
||||
curl -fsSL https://gitee.com/midoks/mdserver-web/raw/master/scripts/install_dev.sh | bash
|
||||
curl -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
|
||||
```
|
||||
|
||||
@@ -169,6 +174,8 @@ curl -fsSL https://gitee.com/midoks/mdserver-web/raw/dev/scripts/update_dev.sh |
|
||||
|
||||
TVbNgrpeGBGZVm5gTLa21ADP7RpnPFhjya
|
||||
|
||||
日行一善,以后必定大富大贵
|
||||
|
||||
|
||||
### 微信赞助
|
||||
|
||||
|
||||
@@ -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:
|
||||
@@ -825,7 +826,7 @@ fi
|
||||
ret_title, json.dumps(a_auth)))
|
||||
break
|
||||
|
||||
if number_of_checks == self._max_check_num:
|
||||
if number_of_checks == self.__max_check_num:
|
||||
raise StopIteration(
|
||||
"错误:已尝试验证{0}次. 最大验证次数为{1}. 验证时间间隔为{2}秒.".format(
|
||||
number_of_checks,
|
||||
@@ -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:
|
||||
|
||||
@@ -736,7 +736,7 @@ class cert_request:
|
||||
ret_title, json.dumps(a_auth)))
|
||||
break
|
||||
|
||||
if number_of_checks == self._max_check_num:
|
||||
if number_of_checks == self.__max_check_num:
|
||||
raise StopIteration(
|
||||
"错误:已尝试验证{0}次. 最大验证次数为{1}. 验证时间间隔为{2}秒.".format(
|
||||
number_of_checks,
|
||||
|
||||
+431
-48
@@ -27,7 +27,7 @@ from flask import request
|
||||
|
||||
class config_api:
|
||||
|
||||
__version = '0.11.1.1'
|
||||
__version = '0.13.3'
|
||||
__api_addr = 'data/api.json'
|
||||
|
||||
def __init__(self):
|
||||
@@ -135,7 +135,8 @@ class config_api:
|
||||
import system_api
|
||||
import firewall_api
|
||||
|
||||
if os.path.exists("/lib/systemd/system/firewalld.service"):
|
||||
sysCfgDir = mw.systemdCfgDir()
|
||||
if os.path.exists(sysCfgDir + "/firewalld.service"):
|
||||
if not firewall_api.firewall_api().getFwStatus():
|
||||
return mw.returnJson(False, 'firewalld必须先启动!')
|
||||
|
||||
@@ -242,7 +243,8 @@ class config_api:
|
||||
import system_api
|
||||
import firewall_api
|
||||
|
||||
if os.path.exists("/lib/systemd/system/firewalld.service"):
|
||||
sysCfgDir = mw.systemdCfgDir()
|
||||
if os.path.exists(sysCfgDir + "/firewalld.service"):
|
||||
if not firewall_api.firewall_api().getFwStatus():
|
||||
return mw.returnJson(False, 'firewalld必须先启动!')
|
||||
|
||||
@@ -338,21 +340,52 @@ class config_api:
|
||||
|
||||
# 获取面板证书
|
||||
def getPanelSslApi(self):
|
||||
cert = {}
|
||||
cert['privateKey'] = mw.readFile('ssl/privateKey.pem')
|
||||
cert['certPem'] = mw.readFile('ssl/certificate.pem')
|
||||
cert['rep'] = os.path.exists('ssl/input.pl')
|
||||
cert = self.getPanelSslData()
|
||||
return mw.getJson(cert)
|
||||
|
||||
def getPanelSslData(self):
|
||||
cert = {}
|
||||
keyPath = 'ssl/private.pem'
|
||||
certPath = 'ssl/cert.pem'
|
||||
if not os.path.exists(certPath):
|
||||
# 不再自动生成证书
|
||||
# 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)
|
||||
cert['rep'] = os.path.exists('ssl/input.pl')
|
||||
cert['info'] = mw.getCertName(certPath)
|
||||
return cert
|
||||
|
||||
# 保存面板证书
|
||||
def savePanelSslApi(self):
|
||||
keyPath = 'ssl/privateKey.pem'
|
||||
certPath = 'ssl/certificate.pem'
|
||||
keyPath = 'ssl/private.pem'
|
||||
certPath = 'ssl/cert.pem'
|
||||
checkCert = '/tmp/cert.pl'
|
||||
|
||||
certPem = request.form.get('certPem', '').strip()
|
||||
privateKey = request.form.get('privateKey', '').strip()
|
||||
|
||||
if(privateKey.find('KEY') == -1):
|
||||
return mw.returnJson(False, '秘钥错误,请检查!')
|
||||
if(certPem.find('CERTIFICATE') == -1):
|
||||
return mw.returnJson(False, '证书错误,请检查!')
|
||||
|
||||
mw.writeFile(checkCert, certPem)
|
||||
if privateKey:
|
||||
mw.writeFile(keyPath, privateKey)
|
||||
@@ -363,22 +396,254 @@ 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, '先要绑定域名!')
|
||||
|
||||
siteName = mw.readFile(bind_domain).strip()
|
||||
auth_to = mw.getRunDir() + "/tmp"
|
||||
to_args = {
|
||||
'domains': [siteName],
|
||||
'auth_type': 'http',
|
||||
'auth_to': auth_to,
|
||||
}
|
||||
|
||||
src_letpath = mw.getServerDir() + '/web_conf/letsencrypt/' + siteName
|
||||
src_csrpath = src_letpath + "/fullchain.pem" # 生成证书路径
|
||||
src_keypath = src_letpath + "/privkey.pem" # 密钥文件路径
|
||||
|
||||
dst_letpath = mw.getRunDir() + '/ssl'
|
||||
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)
|
||||
if not data['status']:
|
||||
msg = data['msg']
|
||||
if type(data['msg']) != str:
|
||||
msg = data['msg'][0]
|
||||
emsg = data['msg'][1]['challenges'][0]['error']
|
||||
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)
|
||||
mw.execShell('echo "lets" > "' + dst_letpath + '/README"')
|
||||
|
||||
data = self.getPanelSslData()
|
||||
|
||||
tmp_well_know = auth_to + '/.well-known'
|
||||
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):
|
||||
domain = request.form.get('domain', '')
|
||||
|
||||
panel_tpl = mw.getRunDir() + "/data/tpl/nginx_panel.conf"
|
||||
dst_panel_path = mw.getServerDir() + "/web_conf/nginx/vhost/panel.conf"
|
||||
|
||||
cfg_domain = 'data/bind_domain.pl'
|
||||
if domain == '':
|
||||
os.remove(cfg_domain)
|
||||
os.remove(dst_panel_path)
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(True, '清空域名成功!')
|
||||
|
||||
reg = r"^([\w\-\*]{1,100}\.){1,4}(\w{1,10}|\w{1,10}\.\w{1,10})$"
|
||||
if not re.match(reg, domain):
|
||||
return mw.returnJson(False, '主域名格式不正确')
|
||||
|
||||
op_dir = mw.getServerDir() + "/openresty"
|
||||
if not os.path.exists(op_dir):
|
||||
return mw.returnJson(False, '依赖OpenResty,先安装启动它!')
|
||||
|
||||
content = mw.readFile(panel_tpl)
|
||||
content = content.replace("{$PORT}", "80")
|
||||
content = content.replace("{$SERVER_NAME}", domain)
|
||||
content = content.replace("{$PANAL_PORT}", mw.readFile('data/port.pl'))
|
||||
content = content.replace("{$LOGPATH}", mw.getRunDir() + '/logs')
|
||||
content = content.replace("{$PANAL_ADDR}", mw.getRunDir())
|
||||
mw.writeFile(dst_panel_path, content)
|
||||
mw.restartWeb()
|
||||
|
||||
mw.writeFile(cfg_domain, domain)
|
||||
return mw.returnJson(True, '设置域名成功!')
|
||||
|
||||
# 设置面板SSL
|
||||
def setPanelSslApi(self):
|
||||
sslConf = mw.getRunDir() + '/data/ssl.pl'
|
||||
|
||||
panel_tpl = mw.getRunDir() + "/data/tpl/nginx_panel.conf"
|
||||
dst_panel_path = mw.getServerDir() + "/web_conf/nginx/vhost/panel.conf"
|
||||
if os.path.exists(sslConf):
|
||||
os.system('rm -f ' + sslConf)
|
||||
|
||||
conf = mw.readFile(dst_panel_path)
|
||||
if conf:
|
||||
rep = "\s+ssl_certificate\s+.+;\s+ssl_certificate_key\s+.+;"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_protocols\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_ciphers\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_prefer_server_ciphers\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_session_cache\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_session_timeout\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_ecdh_curve\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_session_tickets\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_stapling\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl_stapling_verify\s+.+;\n"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+ssl\s+on;"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+error_page\s497.+;"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+if.+server_port.+\n.+\n\s+\s*}"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+listen\s+443.*;"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+listen\s+\[\:\:\]\:443.*;"
|
||||
conf = re.sub(rep, '', conf)
|
||||
mw.writeFile(dst_panel_path, conf)
|
||||
|
||||
mw.writeLog('面板配置', '面板SSL关闭成功!')
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(True, 'SSL已关闭,请使用http协议访问面板!')
|
||||
else:
|
||||
os.system('pip install cffi==1.10')
|
||||
os.system('pip install cryptography==2.1')
|
||||
os.system('pip install pyOpenSSL==16.2')
|
||||
try:
|
||||
if not self.createSSL():
|
||||
return mw.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!<p>请尝试手动安装: pip install pyOpenSSL</p>')
|
||||
mw.writeFile(sslConf, 'True')
|
||||
|
||||
keyPath = mw.getRunDir() + '/ssl/private.pem'
|
||||
certPath = mw.getRunDir() + '/ssl/cert.pem'
|
||||
|
||||
conf = mw.readFile(dst_panel_path)
|
||||
if conf:
|
||||
if conf.find('ssl_certificate') == -1:
|
||||
sslStr = """#error_page 404/404.html;
|
||||
ssl_certificate %s;
|
||||
ssl_certificate_key %s;
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
error_page 497 https://$host$request_uri;""" % (certPath, keyPath)
|
||||
if(conf.find('ssl_certificate') != -1):
|
||||
return mw.returnJson(True, 'SSL开启成功!')
|
||||
|
||||
conf = conf.replace('#error_page 404/404.html;', sslStr)
|
||||
|
||||
rep = "listen\s+([0-9]+)\s*[default_server]*;"
|
||||
tmp = re.findall(rep, conf)
|
||||
if not mw.inArray(tmp, '443'):
|
||||
listen = re.search(rep, conf).group()
|
||||
http_ssl = "\n\tlisten 443 ssl http2;"
|
||||
http_ssl = http_ssl + "\n\tlisten [::]:443 ssl http2;"
|
||||
conf = conf.replace(listen, listen + http_ssl)
|
||||
|
||||
mw.backFile(dst_panel_path)
|
||||
mw.writeFile(dst_panel_path, conf)
|
||||
isError = mw.checkWebConfig()
|
||||
if(isError != True):
|
||||
mw.restoreFile(dst_panel_path)
|
||||
return mw.returnJson(False, '证书错误: <br><a style="color:red;">' + isError.replace("\n", '<br>') + '</a>')
|
||||
except Exception as ex:
|
||||
return mw.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!<p>请尝试手动安装: pip install pyOpenSSL</p>')
|
||||
return mw.returnJson(False, '开启失败:' + str(ex))
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(True, '开启成功,请使用https协议访问面板!')
|
||||
|
||||
def getApi(self):
|
||||
@@ -386,32 +651,6 @@ class config_api:
|
||||
return mw.getJson(data)
|
||||
##### ----- end ----- ###
|
||||
|
||||
# 自签证书
|
||||
def createSSL(self):
|
||||
if os.path.exists('ssl/input.pl'):
|
||||
return True
|
||||
import OpenSSL
|
||||
key = OpenSSL.crypto.PKey()
|
||||
key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048)
|
||||
cert = OpenSSL.crypto.X509()
|
||||
cert.set_serial_number(0)
|
||||
cert.get_subject().CN = mw.getLocalIp()
|
||||
cert.set_issuer(cert.get_subject())
|
||||
cert.gmtime_adj_notBefore(0)
|
||||
cert.gmtime_adj_notAfter(86400 * 3650)
|
||||
cert.set_pubkey(key)
|
||||
cert.sign(key, 'md5')
|
||||
cert_ca = OpenSSL.crypto.dump_certificate(
|
||||
OpenSSL.crypto.FILETYPE_PEM, cert)
|
||||
private_key = OpenSSL.crypto.dump_privatekey(
|
||||
OpenSSL.crypto.FILETYPE_PEM, key)
|
||||
if len(cert_ca) > 100 and len(private_key) > 100:
|
||||
mw.writeFile('ssl/certificate.pem', cert_ca)
|
||||
mw.writeFile('ssl/privateKey.pem', private_key)
|
||||
print(cert_ca, private_key)
|
||||
return True
|
||||
return False
|
||||
|
||||
# 获取临时登录列表
|
||||
def getTempLoginApi(self):
|
||||
if 'tmp_login_expire' in session:
|
||||
@@ -502,9 +741,76 @@ 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, '验证失败')
|
||||
|
||||
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": []}
|
||||
@@ -523,7 +829,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'] = "***********************************"
|
||||
|
||||
@@ -535,10 +841,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)
|
||||
@@ -548,7 +850,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:
|
||||
@@ -563,12 +872,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 = {}
|
||||
@@ -614,6 +949,15 @@ class config_api:
|
||||
else:
|
||||
data['basic_auth'] = ''
|
||||
|
||||
cfg_domain = 'data/bind_domain.pl'
|
||||
if os.path.exists(cfg_domain):
|
||||
domain = mw.readFile(cfg_domain)
|
||||
data['bind_domain'] = domain.strip()
|
||||
else:
|
||||
data['bind_domain'] = ''
|
||||
|
||||
data = self.renderUnauthorizedStatus(data)
|
||||
|
||||
api_token = self.__api_addr
|
||||
if os.path.exists(api_token):
|
||||
bac = mw.readFile(api_token)
|
||||
@@ -628,4 +972,43 @@ class config_api:
|
||||
data['username'] = mw.M('users').where(
|
||||
"id=?", (1,)).getField('username')
|
||||
|
||||
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
|
||||
|
||||
+47
-22
@@ -94,7 +94,7 @@ class crontab_api:
|
||||
rdata['list'] = mw.getPage(_page)
|
||||
rdata['p'] = p
|
||||
|
||||
# backup hock
|
||||
# backup hook
|
||||
bh_file = mw.getPanelDataDir() + "/hook_backup.json"
|
||||
if os.path.exists(bh_file):
|
||||
hb_data = mw.readFile(bh_file)
|
||||
@@ -131,7 +131,7 @@ class crontab_api:
|
||||
# 参数校验
|
||||
def cronCheck(self, params):
|
||||
|
||||
if params['stype'] == 'site' or params['stype'] == 'database' or params['stype'] == 'logs':
|
||||
if params['stype'] == 'site' or params['stype'] == 'database' or params['stype'].find('database_') > -1 or params['stype'] == 'logs' or params['stype'] == 'path':
|
||||
if params['save'] == '':
|
||||
return False, '保留份数不能为空!'
|
||||
|
||||
@@ -230,8 +230,8 @@ class crontab_api:
|
||||
cronInfo['sbody'] = get['sbody']
|
||||
cronInfo['urladdress'] = get['urladdress']
|
||||
|
||||
addData = mw.M('crontab').where('id=?', (sid,)).save('name,type,where1,where_hour,where_minute,save,backup_to,sbody,urladdress', (get[
|
||||
'name'], field_type, get['where1'], get['hour'], get['minute'], get['save'], get['backup_to'], get['sbody'], get['urladdress']))
|
||||
addData = mw.M('crontab').where('id=?', (sid,)).save('name,type,where1,where_hour,where_minute,save,backup_to, sname, sbody,urladdress',
|
||||
(iname, field_type, get['where1'], get['hour'], get['minute'], get['save'], get['backup_to'], sname, get['sbody'], get['urladdress']))
|
||||
self.removeForCrond(cronInfo['echo'])
|
||||
self.syncToCrond(cronInfo)
|
||||
mw.writeLog('计划任务', '修改计划任务[' + cronInfo['name'] + ']成功')
|
||||
@@ -377,28 +377,46 @@ class crontab_api:
|
||||
stype = request.form.get('type', '')
|
||||
|
||||
bak_data = []
|
||||
|
||||
if stype == 'sites' or stype == 'databases':
|
||||
if stype == 'site' or stype == 'sites' or stype == 'database' or stype.find('database_') > -1 or stype == 'path':
|
||||
hookPath = mw.getPanelDataDir() + "/hook_backup.json"
|
||||
if os.path.exists(hookPath):
|
||||
t = mw.readFile(hookPath)
|
||||
bak_data = json.loads(t)
|
||||
|
||||
if stype == 'databases':
|
||||
if stype == 'database' or stype.find('database_') > -1:
|
||||
sqlite3_name = 'mysql'
|
||||
path = mw.getServerDir() + '/mysql'
|
||||
if stype != 'database':
|
||||
soft_name = stype.replace('database_', '')
|
||||
path = mw.getServerDir() + '/' + soft_name
|
||||
|
||||
if soft_name == 'postgresql':
|
||||
sqlite3_name = 'pgsql'
|
||||
|
||||
db_list = {}
|
||||
db_list['orderOpt'] = bak_data
|
||||
path = mw.getServerDir() + '/mysql'
|
||||
if not os.path.exists(path + '/mysql.db'):
|
||||
|
||||
if not os.path.exists(path + '/' + sqlite3_name + '.db'):
|
||||
db_list['data'] = []
|
||||
else:
|
||||
db_list['data'] = mw.M('databases').dbPos(
|
||||
path, 'mysql').field('name,ps').select()
|
||||
path, sqlite3_name).field('name,ps').select()
|
||||
return mw.getJson(db_list)
|
||||
|
||||
if stype == 'path':
|
||||
db_list = {}
|
||||
db_list['data'] = [{"name": mw.getWwwDir(), "ps": "www"}]
|
||||
db_list['orderOpt'] = bak_data
|
||||
return mw.getJson(db_list)
|
||||
|
||||
data = {}
|
||||
data['orderOpt'] = bak_data
|
||||
|
||||
data['data'] = mw.M(stype).field('name,ps').select()
|
||||
default_db = 'sites'
|
||||
# if stype == 'site' or stype == 'logs':
|
||||
# stype == 'sites'
|
||||
|
||||
data['data'] = mw.M(default_db).field('name,ps').select()
|
||||
return mw.getJson(data)
|
||||
##### ----- start ----- ###
|
||||
|
||||
@@ -495,13 +513,19 @@ export LANG=en_US.UTF-8
|
||||
MW_PATH=%s/bin/activate
|
||||
if [ -f $MW_PATH ];then
|
||||
source $MW_PATH
|
||||
fi
|
||||
''' % (mw.getRunDir(),)
|
||||
fi''' % (mw.getRunDir(),)
|
||||
|
||||
head = head + source_bin_activate + "\n"
|
||||
log = '.log'
|
||||
|
||||
script_dir = mw.getServerDir() + "/mdserver-web/scripts"
|
||||
script_dir = mw.getRunDir() + "/scripts"
|
||||
source_stype = 'database'
|
||||
if stype.find('database_') > -1:
|
||||
plugin_name = stype.replace('database_', '')
|
||||
script_dir = mw.getRunDir() + "/plugins/" + plugin_name + "/scripts"
|
||||
|
||||
source_stype = stype
|
||||
stype = 'database'
|
||||
|
||||
wheres = {
|
||||
'path': head + "python3 " + script_dir + "/backup.py path " + param['sname'] + " " + str(param['save']),
|
||||
@@ -513,13 +537,14 @@ fi
|
||||
if param['backup_to'] != 'localhost':
|
||||
cfile = mw.getPluginDir() + "/" + \
|
||||
param['backup_to'] + "/index.py"
|
||||
wheres = {
|
||||
'path': head + "python3 " + cfile + " path " + param['sname'] + " " + str(param['save']),
|
||||
'site': head + "python3 " + cfile + " site " + param['sname'] + " " + str(param['save']),
|
||||
'database': head + "python3 " + cfile + " database " + param['sname'] + " " + str(param['save']),
|
||||
'logs': head + "python3 " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
|
||||
'rememory': head + "/bin/bash " + script_dir + '/rememory.sh'
|
||||
}
|
||||
|
||||
wheres['path'] = head + "python3 " + cfile + \
|
||||
" path " + param['sname'] + " " + str(param['save'])
|
||||
wheres['site'] = head + "python3 " + cfile + \
|
||||
" site " + param['sname'] + " " + str(param['save'])
|
||||
wheres['database'] = head + "python3 " + cfile + " " + \
|
||||
source_stype + " " + \
|
||||
param['sname'] + " " + str(param['save'])
|
||||
try:
|
||||
shell = wheres[stype]
|
||||
except:
|
||||
@@ -583,9 +608,9 @@ echo "--------------------------------------------------------------------------
|
||||
# 重载配置
|
||||
def crondReload(self):
|
||||
if mw.isAppleSystem():
|
||||
# mw.execShell('/usr/sbin/cron restart')
|
||||
if os.path.exists('/etc/crontab'):
|
||||
pass
|
||||
# mw.execShell('/usr/sbin/cron restart')
|
||||
else:
|
||||
if os.path.exists('/etc/init.d/crond'):
|
||||
mw.execShell('/etc/init.d/crond reload')
|
||||
|
||||
+2
-1
@@ -117,6 +117,7 @@ class Sql():
|
||||
sql = "SELECT " + self.__OPT_FIELD + " FROM " + self.__DB_TABLE + \
|
||||
self.__OPT_WHERE + self.__OPT_GROUP + self.__OPT_ORDER + self.__OPT_LIMIT
|
||||
# print(sql)
|
||||
# print(self.__OPT_PARAM)
|
||||
result = self.__DB_CONN.execute(sql, self.__OPT_PARAM)
|
||||
data = result.fetchall()
|
||||
# 构造字曲系列
|
||||
@@ -347,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:
|
||||
|
||||
+224
-80
@@ -97,11 +97,11 @@ class files_api:
|
||||
import shutil
|
||||
try:
|
||||
shutil.move(sfile, dfile)
|
||||
msg = mw.getInfo('移动文件或目录[{1}]到[{2}]成功!', (sfile, dfile,))
|
||||
msg = mw.getInfo('移动或重名命文件[{1}]到[{2}]成功!', (sfile, dfile,))
|
||||
mw.writeLog('文件管理', msg)
|
||||
return mw.returnJson(True, '移动文件或目录成功!')
|
||||
return mw.returnJson(True, '移动或重名命文件成功!')
|
||||
except:
|
||||
return mw.returnJson(False, '移动文件或目录失败!')
|
||||
return mw.returnJson(False, '移动或重名命文件失败!')
|
||||
|
||||
def deleteApi(self):
|
||||
path = request.form.get('path', '')
|
||||
@@ -148,12 +148,16 @@ class files_api:
|
||||
if not os.path.exists(path):
|
||||
path = mw.getRootDir() + "/wwwroot"
|
||||
search = request.args.get('search', '').strip().lower()
|
||||
search_all = request.args.get('all', '').strip().lower()
|
||||
page = request.args.get('p', '1').strip().lower()
|
||||
row = request.args.get('showRow', '10')
|
||||
disk = request.form.get('disk', '')
|
||||
if disk == 'True':
|
||||
row = 1000
|
||||
|
||||
# return self.getAllDir(path, int(page), int(row), "wp-inlcude")
|
||||
if search_all == 'yes' and search != '':
|
||||
return self.getAllDir(path, int(page), int(row), search)
|
||||
return self.getDir(path, int(page), int(row), search)
|
||||
|
||||
def createFileApi(self):
|
||||
@@ -236,10 +240,15 @@ class files_api:
|
||||
system_api.system_api().restartTask()
|
||||
except:
|
||||
system_api.system_api().restartTask()
|
||||
|
||||
# 删除日志
|
||||
task_log = mw.getRunDir() + "/tmp/panelTask.pl"
|
||||
if os.path.exists(task_log):
|
||||
os.remove(task_log)
|
||||
return mw.returnJson(True, '任务已删除!')
|
||||
|
||||
# 上传文件
|
||||
def uploadFileApi(self):
|
||||
# 上传文件
|
||||
from werkzeug.utils import secure_filename
|
||||
from flask import request
|
||||
|
||||
@@ -254,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)
|
||||
@@ -262,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):
|
||||
@@ -617,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)
|
||||
@@ -668,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):
|
||||
@@ -725,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()
|
||||
|
||||
@@ -830,11 +891,59 @@ class files_api:
|
||||
if search:
|
||||
if name.lower().find(search) == -1:
|
||||
continue
|
||||
# if name[0:1] == '.':
|
||||
# continue
|
||||
if name == '.':
|
||||
continue
|
||||
i += 1
|
||||
return i
|
||||
|
||||
def getAllDir(self, path, page=1, page_size=10, search=None):
|
||||
# print("search:", search)
|
||||
data = {}
|
||||
dirnames = []
|
||||
filenames = []
|
||||
|
||||
count = 0
|
||||
max_limit = 3000
|
||||
|
||||
for d_list in os.walk(path):
|
||||
if count >= max_limit:
|
||||
break
|
||||
|
||||
for d in d_list[1]:
|
||||
if count >= max_limit:
|
||||
break
|
||||
if d.lower().find(search) != -1:
|
||||
filename = d_list[0] + '/' + d
|
||||
if not os.path.exists(filename):
|
||||
continue
|
||||
dirnames.append(self.__get_stats(filename, path))
|
||||
count += 1
|
||||
|
||||
for f in d_list[2]:
|
||||
if count >= max_limit:
|
||||
break
|
||||
|
||||
if f.lower().find(search) != -1:
|
||||
filename = d_list[0] + '/' + f
|
||||
if not os.path.exists(filename):
|
||||
continue
|
||||
filenames.append(self.__get_stats(filename, path))
|
||||
count += 1
|
||||
|
||||
data['DIR'] = sorted(dirnames)
|
||||
data['FILES'] = sorted(filenames)
|
||||
data['PATH'] = path.replace('//', '/')
|
||||
|
||||
info = {}
|
||||
info['count'] = len(dirnames) + len(filenames)
|
||||
info['row'] = page_size
|
||||
info['p'] = page
|
||||
info['tojs'] = 'getFiles'
|
||||
pageObj = mw.getPageObject(info, '1,2,3,4,5,6,7,8')
|
||||
data['PAGE'] = pageObj[0]
|
||||
|
||||
return mw.getJson(data)
|
||||
|
||||
def getDir(self, path, page=1, page_size=10, search=None):
|
||||
data = {}
|
||||
dirnames = []
|
||||
@@ -861,31 +970,14 @@ class files_api:
|
||||
continue
|
||||
try:
|
||||
filePath = path + '/' + filename
|
||||
link = ''
|
||||
if os.path.islink(filePath):
|
||||
filePath = os.readlink(filePath)
|
||||
link = ' -> ' + filePath
|
||||
if not os.path.exists(filePath):
|
||||
filePath = path + '/' + filePath
|
||||
if not os.path.exists(filePath):
|
||||
continue
|
||||
if not os.path.exists(filePath):
|
||||
continue
|
||||
|
||||
stat = os.stat(filePath)
|
||||
accept = str(oct(stat.st_mode)[-3:])
|
||||
mtime = str(int(stat.st_mtime))
|
||||
user = ''
|
||||
try:
|
||||
user = pwd.getpwuid(stat.st_uid).pw_name
|
||||
except Exception as ee:
|
||||
user = str(stat.st_uid)
|
||||
|
||||
size = str(stat.st_size)
|
||||
file_stats = self.__get_stats(filePath, path)
|
||||
if os.path.isdir(filePath):
|
||||
dirnames.append(filename + ';' + size + ';' +
|
||||
mtime + ';' + accept + ';' + user + ';' + link)
|
||||
dirnames.append(file_stats)
|
||||
else:
|
||||
filenames.append(filename + ';' + size + ';' +
|
||||
mtime + ';' + accept + ';' + user + ';' + link)
|
||||
filenames.append(file_stats)
|
||||
n += 1
|
||||
except Exception as e:
|
||||
continue
|
||||
@@ -894,3 +986,55 @@ class files_api:
|
||||
data['PATH'] = path.replace('//', '/')
|
||||
|
||||
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:
|
||||
stat = os.stat(filename)
|
||||
accept = str(oct(stat.st_mode)[-3:])
|
||||
mtime = str(int(stat.st_mtime))
|
||||
user = ''
|
||||
try:
|
||||
user = str(pwd.getpwuid(stat.st_uid).pw_name)
|
||||
except:
|
||||
user = str(stat.st_uid)
|
||||
size = str(stat.st_size)
|
||||
link = ''
|
||||
if os.path.islink(filename):
|
||||
link = ' -> ' + os.readlink(filename)
|
||||
|
||||
if path:
|
||||
tmp_path = (path + '/').replace('//', '/')
|
||||
filename = filename.replace(tmp_path, '', 1)
|
||||
|
||||
return filename + ';' + size + ';' + mtime + ';' + accept + ';' + user + ';' + link
|
||||
except Exception as e:
|
||||
# print(e)
|
||||
return ';;;;;'
|
||||
|
||||
+86
-64
@@ -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):
|
||||
@@ -342,29 +340,52 @@ class firewall_api:
|
||||
status = request.form.get('status', '1')
|
||||
return mw.getJson(self.setFw(status))
|
||||
|
||||
def setFwIptables(self, status):
|
||||
# iptables特殊处理
|
||||
if status == '1':
|
||||
mw.execShell('service iptables save')
|
||||
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):
|
||||
cmd = 'iptables -I INPUT -s ' + port + ' -j DROP'
|
||||
mw.execShell(cmd)
|
||||
else:
|
||||
self.addAcceptPort(port)
|
||||
|
||||
mw.execShell('service iptables save')
|
||||
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:
|
||||
mw.execShell('/etc/init.d/iptables save')
|
||||
mw.execShell('/etc/init.d/iptables stop')
|
||||
pass
|
||||
else:
|
||||
if self.__isUfw:
|
||||
mw.execShell("echo 'y'|sudo ufw enable")
|
||||
if self.__isFirewalld:
|
||||
mw.execShell("echo 'y'| ufw enable")
|
||||
elif self.__isFirewalld:
|
||||
mw.execShell('systemctl start firewalld.service')
|
||||
mw.execShell('systemctl enable firewalld.service')
|
||||
elif self.__isMac:
|
||||
pass
|
||||
else:
|
||||
mw.execShell('/etc/init.d/iptables save')
|
||||
mw.execShell('/etc/init.d/iptables restart')
|
||||
pass
|
||||
|
||||
return mw.returnData(True, '设置成功!')
|
||||
|
||||
@@ -422,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:
|
||||
elif self.__isIptables:
|
||||
mw.execShell('service iptables save')
|
||||
mw.execShell('service iptables restart')
|
||||
elif self.__isFirewalld:
|
||||
mw.execShell('firewall-cmd --reload')
|
||||
elif self.__isMac:
|
||||
pass
|
||||
else:
|
||||
mw.execShell('/etc/init.d/iptables save')
|
||||
mw.execShell('/etc/init.d/iptables restart')
|
||||
pass
|
||||
|
||||
def getFwStatus(self):
|
||||
if self.__isUfw:
|
||||
@@ -447,17 +469,17 @@ class firewall_api:
|
||||
if data[0].strip() == 'inactive':
|
||||
return False
|
||||
return True
|
||||
if self.__isFirewalld:
|
||||
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
|
||||
elif self.__isMac:
|
||||
return False
|
||||
else:
|
||||
cmd = "ps -ef|grep iptables |grep -v grep | awk '{print $2}'"
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return False
|
||||
return True
|
||||
return False
|
||||
|
||||
+650
-14
@@ -22,6 +22,8 @@ import hashlib
|
||||
import shlex
|
||||
import datetime
|
||||
import subprocess
|
||||
import glob
|
||||
|
||||
import re
|
||||
import db
|
||||
from random import Random
|
||||
@@ -80,6 +82,10 @@ def getPanelDataDir():
|
||||
return getRunDir() + '/data'
|
||||
|
||||
|
||||
def getPanelTmp():
|
||||
return getRunDir() + '/tmp'
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return getRootDir() + '/server'
|
||||
|
||||
@@ -123,6 +129,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')
|
||||
@@ -219,6 +242,23 @@ def isInstalledWeb():
|
||||
return False
|
||||
|
||||
|
||||
def isIpAddr(ip):
|
||||
check_ip = re.compile(
|
||||
'^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$')
|
||||
if check_ip.match(ip):
|
||||
return True
|
||||
else:
|
||||
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")
|
||||
|
||||
@@ -243,6 +283,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()
|
||||
@@ -445,16 +542,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)
|
||||
@@ -490,6 +638,18 @@ def backFile(file, act=None):
|
||||
execShell("cp -p {0} {1}".format(file, file + file_type))
|
||||
|
||||
|
||||
def removeBackFile(file, act=None):
|
||||
"""
|
||||
@name 删除备份配置文件
|
||||
@param file 需要删除备份文件
|
||||
@param act 如果存在,则还原默认配置
|
||||
"""
|
||||
file_type = "_bak"
|
||||
if act:
|
||||
file_type = "_def"
|
||||
execShell("rm -rf {0}".format(file + file_type))
|
||||
|
||||
|
||||
def restoreFile(file, act=None):
|
||||
"""
|
||||
@name 还原配置文件
|
||||
@@ -544,28 +704,75 @@ 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
|
||||
|
||||
|
||||
@@ -841,7 +1048,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 == '':
|
||||
@@ -850,7 +1057,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 == '':
|
||||
@@ -890,6 +1097,56 @@ def checkIp(ip):
|
||||
return False
|
||||
|
||||
|
||||
def getHost(port=False):
|
||||
from flask import request
|
||||
host_tmp = request.headers.get('host')
|
||||
if not host_tmp:
|
||||
if request.url_root:
|
||||
tmp = re.findall(r"(https|http)://([\w:\.-]+)", request.url_root)
|
||||
if tmp:
|
||||
host_tmp = tmp[0][1]
|
||||
if not host_tmp:
|
||||
host_tmp = getLocalIp() + ':' + readFile('data/port.pl').strip()
|
||||
try:
|
||||
if host_tmp.find(':') == -1:
|
||||
host_tmp += ':80'
|
||||
except:
|
||||
host_tmp = "127.0.0.1:8888"
|
||||
h = host_tmp.split(':')
|
||||
if port:
|
||||
return h[-1]
|
||||
return ':'.join(h[0:-1])
|
||||
|
||||
|
||||
def getClientIp():
|
||||
from flask import request
|
||||
return request.remote_addr.replace('::ffff:', '')
|
||||
|
||||
|
||||
def checkDomainPanel():
|
||||
tmp = getHost()
|
||||
domain = readFile('data/bind_domain.pl')
|
||||
port = readFile('data/port.pl').strip()
|
||||
|
||||
npid = getServerDir() + "/openresty/nginx/logs/nginx.pid"
|
||||
if not os.path.exists(npid):
|
||||
return False
|
||||
|
||||
nconf = getServerDir() + "/web_conf/nginx/vhost/panel.conf"
|
||||
if os.path.exists(nconf):
|
||||
port = "80"
|
||||
|
||||
if domain:
|
||||
client_ip = getClientIp()
|
||||
if client_ip in ['127.0.0.1', 'localhost', '::1']:
|
||||
return False
|
||||
if tmp.strip().lower() != domain.strip().lower():
|
||||
from flask import Flask, redirect, request, url_for
|
||||
to = "http://" + domain + ":" + str(port)
|
||||
return redirect(to, code=302)
|
||||
return False
|
||||
|
||||
|
||||
def createLinuxUser(user, group):
|
||||
execShell("groupadd {}".format(group))
|
||||
execShell('useradd -s /sbin/nologin -g {} {}'.format(user, group))
|
||||
@@ -925,6 +1182,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']
|
||||
@@ -1010,7 +1276,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'
|
||||
@@ -1196,6 +1462,10 @@ def toSize(size):
|
||||
return str(round(size, 2)) + ' ' + b
|
||||
|
||||
|
||||
def getPathSuffix(path):
|
||||
return os.path.splitext(path)[-1]
|
||||
|
||||
|
||||
def getMacAddress():
|
||||
# 获取mac
|
||||
import uuid
|
||||
@@ -1241,13 +1511,107 @@ def get_string_arr(t):
|
||||
t_arr.append(str(i) + str(j))
|
||||
return t_arr
|
||||
|
||||
# 转换时间
|
||||
|
||||
|
||||
def strfDate(sdate):
|
||||
return time.strftime('%Y-%m-%d', time.strptime(sdate, '%Y%m%d%H%M%S'))
|
||||
|
||||
|
||||
# 获取证书名称
|
||||
def getCertName(certPath):
|
||||
if not os.path.exists(certPath):
|
||||
return None
|
||||
try:
|
||||
import OpenSSL
|
||||
result = {}
|
||||
x509 = OpenSSL.crypto.load_certificate(
|
||||
OpenSSL.crypto.FILETYPE_PEM, readFile(certPath))
|
||||
# 取产品名称
|
||||
issuer = x509.get_issuer()
|
||||
result['issuer'] = ''
|
||||
if hasattr(issuer, 'CN'):
|
||||
result['issuer'] = issuer.CN
|
||||
if not result['issuer']:
|
||||
is_key = [b'0', '0']
|
||||
issue_comp = issuer.get_components()
|
||||
if len(issue_comp) == 1:
|
||||
is_key = [b'CN', 'CN']
|
||||
for iss in issue_comp:
|
||||
if iss[0] in is_key:
|
||||
result['issuer'] = iss[1].decode()
|
||||
break
|
||||
if not result['issuer']:
|
||||
if hasattr(issuer, 'O'):
|
||||
result['issuer'] = issuer.O
|
||||
# 取到期时间
|
||||
result['notAfter'] = strfDate(
|
||||
bytes.decode(x509.get_notAfter())[:-1])
|
||||
# 取申请时间
|
||||
result['notBefore'] = strfDate(
|
||||
bytes.decode(x509.get_notBefore())[:-1])
|
||||
# 取可选名称
|
||||
result['dns'] = []
|
||||
for i in range(x509.get_extension_count()):
|
||||
s_name = x509.get_extension(i)
|
||||
if s_name.get_short_name() in [b'subjectAltName', 'subjectAltName']:
|
||||
s_dns = str(s_name).split(',')
|
||||
for d in s_dns:
|
||||
result['dns'].append(d.split(':')[1])
|
||||
subject = x509.get_subject().get_components()
|
||||
# 取主要认证名称
|
||||
if len(subject) == 1:
|
||||
result['subject'] = subject[0][1].decode()
|
||||
else:
|
||||
if not result['dns']:
|
||||
for sub in subject:
|
||||
if sub[0] == b'CN':
|
||||
result['subject'] = sub[1].decode()
|
||||
break
|
||||
if 'subject' in result:
|
||||
result['dns'].append(result['subject'])
|
||||
else:
|
||||
result['subject'] = result['dns'][0]
|
||||
result['endtime'] = int(int(time.mktime(time.strptime(
|
||||
result['notAfter'], "%Y-%m-%d")) - time.time()) / 86400)
|
||||
return result
|
||||
except Exception as e:
|
||||
writeFileLog(getTracebackInfo())
|
||||
return None
|
||||
|
||||
|
||||
def createSSL():
|
||||
# 自签证书
|
||||
if os.path.exists('ssl/input.pl'):
|
||||
return True
|
||||
import OpenSSL
|
||||
key = OpenSSL.crypto.PKey()
|
||||
key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048)
|
||||
cert = OpenSSL.crypto.X509()
|
||||
cert.set_serial_number(0)
|
||||
cert.get_subject().CN = getLocalIp()
|
||||
cert.set_issuer(cert.get_subject())
|
||||
cert.gmtime_adj_notBefore(0)
|
||||
cert.gmtime_adj_notAfter(86400 * 3650)
|
||||
cert.set_pubkey(key)
|
||||
cert.sign(key, 'md5')
|
||||
cert_ca = OpenSSL.crypto.dump_certificate(
|
||||
OpenSSL.crypto.FILETYPE_PEM, cert)
|
||||
private_key = OpenSSL.crypto.dump_privatekey(
|
||||
OpenSSL.crypto.FILETYPE_PEM, key)
|
||||
if len(cert_ca) > 100 and len(private_key) > 100:
|
||||
writeFile('ssl/cert.pem', cert_ca, 'wb+')
|
||||
writeFile('ssl/private.pem', private_key, 'wb+')
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def getSSHPort():
|
||||
try:
|
||||
file = '/etc/ssh/sshd_config'
|
||||
conf = readFile(file)
|
||||
rep = "#*Port\s+([0-9]+)\s*\n"
|
||||
port = re.search(rep, conf).groups(0)[0]
|
||||
rep = "(#*)?Port\s+([0-9]+)\s*\n"
|
||||
port = re.search(rep, conf).groups(0)[1]
|
||||
return int(port)
|
||||
except:
|
||||
return 22
|
||||
@@ -1309,3 +1673,275 @@ def getMyORMDb():
|
||||
import ormDb
|
||||
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']
|
||||
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 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)
|
||||
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
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def echoStart(tag):
|
||||
print("=" * 90)
|
||||
print("★开始{}[{}]".format(tag, formatDate()))
|
||||
print("=" * 90)
|
||||
|
||||
|
||||
def echoEnd(tag):
|
||||
print("=" * 90)
|
||||
print("☆{}完成[{}]".format(tag, formatDate()))
|
||||
print("=" * 90)
|
||||
print("\n")
|
||||
|
||||
|
||||
def echoInfo(msg):
|
||||
print("|-{}".format(msg))
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 打印相关 END
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
+83
-17
@@ -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']:
|
||||
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']:
|
||||
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
|
||||
|
||||
+198
-114
@@ -72,20 +72,44 @@ 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')
|
||||
p = request.form.get('p', '1')
|
||||
type_id = request.form.get('type_id', '')
|
||||
type_id = request.form.get('type_id', '0').strip()
|
||||
|
||||
start = (int(p) - 1) * (int(limit))
|
||||
|
||||
siteM = mw.M('sites')
|
||||
if type_id != '' and type_id == '-1' and type_id == '0':
|
||||
siteM.where('type_id=?', (type_id))
|
||||
siteM = mw.M('sites').field('id,name,path,status,ps,addtime,edate')
|
||||
if type_id != '' and int(type_id) >= 0:
|
||||
siteM.where('type_id=?', (type_id,))
|
||||
|
||||
_list = siteM.field('id,name,path,status,ps,addtime,edate').limit(
|
||||
(str(start)) + ',' + limit).order('id desc').select()
|
||||
_list = siteM.limit((str(start)) + ',' +
|
||||
limit).order('id desc').select()
|
||||
|
||||
for i in range(len(_list)):
|
||||
_list[i]['backup_count'] = mw.M('backup').where(
|
||||
@@ -139,6 +163,62 @@ class site_api:
|
||||
data['default_site'] = mw.readFile('data/default_site.pl')
|
||||
return mw.getJson(data)
|
||||
|
||||
def getCliPhpVersionApi(self):
|
||||
php_dir = mw.getServerDir() + '/php'
|
||||
if not os.path.exists(php_dir):
|
||||
return mw.returnJson(False, '未安装PHP,无法设置')
|
||||
|
||||
php_bin = '/usr/bin/php'
|
||||
php_versions = self.getPhpVersion()
|
||||
php_versions = php_versions[1:]
|
||||
|
||||
if len(php_versions) < 1:
|
||||
return mw.returnJson(False, '未安装PHP,无法设置')
|
||||
|
||||
if os.path.exists(php_bin) and os.path.islink(php_bin):
|
||||
link_re = os.readlink(php_bin)
|
||||
for v in php_versions:
|
||||
if link_re.find(v['version']) != -1:
|
||||
return mw.getJson({"select": v, "versions": php_versions})
|
||||
|
||||
return mw.getJson({
|
||||
"select": php_versions[0],
|
||||
"versions": php_versions})
|
||||
|
||||
def setCliPhpVersionApi(self):
|
||||
if mw.isAppleSystem():
|
||||
return mw.returnJson(False, "开发机不可设置!")
|
||||
|
||||
version = request.form.get('version', '')
|
||||
|
||||
php_bin = '/usr/bin/php'
|
||||
php_bin_src = "/www/server/php/%s/bin/php" % version
|
||||
php_ize = '/usr/bin/phpize'
|
||||
php_ize_src = "/www/server/php/%s/bin/phpize" % version
|
||||
php_fpm = '/usr/bin/php-fpm'
|
||||
php_fpm_src = "/www/server/php/%s/sbin/php-fpm" % version
|
||||
php_pecl = '/usr/bin/pecl'
|
||||
php_pecl_src = "/www/server/php/%s/bin/pecl" % version
|
||||
php_pear = '/usr/bin/pear'
|
||||
php_pear_src = "/www/server/php/%s/bin/pear" % version
|
||||
if not os.path.exists(php_bin_src):
|
||||
return mw.returnJson(False, '指定PHP版本未安装!')
|
||||
|
||||
is_chattr = mw.execShell('lsattr /usr|grep /usr/bin')[0].find('-i-')
|
||||
if is_chattr != -1:
|
||||
mw.execShell('chattr -i /usr/bin')
|
||||
mw.execShell("rm -f " + php_bin + ' ' + php_ize + ' ' +
|
||||
php_fpm + ' ' + php_pecl + ' ' + php_pear)
|
||||
mw.execShell("ln -sf %s %s" % (php_bin_src, php_bin))
|
||||
mw.execShell("ln -sf %s %s" % (php_ize_src, php_ize))
|
||||
mw.execShell("ln -sf %s %s" % (php_fpm_src, php_fpm))
|
||||
mw.execShell("ln -sf %s %s" % (php_pecl_src, php_pecl))
|
||||
mw.execShell("ln -sf %s %s" % (php_pear_src, php_pear))
|
||||
if is_chattr != -1:
|
||||
mw.execShell('chattr +i /usr/bin')
|
||||
mw.writeLog('面板设置', '设置PHP-CLI版本为: %s' % version)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
def setPsApi(self):
|
||||
mid = request.form.get('id', '')
|
||||
ps = request.form.get('ps', '')
|
||||
@@ -266,7 +346,8 @@ class site_api:
|
||||
return mw.returnJson(True, '站点删除成功!')
|
||||
|
||||
def getPhpVersionApi(self):
|
||||
return self.getPhpVersion()
|
||||
data = self.getPhpVersion()
|
||||
return mw.getJson(data)
|
||||
|
||||
def setPhpVersionApi(self):
|
||||
siteName = request.form.get('siteName', '')
|
||||
@@ -493,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, '使用中,先关闭再删除')
|
||||
@@ -530,13 +611,13 @@ 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)
|
||||
cert_data = self.getCertName(csr_path)
|
||||
cert_data = mw.getCertName(csr_path)
|
||||
data = {
|
||||
'status': status,
|
||||
'domain': domains,
|
||||
@@ -760,9 +841,9 @@ class site_api:
|
||||
if not len(domains):
|
||||
return mw.returnJson(False, '请选择域名')
|
||||
|
||||
file = self.getHostConf(siteName)
|
||||
if os.path.exists(file):
|
||||
siteConf = mw.readFile(file)
|
||||
host_conf_file = self.getHostConf(siteName)
|
||||
if os.path.exists(host_conf_file):
|
||||
siteConf = mw.readFile(host_conf_file)
|
||||
if siteConf.find('301-END') != -1:
|
||||
return mw.returnJson(False, '检测到您的站点做了301重定向设置,请先关闭重定向!')
|
||||
|
||||
@@ -780,25 +861,21 @@ class site_api:
|
||||
if os.path.exists(proxy_dir_file):
|
||||
return mw.returnJson(False, '检测到您的站点做了反向代理设置,请先关闭反向代理!')
|
||||
|
||||
auth_to = self.getSitePath(siteName)
|
||||
# fix binddir domain ssl apply question
|
||||
mw.backFile(host_conf_file)
|
||||
auth_to = self.getSitePath(siteName)
|
||||
rep = "\s*root\s*(.+);"
|
||||
replace_root = "\n\troot " + auth_to + ";"
|
||||
siteConf = re.sub(rep, replace_root, siteConf)
|
||||
mw.writeFile(host_conf_file, siteConf)
|
||||
mw.restartWeb()
|
||||
|
||||
to_args = {
|
||||
'domains': domains,
|
||||
'auth_type': 'http',
|
||||
'auth_to': auth_to,
|
||||
}
|
||||
|
||||
import cert_api
|
||||
data = cert_api.cert_api().applyCertApi(to_args)
|
||||
|
||||
if not data['status']:
|
||||
msg = data['msg']
|
||||
if type(data['msg']) != str:
|
||||
msg = data['msg'][0]
|
||||
emsg = data['msg'][1]['challenges'][0]['error']
|
||||
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'])
|
||||
|
||||
src_letpath = mw.getServerDir() + '/web_conf/letsencrypt/' + siteName
|
||||
src_csrpath = src_letpath + "/fullchain.pem" # 生成证书路径
|
||||
src_keypath = src_letpath + "/privkey.pem" # 密钥文件路径
|
||||
@@ -807,11 +884,23 @@ class site_api:
|
||||
dst_csrpath = dst_letpath + '/fullchain.pem'
|
||||
dst_keypath = dst_letpath + '/privkey.pem'
|
||||
|
||||
if not os.path.exists(dst_letpath):
|
||||
mw.execShell('mkdir -p ' + dst_letpath)
|
||||
mw.buildSoftLink(src_csrpath, dst_csrpath, True)
|
||||
mw.buildSoftLink(src_keypath, dst_keypath, True)
|
||||
mw.execShell('echo "lets" > "' + dst_letpath + '/README"')
|
||||
if not os.path.exists(src_letpath):
|
||||
import cert_api
|
||||
data = cert_api.cert_api().applyCertApi(to_args)
|
||||
mw.restoreFile(host_conf_file)
|
||||
if not data['status']:
|
||||
msg = data['msg']
|
||||
if type(data['msg']) != str:
|
||||
msg = data['msg'][0]
|
||||
emsg = data['msg'][1]['challenges'][0]['error']
|
||||
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'])
|
||||
|
||||
mw.execShell('mkdir -p ' + dst_letpath)
|
||||
mw.buildSoftLink(src_csrpath, dst_csrpath, True)
|
||||
mw.buildSoftLink(src_keypath, dst_keypath, True)
|
||||
mw.execShell('echo "lets" > "' + dst_letpath + '/README"')
|
||||
|
||||
# 写入配置文件
|
||||
result = self.setSslConf(siteName)
|
||||
@@ -820,6 +909,8 @@ class site_api:
|
||||
|
||||
result['csr'] = mw.readFile(src_csrpath)
|
||||
result['key'] = mw.readFile(src_keypath)
|
||||
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(data['status'], data['msg'], result)
|
||||
|
||||
def getAcmeLogsApi(self):
|
||||
@@ -922,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]
|
||||
@@ -1062,6 +1154,26 @@ class site_api:
|
||||
host = self.getHostConf(siteName)
|
||||
return mw.getJson({'host': host})
|
||||
|
||||
def saveHostConfApi(self):
|
||||
path = request.form.get('path', '')
|
||||
data = request.form.get('data', '')
|
||||
encoding = request.form.get('encoding', '')
|
||||
|
||||
import files_api
|
||||
|
||||
mw.backFile(path)
|
||||
save_ret_data = files_api.files_api().saveBody(path, data, encoding)
|
||||
rdata = json.loads(save_ret_data)
|
||||
|
||||
if rdata['status']:
|
||||
isError = mw.checkWebConfig()
|
||||
if isError != True:
|
||||
mw.restoreFile(path)
|
||||
return mw.returnJson(False, 'ERROR: 检测到配置文件有错误,请先排除后再操作<br><br><a style="color:red;">' + isError.replace("\n", '<br>') + '</a>')
|
||||
mw.restartWeb()
|
||||
mw.removeBackFile(path)
|
||||
return save_ret_data
|
||||
|
||||
def getRewriteConfApi(self):
|
||||
siteName = request.form.get('siteName', '')
|
||||
rewrite = self.getRewriteConf(siteName)
|
||||
@@ -1155,14 +1267,26 @@ class site_api:
|
||||
return mw.returnJson(False, '端口范围不合法!')
|
||||
|
||||
opid = mw.M('domain').where(
|
||||
"name=? AND (port=? OR pid=?)", (domain, domain_port, pid)).getField('pid')
|
||||
if opid:
|
||||
if mw.M('sites').where('id=?', (opid,)).count():
|
||||
return mw.returnJson(False, '指定域名已绑定过!')
|
||||
mw.M('domain').where('pid=?', (opid,)).delete()
|
||||
"name=? AND (port=? OR pid=?)", (domain_name, domain_port, pid,)).getField('pid')
|
||||
# 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, '指定域名已绑定过!')
|
||||
# mw.M('domain').where('pid=?', (opid,)).delete()
|
||||
|
||||
if mw.M('binding').where('domain=?', (domain,)).count():
|
||||
return mw.returnJson(False, '您添加的域名已存在!')
|
||||
return mw.returnJson(False, '您添加的域名,子目录已绑定!')
|
||||
|
||||
self.nginxAddDomain(webname, domain_name, domain_port)
|
||||
|
||||
@@ -1172,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):
|
||||
@@ -1214,17 +1339,18 @@ class site_api:
|
||||
content = content.replace('{$ROOT_DIR}', webdir)
|
||||
content = content.replace('{$SERVER_MAIN}', siteInfo['name'])
|
||||
content = content.replace('{$OR_REWRITE}', self.rewritePath)
|
||||
content = content.replace('{$PHP_DIR}', self.setupPath + '/php')
|
||||
content = content.replace('{$LOGPATH}', mw.getLogsDir())
|
||||
|
||||
conf += "\r\n" + content
|
||||
shutil.copyfile(filename, '/tmp/backup.conf')
|
||||
mw.backFile(filename)
|
||||
mw.writeFile(filename, conf)
|
||||
conf = mw.readFile(filename)
|
||||
|
||||
# 检查配置是否有误
|
||||
isError = mw.checkWebConfig()
|
||||
if isError != True:
|
||||
shutil.copyfile('/tmp/backup.conf', filename)
|
||||
mw.restoreFile(filename)
|
||||
return mw.returnJson(False, 'ERROR: <br><a style="color:red;">' + isError.replace("\n", '<br>') + '</a>')
|
||||
|
||||
mw.M('binding').add('pid,domain,port,path,addtime',
|
||||
@@ -1234,6 +1360,7 @@ class site_api:
|
||||
(siteInfo['name'], dirName, domain))
|
||||
mw.writeLog('网站管理', msg)
|
||||
mw.restartWeb()
|
||||
mw.removeBackFile(filename)
|
||||
return mw.returnJson(True, '添加成功!')
|
||||
|
||||
def delDirBindApi(self):
|
||||
@@ -1299,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', '')
|
||||
@@ -2311,7 +2438,7 @@ location ^~ {from} {\n\
|
||||
tmp['name'] = 'PHP-' + matchVer
|
||||
data.append(tmp)
|
||||
|
||||
return mw.getJson(data)
|
||||
return data
|
||||
|
||||
# 是否跳转到https
|
||||
def isToHttps(self, siteName):
|
||||
@@ -2428,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):
|
||||
@@ -2487,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):
|
||||
@@ -2529,7 +2678,6 @@ location ^~ {from} {\n\
|
||||
conf = conf.replace(listen, listen + http_ssl)
|
||||
|
||||
mw.backFile(file)
|
||||
|
||||
mw.writeFile(file, conf)
|
||||
isError = mw.checkWebConfig()
|
||||
if(isError != True):
|
||||
@@ -2546,7 +2694,7 @@ location ^~ {from} {\n\
|
||||
|
||||
def saveCert(self, keyPath, certPath):
|
||||
try:
|
||||
certInfo = self.getCertName(certPath)
|
||||
certInfo = mw.getCertName(certPath)
|
||||
if not certInfo:
|
||||
return mw.returnData(False, '证书解析失败!')
|
||||
vpath = self.sslDir + '/' + certInfo['subject'].strip()
|
||||
@@ -2559,70 +2707,6 @@ location ^~ {from} {\n\
|
||||
except Exception as e:
|
||||
return mw.returnData(False, '证书保存失败!')
|
||||
|
||||
# 转换时间
|
||||
def strfDate(self, sdate):
|
||||
return time.strftime('%Y-%m-%d', time.strptime(sdate, '%Y%m%d%H%M%S'))
|
||||
|
||||
# 获取证书名称
|
||||
def getCertName(self, certPath):
|
||||
if not os.path.exists(certPath):
|
||||
return None
|
||||
try:
|
||||
import OpenSSL
|
||||
result = {}
|
||||
x509 = OpenSSL.crypto.load_certificate(
|
||||
OpenSSL.crypto.FILETYPE_PEM, mw.readFile(certPath))
|
||||
# 取产品名称
|
||||
issuer = x509.get_issuer()
|
||||
result['issuer'] = ''
|
||||
if hasattr(issuer, 'CN'):
|
||||
result['issuer'] = issuer.CN
|
||||
if not result['issuer']:
|
||||
is_key = [b'0', '0']
|
||||
issue_comp = issuer.get_components()
|
||||
if len(issue_comp) == 1:
|
||||
is_key = [b'CN', 'CN']
|
||||
for iss in issue_comp:
|
||||
if iss[0] in is_key:
|
||||
result['issuer'] = iss[1].decode()
|
||||
break
|
||||
if not result['issuer']:
|
||||
if hasattr(issuer, 'O'):
|
||||
result['issuer'] = issuer.O
|
||||
# 取到期时间
|
||||
result['notAfter'] = self.strfDate(
|
||||
bytes.decode(x509.get_notAfter())[:-1])
|
||||
# 取申请时间
|
||||
result['notBefore'] = self.strfDate(
|
||||
bytes.decode(x509.get_notBefore())[:-1])
|
||||
# 取可选名称
|
||||
result['dns'] = []
|
||||
for i in range(x509.get_extension_count()):
|
||||
s_name = x509.get_extension(i)
|
||||
if s_name.get_short_name() in [b'subjectAltName', 'subjectAltName']:
|
||||
s_dns = str(s_name).split(',')
|
||||
for d in s_dns:
|
||||
result['dns'].append(d.split(':')[1])
|
||||
subject = x509.get_subject().get_components()
|
||||
# 取主要认证名称
|
||||
if len(subject) == 1:
|
||||
result['subject'] = subject[0][1].decode()
|
||||
else:
|
||||
if not result['dns']:
|
||||
for sub in subject:
|
||||
if sub[0] == b'CN':
|
||||
result['subject'] = sub[1].decode()
|
||||
break
|
||||
if 'subject' in result:
|
||||
result['dns'].append(result['subject'])
|
||||
else:
|
||||
result['subject'] = result['dns'][0]
|
||||
result['endtime'] = int(int(time.mktime(time.strptime(
|
||||
result['notAfter'], "%Y-%m-%d")) - time.time()) / 86400)
|
||||
return result
|
||||
except:
|
||||
return None
|
||||
|
||||
# 清除多余user.ini
|
||||
def delUserInI(self, path, up=0):
|
||||
for p1 in os.listdir(path):
|
||||
|
||||
@@ -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, '安装更新成功!')
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -17,7 +17,7 @@ server
|
||||
#ERROR-PAGE-END
|
||||
|
||||
#PHP-INFO-START
|
||||
include enable-php-{$PHPVER}.conf;
|
||||
include {$PHP_DIR}/conf/enable-php-{$PHPVER}.conf;
|
||||
#PHP-INFO-END
|
||||
|
||||
#REWRITE-START
|
||||
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
server
|
||||
{
|
||||
listen {$PORT};
|
||||
listen [::]:{$PORT};
|
||||
|
||||
server_name {$SERVER_NAME};
|
||||
index index.php index.html index.htm default.php default.htm default.html;
|
||||
|
||||
#SSL-START
|
||||
#error_page 404/404.html;
|
||||
#SSL-END
|
||||
|
||||
#PROXY-START
|
||||
location ^~ / {
|
||||
proxy_pass http://0.0.0.0:{$PANAL_PORT}/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
}
|
||||
#PROXY-END
|
||||
|
||||
error_log {$LOGPATH}/{$SERVER_NAME}.error.log;
|
||||
}
|
||||
@@ -80,11 +80,13 @@ class FtpPSClient:
|
||||
return default_config
|
||||
|
||||
def injection_config(self, data):
|
||||
host = data["ftp_host"].strip()
|
||||
self.__host = host = data["ftp_host"].strip()
|
||||
if host.find(':') == -1:
|
||||
self.__port = self.default_port
|
||||
else:
|
||||
self.__host = host.split(':')[0]
|
||||
self.__port = host.split(':')[1]
|
||||
|
||||
self.__host = data['ftp_host'].strip()
|
||||
self.__user = data['ftp_user'].strip()
|
||||
self.__password = data['ftp_pass'].strip()
|
||||
bp = data['backup_path'].strip()
|
||||
|
||||
+26
-15
@@ -57,9 +57,8 @@ def getArgs():
|
||||
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
|
||||
|
||||
|
||||
@@ -180,34 +179,46 @@ def backupAllFunc(stype):
|
||||
name = sys.argv[2]
|
||||
num = sys.argv[3]
|
||||
|
||||
args = stype + " " + name + " " + num
|
||||
|
||||
cmd = 'python3 ' + mw.getRunDir() + '/scripts/backup.py ' + args
|
||||
os.system(cmd)
|
||||
|
||||
# 开始执行上传信息
|
||||
|
||||
prefix_dict = {
|
||||
"site": "web",
|
||||
"database": "db",
|
||||
"path": "path",
|
||||
}
|
||||
|
||||
find_path = mw.getBackupDir() + '/' + stype + '/' + \
|
||||
prefix_dict[stype] + '_' + name
|
||||
args = stype + " " + name + " " + num
|
||||
cmd = 'python3 ' + mw.getRunDir() + '/scripts/backup.py ' + args
|
||||
if stype.find('database_') > -1:
|
||||
plugin_name = stype.replace('database_', '')
|
||||
args = "database " + name + " " + num
|
||||
cmd = 'python3 ' + mw.getRunDir() + '/plugins/' + plugin_name + \
|
||||
'/scripts/backup.py ' + args
|
||||
|
||||
os.system(cmd)
|
||||
|
||||
# 开始执行上传信息.
|
||||
|
||||
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 + \
|
||||
"_* | grep '.gz' | cut -d \ -f 1 | awk 'END {print}'"
|
||||
|
||||
filename = mw.execShell(find_new_file)[0].strip()
|
||||
if filename == "":
|
||||
print("not find upload file!")
|
||||
mw.echoInfo("not find upload file!")
|
||||
return False
|
||||
|
||||
print("|-准备上传文件 {}".format(filename))
|
||||
ftp = FtpPSClient()
|
||||
ftp.uploadFile(filename, stype)
|
||||
|
||||
return True
|
||||
return ''
|
||||
|
||||
|
||||
def backupSite():
|
||||
@@ -251,7 +262,7 @@ if __name__ == "__main__":
|
||||
print(deleteDir())
|
||||
elif func == 'delete_file':
|
||||
print(deleteFile())
|
||||
elif in_array(func, ['site', 'database', 'path']):
|
||||
elif in_array(func, ['site', 'database', 'path']) or func.find('database_') > -1:
|
||||
print(backupAllFunc(func))
|
||||
else:
|
||||
print('error')
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -10,6 +10,7 @@ GIT_PROJECT_DIR="${GIT_USER_DIR}/{$PROJECT}"
|
||||
|
||||
|
||||
git config --global credential.helper store
|
||||
git config --global pull.rebase false
|
||||
|
||||
# echo $GIT_PROJECT_DIR
|
||||
if [ ! -d $GIT_PROJECT_DIR ];then
|
||||
@@ -18,6 +19,7 @@ if [ ! -d $GIT_PROJECT_DIR ];then
|
||||
fi
|
||||
|
||||
unset GIT_DIR
|
||||
|
||||
cd $GIT_PROJECT_DIR && git pull
|
||||
|
||||
# func 2
|
||||
@@ -26,9 +28,17 @@ cd $GIT_PROJECT_DIR && git pull
|
||||
|
||||
#更新的目的地址
|
||||
WEB_PATH={$WEB_ROOT}/{$USERNAME}/{$PROJECT}
|
||||
mkdir -p $WEB_PATH
|
||||
|
||||
rsync -vauP --delete --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
if [ ! -d $WEB_PATH ];then
|
||||
mkdir -p $WEB_PATH
|
||||
rsync -vauP --delete --exclude=".*" $GIT_PROJECT_DIR/ $WEB_PATH
|
||||
else
|
||||
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`
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
|
||||
@@ -15,6 +15,8 @@ if [ ! -d $GIT_PROJECT_DIR ];then
|
||||
fi
|
||||
|
||||
unset GIT_DIR
|
||||
git config pull.rebase false
|
||||
|
||||
cd $GIT_PROJECT_DIR && git pull
|
||||
|
||||
# func 2
|
||||
|
||||
@@ -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">
|
||||
|
||||
+25
-7
@@ -101,7 +101,7 @@ def getHomeDir():
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return '/Users/' + user
|
||||
else:
|
||||
return 'git'
|
||||
return 'www'
|
||||
|
||||
|
||||
def getRunUser():
|
||||
@@ -110,7 +110,7 @@ def getRunUser():
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return user
|
||||
else:
|
||||
return 'git'
|
||||
return 'www'
|
||||
|
||||
__SR = '''#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
@@ -135,6 +135,10 @@ def initDreplace():
|
||||
file_tpl = getInitdConfTpl()
|
||||
service_path = mw.getServerDir()
|
||||
|
||||
git_dir = mw.getServerDir() + '/git'
|
||||
if not os.path.exists(git_dir):
|
||||
mw.execShell('mkdir -p ' + git_dir)
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
@@ -445,7 +449,7 @@ def submitGogsConf():
|
||||
val = g + ' = ' + args[g]
|
||||
conf = re.sub(rep, val, conf)
|
||||
mw.writeFile(filename, conf)
|
||||
reload()
|
||||
restart()
|
||||
return mw.returnJson(True, '设置成功')
|
||||
|
||||
|
||||
@@ -515,7 +519,7 @@ def checkProjectListIsHasScript(user, data):
|
||||
path = getRootPath() + '/' + user
|
||||
for x in range(len(data)):
|
||||
name = data[x]['name'] + '.git'
|
||||
path_tmp = path + '/' + name + '/custom_hooks/post-receive'
|
||||
path_tmp = path + '/' + name + '/hooks/post-receive.d/post-receive'
|
||||
if os.path.exists(path_tmp):
|
||||
data[x]['has_hook'] = True
|
||||
else:
|
||||
@@ -556,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)
|
||||
|
||||
@@ -593,15 +597,17 @@ def projectScriptLoad():
|
||||
|
||||
path = getRootPath() + '/' + user + '/' + name
|
||||
post_receive_tpl = getPluginDir() + '/hook/post-receive.tpl'
|
||||
post_receive = path + '/custom_hooks/post-receive'
|
||||
post_receive = path + '/hooks/post-receive.d/post-receive'
|
||||
|
||||
if not os.path.exists(path + '/custom_hooks'):
|
||||
mw.execShell('mkdir -p ' + path + '/custom_hooks')
|
||||
mw.execShell('chown -R www:www ' + path + '/custom_hooks')
|
||||
|
||||
pct_content = mw.readFile(post_receive_tpl)
|
||||
pct_content = pct_content.replace('{$PATH}', path + '/custom_hooks')
|
||||
mw.writeFile(post_receive, pct_content)
|
||||
mw.execShell('chmod 777 ' + post_receive)
|
||||
mw.execShell('chown -R www:www ' + post_receive)
|
||||
|
||||
commit_tpl = getPluginDir() + '/hook/commit.tpl'
|
||||
commit = path + '/custom_hooks/commit'
|
||||
@@ -618,6 +624,7 @@ def projectScriptLoad():
|
||||
cc_content = cc_content.replace('{$WEB_ROOT}', mw.getWwwDir())
|
||||
mw.writeFile(commit, cc_content)
|
||||
mw.execShell('chmod 777 ' + commit)
|
||||
mw.execShell('chown -R www:www ' + commit)
|
||||
|
||||
return 'ok'
|
||||
|
||||
@@ -632,7 +639,7 @@ def projectScriptUnload():
|
||||
name = args['name'] + '.git'
|
||||
|
||||
post_receive = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/post-receive'
|
||||
'/hooks/post-receive.d/post-receive'
|
||||
mw.execShell('rm -f ' + post_receive)
|
||||
|
||||
commit = getRootPath() + '/' + user + '/' + name + \
|
||||
@@ -697,6 +704,15 @@ def getTotalStatistics():
|
||||
return mw.returnJson(False, 'fail', data)
|
||||
|
||||
|
||||
def uninstallPreInspection():
|
||||
repo_dir = getServerDir() + "/data/gitea-repositories"
|
||||
if not os.path.exists(repo_dir):
|
||||
return 'ok'
|
||||
dir_list = os.listdir(repo_dir)
|
||||
if len(dir_list) > 0:
|
||||
return "有项目数据!请手动删除Gitea<br/> rm -rf {}".format(getServerDir())
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
@@ -715,6 +731,8 @@ if __name__ == "__main__":
|
||||
print(initdInstall())
|
||||
elif func == 'initd_uninstall':
|
||||
print(initdUinstall())
|
||||
elif func == 'uninstall_pre_inspection':
|
||||
print(uninstallPreInspection())
|
||||
elif func == 'run_log':
|
||||
print(runLog())
|
||||
elif func == 'post_receive_log':
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
"title": "Gitea",
|
||||
"versions": ["1.17.2"],
|
||||
"tip": "soft",
|
||||
"install_pre_inspection":false,
|
||||
"uninstall_pre_inspection":true,
|
||||
"checks": "server/gitea",
|
||||
"path":"server/gitea",
|
||||
"author": "gitea",
|
||||
|
||||
@@ -6,12 +6,12 @@ After=network.target
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=simple
|
||||
User=git
|
||||
Group=git
|
||||
User=www
|
||||
Group=www
|
||||
WorkingDirectory={$SERVER_PATH}/gitea
|
||||
ExecStart={$SERVER_PATH}/gitea/gitea web
|
||||
Restart=always
|
||||
Environment=USER=git HOME=/home/git GITEA_WORK_DIR={$SERVER_PATH}/gitea
|
||||
Environment=USER=www HOME=/home/www GITEA_WORK_DIR={$SERVER_PATH}/gitea
|
||||
RemainAfterExit=yes
|
||||
#AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
|
||||
@@ -26,24 +26,39 @@ getBit(){
|
||||
echo `getconf LONG_BIT`
|
||||
}
|
||||
|
||||
Install_Rsync(){
|
||||
if [ "$OSNAME" == "debian" ] || [ "$OSNAME" == "ubuntu" ];then
|
||||
apt install -y rsync
|
||||
elif [[ "$OSNAME" == "arch" ]]; then
|
||||
echo y | pacman -Sy rsync
|
||||
elif [[ "$OSNAME" == "macos" ]]; then
|
||||
# brew install rsync
|
||||
# brew install lsyncd
|
||||
echo "ok"
|
||||
else
|
||||
yum install -y rsync
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Install_App()
|
||||
{
|
||||
Install_Rsync
|
||||
|
||||
mkdir -p $serverPath/source/gitea
|
||||
|
||||
if id git &> /dev/null ;then
|
||||
echo "git uid is `id -u git`"
|
||||
echo "git shell is `grep "^git:" /etc/passwd |cut -d':' -f7 `"
|
||||
if id www &> /dev/null ;then
|
||||
echo "www uid is `id -u www`"
|
||||
echo "www shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
|
||||
else
|
||||
groupadd git
|
||||
useradd -g git git
|
||||
groupadd www
|
||||
useradd -g www www
|
||||
fi
|
||||
|
||||
if [ "macos" != "$OSNAME" ];then
|
||||
if [ ! -d /home/git ];then
|
||||
mkdir -p /home/git
|
||||
chown -R git:git /home/git
|
||||
if [ ! -d /home/www ];then
|
||||
mkdir -p /home/www
|
||||
chown -R www:www /home/www
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -71,7 +86,7 @@ Install_App()
|
||||
mv $serverPath/source/gitea/$file $serverPath/gitea/gitea
|
||||
chmod +x $serverPath/gitea/gitea
|
||||
|
||||
chown -R git:git $serverPath/gitea
|
||||
chown -R www:www $serverPath/gitea
|
||||
fi
|
||||
|
||||
|
||||
|
||||
+67
-50
@@ -1,19 +1,9 @@
|
||||
|
||||
function str2Obj(str){
|
||||
var data = {};
|
||||
kv = str.split('&');
|
||||
for(i in kv){
|
||||
v = kv[i].split('=');
|
||||
data[v[0]] = v[1];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function gogsPost(method,args,callback, title){
|
||||
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(str2Obj(args));
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
@@ -186,6 +176,28 @@ function giteaUserList(page, search) {
|
||||
}
|
||||
|
||||
function userProjectList(user, search){
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '用户('+user+')项目列表',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div>\
|
||||
<div id='gitea_table' class='divtable' style='margin-top:5px;'>\
|
||||
<table class='table table-hover'>\
|
||||
<thead><tr><th>项目</th><th>操作</th></tr></thead>\
|
||||
<tbody></tbody>\
|
||||
</table>\
|
||||
<div class='dataTables_paginate paging_bootstrap pagination' style='margin-top:0px;'><ul class='page'><div class='gitea_page'></div></ul></div>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>",
|
||||
success:function(){
|
||||
userProjectListPost(user,search);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function userProjectListPost(user, search){
|
||||
var req = {};
|
||||
if (!isNaN(user)){
|
||||
req['page'] = user;
|
||||
@@ -201,8 +213,7 @@ function userProjectList(user, search){
|
||||
if(typeof(search) != 'undefined'){
|
||||
req['search'] = search;
|
||||
}
|
||||
|
||||
$('.layui-layer-close1').click();
|
||||
|
||||
gogsPost('user_project_list', req, function(data){
|
||||
var rdata = [];
|
||||
try {
|
||||
@@ -219,7 +230,8 @@ function userProjectList(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>\
|
||||
@@ -227,24 +239,10 @@ function userProjectList(user, search){
|
||||
</tr>';
|
||||
}
|
||||
|
||||
var page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata['data']['list'];
|
||||
page += '</div></ul></div>';
|
||||
$('#gitea_table tbody').html(list);
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '用户('+user+')项目列表',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div>\
|
||||
<div class='divtable' style='margin-top:5px;'>\
|
||||
<table class='table table-hover'>\
|
||||
<thead><tr><th>项目</th><th>操作</th></tr></thead>\
|
||||
<tbody>" + list + "</tbody>\
|
||||
</table>" +
|
||||
page +
|
||||
"</div></div></div>"
|
||||
});
|
||||
var page = rdata['data']['list'];
|
||||
$('#gitea_table .gitea_page').html(page);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -253,23 +251,41 @@ function projectScript(user, name,has_hook){
|
||||
// console.log(user,name,has_hook);
|
||||
var html = '';
|
||||
if (has_hook){
|
||||
html += '<button onclick="projectScriptEdit(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">手动编辑</button>';
|
||||
html += '<button onclick="projectScriptDebug(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">调试日志</button>';
|
||||
html += '<button onclick="projectScriptLoad(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">重新加载</button>';
|
||||
html += '<button onclick="projectScriptUnload(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">卸载脚本</button>';
|
||||
html += '<button class="btn btn-default btn-sm hook_edit">手动编辑</button>';
|
||||
html += '<button class="btn btn-default btn-sm hook_log">调试日志</button>';
|
||||
html += '<button class="btn btn-default btn-sm hook_load">重新加载</button>';
|
||||
html += '<button class="btn btn-default btn-sm hook_unload">卸载脚本</button>';
|
||||
} else {
|
||||
html += '<button onclick="projectScriptLoad(\''+user+'\',\''+name+'\')" class="btn btn-default btn-sm">加载脚本</button>';
|
||||
html += '<button class="btn btn-default btn-sm hook_load">加载脚本</button>';
|
||||
}
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '['+user+']['+name+']脚本设置',
|
||||
area: '240px',
|
||||
content:'<div class="change-default pd20">'+html+'</div>'
|
||||
content:'<div class="change-default pd20">'+html+'</div>',
|
||||
success:function(layero,index) {
|
||||
|
||||
$('.hook_edit').click(function(){
|
||||
projectScriptEdit(user,name,index);
|
||||
});
|
||||
|
||||
$('.hook_log').click(function(){
|
||||
projectScriptDebug(user,name,index);
|
||||
});
|
||||
|
||||
$('.hook_load').click(function(){
|
||||
projectScriptLoad(user,name,index);
|
||||
});
|
||||
|
||||
$('.hook_unload').click(function(){
|
||||
projectScriptUnload(user,name,index);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptEdit(user,name){
|
||||
function projectScriptEdit(user,name,index){
|
||||
gogsPost('project_script_edit', {'user':user,'name':name}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata['status']){
|
||||
@@ -280,41 +296,42 @@ function projectScriptEdit(user,name){
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptLoad(user,name){
|
||||
function projectScriptLoad(user,name,index){
|
||||
gogsPost('project_script_load', {'user':user,'name':name}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
layer.msg('加载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
setTimeout(function(){
|
||||
userProjectList(1);
|
||||
}, 2000);
|
||||
showMsg('加载成功!',function(){
|
||||
layer.close(index);
|
||||
userProjectListPost(1);
|
||||
},{icon:1,time:2000,shade: [0.3, '#000']},2000);
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptUnload(user,name){
|
||||
function projectScriptUnload(user,name,index){
|
||||
gogsPost('project_script_unload', {'user':user,'name':name}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
layer.msg('卸载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
setTimeout(function(){
|
||||
userProjectList(1);
|
||||
}, 2000);
|
||||
showMsg('卸载成功!',function(){
|
||||
layer.close(index);
|
||||
userProjectListPost(1);
|
||||
},{icon:1,time:2000,shade: [0.3, '#000']},2000);
|
||||
});
|
||||
}
|
||||
|
||||
function projectScriptDebug(user,name){
|
||||
function projectScriptDebug(user,name,index){
|
||||
gogsPost('project_script_debug', {'user':user,'name':name}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata['status']){
|
||||
onlineEditFile(0, rdata['path']);
|
||||
} else {
|
||||
layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
showMsg(rdata.msg,function(){
|
||||
},{icon:1,time:2000,shade: [0.3, '#000']},2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"sort": 7,
|
||||
"ps": "简单邮件服务[DEV]",
|
||||
"ps": "[<b style='color:red;'>DEV</b>]简单邮件服务",
|
||||
"name": "imail",
|
||||
"title": "邮件服务",
|
||||
"shell": "install.sh",
|
||||
|
||||
@@ -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`
|
||||
@@ -21,10 +21,13 @@ OSNAME_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F
|
||||
ARCH="amd64"
|
||||
|
||||
get_arch() {
|
||||
|
||||
TMP_ARCH=`arch`
|
||||
if [ "$TMP_ARCH" == "x86_64" ];then
|
||||
ARCH="amd64"
|
||||
elif [ "$TMP_ARCH" == "aarch64" ];then
|
||||
ARCH="arm64"
|
||||
else
|
||||
echo $ARCH
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -40,4 +40,18 @@ CREATE TABLE IF NOT EXISTS `slave_id_rsa` (
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
-- 从库配置主库的[user]
|
||||
-- drop table `slave_user`;
|
||||
CREATE TABLE IF NOT EXISTS `slave_sync_user` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`ip` TEXT,
|
||||
`port` TEXT,
|
||||
`user` TEXT,
|
||||
`pass` TEXT,
|
||||
`mode` TEXT,
|
||||
`cmd` TEXT,
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ replicate-ignore-db = information_schema
|
||||
replicate-ignore-db = performance_schema
|
||||
replicate-ignore-db = mysql
|
||||
replicate-ignore-db = test
|
||||
replicate-wild-ignore-table=mysql.%
|
||||
|
||||
|
||||
innodb_data_home_dir = {$SERVER_APP_PATH}/data
|
||||
|
||||
+334
-24
@@ -71,6 +71,13 @@ def checkArgs(data, ck=[]):
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getBackupDir():
|
||||
bk_path = mw.getBackupDir() + "/database/mariadb"
|
||||
if not os.path.isdir(bk_path):
|
||||
mw.execShell("mkdir -p {}".format(bk_path))
|
||||
return bk_path
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + '/etc/my.cnf'
|
||||
return path
|
||||
@@ -133,20 +140,27 @@ def contentReplace(content):
|
||||
def pSqliteDb(dbname='databases'):
|
||||
file = getServerDir() + '/mariadb.db'
|
||||
name = 'mysql'
|
||||
if not os.path.exists(file):
|
||||
|
||||
import_sql = mw.readFile(getPluginDir() + '/conf/mariadb.sql')
|
||||
md5_sql = mw.md5(import_sql)
|
||||
|
||||
import_sign = False
|
||||
save_md5_file = getServerDir() + '/import_sql.md5'
|
||||
if os.path.exists(save_md5_file):
|
||||
save_md5_sql = mw.readFile(save_md5_file)
|
||||
if save_md5_sql != md5_sql:
|
||||
import_sign = True
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
else:
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
|
||||
if not os.path.exists(file) or import_sql:
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
csql = mw.readFile(getPluginDir() + '/conf/mariadb.sql')
|
||||
csql_list = csql.split(';')
|
||||
csql_list = import_sql.split(';')
|
||||
for index in range(len(csql_list)):
|
||||
conn.execute(csql_list[index], ())
|
||||
else:
|
||||
# 现有run
|
||||
# conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
# csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
# csql_list = csql.split(';')
|
||||
# for index in range(len(csql_list)):
|
||||
# conn.execute(csql_list[index], ())
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
return conn
|
||||
|
||||
|
||||
@@ -273,6 +287,13 @@ def binLog():
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def cleanBinLog():
|
||||
db = pMysqlDb()
|
||||
cleanTime = time.strftime('%Y-%m-%d %H:%i:%s', time.localtime())
|
||||
db.execute("PURGE MASTER LOGS BEFORE '" + cleanTime + "';")
|
||||
return mw.returnJson(True, '清理BINLOG成功!')
|
||||
|
||||
|
||||
def setSkipGrantTables(v):
|
||||
'''
|
||||
设置是否密码验证
|
||||
@@ -675,7 +696,7 @@ def __createUser(dbname, username, password, address):
|
||||
|
||||
|
||||
def getDbBackupListFunc(dbname=''):
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
blist = os.listdir(bkDir)
|
||||
r = []
|
||||
|
||||
@@ -709,11 +730,11 @@ def importDbBackup():
|
||||
file = args['file']
|
||||
name = args['name']
|
||||
|
||||
file_path = mw.getRootDir() + '/backup/database/' + file
|
||||
file_path_sql = mw.getRootDir() + '/backup/database/' + file.replace('.gz', '')
|
||||
file_path = getBackupDir() + '/' + file
|
||||
file_path_sql = getBackupDir() + '/' + file.replace('.gz', '')
|
||||
|
||||
if not os.path.exists(file_path_sql):
|
||||
cmd = 'cd ' + mw.getRootDir() + '/backup/database && gzip -d ' + file
|
||||
cmd = 'cd ' + mw.getBackupDir() + '/database/mariadb && gzip -d ' + file
|
||||
mw.execShell(cmd)
|
||||
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
@@ -735,7 +756,7 @@ def importDbExternal():
|
||||
file = args['file']
|
||||
name = args['name']
|
||||
|
||||
import_dir = mw.getRootDir() + '/backup/import/'
|
||||
import_dir = mw.getBackupDir() + '/import/'
|
||||
|
||||
file_path = import_dir + file
|
||||
if not os.path.exists(file_path):
|
||||
@@ -797,7 +818,7 @@ def deleteDbBackup():
|
||||
|
||||
path = args['path']
|
||||
full_file = ""
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
full_file = bkDir + '/' + args['filename']
|
||||
if path != "":
|
||||
full_file = path + "/" + args['filename']
|
||||
@@ -812,7 +833,10 @@ def getDbBackupList():
|
||||
return data[1]
|
||||
|
||||
r = getDbBackupListFunc(args['name'])
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
if not os.path.exists(bkDir):
|
||||
os.mkdir(bkDir)
|
||||
|
||||
rr = []
|
||||
for x in range(0, len(r)):
|
||||
p = bkDir + '/' + r[x]
|
||||
@@ -835,7 +859,7 @@ def getDbBackupList():
|
||||
|
||||
def getDbBackupImportList():
|
||||
|
||||
bkImportDir = mw.getRootDir() + '/backup/import'
|
||||
bkImportDir = mw.getBackupDir() + '/import'
|
||||
if not os.path.exists(bkImportDir):
|
||||
os.mkdir(bkImportDir)
|
||||
|
||||
@@ -1775,7 +1799,7 @@ def addMasterRepSlaveUser(version=''):
|
||||
# address = args['address'].strip()
|
||||
# dataAccess = args['dataAccess'].strip()
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
reg = "^[\w-]+$"
|
||||
if not re.match(reg, username):
|
||||
return mw.returnJson(False, '用户名不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
@@ -1796,11 +1820,15 @@ def addMasterRepSlaveUser(version=''):
|
||||
sql = "GRANT REPLICATION SLAVE ON *.* TO '" + username + \
|
||||
"'@'%' identified by '" + password + "';"
|
||||
result = pdb.execute(sql)
|
||||
result = pdb.execute('FLUSH PRIVILEGES;')
|
||||
|
||||
isError = isSqlError(result)
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
sql_select = "grant select,lock tables,PROCESS on *.* to " + username + "@'%';"
|
||||
pdb.execute(sql_select)
|
||||
pdb.execute('FLUSH PRIVILEGES;')
|
||||
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
psdb.add('username,password,accept,ps,addtime',
|
||||
(username, password, '%', '', addTime))
|
||||
@@ -1837,10 +1865,16 @@ def getMasterRepSlaveUserCmd(version):
|
||||
|
||||
mode = recognizeDbMode()
|
||||
|
||||
# 查找同步点
|
||||
# SELECT BINLOG_GTID_POS('master1-bin.000002', 561866201);
|
||||
|
||||
if mode == "gtid":
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
clist[0]['password'] + "', MASTER_AUTO_POSITION=1"
|
||||
clist[0]['password'] + "', " + "MASTER_LOG_FILE='" + mstatus[0]["File"] + \
|
||||
"',MASTER_LOG_POS=" + \
|
||||
str(mstatus[0]["Position"]) + \
|
||||
",MASTER_USE_GTID=slave_pos,MASTER_CONNECT_RETRY=10;"
|
||||
else:
|
||||
sql = "CHANGE MASTER TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \
|
||||
clist[0]['username'] + "', MASTER_PASSWORD='" + \
|
||||
@@ -1926,6 +1960,123 @@ def getSlaveSSHList(version=''):
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSlaveSyncUserByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
"ip=?", (ip,)).select()
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
|
||||
|
||||
def addSlaveSyncUser(version=''):
|
||||
import base64
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
if ip == "":
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
data = checkArgs(args, ['port', 'user', 'pass', 'mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
cmd = args['cmd']
|
||||
port = args['port']
|
||||
user = args['user']
|
||||
apass = args['pass']
|
||||
mode = args['mode']
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip').where("ip=?", (ip,)).select()
|
||||
if len(data) > 0:
|
||||
res = conn.where("ip=?", (ip,)).save(
|
||||
'port,user,pass,mode,cmd', (port, user, apass, mode, cmd))
|
||||
else:
|
||||
conn.add('ip,port,user,cmd,user,pass,mode,addtime',
|
||||
(ip, port, user, cmd, user, apass, mode, addTime))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def delSlaveSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
conn.where("ip=?", (ip,)).delete()
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
def getSlaveSyncUserList(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['page', 'page_size'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
page = int(args['page'])
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
limit = str((page - 1) * page_size) + ',' + str(page_size)
|
||||
|
||||
field = 'id,ip,port,user,pass,cmd,addtime'
|
||||
clist = conn.field(field).limit(limit).order('id desc').select()
|
||||
count = conn.count()
|
||||
|
||||
data = {}
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['p'] = page
|
||||
_page['row'] = page_size
|
||||
_page['tojs'] = args['tojs']
|
||||
data['page'] = mw.getPage(_page)
|
||||
data['data'] = clist
|
||||
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSyncModeFile():
|
||||
return getServerDir() + "/sync.mode"
|
||||
|
||||
|
||||
def getSlaveSyncMode(version):
|
||||
sync_mode = getSyncModeFile()
|
||||
if os.path.exists(sync_mode):
|
||||
mode = mw.readFile(sync_mode).strip()
|
||||
return mw.returnJson(True, 'ok', mode)
|
||||
return mw.returnJson(False, 'fail')
|
||||
|
||||
|
||||
def setSlaveSyncMode(version):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
mode = args['mode']
|
||||
sync_mode = getSyncModeFile()
|
||||
|
||||
if mode == 'none':
|
||||
os.remove(sync_mode)
|
||||
else:
|
||||
mw.writeFile(sync_mode, mode)
|
||||
return mw.returnJson(True, '设置成功', mode)
|
||||
|
||||
|
||||
def getSlaveSSHByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
@@ -2003,8 +2154,6 @@ def getSlaveList(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
|
||||
# print(dlist)
|
||||
ret = []
|
||||
for x in range(0, len(dlist)):
|
||||
tmp = {}
|
||||
@@ -2014,6 +2163,24 @@ def getSlaveList(version=''):
|
||||
tmp['Master_Log_File'] = dlist[x]["Master_Log_File"]
|
||||
tmp['Slave_IO_Running'] = dlist[x]["Slave_IO_Running"]
|
||||
tmp['Slave_SQL_Running'] = dlist[x]["Slave_SQL_Running"]
|
||||
tmp['Last_Error'] = dlist[x]["Last_Error"]
|
||||
tmp['Last_IO_Error'] = dlist[x]["Last_IO_Error"]
|
||||
tmp['Last_SQL_Error'] = dlist[x]["Last_SQL_Error"]
|
||||
tmp['Slave_SQL_Running_State'] = dlist[x]["Slave_SQL_Running_State"]
|
||||
|
||||
tmp['Error'] = ''
|
||||
if tmp['Last_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_Error']
|
||||
|
||||
if tmp['Last_IO_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_IO_Error']
|
||||
|
||||
if tmp['Last_SQL_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_SQL_Error']
|
||||
|
||||
if tmp['Error'] == '':
|
||||
tmp['Error'] = tmp['Slave_SQL_Running_State']
|
||||
|
||||
ret.append(tmp)
|
||||
data = {}
|
||||
data['data'] = ret
|
||||
@@ -2030,6 +2197,47 @@ def getSlaveSyncCmd(version=''):
|
||||
|
||||
|
||||
def initSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return initSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return initSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
|
||||
# print(u['cmd'])
|
||||
t = db.query(u['cmd'])
|
||||
# print(t)
|
||||
db.query("start slave")
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
@@ -2100,6 +2308,41 @@ def initSlaveStatus(version=''):
|
||||
|
||||
|
||||
def setSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
return mw.returnJson(False, '需要手动添加同步账户或者执行初始化!')
|
||||
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
db.query('stop slave')
|
||||
else:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
@@ -2168,6 +2411,61 @@ def writeDbSyncStatus(data):
|
||||
|
||||
|
||||
def doFullSync(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return doFullSyncSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return doFullSyncUser(version)
|
||||
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
ip = data['ip']
|
||||
|
||||
bak_file = '/tmp/tmp.sql'
|
||||
|
||||
writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0})
|
||||
|
||||
writeDbSyncStatus({'code': 1, 'msg': '远程导出数据...', 'progress': 20})
|
||||
|
||||
if not os.path.exists(bak_file):
|
||||
dump_sql_data = getServerDir() + "/bin/mysqldump --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
|
||||
port + " -u" + user + " -p" + apass + " " + sync_db + " > " + bak_file
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
if os.path.exists(bak_file):
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
@@ -2473,6 +2771,18 @@ if __name__ == "__main__":
|
||||
print(delSlaveSSH(version))
|
||||
elif func == 'update_slave_ssh':
|
||||
print(updateSlaveSSH(version))
|
||||
elif func == 'get_slave_sync_user_list':
|
||||
print(getSlaveSyncUserList(version))
|
||||
elif func == 'get_slave_sync_user_by_ip':
|
||||
print(getSlaveSyncUserByIp(version))
|
||||
elif func == 'add_slave_sync_user':
|
||||
print(addSlaveSyncUser(version))
|
||||
elif func == 'del_slave_sync_user':
|
||||
print(delSlaveSyncUser(version))
|
||||
elif func == 'get_slave_sync_mode':
|
||||
print(getSlaveSyncMode(version))
|
||||
elif func == 'set_slave_sync_mode':
|
||||
print(setSlaveSyncMode(version))
|
||||
elif func == 'init_slave_status':
|
||||
print(initSlaveStatus(version))
|
||||
elif func == 'set_slave_status':
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"hook":["database"],
|
||||
"title":"MariaDB",
|
||||
"tip":"soft",
|
||||
"name":"mariadb",
|
||||
@@ -7,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",
|
||||
|
||||
+275
-24
@@ -39,7 +39,7 @@ function myPostN(method,args,callback, title){
|
||||
if (typeof(title) != 'undefined'){
|
||||
_title = title;
|
||||
}
|
||||
$.post('/plugins/run', {name:'mysql', func:method, args:_args}, function(data) {
|
||||
$.post('/plugins/run', {name:'mariadb', func:method, args:_args}, function(data) {
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
@@ -487,19 +487,6 @@ function showHidePass(obj){
|
||||
}
|
||||
}
|
||||
|
||||
function copyPass(password){
|
||||
var clipboard = new ClipboardJS('#bt_copys');
|
||||
clipboard.on('success', function (e) {
|
||||
layer.msg('复制成功',{icon:1,time:2000});
|
||||
});
|
||||
|
||||
clipboard.on('error', function (e) {
|
||||
layer.msg('复制失败,浏览器不兼容!',{icon:2,time:2000});
|
||||
});
|
||||
$("#bt_copys").attr('data-clipboard-text',password);
|
||||
$("#bt_copys").click();
|
||||
}
|
||||
|
||||
function checkSelect(){
|
||||
setTimeout(function () {
|
||||
var num = $('input[type="checkbox"].check:checked').length;
|
||||
@@ -668,8 +655,8 @@ function addDatabase(type){
|
||||
<span class='tname'>数据库名</span>\
|
||||
<div class='info-r'><input name='name' class='bt-input-text mr5' placeholder='新的数据库名称' type='text' style='width:65%' value=''>\
|
||||
<select class='bt-input-text mr5 codeing_a5nGsm' name='codeing' style='width:27%'>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='utf8mb4'>utf8mb4</option>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='gbk'>gbk</option>\
|
||||
<option value='big5'>big5</option>\
|
||||
</select>\
|
||||
@@ -810,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;
|
||||
@@ -1198,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);
|
||||
|
||||
@@ -1517,7 +1504,7 @@ function getMasterRepSlaveUserCmd(username, db=''){
|
||||
title: '同步命令',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70' id='add_master'>\
|
||||
<div class='line'>"+cmd+"</div>\
|
||||
<div class='line' style='word-wrap: break-word;word-break: normal;'>"+cmd+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-cmd'>复制</button>\
|
||||
</div>\
|
||||
@@ -1808,11 +1795,27 @@ function addSlaveSSH(ip=''){
|
||||
}
|
||||
|
||||
|
||||
|
||||
function delSlaveSSH(ip){
|
||||
myPost('del_slave_ssh', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2});
|
||||
getSlaveSSHPage();
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSSHPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function delSlaveSyncUser(ip){
|
||||
myPost('del_slave_sync_user', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1861,6 +1864,234 @@ function getSlaveSSHPage(page=1){
|
||||
});
|
||||
}
|
||||
|
||||
function addSlaveSyncUser(ip=''){
|
||||
|
||||
myPost('get_slave_sync_user_by_ip', {ip:ip}, function(rdata){
|
||||
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
var ip = '127.0.0.1';
|
||||
var port = "22";
|
||||
var cmd = '';
|
||||
var user = 'input_sync_user';
|
||||
var pass = 'input_sync_pwd';
|
||||
var mode = '0';
|
||||
|
||||
if (rdata.data.length>0){
|
||||
ip = rdata.data[0]['ip'];
|
||||
port = rdata.data[0]['port'];
|
||||
cmd = rdata.data[0]['cmd'];
|
||||
user = rdata.data[0]['user'];
|
||||
pass = rdata.data[0]['pass'];
|
||||
mode = rdata.data[0]['mode'];
|
||||
}
|
||||
|
||||
var index = layer.open({
|
||||
type: 1,
|
||||
area: ['500px','470px'],
|
||||
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' type='text' style='width:330px;' value='"+ip+"'></div></div>\
|
||||
<div class='line'><span class='tname'>端口</span><div class='info-r'><input name='port' class='bt-input-text mr5' type='number' style='width:330px;' value='"+port+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步账户</span><div class='info-r'><input name='user' class='bt-input-text mr5' type='text' style='width:330px;' value='"+user+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步密码</span><div class='info-r'><input name='pass' class='bt-input-text mr5' type='text' style='width:330px;' value='"+pass+"'></div></div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>CMD[必填]</span>\
|
||||
<div class='info-r'><textarea class='bt-input-text mr5' row='20' cols='30' name='cmd' style='width:330px;height:150px;'></textarea></div>\
|
||||
</div>\
|
||||
<input type='hidden' name='mode' value='"+mode+"' />\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="cmd"]').html(cmd);
|
||||
|
||||
$('textarea[name="cmd"]').change(function(){
|
||||
var val = $(this).val();
|
||||
var vlist = val.split(',');
|
||||
var a = {};
|
||||
for (var i in vlist) {
|
||||
var tmp = toTrim(vlist[i]);
|
||||
var tmp_a = tmp.split(" ");
|
||||
var real_tmp = tmp_a[tmp_a.length-1];
|
||||
var kv = real_tmp.split("=");
|
||||
a[kv[0]] = kv[1].replace("'",'').replace("'",'');
|
||||
}
|
||||
|
||||
$('input[name="ip"]').val(a['MASTER_HOST']);
|
||||
$('input[name="port"]').val(a['MASTER_PORT']);
|
||||
$('input[name="user"]').val(a['MASTER_USER']);
|
||||
$('input[name="pass"]').val(a['MASTER_PASSWORD']);
|
||||
|
||||
console.log(a['MASTER_USE_GTID'],typeof(a['MASTER_USE_GTID']));
|
||||
if (typeof(a['MASTER_USE_GTID']) != 'undefined' ){
|
||||
$('input[name="mode"]').val('1');
|
||||
}
|
||||
});
|
||||
},
|
||||
yes:function(index){
|
||||
var ip = $('input[name="ip"]').val();
|
||||
var port = $('input[name="port"]').val();
|
||||
var user = $('input[name="user"]').val();
|
||||
var pass = $('input[name="pass"]').val();
|
||||
var cmd = $('textarea[name="cmd"]').val();
|
||||
var mode = $('input[name="mode"]').val();
|
||||
|
||||
var data = {ip:ip,port:port,cmd:cmd,user:user,pass:pass,mode:mode};
|
||||
myPost('add_slave_sync_user', data, function(ret_data){
|
||||
layer.close(index);
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSyncUserPage(page=1){
|
||||
var _data = {};
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 5;
|
||||
_data['tojs'] ='getSlaveSyncUserPage';
|
||||
myPost('get_slave_sync_user_list', _data, function(data){
|
||||
var layerId = null;
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
var list = '';
|
||||
var user_list = rdata['data'];
|
||||
for (i in user_list) {
|
||||
var ip = user_list[i]['ip'];
|
||||
var port = user_list[i]['port'];
|
||||
var user = user_list[i]['user'];
|
||||
var apass = user_list[i]['pass'];
|
||||
|
||||
var cmd = '未设置';
|
||||
if (user_list[i]['cmd']!=''){
|
||||
cmd = '已设置';
|
||||
}
|
||||
|
||||
list += '<tr><td>'+ip+'</td>\
|
||||
<td>'+port+'</td>\
|
||||
<td>'+user+'</td>\
|
||||
<td>'+apass+'</td>\
|
||||
<td>'+cmd+'</td>\
|
||||
<td>\
|
||||
<a class="btlink" onclick="addSlaveSyncUser(\''+ip+'\');">修改</a> | \
|
||||
<a class="btlink" onclick="delSlaveSyncUser(\''+ip+'\');">删除</a>\
|
||||
</td>\
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$('.get-slave-ssh-list tbody').html(list);
|
||||
$('.dataTables_paginate_4').html(rdata['page']);
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveCfg(){
|
||||
|
||||
myPost('get_slave_sync_mode', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var mode_none = 'success';
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'danger';
|
||||
if(rdata.status){
|
||||
var mode_none = 'danger';
|
||||
if (rdata.data == 'ssh'){
|
||||
var mode_ssh = 'success';
|
||||
var mode_sync_user = 'danger';
|
||||
} else {
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步配置',
|
||||
area: ['400px','180px'],
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>当前从库同步模式</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-"+mode_none+" btn-xs slave-db-mode btn-none'>无</button>\
|
||||
<button class='btn btn-"+mode_ssh+" btn-xs slave-db-mode btn-ssh'>SSH</button>\
|
||||
<button class='btn btn-"+mode_sync_user+" btn-xs slave-db-mode btn-sync-user'>同步账户</button>\
|
||||
</p>\
|
||||
<hr />\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>配置设置</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-success btn-xs btn-slave-ssh'>SSH</button>\
|
||||
<button class='btn btn-success btn-xs btn-slave-user'>同步账户</button>\
|
||||
</p>\
|
||||
</div>",
|
||||
success:function(){
|
||||
$('.btn-slave-ssh').click(function(){
|
||||
getSlaveSSHList();
|
||||
});
|
||||
|
||||
$('.btn-slave-user').click(function(){
|
||||
getSlaveUserList();
|
||||
});
|
||||
|
||||
$('.slave-db-mode').click(function(){
|
||||
var _this = this;
|
||||
var mode = 'none';
|
||||
if ($(this).hasClass('btn-ssh')){
|
||||
mode = 'ssh';
|
||||
}
|
||||
if ($(this).hasClass('btn-sync-user')){
|
||||
mode = 'sync-user';
|
||||
}
|
||||
|
||||
myPost('set_slave_sync_mode', {mode:mode}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
$('.slave-db-mode').remove('btn-success').addClass('btn-danger');
|
||||
$(_this).removeClass('btn-danger').addClass('btn-success');
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveUserList(){
|
||||
|
||||
var page = '<div class="dataTables_paginate_4 dataTables_paginate paging_bootstrap page" style="margin-top:0px;"></div>';
|
||||
page += '<div class="table_toolbar" style="left:0px;"><span class="sync btn btn-default btn-sm" onclick="addSlaveSyncUser()" title="">添加同步账户</span></div>';
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
<thead><tr><th>IP</th><th>PORT</th><th>同步账户</th><th>同步密码</th><th>CMD</th><th>操作</th></tr></thead>\
|
||||
<tbody></tbody>\
|
||||
</table></div>\
|
||||
"+page +"\
|
||||
</div>\
|
||||
</div>",
|
||||
success:function(){
|
||||
getSlaveSyncUserPage(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSSHList(page=1){
|
||||
|
||||
@@ -1981,7 +2212,7 @@ function masterOrSlaveConf(version=''){
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "异常";
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
@@ -2023,6 +2254,26 @@ function masterOrSlaveConf(version=''){
|
||||
// <span class="sync btn btn-default btn-sm" onclick="getMasterRepSlaveList()" title="">添加</span>\
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
$('.db_error').click(function(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
</div>\
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2100,7 +2351,7 @@ function masterOrSlaveConf(version=''){
|
||||
<p class="conf_p">\
|
||||
<span class="f14 c6 mr20">Slave[从]配置</span><span class="f14 c6 mr20"></span>\
|
||||
<button class="btn '+(!rdata.slave_status ? 'btn-danger' : 'btn-success')+' btn-xs btn-slave">'+(!rdata.slave_status ? '未启动' : '已启动') +'</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveSSHList()" >[主]SSH配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveCfg()" >同步配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="initSlaveStatus()" >初始化</button>\
|
||||
</p>\
|
||||
<hr/>\
|
||||
@@ -2174,10 +2425,10 @@ function masterOrSlaveConf(version=''){
|
||||
getMasterDbList();
|
||||
}
|
||||
|
||||
if (rdata.slave_status){
|
||||
// if (rdata.slave_status){
|
||||
getAsyncMasterDbList();
|
||||
getAsyncDataList()
|
||||
}
|
||||
// }
|
||||
});
|
||||
}
|
||||
getMasterStatus();
|
||||
|
||||
@@ -40,7 +40,7 @@ class backupTools:
|
||||
"----------------------------------------------------------------------------")
|
||||
return
|
||||
|
||||
backup_path = mw.getRootDir() + '/backup/database'
|
||||
backup_path = mw.getRootDir() + '/backup/database/mariadb'
|
||||
if not os.path.exists(backup_path):
|
||||
mw.execShell("mkdir -p " + backup_path)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -36,11 +36,12 @@ max_connect_errors = 100
|
||||
open_files_limit = 2560
|
||||
max_allowed_packet = 128M
|
||||
|
||||
#skip-external-locking
|
||||
#skip-grant-tables
|
||||
#loose-skip-innodb
|
||||
skip_name_resolve = 1
|
||||
skip-ssl
|
||||
#skip-networking
|
||||
#skip-name-resolve
|
||||
#skip-external-locking
|
||||
#loose-skip-innodb
|
||||
#skip-grant-tables
|
||||
|
||||
log-bin=mysql-bin
|
||||
binlog_format=mixed
|
||||
@@ -64,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
|
||||
|
||||
@@ -40,4 +40,17 @@ CREATE TABLE IF NOT EXISTS `slave_id_rsa` (
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
-- 从库配置主库的[user]
|
||||
-- drop table `slave_user`;
|
||||
CREATE TABLE IF NOT EXISTS `slave_sync_user` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`ip` TEXT,
|
||||
`port` TEXT,
|
||||
`user` TEXT,
|
||||
`pass` TEXT,
|
||||
`mode` TEXT,
|
||||
`cmd` TEXT,
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<p onclick="myLogs();">日志</p>
|
||||
<p onclick="pluginLogs('mysql-apt',$('.plugin_version').attr('version'),'show_log');">慢日志</p>
|
||||
<p onclick="dbList()">管理列表</p>
|
||||
<p onclick="masterOrSlaveConf($('.plugin_version').attr('version'))">主从配置</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
|
||||
+376
-39
@@ -67,6 +67,13 @@ def getArgs():
|
||||
return tmp
|
||||
|
||||
|
||||
def getBackupDir():
|
||||
bk_path = mw.getBackupDir() + "/database/mysql-apt"
|
||||
if not os.path.isdir(bk_path):
|
||||
mw.execShell("mkdir -p {}".format(bk_path))
|
||||
return bk_path
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
@@ -115,20 +122,27 @@ def contentReplace(content):
|
||||
def pSqliteDb(dbname='databases'):
|
||||
file = getServerDir() + '/mysql.db'
|
||||
name = 'mysql'
|
||||
if not os.path.exists(file):
|
||||
|
||||
import_sql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
md5_sql = mw.md5(import_sql)
|
||||
|
||||
import_sign = False
|
||||
save_md5_file = getServerDir() + '/import_sql.md5'
|
||||
if os.path.exists(save_md5_file):
|
||||
save_md5_sql = mw.readFile(save_md5_file)
|
||||
if save_md5_sql != md5_sql:
|
||||
import_sign = True
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
else:
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
|
||||
if not os.path.exists(file) or import_sql:
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
csql_list = csql.split(';')
|
||||
csql_list = import_sql.split(';')
|
||||
for index in range(len(csql_list)):
|
||||
conn.execute(csql_list[index], ())
|
||||
else:
|
||||
# 现有run
|
||||
# conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
# csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
# csql_list = csql.split(';')
|
||||
# for index in range(len(csql_list)):
|
||||
# conn.execute(csql_list[index], ())
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
return conn
|
||||
|
||||
|
||||
@@ -147,9 +161,16 @@ def pMysqlDb():
|
||||
|
||||
def initDreplace(version=''):
|
||||
|
||||
my_dir = getServerDir() + '/etc'
|
||||
if not os.path.exists(my_dir):
|
||||
os.mkdir(my_dir)
|
||||
conf_dir = getServerDir() + '/etc'
|
||||
mode_dir = conf_dir + '/mode'
|
||||
|
||||
conf_list = [
|
||||
conf_dir,
|
||||
mode_dir,
|
||||
]
|
||||
for conf in conf_list:
|
||||
if not os.path.exists(conf):
|
||||
os.mkdir(conf)
|
||||
|
||||
tmp_dir = getServerDir() + '/tmp'
|
||||
if not os.path.exists(tmp_dir):
|
||||
@@ -157,12 +178,26 @@ def initDreplace(version=''):
|
||||
mw.execShell("chown -R mysql:mysql " + tmp_dir)
|
||||
mw.execShell("chmod 750 " + tmp_dir)
|
||||
|
||||
mysql_conf = my_dir + '/my.cnf'
|
||||
if not os.path.exists(mysql_conf):
|
||||
mysql_conf_tpl = getPluginDir() + '/conf/my' + version + '.cnf'
|
||||
content = mw.readFile(mysql_conf_tpl)
|
||||
my_conf = conf_dir + '/my.cnf'
|
||||
if not os.path.exists(my_conf):
|
||||
tpl = getPluginDir() + '/conf/my' + version + '.cnf'
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(mysql_conf, content)
|
||||
mw.writeFile(my_conf, content)
|
||||
|
||||
classic_conf = mode_dir + '/classic.cnf'
|
||||
if not os.path.exists(classic_conf):
|
||||
tpl = getPluginDir() + '/conf/classic.cnf'
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(classic_conf, content)
|
||||
|
||||
gtid_conf = mode_dir + '/gtid.cnf'
|
||||
if not os.path.exists(gtid_conf):
|
||||
tpl = getPluginDir() + '/conf/gtid.cnf'
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(gtid_conf, content)
|
||||
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
@@ -376,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':
|
||||
@@ -448,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]:
|
||||
@@ -463,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)
|
||||
@@ -477,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')
|
||||
@@ -650,7 +686,11 @@ def __createUser(dbname, username, password, address):
|
||||
|
||||
|
||||
def getDbBackupListFunc(dbname=''):
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
|
||||
bkDir = getBackupDir()
|
||||
if not os.path.exists(bkDir):
|
||||
os.mkdir(bkDir)
|
||||
|
||||
blist = os.listdir(bkDir)
|
||||
r = []
|
||||
|
||||
@@ -684,7 +724,7 @@ def importDbExternal():
|
||||
file = args['file']
|
||||
name = args['name']
|
||||
|
||||
import_dir = mw.getRootDir() + '/backup/import/'
|
||||
import_dir = mw.getBackupDir() + '/import/'
|
||||
|
||||
file_path = import_dir + file
|
||||
if not os.path.exists(file_path):
|
||||
@@ -734,10 +774,13 @@ def importDbExternal():
|
||||
pwd + ' ' + name + ' < ' + import_sql
|
||||
|
||||
# print(mysql_cmd)
|
||||
os.system(mysql_cmd)
|
||||
rdata = mw.execShell(mysql_cmd)
|
||||
if ext != 'sql':
|
||||
os.remove(import_sql)
|
||||
|
||||
if rdata[1].lower().find('error') > -1:
|
||||
return mw.returnJson(False, rdata[1])
|
||||
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
@@ -750,11 +793,11 @@ def importDbBackup():
|
||||
file = args['file']
|
||||
name = args['name']
|
||||
|
||||
file_path = mw.getRootDir() + '/backup/database/' + file
|
||||
file_path_sql = mw.getRootDir() + '/backup/database/' + file.replace('.gz', '')
|
||||
file_path = mw.getBackupDir() + '/database/' + file
|
||||
file_path_sql = mw.getBackupDir() + '/database/' + file.replace('.gz', '')
|
||||
|
||||
if not os.path.exists(file_path_sql):
|
||||
cmd = 'cd ' + mw.getRootDir() + '/backup/database && gzip -d ' + file
|
||||
cmd = 'cd ' + mw.getBackupDir() + '/database && gzip -d ' + file
|
||||
mw.execShell(cmd)
|
||||
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
@@ -763,7 +806,12 @@ def importDbBackup():
|
||||
' ' + name + ' < ' + file_path_sql
|
||||
|
||||
# print(mysql_cmd)
|
||||
os.system(mysql_cmd)
|
||||
# os.system(mysql_cmd)
|
||||
|
||||
rdata = mw.execShell(mysql_cmd)
|
||||
if rdata[1].lower().find('error') > -1:
|
||||
return mw.returnJson(False, rdata[1])
|
||||
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
@@ -775,7 +823,7 @@ def deleteDbBackup():
|
||||
|
||||
path = args['path']
|
||||
full_file = ""
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
full_file = bkDir + '/' + args['filename']
|
||||
if path != "":
|
||||
full_file = path + "/" + args['filename']
|
||||
@@ -790,7 +838,7 @@ def getDbBackupList():
|
||||
return data[1]
|
||||
|
||||
r = getDbBackupListFunc(args['name'])
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
rr = []
|
||||
for x in range(0, len(r)):
|
||||
p = bkDir + '/' + r[x]
|
||||
@@ -812,8 +860,7 @@ def getDbBackupList():
|
||||
|
||||
|
||||
def getDbBackupImportList():
|
||||
|
||||
bkImportDir = mw.getRootDir() + '/backup/import'
|
||||
bkImportDir = mw.getBackupDir() + '/import'
|
||||
if not os.path.exists(bkImportDir):
|
||||
os.mkdir(bkImportDir)
|
||||
|
||||
@@ -1094,7 +1141,7 @@ def addDb():
|
||||
dataAccess = args['dataAccess'].strip()
|
||||
ps = args['ps'].strip()
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
reg = "^[\w-]+$"
|
||||
if not re.match(reg, args['name']):
|
||||
return mw.returnJson(False, '数据库名称不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
@@ -1762,7 +1809,7 @@ def addMasterRepSlaveUser(version=''):
|
||||
# address = args['address'].strip()
|
||||
# dataAccess = args['dataAccess'].strip()
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
reg = "^[\w-]+$"
|
||||
if not re.match(reg, username):
|
||||
return mw.returnJson(False, '用户名不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
@@ -1790,17 +1837,18 @@ def addMasterRepSlaveUser(version=''):
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
sql = "FLUSH PRIVILEGES;"
|
||||
pdb.execute(sql)
|
||||
else:
|
||||
sql = "GRANT REPLICATION SLAVE ON *.* TO '" + username + \
|
||||
"'@'%' identified by '" + password + "';"
|
||||
result = pdb.execute(sql)
|
||||
result = pdb.execute('FLUSH PRIVILEGES;')
|
||||
isError = isSqlError(result)
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
sql_select = "grant select,lock tables,PROCESS on *.* to " + username + "@'%';"
|
||||
pdb.execute(sql_select)
|
||||
pdb.execute('FLUSH PRIVILEGES;')
|
||||
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
psdb.add('username,password,accept,ps,addtime',
|
||||
(username, password, '%', '', addTime))
|
||||
@@ -1937,6 +1985,123 @@ def getSlaveSSHList(version=''):
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSlaveSyncUserByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
"ip=?", (ip,)).select()
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
|
||||
|
||||
def addSlaveSyncUser(version=''):
|
||||
import base64
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
if ip == "":
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
data = checkArgs(args, ['port', 'user', 'pass', 'mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
cmd = args['cmd']
|
||||
port = args['port']
|
||||
user = args['user']
|
||||
apass = args['pass']
|
||||
mode = args['mode']
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip').where("ip=?", (ip,)).select()
|
||||
if len(data) > 0:
|
||||
res = conn.where("ip=?", (ip,)).save(
|
||||
'port,user,pass,mode,cmd', (port, user, apass, mode, cmd))
|
||||
else:
|
||||
conn.add('ip,port,user,cmd,user,pass,mode,addtime',
|
||||
(ip, port, user, cmd, user, apass, mode, addTime))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def delSlaveSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
conn.where("ip=?", (ip,)).delete()
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
def getSlaveSyncUserList(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['page', 'page_size'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
page = int(args['page'])
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
limit = str((page - 1) * page_size) + ',' + str(page_size)
|
||||
|
||||
field = 'id,ip,port,user,pass,cmd,addtime'
|
||||
clist = conn.field(field).limit(limit).order('id desc').select()
|
||||
count = conn.count()
|
||||
|
||||
data = {}
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['p'] = page
|
||||
_page['row'] = page_size
|
||||
_page['tojs'] = args['tojs']
|
||||
data['page'] = mw.getPage(_page)
|
||||
data['data'] = clist
|
||||
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSyncModeFile():
|
||||
return getServerDir() + "/sync.mode"
|
||||
|
||||
|
||||
def getSlaveSyncMode(version):
|
||||
sync_mode = getSyncModeFile()
|
||||
if os.path.exists(sync_mode):
|
||||
mode = mw.readFile(sync_mode).strip()
|
||||
return mw.returnJson(True, 'ok', mode)
|
||||
return mw.returnJson(False, 'fail')
|
||||
|
||||
|
||||
def setSlaveSyncMode(version):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
mode = args['mode']
|
||||
sync_mode = getSyncModeFile()
|
||||
|
||||
if mode == 'none':
|
||||
os.remove(sync_mode)
|
||||
else:
|
||||
mw.writeFile(sync_mode, mode)
|
||||
return mw.returnJson(True, '设置成功', mode)
|
||||
|
||||
|
||||
def getSlaveSSHByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
@@ -2023,6 +2188,24 @@ def getSlaveList(version=''):
|
||||
tmp['Master_Log_File'] = dlist[x]["Master_Log_File"]
|
||||
tmp['Slave_IO_Running'] = dlist[x]["Slave_IO_Running"]
|
||||
tmp['Slave_SQL_Running'] = dlist[x]["Slave_SQL_Running"]
|
||||
tmp['Last_Error'] = dlist[x]["Last_Error"]
|
||||
tmp['Last_IO_Error'] = dlist[x]["Last_IO_Error"]
|
||||
tmp['Last_SQL_Error'] = dlist[x]["Last_SQL_Error"]
|
||||
tmp['Slave_SQL_Running_State'] = dlist[x]["Slave_SQL_Running_State"]
|
||||
|
||||
tmp['Error'] = ''
|
||||
if tmp['Last_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_Error']
|
||||
|
||||
if tmp['Last_IO_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_IO_Error']
|
||||
|
||||
if tmp['Last_SQL_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_SQL_Error']
|
||||
|
||||
if tmp['Error'] == '':
|
||||
tmp['Error'] = tmp['Slave_SQL_Running_State']
|
||||
|
||||
ret.append(tmp)
|
||||
data = {}
|
||||
data['data'] = ret
|
||||
@@ -2039,6 +2222,47 @@ def getSlaveSyncCmd(version=''):
|
||||
|
||||
|
||||
def initSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return initSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return initSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
|
||||
t = db.query(u['cmd'])
|
||||
# print(t)
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['user'], u['pass']))
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
@@ -2107,6 +2331,41 @@ def initSlaveStatus(version=''):
|
||||
|
||||
|
||||
def setSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
return mw.returnJson(False, '需要手动添加同步账户或者执行初始化!')
|
||||
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
db.query('stop slave')
|
||||
else:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
@@ -2175,6 +2434,69 @@ def writeDbSyncStatus(data):
|
||||
|
||||
|
||||
def doFullSync(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return doFullSyncSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return doFullSyncUser(version)
|
||||
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
ip = data['ip']
|
||||
|
||||
bak_file = '/tmp/tmp.sql'
|
||||
|
||||
writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0})
|
||||
dmp_option = ''
|
||||
mode = recognizeDbMode()
|
||||
if mode == 'gtid':
|
||||
dmp_option = ' --set-gtid-purged=off '
|
||||
|
||||
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 + \
|
||||
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
if os.path.exists(bak_file):
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
if version == '8.0':
|
||||
db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
else:
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
@@ -2361,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__":
|
||||
@@ -2413,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':
|
||||
@@ -2506,6 +2831,18 @@ if __name__ == "__main__":
|
||||
print(delSlaveSSH(version))
|
||||
elif func == 'update_slave_ssh':
|
||||
print(updateSlaveSSH(version))
|
||||
elif func == 'get_slave_sync_user_list':
|
||||
print(getSlaveSyncUserList(version))
|
||||
elif func == 'get_slave_sync_user_by_ip':
|
||||
print(getSlaveSyncUserByIp(version))
|
||||
elif func == 'add_slave_sync_user':
|
||||
print(addSlaveSyncUser(version))
|
||||
elif func == 'del_slave_sync_user':
|
||||
print(delSlaveSyncUser(version))
|
||||
elif func == 'get_slave_sync_mode':
|
||||
print(getSlaveSyncMode(version))
|
||||
elif func == 'set_slave_sync_mode':
|
||||
print(setSlaveSyncMode(version))
|
||||
elif func == 'init_slave_status':
|
||||
print(initSlaveStatus(version))
|
||||
elif func == 'set_slave_status':
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"hook":["database"],
|
||||
"title":"MySQL[APT]",
|
||||
"tip":"soft",
|
||||
"name":"mysql-apt",
|
||||
"type":"运行环境",
|
||||
"ps":"[<b style='color:red;'>潜龙勿用</b>]一种关系数据库管理系统[debian,ubuntu](极速安装)",
|
||||
"ps":"一种关系数据库管理系统[debian,ubuntu](极速安装)",
|
||||
"todo_versions":["5.7","8.0"],
|
||||
"versions":["5.7","8.0"],
|
||||
"shell":"install.sh",
|
||||
|
||||
@@ -509,19 +509,6 @@ function showHidePass(obj){
|
||||
}
|
||||
}
|
||||
|
||||
function copyPass(password){
|
||||
var clipboard = new ClipboardJS('#bt_copys');
|
||||
clipboard.on('success', function (e) {
|
||||
layer.msg('复制成功',{icon:1,time:2000});
|
||||
});
|
||||
|
||||
clipboard.on('error', function (e) {
|
||||
layer.msg('复制失败,浏览器不兼容!',{icon:2,time:2000});
|
||||
});
|
||||
$("#bt_copys").attr('data-clipboard-text',password);
|
||||
$("#bt_copys").click();
|
||||
}
|
||||
|
||||
function checkSelect(){
|
||||
setTimeout(function () {
|
||||
var num = $('input[type="checkbox"].check:checked').length;
|
||||
@@ -690,8 +677,8 @@ function addDatabase(type){
|
||||
<span class='tname'>数据库名</span>\
|
||||
<div class='info-r'><input name='name' class='bt-input-text mr5' placeholder='新的数据库名称' type='text' style='width:65%' value=''>\
|
||||
<select class='bt-input-text mr5 codeing_a5nGsm' name='codeing' style='width:27%'>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='utf8mb4'>utf8mb4</option>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='gbk'>gbk</option>\
|
||||
<option value='big5'>big5</option>\
|
||||
</select>\
|
||||
@@ -744,7 +731,7 @@ function addDatabase(type){
|
||||
layer.close(index);
|
||||
dbList();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
},{icon: rdata.status ? 1 : 2}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -832,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;
|
||||
}
|
||||
|
||||
@@ -1221,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);
|
||||
|
||||
@@ -1558,13 +1545,9 @@ function getMasterRepSlaveUserCmd(username, db=''){
|
||||
function delMasterRepSlaveUser(username){
|
||||
myPost('del_master_rep_slave_user', {username:username}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
layer.msg(rdata.msg);
|
||||
|
||||
$('.layui-layer-close1').click();
|
||||
|
||||
setTimeout(function(){
|
||||
showMsg(rdata.msg, function(){
|
||||
getMasterRepSlaveList();
|
||||
},1000);
|
||||
},{icon: rdata.status ? 1 : 2},1000)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1834,8 +1817,23 @@ function addSlaveSSH(ip=''){
|
||||
function delSlaveSSH(ip){
|
||||
myPost('del_slave_ssh', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2});
|
||||
getSlaveSSHPage();
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSSHPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function delSlaveSyncUser(ip){
|
||||
myPost('del_slave_sync_user', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1885,6 +1883,237 @@ function getSlaveSSHPage(page=1){
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addSlaveSyncUser(ip=''){
|
||||
|
||||
myPost('get_slave_sync_user_by_ip', {ip:ip}, function(rdata){
|
||||
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
var ip = '127.0.0.1';
|
||||
var port = "22";
|
||||
var cmd = '';
|
||||
var user = 'input_sync_user';
|
||||
var pass = 'input_sync_pwd';
|
||||
var mode = '0';
|
||||
|
||||
if (rdata.data.length>0){
|
||||
ip = rdata.data[0]['ip'];
|
||||
port = rdata.data[0]['port'];
|
||||
cmd = rdata.data[0]['cmd'];
|
||||
user = rdata.data[0]['user'];
|
||||
pass = rdata.data[0]['pass'];
|
||||
mode = rdata.data[0]['mode'];
|
||||
}
|
||||
|
||||
var index = layer.open({
|
||||
type: 1,
|
||||
area: ['500px','470px'],
|
||||
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' type='text' style='width:330px;' value='"+ip+"'></div></div>\
|
||||
<div class='line'><span class='tname'>端口</span><div class='info-r'><input name='port' class='bt-input-text mr5' type='number' style='width:330px;' value='"+port+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步账户</span><div class='info-r'><input name='user' class='bt-input-text mr5' type='text' style='width:330px;' value='"+user+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步密码</span><div class='info-r'><input name='pass' class='bt-input-text mr5' type='text' style='width:330px;' value='"+pass+"'></div></div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>CMD[最好填好]</span>\
|
||||
<div class='info-r'><textarea class='bt-input-text mr5' row='20' cols='30' name='cmd' style='width:330px;height:150px;'></textarea></div>\
|
||||
</div>\
|
||||
<input type='hidden' name='mode' value='"+mode+"' />\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="cmd"]').html(cmd);
|
||||
|
||||
$('textarea[name="cmd"]').change(function(){
|
||||
var val = $(this).val();
|
||||
var vlist = val.split(',');
|
||||
var a = {};
|
||||
for (var i in vlist) {
|
||||
var tmp = toTrim(vlist[i]);
|
||||
var tmp_a = tmp.split(" ");
|
||||
var real_tmp = tmp_a[tmp_a.length-1];
|
||||
var kv = real_tmp.split("=");
|
||||
a[kv[0]] = kv[1].replace("'",'').replace("'",'');
|
||||
}
|
||||
|
||||
$('input[name="ip"]').val(a['MASTER_HOST']);
|
||||
$('input[name="port"]').val(a['MASTER_PORT']);
|
||||
$('input[name="user"]').val(a['MASTER_USER']);
|
||||
$('input[name="pass"]').val(a['MASTER_PASSWORD']);
|
||||
|
||||
console.log(a['MASTER_AUTO_POSITION'],typeof(a['MASTER_AUTO_POSITION']));
|
||||
if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){
|
||||
$('input[name="mode"]').val('1');
|
||||
}
|
||||
});
|
||||
},
|
||||
yes:function(index){
|
||||
var ip = $('input[name="ip"]').val();
|
||||
var port = $('input[name="port"]').val();
|
||||
var user = $('input[name="user"]').val();
|
||||
var pass = $('input[name="pass"]').val();
|
||||
var cmd = $('textarea[name="cmd"]').val();
|
||||
var mode = $('input[name="mode"]').val();
|
||||
|
||||
var data = {ip:ip,port:port,cmd:cmd,user:user,pass:pass,mode:mode};
|
||||
myPost('add_slave_sync_user', data, function(ret_data){
|
||||
layer.close(index);
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSyncUserPage(page=1){
|
||||
var _data = {};
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 5;
|
||||
_data['tojs'] ='getSlaveSyncUserPage';
|
||||
myPost('get_slave_sync_user_list', _data, function(data){
|
||||
var layerId = null;
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
var list = '';
|
||||
var user_list = rdata['data'];
|
||||
for (i in user_list) {
|
||||
var ip = user_list[i]['ip'];
|
||||
var port = user_list[i]['port'];
|
||||
var user = user_list[i]['user'];
|
||||
var apass = user_list[i]['pass'];
|
||||
|
||||
var cmd = '未设置';
|
||||
if (user_list[i]['cmd']!=''){
|
||||
cmd = '已设置';
|
||||
}
|
||||
|
||||
list += '<tr><td>'+ip+'</td>\
|
||||
<td>'+port+'</td>\
|
||||
<td>'+user+'</td>\
|
||||
<td>'+apass+'</td>\
|
||||
<td>'+cmd+'</td>\
|
||||
<td>\
|
||||
<a class="btlink" onclick="addSlaveSyncUser(\''+ip+'\');">修改</a> | \
|
||||
<a class="btlink" onclick="delSlaveSyncUser(\''+ip+'\');">删除</a>\
|
||||
</td>\
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$('.get-slave-ssh-list tbody').html(list);
|
||||
$('.dataTables_paginate_4').html(rdata['page']);
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveCfg(){
|
||||
|
||||
myPost('get_slave_sync_mode', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var mode_none = 'success';
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'danger';
|
||||
if(rdata.status){
|
||||
var mode_none = 'danger';
|
||||
if (rdata.data == 'ssh'){
|
||||
var mode_ssh = 'success';
|
||||
var mode_sync_user = 'danger';
|
||||
} else {
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步配置',
|
||||
area: ['400px','180px'],
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>当前从库同步模式</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-"+mode_none+" btn-xs slave-db-mode btn-none'>无</button>\
|
||||
<button class='btn btn-"+mode_ssh+" btn-xs slave-db-mode btn-ssh'>SSH</button>\
|
||||
<button class='btn btn-"+mode_sync_user+" btn-xs slave-db-mode btn-sync-user'>同步账户</button>\
|
||||
</p>\
|
||||
<hr />\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>配置设置</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-success btn-xs btn-slave-ssh'>SSH</button>\
|
||||
<button class='btn btn-success btn-xs btn-slave-user'>同步账户</button>\
|
||||
</p>\
|
||||
</div>",
|
||||
success:function(){
|
||||
$('.btn-slave-ssh').click(function(){
|
||||
getSlaveSSHList();
|
||||
});
|
||||
|
||||
$('.btn-slave-user').click(function(){
|
||||
getSlaveUserList();
|
||||
});
|
||||
|
||||
$('.slave-db-mode').click(function(){
|
||||
var _this = this;
|
||||
var mode = 'none';
|
||||
if ($(this).hasClass('btn-ssh')){
|
||||
mode = 'ssh';
|
||||
}
|
||||
if ($(this).hasClass('btn-sync-user')){
|
||||
mode = 'sync-user';
|
||||
}
|
||||
|
||||
myPost('set_slave_sync_mode', {mode:mode}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
$('.slave-db-mode').remove('btn-success').addClass('btn-danger');
|
||||
$(_this).removeClass('btn-danger').addClass('btn-success');
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getSlaveUserList(){
|
||||
|
||||
var page = '<div class="dataTables_paginate_4 dataTables_paginate paging_bootstrap page" style="margin-top:0px;"></div>';
|
||||
page += '<div class="table_toolbar" style="left:0px;"><span class="sync btn btn-default btn-sm" onclick="addSlaveSyncUser()" title="">添加同步账户</span></div>';
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
<thead><tr><th>IP</th><th>PORT</th><th>同步账户</th><th>同步密码</th><th>CMD</th><th>操作</th></tr></thead>\
|
||||
<tbody></tbody>\
|
||||
</table></div>\
|
||||
"+page +"\
|
||||
</div>\
|
||||
</div>",
|
||||
success:function(){
|
||||
getSlaveSyncUserPage(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSSHList(page=1){
|
||||
|
||||
var page = '<div class="dataTables_paginate_4 dataTables_paginate paging_bootstrap page" style="margin-top:0px;"></div>';
|
||||
@@ -2004,7 +2233,7 @@ function masterOrSlaveConf(version=''){
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "异常";
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
@@ -2046,6 +2275,26 @@ function masterOrSlaveConf(version=''){
|
||||
// <span class="sync btn btn-default btn-sm" onclick="getMasterRepSlaveList()" title="">添加</span>\
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
$('.db_error').click(function(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
</div>\
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2092,7 +2341,6 @@ function masterOrSlaveConf(version=''){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getMasterStatus(){
|
||||
myPost('get_master_status', '', function(rdata){
|
||||
@@ -2123,7 +2371,7 @@ function masterOrSlaveConf(version=''){
|
||||
<p class="conf_p">\
|
||||
<span class="f14 c6 mr20">Slave[从]配置</span><span class="f14 c6 mr20"></span>\
|
||||
<button class="btn '+(!rdata.slave_status ? 'btn-danger' : 'btn-success')+' btn-xs btn-slave">'+(!rdata.slave_status ? '未启动' : '已启动') +'</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveSSHList()" >[主]SSH配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveCfg()" >同步配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="initSlaveStatus()" >初始化</button>\
|
||||
</p>\
|
||||
<hr/>\
|
||||
@@ -2197,10 +2445,10 @@ function masterOrSlaveConf(version=''){
|
||||
getMasterDbList();
|
||||
}
|
||||
|
||||
if (rdata.slave_status){
|
||||
// if (rdata.slave_status){
|
||||
getAsyncMasterDbList();
|
||||
getAsyncDataList()
|
||||
}
|
||||
// }
|
||||
});
|
||||
}
|
||||
getMasterStatus();
|
||||
|
||||
@@ -44,7 +44,7 @@ class backupTools:
|
||||
"----------------------------------------------------------------------------")
|
||||
return
|
||||
|
||||
backup_path = mw.getRootDir() + '/backup/database'
|
||||
backup_path = mw.getRootDir() + '/backup/database/mysql-apt'
|
||||
if not os.path.exists(backup_path):
|
||||
mw.execShell("mkdir -p " + backup_path)
|
||||
|
||||
|
||||
@@ -37,11 +37,12 @@ max_connect_errors = 100
|
||||
open_files_limit = 2560
|
||||
max_allowed_packet = 128M
|
||||
|
||||
#skip-external-locking
|
||||
#skip-grant-tables
|
||||
#loose-skip-innodb
|
||||
skip_name_resolve = 1
|
||||
skip-ssl
|
||||
#skip-networking
|
||||
#skip-name-resolve
|
||||
#skip-external-locking
|
||||
#loose-skip-innodb
|
||||
#skip-grant-tables
|
||||
|
||||
log-bin=mysql-bin
|
||||
binlog_format=mixed
|
||||
@@ -65,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
|
||||
|
||||
@@ -40,4 +40,17 @@ CREATE TABLE IF NOT EXISTS `slave_id_rsa` (
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
-- 从库配置主库的[user]
|
||||
-- drop table `slave_user`;
|
||||
CREATE TABLE IF NOT EXISTS `slave_sync_user` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`ip` TEXT,
|
||||
`port` TEXT,
|
||||
`user` TEXT,
|
||||
`pass` TEXT,
|
||||
`mode` TEXT,
|
||||
`cmd` TEXT,
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<p onclick="myLogs();">日志</p>
|
||||
<p onclick="pluginLogs('mysql-yum',$('.plugin_version').attr('version'),'show_log');">慢日志</p>
|
||||
<p onclick="dbList()">管理列表</p>
|
||||
<p onclick="masterOrSlaveConf($('.plugin_version').attr('version'))">主从配置</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
|
||||
+361
-43
@@ -65,6 +65,13 @@ def checkArgs(data, ck=[]):
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getBackupDir():
|
||||
bk_path = mw.getBackupDir() + "/database/mysql-yum"
|
||||
if not os.path.isdir(bk_path):
|
||||
mw.execShell("mkdir -p {}".format(bk_path))
|
||||
return bk_path
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + '/etc/my.cnf'
|
||||
return path
|
||||
@@ -122,20 +129,27 @@ def contentReplace(content):
|
||||
def pSqliteDb(dbname='databases'):
|
||||
file = getServerDir() + '/mysql.db'
|
||||
name = 'mysql'
|
||||
if not os.path.exists(file):
|
||||
|
||||
import_sql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
md5_sql = mw.md5(import_sql)
|
||||
|
||||
import_sign = False
|
||||
save_md5_file = getServerDir() + '/import_sql.md5'
|
||||
if os.path.exists(save_md5_file):
|
||||
save_md5_sql = mw.readFile(save_md5_file)
|
||||
if save_md5_sql != md5_sql:
|
||||
import_sign = True
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
else:
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
|
||||
if not os.path.exists(file) or import_sql:
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
csql_list = csql.split(';')
|
||||
csql_list = import_sql.split(';')
|
||||
for index in range(len(csql_list)):
|
||||
conn.execute(csql_list[index], ())
|
||||
else:
|
||||
# 现有run
|
||||
# conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
# csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
# csql_list = csql.split(';')
|
||||
# for index in range(len(csql_list)):
|
||||
# conn.execute(csql_list[index], ())
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
return conn
|
||||
|
||||
|
||||
@@ -154,9 +168,16 @@ def pMysqlDb():
|
||||
|
||||
def initDreplace(version=''):
|
||||
|
||||
my_dir = getServerDir() + '/etc'
|
||||
if not os.path.exists(my_dir):
|
||||
os.mkdir(my_dir)
|
||||
conf_dir = getServerDir() + '/etc'
|
||||
mode_dir = conf_dir + '/mode'
|
||||
|
||||
conf_list = [
|
||||
conf_dir,
|
||||
mode_dir,
|
||||
]
|
||||
for conf in conf_list:
|
||||
if not os.path.exists(conf):
|
||||
os.mkdir(conf)
|
||||
|
||||
tmp_dir = getServerDir() + '/tmp'
|
||||
if not os.path.exists(tmp_dir):
|
||||
@@ -164,12 +185,26 @@ def initDreplace(version=''):
|
||||
mw.execShell("chown -R mysql:mysql " + tmp_dir)
|
||||
mw.execShell("chmod 750 " + tmp_dir)
|
||||
|
||||
mysql_conf = my_dir + '/my.cnf'
|
||||
if not os.path.exists(mysql_conf):
|
||||
mysql_conf_tpl = getPluginDir() + '/conf/my' + version + '.cnf'
|
||||
content = mw.readFile(mysql_conf_tpl)
|
||||
my_conf = conf_dir + '/my.cnf'
|
||||
if not os.path.exists(my_conf):
|
||||
tpl = getPluginDir() + '/conf/my' + version + '.cnf'
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(mysql_conf, content)
|
||||
mw.writeFile(my_conf, content)
|
||||
|
||||
classic_conf = mode_dir + '/classic.cnf'
|
||||
if not os.path.exists(classic_conf):
|
||||
tpl = getPluginDir() + '/conf/classic.cnf'
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(classic_conf, content)
|
||||
|
||||
gtid_conf = mode_dir + '/gtid.cnf'
|
||||
if not os.path.exists(gtid_conf):
|
||||
tpl = getPluginDir() + '/conf/gtid.cnf'
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content)
|
||||
mw.writeFile(gtid_conf, content)
|
||||
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
@@ -226,6 +261,13 @@ def binLog():
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def cleanBinLog():
|
||||
db = pMysqlDb()
|
||||
cleanTime = time.strftime('%Y-%m-%d %H:%i:%s', time.localtime())
|
||||
db.execute("PURGE MASTER LOGS BEFORE '" + cleanTime + "';")
|
||||
return mw.returnJson(True, '清理BINLOG成功!')
|
||||
|
||||
|
||||
def setSkipGrantTables(v):
|
||||
'''
|
||||
设置是否密码验证
|
||||
@@ -355,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':
|
||||
@@ -427,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]:
|
||||
@@ -442,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)
|
||||
@@ -456,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, '文件迁移失败!')
|
||||
|
||||
|
||||
@@ -629,7 +672,7 @@ def __createUser(dbname, username, password, address):
|
||||
|
||||
|
||||
def getDbBackupListFunc(dbname=''):
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
blist = os.listdir(bkDir)
|
||||
r = []
|
||||
|
||||
@@ -663,7 +706,7 @@ def importDbExternal():
|
||||
file = args['file']
|
||||
name = args['name']
|
||||
|
||||
import_dir = mw.getRootDir() + '/backup/import/'
|
||||
import_dir = mw.getBackupDir() + '/import/'
|
||||
|
||||
file_path = import_dir + file
|
||||
if not os.path.exists(file_path):
|
||||
@@ -712,11 +755,13 @@ def importDbExternal():
|
||||
mysql_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + ' -uroot -p' + \
|
||||
pwd + ' ' + name + ' < ' + import_sql
|
||||
|
||||
# print(mysql_cmd)
|
||||
os.system(mysql_cmd)
|
||||
rdata = mw.execShell(mysql_cmd)
|
||||
if ext != 'sql':
|
||||
os.remove(import_sql)
|
||||
|
||||
if rdata[1].lower().find('error') > -1:
|
||||
return mw.returnJson(False, rdata[1])
|
||||
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
@@ -729,11 +774,11 @@ def importDbBackup():
|
||||
file = args['file']
|
||||
name = args['name']
|
||||
|
||||
file_path = mw.getRootDir() + '/backup/database/' + file
|
||||
file_path_sql = mw.getRootDir() + '/backup/database/' + file.replace('.gz', '')
|
||||
file_path = getBackupDir() + '/' + file
|
||||
file_path_sql = getBackupDir() + '/' + file.replace('.gz', '')
|
||||
|
||||
if not os.path.exists(file_path_sql):
|
||||
cmd = 'cd ' + mw.getRootDir() + '/backup/database && gzip -d ' + file
|
||||
cmd = 'cd ' + mw.getBackupDir() + '/database && gzip -d ' + file
|
||||
mw.execShell(cmd)
|
||||
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
@@ -741,8 +786,10 @@ def importDbBackup():
|
||||
mysql_cmd = getServerDir() + '/bin/usr/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + name + ' < ' + file_path_sql
|
||||
|
||||
# print(mysql_cmd)
|
||||
os.system(mysql_cmd)
|
||||
rdata = mw.execShell(mysql_cmd)
|
||||
if rdata[1].lower().find('error') > -1:
|
||||
return mw.returnJson(False, rdata[1])
|
||||
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
@@ -754,7 +801,7 @@ def deleteDbBackup():
|
||||
|
||||
path = args['path']
|
||||
full_file = ""
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
full_file = bkDir + '/' + args['filename']
|
||||
if path != "":
|
||||
full_file = path + "/" + args['filename']
|
||||
@@ -769,7 +816,7 @@ def getDbBackupList():
|
||||
return data[1]
|
||||
|
||||
r = getDbBackupListFunc(args['name'])
|
||||
bkDir = mw.getRootDir() + '/backup/database'
|
||||
bkDir = getBackupDir()
|
||||
rr = []
|
||||
for x in range(0, len(r)):
|
||||
p = bkDir + '/' + r[x]
|
||||
@@ -791,8 +838,7 @@ def getDbBackupList():
|
||||
|
||||
|
||||
def getDbBackupImportList():
|
||||
|
||||
bkImportDir = mw.getRootDir() + '/backup/import'
|
||||
bkImportDir = mw.getBackupDir() + '/import'
|
||||
if not os.path.exists(bkImportDir):
|
||||
os.mkdir(bkImportDir)
|
||||
|
||||
@@ -1073,7 +1119,7 @@ def addDb():
|
||||
dataAccess = args['dataAccess'].strip()
|
||||
ps = args['ps'].strip()
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
reg = "^[\w-]+$"
|
||||
if not re.match(reg, args['name']):
|
||||
return mw.returnJson(False, '数据库名称不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
@@ -1741,7 +1787,7 @@ def addMasterRepSlaveUser(version=''):
|
||||
# address = args['address'].strip()
|
||||
# dataAccess = args['dataAccess'].strip()
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
reg = "^[\w-]+$"
|
||||
if not re.match(reg, username):
|
||||
return mw.returnJson(False, '用户名不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
@@ -1769,17 +1815,18 @@ def addMasterRepSlaveUser(version=''):
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
sql = "FLUSH PRIVILEGES;"
|
||||
pdb.execute(sql)
|
||||
else:
|
||||
sql = "GRANT REPLICATION SLAVE ON *.* TO '" + username + \
|
||||
"'@'%' identified by '" + password + "';"
|
||||
result = pdb.execute(sql)
|
||||
result = pdb.execute('FLUSH PRIVILEGES;')
|
||||
isError = isSqlError(result)
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
sql_select = "grant select,lock tables,PROCESS on *.* to " + username + "@'%';"
|
||||
pdb.execute(sql_select)
|
||||
pdb.execute('FLUSH PRIVILEGES;')
|
||||
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
psdb.add('username,password,accept,ps,addtime',
|
||||
(username, password, '%', '', addTime))
|
||||
@@ -1916,6 +1963,123 @@ def getSlaveSSHList(version=''):
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSlaveSyncUserByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
"ip=?", (ip,)).select()
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
|
||||
|
||||
def addSlaveSyncUser(version=''):
|
||||
import base64
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
if ip == "":
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
data = checkArgs(args, ['port', 'user', 'pass', 'mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
cmd = args['cmd']
|
||||
port = args['port']
|
||||
user = args['user']
|
||||
apass = args['pass']
|
||||
mode = args['mode']
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip').where("ip=?", (ip,)).select()
|
||||
if len(data) > 0:
|
||||
res = conn.where("ip=?", (ip,)).save(
|
||||
'port,user,pass,mode,cmd', (port, user, apass, mode, cmd))
|
||||
else:
|
||||
conn.add('ip,port,user,cmd,user,pass,mode,addtime',
|
||||
(ip, port, user, cmd, user, apass, mode, addTime))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def delSlaveSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
conn.where("ip=?", (ip,)).delete()
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
def getSlaveSyncUserList(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['page', 'page_size'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
page = int(args['page'])
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
limit = str((page - 1) * page_size) + ',' + str(page_size)
|
||||
|
||||
field = 'id,ip,port,user,pass,cmd,addtime'
|
||||
clist = conn.field(field).limit(limit).order('id desc').select()
|
||||
count = conn.count()
|
||||
|
||||
data = {}
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['p'] = page
|
||||
_page['row'] = page_size
|
||||
_page['tojs'] = args['tojs']
|
||||
data['page'] = mw.getPage(_page)
|
||||
data['data'] = clist
|
||||
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSyncModeFile():
|
||||
return getServerDir() + "/sync.mode"
|
||||
|
||||
|
||||
def getSlaveSyncMode(version):
|
||||
sync_mode = getSyncModeFile()
|
||||
if os.path.exists(sync_mode):
|
||||
mode = mw.readFile(sync_mode).strip()
|
||||
return mw.returnJson(True, 'ok', mode)
|
||||
return mw.returnJson(False, 'fail')
|
||||
|
||||
|
||||
def setSlaveSyncMode(version):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
mode = args['mode']
|
||||
sync_mode = getSyncModeFile()
|
||||
|
||||
if mode == 'none':
|
||||
os.remove(sync_mode)
|
||||
else:
|
||||
mw.writeFile(sync_mode, mode)
|
||||
return mw.returnJson(True, '设置成功', mode)
|
||||
|
||||
|
||||
def getSlaveSSHByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
@@ -2018,6 +2182,47 @@ def getSlaveSyncCmd(version=''):
|
||||
|
||||
|
||||
def initSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return initSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return initSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def initSlaveStatusSyncUser(version=''):
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
|
||||
t = db.query(u['cmd'])
|
||||
# print(t)
|
||||
db.query("start slave user='{}' password='{}';".format(
|
||||
u['user'], u['pass']))
|
||||
return mw.returnJson(True, '初始化成功!')
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
@@ -2086,6 +2291,41 @@ def initSlaveStatus(version=''):
|
||||
|
||||
|
||||
def setSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
return mw.returnJson(False, '需要手动添加同步账户或者执行初始化!')
|
||||
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
db.query('stop slave')
|
||||
else:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
@@ -2154,6 +2394,69 @@ def writeDbSyncStatus(data):
|
||||
|
||||
|
||||
def doFullSync(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return doFullSyncSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return doFullSyncUser(version)
|
||||
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
ip = data['ip']
|
||||
|
||||
bak_file = '/tmp/tmp.sql'
|
||||
|
||||
writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0})
|
||||
dmp_option = ''
|
||||
mode = recognizeDbMode()
|
||||
if mode == 'gtid':
|
||||
dmp_option = ' --set-gtid-purged=off '
|
||||
|
||||
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 + \
|
||||
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
if os.path.exists(bak_file):
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
if version == '8.0':
|
||||
db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
else:
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
@@ -2337,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__":
|
||||
@@ -2386,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':
|
||||
@@ -2479,6 +2785,18 @@ if __name__ == "__main__":
|
||||
print(delSlaveSSH(version))
|
||||
elif func == 'update_slave_ssh':
|
||||
print(updateSlaveSSH(version))
|
||||
elif func == 'get_slave_sync_user_list':
|
||||
print(getSlaveSyncUserList(version))
|
||||
elif func == 'get_slave_sync_user_by_ip':
|
||||
print(getSlaveSyncUserByIp(version))
|
||||
elif func == 'add_slave_sync_user':
|
||||
print(addSlaveSyncUser(version))
|
||||
elif func == 'del_slave_sync_user':
|
||||
print(delSlaveSyncUser(version))
|
||||
elif func == 'get_slave_sync_mode':
|
||||
print(getSlaveSyncMode(version))
|
||||
elif func == 'set_slave_sync_mode':
|
||||
print(setSlaveSyncMode(version))
|
||||
elif func == 'init_slave_status':
|
||||
print(initSlaveStatus(version))
|
||||
elif func == 'set_slave_status':
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"hook":["database"],
|
||||
"title":"MySQL[YUM]",
|
||||
"tip":"soft",
|
||||
"name":"mysql-yum",
|
||||
"type":"运行环境",
|
||||
"ps":"[<b style='color:red;'>潜龙勿用</b>]一种关系数据库管理系统[centos](极速安装)",
|
||||
"ps":"一种关系数据库管理系统[centos](极速安装)",
|
||||
"todo_versions":["5.7","8.0"],
|
||||
"versions":["5.7","8.0"],
|
||||
"shell":"install.sh",
|
||||
|
||||
@@ -265,7 +265,7 @@ function myPerfOpt() {
|
||||
}
|
||||
|
||||
function reBootMySqld(){
|
||||
pluginOpService('mysql-apt','restart','');
|
||||
pluginOpService('mysql-yum','restart','');
|
||||
}
|
||||
|
||||
|
||||
@@ -509,19 +509,6 @@ function showHidePass(obj){
|
||||
}
|
||||
}
|
||||
|
||||
function copyPass(password){
|
||||
var clipboard = new ClipboardJS('#bt_copys');
|
||||
clipboard.on('success', function (e) {
|
||||
layer.msg('复制成功',{icon:1,time:2000});
|
||||
});
|
||||
|
||||
clipboard.on('error', function (e) {
|
||||
layer.msg('复制失败,浏览器不兼容!',{icon:2,time:2000});
|
||||
});
|
||||
$("#bt_copys").attr('data-clipboard-text',password);
|
||||
$("#bt_copys").click();
|
||||
}
|
||||
|
||||
function checkSelect(){
|
||||
setTimeout(function () {
|
||||
var num = $('input[type="checkbox"].check:checked').length;
|
||||
@@ -690,8 +677,8 @@ function addDatabase(type){
|
||||
<span class='tname'>数据库名</span>\
|
||||
<div class='info-r'><input name='name' class='bt-input-text mr5' placeholder='新的数据库名称' type='text' style='width:65%' value=''>\
|
||||
<select class='bt-input-text mr5 codeing_a5nGsm' name='codeing' style='width:27%'>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='utf8mb4'>utf8mb4</option>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='gbk'>gbk</option>\
|
||||
<option value='big5'>big5</option>\
|
||||
</select>\
|
||||
@@ -744,7 +731,7 @@ function addDatabase(type){
|
||||
layer.close(index);
|
||||
dbList();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
},{icon: rdata.status ? 1 : 2}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -831,8 +818,8 @@ 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']});
|
||||
if (rdata.choose != 'mysql-yum'){
|
||||
layer.msg('当前为['+rdata.choose+']模式,若要使用请修改phpMyAdmin访问切换.',{icon:2,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1220,8 +1207,8 @@ function myLogs(){
|
||||
var limitCon = '<p class="conf_p">\
|
||||
<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>\
|
||||
<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: 438px;background-color: #333;color:#fff; padding:0 5px" id="error_log"></textarea>\
|
||||
</p>';
|
||||
$(".soft-man-con").html(limitCon);
|
||||
|
||||
@@ -1558,13 +1545,9 @@ function getMasterRepSlaveUserCmd(username, db=''){
|
||||
function delMasterRepSlaveUser(username){
|
||||
myPost('del_master_rep_slave_user', {username:username}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
layer.msg(rdata.msg);
|
||||
|
||||
$('.layui-layer-close1').click();
|
||||
|
||||
setTimeout(function(){
|
||||
showMsg(rdata.msg, function(){
|
||||
getMasterRepSlaveList();
|
||||
},1000);
|
||||
},{icon: rdata.status ? 1 : 2},1000)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1834,8 +1817,23 @@ function addSlaveSSH(ip=''){
|
||||
function delSlaveSSH(ip){
|
||||
myPost('del_slave_ssh', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2});
|
||||
getSlaveSSHPage();
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSSHPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function delSlaveSyncUser(ip){
|
||||
myPost('del_slave_sync_user', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1885,6 +1883,237 @@ function getSlaveSSHPage(page=1){
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addSlaveSyncUser(ip=''){
|
||||
|
||||
myPost('get_slave_sync_user_by_ip', {ip:ip}, function(rdata){
|
||||
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
var ip = '127.0.0.1';
|
||||
var port = "22";
|
||||
var cmd = '';
|
||||
var user = 'input_sync_user';
|
||||
var pass = 'input_sync_pwd';
|
||||
var mode = '0';
|
||||
|
||||
if (rdata.data.length>0){
|
||||
ip = rdata.data[0]['ip'];
|
||||
port = rdata.data[0]['port'];
|
||||
cmd = rdata.data[0]['cmd'];
|
||||
user = rdata.data[0]['user'];
|
||||
pass = rdata.data[0]['pass'];
|
||||
mode = rdata.data[0]['mode'];
|
||||
}
|
||||
|
||||
var index = layer.open({
|
||||
type: 1,
|
||||
area: ['500px','470px'],
|
||||
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' type='text' style='width:330px;' value='"+ip+"'></div></div>\
|
||||
<div class='line'><span class='tname'>端口</span><div class='info-r'><input name='port' class='bt-input-text mr5' type='number' style='width:330px;' value='"+port+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步账户</span><div class='info-r'><input name='user' class='bt-input-text mr5' type='text' style='width:330px;' value='"+user+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步密码</span><div class='info-r'><input name='pass' class='bt-input-text mr5' type='text' style='width:330px;' value='"+pass+"'></div></div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>CMD[最好填好]</span>\
|
||||
<div class='info-r'><textarea class='bt-input-text mr5' row='20' cols='30' name='cmd' style='width:330px;height:150px;'></textarea></div>\
|
||||
</div>\
|
||||
<input type='hidden' name='mode' value='"+mode+"' />\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="cmd"]').html(cmd);
|
||||
|
||||
$('textarea[name="cmd"]').change(function(){
|
||||
var val = $(this).val();
|
||||
var vlist = val.split(',');
|
||||
var a = {};
|
||||
for (var i in vlist) {
|
||||
var tmp = toTrim(vlist[i]);
|
||||
var tmp_a = tmp.split(" ");
|
||||
var real_tmp = tmp_a[tmp_a.length-1];
|
||||
var kv = real_tmp.split("=");
|
||||
a[kv[0]] = kv[1].replace("'",'').replace("'",'');
|
||||
}
|
||||
|
||||
$('input[name="ip"]').val(a['MASTER_HOST']);
|
||||
$('input[name="port"]').val(a['MASTER_PORT']);
|
||||
$('input[name="user"]').val(a['MASTER_USER']);
|
||||
$('input[name="pass"]').val(a['MASTER_PASSWORD']);
|
||||
|
||||
console.log(a['MASTER_AUTO_POSITION'],typeof(a['MASTER_AUTO_POSITION']));
|
||||
if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){
|
||||
$('input[name="mode"]').val('1');
|
||||
}
|
||||
});
|
||||
},
|
||||
yes:function(index){
|
||||
var ip = $('input[name="ip"]').val();
|
||||
var port = $('input[name="port"]').val();
|
||||
var user = $('input[name="user"]').val();
|
||||
var pass = $('input[name="pass"]').val();
|
||||
var cmd = $('textarea[name="cmd"]').val();
|
||||
var mode = $('input[name="mode"]').val();
|
||||
|
||||
var data = {ip:ip,port:port,cmd:cmd,user:user,pass:pass,mode:mode};
|
||||
myPost('add_slave_sync_user', data, function(ret_data){
|
||||
layer.close(index);
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSyncUserPage(page=1){
|
||||
var _data = {};
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 5;
|
||||
_data['tojs'] ='getSlaveSyncUserPage';
|
||||
myPost('get_slave_sync_user_list', _data, function(data){
|
||||
var layerId = null;
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
var list = '';
|
||||
var user_list = rdata['data'];
|
||||
for (i in user_list) {
|
||||
var ip = user_list[i]['ip'];
|
||||
var port = user_list[i]['port'];
|
||||
var user = user_list[i]['user'];
|
||||
var apass = user_list[i]['pass'];
|
||||
|
||||
var cmd = '未设置';
|
||||
if (user_list[i]['cmd']!=''){
|
||||
cmd = '已设置';
|
||||
}
|
||||
|
||||
list += '<tr><td>'+ip+'</td>\
|
||||
<td>'+port+'</td>\
|
||||
<td>'+user+'</td>\
|
||||
<td>'+apass+'</td>\
|
||||
<td>'+cmd+'</td>\
|
||||
<td>\
|
||||
<a class="btlink" onclick="addSlaveSyncUser(\''+ip+'\');">修改</a> | \
|
||||
<a class="btlink" onclick="delSlaveSyncUser(\''+ip+'\');">删除</a>\
|
||||
</td>\
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$('.get-slave-ssh-list tbody').html(list);
|
||||
$('.dataTables_paginate_4').html(rdata['page']);
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveCfg(){
|
||||
|
||||
myPost('get_slave_sync_mode', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var mode_none = 'success';
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'danger';
|
||||
if(rdata.status){
|
||||
var mode_none = 'danger';
|
||||
if (rdata.data == 'ssh'){
|
||||
var mode_ssh = 'success';
|
||||
var mode_sync_user = 'danger';
|
||||
} else {
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步配置',
|
||||
area: ['400px','180px'],
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>当前从库同步模式</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-"+mode_none+" btn-xs slave-db-mode btn-none'>无</button>\
|
||||
<button class='btn btn-"+mode_ssh+" btn-xs slave-db-mode btn-ssh'>SSH</button>\
|
||||
<button class='btn btn-"+mode_sync_user+" btn-xs slave-db-mode btn-sync-user'>同步账户</button>\
|
||||
</p>\
|
||||
<hr />\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>配置设置</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-success btn-xs btn-slave-ssh'>SSH</button>\
|
||||
<button class='btn btn-success btn-xs btn-slave-user'>同步账户</button>\
|
||||
</p>\
|
||||
</div>",
|
||||
success:function(){
|
||||
$('.btn-slave-ssh').click(function(){
|
||||
getSlaveSSHList();
|
||||
});
|
||||
|
||||
$('.btn-slave-user').click(function(){
|
||||
getSlaveUserList();
|
||||
});
|
||||
|
||||
$('.slave-db-mode').click(function(){
|
||||
var _this = this;
|
||||
var mode = 'none';
|
||||
if ($(this).hasClass('btn-ssh')){
|
||||
mode = 'ssh';
|
||||
}
|
||||
if ($(this).hasClass('btn-sync-user')){
|
||||
mode = 'sync-user';
|
||||
}
|
||||
|
||||
myPost('set_slave_sync_mode', {mode:mode}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
$('.slave-db-mode').remove('btn-success').addClass('btn-danger');
|
||||
$(_this).removeClass('btn-danger').addClass('btn-success');
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getSlaveUserList(){
|
||||
|
||||
var page = '<div class="dataTables_paginate_4 dataTables_paginate paging_bootstrap page" style="margin-top:0px;"></div>';
|
||||
page += '<div class="table_toolbar" style="left:0px;"><span class="sync btn btn-default btn-sm" onclick="addSlaveSyncUser()" title="">添加同步账户</span></div>';
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
<thead><tr><th>IP</th><th>PORT</th><th>同步账户</th><th>同步密码</th><th>CMD</th><th>操作</th></tr></thead>\
|
||||
<tbody></tbody>\
|
||||
</table></div>\
|
||||
"+page +"\
|
||||
</div>\
|
||||
</div>",
|
||||
success:function(){
|
||||
getSlaveSyncUserPage(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSSHList(page=1){
|
||||
|
||||
var page = '<div class="dataTables_paginate_4 dataTables_paginate paging_bootstrap page" style="margin-top:0px;"></div>';
|
||||
@@ -2004,7 +2233,7 @@ function masterOrSlaveConf(version=''){
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "异常";
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
@@ -2046,6 +2275,26 @@ function masterOrSlaveConf(version=''){
|
||||
// <span class="sync btn btn-default btn-sm" onclick="getMasterRepSlaveList()" title="">添加</span>\
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
$('.db_error').click(function(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
</div>\
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2092,7 +2341,6 @@ function masterOrSlaveConf(version=''){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getMasterStatus(){
|
||||
myPost('get_master_status', '', function(rdata){
|
||||
@@ -2123,7 +2371,7 @@ function masterOrSlaveConf(version=''){
|
||||
<p class="conf_p">\
|
||||
<span class="f14 c6 mr20">Slave[从]配置</span><span class="f14 c6 mr20"></span>\
|
||||
<button class="btn '+(!rdata.slave_status ? 'btn-danger' : 'btn-success')+' btn-xs btn-slave">'+(!rdata.slave_status ? '未启动' : '已启动') +'</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveSSHList()" >[主]SSH配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveCfg()" >同步配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="initSlaveStatus()" >初始化</button>\
|
||||
</p>\
|
||||
<hr/>\
|
||||
@@ -2197,10 +2445,10 @@ function masterOrSlaveConf(version=''){
|
||||
getMasterDbList();
|
||||
}
|
||||
|
||||
if (rdata.slave_status){
|
||||
// if (rdata.slave_status){
|
||||
getAsyncMasterDbList();
|
||||
getAsyncDataList()
|
||||
}
|
||||
// }
|
||||
});
|
||||
}
|
||||
getMasterStatus();
|
||||
|
||||
@@ -44,7 +44,7 @@ class backupTools:
|
||||
"----------------------------------------------------------------------------")
|
||||
return
|
||||
|
||||
backup_path = mw.getRootDir() + '/backup/database'
|
||||
backup_path = mw.getRootDir() + '/backup/database/mysql-yum'
|
||||
if not os.path.exists(backup_path):
|
||||
mw.execShell("mkdir -p " + backup_path)
|
||||
|
||||
|
||||
@@ -67,8 +67,10 @@ binlog-ignore-db = performance_schema
|
||||
|
||||
#slave
|
||||
log-slave-updates = 1
|
||||
skip-slave-start = 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
|
||||
|
||||
@@ -69,8 +69,10 @@ binlog-ignore-db = performance_schema
|
||||
|
||||
#slave
|
||||
log-slave-updates = 1
|
||||
skip-slave-start = 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
|
||||
|
||||
@@ -8,9 +8,6 @@ default-character-set = UTF8MB4
|
||||
[mysqld]
|
||||
!include {$SERVER_APP_PATH}/etc/mode/classic.cnf
|
||||
|
||||
;sha256_password_private_key_path=mysql.pem
|
||||
;sha256_password_public_key_path=mysql.pub
|
||||
|
||||
pid-file = {$SERVER_APP_PATH}/data/mysql.pid
|
||||
user = mysql
|
||||
port = 3306
|
||||
@@ -44,6 +41,7 @@ open_files_limit = 2560
|
||||
max_allowed_packet = 128M
|
||||
|
||||
skip_name_resolve = 1
|
||||
skip-ssl
|
||||
#skip-networking
|
||||
#skip-external-locking
|
||||
#loose-skip-innodb
|
||||
@@ -70,9 +68,12 @@ binlog-ignore-db = information_schema
|
||||
binlog-ignore-db = performance_schema
|
||||
|
||||
#slave
|
||||
log-slave-updates = 1
|
||||
skip-slave-start = 1
|
||||
# 5.7 It can not be opened later
|
||||
#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
|
||||
|
||||
@@ -68,8 +68,10 @@ binlog-ignore-db = performance_schema
|
||||
|
||||
#slave
|
||||
log_replica_updates = 1
|
||||
skip_replica_start = 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
|
||||
|
||||
@@ -40,4 +40,17 @@ CREATE TABLE IF NOT EXISTS `slave_id_rsa` (
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
-- 从库配置主库的[user]
|
||||
-- drop table `slave_user`;
|
||||
CREATE TABLE IF NOT EXISTS `slave_sync_user` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`ip` TEXT,
|
||||
`port` TEXT,
|
||||
`user` TEXT,
|
||||
`pass` TEXT,
|
||||
`mode` TEXT,
|
||||
`cmd` TEXT,
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
.conf_p span {
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
width: 135px;
|
||||
width: 115px;
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
|
||||
+401
-38
@@ -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
|
||||
|
||||
|
||||
@@ -127,20 +128,27 @@ def contentReplace(content):
|
||||
def pSqliteDb(dbname='databases'):
|
||||
file = getServerDir() + '/mysql.db'
|
||||
name = 'mysql'
|
||||
if not os.path.exists(file):
|
||||
|
||||
import_sql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
md5_sql = mw.md5(import_sql)
|
||||
|
||||
import_sign = False
|
||||
save_md5_file = getServerDir() + '/import_sql.md5'
|
||||
if os.path.exists(save_md5_file):
|
||||
save_md5_sql = mw.readFile(save_md5_file)
|
||||
if save_md5_sql != md5_sql:
|
||||
import_sign = True
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
else:
|
||||
mw.writeFile(save_md5_file, md5_sql)
|
||||
|
||||
if not os.path.exists(file) or import_sql:
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
csql_list = csql.split(';')
|
||||
csql_list = import_sql.split(';')
|
||||
for index in range(len(csql_list)):
|
||||
conn.execute(csql_list[index], ())
|
||||
else:
|
||||
# 现有run
|
||||
# conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
# csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
# csql_list = csql.split(';')
|
||||
# for index in range(len(csql_list)):
|
||||
# conn.execute(csql_list[index], ())
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
return conn
|
||||
|
||||
|
||||
@@ -481,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,))
|
||||
|
||||
@@ -835,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'])
|
||||
@@ -895,15 +920,22 @@ 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)
|
||||
os.system(mysql_cmd)
|
||||
rdata = mw.execShell(mysql_cmd)
|
||||
myPass(False, pwd)
|
||||
# print(rdata)
|
||||
if ext != 'sql':
|
||||
os.remove(import_sql)
|
||||
|
||||
if rdata[1].lower().find('error') > -1:
|
||||
return mw.returnJson(False, rdata[1])
|
||||
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
@@ -923,13 +955,23 @@ def importDbBackup():
|
||||
cmd = 'cd ' + mw.getRootDir() + '/backup/database && gzip -d ' + file
|
||||
mw.execShell(cmd)
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode == 'gtid':
|
||||
pdb = pMysqlDb()
|
||||
pdb.execute('reset master')
|
||||
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
mysql_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + name + ' < ' + file_path_sql
|
||||
|
||||
# print(mysql_cmd)
|
||||
os.system(mysql_cmd)
|
||||
# os.system(mysql_cmd)
|
||||
|
||||
rdata = mw.execShell(mysql_cmd)
|
||||
if rdata[1].lower().find('error') > -1:
|
||||
return mw.returnJson(False, rdata[1])
|
||||
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
|
||||
@@ -1260,7 +1302,7 @@ def addDb():
|
||||
dataAccess = args['dataAccess'].strip()
|
||||
ps = args['ps'].strip()
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
reg = "^[\w-]+$"
|
||||
if not re.match(reg, args['name']):
|
||||
return mw.returnJson(False, '数据库名称不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
@@ -1928,7 +1970,7 @@ def addMasterRepSlaveUser(version=''):
|
||||
# address = args['address'].strip()
|
||||
# dataAccess = args['dataAccess'].strip()
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
reg = "^[\w-]+$"
|
||||
if not re.match(reg, username):
|
||||
return mw.returnJson(False, '用户名不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
@@ -1956,17 +1998,18 @@ def addMasterRepSlaveUser(version=''):
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
sql = "FLUSH PRIVILEGES;"
|
||||
pdb.execute(sql)
|
||||
else:
|
||||
sql = "GRANT REPLICATION SLAVE ON *.* TO '" + username + \
|
||||
sql = "grant replication SLAVE ON *.* TO '" + username + \
|
||||
"'@'%' identified by '" + password + "';"
|
||||
result = pdb.execute(sql)
|
||||
result = pdb.execute('FLUSH PRIVILEGES;')
|
||||
isError = isSqlError(result)
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
sql_select = "grant select,lock tables,PROCESS on *.* to " + username + "@'%';"
|
||||
pdb.execute(sql_select)
|
||||
pdb.execute('FLUSH PRIVILEGES;')
|
||||
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
psdb.add('username,password,accept,ps,addtime',
|
||||
(username, password, '%', '', addTime))
|
||||
@@ -2103,6 +2146,123 @@ def getSlaveSSHList(version=''):
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSlaveSyncUserByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').where(
|
||||
"ip=?", (ip,)).select()
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
|
||||
|
||||
def addSlaveSyncUser(version=''):
|
||||
import base64
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
if ip == "":
|
||||
return mw.returnJson(True, 'ok')
|
||||
|
||||
data = checkArgs(args, ['port', 'user', 'pass', 'mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
cmd = args['cmd']
|
||||
port = args['port']
|
||||
user = args['user']
|
||||
apass = args['pass']
|
||||
mode = args['mode']
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip').where("ip=?", (ip,)).select()
|
||||
if len(data) > 0:
|
||||
res = conn.where("ip=?", (ip,)).save(
|
||||
'port,user,pass,mode,cmd', (port, user, apass, mode, cmd))
|
||||
else:
|
||||
conn.add('ip,port,user,cmd,user,pass,mode,addtime',
|
||||
(ip, port, user, cmd, user, apass, mode, addTime))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def delSlaveSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ip = args['ip']
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
conn.where("ip=?", (ip,)).delete()
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
def getSlaveSyncUserList(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['page', 'page_size'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
page = int(args['page'])
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
limit = str((page - 1) * page_size) + ',' + str(page_size)
|
||||
|
||||
field = 'id,ip,port,user,pass,cmd,addtime'
|
||||
clist = conn.field(field).limit(limit).order('id desc').select()
|
||||
count = conn.count()
|
||||
|
||||
data = {}
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['p'] = page
|
||||
_page['row'] = page_size
|
||||
_page['tojs'] = args['tojs']
|
||||
data['page'] = mw.getPage(_page)
|
||||
data['data'] = clist
|
||||
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getSyncModeFile():
|
||||
return getServerDir() + "/sync.mode"
|
||||
|
||||
|
||||
def getSlaveSyncMode(version):
|
||||
sync_mode = getSyncModeFile()
|
||||
if os.path.exists(sync_mode):
|
||||
mode = mw.readFile(sync_mode).strip()
|
||||
return mw.returnJson(True, 'ok', mode)
|
||||
return mw.returnJson(False, 'fail')
|
||||
|
||||
|
||||
def setSlaveSyncMode(version):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['mode'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
mode = args['mode']
|
||||
sync_mode = getSyncModeFile()
|
||||
|
||||
if mode == 'none':
|
||||
os.remove(sync_mode)
|
||||
else:
|
||||
mw.writeFile(sync_mode, mode)
|
||||
return mw.returnJson(True, '设置成功', mode)
|
||||
|
||||
|
||||
def getSlaveSSHByIp(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['ip'])
|
||||
@@ -2160,7 +2320,7 @@ def delSlaveSSH(version=''):
|
||||
|
||||
conn = pSqliteDb('slave_id_rsa')
|
||||
conn.where("ip=?", (ip,)).delete()
|
||||
return mw.returnJson(True, 'ok')
|
||||
return mw.returnJson(True, '删除SSH成功!')
|
||||
|
||||
|
||||
def updateSlaveSSH(version=''):
|
||||
@@ -2189,6 +2349,24 @@ def getSlaveList(version=''):
|
||||
tmp['Master_Log_File'] = dlist[x]["Master_Log_File"]
|
||||
tmp['Slave_IO_Running'] = dlist[x]["Slave_IO_Running"]
|
||||
tmp['Slave_SQL_Running'] = dlist[x]["Slave_SQL_Running"]
|
||||
tmp['Last_Error'] = dlist[x]["Last_Error"]
|
||||
tmp['Last_IO_Error'] = dlist[x]["Last_IO_Error"]
|
||||
tmp['Last_SQL_Error'] = dlist[x]["Last_SQL_Error"]
|
||||
tmp['Slave_SQL_Running_State'] = dlist[x]["Slave_SQL_Running_State"]
|
||||
|
||||
tmp['Error'] = ''
|
||||
if tmp['Last_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_Error']
|
||||
|
||||
if tmp['Last_IO_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_IO_Error']
|
||||
|
||||
if tmp['Last_SQL_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_SQL_Error']
|
||||
|
||||
if tmp['Error'] == '':
|
||||
tmp['Error'] = tmp['Slave_SQL_Running_State']
|
||||
|
||||
ret.append(tmp)
|
||||
data = {}
|
||||
data['data'] = ret
|
||||
@@ -2205,6 +2383,77 @@ def getSlaveSyncCmd(version=''):
|
||||
|
||||
|
||||
def initSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return initSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
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()
|
||||
if len(data) < 1:
|
||||
return mw.returnJson(False, '需要先添加同步用户配置!')
|
||||
|
||||
# print(data)
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
return mw.returnJson(False, '已经初始化好了zz...')
|
||||
|
||||
u = data
|
||||
|
||||
mode_name = 'classic'
|
||||
if u['mode'] == '1':
|
||||
mode_name = 'gtid'
|
||||
|
||||
local_mode = recognizeDbMode()
|
||||
if local_mode != mode_name:
|
||||
return mw.returnJson(False, '同步模式不一致!')
|
||||
|
||||
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, '初始化成功!')
|
||||
|
||||
|
||||
def initSlaveStatusSSH(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) > 0:
|
||||
@@ -2214,7 +2463,7 @@ def initSlaveStatus(version=''):
|
||||
data = conn.field('ip,port,id_rsa').find()
|
||||
|
||||
if len(data) < 1:
|
||||
return mw.returnJson(False, '需要先配置【[主]SSH配置】!')
|
||||
return mw.returnJson(False, '需要先添加SSH配置!')
|
||||
|
||||
SSH_PRIVATE_KEY = "/tmp/t_ssh.txt"
|
||||
ip = data['ip']
|
||||
@@ -2273,11 +2522,46 @@ def initSlaveStatus(version=''):
|
||||
|
||||
|
||||
def setSlaveStatus(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return setSlaveStatusSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return setSlaveStatusSyncUser(version)
|
||||
|
||||
|
||||
def setSlaveStatusSyncUser(version=''):
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
return mw.returnJson(False, '需要手动添加同步账户或者执行初始化!')
|
||||
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
db.query('stop slave')
|
||||
else:
|
||||
ip = dlist[0]['Master_Host']
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
if len(data) == 0:
|
||||
return mw.returnJson(False, '没有数据无法重启!')
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
|
||||
db.query("start slave")
|
||||
# db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSlaveStatusSSH(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
if len(dlist) == 0:
|
||||
return mw.returnJson(False, '需要手动添加主服务命令或者执行[初始化]!')
|
||||
return mw.returnJson(False, '需要手动添加主服务命令或者执行初始化!')
|
||||
|
||||
if len(dlist) > 0 and (dlist[0]["Slave_IO_Running"] == 'Yes' or dlist[0]["Slave_SQL_Running"] == 'Yes'):
|
||||
db.query('stop slave')
|
||||
@@ -2342,6 +2626,70 @@ def writeDbSyncStatus(data):
|
||||
|
||||
|
||||
def doFullSync(version=''):
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
|
||||
mode = mw.readFile(mode_file)
|
||||
if mode == 'ssh':
|
||||
return doFullSyncSSH(version)
|
||||
if mode == 'sync-user':
|
||||
return doFullSyncUser(version)
|
||||
|
||||
|
||||
def doFullSyncUser(version=''):
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
sync_db = args['db']
|
||||
|
||||
db = pMysqlDb()
|
||||
|
||||
conn = pSqliteDb('slave_sync_user')
|
||||
data = conn.field('ip,port,user,pass,mode,cmd').find()
|
||||
user = data['user']
|
||||
apass = data['pass']
|
||||
port = data['port']
|
||||
ip = data['ip']
|
||||
|
||||
bak_file = '/tmp/tmp.sql'
|
||||
|
||||
writeDbSyncStatus({'code': 0, 'msg': '开始同步...', 'progress': 0})
|
||||
dmp_option = ''
|
||||
mode = recognizeDbMode()
|
||||
if mode == 'gtid':
|
||||
dmp_option = ' --set-gtid-purged=off '
|
||||
|
||||
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 + \
|
||||
"\" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
|
||||
# print(dump_sql_data)
|
||||
mw.execShell(dump_sql_data)
|
||||
|
||||
writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
|
||||
if os.path.exists(bak_file):
|
||||
pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')
|
||||
sock = getSocketFile()
|
||||
my_import_cmd = getServerDir() + '/bin/mysql -S ' + sock + ' -uroot -p' + pwd + \
|
||||
' ' + sync_db + ' < ' + bak_file
|
||||
mw.execShell(my_import_cmd)
|
||||
|
||||
if version == '8.0':
|
||||
db.query("start slave user='{}' password='{}';".format(user, apass))
|
||||
else:
|
||||
db.query("start slave")
|
||||
|
||||
writeDbSyncStatus({'code': 6, 'msg': '从库重启完成...', 'progress': 100})
|
||||
os.system("rm -rf " + bak_file)
|
||||
return True
|
||||
|
||||
|
||||
def doFullSyncSSH(version=''):
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['db'])
|
||||
@@ -2511,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__":
|
||||
@@ -2653,6 +3004,18 @@ if __name__ == "__main__":
|
||||
print(delSlaveSSH(version))
|
||||
elif func == 'update_slave_ssh':
|
||||
print(updateSlaveSSH(version))
|
||||
elif func == 'get_slave_sync_user_list':
|
||||
print(getSlaveSyncUserList(version))
|
||||
elif func == 'get_slave_sync_user_by_ip':
|
||||
print(getSlaveSyncUserByIp(version))
|
||||
elif func == 'add_slave_sync_user':
|
||||
print(addSlaveSyncUser(version))
|
||||
elif func == 'del_slave_sync_user':
|
||||
print(delSlaveSyncUser(version))
|
||||
elif func == 'get_slave_sync_mode':
|
||||
print(getSlaveSyncMode(version))
|
||||
elif func == 'set_slave_sync_mode':
|
||||
print(setSlaveSyncMode(version))
|
||||
elif func == 'init_slave_status':
|
||||
print(initSlaveStatus(version))
|
||||
elif func == 'set_slave_status':
|
||||
|
||||
+278
-30
@@ -509,19 +509,6 @@ function showHidePass(obj){
|
||||
}
|
||||
}
|
||||
|
||||
function copyPass(password){
|
||||
var clipboard = new ClipboardJS('#bt_copys');
|
||||
clipboard.on('success', function (e) {
|
||||
layer.msg('复制成功',{icon:1,time:2000});
|
||||
});
|
||||
|
||||
clipboard.on('error', function (e) {
|
||||
layer.msg('复制失败,浏览器不兼容!',{icon:2,time:2000});
|
||||
});
|
||||
$("#bt_copys").attr('data-clipboard-text',password);
|
||||
$("#bt_copys").click();
|
||||
}
|
||||
|
||||
function checkSelect(){
|
||||
setTimeout(function () {
|
||||
var num = $('input[type="checkbox"].check:checked').length;
|
||||
@@ -690,8 +677,8 @@ function addDatabase(type){
|
||||
<span class='tname'>数据库名</span>\
|
||||
<div class='info-r'><input name='name' class='bt-input-text mr5' placeholder='新的数据库名称' type='text' style='width:65%' value=''>\
|
||||
<select class='bt-input-text mr5 codeing_a5nGsm' name='codeing' style='width:27%'>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='utf8mb4'>utf8mb4</option>\
|
||||
<option value='utf8'>utf-8</option>\
|
||||
<option value='gbk'>gbk</option>\
|
||||
<option value='big5'>big5</option>\
|
||||
</select>\
|
||||
@@ -744,7 +731,7 @@ function addDatabase(type){
|
||||
layer.close(index);
|
||||
dbList();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
},{icon: rdata.status ? 1 : 2}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -832,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;
|
||||
}
|
||||
|
||||
@@ -1221,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);
|
||||
|
||||
@@ -1558,13 +1545,9 @@ function getMasterRepSlaveUserCmd(username, db=''){
|
||||
function delMasterRepSlaveUser(username){
|
||||
myPost('del_master_rep_slave_user', {username:username}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
layer.msg(rdata.msg);
|
||||
|
||||
$('.layui-layer-close1').click();
|
||||
|
||||
setTimeout(function(){
|
||||
showMsg(rdata.msg, function(){
|
||||
getMasterRepSlaveList();
|
||||
},1000);
|
||||
},{icon: rdata.status ? 1 : 2},1000)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1834,8 +1817,23 @@ function addSlaveSSH(ip=''){
|
||||
function delSlaveSSH(ip){
|
||||
myPost('del_slave_ssh', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2});
|
||||
getSlaveSSHPage();
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSSHPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function delSlaveSyncUser(ip){
|
||||
myPost('del_slave_sync_user', {ip:ip}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2}, 600);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1885,6 +1883,237 @@ function getSlaveSSHPage(page=1){
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addSlaveSyncUser(ip=''){
|
||||
|
||||
myPost('get_slave_sync_user_by_ip', {ip:ip}, function(rdata){
|
||||
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
var ip = '127.0.0.1';
|
||||
var port = "22";
|
||||
var cmd = '';
|
||||
var user = 'input_sync_user';
|
||||
var pass = 'input_sync_pwd';
|
||||
var mode = '0';
|
||||
|
||||
if (rdata.data.length>0){
|
||||
ip = rdata.data[0]['ip'];
|
||||
port = rdata.data[0]['port'];
|
||||
cmd = rdata.data[0]['cmd'];
|
||||
user = rdata.data[0]['user'];
|
||||
pass = rdata.data[0]['pass'];
|
||||
mode = rdata.data[0]['mode'];
|
||||
}
|
||||
|
||||
var index = layer.open({
|
||||
type: 1,
|
||||
area: ['500px','470px'],
|
||||
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' type='text' style='width:330px;' value='"+ip+"'></div></div>\
|
||||
<div class='line'><span class='tname'>端口</span><div class='info-r'><input name='port' class='bt-input-text mr5' type='number' style='width:330px;' value='"+port+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步账户</span><div class='info-r'><input name='user' class='bt-input-text mr5' type='text' style='width:330px;' value='"+user+"'></div></div>\
|
||||
<div class='line'><span class='tname'>同步密码</span><div class='info-r'><input name='pass' class='bt-input-text mr5' type='text' style='width:330px;' value='"+pass+"'></div></div>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>CMD[最好填好]</span>\
|
||||
<div class='info-r'><textarea class='bt-input-text mr5' row='20' cols='30' name='cmd' style='width:330px;height:150px;'></textarea></div>\
|
||||
</div>\
|
||||
<input type='hidden' name='mode' value='"+mode+"' />\
|
||||
</form>",
|
||||
success:function(){
|
||||
$('textarea[name="cmd"]').html(cmd);
|
||||
|
||||
$('textarea[name="cmd"]').change(function(){
|
||||
var val = $(this).val();
|
||||
var vlist = val.split(',');
|
||||
var a = {};
|
||||
for (var i in vlist) {
|
||||
var tmp = toTrim(vlist[i]);
|
||||
var tmp_a = tmp.split(" ");
|
||||
var real_tmp = tmp_a[tmp_a.length-1];
|
||||
var kv = real_tmp.split("=");
|
||||
a[kv[0]] = kv[1].replace("'",'').replace("'",'');
|
||||
}
|
||||
|
||||
$('input[name="ip"]').val(a['MASTER_HOST']);
|
||||
$('input[name="port"]').val(a['MASTER_PORT']);
|
||||
$('input[name="user"]').val(a['MASTER_USER']);
|
||||
$('input[name="pass"]').val(a['MASTER_PASSWORD']);
|
||||
|
||||
console.log(a['MASTER_AUTO_POSITION'],typeof(a['MASTER_AUTO_POSITION']));
|
||||
if (typeof(a['MASTER_AUTO_POSITION']) != 'undefined' ){
|
||||
$('input[name="mode"]').val('1');
|
||||
}
|
||||
});
|
||||
},
|
||||
yes:function(index){
|
||||
var ip = $('input[name="ip"]').val();
|
||||
var port = $('input[name="port"]').val();
|
||||
var user = $('input[name="user"]').val();
|
||||
var pass = $('input[name="pass"]').val();
|
||||
var cmd = $('textarea[name="cmd"]').val();
|
||||
var mode = $('input[name="mode"]').val();
|
||||
|
||||
var data = {ip:ip,port:port,cmd:cmd,user:user,pass:pass,mode:mode};
|
||||
myPost('add_slave_sync_user', data, function(ret_data){
|
||||
layer.close(index);
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
getSlaveSyncUserPage();
|
||||
}
|
||||
},{icon: rdata.status ? 1 : 2},600);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSyncUserPage(page=1){
|
||||
var _data = {};
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 5;
|
||||
_data['tojs'] ='getSlaveSyncUserPage';
|
||||
myPost('get_slave_sync_user_list', _data, function(data){
|
||||
var layerId = null;
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
var list = '';
|
||||
var user_list = rdata['data'];
|
||||
for (i in user_list) {
|
||||
var ip = user_list[i]['ip'];
|
||||
var port = user_list[i]['port'];
|
||||
var user = user_list[i]['user'];
|
||||
var apass = user_list[i]['pass'];
|
||||
|
||||
var cmd = '未设置';
|
||||
if (user_list[i]['cmd']!=''){
|
||||
cmd = '已设置';
|
||||
}
|
||||
|
||||
list += '<tr><td>'+ip+'</td>\
|
||||
<td>'+port+'</td>\
|
||||
<td>'+user+'</td>\
|
||||
<td>'+apass+'</td>\
|
||||
<td>'+cmd+'</td>\
|
||||
<td>\
|
||||
<a class="btlink" onclick="addSlaveSyncUser(\''+ip+'\');">修改</a> | \
|
||||
<a class="btlink" onclick="delSlaveSyncUser(\''+ip+'\');">删除</a>\
|
||||
</td>\
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$('.get-slave-ssh-list tbody').html(list);
|
||||
$('.dataTables_paginate_4').html(rdata['page']);
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveCfg(){
|
||||
|
||||
myPost('get_slave_sync_mode', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var mode_none = 'success';
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'danger';
|
||||
if(rdata.status){
|
||||
var mode_none = 'danger';
|
||||
if (rdata.data == 'ssh'){
|
||||
var mode_ssh = 'success';
|
||||
var mode_sync_user = 'danger';
|
||||
} else {
|
||||
var mode_ssh = 'danger';
|
||||
var mode_sync_user = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步配置',
|
||||
area: ['400px','180px'],
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>当前从库同步模式</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-"+mode_none+" btn-xs slave-db-mode btn-none'>无</button>\
|
||||
<button class='btn btn-"+mode_ssh+" btn-xs slave-db-mode btn-ssh'>SSH</button>\
|
||||
<button class='btn btn-"+mode_sync_user+" btn-xs slave-db-mode btn-sync-user'>同步账户</button>\
|
||||
</p>\
|
||||
<hr />\
|
||||
<p class='conf_p'>\
|
||||
<span class='f14 c6 mr20'>配置设置</span>\
|
||||
<b class='f14 c6 mr20'></b>\
|
||||
<button class='btn btn-success btn-xs btn-slave-ssh'>SSH</button>\
|
||||
<button class='btn btn-success btn-xs btn-slave-user'>同步账户</button>\
|
||||
</p>\
|
||||
</div>",
|
||||
success:function(){
|
||||
$('.btn-slave-ssh').click(function(){
|
||||
getSlaveSSHList();
|
||||
});
|
||||
|
||||
$('.btn-slave-user').click(function(){
|
||||
getSlaveUserList();
|
||||
});
|
||||
|
||||
$('.slave-db-mode').click(function(){
|
||||
var _this = this;
|
||||
var mode = 'none';
|
||||
if ($(this).hasClass('btn-ssh')){
|
||||
mode = 'ssh';
|
||||
}
|
||||
if ($(this).hasClass('btn-sync-user')){
|
||||
mode = 'sync-user';
|
||||
}
|
||||
|
||||
myPost('set_slave_sync_mode', {mode:mode}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
$('.slave-db-mode').remove('btn-success').addClass('btn-danger');
|
||||
$(_this).removeClass('btn-danger').addClass('btn-success');
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getSlaveUserList(){
|
||||
|
||||
var page = '<div class="dataTables_paginate_4 dataTables_paginate paging_bootstrap page" style="margin-top:0px;"></div>';
|
||||
page += '<div class="table_toolbar" style="left:0px;"><span class="sync btn btn-default btn-sm" onclick="addSlaveSyncUser()" title="">添加同步账户</span></div>';
|
||||
|
||||
layerId = layer.open({
|
||||
type: 1,
|
||||
title: '同步账户列表',
|
||||
area: '500px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div class='divtable mtb10'>\
|
||||
<div><table class='table table-hover get-slave-ssh-list'>\
|
||||
<thead><tr><th>IP</th><th>PORT</th><th>同步账户</th><th>同步密码</th><th>CMD</th><th>操作</th></tr></thead>\
|
||||
<tbody></tbody>\
|
||||
</table></div>\
|
||||
"+page +"\
|
||||
</div>\
|
||||
</div>",
|
||||
success:function(){
|
||||
getSlaveSyncUserPage(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getSlaveSSHList(page=1){
|
||||
|
||||
var page = '<div class="dataTables_paginate_4 dataTables_paginate paging_bootstrap page" style="margin-top:0px;"></div>';
|
||||
@@ -2004,7 +2233,7 @@ function masterOrSlaveConf(version=''){
|
||||
for(i in rdata.data){
|
||||
|
||||
var v = rdata.data[i];
|
||||
var status = "异常";
|
||||
var status = "<a class='btlink db_error'>异常</>";
|
||||
if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){
|
||||
status = "正常";
|
||||
}
|
||||
@@ -2046,6 +2275,26 @@ function masterOrSlaveConf(version=''){
|
||||
// <span class="sync btn btn-default btn-sm" onclick="getMasterRepSlaveList()" title="">添加</span>\
|
||||
// </div>
|
||||
$(".table_slave_status_list").html(con);
|
||||
|
||||
$('.db_error').click(function(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: '同步异常信息',
|
||||
area: '500px',
|
||||
content:"<form class='bt-form pd20 pb70'>\
|
||||
<div class='line'>"+v['Error']+"</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' class='btn btn-success btn-sm btn-title class-copy-db-err'>复制</button>\
|
||||
</div>\
|
||||
</form>",
|
||||
success:function(){
|
||||
copyText(v['Error']);
|
||||
$('.class-copy-db-err').click(function(){
|
||||
copyText(v['Error']);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2092,7 +2341,6 @@ function masterOrSlaveConf(version=''){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getMasterStatus(){
|
||||
myPost('get_master_status', '', function(rdata){
|
||||
@@ -2123,7 +2371,7 @@ function masterOrSlaveConf(version=''){
|
||||
<p class="conf_p">\
|
||||
<span class="f14 c6 mr20">Slave[从]配置</span><span class="f14 c6 mr20"></span>\
|
||||
<button class="btn '+(!rdata.slave_status ? 'btn-danger' : 'btn-success')+' btn-xs btn-slave">'+(!rdata.slave_status ? '未启动' : '已启动') +'</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveSSHList()" >[主]SSH配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="getSlaveCfg()" >同步配置</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="initSlaveStatus()" >初始化</button>\
|
||||
</p>\
|
||||
<hr/>\
|
||||
@@ -2197,10 +2445,10 @@ function masterOrSlaveConf(version=''){
|
||||
getMasterDbList();
|
||||
}
|
||||
|
||||
if (rdata.slave_status){
|
||||
// if (rdata.slave_status){
|
||||
getAsyncMasterDbList();
|
||||
getAsyncDataList()
|
||||
}
|
||||
// }
|
||||
});
|
||||
}
|
||||
getMasterStatus();
|
||||
|
||||
@@ -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,11 +59,11 @@ 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
|
||||
fi
|
||||
|
||||
|
||||
cd ${openrestyDir} && tar -zxvf openresty-${VERSION}.tar.gz
|
||||
|
||||
# --with-openssl=$serverPath/source/lib/openssl-1.0.2q
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"name": "php-apt",
|
||||
"title": "PHP[APT]",
|
||||
"coexist": true,
|
||||
"versions": ["56","70","71","72","73","74","80","81"],
|
||||
"versions": ["56","70","71","72","73","74","80","81","82"],
|
||||
"install_pre_inspection":true,
|
||||
"tip": "soft",
|
||||
"checks": "server/php-apt/VERSION",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user