Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
243ff1c692 | ||
|
|
585e10559e | ||
|
|
368f4e193b | ||
|
|
d958b0c743 | ||
|
|
fd1503eed5 | ||
|
|
f10695b0bf | ||
|
|
ae22bdbe32 | ||
|
|
f7aba34d1e | ||
|
|
c3e8950139 | ||
|
|
d0228eb2ce | ||
|
|
b8daf8c3b8 | ||
|
|
9a6a1fff4c | ||
|
|
49865d57d9 | ||
|
|
1dd7c85876 | ||
|
|
dd16ce6659 | ||
|
|
16381ce7e0 | ||
|
|
3e9cccb86e | ||
|
|
f91156a0cb | ||
|
|
7231be3944 | ||
|
|
1ebbee14a5 | ||
|
|
f2fe889a7c | ||
|
|
e19af0a4d1 | ||
|
|
c62a3424bc | ||
|
|
8508c9bd5e | ||
|
|
253c58f3c8 | ||
|
|
0a096ffef4 | ||
|
|
b45dfe048e | ||
|
|
3c848e5216 | ||
|
|
0d77cd92d5 | ||
|
|
b9642cc9c3 | ||
|
|
c6a70c53a0 | ||
|
|
70a50254d6 | ||
|
|
8aacbc7bc5 | ||
|
|
67cefe1278 | ||
|
|
c972af584c | ||
|
|
8e889710d7 | ||
|
|
af6f9243ff | ||
|
|
9a56ea5d51 | ||
|
|
173eeba97f | ||
|
|
ca6371edb1 | ||
|
|
f57b2b7b34 | ||
|
|
e263b062c5 | ||
|
|
29b064d65f | ||
|
|
bf6b762371 | ||
|
|
2b5aefd1e8 | ||
|
|
438d5084c9 | ||
|
|
e3ed556f0f | ||
|
|
cfb53ca703 | ||
|
|
0afd382e6c | ||
|
|
ef519331e2 | ||
|
|
19fee9b51b | ||
|
|
16a7f6a4c4 | ||
|
|
1aca99b2d7 | ||
|
|
2733d99cf7 | ||
|
|
6750103337 | ||
|
|
eaff3b8c39 | ||
|
|
c9a9807dd5 | ||
|
|
2b04bf8b5a | ||
|
|
62c84206a4 | ||
|
|
2650174eed | ||
|
|
d199b26ce2 | ||
|
|
0c25ec5978 | ||
|
|
055ff30e39 | ||
|
|
0f39cdbe7b | ||
|
|
4710432572 | ||
|
|
e0c8c73b91 | ||
|
|
b39f0c30ef | ||
|
|
c1753a6d19 | ||
|
|
8f384eaac4 | ||
|
|
a51d6bc50a | ||
|
|
43144804c7 | ||
|
|
dfe4748e97 | ||
|
|
30af159034 | ||
|
|
8819907be5 | ||
|
|
1a29ab0046 | ||
|
|
0ffec7df7f | ||
|
|
876b2d2588 | ||
|
|
af4be7f130 | ||
|
|
0e6cc0f40f | ||
|
|
08d39c33fa | ||
|
|
b76028412c | ||
|
|
fcea0f5332 | ||
|
|
a910cc2b43 | ||
|
|
6df3b36c58 | ||
|
|
e1228b9d69 | ||
|
|
6fff5d2de2 | ||
|
|
ce0eed3577 | ||
|
|
b839e01009 | ||
|
|
bf476e643f | ||
|
|
b88a4d8318 | ||
|
|
12931e7912 | ||
|
|
9205557566 | ||
|
|
4b127fb3f8 | ||
|
|
3728937dc5 | ||
|
|
54b561e278 | ||
|
|
e21f0df3d5 | ||
|
|
c849eb5054 | ||
|
|
799bad5eb6 | ||
|
|
bc103289db | ||
|
|
bbc2e82d12 | ||
|
|
2f3df076de | ||
|
|
9ffc3cdb2f | ||
|
|
d4cb851230 | ||
|
|
f88aa21076 | ||
|
|
c7332fad22 | ||
|
|
0bb158362e | ||
|
|
e9b7a8082b | ||
|
|
4b3c4b7168 | ||
|
|
585b2feb8f | ||
|
|
32b32ff3fc | ||
|
|
adca59d2b4 | ||
|
|
cea315deac | ||
|
|
3174286694 | ||
|
|
bcd213ac54 | ||
|
|
39a2c5ef8c | ||
|
|
dd4ff10cf4 | ||
|
|
2bd015c29f | ||
|
|
f59595e137 | ||
|
|
5cb674a165 | ||
|
|
d69cd1e033 | ||
|
|
252ce08659 | ||
|
|
7e17e47d75 | ||
|
|
9ae2de4dde | ||
|
|
27f2a60298 | ||
|
|
daf4af3abb | ||
|
|
2e775a5cf7 | ||
|
|
f26b4c334b | ||
|
|
b821409b04 | ||
|
|
de4111df21 | ||
|
|
a8817ede54 | ||
|
|
b86380e506 | ||
|
|
b2a6c66439 | ||
|
|
a48785b7aa | ||
|
|
b4362a68fc | ||
|
|
103b96eb19 | ||
|
|
e093e38c17 | ||
|
|
a3a801370b | ||
|
|
bb9b4501c2 | ||
|
|
492c259568 | ||
|
|
c5efa76623 | ||
|
|
b44cd17324 | ||
|
|
acf7f297f0 | ||
|
|
fdb24b115b | ||
|
|
1cd77f877d | ||
|
|
f3ad499273 | ||
|
|
8fca98bdf8 | ||
|
|
7123027287 | ||
|
|
90a85b1b88 | ||
|
|
745b056be9 | ||
|
|
831fe8e32e | ||
|
|
50e2da3fcb | ||
|
|
7db25b9c3a | ||
|
|
be3358b744 | ||
|
|
965fa40429 | ||
|
|
944181c79b | ||
|
|
6332cfbf9b | ||
|
|
7cd1a0ade9 | ||
|
|
57ca48f127 | ||
|
|
08e1811dc8 | ||
|
|
d02c2b70a4 | ||
|
|
a7d23e6ff3 | ||
|
|
db954f8071 | ||
|
|
ce08f966d2 | ||
|
|
87cdc8634f | ||
|
|
3068d972ae | ||
|
|
e2e5c0dd75 | ||
|
|
ed1a361fd0 | ||
|
|
23c26f13c0 | ||
|
|
fdb674282c | ||
|
|
78a733606a | ||
|
|
36182e4b60 | ||
|
|
65528fbcf2 | ||
|
|
9b0b5b00c1 | ||
|
|
899b512ddf | ||
|
|
bf622b87ba | ||
|
|
700332ef0d | ||
|
|
02d8c6b561 | ||
|
|
f7c04f3271 | ||
|
|
257816e793 | ||
|
|
00e16e88ff | ||
|
|
c265f0ea2a | ||
|
|
4085181585 | ||
|
|
55ee7acd97 | ||
|
|
a1894ca898 | ||
|
|
191b21b8cd | ||
|
|
c5d96a4105 | ||
|
|
37b4e234ef | ||
|
|
955687ba31 | ||
|
|
22018dab14 | ||
|
|
7084d7df85 | ||
|
|
83a5e8eb99 | ||
|
|
e505eaa72c | ||
|
|
d4fdd0843c | ||
|
|
eeafa867a5 | ||
|
|
352ac408ed | ||
|
|
9fedfa1023 | ||
|
|
c0afe54bc3 | ||
|
|
91bcc55fbf | ||
|
|
783e475872 | ||
|
|
e53df0cede | ||
|
|
c44a5dade8 | ||
|
|
19a1e31904 | ||
|
|
bc9525938a | ||
|
|
605b6af9d5 | ||
|
|
0c25fca0f8 | ||
|
|
790d985afc | ||
|
|
4a347fe301 | ||
|
|
05011dec7b | ||
|
|
0d9b65ce8a | ||
|
|
97f39e5124 | ||
|
|
9aea12ce5a | ||
|
|
b96555fa42 | ||
|
|
59a7a4e529 | ||
|
|
691a4d00f8 | ||
|
|
dc1e9a8aaa | ||
|
|
05cc45b068 | ||
|
|
00e4fc7a46 | ||
|
|
5202ff3450 | ||
|
|
5d24ada208 | ||
|
|
fda685d0e1 | ||
|
|
4306090a8a | ||
|
|
c7db78dac9 | ||
|
|
e19b776cd4 | ||
|
|
e2dd6be756 | ||
|
|
834f92933e | ||
|
|
d740a2774a | ||
|
|
9d3e926256 | ||
|
|
ab81f5b68e | ||
|
|
ae2010c984 | ||
|
|
b7aee56575 | ||
|
|
5145273283 | ||
|
|
8a2a142ddb | ||
|
|
3808aa38db | ||
|
|
021b97045b | ||
|
|
da79a8a1d1 | ||
|
|
9d0edc5663 | ||
|
|
e94acba817 | ||
|
|
6dda9a7d4c | ||
|
|
50757324fb | ||
|
|
7ed25bf8be | ||
|
|
f4d7ed0842 | ||
|
|
a58ebd2c83 | ||
|
|
fc02709aea | ||
|
|
6a2570b794 | ||
|
|
0b379afd38 | ||
|
|
1f3b145a8c | ||
|
|
8c5c0a8737 | ||
|
|
f1e579eeef | ||
|
|
f7d86c524d | ||
|
|
00315a8892 | ||
|
|
8be1e9f865 | ||
|
|
c0667e2dca | ||
|
|
ccd9cede1b | ||
|
|
91d5a35981 | ||
|
|
7b1774308f | ||
|
|
d0a958426f | ||
|
|
4d21655a1e | ||
|
|
1eb10e3882 | ||
|
|
fa447891be | ||
|
|
a403246ee0 | ||
|
|
eb131757ac | ||
|
|
3b1923bbfd | ||
|
|
5a16772d13 | ||
|
|
3f728b2f9d | ||
|
|
ed3fc3beb4 | ||
|
|
57f080cab5 | ||
|
|
4ccdd28f29 | ||
|
|
ed7884b0e0 | ||
|
|
d35bde9123 | ||
|
|
b0611fc007 | ||
|
|
dea5b3d558 | ||
|
|
ccb27f0253 | ||
|
|
302a5c52d2 | ||
|
|
648f61c1b7 | ||
|
|
07b20bd29d | ||
|
|
eef3686fff | ||
|
|
329d8dd44d | ||
|
|
859fbf70e3 | ||
|
|
cd8fe01cf4 | ||
|
|
b6d62cf8ac | ||
|
|
1c58c6f131 | ||
|
|
f6a93ef531 | ||
|
|
7aaa831589 | ||
|
|
ab648d6f0c | ||
|
|
8257673d2d | ||
|
|
f1793a740e | ||
|
|
92c06df0c0 | ||
|
|
968d03d58b | ||
|
|
c6fcb444ab | ||
|
|
5107fdfe6c | ||
|
|
1f8b1f2e89 | ||
|
|
76975bd75c | ||
|
|
4f6b35d38d | ||
|
|
c9a4d8285b | ||
|
|
2b68fbdc13 | ||
|
|
09e69c7202 | ||
|
|
36d858d1c7 | ||
|
|
96188ee6ed | ||
|
|
5c13ceecc8 | ||
|
|
cb8464f4a8 | ||
|
|
d251431baa | ||
|
|
1c9424c4ba | ||
|
|
9142347855 | ||
|
|
0518995921 | ||
|
|
e4e342397c | ||
|
|
bebb6e989b | ||
|
|
f8dc745aa2 | ||
|
|
9d5c3fd870 | ||
|
|
d331db723b | ||
|
|
e2d85edbfb | ||
|
|
f08d2eb500 | ||
|
|
3433d32457 | ||
|
|
371c2ab1c0 | ||
|
|
ef3315233e | ||
|
|
9dd569be36 | ||
|
|
50b006bf72 | ||
|
|
ad571da40d | ||
|
|
75d13b0649 | ||
|
|
d1bbbdf67a | ||
|
|
63ba9774f9 | ||
|
|
f8a22a5013 | ||
|
|
d3ce4e7491 | ||
|
|
a8a0a1d65d | ||
|
|
b7d7d9eccc | ||
|
|
3bed88a75d | ||
|
|
a01e0100ed | ||
|
|
e4215735f5 | ||
|
|
754714b381 | ||
|
|
9e56409063 | ||
|
|
2c3126c489 | ||
|
|
b5c0b4d895 | ||
|
|
720f842d4b | ||
|
|
5224307da7 | ||
|
|
d7de698fc8 | ||
|
|
894d0c7503 | ||
|
|
b4604bc4da | ||
|
|
bc60a0f184 | ||
|
|
40bc744ea6 | ||
|
|
22e1eabb55 | ||
|
|
d43cbde1f6 | ||
|
|
acffdd76a1 | ||
|
|
c7720066ec | ||
|
|
54743588bb | ||
|
|
0d4c13e0a5 | ||
|
|
f95c25cf73 | ||
|
|
cfe1747160 | ||
|
|
60041da54c | ||
|
|
ebd1a11392 | ||
|
|
73e63027db | ||
|
|
880ace7445 | ||
|
|
f391813a28 | ||
|
|
03e32ba989 | ||
|
|
3674a99c8c | ||
|
|
5a91bc2077 | ||
|
|
da6e392bb1 | ||
|
|
88d25391af | ||
|
|
e6b825dfc9 | ||
|
|
55c263902e | ||
|
|
f459acdfb4 | ||
|
|
6f1b32a152 | ||
|
|
878c717f89 | ||
|
|
7e60ed14b5 | ||
|
|
16be6d1b55 | ||
|
|
96e7b0255f | ||
|
|
805b129c3b | ||
|
|
89e2a4c2eb | ||
|
|
a732febf3b | ||
|
|
494d59cc93 | ||
|
|
b73491cde1 | ||
|
|
8c8af7c6b6 | ||
|
|
c9b755360c | ||
|
|
1b3dc6d831 | ||
|
|
b3966c98fe | ||
|
|
72e10ced88 | ||
|
|
bcf9334aa5 | ||
|
|
27a7a67e3c | ||
|
|
cf58f113c0 | ||
|
|
de63b7df43 | ||
|
|
9ff29c810c | ||
|
|
77ed98d407 | ||
|
|
f22914c3ad | ||
|
|
d4f3e46277 | ||
|
|
fe6f6043e2 | ||
|
|
33b7f9f570 | ||
|
|
ead0f19f60 | ||
|
|
671a0eae8b | ||
|
|
3f08bf96f9 | ||
|
|
41e38fa6f2 | ||
|
|
47ea9419ab | ||
|
|
7be6f51785 | ||
|
|
40489de7f7 | ||
|
|
ccb6bafb93 | ||
|
|
9289a4472a | ||
|
|
3cdd228d36 | ||
|
|
6bd853b6f6 | ||
|
|
a296e0733f | ||
|
|
b6d6fedca2 | ||
|
|
f1ae3ca758 | ||
|
|
1fcad2a9fc | ||
|
|
8dabf5af1d | ||
|
|
b79def8dbf | ||
|
|
4b39a94d88 | ||
|
|
7dcb696492 | ||
|
|
dd76c2c1c9 | ||
|
|
7c9f777eac | ||
|
|
f6e62c1241 | ||
|
|
db6cdf941e | ||
|
|
9fbdbb1c02 | ||
|
|
4f5d575aa4 | ||
|
|
ddd68f7f87 | ||
|
|
8e655777f4 | ||
|
|
7014f91864 | ||
|
|
c6a7aeaca4 | ||
|
|
6d2ab40638 | ||
|
|
2d81bdc286 | ||
|
|
7f38e1fa0d | ||
|
|
f522bdb6ee | ||
|
|
b0cfea6f21 | ||
|
|
0897f84a04 | ||
|
|
0865c98a7f | ||
|
|
aec1a25557 | ||
|
|
6186af44df | ||
|
|
9061201684 | ||
|
|
6abfa6de1a | ||
|
|
77c4a0cea4 | ||
|
|
2f9ee7130f | ||
|
|
f6063e0d6c | ||
|
|
090be360c8 | ||
|
|
3ec790d98d | ||
|
|
876d3ccc6f | ||
|
|
05c27b9365 | ||
|
|
1fec6c3649 | ||
|
|
1776dc7289 | ||
|
|
d3915e3b6d | ||
|
|
26f48aa7f1 | ||
|
|
3dc16414c5 | ||
|
|
acb4e50ee7 | ||
|
|
8a04e17631 | ||
|
|
66133d6cbb | ||
|
|
7ede000597 | ||
|
|
a4247eb4b5 | ||
|
|
0fc993aeb5 | ||
|
|
5010ed7f57 | ||
|
|
ef3dc10215 | ||
|
|
8018a57344 | ||
|
|
b43bcb1c96 | ||
|
|
e2d249a576 | ||
|
|
196c08cb32 | ||
|
|
dc9eea6cc7 | ||
|
|
1be9e5472f | ||
|
|
824393c5c3 | ||
|
|
533dd083fe | ||
|
|
ed68410220 | ||
|
|
f95bb6c6d3 | ||
|
|
704bba92d1 | ||
|
|
632bd12bfa | ||
|
|
72c695de4a | ||
|
|
5c37505430 | ||
|
|
099d3fcf2c | ||
|
|
c7a5388cfd | ||
|
|
109821b068 | ||
|
|
4a34eb80dc | ||
|
|
b4f72d295e | ||
|
|
b2d1de472b | ||
|
|
f7412501e7 | ||
|
|
5bf52e9e24 | ||
|
|
b5a0daa69d | ||
|
|
13d90df9ef | ||
|
|
f72e3565e5 | ||
|
|
0af9943540 | ||
|
|
f73a55f254 | ||
|
|
0a65975b7e | ||
|
|
5fedde1475 | ||
|
|
a8c0f1653d | ||
|
|
211f15882a | ||
|
|
bbab46dd65 | ||
|
|
5d7023f055 | ||
|
|
6c7ac59626 | ||
|
|
4b02ab8d1f | ||
|
|
18938281c2 | ||
|
|
35311010a6 | ||
|
|
64e71b8bef | ||
|
|
103268a5dc | ||
|
|
c595db19b9 | ||
|
|
933809f939 | ||
|
|
c1d66ae6a5 | ||
|
|
6bbe276b18 | ||
|
|
8590dfde30 | ||
|
|
726056591d | ||
|
|
f5fce6d1f4 | ||
|
|
a0a2cd1d47 | ||
|
|
49b3da01cd | ||
|
|
aad7ed8f24 | ||
|
|
4ea5478241 | ||
|
|
e69b596370 | ||
|
|
fe1c6e10dd | ||
|
|
86e0a52bb9 | ||
|
|
1f64715fab | ||
|
|
813eae1216 | ||
|
|
9b29bd64bd | ||
|
|
3875bbfa17 | ||
|
|
f364936087 | ||
|
|
5e1b0be81c | ||
|
|
4de24ff13a | ||
|
|
0b5c903d89 | ||
|
|
076fc8b2e1 | ||
|
|
258be8e67a | ||
|
|
346cb58613 | ||
|
|
b1384475d9 | ||
|
|
5390e965a9 | ||
|
|
bcba0351aa | ||
|
|
8e6132077c | ||
|
|
7361d55e3a | ||
|
|
eee05abaab | ||
|
|
8224996970 | ||
|
|
a2f5665fbc | ||
|
|
231ba13e8c | ||
|
|
eba8af3595 | ||
|
|
1ab7e476a1 | ||
|
|
453d36f658 | ||
|
|
f253afd2fb | ||
|
|
e9580e939b | ||
|
|
2faff58341 | ||
|
|
0c08d9e202 | ||
|
|
0559d29e74 | ||
|
|
726be1cba0 | ||
|
|
bcf581b491 | ||
|
|
897c123daa | ||
|
|
6f0ad73c23 | ||
|
|
a7a52ea85c | ||
|
|
7330f9f728 | ||
|
|
90a3409aac | ||
|
|
5a0fe14f23 | ||
|
|
2629078988 | ||
|
|
b46e35cf7e | ||
|
|
5e356c0422 | ||
|
|
8311c8bd77 | ||
|
|
4899bbd9d5 | ||
|
|
b558cc6d19 | ||
|
|
32ce0e3dd6 | ||
|
|
ab629b5730 | ||
|
|
899d1e9e2e | ||
|
|
ae28d41231 | ||
|
|
eab5708b33 | ||
|
|
31af2bb6db | ||
|
|
29ec73c80b | ||
|
|
a59a0922ca | ||
|
|
186f2e228d | ||
|
|
58257be867 | ||
|
|
90ff08ed98 | ||
|
|
d930d9f003 | ||
|
|
72b61c4c4f | ||
|
|
39921584df | ||
|
|
55a8466d83 | ||
|
|
0d94b7c39e | ||
|
|
4ef73d7fe9 | ||
|
|
8d93fbcca9 | ||
|
|
885f1b0d49 | ||
|
|
ba081c02c2 | ||
|
|
def85f883b | ||
|
|
ab67dd5b8a | ||
|
|
90e78bf413 | ||
|
|
f70a0dab5f | ||
|
|
fcb3864558 | ||
|
|
12c101a122 | ||
|
|
3b24752e06 | ||
|
|
a4e7461f21 | ||
|
|
f86b4c873e | ||
|
|
4c964af58a | ||
|
|
a1200ae0ec | ||
|
|
3354a48c35 | ||
|
|
fd3ae7fa9b | ||
|
|
6ebd5e35bd | ||
|
|
28f5bdea8e | ||
|
|
fa3beabfaf | ||
|
|
f1a7a8c9d7 | ||
|
|
acd647b4a2 | ||
|
|
c759ceff49 | ||
|
|
347d59ec8d | ||
|
|
a1482b15d4 | ||
|
|
40c6f014be | ||
|
|
a3f8e59c39 | ||
|
|
cf9644e902 | ||
|
|
73d6c1dc1c | ||
|
|
8a28d243df | ||
|
|
6703a98419 | ||
|
|
2f039ace9d | ||
|
|
999fac8ad7 | ||
|
|
ac38d342fa | ||
|
|
5b1774c7b7 | ||
|
|
a3435c4c42 | ||
|
|
daaf1f28e1 | ||
|
|
a602b11270 | ||
|
|
f938b2fdd1 | ||
|
|
9993ce8131 | ||
|
|
dfeaf523ee | ||
|
|
3989463beb | ||
|
|
4ad17ba869 | ||
|
|
3fa7590400 | ||
|
|
f85c5cd9ad | ||
|
|
528386cfd6 | ||
|
|
9268e67529 | ||
|
|
614d81f374 | ||
|
|
883dd07d86 | ||
|
|
4b3834e46d | ||
|
|
2dc902fba1 | ||
|
|
f97a9176e7 | ||
|
|
c7e7d2bac6 | ||
|
|
e33b0be3b8 | ||
|
|
f365973bb9 | ||
|
|
d66f8724e9 | ||
|
|
cb1cc67e6b | ||
|
|
34fcd15101 | ||
|
|
391fdbd920 | ||
|
|
036a17a3d9 | ||
|
|
bc23c53981 | ||
|
|
50180e5b7f | ||
|
|
5da5bf1628 | ||
|
|
fd71e0821f | ||
|
|
627ea612e6 | ||
|
|
eccf3c2be1 | ||
|
|
3e26af308c | ||
|
|
5d2b3a53a0 | ||
|
|
1dca14fc01 | ||
|
|
78c71c2fa3 | ||
|
|
6de4877f24 | ||
|
|
509c81a2b5 | ||
|
|
01a4bcf13d | ||
|
|
08f7c1844a | ||
|
|
5a85e47646 | ||
|
|
fe11bf9398 | ||
|
|
829e3a1e47 | ||
|
|
2fc39c52ae | ||
|
|
24005c490d | ||
|
|
b902b5d373 | ||
|
|
6ba3598317 | ||
|
|
179aba622f | ||
|
|
d415b8747b | ||
|
|
27df8a1b51 | ||
|
|
7838ee66fd | ||
|
|
c24a3765a9 | ||
|
|
6f55c8095e | ||
|
|
a6a011c2fa | ||
|
|
adfd5d8179 | ||
|
|
72c14d949b | ||
|
|
12b4545889 | ||
|
|
f1cb45146f | ||
|
|
8d27a17cdb | ||
|
|
32325f70ab | ||
|
|
e706c956e6 | ||
|
|
dce055255c | ||
|
|
20ffb44994 | ||
|
|
04c0d59454 | ||
|
|
8a35139742 | ||
|
|
ff57f95755 | ||
|
|
2f6059908d | ||
|
|
0c9bebd764 | ||
|
|
10529f54f1 | ||
|
|
04ed043146 | ||
|
|
2318944315 | ||
|
|
ddc867d3cc | ||
|
|
37db3c836b | ||
|
|
2e5b1bd1e3 | ||
|
|
91c1ffc6ce | ||
|
|
927038fd4c | ||
|
|
674a178506 | ||
|
|
88dcea59ec | ||
|
|
bdf12fe22a | ||
|
|
9bb847df87 | ||
|
|
63543b5675 | ||
|
|
9abe5874b7 | ||
|
|
d888511f60 | ||
|
|
605f4aface | ||
|
|
e429b17e63 | ||
|
|
4381eb44b4 | ||
|
|
f352ee8f39 | ||
|
|
fadfc24e52 | ||
|
|
78ebeba1bb | ||
|
|
32e3d411ad | ||
|
|
405f41f87f | ||
|
|
9bb8230fc1 | ||
|
|
bd87864e26 | ||
|
|
bfe08e5114 | ||
|
|
aaf79b21f0 | ||
|
|
592c39fb1d | ||
|
|
2ca84c912b | ||
|
|
bc1783cfb6 | ||
|
|
a4bdbb2b54 | ||
|
|
f362c96e1e | ||
|
|
5f58c34c8b | ||
|
|
5f35415849 | ||
|
|
442354db17 | ||
|
|
23b023c562 | ||
|
|
c2f4510a0f | ||
|
|
d23ed2126d | ||
|
|
18ca5d04cc | ||
|
|
f5d5f63366 | ||
|
|
1f8e441090 | ||
|
|
4c8d7b0738 | ||
|
|
d9f9dc6acb | ||
|
|
b3ed822c72 | ||
|
|
d5488f8aa3 | ||
|
|
8bcf5313f4 | ||
|
|
c062cc414a | ||
|
|
a61ff2d200 | ||
|
|
0de2c95934 | ||
|
|
847f0ce1d4 | ||
|
|
a28d7319d8 | ||
|
|
f0201c1039 | ||
|
|
9351c94f35 | ||
|
|
02be614149 | ||
|
|
ee50a67f03 | ||
|
|
445ed1dd60 | ||
|
|
47527d1512 | ||
|
|
af8d4a8c12 | ||
|
|
1bf4cf2347 | ||
|
|
d4a6560d9a | ||
|
|
6157b1a528 | ||
|
|
11d185ad59 | ||
|
|
a05995fba5 | ||
|
|
1c1be202b7 | ||
|
|
5e55b761cf | ||
|
|
fce53fa308 | ||
|
|
9d3df6be7e | ||
|
|
89df38422c | ||
|
|
3413ceb7c2 | ||
|
|
51a3787708 | ||
|
|
bb2cffe10a | ||
|
|
41c282b38b | ||
|
|
53c2e472ae | ||
|
|
4bb7e33b16 | ||
|
|
f35a73f734 | ||
|
|
00900c1315 | ||
|
|
18c11f108b | ||
|
|
3cc4234117 | ||
|
|
fe79fe9fc7 | ||
|
|
57c49089de | ||
|
|
d35e3510a9 | ||
|
|
7178b33807 | ||
|
|
b0d16d3b3d | ||
|
|
5fcbeb60aa | ||
|
|
0435dce9cd | ||
|
|
25e71790c1 | ||
|
|
6aea46e6d5 | ||
|
|
30fc6d1689 | ||
|
|
8078d712f9 | ||
|
|
144f102935 | ||
|
|
383dbd1b7b | ||
|
|
4b7b2f4c27 | ||
|
|
fe27d4c9c7 | ||
|
|
41317a4ef9 | ||
|
|
2912246572 | ||
|
|
f6c596f318 | ||
|
|
45521d5680 | ||
|
|
89f1e72c50 | ||
|
|
4a7a0a7b75 | ||
|
|
6a978515ca | ||
|
|
0cc0e82c5d | ||
|
|
c01c61fc6b | ||
|
|
4831e17b38 | ||
|
|
3cb104cd1b | ||
|
|
60c8b0c7bf | ||
|
|
16c97a3c36 | ||
|
|
1e8180014d | ||
|
|
2330935b90 | ||
|
|
7ea9001aa4 | ||
|
|
694ebc5477 | ||
|
|
824b12a2f8 | ||
|
|
0c87b4119a | ||
|
|
f0f50579fc | ||
|
|
a831ccd8fa | ||
|
|
dd65e32fb5 | ||
|
|
b1b91b0c53 | ||
|
|
c29dd2ad36 | ||
|
|
f56b9ea883 | ||
|
|
d69ce38604 | ||
|
|
92ea594ccf | ||
|
|
5bbf247863 | ||
|
|
2b841adb1b | ||
|
|
5fd335f330 | ||
|
|
cd7f99063c | ||
|
|
58cb05e302 | ||
|
|
cc6d053b6d | ||
|
|
4b0aebd6a5 | ||
|
|
07b896550e | ||
|
|
886886197d | ||
|
|
4aefb4ba8a | ||
|
|
3d30f7a4b0 | ||
|
|
b09d3ec22c | ||
|
|
b43abb4b5d | ||
|
|
d42710497c | ||
|
|
42a73fa392 | ||
|
|
00a4a33c5f | ||
|
|
006ddbc871 | ||
|
|
69e60a3337 | ||
|
|
5beee738df | ||
|
|
8fa3e8f785 | ||
|
|
65e0822b63 | ||
|
|
7edc65cfde | ||
|
|
ff030b9c1c | ||
|
|
7637cd448e | ||
|
|
2a5a45a700 | ||
|
|
ec9439564e | ||
|
|
a0e599d96a | ||
|
|
55fd6ec406 | ||
|
|
e9256ab9aa | ||
|
|
e4b08b1b82 | ||
|
|
62bc3c856f | ||
|
|
f0493543ff | ||
|
|
1b475b123c | ||
|
|
b189fb1b6e | ||
|
|
328a068956 | ||
|
|
efa341c7e8 | ||
|
|
f43942413e | ||
|
|
24bd9ce6ba | ||
|
|
a4d429bbc1 |
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Opening '...'
|
||||
2. Click on '....'
|
||||
3. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots or logs**
|
||||
Add screenshots or logs to help explain your problem.
|
||||
|
||||
**Server (please complete the following information):**
|
||||
- OS: [e.g. Centos, Windows]
|
||||
- ARCH: [e.g. Amd64, Arm]
|
||||
- Tunnel [e.g. TCP, HTTP]
|
||||
- Version [e.g. 0.24.0]
|
||||
|
||||
**Client (please complete the following information):**
|
||||
- OS: [e.g. Centos, Windows]
|
||||
- ARCH: [e.g. Amd64, Arm]
|
||||
- Tunnel [e.g. TCP, HTTP]
|
||||
- Version [e.g. 0.24.0]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,60 @@
|
||||
name: Deploy Docs to GitHub Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
paths:
|
||||
- 'docs/**'
|
||||
- '.github/workflows/docs.yml'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# 并发:同一时刻只允许一次部署,新的提交会取消上一个未完成的运行
|
||||
concurrency:
|
||||
group: pages
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # lastUpdated 需要完整 git 历史
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
|
||||
- name: Install dependencies
|
||||
working-directory: docs
|
||||
run: npm install --legacy-peer-deps
|
||||
|
||||
- name: Build VuePress site
|
||||
working-directory: docs
|
||||
run: npm run docs:build
|
||||
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v4
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: docs/.vuepress/dist
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@@ -0,0 +1,344 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
GUI_DIR: cmd/npc/npc-gui
|
||||
FRONTEND_DIR: cmd/npc/npc-gui/frontend
|
||||
WAILS_VERSION: v3.0.0-beta.12
|
||||
APP_NAME: npc-gui
|
||||
|
||||
jobs:
|
||||
|
||||
# ==================== 跨平台服务端/客户端打包 ====================
|
||||
build_assets:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "1.22"
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go get -v -t -d ./...
|
||||
if [ -f Gopkg.toml ]; then
|
||||
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||
dep ensure
|
||||
fi
|
||||
- name: Build
|
||||
run: |
|
||||
chmod +x build.assets.sh
|
||||
./build.assets.sh
|
||||
- name: Upload
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
|
||||
with:
|
||||
files: |
|
||||
freebsd_386_client.tar.gz
|
||||
freebsd_386_server.tar.gz
|
||||
freebsd_amd64_client.tar.gz
|
||||
freebsd_amd64_server.tar.gz
|
||||
freebsd_arm_client.tar.gz
|
||||
freebsd_arm_server.tar.gz
|
||||
linux_386_client.tar.gz
|
||||
linux_386_server.tar.gz
|
||||
linux_amd64_client.tar.gz
|
||||
linux_amd64_server.tar.gz
|
||||
linux_arm64_client.tar.gz
|
||||
linux_arm64_server.tar.gz
|
||||
linux_arm_v5_client.tar.gz
|
||||
linux_arm_v6_client.tar.gz
|
||||
linux_arm_v7_client.tar.gz
|
||||
linux_arm_v5_server.tar.gz
|
||||
linux_arm_v6_server.tar.gz
|
||||
linux_arm_v7_server.tar.gz
|
||||
linux_mips64le_client.tar.gz
|
||||
linux_mips64le_server.tar.gz
|
||||
linux_mips64_client.tar.gz
|
||||
linux_mips64_server.tar.gz
|
||||
linux_mipsle_client.tar.gz
|
||||
linux_mipsle_server.tar.gz
|
||||
linux_mips_client.tar.gz
|
||||
linux_mips_server.tar.gz
|
||||
darwin_amd64_client.tar.gz
|
||||
darwin_amd64_server.tar.gz
|
||||
darwin_arm64_client.tar.gz
|
||||
darwin_arm64_server.tar.gz
|
||||
windows_386_client.tar.gz
|
||||
windows_386_server.tar.gz
|
||||
windows_amd64_client.tar.gz
|
||||
windows_amd64_server.tar.gz
|
||||
npc_sdk.tar.gz
|
||||
tag_name: ${{ github.ref_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# ==================== Android APK ====================
|
||||
build_android:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
chmod +x build.android.sh
|
||||
docker run --rm -i -w /app -v $(pwd):/app -e ANDROID_HOME=/usr/local/android_sdk -e GOPROXY=direct fyneio/fyne-cross:android-latest /app/build.android.sh
|
||||
ls -la android_client.apk
|
||||
- name: Upload
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
|
||||
with:
|
||||
files: |
|
||||
android_client.apk
|
||||
tag_name: ${{ github.ref_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# ==================== Docker 镜像 ====================
|
||||
build_docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Set env
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: /tmp/.buildx-cache
|
||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-buildx-
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push nps
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.nps
|
||||
platforms: linux/amd64,linux/arm,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/nps:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/nps:${{ env.RELEASE_VERSION }}
|
||||
- name: Build and push npc
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.npc
|
||||
platforms: linux/amd64,linux/arm,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/npc:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/npc:${{ env.RELEASE_VERSION }}
|
||||
|
||||
# ==================== Windows GUI ====================
|
||||
build_windows_gui:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: windows/386
|
||||
os_name: windows
|
||||
arch: 386
|
||||
- platform: windows/amd64
|
||||
os_name: windows
|
||||
arch: amd64
|
||||
- platform: windows/arm64
|
||||
os_name: windows
|
||||
arch: arm64
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: yarn
|
||||
cache-dependency-path: ${{ env.FRONTEND_DIR }}/yarn.lock
|
||||
- name: Enable Yarn (corepack)
|
||||
run: corepack enable
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: ${{ env.GUI_DIR }}/go.mod
|
||||
check-latest: true
|
||||
- name: Install Wails CLI
|
||||
run: go install github.com/wailsapp/wails/v3/cmd/wails3@${{ env.WAILS_VERSION }}
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
- name: Build and package (Windows)
|
||||
shell: pwsh
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
run: |
|
||||
$env:GOOS = "windows"
|
||||
$env:GOARCH = "${{ matrix.arch }}"
|
||||
wails3 build --tags npcgui
|
||||
Set-Location bin
|
||||
$zipName = "$env:APP_NAME-${{ matrix.os_name }}-${{ matrix.arch }}.zip"
|
||||
$exe = Get-ChildItem -Path . -Filter *.exe | Select-Object -First 1
|
||||
if (-not $exe) {
|
||||
Write-Host "No build output found in bin"
|
||||
Get-ChildItem -Path . | Format-Table -AutoSize
|
||||
exit 1
|
||||
}
|
||||
Compress-Archive -Path $exe.Name -DestinationPath $zipName -Force
|
||||
- name: Upload Windows artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: windows-builds-${{ matrix.arch }}
|
||||
path: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
- name: Upload Windows release asset
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
|
||||
with:
|
||||
files: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
tag_name: ${{ github.ref_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# ==================== macOS GUI ====================
|
||||
build_macos_gui:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: darwin/amd64
|
||||
os_name: darwin
|
||||
arch: amd64
|
||||
os: macos-14
|
||||
- platform: darwin/arm64
|
||||
os_name: darwin
|
||||
arch: arm64
|
||||
os: macos-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: yarn
|
||||
cache-dependency-path: ${{ env.FRONTEND_DIR }}/yarn.lock
|
||||
- name: Enable Yarn (corepack)
|
||||
run: corepack enable
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: ${{ env.GUI_DIR }}/go.mod
|
||||
check-latest: true
|
||||
- name: Install Wails CLI
|
||||
run: go install github.com/wailsapp/wails/v3/cmd/wails3@${{ env.WAILS_VERSION }}
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
- name: Build and package (macOS)
|
||||
shell: bash
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
run: |
|
||||
export GOOS=darwin
|
||||
export GOARCH="${{ matrix.arch }}"
|
||||
# wails3 package builds with EXTRA_TAGS=npcgui (Package has no --tags
|
||||
# flag; the var flows into the build dep) and then assembles a proper
|
||||
# bin/npc-gui.app bundle with ad-hoc codesign.
|
||||
wails3 package EXTRA_TAGS=npcgui
|
||||
cd bin
|
||||
# Guard the .app lookups so a no-match does not abort the script
|
||||
# under `set -e -o pipefail`; keep the raw-binary fallback as safety.
|
||||
app="$(ls -1d *.app 2>/dev/null | head -n 1 || true)"
|
||||
if [ -z "$app" ]; then
|
||||
app="$(find . -maxdepth 1 -type f -perm -111 -exec basename {} \; | head -n 1 || true)"
|
||||
fi
|
||||
if [ -z "$app" ]; then
|
||||
echo "No build output found in bin"
|
||||
ls -la
|
||||
exit 1
|
||||
fi
|
||||
zip -q -r "$APP_NAME-${{ matrix.os_name }}-${{ matrix.arch }}.zip" "$app"
|
||||
- name: Upload macOS artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: macos-builds-${{ matrix.arch }}
|
||||
path: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
- name: Upload macOS release asset
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
|
||||
with:
|
||||
files: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
tag_name: ${{ github.ref_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# ==================== Linux GUI ====================
|
||||
build_linux_gui:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: linux/amd64
|
||||
os_name: linux
|
||||
arch: amd64
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential libgtk-4-dev libwebkitgtk-6.0-dev libsoup-3.0-dev libjavascriptcoregtk-6.0-dev libayatana-appindicator3-dev librsvg2-dev patchelf pkg-config
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: yarn
|
||||
cache-dependency-path: ${{ env.FRONTEND_DIR }}/yarn.lock
|
||||
- name: Enable Yarn (corepack)
|
||||
run: corepack enable
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: ${{ env.GUI_DIR }}/go.mod
|
||||
check-latest: true
|
||||
- name: Install Wails CLI
|
||||
run: go install github.com/wailsapp/wails/v3/cmd/wails3@${{ env.WAILS_VERSION }}
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
- name: Build and package (Linux)
|
||||
shell: bash
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
run: |
|
||||
export GOOS=linux
|
||||
export GOARCH="${{ matrix.arch }}"
|
||||
wails3 build --tags npcgui
|
||||
cd bin
|
||||
bin="$(find . -maxdepth 1 -type f -perm -111 -printf '%f\n' | head -n 1)"
|
||||
if [ -z "$bin" ]; then
|
||||
echo "No executable file found in bin"
|
||||
ls -la
|
||||
exit 1
|
||||
fi
|
||||
zip -q "$APP_NAME-${{ matrix.os_name }}-${{ matrix.arch }}.zip" "$bin"
|
||||
- name: Upload Linux artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: linux-builds-${{ matrix.arch }}
|
||||
path: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
- name: Upload Linux release asset
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
|
||||
with:
|
||||
files: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
tag_name: ${{ github.ref_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
+29
-1
@@ -1 +1,29 @@
|
||||
.idea
|
||||
.idea
|
||||
nps
|
||||
|
||||
# Go build outputs
|
||||
/npc
|
||||
/nps.exe
|
||||
/npc.exe
|
||||
|
||||
# Node.js / VuePress
|
||||
node_modules/
|
||||
yarn.lock
|
||||
pnpm-lock.yaml
|
||||
|
||||
# VuePress build artifacts
|
||||
docs/.vuepress/.cache/
|
||||
docs/.vuepress/.temp/
|
||||
docs/.vuepress/dist/
|
||||
# VuePress dev runtime
|
||||
docs/vuepress-dev.log
|
||||
docs/vuepress-dev.err.log
|
||||
docs/vuepress-dev.pid
|
||||
docs/node_modules/
|
||||
docs/yarn.lock
|
||||
docs/.vscode
|
||||
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.14.x
|
||||
services:
|
||||
- docker
|
||||
script:
|
||||
- GOPROXY=direct go test -v ./cmd/nps/
|
||||
os:
|
||||
- linux
|
||||
before_deploy:
|
||||
- chmod +x ./build.sh && chmod +x ./build.android.sh && ./build.sh
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
edge: true
|
||||
token: ${GH_TOKEN}
|
||||
cleanup: false
|
||||
file:
|
||||
- freebsd_386_client.tar.gz
|
||||
- freebsd_386_server.tar.gz
|
||||
- freebsd_amd64_client.tar.gz
|
||||
- freebsd_amd64_server.tar.gz
|
||||
- freebsd_arm_client.tar.gz
|
||||
- freebsd_arm_server.tar.gz
|
||||
- linux_386_client.tar.gz
|
||||
- linux_386_server.tar.gz
|
||||
- linux_amd64_client.tar.gz
|
||||
- linux_amd64_server.tar.gz
|
||||
- linux_arm64_client.tar.gz
|
||||
- linux_arm64_server.tar.gz
|
||||
- linux_arm_v5_client.tar.gz
|
||||
- linux_arm_v6_client.tar.gz
|
||||
- linux_arm_v7_client.tar.gz
|
||||
- linux_arm_v5_server.tar.gz
|
||||
- linux_arm_v6_server.tar.gz
|
||||
- linux_arm_v7_server.tar.gz
|
||||
- linux_mips64le_client.tar.gz
|
||||
- linux_mips64le_server.tar.gz
|
||||
- linux_mips64_client.tar.gz
|
||||
- linux_mips64_server.tar.gz
|
||||
- linux_mipsle_client.tar.gz
|
||||
- linux_mipsle_server.tar.gz
|
||||
- linux_mips_client.tar.gz
|
||||
- linux_mips_server.tar.gz
|
||||
- darwin_amd64_client.tar.gz
|
||||
- darwin_amd64_server.tar.gz
|
||||
- windows_386_client.tar.gz
|
||||
- windows_386_server.tar.gz
|
||||
- windows_amd64_client.tar.gz
|
||||
- windows_amd64_server.tar.gz
|
||||
- npc_syno.spk
|
||||
- npc_sdk.tar.gz
|
||||
- android_client.apk
|
||||
on:
|
||||
tags: true
|
||||
all_branches: true
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
FROM golang:1.24 as builder
|
||||
ARG GOPROXY=direct
|
||||
WORKDIR /go/src/ehang.io/nps
|
||||
COPY . .
|
||||
RUN go get -d -v ./...
|
||||
RUN CGO_ENABLED=0 go build -ldflags="-w -s -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /go/src/ehang.io/nps/npc /
|
||||
VOLUME /conf
|
||||
ENTRYPOINT ["/npc"]
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
FROM golang:1.24 as builder
|
||||
ARG GOPROXY=direct
|
||||
WORKDIR /go/src/ehang.io/nps
|
||||
COPY . .
|
||||
RUN go get -d -v ./...
|
||||
RUN CGO_ENABLED=0 go build -ldflags="-w -s -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /go/src/ehang.io/nps/nps /
|
||||
VOLUME /conf
|
||||
CMD ["/nps"]
|
||||
@@ -1,21 +1,674 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (c) 2018
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,75 @@
|
||||
SOURCE_FILES?=./...
|
||||
TEST_PATTERN?=.
|
||||
TEST_OPTIONS?=
|
||||
|
||||
export PATH := ./bin:$(PATH)
|
||||
export GO111MODULE := on
|
||||
export GOPROXY := https://gocenter.io
|
||||
|
||||
# Build a beta version of goreleaser
|
||||
build:
|
||||
go build cmd/nps/nps.go
|
||||
go build cmd/npc/npc.go
|
||||
.PHONY: build
|
||||
|
||||
# Install all the build and lint dependencies
|
||||
setup:
|
||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh
|
||||
curl -L https://git.io/misspell | sh
|
||||
go mod download
|
||||
.PHONY: setup
|
||||
|
||||
# Run all the tests
|
||||
test:
|
||||
go test $(TEST_OPTIONS) -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=2m
|
||||
.PHONY: test
|
||||
|
||||
# Run all the tests and opens the coverage report
|
||||
cover: test
|
||||
go tool cover -html=coverage.txt
|
||||
.PHONY: cover
|
||||
|
||||
# gofmt and goimports all go files
|
||||
fmt:
|
||||
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
|
||||
.PHONY: fmt
|
||||
|
||||
# Run all the linters
|
||||
lint:
|
||||
# TODO: fix tests and lll issues
|
||||
./bin/golangci-lint run --tests=false --enable-all --disable=lll ./...
|
||||
./bin/misspell -error **/*
|
||||
.PHONY: lint
|
||||
|
||||
# Clean go.mod
|
||||
go-mod-tidy:
|
||||
@go mod tidy -v
|
||||
@git diff HEAD
|
||||
@git diff-index --quiet HEAD
|
||||
.PHONY: go-mod-tidy
|
||||
|
||||
# Run all the tests and code checks
|
||||
ci: build test lint go-mod-tidy
|
||||
.PHONY: ci
|
||||
|
||||
# Generate the static documentation
|
||||
static:
|
||||
@hugo --enableGitInfo --source www
|
||||
.PHONY: static
|
||||
|
||||
# Show to-do items per file.
|
||||
todo:
|
||||
@grep \
|
||||
--exclude-dir=vendor \
|
||||
--exclude-dir=node_modules \
|
||||
--exclude=Makefile \
|
||||
--text \
|
||||
--color \
|
||||
-nRo -E ' TODO:.*|SkipNow' .
|
||||
.PHONY: todo
|
||||
|
||||
clean:
|
||||
rm npc nps
|
||||
.PHONY: clean
|
||||
|
||||
.DEFAULT_GOAL := build
|
||||
@@ -1,894 +1,75 @@
|
||||
# nps
|
||||
  
|
||||
# NPS
|
||||
|
||||
nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务器。目前支持**tcp、udp流量转发**,可支持任何**tcp、udp**上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还**支持内网http代理、内网socks5代理**、**p2p等**,并带有功能强大的web管理端。
|
||||

|
||||

|
||||

|
||||
|
||||
> 一款轻量级、高性能、功能强大的内网穿透代理服务器,基于 [ehang-io/nps](https://github.com/ehang-io/nps) 0.26.10 二次开发 —— 修复大量 bug,持续更新中。
|
||||
> 💬 聊天灌水 QQ 群:**619833483**(热心群主可提供免费远程协助)
|
||||
|
||||
## 背景
|
||||

|
||||
### 📖 在线文档
|
||||
<small>[完整文档](https://yisier.github.io/nps) · [更新日志](https://yisier.github.io/nps/changelog/) · [程序安装](https://yisier.github.io/nps/install/#%E7%A8%8B%E5%BA%8F%E5%AE%89%E8%A3%85) · [宝塔面板](https://yisier.github.io/nps/install/#%E5%AE%9D%E5%A1%94%E9%9D%A2%E6%9D%BF-%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2) · [Docker安装](https://yisier.github.io/nps/install/#docker-%E5%AE%89%E8%A3%85)</small>
|
||||
|
||||
1. 做微信公众号开发、小程序开发等----> 域名代理模式
|
||||
---
|
||||
## 💰 赞助 / 推荐
|
||||
#### ☁️ [雨云 — 国内便宜稳定的云服务器,首月 5 折](https://www.rainyun.com/MjY0MzY1_)
|
||||
500M 带宽,高仿物理机,云服务器**15 元起**,通过此链接注册首月 5 折。
|
||||
|
||||
#### 🚀 [NATNPS 云穿透 — 免费 3M 带宽 / 2 条隧道](https://natnps.com/register?utm_from=MQ==)
|
||||
无需自备服务器,注册即用。免费版 3M 带宽 2 条隧道;6.8 元 12M 带宽 10 条隧道;13.8 元 24M 带宽 20 条隧道。
|
||||
|
||||
2. 想在外网通过ssh连接内网的机器,做云服务器到内网服务器端口的映射,----> tcp代理模式
|
||||
---
|
||||
## 🚀 快速开始
|
||||
|
||||
3. 在非内网环境下使用内网dns,或者需要通过udp访问内网机器等----> udp代理模式
|
||||
### 下载
|
||||
|
||||
4. 在外网使用HTTP代理访问内网站点----> http代理模式
|
||||
从 [releases](https://github.com/yisier/nps/releases) 下载对应平台版本。服务端 `nps` 和客户端 `npc` 是独立的压缩包。
|
||||
|
||||
5. 搭建一个内网穿透ss,在外网如同使用内网vpn一样访问内网资源或者设备----> socks5代理模式
|
||||
|
||||
|
||||
## 目录
|
||||
|
||||
* [安装](#安装)
|
||||
* [编译安装](#源码安装)
|
||||
* [release安装](#release安装)
|
||||
* [使用示例(以web主控模式为主)](#使用示例)
|
||||
* [统一准备工作](#统一准备工作(必做))
|
||||
* [http|https域名解析](#域名解析)
|
||||
* [内网ssh连接即tcp隧道](#tcp隧道)
|
||||
* [内网dns解析即udp隧道](#udp隧道)
|
||||
* [内网socks5代理](#socks5代理)
|
||||
* [内网http正向代理](#http正向代理)
|
||||
* [内网安全私密代理](#私密代理)
|
||||
* [p2p穿透](#p2p服务)
|
||||
* [简单的内网文件访问服务](#文件访问模式)
|
||||
* [服务端](#web管理模式)
|
||||
* [服务端启动](#服务端启动)
|
||||
* [服务端测试](#服务端测试)
|
||||
* [服务端启动](#服务端启动)
|
||||
* [web管理](#web管理)
|
||||
* [服务端停止或重启](#服务端停止或重启)
|
||||
* [配置文件说明](#服务端配置文件)
|
||||
|
||||
* [使用https](#使用https)
|
||||
* [与nginx配合](#与nginx配合)
|
||||
* [关闭http|https代理](#关闭代理)
|
||||
* [将nps安装到系统](#将nps安装到系统)
|
||||
* [流量数据持久化](#流量数据持久化)
|
||||
* [自定义客户端连接密钥](#自定义客户端连接密钥)
|
||||
* [关闭公钥访问](#关闭公钥访问)
|
||||
* [关闭web管理](#关闭web管理)
|
||||
* [客户端](#客户端)
|
||||
* [客户端启动](#客户端启动)
|
||||
* [无配置文件模式](#无配置文件模式)
|
||||
* [配置文件模式](#配置文件模式)
|
||||
* [配置文件说明](#配置文件说明)
|
||||
* [全局配置](#全局配置)
|
||||
* [域名代理](#域名代理)
|
||||
* [tcp隧道](#tcp隧道模式)
|
||||
* [udp隧道](#udp隧道模式)
|
||||
* [http正向代理](#http代理模式)
|
||||
* [socks5代理](#socks5代理模式)
|
||||
* [私密代理](#私密代理模式)
|
||||
* [p2p服务](#p2p代理)
|
||||
* [文件访问代理](#文件访问模式)
|
||||
* [断线重连](#断线重连)
|
||||
* [状态检查](#状态检查)
|
||||
* [重载配置文件](#重载配置文件)
|
||||
* [通过代理连接nps](#通过代理连接nps)
|
||||
* [日志输出级别](#日志输出级别)
|
||||
|
||||
* [相关功能](#相关功能)
|
||||
* [数据压缩支持](#数据压缩支持)
|
||||
* [站点密码保护](#站点保护)
|
||||
* [加密传输](#加密传输)
|
||||
* [host修改](#host修改)
|
||||
* [自定义header](#自定义header)
|
||||
* [自定义404页面](#404页面配置)
|
||||
* [流量限制](#流量限制)
|
||||
* [带宽限制](#带宽限制)
|
||||
* [负载均衡](#负载均衡)
|
||||
* [端口白名单](#端口白名单)
|
||||
* [端口范围映射](#端口范围映射)
|
||||
* [端口范围映射到其他机器](#端口范围映射到其他机器)
|
||||
* [守护进程](#守护进程)
|
||||
* [KCP协议支持](#KCP协议支持)
|
||||
* [域名泛解析](#域名泛解析)
|
||||
* [URL路由](#URL路由)
|
||||
* [限制ip访问](#限制ip访问)
|
||||
* [客户端最大连接数限制](#客户端最大连接数)
|
||||
* [端口复用](#端口复用)
|
||||
* [环境变量渲染](#环境变量渲染)
|
||||
* [健康检查](#健康检查)
|
||||
|
||||
* [相关说明](#相关说明)
|
||||
* [流量统计](#流量统计)
|
||||
* [热更新支持](#热更新支持)
|
||||
* [获取用户真实ip](#获取用户真实ip)
|
||||
* [客户端地址显示](#客户端地址显示)
|
||||
* [客户端与服务端版本对比](#客户端与服务端版本对比)
|
||||
* [简单的性能测试](#简单的性能测试)
|
||||
* [qps](#qps)
|
||||
* [速度测试](#速度测试)
|
||||
* [内存和cpu](#内存和cpu)
|
||||
* [额外消耗连接数](#额外消耗连接数)
|
||||
* [webAPI](#webAPI)
|
||||
* [贡献](#贡献)
|
||||
* [交流群](#交流群)
|
||||
|
||||
|
||||
|
||||
## 安装
|
||||
|
||||
### release安装
|
||||
> https://github.com/cnlh/nps/releases
|
||||
|
||||
下载对应的系统版本即可,服务端和客户端是单独的,go语言开发,无需任何第三方依赖
|
||||
|
||||
### 源码安装
|
||||
- 安装源码
|
||||
> go get -u github.com/cnlh/nps...
|
||||
- 编译
|
||||
> go build cmd/nps/nps.go
|
||||
|
||||
> go build cmd/npc/npc.go
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 统一准备工作(必做)
|
||||
- 开启服务端,假设公网服务器ip为1.1.1.1,配置文件中`bridgePort`为8284,配置文件中`web_port`为8080
|
||||
- 访问1.1.1.1:8080
|
||||
- 在客户端管理中创建一个客户端,记录下验证密钥
|
||||
- 内网客户端运行(windows使用cmd运行加.exe)
|
||||
### 服务端
|
||||
|
||||
```shell
|
||||
./npc -server=1.1.1.1:8284 -vkey=客户端的密钥
|
||||
./nps -server # 交互菜单:安装/卸载/启动/停止/更新
|
||||
```
|
||||
|
||||
### 域名解析
|
||||
首次启动自动生成 `conf/nps.conf`,随机生成 `web_password`、`auth_key`、`auth_crypt_key`,请从启动日志或 `nps.conf` 获取。
|
||||
|
||||
**适用范围:** 小程序开发、微信公众号开发、产品演示
|
||||

|
||||
|
||||
**假设场景:**
|
||||
- 有一个域名proxy.com,有一台公网机器ip为1.1.1.1
|
||||
- 两个内网开发站点127.0.0.1:81,127.0.0.1:82
|
||||
- 想通过(http|https://)a.proxy.com访问127.0.0.1:81,通过(http|https://)b.proxy.com访问127.0.0.1:82
|
||||
### 客户端
|
||||
|
||||
**使用步骤**
|
||||
- 将*.proxy.com解析到公网服务器1.1.1.1
|
||||
- 点击刚才创建的客户端的域名管理,添加两条规则规则:1、域名:`a.proxy.com`,内网目标:`127.0.0.1:81`,2、域名:`b.proxy.com`,内网目标:`127.0.0.1:82`
|
||||
|
||||
现在访问(http|https://)`a.proxy.com`,`b.proxy.com`即可成功
|
||||
|
||||
**https:** 如需使用https请在配置文件中将https端口设置为443,和将对应的证书文件路径添加到配置文件中,上面添加的这条记录将会把http、https都转发到内网目标
|
||||
|
||||
### tcp隧道
|
||||
|
||||
|
||||
**适用范围:** ssh、远程桌面等tcp连接场景
|
||||
|
||||
**假设场景:**
|
||||
想通过访问公网服务器1.1.1.1的8001端口,连接内网机器10.1.50.101的22端口,实现ssh连接
|
||||
|
||||
**使用步骤**
|
||||
- 在刚才创建的客户端隧道管理中添加一条tcp隧道,填写监听的端口(8001)、内网目标ip和目标端口(10.1.50.101:22),保存。
|
||||
- 访问公网服务器ip(1.1.1.1),填写的监听端口(8001),相当于访问内网ip(10.1.50.101):目标端口(22),例如:`ssh -p 8001 root@1.1.1.1`
|
||||
|
||||
### udp隧道
|
||||
|
||||
**适用范围:** 内网dns解析等udp连接场景
|
||||
|
||||
**假设场景:**
|
||||
内网有一台dns(10.1.50.102:53),在非内网环境下想使用该dns,公网服务器为1.1.1.1
|
||||
|
||||
**使用步骤**
|
||||
- 在刚才创建的客户端的隧道管理中添加一条udp隧道,填写监听的端口(53)、内网目标ip和目标端口(10.1.50.102:53),保存。
|
||||
- 修改需要使用的内网dns为127.0.0.1,则相当于使用10.1.50.202作为dns服务器
|
||||
|
||||
### socks5代理
|
||||
|
||||
|
||||
**适用范围:** 在外网环境下如同使用vpn一样访问内网设备或者资源
|
||||
|
||||
**假设场景:**
|
||||
想将公网服务器1.1.1.1的8003端口作为socks5代理,达到访问内网任意设备或者资源的效果
|
||||
|
||||
**使用步骤**
|
||||
- 在刚才创建的客户端隧道管理中添加一条socks5代理,填写监听的端口(8003),保存。
|
||||
- 在外网环境的本机配置socks5代理,ip为公网服务器ip(1.1.1.1),端口为填写的监听端口(8003),即可畅享内网了
|
||||
|
||||
### http正向代理
|
||||
|
||||
**适用范围:** 在外网环境下使用http正向代理访问内网站点
|
||||
|
||||
**假设场景:**
|
||||
想将公网服务器1.1.1.1的8004端口作为http代理,访问内网网站
|
||||
**使用步骤**
|
||||
|
||||
- 在刚才创建的客户端隧道管理中添加一条http代理,填写监听的端口(8004),保存。
|
||||
- 在外网环境的本机配置http代理,ip为公网服务器ip(1.1.1.1),端口为填写的监听端口(8004),即可访问了
|
||||
|
||||
### 私密代理
|
||||
|
||||
**适用范围:** 无需占用多余的端口、安全性要求较高可以防止其他人连接的tcp服务,例如ssh。
|
||||
|
||||
**假设场景:**
|
||||
无需新增多的端口实现访问内网服务器10.1.50.2的22端口
|
||||
|
||||
**使用步骤**
|
||||
- 在刚才创建的客户端中添加一条私密代理,并设置唯一密钥和内网目标10.1.50.2:22
|
||||
- 在需要连接ssh的机器上以配置文件模式启动客户端,内容如下
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
tp=tcp
|
||||
vkey=123
|
||||
[secret_ssh]
|
||||
password=1111
|
||||
port=1000
|
||||
```
|
||||
**注意:** secret前缀必须存在,password为web管理上添加的唯一密钥
|
||||
|
||||
假设用户名为root,现在执行`ssh -p 1000 root@127.0.0.1`即可访问ssh
|
||||
|
||||
### p2p服务
|
||||
|
||||
**适用范围:** 大流量传输场景,流量不经过公网服务器,但是由于p2p穿透和nat类型关系较大,成功率一般,可穿透所有非对称型nat。
|
||||
|
||||
**假设场景:**
|
||||
内网1机器ip为10.1.50.2 内网2机器ip为10.2.50.2
|
||||
|
||||
想通过访问机器1的2001端口---->访问到内网2机器的22端口
|
||||
|
||||
**使用步骤**
|
||||
- 在`nps.conf`中设置`p2p_ip`和`p2p_port`
|
||||
- 在刚才刚才创建的客户端中添加一条p2p代理,并设置唯一密钥p2pssh
|
||||
- 在需要连接的机器上(即机器1)以配置文件模式启动客户端,内容如下
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
tp=tcp
|
||||
vkey=123
|
||||
[p2p_ssh]
|
||||
password=p2pssh
|
||||
port=2001
|
||||
```
|
||||
**注意:** p2p前缀必须存在,password为web管理上添加的唯一密钥
|
||||
|
||||
假设机器2用户名为root,现在在机器1上执行`ssh -p 2001 root@127.0.0.1`即可访问机器2的ssh
|
||||
|
||||
|
||||
|
||||
|
||||
## web管理模式
|
||||
|
||||

|
||||
### 介绍
|
||||
|
||||
可在网页上配置和管理各个tcp、udp隧道、内网站点代理,http、https解析等,功能强大,操作方便。
|
||||
|
||||
|
||||
**提示:使用web模式时,服务端执行文件必须在项目根目录,否则无法正确加载配置文件**
|
||||
|
||||
### 启动
|
||||
|
||||
|
||||
#### 服务端测试
|
||||
```shell
|
||||
./nps test
|
||||
./npc # 直接双击运行,按提示输入即可
|
||||
```
|
||||
如有错误请及时修改配置文件,无错误可继续进行下去
|
||||
#### 服务端启动
|
||||
|
||||
在 Web 后台复制【快捷启动命令】,客户端粘贴即可注册系统服务、启停或卸载。
|
||||
|
||||
|
||||

|
||||
|
||||
#### 命令行直接启动
|
||||
|
||||
```shell
|
||||
./nps start
|
||||
```
|
||||
如果无需daemon运行,去掉start即可
|
||||
|
||||
#### web管理
|
||||
|
||||
进入web界面,公网ip:web界面端口(默认8080),密码默认为123
|
||||
|
||||
进入web管理界面,有详细的说明
|
||||
|
||||
#### 服务端停止或重启
|
||||
如果是daemon启动
|
||||
```shell
|
||||
./nps stop|restart
|
||||
npc -server=ip:8024 -vkey=xxx # 标准
|
||||
npc -server=ip:8025 -vkey=xxx -tls_enable=true # TLS 桥接
|
||||
npc -server=ip:8024 -vkey=vkey1,vkey2 # 多隧道
|
||||
```
|
||||
|
||||
### 服务端配置文件
|
||||
- /conf/nps.conf
|
||||
---
|
||||
|
||||
名称 | 含义
|
||||
---|---
|
||||
web_port | web管理端口
|
||||
web_password | web界面管理密码
|
||||
web_username | web界面管理账号
|
||||
bridge_port | 服务端客户端通信端口
|
||||
pem_path | ssl certFile绝对路径
|
||||
key_path | ssl keyFile绝对路径
|
||||
https_proxy_port | 域名代理https代理监听端口
|
||||
http_proxy_port | 域名代理http代理监听端口
|
||||
auth_key|web api密钥
|
||||
bridge_type|客户端与服务端连接方式kcp或tcp
|
||||
public_vkey|客户端以配置文件模式启动时的密钥,设置为空表示关闭客户端配置文件连接模式
|
||||
ip_limit|是否限制ip访问,true或false或忽略
|
||||
flow_store_interval|服务端流量数据持久化间隔,单位分钟,忽略表示不持久化
|
||||
log_level|日志输出级别
|
||||
auth_crypt_key | 获取服务端authKey时的aes加密密钥,16位
|
||||
p2p_ip| 服务端Ip,使用p2p模式必填
|
||||
p2p_port|p2p模式开启的udp端口
|
||||
## ☕ 请作者喝杯咖啡
|
||||
> 如果这个项目帮到了你,可以请作者喝杯咖啡 ☕ 感谢支持!
|
||||
|
||||
### 使用https
|
||||

|
||||
|
||||
在配置文件中将httpsProxyPort设置为443或者其他你想配置的端口,和将对应的证书文件路径添加到配置文件中,然后就和http代理一样了,例如
|
||||
|
||||
- 需要访问`https://a.proxy.com` 对应内网`127.0.0.1:80`
|
||||
---
|
||||
|
||||
- 在域名代理中添加`a.proxy.com` 内网目标`127.0.0.1:80` 即可将所有到达本代理的http(s)请求都转发到127.0.0.1:80
|
||||
## 📈 Star History
|
||||
|
||||
### 与nginx配合
|
||||
[](https://star-history.dera.page/#yisier/nps&Date)
|
||||
|
||||
有时候我们还需要在云服务器上运行nginx来保证静态文件缓存等,本代理可和nginx配合使用,在配置文件中将httpProxyPort设置为非80端口,并在nginx中配置代理,例如httpProxyPort为8024时
|
||||
```
|
||||
server {
|
||||
listen 80;
|
||||
server_name *.proxy.com;
|
||||
location / {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_pass http://127.0.0.1:8024;
|
||||
}
|
||||
}
|
||||
```
|
||||
如需使用https也可在nginx监听443端口并配置ssl,并将本代理的httpsProxyPort设置为空关闭https即可,例如httpProxyPort为8024时
|
||||
---
|
||||
|
||||
```
|
||||
server {
|
||||
listen 443;
|
||||
server_name *.proxy.com;
|
||||
ssl on;
|
||||
ssl_certificate certificate.crt;
|
||||
ssl_certificate_key private.key;
|
||||
ssl_session_timeout 5m;
|
||||
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
ssl_prefer_server_ciphers on;
|
||||
location / {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_pass http://127.0.0.1:8024;
|
||||
}
|
||||
}
|
||||
```
|
||||
### 关闭代理
|
||||
## 📃 License
|
||||
|
||||
如需关闭http代理可在配置文件中将http_proxy_port设置为空,如需关闭https代理可在配置文件中将https_proxy_port设置为空。
|
||||
|
||||
### 将nps安装到系统
|
||||
如果需要长期并且方便的运行nps服务端,可将nps安装到操作系统中,可执行命令
|
||||
|
||||
```
|
||||
(./nps|nps.exe) install
|
||||
```
|
||||
安装成功后,对于linux,darwin,将会把配置文件和静态文件放置于/etc/nps/,并将可执行文件nps复制到/usr/bin/nps或者/usr/local/bin/nps,安装成功后可在任何位置执行
|
||||
|
||||
```
|
||||
nps test|start|stop|restart|status
|
||||
```
|
||||
对于windows系统,将会把配置文件和静态文件放置于C:\Program Files\nps,安装成功后可将可执行文件nps.exe复制到任何位置执行
|
||||
|
||||
```
|
||||
nps.exe test|start|stop|restart|status
|
||||
```
|
||||
|
||||
### 流量数据持久化
|
||||
服务端支持将流量数据持久化,默认情况下是关闭的,如果有需求可以设置`nps.conf`中的`flow_store_interval`参数,单位为分钟
|
||||
|
||||
**注意:** nps不会持久化通过公钥连接的客户端
|
||||
|
||||
### 自定义客户端连接密钥
|
||||
web上可以自定义客户端连接的密钥,但是必须具有唯一性
|
||||
### 关闭公钥访问
|
||||
可以将`nps.conf`中的`public_vkey`设置为空或者删除
|
||||
|
||||
### 关闭web管理
|
||||
可以将`nps.conf`中的`web_port`设置为空或者删除
|
||||
|
||||
## 客户端
|
||||
|
||||
### 客户端启动
|
||||
#### 无配置文件模式
|
||||
此模式的各种配置在服务端web管理中完成,客户端除运行一条命令外无需任何其他设置
|
||||
```
|
||||
./npc -server=ip:port -vkey=web界面中显示的密钥
|
||||
```
|
||||
#### 配置文件模式
|
||||
此模式使用nps的公钥或者客户端私钥验证,各种配置在客户端完成,同时服务端web也可以进行管理
|
||||
```
|
||||
./npc -config=npc配置文件路径
|
||||
```
|
||||
#### 配置文件说明
|
||||
[示例配置文件](https://github.com/cnlh/nps/tree/master/conf/npc.conf)
|
||||
##### 全局配置
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
tp=tcp
|
||||
vkey=123
|
||||
username=111
|
||||
password=222
|
||||
compress=true
|
||||
crypt=true
|
||||
rate_limit=10000
|
||||
flow_limit=100
|
||||
remark=test
|
||||
max_conn=10
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
server | 服务端ip:port
|
||||
tp | 与服务端通信模式(tcp或kcp)
|
||||
vkey|服务端配置文件中的密钥(非web)
|
||||
username|socks5或http(s)密码保护用户名(可忽略)
|
||||
username|socks5或http(s)密码保护密码(可忽略)
|
||||
compress|是否压缩传输(true或false或忽略)
|
||||
crypt|是否加密传输(true或false或忽略)
|
||||
rate_limit|速度限制,可忽略
|
||||
flow_limit|流量限制,可忽略
|
||||
remark|客户端备注,可忽略
|
||||
max_conn|最大连接数,可忽略
|
||||
##### 域名代理
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[web1]
|
||||
host=a.proxy.com
|
||||
target=127.0.0.1:8080,127.0.0.1:8082
|
||||
host_change=www.proxy.com
|
||||
header_set_proxy=nps
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
web1 | 备注
|
||||
host | 域名(http|https都可解析)
|
||||
target|内网目标,负载均衡时多个目标,逗号隔开
|
||||
host_change|请求host修改
|
||||
header_xxx|请求header修改或添加,header_proxy表示添加header proxy:nps
|
||||
|
||||
##### tcp隧道模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[tcp]
|
||||
mode=tcp
|
||||
target=127.0.0.1:8080
|
||||
port=9001
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | tcp
|
||||
port | 在服务端的代理端口
|
||||
target|内网目标
|
||||
|
||||
##### udp隧道模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[udp]
|
||||
mode=udp
|
||||
target=127.0.0.1:8080
|
||||
port=9002
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | udp
|
||||
port | 在服务端的代理端口
|
||||
target|内网目标
|
||||
##### http代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[http]
|
||||
mode=httpProxy
|
||||
port=9003
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | httpProxy
|
||||
port | 在服务端的代理端口
|
||||
##### socks5代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[socks5]
|
||||
mode=socks5
|
||||
port=9004
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | socks5
|
||||
port | 在服务端的代理端口
|
||||
##### 私密代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[secret_ssh]
|
||||
mode=secret
|
||||
password=ssh2
|
||||
target=10.1.50.2:22
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | secret
|
||||
password | 唯一密钥
|
||||
target|内网目标
|
||||
|
||||
##### p2p代理模式
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[p2p_ssh]
|
||||
mode=p2p
|
||||
password=ssh2
|
||||
target=10.1.50.2:22
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | p2p
|
||||
password | 唯一密钥
|
||||
target|内网目标
|
||||
|
||||
|
||||
##### 文件访问模式
|
||||
利用nps提供一个公网可访问的本地文件服务,此模式仅客户端使用配置文件模式方可启动
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server=1.1.1.1:8284
|
||||
vkey=123
|
||||
[file]
|
||||
mode=file
|
||||
port=9100
|
||||
local_path=/tmp/
|
||||
strip_pre=/web/
|
||||
````
|
||||
|
||||
项 | 含义
|
||||
---|---
|
||||
mode | file
|
||||
port | 服务端开启的端口
|
||||
local_path|本地文件目录
|
||||
strip_pre|前缀
|
||||
|
||||
对于`strip_pre`,访问公网`ip:9100/web/`相当于访问`/tmp/`目录
|
||||
|
||||
#### 断线重连
|
||||
```ini
|
||||
[common]
|
||||
auto_reconnection=true
|
||||
```
|
||||
|
||||
#### 状态检查
|
||||
```
|
||||
./npc status -config=npc配置文件路径
|
||||
```
|
||||
#### 重载配置文件
|
||||
```
|
||||
./npc restart -config=npc配置文件路径
|
||||
```
|
||||
|
||||
#### 通过代理连接nps
|
||||
有时候运行npc的内网机器无法直接访问外网,此时可以可以通过socks5代理连接nps
|
||||
|
||||
对于配置文件方式启动,设置
|
||||
```ini
|
||||
[common]
|
||||
proxy_socks5_url=socks5://111:222@127.0.0.1:8024
|
||||
```
|
||||
对于无配置文件模式,加上参数
|
||||
|
||||
```
|
||||
-proxy=socks5://111:222@127.0.0.1:8024
|
||||
```
|
||||
即socks5://username:password@ip:port
|
||||
|
||||
#### 日志输出级别
|
||||
```
|
||||
-log_level=0~7
|
||||
```
|
||||
```
|
||||
LevelEmergency->0 LevelAlert->1
|
||||
|
||||
LevelCritical->2 LevelError->3
|
||||
|
||||
LevelWarning->4 LevelNotice->5
|
||||
|
||||
LevelInformational->6 LevelDebug->7
|
||||
```
|
||||
默认为全输出,级别为0到7
|
||||
## 相关功能
|
||||
|
||||
### 数据压缩支持
|
||||
|
||||
由于是内网穿透,内网客户端与服务端之间的隧道存在大量的数据交换,为节省流量,加快传输速度,由此本程序支持SNNAPY形式的压缩。
|
||||
|
||||
|
||||
- 所有模式均支持数据压缩
|
||||
- 在web管理或客户端配置文件中设置
|
||||
|
||||
|
||||
### 加密传输
|
||||
|
||||
如果公司内网防火墙对外网访问进行了流量识别与屏蔽,例如禁止了ssh协议等,通过设置 配置文件,将服务端与客户端之间的通信内容加密传输,将会有效防止流量被拦截。
|
||||
- nps使用tls加密,所以一定要保留conf目录下的密钥文件,同时也可以自行生成
|
||||
- 在web管理或客户端配置文件中设置
|
||||
|
||||
|
||||
|
||||
### 站点保护
|
||||
域名代理模式所有客户端共用一个http服务端口,在知道域名后任何人都可访问,一些开发或者测试环境需要保密,所以可以设置用户名和密码,nps将通过 Http Basic Auth 来保护,访问时需要输入正确的用户名和密码。
|
||||
|
||||
|
||||
- 在web管理或客户端配置文件中设置
|
||||
|
||||
### host修改
|
||||
|
||||
由于内网站点需要的host可能与公网域名不一致,域名代理支持host修改功能,即修改request的header中的host字段。
|
||||
|
||||
**使用方法:在web管理中设置**
|
||||
|
||||
### 自定义header
|
||||
|
||||
支持对header进行新增或者修改,以配合服务的需要
|
||||
|
||||
### 404页面配置
|
||||
支持域名解析模式的自定义404页面,修改/web/static/page/error.html中内容即可,暂不支持静态文件等内容
|
||||
|
||||
### 流量限制
|
||||
|
||||
支持客户端级流量限制,当该客户端入口流量与出口流量达到设定的总量后会拒绝服务
|
||||
,域名代理会返回404页面,其他代理会拒绝连接
|
||||
|
||||
### 带宽限制
|
||||
|
||||
支持客户端级带宽限制,带宽计算方式为入口和出口总和,权重均衡
|
||||
|
||||
### 负载均衡
|
||||
本代理支持域名解析模式和tcp代理的负载均衡,在web域名添加或者编辑中内网目标分行填写多个目标即可实现轮训级别的负载均衡
|
||||
|
||||
### 端口白名单
|
||||
为了防止服务端上的端口被滥用,可在nps.conf中配置allow_ports限制可开启的端口,忽略或者不填表示端口不受限制,格式:
|
||||
|
||||
```ini
|
||||
allow_ports=9001-9009,10001,11000-12000
|
||||
```
|
||||
|
||||
### 端口范围映射
|
||||
当客户端以配置文件的方式启动时,可以将本地的端口进行范围映射,仅支持tcp和udp模式,例如:
|
||||
|
||||
```ini
|
||||
[tcp]
|
||||
mode=tcp
|
||||
port=9001-9009,10001,11000-12000
|
||||
target=8001-8009,10002,13000-14000
|
||||
```
|
||||
|
||||
逗号分隔,可单个或者范围,注意上下端口的对应关系,无法一一对应将不能成功
|
||||
### 端口范围映射到其他机器
|
||||
```ini
|
||||
[tcp]
|
||||
mode=tcp
|
||||
port=9001-9009,10001,11000-12000
|
||||
target=8001-8009,10002,13000-14000
|
||||
targetAddr=10.1.50.2
|
||||
```
|
||||
填写targetAddr后则表示映射的该地址机器的端口,忽略则便是映射本地127.0.0.1,仅范围映射时有效
|
||||
### 守护进程
|
||||
本代理支持守护进程,使用示例如下,服务端客户端所有模式通用,支持linux,darwin,windows。
|
||||
```
|
||||
./(nps|npc) start|stop|restart|status 若有其他参数可加其他参数
|
||||
```
|
||||
```
|
||||
(nps|npc).exe start|stop|restart|status 若有其他参数可加其他参数
|
||||
```
|
||||
### KCP协议支持
|
||||
|
||||
KCP 是一个快速可靠协议,能以比 TCP浪费10%-20%的带宽的代价,换取平均延迟降低 30%-40%,在弱网环境下对性能能有一定的提升。可在nps.conf中修改`bridge_type`为kcp
|
||||
,设置后本代理将开启udp端口(`bridge_port`)
|
||||
|
||||
注意:当服务端为kcp时,客户端连接时也需要使用相同配置,无配置文件模式加上参数type=kcp,配置文件模式在配置文件中设置tp=kcp
|
||||
|
||||
### 域名泛解析
|
||||
支持域名泛解析,例如将host设置为*.proxy.com,a.proxy.com、b.proxy.com等都将解析到同一目标,在web管理中或客户端配置文件中将host设置为此格式即可。
|
||||
|
||||
### URL路由
|
||||
本代理支持根据URL将同一域名转发到不同的内网服务器,可在web中或客户端配置文件中设置,此参数也可忽略,例如在客户端配置文件中
|
||||
|
||||
```ini
|
||||
[web1]
|
||||
host=a.proxy.com
|
||||
target=127.0.0.1:7001
|
||||
location=/test
|
||||
[web2]
|
||||
host=a.proxy.com
|
||||
target=127.0.0.1:7002
|
||||
location=/static
|
||||
```
|
||||
对于`a.proxy.com/test`将转发到`web1`,对于`a.proxy.com/static`将转发到`web2`
|
||||
|
||||
### 限制ip访问
|
||||
如果将一些危险性高的端口例如ssh端口暴露在公网上,可能会带来一些风险,本代理支持限制ip访问。
|
||||
|
||||
**使用方法:** 在配置文件nps.conf中设置`ip_limit`=true,设置后仅通过注册的ip方可访问。
|
||||
|
||||
**ip注册**: 在需要访问的机器上,运行客户端
|
||||
|
||||
```
|
||||
./npc register -server=ip:port -vkey=公钥或客户端密钥 time=2
|
||||
```
|
||||
|
||||
time为有效小时数,例如time=2,在当前时间后的两小时内,本机公网ip都可以访问nps代理.
|
||||
|
||||
**注意:** 本机公网ip并不是一成不变的,请自行注意有效期的设置,同时同一网络下,多人也可能是在公用同一个公网ip。
|
||||
### 客户端最大连接数
|
||||
为防止恶意大量长连接,影响服务端程序的稳定性,可以在web或客户端配置文件中为每个客户端设置最大连接数。该功能针对`socks5`、`http正向代理`、`域名代理`、`tcp代理`、`私密代理`生效。
|
||||
|
||||
### 端口复用
|
||||
在一些严格的网络环境中,对端口的个数等限制较大,nps支持强大端口复用功能。将`bridge_port`、 `http_proxy_port`、 `https_proxy_port` 、`web_port`都设置为同一端口,也能正常使用。
|
||||
|
||||
- 使用时将需要复用的端口设置为与`bridge_port`一致即可,将自动识别。
|
||||
- 如需将web管理的端口也复用,需要配置`web_host`也就是一个二级域名以便区分
|
||||
|
||||
### 环境变量渲染
|
||||
npc支持环境变量渲染以适应在某些特殊场景下的要求。
|
||||
|
||||
**在无配置文件启动模式下:**
|
||||
设置环境变量
|
||||
```
|
||||
export NPC_SERVER_ADDR=1.1.1.1:8284
|
||||
export NPC_SERVER_VKEY=xxxxx
|
||||
```
|
||||
直接执行./npc即可运行
|
||||
|
||||
**在配置文件启动模式下:**
|
||||
```ini
|
||||
[common]
|
||||
server={{.NPC_SERVER_ADDR}}
|
||||
tp=tcp
|
||||
vkey={{.NPC_SERVER_VKEY}}
|
||||
auto_reconnection=true
|
||||
[web]
|
||||
host={{.NPC_WEB_HOST}}
|
||||
target={{.NPC_WEB_TARGET}}
|
||||
```
|
||||
在配置文件中填入相应的环境变量名称,npc将自动进行渲染配置文件替换环境变量
|
||||
|
||||
### 健康检查
|
||||
|
||||
当客户端以配置文件模式启动时,支持多节点的健康检查。配置示例如下
|
||||
|
||||
```ini
|
||||
[health_check_test1]
|
||||
health_check_timeout=1
|
||||
health_check_max_failed=3
|
||||
health_check_interval=1
|
||||
health_http_url=/
|
||||
health_check_type=http
|
||||
health_check_target=127.0.0.1:8083,127.0.0.1:8082
|
||||
|
||||
[health_check_test2]
|
||||
health_check_timeout=1
|
||||
health_check_max_failed=3
|
||||
health_check_interval=1
|
||||
health_check_type=tcp
|
||||
health_check_target=127.0.0.1:8083,127.0.0.1:8082
|
||||
```
|
||||
**health关键词必须在开头存在**
|
||||
|
||||
第一种是http模式,也就是以get的方式请求目标+url,返回状态码为200表示成功
|
||||
|
||||
第一种是tcp模式,也就是以tcp的方式与目标建立连接,能成功建立连接表示成功
|
||||
|
||||
如果失败次数超过`health_check_max_failed`,nps则会移除该npc下的所有该目标,如果失败后目标重新上线,nps将自动将目标重新加入。
|
||||
项 | 含义
|
||||
---|---
|
||||
health_check_timeout | 健康检查超时时间
|
||||
health_check_max_failed | 健康检查允许失败次数
|
||||
health_check_interval | 健康检查间隔
|
||||
health_check_type | 健康检查类型
|
||||
health_check_target | 健康检查目标,多个以逗号(,)分隔
|
||||
health_check_type | 健康检查类型
|
||||
health_http_url | 健康检查url,仅http模式适用
|
||||
|
||||
|
||||
## 相关说明
|
||||
|
||||
### 获取用户真实ip
|
||||
|
||||
在域名代理模式中,可以通过request请求 header 中的 X-Forwarded-For 和 X-Real-IP 来获取用户真实 IP。
|
||||
|
||||
**本代理前会在每一个请求中添加了这两个 header。**
|
||||
|
||||
### 热更新支持
|
||||
在web管理中的修改将实时使用,无需重启客户端或者服务端
|
||||
|
||||
### 客户端地址显示
|
||||
在web管理中将显示客户端的连接地址
|
||||
|
||||
### 流量统计
|
||||
可统计显示每个代理使用的流量,由于压缩和加密等原因,会和实际环境中的略有差异
|
||||
|
||||
### 客户端与服务端版本对比
|
||||
为了程序正常运行,客户端与服务端的版本必须一致,否则将导致客户端无法成功连接致服务端。
|
||||
|
||||
## 简单的性能测试
|
||||
|
||||
### qps
|
||||

|
||||
### 速度测试
|
||||
**测试环境:** 1M带宽云服务器,理论125kb/s,带宽与代理无关,与服务器带宽和内网客户端外网带宽关系较大。
|
||||

|
||||
|
||||
|
||||
### 内存和cpu
|
||||
|
||||
**1000次性能测试后**
|
||||

|
||||
|
||||
**启动时**
|
||||

|
||||
|
||||
### 额外消耗连接数
|
||||
为了最大化的提升效率和并发,客户端与服务端之间仅两条tcp连接,减少建立连接的时间消耗和多余socket连接对机器性能的影响。
|
||||
|
||||
## webAPI
|
||||
|
||||
### webAPI验证说明
|
||||
- 采用auth_key的验证方式
|
||||
- 在提交的每个请求后面附带两个参数,`auth_key` 和`timestamp`
|
||||
|
||||
```
|
||||
auth_key的生成方式为:md5(配置文件中的auth_key+当前时间戳)
|
||||
```
|
||||
|
||||
```
|
||||
timestamp为当前时间戳
|
||||
```
|
||||
|
||||
**注意:** 为保证安全,时间戳的有效范围为20秒内,所以每次提交请求必须重新生成。
|
||||
|
||||
### 获取服务端authKey
|
||||
|
||||
如果想获取authKey,服务端提供获取authKey的接口
|
||||
|
||||
```
|
||||
POST /auth/getauthkey
|
||||
```
|
||||
将返回加密后的authKey,采用aes cbc加密,请使用与服务端配置文件中cryptKey相同的密钥进行解密
|
||||
|
||||
|
||||
### 详细文档
|
||||
- 此文档近期可能更新较慢,建议自行抓包
|
||||
|
||||
为方便第三方扩展,在web模式下可利用webAPI进行相关操作,详情见
|
||||
[webAPI文档](https://github.com/cnlh/nps/wiki/webAPI%E6%96%87%E6%A1%A3)
|
||||
|
||||
## 贡献
|
||||
#### **欢迎参与到制作docker、图标、文档翻译等工作**
|
||||
- 如果遇到bug可以直接提交至dev分支
|
||||
- 使用遇到问题可以通过issues反馈
|
||||
- 项目处于开发阶段,还有很多待完善的地方,如果可以贡献代码,请提交 PR 至 dev 分支
|
||||
- 如果有新的功能特性反馈,可以通过issues或者qq群反馈
|
||||
|
||||
|
||||
|
||||
## 交流群
|
||||
|
||||

|
||||
GPL-3.0 License — 基于 [ehang-io/nps](https://github.com/ehang-io/nps) 0.26.10 二次开发。
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
|
||||
# nps
|
||||
 
|
||||
[](https://gitter.im/cnlh-nps/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||

|
||||

|
||||
|
||||
[README](https://github.com/ehang-io/nps/blob/master/README.md)|[中文文档](https://github.com/ehang-io/nps/blob/master/README_zh.md)
|
||||
|
||||
nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务器。目前支持**tcp、udp流量转发**,可支持任何**tcp、udp**上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还**支持内网http代理、内网socks5代理**、**p2p等**,并带有功能强大的web管理端。
|
||||
|
||||
|
||||
## 背景
|
||||

|
||||
|
||||
1. 做微信公众号开发、小程序开发等----> 域名代理模式
|
||||
|
||||
2. 想在外网通过ssh连接内网的机器,做云服务器到内网服务器端口的映射,----> tcp代理模式
|
||||
|
||||
3. 在非内网环境下使用内网dns,或者需要通过udp访问内网机器等----> udp代理模式
|
||||
|
||||
4. 在外网使用HTTP代理访问内网站点----> http代理模式
|
||||
|
||||
5. 搭建一个内网穿透ss,在外网如同使用内网vpn一样访问内网资源或者设备----> socks5代理模式
|
||||
## 特点
|
||||
- 协议支持全面,兼容几乎所有常用协议,例如tcp、udp、http(s)、socks5、p2p、http代理...
|
||||
- 全平台兼容(linux、windows、macos、群辉等),支持一键安装为系统服务
|
||||
- 控制全面,同时支持服务端和客户端控制
|
||||
- https集成,支持将后端代理和web服务转成https,同时支持多证书
|
||||
- 操作简单,只需简单的配置即可在web ui上完成其余操作
|
||||
- 展示信息全面,流量、系统信息、即时带宽、客户端版本等
|
||||
- 扩展功能强大,该有的都有了(缓存、压缩、加密、流量限制、带宽限制、端口复用等等)
|
||||
- 域名解析具备自定义header、404页面配置、host修改、站点保护、URL路由、泛解析等功能
|
||||
- 服务端支持多用户和用户注册功能
|
||||
|
||||
**没找到你想要的功能?不要紧,点击[进入文档](https://ehang-io.github.io/nps)查找吧**
|
||||
## 快速开始
|
||||
|
||||
### 安装
|
||||
> [releases](https://github.com/ehang-io/nps/releases)
|
||||
|
||||
下载对应的系统版本即可,服务端和客户端是单独的
|
||||
|
||||
### 服务端启动
|
||||
下载完服务器压缩包后,解压,然后进入解压后的文件夹
|
||||
|
||||
- 执行安装命令
|
||||
|
||||
对于linux|darwin ```sudo ./nps install```
|
||||
|
||||
对于windows,管理员身份运行cmd,进入安装目录 ```nps.exe install```
|
||||
|
||||
- 默认端口
|
||||
|
||||
nps默认配置文件使用了80,443,8080,8024端口
|
||||
|
||||
80与443端口为域名解析模式默认端口
|
||||
|
||||
8080为web管理访问端口
|
||||
|
||||
8024为网桥端口,用于客户端与服务器通信
|
||||
|
||||
- 启动
|
||||
|
||||
对于linux|darwin ```sudo nps start```
|
||||
|
||||
对于windows,管理员身份运行cmd,进入程序目录 ```nps.exe start```
|
||||
|
||||
```安装后windows配置文件位于 C:\Program Files\nps,linux和darwin位于/etc/nps```
|
||||
|
||||
**如果发现没有启动成功,可以查看日志(Windows日志文件位于当前运行目录下,linux和darwin位于/var/log/nps.log)**
|
||||
- 访问服务端ip:web服务端口(默认为8080)
|
||||
- 使用用户名和密码登陆(默认admin/123,正式使用一定要更改)
|
||||
- 创建客户端
|
||||
|
||||
### 客户端连接
|
||||
- 点击web管理中客户端前的+号,复制启动命令
|
||||
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用cmd执行
|
||||
|
||||
如果需要注册到系统服务可查看[注册到系统服务](https://ehang-io.github.io/nps/#/use?id=注册到系统服务)
|
||||
|
||||
### 配置
|
||||
- 客户端连接后,在web中配置对应穿透服务即可
|
||||
- 更多高级用法见[完整文档](https://ehang-io.github.io/nps/)
|
||||
|
||||
## 贡献
|
||||
- 如果遇到bug可以直接提交至dev分支
|
||||
- 使用遇到问题可以通过issues反馈
|
||||
- 项目处于开发阶段,还有很多待完善的地方,如果可以贡献代码,请提交 PR 至 dev 分支
|
||||
- 如果有新的功能特性反馈,可以通过issues或者qq群反馈
|
||||
+344
-254
@@ -1,176 +1,222 @@
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
_ "crypto/tls"
|
||||
"ehang.io/nps/lib/nps_mux"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/conn"
|
||||
"github.com/cnlh/nps/lib/crypt"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/lib/mux"
|
||||
"github.com/cnlh/nps/lib/version"
|
||||
"github.com/cnlh/nps/server/connection"
|
||||
"github.com/cnlh/nps/server/tool"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"github.com/cnlh/nps/vender/github.com/xtaci/kcp"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/conn"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
"ehang.io/nps/lib/file"
|
||||
"ehang.io/nps/lib/version"
|
||||
"ehang.io/nps/server/connection"
|
||||
"ehang.io/nps/server/tool"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
)
|
||||
|
||||
var ServerTlsEnable bool = false
|
||||
|
||||
type Client struct {
|
||||
tunnel *mux.Mux
|
||||
mu sync.Mutex // 保护 signal/tunnel/Version 等字段的并发读写
|
||||
tunnel *nps_mux.Mux
|
||||
signal *conn.Conn
|
||||
file *mux.Mux
|
||||
retryTime int // it will be add 1 when ping not ok until to 3 will close the client
|
||||
sync.RWMutex
|
||||
file *nps_mux.Mux
|
||||
Version string
|
||||
retryTime atomic.Int32 // it will be add 1 when ping not ok until to 3 will close the client
|
||||
}
|
||||
|
||||
func NewClient(t, f *mux.Mux, s *conn.Conn) *Client {
|
||||
func NewClient(t, f *nps_mux.Mux, s *conn.Conn, vs string) *Client {
|
||||
return &Client{
|
||||
signal: s,
|
||||
tunnel: t,
|
||||
file: f,
|
||||
signal: s,
|
||||
tunnel: t,
|
||||
file: f,
|
||||
Version: vs,
|
||||
}
|
||||
}
|
||||
|
||||
type Bridge struct {
|
||||
TunnelPort int //通信隧道端口
|
||||
Client map[int]*Client
|
||||
tunnelType string //bridge type kcp or tcp
|
||||
OpenTask chan *file.Tunnel
|
||||
CloseTask chan *file.Tunnel
|
||||
CloseClient chan int
|
||||
SecretChan chan *conn.Secret
|
||||
clientLock sync.RWMutex
|
||||
Register map[string]time.Time
|
||||
registerLock sync.RWMutex
|
||||
ipVerify bool
|
||||
runList map[int]interface{}
|
||||
TunnelPort int //通信隧道端口
|
||||
Client sync.Map
|
||||
Register sync.Map
|
||||
tunnelType string //bridge type kcp or tcp
|
||||
OpenTask chan *file.Tunnel
|
||||
CloseTask chan *file.Tunnel
|
||||
CloseClient chan int
|
||||
SecretChan chan *conn.Secret
|
||||
ipVerify bool
|
||||
runList sync.Map //map[int]interface{}
|
||||
disconnectTime int
|
||||
}
|
||||
|
||||
func NewTunnel(tunnelPort int, tunnelType string, ipVerify bool, runList map[int]interface{}) *Bridge {
|
||||
t := new(Bridge)
|
||||
t.TunnelPort = tunnelPort
|
||||
t.Client = make(map[int]*Client)
|
||||
t.tunnelType = tunnelType
|
||||
t.OpenTask = make(chan *file.Tunnel)
|
||||
t.CloseTask = make(chan *file.Tunnel)
|
||||
t.CloseClient = make(chan int)
|
||||
t.Register = make(map[string]time.Time)
|
||||
t.ipVerify = ipVerify
|
||||
t.runList = runList
|
||||
t.SecretChan = make(chan *conn.Secret)
|
||||
return t
|
||||
func NewTunnel(tunnelPort int, tunnelType string, ipVerify bool, runList sync.Map, disconnectTime int) *Bridge {
|
||||
return &Bridge{
|
||||
TunnelPort: tunnelPort,
|
||||
tunnelType: tunnelType,
|
||||
OpenTask: make(chan *file.Tunnel),
|
||||
CloseTask: make(chan *file.Tunnel),
|
||||
CloseClient: make(chan int),
|
||||
SecretChan: make(chan *conn.Secret),
|
||||
ipVerify: ipVerify,
|
||||
runList: runList,
|
||||
disconnectTime: disconnectTime,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Bridge) StartTunnel() error {
|
||||
go s.ping()
|
||||
if s.tunnelType == "kcp" {
|
||||
listener, err := kcp.ListenWithOptions(beego.AppConfig.String("bridge_ip")+":"+beego.AppConfig.String("bridge_port"), nil, 150, 3)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
return err
|
||||
}
|
||||
logs.Info("server start, the bridge type is %s, the bridge port is %d", s.tunnelType, s.TunnelPort)
|
||||
go func() {
|
||||
for {
|
||||
c, err := listener.AcceptKCP()
|
||||
conn.SetUdpSession(c)
|
||||
if err != nil {
|
||||
logs.Warn(err)
|
||||
continue
|
||||
}
|
||||
go s.cliProcess(conn.NewConn(c))
|
||||
}
|
||||
}()
|
||||
return conn.NewKcpListenerAndProcess(beego.AppConfig.String("bridge_ip")+":"+beego.AppConfig.String("bridge_port"), func(c net.Conn) {
|
||||
s.cliProcess(conn.NewConn(c))
|
||||
})
|
||||
} else {
|
||||
listener, err := connection.GetBridgeListener(s.tunnelType)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
c, err := listener.Accept()
|
||||
if err != nil {
|
||||
logs.Warn(err)
|
||||
continue
|
||||
}
|
||||
go s.cliProcess(conn.NewConn(c))
|
||||
listener, err := connection.GetBridgeListener(s.tunnelType)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
return
|
||||
}
|
||||
conn.Accept(listener, func(c net.Conn) {
|
||||
s.cliProcess(conn.NewConn(c))
|
||||
})
|
||||
}()
|
||||
|
||||
// tls
|
||||
if ServerTlsEnable {
|
||||
go func() {
|
||||
// 监听TLS 端口
|
||||
tlsBridgePort := beego.AppConfig.DefaultInt("tls_bridge_port", 8025)
|
||||
|
||||
logs.Info("tls server start, the bridge type is %s, the tls bridge port is %d", "tcp", tlsBridgePort)
|
||||
tlsListener, tlsErr := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP(beego.AppConfig.String("bridge_ip")), tlsBridgePort, ""})
|
||||
if tlsErr != nil {
|
||||
logs.Error(tlsErr)
|
||||
os.Exit(0)
|
||||
return
|
||||
}
|
||||
conn.Accept(tlsListener, func(c net.Conn) {
|
||||
s.cliProcess(conn.NewConn(tls.Server(c, &tls.Config{Certificates: []tls.Certificate{crypt.GetCert()}})))
|
||||
})
|
||||
}()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//get health information form client
|
||||
func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
|
||||
for {
|
||||
if info, status, err := c.GetHealthInfo(); err != nil {
|
||||
logs.Error(err)
|
||||
break
|
||||
} else if !status { //the status is true , return target to the targetArr
|
||||
for _, v := range file.GetCsvDb().Tasks {
|
||||
if v.Client.Id == id && v.Mode == "tcp" && strings.Contains(v.Target, info) {
|
||||
v.Lock()
|
||||
if v.TargetArr == nil || (len(v.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
||||
v.TargetArr = common.TrimArr(strings.Split(v.Target, "\n"))
|
||||
}
|
||||
v.TargetArr = common.RemoveArrVal(v.TargetArr, info)
|
||||
if v.HealthRemoveArr == nil {
|
||||
v.HealthRemoveArr = make([]string, 0)
|
||||
}
|
||||
v.HealthRemoveArr = append(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
}
|
||||
for _, v := range file.GetCsvDb().Hosts {
|
||||
if v.Client.Id == id && strings.Contains(v.Target, info) {
|
||||
v.Lock()
|
||||
if v.TargetArr == nil || (len(v.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
||||
v.TargetArr = common.TrimArr(strings.Split(v.Target, "\n"))
|
||||
}
|
||||
v.TargetArr = common.RemoveArrVal(v.TargetArr, info)
|
||||
if v.HealthRemoveArr == nil {
|
||||
v.HealthRemoveArr = make([]string, 0)
|
||||
}
|
||||
v.HealthRemoveArr = append(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
}
|
||||
} else { //the status is false,remove target from the targetArr
|
||||
for _, v := range file.GetCsvDb().Tasks {
|
||||
if v.Client.Id == id && v.Mode == "tcp" && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.TargetArr, info) {
|
||||
v.Lock()
|
||||
v.TargetArr = append(v.TargetArr, info)
|
||||
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
}
|
||||
for _, v := range file.GetCsvDb().Hosts {
|
||||
if v.Client.Id == id && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.TargetArr, info) {
|
||||
v.Lock()
|
||||
v.TargetArr = append(v.TargetArr, info)
|
||||
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
// requestClientLocalAddr asks the client for private/LAN IPs on the main signal conn.
|
||||
// New clients reply with WriteLenContent; old clients ignore the flag and we time out.
|
||||
func (s *Bridge) requestClientLocalAddr(id int, c *conn.Conn) {
|
||||
if c == nil || c.Conn == nil {
|
||||
return
|
||||
}
|
||||
if _, err := c.Write([]byte(common.REPORT_LOCAL_IP)); err != nil {
|
||||
return
|
||||
}
|
||||
_ = c.Conn.SetReadDeadline(time.Now().Add(2 * time.Second))
|
||||
defer func() {
|
||||
// clear deadline so health / later reads are not affected
|
||||
_ = c.Conn.SetReadDeadline(time.Time{})
|
||||
}()
|
||||
b, err := c.GetShortLenContent()
|
||||
if err != nil {
|
||||
logs.Trace("clientId %d did not report local addr (old client or timeout): %v", id, err)
|
||||
return
|
||||
}
|
||||
localAddr := strings.TrimSpace(string(b))
|
||||
if localAddr == "" {
|
||||
return
|
||||
}
|
||||
if client, err := file.GetDb().GetClient(id); err == nil {
|
||||
client.Lock()
|
||||
client.LocalAddr = localAddr
|
||||
client.Unlock()
|
||||
logs.Info("clientId %d local addr: %s", id, localAddr)
|
||||
}
|
||||
}
|
||||
|
||||
//验证失败,返回错误验证flag,并且关闭连接
|
||||
// get health information form client
|
||||
func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
|
||||
for {
|
||||
if info, status, err := c.GetHealthInfo(); err != nil {
|
||||
break
|
||||
} else if !status { //the status is true , return target to the targetArr
|
||||
file.GetDb().JsonDb.Tasks.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Tunnel)
|
||||
if v.Client.Id == id && v.Mode == "tcp" && strings.Contains(v.Target.TargetStr, info) {
|
||||
v.Lock()
|
||||
if v.Target.TargetArr == nil || (len(v.Target.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
||||
v.Target.TargetArr = common.TrimArr(strings.Split(v.Target.TargetStr, "\n"))
|
||||
}
|
||||
v.Target.TargetArr = common.RemoveArrVal(v.Target.TargetArr, info)
|
||||
if v.HealthRemoveArr == nil {
|
||||
v.HealthRemoveArr = make([]string, 0)
|
||||
}
|
||||
v.HealthRemoveArr = append(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
return true
|
||||
})
|
||||
file.GetDb().JsonDb.Hosts.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Host)
|
||||
if v.Client.Id == id && strings.Contains(v.Target.TargetStr, info) {
|
||||
v.Lock()
|
||||
if v.Target.TargetArr == nil || (len(v.Target.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
||||
v.Target.TargetArr = common.TrimArr(strings.Split(v.Target.TargetStr, "\n"))
|
||||
}
|
||||
v.Target.TargetArr = common.RemoveArrVal(v.Target.TargetArr, info)
|
||||
if v.HealthRemoveArr == nil {
|
||||
v.HealthRemoveArr = make([]string, 0)
|
||||
}
|
||||
v.HealthRemoveArr = append(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else { //the status is false,remove target from the targetArr
|
||||
file.GetDb().JsonDb.Tasks.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Tunnel)
|
||||
if v.Client.Id == id && v.Mode == "tcp" && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.Target.TargetArr, info) {
|
||||
v.Lock()
|
||||
v.Target.TargetArr = append(v.Target.TargetArr, info)
|
||||
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
file.GetDb().JsonDb.Hosts.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Host)
|
||||
if v.Client.Id == id && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.Target.TargetArr, info) {
|
||||
v.Lock()
|
||||
v.Target.TargetArr = append(v.Target.TargetArr, info)
|
||||
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
||||
v.Unlock()
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
s.DelClient(id)
|
||||
}
|
||||
|
||||
// 验证失败,返回错误验证flag,并且关闭连接
|
||||
func (s *Bridge) verifyError(c *conn.Conn) {
|
||||
c.Write([]byte(common.VERIFY_EER))
|
||||
c.Conn.Close()
|
||||
c.Close()
|
||||
}
|
||||
|
||||
func (s *Bridge) verifySuccess(c *conn.Conn) {
|
||||
@@ -178,29 +224,39 @@ func (s *Bridge) verifySuccess(c *conn.Conn) {
|
||||
}
|
||||
|
||||
func (s *Bridge) cliProcess(c *conn.Conn) {
|
||||
// 握手 10s 超时:扫描/半开连接不会一直占着 goroutine;成功后清掉
|
||||
_ = c.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||
|
||||
//read test flag
|
||||
if _, err := c.GetShortContent(3); err != nil {
|
||||
logs.Info("The client %s connect error", c.Conn.RemoteAddr())
|
||||
logs.Info("The client %s connect error", c.Conn.RemoteAddr(), err.Error())
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
//version check
|
||||
if b, err := c.GetShortContent(32); err != nil || string(b) != crypt.Md5(version.GetVersion()) {
|
||||
logs.Info("The client %s version does not match", c.Conn.RemoteAddr())
|
||||
//version check(版本不匹配仍兼容放行;读失败则断开)
|
||||
if _, err := c.GetShortLenContent(); err != nil {
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
//version get
|
||||
var vs []byte
|
||||
var err error
|
||||
if vs, err = c.GetShortLenContent(); err != nil {
|
||||
logs.Info("get client %s version error", err.Error())
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
//write server version to client
|
||||
c.Write([]byte(crypt.Md5(version.GetVersion())))
|
||||
c.SetReadDeadline(5, s.tunnelType)
|
||||
_ = c.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||
var buf []byte
|
||||
var err error
|
||||
//get vKey from client
|
||||
if buf, err = c.GetShortContent(32); err != nil {
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
//verify
|
||||
id, err := file.GetCsvDb().GetIdByVerifyKey(string(buf), c.Conn.RemoteAddr().String())
|
||||
id, err := file.GetDb().GetIdByVerifyKey(string(buf), c.Conn.RemoteAddr().String())
|
||||
if err != nil {
|
||||
logs.Info("Current client connection validation error, close this client:", c.Conn.RemoteAddr())
|
||||
s.verifyError(c)
|
||||
@@ -209,67 +265,85 @@ func (s *Bridge) cliProcess(c *conn.Conn) {
|
||||
s.verifySuccess(c)
|
||||
}
|
||||
if flag, err := c.ReadFlag(); err == nil {
|
||||
s.typeDeal(flag, c, id)
|
||||
// 握手完成,交给 typeDeal 做长连接
|
||||
_ = c.SetReadDeadline(time.Time{})
|
||||
s.typeDeal(flag, c, id, string(vs))
|
||||
} else {
|
||||
logs.Warn(err, flag)
|
||||
c.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Bridge) DelClient(id int, isOther bool) {
|
||||
s.clientLock.Lock()
|
||||
defer s.clientLock.Unlock()
|
||||
if v, ok := s.Client[id]; ok {
|
||||
if c, err := file.GetCsvDb().GetClient(id); err == nil && c.NoStore {
|
||||
func (s *Bridge) DelClient(id int) {
|
||||
if v, ok := s.Client.Load(id); ok {
|
||||
cl := v.(*Client)
|
||||
cl.mu.Lock()
|
||||
signalToClose := cl.signal
|
||||
cl.signal = nil
|
||||
cl.mu.Unlock()
|
||||
if signalToClose != nil {
|
||||
signalToClose.Close()
|
||||
}
|
||||
s.Client.Delete(id)
|
||||
if file.GetDb().IsPubClient(id) {
|
||||
return
|
||||
}
|
||||
if c, err := file.GetDb().GetClient(id); err == nil {
|
||||
s.CloseClient <- c.Id
|
||||
}
|
||||
if v.signal != nil {
|
||||
v.signal.Close()
|
||||
}
|
||||
delete(s.Client, id)
|
||||
}
|
||||
}
|
||||
|
||||
//use different
|
||||
func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) {
|
||||
// use different
|
||||
func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
|
||||
isPub := file.GetDb().IsPubClient(id)
|
||||
switch typeVal {
|
||||
case common.WORK_MAIN:
|
||||
//the vKey connect by another ,close the client of before
|
||||
s.clientLock.Lock()
|
||||
if v, ok := s.Client[id]; ok {
|
||||
s.clientLock.Unlock()
|
||||
if v.signal != nil {
|
||||
v.signal.WriteClose()
|
||||
}
|
||||
v.Lock()
|
||||
v.signal = c
|
||||
v.Unlock()
|
||||
} else {
|
||||
s.Client[id] = NewClient(nil, nil, c)
|
||||
s.clientLock.Unlock()
|
||||
if isPub {
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
tcpConn, ok := c.Conn.(*net.TCPConn)
|
||||
if ok {
|
||||
// add tcp keep alive option for signal connection
|
||||
_ = tcpConn.SetKeepAlive(true)
|
||||
_ = tcpConn.SetKeepAlivePeriod(5 * time.Second)
|
||||
}
|
||||
//the vKey connect by another ,close the client of before
|
||||
if v, ok := s.Client.LoadOrStore(id, NewClient(nil, nil, c, vs)); ok {
|
||||
cl := v.(*Client)
|
||||
cl.mu.Lock()
|
||||
oldSignal := cl.signal
|
||||
cl.signal = c
|
||||
cl.Version = vs
|
||||
cl.mu.Unlock()
|
||||
cl.retryTime.Store(0)
|
||||
if oldSignal != nil {
|
||||
oldSignal.WriteClose()
|
||||
}
|
||||
}
|
||||
// Request private/LAN IPs from client. Old clients ignore the flag; short timeout keeps compatibility.
|
||||
s.requestClientLocalAddr(id, c)
|
||||
go s.GetHealthFromClient(id, c)
|
||||
logs.Info("clientId %d connection succeeded, address:%s ", id, c.Conn.RemoteAddr())
|
||||
case common.WORK_CHAN:
|
||||
s.clientLock.Lock()
|
||||
if v, ok := s.Client[id]; ok {
|
||||
s.clientLock.Unlock()
|
||||
v.Lock()
|
||||
v.tunnel = mux.NewMux(c.Conn, s.tunnelType)
|
||||
v.Unlock()
|
||||
} else {
|
||||
s.Client[id] = NewClient(mux.NewMux(c.Conn, s.tunnelType), nil, nil)
|
||||
s.clientLock.Unlock()
|
||||
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType, s.disconnectTime)
|
||||
if v, ok := s.Client.LoadOrStore(id, NewClient(muxConn, nil, nil, vs)); ok {
|
||||
cl := v.(*Client)
|
||||
cl.mu.Lock()
|
||||
oldTunnel := cl.tunnel
|
||||
cl.tunnel = muxConn
|
||||
cl.mu.Unlock()
|
||||
if oldTunnel != nil {
|
||||
oldTunnel.Close()
|
||||
}
|
||||
}
|
||||
case common.WORK_CONFIG:
|
||||
var isPub bool
|
||||
client, err := file.GetCsvDb().GetClient(id);
|
||||
if err == nil {
|
||||
if client.VerifyKey == beego.AppConfig.String("public_vkey") {
|
||||
isPub = true
|
||||
} else {
|
||||
isPub = false
|
||||
}
|
||||
client, err := file.GetDb().GetClient(id)
|
||||
if err != nil || (!isPub && !client.ConfigConnAllow) {
|
||||
c.Close()
|
||||
return
|
||||
}
|
||||
binary.Write(c, binary.LittleEndian, isPub)
|
||||
go s.getConfig(c, isPub, client)
|
||||
@@ -278,40 +352,47 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) {
|
||||
case common.WORK_SECRET:
|
||||
if b, err := c.GetShortContent(32); err == nil {
|
||||
s.SecretChan <- conn.NewSecret(string(b), c)
|
||||
} else {
|
||||
logs.Error("secret error, failed to match the key successfully")
|
||||
}
|
||||
case common.WORK_FILE:
|
||||
s.clientLock.Lock()
|
||||
if v, ok := s.Client[id]; ok {
|
||||
s.clientLock.Unlock()
|
||||
v.Lock()
|
||||
v.file = mux.NewMux(c.Conn, s.tunnelType)
|
||||
v.Unlock()
|
||||
} else {
|
||||
s.Client[id] = NewClient(nil, mux.NewMux(c.Conn, s.tunnelType), nil)
|
||||
s.clientLock.Unlock()
|
||||
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType, s.disconnectTime)
|
||||
if v, ok := s.Client.LoadOrStore(id, NewClient(nil, muxConn, nil, vs)); ok {
|
||||
cl := v.(*Client)
|
||||
cl.mu.Lock()
|
||||
oldFile := cl.file
|
||||
cl.file = muxConn
|
||||
cl.mu.Unlock()
|
||||
if oldFile != nil {
|
||||
oldFile.Close()
|
||||
}
|
||||
}
|
||||
case common.WORK_P2P:
|
||||
//read md5 secret
|
||||
if b, err := c.GetShortContent(32); err != nil {
|
||||
return
|
||||
} else if t := file.GetCsvDb().GetTaskByMd5Password(string(b)); t == nil {
|
||||
return
|
||||
logs.Error("p2p error,", err.Error())
|
||||
} else if t := file.GetDb().GetTaskByMd5Password(string(b)); t == nil {
|
||||
logs.Error("p2p error, failed to match the key successfully")
|
||||
} else {
|
||||
s.clientLock.Lock()
|
||||
if v, ok := s.Client[t.Client.Id]; !ok {
|
||||
s.clientLock.Unlock()
|
||||
if v, ok := s.Client.Load(t.Client.Id); !ok {
|
||||
return
|
||||
} else {
|
||||
s.clientLock.Unlock()
|
||||
cl := v.(*Client)
|
||||
cl.mu.Lock()
|
||||
sig := cl.signal
|
||||
cl.mu.Unlock()
|
||||
if sig == nil {
|
||||
return
|
||||
}
|
||||
//向密钥对应的客户端发送与服务端udp建立连接信息,地址,密钥
|
||||
v.signal.Write([]byte(common.NEW_UDP_CONN))
|
||||
sig.Write([]byte(common.NEW_UDP_CONN))
|
||||
svrAddr := beego.AppConfig.String("p2p_ip") + ":" + beego.AppConfig.String("p2p_port")
|
||||
if err != nil {
|
||||
logs.Warn("get local udp addr error")
|
||||
return
|
||||
}
|
||||
v.signal.WriteLenContent([]byte(svrAddr))
|
||||
v.signal.WriteLenContent(b)
|
||||
sig.WriteLenContent([]byte(svrAddr))
|
||||
sig.WriteLenContent(b)
|
||||
//向该请求者发送建立连接请求,服务器地址
|
||||
c.WriteLenContent([]byte(svrAddr))
|
||||
}
|
||||
@@ -321,60 +402,59 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) {
|
||||
return
|
||||
}
|
||||
|
||||
//register ip
|
||||
// register ip
|
||||
func (s *Bridge) register(c *conn.Conn) {
|
||||
var hour int32
|
||||
if err := binary.Read(c, binary.LittleEndian, &hour); err == nil {
|
||||
s.registerLock.Lock()
|
||||
s.Register[common.GetIpByAddr(c.Conn.RemoteAddr().String())] = time.Now().Add(time.Hour * time.Duration(hour))
|
||||
s.registerLock.Unlock()
|
||||
s.Register.Store(common.GetIpByAddr(c.Conn.RemoteAddr().String()), time.Now().Add(time.Hour*time.Duration(hour)))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Bridge) SendLinkInfo(clientId int, link *conn.Link, linkAddr string, t *file.Tunnel) (target net.Conn, err error) {
|
||||
s.clientLock.Lock()
|
||||
if v, ok := s.Client[clientId]; ok {
|
||||
s.clientLock.Unlock()
|
||||
|
||||
func (s *Bridge) SendLinkInfo(clientId int, link *conn.Link, t *file.Tunnel) (target net.Conn, err error) {
|
||||
//if the proxy type is local
|
||||
if link.LocalProxy {
|
||||
target, err = net.Dial("tcp", link.Host)
|
||||
return
|
||||
}
|
||||
if v, ok := s.Client.Load(clientId); ok {
|
||||
//If ip is restricted to do ip verification
|
||||
if s.ipVerify {
|
||||
s.registerLock.Lock()
|
||||
ip := common.GetIpByAddr(linkAddr)
|
||||
if v, ok := s.Register[ip]; !ok {
|
||||
s.registerLock.Unlock()
|
||||
ip := common.GetIpByAddr(link.RemoteAddr)
|
||||
if v, ok := s.Register.Load(ip); !ok {
|
||||
return nil, errors.New(fmt.Sprintf("The ip %s is not in the validation list", ip))
|
||||
} else {
|
||||
s.registerLock.Unlock()
|
||||
if !v.After(time.Now()) {
|
||||
if !v.(time.Time).After(time.Now()) {
|
||||
return nil, errors.New(fmt.Sprintf("The validity of the ip %s has expired", ip))
|
||||
}
|
||||
}
|
||||
}
|
||||
var tunnel *mux.Mux
|
||||
var tunnel *nps_mux.Mux
|
||||
cl := v.(*Client)
|
||||
cl.mu.Lock()
|
||||
if t != nil && t.Mode == "file" {
|
||||
tunnel = v.file
|
||||
tunnel = cl.file
|
||||
} else {
|
||||
tunnel = v.tunnel
|
||||
tunnel = cl.tunnel
|
||||
}
|
||||
cl.mu.Unlock()
|
||||
if tunnel == nil {
|
||||
err = errors.New("the client connect error")
|
||||
return
|
||||
}
|
||||
|
||||
if target, err = tunnel.NewConn(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if t != nil && t.Mode == "file" {
|
||||
//TODO if t.mode is file ,not use crypt or compress
|
||||
link.Crypt = false
|
||||
link.Compress = false
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = conn.NewConn(target).SendLinkInfo(link); err != nil {
|
||||
if _, err = conn.NewConn(target).SendInfo(link, ""); err != nil {
|
||||
logs.Info("new connect error ,the target %s refuse to connect", link.Host)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
s.clientLock.Unlock()
|
||||
err = errors.New(fmt.Sprintf("the client %d is not connect", clientId))
|
||||
}
|
||||
return
|
||||
@@ -382,33 +462,39 @@ func (s *Bridge) SendLinkInfo(clientId int, link *conn.Link, linkAddr string, t
|
||||
|
||||
func (s *Bridge) ping() {
|
||||
ticker := time.NewTicker(time.Second * 5)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
s.clientLock.Lock()
|
||||
arr := make([]int, 0)
|
||||
for k, v := range s.Client {
|
||||
if v.tunnel == nil || v.signal == nil {
|
||||
v.retryTime += 1
|
||||
if v.retryTime >= 3 {
|
||||
arr = append(arr, k)
|
||||
s.Client.Range(func(key, value interface{}) bool {
|
||||
v := value.(*Client)
|
||||
v.mu.Lock()
|
||||
tunnel := v.tunnel
|
||||
signal := v.signal
|
||||
if tunnel == nil || signal == nil {
|
||||
v.mu.Unlock()
|
||||
if v.retryTime.Add(1) >= 3 {
|
||||
arr = append(arr, key.(int))
|
||||
}
|
||||
continue
|
||||
return true
|
||||
}
|
||||
if v.tunnel.IsClose {
|
||||
arr = append(arr, k)
|
||||
isClose := tunnel.IsClose()
|
||||
v.mu.Unlock()
|
||||
if isClose {
|
||||
arr = append(arr, key.(int))
|
||||
}
|
||||
}
|
||||
s.clientLock.Unlock()
|
||||
return true
|
||||
})
|
||||
for _, v := range arr {
|
||||
logs.Info("the client %d closed", v)
|
||||
s.DelClient(v, false)
|
||||
s.DelClient(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//get config and add task from client config
|
||||
// get config and add task from client config
|
||||
func (s *Bridge) getConfig(c *conn.Conn, isPub bool, client *file.Client) {
|
||||
var fail bool
|
||||
loop:
|
||||
@@ -423,22 +509,25 @@ loop:
|
||||
break loop
|
||||
} else {
|
||||
var str string
|
||||
id, err := file.GetCsvDb().GetClientIdByVkey(string(b))
|
||||
id, err := file.GetDb().GetClientIdByVkey(string(b))
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
file.GetCsvDb().Lock()
|
||||
for _, v := range file.GetCsvDb().Hosts {
|
||||
file.GetDb().JsonDb.Hosts.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Host)
|
||||
if v.Client.Id == id {
|
||||
str += v.Remark + common.CONN_DATA_SEQ
|
||||
}
|
||||
}
|
||||
for _, v := range file.GetCsvDb().Tasks {
|
||||
if _, ok := s.runList[v.Id]; ok && v.Client.Id == id {
|
||||
return true
|
||||
})
|
||||
file.GetDb().JsonDb.Tasks.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Tunnel)
|
||||
//if _, ok := s.runList[v.Id]; ok && v.Client.Id == id {
|
||||
if _, ok := s.runList.Load(v.Id); ok && v.Client.Id == id {
|
||||
str += v.Remark + common.CONN_DATA_SEQ
|
||||
}
|
||||
}
|
||||
file.GetCsvDb().Unlock()
|
||||
return true
|
||||
})
|
||||
binary.Write(c, binary.LittleEndian, int32(len([]byte(str))))
|
||||
binary.Write(c, binary.LittleEndian, []byte(str))
|
||||
}
|
||||
@@ -449,16 +538,14 @@ loop:
|
||||
c.WriteAddFail()
|
||||
break loop
|
||||
} else {
|
||||
if err = file.GetCsvDb().NewClient(client); err != nil {
|
||||
if err = file.GetDb().NewClient(client); err != nil {
|
||||
fail = true
|
||||
c.WriteAddFail()
|
||||
break loop
|
||||
}
|
||||
c.WriteAddOk()
|
||||
c.Write([]byte(client.VerifyKey))
|
||||
s.clientLock.Lock()
|
||||
s.Client[client.Id] = NewClient(nil, nil, nil)
|
||||
s.clientLock.Unlock()
|
||||
s.Client.Store(client.Id, NewClient(nil, nil, nil, ""))
|
||||
}
|
||||
case common.NEW_HOST:
|
||||
h, err := c.GetHostInfo()
|
||||
@@ -472,12 +559,12 @@ loop:
|
||||
h.Location = "/"
|
||||
}
|
||||
if !client.HasHost(h) {
|
||||
if file.GetCsvDb().IsHostExist(h) {
|
||||
if file.GetDb().IsHostExist(h) {
|
||||
fail = true
|
||||
c.WriteAddFail()
|
||||
break loop
|
||||
} else {
|
||||
file.GetCsvDb().NewHost(h)
|
||||
file.GetDb().NewHost(h)
|
||||
c.WriteAddOk()
|
||||
}
|
||||
} else {
|
||||
@@ -490,12 +577,12 @@ loop:
|
||||
break loop
|
||||
} else {
|
||||
ports := common.GetPorts(t.Ports)
|
||||
targets := common.GetPorts(t.Target)
|
||||
targets := common.GetPorts(t.Target.TargetStr)
|
||||
if len(ports) > 1 && (t.Mode == "tcp" || t.Mode == "udp") && (len(ports) != len(targets)) {
|
||||
fail = true
|
||||
c.WriteAddFail()
|
||||
break loop
|
||||
} else if t.Mode == "secret" {
|
||||
} else if t.Mode == "secret" || t.Mode == "p2p" {
|
||||
ports = append(ports, 0)
|
||||
}
|
||||
if len(ports) == 0 {
|
||||
@@ -507,18 +594,20 @@ loop:
|
||||
tl := new(file.Tunnel)
|
||||
tl.Mode = t.Mode
|
||||
tl.Port = ports[i]
|
||||
tl.ServerIp = t.ServerIp
|
||||
if len(ports) == 1 {
|
||||
tl.Target = t.Target
|
||||
tl.Remark = t.Remark
|
||||
} else {
|
||||
tl.Remark = t.Remark + "_" + strconv.Itoa(tl.Port)
|
||||
tl.Target = new(file.Target)
|
||||
if t.TargetAddr != "" {
|
||||
tl.Target = t.TargetAddr + ":" + strconv.Itoa(targets[i])
|
||||
tl.Target.TargetStr = t.TargetAddr + ":" + strconv.Itoa(targets[i])
|
||||
} else {
|
||||
tl.Target = strconv.Itoa(targets[i])
|
||||
tl.Target.TargetStr = strconv.Itoa(targets[i])
|
||||
}
|
||||
}
|
||||
tl.Id = file.GetCsvDb().GetTaskId()
|
||||
tl.Id = int(file.GetDb().JsonDb.GetTaskId())
|
||||
tl.Status = true
|
||||
tl.Flow = new(file.Flow)
|
||||
tl.NoStore = true
|
||||
@@ -526,8 +615,9 @@ loop:
|
||||
tl.Password = t.Password
|
||||
tl.LocalPath = t.LocalPath
|
||||
tl.StripPre = t.StripPre
|
||||
tl.MultiAccount = t.MultiAccount
|
||||
if !client.HasTunnel(tl) {
|
||||
if err := file.GetCsvDb().NewTask(tl); err != nil {
|
||||
if err := file.GetDb().NewTask(tl); err != nil {
|
||||
logs.Notice("Add task error ", err.Error())
|
||||
fail = true
|
||||
c.WriteAddFail()
|
||||
@@ -547,7 +637,7 @@ loop:
|
||||
}
|
||||
}
|
||||
if fail && client != nil {
|
||||
s.DelClient(client.Id, false)
|
||||
s.DelClient(client.Id)
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
cd /go
|
||||
if grep -q "buster" /etc/apt/sources.list; then
|
||||
sed -i 's|http://deb.debian.org/debian|http://archive.debian.org/debian|g' /etc/apt/sources.list
|
||||
sed -i 's|http://security.debian.org/debian-security|http://archive.debian.org/debian-security|g' /etc/apt/sources.list
|
||||
echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid
|
||||
fi
|
||||
apt-get update
|
||||
apt-get install -y libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev ca-certificates curl
|
||||
|
||||
GO_VERSION="${GO_VERSION:-1.22.7}"
|
||||
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tgz
|
||||
rm -rf /usr/local/go
|
||||
tar -C /usr/local -xzf /tmp/go.tgz
|
||||
export PATH="/usr/local/go/bin:$PATH"
|
||||
export GOTOOLCHAIN=auto
|
||||
go version
|
||||
|
||||
GO111MODULE=on go install fyne.io/tools/cmd/fyne@latest
|
||||
export PATH="$PATH:$(go env GOPATH)/bin"
|
||||
#mkdir -p /go/src/fyne.io
|
||||
#cd src/fyne.io
|
||||
#git clone https://github.com/fyne-io/fyne.git
|
||||
#cd fyne
|
||||
#git checkout v1.2.0
|
||||
#go install -v ./cmd/fyne
|
||||
#fyne package -os android fyne.io/fyne/cmd/hello
|
||||
echo "fyne install success"
|
||||
mkdir -p /go/src/ehang.io/nps
|
||||
cp -R /app/* /go/src/ehang.io/nps
|
||||
cd /go/src/ehang.io/nps
|
||||
#go get -u fyne.io/fyne fyne.io/fyne/cmd/fyne
|
||||
rm -f cmd/npc/sdk.go
|
||||
#go get -u ./...
|
||||
#go mod tidy
|
||||
#rm -rf /go/src/golang.org/x/mobile
|
||||
echo "tidy success"
|
||||
cd /go/src/ehang.io/nps
|
||||
go mod vendor
|
||||
cd vendor
|
||||
cp -R * /go/src
|
||||
cd ..
|
||||
rm -rf vendor
|
||||
#rm -rf ~/.cache/*
|
||||
echo "vendor success"
|
||||
cd gui/npc
|
||||
fyne package -appID org.nps.client -os android -icon ../../docs/logo.png
|
||||
apk="$(ls -1 *.apk 2>/dev/null | head -n 1)"
|
||||
if [ -z "$apk" ]; then
|
||||
echo "No apk produced"
|
||||
ls -la
|
||||
exit 1
|
||||
fi
|
||||
mv "$apk" /app/android_client.apk
|
||||
echo "android build success"
|
||||
Executable
+167
@@ -0,0 +1,167 @@
|
||||
export GOPROXY=direct
|
||||
|
||||
sudo apt-get update
|
||||
sudo apt-get install gcc-mingw-w64-i686 gcc-multilib
|
||||
env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc go build -ldflags "-s -w -extldflags -static -extldflags -static" -buildmode=c-shared -o npc_sdk.dll cmd/npc/sdk.go
|
||||
env GOOS=linux GOARCH=386 CGO_ENABLED=1 CC=gcc go build -ldflags "-s -w -extldflags -static -extldflags -static" -buildmode=c-shared -o npc_sdk.so cmd/npc/sdk.go
|
||||
tar -czvf npc_sdk.tar.gz npc_sdk.dll npc_sdk.so npc_sdk.h
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_amd64_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_386_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf freebsd_386_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf freebsd_amd64_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf freebsd_arm_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_arm_v7_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_arm_v6_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_arm_v5_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_arm64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_mips64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_mips64le_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_mipsle_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf linux_mips_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf windows_386_client.tar.gz npc.exe
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf windows_amd64_client.tar.gz npc.exe
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf darwin_amd64_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
|
||||
tar -czvf darwin_arm64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_amd64_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_386_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm_v5_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm_v6_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm_v7_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm64_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf freebsd_arm_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf freebsd_386_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf freebsd_amd64_server.tar.gz nps
|
||||
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mips_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mips64_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mips64le_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mipsle_server.tar.gz nps
|
||||
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf darwin_amd64_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf darwin_arm64_server.tar.gz nps
|
||||
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf windows_amd64_server.tar.gz nps.exe
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf windows_386_server.tar.gz nps.exe
|
||||
@@ -0,0 +1,168 @@
|
||||
#/bash/sh
|
||||
export VERSION=0.26.38
|
||||
export GOPROXY=direct
|
||||
|
||||
sudo apt-get update
|
||||
sudo apt-get install gcc-mingw-w64-i686 gcc-multilib
|
||||
env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc go build -ldflags "-s -w -extldflags -static -extldflags -static" -buildmode=c-shared -o npc_sdk.dll cmd/npc/sdk.go
|
||||
env GOOS=linux GOARCH=386 CGO_ENABLED=1 CC=gcc go build -ldflags "-s -w -extldflags -static -extldflags -static" -buildmode=c-shared -o npc_sdk.so cmd/npc/sdk.go
|
||||
tar -czvf npc_sdk.tar.gz npc_sdk.dll npc_sdk.so npc_sdk.h
|
||||
|
||||
wget https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz
|
||||
tar -xvf upx-3.95-amd64_linux.tar.xz
|
||||
cp upx-3.95-amd64_linux/upx ./
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_amd64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_386_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf freebsd_386_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf freebsd_amd64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf freebsd_arm_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_arm_v7_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_arm_v6_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_arm_v5_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_arm64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_mips64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_mips64le_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_mipsle_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf linux_mips_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf windows_386_client.tar.gz npc.exe
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf windows_amd64_client.tar.gz npc.exe
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf darwin_amd64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
|
||||
tar -czvf darwin_arm64_client.tar.gz npc
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_386_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_arm_v5_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_arm_v6_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_arm_v7_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_arm64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf freebsd_arm_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf freebsd_386_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf freebsd_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_mips_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_mips64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_mips64le_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf linux_mipsle_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf darwin_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf darwin_arm64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf windows_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps.exe
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
tar -czvf windows_386_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps.exe
|
||||
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
sudo apt-get update
|
||||
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
|
||||
docker --version
|
||||
docker run --rm -i -w /app -v $(pwd):/app -e ANDROID_HOME=/usr/local/android_sdk -e GOPROXY=direct lucor/fyne-cross:android-latest /app/build.android.sh
|
||||
git clone https://github.com/cnlh/spksrc.git ~/spksrc
|
||||
mkdir ~/spksrc/nps && cp -rf ./* ~/spksrc/nps/
|
||||
docker run -itd --name spksrc --env VERSION=$VERSION -e GOPROXY=direct -v ~/spksrc:/spksrc synocommunity/spksrc /bin/bash
|
||||
docker exec -it spksrc /bin/bash -c 'cd /spksrc && make setup && cd /spksrc/spk/npc && make arch-x64-7.0'
|
||||
cp ~/spksrc/packages/npc_x64-7.0_$VERSION-1.spk ./npc_syno.spk
|
||||
|
||||
|
||||
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||
export DOCKER_CLI_EXPERIMENTAL=enabled
|
||||
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
|
||||
docker buildx create --use --name mybuilder
|
||||
docker buildx build --tag ffdfgdfg/nps:$VERSION --tag ffdfgdfg/nps:latest --output type=image,push=true --file Dockerfile.nps --platform=linux/amd64,linux/arm64,linux/386,linux/arm .
|
||||
docker buildx build --tag ffdfgdfg/npc:$VERSION --tag ffdfgdfg/npc:latest --output type=image,push=true --file Dockerfile.npc --platform=linux/amd64,linux/arm64,linux/386,linux/arm .
|
||||
+341
-139
@@ -1,15 +1,25 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/config"
|
||||
"github.com/cnlh/nps/lib/conn"
|
||||
"github.com/cnlh/nps/lib/mux"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"github.com/cnlh/nps/vender/github.com/xtaci/kcp"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"net"
|
||||
"os"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/nps_mux"
|
||||
"github.com/pires/go-proxyproto"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/xtaci/kcp-go"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/config"
|
||||
"ehang.io/nps/lib/conn"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
)
|
||||
|
||||
type TRPClient struct {
|
||||
@@ -17,218 +27,410 @@ type TRPClient struct {
|
||||
bridgeConnType string
|
||||
proxyUrl string
|
||||
vKey string
|
||||
tunnel *mux.Mux
|
||||
p2pAddr map[string]string
|
||||
tunnel *nps_mux.Mux
|
||||
signal *conn.Conn
|
||||
ticker *time.Ticker
|
||||
cnf *config.Config
|
||||
disconnectTime int
|
||||
once sync.Once
|
||||
closeCh chan struct{} // closed when client is shutting down; stops ping
|
||||
logger Logger // 每客户端独立的 logger,未设置时使用全局 logger
|
||||
}
|
||||
|
||||
//new client
|
||||
func NewRPClient(svraddr string, vKey string, bridgeConnType string, proxyUrl string, cnf *config.Config) *TRPClient {
|
||||
// Logger 客户端日志接口,GUI / CLI 均可注入实现
|
||||
type Logger interface {
|
||||
Info(format string, v ...interface{})
|
||||
Error(format string, v ...interface{})
|
||||
Warn(format string, v ...interface{})
|
||||
Trace(format string, v ...interface{})
|
||||
}
|
||||
|
||||
// new client
|
||||
func NewRPClient(svraddr string, vKey string, bridgeConnType string, proxyUrl string, cnf *config.Config, disconnectTime int) *TRPClient {
|
||||
return &TRPClient{
|
||||
svrAddr: svraddr,
|
||||
p2pAddr: make(map[string]string, 0),
|
||||
vKey: vKey,
|
||||
bridgeConnType: bridgeConnType,
|
||||
proxyUrl: proxyUrl,
|
||||
cnf: cnf,
|
||||
disconnectTime: disconnectTime,
|
||||
once: sync.Once{},
|
||||
closeCh: make(chan struct{}),
|
||||
logger: nil, // 默认使用全局 logger,可通过 SetLogger 设置
|
||||
}
|
||||
}
|
||||
|
||||
//start
|
||||
// SetLogger 设置客户端的独立 logger
|
||||
func (s *TRPClient) SetLogger(logger Logger) {
|
||||
s.logger = logger
|
||||
}
|
||||
|
||||
// log 辅助方法:如果设置了独立 logger 就使用,否则使用全局 logger
|
||||
func (s *TRPClient) logInfo(format string, v ...interface{}) {
|
||||
if s.logger != nil {
|
||||
s.logger.Info(format, v...)
|
||||
} else {
|
||||
logs.Info(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TRPClient) logError(format string, v ...interface{}) {
|
||||
if s.logger != nil {
|
||||
s.logger.Error(format, v...)
|
||||
} else {
|
||||
logs.Error(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TRPClient) logWarn(format string, v ...interface{}) {
|
||||
if s.logger != nil {
|
||||
s.logger.Warn(format, v...)
|
||||
} else {
|
||||
logs.Warn(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TRPClient) logTrace(format string, v ...interface{}) {
|
||||
if s.logger != nil {
|
||||
s.logger.Trace(format, v...)
|
||||
} else {
|
||||
logs.Trace(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// IsConnected 返回客户端是否已成功连接到服务器
|
||||
func (s *TRPClient) IsConnected() bool {
|
||||
return s.signal != nil
|
||||
}
|
||||
|
||||
var NowStatus int
|
||||
var CloseClient bool
|
||||
|
||||
// start
|
||||
func (s *TRPClient) Start() {
|
||||
CloseClient = false
|
||||
retry:
|
||||
if CloseClient {
|
||||
return
|
||||
}
|
||||
NowStatus = 0
|
||||
c, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_MAIN, s.proxyUrl)
|
||||
if err != nil {
|
||||
logs.Error("The connection server failed and will be reconnected in five seconds")
|
||||
s.logError("The connection server failed and will be reconnected in five seconds, error", err.Error())
|
||||
time.Sleep(time.Second * 5)
|
||||
goto retry
|
||||
}
|
||||
|
||||
logs.Info("Successful connection with server %s", s.svrAddr)
|
||||
if c == nil {
|
||||
s.logError("Error data from server, and will be reconnected in five seconds")
|
||||
time.Sleep(time.Second * 5)
|
||||
goto retry
|
||||
}
|
||||
s.logInfo("Successful connection with server %s", s.svrAddr)
|
||||
//monitor the connection
|
||||
go s.ping()
|
||||
s.processor(c)
|
||||
}
|
||||
|
||||
func (s *TRPClient) Close() {
|
||||
s.tunnel.Close()
|
||||
s.signal.Close()
|
||||
s.ticker.Stop()
|
||||
}
|
||||
|
||||
//处理
|
||||
func (s *TRPClient) processor(c *conn.Conn) {
|
||||
s.signal = c
|
||||
go s.dealChan()
|
||||
//start a channel connection
|
||||
go s.newChan()
|
||||
//start health check if the it's open
|
||||
if s.cnf != nil && len(s.cnf.Healths) > 0 {
|
||||
go heathCheck(s.cnf.Healths, s.signal)
|
||||
}
|
||||
NowStatus = 1
|
||||
//msg connection, eg udp
|
||||
s.handleMain()
|
||||
}
|
||||
|
||||
// handle main connection
|
||||
func (s *TRPClient) handleMain() {
|
||||
mainLoop:
|
||||
for {
|
||||
flags, err := c.ReadFlag()
|
||||
flags, err := s.signal.ReadFlag()
|
||||
if err != nil {
|
||||
logs.Error("Accept server data error %s, end this service", err.Error())
|
||||
s.logError("Accept server data error %s, end this service", err.Error())
|
||||
break
|
||||
}
|
||||
switch flags {
|
||||
case common.VERIFY_EER:
|
||||
logs.Error("VKey:%s is incorrect, the server refuses to connect, please check", s.vKey)
|
||||
os.Exit(0)
|
||||
case common.RES_CLOSE:
|
||||
logs.Error("The authentication key is connected by another client or the server closes the client.")
|
||||
os.Exit(0)
|
||||
case common.RES_MSG:
|
||||
logs.Error("Server-side return error")
|
||||
break
|
||||
case common.REPORT_LOCAL_IP:
|
||||
// server requests private/LAN IPs (new nps); ignore failures so main loop continues
|
||||
localIPs := common.GetLocalIPs(s.signal.Conn)
|
||||
if err := s.signal.WriteLenContent([]byte(localIPs)); err != nil {
|
||||
s.logWarn("report local ip failed: %s", err.Error())
|
||||
} else {
|
||||
s.logInfo("reported local addr: %s", localIPs)
|
||||
}
|
||||
case common.NEW_UDP_CONN:
|
||||
//读取服务端地址、密钥 继续做处理
|
||||
if lAddr, err := c.GetShortLenContent(); err != nil {
|
||||
logs.Warn(err)
|
||||
return
|
||||
} else if pwd, err := c.GetShortLenContent(); err == nil {
|
||||
go s.newUdpConn(string(lAddr), string(pwd))
|
||||
//read server udp addr and password
|
||||
if lAddr, err := s.signal.GetShortLenContent(); err != nil {
|
||||
s.logWarn(err.Error())
|
||||
break mainLoop
|
||||
} else if pwd, err := s.signal.GetShortLenContent(); err == nil {
|
||||
var localAddr string
|
||||
//The local port remains unchanged for a certain period of time
|
||||
if v, ok := s.p2pAddr[crypt.Md5(string(pwd)+strconv.Itoa(int(time.Now().Unix()/100)))]; !ok {
|
||||
tmpConn, err := common.GetLocalUdpAddr()
|
||||
if err != nil {
|
||||
s.logError(err.Error())
|
||||
break mainLoop
|
||||
}
|
||||
localAddr = tmpConn.LocalAddr().String()
|
||||
} else {
|
||||
localAddr = v
|
||||
}
|
||||
go s.newUdpConn(localAddr, string(lAddr), string(pwd))
|
||||
}
|
||||
default:
|
||||
logs.Warn("The error could not be resolved")
|
||||
break
|
||||
}
|
||||
}
|
||||
c.Close()
|
||||
s.Close()
|
||||
}
|
||||
|
||||
func (s *TRPClient) newUdpConn(rAddr string, md5Password string) {
|
||||
tmpConn, err := common.GetLocalUdpAddr()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
localAddr, _ := net.ResolveUDPAddr("udp", tmpConn.LocalAddr().String())
|
||||
localConn, err := net.ListenUDP("udp", localAddr)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
localKcpConn, err := kcp.NewConn(rAddr, nil, 150, 3, localConn)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
conn.SetUdpSession(localKcpConn)
|
||||
localToolConn := conn.NewConn(localKcpConn)
|
||||
//写入密钥、provider身份
|
||||
if _, err := localToolConn.Write([]byte(md5Password)); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
if _, err := localToolConn.Write([]byte(common.WORK_P2P_PROVIDER)); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//接收服务端传的visitor地址
|
||||
var b []byte
|
||||
if b, err = localToolConn.GetShortLenContent(); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//向visitor地址发送测试消息
|
||||
visitorAddr, err := net.ResolveUDPAddr("udp", string(b))
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//向目标IP发送探测包
|
||||
if _, err := localConn.WriteTo([]byte("test"), visitorAddr); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//给服务端发反馈
|
||||
if _, err := localToolConn.Write([]byte(common.VERIFY_SUCCESS)); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//关闭与服务端的连接
|
||||
localConn.Close()
|
||||
//关闭与服务端udp conn,建立新的监听
|
||||
if localConn, err = net.ListenUDP("udp", localAddr); err != nil {
|
||||
logs.Error(err)
|
||||
func (s *TRPClient) newUdpConn(localAddr, rAddr string, md5Password string) {
|
||||
var localConn net.PacketConn
|
||||
var err error
|
||||
var remoteAddress string
|
||||
if remoteAddress, localConn, err = handleP2PUdp(localAddr, rAddr, md5Password, common.WORK_P2P_PROVIDER); err != nil {
|
||||
s.logError(err.Error())
|
||||
return
|
||||
}
|
||||
l, err := kcp.ServeConn(nil, 150, 3, localConn)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
s.logError(err.Error())
|
||||
return
|
||||
}
|
||||
//接收新的监听,得到conn,
|
||||
s.logTrace("start local p2p udp listen, local address %s", localConn.LocalAddr().String())
|
||||
for {
|
||||
udpTunnel, err := l.AcceptKCP()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
s.logError(err.Error())
|
||||
l.Close()
|
||||
return
|
||||
}
|
||||
if udpTunnel.RemoteAddr().String() == string(b) {
|
||||
if udpTunnel.RemoteAddr().String() == string(remoteAddress) {
|
||||
conn.SetUdpSession(udpTunnel)
|
||||
//读取link,设置msgCh 设置msgConn消息回传响应机制
|
||||
l := mux.NewMux(udpTunnel, s.bridgeConnType)
|
||||
for {
|
||||
connMux, err := l.Accept()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
go s.srcProcess(connMux)
|
||||
}
|
||||
s.logTrace("successful connection with client ,address %s", udpTunnel.RemoteAddr().String())
|
||||
//read link info from remote
|
||||
conn.Accept(nps_mux.NewMux(udpTunnel, s.bridgeConnType, s.disconnectTime), func(c net.Conn) {
|
||||
go s.handleChan(c)
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//mux tunnel
|
||||
func (s *TRPClient) dealChan() {
|
||||
// pmux tunnel
|
||||
func (s *TRPClient) newChan() {
|
||||
tunnel, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_CHAN, s.proxyUrl)
|
||||
if err != nil {
|
||||
logs.Error("connect to ", s.svrAddr, "error:", err)
|
||||
// WORK_MAIN may already be up; without Close the client stays half-connected
|
||||
// (handleMain blocks, outer reconnect loop never runs). See #115.
|
||||
s.logError("connect to %s error: %v, client will reconnect", s.svrAddr, err)
|
||||
s.Close()
|
||||
return
|
||||
}
|
||||
s.tunnel = mux.NewMux(tunnel.Conn, s.bridgeConnType)
|
||||
s.tunnel = nps_mux.NewMux(tunnel.Conn, s.bridgeConnType, s.disconnectTime)
|
||||
for {
|
||||
src, err := s.tunnel.Accept()
|
||||
if err != nil {
|
||||
logs.Warn(err)
|
||||
s.logWarn(err.Error())
|
||||
s.Close()
|
||||
break
|
||||
}
|
||||
go s.srcProcess(src)
|
||||
go s.handleChan(src)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TRPClient) srcProcess(src net.Conn) {
|
||||
func (s *TRPClient) handleChan(src net.Conn) {
|
||||
lk, err := conn.NewConn(src).GetLinkInfo()
|
||||
if err != nil {
|
||||
if err != nil || lk == nil {
|
||||
src.Close()
|
||||
logs.Error("get connection info from server error ", err)
|
||||
s.logError("get connection info from server error %v", err)
|
||||
return
|
||||
}
|
||||
//host for target processing
|
||||
lk.Host = common.FormatAddress(lk.Host)
|
||||
//connect to target
|
||||
if targetConn, err := net.Dial(lk.ConnType, lk.Host); err != nil {
|
||||
logs.Warn("connect to %s error %s", lk.Host, err.Error())
|
||||
//if Conn type is http, read the request and log
|
||||
if lk.ConnType == "http" {
|
||||
if targetConn, err := net.DialTimeout(common.CONN_TCP, lk.Host, lk.Option.Timeout); err != nil {
|
||||
s.logWarn("connect to %s error %s", lk.Host, err.Error())
|
||||
src.Close()
|
||||
} else {
|
||||
srcConn := conn.GetConn(src, lk.Crypt, lk.Compress, nil, false)
|
||||
go func() {
|
||||
common.CopyBuffer(srcConn, targetConn)
|
||||
srcConn.Close()
|
||||
targetConn.Close()
|
||||
}()
|
||||
br := bufio.NewReader(srcConn)
|
||||
for {
|
||||
if r, err := http.ReadRequest(br); err != nil {
|
||||
srcConn.Close()
|
||||
targetConn.Close()
|
||||
break
|
||||
} else {
|
||||
remoteAddr := strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
|
||||
if len(remoteAddr) == 0 {
|
||||
remoteAddr = r.RemoteAddr
|
||||
}
|
||||
s.logTrace("http request, method %s, host %s, url %s, remote address %s", r.Method, r.Host, r.URL.Path, remoteAddr)
|
||||
r.Write(targetConn)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if lk.ConnType == "udp5" {
|
||||
s.logTrace("new %s connection with the goal of %s, remote address:%s", lk.ConnType, lk.Host, lk.RemoteAddr)
|
||||
s.handleUdp(src)
|
||||
}
|
||||
//connect to target if conn type is tcp or udp
|
||||
if targetConn, err := net.DialTimeout(lk.ConnType, lk.Host, lk.Option.Timeout); err != nil {
|
||||
s.logWarn("connect to %s error %s", lk.Host, err.Error())
|
||||
src.Close()
|
||||
} else {
|
||||
logs.Trace("new %s connection with the goal of %s, remote address:%s", lk.ConnType, lk.Host, lk.RemoteAddr)
|
||||
conn.CopyWaitGroup(src, targetConn, lk.Crypt, lk.Compress, nil, nil, false)
|
||||
s.logTrace("new %s connection with the goal of %s, remote address:%s", lk.ConnType, lk.Host, lk.RemoteAddr)
|
||||
|
||||
if lk.ProtoVersion == "V1" || lk.ProtoVersion == "V2" {
|
||||
var addr = targetConn.RemoteAddr()
|
||||
if lk.RemoteAddr != "" {
|
||||
s := strings.Split(lk.RemoteAddr, ":")[1]
|
||||
port, _ := strconv.Atoi(s)
|
||||
addr = &net.TCPAddr{
|
||||
IP: net.ParseIP(strings.Split(lk.RemoteAddr, ":")[0]),
|
||||
Port: port,
|
||||
}
|
||||
}
|
||||
|
||||
var version byte
|
||||
|
||||
if lk.ProtoVersion == "V1" {
|
||||
version = 1
|
||||
} else if lk.ProtoVersion == "V2" {
|
||||
version = 2
|
||||
}
|
||||
|
||||
transportProtocol := proxyproto.TCPv4
|
||||
if strings.Contains(addr.String(), ".") {
|
||||
transportProtocol = proxyproto.TCPv4
|
||||
} else {
|
||||
transportProtocol = proxyproto.TCPv6
|
||||
}
|
||||
|
||||
header := &proxyproto.Header{
|
||||
Command: proxyproto.PROXY,
|
||||
SourceAddr: addr,
|
||||
DestinationAddr: targetConn.RemoteAddr(),
|
||||
Version: version,
|
||||
TransportProtocol: transportProtocol,
|
||||
}
|
||||
|
||||
_, err2 := header.WriteTo(targetConn)
|
||||
if err2 != nil {
|
||||
s.logError(err2.Error())
|
||||
}
|
||||
}
|
||||
|
||||
conn.CopyWaitGroup(src, targetConn, lk.Crypt, lk.Compress, nil, nil, false, nil, nil, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TRPClient) ping() {
|
||||
s.ticker = time.NewTicker(time.Second * 5)
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-s.ticker.C:
|
||||
if s.tunnel.IsClose {
|
||||
s.Close()
|
||||
s.ticker.Stop()
|
||||
break loop
|
||||
func (s *TRPClient) handleUdp(serverConn net.Conn) {
|
||||
// bind a local udp port
|
||||
local, err := net.ListenUDP("udp", nil)
|
||||
defer serverConn.Close()
|
||||
if err != nil {
|
||||
s.logError("bind local udp port error %s", err.Error())
|
||||
return
|
||||
}
|
||||
defer local.Close()
|
||||
go func() {
|
||||
defer serverConn.Close()
|
||||
b := common.BufPoolUdp.Get().([]byte)
|
||||
defer common.BufPoolUdp.Put(b)
|
||||
var buf bytes.Buffer
|
||||
for {
|
||||
n, raddr, err := local.ReadFrom(b)
|
||||
if err != nil {
|
||||
s.logError("read data from remote server error %s", err.Error())
|
||||
return
|
||||
}
|
||||
buf.Reset()
|
||||
dgram := common.NewUDPDatagram(common.NewUDPHeader(0, 0, common.ToSocksAddr(raddr)), b[:n])
|
||||
dgram.Write(&buf)
|
||||
data, err := conn.GetLenBytes(buf.Bytes())
|
||||
if err != nil {
|
||||
s.logWarn("get len bytes error %s", err.Error())
|
||||
continue
|
||||
}
|
||||
if _, err := serverConn.Write(data); err != nil {
|
||||
s.logError("write data to remote error %s", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
b := common.BufPoolUdp.Get().([]byte)
|
||||
defer common.BufPoolUdp.Put(b)
|
||||
for {
|
||||
n, err := serverConn.Read(b)
|
||||
if err != nil {
|
||||
s.logError("read udp data from server error %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
udpData, err := common.ReadUDPDatagram(bytes.NewReader(b[:n]))
|
||||
if err != nil {
|
||||
s.logError("unpack data error %s", err.Error())
|
||||
return
|
||||
}
|
||||
raddr, err := net.ResolveUDPAddr("udp", udpData.Header.Addr.String())
|
||||
if err != nil {
|
||||
s.logError("build remote addr err %s", err.Error())
|
||||
continue // drop silently
|
||||
}
|
||||
_, err = local.WriteTo(udpData.Data, raddr)
|
||||
if err != nil {
|
||||
s.logError("write data to remote %s error %s", raddr.String(), err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Whether the monitor channel is closed
|
||||
func (s *TRPClient) ping() {
|
||||
s.ticker = time.NewTicker(time.Second * 5)
|
||||
defer s.ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-s.ticker.C:
|
||||
// tunnel still nil: newChan failed or still connecting; if Close already ran, closeCh fires.
|
||||
// tunnel established then closed: tear down so outer loop can reconnect.
|
||||
if s.tunnel != nil && s.tunnel.IsClose() {
|
||||
s.Close()
|
||||
return
|
||||
}
|
||||
case <-s.closeCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TRPClient) Close() {
|
||||
s.once.Do(s.closing)
|
||||
}
|
||||
|
||||
func (s *TRPClient) closing() {
|
||||
CloseClient = true
|
||||
NowStatus = 0
|
||||
// unblock ping; safe: closing runs only once via once.Do
|
||||
select {
|
||||
case <-s.closeCh:
|
||||
default:
|
||||
close(s.closeCh)
|
||||
}
|
||||
if s.tunnel != nil {
|
||||
_ = s.tunnel.Close()
|
||||
}
|
||||
if s.signal != nil {
|
||||
_ = s.signal.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
conn2 "github.com/cnlh/nps/lib/conn"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
conn, err := net.Dial("tcp", "127.0.0.1:8284")
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
c := conn2.NewConn(conn)
|
||||
c.SetAlive("tcp")
|
||||
if _, err := c.Write([]byte(common.Getverifyval("123"))); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
c.WriteConfig()
|
||||
config := &file.Config{
|
||||
U: "1",
|
||||
P: "2",
|
||||
Compress: "snappy",
|
||||
Crypt: true,
|
||||
CompressEncode: 0,
|
||||
CompressDecode: 0,
|
||||
}
|
||||
host := &file.Host{
|
||||
Host: "a.o.com",
|
||||
Target: "127.0.0.1:8080",
|
||||
HeaderChange: "",
|
||||
HostChange: "",
|
||||
Flow: nil,
|
||||
Client: nil,
|
||||
Remark: "111",
|
||||
NowIndex: 0,
|
||||
TargetArr: nil,
|
||||
NoStore: false,
|
||||
RWMutex: sync.RWMutex{},
|
||||
}
|
||||
tunnel := &file.Tunnel{
|
||||
Port: 9001,
|
||||
Mode: "tcp",
|
||||
Target: "127.0.0.1:8082",
|
||||
Remark: "333",
|
||||
}
|
||||
var b []byte
|
||||
if b, err = c.ReadLen(16); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if _, err := c.SendConfigInfo(config); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if !c.GetAddStatus() {
|
||||
t.Fail()
|
||||
}
|
||||
if _, err := c.SendHostInfo(host); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if !c.GetAddStatus() {
|
||||
t.Fail()
|
||||
}
|
||||
if _, err := c.SendTaskInfo(tunnel); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if !c.GetAddStatus() {
|
||||
t.Fail()
|
||||
}
|
||||
c.Close()
|
||||
NewRPClient("127.0.0.1:8284", string(b), "tcp").Start()
|
||||
}
|
||||
+378
-42
@@ -1,27 +1,45 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/config"
|
||||
"github.com/cnlh/nps/lib/conn"
|
||||
"github.com/cnlh/nps/lib/crypt"
|
||||
"github.com/cnlh/nps/lib/version"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"github.com/cnlh/nps/vender/github.com/xtaci/kcp"
|
||||
"github.com/cnlh/nps/vender/golang.org/x/net/proxy"
|
||||
"io/ioutil"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/config"
|
||||
"ehang.io/nps/lib/conn"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
"ehang.io/nps/lib/version"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/xtaci/kcp-go"
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
|
||||
var tlsEnable1 = false
|
||||
|
||||
func SetTlsEnable(tlsEnable11 bool) {
|
||||
tlsEnable1 = tlsEnable11
|
||||
}
|
||||
|
||||
func GetTlsEnable() bool {
|
||||
return tlsEnable1
|
||||
}
|
||||
|
||||
func GetTaskStatus(path string) {
|
||||
cnf, err := config.NewConfig(path)
|
||||
if err != nil {
|
||||
@@ -31,11 +49,9 @@ func GetTaskStatus(path string) {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if _, err := c.Write([]byte(common.WORK_STATUS)); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
//read now vKey and write to server
|
||||
if f, err := common.ReadAllFromFile(filepath.Join(common.GetTmpPath(), "npc_vkey.txt")); err != nil {
|
||||
log.Fatalln(err)
|
||||
@@ -86,11 +102,13 @@ func StartFromFile(path string) {
|
||||
first := true
|
||||
cnf, err := config.NewConfig(path)
|
||||
if err != nil || cnf.CommonConfig == nil {
|
||||
logs.Error("Config file %s loading error", path)
|
||||
logs.Error("Config file %s loading error %s", path, err.Error())
|
||||
os.Exit(0)
|
||||
}
|
||||
logs.Info("Loading configuration file %s successfully", path)
|
||||
|
||||
SetTlsEnable(cnf.CommonConfig.TlsEnable)
|
||||
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), GetTlsEnable())
|
||||
re:
|
||||
if first || cnf.CommonConfig.AutoReconnection {
|
||||
if !first {
|
||||
@@ -114,12 +132,12 @@ re:
|
||||
vkey := cnf.CommonConfig.VKey
|
||||
if isPub {
|
||||
// send global configuration to server and get status of config setting
|
||||
if _, err := c.SendConfigInfo(cnf.CommonConfig); err != nil {
|
||||
if _, err := c.SendInfo(cnf.CommonConfig.Client, common.NEW_CONF); err != nil {
|
||||
logs.Error(err)
|
||||
goto re
|
||||
}
|
||||
if !c.GetAddStatus() {
|
||||
logs.Error(errAdd)
|
||||
logs.Error("the web_user may have been occupied!")
|
||||
goto re
|
||||
}
|
||||
|
||||
@@ -129,11 +147,11 @@ re:
|
||||
}
|
||||
vkey = string(b)
|
||||
}
|
||||
ioutil.WriteFile(filepath.Join(common.GetTmpPath(), "npc_vkey.txt"), []byte(vkey), 0600)
|
||||
os.WriteFile(filepath.Join(common.GetTmpPath(), "npc_vkey.txt"), []byte(vkey), 0600)
|
||||
|
||||
//send hosts to server
|
||||
for _, v := range cnf.Hosts {
|
||||
if _, err := c.SendHostInfo(v); err != nil {
|
||||
if _, err := c.SendInfo(v, common.NEW_HOST); err != nil {
|
||||
logs.Error(err)
|
||||
goto re
|
||||
}
|
||||
@@ -145,12 +163,12 @@ re:
|
||||
|
||||
//send task to server
|
||||
for _, v := range cnf.Tasks {
|
||||
if _, err := c.SendTaskInfo(v); err != nil {
|
||||
if _, err := c.SendInfo(v, common.NEW_TASK); err != nil {
|
||||
logs.Error(err)
|
||||
goto re
|
||||
}
|
||||
if !c.GetAddStatus() {
|
||||
logs.Error(errAdd, v.Ports)
|
||||
logs.Error(errAdd, v.Ports, v.Remark)
|
||||
goto re
|
||||
}
|
||||
if v.Mode == "file" {
|
||||
@@ -165,7 +183,12 @@ re:
|
||||
}
|
||||
|
||||
c.Close()
|
||||
NewRPClient(cnf.CommonConfig.Server, vkey, cnf.CommonConfig.Tp, cnf.CommonConfig.ProxyUrl, cnf).Start()
|
||||
if cnf.CommonConfig.Client.WebUserName == "" || cnf.CommonConfig.Client.WebPassword == "" {
|
||||
logs.Notice("web access login username:user password:%s", vkey)
|
||||
} else {
|
||||
logs.Notice("web access login username:%s password:%s", cnf.CommonConfig.Client.WebUserName, cnf.CommonConfig.Client.WebPassword)
|
||||
}
|
||||
NewRPClient(cnf.CommonConfig.Server, vkey, cnf.CommonConfig.Tp, cnf.CommonConfig.ProxyUrl, cnf, cnf.CommonConfig.DisconnectTime).Start()
|
||||
CloseLocalServer()
|
||||
goto re
|
||||
}
|
||||
@@ -181,51 +204,364 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st
|
||||
if er != nil {
|
||||
return nil, er
|
||||
}
|
||||
n, er := proxy.FromURL(u, nil)
|
||||
if er != nil {
|
||||
return nil, er
|
||||
switch u.Scheme {
|
||||
case "socks5":
|
||||
n, er := proxy.FromURL(u, nil)
|
||||
if er != nil {
|
||||
return nil, er
|
||||
}
|
||||
connection, err = n.Dial("tcp", server)
|
||||
default:
|
||||
connection, err = NewHttpProxyConn(u, server)
|
||||
}
|
||||
connection, err = n.Dial("tcp", server)
|
||||
} else {
|
||||
connection, err = net.Dial("tcp", server)
|
||||
if GetTlsEnable() {
|
||||
//tls 流量加密
|
||||
conf := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
connection, err = tls.Dial("tcp", server, conf)
|
||||
} else {
|
||||
connection, err = net.Dial("tcp", server)
|
||||
}
|
||||
|
||||
//header := &proxyproto.Header{
|
||||
// Version: 1,
|
||||
// Command: proxyproto.PROXY,
|
||||
// TransportProtocol: proxyproto.TCPv4,
|
||||
// SourceAddr: &net.TCPAddr{
|
||||
// IP: net.ParseIP("10.1.1.1"),
|
||||
// Port: 1000,
|
||||
// },
|
||||
// DestinationAddr: &net.TCPAddr{
|
||||
// IP: net.ParseIP("20.2.2.2"),
|
||||
// Port: 2000,
|
||||
// },
|
||||
//}
|
||||
//
|
||||
//_, err = header.WriteTo(connection)
|
||||
//_, err = io.WriteString(connection, "HELO")
|
||||
}
|
||||
} else {
|
||||
sess, err = kcp.DialWithOptions(server, nil, 10, 3)
|
||||
conn.SetUdpSession(sess)
|
||||
connection = sess
|
||||
if err == nil {
|
||||
conn.SetUdpSession(sess)
|
||||
connection = sess
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
connection.SetDeadline(time.Now().Add(time.Second * 10))
|
||||
defer connection.SetDeadline(time.Time{})
|
||||
c := conn.NewConn(connection)
|
||||
if _, err := c.Write([]byte(common.CONN_TEST)); err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
return nil, err
|
||||
}
|
||||
if _, err := c.Write([]byte(crypt.Md5(version.GetVersion()))); err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
if err := c.WriteLenContent([]byte(version.GetVersion())); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if b, err := c.GetShortContent(32); err != nil || crypt.Md5(version.GetVersion()) != string(b) {
|
||||
logs.Error("The client does not match the server version. The current version of the client is", version.GetVersion())
|
||||
os.Exit(0)
|
||||
if err := c.WriteLenContent([]byte(version.VERSION)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := c.GetShortContent(32)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
if crypt.Md5(version.GetVersion()) != string(b) {
|
||||
//logs.Error("The client does not match the server version. The current core version of the client is", version.GetVersion())
|
||||
//return nil, err
|
||||
}
|
||||
if _, err := c.Write([]byte(common.Getverifyval(vkey))); err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
return nil, err
|
||||
}
|
||||
if s, err := c.ReadFlag(); err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
return nil, err
|
||||
} else if s == common.VERIFY_EER {
|
||||
logs.Error("Validation key %s incorrect", vkey)
|
||||
os.Exit(0)
|
||||
return nil, errors.New(fmt.Sprintf("Validation key %s incorrect", vkey))
|
||||
}
|
||||
if _, err := c.Write([]byte(connType)); err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
return nil, err
|
||||
}
|
||||
c.SetAlive(tp)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// http proxy connection
|
||||
func NewHttpProxyConn(url *url.URL, remoteAddr string) (net.Conn, error) {
|
||||
req, err := http.NewRequest("CONNECT", "http://"+remoteAddr, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
password, _ := url.User.Password()
|
||||
req.Header.Set("Authorization", "Basic "+basicAuth(strings.Trim(url.User.Username(), " "), password))
|
||||
// we make a http proxy request
|
||||
proxyConn, err := net.Dial("tcp", url.Host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := req.Write(proxyConn); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := http.ReadResponse(bufio.NewReader(proxyConn), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
return nil, errors.New("Proxy error " + res.Status)
|
||||
}
|
||||
return proxyConn, nil
|
||||
}
|
||||
|
||||
// get a basic auth string
|
||||
func basicAuth(username, password string) string {
|
||||
auth := username + ":" + password
|
||||
return base64.StdEncoding.EncodeToString([]byte(auth))
|
||||
}
|
||||
|
||||
func getRemoteAddressFromServer(rAddr string, localConn *net.UDPConn, md5Password, role string, add int) error {
|
||||
rAddr, err := getNextAddr(rAddr, add)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return err
|
||||
}
|
||||
addr, err := net.ResolveUDPAddr("udp", rAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := localConn.WriteTo(common.GetWriteStr(md5Password, role), addr); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleP2PUdp(localAddr, rAddr, md5Password, role string) (remoteAddress string, c net.PacketConn, err error) {
|
||||
localConn, err := newUdpConnByAddr(localAddr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer localConn.Close()
|
||||
err = getRemoteAddressFromServer(rAddr, localConn, md5Password, role, 0)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
err = getRemoteAddressFromServer(rAddr, localConn, md5Password, role, 1)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
err = getRemoteAddressFromServer(rAddr, localConn, md5Password, role, 2)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
var remoteAddr1, remoteAddr2, remoteAddr3 string
|
||||
// 修复:添加超时,避免无限等待远端响应
|
||||
localConn.SetReadDeadline(time.Now().Add(30 * time.Second))
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
var n int
|
||||
var addr *net.UDPAddr
|
||||
n, addr, err = localConn.ReadFromUDP(buf)
|
||||
if err != nil {
|
||||
localConn.SetReadDeadline(time.Time{})
|
||||
return
|
||||
}
|
||||
rAddr2, _ := getNextAddr(rAddr, 1)
|
||||
rAddr3, _ := getNextAddr(rAddr, 2)
|
||||
switch addr.String() {
|
||||
case rAddr:
|
||||
remoteAddr1 = string(buf[:n])
|
||||
case rAddr2:
|
||||
remoteAddr2 = string(buf[:n])
|
||||
case rAddr3:
|
||||
remoteAddr3 = string(buf[:n])
|
||||
}
|
||||
if remoteAddr1 != "" && remoteAddr2 != "" && remoteAddr3 != "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
localConn.SetReadDeadline(time.Time{})
|
||||
if remoteAddress, err = sendP2PTestMsg(localConn, remoteAddr1, remoteAddr2, remoteAddr3); err != nil {
|
||||
return
|
||||
}
|
||||
c, err = newUdpConnByAddr(localAddr)
|
||||
return
|
||||
}
|
||||
|
||||
func sendP2PTestMsg(localConn *net.UDPConn, remoteAddr1, remoteAddr2, remoteAddr3 string) (string, error) {
|
||||
logs.Trace(remoteAddr3, remoteAddr2, remoteAddr1)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
interval, err := getAddrInterval(remoteAddr1, remoteAddr2, remoteAddr3)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
go func() {
|
||||
addr, err := getNextAddr(remoteAddr3, interval)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
remoteUdpAddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
logs.Trace("try send test packet to target %s", addr)
|
||||
ticker := time.NewTicker(time.Millisecond * 500)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if _, err := localConn.WriteTo([]byte(common.WORK_P2P_CONNECT), remoteUdpAddr); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
if interval != 0 {
|
||||
ip := common.GetIpByAddr(remoteAddr2)
|
||||
go func() {
|
||||
ports := getRandomPortArr(common.GetPortByAddr(remoteAddr3), common.GetPortByAddr(remoteAddr3)+interval*50)
|
||||
for i := 0; i <= 50; i++ {
|
||||
go func(port int) {
|
||||
trueAddress := ip + ":" + strconv.Itoa(port)
|
||||
logs.Trace("try send test packet to target %s", trueAddress)
|
||||
remoteUdpAddr, err := net.ResolveUDPAddr("udp", trueAddress)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ticker := time.NewTicker(time.Second * 2)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if _, err := localConn.WriteTo([]byte(common.WORK_P2P_CONNECT), remoteUdpAddr); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}(ports[i])
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
buf := make([]byte, 10)
|
||||
for {
|
||||
localConn.SetReadDeadline(time.Now().Add(time.Second * 10))
|
||||
n, addr, err := localConn.ReadFromUDP(buf)
|
||||
localConn.SetReadDeadline(time.Time{})
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
switch string(buf[:n]) {
|
||||
case common.WORK_P2P_SUCCESS:
|
||||
for i := 20; i > 0; i-- {
|
||||
if _, err = localConn.WriteTo([]byte(common.WORK_P2P_END), addr); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return addr.String(), nil
|
||||
case common.WORK_P2P_END:
|
||||
logs.Trace("Remotely Address %s Reply Packet Successfully Received", addr.String())
|
||||
return addr.String(), nil
|
||||
case common.WORK_P2P_CONNECT:
|
||||
go func() {
|
||||
for i := 20; i > 0; i-- {
|
||||
logs.Trace("try send receive success packet to target %s", addr.String())
|
||||
if _, err = localConn.WriteTo([]byte(common.WORK_P2P_SUCCESS), addr); err != nil {
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}()
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
return "", errors.New("connect to the target failed, maybe the nat type is not support p2p")
|
||||
}
|
||||
|
||||
func newUdpConnByAddr(addr string) (*net.UDPConn, error) {
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
udpConn, err := net.ListenUDP("udp", udpAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return udpConn, nil
|
||||
}
|
||||
|
||||
func getNextAddr(addr string, n int) (string, error) {
|
||||
arr := strings.Split(addr, ":")
|
||||
if len(arr) != 2 {
|
||||
return "", errors.New(fmt.Sprintf("the format of %s incorrect", addr))
|
||||
}
|
||||
if p, err := strconv.Atoi(arr[1]); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
return arr[0] + ":" + strconv.Itoa(p+n), nil
|
||||
}
|
||||
}
|
||||
|
||||
func getAddrInterval(addr1, addr2, addr3 string) (int, error) {
|
||||
arr1 := strings.Split(addr1, ":")
|
||||
if len(arr1) != 2 {
|
||||
return 0, errors.New(fmt.Sprintf("the format of %s incorrect", addr1))
|
||||
}
|
||||
arr2 := strings.Split(addr2, ":")
|
||||
if len(arr2) != 2 {
|
||||
return 0, errors.New(fmt.Sprintf("the format of %s incorrect", addr2))
|
||||
}
|
||||
arr3 := strings.Split(addr3, ":")
|
||||
if len(arr3) != 2 {
|
||||
return 0, errors.New(fmt.Sprintf("the format of %s incorrect", addr3))
|
||||
}
|
||||
p1, err := strconv.Atoi(arr1[1])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
p2, err := strconv.Atoi(arr2[1])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
p3, err := strconv.Atoi(arr3[1])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
interVal := int(math.Floor(math.Min(math.Abs(float64(p3-p2)), math.Abs(float64(p2-p1)))))
|
||||
if p3-p1 < 0 {
|
||||
return -interVal, nil
|
||||
}
|
||||
return interVal, nil
|
||||
}
|
||||
|
||||
func getRandomPortArr(min, max int) []int {
|
||||
if min > max {
|
||||
min, max = max, min
|
||||
}
|
||||
addrAddr := make([]int, max-min+1)
|
||||
for i := min; i <= max; i++ {
|
||||
addrAddr[max-i] = i
|
||||
}
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
var ri, temp int
|
||||
for i := max - min; i > 0; i-- {
|
||||
ri = r.Int() % i
|
||||
temp = addrAddr[i]
|
||||
addrAddr[i] = addrAddr[ri]
|
||||
addrAddr[ri] = temp
|
||||
}
|
||||
return addrAddr
|
||||
}
|
||||
|
||||
+15
-8
@@ -2,15 +2,16 @@ package client
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"github.com/cnlh/nps/lib/conn"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/lib/sheap"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"github.com/pkg/errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/conn"
|
||||
"ehang.io/nps/lib/file"
|
||||
"ehang.io/nps/lib/sheap"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var isStart bool
|
||||
@@ -63,14 +64,18 @@ func session(healths []*file.Health, h *sheap.IntHeap) {
|
||||
}
|
||||
}
|
||||
|
||||
//只针对一个端口 面向多个目标的情况
|
||||
// work when just one port and many target
|
||||
func check(t *file.Health) {
|
||||
arr := strings.Split(t.HealthCheckTarget, ",")
|
||||
var err error
|
||||
var rs *http.Response
|
||||
for _, v := range arr {
|
||||
if t.HealthCheckType == "tcp" {
|
||||
_, err = net.DialTimeout("tcp", v, time.Duration(t.HealthCheckTimeout)*time.Second);
|
||||
var c net.Conn
|
||||
c, err = net.DialTimeout("tcp", v, time.Duration(t.HealthCheckTimeout)*time.Second)
|
||||
if err == nil {
|
||||
c.Close()
|
||||
}
|
||||
} else {
|
||||
client := &http.Client{}
|
||||
client.Timeout = time.Duration(t.HealthCheckTimeout) * time.Second
|
||||
@@ -79,6 +84,7 @@ func check(t *file.Health) {
|
||||
err = errors.New("status code is not match")
|
||||
}
|
||||
}
|
||||
t.Lock()
|
||||
if err != nil {
|
||||
t.HealthMap[v] += 1
|
||||
} else if t.HealthMap[v] >= t.HealthMaxFail {
|
||||
@@ -87,9 +93,10 @@ func check(t *file.Health) {
|
||||
t.HealthMap[v] = 0
|
||||
}
|
||||
|
||||
if t.HealthMap[v] == t.HealthMaxFail {
|
||||
if t.HealthMap[v] > 0 && t.HealthMap[v]%t.HealthMaxFail == 0 {
|
||||
//send fail remove
|
||||
serverConn.SendHealthInfo(v, "0")
|
||||
}
|
||||
t.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
+143
-91
@@ -1,23 +1,57 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/config"
|
||||
"github.com/cnlh/nps/lib/conn"
|
||||
"github.com/cnlh/nps/lib/crypt"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/lib/mux"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"github.com/cnlh/nps/vender/github.com/xtaci/kcp"
|
||||
"ehang.io/nps/lib/nps_mux"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/config"
|
||||
"ehang.io/nps/lib/conn"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
"ehang.io/nps/lib/file"
|
||||
"ehang.io/nps/server/proxy"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/xtaci/kcp-go"
|
||||
)
|
||||
|
||||
var LocalServer []*net.TCPListener
|
||||
var udpConn net.Conn
|
||||
var muxSession *mux.Mux
|
||||
var fileServer []*http.Server
|
||||
var (
|
||||
LocalServer []*net.TCPListener
|
||||
udpConn net.Conn
|
||||
muxSession *nps_mux.Mux
|
||||
fileServer []*http.Server
|
||||
p2pNetBridge *p2pBridge
|
||||
lock sync.RWMutex
|
||||
udpConnStatus bool
|
||||
)
|
||||
|
||||
type p2pBridge struct {
|
||||
}
|
||||
|
||||
func (p2pBridge *p2pBridge) SendLinkInfo(clientId int, link *conn.Link, t *file.Tunnel) (target net.Conn, err error) {
|
||||
for i := 0; muxSession == nil; i++ {
|
||||
if i >= 20 {
|
||||
err = errors.New("p2pBridge:too many times to get muxSession")
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
runtime.Gosched() // waiting for another goroutine establish the mux connection
|
||||
}
|
||||
nowConn, err := muxSession.NewConn()
|
||||
if err != nil {
|
||||
udpConn = nil
|
||||
return nil, err
|
||||
}
|
||||
if _, err := conn.NewConn(nowConn).SendInfo(link, ""); err != nil {
|
||||
udpConnStatus = false
|
||||
return nil, err
|
||||
}
|
||||
return nowConn, nil
|
||||
}
|
||||
|
||||
func CloseLocalServer() {
|
||||
for _, v := range LocalServer {
|
||||
@@ -39,37 +73,85 @@ func startLocalFileServer(config *config.CommonConfig, t *file.Tunnel, vkey stri
|
||||
}
|
||||
logs.Info("start local file system, local path %s, strip prefix %s ,remote port %s ", t.LocalPath, t.StripPre, t.Ports)
|
||||
fileServer = append(fileServer, srv)
|
||||
listener := mux.NewMux(remoteConn.Conn, common.CONN_TCP)
|
||||
logs.Warn(srv.Serve(listener))
|
||||
listener := nps_mux.NewMux(remoteConn.Conn, common.CONN_TCP, config.DisconnectTime)
|
||||
logs.Error(srv.Serve(listener))
|
||||
}
|
||||
|
||||
func StartLocalServer(l *config.LocalServer, config *config.CommonConfig) error {
|
||||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP("0.0.0.0"), l.Port, ""})
|
||||
if err != nil {
|
||||
logs.Error("local listener startup failed port %d, error %s", l.Port, err.Error())
|
||||
return err
|
||||
if l.Type != "secret" {
|
||||
go handleUdpMonitor(config, l)
|
||||
}
|
||||
LocalServer = append(LocalServer, listener)
|
||||
logs.Info("successful start-up of local monitoring, port", l.Port)
|
||||
for {
|
||||
c, err := listener.AcceptTCP()
|
||||
task := &file.Tunnel{
|
||||
Port: l.Port,
|
||||
ServerIp: "0.0.0.0",
|
||||
Status: true,
|
||||
Client: &file.Client{
|
||||
Cnf: &file.Config{
|
||||
U: "",
|
||||
P: "",
|
||||
Compress: config.Client.Cnf.Compress,
|
||||
},
|
||||
Status: true,
|
||||
RateLimit: 0,
|
||||
Flow: &file.Flow{},
|
||||
},
|
||||
Flow: &file.Flow{},
|
||||
Target: &file.Target{},
|
||||
}
|
||||
switch l.Type {
|
||||
case "p2ps":
|
||||
logs.Info("successful start-up of local socks5 monitoring, port", l.Port)
|
||||
return proxy.NewSock5ModeServer(p2pNetBridge, task).Start()
|
||||
case "p2pt":
|
||||
logs.Info("successful start-up of local tcp trans monitoring, port", l.Port)
|
||||
return proxy.NewTunnelModeServer(proxy.HandleTrans, p2pNetBridge, task).Start()
|
||||
case "p2p", "secret":
|
||||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP("0.0.0.0"), l.Port, ""})
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "use of closed network connection") {
|
||||
break
|
||||
logs.Error("local listener startup failed port %d, error %s", l.Port, err.Error())
|
||||
return err
|
||||
}
|
||||
LocalServer = append(LocalServer, listener)
|
||||
logs.Info("successful start-up of local tcp monitoring, port", l.Port)
|
||||
conn.Accept(listener, func(c net.Conn) {
|
||||
logs.Trace("new %s connection", l.Type)
|
||||
if l.Type == "secret" {
|
||||
handleSecret(c, config, l)
|
||||
} else if l.Type == "p2p" {
|
||||
handleP2PVisitor(c, config, l)
|
||||
}
|
||||
logs.Info(err)
|
||||
continue
|
||||
}
|
||||
if l.Type == "secret" {
|
||||
go processSecret(c, config, l)
|
||||
} else {
|
||||
go processP2P(c, config, l)
|
||||
}
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func processSecret(localTcpConn net.Conn, config *config.CommonConfig, l *config.LocalServer) {
|
||||
func handleUdpMonitor(config *config.CommonConfig, l *config.LocalServer) {
|
||||
ticker := time.NewTicker(time.Second * 1)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if !udpConnStatus {
|
||||
udpConn = nil
|
||||
tmpConn, err := common.GetLocalUdpAddr()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
logs.Notice("try to connect to the server", i+1)
|
||||
newUdpConn(tmpConn.LocalAddr().String(), config, l)
|
||||
if udpConn != nil {
|
||||
udpConnStatus = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleSecret(localTcpConn net.Conn, config *config.CommonConfig, l *config.LocalServer) {
|
||||
remoteConn, err := NewConn(config.Tp, config.VKey, config.Server, common.WORK_SECRET, config.ProxyUrl)
|
||||
if err != nil {
|
||||
logs.Error("Local connection server failed ", err.Error())
|
||||
@@ -79,31 +161,30 @@ func processSecret(localTcpConn net.Conn, config *config.CommonConfig, l *config
|
||||
logs.Error("Local connection server failed ", err.Error())
|
||||
return
|
||||
}
|
||||
conn.CopyWaitGroup(remoteConn.Conn, localTcpConn, false, false, nil, nil, false)
|
||||
conn.CopyWaitGroup(remoteConn.Conn, localTcpConn, false, false, nil, nil, false, nil, nil, nil)
|
||||
}
|
||||
|
||||
func processP2P(localTcpConn net.Conn, config *config.CommonConfig, l *config.LocalServer) {
|
||||
func handleP2PVisitor(localTcpConn net.Conn, config *config.CommonConfig, l *config.LocalServer) {
|
||||
if udpConn == nil {
|
||||
newUdpConn(config, l)
|
||||
if udpConn == nil {
|
||||
return
|
||||
}
|
||||
muxSession = mux.NewMux(udpConn, "kcp")
|
||||
}
|
||||
nowConn, err := muxSession.NewConn()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
logs.Notice("new conn, P2P can not penetrate successfully, traffic will be transferred through the server")
|
||||
handleSecret(localTcpConn, config, l)
|
||||
return
|
||||
}
|
||||
link := conn.NewLink(common.CONN_TCP, l.Target, config.Cnf.Crypt, config.Cnf.Compress, localTcpConn.LocalAddr().String())
|
||||
if _, err := conn.NewConn(nowConn).SendLinkInfo(link); err != nil {
|
||||
logs.Trace("start trying to connect with the server")
|
||||
//TODO just support compress now because there is not tls file in client packages
|
||||
link := conn.NewLink(common.CONN_TCP, l.Target, false, config.Client.Cnf.Compress, localTcpConn.LocalAddr().String(), false, "")
|
||||
if target, err := p2pNetBridge.SendLinkInfo(0, link, nil); err != nil {
|
||||
logs.Error(err)
|
||||
udpConnStatus = false
|
||||
return
|
||||
} else {
|
||||
conn.CopyWaitGroup(target, localTcpConn, false, config.Client.Cnf.Compress, nil, nil, false, nil, nil, nil)
|
||||
}
|
||||
conn.CopyWaitGroup(nowConn, localTcpConn, config.Cnf.Crypt, config.Cnf.Compress, nil, nil, false)
|
||||
}
|
||||
|
||||
func newUdpConn(config *config.CommonConfig, l *config.LocalServer) {
|
||||
func newUdpConn(localAddr string, config *config.CommonConfig, l *config.LocalServer) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
remoteConn, err := NewConn(config.Tp, config.VKey, config.Server, common.WORK_P2P, config.ProxyUrl)
|
||||
if err != nil {
|
||||
logs.Error("Local connection server failed ", err.Error())
|
||||
@@ -119,49 +200,20 @@ func newUdpConn(config *config.CommonConfig, l *config.LocalServer) {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//与服务端udp建立连接
|
||||
tmpConn, err := common.GetLocalUdpAddr()
|
||||
if err != nil {
|
||||
var localConn net.PacketConn
|
||||
var remoteAddress string
|
||||
if remoteAddress, localConn, err = handleP2PUdp(localAddr, string(rAddr), crypt.Md5(l.Password), common.WORK_P2P_VISITOR); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
udpTunnel, err := kcp.NewConn(remoteAddress, nil, 150, 3, localConn)
|
||||
if err != nil || udpTunnel == nil {
|
||||
logs.Warn(err)
|
||||
return
|
||||
}
|
||||
//与服务端建立udp连接
|
||||
localAddr, _ := net.ResolveUDPAddr("udp", tmpConn.LocalAddr().String())
|
||||
localConn, err := net.ListenUDP("udp", localAddr)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
localKcpConn, err := kcp.NewConn(string(rAddr), nil, 150, 3, localConn)
|
||||
conn.SetUdpSession(localKcpConn)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//写入密钥、provider身份
|
||||
if _, err := localKcpConn.Write([]byte(crypt.Md5(l.Password))); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
if _, err := localKcpConn.Write([]byte(common.WORK_P2P_VISITOR)); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
//接收服务端传的visitor地址
|
||||
if b, err := conn.NewConn(localKcpConn).GetShortLenContent(); err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
} else {
|
||||
//关闭与服务端连接
|
||||
localConn.Close()
|
||||
//建立新的连接
|
||||
localConn, err = net.ListenUDP("udp", localAddr)
|
||||
udpTunnel, err := kcp.NewConn(string(b), nil, 150, 3, localConn)
|
||||
if err != nil || udpTunnel == nil {
|
||||
logs.Warn(err)
|
||||
return
|
||||
}
|
||||
conn.SetUdpSession(udpTunnel)
|
||||
udpConn = udpTunnel
|
||||
}
|
||||
logs.Trace("successful create a connection with server", remoteAddress)
|
||||
conn.SetUdpSession(udpTunnel)
|
||||
udpConn = udpTunnel
|
||||
muxSession = nps_mux.NewMux(udpConn, "kcp", config.DisconnectTime)
|
||||
p2pNetBridge = &p2pBridge{}
|
||||
}
|
||||
|
||||
+2
-1
@@ -2,9 +2,10 @@ package client
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
)
|
||||
|
||||
func RegisterLocalIp(server string, vKey string, tp string, proxyUrl string, hour int) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# 编译输出
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# 依赖包
|
||||
node_modules/
|
||||
vendor/
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# 系统文件
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# 构建临时文件
|
||||
*.tmp
|
||||
*.syso
|
||||
dist/
|
||||
|
||||
# wails3 构建输出
|
||||
bin/
|
||||
|
||||
# wails3 task 缓存
|
||||
.task/
|
||||
|
||||
# NSIS 打包产物(WebView2 bootstrapper / 安装器)
|
||||
build/windows/nsis/*.exe
|
||||
@@ -0,0 +1,133 @@
|
||||
# NPS 客户端 GUI (Wails v3 版本)
|
||||
|
||||
基于 [Wails v3](https://v3.wails.io/)(beta)构建的 NPS 客户端图形界面。
|
||||
|
||||
## 快捷命令格式
|
||||
|
||||
快捷命令使用 Base64 编码,解码后的格式为:
|
||||
```
|
||||
nps:name|addr|key|tls
|
||||
```
|
||||
|
||||
示例:
|
||||
```
|
||||
nps:MyServer|127.0.0.1:8024|mykey123|false
|
||||
```
|
||||
|
||||
编码后的 Base64:
|
||||
```
|
||||
bnBzOk15U2VydmVyfDEyNy4wLjAuMTo4MDI0fG15a2V5MTIzfGZhbHNl
|
||||
```
|
||||
|
||||
## 前置要求
|
||||
|
||||
- Go 1.25+(wails v3 最低要求)
|
||||
- Node.js 16+
|
||||
- Yarn
|
||||
- Wails v3 CLI(wails3)
|
||||
|
||||
安装 Wails CLI:
|
||||
|
||||
```bash
|
||||
go install github.com/wailsapp/wails/v3/cmd/wails3@v3.0.0-beta.12
|
||||
```
|
||||
|
||||
## 启动 / 调试
|
||||
|
||||
### 开发模式(热重载)
|
||||
|
||||
```bash
|
||||
cd cmd/npc/npc-gui
|
||||
|
||||
# 启动开发模式:自动执行前端依赖安装、bindings 生成、yarn build:dev、
|
||||
# Go 编译并运行应用(无需手动 yarn build)
|
||||
# Vite 端口默认为 9245,自定义端口用 -port(如 -port 34115)
|
||||
wails3 dev
|
||||
```
|
||||
|
||||
### 构建
|
||||
|
||||
```bash
|
||||
cd cmd/npc/npc-gui
|
||||
|
||||
# 构建当前平台(前端构建 + bindings 生成 + Go 编译自动完成)
|
||||
wails3 build --tags npcgui
|
||||
```
|
||||
|
||||
产物输出到 `bin/` 目录(如 Windows 为 `bin/npc-gui.exe`)。
|
||||
|
||||
### 跨平台构建
|
||||
|
||||
通过 `GOOS`/`GOARCH` 环境变量指定目标平台:
|
||||
|
||||
```bash
|
||||
# Windows amd64(在非 Windows 上需 Docker 镜像 wails-cross 支持 CGO 交叉编译)
|
||||
GOOS=windows GOARCH=amd64 wails3 build --tags npcgui
|
||||
|
||||
# macOS
|
||||
GOOS=darwin GOARCH=arm64 wails3 build --tags npcgui
|
||||
|
||||
# Linux(需要 libgtk-3-dev / libwebkit2gtk-4.1-dev)
|
||||
GOOS=linux GOARCH=amd64 wails3 build --tags npcgui
|
||||
```
|
||||
|
||||
### 打包安装包
|
||||
|
||||
```bash
|
||||
# Windows NSIS 安装器(需要 makensis)
|
||||
wails3 package
|
||||
|
||||
# 或指定安装范围(user = 免 UAC 按用户安装)
|
||||
wails3 package INSTALL_SCOPE=user
|
||||
```
|
||||
|
||||
### 手动生成前端绑定
|
||||
|
||||
Go 侧绑定方法签名变更后,重新生成前端 bindings:
|
||||
|
||||
```bash
|
||||
cd cmd/npc/npc-gui
|
||||
wails3 generate bindings
|
||||
```
|
||||
|
||||
生成结果位于 `frontend/bindings/`。
|
||||
|
||||
### 常用任务
|
||||
|
||||
```bash
|
||||
wails3 task --list # 列出所有 Taskfile 任务
|
||||
wails3 task build # 等价于 wails3 build
|
||||
wails3 task run # 运行已构建的产物
|
||||
wails3 update build-assets # 刷新 build/ 目录构建资产
|
||||
```
|
||||
|
||||
## 项目结构(v3)
|
||||
|
||||
```
|
||||
cmd/npc/npc-gui/
|
||||
├── Taskfile.yml # 根任务定义(APP_NAME、包管理器、端口)
|
||||
├── main.go # 应用入口(application.New + 窗口 + 服务注册)
|
||||
├── app_bindings.go # App 服务(前端可调用的绑定方法)
|
||||
├── tray.go # 系统托盘(v3 内置 SystemTray)
|
||||
├── build/
|
||||
│ ├── config.yml # 应用信息、版本、dev 模式配置
|
||||
│ ├── Taskfile.yml # 公共任务(前端安装/构建、bindings 生成、图标)
|
||||
│ └── windows|darwin|linux/ # 各平台构建资产与打包模板
|
||||
└── frontend/
|
||||
├── bindings/ # wails3 generate bindings 生成(已提交)
|
||||
├── src/App.vue # 主界面(import { App as AppAPI } from '../bindings/npc-gui/index.js')
|
||||
└── dist/ # 前端构建产物(embed 进二进制)
|
||||
```
|
||||
|
||||
## 构建标签
|
||||
|
||||
- `npcgui`:GUI 客户端构建必须传入(排除 `server/proxy/tcp.go` 中的服务端隧道实现,见 `server/proxy/tcp_npcgui.go` 占位实现)
|
||||
|
||||
## 配置存储
|
||||
|
||||
连接配置自动保存在以下位置:
|
||||
- Windows: `%APPDATA%\npc\npc_data.json`
|
||||
- Linux: `~/.config/npc/npc_data.json`
|
||||
- macOS: `~/Library/Application Support/npc/npc_data.json`
|
||||
|
||||
客户端日志默认保存在 `<配置目录>/npc/logs/`,可在设置中修改日志目录。
|
||||
@@ -0,0 +1,37 @@
|
||||
version: '3'
|
||||
|
||||
vars:
|
||||
APP_NAME: "npc-gui"
|
||||
BIN_DIR: "bin"
|
||||
PACKAGE_MANAGER: "yarn"
|
||||
VITE_PORT: '{{.WAILS_VITE_PORT | default 34115}}'
|
||||
# Target OS for build/package/run. Defaults to the host OS, and is overridden
|
||||
# by `wails3 build GOOS=...` (or the GOOS env var) for cross-compilation.
|
||||
GOOS: '{{.GOOS | default OS}}'
|
||||
|
||||
includes:
|
||||
common: ./build/Taskfile.yml
|
||||
windows: ./build/windows/Taskfile.yml
|
||||
darwin: ./build/darwin/Taskfile.yml
|
||||
linux: ./build/linux/Taskfile.yml
|
||||
|
||||
tasks:
|
||||
build:
|
||||
summary: Builds the application
|
||||
cmds:
|
||||
- task: "{{.GOOS}}:build"
|
||||
|
||||
package:
|
||||
summary: Packages a production build of the application
|
||||
cmds:
|
||||
- task: "{{.GOOS}}:package"
|
||||
|
||||
run:
|
||||
summary: Runs the application
|
||||
cmds:
|
||||
- task: "{{.GOOS}}:run"
|
||||
|
||||
dev:
|
||||
summary: Runs the application in development mode
|
||||
cmds:
|
||||
- wails3 dev -config ./build/config.yml -port {{.VITE_PORT}}
|
||||
@@ -0,0 +1,746 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/client"
|
||||
"ehang.io/nps/lib/version"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
app *application.App
|
||||
window *application.WebviewWindow
|
||||
tray *application.SystemTray
|
||||
}
|
||||
|
||||
// ShortClient 与前端结构对应
|
||||
type ShortClient struct {
|
||||
Name string `json:"name"`
|
||||
Addr string `json:"addr"`
|
||||
Key string `json:"key"`
|
||||
TLS bool `json:"tls"`
|
||||
Running bool `json:"running"` // 兼容旧版本,实际用Status
|
||||
Error string `json:"error"` // 连接错误信息
|
||||
Status string `json:"status"` // 连接状态: "stopped", "connecting", "connected"
|
||||
}
|
||||
|
||||
// ConnectionLog 连接日志项
|
||||
type ConnectionLog struct {
|
||||
Timestamp string `json:"timestamp"`
|
||||
Message string `json:"message"`
|
||||
Type string `json:"type"` // "info", "error", "warning", "success"
|
||||
ClientId string `json:"clientId"`
|
||||
}
|
||||
|
||||
var (
|
||||
shortcuts []ShortClient
|
||||
shortcutsMu sync.Mutex
|
||||
|
||||
// 改为用 context 管理内置客户端,而不是外部进程
|
||||
running = make(map[string]context.CancelFunc)
|
||||
clients = make(map[string]*client.TRPClient)
|
||||
clientErrors = make(map[string]string) // 存储客户端连接错误信息
|
||||
clientConnected = make(map[string]bool) // 存储客户端连接状态 (true=connected)
|
||||
clientAttempted = make(map[string]bool) // 存储客户端是否尝试过连接
|
||||
statusMu sync.Mutex // 状态锁
|
||||
runningMu sync.Mutex
|
||||
disconnectTimeout = 60
|
||||
connType = "tcp"
|
||||
)
|
||||
|
||||
func NewApp(app *application.App, window *application.WebviewWindow) *App {
|
||||
return &App{app: app, window: window}
|
||||
}
|
||||
|
||||
func (a *App) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
|
||||
// 初始化日志系统:应用日志走 slog,客户端日志走内存缓冲 + JSON 文件
|
||||
initAppLogger()
|
||||
|
||||
// 同步开机启动状态:检查配置与实际注册表是否一致
|
||||
go func() {
|
||||
store, err := loadPersistentStore()
|
||||
if err == nil {
|
||||
actualEnabled := isStartupEnabled()
|
||||
if store.Settings.StartupEnabled && !actualEnabled {
|
||||
// 配置说启用,但实际未启用,则启用之
|
||||
slog.Info("同步开机启动状态:启用")
|
||||
if err := enableStartup(); err != nil {
|
||||
slog.Error("同步开机启动失败", "err", err)
|
||||
}
|
||||
} else if !store.Settings.StartupEnabled && actualEnabled {
|
||||
// 配置说禁用,但实际已启用,则禁用之
|
||||
slog.Info("同步开机启动状态:禁用")
|
||||
if err := disableStartup(); err != nil {
|
||||
slog.Error("同步开机启动失败", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
a.startTray()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) ServiceShutdown() error {
|
||||
setQuitting()
|
||||
closeAllLogStores()
|
||||
if a.tray != nil {
|
||||
a.tray.Destroy()
|
||||
a.tray = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getLogsPath() string {
|
||||
// 尝试从配置中读取用户设置的日志目录
|
||||
store, err := loadPersistentStore()
|
||||
if err == nil && store.Settings.LogDir != "" {
|
||||
// 确保目录存在
|
||||
_ = os.MkdirAll(store.Settings.LogDir, 0o755)
|
||||
return store.Settings.LogDir
|
||||
}
|
||||
|
||||
// 如果没有配置或读取失败,使用默认路径
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
dir = "."
|
||||
}
|
||||
cfgDir := filepath.Join(dir, "npc")
|
||||
_ = os.MkdirAll(cfgDir, 0o755)
|
||||
logsDir := filepath.Join(cfgDir, "logs")
|
||||
_ = os.MkdirAll(logsDir, 0o755)
|
||||
return logsDir
|
||||
}
|
||||
|
||||
// getClientLogFilePath 获取客户端的独立日志文件路径
|
||||
func getClientLogFilePath(vkey string) string {
|
||||
logsDir := getLogsPath()
|
||||
// 如果传入的是包含 addr|vkey 的 id,则提取最后一段作为 vkey
|
||||
if strings.Contains(vkey, "|") {
|
||||
parts := strings.Split(vkey, "|")
|
||||
vkey = parts[len(parts)-1]
|
||||
}
|
||||
// 进一步替换可能在 vkey 中出现的不适合作为文件名的字符
|
||||
vkey = strings.ReplaceAll(vkey, ":", "-")
|
||||
vkey = strings.ReplaceAll(vkey, "\\", "-")
|
||||
vkey = strings.ReplaceAll(vkey, "/", "-")
|
||||
return filepath.Join(logsDir, fmt.Sprintf("npc-client-%s.log", vkey))
|
||||
}
|
||||
|
||||
// 持久化文件结构(向后兼容旧的仅数组格式)
|
||||
type GuiSettings struct {
|
||||
StartupEnabled bool `json:"startupEnabled"`
|
||||
RememberClientState bool `json:"rememberClientState"`
|
||||
LogDir string `json:"logDir"`
|
||||
ThemeMode string `json:"themeMode"` // "auto", "light", "dark"
|
||||
}
|
||||
|
||||
type PersistentStore struct {
|
||||
Shortcuts []ShortClient `json:"shortcuts"`
|
||||
Settings GuiSettings `json:"settings,omitempty"`
|
||||
ClientStates map[string]string `json:"clientStates,omitempty"`
|
||||
}
|
||||
|
||||
func getStoragePath() string {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
dir = "."
|
||||
}
|
||||
cfgDir := filepath.Join(dir, "npc")
|
||||
_ = os.MkdirAll(cfgDir, 0o755)
|
||||
return filepath.Join(cfgDir, "npc_data.json")
|
||||
}
|
||||
|
||||
// 读取持久化 store,向后兼容:如果是数组则解析为 shortcuts
|
||||
func loadPersistentStore() (PersistentStore, error) {
|
||||
p := getStoragePath()
|
||||
b, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
return PersistentStore{}, err
|
||||
}
|
||||
|
||||
// 尝试解析为对象结构
|
||||
var store PersistentStore
|
||||
if err := json.Unmarshal(b, &store); err == nil {
|
||||
// 如果文件是对象但没有 shortcuts 字段,ensure empty slice
|
||||
if store.Shortcuts == nil {
|
||||
store.Shortcuts = []ShortClient{}
|
||||
}
|
||||
return store, nil
|
||||
}
|
||||
|
||||
// 兼容旧格式:直接是 ShortClient 数组
|
||||
var arr []ShortClient
|
||||
if err := json.Unmarshal(b, &arr); err == nil {
|
||||
return PersistentStore{Shortcuts: arr}, nil
|
||||
}
|
||||
|
||||
return PersistentStore{}, errors.New("invalid storage format")
|
||||
}
|
||||
|
||||
// 保存整个 store,保持 settings 与 clientStates
|
||||
func savePersistentStoreLocked(store PersistentStore) {
|
||||
p := getStoragePath()
|
||||
if data, err := json.MarshalIndent(store, "", " "); err == nil {
|
||||
_ = os.WriteFile(p, data, 0o644)
|
||||
}
|
||||
}
|
||||
|
||||
func loadShortcuts() {
|
||||
shortcutsMu.Lock()
|
||||
defer shortcutsMu.Unlock()
|
||||
p := getStoragePath()
|
||||
b, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
shortcuts = []ShortClient{}
|
||||
return
|
||||
}
|
||||
|
||||
// 先尝试解析为对象格式
|
||||
var store PersistentStore
|
||||
if err := json.Unmarshal(b, &store); err == nil {
|
||||
shortcuts = store.Shortcuts
|
||||
if shortcuts == nil {
|
||||
shortcuts = []ShortClient{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 兼容旧格式:直接是 ShortClient 数组
|
||||
var s []ShortClient
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
shortcuts = []ShortClient{}
|
||||
return
|
||||
}
|
||||
shortcuts = s
|
||||
}
|
||||
|
||||
func saveShortcuts() {
|
||||
shortcutsMu.Lock()
|
||||
defer shortcutsMu.Unlock()
|
||||
saveShortcutsLocked()
|
||||
}
|
||||
|
||||
func saveShortcutsLocked() {
|
||||
p := getStoragePath()
|
||||
|
||||
var store PersistentStore
|
||||
// 尝试读取已有 store 以保留 settings/clientStates
|
||||
if b, err := os.ReadFile(p); err == nil {
|
||||
_ = json.Unmarshal(b, &store) // ignore errors, we'll overwrite shortcuts
|
||||
}
|
||||
store.Shortcuts = shortcuts
|
||||
savePersistentStoreLocked(store)
|
||||
}
|
||||
|
||||
// 以下为对 settings 与 clientStates 的访问方法(供前端调用)
|
||||
func (a *App) GetGuiSettings() (GuiSettings, error) {
|
||||
store, err := loadPersistentStore()
|
||||
if err != nil {
|
||||
// 返回默认值
|
||||
return GuiSettings{StartupEnabled: true, RememberClientState: true, LogDir: getLogsPath(), ThemeMode: "auto"}, nil
|
||||
}
|
||||
// 合并默认值
|
||||
s := store.Settings
|
||||
// 如果 LogDir 为空,使用默认路径
|
||||
if s.LogDir == "" {
|
||||
s.LogDir = getLogsPath()
|
||||
}
|
||||
// 如果 ThemeMode 为空,使用默认值 "auto"
|
||||
if s.ThemeMode == "" {
|
||||
s.ThemeMode = "auto"
|
||||
}
|
||||
// 检测是否为首次使用(配置为空),如果是则使用默认值 true
|
||||
// 注意:这里无法区分用户主动设置为 false 还是从未设置过,所以采用保守策略
|
||||
// 只有当配置文件存在但 Settings 字段完全为空时才认为是首次使用
|
||||
isFirstTime := !s.StartupEnabled && !s.RememberClientState
|
||||
if isFirstTime {
|
||||
// 首次使用,设置为默认值 true
|
||||
s.StartupEnabled = true
|
||||
s.RememberClientState = true
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (a *App) SaveGuiSettings(s GuiSettings) error {
|
||||
shortcutsMu.Lock()
|
||||
defer shortcutsMu.Unlock()
|
||||
store, _ := loadPersistentStore()
|
||||
|
||||
// 保存之前检查开机启动设置是否有变化
|
||||
oldStartupEnabled := store.Settings.StartupEnabled
|
||||
|
||||
store.Settings = s
|
||||
// 如果 LogDir 为空,填充默认
|
||||
if store.Settings.LogDir == "" {
|
||||
store.Settings.LogDir = getLogsPath()
|
||||
}
|
||||
savePersistentStoreLocked(store)
|
||||
|
||||
// 如果开机启动设置发生变化,应用到系统
|
||||
if oldStartupEnabled != s.StartupEnabled {
|
||||
if s.StartupEnabled {
|
||||
if err := enableStartup(); err != nil {
|
||||
slog.Error("启用开机启动失败", "err", err)
|
||||
return fmt.Errorf("启用开机启动失败: %v", err)
|
||||
}
|
||||
slog.Info("已启用开机启动")
|
||||
} else {
|
||||
if err := disableStartup(); err != nil {
|
||||
slog.Error("禁用开机启动失败", "err", err)
|
||||
return fmt.Errorf("禁用开机启动失败: %v", err)
|
||||
}
|
||||
slog.Info("已禁用开机启动")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetClientStates() (map[string]string, error) {
|
||||
store, err := loadPersistentStore()
|
||||
if err != nil {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
if store.ClientStates == nil {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
return store.ClientStates, nil
|
||||
}
|
||||
|
||||
func (a *App) SaveClientStates(m map[string]string) error {
|
||||
shortcutsMu.Lock()
|
||||
defer shortcutsMu.Unlock()
|
||||
store, _ := loadPersistentStore()
|
||||
store.ClientStates = m
|
||||
savePersistentStoreLocked(store)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDefaultLogDir 获取默认日志目录路径
|
||||
func (a *App) GetDefaultLogDir() string {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
dir = "."
|
||||
}
|
||||
cfgDir := filepath.Join(dir, "npc")
|
||||
logsDir := filepath.Join(cfgDir, "logs")
|
||||
return logsDir
|
||||
}
|
||||
|
||||
// SelectDirectory 打开目录选择对话框
|
||||
func (a *App) SelectDirectory() (string, error) {
|
||||
slog.Info("SelectDirectory 被调用")
|
||||
|
||||
// 获取当前设置的日志目录作为默认目录
|
||||
defaultDir := ""
|
||||
store, err := loadPersistentStore()
|
||||
if err == nil && store.Settings.LogDir != "" {
|
||||
defaultDir = store.Settings.LogDir
|
||||
}
|
||||
|
||||
slog.Info("默认目录", "dir", defaultDir)
|
||||
|
||||
// 打开目录选择对话框
|
||||
dialog := a.app.Dialog.OpenFileWithOptions(&application.OpenFileDialogOptions{
|
||||
CanChooseDirectories: true,
|
||||
CanChooseFiles: false,
|
||||
Title: "选择日志目录",
|
||||
Directory: defaultDir,
|
||||
})
|
||||
selectedDir, err := dialog.PromptForSingleSelection()
|
||||
|
||||
if err != nil {
|
||||
slog.Error("打开目录选择对话框失败", "err", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
slog.Info("用户选择的目录", "dir", selectedDir)
|
||||
return selectedDir, nil
|
||||
}
|
||||
|
||||
// GetAppVersion 返回来自 lib/version 的版本号
|
||||
func (a *App) GetAppVersion() string {
|
||||
return version.VERSION
|
||||
}
|
||||
|
||||
func addShortcut(sc ShortClient) {
|
||||
shortcutsMu.Lock()
|
||||
shortcuts = append(shortcuts, sc)
|
||||
shortcutsMu.Unlock()
|
||||
saveShortcuts()
|
||||
}
|
||||
|
||||
func findShortcutIndex(name, addr, key string) int {
|
||||
shortcutsMu.Lock()
|
||||
defer shortcutsMu.Unlock()
|
||||
for i, it := range shortcuts {
|
||||
if it.Name == name && it.Addr == addr && it.Key == key {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (a *App) AddShortcut(arg string) error {
|
||||
// accept a JSON string from frontend
|
||||
var sc ShortClient
|
||||
if err := json.Unmarshal([]byte(arg), &sc); err != nil {
|
||||
return err
|
||||
}
|
||||
addShortcut(sc)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) AddShortcutFromBase64(s string) error {
|
||||
if s == "" {
|
||||
return errors.New("无效的启动命令")
|
||||
}
|
||||
b, err := base64.StdEncoding.DecodeString(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
payload := string(b)
|
||||
if !strings.HasPrefix(payload, "nps:") {
|
||||
return errors.New("无效的启动命令")
|
||||
}
|
||||
payload = payload[len("nps:"):]
|
||||
parts := strings.Split(payload, "|")
|
||||
if len(parts) != 4 {
|
||||
return errors.New("无效的启动命令")
|
||||
}
|
||||
tls := false
|
||||
if parts[3] == "true" {
|
||||
tls = true
|
||||
}
|
||||
sc := ShortClient{Name: parts[0], Addr: parts[1], Key: parts[2], TLS: tls}
|
||||
|
||||
// Check if shortcut already exists
|
||||
shortcutsMu.Lock()
|
||||
for _, existing := range shortcuts {
|
||||
if existing.Addr == sc.Addr && existing.Key == sc.Key {
|
||||
shortcutsMu.Unlock()
|
||||
return errors.New("该客户端已被添加")
|
||||
}
|
||||
}
|
||||
shortcutsMu.Unlock()
|
||||
|
||||
addShortcut(sc)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetShortcuts() ([]ShortClient, error) {
|
||||
loadShortcuts()
|
||||
shortcutsMu.Lock()
|
||||
defer shortcutsMu.Unlock()
|
||||
// populate running state
|
||||
res := make([]ShortClient, len(shortcuts))
|
||||
runningMu.Lock()
|
||||
statusMu.Lock()
|
||||
defer runningMu.Unlock()
|
||||
defer statusMu.Unlock()
|
||||
|
||||
for i, sc := range shortcuts {
|
||||
key := sc.Addr + "|" + sc.Key
|
||||
sc.Running = false
|
||||
sc.Status = "stopped"
|
||||
sc.Error = ""
|
||||
|
||||
// 检查客户端是否在 running map 中
|
||||
if _, ok := running[key]; ok {
|
||||
// 客户端正在运行(或重连中)
|
||||
if isConnected, ok := clientConnected[key]; ok && isConnected {
|
||||
// 连接成功
|
||||
sc.Status = "connected"
|
||||
sc.Running = true
|
||||
} else if _, attempted := clientAttempted[key]; attempted {
|
||||
// 尝试过连接但失败,显示为"连接中"(正在重连)
|
||||
sc.Status = "connecting"
|
||||
if errMsg, ok := clientErrors[key]; ok && errMsg != "" {
|
||||
sc.Error = errMsg
|
||||
}
|
||||
} else {
|
||||
// 刚启动,还未尝试连接
|
||||
sc.Status = "connecting"
|
||||
}
|
||||
}
|
||||
res[i] = sc
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (a *App) RemoveShortcut(name, addr, key string) error {
|
||||
// stop if running
|
||||
id := addr + "|" + key
|
||||
runningMu.Lock()
|
||||
if cancel, ok := running[id]; ok {
|
||||
cancel()
|
||||
delete(running, id)
|
||||
// 也要关闭客户端
|
||||
if rpcClient, ok := clients[id]; ok {
|
||||
rpcClient.Close()
|
||||
delete(clients, id)
|
||||
}
|
||||
}
|
||||
statusMu.Lock()
|
||||
delete(clientErrors, id)
|
||||
delete(clientConnected, id)
|
||||
delete(clientAttempted, id)
|
||||
statusMu.Unlock()
|
||||
runningMu.Unlock()
|
||||
|
||||
// remove from slice
|
||||
shortcutsMu.Lock()
|
||||
defer shortcutsMu.Unlock()
|
||||
idx := -1
|
||||
for i, it := range shortcuts {
|
||||
if it.Name == name && it.Addr == addr && it.Key == key {
|
||||
idx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if idx == -1 {
|
||||
return nil
|
||||
}
|
||||
shortcuts = append(shortcuts[:idx], shortcuts[idx+1:]...)
|
||||
saveShortcutsLocked()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) ToggleClient(name, addr, key string, tls bool, runningState bool) error {
|
||||
id := addr + "|" + key
|
||||
slog.Info("ToggleClient called", "name", name, "addr", addr, "tls", tls, "runningState", runningState)
|
||||
runningMu.Lock()
|
||||
defer runningMu.Unlock()
|
||||
if runningState {
|
||||
// start npc client in goroutine
|
||||
if _, ok := running[id]; !ok {
|
||||
slog.Info("Starting NPC client", "id", id)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
running[id] = cancel
|
||||
// 清除之前的状态
|
||||
statusMu.Lock()
|
||||
delete(clientErrors, id)
|
||||
clientConnected[id] = false
|
||||
delete(clientAttempted, id)
|
||||
statusMu.Unlock()
|
||||
go startNpcClientWithContext(ctx, id, addr, key, tls)
|
||||
} else {
|
||||
slog.Info("Client already running", "id", id)
|
||||
}
|
||||
} else {
|
||||
// stop the client
|
||||
if cancel, ok := running[id]; ok {
|
||||
slog.Info("Stopping NPC client", "id", id)
|
||||
cancel()
|
||||
delete(running, id)
|
||||
// 清除状态
|
||||
statusMu.Lock()
|
||||
delete(clientErrors, id)
|
||||
delete(clientConnected, id)
|
||||
delete(clientAttempted, id)
|
||||
statusMu.Unlock()
|
||||
// 也要关闭客户端
|
||||
if rpcClient, ok := clients[id]; ok {
|
||||
rpcClient.Close()
|
||||
delete(clients, id)
|
||||
}
|
||||
} else {
|
||||
slog.Info("Client not running, nothing to stop", "id", id)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// startNpcClient 在 goroutine 中启动 npc 客户端(内置,不是外部进程)
|
||||
func startNpcClient(id, server, vkey string, tlsEnable bool) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
runningMu.Lock()
|
||||
running[id] = cancel
|
||||
runningMu.Unlock()
|
||||
|
||||
startNpcClientWithContext(ctx, id, server, vkey, tlsEnable)
|
||||
}
|
||||
|
||||
// startNpcClientWithContext 在给定的 context 中运行 npc 客户端
|
||||
func startNpcClientWithContext(ctx context.Context, id, server, vkey string, tlsEnable bool) {
|
||||
// 为该客户端准备日志存储(内存缓冲 + 独立日志文件)
|
||||
store := getClientLogStore(id)
|
||||
clientLogger := &trpcLogger{store: store}
|
||||
|
||||
client.SetTlsEnable(tlsEnable)
|
||||
clientLogger.Info("启动 NPC 客户端: server=%s, vkey=%s, tls=%v", server, vkey, tlsEnable)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
clientLogger.Info("停止 NPC 客户端")
|
||||
statusMu.Lock()
|
||||
delete(clientConnected, id)
|
||||
delete(clientAttempted, id)
|
||||
delete(clientErrors, id)
|
||||
statusMu.Unlock()
|
||||
runningMu.Lock()
|
||||
if rpcClient, ok := clients[id]; ok {
|
||||
rpcClient.Close()
|
||||
delete(clients, id)
|
||||
}
|
||||
runningMu.Unlock()
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
clientLogger.Info("连接服务器")
|
||||
|
||||
// 重置连接状态,准备新的连接尝试
|
||||
statusMu.Lock()
|
||||
clientConnected[id] = false
|
||||
statusMu.Unlock()
|
||||
|
||||
rpcClient := client.NewRPClient(server, vkey, connType, "", nil, disconnectTimeout)
|
||||
|
||||
// 设置客户端的独立 logger
|
||||
rpcClient.SetLogger(clientLogger)
|
||||
|
||||
// 将客户端保存到全局 map
|
||||
runningMu.Lock()
|
||||
clients[id] = rpcClient
|
||||
runningMu.Unlock()
|
||||
|
||||
// 启动连接监听器(每次重连都启动)
|
||||
go monitorFirstConnection(ctx, id, rpcClient)
|
||||
|
||||
// 在后台监听 context 取消事件
|
||||
go func() {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
clientLogger.Info("Context 已取消,关闭客户端")
|
||||
rpcClient.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
rpcClient.Start()
|
||||
|
||||
// 检查 context 是否已取消
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
clientLogger.Info("停止 NPC 客户端")
|
||||
statusMu.Lock()
|
||||
delete(clientConnected, id)
|
||||
delete(clientAttempted, id)
|
||||
delete(clientErrors, id)
|
||||
statusMu.Unlock()
|
||||
runningMu.Lock()
|
||||
if rpcClient, ok := clients[id]; ok {
|
||||
rpcClient.Close()
|
||||
delete(clients, id)
|
||||
}
|
||||
runningMu.Unlock()
|
||||
return
|
||||
case <-time.After(5 * time.Second):
|
||||
// 继续重新连接
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// monitorFirstConnection 监听连接的结果,持续检查连接状态
|
||||
func monitorFirstConnection(ctx context.Context, id string, rpcClient *client.TRPClient) {
|
||||
ticker := time.NewTicker(100 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
initialTimeout := time.After(5 * time.Second)
|
||||
connected := false
|
||||
|
||||
clientLogger := &trpcLogger{store: getClientLogStore(id)}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-initialTimeout:
|
||||
if !connected {
|
||||
statusMu.Lock()
|
||||
clientAttempted[id] = true // 标记为已尝试
|
||||
clientConnected[id] = false
|
||||
clientErrors[id] = "连接服务器失败,正在重新连接..."
|
||||
statusMu.Unlock()
|
||||
clientLogger.Error("连接服务器失败 (timeout),将自动重连")
|
||||
}
|
||||
// 即使超时,也继续监听连接状态变化
|
||||
case <-ticker.C:
|
||||
// 检查连接是否成功
|
||||
isNowConnected := rpcClient.IsConnected()
|
||||
if isNowConnected {
|
||||
if !connected {
|
||||
statusMu.Lock()
|
||||
clientAttempted[id] = true
|
||||
clientConnected[id] = true
|
||||
delete(clientErrors, id)
|
||||
statusMu.Unlock()
|
||||
clientLogger.Info("客户端连接成功")
|
||||
connected = true
|
||||
}
|
||||
} else {
|
||||
// 如果已连接但现在断开,标记为断开状态
|
||||
if connected {
|
||||
statusMu.Lock()
|
||||
clientConnected[id] = false
|
||||
clientErrors[id] = "连接已断开,正在重新连接..."
|
||||
statusMu.Unlock()
|
||||
clientLogger.Warn("客户端连接已断开")
|
||||
connected = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetConnectionLogs 获取指定客户端的连接日志(直接读内存缓冲,无需解析文件)
|
||||
func (a *App) GetConnectionLogs(clientId string) ([]ConnectionLog, error) {
|
||||
return getClientLogStore(clientId).snapshot(), nil
|
||||
}
|
||||
|
||||
// ClearConnectionLogs 清空指定客户端的连接日志(内存缓冲与日志文件)
|
||||
func (a *App) ClearConnectionLogs(clientId string) error {
|
||||
return getClientLogStore(clientId).clear()
|
||||
}
|
||||
|
||||
// getExecutablePath 获取当前可执行文件的完整路径
|
||||
func getExecutablePath() (string, error) {
|
||||
exePath, err := os.Executable()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// 解析符号链接,获取真实路径
|
||||
exePath, err = filepath.EvalSymlinks(exePath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return exePath, nil
|
||||
}
|
||||
|
||||
// enableStartup 启用开机启动(跨平台)
|
||||
func enableStartup() error {
|
||||
return enableStartupImpl()
|
||||
}
|
||||
|
||||
// disableStartup 禁用开机启动(跨平台)
|
||||
func disableStartup() error {
|
||||
return disableStartupImpl()
|
||||
}
|
||||
|
||||
// isStartupEnabled 检查是否已启用开机启动(跨平台)
|
||||
func isStartupEnabled() bool {
|
||||
return isStartupEnabledImpl()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
keep
|
||||
@@ -0,0 +1,398 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
go:mod:tidy:
|
||||
summary: Runs `go mod tidy`
|
||||
internal: true
|
||||
# Universal/multi-arch builds invoke this concurrently from parallel deps;
|
||||
# two `go mod tidy` processes racing on go.mod can corrupt it (#4637).
|
||||
run: once
|
||||
cmds:
|
||||
- go mod tidy
|
||||
|
||||
install:frontend:deps:
|
||||
summary: Install frontend dependencies
|
||||
run: once
|
||||
cmds:
|
||||
- task: install:frontend:deps:{{.PACKAGE_MANAGER}}
|
||||
|
||||
install:frontend:deps:npm:
|
||||
dir: frontend
|
||||
sources:
|
||||
- package.json
|
||||
- package-lock.json
|
||||
generates:
|
||||
- node_modules
|
||||
preconditions:
|
||||
- sh: npm version
|
||||
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
|
||||
cmds:
|
||||
- npm install
|
||||
|
||||
install:frontend:deps:bun:
|
||||
dir: frontend
|
||||
sources:
|
||||
- package.json
|
||||
- bun.lock
|
||||
- bun.lockb
|
||||
generates:
|
||||
- node_modules
|
||||
preconditions:
|
||||
- sh: bun --version
|
||||
msg: "bun not found"
|
||||
cmds:
|
||||
- bun install
|
||||
|
||||
install:frontend:deps:pnpm:
|
||||
dir: frontend
|
||||
sources:
|
||||
- package.json
|
||||
- pnpm-lock.yaml
|
||||
generates:
|
||||
- node_modules
|
||||
preconditions:
|
||||
- sh: pnpm --version
|
||||
msg: "pnpm not found"
|
||||
cmds:
|
||||
- pnpm install
|
||||
|
||||
install:frontend:deps:yarn:
|
||||
dir: frontend
|
||||
sources:
|
||||
- package.json
|
||||
- yarn.lock
|
||||
status:
|
||||
- test -d node_modules || test -f .pnp.cjs
|
||||
preconditions:
|
||||
- sh: yarn --version
|
||||
msg: "yarn not found"
|
||||
cmds:
|
||||
- yarn install
|
||||
|
||||
build:frontend:
|
||||
label: build:frontend (DEV={{.DEV}} RUNNER={{.PACKAGE_MANAGER}})
|
||||
summary: Build the frontend project
|
||||
# darwin:build:universal runs its per-arch builds as parallel deps, each of
|
||||
# which depends on this task. Without run:once the two executions race:
|
||||
# one regenerates frontend/bindings (-clean deletes it first) while the
|
||||
# other's bundler is reading it, failing intermittently with
|
||||
# 'Could not resolve "./bindings/<pkg>"' (#4637).
|
||||
run: once
|
||||
dir: frontend
|
||||
sources:
|
||||
- "**/*"
|
||||
- exclude: node_modules/**/*
|
||||
generates:
|
||||
- dist/**/*
|
||||
deps:
|
||||
- task: install:frontend:deps
|
||||
- task: generate:bindings
|
||||
vars:
|
||||
BUILD_FLAGS:
|
||||
ref: .BUILD_FLAGS
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
cmds:
|
||||
- task: frontend:run
|
||||
vars:
|
||||
SCRIPT: '{{if eq .DEV "true"}}build:dev{{else}}build{{end}}'
|
||||
env:
|
||||
PRODUCTION: '{{if eq .DEV "true"}}false{{else}}true{{end}}'
|
||||
|
||||
frontend:run:
|
||||
summary: Run a frontend script with selected runner
|
||||
cmds:
|
||||
- task: frontend:run:{{.PACKAGE_MANAGER}}
|
||||
vars:
|
||||
SCRIPT: "{{.SCRIPT}}"
|
||||
vars:
|
||||
SCRIPT: "{{.SCRIPT}}"
|
||||
|
||||
frontend:run:npm:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- npm run {{.SCRIPT}} -q
|
||||
vars:
|
||||
SCRIPT: "{{.SCRIPT}}"
|
||||
|
||||
frontend:run:yarn:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- yarn {{.SCRIPT}}
|
||||
vars:
|
||||
SCRIPT: "{{.SCRIPT}}"
|
||||
|
||||
frontend:run:pnpm:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- pnpm run {{.SCRIPT}}
|
||||
vars:
|
||||
SCRIPT: "{{.SCRIPT}}"
|
||||
|
||||
frontend:run:bun:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- bun run {{.SCRIPT}}
|
||||
vars:
|
||||
SCRIPT: "{{.SCRIPT}}"
|
||||
|
||||
frontend:vendor:puppertino:
|
||||
summary: Fetches Puppertino CSS into frontend/public for consistent mobile styling
|
||||
sources:
|
||||
- frontend/public/puppertino/puppertino.css
|
||||
generates:
|
||||
- frontend/public/puppertino/puppertino.css
|
||||
cmds:
|
||||
- |
|
||||
set -euo pipefail
|
||||
mkdir -p frontend/public/puppertino
|
||||
# If bundled Puppertino exists, prefer it. Otherwise, try to fetch, but don't fail build on error.
|
||||
if [ ! -f frontend/public/puppertino/puppertino.css ]; then
|
||||
echo "No bundled Puppertino found. Attempting to fetch from GitHub..."
|
||||
if curl -fsSL https://raw.githubusercontent.com/codedgar/Puppertino/main/dist/css/full.css -o frontend/public/puppertino/puppertino.css; then
|
||||
curl -fsSL https://raw.githubusercontent.com/codedgar/Puppertino/main/LICENSE -o frontend/public/puppertino/LICENSE || true
|
||||
echo "Puppertino CSS downloaded to frontend/public/puppertino/puppertino.css"
|
||||
else
|
||||
echo "Warning: Could not fetch Puppertino CSS. Proceeding without download since template may bundle it."
|
||||
fi
|
||||
else
|
||||
echo "Using bundled Puppertino at frontend/public/puppertino/puppertino.css"
|
||||
fi
|
||||
# Ensure index.html includes Puppertino CSS and button classes
|
||||
INDEX_HTML=frontend/index.html
|
||||
if [ -f "$INDEX_HTML" ]; then
|
||||
if ! grep -q 'href="/puppertino/puppertino.css"' "$INDEX_HTML"; then
|
||||
# Insert Puppertino link tag after style.css link
|
||||
awk '
|
||||
/href="\/style.css"\/?/ && !x { print; print " <link rel=\"stylesheet\" href=\"/puppertino/puppertino.css\"/>"; x=1; next }1
|
||||
' "$INDEX_HTML" > "$INDEX_HTML.tmp" && mv "$INDEX_HTML.tmp" "$INDEX_HTML"
|
||||
fi
|
||||
# Replace default .btn with Puppertino primary button classes if present
|
||||
sed -E -i'' 's/class=\"btn\"/class=\"p-btn p-prim-col\"/g' "$INDEX_HTML" || true
|
||||
fi
|
||||
|
||||
|
||||
|
||||
generate:bindings:
|
||||
summary: Generates bindings for the frontend
|
||||
run: once
|
||||
deps:
|
||||
- task: go:mod:tidy
|
||||
sources:
|
||||
- "**/*.[jt]s"
|
||||
- exclude: frontend/**/*
|
||||
- frontend/bindings/**/* # Rerun when switching between dev/production mode causes changes in output
|
||||
- "**/*.go"
|
||||
- go.mod
|
||||
- go.sum
|
||||
generates:
|
||||
- frontend/bindings/**/*
|
||||
cmds:
|
||||
- wails3 generate bindings -f '{{.BUILD_FLAGS}}' -clean=true -time-type=Date{{if eq .OBFUSCATED "true"}} -obfuscated{{end}}
|
||||
|
||||
generate:icons:
|
||||
summary: Generates Windows `.ico` and Mac `.icns` from an image; on macOS, `-iconcomposerinput appicon.icon -macassetdir darwin` also produces `Assets.car` from a `.icon` file (skipped on other platforms).
|
||||
run: once
|
||||
dir: build
|
||||
sources:
|
||||
- "appicon.png"
|
||||
- "appicon.icon"
|
||||
generates:
|
||||
- "darwin/icons.icns"
|
||||
- "windows/icon.ico"
|
||||
cmds:
|
||||
- wails3 generate icons -input appicon.png -macfilename darwin/icons.icns -windowsfilename windows/icon.ico -iconcomposerinput appicon.icon -macassetdir darwin
|
||||
|
||||
dev:frontend:
|
||||
summary: Runs the frontend in development mode
|
||||
deps:
|
||||
- task: install:frontend:deps
|
||||
cmds:
|
||||
- task: frontend:dev:{{.PACKAGE_MANAGER}}
|
||||
|
||||
frontend:dev:npm:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- npm run dev -- --port {{.VITE_PORT}} --strictPort
|
||||
|
||||
frontend:dev:yarn:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- yarn dev --port {{.VITE_PORT}} --strictPort
|
||||
|
||||
frontend:dev:pnpm:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- pnpm dev --port {{.VITE_PORT}} --strictPort
|
||||
|
||||
frontend:dev:bun:
|
||||
dir: frontend
|
||||
cmds:
|
||||
- bun run dev --port {{.VITE_PORT}} --strictPort
|
||||
|
||||
update:build-assets:
|
||||
summary: Updates the build assets
|
||||
dir: build
|
||||
cmds:
|
||||
- wails3 update build-assets -name "{{.APP_NAME}}" -binaryname "{{.APP_NAME}}" -config config.yml -dir .
|
||||
|
||||
build:server:
|
||||
summary: Builds the application in server mode (no GUI, HTTP server only)
|
||||
desc: |
|
||||
Builds a production server binary by default: -tags server,production,
|
||||
-trimpath and a stripped binary, mirroring the desktop `build` task.
|
||||
Server mode runs as a pure HTTP server without native GUI dependencies.
|
||||
|
||||
Usage: task build:server [DEV=true] [OBFUSCATED=true] [EXTRA_TAGS=tag1,tag2]
|
||||
DEV=true development server (-tags server, no strip, inlining kept)
|
||||
OBFUSCATED=true obfuscated build via garble (requires garble installed)
|
||||
EXTRA_TAGS additional comma-separated build tags
|
||||
deps:
|
||||
- task: build:frontend
|
||||
vars:
|
||||
DEV:
|
||||
ref: .DEV
|
||||
BUILD_FLAGS:
|
||||
ref: .BUILD_FLAGS
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
preconditions:
|
||||
- sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
|
||||
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
|
||||
cmds:
|
||||
- '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o "{{.BIN_DIR}}/{{.APP_NAME}}-server{{exeExt}}"'
|
||||
vars:
|
||||
BUILD_FLAGS: '-tags server{{if eq .DEV "true"}}{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -buildvcs=false -gcflags=all="-l"{{else}},production{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -trimpath -buildvcs=false -ldflags="-w -s"{{end}}'
|
||||
|
||||
run:server:
|
||||
summary: Builds and runs a development server (DEV=true)
|
||||
deps:
|
||||
- task: build:server
|
||||
vars:
|
||||
DEV: "true"
|
||||
cmds:
|
||||
- '"./{{.BIN_DIR}}/{{.APP_NAME}}-server{{exeExt}}"'
|
||||
|
||||
build:docker:
|
||||
summary: Builds a Docker image for server mode deployment
|
||||
desc: |
|
||||
Creates a minimal Docker image containing the production server binary.
|
||||
Defaults to a pure-Go static binary on a distroless/static base. The
|
||||
production frontend is built first so the embedded assets are current.
|
||||
|
||||
Usage: task build:docker [TAG=myapp:latest] [CGO_ENABLED=1] [GO_IMAGE=...] [RUNTIME_IMAGE=...]
|
||||
For CGO apps, set CGO_ENABLED=1 with libc-compatible builder/runtime images, e.g.:
|
||||
task build:docker CGO_ENABLED=1 GO_IMAGE=golang:bookworm RUNTIME_IMAGE=gcr.io/distroless/base-debian12
|
||||
deps:
|
||||
# Build the production frontend so frontend/dist (embedded by the Go build
|
||||
# inside the image) is present and current in the Docker build context.
|
||||
# Pass the server,production tags so binding generation analyses the same
|
||||
# build the Docker image compiles, not the default-tag build.
|
||||
- task: build:frontend
|
||||
vars:
|
||||
BUILD_FLAGS: "-tags server,production"
|
||||
cmds:
|
||||
- >-
|
||||
docker build
|
||||
--build-arg CGO_ENABLED={{.CGO_ENABLED | default "0"}}
|
||||
--build-arg GO_IMAGE={{.GO_IMAGE | default "golang:alpine"}}
|
||||
--build-arg RUNTIME_IMAGE={{.RUNTIME_IMAGE | default "gcr.io/distroless/static-debian12"}}
|
||||
-t {{.TAG | default (printf "%s:latest" .APP_NAME)}}
|
||||
-f build/docker/Dockerfile.server .
|
||||
vars:
|
||||
TAG: "{{.TAG}}"
|
||||
preconditions:
|
||||
- sh: docker info > /dev/null 2>&1
|
||||
msg: "Docker is required. Please install Docker first."
|
||||
- sh: test -f build/docker/Dockerfile.server
|
||||
msg: "Dockerfile.server not found. Run 'wails3 update build-assets' to generate it."
|
||||
|
||||
run:docker:
|
||||
summary: Builds and runs the Docker image
|
||||
desc: |
|
||||
Builds the Docker image and runs it, exposing port 8080.
|
||||
Usage: task run:docker [TAG=myapp:latest] [PORT=8080]
|
||||
Note: The internal container port is always 8080. The PORT variable
|
||||
only changes the host port mapping. Ensure your app uses port 8080
|
||||
or modify the Dockerfile to match your ServerOptions.Port setting.
|
||||
deps:
|
||||
- task: build:docker
|
||||
vars:
|
||||
TAG:
|
||||
ref: .TAG
|
||||
cmds:
|
||||
- docker run --rm -p {{.PORT | default "8080"}}:8080 {{.TAG | default (printf "%s:latest" .APP_NAME)}}
|
||||
vars:
|
||||
TAG: "{{.TAG}}"
|
||||
PORT: "{{.PORT}}"
|
||||
|
||||
setup:docker:
|
||||
summary: Builds Docker image for cross-compilation (~800MB download)
|
||||
desc: |
|
||||
Builds the Docker image needed for cross-compiling to any platform.
|
||||
Run this once to enable cross-platform builds from any OS.
|
||||
cmds:
|
||||
- docker build -t wails-cross -f build/docker/Dockerfile.cross build/docker/
|
||||
preconditions:
|
||||
- sh: docker info > /dev/null 2>&1
|
||||
msg: "Docker is required. Please install Docker first."
|
||||
|
||||
ios:device:list:
|
||||
summary: Lists connected iOS devices (UDIDs)
|
||||
cmds:
|
||||
- xcrun xcdevice list
|
||||
|
||||
ios:run:device:
|
||||
summary: Build, install, and launch on a physical iPhone using Apple tools (xcodebuild/devicectl)
|
||||
vars:
|
||||
PROJECT: '{{.PROJECT}}' # e.g., build/ios/xcode/<YourProject>.xcodeproj
|
||||
SCHEME: '{{.SCHEME}}' # e.g., ios.dev
|
||||
CONFIG: '{{.CONFIG | default "Debug"}}'
|
||||
DERIVED: '{{.DERIVED | default "build/ios/DerivedData"}}'
|
||||
UDID: '{{.UDID}}' # from `task ios:device:list`
|
||||
BUNDLE_ID: '{{.BUNDLE_ID}}' # e.g., com.yourco.wails.ios.dev
|
||||
TEAM_ID: '{{.TEAM_ID}}' # optional, if your project is not already set up for signing
|
||||
preconditions:
|
||||
- sh: xcrun -f xcodebuild
|
||||
msg: "xcodebuild not found. Please install Xcode."
|
||||
- sh: xcrun -f devicectl
|
||||
msg: "devicectl not found. Please update to Xcode 15+ (which includes devicectl)."
|
||||
- sh: test -n '{{.PROJECT}}'
|
||||
msg: "Set PROJECT to your .xcodeproj path (e.g., PROJECT=build/ios/xcode/App.xcodeproj)."
|
||||
- sh: test -n '{{.SCHEME}}'
|
||||
msg: "Set SCHEME to your app scheme (e.g., SCHEME=ios.dev)."
|
||||
- sh: test -n '{{.UDID}}'
|
||||
msg: "Set UDID to your device UDID (see: task ios:device:list)."
|
||||
- sh: test -n '{{.BUNDLE_ID}}'
|
||||
msg: "Set BUNDLE_ID to your app's bundle identifier (e.g., com.yourco.wails.ios.dev)."
|
||||
cmds:
|
||||
- |
|
||||
set -euo pipefail
|
||||
echo "Building for device: UDID={{.UDID}} SCHEME={{.SCHEME}} PROJECT={{.PROJECT}}"
|
||||
XCB_ARGS=(
|
||||
-project "{{.PROJECT}}"
|
||||
-scheme "{{.SCHEME}}"
|
||||
-configuration "{{.CONFIG}}"
|
||||
-destination "id={{.UDID}}"
|
||||
-derivedDataPath "{{.DERIVED}}"
|
||||
-allowProvisioningUpdates
|
||||
-allowProvisioningDeviceRegistration
|
||||
)
|
||||
# Optionally inject signing identifiers if provided
|
||||
if [ -n '{{.TEAM_ID}}' ]; then XCB_ARGS+=(DEVELOPMENT_TEAM={{.TEAM_ID}}); fi
|
||||
if [ -n '{{.BUNDLE_ID}}' ]; then XCB_ARGS+=(PRODUCT_BUNDLE_IDENTIFIER={{.BUNDLE_ID}}); fi
|
||||
xcodebuild "${XCB_ARGS[@]}" build | xcpretty || true
|
||||
# If xcpretty isn't installed, run without it
|
||||
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
|
||||
xcodebuild "${XCB_ARGS[@]}" build
|
||||
fi
|
||||
# Find built .app
|
||||
APP_PATH=$(find "{{.DERIVED}}/Build/Products" -type d -name "*.app" -maxdepth 3 | head -n 1)
|
||||
if [ -z "$APP_PATH" ]; then
|
||||
echo "Could not locate built .app under {{.DERIVED}}/Build/Products" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Installing: $APP_PATH"
|
||||
xcrun devicectl device install app --device "{{.UDID}}" "$APP_PATH"
|
||||
echo "Launching: {{.BUNDLE_ID}}"
|
||||
xcrun devicectl device process launch --device "{{.UDID}}" --stderr console --stdout console "{{.BUNDLE_ID}}"
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg width="100%" height="100%" viewBox="0 0 583 533" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||
<g transform="matrix(1,0,0,1,-246,-251)">
|
||||
<g id="Ebene1">
|
||||
<path d="M246,251L265,784L401,784L506,450L507,450L505,784L641,784L829,251L682,251L596,567L595,567L596,251L478,251L378,568L391,251L246,251Z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 698 B |
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"fill" : {
|
||||
"automatic-gradient" : "extended-gray:1.00000,1.00000"
|
||||
},
|
||||
"groups" : [
|
||||
{
|
||||
"layers" : [
|
||||
{
|
||||
"fill-specializations" : [
|
||||
{
|
||||
"appearance" : "dark",
|
||||
"value" : {
|
||||
"solid" : "srgb:0.92143,0.92145,0.92144,1.00000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"appearance" : "tinted",
|
||||
"value" : {
|
||||
"solid" : "srgb:0.83742,0.83744,0.83743,1.00000"
|
||||
}
|
||||
}
|
||||
],
|
||||
"image-name" : "wails_icon_vector.svg",
|
||||
"name" : "wails_icon_vector",
|
||||
"position" : {
|
||||
"scale" : 0.85,
|
||||
"translation-in-points" : [
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"shadow" : {
|
||||
"kind" : "neutral",
|
||||
"opacity" : 0.5
|
||||
},
|
||||
"specular" : true,
|
||||
"translucency" : {
|
||||
"enabled" : true,
|
||||
"value" : 0.5
|
||||
}
|
||||
}
|
||||
],
|
||||
"supported-platforms" : {
|
||||
"circles" : [
|
||||
"watchOS"
|
||||
],
|
||||
"squares" : "shared"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 614 KiB |
@@ -0,0 +1,79 @@
|
||||
# This file contains the configuration for this project.
|
||||
# When you update `info` or `fileAssociations`, run `wails3 task common:update:build-assets` to update the assets.
|
||||
# Note that this will overwrite any changes you have made to the assets.
|
||||
version: '3'
|
||||
|
||||
# This information is used to generate the build assets.
|
||||
info:
|
||||
companyName: "My Company" # The name of the company
|
||||
productName: "My Product" # The name of the application
|
||||
productIdentifier: "com.mycompany.myproduct" # The unique product identifier
|
||||
description: "A program that does X" # The application description
|
||||
copyright: "(c) 2025, My Company" # Copyright text
|
||||
comments: "Some Product Comments" # Comments
|
||||
version: "0.0.1" # The application version
|
||||
# cfBundleIconName: "appicon" # The macOS icon name in Assets.car icon bundles (optional)
|
||||
# # Should match the name of your .icon file without the extension
|
||||
# # If not set and Assets.car exists, defaults to "appicon"
|
||||
|
||||
# iOS build configuration (uncomment to customise iOS project generation)
|
||||
# Note: Keys under `ios` OVERRIDE values under `info` when set.
|
||||
# ios:
|
||||
# # The iOS bundle identifier used in the generated Xcode project (CFBundleIdentifier)
|
||||
# bundleID: "com.mycompany.myproduct"
|
||||
# # The display name shown under the app icon (CFBundleDisplayName/CFBundleName)
|
||||
# displayName: "My Product"
|
||||
# # The app version to embed in Info.plist (CFBundleShortVersionString/CFBundleVersion)
|
||||
# version: "0.0.1"
|
||||
# # The company/organisation name for templates and project settings
|
||||
# company: "My Company"
|
||||
# # Additional comments to embed in Info.plist metadata
|
||||
# comments: "Some Product Comments"
|
||||
|
||||
# Dev mode configuration
|
||||
dev_mode:
|
||||
root_path: .
|
||||
log_level: warn
|
||||
debounce: 1000
|
||||
ignore:
|
||||
dir:
|
||||
- .git
|
||||
- node_modules
|
||||
- frontend
|
||||
- bin
|
||||
file:
|
||||
- .DS_Store
|
||||
- .gitignore
|
||||
- .gitkeep
|
||||
- "*_test.go"
|
||||
watched_extension:
|
||||
- "*.go"
|
||||
- "*.js" # Watch for changes to JS/TS files included using the //wails:include directive.
|
||||
- "*.ts" # The frontend directory will be excluded entirely by the setting above.
|
||||
git_ignore: true
|
||||
executes:
|
||||
- cmd: wails3 build DEV=true
|
||||
type: blocking
|
||||
- cmd: wails3 task common:dev:frontend
|
||||
type: background
|
||||
- cmd: wails3 task run
|
||||
type: primary
|
||||
|
||||
# File Associations
|
||||
# More information at: https://v3.wails.io/noit/done/yet
|
||||
fileAssociations:
|
||||
# - ext: wails
|
||||
# name: Wails
|
||||
# description: Wails Application File
|
||||
# iconName: wailsFileIcon
|
||||
# role: Editor
|
||||
# - ext: jpg
|
||||
# name: JPEG
|
||||
# description: Image File
|
||||
# iconName: jpegFileIcon
|
||||
# role: Editor
|
||||
# mimeType: image/jpeg # (optional)
|
||||
|
||||
# Other data
|
||||
other:
|
||||
- name: My Other Data
|
||||
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>NPS Client</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>npc-gui</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.nps.client</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>0.26.38</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>NPS 客户端</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.26.38</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>icons</string>
|
||||
<key>CFBundleIconName</key>
|
||||
<string>appicon</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>12.0.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<string>true</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2026 NPS</string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsLocalNetworking</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>NPS Client</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>npc-gui</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.nps.client</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>0.26.38</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>NPS 客户端</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.26.38</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>icons</string>
|
||||
<key>CFBundleIconName</key>
|
||||
<string>appicon</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>12.0.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<string>true</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2026 NPS</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,220 @@
|
||||
version: '3'
|
||||
|
||||
includes:
|
||||
common: ../Taskfile.yml
|
||||
|
||||
vars:
|
||||
# Docker image for cross-compilation (used when building on non-macOS)
|
||||
CROSS_IMAGE: wails-cross
|
||||
|
||||
tasks:
|
||||
build:
|
||||
summary: Builds the application
|
||||
cmds:
|
||||
- task: '{{if eq OS "darwin"}}build:native{{else}}build:docker{{end}}'
|
||||
vars:
|
||||
ARCH: '{{.ARCH}}'
|
||||
DEV: '{{.DEV}}'
|
||||
OUTPUT: '{{.OUTPUT}}'
|
||||
EXTRA_TAGS: '{{.EXTRA_TAGS}}'
|
||||
OBFUSCATED: '{{.OBFUSCATED}}'
|
||||
GARBLE_ARGS: '{{.GARBLE_ARGS}}'
|
||||
vars:
|
||||
DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
|
||||
OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
|
||||
|
||||
build:native:
|
||||
summary: Builds the application natively on macOS
|
||||
internal: true
|
||||
deps:
|
||||
- task: common:go:mod:tidy
|
||||
- task: common:build:frontend
|
||||
vars:
|
||||
BUILD_FLAGS:
|
||||
ref: .BUILD_FLAGS
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
DEV:
|
||||
ref: .DEV
|
||||
- task: common:generate:icons
|
||||
preconditions:
|
||||
- sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
|
||||
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
|
||||
cmds:
|
||||
- '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o "{{.OUTPUT}}"'
|
||||
vars:
|
||||
BUILD_FLAGS: '{{if eq .DEV "true"}}{{if or .EXTRA_TAGS (eq .OBFUSCATED "true")}}-tags {{if eq .OBFUSCATED "true"}}wails_obfuscated{{if .EXTRA_TAGS}},{{end}}{{end}}{{.EXTRA_TAGS}} {{end}}-buildvcs=false -gcflags=all="-l"{{else}}-tags production{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -trimpath -buildvcs=false -ldflags="-w -s"{{end}}'
|
||||
DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
|
||||
OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
|
||||
env:
|
||||
GOOS: darwin
|
||||
CGO_ENABLED: 1
|
||||
GOARCH: '{{.ARCH | default ARCH}}'
|
||||
CGO_CFLAGS: "-mmacosx-version-min=12.0"
|
||||
CGO_LDFLAGS: "-mmacosx-version-min=12.0"
|
||||
MACOSX_DEPLOYMENT_TARGET: "12.0"
|
||||
|
||||
build:docker:
|
||||
summary: Cross-compiles for macOS using Docker (for Linux/Windows hosts)
|
||||
internal: true
|
||||
deps:
|
||||
- task: common:build:frontend
|
||||
vars:
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
- task: common:generate:icons
|
||||
preconditions:
|
||||
- sh: docker info > /dev/null 2>&1
|
||||
msg: "Docker is required for cross-compilation. Please install Docker."
|
||||
- sh: docker image inspect {{.CROSS_IMAGE}} > /dev/null 2>&1
|
||||
msg: |
|
||||
Docker image '{{.CROSS_IMAGE}}' not found.
|
||||
Build it first: wails3 task setup:docker
|
||||
cmds:
|
||||
- docker run --rm -v "{{.ROOT_DIR}}:/app" {{.DOCKER_MOUNTS}} -e APP_NAME="{{.APP_NAME}}" {{if .EXTRA_TAGS}}-e EXTRA_TAGS="{{.EXTRA_TAGS}}"{{end}} {{if eq .OBFUSCATED "true"}}-e OBFUSCATED=true{{end}} {{if .GARBLE_ARGS}}-e GARBLE_ARGS="{{.GARBLE_ARGS}}"{{end}} {{.CROSS_IMAGE}} darwin {{.DOCKER_ARCH}}
|
||||
- cmd: docker run --rm -v "{{.ROOT_DIR}}:/app" alpine chown -R $(id -u):$(id -g) /app/bin
|
||||
platforms: [linux, darwin]
|
||||
- mkdir -p {{.BIN_DIR}}
|
||||
- mv "bin/{{.APP_NAME}}-darwin-{{.DOCKER_ARCH}}" "{{.OUTPUT}}"
|
||||
vars:
|
||||
DOCKER_ARCH: '{{if eq .ARCH "arm64"}}arm64{{else if eq .ARCH "amd64"}}amd64{{else}}arm64{{end}}'
|
||||
DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
|
||||
OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
|
||||
# Generate Docker volume mounts: Go module cache + go.mod replace directives
|
||||
# Uses wails3 tool docker-mounts for cross-platform compatibility (Windows/Linux/macOS)
|
||||
DOCKER_MOUNTS:
|
||||
sh: 'wails3 tool docker-mounts'
|
||||
|
||||
build:universal:
|
||||
summary: Builds darwin universal binary (arm64 + amd64)
|
||||
deps:
|
||||
- task: build
|
||||
vars:
|
||||
ARCH: amd64
|
||||
OUTPUT: "{{.BIN_DIR}}/{{.APP_NAME}}-amd64"
|
||||
- task: build
|
||||
vars:
|
||||
ARCH: arm64
|
||||
OUTPUT: "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
|
||||
cmds:
|
||||
- task: '{{if eq OS "darwin"}}build:universal:lipo:native{{else}}build:universal:lipo:go{{end}}'
|
||||
|
||||
build:universal:lipo:native:
|
||||
summary: Creates universal binary using native lipo (macOS)
|
||||
internal: true
|
||||
cmds:
|
||||
- lipo -create -output "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
|
||||
- rm "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
|
||||
|
||||
build:universal:lipo:go:
|
||||
summary: Creates universal binary using wails3 tool lipo (Linux/Windows)
|
||||
internal: true
|
||||
cmds:
|
||||
- wails3 tool lipo -output "{{.BIN_DIR}}/{{.APP_NAME}}" -input "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" -input "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
|
||||
- rm -f "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
|
||||
|
||||
package:
|
||||
summary: Packages the application into a `.app` bundle
|
||||
deps:
|
||||
- task: build
|
||||
cmds:
|
||||
- task: create:app:bundle
|
||||
|
||||
package:universal:
|
||||
summary: Packages darwin universal binary (arm64 + amd64)
|
||||
deps:
|
||||
- task: build:universal
|
||||
cmds:
|
||||
- task: create:app:bundle
|
||||
|
||||
package:dmg:
|
||||
summary: Packages the application into a styled `.dmg`
|
||||
deps:
|
||||
- task: package
|
||||
cmds:
|
||||
- task: create:dmg
|
||||
|
||||
create:dmg:
|
||||
summary: Creates a configurable `.dmg` from the `.app` bundle
|
||||
platforms: [darwin]
|
||||
cmds:
|
||||
- >-
|
||||
wails3 tool package --format dmg --name "{{.APP_NAME}}" --out "{{.BIN_DIR}}"
|
||||
--background "{{.DMG_BACKGROUND}}"
|
||||
--volume-icon "{{.DMG_VOLUME_ICON}}"
|
||||
--file-icon "{{.DMG_FILE_ICON}}"
|
||||
--window-width "{{.DMG_WINDOW_WIDTH}}"
|
||||
--window-height "{{.DMG_WINDOW_HEIGHT}}"
|
||||
{{if .DMG_FILES}}--files "{{.DMG_FILES}}"{{end}}
|
||||
vars:
|
||||
DMG_BACKGROUND: '{{.DMG_BACKGROUND | default "build/darwin/dmg-background.png"}}'
|
||||
DMG_VOLUME_ICON: '{{.DMG_VOLUME_ICON | default "build/darwin/icons.icns"}}'
|
||||
DMG_FILE_ICON: '{{.DMG_FILE_ICON | default "build/darwin/dmg-file-icon.icns"}}'
|
||||
DMG_WINDOW_WIDTH: '{{.DMG_WINDOW_WIDTH | default "540"}}'
|
||||
DMG_WINDOW_HEIGHT: '{{.DMG_WINDOW_HEIGHT | default "380"}}'
|
||||
DMG_FILES: '{{.DMG_FILES | default ""}}'
|
||||
|
||||
|
||||
create:app:bundle:
|
||||
summary: Creates an `.app` bundle
|
||||
cmds:
|
||||
- mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/MacOS"
|
||||
- mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
|
||||
- cp build/darwin/icons.icns "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
|
||||
- |
|
||||
if [ -f build/darwin/Assets.car ]; then
|
||||
cp build/darwin/Assets.car "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
|
||||
fi
|
||||
- cp "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/MacOS"
|
||||
- cp build/darwin/Info.plist "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents"
|
||||
- task: '{{if eq OS "darwin"}}codesign:adhoc{{else}}codesign:skip{{end}}'
|
||||
|
||||
codesign:adhoc:
|
||||
summary: Ad-hoc signs the app bundle (macOS only)
|
||||
internal: true
|
||||
cmds:
|
||||
- codesign --force --deep --sign - "{{.BIN_DIR}}/{{.APP_NAME}}.app"
|
||||
|
||||
codesign:skip:
|
||||
summary: Skips codesigning when cross-compiling
|
||||
internal: true
|
||||
cmds:
|
||||
- 'echo "Skipping codesign (not available on {{OS}}). Sign the .app on macOS before distribution."'
|
||||
|
||||
run:
|
||||
cmds:
|
||||
- mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS"
|
||||
- mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
|
||||
- cp build/darwin/icons.icns "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
|
||||
- |
|
||||
if [ -f build/darwin/Assets.car ]; then
|
||||
cp build/darwin/Assets.car "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
|
||||
fi
|
||||
- cp "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS"
|
||||
- cp "build/darwin/Info.dev.plist" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Info.plist"
|
||||
- codesign --force --deep --sign - "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
|
||||
- '"{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS/{{.APP_NAME}}"'
|
||||
|
||||
sign:
|
||||
summary: Signs the application bundle with Developer ID
|
||||
desc: |
|
||||
Signs the .app bundle for distribution.
|
||||
Uses signing identity from `wails3 setup` (stored in ~/.config/wails/defaults.yaml).
|
||||
Override with: task darwin:sign -- --identity "Developer ID Application: ..."
|
||||
deps:
|
||||
- task: package
|
||||
cmds:
|
||||
- wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.app" {{.CLI_ARGS}}
|
||||
|
||||
sign:notarize:
|
||||
summary: Signs and notarizes the application bundle
|
||||
desc: |
|
||||
Signs the .app bundle and submits it for notarization.
|
||||
Uses signing identity and keychain profile from `wails3 setup`.
|
||||
|
||||
First-time setup:
|
||||
wails3 setup
|
||||
deps:
|
||||
- task: package
|
||||
cmds:
|
||||
- wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.app" --notarize {{.CLI_ARGS}}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
Binary file not shown.
@@ -0,0 +1,225 @@
|
||||
# Cross-compile Wails v3 apps to any platform
|
||||
#
|
||||
# Darwin: Zig + macOS SDK
|
||||
# Linux: Native GCC when host matches target, Zig for cross-arch
|
||||
# Windows: Zig + bundled mingw
|
||||
#
|
||||
# Usage:
|
||||
# docker build -t wails-cross -f Dockerfile.cross .
|
||||
# docker run --rm -v $(pwd):/app wails-cross darwin arm64
|
||||
# docker run --rm -v $(pwd):/app wails-cross darwin amd64
|
||||
# docker run --rm -v $(pwd):/app wails-cross linux amd64
|
||||
# docker run --rm -v $(pwd):/app wails-cross linux arm64
|
||||
# docker run --rm -v $(pwd):/app wails-cross windows amd64
|
||||
# docker run --rm -v $(pwd):/app wails-cross windows arm64
|
||||
|
||||
# Debian 13 provides the GTK >= 4.14 API baseline used by the default Linux backend.
|
||||
FROM golang:1.26-trixie
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG GARBLE_VERSION=v0.16.0
|
||||
|
||||
# Install base tools, GCC, and GTK/WebKit dev packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl xz-utils python3 nodejs npm pkg-config gcc libc6-dev \
|
||||
libgtk-3-dev libwebkit2gtk-4.1-dev \
|
||||
libgtk-4-dev libwebkitgtk-6.0-dev \
|
||||
&& pkg-config --atleast-version=4.14 gtk4 \
|
||||
&& pkg-config --exists webkitgtk-6.0 \
|
||||
&& pkg-config --exists gtk+-3.0 \
|
||||
&& pkg-config --exists webkit2gtk-4.1 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN go install mvdan.cc/garble@${GARBLE_VERSION}
|
||||
|
||||
# Install Zig - automatically selects correct binary for host architecture.
|
||||
# The SHA-256 is fetched from Zig's official download manifest and verified
|
||||
# before extraction to protect against MITM or corrupted downloads.
|
||||
ARG ZIG_VERSION=0.14.0
|
||||
RUN ZIG_ARCH=$(case "${TARGETARCH}" in arm64) echo "aarch64" ;; *) echo "x86_64" ;; esac) && \
|
||||
ZIG_FILE="zig-linux-${ZIG_ARCH}-${ZIG_VERSION}.tar.xz" && \
|
||||
curl -fSL "https://ziglang.org/download/${ZIG_VERSION}/${ZIG_FILE}" -o "/tmp/${ZIG_FILE}" && \
|
||||
EXPECTED=$(curl -fsSL "https://ziglang.org/download/index.json" | \
|
||||
python3 -c "import json,sys; d=json.load(sys.stdin); print(d[sys.argv[1]][sys.argv[2]+'-linux']['shasum'])" \
|
||||
"${ZIG_VERSION}" "${ZIG_ARCH}") && \
|
||||
echo "${EXPECTED} /tmp/${ZIG_FILE}" | sha256sum -c - && \
|
||||
tar -xJ -f "/tmp/${ZIG_FILE}" -C /opt && \
|
||||
rm "/tmp/${ZIG_FILE}" && \
|
||||
ln -s /opt/zig-linux-${ZIG_ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig
|
||||
|
||||
# Download macOS SDK (required for darwin targets)
|
||||
ARG MACOS_SDK_VERSION=14.5
|
||||
RUN curl -L "https://github.com/joseluisq/macosx-sdks/releases/download/${MACOS_SDK_VERSION}/MacOSX${MACOS_SDK_VERSION}.sdk.tar.xz" \
|
||||
| tar -xJ -C /opt \
|
||||
&& mv /opt/MacOSX${MACOS_SDK_VERSION}.sdk /opt/macos-sdk
|
||||
|
||||
ENV MACOS_SDK_PATH=/opt/macos-sdk
|
||||
|
||||
# Create Zig CC wrappers for cross-compilation targets
|
||||
# Darwin and Windows use Zig; Linux uses native GCC (run with --platform for cross-arch)
|
||||
|
||||
# Darwin arm64
|
||||
COPY <<'ZIGWRAP' /usr/local/bin/zcc-darwin-arm64
|
||||
#!/bin/sh
|
||||
ARGS=""
|
||||
SKIP_NEXT=0
|
||||
for arg in "$@"; do
|
||||
if [ $SKIP_NEXT -eq 1 ]; then
|
||||
SKIP_NEXT=0
|
||||
continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-target) SKIP_NEXT=1 ;;
|
||||
-mmacosx-version-min=*) ;;
|
||||
*) ARGS="$ARGS $arg" ;;
|
||||
esac
|
||||
done
|
||||
exec zig cc -fno-sanitize=all -target aarch64-macos-none -isysroot /opt/macos-sdk -I/opt/macos-sdk/usr/include -L/opt/macos-sdk/usr/lib -F/opt/macos-sdk/System/Library/Frameworks -w $ARGS
|
||||
ZIGWRAP
|
||||
RUN chmod +x /usr/local/bin/zcc-darwin-arm64
|
||||
|
||||
# Darwin amd64
|
||||
COPY <<'ZIGWRAP' /usr/local/bin/zcc-darwin-amd64
|
||||
#!/bin/sh
|
||||
ARGS=""
|
||||
SKIP_NEXT=0
|
||||
for arg in "$@"; do
|
||||
if [ $SKIP_NEXT -eq 1 ]; then
|
||||
SKIP_NEXT=0
|
||||
continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-target) SKIP_NEXT=1 ;;
|
||||
-mmacosx-version-min=*) ;;
|
||||
*) ARGS="$ARGS $arg" ;;
|
||||
esac
|
||||
done
|
||||
exec zig cc -fno-sanitize=all -target x86_64-macos-none -isysroot /opt/macos-sdk -I/opt/macos-sdk/usr/include -L/opt/macos-sdk/usr/lib -F/opt/macos-sdk/System/Library/Frameworks -w $ARGS
|
||||
ZIGWRAP
|
||||
RUN chmod +x /usr/local/bin/zcc-darwin-amd64
|
||||
|
||||
# Windows amd64 - uses Zig's bundled mingw
|
||||
COPY <<'ZIGWRAP' /usr/local/bin/zcc-windows-amd64
|
||||
#!/bin/sh
|
||||
ARGS=""
|
||||
SKIP_NEXT=0
|
||||
for arg in "$@"; do
|
||||
if [ $SKIP_NEXT -eq 1 ]; then
|
||||
SKIP_NEXT=0
|
||||
continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-target) SKIP_NEXT=1 ;;
|
||||
-Wl,*) ;;
|
||||
*) ARGS="$ARGS $arg" ;;
|
||||
esac
|
||||
done
|
||||
exec zig cc -target x86_64-windows-gnu $ARGS
|
||||
ZIGWRAP
|
||||
RUN chmod +x /usr/local/bin/zcc-windows-amd64
|
||||
|
||||
# Windows arm64 - uses Zig's bundled mingw
|
||||
COPY <<'ZIGWRAP' /usr/local/bin/zcc-windows-arm64
|
||||
#!/bin/sh
|
||||
ARGS=""
|
||||
SKIP_NEXT=0
|
||||
for arg in "$@"; do
|
||||
if [ $SKIP_NEXT -eq 1 ]; then
|
||||
SKIP_NEXT=0
|
||||
continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-target) SKIP_NEXT=1 ;;
|
||||
-Wl,*) ;;
|
||||
*) ARGS="$ARGS $arg" ;;
|
||||
esac
|
||||
done
|
||||
exec zig cc -target aarch64-windows-gnu $ARGS
|
||||
ZIGWRAP
|
||||
RUN chmod +x /usr/local/bin/zcc-windows-arm64
|
||||
|
||||
# Build script
|
||||
COPY <<'SCRIPT' /usr/local/bin/build.sh
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
OS=${1:-darwin}
|
||||
ARCH=${2:-arm64}
|
||||
|
||||
case "${OS}-${ARCH}" in
|
||||
darwin-arm64|darwin-aarch64)
|
||||
export CC=zcc-darwin-arm64
|
||||
export GOARCH=arm64
|
||||
export GOOS=darwin
|
||||
;;
|
||||
darwin-amd64|darwin-x86_64)
|
||||
export CC=zcc-darwin-amd64
|
||||
export GOARCH=amd64
|
||||
export GOOS=darwin
|
||||
;;
|
||||
linux-arm64|linux-aarch64)
|
||||
export CC=gcc
|
||||
export GOARCH=arm64
|
||||
export GOOS=linux
|
||||
;;
|
||||
linux-amd64|linux-x86_64)
|
||||
export CC=gcc
|
||||
export GOARCH=amd64
|
||||
export GOOS=linux
|
||||
;;
|
||||
windows-arm64|windows-aarch64)
|
||||
export CC=zcc-windows-arm64
|
||||
export GOARCH=arm64
|
||||
export GOOS=windows
|
||||
;;
|
||||
windows-amd64|windows-x86_64)
|
||||
export CC=zcc-windows-amd64
|
||||
export GOARCH=amd64
|
||||
export GOOS=windows
|
||||
;;
|
||||
*)
|
||||
echo "Usage: <os> <arch>"
|
||||
echo " os: darwin, linux, windows"
|
||||
echo " arch: amd64, arm64"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
export CGO_ENABLED=1
|
||||
export CGO_CFLAGS="-w"
|
||||
|
||||
# Build frontend if exists and not already built (host may have built it)
|
||||
if [ -d "frontend" ] && [ -f "frontend/package.json" ] && [ ! -d "frontend/dist" ]; then
|
||||
(cd frontend && npm install --silent && npm run build --silent)
|
||||
fi
|
||||
|
||||
# Build
|
||||
APP=${APP_NAME:-$(basename $(pwd))}
|
||||
mkdir -p bin
|
||||
|
||||
EXT=""
|
||||
LDFLAGS="-s -w"
|
||||
if [ "$GOOS" = "windows" ]; then
|
||||
EXT=".exe"
|
||||
LDFLAGS="-s -w -H windowsgui"
|
||||
fi
|
||||
|
||||
TAGS="production"
|
||||
if [ -n "$EXTRA_TAGS" ]; then
|
||||
TAGS="${TAGS},${EXTRA_TAGS}"
|
||||
fi
|
||||
|
||||
COMPILER="go build"
|
||||
if [ "$OBFUSCATED" = "true" ]; then
|
||||
COMPILER="garble ${GARBLE_ARGS} build"
|
||||
TAGS="${TAGS},wails_obfuscated"
|
||||
fi
|
||||
|
||||
${COMPILER} -tags "$TAGS" -trimpath -buildvcs=false -ldflags="$LDFLAGS" -o bin/${APP}-${GOOS}-${GOARCH}${EXT} .
|
||||
echo "Built: bin/${APP}-${GOOS}-${GOARCH}${EXT}"
|
||||
SCRIPT
|
||||
RUN chmod +x /usr/local/bin/build.sh
|
||||
|
||||
WORKDIR /app
|
||||
ENTRYPOINT ["/usr/local/bin/build.sh"]
|
||||
CMD ["darwin", "arm64"]
|
||||
@@ -0,0 +1,67 @@
|
||||
# Wails Server Mode Dockerfile
|
||||
# Multi-stage build for a minimal image.
|
||||
#
|
||||
# Defaults produce a pure-Go, fully static binary on a distroless/static base:
|
||||
# the smallest, most secure image, and correct for the default (CGO-free) app.
|
||||
#
|
||||
# If your app needs CGO, override the build args, e.g.:
|
||||
# docker build --build-arg CGO_ENABLED=1 \
|
||||
# --build-arg GO_IMAGE=golang:bookworm \
|
||||
# --build-arg RUNTIME_IMAGE=gcr.io/distroless/base-debian12 \
|
||||
# -f build/docker/Dockerfile.server .
|
||||
# CGO needs a C toolchain in the builder and a libc in the runtime image; keep
|
||||
# the builder and runtime libc compatible (a glibc builder -> a glibc runtime).
|
||||
# The Taskfile passes these through: task build:docker CGO_ENABLED=1 GO_IMAGE=... RUNTIME_IMAGE=...
|
||||
|
||||
ARG GO_IMAGE=golang:alpine
|
||||
ARG RUNTIME_IMAGE=gcr.io/distroless/static-debian12
|
||||
ARG CGO_ENABLED=0
|
||||
|
||||
# Build stage
|
||||
FROM ${GO_IMAGE} AS builder
|
||||
ARG CGO_ENABLED
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install build dependencies: git always; a C compiler only when CGO is enabled.
|
||||
# Supports both apk (alpine) and apt (debian/bookworm) base images.
|
||||
RUN if command -v apk >/dev/null 2>&1; then \
|
||||
apk add --no-cache git $([ "$CGO_ENABLED" = "1" ] && echo gcc musl-dev); \
|
||||
else \
|
||||
apt-get update && apt-get install -y --no-install-recommends git $([ "$CGO_ENABLED" = "1" ] && echo gcc libc6-dev) && rm -rf /var/lib/apt/lists/*; \
|
||||
fi
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Remove local replace directive if present (for production builds)
|
||||
RUN sed -i '/^replace/d' go.mod || true
|
||||
|
||||
# Download dependencies
|
||||
RUN go mod tidy
|
||||
|
||||
# Build the production server binary.
|
||||
# - server,production tags: HTTP server mode with production code paths (no dev
|
||||
# logger/asset middleware), matching the desktop production build.
|
||||
# - CGO_ENABLED defaults to 0 for a fully static binary (distroless/static);
|
||||
# override with --build-arg CGO_ENABLED=1 (see header) for CGO apps.
|
||||
RUN CGO_ENABLED=${CGO_ENABLED} go build -tags server,production -trimpath -buildvcs=false -ldflags="-s -w" -o server .
|
||||
|
||||
# Runtime stage - minimal image
|
||||
FROM ${RUNTIME_IMAGE}
|
||||
|
||||
# Copy the binary
|
||||
COPY --from=builder /app/server /server
|
||||
|
||||
# Copy frontend assets
|
||||
COPY --from=builder /app/frontend/dist /frontend/dist
|
||||
|
||||
# Expose the default port
|
||||
EXPOSE 8080
|
||||
|
||||
# Bind to all interfaces (required for Docker)
|
||||
# Can be overridden at runtime with -e WAILS_SERVER_HOST=...
|
||||
ENV WAILS_SERVER_HOST=0.0.0.0
|
||||
|
||||
# Run the server
|
||||
ENTRYPOINT ["/server"]
|
||||
@@ -0,0 +1,220 @@
|
||||
version: '3'
|
||||
|
||||
includes:
|
||||
common: ../Taskfile.yml
|
||||
|
||||
vars:
|
||||
# Signing configuration - edit these values for your project
|
||||
# PGP_KEY: "path/to/signing-key.asc"
|
||||
# SIGN_ROLE: "builder" # Options: origin, maint, archive, builder
|
||||
#
|
||||
# Password is stored securely in system keychain. Run: wails3 setup signing
|
||||
|
||||
# Docker image for cross-compilation (used when building on non-Linux or no CC available)
|
||||
CROSS_IMAGE: wails-cross
|
||||
|
||||
tasks:
|
||||
build:
|
||||
summary: Builds the application for Linux
|
||||
cmds:
|
||||
# Linux requires CGO - use Docker when:
|
||||
# 1. Cross-compiling from non-Linux, OR
|
||||
# 2. No C compiler is available, OR
|
||||
# 3. Target architecture differs from host architecture (cross-arch compilation)
|
||||
- task: '{{if and (eq OS "linux") (eq .HAS_CC "true") (eq .TARGET_ARCH ARCH)}}build:native{{else}}build:docker{{end}}'
|
||||
vars:
|
||||
ARCH: '{{.ARCH}}'
|
||||
DEV: '{{.DEV}}'
|
||||
OUTPUT: '{{.OUTPUT}}'
|
||||
EXTRA_TAGS: '{{.EXTRA_TAGS}}'
|
||||
OBFUSCATED: '{{.OBFUSCATED}}'
|
||||
GARBLE_ARGS: '{{.GARBLE_ARGS}}'
|
||||
vars:
|
||||
DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
|
||||
OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
|
||||
# Determine target architecture (defaults to host ARCH if not specified)
|
||||
TARGET_ARCH: '{{.ARCH | default ARCH}}'
|
||||
# Check if a C compiler is available (gcc or clang) — cross-platform via wails3 tool
|
||||
HAS_CC:
|
||||
sh: 'wails3 tool has "gcc|clang"'
|
||||
|
||||
build:native:
|
||||
summary: Builds the application natively on Linux
|
||||
internal: true
|
||||
deps:
|
||||
- task: common:go:mod:tidy
|
||||
- task: common:build:frontend
|
||||
vars:
|
||||
BUILD_FLAGS:
|
||||
ref: .BUILD_FLAGS
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
DEV:
|
||||
ref: .DEV
|
||||
- task: common:generate:icons
|
||||
- task: generate:dotdesktop
|
||||
preconditions:
|
||||
- sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
|
||||
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
|
||||
cmds:
|
||||
- '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o {{.OUTPUT}}'
|
||||
vars:
|
||||
BUILD_FLAGS: '{{if eq .DEV "true"}}{{if or .EXTRA_TAGS (eq .OBFUSCATED "true")}}-tags {{if eq .OBFUSCATED "true"}}wails_obfuscated{{if .EXTRA_TAGS}},{{end}}{{end}}{{.EXTRA_TAGS}} {{end}}-buildvcs=false -gcflags=all="-l"{{else}}-tags production{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -trimpath -buildvcs=false -ldflags="-w -s"{{end}}'
|
||||
DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
|
||||
OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
|
||||
env:
|
||||
GOOS: linux
|
||||
CGO_ENABLED: 1
|
||||
GOARCH: '{{.ARCH | default ARCH}}'
|
||||
|
||||
build:docker:
|
||||
summary: Builds for Linux using Docker (for non-Linux hosts or when no C compiler available)
|
||||
internal: true
|
||||
deps:
|
||||
- task: common:build:frontend
|
||||
vars:
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
- task: common:generate:icons
|
||||
- task: generate:dotdesktop
|
||||
preconditions:
|
||||
- sh: docker info > /dev/null 2>&1
|
||||
msg: "Docker is required for cross-compilation to Linux. Please install Docker."
|
||||
- sh: docker image inspect {{.CROSS_IMAGE}} > /dev/null 2>&1
|
||||
msg: |
|
||||
Docker image '{{.CROSS_IMAGE}}' not found.
|
||||
Build it first: wails3 task setup:docker
|
||||
cmds:
|
||||
- docker run --rm -v "{{.ROOT_DIR}}:/app" {{.DOCKER_MOUNTS}} -e APP_NAME="{{.APP_NAME}}" {{if .EXTRA_TAGS}}-e EXTRA_TAGS="{{.EXTRA_TAGS}}"{{end}} {{if eq .OBFUSCATED "true"}}-e OBFUSCATED=true{{end}} {{if .GARBLE_ARGS}}-e GARBLE_ARGS="{{.GARBLE_ARGS}}"{{end}} "{{.CROSS_IMAGE}}" linux {{.DOCKER_ARCH}}
|
||||
- cmd: docker run --rm -v "{{.ROOT_DIR}}:/app" alpine chown -R $(id -u):$(id -g) /app/bin
|
||||
platforms: [linux, darwin]
|
||||
- mkdir -p {{.BIN_DIR}}
|
||||
- mv "bin/{{.APP_NAME}}-linux-{{.DOCKER_ARCH}}" "{{.OUTPUT}}"
|
||||
vars:
|
||||
DOCKER_ARCH: '{{.ARCH | default "amd64"}}'
|
||||
DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
|
||||
OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
|
||||
# Generate Docker volume mounts: Go module cache + go.mod replace directives
|
||||
# Uses wails3 tool docker-mounts for cross-platform compatibility (Windows/Linux/macOS)
|
||||
DOCKER_MOUNTS:
|
||||
sh: 'wails3 tool docker-mounts'
|
||||
|
||||
package:
|
||||
summary: Packages the application for Linux
|
||||
deps:
|
||||
- task: build
|
||||
cmds:
|
||||
- task: create:appimage
|
||||
- task: create:deb
|
||||
- task: create:rpm
|
||||
- task: create:aur
|
||||
|
||||
create:appimage:
|
||||
summary: Creates an AppImage
|
||||
dir: build/linux/appimage
|
||||
deps:
|
||||
- task: build
|
||||
- task: generate:dotdesktop
|
||||
cmds:
|
||||
- cp "{{.APP_BINARY}}" "{{.APP_NAME}}"
|
||||
- cp ../../appicon.png "{{.APP_NAME}}.png"
|
||||
- wails3 generate appimage -binary "{{.APP_NAME}}" -icon {{.ICON}} -desktopfile {{.DESKTOP_FILE}} -outputdir {{.OUTPUT_DIR}} -builddir {{.ROOT_DIR}}/build/linux/appimage/build
|
||||
vars:
|
||||
APP_NAME: '{{.APP_NAME}}'
|
||||
APP_BINARY: '../../../bin/{{.APP_NAME}}'
|
||||
ICON: '{{.APP_NAME}}.png'
|
||||
DESKTOP_FILE: '../{{.APP_NAME}}.desktop'
|
||||
OUTPUT_DIR: '../../../bin'
|
||||
|
||||
create:deb:
|
||||
summary: Creates a deb package
|
||||
deps:
|
||||
- task: build
|
||||
cmds:
|
||||
- task: generate:dotdesktop
|
||||
- task: generate:deb
|
||||
|
||||
create:rpm:
|
||||
summary: Creates a rpm package
|
||||
deps:
|
||||
- task: build
|
||||
cmds:
|
||||
- task: generate:dotdesktop
|
||||
- task: generate:rpm
|
||||
|
||||
create:aur:
|
||||
summary: Creates a arch linux packager package
|
||||
deps:
|
||||
- task: build
|
||||
cmds:
|
||||
- task: generate:dotdesktop
|
||||
- task: generate:aur
|
||||
|
||||
generate:deb:
|
||||
summary: Creates a deb package
|
||||
cmds:
|
||||
- wails3 tool package -name "{{.APP_NAME}}" -format deb -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin
|
||||
|
||||
generate:rpm:
|
||||
summary: Creates a rpm package
|
||||
cmds:
|
||||
- wails3 tool package -name "{{.APP_NAME}}" -format rpm -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin
|
||||
|
||||
generate:aur:
|
||||
summary: Creates a arch linux packager package
|
||||
cmds:
|
||||
- wails3 tool package -name "{{.APP_NAME}}" -format archlinux -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin
|
||||
|
||||
generate:dotdesktop:
|
||||
summary: Generates a `.desktop` file
|
||||
dir: build
|
||||
cmds:
|
||||
- mkdir -p {{.ROOT_DIR}}/build/linux/appimage
|
||||
- wails3 generate .desktop -name "{{.APP_NAME}}" -exec "{{.EXEC}}" -icon "{{.ICON}}" -outputfile "{{.ROOT_DIR}}/build/linux/{{.APP_NAME}}.desktop" -categories "{{.CATEGORIES}}"
|
||||
vars:
|
||||
APP_NAME: '{{.APP_NAME}}'
|
||||
EXEC: '{{.APP_NAME}}'
|
||||
ICON: '{{.APP_NAME}}'
|
||||
CATEGORIES: 'Development;'
|
||||
OUTPUTFILE: '{{.ROOT_DIR}}/build/linux/{{.APP_NAME}}.desktop'
|
||||
|
||||
run:
|
||||
cmds:
|
||||
- '{{.BIN_DIR}}/{{.APP_NAME}}'
|
||||
|
||||
sign:deb:
|
||||
summary: Signs the DEB package
|
||||
desc: |
|
||||
Signs the .deb package with a PGP key.
|
||||
Set PGP_KEY in the vars section to override the key configured globally via
|
||||
`wails3 setup` (~/.config/wails/defaults.yaml).
|
||||
Password is retrieved from system keychain (run: wails3 setup signing)
|
||||
deps:
|
||||
- task: create:deb
|
||||
cmds:
|
||||
# PGP_KEY is optional: if unset, `wails3 tool sign` falls back to the key
|
||||
# configured globally via `wails3 setup`.
|
||||
- wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}*.deb" {{if .PGP_KEY}}--pgp-key "{{.PGP_KEY}}"{{end}} {{if .SIGN_ROLE}}--role "{{.SIGN_ROLE}}"{{end}}
|
||||
|
||||
sign:rpm:
|
||||
summary: Signs the RPM package
|
||||
desc: |
|
||||
Signs the .rpm package with a PGP key.
|
||||
Set PGP_KEY in the vars section to override the key configured globally via
|
||||
`wails3 setup` (~/.config/wails/defaults.yaml).
|
||||
Password is retrieved from system keychain (run: wails3 setup signing)
|
||||
deps:
|
||||
- task: create:rpm
|
||||
cmds:
|
||||
- wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}*.rpm" {{if .PGP_KEY}}--pgp-key "{{.PGP_KEY}}"{{end}}
|
||||
|
||||
sign:packages:
|
||||
summary: Signs all Linux packages (DEB and RPM)
|
||||
desc: |
|
||||
Signs both .deb and .rpm packages with a PGP key.
|
||||
Set PGP_KEY in the vars section to override the key configured globally via
|
||||
`wails3 setup` (~/.config/wails/defaults.yaml).
|
||||
Password is retrieved from system keychain (run: wails3 setup signing)
|
||||
cmds:
|
||||
- task: sign:deb
|
||||
- task: sign:rpm
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2018-Present Lea Anthony
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Fail script on any error
|
||||
set -euxo pipefail
|
||||
|
||||
# Define variables
|
||||
APP_DIR="${APP_NAME}.AppDir"
|
||||
|
||||
# Create AppDir structure
|
||||
mkdir -p "${APP_DIR}/usr/bin"
|
||||
cp -r "${APP_BINARY}" "${APP_DIR}/usr/bin/"
|
||||
cp "${ICON_PATH}" "${APP_DIR}/"
|
||||
cp "${DESKTOP_FILE}" "${APP_DIR}/"
|
||||
|
||||
if [[ $(uname -m) == *x86_64* ]]; then
|
||||
# Download linuxdeploy and make it executable
|
||||
wget -q -4 -N https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
|
||||
chmod +x linuxdeploy-x86_64.AppImage
|
||||
|
||||
# Run linuxdeploy to bundle the application
|
||||
./linuxdeploy-x86_64.AppImage --appdir "${APP_DIR}" --output appimage
|
||||
else
|
||||
# Download linuxdeploy and make it executable (arm64)
|
||||
wget -q -4 -N https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-aarch64.AppImage
|
||||
chmod +x linuxdeploy-aarch64.AppImage
|
||||
|
||||
# Run linuxdeploy to bundle the application (arm64)
|
||||
./linuxdeploy-aarch64.AppImage --appdir "${APP_DIR}" --output appimage
|
||||
fi
|
||||
|
||||
# Rename the generated AppImage
|
||||
mv "${APP_NAME}*.AppImage" "${APP_NAME}.AppImage"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[Desktop Entry]
|
||||
Version=1.0
|
||||
Name=NPS Client
|
||||
Comment=NPS 客户端
|
||||
# The Exec line includes %u to pass the URL to the application
|
||||
Exec=/usr/local/bin/npc-gui %u
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Icon=npc-gui
|
||||
Categories=Utility;
|
||||
StartupWMClass=npc-gui
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# Feel free to remove those if you don't want/need to use them.
|
||||
# Make sure to check the documentation at https://nfpm.goreleaser.com
|
||||
#
|
||||
# The lines below are called `modelines`. See `:help modeline`
|
||||
|
||||
name: "npc-gui"
|
||||
arch: ${GOARCH}
|
||||
platform: "linux"
|
||||
version: "0.26.38"
|
||||
section: "default"
|
||||
priority: "extra"
|
||||
maintainer: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>
|
||||
description: "NPS 客户端"
|
||||
vendor: "NPS"
|
||||
homepage: "https://wails.io"
|
||||
license: "MIT"
|
||||
release: "1"
|
||||
|
||||
contents:
|
||||
- src: "./bin/npc-gui"
|
||||
dst: "/usr/local/bin/npc-gui"
|
||||
- src: "./build/appicon.png"
|
||||
dst: "/usr/share/icons/hicolor/128x128/apps/npc-gui.png"
|
||||
- src: "./build/linux/npc-gui.desktop"
|
||||
dst: "/usr/share/applications/npc-gui.desktop"
|
||||
|
||||
# Default dependencies for the GTK4 + WebKitGTK 6.0 stack (Ubuntu 24.04+ / Debian 13+)
|
||||
depends:
|
||||
- libgtk-4-1
|
||||
- libwebkitgtk-6.0-4
|
||||
|
||||
# Distribution-specific overrides for different package formats
|
||||
overrides:
|
||||
# RPM packages for Fedora / RHEL / AlmaLinux / Rocky Linux
|
||||
rpm:
|
||||
depends:
|
||||
- gtk4
|
||||
- webkitgtk6.0
|
||||
|
||||
# Arch Linux packages
|
||||
archlinux:
|
||||
depends:
|
||||
- gtk4
|
||||
- webkitgtk-6.0
|
||||
|
||||
# scripts section to ensure desktop database is updated after install
|
||||
scripts:
|
||||
postinstall: "./build/linux/nfpm/scripts/postinstall.sh"
|
||||
# You can also add preremove, postremove if needed
|
||||
# preremove: "./build/linux/nfpm/scripts/preremove.sh"
|
||||
# postremove: "./build/linux/nfpm/scripts/postremove.sh"
|
||||
|
||||
# If you build your app with -tags gtk3 (legacy WebKit2GTK 4.1 stack — supported through v3.0.x, removed in v3.1),
|
||||
# replace the depends/overrides above with these:
|
||||
#
|
||||
# depends:
|
||||
# - libgtk-3-0
|
||||
# - libwebkit2gtk-4.1-0
|
||||
# overrides:
|
||||
# rpm:
|
||||
# depends:
|
||||
# - gtk3
|
||||
# - webkit2gtk4.1
|
||||
# archlinux:
|
||||
# depends:
|
||||
# - gtk3
|
||||
# - webkit2gtk-4.1
|
||||
#
|
||||
# replaces:
|
||||
# - foobar
|
||||
# provides:
|
||||
# - bar
|
||||
# recommends:
|
||||
# - whatever
|
||||
# suggests:
|
||||
# - something-else
|
||||
# conflicts:
|
||||
# - not-foo
|
||||
# - not-bar
|
||||
# changelog: "changelog.yaml"
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Update desktop database for .desktop file changes
|
||||
# This makes the application appear in application menus and registers its capabilities.
|
||||
if command -v update-desktop-database >/dev/null 2>&1; then
|
||||
echo "Updating desktop database..."
|
||||
update-desktop-database -q /usr/share/applications
|
||||
else
|
||||
echo "Warning: update-desktop-database command not found. Desktop file may not be immediately recognized." >&2
|
||||
fi
|
||||
|
||||
# Update MIME database for custom URL schemes (x-scheme-handler)
|
||||
# This ensures the system knows how to handle your custom protocols.
|
||||
if command -v update-mime-database >/dev/null 2>&1; then
|
||||
echo "Updating MIME database..."
|
||||
update-mime-database -n /usr/share/mime
|
||||
else
|
||||
echo "Warning: update-mime-database command not found. Custom URL schemes may not be immediately recognized." >&2
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/bash
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/bash
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/bash
|
||||
@@ -0,0 +1,195 @@
|
||||
version: '3'
|
||||
|
||||
includes:
|
||||
common: ../Taskfile.yml
|
||||
|
||||
vars:
|
||||
# Signing configuration - edit these values for your project
|
||||
# SIGN_CERTIFICATE: "path/to/certificate.pfx"
|
||||
# SIGN_THUMBPRINT: "certificate-thumbprint" # Alternative to SIGN_CERTIFICATE
|
||||
# TIMESTAMP_SERVER: "http://timestamp.digicert.com"
|
||||
#
|
||||
# Password is stored securely in system keychain. Run: wails3 setup signing
|
||||
|
||||
# Docker image for cross-compilation with CGO (used when CGO_ENABLED=1 on non-Windows)
|
||||
CROSS_IMAGE: wails-cross
|
||||
|
||||
tasks:
|
||||
build:
|
||||
summary: Builds the application for Windows
|
||||
cmds:
|
||||
# Auto-detect CGO: if CGO_ENABLED=1, use Docker; otherwise use native Go cross-compile
|
||||
- task: '{{if and (ne OS "windows") (eq .CGO_ENABLED "1")}}build:docker{{else}}build:native{{end}}'
|
||||
vars:
|
||||
ARCH: '{{.ARCH}}'
|
||||
DEV: '{{.DEV}}'
|
||||
EXTRA_TAGS: '{{.EXTRA_TAGS}}'
|
||||
OBFUSCATED: '{{.OBFUSCATED}}'
|
||||
GARBLE_ARGS: '{{.GARBLE_ARGS}}'
|
||||
vars:
|
||||
# Default to CGO_ENABLED=0 if not explicitly set
|
||||
CGO_ENABLED: '{{.CGO_ENABLED | default "0"}}'
|
||||
|
||||
build:native:
|
||||
summary: Builds the application using native Go cross-compilation
|
||||
internal: true
|
||||
deps:
|
||||
- task: common:go:mod:tidy
|
||||
- task: common:build:frontend
|
||||
vars:
|
||||
BUILD_FLAGS:
|
||||
ref: .BUILD_FLAGS
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
DEV:
|
||||
ref: .DEV
|
||||
- task: common:generate:icons
|
||||
preconditions:
|
||||
- sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
|
||||
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
|
||||
cmds:
|
||||
- task: generate:syso
|
||||
vars:
|
||||
ARCH: '{{.ARCH}}'
|
||||
- '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o "{{.BIN_DIR}}/{{.APP_NAME}}.exe"'
|
||||
- cmd: powershell Remove-item *.syso
|
||||
platforms: [windows]
|
||||
- cmd: rm -f *.syso
|
||||
platforms: [linux, darwin]
|
||||
vars:
|
||||
BUILD_FLAGS: '{{if eq .DEV "true"}}{{if or .EXTRA_TAGS (eq .OBFUSCATED "true")}}-tags {{if eq .OBFUSCATED "true"}}wails_obfuscated{{if .EXTRA_TAGS}},{{end}}{{end}}{{.EXTRA_TAGS}} {{end}}-buildvcs=false -gcflags=all="-l"{{else}}-tags production{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -trimpath -buildvcs=false -ldflags="-w -s -H windowsgui"{{end}}'
|
||||
env:
|
||||
GOOS: windows
|
||||
CGO_ENABLED: '{{.CGO_ENABLED | default "0"}}'
|
||||
GOARCH: '{{.ARCH | default ARCH}}'
|
||||
|
||||
build:docker:
|
||||
summary: Cross-compiles for Windows using Docker with Zig (for CGO builds on non-Windows)
|
||||
internal: true
|
||||
deps:
|
||||
- task: common:build:frontend
|
||||
vars:
|
||||
OBFUSCATED:
|
||||
ref: .OBFUSCATED
|
||||
- task: common:generate:icons
|
||||
preconditions:
|
||||
- sh: docker info > /dev/null 2>&1
|
||||
msg: "Docker is required for CGO cross-compilation. Please install Docker."
|
||||
- sh: docker image inspect {{.CROSS_IMAGE}} > /dev/null 2>&1
|
||||
msg: |
|
||||
Docker image '{{.CROSS_IMAGE}}' not found.
|
||||
Build it first: wails3 task setup:docker
|
||||
cmds:
|
||||
- task: generate:syso
|
||||
vars:
|
||||
ARCH: '{{.ARCH}}'
|
||||
- docker run --rm -v "{{.ROOT_DIR}}:/app" {{.DOCKER_MOUNTS}} -e APP_NAME="{{.APP_NAME}}" {{if .EXTRA_TAGS}}-e EXTRA_TAGS="{{.EXTRA_TAGS}}"{{end}} {{if eq .OBFUSCATED "true"}}-e OBFUSCATED=true{{end}} {{if .GARBLE_ARGS}}-e GARBLE_ARGS="{{.GARBLE_ARGS}}"{{end}} {{.CROSS_IMAGE}} windows {{.DOCKER_ARCH}}
|
||||
- cmd: docker run --rm -v "{{.ROOT_DIR}}:/app" alpine chown -R $(id -u):$(id -g) /app/bin
|
||||
platforms: [linux, darwin]
|
||||
- rm -f *.syso
|
||||
vars:
|
||||
DOCKER_ARCH: '{{.ARCH | default "amd64"}}'
|
||||
# Generate Docker volume mounts: Go module cache + go.mod replace directives
|
||||
# Uses wails3 tool docker-mounts for cross-platform compatibility (Windows/Linux/macOS)
|
||||
DOCKER_MOUNTS:
|
||||
sh: 'wails3 tool docker-mounts'
|
||||
|
||||
package:
|
||||
summary: Packages the application
|
||||
cmds:
|
||||
- task: '{{if eq (.FORMAT | default "nsis") "msix"}}create:msix:package{{else}}create:nsis:installer{{end}}'
|
||||
vars:
|
||||
INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
|
||||
vars:
|
||||
FORMAT: '{{.FORMAT | default "nsis"}}'
|
||||
INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
|
||||
|
||||
generate:syso:
|
||||
summary: Generates Windows `.syso` file
|
||||
dir: build
|
||||
cmds:
|
||||
- wails3 generate syso -arch {{.ARCH}} -icon windows/icon.ico -manifest windows/wails.exe.manifest -info windows/info.json -out ../wails_windows_{{.ARCH}}.syso
|
||||
vars:
|
||||
ARCH: '{{.ARCH | default ARCH}}'
|
||||
|
||||
create:nsis:installer:
|
||||
summary: Creates an NSIS installer
|
||||
dir: build/windows/nsis
|
||||
deps:
|
||||
- task: build
|
||||
preconditions:
|
||||
- sh: '[ "{{.INSTALL_SCOPE}}" = "user" ] || [ "{{.INSTALL_SCOPE}}" = "machine" ]'
|
||||
msg: "INSTALL_SCOPE must be 'user' or 'machine', got '{{.INSTALL_SCOPE}}'"
|
||||
cmds:
|
||||
# Create the Microsoft WebView2 bootstrapper if it doesn't exist
|
||||
- wails3 generate webview2bootstrapper -dir "{{.ROOT_DIR}}/build/windows/nsis"
|
||||
- |
|
||||
{{if eq OS "windows"}}
|
||||
makensis {{if eq .INSTALL_SCOPE "user"}}-DWAILS_INSTALL_SCOPE=user -DREQUEST_EXECUTION_LEVEL=user {{end}}-DARG_WAILS_{{.ARG_FLAG}}_BINARY="{{.ROOT_DIR}}\{{.BIN_DIR}}\{{.APP_NAME}}.exe" project.nsi
|
||||
{{else}}
|
||||
makensis {{if eq .INSTALL_SCOPE "user"}}-DWAILS_INSTALL_SCOPE=user -DREQUEST_EXECUTION_LEVEL=user {{end}}-DARG_WAILS_{{.ARG_FLAG}}_BINARY="{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}.exe" project.nsi
|
||||
{{end}}
|
||||
vars:
|
||||
ARCH: '{{.ARCH | default ARCH}}'
|
||||
ARG_FLAG: '{{if eq .ARCH "amd64"}}AMD64{{else}}ARM64{{end}}'
|
||||
INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
|
||||
|
||||
create:msix:package:
|
||||
summary: Creates an MSIX package
|
||||
deps:
|
||||
- task: build
|
||||
cmds:
|
||||
- |-
|
||||
wails3 tool msix \
|
||||
--config "{{.ROOT_DIR}}/wails.json" \
|
||||
--name "{{.APP_NAME}}" \
|
||||
--executable "{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}.exe" \
|
||||
--arch "{{.ARCH}}" \
|
||||
--out "{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}-{{.ARCH}}.msix" \
|
||||
{{if .CERT_PATH}}--cert "{{.CERT_PATH}}"{{end}} \
|
||||
{{if .PUBLISHER}}--publisher "{{.PUBLISHER}}"{{end}} \
|
||||
{{if .USE_MSIX_TOOL}}--use-msix-tool{{else}}--use-makeappx{{end}}
|
||||
vars:
|
||||
ARCH: '{{.ARCH | default ARCH}}'
|
||||
CERT_PATH: '{{.CERT_PATH | default ""}}'
|
||||
PUBLISHER: '{{.PUBLISHER | default ""}}'
|
||||
USE_MSIX_TOOL: '{{.USE_MSIX_TOOL | default "false"}}'
|
||||
|
||||
install:msix:tools:
|
||||
summary: Installs tools required for MSIX packaging
|
||||
cmds:
|
||||
- wails3 tool msix-install-tools
|
||||
|
||||
run:
|
||||
cmds:
|
||||
- '{{.BIN_DIR}}/{{.APP_NAME}}.exe'
|
||||
|
||||
sign:
|
||||
summary: Signs the Windows executable
|
||||
desc: |
|
||||
Signs the .exe with an Authenticode certificate.
|
||||
Set SIGN_CERTIFICATE or SIGN_THUMBPRINT to override the certificate
|
||||
configured globally via `wails3 setup` (~/.config/wails/defaults.yaml).
|
||||
Password is retrieved from system keychain (run: wails3 setup signing)
|
||||
deps:
|
||||
- task: build
|
||||
cmds:
|
||||
# Certificate vars are optional: if unset, `wails3 tool sign` falls back to
|
||||
# the certificate configured globally via `wails3 setup`.
|
||||
- wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.exe" {{if .SIGN_CERTIFICATE}}--certificate "{{.SIGN_CERTIFICATE}}"{{end}} {{if .SIGN_THUMBPRINT}}--thumbprint "{{.SIGN_THUMBPRINT}}"{{end}} {{if .TIMESTAMP_SERVER}}--timestamp "{{.TIMESTAMP_SERVER}}"{{end}}
|
||||
|
||||
sign:installer:
|
||||
summary: Signs the NSIS installer
|
||||
desc: |
|
||||
Creates and signs the NSIS installer.
|
||||
Set SIGN_CERTIFICATE or SIGN_THUMBPRINT to override the certificate
|
||||
configured globally via `wails3 setup` (~/.config/wails/defaults.yaml).
|
||||
Password is retrieved from system keychain (run: wails3 setup signing)
|
||||
deps:
|
||||
- task: create:nsis:installer
|
||||
vars:
|
||||
INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
|
||||
vars:
|
||||
INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
|
||||
cmds:
|
||||
- wails3 tool sign --input "build/windows/nsis/{{.APP_NAME}}-installer.exe" {{if .SIGN_CERTIFICATE}}--certificate "{{.SIGN_CERTIFICATE}}"{{end}} {{if .SIGN_THUMBPRINT}}--thumbprint "{{.SIGN_THUMBPRINT}}"{{end}} {{if .TIMESTAMP_SERVER}}--timestamp "{{.TIMESTAMP_SERVER}}"{{end}}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"fixed": {
|
||||
"file_version": "0.26.38"
|
||||
},
|
||||
"info": {
|
||||
"0000": {
|
||||
"ProductVersion": "0.26.38",
|
||||
"CompanyName": "NPS",
|
||||
"FileDescription": "NPS 客户端",
|
||||
"LegalCopyright": "Copyright © 2026 NPS",
|
||||
"ProductName": "NPS Client",
|
||||
"Comments": "NPS 客户端"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
|
||||
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
|
||||
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
|
||||
IgnorableNamespaces="uap3">
|
||||
|
||||
<Identity
|
||||
Name="com.nps.client"
|
||||
Publisher="CN=NPS"
|
||||
Version="0.26.38.0"
|
||||
ProcessorArchitecture="x64" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>NPS Client</DisplayName>
|
||||
<PublisherDisplayName>NPS</PublisherDisplayName>
|
||||
<Description>NPS 客户端</Description>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
|
||||
</Dependencies>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="en-us" />
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="com.nps.client" Executable="npc-gui" EntryPoint="Windows.FullTrustApplication">
|
||||
<uap:VisualElements
|
||||
DisplayName="NPS Client"
|
||||
Description="NPS 客户端"
|
||||
BackgroundColor="transparent"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
|
||||
<Extensions>
|
||||
<desktop:Extension Category="windows.fullTrustProcess" Executable="npc-gui" />
|
||||
|
||||
|
||||
</Extensions>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
<Capabilities>
|
||||
<rescap:Capability Name="runFullTrust" />
|
||||
|
||||
</Capabilities>
|
||||
</Package>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MsixPackagingToolTemplate
|
||||
xmlns="http://schemas.microsoft.com/msix/packaging/msixpackagingtool/template/2022">
|
||||
<Settings
|
||||
AllowTelemetry="false"
|
||||
ApplyACLsToPackageFiles="true"
|
||||
GenerateCommandLineFile="true"
|
||||
AllowPromptForPassword="false">
|
||||
</Settings>
|
||||
<Installer
|
||||
Path="npc-gui"
|
||||
Arguments=""
|
||||
InstallLocation="C:\Program Files\NPS\NPS Client">
|
||||
</Installer>
|
||||
<PackageInformation
|
||||
PackageName="NPS Client"
|
||||
PackageDisplayName="NPS Client"
|
||||
PublisherName="CN=NPS"
|
||||
PublisherDisplayName="NPS"
|
||||
Version="0.26.38.0"
|
||||
PackageDescription="NPS 客户端">
|
||||
<Capabilities>
|
||||
<Capability Name="runFullTrust" />
|
||||
|
||||
</Capabilities>
|
||||
<Applications>
|
||||
<Application
|
||||
Id="com.nps.client"
|
||||
Description="NPS 客户端"
|
||||
DisplayName="NPS Client"
|
||||
ExecutableName="npc-gui"
|
||||
EntryPoint="Windows.FullTrustApplication">
|
||||
|
||||
</Application>
|
||||
</Applications>
|
||||
<Resources>
|
||||
<Resource Language="en-us" />
|
||||
</Resources>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
|
||||
</Dependencies>
|
||||
<Properties>
|
||||
<Framework>false</Framework>
|
||||
<DisplayName>NPS Client</DisplayName>
|
||||
<PublisherDisplayName>NPS</PublisherDisplayName>
|
||||
<Description>NPS 客户端</Description>
|
||||
<Logo>Assets\AppIcon.png</Logo>
|
||||
</Properties>
|
||||
</PackageInformation>
|
||||
<SaveLocation PackagePath="npc-gui.msix" />
|
||||
<PackageIntegrity>
|
||||
<CertificatePath></CertificatePath>
|
||||
</PackageIntegrity>
|
||||
</MsixPackagingToolTemplate>
|
||||
@@ -0,0 +1,119 @@
|
||||
Unicode true
|
||||
|
||||
####
|
||||
## Please note: Template replacements don't work in this file. They are provided with default defines like
|
||||
## mentioned underneath.
|
||||
## If the keyword is not defined, "wails_tools.nsh" will populate them.
|
||||
## If they are defined here, "wails_tools.nsh" will not touch them. This allows you to use this project.nsi manually
|
||||
## from outside of Wails for debugging and development of the installer.
|
||||
##
|
||||
## For development first make a wails nsis build to populate the "wails_tools.nsh":
|
||||
## > wails build --target windows/amd64 --nsis
|
||||
## Then you can call makensis on this file with specifying the path to your binary:
|
||||
## For a AMD64 only installer:
|
||||
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app.exe
|
||||
## For a ARM64 only installer:
|
||||
## > makensis -DARG_WAILS_ARM64_BINARY=..\..\bin\app.exe
|
||||
## For a installer with both architectures:
|
||||
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app-amd64.exe -DARG_WAILS_ARM64_BINARY=..\..\bin\app-arm64.exe
|
||||
####
|
||||
## The following information is taken from the wails_tools.nsh file, but they can be overwritten here.
|
||||
####
|
||||
## !define INFO_PROJECTNAME "my-project" # Default "npc-gui"
|
||||
## !define INFO_COMPANYNAME "My Company" # Default "NPS"
|
||||
## !define INFO_PRODUCTNAME "My Product Name" # Default "NPS Client"
|
||||
## !define INFO_PRODUCTVERSION "1.0.0" # Default "0.26.38"
|
||||
## !define INFO_COPYRIGHT "(c) Now, My Company" # Default "Copyright © 2026 NPS"
|
||||
###
|
||||
## !define PRODUCT_EXECUTABLE "Application.exe" # Default "${INFO_PROJECTNAME}.exe"
|
||||
## !define UNINST_KEY_NAME "UninstKeyInRegistry" # Default "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
|
||||
####
|
||||
## !define REQUEST_EXECUTION_LEVEL "admin" # Default "admin" see also https://nsis.sourceforge.io/Docs/Chapter4.html
|
||||
## !define WAILS_INSTALL_SCOPE "user" # Default "machine" - set to "user" for per-user install ($LOCALAPPDATA) without UAC prompt
|
||||
####
|
||||
## Include the wails tools
|
||||
####
|
||||
!include "wails_tools.nsh"
|
||||
|
||||
# The version information for this two must consist of 4 parts
|
||||
VIProductVersion "${INFO_PRODUCTVERSION}.0"
|
||||
VIFileVersion "${INFO_PRODUCTVERSION}.0"
|
||||
|
||||
VIAddVersionKey "CompanyName" "${INFO_COMPANYNAME}"
|
||||
VIAddVersionKey "FileDescription" "${INFO_PRODUCTNAME} Installer"
|
||||
VIAddVersionKey "ProductVersion" "${INFO_PRODUCTVERSION}"
|
||||
VIAddVersionKey "FileVersion" "${INFO_PRODUCTVERSION}"
|
||||
VIAddVersionKey "LegalCopyright" "${INFO_COPYRIGHT}"
|
||||
VIAddVersionKey "ProductName" "${INFO_PRODUCTNAME}"
|
||||
|
||||
# Enable HiDPI support. https://nsis.sourceforge.io/Reference/ManifestDPIAware
|
||||
ManifestDPIAware true
|
||||
|
||||
!include "MUI.nsh"
|
||||
|
||||
!define MUI_ICON "..\icon.ico"
|
||||
!define MUI_UNICON "..\icon.ico"
|
||||
# !define MUI_WELCOMEFINISHPAGE_BITMAP "resources\leftimage.bmp" #Include this to add a bitmap on the left side of the Welcome Page. Must be a size of 164x314
|
||||
!define MUI_FINISHPAGE_NOAUTOCLOSE # Wait on the INSTFILES page so the user can take a look into the details of the installation steps
|
||||
!define MUI_ABORTWARNING # This will warn the user if they exit from the installer.
|
||||
|
||||
!insertmacro MUI_PAGE_WELCOME # Welcome to the installer page.
|
||||
# !insertmacro MUI_PAGE_LICENSE "resources\eula.txt" # Adds a EULA page to the installer
|
||||
!insertmacro MUI_PAGE_DIRECTORY # In which folder install page.
|
||||
!insertmacro MUI_PAGE_INSTFILES # Installing page.
|
||||
!insertmacro MUI_PAGE_FINISH # Finished installation page.
|
||||
|
||||
!insertmacro MUI_UNPAGE_INSTFILES # Uninstalling page
|
||||
|
||||
!insertmacro MUI_LANGUAGE "English" # Set the Language of the installer
|
||||
|
||||
## The following two statements can be used to sign the installer and the uninstaller. The path to the binaries are provided in %1
|
||||
#!uninstfinalize 'signtool --file "%1"'
|
||||
#!finalize 'signtool --file "%1"'
|
||||
|
||||
Name "${INFO_PRODUCTNAME}"
|
||||
OutFile "..\..\..\bin\${INFO_PROJECTNAME}-${ARCH}-installer.exe" # Name of the installer's file.
|
||||
!if "${WAILS_INSTALL_SCOPE}" == "user"
|
||||
InstallDir "$LOCALAPPDATA\Programs\${INFO_PRODUCTNAME}"
|
||||
!else
|
||||
InstallDir "$PROGRAMFILES64\${INFO_COMPANYNAME}\${INFO_PRODUCTNAME}"
|
||||
!endif
|
||||
ShowInstDetails show # This will always show the installation details.
|
||||
|
||||
Function .onInit
|
||||
!insertmacro wails.checkArchitecture
|
||||
FunctionEnd
|
||||
|
||||
Section
|
||||
!insertmacro wails.setShellContext
|
||||
|
||||
!insertmacro wails.webview2runtime
|
||||
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
!insertmacro wails.files
|
||||
|
||||
CreateShortcut "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
CreateShortCut "$DESKTOP\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
|
||||
!insertmacro wails.associateFiles
|
||||
!insertmacro wails.associateCustomProtocols
|
||||
|
||||
!insertmacro wails.writeUninstaller
|
||||
SectionEnd
|
||||
|
||||
Section "uninstall"
|
||||
!insertmacro wails.setShellContext
|
||||
|
||||
RMDir /r "$AppData\${PRODUCT_EXECUTABLE}" # Remove the WebView2 DataPath
|
||||
|
||||
RMDir /r $INSTDIR
|
||||
|
||||
Delete "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk"
|
||||
Delete "$DESKTOP\${INFO_PRODUCTNAME}.lnk"
|
||||
|
||||
!insertmacro wails.unassociateFiles
|
||||
!insertmacro wails.unassociateCustomProtocols
|
||||
|
||||
!insertmacro wails.deleteUninstaller
|
||||
SectionEnd
|
||||
@@ -0,0 +1,261 @@
|
||||
# DO NOT EDIT - Generated automatically by `wails build`
|
||||
|
||||
!include "x64.nsh"
|
||||
!include "WinVer.nsh"
|
||||
!include "FileFunc.nsh"
|
||||
|
||||
!ifndef INFO_PROJECTNAME
|
||||
!define INFO_PROJECTNAME "npc-gui"
|
||||
!endif
|
||||
!ifndef INFO_COMPANYNAME
|
||||
!define INFO_COMPANYNAME "NPS"
|
||||
!endif
|
||||
!ifndef INFO_PRODUCTNAME
|
||||
!define INFO_PRODUCTNAME "NPS Client"
|
||||
!endif
|
||||
!ifndef INFO_PRODUCTVERSION
|
||||
!define INFO_PRODUCTVERSION "0.26.38"
|
||||
!endif
|
||||
!ifndef INFO_COPYRIGHT
|
||||
!define INFO_COPYRIGHT "Copyright © 2026 NPS"
|
||||
!endif
|
||||
!ifndef PRODUCT_EXECUTABLE
|
||||
!define PRODUCT_EXECUTABLE "${INFO_PROJECTNAME}.exe"
|
||||
!endif
|
||||
!ifndef UNINST_KEY_NAME
|
||||
!define UNINST_KEY_NAME "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
|
||||
!endif
|
||||
!define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINST_KEY_NAME}"
|
||||
|
||||
!ifndef WAILS_INSTALL_SCOPE
|
||||
!define WAILS_INSTALL_SCOPE "machine"
|
||||
!endif
|
||||
|
||||
!ifndef REQUEST_EXECUTION_LEVEL
|
||||
!if "${WAILS_INSTALL_SCOPE}" == "user"
|
||||
!define REQUEST_EXECUTION_LEVEL "user"
|
||||
!else
|
||||
!define REQUEST_EXECUTION_LEVEL "admin"
|
||||
!endif
|
||||
!endif
|
||||
|
||||
RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"
|
||||
|
||||
!ifdef ARG_WAILS_AMD64_BINARY
|
||||
!define SUPPORTS_AMD64
|
||||
!endif
|
||||
|
||||
!ifdef ARG_WAILS_ARM64_BINARY
|
||||
!define SUPPORTS_ARM64
|
||||
!endif
|
||||
|
||||
!ifdef SUPPORTS_AMD64
|
||||
!ifdef SUPPORTS_ARM64
|
||||
!define ARCH "amd64_arm64"
|
||||
!else
|
||||
!define ARCH "amd64"
|
||||
!endif
|
||||
!else
|
||||
!ifdef SUPPORTS_ARM64
|
||||
!define ARCH "arm64"
|
||||
!else
|
||||
!error "Wails: Undefined ARCH, please provide at least one of ARG_WAILS_AMD64_BINARY or ARG_WAILS_ARM64_BINARY"
|
||||
!endif
|
||||
!endif
|
||||
|
||||
!macro wails.checkArchitecture
|
||||
!ifndef WAILS_WIN10_REQUIRED
|
||||
!define WAILS_WIN10_REQUIRED "This product is only supported on Windows 10 (Server 2016) and later."
|
||||
!endif
|
||||
|
||||
!ifndef WAILS_ARCHITECTURE_NOT_SUPPORTED
|
||||
!define WAILS_ARCHITECTURE_NOT_SUPPORTED "This product can't be installed on the current Windows architecture. Supports: ${ARCH}"
|
||||
!endif
|
||||
|
||||
${If} ${AtLeastWin10}
|
||||
!ifdef SUPPORTS_AMD64
|
||||
${if} ${IsNativeAMD64}
|
||||
Goto ok
|
||||
${EndIf}
|
||||
!endif
|
||||
|
||||
!ifdef SUPPORTS_ARM64
|
||||
${if} ${IsNativeARM64}
|
||||
Goto ok
|
||||
${EndIf}
|
||||
!endif
|
||||
|
||||
IfSilent silentArch notSilentArch
|
||||
silentArch:
|
||||
SetErrorLevel 65
|
||||
Abort
|
||||
notSilentArch:
|
||||
MessageBox MB_OK "${WAILS_ARCHITECTURE_NOT_SUPPORTED}"
|
||||
Quit
|
||||
${else}
|
||||
IfSilent silentWin notSilentWin
|
||||
silentWin:
|
||||
SetErrorLevel 64
|
||||
Abort
|
||||
notSilentWin:
|
||||
MessageBox MB_OK "${WAILS_WIN10_REQUIRED}"
|
||||
Quit
|
||||
${EndIf}
|
||||
|
||||
ok:
|
||||
!macroend
|
||||
|
||||
!macro wails.files
|
||||
!ifdef SUPPORTS_AMD64
|
||||
${if} ${IsNativeAMD64}
|
||||
File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_AMD64_BINARY}"
|
||||
${EndIf}
|
||||
!endif
|
||||
|
||||
!ifdef SUPPORTS_ARM64
|
||||
${if} ${IsNativeARM64}
|
||||
File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_ARM64_BINARY}"
|
||||
${EndIf}
|
||||
!endif
|
||||
!macroend
|
||||
|
||||
!macro wails.writeUninstaller
|
||||
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||
|
||||
SetRegView 64
|
||||
!if "${WAILS_INSTALL_SCOPE}" == "user"
|
||||
WriteRegStr HKCU "${UNINST_KEY}" "Publisher" "${INFO_COMPANYNAME}"
|
||||
WriteRegStr HKCU "${UNINST_KEY}" "DisplayName" "${INFO_PRODUCTNAME}"
|
||||
WriteRegStr HKCU "${UNINST_KEY}" "DisplayVersion" "${INFO_PRODUCTVERSION}"
|
||||
WriteRegStr HKCU "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
WriteRegStr HKCU "${UNINST_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
|
||||
WriteRegStr HKCU "${UNINST_KEY}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
|
||||
|
||||
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
|
||||
IntFmt $0 "0x%08X" $0
|
||||
WriteRegDWORD HKCU "${UNINST_KEY}" "EstimatedSize" "$0"
|
||||
!else
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "${INFO_COMPANYNAME}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "${INFO_PRODUCTNAME}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${INFO_PRODUCTVERSION}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
|
||||
|
||||
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
|
||||
IntFmt $0 "0x%08X" $0
|
||||
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" "$0"
|
||||
!endif
|
||||
!macroend
|
||||
|
||||
!macro wails.deleteUninstaller
|
||||
Delete "$INSTDIR\uninstall.exe"
|
||||
|
||||
SetRegView 64
|
||||
!if "${WAILS_INSTALL_SCOPE}" == "user"
|
||||
DeleteRegKey HKCU "${UNINST_KEY}"
|
||||
!else
|
||||
DeleteRegKey HKLM "${UNINST_KEY}"
|
||||
!endif
|
||||
!macroend
|
||||
|
||||
!macro wails.setShellContext
|
||||
${If} ${REQUEST_EXECUTION_LEVEL} == "admin"
|
||||
SetShellVarContext all
|
||||
${else}
|
||||
SetShellVarContext current
|
||||
${EndIf}
|
||||
!macroend
|
||||
|
||||
# Install webview2 by launching the bootstrapper
|
||||
# See https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#online-only-deployment
|
||||
!macro wails.webview2runtime
|
||||
!ifndef WAILS_INSTALL_WEBVIEW_DETAILPRINT
|
||||
!define WAILS_INSTALL_WEBVIEW_DETAILPRINT "Installing: WebView2 Runtime"
|
||||
!endif
|
||||
|
||||
SetRegView 64
|
||||
# If the admin key exists and is not empty then webview2 is already installed
|
||||
ReadRegStr $0 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
|
||||
${If} $0 != ""
|
||||
Goto ok
|
||||
${EndIf}
|
||||
|
||||
${If} ${REQUEST_EXECUTION_LEVEL} == "user"
|
||||
# If the installer is run in user level, check the user specific key exists and is not empty then webview2 is already installed
|
||||
ReadRegStr $0 HKCU "Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
|
||||
${If} $0 != ""
|
||||
Goto ok
|
||||
${EndIf}
|
||||
${EndIf}
|
||||
|
||||
SetDetailsPrint both
|
||||
DetailPrint "${WAILS_INSTALL_WEBVIEW_DETAILPRINT}"
|
||||
SetDetailsPrint listonly
|
||||
|
||||
InitPluginsDir
|
||||
CreateDirectory "$pluginsdir\webview2bootstrapper"
|
||||
SetOutPath "$pluginsdir\webview2bootstrapper"
|
||||
File "MicrosoftEdgeWebview2Setup.exe"
|
||||
ExecWait '"$pluginsdir\webview2bootstrapper\MicrosoftEdgeWebview2Setup.exe" /silent /install'
|
||||
|
||||
SetDetailsPrint both
|
||||
ok:
|
||||
!macroend
|
||||
|
||||
# Copy of APP_ASSOCIATE and APP_UNASSOCIATE macros from here https://gist.github.com/nikku/281d0ef126dbc215dd58bfd5b3a5cd5b
|
||||
!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
|
||||
; Backup the previously associated file class
|
||||
ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "${FILECLASS}_backup" "$R0"
|
||||
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "${FILECLASS}"
|
||||
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}" "" `${DESCRIPTION}`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\DefaultIcon" "" `${ICON}`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell" "" "open"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open" "" `${COMMANDTEXT}`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open\command" "" `${COMMAND}`
|
||||
!macroend
|
||||
|
||||
!macro APP_UNASSOCIATE EXT FILECLASS
|
||||
; Backup the previously associated file class
|
||||
ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" `${FILECLASS}_backup`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "$R0"
|
||||
|
||||
DeleteRegKey SHELL_CONTEXT `Software\Classes\${FILECLASS}`
|
||||
!macroend
|
||||
|
||||
!macro wails.associateFiles
|
||||
; Create file associations
|
||||
|
||||
!macroend
|
||||
|
||||
!macro wails.unassociateFiles
|
||||
; Delete app associations
|
||||
|
||||
!macroend
|
||||
|
||||
!macro CUSTOM_PROTOCOL_ASSOCIATE PROTOCOL DESCRIPTION ICON COMMAND
|
||||
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "" "${DESCRIPTION}"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "URL Protocol" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\DefaultIcon" "" "${ICON}"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell" "" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open" "" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open\command" "" "${COMMAND}"
|
||||
!macroend
|
||||
|
||||
!macro CUSTOM_PROTOCOL_UNASSOCIATE PROTOCOL
|
||||
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
|
||||
!macroend
|
||||
|
||||
!macro wails.associateCustomProtocols
|
||||
; Create custom protocols associations
|
||||
|
||||
!macroend
|
||||
|
||||
!macro wails.unassociateCustomProtocols
|
||||
; Delete app custom protocol associations
|
||||
|
||||
!macroend
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||
<assemblyIdentity type="win32" name="com.nps.client" version="0.26.38" processorArchitecture="*"/>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<asmv3:application>
|
||||
<asmv3:windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> <!-- fallback for Windows 7 and 8 -->
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness> <!-- falls back to per-monitor if per-monitor v2 is not supported -->
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
||||
@@ -0,0 +1,9 @@
|
||||
//@ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import { Create as $Create } from "@wailsio/runtime";
|
||||
|
||||
Object.freeze($Create.Events);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
@@ -0,0 +1,173 @@
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import { Call as $Call, CancellablePromise as $CancellablePromise, Create as $Create } from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
|
||||
/**
|
||||
* @param {string} arg
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function AddShortcut(arg) {
|
||||
return $Call.ByID(1551262862, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} s
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function AddShortcutFromBase64(s) {
|
||||
return $Call.ByID(1504335541, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* CheckForUpdate 检查是否有新版本可用(检测升级)
|
||||
* @returns {$CancellablePromise<$models.UpdateInfo | null>}
|
||||
*/
|
||||
export function CheckForUpdate() {
|
||||
return $Call.ByID(2347956003).then(/** @type {($result: any) => any} */(($result) => {
|
||||
return $$createType1($result);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* ClearConnectionLogs 清空指定客户端的连接日志(内存缓冲与日志文件)
|
||||
* @param {string} clientId
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function ClearConnectionLogs(clientId) {
|
||||
return $Call.ByID(390310005, clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* DownloadAndInstallUpdate 下载最新版本并热替换当前可执行文件
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function DownloadAndInstallUpdate() {
|
||||
return $Call.ByID(2440793480);
|
||||
}
|
||||
|
||||
/**
|
||||
* GetAppVersion 返回来自 lib/version 的版本号
|
||||
* @returns {$CancellablePromise<string>}
|
||||
*/
|
||||
export function GetAppVersion() {
|
||||
return $Call.ByID(1780012486);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {$CancellablePromise<{ [_ in string]?: string }>}
|
||||
*/
|
||||
export function GetClientStates() {
|
||||
return $Call.ByID(4274000306).then(/** @type {($result: any) => any} */(($result) => {
|
||||
return $$createType2($result);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* GetConnectionLogs 获取指定客户端的连接日志(直接读内存缓冲,无需解析文件)
|
||||
* @param {string} clientId
|
||||
* @returns {$CancellablePromise<$models.ConnectionLog[]>}
|
||||
*/
|
||||
export function GetConnectionLogs(clientId) {
|
||||
return $Call.ByID(1455453564, clientId).then(/** @type {($result: any) => any} */(($result) => {
|
||||
return $$createType4($result);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* GetDefaultLogDir 获取默认日志目录路径
|
||||
* @returns {$CancellablePromise<string>}
|
||||
*/
|
||||
export function GetDefaultLogDir() {
|
||||
return $Call.ByID(2287653297);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以下为对 settings 与 clientStates 的访问方法(供前端调用)
|
||||
* @returns {$CancellablePromise<$models.GuiSettings>}
|
||||
*/
|
||||
export function GetGuiSettings() {
|
||||
return $Call.ByID(3468339871).then(/** @type {($result: any) => any} */(($result) => {
|
||||
return $$createType5($result);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {$CancellablePromise<$models.ShortClient[]>}
|
||||
*/
|
||||
export function GetShortcuts() {
|
||||
return $Call.ByID(737927018).then(/** @type {($result: any) => any} */(($result) => {
|
||||
return $$createType7($result);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {string} addr
|
||||
* @param {string} key
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function RemoveShortcut(name, addr, key) {
|
||||
return $Call.ByID(658180051, name, addr, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* RestartApp 重启当前程序(更新完成后调用)
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function RestartApp() {
|
||||
return $Call.ByID(4246341431);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ [_ in string]?: string }} m
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function SaveClientStates(m) {
|
||||
return $Call.ByID(2752835897, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {$models.GuiSettings} s
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function SaveGuiSettings(s) {
|
||||
return $Call.ByID(979570966, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* SelectDirectory 打开目录选择对话框
|
||||
* @returns {$CancellablePromise<string>}
|
||||
*/
|
||||
export function SelectDirectory() {
|
||||
return $Call.ByID(1735672136);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {string} addr
|
||||
* @param {string} key
|
||||
* @param {boolean} tls
|
||||
* @param {boolean} runningState
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function ToggleClient(name, addr, key, tls, runningState) {
|
||||
return $Call.ByID(1335627254, name, addr, key, tls, runningState);
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = $models.UpdateInfo.createFrom;
|
||||
const $$createType1 = $Create.Nullable($$createType0);
|
||||
const $$createType2 = $Create.Map($Create.Any, $Create.Any);
|
||||
const $$createType3 = $models.ConnectionLog.createFrom;
|
||||
const $$createType4 = $Create.Array($$createType3);
|
||||
const $$createType5 = $models.GuiSettings.createFrom;
|
||||
const $$createType6 = $models.ShortClient.createFrom;
|
||||
const $$createType7 = $Create.Array($$createType6);
|
||||
@@ -0,0 +1,15 @@
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
import * as App from "./app.js";
|
||||
export {
|
||||
App
|
||||
};
|
||||
|
||||
export {
|
||||
ConnectionLog,
|
||||
GuiSettings,
|
||||
ShortClient,
|
||||
UpdateInfo
|
||||
} from "./models.js";
|
||||
@@ -0,0 +1,262 @@
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import { Create as $Create } from "@wailsio/runtime";
|
||||
|
||||
/**
|
||||
* ConnectionLog 连接日志项
|
||||
*/
|
||||
export class ConnectionLog {
|
||||
/**
|
||||
* Creates a new ConnectionLog instance.
|
||||
* @param {Partial<ConnectionLog>} [$$source = {}] - The source object to create the ConnectionLog.
|
||||
*/
|
||||
constructor($$source = {}) {
|
||||
if (!("timestamp" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["timestamp"] = "";
|
||||
}
|
||||
if (!("message" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["message"] = "";
|
||||
}
|
||||
if (!("type" in $$source)) {
|
||||
/**
|
||||
* "info", "error", "warning", "success"
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["type"] = "";
|
||||
}
|
||||
if (!("clientId" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["clientId"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ConnectionLog instance from a string or object.
|
||||
* @param {any} [$$source = {}]
|
||||
* @returns {ConnectionLog}
|
||||
*/
|
||||
static createFrom($$source = {}) {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new ConnectionLog(/** @type {Partial<ConnectionLog>} */($$parsedSource));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 持久化文件结构(向后兼容旧的仅数组格式)
|
||||
*/
|
||||
export class GuiSettings {
|
||||
/**
|
||||
* Creates a new GuiSettings instance.
|
||||
* @param {Partial<GuiSettings>} [$$source = {}] - The source object to create the GuiSettings.
|
||||
*/
|
||||
constructor($$source = {}) {
|
||||
if (!("startupEnabled" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {boolean}
|
||||
*/
|
||||
this["startupEnabled"] = false;
|
||||
}
|
||||
if (!("rememberClientState" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {boolean}
|
||||
*/
|
||||
this["rememberClientState"] = false;
|
||||
}
|
||||
if (!("logDir" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["logDir"] = "";
|
||||
}
|
||||
if (!("themeMode" in $$source)) {
|
||||
/**
|
||||
* "auto", "light", "dark"
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["themeMode"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new GuiSettings instance from a string or object.
|
||||
* @param {any} [$$source = {}]
|
||||
* @returns {GuiSettings}
|
||||
*/
|
||||
static createFrom($$source = {}) {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new GuiSettings(/** @type {Partial<GuiSettings>} */($$parsedSource));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ShortClient 与前端结构对应
|
||||
*/
|
||||
export class ShortClient {
|
||||
/**
|
||||
* Creates a new ShortClient instance.
|
||||
* @param {Partial<ShortClient>} [$$source = {}] - The source object to create the ShortClient.
|
||||
*/
|
||||
constructor($$source = {}) {
|
||||
if (!("name" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["name"] = "";
|
||||
}
|
||||
if (!("addr" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["addr"] = "";
|
||||
}
|
||||
if (!("key" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["key"] = "";
|
||||
}
|
||||
if (!("tls" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {boolean}
|
||||
*/
|
||||
this["tls"] = false;
|
||||
}
|
||||
if (!("running" in $$source)) {
|
||||
/**
|
||||
* 兼容旧版本,实际用Status
|
||||
* @member
|
||||
* @type {boolean}
|
||||
*/
|
||||
this["running"] = false;
|
||||
}
|
||||
if (!("error" in $$source)) {
|
||||
/**
|
||||
* 连接错误信息
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["error"] = "";
|
||||
}
|
||||
if (!("status" in $$source)) {
|
||||
/**
|
||||
* 连接状态: "stopped", "connecting", "connected"
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["status"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ShortClient instance from a string or object.
|
||||
* @param {any} [$$source = {}]
|
||||
* @returns {ShortClient}
|
||||
*/
|
||||
static createFrom($$source = {}) {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new ShortClient(/** @type {Partial<ShortClient>} */($$parsedSource));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* UpdateInfo 版本检查结果,供前端展示
|
||||
*/
|
||||
export class UpdateInfo {
|
||||
/**
|
||||
* Creates a new UpdateInfo instance.
|
||||
* @param {Partial<UpdateInfo>} [$$source = {}] - The source object to create the UpdateInfo.
|
||||
*/
|
||||
constructor($$source = {}) {
|
||||
if (!("currentVersion" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["currentVersion"] = "";
|
||||
}
|
||||
if (!("latestVersion" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["latestVersion"] = "";
|
||||
}
|
||||
if (!("updateAvailable" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {boolean}
|
||||
*/
|
||||
this["updateAvailable"] = false;
|
||||
}
|
||||
if (!("releaseNotes" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["releaseNotes"] = "";
|
||||
}
|
||||
if (!("publishedAt" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["publishedAt"] = "";
|
||||
}
|
||||
if (!("downloadUrl" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["downloadUrl"] = "";
|
||||
}
|
||||
if (!("assetName" in $$source)) {
|
||||
/**
|
||||
* @member
|
||||
* @type {string}
|
||||
*/
|
||||
this["assetName"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new UpdateInfo instance from a string or object.
|
||||
* @param {any} [$$source = {}]
|
||||
* @returns {UpdateInfo}
|
||||
*/
|
||||
static createFrom($$source = {}) {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new UpdateInfo(/** @type {Partial<UpdateInfo>} */($$parsedSource));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>NPS 客户端</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "npc-client",
|
||||
"packageManager": "yarn@1.22.22",
|
||||
"type": "module",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"build:dev": "vite build --minify false --mode development",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wailsio/runtime": "^3.0.0-beta.12",
|
||||
"vue": "^3.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^4.2.3",
|
||||
"vite": "^4.3.9"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
@@ -0,0 +1,17 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
// 必须绑定 IPv4 回环地址:Wails 应用通过 127.0.0.1 代理请求 dev server,
|
||||
// vite 默认只监听 ::1(IPv6)会导致 502
|
||||
host: '127.0.0.1',
|
||||
port: Number(process.env.WAILS_VITE_PORT) || 34115,
|
||||
strictPort: true
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist'
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,342 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@babel/helper-string-parser@^7.29.7":
|
||||
version "7.29.7"
|
||||
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz#7f0871d99824d23137d60f86fcf6130fd5a1b51f"
|
||||
integrity sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==
|
||||
|
||||
"@babel/helper-validator-identifier@^7.29.7":
|
||||
version "7.29.7"
|
||||
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz#bd87084ced0c796ec46bda492de6e83d29e89fc2"
|
||||
integrity sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==
|
||||
|
||||
"@babel/parser@^7.29.8":
|
||||
version "7.29.8"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.29.8.tgz#9653716a2f10c677b98fbc63d4bfb000c302cf17"
|
||||
integrity sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA==
|
||||
dependencies:
|
||||
"@babel/types" "^7.29.8"
|
||||
|
||||
"@babel/types@^7.29.8":
|
||||
version "7.29.8"
|
||||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.29.8.tgz#1229eef31d85156d70fa3f4cd859376d0eaf6863"
|
||||
integrity sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==
|
||||
dependencies:
|
||||
"@babel/helper-string-parser" "^7.29.7"
|
||||
"@babel/helper-validator-identifier" "^7.29.7"
|
||||
|
||||
"@esbuild/android-arm64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.18.20.tgz#984b4f9c8d0377443cc2dfcef266d02244593622"
|
||||
integrity sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==
|
||||
|
||||
"@esbuild/android-arm@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.18.20.tgz#fedb265bc3a589c84cc11f810804f234947c3682"
|
||||
integrity sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==
|
||||
|
||||
"@esbuild/android-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/android-x64/-/android-x64-0.18.20.tgz#35cf419c4cfc8babe8893d296cd990e9e9f756f2"
|
||||
integrity sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==
|
||||
|
||||
"@esbuild/darwin-arm64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz#08172cbeccf95fbc383399a7f39cfbddaeb0d7c1"
|
||||
integrity sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==
|
||||
|
||||
"@esbuild/darwin-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/darwin-x64/-/darwin-x64-0.18.20.tgz#d70d5790d8bf475556b67d0f8b7c5bdff053d85d"
|
||||
integrity sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==
|
||||
|
||||
"@esbuild/freebsd-arm64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.20.tgz#98755cd12707f93f210e2494d6a4b51b96977f54"
|
||||
integrity sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==
|
||||
|
||||
"@esbuild/freebsd-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/freebsd-x64/-/freebsd-x64-0.18.20.tgz#c1eb2bff03915f87c29cece4c1a7fa1f423b066e"
|
||||
integrity sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==
|
||||
|
||||
"@esbuild/linux-arm64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-arm64/-/linux-arm64-0.18.20.tgz#bad4238bd8f4fc25b5a021280c770ab5fc3a02a0"
|
||||
integrity sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==
|
||||
|
||||
"@esbuild/linux-arm@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-arm/-/linux-arm-0.18.20.tgz#3e617c61f33508a27150ee417543c8ab5acc73b0"
|
||||
integrity sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==
|
||||
|
||||
"@esbuild/linux-ia32@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-ia32/-/linux-ia32-0.18.20.tgz#699391cccba9aee6019b7f9892eb99219f1570a7"
|
||||
integrity sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==
|
||||
|
||||
"@esbuild/linux-loong64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.18.20.tgz#e6fccb7aac178dd2ffb9860465ac89d7f23b977d"
|
||||
integrity sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==
|
||||
|
||||
"@esbuild/linux-mips64el@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-mips64el/-/linux-mips64el-0.18.20.tgz#eeff3a937de9c2310de30622a957ad1bd9183231"
|
||||
integrity sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==
|
||||
|
||||
"@esbuild/linux-ppc64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-ppc64/-/linux-ppc64-0.18.20.tgz#2f7156bde20b01527993e6881435ad79ba9599fb"
|
||||
integrity sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==
|
||||
|
||||
"@esbuild/linux-riscv64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-riscv64/-/linux-riscv64-0.18.20.tgz#6628389f210123d8b4743045af8caa7d4ddfc7a6"
|
||||
integrity sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==
|
||||
|
||||
"@esbuild/linux-s390x@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-s390x/-/linux-s390x-0.18.20.tgz#255e81fb289b101026131858ab99fba63dcf0071"
|
||||
integrity sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==
|
||||
|
||||
"@esbuild/linux-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz#c7690b3417af318a9b6f96df3031a8865176d338"
|
||||
integrity sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==
|
||||
|
||||
"@esbuild/netbsd-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/netbsd-x64/-/netbsd-x64-0.18.20.tgz#30e8cd8a3dded63975e2df2438ca109601ebe0d1"
|
||||
integrity sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==
|
||||
|
||||
"@esbuild/openbsd-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/openbsd-x64/-/openbsd-x64-0.18.20.tgz#7812af31b205055874c8082ea9cf9ab0da6217ae"
|
||||
integrity sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==
|
||||
|
||||
"@esbuild/sunos-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/sunos-x64/-/sunos-x64-0.18.20.tgz#d5c275c3b4e73c9b0ecd38d1ca62c020f887ab9d"
|
||||
integrity sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==
|
||||
|
||||
"@esbuild/win32-arm64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/win32-arm64/-/win32-arm64-0.18.20.tgz#73bc7f5a9f8a77805f357fab97f290d0e4820ac9"
|
||||
integrity sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==
|
||||
|
||||
"@esbuild/win32-ia32@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/win32-ia32/-/win32-ia32-0.18.20.tgz#ec93cbf0ef1085cc12e71e0d661d20569ff42102"
|
||||
integrity sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==
|
||||
|
||||
"@esbuild/win32-x64@0.18.20":
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz#786c5f41f043b07afb1af37683d7c33668858f6d"
|
||||
integrity sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==
|
||||
|
||||
"@jridgewell/sourcemap-codec@^1.5.5":
|
||||
version "1.5.5"
|
||||
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz#6912b00d2c631c0d15ce1a7ab57cd657f2a8f8ba"
|
||||
integrity sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==
|
||||
|
||||
"@vitejs/plugin-vue@^4.2.3":
|
||||
version "4.6.2"
|
||||
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-4.6.2.tgz#057d2ded94c4e71b94e9814f92dcd9306317aa46"
|
||||
integrity sha512-kqf7SGFoG+80aZG6Pf+gsZIVvGSCKE98JbiWqcCV9cThtg91Jav0yvYFC9Zb+jKetNGF6ZKeoaxgZfND21fWKw==
|
||||
|
||||
"@vue/compiler-core@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.5.41.tgz#82a4012d8b420f5a62c1658a72d16f7d1edf11aa"
|
||||
integrity sha512-q0Xtv/F9w2YO/7htQhtiL+Ev2WCJbe5N2hc+XfgyKkEKqWpSxknmT8QOuGdEKNdjPq0c3F7rNpFkTo3Kfrm7pg==
|
||||
dependencies:
|
||||
"@babel/parser" "^7.29.8"
|
||||
"@vue/shared" "3.5.41"
|
||||
entities "^7.0.1"
|
||||
estree-walker "^2.0.2"
|
||||
source-map-js "^1.2.1"
|
||||
|
||||
"@vue/compiler-dom@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.5.41.tgz#1029f75de09c665a0a92c6156463754192acb361"
|
||||
integrity sha512-oKacVfNglLvGjnS6BXOlGL7EyG2h8X03pqXCjzotRZUaXGjbrTJUnVAQjrCqUnS+lyu31nwQjZY/d817GmCnfw==
|
||||
dependencies:
|
||||
"@vue/compiler-core" "3.5.41"
|
||||
"@vue/shared" "3.5.41"
|
||||
|
||||
"@vue/compiler-sfc@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.5.41.tgz#f9c7c2170ad6ee4bf35c178b5df026485d8a63db"
|
||||
integrity sha512-XJhip7R2wy6vX3knCxdZN4KracFaZUef58s1KYewqluedHIJaPIVfXoYT7MF1F8nCvv6k8bWWxDC8opMkg1VTQ==
|
||||
dependencies:
|
||||
"@babel/parser" "^7.29.8"
|
||||
"@vue/compiler-core" "3.5.41"
|
||||
"@vue/compiler-dom" "3.5.41"
|
||||
"@vue/compiler-ssr" "3.5.41"
|
||||
"@vue/shared" "3.5.41"
|
||||
estree-walker "^2.0.2"
|
||||
magic-string "^0.30.21"
|
||||
postcss "^8.5.19"
|
||||
source-map-js "^1.2.1"
|
||||
|
||||
"@vue/compiler-ssr@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.5.41.tgz#8e5f9f6a8d21b802fce7373807dd935ed4541083"
|
||||
integrity sha512-U3v5OejKEGqOI0Wy0+Sz7hGuIFZHA4LSXzrNM3IMIeDyJEBBfTpX26n3SDgToRpP2bLc9FfI2j/kSgcJ8Emq5A==
|
||||
dependencies:
|
||||
"@vue/compiler-dom" "3.5.41"
|
||||
"@vue/shared" "3.5.41"
|
||||
|
||||
"@vue/reactivity@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.5.41.tgz#83be61b88b198f21c157d3aa6dcb843a25a11872"
|
||||
integrity sha512-rznsqKM0np0x18EjzF8x88MpEhdNsffbvFbckLL5+oUKz1BxAImEmO7J1ArRYSyo6aQaVoBDp7jEkT91OOxydA==
|
||||
dependencies:
|
||||
"@vue/shared" "3.5.41"
|
||||
|
||||
"@vue/runtime-core@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.5.41.tgz#a3e023c9f21809c81f24813dacb7ffa18a2e4161"
|
||||
integrity sha512-Vcry58hiAKwGen9Z1jUZE0feFsNArPCMOImYI8el48A9Idf6DuQYD0U05zZIF2Iad1hGhPSvcbBbAOhNr55fhg==
|
||||
dependencies:
|
||||
"@vue/reactivity" "3.5.41"
|
||||
"@vue/shared" "3.5.41"
|
||||
|
||||
"@vue/runtime-dom@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.5.41.tgz#428f7a0420402385fae17d413d25169f98f64205"
|
||||
integrity sha512-3vVBahVBS9+U6cmXBLyb8nE6/yYo4J/CGI9eVFs3KiMc0YHuudwKyShTD65jtJy/L9PUUxNAFu4cj4LiJ0UFbw==
|
||||
dependencies:
|
||||
"@vue/reactivity" "3.5.41"
|
||||
"@vue/runtime-core" "3.5.41"
|
||||
"@vue/shared" "3.5.41"
|
||||
csstype "^3.2.3"
|
||||
|
||||
"@vue/server-renderer@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/server-renderer/-/server-renderer-3.5.41.tgz#035a38c79182f154495238ea83acba24266ac200"
|
||||
integrity sha512-n6hx/pNFfbD6SuyeuMVkvqox8bwf/ET9JlA/kAz/imw8sw++wkqKe2mHX5KutjPpbKE4Z56yTHszoOjGMI9igQ==
|
||||
dependencies:
|
||||
"@vue/compiler-ssr" "3.5.41"
|
||||
"@vue/runtime-dom" "3.5.41"
|
||||
"@vue/shared" "3.5.41"
|
||||
|
||||
"@vue/shared@3.5.41":
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.5.41.tgz#ac476497f74495f7525087270849841756555cf2"
|
||||
integrity sha512-IOnwSCma8j+9xJT6b8H0dEYidC80NsYmNMlZxRsukYcSoGaDBohog5hDxzeUXdFeGWFA++vWvxqOmrr96VlqMA==
|
||||
|
||||
"@wailsio/runtime@^3.0.0-beta.12":
|
||||
version "3.0.0-beta.12"
|
||||
resolved "https://registry.yarnpkg.com/@wailsio/runtime/-/runtime-3.0.0-beta.12.tgz#0fb8347441271fae40f59641fd9f66b56561b5bc"
|
||||
integrity sha512-2B456rspX5rDXYhNjRqXNDOPkRXjletGJ4R3beF2FGs7K67MTovLy9acXHYb8nolzL96kygyJ622RIjB45oumg==
|
||||
|
||||
csstype@^3.2.3:
|
||||
version "3.2.3"
|
||||
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.2.3.tgz#ec48c0f3e993e50648c86da559e2610995cf989a"
|
||||
integrity sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==
|
||||
|
||||
entities@^7.0.1:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/entities/-/entities-7.0.1.tgz#26e8a88889db63417dcb9a1e79a3f1bc92b5976b"
|
||||
integrity sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==
|
||||
|
||||
esbuild@^0.18.10:
|
||||
version "0.18.20"
|
||||
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.18.20.tgz#4709f5a34801b43b799ab7d6d82f7284a9b7a7a6"
|
||||
integrity sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==
|
||||
optionalDependencies:
|
||||
"@esbuild/android-arm" "0.18.20"
|
||||
"@esbuild/android-arm64" "0.18.20"
|
||||
"@esbuild/android-x64" "0.18.20"
|
||||
"@esbuild/darwin-arm64" "0.18.20"
|
||||
"@esbuild/darwin-x64" "0.18.20"
|
||||
"@esbuild/freebsd-arm64" "0.18.20"
|
||||
"@esbuild/freebsd-x64" "0.18.20"
|
||||
"@esbuild/linux-arm" "0.18.20"
|
||||
"@esbuild/linux-arm64" "0.18.20"
|
||||
"@esbuild/linux-ia32" "0.18.20"
|
||||
"@esbuild/linux-loong64" "0.18.20"
|
||||
"@esbuild/linux-mips64el" "0.18.20"
|
||||
"@esbuild/linux-ppc64" "0.18.20"
|
||||
"@esbuild/linux-riscv64" "0.18.20"
|
||||
"@esbuild/linux-s390x" "0.18.20"
|
||||
"@esbuild/linux-x64" "0.18.20"
|
||||
"@esbuild/netbsd-x64" "0.18.20"
|
||||
"@esbuild/openbsd-x64" "0.18.20"
|
||||
"@esbuild/sunos-x64" "0.18.20"
|
||||
"@esbuild/win32-arm64" "0.18.20"
|
||||
"@esbuild/win32-ia32" "0.18.20"
|
||||
"@esbuild/win32-x64" "0.18.20"
|
||||
|
||||
estree-walker@^2.0.2:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac"
|
||||
integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==
|
||||
|
||||
fsevents@~2.3.2:
|
||||
version "2.3.3"
|
||||
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
|
||||
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
|
||||
|
||||
magic-string@^0.30.21:
|
||||
version "0.30.21"
|
||||
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.21.tgz#56763ec09a0fa8091df27879fd94d19078c00d91"
|
||||
integrity sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==
|
||||
dependencies:
|
||||
"@jridgewell/sourcemap-codec" "^1.5.5"
|
||||
|
||||
nanoid@^3.3.17:
|
||||
version "3.3.18"
|
||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.18.tgz#f66a2de1199ffde0fcf21c8a5f13106b1c081913"
|
||||
integrity sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==
|
||||
|
||||
picocolors@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
|
||||
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==
|
||||
|
||||
postcss@^8.4.27, postcss@^8.5.19:
|
||||
version "8.5.26"
|
||||
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.5.26.tgz#6e75135780c7e10df3433bf2266c552d35c8c620"
|
||||
integrity sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==
|
||||
dependencies:
|
||||
nanoid "^3.3.17"
|
||||
picocolors "^1.1.1"
|
||||
source-map-js "^1.2.1"
|
||||
|
||||
rollup@^3.27.1:
|
||||
version "3.30.0"
|
||||
resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.30.0.tgz#3fa506fee2c5ba9d540a38da87067376cd55966d"
|
||||
integrity sha512-kQvGasUgN+AlWGliFn2POSajRQEsULVYFGTvOZmK06d7vCD+YhZztt70kGk3qaeAXeWYL5eO7zx+rAubBc55eA==
|
||||
optionalDependencies:
|
||||
fsevents "~2.3.2"
|
||||
|
||||
source-map-js@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.1.tgz#1ce5650fddd87abc099eda37dcff024c2667ae46"
|
||||
integrity sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==
|
||||
|
||||
vite@^4.3.9:
|
||||
version "4.5.14"
|
||||
resolved "https://registry.yarnpkg.com/vite/-/vite-4.5.14.tgz#2e652bc1d898265d987d6543ce866ecd65fa4086"
|
||||
integrity sha512-+v57oAaoYNnO3hIu5Z/tJRZjq5aHM2zDve9YZ8HngVHbhk66RStobhb1sqPMIPEleV6cNKYK4eGrAbE9Ulbl2g==
|
||||
dependencies:
|
||||
esbuild "^0.18.10"
|
||||
postcss "^8.4.27"
|
||||
rollup "^3.27.1"
|
||||
optionalDependencies:
|
||||
fsevents "~2.3.2"
|
||||
|
||||
vue@^3.3.4:
|
||||
version "3.5.41"
|
||||
resolved "https://registry.yarnpkg.com/vue/-/vue-3.5.41.tgz#8864bddfe59ce128a28c9bad219cd9248916af73"
|
||||
integrity sha512-2laE0p+aK+/AOPG/XL/WepOs/GlK755LJ1XECi9kDUrz1FKNw8rb2Xzlw9JS1rqEV55nb0ttsKxVlTCcd+R5cg==
|
||||
dependencies:
|
||||
"@vue/compiler-dom" "3.5.41"
|
||||
"@vue/compiler-sfc" "3.5.41"
|
||||
"@vue/runtime-dom" "3.5.41"
|
||||
"@vue/server-renderer" "3.5.41"
|
||||
"@vue/shared" "3.5.41"
|
||||
@@ -0,0 +1,53 @@
|
||||
module npc-gui
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
ehang.io/nps v0.0.0-00010101000000-000000000000
|
||||
github.com/astaxie/beego v1.12.3
|
||||
github.com/wailsapp/wails/v3 v3.0.0-beta.12
|
||||
golang.org/x/sys v0.46.0
|
||||
)
|
||||
|
||||
// 使用本地路径替代依赖
|
||||
replace (
|
||||
ehang.io/nps => ../../..
|
||||
github.com/astaxie/beego => github.com/exfly/beego v1.12.0-export-init
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/adrg/xdg v0.5.3 // indirect
|
||||
github.com/coder/websocket v1.8.14 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/godbus/dbus/v5 v5.2.2 // indirect
|
||||
github.com/golang/snappy v0.0.3 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/jchv/go-winloader v0.0.0-20250406163304-c1995be93bd1 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/klauspost/reedsolomon v1.9.12 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/panjf2000/ants/v2 v2.4.2 // indirect
|
||||
github.com/pires/go-proxyproto v0.8.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
|
||||
github.com/shirou/gopsutil/v3 v3.23.10 // indirect
|
||||
github.com/shoenig/go-m1cpu v0.2.2 // indirect
|
||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
|
||||
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
|
||||
github.com/tjfoc/gmsm v1.4.0 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||
github.com/xtaci/kcp-go v5.4.20+incompatible // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
golang.org/x/crypto v0.53.0 // indirect
|
||||
golang.org/x/net v0.56.0 // indirect
|
||||
golang.org/x/text v0.39.0 // indirect
|
||||
golang.org/x/time v0.14.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
@@ -0,0 +1,224 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
|
||||
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
|
||||
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
|
||||
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
|
||||
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
|
||||
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
|
||||
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
|
||||
github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U=
|
||||
github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
|
||||
github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/exfly/beego v1.12.0-export-init h1:VQNYKdXhAwZGUaFmQv8Aj921O3rQJZRIF8xeGrhsjrI=
|
||||
github.com/exfly/beego v1.12.0-export-init/go.mod h1:fysx+LZNZKnvh4GED/xND7jWtjCR6HzydR2Hh2Im57o=
|
||||
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e h1:Lf/gRkoycfOBPa42vU2bbgPurFong6zXeFtPoxholzU=
|
||||
github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e/go.mod h1:uNVvRXArCGbZ508SxYYTC5v1JWoz2voff5pm25jU1Ok=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ=
|
||||
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
|
||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jchv/go-winloader v0.0.0-20250406163304-c1995be93bd1 h1:njuLRcjAuMKr7kI3D85AXWkw6/+v9PwtV6M6o11sWHQ=
|
||||
github.com/jchv/go-winloader v0.0.0-20250406163304-c1995be93bd1/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
|
||||
github.com/klauspost/cpuid/v2 v2.0.2/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/klauspost/reedsolomon v1.9.12 h1:EyOucRmcrLH+2hqKGdoA5SM8pwPKR6BJsf3r6zpYOA0=
|
||||
github.com/klauspost/reedsolomon v1.9.12/go.mod h1:nLvuzNvy1ZDNQW30IuMc2ZWCbiqrJgdLoUS2X8HAUVg=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
|
||||
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/panjf2000/ants/v2 v2.4.2 h1:kesjjo8JipN3vNNg1XaiXaeSs6xJweBTgenkBtsrHf8=
|
||||
github.com/panjf2000/ants/v2 v2.4.2/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pires/go-proxyproto v0.8.0 h1:5unRmEAPbHXHuLjDg01CxJWf91cw3lKHc/0xzKpXEe0=
|
||||
github.com/pires/go-proxyproto v0.8.0/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
|
||||
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
|
||||
github.com/shirou/gopsutil/v3 v3.23.10 h1:/N42opWlYzegYaVkWejXWJpbzKv2JDy3mrgGzKsh9hM=
|
||||
github.com/shirou/gopsutil/v3 v3.23.10/go.mod h1:JIE26kpucQi+innVlAUnIEOSBhBUkirr5b44yr55+WE=
|
||||
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
|
||||
github.com/shoenig/go-m1cpu v0.2.2 h1:4nc55oVv7nygGnfI9bhLCLzUEs4794y0Bkqx4q2zy7Y=
|
||||
github.com/shoenig/go-m1cpu v0.2.2/go.mod h1:KkDOw6m3ZJQAPHbrzkZki4hnx+pDRR1Lo+ldA56wD5w=
|
||||
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
|
||||
github.com/shoenig/test v1.7.0 h1:eWcHtTXa6QLnBvm0jgEabMRN/uJ4DMV3M8xUGgRkZmk=
|
||||
github.com/shoenig/test v1.7.0/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI=
|
||||
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
|
||||
github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=
|
||||
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
|
||||
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
|
||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7SJEOqkIdNDGJXrQIhuIx9D2DBXjavSU=
|
||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
|
||||
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b h1:fj5tQ8acgNUr6O8LEplsxDhUIe2573iLkJc+PqnzZTI=
|
||||
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
|
||||
github.com/tjfoc/gmsm v1.4.0 h1:8nbaiZG+iVdh+fXVw0DZoZZa7a4TGm3Qab+xdrdzj8s=
|
||||
github.com/tjfoc/gmsm v1.4.0/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
|
||||
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
||||
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
||||
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
|
||||
github.com/wailsapp/wails/v3 v3.0.0-beta.12 h1:Vema2kFgJvkwPovQ8GMBBrkZNm5cKVR4bYzSCMgU+PU=
|
||||
github.com/wailsapp/wails/v3 v3.0.0-beta.12/go.mod h1:zKZYhB3WjrN5LhJWbnOAVMN0Xf8qTozbw2nf5micKl4=
|
||||
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
|
||||
github.com/xtaci/kcp-go v5.4.20+incompatible h1:TN1uey3Raw0sTz0Fg8GkfM0uH3YwzhnZWQ1bABv5xAg=
|
||||
github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE=
|
||||
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae h1:J0GxkO96kL4WF+AIT3M4mfUVinOCPgf2uUWYFUzN0sM=
|
||||
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE=
|
||||
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
|
||||
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
|
||||
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
||||
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus=
|
||||
golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM=
|
||||
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
|
||||
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
@@ -0,0 +1,310 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
)
|
||||
|
||||
const (
|
||||
// logBufferCap 每个客户端内存中最多保留的日志条数
|
||||
logBufferCap = 3000
|
||||
// logFileMaxSize 单个日志文件超过该大小后轮转(5MB)
|
||||
logFileMaxSize = 5 << 20
|
||||
// logFileMaxBackups 轮转时最多保留的历史文件个数(.1 .2 .3)
|
||||
logFileMaxBackups = 3
|
||||
)
|
||||
|
||||
// initAppLogger 初始化 GUI 自身的日志系统。
|
||||
// - 全局 beego logger 仍切到 store,避免客户端库的全局日志刷屏控制台(保持原有行为)
|
||||
// - 应用自身日志使用 slog(JSON),同时写入 logs/npc-gui.log 与控制台
|
||||
func initAppLogger() {
|
||||
_ = logs.SetLogger("store")
|
||||
logs.SetLevel(logs.LevelDebug)
|
||||
|
||||
var w io.Writer = os.Stderr
|
||||
if fw, err := newRotatingFileWriter(filepath.Join(getLogsPath(), "npc-gui.log")); err == nil {
|
||||
w = io.MultiWriter(fw, os.Stderr)
|
||||
}
|
||||
logger := slog.New(slog.NewJSONHandler(w, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
||||
slog.SetDefault(logger)
|
||||
}
|
||||
|
||||
// rotatingFileWriter 带大小轮转的日志文件写入器(线程安全)。
|
||||
// 写入超过 maxSize 时把当前文件顺延为 .1 .2 ...,保留 maxBackups 份历史。
|
||||
type rotatingFileWriter struct {
|
||||
mu sync.Mutex
|
||||
path string
|
||||
maxSize int64
|
||||
maxBackups int
|
||||
file *os.File
|
||||
size int64
|
||||
}
|
||||
|
||||
func newRotatingFileWriter(path string) (*rotatingFileWriter, error) {
|
||||
w := &rotatingFileWriter{path: path, maxSize: logFileMaxSize, maxBackups: logFileMaxBackups}
|
||||
if err := w.open(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func (w *rotatingFileWriter) open() error {
|
||||
f, err := os.OpenFile(w.path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
st, err := f.Stat()
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
w.file = f
|
||||
w.size = st.Size()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *rotatingFileWriter) Write(p []byte) (int, error) {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
if w.file == nil {
|
||||
if err := w.open(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
if w.size > 0 && w.size+int64(len(p)) > w.maxSize {
|
||||
w.rotateLocked()
|
||||
}
|
||||
n, err := w.file.Write(p)
|
||||
w.size += int64(n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (w *rotatingFileWriter) rotateLocked() {
|
||||
_ = w.file.Close()
|
||||
w.file = nil
|
||||
for i := w.maxBackups - 1; i >= 1; i-- {
|
||||
src := fmt.Sprintf("%s.%d", w.path, i)
|
||||
if _, err := os.Stat(src); err == nil {
|
||||
_ = os.Remove(fmt.Sprintf("%s.%d", w.path, i+1))
|
||||
_ = os.Rename(src, fmt.Sprintf("%s.%d", w.path, i+1))
|
||||
}
|
||||
}
|
||||
_ = os.Remove(w.path + ".1")
|
||||
_ = os.Rename(w.path, w.path+".1")
|
||||
w.size = 0
|
||||
_ = w.open()
|
||||
}
|
||||
|
||||
// truncate 清空当前文件内容
|
||||
func (w *rotatingFileWriter) truncate() error {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
if w.file != nil {
|
||||
_ = w.file.Close()
|
||||
w.file = nil
|
||||
}
|
||||
f, err := os.Create(w.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.file = f
|
||||
w.size = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *rotatingFileWriter) Close() error {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
if w.file != nil {
|
||||
err := w.file.Close()
|
||||
w.file = nil
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ringBuffer 固定容量的环形日志缓冲
|
||||
type ringBuffer struct {
|
||||
buf []ConnectionLog
|
||||
start int
|
||||
count int
|
||||
}
|
||||
|
||||
func newRingBuffer(cap int) *ringBuffer {
|
||||
return &ringBuffer{buf: make([]ConnectionLog, cap)}
|
||||
}
|
||||
|
||||
func (r *ringBuffer) add(e ConnectionLog) {
|
||||
if r.count == len(r.buf) {
|
||||
r.buf[r.start] = e
|
||||
r.start = (r.start + 1) % len(r.buf)
|
||||
} else {
|
||||
r.buf[(r.start+r.count)%len(r.buf)] = e
|
||||
r.count++
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ringBuffer) all() []ConnectionLog {
|
||||
out := make([]ConnectionLog, 0, r.count)
|
||||
for i := 0; i < r.count; i++ {
|
||||
out = append(out, r.buf[(r.start+i)%len(r.buf)])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (r *ringBuffer) reset() {
|
||||
r.start = 0
|
||||
r.count = 0
|
||||
}
|
||||
|
||||
// clientLogStore 单个客户端的日志存储:内存环形缓冲 + JSON Lines 文件持久化。
|
||||
// UI 直接读取内存缓冲,不再解析日志文件文本。
|
||||
type clientLogStore struct {
|
||||
mu sync.Mutex
|
||||
clientId string
|
||||
ring *ringBuffer
|
||||
file *rotatingFileWriter
|
||||
}
|
||||
|
||||
func newClientLogStore(clientId string) *clientLogStore {
|
||||
s := &clientLogStore{
|
||||
clientId: clientId,
|
||||
ring: newRingBuffer(logBufferCap),
|
||||
}
|
||||
if fw, err := newRotatingFileWriter(getClientLogFilePath(clientId)); err == nil {
|
||||
s.file = fw
|
||||
s.loadHistoryLocked()
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// loadHistoryLocked 启动时把已有日志文件尾部的 JSON 行载入内存缓冲(跨重启保留历史)。
|
||||
func (s *clientLogStore) loadHistoryLocked() {
|
||||
data, err := os.ReadFile(s.file.path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sc := bufio.NewScanner(strings.NewReader(string(data)))
|
||||
sc.Buffer(make([]byte, 1024*1024), 1024*1024)
|
||||
var lines []string
|
||||
for sc.Scan() {
|
||||
line := strings.TrimSpace(sc.Text())
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
lines = append(lines, line)
|
||||
}
|
||||
if len(lines) > logBufferCap {
|
||||
lines = lines[len(lines)-logBufferCap:]
|
||||
}
|
||||
for _, line := range lines {
|
||||
var e ConnectionLog
|
||||
if json.Unmarshal([]byte(line), &e) == nil && e.Message != "" {
|
||||
s.ring.add(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log 写入一条日志:先入内存缓冲,再持久化到 JSON Lines 文件。
|
||||
func (s *clientLogStore) log(level, format string, v ...interface{}) {
|
||||
msg := fmt.Sprintf(format, v...)
|
||||
logType := level
|
||||
if level == "info" && isSuccessMessage(msg) {
|
||||
logType = "success"
|
||||
}
|
||||
e := ConnectionLog{
|
||||
Timestamp: time.Now().Format("2006-01-02 15:04:05"),
|
||||
Message: msg,
|
||||
Type: logType,
|
||||
ClientId: s.clientId,
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.ring.add(e)
|
||||
if s.file != nil {
|
||||
if line, err := json.Marshal(e); err == nil {
|
||||
_, _ = s.file.Write(append(line, '\n'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *clientLogStore) snapshot() []ConnectionLog {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.ring.all()
|
||||
}
|
||||
|
||||
func (s *clientLogStore) clear() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.ring.reset()
|
||||
if s.file != nil {
|
||||
return s.file.truncate()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *clientLogStore) close() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.file != nil {
|
||||
_ = s.file.Close()
|
||||
s.file = nil
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
logStoresMu sync.Mutex
|
||||
logStores = make(map[string]*clientLogStore)
|
||||
)
|
||||
|
||||
// getClientLogStore 获取客户端的日志存储(懒创建,未启动也能查看历史日志)
|
||||
func getClientLogStore(clientId string) *clientLogStore {
|
||||
logStoresMu.Lock()
|
||||
defer logStoresMu.Unlock()
|
||||
if s, ok := logStores[clientId]; ok {
|
||||
return s
|
||||
}
|
||||
s := newClientLogStore(clientId)
|
||||
logStores[clientId] = s
|
||||
return s
|
||||
}
|
||||
|
||||
// closeAllLogStores 应用退出时关闭所有日志文件
|
||||
func closeAllLogStores() {
|
||||
logStoresMu.Lock()
|
||||
defer logStoresMu.Unlock()
|
||||
for id, s := range logStores {
|
||||
s.close()
|
||||
delete(logStores, id)
|
||||
}
|
||||
}
|
||||
|
||||
// trpcLogger 把 client.Logger 桥接到 clientLogStore,供 TRPClient 使用。
|
||||
// Trace 级别与原先 beego(LevelDebug) 行为一致,不落盘。
|
||||
type trpcLogger struct {
|
||||
store *clientLogStore
|
||||
}
|
||||
|
||||
func (l *trpcLogger) Info(format string, v ...interface{}) { l.store.log("info", format, v...) }
|
||||
func (l *trpcLogger) Error(format string, v ...interface{}) { l.store.log("error", format, v...) }
|
||||
func (l *trpcLogger) Warn(format string, v ...interface{}) { l.store.log("warning", format, v...) }
|
||||
func (l *trpcLogger) Trace(format string, v ...interface{}) {}
|
||||
|
||||
// isSuccessMessage 判断是否为“成功”类日志(用于 UI 高亮)
|
||||
func isSuccessMessage(msg string) bool {
|
||||
lower := strings.ToLower(msg)
|
||||
return strings.Contains(msg, "成功") ||
|
||||
strings.Contains(lower, "success") ||
|
||||
strings.Contains(lower, "connected")
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRingBuffer(t *testing.T) {
|
||||
r := newRingBuffer(3)
|
||||
r.add(ConnectionLog{Message: "1"})
|
||||
r.add(ConnectionLog{Message: "2"})
|
||||
r.add(ConnectionLog{Message: "3"})
|
||||
r.add(ConnectionLog{Message: "4"})
|
||||
all := r.all()
|
||||
if len(all) != 3 || all[0].Message != "2" || all[2].Message != "4" {
|
||||
t.Fatalf("unexpected ring buffer contents: %v", all)
|
||||
}
|
||||
r.reset()
|
||||
if len(r.all()) != 0 {
|
||||
t.Fatal("reset failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRotatingFileWriterRotation(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "test.log")
|
||||
w, err := newRotatingFileWriter(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer w.Close()
|
||||
w.maxSize = 10
|
||||
w.maxBackups = 2
|
||||
for i := 0; i < 20; i++ {
|
||||
if _, err := w.Write([]byte("0123456789\n")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(path + ".1"); err != nil {
|
||||
t.Fatal("missing .1 backup:", err)
|
||||
}
|
||||
if _, err := os.Stat(path + ".2"); err != nil {
|
||||
t.Fatal("missing .2 backup:", err)
|
||||
}
|
||||
if err := w.truncate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if st, err := os.Stat(path); err != nil || st.Size() != 0 {
|
||||
t.Fatal("truncate failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientLogStore(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "client.log")
|
||||
fw, err := newRotatingFileWriter(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := &clientLogStore{clientId: "test", ring: newRingBuffer(logBufferCap), file: fw}
|
||||
defer fw.Close()
|
||||
|
||||
store.log("info", "hello %s", "world")
|
||||
store.log("error", "boom")
|
||||
store.log("info", "连接成功")
|
||||
|
||||
snap := store.snapshot()
|
||||
if len(snap) != 3 {
|
||||
t.Fatalf("expected 3 logs, got %d", len(snap))
|
||||
}
|
||||
if snap[0].Type != "info" || snap[0].Message != "hello world" {
|
||||
t.Fatalf("bad entry: %+v", snap[0])
|
||||
}
|
||||
if snap[1].Type != "error" {
|
||||
t.Fatalf("bad type: %+v", snap[1])
|
||||
}
|
||||
if snap[2].Type != "success" {
|
||||
t.Fatalf("expected success type, got %+v", snap[2])
|
||||
}
|
||||
|
||||
// 从文件恢复历史
|
||||
fw2, err := newRotatingFileWriter(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store2 := &clientLogStore{clientId: "test", ring: newRingBuffer(logBufferCap), file: fw2}
|
||||
defer fw2.Close()
|
||||
store2.loadHistoryLocked()
|
||||
snap2 := store2.snapshot()
|
||||
if len(snap2) != 3 {
|
||||
t.Fatalf("expected 3 logs after reload, got %d", len(snap2))
|
||||
}
|
||||
if snap2[0].Message != "hello world" || snap2[2].Type != "success" {
|
||||
t.Fatalf("bad reloaded entries: %+v", snap2)
|
||||
}
|
||||
|
||||
// 清空
|
||||
if err := store.clear(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(store.snapshot()) != 0 {
|
||||
t.Fatal("clear failed")
|
||||
}
|
||||
if st, err := os.Stat(path); err != nil || st.Size() != 0 {
|
||||
t.Fatal("file not truncated after clear")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSuccessMessage(t *testing.T) {
|
||||
cases := map[string]bool{
|
||||
"客户端连接成功": true,
|
||||
"Successful connection with server": true,
|
||||
"connection failed": false,
|
||||
"启动 NPC 客户端": false,
|
||||
}
|
||||
for msg, want := range cases {
|
||||
if got := isSuccessMessage(msg); got != want {
|
||||
t.Fatalf("isSuccessMessage(%q) = %v, want %v", msg, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
)
|
||||
|
||||
//go:embed all:frontend/dist
|
||||
var assets embed.FS
|
||||
|
||||
//go:embed build/appicon.png
|
||||
var trayIcon []byte
|
||||
|
||||
func main() {
|
||||
app := application.New(application.Options{
|
||||
Name: "NPS 客户端",
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
},
|
||||
Windows: application.WindowsOptions{
|
||||
DisableQuitOnLastWindowClosed: true,
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: false,
|
||||
},
|
||||
Linux: application.LinuxOptions{
|
||||
DisableQuitOnLastWindowClosed: true,
|
||||
},
|
||||
})
|
||||
|
||||
window := app.Window.NewWithOptions(application.WebviewWindowOptions{
|
||||
Name: "main",
|
||||
Title: "NPS 客户端",
|
||||
Width: 1000,
|
||||
Height: 600,
|
||||
MinWidth: 1000,
|
||||
MinHeight: 600,
|
||||
BackgroundColour: application.NewRGB(27, 38, 54),
|
||||
})
|
||||
|
||||
// 点击关闭按钮时隐藏窗口而不是退出(托盘应用常驻)
|
||||
window.RegisterHook(events.Common.WindowClosing, func(event *application.WindowEvent) {
|
||||
if isQuitting() {
|
||||
return
|
||||
}
|
||||
event.Cancel()
|
||||
window.Hide()
|
||||
})
|
||||
|
||||
app.RegisterService(application.NewService(NewApp(app, window)))
|
||||
|
||||
if runErr := app.Run(); runErr != nil {
|
||||
log.Fatal(runErr)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
//go:build darwin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
appName = "com.nps.client"
|
||||
plistFormat = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>%s</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>%s</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>KeepAlive</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>`
|
||||
)
|
||||
|
||||
// getLaunchAgentPath 获取 LaunchAgent plist 文件路径
|
||||
func getLaunchAgentPath() (string, error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
launchAgentsDir := filepath.Join(homeDir, "Library", "LaunchAgents")
|
||||
// 确保目录存在
|
||||
if err := os.MkdirAll(launchAgentsDir, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(launchAgentsDir, appName+".plist"), nil
|
||||
}
|
||||
|
||||
// enableStartupImpl macOS 平台的开机启动实现(使用 LaunchAgents)
|
||||
func enableStartupImpl() error {
|
||||
// 获取可执行文件路径
|
||||
exePath, err := getExecutablePath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取可执行文件路径失败: %v", err)
|
||||
}
|
||||
|
||||
// 获取 plist 文件路径
|
||||
plistPath, err := getLaunchAgentPath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取 LaunchAgent 路径失败: %v", err)
|
||||
}
|
||||
|
||||
// 生成 plist 内容
|
||||
plistContent := fmt.Sprintf(plistFormat, appName, exePath)
|
||||
|
||||
// 写入 plist 文件
|
||||
if err := os.WriteFile(plistPath, []byte(plistContent), 0644); err != nil {
|
||||
return fmt.Errorf("写入 plist 文件失败: %v", err)
|
||||
}
|
||||
|
||||
slog.Info("成功添加开机启动项", "app", appName, "path", plistPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
// disableStartupImpl macOS 平台的禁用开机启动实现(删除 plist 文件)
|
||||
func disableStartupImpl() error {
|
||||
plistPath, err := getLaunchAgentPath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取 LaunchAgent 路径失败: %v", err)
|
||||
}
|
||||
|
||||
// 删除 plist 文件
|
||||
if err := os.Remove(plistPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
slog.Info("开机启动项不存在,无需删除")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("删除 plist 文件失败: %v", err)
|
||||
}
|
||||
|
||||
slog.Info("成功删除开机启动项", "path", plistPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
// isStartupEnabledImpl macOS 平台检查是否已启用开机启动
|
||||
func isStartupEnabledImpl() bool {
|
||||
plistPath, err := getLaunchAgentPath()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// 检查 plist 文件是否存在
|
||||
_, err = os.Stat(plistPath)
|
||||
return err == nil
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
appName = "nps-client"
|
||||
desktopFormat = `[Desktop Entry]
|
||||
Type=Application
|
||||
Name=NPS Client
|
||||
Comment=NPS Client Auto Start
|
||||
Exec=%s
|
||||
Terminal=false
|
||||
X-GNOME-Autostart-enabled=true
|
||||
`
|
||||
)
|
||||
|
||||
// getAutostartPath 获取自动启动目录路径
|
||||
func getAutostartPath() (string, error) {
|
||||
// 优先使用 XDG_CONFIG_HOME
|
||||
configHome := os.Getenv("XDG_CONFIG_HOME")
|
||||
if configHome == "" {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
configHome = filepath.Join(homeDir, ".config")
|
||||
}
|
||||
|
||||
autostartDir := filepath.Join(configHome, "autostart")
|
||||
// 确保目录存在
|
||||
if err := os.MkdirAll(autostartDir, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return filepath.Join(autostartDir, appName+".desktop"), nil
|
||||
}
|
||||
|
||||
// enableStartupImpl Linux 平台的开机启动实现(使用 .desktop 文件)
|
||||
func enableStartupImpl() error {
|
||||
// 获取可执行文件路径
|
||||
exePath, err := getExecutablePath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取可执行文件路径失败: %v", err)
|
||||
}
|
||||
|
||||
// 获取 .desktop 文件路径
|
||||
desktopPath, err := getAutostartPath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取 autostart 路径失败: %v", err)
|
||||
}
|
||||
|
||||
// 生成 .desktop 文件内容
|
||||
desktopContent := fmt.Sprintf(desktopFormat, exePath)
|
||||
|
||||
// 写入 .desktop 文件
|
||||
if err := os.WriteFile(desktopPath, []byte(desktopContent), 0644); err != nil {
|
||||
return fmt.Errorf("写入 desktop 文件失败: %v", err)
|
||||
}
|
||||
|
||||
slog.Info("成功添加开机启动项", "app", appName, "path", desktopPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
// disableStartupImpl Linux 平台的禁用开机启动实现(删除 .desktop 文件)
|
||||
func disableStartupImpl() error {
|
||||
desktopPath, err := getAutostartPath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取 autostart 路径失败: %v", err)
|
||||
}
|
||||
|
||||
// 删除 .desktop 文件
|
||||
if err := os.Remove(desktopPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
slog.Info("开机启动项不存在,无需删除")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("删除 desktop 文件失败: %v", err)
|
||||
}
|
||||
|
||||
slog.Info("成功删除开机启动项", "path", desktopPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
// isStartupEnabledImpl Linux 平台检查是否已启用开机启动
|
||||
func isStartupEnabledImpl() bool {
|
||||
desktopPath, err := getAutostartPath()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// 检查 .desktop 文件是否存在
|
||||
_, err = os.Stat(desktopPath)
|
||||
return err == nil
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
const appName = "NPS客户端"
|
||||
|
||||
// enableStartupImpl Windows 平台的开机启动实现(使用注册表)
|
||||
func enableStartupImpl() error {
|
||||
// 获取可执行文件路径
|
||||
exePath, err := getExecutablePath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取可执行文件路径失败: %v", err)
|
||||
}
|
||||
|
||||
// 打开注册表键
|
||||
key, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.SET_VALUE)
|
||||
if err != nil {
|
||||
return fmt.Errorf("打开注册表失败: %v", err)
|
||||
}
|
||||
defer key.Close()
|
||||
|
||||
// 设置注册表值(应用名称 -> 可执行文件路径)
|
||||
err = key.SetStringValue(appName, exePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("设置注册表值失败: %v", err)
|
||||
}
|
||||
|
||||
slog.Info("成功添加开机启动项", "app", appName, "path", exePath)
|
||||
return nil
|
||||
}
|
||||
|
||||
// disableStartupImpl Windows 平台的禁用开机启动实现(删除注册表项)
|
||||
func disableStartupImpl() error {
|
||||
// 打开注册表键
|
||||
key, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.SET_VALUE)
|
||||
if err != nil {
|
||||
return fmt.Errorf("打开注册表失败: %v", err)
|
||||
}
|
||||
defer key.Close()
|
||||
|
||||
// 删除注册表值
|
||||
err = key.DeleteValue(appName)
|
||||
if err != nil {
|
||||
// 如果键不存在,不算错误
|
||||
if err == registry.ErrNotExist {
|
||||
slog.Info("开机启动项不存在,无需删除")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("删除注册表值失败: %v", err)
|
||||
}
|
||||
|
||||
slog.Info("成功删除开机启动项", "app", appName)
|
||||
return nil
|
||||
}
|
||||
|
||||
// isStartupEnabledImpl Windows 平台检查是否已启用开机启动
|
||||
func isStartupEnabledImpl() bool {
|
||||
key, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer key.Close()
|
||||
|
||||
_, _, err = key.GetStringValue(appName)
|
||||
return err == nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
// startTray 初始化系统托盘(使用 Wails v3 内置托盘,三平台统一)
|
||||
func (a *App) startTray() {
|
||||
tray := a.app.SystemTray.New()
|
||||
|
||||
// 使用 PNG 图标(wails3 各平台均支持)
|
||||
if len(trayIcon) > 0 {
|
||||
tray.SetIcon(trayIcon)
|
||||
}
|
||||
tray.SetTooltip("NPS 客户端")
|
||||
|
||||
menu := a.app.NewMenu()
|
||||
menu.Add("显示").OnClick(func(_ *application.Context) {
|
||||
a.showMainWindow()
|
||||
})
|
||||
menu.Add("退出").OnClick(func(_ *application.Context) {
|
||||
if !isQuitting() {
|
||||
setQuitting()
|
||||
a.app.Quit()
|
||||
}
|
||||
})
|
||||
tray.SetMenu(menu)
|
||||
|
||||
// 左键单击托盘图标也显示主窗口
|
||||
tray.OnClick(func() {
|
||||
a.showMainWindow()
|
||||
})
|
||||
|
||||
a.tray = tray
|
||||
}
|
||||
|
||||
// showMainWindow 显示主窗口
|
||||
func (a *App) showMainWindow() {
|
||||
if isQuitting() || a.window == nil {
|
||||
return
|
||||
}
|
||||
a.app.Event.Emit("tray-show")
|
||||
a.window.Show()
|
||||
a.window.Focus()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "sync"
|
||||
|
||||
// 退出状态由公共文件维护,避免平台实现重复定义。
|
||||
var (
|
||||
quitting bool
|
||||
quitMutex sync.Mutex
|
||||
)
|
||||
|
||||
// setQuitting 设置退出状态
|
||||
func setQuitting() {
|
||||
quitMutex.Lock()
|
||||
defer quitMutex.Unlock()
|
||||
quitting = true
|
||||
}
|
||||
|
||||
// isQuitting 检查是否正在退出
|
||||
func isQuitting() bool {
|
||||
quitMutex.Lock()
|
||||
defer quitMutex.Unlock()
|
||||
return quitting
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/version"
|
||||
)
|
||||
|
||||
const (
|
||||
updateRepo = "yisier/nps"
|
||||
updateAPIURL = "https://api.github.com/repos/" + updateRepo + "/releases/latest"
|
||||
updateDownBase = "https://github.com/" + updateRepo + "/releases/download"
|
||||
)
|
||||
|
||||
// UpdateInfo 版本检查结果,供前端展示
|
||||
type UpdateInfo struct {
|
||||
CurrentVersion string `json:"currentVersion"`
|
||||
LatestVersion string `json:"latestVersion"`
|
||||
UpdateAvailable bool `json:"updateAvailable"`
|
||||
ReleaseNotes string `json:"releaseNotes"`
|
||||
PublishedAt string `json:"publishedAt"`
|
||||
DownloadURL string `json:"downloadUrl"`
|
||||
AssetName string `json:"assetName"`
|
||||
}
|
||||
|
||||
type ghAsset struct {
|
||||
Name string `json:"name"`
|
||||
BrowserDownloadURL string `json:"browser_download_url"`
|
||||
}
|
||||
|
||||
type ghRelease struct {
|
||||
TagName string `json:"tag_name"`
|
||||
Body string `json:"body"`
|
||||
PublishedAt string `json:"published_at"`
|
||||
Assets []ghAsset `json:"assets"`
|
||||
}
|
||||
|
||||
// guiAssetName 当前平台对应的 GUI 发布包文件名
|
||||
func guiAssetName() string {
|
||||
return fmt.Sprintf("npc-gui-%s-%s.zip", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
// compareVersion 比较两个版本号(忽略前导 v)。a<b 返回 -1,a>b 返回 1,相等返回 0
|
||||
func compareVersion(a, b string) int {
|
||||
ai, _ := strconv.Atoi(strings.ReplaceAll(strings.TrimPrefix(strings.TrimSpace(a), "v"), ".", ""))
|
||||
bi, _ := strconv.Atoi(strings.ReplaceAll(strings.TrimPrefix(strings.TrimSpace(b), "v"), ".", ""))
|
||||
switch {
|
||||
case ai < bi:
|
||||
return -1
|
||||
case ai > bi:
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// fetchLatestRelease 拉取 GitHub 最新 release 信息
|
||||
func fetchLatestRelease() (*ghRelease, error) {
|
||||
client := &http.Client{Timeout: 15 * time.Second}
|
||||
req, err := http.NewRequest(http.MethodGet, updateAPIURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Accept", "application/vnd.github+json")
|
||||
req.Header.Set("User-Agent", "npc-gui-updater")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("获取版本信息失败: HTTP %d", resp.StatusCode)
|
||||
}
|
||||
rl := new(ghRelease)
|
||||
if err := json.NewDecoder(resp.Body).Decode(rl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rl.TagName == "" {
|
||||
return nil, errors.New("无法解析最新版本号")
|
||||
}
|
||||
return rl, nil
|
||||
}
|
||||
|
||||
func findAsset(rl *ghRelease, name string) (*ghAsset, error) {
|
||||
for i := range rl.Assets {
|
||||
if rl.Assets[i].Name == name {
|
||||
return &rl.Assets[i], nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("发布资源中未找到 %s,当前平台暂不支持自动更新", name)
|
||||
}
|
||||
|
||||
// CheckForUpdate 检查是否有新版本可用(检测升级)
|
||||
func (a *App) CheckForUpdate() (*UpdateInfo, error) {
|
||||
rl, err := fetchLatestRelease()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
latest := strings.TrimPrefix(rl.TagName, "v")
|
||||
current := version.VERSION
|
||||
|
||||
assetName := guiAssetName()
|
||||
downloadURL := ""
|
||||
if asset, err := findAsset(rl, assetName); err == nil {
|
||||
downloadURL = asset.BrowserDownloadURL
|
||||
}
|
||||
|
||||
return &UpdateInfo{
|
||||
CurrentVersion: current,
|
||||
LatestVersion: latest,
|
||||
UpdateAvailable: compareVersion(current, latest) < 0,
|
||||
ReleaseNotes: rl.Body,
|
||||
PublishedAt: rl.PublishedAt,
|
||||
DownloadURL: downloadURL,
|
||||
AssetName: assetName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DownloadAndInstallUpdate 下载最新版本并热替换当前可执行文件
|
||||
func (a *App) DownloadAndInstallUpdate() error {
|
||||
rl, err := fetchLatestRelease()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
latest := strings.TrimPrefix(rl.TagName, "v")
|
||||
if compareVersion(version.VERSION, latest) >= 0 {
|
||||
return fmt.Errorf("当前已是最新版本 %s,无需更新", version.VERSION)
|
||||
}
|
||||
|
||||
assetName := guiAssetName()
|
||||
asset, err := findAsset(rl, assetName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Info("开始下载更新包", "url", asset.BrowserDownloadURL)
|
||||
|
||||
exePath, err := getExecutablePath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取当前程序路径失败: %w", err)
|
||||
}
|
||||
|
||||
tempDir := filepath.Join(os.TempDir(), "npc-gui-update")
|
||||
_ = os.RemoveAll(tempDir)
|
||||
if err := os.MkdirAll(tempDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
zipPath := filepath.Join(tempDir, assetName)
|
||||
if err := downloadFile(asset.BrowserDownloadURL, zipPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := replaceFromZip(zipPath, exePath, tempDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Info("更新完成,请重启程序生效")
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestartApp 重启当前程序(更新完成后调用)
|
||||
func (a *App) RestartApp() error {
|
||||
exePath, err := getExecutablePath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取当前程序路径失败: %w", err)
|
||||
}
|
||||
cmd := exec.Command(exePath)
|
||||
if err := cmd.Start(); err != nil {
|
||||
return fmt.Errorf("启动新版本失败: %w", err)
|
||||
}
|
||||
// 延迟退出当前进程,确保新进程已启动
|
||||
go func() {
|
||||
time.Sleep(800 * time.Millisecond)
|
||||
if a.app != nil {
|
||||
a.app.Quit()
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func downloadFile(url, dest string) error {
|
||||
client := &http.Client{Timeout: 10 * time.Minute}
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("User-Agent", "npc-gui-updater")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("下载更新包失败: HTTP %d", resp.StatusCode)
|
||||
}
|
||||
out, err := os.Create(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
return err
|
||||
}
|
||||
|
||||
// replaceFromZip 从 zip 更新包中取出可执行文件并热替换正在运行的程序
|
||||
func replaceFromZip(zipPath, exePath, tempDir string) error {
|
||||
zr, err := zip.OpenReader(zipPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("打开更新包失败: %w", err)
|
||||
}
|
||||
defer zr.Close()
|
||||
|
||||
exeBase := filepath.Base(exePath)
|
||||
var found *zip.File
|
||||
for _, f := range zr.File {
|
||||
name := filepath.Base(f.Name)
|
||||
if strings.EqualFold(name, exeBase) || strings.EqualFold(name, "npc-gui") || strings.EqualFold(name, "npc-gui.exe") {
|
||||
found = f
|
||||
break
|
||||
}
|
||||
}
|
||||
if found == nil {
|
||||
return fmt.Errorf("更新包中未找到可执行文件 %s", exeBase)
|
||||
}
|
||||
|
||||
rc, err := found.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
newBin := filepath.Join(tempDir, "npc-gui"+guiExeExt())
|
||||
out, err := os.Create(newBin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.Copy(out, rc); err != nil {
|
||||
out.Close()
|
||||
return err
|
||||
}
|
||||
out.Close()
|
||||
chmodExecutable(newBin, 0o755)
|
||||
|
||||
return replaceExecutableFile(newBin, exePath)
|
||||
}
|
||||
|
||||
func guiExeExt() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return ".exe"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// replaceExecutableFile 用新文件替换正在运行的可执行文件。
|
||||
// Windows 下运行中的 exe 不能直接覆盖,先改名备份再替换。
|
||||
func replaceExecutableFile(srcBin, destBin string) error {
|
||||
if srcFi, err := os.Stat(srcBin); err == nil {
|
||||
if dstFi, err := os.Stat(destBin); err == nil {
|
||||
if os.SameFile(srcFi, dstFi) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(destBin), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 将当前程序改名为 .old 备份(Windows 上运行中的文件允许改名)
|
||||
if _, err := os.Stat(destBin); err == nil {
|
||||
bak := destBin + ".old"
|
||||
_ = os.Remove(bak)
|
||||
if err := os.Rename(destBin, bak); err != nil {
|
||||
return fmt.Errorf("无法备份当前程序 %s: %w", destBin, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 同文件系统 rename 原子替换;跨卷回退为拷贝
|
||||
if err := os.Rename(srcBin, destBin); err != nil {
|
||||
if _, copyErr := copyFileForUpdate(srcBin, destBin); copyErr != nil {
|
||||
// 尽力恢复旧程序
|
||||
bak := destBin + ".old"
|
||||
if _, statErr := os.Stat(bak); statErr == nil {
|
||||
_ = os.Rename(bak, destBin)
|
||||
}
|
||||
return fmt.Errorf("替换可执行文件失败: %w", copyErr)
|
||||
}
|
||||
_ = os.Remove(srcBin)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyFileForUpdate(src, dest string) (int64, error) {
|
||||
srcF, err := os.Open(src)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer srcF.Close()
|
||||
dstF, err := os.Create(dest)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer dstF.Close()
|
||||
return io.Copy(dstF, srcF)
|
||||
}
|
||||
|
||||
func chmodExecutable(path string, mode os.FileMode) {
|
||||
if runtime.GOOS != "windows" {
|
||||
_ = os.Chmod(path, mode)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
+532
-30
@@ -1,47 +1,233 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
"flag"
|
||||
"github.com/cnlh/nps/client"
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/daemon"
|
||||
"github.com/cnlh/nps/lib/version"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/client"
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/config"
|
||||
"ehang.io/nps/lib/file"
|
||||
"ehang.io/nps/lib/install"
|
||||
"ehang.io/nps/lib/version"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/ccding/go-stun/stun"
|
||||
"github.com/fatih/color"
|
||||
"github.com/kardianos/service"
|
||||
)
|
||||
|
||||
var (
|
||||
serverAddr = flag.String("server", "", "Server addr (ip:port)")
|
||||
configPath = flag.String("config", "", "Configuration file path")
|
||||
verifyKey = flag.String("vkey", "", "Authentication key")
|
||||
logType = flag.String("log", "stdout", "Log output mode(stdout|file)")
|
||||
connType = flag.String("type", "tcp", "Connection type with the server(kcp|tcp)")
|
||||
proxyUrl = flag.String("proxy", "", "proxy socks5 url(eg:socks5://111:222@127.0.0.1:9007)")
|
||||
logLevel = flag.String("log_level", "7", "log level 0~7")
|
||||
registerTime = flag.Int("time", 2, "register time long /h")
|
||||
serverAddr = flag.String("server", "", "Server addr (ip:port)")
|
||||
configPath = flag.String("config", "", "Configuration file path")
|
||||
verifyKey = flag.String("vkey", "", "Authentication key")
|
||||
logType = flag.String("log", "stdout", "Log output mode(stdout|file)")
|
||||
connType = flag.String("type", "tcp", "Connection type with the server(kcp|tcp)")
|
||||
proxyUrl = flag.String("proxy", "", "proxy socks5 url(eg:socks5://111:222@127.0.0.1:9007)")
|
||||
logLevel = flag.String("log_level", "7", "log level 0~7")
|
||||
registerTime = flag.Int("time", 2, "register time long /h")
|
||||
localPort = flag.Int("local_port", 2000, "p2p local port")
|
||||
password = flag.String("password", "", "p2p password flag")
|
||||
target = flag.String("target", "", "p2p target")
|
||||
localType = flag.String("local_type", "p2p", "p2p target")
|
||||
logPath = flag.String("log_path", "", "npc log path")
|
||||
debug = flag.Bool("debug", true, "npc debug")
|
||||
pprofAddr = flag.String("pprof", "", "PProf debug addr (ip:port)")
|
||||
stunAddr = flag.String("stun_addr", "stun.stunprotocol.org:3478", "stun server address (eg:stun.stunprotocol.org:3478)")
|
||||
ver = flag.Bool("version", false, "show current version")
|
||||
disconnectTime = flag.Int("disconnect_timeout", 60, "not receiving check packet times, until timeout will disconnect the client")
|
||||
tlsEnable = flag.Bool("tls_enable", false, "enable tls")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if len(os.Args) > 2 {
|
||||
logs.Reset()
|
||||
logs.EnableFuncCallDepth(true)
|
||||
logs.SetLogFuncCallDepth(3)
|
||||
if *ver {
|
||||
common.PrintVersion()
|
||||
return
|
||||
}
|
||||
if *logPath == "" {
|
||||
*logPath = common.GetNpcLogPath()
|
||||
}
|
||||
if common.IsWindows() {
|
||||
*logPath = strings.Replace(*logPath, "\\", "\\\\", -1)
|
||||
}
|
||||
if *debug {
|
||||
logs.SetLogger(logs.AdapterConsole, `{"level":`+*logLevel+`,"color":true}`)
|
||||
} else {
|
||||
logs.SetLogger(logs.AdapterFile, `{"level":`+*logLevel+`,"filename":"`+*logPath+`","daily":false,"maxlines":100000,"color":true}`)
|
||||
}
|
||||
|
||||
// init service
|
||||
options := make(service.KeyValue)
|
||||
svcConfig := &service.Config{
|
||||
Name: "Npc",
|
||||
DisplayName: "nps内网穿透客户端",
|
||||
Description: "一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。",
|
||||
Option: options,
|
||||
}
|
||||
if !common.IsWindows() {
|
||||
svcConfig.Dependencies = []string{
|
||||
"Requires=network.target",
|
||||
"After=network-online.target syslog.target"}
|
||||
svcConfig.Option["SystemdScript"] = install.SystemdScript
|
||||
svcConfig.Option["SysvScript"] = install.SysvScript
|
||||
}
|
||||
for _, v := range os.Args[1:] {
|
||||
switch v {
|
||||
case "install", "start", "stop", "uninstall", "restart":
|
||||
continue
|
||||
}
|
||||
if !strings.Contains(v, "-service=") && !strings.Contains(v, "-debug=") {
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, v)
|
||||
}
|
||||
}
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-debug=false")
|
||||
prg := &npc{
|
||||
exit: make(chan struct{}),
|
||||
}
|
||||
s, err := service.New(prg, svcConfig)
|
||||
if err != nil {
|
||||
logs.Error(err, "service function disabled")
|
||||
run()
|
||||
// run without service
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
wg.Wait()
|
||||
return
|
||||
}
|
||||
if len(os.Args) >= 2 {
|
||||
switch os.Args[1] {
|
||||
case "status":
|
||||
path := strings.Replace(os.Args[2], "-config=", "", -1)
|
||||
client.GetTaskStatus(path)
|
||||
if len(os.Args) > 2 {
|
||||
path := strings.Replace(os.Args[2], "-config=", "", -1)
|
||||
client.GetTaskStatus(path)
|
||||
}
|
||||
case "register":
|
||||
flag.CommandLine.Parse(os.Args[2:])
|
||||
client.RegisterLocalIp(*serverAddr, *verifyKey, *connType, *proxyUrl, *registerTime)
|
||||
case "update":
|
||||
install.UpdateNpc()
|
||||
return
|
||||
case "nat":
|
||||
c := stun.NewClient()
|
||||
flag.CommandLine.Parse(os.Args[2:])
|
||||
c.SetServerAddr(*stunAddr)
|
||||
nat, host, err := c.Discover()
|
||||
if err != nil || host == nil {
|
||||
logs.Error("get nat type error", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("nat type: %s \npublic address: %s\n", nat.String(), host.String())
|
||||
os.Exit(0)
|
||||
case "start", "stop", "restart":
|
||||
// support busyBox and sysV, for openWrt
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
cmd := exec.Command("/etc/init.d/"+svcConfig.Name, os.Args[1])
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
err := service.Control(s, os.Args[1])
|
||||
if err != nil {
|
||||
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
|
||||
}
|
||||
return
|
||||
case "install":
|
||||
service.Control(s, "stop")
|
||||
service.Control(s, "uninstall")
|
||||
install.InstallNpc()
|
||||
err := service.Control(s, os.Args[1])
|
||||
if err != nil {
|
||||
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
|
||||
}
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
confPath := "/etc/init.d/" + svcConfig.Name
|
||||
os.Symlink(confPath, "/etc/rc.d/S90"+svcConfig.Name)
|
||||
os.Symlink(confPath, "/etc/rc.d/K02"+svcConfig.Name)
|
||||
}
|
||||
return
|
||||
case "uninstall":
|
||||
err := service.Control(s, os.Args[1])
|
||||
if err != nil {
|
||||
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
|
||||
}
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
os.Remove("/etc/rc.d/S90" + svcConfig.Name)
|
||||
os.Remove("/etc/rc.d/K02" + svcConfig.Name)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
daemon.InitDaemon("npc", common.GetRunPath(), common.GetTmpPath())
|
||||
logs.EnableFuncCallDepth(true)
|
||||
logs.SetLogFuncCallDepth(3)
|
||||
if *logType == "stdout" {
|
||||
logs.SetLogger(logs.AdapterConsole, `{"level":`+*logLevel+`,"color":true}`)
|
||||
} else {
|
||||
logs.SetLogger(logs.AdapterFile, `{"level":`+*logLevel+`,"filename":"npc_log.log"}`)
|
||||
s.Run()
|
||||
}
|
||||
|
||||
type npc struct {
|
||||
exit chan struct{}
|
||||
}
|
||||
|
||||
func (p *npc) Start(s service.Service) error {
|
||||
go p.run()
|
||||
return nil
|
||||
}
|
||||
func (p *npc) Stop(s service.Service) error {
|
||||
close(p.exit)
|
||||
if service.Interactive() {
|
||||
os.Exit(0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *npc) run() error {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
logs.Warning("npc: panic serving %v: %v\n%s", err, string(buf))
|
||||
}
|
||||
}()
|
||||
run()
|
||||
select {
|
||||
case <-p.exit:
|
||||
logs.Warning("stop...")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func run() {
|
||||
common.InitPProfFromArg(*pprofAddr)
|
||||
//p2p or secret command
|
||||
if *password != "" {
|
||||
client.SetTlsEnable(*tlsEnable)
|
||||
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), client.GetTlsEnable())
|
||||
commonConfig := new(config.CommonConfig)
|
||||
commonConfig.Server = *serverAddr
|
||||
commonConfig.VKey = *verifyKey
|
||||
commonConfig.Tp = *connType
|
||||
localServer := new(config.LocalServer)
|
||||
localServer.Type = *localType
|
||||
localServer.Password = *password
|
||||
localServer.Target = *target
|
||||
localServer.Port = *localPort
|
||||
commonConfig.Client = new(file.Client)
|
||||
commonConfig.Client.Cnf = new(file.Config)
|
||||
go client.StartLocalServer(localServer, commonConfig)
|
||||
return
|
||||
}
|
||||
env := common.GetEnvMap()
|
||||
if *serverAddr == "" {
|
||||
@@ -50,17 +236,333 @@ func main() {
|
||||
if *verifyKey == "" {
|
||||
*verifyKey, _ = env["NPC_SERVER_VKEY"]
|
||||
}
|
||||
logs.Info("the version of client is %s", version.VERSION)
|
||||
if *verifyKey != "" && *serverAddr != "" && *configPath == "" {
|
||||
for {
|
||||
client.NewRPClient(*serverAddr, *verifyKey, *connType, *proxyUrl, nil).Start()
|
||||
logs.Info("It will be reconnected in five seconds")
|
||||
time.Sleep(time.Second * 5)
|
||||
client.SetTlsEnable(*tlsEnable)
|
||||
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), client.GetTlsEnable())
|
||||
|
||||
vkeys := strings.Split(*verifyKey, `,`)
|
||||
for _, key := range vkeys {
|
||||
key := key
|
||||
go func() {
|
||||
for {
|
||||
logs.Info("start vkey:" + key)
|
||||
client.NewRPClient(*serverAddr, key, *connType, *proxyUrl, nil, *disconnectTime).Start()
|
||||
logs.Info("Client closed! It will be reconnected in five seconds")
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
} else {
|
||||
if *configPath == "" {
|
||||
*configPath = "npc.conf"
|
||||
*configPath = common.GetConfigPath()
|
||||
}
|
||||
|
||||
// 判断路径下是否有配置文件
|
||||
if common.FileExists(*configPath) {
|
||||
logs.Info("配置文件模式启动")
|
||||
go client.StartFromFile(*configPath)
|
||||
} else {
|
||||
// 无配置文件模式双击运行
|
||||
printSlogan()
|
||||
inputCmd()
|
||||
}
|
||||
client.StartFromFile(*configPath)
|
||||
}
|
||||
}
|
||||
|
||||
func printSlogan() {
|
||||
green := color.New(color.FgGreen).SprintFunc()
|
||||
// 第一次输入,如果输入 1,2,3,4 则需要输入秘钥,否则
|
||||
|
||||
fmt.Printf("%s", green(""))
|
||||
|
||||
fmt.Printf("\033[32;0m###########################################################\n")
|
||||
fmt.Printf("\033[32;0m# \033[31mNPS内网穿透客户端\033[0m #\n")
|
||||
fmt.Printf("\033[32;0m# #\n")
|
||||
fmt.Printf("\033[32;0m#\033[32m 地址:\033[31;0mhttps://github.com/yisier/nps\033[0m #\n")
|
||||
fmt.Printf("\033[32;0m#\033[32m 提示:\033[32;0m1、涉及到系统服务的需要以管理员身份运行\033[0m\033[32;0m #\n")
|
||||
fmt.Printf("\033[32;0m#\033[32m \033[32;0m2、直接启动或[注册系统服务]需要使用[快捷启动命令]\033[0m\033[32;0m #\n")
|
||||
fmt.Printf("\033[32;0m#\033[32m \033[32;0m3、其他命令如卸载/启动/停止只需要输入[vkey]\033[0m\033[32;0m #\n")
|
||||
fmt.Printf("\033[32;0m###########################################################\n")
|
||||
fmt.Printf("\033[0m") // 重置颜色
|
||||
|
||||
fmt.Printf("\n")
|
||||
|
||||
fmt.Printf("\u001B[32m输入[1]\u001B[0m - 注册系统服务\n")
|
||||
fmt.Printf("\u001B[32m输入[2]\u001B[0m - 卸载系统服务\n")
|
||||
fmt.Printf("---------------------\n")
|
||||
fmt.Printf("\u001B[32m输入[3]\u001B[0m - 启动系统服务\n")
|
||||
fmt.Printf("\u001B[32m输入[4]\u001B[0m - 停止系统服务\n")
|
||||
fmt.Printf("---------------------\n")
|
||||
fmt.Printf("\u001B[32m输入[5]\u001B[0m - 更新客户端\n")
|
||||
fmt.Printf("\u001B[32m输入[0]\u001B[0m - 退出\n")
|
||||
fmt.Printf("---------------------\n")
|
||||
fmt.Printf("\u001B[32m当前版本:%s\u001B[0m\n", version.VERSION)
|
||||
fmt.Printf("直接输入[快捷启动命令]则是启动隧道,多个[快捷启动命令]用英文逗号拼接\n")
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
func inputCmd() {
|
||||
|
||||
var flag string
|
||||
fmt.Printf("请输入:")
|
||||
|
||||
stdin := bufio.NewReader(os.Stdin)
|
||||
_, err := fmt.Fscanln(stdin, &flag)
|
||||
if err != nil {
|
||||
fmt.Println("输入有误")
|
||||
} else {
|
||||
if flag == "0" {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
flag := strings.Replace(flag, " ", "", -1)
|
||||
|
||||
// 如果输入不等于 1,2,3,4,5,则启动隧道
|
||||
if flag != "1" && flag != "2" && flag != "3" && flag != "4" && flag != "5" {
|
||||
|
||||
vkeys := strings.Split(flag, `,`)
|
||||
var cmdArray []string
|
||||
|
||||
for _, key := range vkeys {
|
||||
startCmd, err := crypt.Base64Decoding(key)
|
||||
if err != nil {
|
||||
fmt.Println("快捷启动命令解析失败")
|
||||
inputCmd()
|
||||
return
|
||||
}
|
||||
|
||||
cmdArray = append(cmdArray, startCmd)
|
||||
}
|
||||
|
||||
for _, item := range cmdArray {
|
||||
startNpcServer(item)
|
||||
}
|
||||
|
||||
} else {
|
||||
if flag == "5" {
|
||||
install.UpdateNpcNew()
|
||||
inputCmd()
|
||||
} else {
|
||||
systemService(flag)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func startNpcServer(startCmd string) {
|
||||
var serAddr string
|
||||
var vkey string
|
||||
var tls string
|
||||
array := strings.Fields(startCmd)
|
||||
serAddr = array[0]
|
||||
vkey = array[1]
|
||||
if len(array) > 2 {
|
||||
tls = array[2]
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
if tls == "-tls_enable=true" || tls == "true" {
|
||||
client.SetTlsEnable(true)
|
||||
logs.Info("start cmd:-server=" + serAddr + " -vkey=" + vkey + " " + tls)
|
||||
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), client.GetTlsEnable())
|
||||
} else {
|
||||
client.SetTlsEnable(false)
|
||||
logs.Info("start cmd:-server=" + serAddr + " -vkey=" + vkey)
|
||||
logs.Info("the version of client is %s, the core version of client is %s", version.VERSION, version.GetVersion())
|
||||
}
|
||||
|
||||
client.NewRPClient(serAddr, vkey, *connType, *proxyUrl, nil, *disconnectTime).Start()
|
||||
logs.Info("Client closed! It will be reconnected in five seconds")
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func systemService(flag string) {
|
||||
|
||||
if flag == "1" {
|
||||
fmt.Printf("请输入[快捷启动命令],多个[快捷启动命令]用英文逗号拼接:")
|
||||
} else {
|
||||
fmt.Printf("请输入[VKEY],多个[VKEY]用英文逗号拼接:")
|
||||
}
|
||||
|
||||
var vkey string
|
||||
stdin := bufio.NewReader(os.Stdin)
|
||||
_, err := fmt.Fscanln(stdin, &vkey)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("输入错误,请重试")
|
||||
systemService(flag)
|
||||
return
|
||||
} else {
|
||||
if vkey == "0" {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
vkey = strings.Replace(vkey, " ", "", -1)
|
||||
|
||||
vkeys := strings.Split(vkey, `,`)
|
||||
|
||||
if flag == "1" {
|
||||
var cmdArray []string
|
||||
for _, key := range vkeys {
|
||||
startCmd, err := crypt.Base64Decoding(key)
|
||||
if err != nil {
|
||||
fmt.Println("快捷启动命令解析失败")
|
||||
systemService(flag)
|
||||
return
|
||||
}
|
||||
cmdArray = append(cmdArray, startCmd)
|
||||
}
|
||||
|
||||
for _, item := range cmdArray {
|
||||
array := strings.Fields(item)
|
||||
|
||||
tls := "false"
|
||||
if len(array) > 2 {
|
||||
tls = array[2]
|
||||
}
|
||||
// tls
|
||||
if tls == "-tls_enable=true" || tls == "true" {
|
||||
systemPro(flag, array[0], array[1], true)
|
||||
} else {
|
||||
systemPro(flag, array[0], array[1], false)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, key := range vkeys {
|
||||
systemPro(flag, "", key, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inputCmd()
|
||||
return
|
||||
}
|
||||
|
||||
func systemPro(flag string, serAddr string, vkey string, tls bool) {
|
||||
// init service
|
||||
prg := &npc{
|
||||
exit: make(chan struct{}),
|
||||
}
|
||||
options := make(service.KeyValue)
|
||||
svcConfig := &service.Config{
|
||||
Name: "nps-client-" + vkey,
|
||||
DisplayName: "nps-client-" + vkey,
|
||||
Description: "NPS内网穿透客户端,支持tcp、udp流量转发,支持内网http代理,地址:https://github.com/yisier/nps",
|
||||
Option: options,
|
||||
}
|
||||
s, _ := service.New(prg, svcConfig)
|
||||
|
||||
switch flag {
|
||||
case "1":
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-server="+serAddr)
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-vkey="+vkey)
|
||||
if tls {
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-tls_enable=true")
|
||||
}
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-debug=false")
|
||||
|
||||
*logPath = common.GetNpcLogPath()
|
||||
if common.IsWindows() {
|
||||
*logPath = strings.Replace(*logPath, "\\", "\\\\", -1)
|
||||
}
|
||||
|
||||
*logPath = strings.Replace(*logPath, "npc.log", "npc-"+vkey+".log", -1)
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-log_path="+*logPath)
|
||||
|
||||
logs.NewLogger()
|
||||
logs.Reset()
|
||||
logs.EnableFuncCallDepth(true)
|
||||
logs.SetLogFuncCallDepth(3)
|
||||
logs.SetLogger(logs.AdapterFile, `{"level":`+*logLevel+`,"filename":"`+*logPath+`","daily":false,"maxlines":100000,"color":true}`)
|
||||
|
||||
install.InstallNpc()
|
||||
err := service.Control(s, "install")
|
||||
if err != nil {
|
||||
fmt.Println("隧道["+vkey+"]安装到系统服务失败", err)
|
||||
return
|
||||
} else {
|
||||
fmt.Println("隧道[" + vkey + "]已经安装到系统")
|
||||
}
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
confPath := "/etc/init.d/" + svcConfig.Name
|
||||
os.Symlink(confPath, "/etc/rc.d/S90"+svcConfig.Name)
|
||||
os.Symlink(confPath, "/etc/rc.d/K02"+svcConfig.Name)
|
||||
}
|
||||
|
||||
err2 := service.Control(s, "start")
|
||||
if err2 != nil {
|
||||
fmt.Println("隧道["+vkey+"]启动服务失败", err2)
|
||||
} else {
|
||||
fmt.Println("隧道[" + vkey + "]服务已启动")
|
||||
}
|
||||
|
||||
return
|
||||
case "2":
|
||||
// 卸载系统服务
|
||||
err := service.Control(s, "stop")
|
||||
if err != nil {
|
||||
fmt.Println("隧道["+vkey+"]服务停止失败", err)
|
||||
} else {
|
||||
fmt.Println("隧道[" + vkey + "]服务已停止")
|
||||
}
|
||||
|
||||
err = service.Control(s, "uninstall")
|
||||
if err != nil {
|
||||
fmt.Println("隧道["+vkey+"]服务卸载失败", err)
|
||||
}
|
||||
if service.Platform() == "unix-systemv" {
|
||||
fmt.Println("unix-systemv service")
|
||||
os.Remove("/etc/rc.d/S90" + svcConfig.Name)
|
||||
os.Remove("/etc/rc.d/K02" + svcConfig.Name)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
fmt.Println("隧道[" + vkey + "]服务已卸载成功")
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
case "3":
|
||||
//启动系统服务
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
cmd := exec.Command("/etc/init.d/"+svcConfig.Name, "start")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
err := service.Control(s, "start")
|
||||
if err != nil {
|
||||
fmt.Println("隧道["+vkey+"]服务启动失败", err)
|
||||
} else {
|
||||
fmt.Println("隧道[" + vkey + "]服务启动成功")
|
||||
}
|
||||
|
||||
return
|
||||
case "4":
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
cmd := exec.Command("/etc/init.d/"+svcConfig.Name, "stop")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
err := service.Control(s, "stop")
|
||||
if err != nil {
|
||||
fmt.Println("隧道["+vkey+"]服务停止失败", err)
|
||||
} else {
|
||||
fmt.Println("隧道[" + vkey + "]服务停止成功")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"C"
|
||||
"ehang.io/nps/client"
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/version"
|
||||
"github.com/astaxie/beego/logs"
|
||||
)
|
||||
|
||||
var cl *client.TRPClient
|
||||
|
||||
//export StartClientByVerifyKey
|
||||
func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
|
||||
_ = logs.SetLogger("store")
|
||||
if cl != nil {
|
||||
cl.Close()
|
||||
}
|
||||
cl = client.NewRPClient(C.GoString(serverAddr), C.GoString(verifyKey), C.GoString(connType), C.GoString(proxyUrl), nil, 60)
|
||||
cl.Start()
|
||||
return 1
|
||||
}
|
||||
|
||||
//export GetClientStatus
|
||||
func GetClientStatus() int {
|
||||
return client.NowStatus
|
||||
}
|
||||
|
||||
//export CloseClient
|
||||
func CloseClient() {
|
||||
if cl != nil {
|
||||
cl.Close()
|
||||
}
|
||||
}
|
||||
|
||||
//export Version
|
||||
func Version() *C.char {
|
||||
return C.CString(version.VERSION)
|
||||
}
|
||||
|
||||
//export Logs
|
||||
func Logs() *C.char {
|
||||
return C.CString(common.GetLogMsg())
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Need a main function to make CGO compile package as C shared library
|
||||
}
|
||||
+513
-31
@@ -1,55 +1,447 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"ehang.io/nps/bridge"
|
||||
"ehang.io/nps/lib/daemon"
|
||||
"ehang.io/nps/server"
|
||||
"flag"
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/daemon"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/lib/install"
|
||||
"github.com/cnlh/nps/lib/version"
|
||||
"github.com/cnlh/nps/server"
|
||||
"github.com/cnlh/nps/server/connection"
|
||||
"github.com/cnlh/nps/server/test"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
_ "github.com/cnlh/nps/web/routers"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"ehang.io/nps/lib/file"
|
||||
"ehang.io/nps/lib/install"
|
||||
"ehang.io/nps/lib/version"
|
||||
"ehang.io/nps/server/connection"
|
||||
"ehang.io/nps/server/tool"
|
||||
"ehang.io/nps/web/routers"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
|
||||
"github.com/kardianos/service"
|
||||
)
|
||||
|
||||
var (
|
||||
level string
|
||||
logType = flag.String("log", "stdout", "Log output mode(stdout|file)")
|
||||
level string
|
||||
ver = flag.Bool("version", false, "show current version")
|
||||
confPath = flag.String("conf_path", "", "set current confPath")
|
||||
serverCmd = flag.Bool("server", false, "NPS管理脚本")
|
||||
npsLogPath = flag.String("log_path", "", "nps log path")
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
debug.SetMaxThreads(1000000)
|
||||
|
||||
flag.Parse()
|
||||
beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf"))
|
||||
if len(os.Args) > 1 {
|
||||
switch os.Args[1] {
|
||||
case "test":
|
||||
test.TestServerConfig()
|
||||
log.Println("test ok, no error")
|
||||
return
|
||||
case "start", "restart", "stop", "status":
|
||||
daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
|
||||
case "install":
|
||||
install.InstallNps()
|
||||
return
|
||||
// init log
|
||||
if *ver {
|
||||
common.PrintVersion()
|
||||
return
|
||||
}
|
||||
if *serverCmd {
|
||||
_ = logs.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)
|
||||
printSlogan()
|
||||
inputCmd()
|
||||
return
|
||||
}
|
||||
|
||||
var logPath string
|
||||
// *confPath why get null value ?
|
||||
for _, v := range os.Args[1:] {
|
||||
switch v {
|
||||
case "install", "start", "stop", "uninstall", "restart":
|
||||
continue
|
||||
}
|
||||
if strings.Contains(v, "-conf_path=") {
|
||||
common.ConfPath = strings.Replace(v, "-conf_path=", "", -1)
|
||||
}
|
||||
|
||||
if strings.Contains(v, "-log_path=") {
|
||||
logPath = strings.Replace(v, "-log_path=", "", -1)
|
||||
}
|
||||
}
|
||||
|
||||
// auto-generate default config files if not exist
|
||||
initConfig(filepath.Join(common.GetRunPath(), "conf"))
|
||||
|
||||
if err := beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf")); err != nil {
|
||||
log.Fatalln("load config file error", err.Error())
|
||||
}
|
||||
|
||||
common.InitPProfFromFile()
|
||||
if level = beego.AppConfig.String("log_level"); level == "" {
|
||||
level = "7"
|
||||
}
|
||||
logs.Reset()
|
||||
logs.EnableFuncCallDepth(true)
|
||||
logs.SetLogFuncCallDepth(3)
|
||||
if *logType == "stdout" {
|
||||
logs.SetLogger(logs.AdapterConsole, `{"level":`+level+`,"color":true}`)
|
||||
} else {
|
||||
logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"nps_log.log"}`)
|
||||
|
||||
if logPath == "" {
|
||||
logPath := beego.AppConfig.String("log_path")
|
||||
if logPath == "" {
|
||||
logPath = common.GetLogPath()
|
||||
}
|
||||
if common.IsWindows() {
|
||||
logPath = strings.Replace(logPath, "\\", "\\\\", -1)
|
||||
}
|
||||
}
|
||||
|
||||
// init service
|
||||
options := make(service.KeyValue)
|
||||
svcConfig := &service.Config{
|
||||
Name: "Nps",
|
||||
DisplayName: "nps内网穿透代理服务器",
|
||||
Description: "一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。",
|
||||
Option: options,
|
||||
}
|
||||
|
||||
bridge.ServerTlsEnable = beego.AppConfig.DefaultBool("tls_enable", false)
|
||||
|
||||
for _, v := range os.Args[1:] {
|
||||
switch v {
|
||||
case "install", "start", "stop", "uninstall", "restart":
|
||||
continue
|
||||
}
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, v)
|
||||
}
|
||||
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "service")
|
||||
if len(os.Args) > 1 && os.Args[1] == "service" {
|
||||
_ = logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"`+logPath+`","daily":false,"maxlines":100000,"color":true}`)
|
||||
} else {
|
||||
_ = logs.SetLogger(logs.AdapterConsole, `{"level":`+level+`,"color":true}`)
|
||||
}
|
||||
if !common.IsWindows() {
|
||||
svcConfig.Dependencies = []string{
|
||||
"Requires=network.target",
|
||||
"After=network-online.target syslog.target"}
|
||||
svcConfig.Option["SystemdScript"] = install.SystemdScript
|
||||
svcConfig.Option["SysvScript"] = install.SysvScript
|
||||
}
|
||||
prg := &nps{}
|
||||
prg.exit = make(chan struct{})
|
||||
s, err := service.New(prg, svcConfig)
|
||||
if err != nil {
|
||||
logs.Error(err, "service function disabled")
|
||||
run()
|
||||
// run without service
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
wg.Wait()
|
||||
return
|
||||
}
|
||||
|
||||
if len(os.Args) > 1 && os.Args[1] != "service" {
|
||||
switch os.Args[1] {
|
||||
case "reload":
|
||||
daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
|
||||
return
|
||||
case "install":
|
||||
// uninstall before
|
||||
_ = service.Control(s, "stop")
|
||||
_ = service.Control(s, "uninstall")
|
||||
|
||||
binPath := install.InstallNps()
|
||||
svcConfig.Executable = binPath
|
||||
s, err := service.New(prg, svcConfig)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return
|
||||
}
|
||||
err = service.Control(s, os.Args[1])
|
||||
if err != nil {
|
||||
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
|
||||
}
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
confPath := "/etc/init.d/" + svcConfig.Name
|
||||
os.Symlink(confPath, "/etc/rc.d/S90"+svcConfig.Name)
|
||||
os.Symlink(confPath, "/etc/rc.d/K02"+svcConfig.Name)
|
||||
}
|
||||
return
|
||||
case "start", "restart", "stop":
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
cmd := exec.Command("/etc/init.d/"+svcConfig.Name, os.Args[1])
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
err := service.Control(s, os.Args[1])
|
||||
if err != nil {
|
||||
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
|
||||
}
|
||||
return
|
||||
case "uninstall":
|
||||
err := service.Control(s, os.Args[1])
|
||||
if err != nil {
|
||||
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
|
||||
}
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
os.Remove("/etc/rc.d/S90" + svcConfig.Name)
|
||||
os.Remove("/etc/rc.d/K02" + svcConfig.Name)
|
||||
}
|
||||
return
|
||||
case "update":
|
||||
install.UpdateNps()
|
||||
return
|
||||
//default:
|
||||
// logs.Error("command is not support")
|
||||
// return
|
||||
}
|
||||
}
|
||||
|
||||
_ = s.Run()
|
||||
}
|
||||
|
||||
func printSlogan() {
|
||||
green := color.New(color.FgGreen).SprintFunc()
|
||||
// 第一次输入,如果输入 1,2,3,4 则需要输入秘钥,否则
|
||||
|
||||
fmt.Printf("%s", green(""))
|
||||
|
||||
fmt.Printf("\033[32;0m欢迎使用 NPS 管理脚本,当前版本:v%s\n", version.VERSION)
|
||||
fmt.Printf("\033[0m") // 重置颜色
|
||||
|
||||
fmt.Printf("\n")
|
||||
|
||||
fmt.Printf("\u001B[32m输入[1]\u001B[0m - 安装 NPS\n")
|
||||
fmt.Printf("\u001B[32m输入[2]\u001B[0m - 卸载 NPS\n")
|
||||
fmt.Printf("\u001B[32m输入[3]\u001B[0m - 更新 NPS\n")
|
||||
fmt.Printf("---------------------\n")
|
||||
fmt.Printf("\u001B[32m输入[4]\u001B[0m - 查看状态\n")
|
||||
fmt.Printf("---------------------\n")
|
||||
fmt.Printf("\u001B[32m输入[5]\u001B[0m - 启动 NPS\n")
|
||||
fmt.Printf("\u001B[32m输入[6]\u001B[0m - 停止 NPS\n")
|
||||
fmt.Printf("\u001B[32m输入[7]\u001B[0m - 重启 NPS\n")
|
||||
fmt.Printf("---------------------\n")
|
||||
fmt.Printf("\u001B[32m输入[0]\u001B[0m - 退出脚本\n")
|
||||
fmt.Printf("---------------------\n")
|
||||
fmt.Printf("\n")
|
||||
|
||||
}
|
||||
|
||||
func inputCmd() {
|
||||
var flag string
|
||||
fmt.Printf("请输入[0-7]:")
|
||||
|
||||
stdin := bufio.NewReader(os.Stdin)
|
||||
_, err := fmt.Fscanln(stdin, &flag)
|
||||
if err != nil {
|
||||
fmt.Println("输入有误")
|
||||
} else {
|
||||
if flag == "0" {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// init service
|
||||
|
||||
prg := &nps{
|
||||
exit: make(chan struct{}),
|
||||
}
|
||||
options := make(service.KeyValue)
|
||||
svcConfig := &service.Config{
|
||||
Name: "Nps",
|
||||
DisplayName: "nps内网穿透代理服务器",
|
||||
Description: "一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。",
|
||||
Option: options,
|
||||
}
|
||||
s, _ := service.New(prg, svcConfig)
|
||||
|
||||
switch flag {
|
||||
case "1":
|
||||
// uninstall before
|
||||
_ = service.Control(s, "stop")
|
||||
_ = service.Control(s, "uninstall")
|
||||
binPath := install.InstallNpsToCurrentDir()
|
||||
|
||||
// Ensure conf exists (same as normal startup), then load it for display.
|
||||
// Previously LoadAppConfig error was ignored and web_port could be empty,
|
||||
// printing "127.0.0.1:" with no port. See #317.
|
||||
confDir := filepath.Join(common.GetAppPath(), "conf")
|
||||
initConfig(confDir)
|
||||
if err := beego.LoadAppConfig("ini", filepath.Join(confDir, "nps.conf")); err != nil {
|
||||
fmt.Println("加载配置文件失败:", err)
|
||||
break
|
||||
}
|
||||
|
||||
logPath := filepath.Join(common.GetAppPath(), "nps.log")
|
||||
if common.IsWindows() {
|
||||
logPath = strings.Replace(logPath, "\\", "\\\\", -1)
|
||||
}
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "service")
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-conf_path="+common.GetAppPath())
|
||||
svcConfig.Arguments = append(svcConfig.Arguments, "-log_path="+logPath)
|
||||
|
||||
fmt.Println("日志文件路径为:", logPath)
|
||||
|
||||
svcConfig.Executable = binPath
|
||||
s, err := service.New(prg, svcConfig)
|
||||
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
confPath := "/etc/init.d/" + svcConfig.Name
|
||||
os.Symlink(confPath, "/etc/rc.d/S90"+svcConfig.Name)
|
||||
os.Symlink(confPath, "/etc/rc.d/K02"+svcConfig.Name)
|
||||
}
|
||||
|
||||
err = service.Control(s, "install")
|
||||
if err != nil {
|
||||
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
|
||||
} else {
|
||||
fmt.Println("NPS服务安装成功")
|
||||
}
|
||||
|
||||
err = service.Control(s, "start")
|
||||
if err != nil {
|
||||
fmt.Println("启动NPS服务失败", err)
|
||||
} else {
|
||||
webPort := beego.AppConfig.String("web_port")
|
||||
if webPort == "" {
|
||||
fmt.Println("NPS服务已启动(未配置 web_port,管理面板已关闭)")
|
||||
} else {
|
||||
scheme := "http"
|
||||
if beego.AppConfig.DefaultBool("web_open_ssl", false) {
|
||||
scheme = "https"
|
||||
}
|
||||
fmt.Println("NPS服务已启动,管理面板访问地址:" + scheme + "://127.0.0.1:" + webPort)
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
case "2":
|
||||
// 卸载系统服务
|
||||
err := service.Control(s, "stop")
|
||||
if err != nil {
|
||||
fmt.Println("NPS服务停止失败", err)
|
||||
} else {
|
||||
fmt.Println("NPS服务已停止")
|
||||
}
|
||||
|
||||
err = service.Control(s, "uninstall")
|
||||
if err != nil {
|
||||
logs.Error("NPS服务卸载失败")
|
||||
}
|
||||
if service.Platform() == "unix-systemv" {
|
||||
logs.Info("unix-systemv service")
|
||||
os.Remove("/etc/rc.d/S90" + svcConfig.Name)
|
||||
os.Remove("/etc/rc.d/K02" + svcConfig.Name)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
fmt.Println("NPS服务已卸载成功")
|
||||
}
|
||||
break
|
||||
case "3":
|
||||
install.UpdateNpsNew()
|
||||
break
|
||||
case "4":
|
||||
// 查看状态
|
||||
var statusMsg = ""
|
||||
status, err := s.Status()
|
||||
if err != nil {
|
||||
statusMsg = "\u001B[31m未运行\u001B[0m"
|
||||
} else {
|
||||
if status == 1 {
|
||||
statusMsg = "\u001B[32m运行中\u001B[0m"
|
||||
} else {
|
||||
statusMsg = "\u001B[31m未运行\u001B[0m"
|
||||
}
|
||||
}
|
||||
fmt.Println("NPS服务状态:" + statusMsg)
|
||||
break
|
||||
case "5":
|
||||
// 启动 NPS
|
||||
err := service.Control(s, "start")
|
||||
if err != nil {
|
||||
fmt.Println("NPS服务启动失败", err)
|
||||
} else {
|
||||
fmt.Println("NPS服务启动成功")
|
||||
}
|
||||
|
||||
break
|
||||
case "6":
|
||||
// 停止 NPS
|
||||
err := service.Control(s, "stop")
|
||||
if err != nil {
|
||||
fmt.Println("NPS服务停止失败", err)
|
||||
} else {
|
||||
fmt.Println("NPS服务停止成功")
|
||||
}
|
||||
|
||||
break
|
||||
case "7":
|
||||
// 重启 NPS
|
||||
err := service.Control(s, "restart")
|
||||
if err != nil {
|
||||
fmt.Println("NPS服务重启失败", err)
|
||||
} else {
|
||||
fmt.Println("NPS服务重启成功")
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
inputCmd()
|
||||
}
|
||||
|
||||
func installNps() {
|
||||
|
||||
}
|
||||
|
||||
type nps struct {
|
||||
exit chan struct{}
|
||||
}
|
||||
|
||||
func (p *nps) Start(s service.Service) error {
|
||||
_, _ = s.Status()
|
||||
go p.run()
|
||||
return nil
|
||||
}
|
||||
func (p *nps) Stop(s service.Service) error {
|
||||
_, _ = s.Status()
|
||||
close(p.exit)
|
||||
if service.Interactive() {
|
||||
os.Exit(0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *nps) run() error {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
logs.Warning("nps: panic serving %v: %v\n%s", err, string(buf))
|
||||
}
|
||||
}()
|
||||
run()
|
||||
select {
|
||||
case <-p.exit:
|
||||
logs.Warning("stop...")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func run() {
|
||||
routers.Init()
|
||||
task := &file.Tunnel{
|
||||
Mode: "webServer",
|
||||
}
|
||||
@@ -58,7 +450,97 @@ func main() {
|
||||
logs.Error("Getting bridge_port error", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
logs.Info("the version of server is %s ,allow client version to be %s", version.VERSION, version.GetVersion())
|
||||
|
||||
logs.Info("日志路径:" + *npsLogPath)
|
||||
logs.Info("the config path is:" + common.GetRunPath())
|
||||
logs.Info("the version of server is %s ,allow client core version to be %s,tls enable is %t", version.VERSION, version.GetVersion(), bridge.ServerTlsEnable)
|
||||
connection.InitConnectionService()
|
||||
server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"))
|
||||
//crypt.InitTls(filepath.Join(common.GetRunPath(), "conf", "server.pem"), filepath.Join(common.GetRunPath(), "conf", "server.key"))
|
||||
crypt.InitTls()
|
||||
tool.InitAllowPort()
|
||||
tool.StartSystemInfo()
|
||||
timeout, err := beego.AppConfig.Int("disconnect_timeout")
|
||||
if err != nil {
|
||||
timeout = 60
|
||||
}
|
||||
go server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"), timeout)
|
||||
}
|
||||
|
||||
func initConfig(confDir string) {
|
||||
if !common.FileExists(confDir) {
|
||||
os.MkdirAll(confDir, 0755)
|
||||
}
|
||||
confPath := filepath.Join(confDir, "nps.conf")
|
||||
if !common.FileExists(confPath) {
|
||||
webPassword := crypt.GetRandomString(8)
|
||||
authKey := crypt.GetRandomString(8)
|
||||
authCryptKey := crypt.GetRandomString(16)
|
||||
content := strings.Replace(defaultNpsConf, "web_password=123", "web_password="+webPassword, 1)
|
||||
content = strings.Replace(content, "auth_key=123", "auth_key="+authKey, 1)
|
||||
content = strings.Replace(content, "auth_crypt_key =213", "auth_crypt_key ="+authCryptKey, 1)
|
||||
f, err := os.Create(confPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
f.WriteString(content)
|
||||
logs.Info("Auto-generated default config file:", confPath)
|
||||
logs.Info("Web login username: admin, password:", webPassword)
|
||||
logs.Info("auth_key:", authKey)
|
||||
logs.Info("auth_crypt_key:", authCryptKey)
|
||||
}
|
||||
}
|
||||
|
||||
const defaultNpsConf = `http_proxy_ip=0.0.0.0
|
||||
http_proxy_port=80
|
||||
https_proxy_port=443
|
||||
show_http_proxy_port=true
|
||||
|
||||
bridge_type=tcp
|
||||
bridge_port=8024
|
||||
bridge_ip=0.0.0.0
|
||||
|
||||
public_vkey=123
|
||||
|
||||
flow_store_interval=1
|
||||
|
||||
log_level=6
|
||||
log_path=nps.log
|
||||
|
||||
web_host=a.o.com
|
||||
web_username=admin
|
||||
web_password=123
|
||||
web_port = 8081
|
||||
web_ip=0.0.0.0
|
||||
web_base_url=
|
||||
web_open_ssl=false
|
||||
web_cert_file=conf/server.pem
|
||||
web_key_file=conf/server.key
|
||||
|
||||
auth_key=123
|
||||
auth_crypt_key =213
|
||||
|
||||
allow_user_login=true
|
||||
allow_user_register=false
|
||||
allow_user_change_username=true
|
||||
|
||||
allow_flow_limit=true
|
||||
allow_rate_limit=true
|
||||
allow_tunnel_num_limit=true
|
||||
allow_local_proxy=false
|
||||
allow_connection_num_limit=true
|
||||
allow_multi_ip=true
|
||||
system_info_display=true
|
||||
|
||||
http_add_origin_header=true
|
||||
|
||||
http_cache=false
|
||||
http_cache_length=100
|
||||
|
||||
disconnect_timeout=60
|
||||
|
||||
open_captcha=false
|
||||
|
||||
tls_enable=true
|
||||
tls_bridge_port=8025
|
||||
`
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
2,corjmrbhr33otit1,,true,,,0,false,0,0,0
|
||||
5,2dyy78gj7b9zw09l,,true,,,1,false,0,0,0
|
||||
|
@@ -0,0 +1,3 @@
|
||||
{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"e9cba3f8a9","Addr":"127.0.0.1","LocalAddr":"172.16.10.6","Remark":"测试2","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":1446223,"InletFlow":1446223,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.38","BlackIpList":[],"CreateTime":"2026-08-24 11:20:39","LastOnlineTime":"2026-08-24 17:48:47","IpWhite":false,"IpWhitePass":"","IpWhiteList":[],"ExpireTime":""}
|
||||
*#*{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":4,"VerifyKey":"b6873d7af1","Addr":"127.0.0.1","LocalAddr":"172.16.10.6","Remark":"测试1","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":0,"InletFlow":0,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.38","BlackIpList":[],"CreateTime":"2026-08-24 13:40:26","LastOnlineTime":"2026-08-24 17:48:47","IpWhite":false,"IpWhitePass":"","IpWhiteList":[],"ExpireTime":""}
|
||||
*#*
|
||||
@@ -0,0 +1 @@
|
||||
{"BlackIpList":[],"ServerUrl":""}
|
||||
@@ -1,3 +0,0 @@
|
||||
c.o.com,10.1.50.196:4000,5,,,,/,2,7543392,22379,all
|
||||
a.o.com,127.0.0.1:8080,2,,,,/,3,0,0,all
|
||||
b.o.com,127.0.0.1:8082,5,,,,/,4,0,0,all
|
||||
|
@@ -0,0 +1,2 @@
|
||||
{"Id":1,"Host":"wmstest22.hn1.pp2pdf.com","HeaderChange":"","HostChange":"","Location":"/","Remark":"","Scheme":"https","CertFilePath":"","KeyFilePath":"","NoStore":false,"IsClose":false,"AutoHttps":false,"Flow":{"ExportFlow":1446223,"InletFlow":1446223,"FlowLimit":0},"Client":{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"e9cba3f8a9","Addr":"127.0.0.1","LocalAddr":"172.16.10.6","Remark":"测试2","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":1446223,"InletFlow":1446223,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.38","BlackIpList":[],"CreateTime":"2026-08-24 11:20:39","LastOnlineTime":"2026-08-24 17:48:47","IpWhite":false,"IpWhitePass":"","IpWhiteList":[],"ExpireTime":""},"Target":{"TargetStr":"127.0.0.1:8443","TargetArr":["127.0.0.1:8443"],"LocalProxy":false}}
|
||||
*#*
|
||||
@@ -0,0 +1,2 @@
|
||||
# key -> user | value -> pwd
|
||||
npc=npc.pwd
|
||||
+43
-29
@@ -1,11 +1,20 @@
|
||||
[common]
|
||||
server=127.0.0.1:8024
|
||||
tp=tcp
|
||||
vkey=2dyy78gj7b9zw09l
|
||||
server_addr=127.0.0.1:8024
|
||||
conn_type=tcp
|
||||
vkey=123
|
||||
auto_reconnection=true
|
||||
[web]
|
||||
host=b.o.com
|
||||
target=10.1.50.203:80
|
||||
max_conn=1000
|
||||
flow_limit=1000
|
||||
rate_limit=1000
|
||||
basic_username=11
|
||||
basic_password=3
|
||||
web_username=user
|
||||
web_password=1234
|
||||
crypt=true
|
||||
compress=true
|
||||
#pprof_addr=0.0.0.0:9999
|
||||
disconnect_timeout=60
|
||||
tls_enable=true
|
||||
|
||||
[health_check_test1]
|
||||
health_check_timeout=1
|
||||
@@ -22,44 +31,49 @@ health_check_interval=1
|
||||
health_check_type=tcp
|
||||
health_check_target=127.0.0.1:8083,127.0.0.1:8082
|
||||
|
||||
[web]
|
||||
host=c.o.com
|
||||
target_addr=127.0.0.1:8083,127.0.0.1:8082
|
||||
|
||||
[tcp]
|
||||
mode=tcp
|
||||
target=127.0.0.1:8083,127.0.0.1:8082
|
||||
port=9006
|
||||
targetAddr=123.206.77.88
|
||||
target_addr=127.0.0.1:8080
|
||||
server_port=10000
|
||||
|
||||
[socks5]
|
||||
mode=socks5
|
||||
port=9005
|
||||
|
||||
[http]
|
||||
mode=httpProxy
|
||||
port=9004
|
||||
|
||||
server_port=19009
|
||||
multi_account=multi_account.conf
|
||||
|
||||
[file]
|
||||
mode=file
|
||||
port=9100
|
||||
local_path=./
|
||||
server_port=19008
|
||||
local_path=/Users/liuhe/Downloads
|
||||
strip_pre=/web/
|
||||
|
||||
[s_ssh]
|
||||
mode=secret
|
||||
password=1234
|
||||
target=123.206.77.88:22
|
||||
[http]
|
||||
mode=httpProxy
|
||||
server_port=19004
|
||||
|
||||
[udp]
|
||||
mode=udp
|
||||
port=53
|
||||
target=114.114.114.114:53
|
||||
server_port=12253
|
||||
target_addr=114.114.114.114:53
|
||||
|
||||
[p2p_ssh]
|
||||
port=2001
|
||||
password=p2pssh
|
||||
target=123.206.77.88:22
|
||||
[ssh_secret]
|
||||
mode=secret
|
||||
password=ssh2
|
||||
target_addr=123.206.77.88:22
|
||||
|
||||
[ssh_p2p]
|
||||
mode=p2p
|
||||
password=ssh3
|
||||
|
||||
[secret_ssh]
|
||||
port=2002
|
||||
password=1234
|
||||
local_port=2001
|
||||
password=ssh2
|
||||
|
||||
[p2p_ssh]
|
||||
local_port=2002
|
||||
password=ssh3
|
||||
target_addr=123.206.77.88:22
|
||||
+65
-19
@@ -1,18 +1,9 @@
|
||||
appname = nps
|
||||
#Boot mode(dev|pro)
|
||||
runmode = dev
|
||||
|
||||
|
||||
|
||||
#HTTP(S) proxy port, no startup if empty
|
||||
http_proxy_ip=0.0.0.0
|
||||
http_proxy_port=80
|
||||
#https_proxy_port=443
|
||||
https_just_proxy=true
|
||||
#certFile absolute path
|
||||
pem_path=conf/server.pem
|
||||
#KeyFile absolute path
|
||||
key_path=conf/server.key
|
||||
|
||||
https_proxy_port=443
|
||||
# 是否展示非【80】端口
|
||||
show_http_proxy_port=true
|
||||
##bridge
|
||||
bridge_type=tcp
|
||||
bridge_port=8024
|
||||
@@ -24,10 +15,11 @@ public_vkey=123
|
||||
|
||||
#Traffic data persistence interval(minute)
|
||||
#Ignorance means no persistence
|
||||
#flow_store_interval=1
|
||||
flow_store_interval=1
|
||||
|
||||
# log level LevelEmergency->0 LevelAlert->1 LevelCritical->2 LevelError->3 LevelWarning->4 LevelNotice->5 LevelInformational->6 LevelDebug->7
|
||||
log_level=7
|
||||
log_level=6
|
||||
log_path=nps.log
|
||||
|
||||
#Whether to restrict IP access, true or false or ignore
|
||||
#ip_limit=true
|
||||
@@ -40,10 +32,64 @@ log_level=7
|
||||
web_host=a.o.com
|
||||
web_username=admin
|
||||
web_password=123
|
||||
web_port = 8080
|
||||
web_port = 8081
|
||||
web_ip=0.0.0.0
|
||||
#Web API unauthenticated IP address
|
||||
auth_key=test
|
||||
auth_crypt_key =1234567812345678
|
||||
web_base_url=
|
||||
web_open_ssl=false
|
||||
web_cert_file=conf/server.pem
|
||||
web_key_file=conf/server.key
|
||||
# if web under proxy use sub path. like http://host/nps need this.
|
||||
#web_base_url=/nps
|
||||
|
||||
#Web API unauthenticated IP address(the len of auth_crypt_key must be 16)
|
||||
#Remove comments if needed
|
||||
#auth_key=test
|
||||
auth_key=123
|
||||
#获取服务端authKey时的aes加密密钥,16位
|
||||
auth_crypt_key =213
|
||||
|
||||
#allow_ports=9001-9009,10001,11000-12000
|
||||
|
||||
#Web management multi-user login
|
||||
allow_user_login=true
|
||||
allow_user_register=false
|
||||
allow_user_change_username=true
|
||||
|
||||
#extension
|
||||
#流量限制
|
||||
allow_flow_limit=true
|
||||
#带宽限制
|
||||
allow_rate_limit=true
|
||||
#客户端最大隧道数限制
|
||||
allow_tunnel_num_limit=true
|
||||
allow_local_proxy=false
|
||||
#客户端最大连接数
|
||||
allow_connection_num_limit=true
|
||||
#每个隧道监听不同的服务端端口
|
||||
allow_multi_ip=true
|
||||
system_info_display=true
|
||||
|
||||
#获取用户真实ip
|
||||
http_add_origin_header=true
|
||||
|
||||
#cache
|
||||
http_cache=false
|
||||
http_cache_length=100
|
||||
|
||||
#get origin ip
|
||||
#http_add_origin_header=false
|
||||
|
||||
#pprof debug options
|
||||
#pprof_ip=0.0.0.0
|
||||
#pprof_port=9999
|
||||
|
||||
#client disconnect timeout
|
||||
disconnect_timeout=60
|
||||
|
||||
#管理面板开启验证码校验
|
||||
open_captcha=false
|
||||
|
||||
|
||||
# 是否开启tls
|
||||
tls_enable=true
|
||||
tls_bridge_port=8025
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEA2MVLOHvgU8FCp6LgQrPfaWcGygrsRk7TL9hbT8MxbCRUSLV7
|
||||
Lbt3q5Knz8eTN4NWmwE6L5glOcH2x3Hnn+hPjbvgq35XBBIccAm0cYYKqoKkikeK
|
||||
FZM0Gp/WhSrhJ4laTyQqyleIFKpwD9kHDiC/sxjGDhSFmHKhhAnsQIRm2tppFXX0
|
||||
aAMqJEm88jzk1BN2QtKjEAn1u8v1+QW1KP3WuzdXH4L7hhMll66/KIm6Hfs2FRHQ
|
||||
pRUWqZeJY4q79NW5p5f+siGwOsGpxb/p11pM+0xnCH3UIFbm3zCTzP4sLvkfFGAe
|
||||
yAHsAwmaP8dJxh40ej3NN8uNiNvt8nw2Vb/1LwIDAQABAoIBAD40x/RKoEKIyE8B
|
||||
D6g0pB1EQo+CePFoN3SYewO1uR4WgtVmtxWVoa7r5BpdZGLe3uCWhpMX7z7W6bGs
|
||||
f1LFQOckjkHIfMIfTGfecRjO5Yqu+Pbxtq+gUah+S/plJr3IzdC+SUVNvzBnBMeX
|
||||
eU3Vmg2UQ2nQ+9GWu8D/c/vDwxx0X8oQ2G8QaxX0tUurlSMNA3M7xySwEvhx54fO
|
||||
UrDF3Q4yF48eA4butxVLFWf3cnlY+nR8uYd2vKfmp689/8C6kkfoM9igB78e93sm
|
||||
uDM2eRLm4kU5WLl301T42n6AF7w8J0MhLLVOIeLs4l5gZPa3uKvYFmuHQao7e/5R
|
||||
U/jHKrECgYEA8alPXuxFSVOvdhIsSN//Frj9CdExVdYmaLkt/2LO4FMnOaWh1xh7
|
||||
5iCY1bJT8D9dhfbqRg3qW2oguZD8gu04R8fTRegQ89qmAIwsEYqVf9salR41lZU4
|
||||
Rc+5yc7O11WIe9Lzu+ONFBFkAh3UFMR4zVZ/JhKIG/P5Srm7SUdKW2cCgYEA5aHo
|
||||
x2LR+yKhjkrBzHG3Qrfy1PtlYHjOpYYAKHQcBFuiG08W3CK/vkYl+mhv0uyhT7mn
|
||||
q6NDqrpZPRnDlOoEqgRS1X/QWKN6Pgd4HNLIawvp0vK9jYXDPcAXFzVthXCIwFcn
|
||||
3a3m4cHiuLdRNOHkydiHQyTOF6eEneN07TDvwvkCgYEApzOd1u9igPmFzQuF2GYi
|
||||
+HXFnaU/nUQuDwcQ7EJRIKRn31raPxiRoQesty5LJU6yRp4wOYgnPliPi9Tk4TGA
|
||||
XynC4/tMv2vorzhMxVY9Wdke602bhYNZC/RNd3O/aP2lEQdD3Bv04I2nxE8fDb9i
|
||||
VbAjCRSJV83WDf2zt1+78sECgYEAzezjRiKdcZu9y0/I+WEk2cUCE/MaF2he0FsZ
|
||||
uy1cjp/qAJltQ5452xUnK6cKWNlxU4CHF0mC/hC8xCldliZCZoEYE3PaUBLSJdwm
|
||||
35o6tpxpZI3gZJCG5NJlIp/8BkVDrVC7ZHV17hAkFEf4n/bPaB8wNYtE8jt8luaK
|
||||
TcarzGkCgYBn2alN0RLN2PHDurraFZB6GuCvh/arEjSCY3SDFQPF10CVjTDV7sx3
|
||||
eqJkwJ81syTmfJwZIceWbOFGgsuSx37UrQAVlHZSvzeqEg9dA5HqSoOACyidJI7j
|
||||
RG2+HB+KpsIZjGgLrEM4i7VOpYUDRdaouIXngFq/t9HNT+MDck5/Lw==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@@ -1,22 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDtTCCAp2gAwIBAgIJAPXRSiP0Fs7sMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
|
||||
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||
aWRnaXRzIFB0eSBMdGQwHhcNMTcxMTA3MDg1MzQ2WhcNMjcxMTA1MDg1MzQ2WjBF
|
||||
MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
|
||||
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
||||
CgKCAQEA2MVLOHvgU8FCp6LgQrPfaWcGygrsRk7TL9hbT8MxbCRUSLV7Lbt3q5Kn
|
||||
z8eTN4NWmwE6L5glOcH2x3Hnn+hPjbvgq35XBBIccAm0cYYKqoKkikeKFZM0Gp/W
|
||||
hSrhJ4laTyQqyleIFKpwD9kHDiC/sxjGDhSFmHKhhAnsQIRm2tppFXX0aAMqJEm8
|
||||
8jzk1BN2QtKjEAn1u8v1+QW1KP3WuzdXH4L7hhMll66/KIm6Hfs2FRHQpRUWqZeJ
|
||||
Y4q79NW5p5f+siGwOsGpxb/p11pM+0xnCH3UIFbm3zCTzP4sLvkfFGAeyAHsAwma
|
||||
P8dJxh40ej3NN8uNiNvt8nw2Vb/1LwIDAQABo4GnMIGkMB0GA1UdDgQWBBQdPc0R
|
||||
a8alY6Ab7voidkTGaH4PxzB1BgNVHSMEbjBsgBQdPc0Ra8alY6Ab7voidkTGaH4P
|
||||
x6FJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNV
|
||||
BAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAPXRSiP0Fs7sMAwGA1UdEwQF
|
||||
MAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAH1IZNkjuvt2nZPzXsuiVNyCE1vm346z
|
||||
naE0Uzt3aseAN9m/iiB8mLz+ryvWc2aFMX5lTdsHdm2rqmqBCBXeRwTLf4OeHIju
|
||||
ZQW6makWt6PxANEo6gbdPbQXbS420ssUhnR2irIH1SdI31iikVFPdiS0baRRE/gS
|
||||
+440M1jOOOnKm0Qin92ejsshmji/0qaD2+6D5TNw4HmIZaFTBw+kfjxCL6trfeBn
|
||||
4fT0RJ121V3G3+AtG5sWQ93B3pCg+jtD+fGKkNSLhphq84bD1Zv7l73QGOoylkEn
|
||||
Sc0ajTLOXFBb83yRdlgV3Da95jH9rDZ4jSod48m+KemoZTDQw0vSwAU=
|
||||
-----END CERTIFICATE-----
|
||||
@@ -1,5 +0,0 @@
|
||||
8025,socks5,,1,1,2,,0,0,
|
||||
8026,httpProxy,,1,2,2,,0,0,
|
||||
9002,tcp,127.0.0.1:8082,1,3,2,,0,0,
|
||||
9003,socks5,,1,5,5,,0,0,
|
||||
9009,tcp,127.0.0.1:8082,1,21,5,,8244480,2382592,
|
||||
|
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
cd /d D:\yisi\github\nps\docs
|
||||
yarn docs:dev > vuepress-dev.log 2> vuepress-dev.err.log
|
||||
@@ -0,0 +1,15 @@
|
||||
import { defineClientConfig } from 'vuepress/client'
|
||||
import { watch } from 'vue'
|
||||
import { usePageData, useRoute } from 'vuepress/client'
|
||||
|
||||
export default defineClientConfig({
|
||||
setup() {
|
||||
const page = usePageData()
|
||||
const route = useRoute()
|
||||
// eslint-disable-next-line no-console
|
||||
watch(() => route.path, () => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[debug] route:', route.path, 'headers:', JSON.stringify(page.value.headers))
|
||||
}, { immediate: true })
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,143 @@
|
||||
import type { SidebarConfig } from 'vuepress'
|
||||
import { defineUserConfig } from 'vuepress'
|
||||
import { viteBundler } from '@vuepress/bundler-vite'
|
||||
import { defaultTheme } from '@vuepress/theme-default'
|
||||
import { prismjsPlugin } from '@vuepress/plugin-prismjs'
|
||||
import { searchPlugin } from '@vuepress/plugin-search'
|
||||
|
||||
const serverSidebar: SidebarConfig = [
|
||||
{ text: '服务端', children: [
|
||||
{ text: '使用说明', link: '/server/nps_use.html' },
|
||||
{ text: '配置文件', link: '/server/server_config.html' },
|
||||
{ text: '增强功能', link: '/server/nps_extend.html' },
|
||||
]},
|
||||
]
|
||||
|
||||
const clientSidebar: SidebarConfig = [
|
||||
{ text: '客户端', children: [
|
||||
{ text: '使用说明', link: '/client/use.html' },
|
||||
{ text: '增强功能', link: '/client/npc_extend.html' },
|
||||
{ text: 'SDK', link: '/client/npc_sdk.html' },
|
||||
]},
|
||||
]
|
||||
|
||||
const extendSidebar: SidebarConfig = [
|
||||
{ text: '扩展', children: [
|
||||
{ text: '更多功能', link: '/extend/feature.html' },
|
||||
{ text: '配置示例', link: '/extend/example.html' },
|
||||
{ text: 'API接入方式', link: '/extend/api.html' },
|
||||
{ text: 'API 清单', link: '/extend/webapi.html' },
|
||||
]},
|
||||
]
|
||||
|
||||
export default defineUserConfig({
|
||||
base: '/nps/',
|
||||
bundler: viteBundler(),
|
||||
lang: 'zh-CN',
|
||||
title: 'NPS',
|
||||
description: 'NPS 内网穿透文档 — 服务端、客户端、Web API、增强功能、更新日志',
|
||||
head: [
|
||||
['link', { rel: 'icon', href: '/logo.svg' }],
|
||||
['meta', { name: 'theme-color', content: '#4f46e5' }],
|
||||
],
|
||||
|
||||
plugins: [
|
||||
prismjsPlugin({
|
||||
lineNumbers: true,
|
||||
}),
|
||||
searchPlugin({}),
|
||||
],
|
||||
|
||||
theme: defaultTheme({
|
||||
logo: '/logo.svg',
|
||||
repo: 'yisier/nps',
|
||||
repoLabel: 'GitHub',
|
||||
docsRepo: 'https://github.com/yisier/nps',
|
||||
docsBranch: 'master',
|
||||
docsDir: 'docs',
|
||||
editLink: true,
|
||||
editLinkText: '在 GitHub 上编辑此页',
|
||||
lastUpdated: true,
|
||||
lastUpdatedText: '最后更新',
|
||||
contributors: false,
|
||||
|
||||
navbar: [
|
||||
{ text: '首页', link: '/' },
|
||||
{ text: '快速上手', link: '/install/' },
|
||||
{
|
||||
text: '服务端',
|
||||
children: [
|
||||
{ text: '使用说明', link: '/server/nps_use.html' },
|
||||
{ text: '配置文件', link: '/server/server_config.html' },
|
||||
{ text: '增强功能', link: '/server/nps_extend.html' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: '客户端',
|
||||
children: [
|
||||
{ text: '使用说明', link: '/client/use.html' },
|
||||
{ text: '增强功能', link: '/client/npc_extend.html' },
|
||||
{ text: 'SDK', link: '/client/npc_sdk.html' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: '扩展',
|
||||
children: [
|
||||
{ text: '更多功能', link: '/extend/feature.html' },
|
||||
{ text: '配置示例', link: '/extend/example.html' },
|
||||
{ text: 'API接入方式', link: '/extend/api.html' },
|
||||
{ text: 'API 清单', link: '/extend/webapi.html' },
|
||||
],
|
||||
},
|
||||
{ text: '更新日志', link: '/changelog/' },
|
||||
],
|
||||
|
||||
sidebar: {
|
||||
'/install/': [
|
||||
{ text: '快速上手', link: '/install/' },
|
||||
],
|
||||
'/server/introduction.html': serverSidebar,
|
||||
'/server/nps_use.html': serverSidebar,
|
||||
'/server/server_config.html': serverSidebar,
|
||||
'/server/nps_extend.html': serverSidebar,
|
||||
'/client/use.html': clientSidebar,
|
||||
'/client/npc_extend.html': clientSidebar,
|
||||
'/client/npc_sdk.html': clientSidebar,
|
||||
'/extend/feature.html': extendSidebar,
|
||||
'/extend/example.html': extendSidebar,
|
||||
'/extend/api.html': extendSidebar,
|
||||
'/extend/webapi.html': extendSidebar,
|
||||
'/': [
|
||||
{ text: '首页', link: '/' },
|
||||
{ text: '快速上手', link: '/install/' },
|
||||
{
|
||||
text: '服务端',
|
||||
children: [
|
||||
{ text: '使用说明', link: '/server/nps_use.html' },
|
||||
{ text: '配置文件', link: '/server/server_config.html' },
|
||||
{ text: '增强功能', link: '/server/nps_extend.html' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: '客户端',
|
||||
children: [
|
||||
{ text: '使用说明', link: '/client/use.html' },
|
||||
{ text: '增强功能', link: '/client/npc_extend.html' },
|
||||
{ text: 'SDK', link: '/client/npc_sdk.html' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: '扩展',
|
||||
children: [
|
||||
{ text: '功能', link: '/extend/feature.html' },
|
||||
{ text: '配置示例', link: '/extend/example.html' },
|
||||
{ text: 'API接入方式', link: '/extend/api.html' },
|
||||
{ text: 'Web API 详细', link: '/extend/webapi.html' },
|
||||
],
|
||||
},
|
||||
{ text: '更新日志', link: '/changelog/' },
|
||||
],
|
||||
},
|
||||
sidebarDepth: 2,
|
||||
}),
|
||||
})
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user