Compare commits
584 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
0ed7071e8e | 2 years ago |
|
|
2f7070377f | 2 years ago |
|
|
f2a586ca78 | 2 years ago |
|
|
d1984a06a3 | 2 years ago |
|
|
7a4fb1daf7 | 2 years ago |
|
|
f6f66a3b24 | 2 years ago |
|
|
46ae1127a2 | 2 years ago |
|
|
45048315cd | 2 years ago |
|
|
2f51b5612b | 2 years ago |
|
|
f3355eda4f | 2 years ago |
|
|
b445a1bb69 | 2 years ago |
|
|
018a3f15fd | 2 years ago |
|
|
aa30b0b4af | 2 years ago |
|
|
f42a6c2d08 | 2 years ago |
|
|
a14f16eeef | 2 years ago |
|
|
0a6a7693a1 | 2 years ago |
|
|
bdfbbd0e8f | 2 years ago |
|
|
44c3180df7 | 2 years ago |
|
|
cb3599e721 | 2 years ago |
|
|
745e98d1a9 | 2 years ago |
|
|
796005fad4 | 2 years ago |
|
|
53eac765a2 | 2 years ago |
|
|
86ebed7953 | 2 years ago |
|
|
f4f74e3d11 | 2 years ago |
|
|
be43a6ab20 | 2 years ago |
|
|
ec312c9f28 | 2 years ago |
|
|
2feefbe65e | 2 years ago |
|
|
57e82cd3c7 | 2 years ago |
|
|
4179fad640 | 2 years ago |
|
|
e93455a302 | 2 years ago |
|
|
c2e395463b | 2 years ago |
|
|
15f8095b99 | 2 years ago |
|
|
475b1ec088 | 2 years ago |
|
|
eb890652eb | 2 years ago |
|
|
45766cf117 | 2 years ago |
|
|
324a7635cd | 2 years ago |
|
|
bc92c0f344 | 2 years ago |
|
|
c700a29e17 | 2 years ago |
|
|
5d49bda104 | 2 years ago |
|
|
6f6540ace1 | 2 years ago |
|
|
2cce7849f2 | 2 years ago |
|
|
b0d64e41e0 | 2 years ago |
|
|
6ab37fa08a | 2 years ago |
|
|
d45355e71a | 2 years ago |
|
|
bf4d2e8c90 | 2 years ago |
|
|
cedcb61fbd | 2 years ago |
|
|
7650af1fa2 | 2 years ago |
|
|
b147ecc44d | 2 years ago |
|
|
713165f360 | 2 years ago |
|
|
66320c2044 | 2 years ago |
|
|
3058f48602 | 2 years ago |
|
|
06091651f9 | 2 years ago |
|
|
89632dcacf | 2 years ago |
|
|
131c0fd5dd | 2 years ago |
|
|
a0dde8f6d3 | 2 years ago |
|
|
3d57f1acc4 | 2 years ago |
|
|
9a9e4f18f1 | 2 years ago |
|
|
6200b316b2 | 2 years ago |
|
|
1013b41001 | 2 years ago |
|
|
37d5ff3c6c | 2 years ago |
|
|
02b4a99160 | 2 years ago |
|
|
2a03eb7740 | 2 years ago |
|
|
43fb701425 | 2 years ago |
|
|
6c7b644f60 | 2 years ago |
|
|
f1c0f8ddca | 2 years ago |
|
|
013d810678 | 2 years ago |
|
|
226827f21e | 2 years ago |
|
|
cd0c79cfdf | 2 years ago |
|
|
aece83403c | 2 years ago |
|
|
8da309bb88 | 2 years ago |
|
|
e485dd3fac | 2 years ago |
|
|
ea354789d3 | 2 years ago |
|
|
3bd70475ef | 2 years ago |
|
|
85d74932a0 | 2 years ago |
|
|
581efa89f9 | 2 years ago |
|
|
e2a3611f57 | 2 years ago |
|
|
83981349d7 | 2 years ago |
|
|
53c57b2d3d | 2 years ago |
|
|
e3b0c392ab | 2 years ago |
|
|
e65ce0d87e | 2 years ago |
|
|
4d088f6a44 | 2 years ago |
|
|
e72e8cef57 | 2 years ago |
|
|
31bbab71c9 | 2 years ago |
|
|
3a035e9930 | 2 years ago |
|
|
a0e3d1ee91 | 2 years ago |
|
|
e9aa8d3e9d | 2 years ago |
|
|
40d6a07514 | 2 years ago |
|
|
11c733547f | 2 years ago |
|
|
d0af8bd427 | 2 years ago |
|
|
e8d160d713 | 2 years ago |
|
|
26827b5114 | 2 years ago |
|
|
c9370a0562 | 2 years ago |
|
|
1c1da92363 | 2 years ago |
|
|
e75dce92ad | 2 years ago |
|
|
ace8d7a0fe | 2 years ago |
|
|
5dd2c8f931 | 2 years ago |
|
|
53ae1a1ef9 | 2 years ago |
|
|
eb9ede5a4e | 2 years ago |
|
|
7646b87da0 | 2 years ago |
|
|
106397ed27 | 2 years ago |
|
|
e05d91e8b3 | 2 years ago |
|
|
4660a46a7e | 2 years ago |
|
|
532d6e83c5 | 2 years ago |
|
|
b9c7d1d001 | 2 years ago |
|
|
2d6fa63964 | 2 years ago |
|
|
e1a5521f4a | 2 years ago |
|
|
ada02323d8 | 2 years ago |
|
|
2b6e84ab62 | 2 years ago |
|
|
45a136380d | 2 years ago |
|
|
a48fde8be3 | 2 years ago |
|
|
08ed0693ca | 2 years ago |
|
|
bcff00c47b | 2 years ago |
|
|
46e78f4405 | 2 years ago |
|
|
afd6bf4268 | 2 years ago |
|
|
b68e8a1403 | 2 years ago |
|
|
a5dda59ad5 | 2 years ago |
|
|
3a22861640 | 2 years ago |
|
|
802d05f692 | 2 years ago |
|
|
5abd9b75bb | 2 years ago |
|
|
8d8ba150ef | 2 years ago |
|
|
42cd7093a9 | 2 years ago |
|
|
852838a521 | 2 years ago |
|
|
3a600be3b3 | 2 years ago |
|
|
d389bb07ae | 2 years ago |
|
|
01644ccd19 | 2 years ago |
|
|
da682cc3d6 | 2 years ago |
|
|
7c21aa2377 | 2 years ago |
|
|
f5a0a9ed50 | 2 years ago |
|
|
7ef4fec896 | 2 years ago |
|
|
f41b6bc07b | 2 years ago |
|
|
43c5419fc6 | 2 years ago |
|
|
fb2ea7ec7d | 2 years ago |
|
|
743daaa56f | 2 years ago |
|
|
cff843b82b | 2 years ago |
|
|
ccb04c07d8 | 2 years ago |
|
|
204ffaed6d | 2 years ago |
|
|
ff1399e044 | 2 years ago |
|
|
d6b22c157c | 2 years ago |
|
|
3b937ee0f4 | 2 years ago |
|
|
7a9aa3a33b | 2 years ago |
|
|
7f3f23d706 | 2 years ago |
|
|
1722d74670 | 2 years ago |
|
|
b69872dd50 | 2 years ago |
|
|
f8c3ced1d9 | 2 years ago |
|
|
7fb84597cf | 2 years ago |
|
|
ff7e3e79ca | 2 years ago |
|
|
bd6609226b | 2 years ago |
|
|
ce7d95210d | 2 years ago |
|
|
24cf21b18a | 2 years ago |
|
|
7d5104e550 | 2 years ago |
|
|
6f349aa12a | 2 years ago |
|
|
9aac7c2e4c | 2 years ago |
|
|
65befe282b | 2 years ago |
|
|
47d4013f3d | 2 years ago |
|
|
217f4dc417 | 2 years ago |
|
|
b3486a42a5 | 2 years ago |
|
|
11e460765a | 2 years ago |
|
|
805934567a | 2 years ago |
|
|
993e4a903d | 2 years ago |
|
|
59024f57a3 | 2 years ago |
|
|
a3659017a2 | 2 years ago |
|
|
80a8b1de97 | 2 years ago |
|
|
cb303bad7e | 2 years ago |
|
|
020a9ba2f2 | 2 years ago |
|
|
c8502ad7bf | 3 years ago |
|
|
0e3a824c11 | 3 years ago |
|
|
f52c84ea21 | 3 years ago |
|
|
538be53e9c | 3 years ago |
|
|
c1c1094544 | 3 years ago |
|
|
6302454826 | 3 years ago |
|
|
189f623994 | 3 years ago |
|
|
7ce0c1f951 | 3 years ago |
|
|
0d5a1f3a8c | 3 years ago |
|
|
191b6bae10 | 3 years ago |
|
|
931f7a8737 | 3 years ago |
|
|
d6d7cdbb1f | 3 years ago |
|
|
392cac4186 | 3 years ago |
|
|
c18f8f0b27 | 3 years ago |
|
|
621772bafa | 3 years ago |
|
|
1ac1d150c0 | 3 years ago |
|
|
e0366f949f | 3 years ago |
|
|
29f1b7db89 | 3 years ago |
|
|
9a13ee601c | 3 years ago |
|
|
a689608bdb | 3 years ago |
|
|
b429c15893 | 3 years ago |
|
|
cc5d2be1bd | 3 years ago |
|
|
1e9de6f21b | 3 years ago |
|
|
4c74bc8619 | 3 years ago |
|
|
13c4eb04a3 | 3 years ago |
|
|
cb0fb47e1c | 3 years ago |
|
|
a82ad2aea4 | 3 years ago |
|
|
d4fbeef498 | 3 years ago |
|
|
2071891841 | 3 years ago |
|
|
9413978697 | 3 years ago |
|
|
f0dafa79f2 | 3 years ago |
|
|
8623e1e89b | 3 years ago |
|
|
ee30e840e3 | 3 years ago |
|
|
7669e34b62 | 3 years ago |
|
|
abc73bbf77 | 3 years ago |
|
|
45a68112b1 | 3 years ago |
|
|
070c0b4620 | 3 years ago |
|
|
9bd1507392 | 3 years ago |
|
|
bd0bbe95ef | 3 years ago |
|
|
be784a4a88 | 3 years ago |
|
|
02d279fa97 | 3 years ago |
|
|
4f06d80a2e | 3 years ago |
|
|
92fced15db | 3 years ago |
|
|
1bf72009dc | 3 years ago |
|
|
7ee7b12cac | 3 years ago |
|
|
4ad5e77fd3 | 3 years ago |
|
|
7be4a70824 | 3 years ago |
|
|
d3e9d92750 | 3 years ago |
|
|
dd56fecc53 | 3 years ago |
|
|
660f11a50e | 3 years ago |
|
|
be5eae0df9 | 3 years ago |
|
|
49a0c6fa87 | 3 years ago |
|
|
d0924eb4ae | 3 years ago |
|
|
1e9c537bdb | 3 years ago |
|
|
405fdb7c34 | 3 years ago |
|
|
642e21a260 | 3 years ago |
|
|
2ee82e774b | 3 years ago |
|
|
e84ea98be9 | 3 years ago |
|
|
3b116b3654 | 3 years ago |
|
|
08631437ee | 3 years ago |
|
|
cfa7629c30 | 3 years ago |
|
|
a0013b5cef | 3 years ago |
|
|
7d22e86f35 | 3 years ago |
|
|
e16b077d20 | 3 years ago |
|
|
e3876cffaf | 3 years ago |
|
|
49b41d6eb7 | 3 years ago |
|
|
3e90b838fd | 3 years ago |
|
|
464e84a64f | 3 years ago |
|
|
f0dcd67004 | 3 years ago |
|
|
e77d37bbaa | 3 years ago |
|
|
4c7e037b76 | 3 years ago |
|
|
59d59dd3ed | 3 years ago |
|
|
376e2a76d1 | 3 years ago |
|
|
b60d6096fa | 3 years ago |
|
|
4e52563d59 | 3 years ago |
|
|
386c927791 | 3 years ago |
|
|
ab96e9c54d | 3 years ago |
|
|
5a8b3902d3 | 3 years ago |
|
|
9aaeff2fc3 | 3 years ago |
|
|
91d566a377 | 3 years ago |
|
|
4289d55562 | 3 years ago |
|
|
aeed27a2fa | 3 years ago |
|
|
67b60a620f | 3 years ago |
|
|
979a1d5326 | 3 years ago |
|
|
1577eb184d | 3 years ago |
|
|
1cdd2f9830 | 3 years ago |
|
|
645d6c4fbf | 3 years ago |
|
|
744f8bc93b | 3 years ago |
|
|
4b277cf3c1 | 3 years ago |
|
|
7b25eb4d27 | 3 years ago |
|
|
bef697b098 | 3 years ago |
|
|
71445a8a88 | 3 years ago |
|
|
55f688900a | 3 years ago |
|
|
cbe4da76cd | 3 years ago |
|
|
1d6e61c744 | 3 years ago |
|
|
8965edb0b4 | 3 years ago |
|
|
7640c1fdc3 | 3 years ago |
|
|
c8cd3e6186 | 3 years ago |
|
|
0fa98703cd | 3 years ago |
|
|
b7f50f0053 | 3 years ago |
|
|
b61534ebfe | 3 years ago |
|
|
0d140b41da | 3 years ago |
|
|
b1e95d30f1 | 3 years ago |
|
|
0a24469248 | 3 years ago |
|
|
9ed10d65ba | 3 years ago |
|
|
fcf625f55e | 3 years ago |
|
|
cde3732ca6 | 3 years ago |
|
|
8d9e763503 | 3 years ago |
|
|
17e511a2e5 | 3 years ago |
|
|
36e6ec555a | 3 years ago |
|
|
fdaa11872a | 3 years ago |
|
|
99da617d61 | 3 years ago |
|
|
1c4fb7afcc | 3 years ago |
|
|
c66250532e | 3 years ago |
|
|
371adde8b6 | 3 years ago |
|
|
97ec26331b | 3 years ago |
|
|
f727218a28 | 3 years ago |
|
|
547aeeadd3 | 3 years ago |
|
|
22d62e420b | 3 years ago |
|
|
a095c88fd2 | 3 years ago |
|
|
fd519aea5e | 3 years ago |
|
|
c3b22c1b27 | 3 years ago |
|
|
9be508c976 | 3 years ago |
|
|
e12e83c90a | 3 years ago |
|
|
e3b1bfbf50 | 3 years ago |
|
|
1338182b86 | 3 years ago |
|
|
3bbe56cdc4 | 3 years ago |
|
|
66571bc1d4 | 3 years ago |
|
|
2526d71c0e | 3 years ago |
|
|
abe43c5c4d | 3 years ago |
|
|
371472e67b | 3 years ago |
|
|
4e369baddb | 3 years ago |
|
|
e1c38e28a8 | 3 years ago |
|
|
4eb32538db | 3 years ago |
|
|
43f07cc98f | 3 years ago |
|
|
da2c6d83d6 | 3 years ago |
|
|
db832d045b | 3 years ago |
|
|
1950d9a86a | 3 years ago |
|
|
de8d6073a3 | 3 years ago |
|
|
a798b2cce9 | 3 years ago |
|
|
741ffa14b0 | 3 years ago |
|
|
4c1112c023 | 3 years ago |
|
|
e247471d5b | 3 years ago |
|
|
33b9c1a4f3 | 3 years ago |
|
|
f03756ad8a | 3 years ago |
|
|
0381d2290c | 3 years ago |
|
|
398eea2159 | 3 years ago |
|
|
b0a3989ef4 | 3 years ago |
|
|
8581bdd3c6 | 3 years ago |
|
|
d67b8428e4 | 3 years ago |
|
|
d70e37c857 | 3 years ago |
|
|
f20d97a9fd | 3 years ago |
|
|
140cd170ed | 3 years ago |
|
|
40a17d0e72 | 3 years ago |
|
|
49f70bc9e9 | 3 years ago |
|
|
1658e4b5a3 | 3 years ago |
|
|
99d6983924 | 3 years ago |
|
|
d5c7d7afe8 | 3 years ago |
|
|
a66bc142dd | 3 years ago |
|
|
81db62b5ba | 3 years ago |
|
|
2d52ada657 | 3 years ago |
|
|
712a4d2185 | 3 years ago |
|
|
e7d394b73b | 3 years ago |
|
|
526fedd04a | 3 years ago |
|
|
79d0d37526 | 3 years ago |
|
|
70c89b794e | 3 years ago |
|
|
e093d9276c | 3 years ago |
|
|
85da74b3f0 | 3 years ago |
|
|
af9395ad69 | 3 years ago |
|
|
a03ef576bd | 3 years ago |
|
|
53cedb56da | 3 years ago |
|
|
667594bdd4 | 3 years ago |
|
|
ab7b137074 | 3 years ago |
|
|
e945de0309 | 3 years ago |
|
|
7f9f06dfbf | 3 years ago |
|
|
68afb7e7e8 | 3 years ago |
|
|
626196a239 | 3 years ago |
|
|
5a19133254 | 3 years ago |
|
|
6d5f34751d | 3 years ago |
|
|
18f2b4aba8 | 3 years ago |
|
|
38c9727e15 | 3 years ago |
|
|
ec93ab05a3 | 3 years ago |
|
|
827e76c46e | 3 years ago |
|
|
0a9e23daf4 | 3 years ago |
|
|
0a1ac06266 | 3 years ago |
|
|
f2f2ee1379 | 3 years ago |
|
|
a63e85aa37 | 3 years ago |
|
|
9a18005eae | 3 years ago |
|
|
591486a689 | 3 years ago |
|
|
53e1c32444 | 3 years ago |
|
|
dfee30e9d9 | 3 years ago |
|
|
fc0895fe62 | 3 years ago |
|
|
6c8bfd267a | 3 years ago |
|
|
2649b710bb | 3 years ago |
|
|
9c16b55dde | 3 years ago |
|
|
384c2ae8aa | 3 years ago |
|
|
d9d8bee5d0 | 3 years ago |
|
|
b2854d4965 | 3 years ago |
|
|
43074728bf | 3 years ago |
|
|
aec519499f | 3 years ago |
|
|
04bf8ec487 | 3 years ago |
|
|
a7e523b47b | 3 years ago |
|
|
4984771c7d | 3 years ago |
|
|
9a6900b07f | 3 years ago |
|
|
17d6216e36 | 3 years ago |
|
|
d1cbc72044 | 3 years ago |
|
|
013dc0bd52 | 3 years ago |
|
|
9d62b3ef03 | 3 years ago |
|
|
40ca44d183 | 3 years ago |
|
|
33039f0195 | 3 years ago |
|
|
d2ba3ebad3 | 3 years ago |
|
|
0e8798cd90 | 3 years ago |
|
|
d4d5bd41c2 | 3 years ago |
|
|
0a4c1cd1ac | 3 years ago |
|
|
ce7ccb6d4c | 3 years ago |
|
|
b19b9cfe9e | 3 years ago |
|
|
0e28506bdd | 3 years ago |
|
|
179995c4b0 | 3 years ago |
|
|
f7d9f2564f | 3 years ago |
|
|
30f75ff7cd | 3 years ago |
|
|
7c6b4fec91 | 3 years ago |
|
|
6fa90a15e4 | 3 years ago |
|
|
b6cbc34e6f | 3 years ago |
|
|
fcf789e271 | 3 years ago |
|
|
c068d4b8a4 | 3 years ago |
|
|
3035d32676 | 3 years ago |
|
|
582852f6e9 | 3 years ago |
|
|
26788f301f | 3 years ago |
|
|
4bab7b243d | 3 years ago |
|
|
f6712a80bb | 3 years ago |
|
|
994b9087ae | 3 years ago |
|
|
ddb6cee153 | 3 years ago |
|
|
ac68fd05c9 | 3 years ago |
|
|
7c47f08a72 | 3 years ago |
|
|
ca683f9c7f | 3 years ago |
|
|
a49d9e0037 | 3 years ago |
|
|
5b3cd981e9 | 3 years ago |
|
|
002d9c22ab | 3 years ago |
|
|
c783b962ac | 3 years ago |
|
|
fc4b503952 | 3 years ago |
|
|
8d75e1750d | 3 years ago |
|
|
6dd0ec46a3 | 3 years ago |
|
|
37fa8b899f | 3 years ago |
|
|
ed72b67300 | 3 years ago |
|
|
b955e84668 | 3 years ago |
|
|
3098af113c | 3 years ago |
|
|
dcdd87ac1b | 3 years ago |
|
|
33f64ffee9 | 3 years ago |
|
|
baa4c08264 | 3 years ago |
|
|
55c17a674e | 3 years ago |
|
|
7a94734d99 | 3 years ago |
|
|
14903b6aa6 | 3 years ago |
|
|
2679527cce | 3 years ago |
|
|
4e85d72e96 | 3 years ago |
|
|
9524e89c17 | 3 years ago |
|
|
23b39a80ab | 3 years ago |
|
|
ab1adcfa3d | 3 years ago |
|
|
d325dd7493 | 3 years ago |
|
|
287ef7527d | 3 years ago |
|
|
5ab50b8a93 | 3 years ago |
|
|
60798b5f4a | 3 years ago |
|
|
b475d8b609 | 3 years ago |
|
|
50b4fbcda4 | 3 years ago |
|
|
d272f7900f | 3 years ago |
|
|
45c4b130ff | 3 years ago |
|
|
087a93d5fb | 3 years ago |
|
|
6993cc67e3 | 3 years ago |
|
|
98e08786b0 | 3 years ago |
|
|
50dc75eb22 | 3 years ago |
|
|
8aa9363bbe | 3 years ago |
|
|
e5a5889931 | 3 years ago |
|
|
c1193a5b8c | 3 years ago |
|
|
91817a3a32 | 3 years ago |
|
|
500998b49f | 3 years ago |
|
|
867669cb90 | 3 years ago |
|
|
831e90b14b | 3 years ago |
|
|
08bfa6b221 | 3 years ago |
|
|
d84dbffb54 | 3 years ago |
|
|
c578f26054 | 3 years ago |
|
|
7fe3517afe | 3 years ago |
|
|
34289150fa | 3 years ago |
|
|
9a4174e6ef | 3 years ago |
|
|
4b567e474c | 3 years ago |
|
|
7aa1765dda | 3 years ago |
|
|
1fa90acc3e | 3 years ago |
|
|
9bdedc0151 | 3 years ago |
|
|
04a61c6200 | 3 years ago |
|
|
3ee8ef0523 | 3 years ago |
|
|
ba4aeb85ca | 3 years ago |
|
|
4ec19c9cda | 3 years ago |
|
|
13c24ede28 | 3 years ago |
|
|
3843fe9cef | 3 years ago |
|
|
82eabbf17e | 3 years ago |
|
|
8ac5fc2052 | 3 years ago |
|
|
9f19d15da9 | 3 years ago |
|
|
32c89ac8b6 | 3 years ago |
|
|
ff442a9a15 | 3 years ago |
|
|
2982782721 | 3 years ago |
|
|
5fcad2311b | 3 years ago |
|
|
4b75aed9f6 | 3 years ago |
|
|
ee79a2f309 | 3 years ago |
|
|
f08b60656f | 3 years ago |
|
|
33e5c4b2f6 | 3 years ago |
|
|
5eda4abe45 | 3 years ago |
|
|
2cba64c989 | 3 years ago |
|
|
5165554282 | 3 years ago |
|
|
5cf11813e9 | 3 years ago |
|
|
8cc71942c8 | 3 years ago |
|
|
6ede443bbe | 3 years ago |
|
|
477bec07d8 | 3 years ago |
|
|
21a6acb95b | 3 years ago |
|
|
4e14d26b3f | 3 years ago |
|
|
61ce1938b4 | 3 years ago |
|
|
56540330f6 | 3 years ago |
|
|
b257edde86 | 3 years ago |
|
|
de9bcff99b | 3 years ago |
|
|
4dadecc98a | 3 years ago |
|
|
01611ef622 | 3 years ago |
|
|
cc6a325ddd | 3 years ago |
|
|
2bc14bd23b | 3 years ago |
|
|
0c1b5f12c6 | 3 years ago |
|
|
1a2aabf5df | 4 years ago |
|
|
b057d92ff0 | 4 years ago |
|
|
6b98c4a0c8 | 4 years ago |
|
|
a2fba39b13 | 4 years ago |
|
|
9dcb867d60 | 4 years ago |
|
|
b8177e8151 | 4 years ago |
|
|
1226259b79 | 4 years ago |
|
|
e1119f0e62 | 4 years ago |
|
|
6fefa97ecc | 4 years ago |
|
|
3403ab3e52 | 4 years ago |
|
|
cb5196b11c | 4 years ago |
|
|
4b1c1b059b | 4 years ago |
|
|
fe99d83456 | 4 years ago |
|
|
5746d5db2e | 4 years ago |
|
|
a299c0b82c | 4 years ago |
|
|
ccf548e7b7 | 4 years ago |
|
|
95093e8bf9 | 4 years ago |
|
|
0d1836b4f0 | 4 years ago |
|
|
9f2a169fff | 4 years ago |
|
|
5b44a72082 | 4 years ago |
|
|
aa6acbd18c | 4 years ago |
|
|
fbc44dc794 | 4 years ago |
|
|
8ab5b89ac2 | 4 years ago |
|
|
304ffc36fd | 4 years ago |
|
|
6ba6e63138 | 4 years ago |
|
|
8da49272b3 | 4 years ago |
|
|
6ce6d43916 | 4 years ago |
|
|
1a78cebd50 | 4 years ago |
|
|
509d059ceb | 4 years ago |
|
|
e38380aac0 | 4 years ago |
|
|
d9f78318f1 | 4 years ago |
|
|
e793d9d882 | 4 years ago |
|
|
d3184ff8d0 | 4 years ago |
|
|
b1b6e8fec8 | 4 years ago |
|
|
0265e44c17 | 4 years ago |
|
|
3ae494ae9d | 4 years ago |
|
|
8f683eb632 | 4 years ago |
|
|
1e827fcdd7 | 4 years ago |
|
|
ce8c1b1268 | 4 years ago |
|
|
808ca3d508 | 4 years ago |
|
|
ca3d19a5d7 | 4 years ago |
|
|
21cd91b163 | 4 years ago |
|
|
228a36b079 | 4 years ago |
|
|
aee3b87076 | 4 years ago |
|
|
969781f720 | 4 years ago |
|
|
1f4e732d14 | 4 years ago |
|
|
2635d0134c | 4 years ago |
|
|
57e1d066c0 | 4 years ago |
|
|
f73e733a2c | 4 years ago |
|
|
d44148cd64 | 4 years ago |
|
|
aa1258e0a5 | 4 years ago |
|
|
4135146b67 | 4 years ago |
|
|
0bae0e0912 | 4 years ago |
|
|
db1b34fef1 | 4 years ago |
|
|
5021e6f4ab | 4 years ago |
|
|
8e88d6a4b3 | 4 years ago |
|
|
5e7bc3112d | 4 years ago |
|
|
d158857361 | 4 years ago |
|
|
8c5ee48719 | 4 years ago |
|
|
6c38b11ab3 | 4 years ago |
|
|
bc6a25cd1f | 4 years ago |
|
|
cbc443eb64 | 4 years ago |
|
|
8a498adcb2 | 4 years ago |
|
|
fe4f33dd19 | 4 years ago |
|
|
3d9748b17f | 4 years ago |
|
|
47ea62adb2 | 4 years ago |
|
|
a7f583bdca | 4 years ago |
|
|
8857165f9c | 4 years ago |
|
|
c49c987dc6 | 4 years ago |
|
|
d4762f66a5 | 4 years ago |
|
|
9f9c60ff71 | 4 years ago |
|
|
3ed9ff1a19 | 4 years ago |
|
|
26524d20fb | 4 years ago |
|
|
90af155e1b | 4 years ago |
|
|
18ed5deaee | 4 years ago |
|
|
7deaef920d | 4 years ago |
|
|
cab5ff2c78 | 4 years ago |
|
|
2529ca90ca | 4 years ago |
|
|
af12612343 | 4 years ago |
|
|
59ca8d9eb8 | 4 years ago |
|
|
6bc6ceac19 | 4 years ago |
|
|
f305701b30 | 4 years ago |
|
|
2831208de3 | 4 years ago |
|
|
efda5a84dc | 4 years ago |
|
|
c35433f235 | 4 years ago |
|
|
20ad17bbfa | 4 years ago |
|
|
9ac5708eca | 4 years ago |
|
|
a2fe98e1a2 | 4 years ago |
|
|
5b34f0f052 | 4 years ago |
|
|
c16ea53ed1 | 4 years ago |
|
|
fd342e6075 | 4 years ago |
|
|
9eab625ee5 | 4 years ago |
|
|
716858ebdc | 4 years ago |
|
|
0982878211 | 4 years ago |
|
|
82704733a4 | 4 years ago |
|
|
1ee5700aa0 | 4 years ago |
|
|
b8b17d8cc9 | 4 years ago |
|
|
47572984ea | 4 years ago |
|
|
ee1f67b3cd | 4 years ago |
@ -0,0 +1,4 @@
|
||||
.git
|
||||
app/node_modules
|
||||
.idea
|
||||
tmp
|
||||
@ -1,15 +1,16 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
block_comment_start = /*
|
||||
block_comment_end = */
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.go]
|
||||
indent_size = 4
|
||||
|
||||
[README.md]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/app"
|
||||
target-branch: "dev"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
target-branch: "dev"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
@ -1,255 +1,266 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
paths:
|
||||
- "**/*.js"
|
||||
- "**/*.vue"
|
||||
- "frontend/package.json"
|
||||
- "frontend/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/*.yml"
|
||||
- "resources/*"
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "**/*.js"
|
||||
- "**/*.vue"
|
||||
- "frontend/package.json"
|
||||
- "frontend/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/*.yml"
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
- '!weblate'
|
||||
paths:
|
||||
- "app/**/*.js"
|
||||
- "app/**/*.vue"
|
||||
- "app/src/language/**/*.po"
|
||||
- "app/i18n.json"
|
||||
- "app/package.json"
|
||||
- "app/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/build*.yml"
|
||||
- "resources/docker/docker/*"
|
||||
- "resources/development/*"
|
||||
- "resources/demo/*"
|
||||
- "Dockerfile"
|
||||
- "demo.Dockerfile"
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "**/*.js"
|
||||
- "**/*.vue"
|
||||
- "app/package.json"
|
||||
- "app/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/*.yml"
|
||||
- "resources/docker/docker/*"
|
||||
- "resources/development/*"
|
||||
- "resources/demo/*"
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
build_frontend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up nodejs
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: 'frontend/yarn.lock'
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install
|
||||
working-directory: frontend
|
||||
|
||||
- name: Update translations
|
||||
run: yarn gettext:compile
|
||||
working-directory: frontend
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
npx browserslist@latest --update-db
|
||||
yarn build
|
||||
working-directory: frontend
|
||||
|
||||
- name: Archive frontend artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: frontend-dist
|
||||
path: frontend/dist
|
||||
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md frontend/dist
|
||||
find frontend/dist -printf '%P\n' | tar -C frontend/dist --no-recursion -zcvf frontend-dist.tar.gz -T -
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: frontend-dist.tar.gz
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build_frontend
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [ linux, darwin ]
|
||||
goarch: [ amd64, 386, arm64 ]
|
||||
exclude:
|
||||
# Exclude i386 on darwin.
|
||||
- goarch: 386
|
||||
goos: darwin
|
||||
include:
|
||||
# BEGIN Linux ARM 5 6 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 6
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 5
|
||||
# END Linux ARM 5 6 7
|
||||
env:
|
||||
CGO_ENABLED: 1
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
GOARM: ${{ matrix.goarm }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ^1.20.1
|
||||
|
||||
- name: Set up cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}-go-
|
||||
|
||||
- name: Setup compiler environment
|
||||
id: info
|
||||
run: |
|
||||
export _NAME=nginx-ui-$(jq ".$GOOS[\"$GOARCH$GOARM\"].name" -r < .github/build/build_info.json)
|
||||
export _ARCH=$(jq ".$GOOS[\"$GOARCH$GOARM\"].arch" -r < .github/build/build_info.json)
|
||||
export _ABI=$(jq ".$GOOS[\"$GOARCH$GOARM\"].abi // \"\"" -r < .github/build/build_info.json)
|
||||
export _ARTIFACT=nginx-ui-$GOOS-$GOARCH$(if [[ "$GOARM" ]]; then echo "v$GOARM"; fi)
|
||||
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME, ARTIFACT_NAME: $_ARTIFACT"
|
||||
echo "ARCH_NAME=$_ARCH" >> $GITHUB_ENV
|
||||
echo "ABI=$_ABI" >> $GITHUB_ENV
|
||||
echo "DIST=$_NAME" >> $GITHUB_ENV
|
||||
echo "ARTIFACT=$_ARTIFACT" >> $GITHUB_ENV
|
||||
|
||||
- name: Install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
uses: 0xJacky/musl-cross-compilers@v0.6.5
|
||||
id: musl
|
||||
with:
|
||||
target: ${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}
|
||||
|
||||
- name: Post install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
run: |
|
||||
echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-gcc" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-g++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=--extldflags '-static'" >> $GITHUB_ENV
|
||||
|
||||
- name: Install darwin cross compiler
|
||||
if: env.GOOS == 'darwin'
|
||||
run: |
|
||||
curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
|
||||
tar xvaf crossosx.tar.zst
|
||||
echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
|
||||
echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-clang" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-clang++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=-s -w" >> $GITHUB_ENV
|
||||
|
||||
- name: Download frontend artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: frontend-dist
|
||||
path: frontend/dist
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p dist
|
||||
go build -ldflags "$LD_FLAGS -X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o dist/nginx-ui -v main.go
|
||||
|
||||
- name: Archive backend artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ env.ARTIFACT }}
|
||||
path: dist/nginx-ui
|
||||
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md ./dist
|
||||
find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: ${{ env.DIST }}.tar.gz
|
||||
|
||||
docker-build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
env:
|
||||
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/arm/v5
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get the version
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
path: ./dist
|
||||
|
||||
- name: Prepare Artifacts
|
||||
run: chmod +x ./dist/nginx-ui-*/nginx-ui
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Prepare Dockerfile
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp ./Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
|
||||
- name: Build and push
|
||||
if: github.event_name == 'release'
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui:latest
|
||||
uozi/nginx-ui:${{ steps.get_version.outputs.VERSION }}
|
||||
|
||||
- name: Prepare Demo Dockerfile
|
||||
run: |
|
||||
cp ./demo.Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
|
||||
- name: Build and push demo
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/demo.Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui-demo:latest
|
||||
build_app:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: current
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
pnpm install
|
||||
working-directory: app
|
||||
|
||||
- name: Check frontend code style
|
||||
run: |
|
||||
pnpm run lint
|
||||
working-directory: app
|
||||
|
||||
- name: Check frontend types
|
||||
run: |
|
||||
pnpm run typecheck
|
||||
working-directory: app
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
npx browserslist@latest --update-db
|
||||
pnpm build
|
||||
working-directory: app
|
||||
|
||||
- name: Archive app artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: app-dist
|
||||
path: app/dist
|
||||
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md app/dist
|
||||
find app/dist -printf '%P\n' | tar -C app/dist --no-recursion -zcvf app-dist.tar.gz -T -
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: app-dist.tar.gz
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build_app
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [ linux, darwin ]
|
||||
goarch: [ amd64, 386, arm64 ]
|
||||
exclude:
|
||||
# Exclude i386 on darwin.
|
||||
- goarch: 386
|
||||
goos: darwin
|
||||
include:
|
||||
# BEGIN Linux ARM 5 6 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 6
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 5
|
||||
# END Linux ARM 5 6 7
|
||||
env:
|
||||
CGO_ENABLED: 1
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
GOARM: ${{ matrix.goarm }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ^1.23.0
|
||||
|
||||
- name: Setup compiler environment
|
||||
id: info
|
||||
run: |
|
||||
export _NAME=nginx-ui-$(jq ".$GOOS[\"$GOARCH$GOARM\"].name" -r < .github/build/build_info.json)
|
||||
export _ARCH=$(jq ".$GOOS[\"$GOARCH$GOARM\"].arch" -r < .github/build/build_info.json)
|
||||
export _ABI=$(jq ".$GOOS[\"$GOARCH$GOARM\"].abi // \"\"" -r < .github/build/build_info.json)
|
||||
export _ARTIFACT=nginx-ui-$GOOS-$GOARCH$(if [[ "$GOARM" ]]; then echo "v$GOARM"; fi)
|
||||
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME, ARTIFACT_NAME: $_ARTIFACT"
|
||||
echo "ARCH_NAME=$_ARCH" >> $GITHUB_ENV
|
||||
echo "ABI=$_ABI" >> $GITHUB_ENV
|
||||
echo "DIST=$_NAME" >> $GITHUB_ENV
|
||||
echo "ARTIFACT=$_ARTIFACT" >> $GITHUB_ENV
|
||||
|
||||
- name: Install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
uses: 0xJacky/musl-cross-compilers@v0.6.6
|
||||
id: musl
|
||||
with:
|
||||
target: ${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}
|
||||
|
||||
- name: Post install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
run: |
|
||||
echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-gcc" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-g++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=-w --extldflags '-static'" >> $GITHUB_ENV
|
||||
|
||||
- name: Install darwin cross compiler
|
||||
if: env.GOOS == 'darwin'
|
||||
run: |
|
||||
curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
|
||||
tar xvaf crossosx.tar.zst
|
||||
echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
|
||||
echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-clang" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-clang++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=-w" >> $GITHUB_ENV
|
||||
|
||||
- name: Download app artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: app-dist
|
||||
path: app/dist
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p dist
|
||||
go build -tags=jsoniter -ldflags "$LD_FLAGS -X 'github.com/0xJacky/Nginx-UI/settings.buildTime=$(date +%s)'" -o dist/nginx-ui -v main.go
|
||||
|
||||
- name: Archive backend artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.ARTIFACT }}
|
||||
path: dist/nginx-ui
|
||||
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md ./dist
|
||||
find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
|
||||
openssl dgst -sha512 ${{ env.DIST }}.tar.gz | sed 's/([^)]*)//g' | awk '{print $NF}' >> ${{ env.DIST }}.tar.gz.digest
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: |
|
||||
${{ env.DIST }}.tar.gz
|
||||
${{ env.DIST }}.tar.gz.digest
|
||||
|
||||
docker-build:
|
||||
if: github.event_name != 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
env:
|
||||
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/arm/v5
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Get the version
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: ./dist
|
||||
|
||||
- name: Prepare Artifacts
|
||||
run: chmod +x ./dist/nginx-ui-*/nginx-ui
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Prepare Dockerfile
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp ./Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
|
||||
- name: Build and push
|
||||
if: github.event_name == 'release'
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui:latest
|
||||
uozi/nginx-ui:${{ steps.get_version.outputs.VERSION }}
|
||||
|
||||
- name: Prepare Demo Dockerfile
|
||||
run: |
|
||||
cp ./demo.Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
|
||||
- name: Build and push demo
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/demo.Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui-demo:latest
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
name: Build Documents
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
paths:
|
||||
- "docs/**/*.js"
|
||||
- "docs/**/*.ts"
|
||||
- "docs/**/*.vue"
|
||||
- "docs/package.json"
|
||||
- "docs/.env*"
|
||||
- "docs/**/*.md"
|
||||
- ".github/workflows/doc*.yml"
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "docs/**/*.js"
|
||||
- "docs/**/*.ts"
|
||||
- "docs/**/*.vue"
|
||||
- "docs/package.json"
|
||||
- "docs/.env*"
|
||||
- "docs/**/*.md"
|
||||
- ".github/workflows/doc*.yml"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 21.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
pnpm install
|
||||
working-directory: docs
|
||||
|
||||
- name: Build
|
||||
run: COMMIT_REF=$(git rev-parse HEAD) pnpm docs:build
|
||||
working-directory: docs
|
||||
|
||||
- name: Archive artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
path: docs/.vitepress/dist
|
||||
|
||||
- name: Deploy to server
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: easingthemes/ssh-deploy@main
|
||||
env:
|
||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
TARGET: ${{ secrets.REMOTE_TARGET }}
|
||||
SOURCE: "docs/.vitepress/dist/"
|
||||
ARGS: "-rlgoDzvc -i --delete"
|
||||
@ -0,0 +1,32 @@
|
||||
name: Weblate Pull Branch
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request_target:
|
||||
branches:
|
||||
- 'dev'
|
||||
types: [ closed ]
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
weblate:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.merged == true || github.event.action == 'published' || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install wlc
|
||||
run: pip install wlc
|
||||
|
||||
- name: Update Repository
|
||||
env:
|
||||
WEBLATE_TOKEN: ${{ secrets.WEBLATE_TOKEN }}
|
||||
run: wlc --key $WEBLATE_TOKEN pull
|
||||
@ -0,0 +1,86 @@
|
||||
name: Synchronize Weblate Branch
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '15 18 * * *'
|
||||
|
||||
env:
|
||||
DEVELOP_BRANCH: dev
|
||||
WEBLATE_BRANCH: weblate
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check Branches
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
behind: ${{ steps.check.outputs.behind }}
|
||||
ahead: ${{ steps.check.outputs.ahead }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ env.DEVELOP_BRANCH }}
|
||||
clean: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check branches
|
||||
id: check
|
||||
run: |
|
||||
git fetch --all
|
||||
git branch $WEBLATE_BRANCH origin/$WEBLATE_BRANCH
|
||||
echo "behind=$(git rev-list --count $WEBLATE_BRANCH..$DEVELOP_BRANCH)" >> $GITHUB_OUTPUT
|
||||
echo "ahead=$(git rev-list --count $DEVELOP_BRANCH..$WEBLATE_BRANCH)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Echo outputs
|
||||
run: |
|
||||
echo "behind: ${{ steps.check.outputs.behind }}"
|
||||
echo "ahead: ${{ steps.check.outputs.ahead }}"
|
||||
|
||||
force-update:
|
||||
name: Force Update Weblate Status
|
||||
runs-on: ubuntu-latest
|
||||
needs: check
|
||||
if: ${{ needs.check.outputs.behind > 0 }}
|
||||
env:
|
||||
WEBLATE_TOKEN: ${{ secrets.WEBLATE_TOKEN }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install wlc
|
||||
run: pip install wlc
|
||||
|
||||
- name: Update weblate repository
|
||||
run: wlc --key $WEBLATE_TOKEN pull
|
||||
|
||||
- name: Push weblate branch
|
||||
run: wlc --key $WEBLATE_TOKEN push
|
||||
|
||||
sync-branch:
|
||||
name: Sync Weblate Branch
|
||||
runs-on: ubuntu-latest
|
||||
needs: [check, force-update]
|
||||
if: ${{ needs.check.outputs.ahead > 0 && always() }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ env.DEVELOP_BRANCH }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up git
|
||||
run: |
|
||||
git config --global user.name 'Weblate'
|
||||
git config --global user.email 'weblate@nginxui.com'
|
||||
|
||||
- name: Push changes of weblate branch to develop branch
|
||||
run: |
|
||||
git fetch origin
|
||||
git merge --ff-only -- origin/${{ env.WEBLATE_BRANCH }}
|
||||
git push origin ${{ env.DEVELOP_BRANCH }}
|
||||
@ -1,10 +1,13 @@
|
||||
.DS_Store
|
||||
.idea
|
||||
database.db
|
||||
tmp
|
||||
node_modules
|
||||
/app.ini
|
||||
.pnpm-store
|
||||
app.ini
|
||||
dist
|
||||
*.exe
|
||||
*.po~
|
||||
nginx-ui
|
||||
resources/development/nginx
|
||||
app/.env
|
||||
app/.status_hash
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
||||
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/nginx-ui.iml" filepath="$PROJECT_DIR$/.idea/nginx-ui.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,3 @@
|
||||
[weblate]
|
||||
url = https://weblate.nginxui.com/api/
|
||||
translation = nginx-ui
|
||||
@ -0,0 +1,147 @@
|
||||
package analytic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/host"
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"github.com/shirou/gopsutil/v3/net"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func Analytic(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
var stat Stat
|
||||
|
||||
for {
|
||||
stat.Memory, err = analytic.GetMemoryStat()
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
cpuTimesBefore, _ := cpu.Times(false)
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
cpuTimesAfter, _ := cpu.Times(false)
|
||||
threadNum := runtime.GOMAXPROCS(0)
|
||||
cpuUserUsage := (cpuTimesAfter[0].User - cpuTimesBefore[0].User) / (float64(1000*threadNum) / 1000)
|
||||
cpuSystemUsage := (cpuTimesAfter[0].System - cpuTimesBefore[0].System) / (float64(1000*threadNum) / 1000)
|
||||
|
||||
stat.CPU = CPUStat{
|
||||
User: cast.ToFloat64(fmt.Sprintf("%.2f", cpuUserUsage*100)),
|
||||
System: cast.ToFloat64(fmt.Sprintf("%.2f", cpuSystemUsage*100)),
|
||||
Idle: cast.ToFloat64(fmt.Sprintf("%.2f", (1-cpuUserUsage-cpuSystemUsage)*100)),
|
||||
Total: cast.ToFloat64(fmt.Sprintf("%.2f", (cpuUserUsage+cpuSystemUsage)*100)),
|
||||
}
|
||||
|
||||
stat.Uptime, _ = host.Uptime()
|
||||
|
||||
stat.LoadAvg, _ = load.Avg()
|
||||
|
||||
stat.Disk, err = analytic.GetDiskStat()
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
network, _ := net.IOCounters(false)
|
||||
|
||||
if len(network) > 0 {
|
||||
stat.Network = network[0]
|
||||
}
|
||||
|
||||
// write
|
||||
err = ws.WriteJSON(stat)
|
||||
if helper.IsUnexpectedWebsocketError(err) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
time.Sleep(800 * time.Microsecond)
|
||||
}
|
||||
}
|
||||
|
||||
func GetAnalyticInit(c *gin.Context) {
|
||||
cpuInfo, err := cpu.Info()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
network, err := net.IOCounters(false)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
memory, err := analytic.GetMemoryStat()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
diskStat, err := analytic.GetDiskStat()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
var _net net.IOCountersStat
|
||||
if len(network) > 0 {
|
||||
_net = network[0]
|
||||
}
|
||||
hostInfo, _ := host.Info()
|
||||
|
||||
switch hostInfo.Platform {
|
||||
case "ubuntu":
|
||||
hostInfo.Platform = "Ubuntu"
|
||||
case "centos":
|
||||
hostInfo.Platform = "CentOS"
|
||||
}
|
||||
|
||||
loadAvg, err := load.Avg()
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, InitResp{
|
||||
Host: hostInfo,
|
||||
CPU: CPURecords{
|
||||
Info: cpuInfo,
|
||||
User: analytic.CpuUserRecord,
|
||||
Total: analytic.CpuTotalRecord,
|
||||
},
|
||||
Network: NetworkRecords{
|
||||
Init: _net,
|
||||
BytesRecv: analytic.NetRecvRecord,
|
||||
BytesSent: analytic.NetSentRecord,
|
||||
},
|
||||
DiskIO: DiskIORecords{
|
||||
Writes: analytic.DiskWriteRecord,
|
||||
Reads: analytic.DiskReadRecord,
|
||||
},
|
||||
Memory: memory,
|
||||
Disk: diskStat,
|
||||
LoadAvg: loadAvg,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package analytic
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetNodeStat(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
// write
|
||||
err = ws.WriteJSON(analytic.GetNodeStat())
|
||||
if helper.IsUnexpectedWebsocketError(err) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func GetNodesAnalytic(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
// write
|
||||
err = ws.WriteJSON(analytic.NodeMap)
|
||||
if helper.IsUnexpectedWebsocketError(err) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package analytic
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitWebSocketRouter(r *gin.RouterGroup) {
|
||||
r.GET("analytic", Analytic)
|
||||
r.GET("analytic/intro", GetNodeStat)
|
||||
r.GET("analytic/nodes", GetNodesAnalytic)
|
||||
}
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("analytic/init", GetAnalyticInit)
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package analytic
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/host"
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"github.com/shirou/gopsutil/v3/net"
|
||||
)
|
||||
|
||||
type CPUStat struct {
|
||||
User float64 `json:"user"`
|
||||
System float64 `json:"system"`
|
||||
Idle float64 `json:"idle"`
|
||||
Total float64 `json:"total"`
|
||||
}
|
||||
|
||||
type Stat struct {
|
||||
Uptime uint64 `json:"uptime"`
|
||||
LoadAvg *load.AvgStat `json:"loadavg"`
|
||||
CPU CPUStat `json:"cpu"`
|
||||
Memory analytic.MemStat `json:"memory"`
|
||||
Disk analytic.DiskStat `json:"disk"`
|
||||
Network net.IOCountersStat `json:"network"`
|
||||
}
|
||||
|
||||
type CPURecords struct {
|
||||
Info []cpu.InfoStat `json:"info"`
|
||||
User []analytic.Usage[float64] `json:"user"`
|
||||
Total []analytic.Usage[float64] `json:"total"`
|
||||
}
|
||||
|
||||
type NetworkRecords struct {
|
||||
Init net.IOCountersStat `json:"init"`
|
||||
BytesRecv []analytic.Usage[uint64] `json:"bytesRecv"`
|
||||
BytesSent []analytic.Usage[uint64] `json:"bytesSent"`
|
||||
}
|
||||
|
||||
type DiskIORecords struct {
|
||||
Writes []analytic.Usage[uint64] `json:"writes"`
|
||||
Reads []analytic.Usage[uint64] `json:"reads"`
|
||||
}
|
||||
|
||||
type InitResp struct {
|
||||
Host *host.InfoStat `json:"host"`
|
||||
CPU CPURecords `json:"cpu"`
|
||||
Network NetworkRecords `json:"network"`
|
||||
DiskIO DiskIORecords `json:"disk_io"`
|
||||
Memory analytic.MemStat `json:"memory"`
|
||||
Disk analytic.DiskStat `json:"disk"`
|
||||
LoadAvg *load.AvgStat `json:"loadavg"`
|
||||
}
|
||||
@ -0,0 +1,127 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CurrentUser(c *gin.Context) *model.User {
|
||||
return c.MustGet("user").(*model.User)
|
||||
}
|
||||
|
||||
func ErrHandler(c *gin.Context, err error) {
|
||||
logger.GetLogger().Errorln(err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
type ValidError struct {
|
||||
Key string
|
||||
Message string
|
||||
}
|
||||
|
||||
func BindAndValid(c *gin.Context, target interface{}) bool {
|
||||
err := c.ShouldBindJSON(target)
|
||||
if err != nil {
|
||||
logger.Error("bind err", err)
|
||||
|
||||
var verrs validator.ValidationErrors
|
||||
ok := errors.As(err, &verrs)
|
||||
|
||||
if !ok {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "Requested with wrong parameters",
|
||||
"code": http.StatusNotAcceptable,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
t := reflect.TypeOf(target).Elem()
|
||||
errorsMap := make(map[string]interface{})
|
||||
for _, value := range verrs {
|
||||
var path []string
|
||||
|
||||
namespace := strings.Split(value.StructNamespace(), ".")
|
||||
// logger.Debug(t.Name(), namespace)
|
||||
if t.Name() != "" && len(namespace) > 1 {
|
||||
namespace = namespace[1:]
|
||||
}
|
||||
|
||||
getJsonPath(t, namespace, &path)
|
||||
insertError(errorsMap, path, value.Tag())
|
||||
}
|
||||
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"errors": errorsMap,
|
||||
"message": "Requested with wrong parameters",
|
||||
"code": http.StatusNotAcceptable,
|
||||
})
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// findField recursively finds the field in a nested struct
|
||||
func getJsonPath(t reflect.Type, fields []string, path *[]string) {
|
||||
field := fields[0]
|
||||
// used in case of array
|
||||
var index string
|
||||
if field[len(field)-1] == ']' {
|
||||
re := regexp.MustCompile(`(\w+)\[(\d+)\]`)
|
||||
matches := re.FindStringSubmatch(field)
|
||||
|
||||
if len(matches) > 2 {
|
||||
field = matches[1]
|
||||
index = matches[2]
|
||||
}
|
||||
}
|
||||
|
||||
f, ok := t.FieldByName(field)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
*path = append(*path, f.Tag.Get("json"))
|
||||
|
||||
if index != "" {
|
||||
*path = append(*path, index)
|
||||
}
|
||||
|
||||
if len(fields) > 1 {
|
||||
subFields := fields[1:]
|
||||
getJsonPath(f.Type, subFields, path)
|
||||
}
|
||||
}
|
||||
|
||||
// insertError inserts an error into the errors map
|
||||
func insertError(errorsMap map[string]interface{}, path []string, errorTag string) {
|
||||
if len(path) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
jsonTag := path[0]
|
||||
if len(path) == 1 {
|
||||
// Last element in the path, set the error
|
||||
errorsMap[jsonTag] = errorTag
|
||||
return
|
||||
}
|
||||
|
||||
// Create a new map if necessary
|
||||
if _, ok := errorsMap[jsonTag]; !ok {
|
||||
errorsMap[jsonTag] = make(map[string]interface{})
|
||||
}
|
||||
|
||||
// Recursively insert into the nested map
|
||||
subMap, _ := errorsMap[jsonTag].(map[string]interface{})
|
||||
insertError(subMap, path[1:], errorTag)
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
package certificate
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetAcmeUser(c *gin.Context) {
|
||||
u := query.AcmeUser
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
user, err := u.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
func CreateAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).SetValidRules(gin.H{
|
||||
"name": "required",
|
||||
"email": "required,email",
|
||||
"ca_dir": "omitempty",
|
||||
}).BeforeExecuteHook(func(ctx *cosy.Ctx[model.AcmeUser]) {
|
||||
if ctx.Model.CADir == "" {
|
||||
ctx.Model.CADir = settings.ServerSettings.GetCADir()
|
||||
}
|
||||
err := ctx.Model.Register()
|
||||
if err != nil {
|
||||
ctx.AbortWithError(err)
|
||||
return
|
||||
}
|
||||
}).Create()
|
||||
}
|
||||
|
||||
func ModifyAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).SetValidRules(gin.H{
|
||||
"name": "omitempty",
|
||||
"email": "omitempty,email",
|
||||
"ca_dir": "omitempty",
|
||||
}).BeforeExecuteHook(func(ctx *cosy.Ctx[model.AcmeUser]) {
|
||||
if ctx.Model.CADir == "" {
|
||||
ctx.Model.CADir = settings.ServerSettings.GetCADir()
|
||||
}
|
||||
|
||||
if ctx.OriginModel.Email != ctx.Model.Email ||
|
||||
ctx.OriginModel.CADir != ctx.Model.CADir {
|
||||
err := ctx.Model.Register()
|
||||
if err != nil {
|
||||
ctx.AbortWithError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}).Modify()
|
||||
}
|
||||
|
||||
func GetAcmeUserList(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).
|
||||
SetFussy("name", "email").
|
||||
PagingList()
|
||||
}
|
||||
|
||||
func DestroyAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).Destroy()
|
||||
}
|
||||
|
||||
func RecoverAcmeUser(c *gin.Context) {
|
||||
cosy.Core[model.AcmeUser](c).Recover()
|
||||
}
|
||||
|
||||
func RegisterAcmeUser(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
u := query.AcmeUser
|
||||
user, err := u.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
err = user.Register()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
_, err = u.Where(u.ID.Eq(id)).Updates(user)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
@ -0,0 +1,243 @@
|
||||
package certificate
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/internal/notification"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type APICertificate struct {
|
||||
*model.Cert
|
||||
SSLCertificate string `json:"ssl_certificate,omitempty"`
|
||||
SSLCertificateKey string `json:"ssl_certificate_key,omitempty"`
|
||||
CertificateInfo *cert.Info `json:"certificate_info,omitempty"`
|
||||
}
|
||||
|
||||
func Transformer(certModel *model.Cert) (certificate *APICertificate) {
|
||||
var sslCertificationBytes, sslCertificationKeyBytes []byte
|
||||
var certificateInfo *cert.Info
|
||||
if certModel.SSLCertificatePath != "" &&
|
||||
helper.IsUnderDirectory(certModel.SSLCertificatePath, nginx.GetConfPath()) {
|
||||
if _, err := os.Stat(certModel.SSLCertificatePath); err == nil {
|
||||
sslCertificationBytes, _ = os.ReadFile(certModel.SSLCertificatePath)
|
||||
if !cert.IsCertificate(string(sslCertificationBytes)) {
|
||||
sslCertificationBytes = []byte{}
|
||||
}
|
||||
}
|
||||
|
||||
certificateInfo, _ = cert.GetCertInfo(certModel.SSLCertificatePath)
|
||||
}
|
||||
|
||||
if certModel.SSLCertificateKeyPath != "" &&
|
||||
helper.IsUnderDirectory(certModel.SSLCertificateKeyPath, nginx.GetConfPath()) {
|
||||
if _, err := os.Stat(certModel.SSLCertificateKeyPath); err == nil {
|
||||
sslCertificationKeyBytes, _ = os.ReadFile(certModel.SSLCertificateKeyPath)
|
||||
if !cert.IsPrivateKey(string(sslCertificationKeyBytes)) {
|
||||
sslCertificationKeyBytes = []byte{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &APICertificate{
|
||||
Cert: certModel,
|
||||
SSLCertificate: string(sslCertificationBytes),
|
||||
SSLCertificateKey: string(sslCertificationKeyBytes),
|
||||
CertificateInfo: certificateInfo,
|
||||
}
|
||||
}
|
||||
|
||||
func GetCertList(c *gin.Context) {
|
||||
cosy.Core[model.Cert](c).SetFussy("name", "domain").SetTransformer(func(m *model.Cert) any {
|
||||
|
||||
info, _ := cert.GetCertInfo(m.SSLCertificatePath)
|
||||
|
||||
return APICertificate{
|
||||
Cert: m,
|
||||
CertificateInfo: info,
|
||||
}
|
||||
}).PagingList()
|
||||
}
|
||||
|
||||
func GetCert(c *gin.Context) {
|
||||
q := query.Cert
|
||||
|
||||
certModel, err := q.FirstByID(cast.ToInt(c.Param("id")))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, Transformer(certModel))
|
||||
}
|
||||
|
||||
type certJson struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
SSLCertificatePath string `json:"ssl_certificate_path" binding:"required,certificate_path"`
|
||||
SSLCertificateKeyPath string `json:"ssl_certificate_key_path" binding:"required,privatekey_path"`
|
||||
SSLCertificate string `json:"ssl_certificate" binding:"omitempty,certificate"`
|
||||
SSLCertificateKey string `json:"ssl_certificate_key" binding:"omitempty,privatekey"`
|
||||
KeyType certcrypto.KeyType `json:"key_type" binding:"omitempty,auto_cert_key_type"`
|
||||
ChallengeMethod string `json:"challenge_method"`
|
||||
DnsCredentialID int `json:"dns_credential_id"`
|
||||
ACMEUserID int `json:"acme_user_id"`
|
||||
SyncNodeIds []int `json:"sync_node_ids"`
|
||||
}
|
||||
|
||||
func AddCert(c *gin.Context) {
|
||||
var json certJson
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
certModel := &model.Cert{
|
||||
Name: json.Name,
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
KeyType: json.KeyType,
|
||||
ChallengeMethod: json.ChallengeMethod,
|
||||
DnsCredentialID: json.DnsCredentialID,
|
||||
ACMEUserID: json.ACMEUserID,
|
||||
SyncNodeIds: json.SyncNodeIds,
|
||||
}
|
||||
|
||||
err := certModel.Insert()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
content := &cert.Content{
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
SSLCertificate: json.SSLCertificate,
|
||||
SSLCertificateKey: json.SSLCertificateKey,
|
||||
}
|
||||
|
||||
err = content.WriteFile()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = cert.SyncToRemoteServer(certModel)
|
||||
if err != nil {
|
||||
notification.Error("Sync Certificate Error", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, Transformer(certModel))
|
||||
}
|
||||
|
||||
func ModifyCert(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
|
||||
var json certJson
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
q := query.Cert
|
||||
|
||||
certModel, err := q.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = certModel.Updates(&model.Cert{
|
||||
Name: json.Name,
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
ChallengeMethod: json.ChallengeMethod,
|
||||
KeyType: json.KeyType,
|
||||
DnsCredentialID: json.DnsCredentialID,
|
||||
ACMEUserID: json.ACMEUserID,
|
||||
SyncNodeIds: json.SyncNodeIds,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
content := &cert.Content{
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
SSLCertificate: json.SSLCertificate,
|
||||
SSLCertificateKey: json.SSLCertificateKey,
|
||||
}
|
||||
|
||||
err = content.WriteFile()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = cert.SyncToRemoteServer(certModel)
|
||||
if err != nil {
|
||||
notification.Error("Sync Certificate Error", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
GetCert(c)
|
||||
}
|
||||
|
||||
func RemoveCert(c *gin.Context) {
|
||||
cosy.Core[model.Cert](c).Destroy()
|
||||
}
|
||||
|
||||
func SyncCertificate(c *gin.Context) {
|
||||
var json cert.SyncCertificatePayload
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
certModel := &model.Cert{
|
||||
Name: json.Name,
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
KeyType: json.KeyType,
|
||||
AutoCert: model.AutoCertSync,
|
||||
}
|
||||
|
||||
db := model.UseDB()
|
||||
|
||||
err := db.Where(certModel).FirstOrCreate(certModel).Error
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
content := &cert.Content{
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
SSLCertificate: json.SSLCertificate,
|
||||
SSLCertificateKey: json.SSLCertificateKey,
|
||||
}
|
||||
|
||||
err = content.WriteFile()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
nginx.Reload()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,105 @@
|
||||
package certificate
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert/dns"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetDnsCredential(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
|
||||
d := query.DnsCredential
|
||||
|
||||
dnsCredential, err := d.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
type apiDnsCredential struct {
|
||||
model.Model
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
dns.Config
|
||||
}
|
||||
c.JSON(http.StatusOK, apiDnsCredential{
|
||||
Model: dnsCredential.Model,
|
||||
Name: dnsCredential.Name,
|
||||
Provider: dnsCredential.Provider,
|
||||
Config: *dnsCredential.Config,
|
||||
})
|
||||
}
|
||||
|
||||
func GetDnsCredentialList(c *gin.Context) {
|
||||
cosy.Core[model.DnsCredential](c).SetFussy("provider").PagingList()
|
||||
}
|
||||
|
||||
type DnsCredentialManageJson struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Provider string `json:"provider"`
|
||||
dns.Config
|
||||
}
|
||||
|
||||
func AddDnsCredential(c *gin.Context) {
|
||||
var json DnsCredentialManageJson
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
json.Config.Name = json.Provider
|
||||
dnsCredential := model.DnsCredential{
|
||||
Name: json.Name,
|
||||
Config: &json.Config,
|
||||
Provider: json.Provider,
|
||||
}
|
||||
|
||||
d := query.DnsCredential
|
||||
|
||||
err := d.Create(&dnsCredential)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, dnsCredential)
|
||||
}
|
||||
|
||||
func EditDnsCredential(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
|
||||
var json DnsCredentialManageJson
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
d := query.DnsCredential
|
||||
|
||||
dnsCredential, err := d.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
json.Config.Name = json.Provider
|
||||
_, err = d.Where(d.ID.Eq(dnsCredential.ID)).Updates(&model.DnsCredential{
|
||||
Name: json.Name,
|
||||
Config: &json.Config,
|
||||
Provider: json.Provider,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
GetDnsCredential(c)
|
||||
}
|
||||
|
||||
func DeleteDnsCredential(c *gin.Context) {
|
||||
cosy.Core[model.DnsCredential](c).Destroy()
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package certificate
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert/dns"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetDNSProvidersList(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, dns.GetProvidersList())
|
||||
}
|
||||
|
||||
func GetDNSProvider(c *gin.Context) {
|
||||
code := c.Param("code")
|
||||
|
||||
provider, ok := dns.GetProvider(code)
|
||||
|
||||
if !ok {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "provider not found",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, provider)
|
||||
}
|
||||
|
||||
@ -0,0 +1,155 @@
|
||||
package certificate
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
Success = "success"
|
||||
Info = "info"
|
||||
Error = "error"
|
||||
)
|
||||
|
||||
type IssueCertResponse struct {
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
SSLCertificate string `json:"ssl_certificate,omitempty"`
|
||||
SSLCertificateKey string `json:"ssl_certificate_key,omitempty"`
|
||||
KeyType certcrypto.KeyType `json:"key_type"`
|
||||
}
|
||||
|
||||
func handleIssueCertLogChan(conn *websocket.Conn, log *cert.Logger, logChan chan string) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
for logString := range logChan {
|
||||
log.Info(logString)
|
||||
|
||||
err := conn.WriteJSON(IssueCertResponse{
|
||||
Status: Info,
|
||||
Message: logString,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func IssueCert(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer func(ws *websocket.Conn) {
|
||||
_ = ws.Close()
|
||||
}(ws)
|
||||
|
||||
// read
|
||||
payload := &cert.ConfigPayload{}
|
||||
|
||||
err = ws.ReadJSON(payload)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
certModel, err := model.FirstOrCreateCert(c.Param("name"), payload.GetKeyType())
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
certInfo, _ := cert.GetCertInfo(certModel.SSLCertificatePath)
|
||||
if certInfo != nil {
|
||||
payload.Resource = certModel.Resource
|
||||
payload.NotBefore = certInfo.NotBefore
|
||||
}
|
||||
|
||||
logChan := make(chan string, 1)
|
||||
errChan := make(chan error, 1)
|
||||
|
||||
log := &cert.Logger{}
|
||||
log.SetCertModel(&certModel)
|
||||
|
||||
payload.CertID = certModel.ID
|
||||
|
||||
go cert.IssueCert(payload, logChan, errChan)
|
||||
|
||||
go handleIssueCertLogChan(ws, log, logChan)
|
||||
|
||||
// block, until errChan closes
|
||||
for err = range errChan {
|
||||
|
||||
log.Error(err)
|
||||
|
||||
// Save logs to db
|
||||
log.Exit()
|
||||
|
||||
err = ws.WriteJSON(IssueCertResponse{
|
||||
Status: Error,
|
||||
Message: err.Error(),
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
err = certModel.Updates(&model.Cert{
|
||||
Domains: payload.ServerName,
|
||||
SSLCertificatePath: payload.GetCertificatePath(),
|
||||
SSLCertificateKeyPath: payload.GetCertificateKeyPath(),
|
||||
AutoCert: model.AutoCertEnabled,
|
||||
KeyType: payload.KeyType,
|
||||
ChallengeMethod: payload.ChallengeMethod,
|
||||
DnsCredentialID: payload.DNSCredentialID,
|
||||
Resource: payload.Resource,
|
||||
MustStaple: payload.MustStaple,
|
||||
LegoDisableCNAMESupport: payload.LegoDisableCNAMESupport,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
_ = ws.WriteJSON(IssueCertResponse{
|
||||
Status: Error,
|
||||
Message: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Save logs to db
|
||||
log.Exit()
|
||||
|
||||
err = ws.WriteJSON(IssueCertResponse{
|
||||
Status: Success,
|
||||
Message: "Issued certificate successfully",
|
||||
SSLCertificate: payload.GetCertificatePath(),
|
||||
SSLCertificateKey: payload.GetCertificateKeyPath(),
|
||||
KeyType: payload.GetKeyType(),
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package certificate
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitDNSCredentialRouter(r *gin.RouterGroup) {
|
||||
r.GET("dns_credentials", GetDnsCredentialList)
|
||||
r.GET("dns_credential/:id", GetDnsCredential)
|
||||
r.POST("dns_credential", AddDnsCredential)
|
||||
r.POST("dns_credential/:id", EditDnsCredential)
|
||||
r.DELETE("dns_credential/:id", DeleteDnsCredential)
|
||||
}
|
||||
|
||||
func InitCertificateRouter(r *gin.RouterGroup) {
|
||||
r.GET("certs", GetCertList)
|
||||
r.GET("cert/:id", GetCert)
|
||||
r.POST("cert", AddCert)
|
||||
r.POST("cert/:id", ModifyCert)
|
||||
r.DELETE("cert/:id", RemoveCert)
|
||||
r.PUT("cert_sync", SyncCertificate)
|
||||
r.GET("certificate/dns_providers", GetDNSProvidersList)
|
||||
r.GET("certificate/dns_provider/:code", GetDNSProvider)
|
||||
}
|
||||
|
||||
func InitCertificateWebSocketRouter(r *gin.RouterGroup) {
|
||||
r.GET("domain/:name/cert", IssueCert)
|
||||
}
|
||||
|
||||
func InitAcmeUserRouter(r *gin.RouterGroup) {
|
||||
r.GET("acme_users", GetAcmeUserList)
|
||||
r.GET("acme_user/:id", GetAcmeUser)
|
||||
r.POST("acme_user", CreateAcmeUser)
|
||||
r.POST("acme_user/:id", ModifyAcmeUser)
|
||||
r.POST("acme_user/:id/register", RegisterAcmeUser)
|
||||
r.DELETE("acme_user/:id", DestroyAcmeUser)
|
||||
r.PATCH("acme_user/:id", RecoverAcmeUser)
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cluster"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetEnvironment(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
|
||||
envQuery := query.Environment
|
||||
|
||||
env, err := envQuery.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, analytic.GetNode(env))
|
||||
}
|
||||
|
||||
func GetEnvironmentList(c *gin.Context) {
|
||||
core := cosy.Core[model.Environment](c).
|
||||
SetFussy("name")
|
||||
|
||||
// fix for sqlite
|
||||
if c.Query("enabled") != "" {
|
||||
core.GormScope(func(tx *gorm.DB) *gorm.DB {
|
||||
return tx.Where("enabled = ?", cast.ToInt(cast.ToBool(c.Query("enabled"))))
|
||||
})
|
||||
}
|
||||
|
||||
core.SetTransformer(func(m *model.Environment) any {
|
||||
return analytic.GetNode(m)
|
||||
}).PagingList()
|
||||
}
|
||||
|
||||
func AddEnvironment(c *gin.Context) {
|
||||
cosy.Core[model.Environment](c).SetValidRules(gin.H{
|
||||
"name": "required",
|
||||
"url": "required,url",
|
||||
"token": "required",
|
||||
"enabled": "omitempty,boolean",
|
||||
}).ExecutedHook(func(c *cosy.Ctx[model.Environment]) {
|
||||
go analytic.RestartRetrieveNodesStatus()
|
||||
}).Create()
|
||||
}
|
||||
|
||||
func EditEnvironment(c *gin.Context) {
|
||||
cosy.Core[model.Environment](c).SetValidRules(gin.H{
|
||||
"name": "required",
|
||||
"url": "required,url",
|
||||
"token": "required",
|
||||
"enabled": "omitempty,boolean",
|
||||
}).ExecutedHook(func(c *cosy.Ctx[model.Environment]) {
|
||||
go analytic.RestartRetrieveNodesStatus()
|
||||
}).Modify()
|
||||
}
|
||||
|
||||
func DeleteEnvironment(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
envQuery := query.Environment
|
||||
|
||||
env, err := envQuery.FirstByID(id)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
err = envQuery.DeleteByID(env.ID)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
go analytic.RestartRetrieveNodesStatus()
|
||||
|
||||
c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func LoadEnvironmentFromSettings(c *gin.Context) {
|
||||
err := settings.ReloadCluster()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
cluster.RegisterPredefinedNodes()
|
||||
|
||||
go analytic.RestartRetrieveNodesStatus()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
analytic2 "github.com/0xJacky/Nginx-UI/internal/analytic"
|
||||
"github.com/0xJacky/Nginx-UI/internal/upgrader"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetCurrentNode(c *gin.Context) {
|
||||
if _, ok := c.Get("NodeSecret"); !ok {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "node secret not exist",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
runtimeInfo, err := upgrader.GetRuntimeInfo()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
cpuInfo, _ := cpu.Info()
|
||||
memory, _ := analytic2.GetMemoryStat()
|
||||
ver, _ := upgrader.GetCurrentVersion()
|
||||
diskUsage, _ := disk.Usage(".")
|
||||
|
||||
nodeInfo := analytic2.NodeInfo{
|
||||
NodeRuntimeInfo: runtimeInfo,
|
||||
CPUNum: len(cpuInfo),
|
||||
MemoryTotal: memory.Total,
|
||||
DiskTotal: humanize.Bytes(diskUsage.Total),
|
||||
Version: ver.Version,
|
||||
}
|
||||
|
||||
stat := analytic2.GetNodeStat()
|
||||
|
||||
c.JSON(http.StatusOK, analytic2.Node{
|
||||
NodeInfo: nodeInfo,
|
||||
NodeStat: stat,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package cluster
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
// Environment
|
||||
r.GET("environments", GetEnvironmentList)
|
||||
r.POST("environments/load_from_settings", LoadEnvironmentFromSettings)
|
||||
envGroup := r.Group("environment")
|
||||
{
|
||||
envGroup.GET("/:id", GetEnvironment)
|
||||
envGroup.POST("", AddEnvironment)
|
||||
envGroup.POST("/:id", EditEnvironment)
|
||||
envGroup.DELETE("/:id", DeleteEnvironment)
|
||||
}
|
||||
// Node
|
||||
r.GET("node", GetCurrentNode)
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
func AddConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
NewFilepath string `json:"new_filepath" binding:"required"`
|
||||
Content string `json:"content"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
SyncNodeIds []int `json:"sync_node_ids"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
name := json.Name
|
||||
content := json.Content
|
||||
path := json.NewFilepath
|
||||
if !helper.IsUnderDirectory(path, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "new filepath is not under the nginx conf path",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if !json.Overwrite && helper.FileExists(path) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// check if the dir exists, if not, use mkdirAll to create the dir
|
||||
dir := filepath.Dir(path)
|
||||
if !helper.FileExists(dir) {
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err := os.WriteFile(path, []byte(content), 0644)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
output := nginx.Reload()
|
||||
if nginx.GetLogLevel(output) >= nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
q := query.Config
|
||||
_, err = q.Where(q.Filepath.Eq(path)).Delete()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = q.Create(&model.Config{
|
||||
Name: name,
|
||||
Filepath: path,
|
||||
SyncNodeIds: json.SyncNodeIds,
|
||||
SyncOverwrite: json.Overwrite,
|
||||
})
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, config.Config{
|
||||
Name: name,
|
||||
Content: content,
|
||||
ChatGPTMessages: make([]openai.ChatCompletionMessage, 0),
|
||||
FilePath: path,
|
||||
ModifiedAt: time.Now(),
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetBasePath(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"base_path": nginx.GetConfPath(),
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type APIConfigResp struct {
|
||||
config.Config
|
||||
SyncNodeIds []int `json:"sync_node_ids" gorm:"serializer:json"`
|
||||
SyncOverwrite bool `json:"sync_overwrite"`
|
||||
}
|
||||
|
||||
func GetConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
|
||||
path := nginx.GetConfPath("/", name)
|
||||
if !helper.IsUnderDirectory(path, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "path is not under the nginx conf path",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
stat, err := os.Stat(path)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
q := query.Config
|
||||
g := query.ChatGPTLog
|
||||
chatgpt, err := g.Where(g.Name.Eq(path)).FirstOrCreate()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if chatgpt.Content == nil {
|
||||
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
|
||||
}
|
||||
|
||||
cfg, err := q.Where(q.Filepath.Eq(path)).FirstOrInit()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, APIConfigResp{
|
||||
Config: config.Config{
|
||||
Name: stat.Name(),
|
||||
Content: string(content),
|
||||
ChatGPTMessages: chatgpt.Content,
|
||||
FilePath: path,
|
||||
ModifiedAt: stat.ModTime(),
|
||||
},
|
||||
SyncNodeIds: cfg.SyncNodeIds,
|
||||
SyncOverwrite: cfg.SyncOverwrite,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetConfigs(c *gin.Context) {
|
||||
name := c.Query("name")
|
||||
orderBy := c.Query("order_by")
|
||||
sort := c.DefaultQuery("sort", "desc")
|
||||
dir := c.DefaultQuery("dir", "/")
|
||||
|
||||
configFiles, err := os.ReadDir(nginx.GetConfPath(dir))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
configs := make([]config.Config, 0)
|
||||
|
||||
for i := range configFiles {
|
||||
file := configFiles[i]
|
||||
fileInfo, _ := file.Info()
|
||||
|
||||
if name != "" && !strings.Contains(file.Name(), name) {
|
||||
continue
|
||||
}
|
||||
|
||||
switch mode := fileInfo.Mode(); {
|
||||
case mode.IsRegular(): // regular file, not a hidden file
|
||||
if "." == file.Name()[0:1] {
|
||||
continue
|
||||
}
|
||||
case mode&os.ModeSymlink != 0: // is a symbol
|
||||
var targetPath string
|
||||
targetPath, err = os.Readlink(nginx.GetConfPath(dir, file.Name()))
|
||||
if err != nil {
|
||||
logger.Error("Read Symlink Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var targetInfo os.FileInfo
|
||||
targetInfo, err = os.Stat(targetPath)
|
||||
if err != nil {
|
||||
logger.Error("Stat Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
// hide the file if it's target file is a directory
|
||||
if targetInfo.IsDir() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
configs = append(configs, config.Config{
|
||||
Name: file.Name(),
|
||||
ModifiedAt: fileInfo.ModTime(),
|
||||
Size: fileInfo.Size(),
|
||||
IsDir: fileInfo.IsDir(),
|
||||
})
|
||||
}
|
||||
|
||||
configs = config.Sort(orderBy, sort, configs)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": configs,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Mkdir(c *gin.Context) {
|
||||
var json struct {
|
||||
BasePath string `json:"base_path"`
|
||||
FolderName string `json:"folder_name"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
fullPath := nginx.GetConfPath(json.BasePath, json.FolderName)
|
||||
if !helper.IsUnderDirectory(fullPath, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "You are not allowed to create a folder " +
|
||||
"outside of the nginx configuration directory",
|
||||
})
|
||||
return
|
||||
}
|
||||
err := os.Mkdir(fullPath, 0755)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,143 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type EditConfigJson struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
func EditConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Filepath string `json:"filepath" binding:"required"`
|
||||
NewFilepath string `json:"new_filepath" binding:"required"`
|
||||
Content string `json:"content"`
|
||||
SyncOverwrite bool `json:"sync_overwrite"`
|
||||
SyncNodeIds []int `json:"sync_node_ids"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
path := json.Filepath
|
||||
if !helper.IsUnderDirectory(path, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "filepath is not under the nginx conf path",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if !helper.IsUnderDirectory(json.NewFilepath, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "new filepath is not under the nginx conf path",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if !helper.FileExists(path) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "file not found",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
content := json.Content
|
||||
origContent, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if content != "" && content != string(origContent) {
|
||||
err = os.WriteFile(path, []byte(content), 0644)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
q := query.Config
|
||||
cfg, err := q.Where(q.Filepath.Eq(json.Filepath)).FirstOrCreate()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = q.Where(q.Filepath.Eq(json.Filepath)).
|
||||
Select(q.Name, q.Filepath, q.SyncNodeIds, q.SyncOverwrite).
|
||||
Updates(&model.Config{
|
||||
Name: json.Name,
|
||||
Filepath: json.NewFilepath,
|
||||
SyncNodeIds: json.SyncNodeIds,
|
||||
SyncOverwrite: json.SyncOverwrite,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
g := query.ChatGPTLog
|
||||
// handle rename
|
||||
if path != json.NewFilepath {
|
||||
if helper.FileExists(json.NewFilepath) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
err := os.Rename(json.Filepath, json.NewFilepath)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// update ChatGPT record
|
||||
_, _ = g.Where(g.Name.Eq(json.NewFilepath)).Delete()
|
||||
_, _ = g.Where(g.Name.Eq(path)).Update(g.Name, json.NewFilepath)
|
||||
}
|
||||
|
||||
err = config.SyncToRemoteServer(cfg, json.NewFilepath)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
output := nginx.Reload()
|
||||
if nginx.GetLogLevel(output) >= nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
chatgpt, err := g.Where(g.Name.Eq(json.NewFilepath)).FirstOrCreate()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if chatgpt.Content == nil {
|
||||
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, config.Config{
|
||||
Name: name,
|
||||
Content: content,
|
||||
ChatGPTMessages: chatgpt.Content,
|
||||
FilePath: json.NewFilepath,
|
||||
ModifiedAt: time.Now(),
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Rename(c *gin.Context) {
|
||||
var json struct {
|
||||
BasePath string `json:"base_path"`
|
||||
OrigName string `json:"orig_name"`
|
||||
NewName string `json:"new_name"`
|
||||
SyncNodeIds []int `json:"sync_node_ids" gorm:"serializer:json"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
logger.Debug(json)
|
||||
if json.OrigName == json.NewName {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
return
|
||||
}
|
||||
origFullPath := nginx.GetConfPath(json.BasePath, json.OrigName)
|
||||
newFullPath := nginx.GetConfPath(json.BasePath, json.NewName)
|
||||
if !helper.IsUnderDirectory(origFullPath, nginx.GetConfPath()) ||
|
||||
!helper.IsUnderDirectory(newFullPath, nginx.GetConfPath()) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "you are not allowed to rename a file " +
|
||||
"outside of the nginx config path",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
stat, err := os.Stat(origFullPath)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if helper.FileExists(newFullPath) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "target file already exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
err = os.Rename(origFullPath, newFullPath)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// update ChatGPT records
|
||||
g := query.ChatGPTLog
|
||||
q := query.Config
|
||||
cfg, err := q.Where(q.Filepath.Eq(origFullPath)).FirstOrInit()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
if !stat.IsDir() {
|
||||
_, _ = g.Where(g.Name.Eq(newFullPath)).Delete()
|
||||
_, _ = g.Where(g.Name.Eq(origFullPath)).Update(g.Name, newFullPath)
|
||||
// for file, the sync policy for this file is used
|
||||
json.SyncNodeIds = cfg.SyncNodeIds
|
||||
} else {
|
||||
// is directory, update all records under the directory
|
||||
_, _ = g.Where(g.Name.Like(origFullPath+"%")).Update(g.Name, g.Name.Replace(origFullPath, newFullPath))
|
||||
}
|
||||
|
||||
_, err = q.Where(q.Filepath.Eq(origFullPath)).Update(q.Filepath, newFullPath)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(json.SyncNodeIds) > 0 {
|
||||
err = config.SyncRenameOnRemoteServer(origFullPath, newFullPath, json.SyncNodeIds)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("config_base_path", GetBasePath)
|
||||
|
||||
r.GET("configs", GetConfigs)
|
||||
r.GET("config/*name", GetConfig)
|
||||
r.POST("config", AddConfig)
|
||||
r.POST("config/*name", EditConfig)
|
||||
|
||||
o := r.Group("", middleware.RequireSecureSession())
|
||||
{
|
||||
o.POST("config_mkdir", Mkdir)
|
||||
o.POST("config_rename", Rename)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package nginx
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Reload(c *gin.Context) {
|
||||
output := nginx.Reload()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": output,
|
||||
"level": nginx.GetLogLevel(output),
|
||||
})
|
||||
}
|
||||
|
||||
func Test(c *gin.Context) {
|
||||
output := nginx.TestConf()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": output,
|
||||
"level": nginx.GetLogLevel(output),
|
||||
})
|
||||
}
|
||||
|
||||
func Restart(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
go nginx.Restart()
|
||||
}
|
||||
|
||||
func Status(c *gin.Context) {
|
||||
pidPath := nginx.GetPIDPath()
|
||||
lastOutput := nginx.GetLastOutput()
|
||||
|
||||
running := true
|
||||
if fileInfo, err := os.Stat(pidPath); err != nil || fileInfo.Size() == 0 { // fileInfo.Size() == 0 no process id
|
||||
running = false
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"running": running,
|
||||
"message": lastOutput,
|
||||
"level": nginx.GetLogLevel(lastOutput),
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package nginx
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func BuildNginxConfig(c *gin.Context) {
|
||||
var ngxConf nginx.NgxConfig
|
||||
if !api.BindAndValid(c, &ngxConf) {
|
||||
return
|
||||
}
|
||||
content, err := ngxConf.BuildConfig()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": content,
|
||||
})
|
||||
}
|
||||
|
||||
func TokenizeNginxConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
ngxConfig, err := nginx.ParseNgxConfigByContent(json.Content)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, ngxConfig)
|
||||
|
||||
}
|
||||
|
||||
func FormatNginxConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
content, err := nginx.FmtCode(json.Content)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": content,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package nginx
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.POST("ngx/build_config", BuildNginxConfig)
|
||||
r.POST("ngx/tokenize_config", TokenizeNginxConfig)
|
||||
r.POST("ngx/format_code", FormatNginxConfig)
|
||||
r.POST("nginx/reload", Reload)
|
||||
r.POST("nginx/restart", Restart)
|
||||
r.POST("nginx/test", Test)
|
||||
r.GET("nginx/status", Status)
|
||||
r.POST("nginx_log", GetNginxLogPage)
|
||||
}
|
||||
|
||||
func InitNginxLogRouter(r *gin.RouterGroup) {
|
||||
r.GET("nginx_log", Log)
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Get(c *gin.Context) {
|
||||
n := query.Notification
|
||||
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
|
||||
data, err := n.FirstByID(id)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
func GetList(c *gin.Context) {
|
||||
cosy.Core[model.Notification](c).PagingList()
|
||||
}
|
||||
|
||||
func Destroy(c *gin.Context) {
|
||||
cosy.Core[model.Notification](c).Destroy()
|
||||
}
|
||||
|
||||
func DestroyAll(c *gin.Context) {
|
||||
db := model.UseDB()
|
||||
// remove all records
|
||||
err := db.Exec("DELETE FROM notifications").Error
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
// reset auto increment
|
||||
err = db.Exec("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'notifications';").Error
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package notification
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("notifications", GetList)
|
||||
r.GET("notification/:id", Get)
|
||||
r.DELETE("notification/:id", Destroy)
|
||||
r.DELETE("notifications", DestroyAll)
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package openai
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
// ChatGPT
|
||||
r.POST("chatgpt", MakeChatCompletionRequest)
|
||||
r.POST("chatgpt_record", StoreChatGPTRecord)
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package openai
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func StoreChatGPTRecord(c *gin.Context) {
|
||||
var json struct {
|
||||
FileName string `json:"file_name"`
|
||||
Messages []openai.ChatCompletionMessage `json:"messages"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
name := json.FileName
|
||||
g := query.ChatGPTLog
|
||||
_, err := g.Where(g.Name.Eq(name)).FirstOrCreate()
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = g.Where(g.Name.Eq(name)).Updates(&model.ChatGPTLog{
|
||||
Name: name,
|
||||
Content: json.Messages,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetBanLoginIP(c *gin.Context) {
|
||||
b := query.BanIP
|
||||
|
||||
// clear expired banned IPs
|
||||
_, _ = b.Where(b.ExpiredAt.Lte(time.Now().Unix())).Delete()
|
||||
|
||||
banIps, err := b.Where(
|
||||
b.ExpiredAt.Gte(time.Now().Unix()),
|
||||
b.Attempts.Gte(settings.AuthSettings.MaxAttempts)).Find()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, banIps)
|
||||
}
|
||||
|
||||
func RemoveBannedIP(c *gin.Context) {
|
||||
var json struct {
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
b := query.BanIP
|
||||
_, err := b.Where(b.IP.Eq(json.IP)).Delete()
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("settings/server/name", GetServerName)
|
||||
r.GET("settings", GetSettings)
|
||||
r.POST("settings", middleware.RequireSecureSession(), SaveSettings)
|
||||
|
||||
r.GET("settings/auth/banned_ips", GetBanLoginIP)
|
||||
r.DELETE("settings/auth/banned_ip", RemoveBannedIP)
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cron"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetServerName(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"name": settings.ServerSettings.Name,
|
||||
})
|
||||
}
|
||||
|
||||
func GetSettings(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"server": settings.ServerSettings,
|
||||
"nginx": settings.NginxSettings,
|
||||
"openai": settings.OpenAISettings,
|
||||
"logrotate": settings.LogrotateSettings,
|
||||
"auth": settings.AuthSettings,
|
||||
})
|
||||
}
|
||||
|
||||
func SaveSettings(c *gin.Context) {
|
||||
var json struct {
|
||||
Server settings.Server `json:"server"`
|
||||
Nginx settings.Nginx `json:"nginx"`
|
||||
Openai settings.OpenAI `json:"openai"`
|
||||
Logrotate settings.Logrotate `json:"logrotate"`
|
||||
Auth settings.Auth `json:"auth"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
if settings.LogrotateSettings.Enabled != json.Logrotate.Enabled ||
|
||||
settings.LogrotateSettings.Interval != json.Logrotate.Interval {
|
||||
go cron.RestartLogrotate()
|
||||
}
|
||||
|
||||
settings.ProtectedFill(&settings.ServerSettings, &json.Server)
|
||||
settings.ProtectedFill(&settings.NginxSettings, &json.Nginx)
|
||||
settings.ProtectedFill(&settings.OpenAISettings, &json.Openai)
|
||||
settings.ProtectedFill(&settings.LogrotateSettings, &json.Logrotate)
|
||||
settings.ProtectedFill(&settings.AuthSettings, &json.Auth)
|
||||
|
||||
err := settings.Save()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
GetSettings(c)
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DomainEditByAdvancedMode(c *gin.Context) {
|
||||
var json struct {
|
||||
Advanced bool `json:"advanced"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
name := c.Param("name")
|
||||
path := nginx.GetConfPath("sites-available", name)
|
||||
|
||||
s := query.Site
|
||||
|
||||
_, err := s.Where(s.Path.Eq(path)).FirstOrCreate()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = s.Where(s.Path.Eq(path)).Update(s.Advanced, json.Advanced)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func AddDomainToAutoCert(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
|
||||
var json struct {
|
||||
DnsCredentialID int `json:"dns_credential_id"`
|
||||
ChallengeMethod string `json:"challenge_method"`
|
||||
Domains []string `json:"domains"`
|
||||
KeyType certcrypto.KeyType `json:"key_type"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
certModel, err := model.FirstOrCreateCert(name, helper.GetKeyType(json.KeyType))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = certModel.Updates(&model.Cert{
|
||||
Name: name,
|
||||
Domains: json.Domains,
|
||||
AutoCert: model.AutoCertEnabled,
|
||||
DnsCredentialID: json.DnsCredentialID,
|
||||
ChallengeMethod: json.ChallengeMethod,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, certModel)
|
||||
}
|
||||
|
||||
func RemoveDomainFromAutoCert(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
certModel, err := model.FirstCert(name)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = certModel.Updates(&model.Cert{
|
||||
AutoCert: model.AutoCertDisabled,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, nil)
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DuplicateSite(c *gin.Context) {
|
||||
// Source name
|
||||
name := c.Param("name")
|
||||
|
||||
// Destination name
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
src := nginx.GetConfPath("sites-available", name)
|
||||
dst := nginx.GetConfPath("sites-available", json.Name)
|
||||
|
||||
if helper.FileExists(dst) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_, err := helper.CopyFile(src, dst)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"dst": dst,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package sites
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("domains", GetDomains)
|
||||
r.GET("domain/:name", GetDomain)
|
||||
r.POST("domain/:name", SaveDomain)
|
||||
r.POST("domain/:name/enable", EnableDomain)
|
||||
r.POST("domain/:name/disable", DisableDomain)
|
||||
r.POST("domain/:name/advance", DomainEditByAdvancedMode)
|
||||
r.DELETE("domain/:name", DeleteDomain)
|
||||
r.POST("domain/:name/duplicate", DuplicateSite)
|
||||
r.POST("auto_cert/:name", AddDomainToAutoCert)
|
||||
r.DELETE("auto_cert/:name", RemoveDomainFromAutoCert)
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Site struct {
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
Advanced bool `json:"advanced"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Name string `json:"name"`
|
||||
Config string `json:"config"`
|
||||
AutoCert bool `json:"auto_cert"`
|
||||
ChatGPTMessages []openai.ChatCompletionMessage `json:"chatgpt_messages,omitempty"`
|
||||
Tokenized *nginx.NgxConfig `json:"tokenized,omitempty"`
|
||||
CertInfo map[int][]*cert.Info `json:"cert_info,omitempty"`
|
||||
Filepath string `json:"filepath"`
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package streams
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func AdvancedEdit(c *gin.Context) {
|
||||
var json struct {
|
||||
Advanced bool `json:"advanced"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
name := c.Param("name")
|
||||
path := nginx.GetConfPath("streams-available", name)
|
||||
|
||||
s := query.Site
|
||||
|
||||
_, err := s.Where(s.Path.Eq(path)).FirstOrCreate()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = s.Where(s.Path.Eq(path)).Update(s.Advanced, json.Advanced)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package streams
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Duplicate(c *gin.Context) {
|
||||
// Source name
|
||||
name := c.Param("name")
|
||||
|
||||
// Destination name
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
src := nginx.GetConfPath("streams-available", name)
|
||||
dst := nginx.GetConfPath("streams-available", json.Name)
|
||||
|
||||
if helper.FileExists(dst) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_, err := helper.CopyFile(src, dst)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"dst": dst,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package streams
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("streams", GetStreams)
|
||||
r.GET("stream/:name", GetStream)
|
||||
r.POST("stream/:name", SaveStream)
|
||||
r.POST("stream/:name/enable", EnableStream)
|
||||
r.POST("stream/:name/disable", DisableStream)
|
||||
r.POST("stream/:name/advance", AdvancedEdit)
|
||||
r.DELETE("stream/:name", DeleteStream)
|
||||
r.POST("stream/:name/duplicate", Duplicate)
|
||||
}
|
||||
@ -0,0 +1,359 @@
|
||||
package streams
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Stream struct {
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
Advanced bool `json:"advanced"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Name string `json:"name"`
|
||||
Config string `json:"config"`
|
||||
ChatGPTMessages []openai.ChatCompletionMessage `json:"chatgpt_messages,omitempty"`
|
||||
Tokenized *nginx.NgxConfig `json:"tokenized,omitempty"`
|
||||
Filepath string `json:"filepath"`
|
||||
}
|
||||
|
||||
func GetStreams(c *gin.Context) {
|
||||
name := c.Query("name")
|
||||
orderBy := c.Query("order_by")
|
||||
sort := c.DefaultQuery("sort", "desc")
|
||||
|
||||
configFiles, err := os.ReadDir(nginx.GetConfPath("streams-available"))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
enabledConfig, err := os.ReadDir(nginx.GetConfPath("streams-enabled"))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
enabledConfigMap := make(map[string]bool)
|
||||
for i := range enabledConfig {
|
||||
enabledConfigMap[enabledConfig[i].Name()] = true
|
||||
}
|
||||
|
||||
var configs []config.Config
|
||||
|
||||
for i := range configFiles {
|
||||
file := configFiles[i]
|
||||
fileInfo, _ := file.Info()
|
||||
if !file.IsDir() {
|
||||
if name != "" && !strings.Contains(file.Name(), name) {
|
||||
continue
|
||||
}
|
||||
configs = append(configs, config.Config{
|
||||
Name: file.Name(),
|
||||
ModifiedAt: fileInfo.ModTime(),
|
||||
Size: fileInfo.Size(),
|
||||
IsDir: fileInfo.IsDir(),
|
||||
Enabled: enabledConfigMap[file.Name()],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
configs = config.Sort(orderBy, sort, configs)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": configs,
|
||||
})
|
||||
}
|
||||
|
||||
func GetStream(c *gin.Context) {
|
||||
rewriteName, ok := c.Get("rewriteConfigFileName")
|
||||
|
||||
name := c.Param("name")
|
||||
|
||||
// for modify filename
|
||||
if ok {
|
||||
name = rewriteName.(string)
|
||||
}
|
||||
|
||||
path := nginx.GetConfPath("streams-available", name)
|
||||
file, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "file not found",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
enabled := true
|
||||
|
||||
if _, err := os.Stat(nginx.GetConfPath("streams-enabled", name)); os.IsNotExist(err) {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
g := query.ChatGPTLog
|
||||
chatgpt, err := g.Where(g.Name.Eq(path)).FirstOrCreate()
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if chatgpt.Content == nil {
|
||||
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
|
||||
}
|
||||
|
||||
s := query.Stream
|
||||
stream, err := s.Where(s.Path.Eq(path)).FirstOrInit()
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if stream.Advanced {
|
||||
origContent, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, Stream{
|
||||
ModifiedAt: file.ModTime(),
|
||||
Advanced: stream.Advanced,
|
||||
Enabled: enabled,
|
||||
Name: name,
|
||||
Config: string(origContent),
|
||||
ChatGPTMessages: chatgpt.Content,
|
||||
Filepath: path,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
nginxConfig, err := nginx.ParseNgxConfig(path)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, Stream{
|
||||
ModifiedAt: file.ModTime(),
|
||||
Advanced: stream.Advanced,
|
||||
Enabled: enabled,
|
||||
Name: name,
|
||||
Config: nginxConfig.FmtCode(),
|
||||
Tokenized: nginxConfig,
|
||||
ChatGPTMessages: chatgpt.Content,
|
||||
Filepath: path,
|
||||
})
|
||||
}
|
||||
|
||||
func SaveStream(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
|
||||
if name == "" {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "param name is empty",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
Overwrite bool `json:"overwrite"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
path := nginx.GetConfPath("streams-available", name)
|
||||
|
||||
if !json.Overwrite && helper.FileExists(path) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
err := os.WriteFile(path, []byte(json.Content), 0644)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
enabledConfigFilePath := nginx.GetConfPath("streams-enabled", name)
|
||||
// rename the config file if needed
|
||||
if name != json.Name {
|
||||
newPath := nginx.GetConfPath("streams-available", json.Name)
|
||||
s := query.Stream
|
||||
_, err = s.Where(s.Path.Eq(path)).Update(s.Path, newPath)
|
||||
|
||||
// check if dst file exists, do not rename
|
||||
if helper.FileExists(newPath) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
// recreate a soft link
|
||||
if helper.FileExists(enabledConfigFilePath) {
|
||||
_ = os.Remove(enabledConfigFilePath)
|
||||
enabledConfigFilePath = nginx.GetConfPath("streams-enabled", json.Name)
|
||||
err = os.Symlink(newPath, enabledConfigFilePath)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = os.Rename(path, newPath)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
name = json.Name
|
||||
c.Set("rewriteConfigFileName", name)
|
||||
}
|
||||
|
||||
enabledConfigFilePath = nginx.GetConfPath("streams-enabled", name)
|
||||
if helper.FileExists(enabledConfigFilePath) {
|
||||
// Test nginx configuration
|
||||
output := nginx.TestConf()
|
||||
|
||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
output = nginx.Reload()
|
||||
|
||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
GetStream(c)
|
||||
}
|
||||
|
||||
func EnableStream(c *gin.Context) {
|
||||
configFilePath := nginx.GetConfPath("streams-available", c.Param("name"))
|
||||
enabledConfigFilePath := nginx.GetConfPath("streams-enabled", c.Param("name"))
|
||||
|
||||
_, err := os.Stat(configFilePath)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = os.Stat(enabledConfigFilePath); os.IsNotExist(err) {
|
||||
err = os.Symlink(configFilePath, enabledConfigFilePath)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Test nginx config, if not pass, then disable the stream.
|
||||
output := nginx.TestConf()
|
||||
|
||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||
_ = os.Remove(enabledConfigFilePath)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
output = nginx.Reload()
|
||||
|
||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
|
||||
func DisableStream(c *gin.Context) {
|
||||
enabledConfigFilePath := nginx.GetConfPath("streams-enabled", c.Param("name"))
|
||||
|
||||
_, err := os.Stat(enabledConfigFilePath)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.Remove(enabledConfigFilePath)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
output := nginx.Reload()
|
||||
|
||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteStream(c *gin.Context) {
|
||||
var err error
|
||||
name := c.Param("name")
|
||||
availablePath := nginx.GetConfPath("streams-available", name)
|
||||
enabledPath := nginx.GetConfPath("streams-enabled", name)
|
||||
|
||||
if _, err = os.Stat(availablePath); os.IsNotExist(err) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "stream not found",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = os.Stat(enabledPath); err == nil {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "stream is enabled",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.Remove(availablePath); err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/kernal"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func installLockStatus() bool {
|
||||
return settings.ServerSettings.SkipInstallation || "" != settings.ServerSettings.JwtSecret
|
||||
}
|
||||
|
||||
func InstallLockCheck(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"lock": installLockStatus(),
|
||||
})
|
||||
}
|
||||
|
||||
type InstallJson struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Username string `json:"username" binding:"required,max=255"`
|
||||
Password string `json:"password" binding:"required,max=255"`
|
||||
Database string `json:"database"`
|
||||
}
|
||||
|
||||
func InstallNginxUI(c *gin.Context) {
|
||||
// Visit this api after installed is forbidden
|
||||
if installLockStatus() {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"error": "installed",
|
||||
})
|
||||
return
|
||||
}
|
||||
var json InstallJson
|
||||
ok := api.BindAndValid(c, &json)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
settings.ServerSettings.JwtSecret = uuid.New().String()
|
||||
settings.ServerSettings.NodeSecret = uuid.New().String()
|
||||
settings.ServerSettings.Email = json.Email
|
||||
if "" != json.Database {
|
||||
settings.ServerSettings.Database = json.Database
|
||||
}
|
||||
|
||||
err := settings.Save()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Init model
|
||||
kernal.InitDatabase()
|
||||
|
||||
pwd, _ := bcrypt.GenerateFromPassword([]byte(json.Password), bcrypt.DefaultCost)
|
||||
|
||||
u := query.User
|
||||
err = u.Create(&model.User{
|
||||
Name: json.Username,
|
||||
Password: string(pwd),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitPublicRouter(r *gin.RouterGroup) {
|
||||
r.GET("install", InstallLockCheck)
|
||||
r.POST("install", InstallNginxUI)
|
||||
r.GET("translation/:code", GetTranslation)
|
||||
}
|
||||
|
||||
func InitPrivateRouter(r *gin.RouterGroup) {
|
||||
r.GET("upgrade/release", GetRelease)
|
||||
r.GET("upgrade/current", GetCurrentVersion)
|
||||
}
|
||||
|
||||
func InitWebSocketRouter(r *gin.RouterGroup) {
|
||||
r.GET("upgrade/perform", PerformCoreUpgrade)
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/translation"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetTranslation(c *gin.Context) {
|
||||
code := c.Param("code")
|
||||
|
||||
c.JSON(http.StatusOK, translation.GetTranslation(code))
|
||||
}
|
||||
@ -0,0 +1,156 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/upgrader"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func GetRelease(c *gin.Context) {
|
||||
data, err := upgrader.GetRelease(c.Query("channel"))
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
runtimeInfo, err := upgrader.GetRuntimeInfo()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
type resp struct {
|
||||
upgrader.TRelease
|
||||
upgrader.RuntimeInfo
|
||||
}
|
||||
c.JSON(http.StatusOK, resp{
|
||||
data, runtimeInfo,
|
||||
})
|
||||
}
|
||||
|
||||
func GetCurrentVersion(c *gin.Context) {
|
||||
curVer, err := upgrader.GetCurrentVersion()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, curVer)
|
||||
}
|
||||
|
||||
const (
|
||||
UpgradeStatusInfo = "info"
|
||||
UpgradeStatusError = "error"
|
||||
UpgradeStatusProgress = "progress"
|
||||
)
|
||||
|
||||
type CoreUpgradeResp struct {
|
||||
Status string `json:"status"`
|
||||
Progress float64 `json:"progress"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func PerformCoreUpgrade(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
defer ws.Close()
|
||||
|
||||
var control struct {
|
||||
DryRun bool `json:"dry_run"`
|
||||
Channel string `json:"channel"`
|
||||
}
|
||||
|
||||
err = ws.ReadJSON(&control)
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusInfo,
|
||||
Message: "Initialing core upgrader",
|
||||
})
|
||||
|
||||
u, err := upgrader.NewUpgrader(control.Channel)
|
||||
|
||||
if err != nil {
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusError,
|
||||
Message: "Initial core upgrader error",
|
||||
})
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusError,
|
||||
Message: err.Error(),
|
||||
})
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusInfo,
|
||||
Message: "Downloading latest release",
|
||||
})
|
||||
progressChan := make(chan float64)
|
||||
go func() {
|
||||
for progress := range progressChan {
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusProgress,
|
||||
Progress: progress,
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
tarName, err := u.DownloadLatestRelease(progressChan)
|
||||
if err != nil {
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusError,
|
||||
Message: "Download latest release error",
|
||||
})
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusError,
|
||||
Message: err.Error(),
|
||||
})
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
_ = os.Remove(tarName)
|
||||
_ = os.Remove(tarName + ".digest")
|
||||
}()
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusInfo,
|
||||
Message: "Performing core upgrade",
|
||||
})
|
||||
// dry run
|
||||
if control.DryRun || settings.ServerSettings.Demo {
|
||||
return
|
||||
}
|
||||
|
||||
// bye, will restart nginx-ui in performCoreUpgrade
|
||||
err = u.PerformCoreUpgrade(tarName)
|
||||
if err != nil {
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusError,
|
||||
Message: "Perform core upgrade error",
|
||||
})
|
||||
_ = ws.WriteJSON(CoreUpgradeResp{
|
||||
Status: UpgradeStatusError,
|
||||
Message: err.Error(),
|
||||
})
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package template
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("template", GetTemplate)
|
||||
r.GET("template/configs", GetTemplateConfList)
|
||||
r.GET("template/blocks", GetTemplateBlockList)
|
||||
r.GET("template/block/:name", GetTemplateBlock)
|
||||
r.POST("template/block/:name", GetTemplateBlock)
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package terminal
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("pty", Pty)
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package upstream
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.GET("/availability_test", AvailabilityTest)
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package upstream
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/upstream"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func AvailabilityTest(c *gin.Context) {
|
||||
var upGrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
|
||||
var body []string
|
||||
|
||||
err = ws.ReadJSON(&body)
|
||||
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
for {
|
||||
err = ws.WriteJSON(upstream.AvailabilityTest(body))
|
||||
if helper.IsUnexpectedWebsocketError(err) {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,156 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||
"github.com/0xJacky/Nginx-UI/internal/passkey"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/google/uuid"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Status2FA struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
OTPStatus bool `json:"otp_status"`
|
||||
PasskeyStatus bool `json:"passkey_status"`
|
||||
}
|
||||
|
||||
func get2FAStatus(c *gin.Context) (status Status2FA) {
|
||||
// when accessing the node from the main cluster, there is no user in the context
|
||||
u, ok := c.Get("user")
|
||||
if ok {
|
||||
userPtr := u.(*model.User)
|
||||
status.OTPStatus = userPtr.EnabledOTP()
|
||||
status.PasskeyStatus = userPtr.EnabledPasskey() && passkey.Enabled()
|
||||
status.Enabled = status.OTPStatus || status.PasskeyStatus
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Get2FAStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, get2FAStatus(c))
|
||||
}
|
||||
|
||||
func SecureSessionStatus(c *gin.Context) {
|
||||
status2FA := get2FAStatus(c)
|
||||
if !status2FA.Enabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ssid := c.GetHeader("X-Secure-Session-ID")
|
||||
if ssid == "" {
|
||||
ssid = c.Query("X-Secure-Session-ID")
|
||||
}
|
||||
if ssid == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
u := api.CurrentUser(c)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": user.VerifySecureSessionID(ssid, u.ID),
|
||||
})
|
||||
}
|
||||
|
||||
func Start2FASecureSessionByOTP(c *gin.Context) {
|
||||
var json struct {
|
||||
OTP string `json:"otp"`
|
||||
RecoveryCode string `json:"recovery_code"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
u := api.CurrentUser(c)
|
||||
if !u.EnabledOTP() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "User has not configured OTP as 2FA",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if json.OTP == "" && json.RecoveryCode == "" {
|
||||
c.JSON(http.StatusBadRequest, LoginResponse{
|
||||
Message: "The user has enabled OTP as 2FA",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err := user.VerifyOTP(u, json.OTP, json.RecoveryCode); err != nil {
|
||||
c.JSON(http.StatusBadRequest, LoginResponse{
|
||||
Message: "Invalid OTP or recovery code",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
sessionId := user.SetSecureSessionID(u.ID)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": sessionId,
|
||||
})
|
||||
}
|
||||
|
||||
func BeginStart2FASecureSessionByPasskey(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
u := api.CurrentUser(c)
|
||||
options, sessionData, err := webauthnInstance.BeginLogin(u)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
passkeySessionID := uuid.NewString()
|
||||
cache.Set(passkeySessionID, sessionData, passkeyTimeout)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": passkeySessionID,
|
||||
"options": options,
|
||||
})
|
||||
}
|
||||
|
||||
func FinishStart2FASecureSessionByPasskey(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
passkeySessionID := c.GetHeader("X-Passkey-Session-ID")
|
||||
sessionDataBytes, ok := cache.Get(passkeySessionID)
|
||||
if !ok {
|
||||
api.ErrHandler(c, fmt.Errorf("session not found"))
|
||||
return
|
||||
}
|
||||
sessionData := sessionDataBytes.(*webauthn.SessionData)
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
u := api.CurrentUser(c)
|
||||
credential, err := webauthnInstance.FinishLogin(u, *sessionData, c.Request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
rawID := strings.TrimRight(base64.StdEncoding.EncodeToString(credential.ID), "=")
|
||||
p := query.Passkey
|
||||
_, _ = p.Where(p.RawID.Eq(rawID)).Updates(&model.Passkey{
|
||||
LastUsedAt: time.Now().Unix(),
|
||||
})
|
||||
|
||||
sessionId := user.SetSecureSessionID(u.ID)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": sessionId,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
"math/rand/v2"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var mutex = &sync.Mutex{}
|
||||
|
||||
type LoginUser struct {
|
||||
Name string `json:"name" binding:"required,max=255"`
|
||||
Password string `json:"password" binding:"required,max=255"`
|
||||
OTP string `json:"otp"`
|
||||
RecoveryCode string `json:"recovery_code"`
|
||||
}
|
||||
|
||||
const (
|
||||
ErrPasswordIncorrect = 4031
|
||||
ErrMaxAttempts = 4291
|
||||
ErrUserBanned = 4033
|
||||
Enabled2FA = 199
|
||||
Error2FACode = 4034
|
||||
LoginSuccess = 200
|
||||
)
|
||||
|
||||
type LoginResponse struct {
|
||||
Message string `json:"message"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Code int `json:"code"`
|
||||
Token string `json:"token,omitempty"`
|
||||
SecureSessionID string `json:"secure_session_id,omitempty"`
|
||||
}
|
||||
|
||||
func Login(c *gin.Context) {
|
||||
// make sure that only one request is processed at a time
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
// check if the ip is banned
|
||||
clientIP := c.ClientIP()
|
||||
b := query.BanIP
|
||||
banIP, _ := b.Where(b.IP.Eq(clientIP),
|
||||
b.ExpiredAt.Gte(time.Now().Unix()),
|
||||
b.Attempts.Gte(settings.AuthSettings.MaxAttempts),
|
||||
).Count()
|
||||
|
||||
if banIP > 0 {
|
||||
c.JSON(http.StatusTooManyRequests, LoginResponse{
|
||||
Message: "Max attempts",
|
||||
Code: ErrMaxAttempts,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var json LoginUser
|
||||
ok := api.BindAndValid(c, &json)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
u, err := user.Login(json.Name, json.Password)
|
||||
if err != nil {
|
||||
random := time.Duration(rand.Int() % 10)
|
||||
time.Sleep(random * time.Second)
|
||||
switch {
|
||||
case errors.Is(err, user.ErrPasswordIncorrect):
|
||||
c.JSON(http.StatusForbidden, LoginResponse{
|
||||
Message: "Password incorrect",
|
||||
Code: ErrPasswordIncorrect,
|
||||
})
|
||||
case errors.Is(err, user.ErrUserBanned):
|
||||
c.JSON(http.StatusForbidden, LoginResponse{
|
||||
Message: "The user is banned",
|
||||
Code: ErrUserBanned,
|
||||
})
|
||||
default:
|
||||
api.ErrHandler(c, err)
|
||||
}
|
||||
user.BanIP(clientIP)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the user enables 2FA
|
||||
var secureSessionID string
|
||||
|
||||
if u.EnabledOTP() {
|
||||
if json.OTP == "" && json.RecoveryCode == "" {
|
||||
c.JSON(http.StatusOK, LoginResponse{
|
||||
Message: "The user has enabled 2FA",
|
||||
Code: Enabled2FA,
|
||||
})
|
||||
user.BanIP(clientIP)
|
||||
return
|
||||
}
|
||||
|
||||
if err = user.VerifyOTP(u, json.OTP, json.RecoveryCode); err != nil {
|
||||
c.JSON(http.StatusForbidden, LoginResponse{
|
||||
Message: "Invalid 2FA or recovery code",
|
||||
Code: Error2FACode,
|
||||
})
|
||||
user.BanIP(clientIP)
|
||||
return
|
||||
}
|
||||
|
||||
secureSessionID = user.SetSecureSessionID(u.ID)
|
||||
}
|
||||
|
||||
// login success, clear banned record
|
||||
_, _ = b.Where(b.IP.Eq(clientIP)).Delete()
|
||||
|
||||
logger.Info("[User Login]", u.Name)
|
||||
token, err := user.GenerateJWT(u)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, LoginResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, LoginResponse{
|
||||
Code: LoginSuccess,
|
||||
Message: "ok",
|
||||
Token: token,
|
||||
SecureSessionID: secureSessionID,
|
||||
})
|
||||
}
|
||||
|
||||
func Logout(c *gin.Context) {
|
||||
token := c.GetHeader("Authorization")
|
||||
if token != "" {
|
||||
user.DeleteToken(token)
|
||||
}
|
||||
c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type CasdoorLoginUser struct {
|
||||
Code string `json:"code" binding:"required,max=255"`
|
||||
State string `json:"state" binding:"required,max=255"`
|
||||
}
|
||||
|
||||
func CasdoorCallback(c *gin.Context) {
|
||||
var loginUser CasdoorLoginUser
|
||||
|
||||
ok := api.BindAndValid(c, &loginUser)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
endpoint := settings.CasdoorSettings.Endpoint
|
||||
clientId := settings.CasdoorSettings.ClientId
|
||||
clientSecret := settings.CasdoorSettings.ClientSecret
|
||||
certificate := settings.CasdoorSettings.Certificate
|
||||
organization := settings.CasdoorSettings.Organization
|
||||
application := settings.CasdoorSettings.Application
|
||||
if endpoint == "" || clientId == "" || clientSecret == "" || certificate == "" || organization == "" || application == "" {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": "Casdoor is not configured",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
casdoorsdk.InitConfig(endpoint, clientId, clientSecret, certificate, organization, application)
|
||||
|
||||
token, err := casdoorsdk.GetOAuthToken(loginUser.Code, loginUser.State)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
claims, err := casdoorsdk.ParseJwtToken(token.AccessToken)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
u, err := user.GetUser(claims.Name)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"message": "User not exist",
|
||||
})
|
||||
} else {
|
||||
api.ErrHandler(c, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
userToken, err := user.GenerateJWT(u)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, LoginResponse{
|
||||
Message: "ok",
|
||||
Token: userToken,
|
||||
})
|
||||
}
|
||||
|
||||
func GetCasdoorUri(c *gin.Context) {
|
||||
endpoint := settings.CasdoorSettings.Endpoint
|
||||
clientId := settings.CasdoorSettings.ClientId
|
||||
redirectUri := settings.CasdoorSettings.RedirectUri
|
||||
state := settings.CasdoorSettings.Application
|
||||
|
||||
if endpoint == "" || clientId == "" || redirectUri == "" || state == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"uri": "",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
encodedRedirectUri := url.QueryEscape(redirectUri)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"uri": fmt.Sprintf("%s/login/oauth/authorize?client_id=%s&response_type=code&redirect_uri=%s&state=%s&scope=read", endpoint, clientId, encodedRedirectUri, state),
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,147 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/crypto"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pquerna/otp"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"image/jpeg"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GenerateTOTP(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
|
||||
issuer := fmt.Sprintf("Nginx UI %s", settings.ServerSettings.Name)
|
||||
issuer = strings.TrimSpace(issuer)
|
||||
|
||||
otpOpts := totp.GenerateOpts{
|
||||
Issuer: issuer,
|
||||
AccountName: u.Name,
|
||||
Period: 30, // seconds
|
||||
Digits: otp.DigitsSix,
|
||||
Algorithm: otp.AlgorithmSHA1,
|
||||
}
|
||||
otpKey, err := totp.Generate(otpOpts)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
qrCode, err := otpKey.Image(512, 512)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Encode the image to a buffer
|
||||
var buf []byte
|
||||
buffer := bytes.NewBuffer(buf)
|
||||
err = jpeg.Encode(buffer, qrCode, nil)
|
||||
if err != nil {
|
||||
fmt.Println("Error encoding image:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Convert the buffer to a base64 string
|
||||
base64Str := "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(buffer.Bytes())
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"secret": otpKey.Secret(),
|
||||
"qr_code": base64Str,
|
||||
})
|
||||
}
|
||||
|
||||
func EnrollTOTP(c *gin.Context) {
|
||||
cUser := api.CurrentUser(c)
|
||||
if cUser.EnabledOTP() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "User already enrolled",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if settings.ServerSettings.Demo {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "This feature is disabled in demo mode",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var json struct {
|
||||
Secret string `json:"secret" binding:"required"`
|
||||
Passcode string `json:"passcode" binding:"required"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
if ok := totp.Validate(json.Passcode, json.Secret); !ok {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "Invalid passcode",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ciphertext, err := crypto.AesEncrypt([]byte(json.Secret))
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
u := query.User
|
||||
_, err = u.Where(u.ID.Eq(cUser.ID)).Update(u.OTPSecret, ciphertext)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
recoveryCode := sha1.Sum(ciphertext)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
"recovery_code": hex.EncodeToString(recoveryCode[:]),
|
||||
})
|
||||
}
|
||||
|
||||
func ResetOTP(c *gin.Context) {
|
||||
var json struct {
|
||||
RecoveryCode string `json:"recovery_code"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
recoverCode, err := hex.DecodeString(json.RecoveryCode)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
cUser := api.CurrentUser(c)
|
||||
k := sha1.Sum(cUser.OTPSecret)
|
||||
if !bytes.Equal(k[:], recoverCode) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "Invalid recovery code",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
u := query.User
|
||||
_, err = u.Where(u.ID.Eq(cUser.ID)).UpdateSimple(u.OTPSecret.Null())
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,195 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/passkey"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const passkeyTimeout = 30 * time.Second
|
||||
|
||||
func buildCachePasskeyRegKey(id int) string {
|
||||
return fmt.Sprintf("passkey-reg-%d", id)
|
||||
}
|
||||
|
||||
func GetPasskeyConfigStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": passkey.Enabled(),
|
||||
})
|
||||
}
|
||||
|
||||
func BeginPasskeyRegistration(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
|
||||
options, sessionData, err := webauthnInstance.BeginRegistration(u)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
cache.Set(buildCachePasskeyRegKey(u.ID), sessionData, passkeyTimeout)
|
||||
|
||||
c.JSON(http.StatusOK, options)
|
||||
}
|
||||
|
||||
func FinishPasskeyRegistration(c *gin.Context) {
|
||||
cUser := api.CurrentUser(c)
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
sessionDataBytes, ok := cache.Get(buildCachePasskeyRegKey(cUser.ID))
|
||||
if !ok {
|
||||
api.ErrHandler(c, fmt.Errorf("session not found"))
|
||||
return
|
||||
}
|
||||
|
||||
sessionData := sessionDataBytes.(*webauthn.SessionData)
|
||||
credential, err := webauthnInstance.FinishRegistration(cUser, *sessionData, c.Request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
cache.Del(buildCachePasskeyRegKey(cUser.ID))
|
||||
|
||||
rawId := strings.TrimRight(base64.StdEncoding.EncodeToString(credential.ID), "=")
|
||||
passkeyName := c.Query("name")
|
||||
p := query.Passkey
|
||||
err = p.Create(&model.Passkey{
|
||||
UserID: cUser.ID,
|
||||
Name: passkeyName,
|
||||
RawID: rawId,
|
||||
Credential: credential,
|
||||
LastUsedAt: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
|
||||
func BeginPasskeyLogin(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
options, sessionData, err := webauthnInstance.BeginDiscoverableLogin()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
sessionID := uuid.NewString()
|
||||
cache.Set(sessionID, sessionData, passkeyTimeout)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": sessionID,
|
||||
"options": options,
|
||||
})
|
||||
}
|
||||
|
||||
func FinishPasskeyLogin(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
sessionId := c.GetHeader("X-Passkey-Session-ID")
|
||||
sessionDataBytes, ok := cache.Get(sessionId)
|
||||
if !ok {
|
||||
api.ErrHandler(c, fmt.Errorf("session not found"))
|
||||
return
|
||||
}
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
sessionData := sessionDataBytes.(*webauthn.SessionData)
|
||||
var outUser *model.User
|
||||
_, err := webauthnInstance.FinishDiscoverableLogin(
|
||||
func(rawID, userHandle []byte) (user webauthn.User, err error) {
|
||||
encodeRawID := strings.TrimRight(base64.StdEncoding.EncodeToString(rawID), "=")
|
||||
u := query.User
|
||||
logger.Debug("[WebAuthn] Discoverable Login", cast.ToInt(string(userHandle)))
|
||||
|
||||
p := query.Passkey
|
||||
_, _ = p.Where(p.RawID.Eq(encodeRawID)).Updates(&model.Passkey{
|
||||
LastUsedAt: time.Now().Unix(),
|
||||
})
|
||||
|
||||
outUser, err = u.FirstByID(cast.ToInt(string(userHandle)))
|
||||
return outUser, err
|
||||
}, *sessionData, c.Request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
b := query.BanIP
|
||||
clientIP := c.ClientIP()
|
||||
// login success, clear banned record
|
||||
_, _ = b.Where(b.IP.Eq(clientIP)).Delete()
|
||||
|
||||
logger.Info("[User Login]", outUser.Name)
|
||||
token, err := user.GenerateJWT(outUser)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, LoginResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, LoginResponse{
|
||||
Code: LoginSuccess,
|
||||
Message: "ok",
|
||||
Token: token,
|
||||
// SecureSessionID: secureSessionID,
|
||||
})
|
||||
}
|
||||
|
||||
func GetPasskeyList(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
p := query.Passkey
|
||||
passkeys, err := p.Where(p.UserID.Eq(u.ID)).Find()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(passkeys) == 0 {
|
||||
passkeys = make([]*model.Passkey, 0)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, passkeys)
|
||||
}
|
||||
|
||||
func UpdatePasskey(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
cosy.Core[model.Passkey](c).
|
||||
SetValidRules(gin.H{
|
||||
"name": "required",
|
||||
}).GormScope(func(tx *gorm.DB) *gorm.DB {
|
||||
return tx.Where("user_id", u.ID)
|
||||
}).Modify()
|
||||
}
|
||||
|
||||
func DeletePasskey(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
cosy.Core[model.Passkey](c).
|
||||
GormScope(func(tx *gorm.DB) *gorm.DB {
|
||||
return tx.Where("user_id", u.ID)
|
||||
}).PermanentlyDelete()
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitAuthRouter(r *gin.RouterGroup) {
|
||||
r.POST("/login", Login)
|
||||
r.DELETE("/logout", Logout)
|
||||
|
||||
r.GET("/begin_passkey_login", BeginPasskeyLogin)
|
||||
r.POST("/finish_passkey_login", FinishPasskeyLogin)
|
||||
|
||||
r.GET("/casdoor_uri", GetCasdoorUri)
|
||||
r.POST("/casdoor_callback", CasdoorCallback)
|
||||
|
||||
r.GET("/passkeys/config", GetPasskeyConfigStatus)
|
||||
}
|
||||
|
||||
func InitManageUserRouter(r *gin.RouterGroup) {
|
||||
r.GET("users", GetUsers)
|
||||
r.GET("user/:id", GetUser)
|
||||
r.POST("user", AddUser)
|
||||
r.POST("user/:id", EditUser)
|
||||
r.DELETE("user/:id", DeleteUser)
|
||||
r.PATCH("user/:id", RecoverUser)
|
||||
}
|
||||
|
||||
func InitUserRouter(r *gin.RouterGroup) {
|
||||
r.GET("/2fa_status", Get2FAStatus)
|
||||
r.GET("/2fa_secure_session/status", SecureSessionStatus)
|
||||
r.POST("/2fa_secure_session/otp", Start2FASecureSessionByOTP)
|
||||
r.GET("/2fa_secure_session/passkey", BeginStart2FASecureSessionByPasskey)
|
||||
r.POST("/2fa_secure_session/passkey", FinishStart2FASecureSessionByPasskey)
|
||||
|
||||
r.GET("/otp_secret", GenerateTOTP)
|
||||
r.POST("/otp_enroll", EnrollTOTP)
|
||||
r.POST("/otp_reset", ResetOTP)
|
||||
|
||||
r.GET("/begin_passkey_register", BeginPasskeyRegistration)
|
||||
r.POST("/finish_passkey_register", FinishPasskeyRegistration)
|
||||
|
||||
r.GET("/passkeys", GetPasskeyList)
|
||||
r.POST("/passkeys/:id", UpdatePasskey)
|
||||
r.DELETE("/passkeys/:id", DeletePasskey)
|
||||
}
|
||||
@ -0,0 +1,132 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetUsers(c *gin.Context) {
|
||||
cosy.Core[model.User](c).SetFussy("name").PagingList()
|
||||
}
|
||||
|
||||
func GetUser(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
|
||||
u := query.User
|
||||
|
||||
user, err := u.FirstByID(id)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
type UserJson struct {
|
||||
Name string `json:"name" binding:"required,max=255"`
|
||||
Password string `json:"password" binding:"max=255"`
|
||||
}
|
||||
|
||||
func AddUser(c *gin.Context) {
|
||||
var json UserJson
|
||||
ok := api.BindAndValid(c, &json)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
u := query.User
|
||||
|
||||
pwd, err := bcrypt.GenerateFromPassword([]byte(json.Password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
json.Password = string(pwd)
|
||||
|
||||
user := model.User{
|
||||
Name: json.Name,
|
||||
Password: json.Password,
|
||||
}
|
||||
|
||||
err = u.Create(&user)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, user)
|
||||
|
||||
}
|
||||
|
||||
func EditUser(c *gin.Context) {
|
||||
userId := cast.ToInt(c.Param("id"))
|
||||
|
||||
if settings.ServerSettings.Demo && userId == 1 {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "Changing user password is forbidden in demo mode",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var json UserJson
|
||||
ok := api.BindAndValid(c, &json)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
u := query.User
|
||||
user, err := u.FirstByID(userId)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
edit := &model.User{
|
||||
Name: json.Name,
|
||||
}
|
||||
|
||||
// encrypt password
|
||||
if json.Password != "" {
|
||||
var pwd []byte
|
||||
pwd, err = bcrypt.GenerateFromPassword([]byte(json.Password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
edit.Password = string(pwd)
|
||||
}
|
||||
|
||||
_, err = u.Where(u.ID.Eq(userId)).Updates(&edit)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
func DeleteUser(c *gin.Context) {
|
||||
id := cast.ToInt(c.Param("id"))
|
||||
if cast.ToInt(id) == 1 {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "Prohibit deleting the default user",
|
||||
})
|
||||
return
|
||||
}
|
||||
cosy.Core[model.User](c).Destroy()
|
||||
}
|
||||
|
||||
func RecoverUser(c *gin.Context) {
|
||||
cosy.Core[model.User](c).Recover()
|
||||
}
|
||||
@ -1,29 +1,67 @@
|
||||
; suppress inspection "DuplicateKeyInSection" for whole file
|
||||
[server]
|
||||
HttpPort = 9000
|
||||
RunMode = debug
|
||||
JwtSecret =
|
||||
Email =
|
||||
HTTPChallengePort = 9180
|
||||
StartCmd = login
|
||||
Database = database
|
||||
CADir =
|
||||
Demo =
|
||||
GithubProxy =
|
||||
NginxConfigDir =
|
||||
|
||||
[nginx_log]
|
||||
HttpPort = 9000
|
||||
RunMode = debug
|
||||
JwtSecret =
|
||||
Email =
|
||||
HTTPChallengePort = 9180
|
||||
StartCmd = bash
|
||||
Database = database
|
||||
CADir =
|
||||
GithubProxy =
|
||||
NodeSecret =
|
||||
Demo = false
|
||||
PageSize = 10
|
||||
HttpHost = 0.0.0.0
|
||||
CertRenewalInterval = 7
|
||||
RecursiveNameservers =
|
||||
SkipInstallation = false
|
||||
Name =
|
||||
InsecureSkipVerify = false
|
||||
|
||||
[nginx]
|
||||
AccessLogPath = /var/log/nginx/access.log
|
||||
ErrorLogPath = /var/log/nginx/error.log
|
||||
ErrorLogPath = /var/log/nginx/error.log
|
||||
ConfigDir =
|
||||
PIDPath =
|
||||
TestConfigCmd =
|
||||
ReloadCmd =
|
||||
RestartCmd =
|
||||
|
||||
[openai]
|
||||
Model =
|
||||
BaseUrl =
|
||||
Proxy =
|
||||
Token =
|
||||
|
||||
[git]
|
||||
Url =
|
||||
AuthMethod =
|
||||
Username =
|
||||
Password =
|
||||
PrivateKeyFile =
|
||||
Model =
|
||||
BaseUrl =
|
||||
Proxy =
|
||||
Token =
|
||||
|
||||
[casdoor]
|
||||
Endpoint =
|
||||
ClientId =
|
||||
ClientSecret =
|
||||
Certificate =
|
||||
Organization =
|
||||
Application =
|
||||
RedirectUri =
|
||||
|
||||
[logrotate]
|
||||
Enabled = false
|
||||
CMD = logrotate /etc/logrotate.d/nginx
|
||||
Interval = 1440
|
||||
|
||||
[cluster]
|
||||
Node = http://10.0.0.1:9000?name=node1&node_secret=my-node-secret&enabled=true
|
||||
Node = http://10.0.0.2:9000?name=node2&node_secret=my-node-secret&enabled=true
|
||||
Node = http://10.0.0.3?name=node3&node_secret=my-node-secret&enabled=true
|
||||
|
||||
[auth]
|
||||
IPWhiteList =
|
||||
BanThresholdMinutes = 10
|
||||
MaxAttempts = 10
|
||||
|
||||
[crypto]
|
||||
Secret = secret2
|
||||
|
||||
[webauthn]
|
||||
RPDisplayName =
|
||||
RPID =
|
||||
RPOrigins =
|
||||
|
||||
@ -0,0 +1,257 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: [
|
||||
'@antfu/eslint-config-vue',
|
||||
'plugin:vue/vue3-recommended',
|
||||
'plugin:import/recommended',
|
||||
'plugin:import/typescript',
|
||||
'plugin:sonarjs/recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
|
||||
// 'plugin:unicorn/recommended',
|
||||
],
|
||||
parser: 'vue-eslint-parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 13,
|
||||
parser: '@typescript-eslint/parser',
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: [
|
||||
'vue',
|
||||
'@typescript-eslint',
|
||||
'regex',
|
||||
],
|
||||
ignorePatterns: ['src/@iconify/*.js', 'node_modules', 'dist', '*.d.ts'],
|
||||
rules: {
|
||||
'vue/no-v-html': 'off',
|
||||
|
||||
'vue/block-tag-newline': 'off',
|
||||
// eslint-disable-next-line n/prefer-global/process
|
||||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
// eslint-disable-next-line n/prefer-global/process
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
|
||||
// indentation (Already present in TypeScript)
|
||||
'comma-spacing': ['error', {
|
||||
before: false,
|
||||
after: true,
|
||||
}],
|
||||
'key-spacing': ['error', {afterColon: true}],
|
||||
|
||||
'vue/first-attribute-linebreak': ['error', {
|
||||
singleline: 'beside',
|
||||
multiline: 'below',
|
||||
}],
|
||||
|
||||
'antfu/top-level-function': 'off',
|
||||
|
||||
// Enforce trailing comma (Already present in TypeScript)
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
|
||||
// Disable max-len
|
||||
'max-len': 'off',
|
||||
|
||||
// we don't want it
|
||||
'semi': ['error', 'never'],
|
||||
|
||||
// add parens ony when required in arrow function
|
||||
'arrow-parens': ['error', 'as-needed'],
|
||||
|
||||
// add new line above comment
|
||||
'newline-before-return': 'error',
|
||||
|
||||
// add new line above comment
|
||||
'lines-around-comment': [
|
||||
'error',
|
||||
{
|
||||
beforeBlockComment: true,
|
||||
beforeLineComment: true,
|
||||
allowBlockStart: true,
|
||||
allowClassStart: true,
|
||||
allowObjectStart: true,
|
||||
allowArrayStart: true,
|
||||
},
|
||||
],
|
||||
|
||||
// Ignore _ as unused variable
|
||||
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_+$'}],
|
||||
|
||||
'array-element-newline': ['error', 'consistent'],
|
||||
'array-bracket-newline': ['error', 'consistent'],
|
||||
|
||||
'vue/multi-word-component-names': 'off',
|
||||
|
||||
'padding-line-between-statements': [
|
||||
'error',
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: 'expression',
|
||||
next: 'const',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: 'const',
|
||||
next: 'expression',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: 'multiline-const',
|
||||
next: '*',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: '*',
|
||||
next: 'multiline-const',
|
||||
},
|
||||
],
|
||||
|
||||
// Plugin: eslint-plugin-import
|
||||
'import/prefer-default-export': 'off',
|
||||
'import/newline-after-import': ['error', {count: 1}],
|
||||
'no-restricted-imports': ['error', 'vuetify/components'],
|
||||
|
||||
// For omitting extension for ts files
|
||||
'import/extensions': [
|
||||
'error',
|
||||
'ignorePackages',
|
||||
{
|
||||
mjs: 'never',
|
||||
js: 'never',
|
||||
jsx: 'never',
|
||||
ts: 'never',
|
||||
tsx: 'never',
|
||||
},
|
||||
],
|
||||
|
||||
// ignore virtual files
|
||||
'import/no-unresolved': [2, {
|
||||
ignore: [
|
||||
'~pages$',
|
||||
'virtual:generated-layouts',
|
||||
|
||||
// Ignore vite's ?raw imports
|
||||
'.*\?raw',
|
||||
],
|
||||
}],
|
||||
|
||||
// Thanks: https://stackoverflow.com/a/63961972/10796681
|
||||
'no-shadow': 'off',
|
||||
'@typescript-eslint/no-shadow': ['error'],
|
||||
|
||||
'@typescript-eslint/consistent-type-imports': 'error',
|
||||
|
||||
// Plugin: eslint-plugin-promise
|
||||
'promise/always-return': 'off',
|
||||
'promise/catch-or-return': 'off',
|
||||
|
||||
// ESLint plugin vue
|
||||
'vue/component-api-style': 'error',
|
||||
'vue/component-name-in-template-casing': ['error', 'PascalCase', {registeredComponentsOnly: false}],
|
||||
'vue/custom-event-name-casing': ['error', 'camelCase', {
|
||||
ignores: [
|
||||
'/^(click):[a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?/',
|
||||
],
|
||||
}],
|
||||
'vue/define-macros-order': 'error',
|
||||
'vue/html-comment-content-newline': 'error',
|
||||
'vue/html-comment-content-spacing': 'error',
|
||||
'vue/html-comment-indent': 'error',
|
||||
'vue/match-component-file-name': 'error',
|
||||
'vue/no-child-content': 'error',
|
||||
'vue/require-default-prop': 'off',
|
||||
|
||||
// NOTE this rule only supported in SFC, Users of the unplugin-vue-define-options should disable that rule: https://github.com/vuejs/eslint-plugin-vue/issues/1886
|
||||
// 'vue/no-duplicate-attr-inheritance': 'error',
|
||||
'vue/no-multiple-objects-in-class': 'error',
|
||||
'vue/no-reserved-component-names': 'error',
|
||||
'vue/no-template-target-blank': 'error',
|
||||
'vue/no-useless-mustaches': 'error',
|
||||
'vue/no-useless-v-bind': 'error',
|
||||
'vue/padding-line-between-blocks': 'error',
|
||||
'vue/prefer-separate-static-class': 'error',
|
||||
'vue/prefer-true-attribute-shorthand': 'error',
|
||||
'vue/v-on-function-call': 'error',
|
||||
'vue/valid-v-slot': ['error', {
|
||||
allowModifiers: true,
|
||||
}],
|
||||
|
||||
// -- Extension Rules
|
||||
'vue/no-irregular-whitespace': 'error',
|
||||
|
||||
// -- Sonarlint
|
||||
'sonarjs/no-duplicate-string': 'off',
|
||||
'sonarjs/no-nested-template-literals': 'off',
|
||||
|
||||
// -- Unicorn
|
||||
// 'unicorn/filename-case': 'off',
|
||||
// 'unicorn/prevent-abbreviations': ['error', {
|
||||
// replacements: {
|
||||
// props: false,
|
||||
// },
|
||||
// }],
|
||||
// https://github.com/gmullerb/eslint-plugin-regex
|
||||
'regex/invalid': [
|
||||
'error',
|
||||
[
|
||||
{
|
||||
regex: '@/assets/images',
|
||||
replacement: '@images',
|
||||
message: 'Use \'@images\' path alias for image imports',
|
||||
},
|
||||
{
|
||||
regex: '@/styles',
|
||||
replacement: '@styles',
|
||||
message: 'Use \'@styles\' path alias for importing styles from \'src/styles\'',
|
||||
},
|
||||
|
||||
// {
|
||||
// id: 'Disallow icon of icon library',
|
||||
// regex: 'tabler-\\w',
|
||||
// message: 'Only \'mdi\' icons are allowed',
|
||||
// },
|
||||
|
||||
{
|
||||
regex: '@core/\\w',
|
||||
message: 'You can\'t use @core when you are in @layouts module',
|
||||
files: {
|
||||
inspect: '@layouts/.*',
|
||||
},
|
||||
},
|
||||
{
|
||||
regex: 'useLayouts\\(',
|
||||
message: '`useLayouts` composable is only allowed in @layouts & @core directory. Please use `useThemeConfig` composable instead.',
|
||||
files: {
|
||||
inspect: '^(?!.*(@core|@layouts)).*',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
// Ignore files
|
||||
'\.eslintrc\.js',
|
||||
],
|
||||
},
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
node: {
|
||||
extensions: ['.ts', '.js', '.tsx', '.jsx', '.mjs', '.png', '.jpg'],
|
||||
},
|
||||
typescript: {},
|
||||
alias: {
|
||||
map: [
|
||||
['@', './src'],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.json'],
|
||||
rules: {
|
||||
'no-invalid-meta': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
||||
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
|
||||
</profile>
|
||||
</component>
|
||||
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<includedPredefinedLibrary name="Node.js Core" />
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EslintConfiguration">
|
||||
<custom-configuration-file used="false" path="$PROJECT_DIR$/.eslintrc.cjs" />
|
||||
<option name="fix-on-save" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/frontend.iml" filepath="$PROJECT_DIR$/.idea/frontend.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectTasksOptions" suppressed-tasks="Less" />
|
||||
</project>
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"Vue.volar"
|
||||
]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue