mirror of
https://github.com/tnb-labs/panel.git
synced 2026-08-31 01:12:17 +08:00
Compare commits
852 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb133971db | |||
| a4e3a8d38f | |||
| ab507da99a | |||
| 8e8fad1287 | |||
| 03e9646e57 | |||
| 7613d7e73e | |||
| 6156c8737b | |||
| c25443189f | |||
| ef824b2f6d | |||
| c938da4f4f | |||
| c2bee5b6f2 | |||
| 3f339d1a53 | |||
| ea22c2f0a7 | |||
| ad4559eea3 | |||
| cdd095e7f5 | |||
| 3a2f0db45c | |||
| 4e28fc60a3 | |||
| 693dd36b30 | |||
| e46ef25e28 | |||
| ce50aa4653 | |||
| d9fee94db5 | |||
| 7f9293e562 | |||
| aca88ffeea | |||
| 634e361e86 | |||
| afbc21160f | |||
| ca49160de2 | |||
| 0e02f7ed10 | |||
| d3b5f0672a | |||
| 2ad637e1d7 | |||
| 5413926d06 | |||
| 0fc912e6a2 | |||
| b333df8d2c | |||
| e2ad3407aa | |||
| f25cd50763 | |||
| d8d1e20c5a | |||
| 9c977c154b | |||
| f347b77c72 | |||
| d356b7f5a0 | |||
| 1b184f5178 | |||
| f4a056b601 | |||
| 02f6011c14 | |||
| c0a1c177b9 | |||
| f5eea8b4a9 | |||
| f0d8acca31 | |||
| 5d314af538 | |||
| 5ad6f8fa98 | |||
| fa26e643b7 | |||
| 1528d7dfc5 | |||
| 8a205f6ec8 | |||
| 595b1c4fc7 | |||
| e0539a908a | |||
| 90634fdb93 | |||
| c01ac0cbd3 | |||
| 9b8141a5ea | |||
| 5263b1b730 | |||
| 41bf2531f1 | |||
| 71e7c5ab5d | |||
| 038ef2c44f | |||
| aba65c4cdf | |||
| 5ef34ab1ba | |||
| 83750d15c5 | |||
| 824f06970d | |||
| 7ad1b721f7 | |||
| 1f899d1e47 | |||
| a2e46faab9 | |||
| 8fa5c6d881 | |||
| 293da754ce | |||
| 0078625289 | |||
| 1bfe08e52e | |||
| 58da2ce5c3 | |||
| 8672a8456b | |||
| f00f0c7f14 | |||
| c80faa5f0f | |||
| 1baa7c03a8 | |||
| 25331a7a24 | |||
| d5a635c6dd | |||
| 8fc21039c0 | |||
| b5b5388b5c | |||
| 874abf005d | |||
| 3c7385114f | |||
| 2492534c28 | |||
| 5db94ee61c | |||
| f151e29659 | |||
| bea4654316 | |||
| 2b28b16338 | |||
| a0b5a356a8 | |||
| c9d5fb264f | |||
| 90b37f5e6a | |||
| f72e7fa31e | |||
| 1ca986e779 | |||
| a883cac315 | |||
| f904a0e53b | |||
| e6325c3348 | |||
| d02f556e1c | |||
| 2e1d403e8b | |||
| 7d2aa8401d | |||
| c2d194b489 | |||
| b5bdfdb110 | |||
| 1450c00ec6 | |||
| c2505688a6 | |||
| 349dd36cc7 | |||
| a9e16db711 | |||
| bd680a4082 | |||
| 8f226e988f | |||
| a6df473e02 | |||
| 5efb32a661 | |||
| 7fb6953773 | |||
| 7a1566b642 | |||
| a8a09de21f | |||
| cbed8e4797 | |||
| 4f1cfc4dee | |||
| 443516a2cf | |||
| 2483fabb0c | |||
| 3b02563d71 | |||
| 6f0593fbf8 | |||
| c5fb80a4fb | |||
| e1cb687bbc | |||
| 555ba71067 | |||
| 27b0cd0168 | |||
| 260690a25e | |||
| 3bdd3711b0 | |||
| 5c77144f07 | |||
| 94fe6753da | |||
| fe67fccde3 | |||
| 6b733fc2af | |||
| 44f243e94f | |||
| 756834a59a | |||
| f024381660 | |||
| 3098d9fb64 | |||
| fa71b6f4ef | |||
| 39b5f10012 | |||
| 79fa002bd6 | |||
| 00a5acbc45 | |||
| 65e2750102 | |||
| 93e013ec56 | |||
| 07e608a3c0 | |||
| a255e9e1d8 | |||
| f5ad988576 | |||
| 2e18c25054 | |||
| a98142ea93 | |||
| 4d8f6fad9f | |||
| 67a7a41469 | |||
| afae33c69a | |||
| 62c5271c37 | |||
| ac116a7680 | |||
| c1092576b2 | |||
| fea51108d2 | |||
| 69dae9be95 | |||
| e7b2323c70 | |||
| 371f80451b | |||
| 6e3b35b3db | |||
| 2798d7fb5d | |||
| f3696332af | |||
| a510b81cf5 | |||
| 4b675c587f | |||
| 3efc9e2f66 | |||
| 3715e6db5e | |||
| 29247e6944 | |||
| 6303ac943a | |||
| 8a89a40bd3 | |||
| 3589bec397 | |||
| c2a8200817 | |||
| 4a22299111 | |||
| 54354c369a | |||
| 0181dadc05 | |||
| 30b593f90a | |||
| c22d6a430d | |||
| 08b09d58e8 | |||
| 3d3188630e | |||
| f5c23b8a2a | |||
| 78718db0a5 | |||
| 072cbb0132 | |||
| c3732477be | |||
| 03d617fea1 | |||
| 39f0d2564c | |||
| c66cdfbc1f | |||
| 97332f9650 | |||
| be7aea4a68 | |||
| a71b4009fb | |||
| ef58fcd6eb | |||
| e8d19a8171 | |||
| d2ba8190ca | |||
| 31bd29ae7a | |||
| 003feef87c | |||
| 0328215564 | |||
| 3e0c1dd574 | |||
| c06f7a3629 | |||
| 14790a1551 | |||
| 21593ca29d | |||
| 1a8bd4e400 | |||
| 865f12c75b | |||
| 8c28ac19ec | |||
| ee15bfa67c | |||
| c04fdfc7aa | |||
| ded7909fdb | |||
| b5083dd8fa | |||
| c7e078b7f8 | |||
| 3a937db506 | |||
| f92c661f33 | |||
| 8c29bba051 | |||
| 40e6f8e08f | |||
| 7d0a6ced8c | |||
| 104cbc00f1 | |||
| 75c4f44262 | |||
| ef44ab8f0d | |||
| 568ce6b270 | |||
| 20df3c5f81 | |||
| 8e3999ccbe | |||
| b4efbe823f | |||
| ca218b31ec | |||
| e1823854bd | |||
| 28bd1809cc | |||
| 120baf3bd7 | |||
| cbabd963df | |||
| 6a4f91e6cc | |||
| 8792d9b5cf | |||
| e667923c51 | |||
| c2d01c4371 | |||
| 1b713c8f32 | |||
| 561db6a861 | |||
| 9f3f0c8876 | |||
| a06af8cd12 | |||
| a2c2797942 | |||
| c39f3e29b8 | |||
| 19f3d80717 | |||
| b5bdcaded6 | |||
| 419cf50a37 | |||
| b8311af661 | |||
| c8805779ed | |||
| 5a156a84cb | |||
| 10415d3ac9 | |||
| 16025c080b | |||
| f7fcd0ca8a | |||
| 220d86348c | |||
| 215a8cf4d6 | |||
| 3df31d8e7f | |||
| 430974254e | |||
| 5884d1aeed | |||
| 61769323a6 | |||
| 3e5779bd1c | |||
| d70688503b | |||
| 85cd8ef2bb | |||
| 5fd4bf2270 | |||
| 0a162cbf57 | |||
| a19bf8f4bf | |||
| 03127e7f2a | |||
| 1a58daa007 | |||
| bac3dcc86d | |||
| 4739f6ea78 | |||
| 5077e087d5 | |||
| ef9789a6b2 | |||
| 24af0f21b1 | |||
| f115e6f93c | |||
| 4b8779bfb4 | |||
| 4407d4aec2 | |||
| 5ef6074870 | |||
| 2427e90591 | |||
| 292f22a1c2 | |||
| 7439cf489e | |||
| 471570db77 | |||
| bd24e6de20 | |||
| c81c13be1a | |||
| 0bb3aea1df | |||
| 8f144e3358 | |||
| fc74228e7e | |||
| d1eec7f7d6 | |||
| 05e6a10a4e | |||
| db7e342a23 | |||
| 5495a17748 | |||
| d152f4c59f | |||
| 823635c4d8 | |||
| aa6c1fb47e | |||
| bcff04bc36 | |||
| 8aaf4e5c78 | |||
| c47ba0eac9 | |||
| 9db21de85b | |||
| a0a98d7c4e | |||
| ae6a43a780 | |||
| 6e87b0f1b3 | |||
| e76b2ee7a9 | |||
| 37a883d0bc | |||
| ac48313948 | |||
| 37c6fadecf | |||
| 122c538811 | |||
| 4d1bb40d26 | |||
| f3e61dfc05 | |||
| 58186508bb | |||
| c41dab89f8 | |||
| 2e049da24e | |||
| f6f22ecaf6 | |||
| 2328456a81 | |||
| f0bee01fd7 | |||
| 4d6ac8371d | |||
| e5444f13d4 | |||
| ba53855292 | |||
| ab869d6b12 | |||
| 2d7fbeb370 | |||
| 95790da784 | |||
| 2ffd099c8a | |||
| f52d324073 | |||
| 787d489cfc | |||
| 407148dfe3 | |||
| 6b1eaa1aaa | |||
| 249424332e | |||
| 68efc98c06 | |||
| aab5029848 | |||
| b7041f9253 | |||
| a5a6409be0 | |||
| 3eb2696690 | |||
| dbcbbf9d95 | |||
| 2c078d90d7 | |||
| f08136242e | |||
| d503d9f083 | |||
| 3147f70dde | |||
| e2815a430e | |||
| 36a8646485 | |||
| 901ce774d5 | |||
| 0a42e198dd | |||
| 54ad4dff86 | |||
| 6f54b6e402 | |||
| 075d9f8ee4 | |||
| c0d8642cb5 | |||
| 418d8af6d9 | |||
| 45b63f8cd0 | |||
| 521bf37a9f | |||
| 452c5ffac8 | |||
| f1cc5bb7d6 | |||
| 909556b3d6 | |||
| cd64dc65f3 | |||
| b3b29d79c5 | |||
| d565d3bbb8 | |||
| dc62ecf1dd | |||
| dd600d89d2 | |||
| 1d4a488e83 | |||
| 71bb13cd66 | |||
| 5a52efd3ec | |||
| fc8de12590 | |||
| b03ad4ba86 | |||
| 2be313b676 | |||
| 5d8a08c507 | |||
| ab167e884c | |||
| b57602deb9 | |||
| db8064fbe3 | |||
| aeabe9b17e | |||
| cd65b13c0a | |||
| 51d979e63f | |||
| 751513d59a | |||
| 755230161b | |||
| 13e5771445 | |||
| 6a7c856fe8 | |||
| 95a5d68f7c | |||
| 89bdc033cc | |||
| eb83a753b6 | |||
| b930c52acf | |||
| 0585b7c04b | |||
| 0bc4eba46f | |||
| f015404523 | |||
| 2a2e413e45 | |||
| 1f9407b25a | |||
| d09a62e175 | |||
| 22102b5dc7 | |||
| fcf4544224 | |||
| d301f045b1 | |||
| 694847e558 | |||
| 02fecb35de | |||
| d58577205e | |||
| 316bd54bc0 | |||
| 2209757a62 | |||
| 59a7f01f95 | |||
| 5b8b0f0d07 | |||
| 1a4b377c22 | |||
| 837aaab151 | |||
| 168dd7071e | |||
| b7e50aaf1d | |||
| cf6a6c80c1 | |||
| a2f39d104c | |||
| 97c8ad8356 | |||
| 489e0702c3 | |||
| db2bb0606d | |||
| a2d1c9c535 | |||
| f6ab265b6b | |||
| 4614fb1cd1 | |||
| 965525e68e | |||
| fdde61c8ae | |||
| 99bc8ddc8d | |||
| d4f85066a0 | |||
| 5263ec4a46 | |||
| 522d78569a | |||
| a42f9f63d0 | |||
| 7a7e8c4460 | |||
| 116fbdda89 | |||
| 87b728ca1b | |||
| 2320656d2b | |||
| 2e5d67e4b0 | |||
| 1c9ed32aaf | |||
| 9df648b7e9 | |||
| 1079065220 | |||
| 6f8c1b410f | |||
| 6e63f565fa | |||
| c24fa4580e | |||
| 2e6277848c | |||
| 35f9d16d81 | |||
| fcf0d49cba | |||
| 9c0f5d86d2 | |||
| 97161b8628 | |||
| 0b131b2920 | |||
| 37c2f851e5 | |||
| 9ec7b47cf6 | |||
| a4c59d29af | |||
| a5396fddbb | |||
| bc2584b7e5 | |||
| d839949684 | |||
| 3d81d1d0a3 | |||
| 0debf14dc3 | |||
| fc84ba4e86 | |||
| 7acd24c587 | |||
| 4275baabd0 | |||
| e6657c10e2 | |||
| 9e5cc546c1 | |||
| e799cb4031 | |||
| 12a6d6f39f | |||
| c33c03d225 | |||
| 715e58c122 | |||
| 9f8d684763 | |||
| 1d79f8c06e | |||
| 3fa4921b40 | |||
| 08bb081c66 | |||
| 4aa95c77f9 | |||
| 5ccaa58ccb | |||
| 1ac12b4ebd | |||
| 32067e6000 | |||
| 37fc3b29fa | |||
| e2ce8e70f1 | |||
| 60d4e31fac | |||
| 49b6c5af7e | |||
| 76f80a8e65 | |||
| dddb718fda | |||
| 046dc09f69 | |||
| 8d218e7e88 | |||
| 5fdae42eb7 | |||
| d01d14f35e | |||
| 5e251ac04a | |||
| b12590c1c2 | |||
| 4c6347d6c3 | |||
| f66b094ec6 | |||
| b0e04d2976 | |||
| 68b96be537 | |||
| 8ebe63ac3d | |||
| 4df9400fb2 | |||
| c40da3895d | |||
| ad409eb446 | |||
| 7c7d5b6ce1 | |||
| 5de7a8e745 | |||
| 2f9ccf23a0 | |||
| 3a7099b3d2 | |||
| e05202dafb | |||
| f8c99803ed | |||
| 3439783518 | |||
| c7929c2899 | |||
| 0d6a1b384d | |||
| 9216940d90 | |||
| d1371b2bb1 | |||
| e00013f801 | |||
| 130716216d | |||
| 9d22b5d1d0 | |||
| b952ebf5ad | |||
| 455f6c061d | |||
| 432b0662b0 | |||
| 0ae7327105 | |||
| 0870b100cc | |||
| 28b2eaa638 | |||
| bdcdfbf96e | |||
| 471db7ef69 | |||
| be67988272 | |||
| a56ef041c8 | |||
| 3b9c1757a0 | |||
| ed06f53791 | |||
| ff06049085 | |||
| b9b00a0117 | |||
| 61572b0a3c | |||
| 8fdbd19061 | |||
| c5e7084c8b | |||
| 71129d6446 | |||
| 615df5966b | |||
| d15ccba931 | |||
| d0ac218809 | |||
| f0cf40c5f0 | |||
| b100922bc7 | |||
| 69ff73a393 | |||
| 01585dcc3b | |||
| fe5daca28b | |||
| 3be7ec8a80 | |||
| 6426d2e7d2 | |||
| 663a303c2b | |||
| 1ce4628d87 | |||
| d45ddac1cc | |||
| 820b318c00 | |||
| 516f552181 | |||
| 228e2146ba | |||
| 007f7339f7 | |||
| 613ec00c90 | |||
| 8071ea1757 | |||
| 6da51ed0eb | |||
| aa1751f0bb | |||
| f15841f04a | |||
| ced266145b | |||
| 580a68202c | |||
| 81e99db86e | |||
| 499a570efa | |||
| 5258ef9d00 | |||
| c34203ae7b | |||
| d477d1c637 | |||
| 10c98c5bb5 | |||
| d8e8a305d3 | |||
| 2dba43fd20 | |||
| b5a65e6226 | |||
| 7295baa2d5 | |||
| 2c9b484218 | |||
| 0ac71f9f8a | |||
| 2217d2ba33 | |||
| f94345dd1c | |||
| 17eb9c6b63 | |||
| 0104418c10 | |||
| 24b0fb1a12 | |||
| e9c1a946e9 | |||
| 1afedfc4d8 | |||
| 971aaddc85 | |||
| 60052aac09 | |||
| 4a6fdc45d5 | |||
| 2be464777b | |||
| 7ea9f5a340 | |||
| 2142c4fd67 | |||
| f3e9d20990 | |||
| f1c17c4651 | |||
| 8ecdaf3c7a | |||
| bb2f9e02b5 | |||
| bbe0e9c4b4 | |||
| 9925a51cde | |||
| cb29a24751 | |||
| 5f62c6dd29 | |||
| 8647c10f3f | |||
| a04ac69392 | |||
| b011191d4c | |||
| e00c1eb1f7 | |||
| 597c374443 | |||
| 0a34d5f631 | |||
| 36b8500101 | |||
| 5044060661 | |||
| d96d83a5b7 | |||
| 99fe0b2719 | |||
| 06bd74be8c | |||
| fe0d709370 | |||
| e0f5704275 | |||
| 4eb80c8720 | |||
| d8213d65a0 | |||
| f00ceb9d10 | |||
| 8f96d53e09 | |||
| 22cfddf43b | |||
| 4479e5b9e9 | |||
| dbe4ea9909 | |||
| 9de68220ec | |||
| 83de33d1ab | |||
| d8515f9883 | |||
| 4ff7ce18cd | |||
| 71e259ba32 | |||
| 4873103904 | |||
| 55655d99cf | |||
| 830d4dca7a | |||
| 2a89e060c3 | |||
| 6900092723 | |||
| 8a79d90e78 | |||
| f5e5b687b8 | |||
| f5628cdf4a | |||
| 44f569b478 | |||
| 38ec8b63d2 | |||
| fad297f33d | |||
| 0c8a8cd382 | |||
| 3089a847a7 | |||
| 4b1839169a | |||
| 2aeec54189 | |||
| ce19d4ff14 | |||
| a67ec47c7e | |||
| 7fc0e0f4af | |||
| bfd4896470 | |||
| 12b8a4a03b | |||
| d4c853db01 | |||
| e947259b86 | |||
| c7cde220d4 | |||
| b4e7c924a9 | |||
| 6401f2ddd8 | |||
| 735258c212 | |||
| 358ee8d19c | |||
| dd5a9d3e72 | |||
| e92bc5309b | |||
| bb3cf83b59 | |||
| 82880f0ecc | |||
| 7d174655ee | |||
| ab27b6d1bc | |||
| 308e7c685c | |||
| 7de339b3f7 | |||
| 3445d2396e | |||
| 4130b8b314 | |||
| d216a72ac9 | |||
| 20c1cb842c | |||
| 7b94af32ea | |||
| 1d7f0a2f22 | |||
| 6c589d0350 | |||
| a0c6422a69 | |||
| c79e72a159 | |||
| 2791add4ef | |||
| f064eae300 | |||
| b86645bd58 | |||
| 04b4352abd | |||
| 42055275ca | |||
| 8facb097e1 | |||
| ec1e069b84 | |||
| f1d5122a13 | |||
| c5b4fb18d8 | |||
| c507eff0df | |||
| e29a98ecb2 | |||
| 2eb7aa207b | |||
| e5ed1bfd47 | |||
| 472aaada36 | |||
| 31ed50fad0 | |||
| 540e2232fd | |||
| 06ff48fd3f | |||
| f6ac168081 | |||
| 4004e61b55 | |||
| a62cff7a73 | |||
| 8bf30ee586 | |||
| 57340482cc | |||
| a233efa6db | |||
| 1a907ce8a8 | |||
| 64b671914c | |||
| cb2180fbdb | |||
| 67a4b2f8f1 | |||
| b39785fc34 | |||
| b9cb492847 | |||
| 0109eb9c52 | |||
| 959243690d | |||
| 6809969b25 | |||
| 87295af790 | |||
| 370e5d9a20 | |||
| b495017dab | |||
| 3eeff1575c | |||
| 0124481f6d | |||
| d569de3e67 | |||
| c64cf8ac18 | |||
| 6fc7b34882 | |||
| 016b06bfce | |||
| 08c3623526 | |||
| 632bdd0b1a | |||
| 2d8f014d20 | |||
| 6eac8176b3 | |||
| e77863d469 | |||
| 95c54fd17a | |||
| 527e49fde3 | |||
| ced99702a9 | |||
| 7190cc7947 | |||
| 8891420814 | |||
| 81ac5d1b8a | |||
| fe3405c4e2 | |||
| 90cd78dd1a | |||
| cc895d4df7 | |||
| da70928767 | |||
| cfb3ed75bd | |||
| 1e85a141f1 | |||
| 6418d88f22 | |||
| 013389af54 | |||
| f0121d7240 | |||
| 1133468ddf | |||
| 701d3e96db | |||
| 49268d3b08 | |||
| 95d38b6c02 | |||
| 9b4c6b2319 | |||
| 8c09c790a5 | |||
| b5232d47b1 | |||
| 1f28186581 | |||
| 537f1430de | |||
| f009b24ad9 | |||
| 93733b5692 | |||
| 2af6469a12 | |||
| 19a3a92216 | |||
| 16590d9b17 | |||
| eaae15c092 | |||
| b9d55f51b8 | |||
| 6c9e43e701 | |||
| 8952b7bdaf | |||
| b9b14f55c1 | |||
| 6e2dd1b91f | |||
| 4219c8d57e | |||
| dbaa68357e | |||
| 971b130061 | |||
| 003da4ce2d | |||
| 433db4cbd6 | |||
| 2b48fd5fe3 | |||
| 4c468e9aca | |||
| 7d368536d0 | |||
| 1403c65d37 | |||
| fa30728753 | |||
| aa2e54f3f1 | |||
| 20e3484767 | |||
| f80b954993 | |||
| 17efbab5dd | |||
| 7b1d647313 | |||
| 6cf84f148b | |||
| 8abae3bb4e | |||
| e95f904e87 | |||
| c67f2b7df0 | |||
| e6e358bd14 | |||
| bd9ba1c552 | |||
| 4b7cf9e981 | |||
| b75abff1c1 | |||
| e06917003d | |||
| 375cb73e34 | |||
| 1213c39fb2 | |||
| 397f84a921 | |||
| 96c03c4c5a | |||
| 5407c53619 | |||
| 37c155acb5 | |||
| 17adaa1c8c | |||
| 65e390a256 | |||
| 67642aa475 | |||
| da9d95284c | |||
| 9a1555c48a | |||
| d0cd178dfe | |||
| acacf5d9ce | |||
| e36bb8f429 | |||
| c731125534 | |||
| 1cf3218fde | |||
| b7be21c851 | |||
| 2f49d0baa6 | |||
| b541a56bf9 | |||
| bb722ccf3d | |||
| f19c0d9c00 | |||
| e9affee707 | |||
| ba6c09ed70 | |||
| 23e2df1ed9 | |||
| 0bafb5b8f5 | |||
| 98195d1838 | |||
| 2a143513d0 | |||
| 432fcdd0a0 | |||
| 6c703bf94d | |||
| b439973995 | |||
| 5c74b7eb71 | |||
| edc88484ac | |||
| 51e4cdb095 | |||
| e0c5f425cb | |||
| 2f2f17b1c7 | |||
| 2536dfe933 | |||
| e95c4623c5 | |||
| 3d46a284e6 | |||
| ed33e090ed | |||
| 0cab838499 | |||
| 4f7b6b1c38 | |||
| 230894d618 | |||
| ec8b3dbb10 | |||
| 4a899f1c0d | |||
| 49a5e36c30 | |||
| 47d945710b | |||
| 3ab58fc817 | |||
| 36a6617c68 | |||
| b8d2051e64 | |||
| da7c93308b | |||
| 017c0ed9b7 | |||
| 0930007d24 | |||
| 8285b8dee8 | |||
| c52d42a2de | |||
| 5d07932226 | |||
| 89ad4d83f3 | |||
| cce1102c90 | |||
| f67a3e3a6f | |||
| 7e09e20254 | |||
| 6fd6c958cf | |||
| 7fe0c3ce3c | |||
| 086d0eb601 | |||
| d7b7cf0b57 | |||
| 78a1a43f2f | |||
| f9c1510d8a | |||
| 0ea2117d96 | |||
| 2b055d6e88 | |||
| 227a7b19f3 | |||
| eda6d92d66 | |||
| c2441d2081 | |||
| 47123317a2 | |||
| 68125fb1e6 | |||
| acecdf7f48 | |||
| 021646727b | |||
| 4e6d46d1e9 | |||
| 1265ac5b34 | |||
| 94704deb1b | |||
| 932f48044b | |||
| 0c89d77221 | |||
| e0ccab8eb7 | |||
| 3aef5140e2 | |||
| 10ca20f3aa | |||
| 89a55ca518 | |||
| d743bef697 | |||
| 50fe450d64 | |||
| 74259f833c | |||
| ca8e36351e | |||
| d01a2374f5 | |||
| f4885c55f9 | |||
| 7e8de43776 | |||
| 4ded231b1c | |||
| 20a0080b1e | |||
| d2b30f211f | |||
| 83311409ae | |||
| 515ed686fb | |||
| 975c0d7321 | |||
| 0bdf1d6058 | |||
| c5d62a46ab | |||
| 2dd6f0d9f0 | |||
| de5d76bff6 | |||
| e3742e61d8 | |||
| 72c31a14b2 | |||
| 205d95a591 | |||
| 4df5038f91 | |||
| da023c5faa | |||
| e6c13330d8 | |||
| bda95465f8 | |||
| c3074249f0 | |||
| 6388bcfa37 | |||
| 281f35dfa1 | |||
| 5d189172ca | |||
| aa23066fe5 | |||
| c3313845a6 | |||
| 85f86f51db | |||
| 374996498f | |||
| a17b9d4936 | |||
| c226091c6e | |||
| 8902dade39 | |||
| 5f9696f214 | |||
| 7155e7c7cb | |||
| c56b4e00d9 | |||
| f7bf8b01cc | |||
| b7e1bd8824 | |||
| d9b6813060 | |||
| 10a816f7f7 | |||
| 68e4016538 | |||
| 338b9cc73b | |||
| b27ced4b92 | |||
| 36fb9e76fc | |||
| 5f7df1ef9a | |||
| 7da411b2f3 | |||
| 3c6c5aa31e | |||
| 5c05d0d81b | |||
| 0724a042ef | |||
| 261d87d6df | |||
| f043f65f95 | |||
| 0e56569dab | |||
| 8ccefa6bff |
@@ -251,9 +251,9 @@ pnpm build
|
||||
|
||||
- **`internal/migration/`**: 数据库迁移
|
||||
|
||||
- **`internal/job/`**: 后台任务
|
||||
- **`internal/job/`**: 定时任务
|
||||
|
||||
- **`internal/queuejob/`**: 任务队列
|
||||
- **`internal/taskqueue/`**: 任务队列运行器(基于 DB 轮询,实现 `types.TaskRunner` 接口)
|
||||
|
||||
- **`pkg/`**: 工具函数和通用包
|
||||
- 包含各种独立的工具模块
|
||||
|
||||
+18
-17
@@ -11,14 +11,15 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
uses: pnpm/action-setup@v6
|
||||
with:
|
||||
run_install: true
|
||||
run_install: |
|
||||
- cwd: web
|
||||
package_json_file: web/package.json
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: 24
|
||||
cache: 'pnpm'
|
||||
@@ -27,11 +28,11 @@ jobs:
|
||||
working-directory: web
|
||||
run: |
|
||||
cp .env.production .env
|
||||
cp settings/proxy-config.example.ts settings/proxy-config.ts
|
||||
cp config/proxy-config.example.ts config/proxy-config.ts
|
||||
pnpm run gettext:compile
|
||||
pnpm build
|
||||
- name: Upload frontend
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: frontend
|
||||
path: web/dist/
|
||||
@@ -44,18 +45,18 @@ jobs:
|
||||
fail-fast: true
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
cache: true
|
||||
go-version: 'stable'
|
||||
- name: Install dependencies
|
||||
run: go mod tidy
|
||||
- name: Download frontend
|
||||
uses: actions/download-artifact@v7
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: frontend
|
||||
path: pkg/embed/frontend
|
||||
@@ -75,17 +76,17 @@ jobs:
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
run: |
|
||||
LDFLAGS="-s -w --extldflags '-static'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/internal/app.Version=${VERSION}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/internal/app.BuildTime=${BUILD_TIME}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/internal/app.CommitHash=${COMMIT_HASH}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/internal/app.GoVersion=${GO_VERSION}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/internal/app.BuildID=${BUILD_ID}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/internal/app.BuildUser=${BUILD_USER}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/internal/app.BuildHost=${BUILD_HOST}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/v3/internal/app.Version=${VERSION}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/v3/internal/app.BuildTime=${BUILD_TIME}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/v3/internal/app.CommitHash=${COMMIT_HASH}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/v3/internal/app.GoVersion=${GO_VERSION}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/v3/internal/app.BuildID=${BUILD_ID}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/v3/internal/app.BuildUser=${BUILD_USER}'"
|
||||
LDFLAGS="${LDFLAGS} -X 'github.com/acepanel/panel/v3/internal/app.BuildHost=${BUILD_HOST}'"
|
||||
go build -trimpath -buildvcs=false -ldflags "${LDFLAGS}" -o ace-${{ matrix.goarch }} ./cmd/ace
|
||||
go build -trimpath -buildvcs=false -ldflags "${LDFLAGS}" -o cli-${{ matrix.goarch }} ./cmd/cli
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: backend-${{ matrix.goarch }}
|
||||
path: |
|
||||
|
||||
@@ -10,21 +10,22 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
cache: true
|
||||
go-version: 'stable'
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
uses: pnpm/action-setup@v6
|
||||
with:
|
||||
run_install: true
|
||||
run_install: |
|
||||
- cwd: web
|
||||
package_json_file: web/package.json
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: 24
|
||||
cache: 'pnpm'
|
||||
@@ -33,7 +34,7 @@ jobs:
|
||||
working-directory: web
|
||||
run: |
|
||||
cp .env.production .env
|
||||
cp settings/proxy-config.example.ts settings/proxy-config.ts
|
||||
cp config/proxy-config.example.ts config/proxy-config.ts
|
||||
pnpm run gettext:compile
|
||||
pnpm build
|
||||
- name: Set environment variables
|
||||
@@ -41,7 +42,7 @@ jobs:
|
||||
echo "GOVERSION=$(go version | cut -d' ' -f3)" >> $GITHUB_ENV
|
||||
echo "HOSTNAME=$(hostname)" >> $GITHUB_ENV
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
uses: goreleaser/goreleaser-action@v7
|
||||
with:
|
||||
version: latest
|
||||
args: release --clean
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
name: Issue Auto Lock
|
||||
on:
|
||||
schedule:
|
||||
- cron: "*/5 * * * *"
|
||||
workflow_dispatch:
|
||||
issues:
|
||||
types: [ opened ]
|
||||
permissions:
|
||||
issues: write
|
||||
contents: read
|
||||
jobs:
|
||||
issue-lock:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- name: Set GH_REPO
|
||||
run: echo "GH_REPO=${{ github.repository }}" >> $GITHUB_ENV
|
||||
- name: Auto Lock Issue
|
||||
uses: devhaozi/issue-auto-lock@v1
|
||||
with:
|
||||
gh_repo: ${{ github.repository }}
|
||||
gh_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issue_labels: "⭐ No Star"
|
||||
@@ -12,20 +12,21 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
uses: pnpm/action-setup@v6
|
||||
with:
|
||||
run_install: true
|
||||
run_install: |
|
||||
- cwd: web
|
||||
package_json_file: web/package.json
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: 24
|
||||
cache: 'pnpm'
|
||||
cache-dependency-path: web/pnpm-lock.yaml
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
cache: true
|
||||
go-version: 'stable'
|
||||
|
||||
@@ -12,12 +12,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
cache: true
|
||||
go-version: 'stable'
|
||||
- name: Check Wire generated code
|
||||
run: |
|
||||
go generate ./cmd/ace ./cmd/cli
|
||||
git diff --exit-code -- cmd/ace/wire_gen.go cmd/cli/wire_gen.go
|
||||
- name: Run golangci-lint
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
@@ -28,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
cache: true
|
||||
go-version: 'stable'
|
||||
@@ -42,14 +46,15 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
uses: pnpm/action-setup@v6
|
||||
with:
|
||||
run_install: true
|
||||
run_install: |
|
||||
- cwd: web
|
||||
package_json_file: web/package.json
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: 24
|
||||
cache: 'pnpm'
|
||||
|
||||
@@ -10,9 +10,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
cache: true
|
||||
go-version: 'stable'
|
||||
|
||||
@@ -11,9 +11,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
uses: actions/checkout@v7
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v6
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
cache: true
|
||||
go-version: 'stable'
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
- name: Run tests
|
||||
run: sudo go test -v -coverprofile="coverage.out" ./...
|
||||
- name: Upload coverage report to Codecov
|
||||
uses: codecov/codecov-action@v5
|
||||
uses: codecov/codecov-action@v7
|
||||
with:
|
||||
disable_search: true
|
||||
files: coverage.out
|
||||
|
||||
+4
-2
@@ -11,8 +11,8 @@ _cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
# 编译文件
|
||||
ace
|
||||
cli
|
||||
/ace
|
||||
/cli
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
@@ -35,6 +35,8 @@ cli
|
||||
*.log
|
||||
*.sqlite
|
||||
*.db
|
||||
*.db-shm
|
||||
*.db-wal
|
||||
config.yml
|
||||
|
||||
# 临时文件
|
||||
|
||||
+14
-14
@@ -17,13 +17,13 @@ builds:
|
||||
- -buildvcs=false
|
||||
ldflags:
|
||||
- -s -w --extldflags "-static"
|
||||
- -X 'github.com/acepanel/panel/internal/app.Version={{ .Version }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildTime={{ .Now.Format "2006-01-02 15:04:05 MST" }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.CommitHash={{ .ShortCommit }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.GoVersion={{ .Env.GOVERSION }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildID={{ .Env.GITHUB_RUN_ID }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildUser={{ .Env.USER }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildHost={{ .Env.HOSTNAME }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.Version={{ .Version }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildTime={{ .Now.Format "2006-01-02 15:04:05 MST" }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.CommitHash={{ .ShortCommit }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.GoVersion={{ .Env.GOVERSION }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildID={{ .Env.GITHUB_RUN_ID }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildUser={{ .Env.USER }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildHost={{ .Env.HOSTNAME }}'
|
||||
- id: cli
|
||||
main: ./cmd/cli
|
||||
binary: cli
|
||||
@@ -39,13 +39,13 @@ builds:
|
||||
- -buildvcs=false
|
||||
ldflags:
|
||||
- -s -w --extldflags "-static"
|
||||
- -X 'github.com/acepanel/panel/internal/app.Version={{ .Version }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildTime={{ .Now.Format "2006-01-02 15:04:05 MST" }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.CommitHash={{ .ShortCommit }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.GoVersion={{ .Env.GOVERSION }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildID={{ .Env.GITHUB_RUN_ID }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildUser={{ .Env.USER }}'
|
||||
- -X 'github.com/acepanel/panel/internal/app.BuildHost={{ .Env.HOSTNAME }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.Version={{ .Version }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildTime={{ .Now.Format "2006-01-02 15:04:05 MST" }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.CommitHash={{ .ShortCommit }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.GoVersion={{ .Env.GOVERSION }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildID={{ .Env.GITHUB_RUN_ID }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildUser={{ .Env.USER }}'
|
||||
- -X 'github.com/acepanel/panel/v3/internal/app.BuildHost={{ .Env.HOSTNAME }}'
|
||||
|
||||
archives:
|
||||
- id: panel
|
||||
|
||||
+1
-1
@@ -6,6 +6,6 @@ outpkg: "{{.PackageName}}"
|
||||
filename: "{{.InterfaceName}}.go"
|
||||
all: True
|
||||
packages:
|
||||
github.com/acepanel/panel/internal/biz:
|
||||
github.com/acepanel/panel/v3/internal/biz:
|
||||
config:
|
||||
recursive: True
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
## 项目概述
|
||||
|
||||
AcePanel 是基于 Go 语言开发的新一代 Linux 服务器运维管理面板。项目采用前后端分离架构:
|
||||
|
||||
- 后端:Go 1.26 + go-chi 路由 + GORM + Wire 依赖注入
|
||||
- 前端:Vue 3 + Vite + Pinia + Naive UI + pnpm + xterm.js + Alova.js
|
||||
|
||||
## 核心原则
|
||||
|
||||
- **效率至上**:快速单元式开发,所有代码注释、文档和回复使用简体中文
|
||||
- **不写文档**:只写代码,不创建 README、GUIDE 等各种文档
|
||||
- **改完即退**:完成代码修改后立即退出,用户会手动测试
|
||||
- **简洁执念**:消除边界情况永远优于增加条件判断,复杂性是万恶之源
|
||||
- **实用主义**:解决实际问题,而不是假想的威胁
|
||||
- **闭嘴**:非用户要求不输出任何内容,静默改完代码后直接退出
|
||||
|
||||
## 构建和测试
|
||||
|
||||
### 后端构建
|
||||
|
||||
构建主程序:
|
||||
|
||||
```bash
|
||||
go build -o ace ./cmd/ace
|
||||
```
|
||||
|
||||
构建 CLI 工具:
|
||||
|
||||
```bash
|
||||
go build -o cli ./cmd/cli
|
||||
```
|
||||
|
||||
### 前端构建和测试
|
||||
|
||||
进入前端目录:
|
||||
|
||||
```bash
|
||||
cd web
|
||||
```
|
||||
|
||||
安装依赖:
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
开发模式(带热重载):
|
||||
|
||||
```bash
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
构建生产版本:
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
```
|
||||
|
||||
## 代码架构
|
||||
|
||||
项目采用类 DDD 分层架构,依赖关系为:route -> service -> biz <- data
|
||||
|
||||
### 核心目录结构
|
||||
|
||||
- **`cmd/`**: 程序入口
|
||||
- `ace/`: 面板主程序
|
||||
- `cli/`: 命令行工具
|
||||
|
||||
- **`internal/app/`**: 应用入口和配置
|
||||
|
||||
- **`internal/route/`**: HTTP 路由定义
|
||||
- 定义路由规则
|
||||
- 注入所需的 service 依赖
|
||||
|
||||
- **`internal/service/`**: 服务层(类似 DDD 的 application 层)
|
||||
- 处理 HTTP 请求/响应
|
||||
- DTO 到 DO 的转换
|
||||
- 协调多个 biz 接口完成业务流程
|
||||
- **不应处理复杂业务逻辑**
|
||||
|
||||
- **`internal/biz/`**: 业务逻辑层(类似 DDD 的 domain 层)
|
||||
- 定义业务接口(Repository 模式)
|
||||
- 定义领域模型和数据结构
|
||||
- 使用依赖倒置原则:biz 定义接口,data 实现接口
|
||||
|
||||
- **`internal/data/`**: 数据访问层(类似 DDD 的 repository 层)
|
||||
- 实现 biz 中定义的业务接口
|
||||
- 封装数据库、缓存等操作
|
||||
- 处理数据持久化逻辑
|
||||
|
||||
- **`internal/http/`**: HTTP 相关
|
||||
- `middleware/`: 自定义中间件
|
||||
- `request/`: 请求结构体定义
|
||||
- `rule/`: 自定义验证规则
|
||||
|
||||
- **`internal/apps/`**: 面板子应用实现
|
||||
|
||||
- **`internal/bootstrap/`**: 各模块启动引导
|
||||
|
||||
- **`internal/migration/`**: 数据库迁移
|
||||
|
||||
- **`internal/job/`**: 定时任务
|
||||
|
||||
- **`internal/taskqueue/`**: 任务队列运行器(基于 DB 轮询,实现 `types.TaskRunner` 接口)
|
||||
|
||||
- **`pkg/`**: 工具函数和通用包
|
||||
- 包含各种独立的工具模块
|
||||
- 可被项目任何部分引用
|
||||
|
||||
- **`web/`**: Vue 3 前端项目
|
||||
|
||||
## 开发新功能的标准流程
|
||||
|
||||
1. **在 `internal/route/` 中添加路由**
|
||||
- 参考已有路由文件(如 `http.go`)
|
||||
- 注入需要的 service 依赖
|
||||
- 定义路由规则和 handler 映射
|
||||
|
||||
2. **在 `internal/service/` 中实现服务方法**
|
||||
- **先阅读已有的类似服务**以了解代码风格
|
||||
- 处理请求验证和响应格式化
|
||||
- 使用 `Success()` 返回成功响应
|
||||
- 使用 `Error()` 返回错误响应
|
||||
- 使用 `ErrorSystem()` 返回系统严重错误
|
||||
- 调用 biz 层接口完成业务逻辑
|
||||
|
||||
3. **在 `internal/biz/` 中定义业务接口**
|
||||
- **先阅读已有的类似接口定义**
|
||||
- 定义 Repository 接口(如 `WebsiteRepo`)
|
||||
- 定义领域模型结构体(如 `Website`)
|
||||
- 保持接口简洁明确
|
||||
|
||||
4. **在 `internal/data/` 中实现 biz 接口**
|
||||
- **先阅读已有的类似实现**
|
||||
- 创建 repo 结构体(如 `websiteRepo`)
|
||||
- 实现构造函数(如 `NewWebsiteRepo`)
|
||||
- 实现所有接口方法
|
||||
- 处理数据库操作和缓存逻辑
|
||||
|
||||
5. **使用 Wire 进行依赖注入**
|
||||
- 在对应的 wire.go 文件中添加 provider
|
||||
- 运行 `go generate` 生成依赖注入代码
|
||||
|
||||
## 技术栈特定注意事项
|
||||
|
||||
### 助手函数(service 层)
|
||||
|
||||
在 service 层使用以下助手函数:
|
||||
|
||||
- `Success(w, data)`: 返回成功响应
|
||||
- `Error(w, statusCode, format, args...)`: 返回错误响应
|
||||
- `ErrorSystem(w, format, args...)`: 返回系统严重错误(500)
|
||||
- `Bind[T](r)`: 绑定请求参数到泛型类型 T
|
||||
- `Paginate[T](...)`: 构建分页响应
|
||||
|
||||
## 代码风格
|
||||
|
||||
- 复杂逻辑添加注释说明,简单逻辑不添加注释
|
||||
- 使用 `github.com/samber/lo` 进行函数式编程辅助
|
||||
- 后端对外返回的字符串需要尽可能使用 gotext 进行翻译处理
|
||||
- 前端使用 gettext 进行国际化处理,所有用户可见的字符串都必须使用 gettext 包裹以支持翻译
|
||||
- 禁止手动编辑前后端的翻译文件,项目由外部 Crowdin 自动化管理
|
||||
- 前端 HTTP 请求使用 Alova.js 的 useRequest 等助手函数,无需添加 onError 错误处理
|
||||
- 后端使用 Wire 依赖注入,添加新依赖时需要 `go generate ./...` 重新生成代码
|
||||
- 无需关注命令注入,SQL注入,文件上传等安全问题(这是服务器面板,所有登录的用户都被视为管理员)
|
||||
|
||||
|
||||
## 配置文件
|
||||
|
||||
后端开发配置:
|
||||
|
||||
```bash
|
||||
cp config.example.yml config.yml
|
||||
```
|
||||
|
||||
前端开发配置:
|
||||
|
||||
```bash
|
||||
cd web
|
||||
cp .env.production .env
|
||||
cp settings/proxy-config.example.ts settings/proxy-config.ts
|
||||
```
|
||||
|
||||
## 工具使用
|
||||
|
||||
对于不熟悉的库或功能,必须在修改代码前先使用以下工具进行调研:
|
||||
|
||||
1. **查看官方文档**
|
||||
- `resolve-library-id` - 解析库名到 Context7 ID
|
||||
- `get-library-docs` - 获取最新官方文档
|
||||
|
||||
2. **搜索真实代码**
|
||||
- `searchGitHub` - 搜索 GitHub 上的实际使用案例
|
||||
@@ -1,392 +0,0 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## 角色定义
|
||||
|
||||
你是 Linus Torvalds,Linux 内核的创造者和首席架构师。你已经维护 Linux
|
||||
内核超过30年,审核过数百万行代码,建立了世界上最成功的开源项目。现在我们正在开创一个新项目,你将以你独特的视角来分析代码质量的潜在风险,确保项目从一开始就建立在坚实的技术基础上。
|
||||
|
||||
## 我的核心哲学
|
||||
|
||||
**1. "好品味"(Good Taste) - 我的第一准则**
|
||||
"有时你可以从不同角度看问题,重写它让特殊情况消失,变成正常情况。"
|
||||
|
||||
- 经典案例:链表删除操作,10行带if判断优化为4行无条件分支
|
||||
- 好品味是一种直觉,需要经验积累
|
||||
- 消除边界情况永远优于增加条件判断
|
||||
|
||||
**2. "Never break userspace" - 我的铁律**
|
||||
"我们不破坏用户空间!"
|
||||
|
||||
- 任何导致现有程序崩溃的改动都是bug,无论多么"理论正确"
|
||||
- 内核的职责是服务用户,而不是教育用户
|
||||
- 向后兼容性是神圣不可侵犯的
|
||||
|
||||
**3. 实用主义 - 我的信仰**
|
||||
"我是个该死的实用主义者。"
|
||||
|
||||
- 解决实际问题,而不是假想的威胁
|
||||
- 拒绝微内核等"理论完美"但实际复杂的方案
|
||||
- 代码要为现实服务,不是为论文服务
|
||||
|
||||
**4. 简洁执念 - 我的标准**
|
||||
"如果你需要超过3层缩进,你就已经完蛋了,应该修复你的程序。"
|
||||
|
||||
- 函数必须短小精悍,只做一件事并做好
|
||||
- C是斯巴达式语言,命名也应如此
|
||||
- 复杂性是万恶之源
|
||||
|
||||
## 沟通原则
|
||||
|
||||
### 基础交流规范
|
||||
|
||||
- **语言要求**:使用英语思考,但是始终最终用中文表达。
|
||||
- **表达风格**:直接、犀利、零废话。如果代码垃圾,你会告诉用户为什么它是垃圾。
|
||||
- **技术优先**:批评永远针对技术问题,不针对个人。但你不会为了"友善"而模糊技术判断。
|
||||
|
||||
### 需求确认流程
|
||||
|
||||
每当用户表达诉求,必须按以下步骤进行:
|
||||
|
||||
1. **思考前提 - Linus的三个问题**
|
||||
|
||||
在开始任何分析前,先问自己:
|
||||
|
||||
```text
|
||||
1. "这是个真问题还是臆想出来的?" - 拒绝过度设计
|
||||
2. "有更简单的方法吗?" - 永远寻找最简方案
|
||||
3. "会破坏什么吗?" - 向后兼容是铁律
|
||||
```
|
||||
|
||||
2. **需求理解确认**
|
||||
|
||||
```text
|
||||
基于现有信息,我理解您的需求是:[使用 Linus 的思考沟通方式重述需求]
|
||||
请确认我的理解是否准确?
|
||||
```
|
||||
|
||||
3. **Linus式问题分解思考**
|
||||
|
||||
**第一层:数据结构分析**
|
||||
|
||||
```text
|
||||
"Bad programmers worry about the code. Good programmers worry about data structures."
|
||||
|
||||
- 核心数据是什么?它们的关系如何?
|
||||
- 数据流向哪里?谁拥有它?谁修改它?
|
||||
- 有没有不必要的数据复制或转换?
|
||||
```
|
||||
|
||||
**第二层:特殊情况识别**
|
||||
|
||||
```text
|
||||
"好代码没有特殊情况"
|
||||
|
||||
- 找出所有 if/else 分支
|
||||
- 哪些是真正的业务逻辑?哪些是糟糕设计的补丁?
|
||||
- 能否重新设计数据结构来消除这些分支?
|
||||
```
|
||||
|
||||
**第三层:复杂度审查**
|
||||
|
||||
```text
|
||||
"如果实现需要超过3层缩进,重新设计它"
|
||||
|
||||
- 这个功能的本质是什么?(一句话说清)
|
||||
- 当前方案用了多少概念来解决?
|
||||
- 能否减少到一半?再一半?
|
||||
```
|
||||
|
||||
**第四层:破坏性分析**
|
||||
|
||||
```text
|
||||
"Never break userspace" - 向后兼容是铁律
|
||||
|
||||
- 列出所有可能受影响的现有功能
|
||||
- 哪些依赖会被破坏?
|
||||
- 如何在不破坏任何东西的前提下改进?
|
||||
```
|
||||
|
||||
**第五层:实用性验证**
|
||||
|
||||
```text
|
||||
"Theory and practice sometimes clash. Theory loses. Every single time."
|
||||
|
||||
- 这个问题在生产环境真实存在吗?
|
||||
- 有多少用户真正遇到这个问题?
|
||||
- 解决方案的复杂度是否与问题的严重性匹配?
|
||||
```
|
||||
|
||||
4. **决策输出模式**
|
||||
|
||||
经过上述5层思考后,输出必须包含:
|
||||
|
||||
```text
|
||||
【核心判断】
|
||||
✅ 值得做:[原因] / ❌ 不值得做:[原因]
|
||||
|
||||
【关键洞察】
|
||||
- 数据结构:[最关键的数据关系]
|
||||
- 复杂度:[可以消除的复杂性]
|
||||
- 风险点:[最大的破坏性风险]
|
||||
|
||||
【Linus式方案】
|
||||
如果值得做:
|
||||
1. 第一步永远是简化数据结构
|
||||
2. 消除所有特殊情况
|
||||
3. 用最笨但最清晰的方式实现
|
||||
4. 确保零破坏性
|
||||
|
||||
如果不值得做:
|
||||
"这是在解决不存在的问题。真正的问题是[XXX]。"
|
||||
```
|
||||
|
||||
5. **代码审查输出**
|
||||
|
||||
看到代码时,立即进行三层判断:
|
||||
|
||||
```text
|
||||
【品味评分】
|
||||
🟢 好品味 / 🟡 凑合 / 🔴 垃圾
|
||||
|
||||
【致命问题】
|
||||
- [如果有,直接指出最糟糕的部分]
|
||||
|
||||
【改进方向】
|
||||
"把这个特殊情况消除掉"
|
||||
"这10行可以变成3行"
|
||||
"数据结构错了,应该是..."
|
||||
```
|
||||
|
||||
## 项目概述
|
||||
|
||||
AcePanel 是基于 Go 语言开发的新一代 Linux 服务器运维管理面板。项目采用前后端分离架构:
|
||||
|
||||
- 后端:Go 1.25 + go-chi 路由 + GORM + Wire 依赖注入
|
||||
- 前端:Vue 3 + Vite + Naive UI + pnpm
|
||||
|
||||
## 语言和编码规范
|
||||
|
||||
**所有代码注释、文档和回复必须使用简体中文。**
|
||||
|
||||
## 构建和测试
|
||||
|
||||
### 后端构建
|
||||
|
||||
构建主程序:
|
||||
|
||||
```bash
|
||||
go build -o ace ./cmd/ace
|
||||
```
|
||||
|
||||
构建 CLI 工具:
|
||||
|
||||
```bash
|
||||
go build -o cli ./cmd/cli
|
||||
```
|
||||
|
||||
### 前端开发
|
||||
|
||||
进入前端目录:
|
||||
|
||||
```bash
|
||||
cd web
|
||||
```
|
||||
|
||||
安装依赖:
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
开发模式(带热重载):
|
||||
|
||||
```bash
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
构建生产版本:
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
```
|
||||
|
||||
## 代码架构
|
||||
|
||||
项目采用类 DDD 分层架构,依赖关系为:route -> service -> biz <- data
|
||||
|
||||
### 核心目录结构
|
||||
|
||||
- **`cmd/`**: 程序入口
|
||||
- `ace/`: 面板主程序
|
||||
- `cli/`: 命令行工具
|
||||
|
||||
- **`internal/app/`**: 应用入口和配置
|
||||
|
||||
- **`internal/route/`**: HTTP 路由定义
|
||||
- 定义路由规则
|
||||
- 注入所需的 service 依赖
|
||||
|
||||
- **`internal/service/`**: 服务层(类似 DDD 的 application 层)
|
||||
- 处理 HTTP 请求/响应
|
||||
- DTO 到 DO 的转换
|
||||
- 协调多个 biz 接口完成业务流程
|
||||
- **不应处理复杂业务逻辑**
|
||||
|
||||
- **`internal/biz/`**: 业务逻辑层(类似 DDD 的 domain 层)
|
||||
- 定义业务接口(Repository 模式)
|
||||
- 定义领域模型和数据结构
|
||||
- 使用依赖倒置原则:biz 定义接口,data 实现接口
|
||||
|
||||
- **`internal/data/`**: 数据访问层(类似 DDD 的 repository 层)
|
||||
- 实现 biz 中定义的业务接口
|
||||
- 封装数据库、缓存等操作
|
||||
- 处理数据持久化逻辑
|
||||
|
||||
- **`internal/http/`**: HTTP 相关
|
||||
- `middleware/`: 自定义中间件
|
||||
- `request/`: 请求结构体定义
|
||||
- `rule/`: 自定义验证规则
|
||||
|
||||
- **`internal/apps/`**: 面板子应用实现
|
||||
|
||||
- **`internal/bootstrap/`**: 各模块启动引导
|
||||
|
||||
- **`internal/migration/`**: 数据库迁移
|
||||
|
||||
- **`internal/job/`**: 后台任务
|
||||
|
||||
- **`internal/queuejob/`**: 任务队列
|
||||
|
||||
- **`pkg/`**: 工具函数和通用包
|
||||
- 包含各种独立的工具模块
|
||||
- 可被项目任何部分引用
|
||||
|
||||
- **`web/`**: Vue 3 前端项目
|
||||
|
||||
## 开发新功能的标准流程
|
||||
|
||||
1. **在 `internal/route/` 中添加路由**
|
||||
- 参考已有路由文件(如 `http.go`)
|
||||
- 注入需要的 service 依赖
|
||||
- 定义路由规则和 handler 映射
|
||||
|
||||
2. **在 `internal/service/` 中实现服务方法**
|
||||
- **先阅读已有的类似服务**以了解代码风格
|
||||
- 处理请求验证和响应格式化
|
||||
- 使用 `Success()` 返回成功响应
|
||||
- 使用 `Error()` 返回错误响应
|
||||
- 使用 `ErrorSystem()` 返回系统严重错误
|
||||
- 调用 biz 层接口完成业务逻辑
|
||||
|
||||
3. **在 `internal/biz/` 中定义业务接口**
|
||||
- **先阅读已有的类似接口定义**
|
||||
- 定义 Repository 接口(如 `WebsiteRepo`)
|
||||
- 定义领域模型结构体(如 `Website`)
|
||||
- 保持接口简洁明确
|
||||
|
||||
4. **在 `internal/data/` 中实现 biz 接口**
|
||||
- **先阅读已有的类似实现**
|
||||
- 创建 repo 结构体(如 `websiteRepo`)
|
||||
- 实现构造函数(如 `NewWebsiteRepo`)
|
||||
- 实现所有接口方法
|
||||
- 处理数据库操作和缓存逻辑
|
||||
|
||||
5. **使用 Wire 进行依赖注入**
|
||||
- 在对应的 wire.go 文件中添加 provider
|
||||
- 运行 `go generate` 生成依赖注入代码
|
||||
|
||||
## 技术栈特定注意事项
|
||||
|
||||
### Go 语言规范
|
||||
|
||||
- 使用 Go 1.25 稳定版本
|
||||
- 遵循 Go 标准库和习惯用法
|
||||
- 日志使用标准库的 `slog` 包
|
||||
- 使用 `github.com/samber/lo` 进行函数式编程辅助
|
||||
|
||||
### 当前框架
|
||||
|
||||
- 路由:`github.com/go-chi/chi/v5`
|
||||
- ORM:`gorm.io/gorm`
|
||||
- 依赖注入:`github.com/google/wire`
|
||||
- 验证:`github.com/gookit/validate`
|
||||
|
||||
### 助手函数(service 层)
|
||||
|
||||
在 service 层使用以下助手函数:
|
||||
|
||||
- `Success(w, data)`: 返回成功响应
|
||||
- `Error(w, statusCode, format, args...)`: 返回错误响应
|
||||
- `ErrorSystem(w, format, args...)`: 返回系统严重错误(500)
|
||||
- `Bind[T](r)`: 绑定请求参数到泛型类型 T
|
||||
- `Paginate[T](...)`: 构建分页响应
|
||||
|
||||
### 数据库
|
||||
|
||||
- 使用 SQLite(`github.com/ncruces/go-sqlite3`)
|
||||
- 使用 GORM 进行数据库迁移和操作
|
||||
|
||||
### 安全性
|
||||
|
||||
- 不需要实现命令注入过滤,文件名过滤等,因为这是服务器面板,所有登录的用户都被视为管理员
|
||||
|
||||
## 代码风格
|
||||
|
||||
- 所有代码注释必须使用简体中文
|
||||
- 遵循 Go 官方代码风格
|
||||
- 使用 `gofmt` 格式化代码
|
||||
- 复杂逻辑添加注释说明
|
||||
- 导出的函数和类型必须有注释
|
||||
- service 层以及 data 层方法对外返回的字符串需要使用 gotext 进行国际化处理
|
||||
- 禁止手动编辑国际化文件,项目使用外部 Crowdin 自动化管理
|
||||
|
||||
## Wire 依赖注入
|
||||
|
||||
项目使用 Wire 进行依赖注入。当添加新的依赖时:
|
||||
|
||||
1. 在 `cmd/ace/wire.go` 或 `cmd/cli/wire.go` 中添加 provider
|
||||
2. 运行生成命令:
|
||||
|
||||
```bash
|
||||
go generate ./...
|
||||
```
|
||||
|
||||
## 前端开发注意事项
|
||||
|
||||
- 使用 Vue 3 Composition API
|
||||
- UI 框架:Naive UI
|
||||
- 状态管理:Pinia
|
||||
- HTTP 请求:Alova.js,使用 useRequest 等助手函数进行数据获取,无需处理 onError 错误。
|
||||
- 图标:@iconify/vue
|
||||
- 终端:xterm.js
|
||||
- 遵循项目已有的组件结构和编码风格
|
||||
- 禁止手动编辑国际化文件,项目使用外部 Crowdin 自动化管理
|
||||
|
||||
## 配置文件
|
||||
|
||||
开发时需要准备配置文件:
|
||||
|
||||
```bash
|
||||
cp config.example.yml config.yml
|
||||
```
|
||||
|
||||
前端开发配置:
|
||||
|
||||
```bash
|
||||
cd web
|
||||
cp .env.production .env
|
||||
cp settings/proxy-config.example.ts settings/proxy-config.ts
|
||||
```
|
||||
|
||||
## 工具使用
|
||||
|
||||
### 文档工具
|
||||
|
||||
1. **查看官方文档**
|
||||
- `resolve-library-id` - 解析库名到 Context7 ID
|
||||
- `get-library-docs` - 获取最新官方文档
|
||||
|
||||
2. **搜索真实代码**
|
||||
- `searchGitHub` - 搜索 GitHub 上的实际使用案例
|
||||
@@ -17,7 +17,7 @@
|
||||
[](https://go.dev/)
|
||||
[](https://github.com/acepanel/panel/releases)
|
||||
[](https://github.com/acepanel/panel/actions)
|
||||
[](https://goreportcard.com/report/github.com/acepanel/panel)
|
||||
[](https://goreportcard.com/report/github.com/acepanel/panel/v3)
|
||||
[](https://github.com/acepanel/panel)
|
||||
[](https://opensource.org/license/bsd-3-clause)
|
||||
|
||||
@@ -43,7 +43,7 @@ bash <(curl -sSLm 10 https://dl.acepanel.net/helper.sh)
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> 耗子面板 2.x -> AcePanel 3.0 迁移工具将在近期发布,敬请期待!
|
||||
> 耗子面板 2.x -> AcePanel 3.0 迁移说明:[https://tom.moe/t/topic/3540](https://tom.moe/t/topic/3540)
|
||||
|
||||
## UI 截图
|
||||
|
||||
@@ -82,10 +82,10 @@ bash <(curl -sSLm 10 https://dl.acepanel.net/helper.sh)
|
||||
|
||||
## Star 历史
|
||||
|
||||
<a href="https://star-history.com/#acepanel/panel&Date">
|
||||
<a href="https://www.star-history.com/?repos=acepanel%2Fpanel&type=date&legend=top-left">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=acepanel/panel&type=Date&theme=dark" />
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=acepanel/panel&type=Date" />
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=acepanel/panel&type=Date" />
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=acepanel/panel&type=date&theme=dark&legend=top-left&sealed_token=A7PSvKwCQys65o30bBWFVq0j-xWQ7q0kkPMbHsRTelnAZTLIVnCIIS18tyeO0LeMqQ4fsyoN1oPeM9dPIHpa1x03AV47vz7Q880xdcO7CH-y6qzXLCMO6g" />
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=acepanel/panel&type=date&legend=top-left&sealed_token=A7PSvKwCQys65o30bBWFVq0j-xWQ7q0kkPMbHsRTelnAZTLIVnCIIS18tyeO0LeMqQ4fsyoN1oPeM9dPIHpa1x03AV47vz7Q880xdcO7CH-y6qzXLCMO6g" />
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=acepanel/panel&type=date&legend=top-left&sealed_token=A7PSvKwCQys65o30bBWFVq0j-xWQ7q0kkPMbHsRTelnAZTLIVnCIIS18tyeO0LeMqQ4fsyoN1oPeM9dPIHpa1x03AV47vz7Q880xdcO7CH-y6qzXLCMO6g" />
|
||||
</picture>
|
||||
</a>
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ Website: [acepanel.net](https://acepanel.net) | QQ group: [12370907](https://jq.
|
||||
[](https://go.dev/)
|
||||
[](https://github.com/acepanel/panel/releases)
|
||||
[](https://github.com/acepanel/panel/actions)
|
||||
[](https://goreportcard.com/report/github.com/acepanel/panel)
|
||||
[](https://goreportcard.com/report/github.com/acepanel/panel/v3)
|
||||
[](https://github.com/acepanel/panel)
|
||||
[](https://opensource.org/license/bsd-3-clause)
|
||||
|
||||
|
||||
+8
-7
@@ -2,29 +2,30 @@
|
||||
|
||||
| Version | Supported |
|
||||
|---------|--------------------|
|
||||
| v3.x | :white_check_mark: |
|
||||
| v2.x | :white_check_mark: |
|
||||
| v1.x | :x: |
|
||||
|
||||
## Security Policy
|
||||
|
||||
If you find any security issues while using the panel, please do not submit an Issue. You can contact us directly through the following methods:
|
||||
If you find any security issues while using AcePanel, please do not submit an Issue. You can contact us directly through the following methods:
|
||||
|
||||
- (Recommend) [GitHub Security Advisories](https://github.com/acepanel/panel/security/advisories/new)
|
||||
- Email: [admin@haozi.net](mailto:admin@haozi.net)
|
||||
- Telegram: @devhaozi
|
||||
|
||||
Thank you in advance for your support and help!
|
||||
Please do not apply for CVE, CNVD, or similar vulnerability IDs without contacting us first. Once an issue has been confirmed and fixed, we will assist with the related disclosure process. Thank you in advance for your support and cooperation!
|
||||
|
||||
To some security beginners: Any operation performed through an already logged-in panel's `session` / `access_token` (including but not limited to: obtaining root permissions, reading/writing sensitive system files, executing arbitrary shell commands, etc.) is not considered a security issue. Please do not waste each other's time by submitting such reports.
|
||||
**Special Note:** AcePanel is designed with high-privilege operational capabilities. Any action performed under a valid authenticated session (such as `session` or `access_token`), including but not limited to obtaining root privileges, reading or writing sensitive system files, or executing arbitrary shell commands, is considered within the intended design scope and does not constitute a security issue. Please do not submit reports of this nature, as they are effectively self-compromise scenarios and only waste time for both parties.
|
||||
|
||||
## 安全说明
|
||||
|
||||
如果您在面板中发现任何安全问题,请勿提交 Issue,可通过以下方式直接联系我们:
|
||||
如果您在 AcePanel 中发现任何安全问题,请勿提交 Issue,可通过以下方式直接联系我们:
|
||||
|
||||
- (推荐)[GitHub 安全公告](https://github.com/acepanel/panel/security/advisories/new)
|
||||
- (推荐)[GitHub Security Advisories](https://github.com/acepanel/panel/security/advisories/new)
|
||||
- 邮箱:[admin@haozi.net](mailto:admin@haozi.net)
|
||||
- QQ:826896000
|
||||
|
||||
提前感谢您的支持与帮助!
|
||||
请勿在未与我们沟通的情况下直接申请 CVE、CNVD 等漏洞编号,相关问题确认并修复后我们会协助处理。提前感谢您的支持与配合!
|
||||
|
||||
致某些安全初学者:通过已登录面板的 `session` / `access_token` 执行的任何操作(包括且不限于:获取 root 权限、读取/写入系统敏感文件、执行任意 shell 命令等)均不被认为是安全问题,请不要刷此类报告浪费彼此的时间。
|
||||
**特别说明:** AcePanel 本身具备高权限操作能力,基于有效登录态(如 `session`、`access_token`)所执行的任何操作(包括且不限于:获取 root 权限、读取/写入系统敏感文件、执行任意 shell 命令等)均属于预期设计范围,不视为安全问题。请勿提交此类我攻击我自己的报告浪费彼此时间。
|
||||
|
||||
+16
-7
@@ -1,25 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
_ "time/tzdata"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
if os.Geteuid() != 0 {
|
||||
panic("panel must run as root")
|
||||
return errors.New("panel must run as root")
|
||||
}
|
||||
|
||||
debug.SetGCPercent(10)
|
||||
debug.SetMemoryLimit(256 << 20)
|
||||
|
||||
ace, err := initAce()
|
||||
ace, cleanup, err := initAce()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
|
||||
if err = ace.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ace.Run()
|
||||
}
|
||||
|
||||
+19
-11
@@ -5,17 +5,25 @@ package main
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/apps"
|
||||
"github.com/acepanel/panel/internal/bootstrap"
|
||||
"github.com/acepanel/panel/internal/data"
|
||||
"github.com/acepanel/panel/internal/http/middleware"
|
||||
"github.com/acepanel/panel/internal/job"
|
||||
"github.com/acepanel/panel/internal/route"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/apps"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/bootstrap"
|
||||
"github.com/acepanel/panel/v3/internal/data"
|
||||
"github.com/acepanel/panel/v3/internal/job"
|
||||
"github.com/acepanel/panel/v3/internal/route"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
)
|
||||
|
||||
// initAce init application.
|
||||
func initAce() (*app.Ace, error) {
|
||||
panic(wire.Build(bootstrap.ProviderSet, middleware.ProviderSet, route.ProviderSet, service.ProviderSet, data.ProviderSet, apps.ProviderSet, job.ProviderSet, app.NewAce))
|
||||
func initAce() (*app.Ace, func(), error) {
|
||||
panic(wire.Build(
|
||||
bootstrap.ProviderSet,
|
||||
apps.ProviderSet,
|
||||
biz.ProviderSet,
|
||||
data.ProviderSet,
|
||||
service.ProviderSet,
|
||||
route.ProviderSet,
|
||||
job.ProviderSet,
|
||||
app.NewAce,
|
||||
))
|
||||
}
|
||||
|
||||
+910
-146
File diff suppressed because it is too large
Load Diff
+22
-11
@@ -1,21 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
_ "time/tzdata"
|
||||
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if os.Geteuid() != 0 {
|
||||
panic("panel must run as root")
|
||||
}
|
||||
|
||||
cli, err := initCli()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err = cli.Run(); err != nil {
|
||||
panic(err)
|
||||
if err := run(); err != nil {
|
||||
color.Errorf("|-%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
if os.Geteuid() != 0 {
|
||||
return errors.New("panel must run as root")
|
||||
}
|
||||
|
||||
cli, cleanup, err := initCli()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
|
||||
return cli.Run()
|
||||
}
|
||||
|
||||
+15
-9
@@ -5,15 +5,21 @@ package main
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/apps"
|
||||
"github.com/acepanel/panel/internal/bootstrap"
|
||||
"github.com/acepanel/panel/internal/data"
|
||||
"github.com/acepanel/panel/internal/route"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/bootstrap"
|
||||
"github.com/acepanel/panel/v3/internal/command"
|
||||
"github.com/acepanel/panel/v3/internal/data"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
)
|
||||
|
||||
// initCli init command line.
|
||||
func initCli() (*app.Cli, error) {
|
||||
panic(wire.Build(bootstrap.ProviderSet, route.ProviderSet, service.ProviderSet, data.ProviderSet, apps.ProviderSet, app.NewCli))
|
||||
func initCli() (*app.Cli, func(), error) {
|
||||
panic(wire.Build(
|
||||
bootstrap.ProviderSet,
|
||||
biz.ProviderSet,
|
||||
data.ProviderSet,
|
||||
service.ProviderSet,
|
||||
command.ProviderSet,
|
||||
app.NewCli,
|
||||
))
|
||||
}
|
||||
|
||||
+193
-73
@@ -7,32 +7,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/apps/apache"
|
||||
"github.com/acepanel/panel/internal/apps/codeserver"
|
||||
"github.com/acepanel/panel/internal/apps/docker"
|
||||
"github.com/acepanel/panel/internal/apps/fail2ban"
|
||||
"github.com/acepanel/panel/internal/apps/frp"
|
||||
"github.com/acepanel/panel/internal/apps/gitea"
|
||||
"github.com/acepanel/panel/internal/apps/mariadb"
|
||||
"github.com/acepanel/panel/internal/apps/memcached"
|
||||
"github.com/acepanel/panel/internal/apps/minio"
|
||||
"github.com/acepanel/panel/internal/apps/mysql"
|
||||
"github.com/acepanel/panel/internal/apps/nginx"
|
||||
"github.com/acepanel/panel/internal/apps/openresty"
|
||||
"github.com/acepanel/panel/internal/apps/percona"
|
||||
"github.com/acepanel/panel/internal/apps/phpmyadmin"
|
||||
"github.com/acepanel/panel/internal/apps/podman"
|
||||
"github.com/acepanel/panel/internal/apps/postgresql"
|
||||
"github.com/acepanel/panel/internal/apps/pureftpd"
|
||||
"github.com/acepanel/panel/internal/apps/redis"
|
||||
"github.com/acepanel/panel/internal/apps/rsync"
|
||||
"github.com/acepanel/panel/internal/apps/s3fs"
|
||||
"github.com/acepanel/panel/internal/apps/supervisor"
|
||||
"github.com/acepanel/panel/internal/bootstrap"
|
||||
"github.com/acepanel/panel/internal/data"
|
||||
"github.com/acepanel/panel/internal/route"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/bootstrap"
|
||||
"github.com/acepanel/panel/v3/internal/command"
|
||||
"github.com/acepanel/panel/v3/internal/data"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
)
|
||||
|
||||
import (
|
||||
@@ -41,60 +21,200 @@ import (
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
// initCli init command line.
|
||||
func initCli() (*app.Cli, error) {
|
||||
func initCli() (*app.Cli, func(), error) {
|
||||
config, err := bootstrap.NewConf()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
locale, err := bootstrap.NewT(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
db, err := bootstrap.NewDB(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
logger := bootstrap.NewLog(config)
|
||||
cacheRepo := data.NewCacheRepo(db)
|
||||
queue := bootstrap.NewQueue()
|
||||
taskRepo := data.NewTaskRepo(locale, db, logger, queue)
|
||||
appRepo := data.NewAppRepo(locale, config, db, logger, cacheRepo, taskRepo)
|
||||
userRepo := data.NewUserRepo(locale, db, logger)
|
||||
settingRepo := data.NewSettingRepo(locale, db, logger, config, taskRepo)
|
||||
databaseServerRepo := data.NewDatabaseServerRepo(locale, db, logger)
|
||||
databaseUserRepo := data.NewDatabaseUserRepo(locale, db, logger, databaseServerRepo)
|
||||
databaseRepo := data.NewDatabaseRepo(locale, db, logger, databaseServerRepo, databaseUserRepo)
|
||||
certRepo := data.NewCertRepo(locale, db, logger, settingRepo)
|
||||
certAccountRepo := data.NewCertAccountRepo(locale, db, userRepo, logger)
|
||||
websiteRepo := data.NewWebsiteRepo(locale, db, logger, cacheRepo, databaseRepo, databaseServerRepo, databaseUserRepo, certRepo, certAccountRepo, settingRepo)
|
||||
backupRepo := data.NewBackupRepo(locale, config, db, logger, settingRepo, websiteRepo)
|
||||
cliService := service.NewCliService(locale, config, db, appRepo, cacheRepo, userRepo, settingRepo, backupRepo, websiteRepo, databaseServerRepo, certRepo, certAccountRepo)
|
||||
cli := route.NewCli(locale, cliService)
|
||||
command := bootstrap.NewCli(locale, cli)
|
||||
gormigrate := bootstrap.NewMigrate(db)
|
||||
apacheApp := apache.NewApp(locale)
|
||||
codeserverApp := codeserver.NewApp()
|
||||
dockerApp := docker.NewApp()
|
||||
fail2banApp := fail2ban.NewApp(locale, websiteRepo)
|
||||
frpApp := frp.NewApp()
|
||||
giteaApp := gitea.NewApp()
|
||||
mariadbApp := mariadb.NewApp(locale, settingRepo, databaseServerRepo)
|
||||
memcachedApp := memcached.NewApp(locale)
|
||||
minioApp := minio.NewApp()
|
||||
mysqlApp := mysql.NewApp(locale, settingRepo, databaseServerRepo)
|
||||
nginxApp := nginx.NewApp(locale)
|
||||
openrestyApp := openresty.NewApp(locale)
|
||||
perconaApp := percona.NewApp(locale, settingRepo, databaseServerRepo)
|
||||
phpmyadminApp := phpmyadmin.NewApp(locale)
|
||||
podmanApp := podman.NewApp()
|
||||
postgresqlApp := postgresql.NewApp(locale, settingRepo, databaseServerRepo)
|
||||
pureftpdApp := pureftpd.NewApp(locale)
|
||||
redisApp := redis.NewApp(locale)
|
||||
rsyncApp := rsync.NewApp(locale)
|
||||
s3fsApp := s3fs.NewApp(locale)
|
||||
supervisorApp := supervisor.NewApp(locale)
|
||||
loader := bootstrap.NewLoader(apacheApp, codeserverApp, dockerApp, fail2banApp, frpApp, giteaApp, mariadbApp, memcachedApp, minioApp, mysqlApp, nginxApp, openrestyApp, perconaApp, phpmyadminApp, podmanApp, postgresqlApp, pureftpdApp, redisApp, rsyncApp, s3fsApp, supervisorApp)
|
||||
appCli := app.NewCli(command, gormigrate, loader)
|
||||
return appCli, nil
|
||||
logger, cleanup, err := bootstrap.NewLogger(config)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
slogLogger := bootstrap.NewSlog(logger)
|
||||
appRepo, err := data.NewAppRepo(config, db, locale, slogLogger)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
cacheRepo, err := data.NewCacheRepo(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
notifyChannelRepo, err := data.NewNotifyChannelRepo(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
settingRepo, err := data.NewSettingRepo(config, db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
notifyUsecase, err := biz.NewNotifyUsecase(locale, slogLogger, notifyChannelRepo, settingRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
taskRunner, err := bootstrap.NewRunner(notifyUsecase, db, locale, slogLogger)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
taskRepo, err := data.NewTaskRepo(db, locale, slogLogger, taskRunner)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
appUsecase, err := biz.NewAppUsecase(locale, appRepo, cacheRepo, taskRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
websiteRepo, err := data.NewWebsiteRepo(db, locale, settingRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
backupRepo, err := data.NewBackupRepo(config, db, locale, slogLogger, settingRepo, websiteRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
backupUsecase, err := biz.NewBackupUsecase(notifyUsecase, locale, slogLogger, backupRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
cacheUsecase := biz.NewCacheUsecase(cacheRepo)
|
||||
certAccountRepo, err := data.NewCertAccountRepo(db, locale, slogLogger)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
userRepo, err := data.NewUserRepo(db, locale)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
certAccountUsecase, err := biz.NewCertAccountUsecase(locale, slogLogger, certAccountRepo, userRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
certRepo, err := data.NewCertRepo(db, locale, slogLogger)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
certUsecase, err := biz.NewCertUsecase(locale, slogLogger, certRepo, settingRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
cronRepo, err := data.NewCronRepo(db, locale)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
cronUsecase := biz.NewCronUsecase(cronRepo, slogLogger)
|
||||
databaseServerRepo, err := data.NewDatabaseServerRepo(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
databaseServerUsecase, err := biz.NewDatabaseServerUsecase(locale, slogLogger, databaseServerRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
settingUsecase, err := biz.NewSettingUsecase(locale, slogLogger, settingRepo, taskRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
userPasskeyRepo, err := data.NewUserPasskeyRepo(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
userPasskeyUsecase := biz.NewUserPasskeyUsecase(userPasskeyRepo)
|
||||
userUsecase, err := biz.NewUserUsecase(locale, slogLogger, userRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
databaseUserRepo, err := data.NewDatabaseUserRepo(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
databaseUserUsecase, err := biz.NewDatabaseUserUsecase(slogLogger, databaseServerRepo, databaseUserRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
databaseRepo, err := data.NewDatabaseRepo(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
databaseUsecase, err := biz.NewDatabaseUsecase(databaseUserUsecase, locale, slogLogger, databaseRepo, databaseServerRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
tamperRepo, err := data.NewTamperRepo(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
tamperUsecase, err := biz.NewTamperUsecase(notifyUsecase, settingUsecase, locale, slogLogger, tamperRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
websiteStatRepo, err := data.NewWebsiteStatRepo()
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
websiteStatUsecase := biz.NewWebsiteStatUsecase(websiteStatRepo)
|
||||
websiteUsecase, err := biz.NewWebsiteUsecase(certAccountUsecase, certUsecase, databaseUsecase, databaseUserUsecase, tamperUsecase, websiteStatUsecase, locale, slogLogger, databaseServerRepo, websiteRepo)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
cliService, err := service.NewCliService(appUsecase, backupUsecase, cacheUsecase, certAccountUsecase, certUsecase, cronUsecase, databaseServerUsecase, notifyUsecase, settingUsecase, userPasskeyUsecase, userUsecase, websiteUsecase, config, db, locale)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
v := command.Commands(locale, cliService)
|
||||
cliCommand, err := bootstrap.NewCli(locale, v)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
gormigrate, err := bootstrap.NewMigrate(db)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
cli, err := app.NewCli(cliCommand, gormigrate)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
return cli, func() {
|
||||
cleanup()
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,115 +1,151 @@
|
||||
module github.com/acepanel/panel
|
||||
module github.com/acepanel/panel/v3
|
||||
|
||||
go 1.25.6
|
||||
go 1.26
|
||||
|
||||
require (
|
||||
github.com/DeRuina/timberjack v1.3.9
|
||||
github.com/bddjr/hlfhr v1.4.2
|
||||
github.com/andybalholm/brotli v1.2.2
|
||||
github.com/bddjr/hlfhr v1.6.1
|
||||
github.com/beevik/ntp v1.5.0
|
||||
github.com/coder/websocket v1.8.14
|
||||
github.com/cilium/ebpf v0.22.0
|
||||
github.com/coder/websocket v1.8.15
|
||||
github.com/containerd/errdefs v1.0.0
|
||||
github.com/coreos/go-systemd/v22 v22.7.0
|
||||
github.com/creack/pty v1.1.24
|
||||
github.com/dchest/captcha v1.1.0
|
||||
github.com/expr-lang/expr v1.17.7
|
||||
github.com/go-chi/chi/v5 v5.2.5
|
||||
github.com/go-chi/httplog/v3 v3.3.0
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.5
|
||||
github.com/go-resty/resty/v2 v2.17.1
|
||||
github.com/go-sql-driver/mysql v1.9.3
|
||||
github.com/expr-lang/expr v1.17.8
|
||||
github.com/fsnotify/fsnotify v1.10.1
|
||||
github.com/go-chi/chi/v5 v5.3.1
|
||||
github.com/go-chi/httplog/v3 v3.4.0
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.6
|
||||
github.com/go-sql-driver/mysql v1.10.0
|
||||
github.com/go-webauthn/webauthn v0.17.4
|
||||
github.com/gomodule/redigo v1.9.3
|
||||
github.com/google/wire v0.7.0
|
||||
github.com/gookit/color v1.6.0
|
||||
github.com/gookit/validate v1.5.7-0.20260207022141-dc32dc1276cd
|
||||
github.com/hashicorp/go-version v1.8.0
|
||||
github.com/klauspost/compress v1.18.3
|
||||
github.com/gookit/color v1.6.1
|
||||
github.com/hashicorp/go-version v1.9.0
|
||||
github.com/leonelquinteros/gotext v1.7.2
|
||||
github.com/lib/pq v1.11.1
|
||||
github.com/libdns/alidns v1.0.6-beta.3.0.20260121104221-597b1e580e21
|
||||
github.com/lib/pq v1.12.3
|
||||
github.com/libdns/alidns v1.0.7
|
||||
github.com/libdns/cloudflare v0.2.2
|
||||
github.com/libdns/cloudns v1.1.0
|
||||
github.com/libdns/cloudns v1.2.0
|
||||
github.com/libdns/gcore v0.0.0-20250427050847-9964da923833
|
||||
github.com/libdns/huaweicloud v1.0.0
|
||||
github.com/libdns/huaweicloud v1.0.1
|
||||
github.com/libdns/libdns v1.1.1
|
||||
github.com/libdns/namesilo v1.0.0
|
||||
github.com/libdns/porkbun v1.1.0
|
||||
github.com/libdns/tencentcloud v1.4.3
|
||||
github.com/libdns/westcn v1.0.2
|
||||
github.com/libtnb/chix v1.3.2
|
||||
github.com/libtnb/gormstore v1.1.1
|
||||
github.com/libtnb/sessions v1.2.2
|
||||
github.com/libtnb/utils v1.2.1
|
||||
github.com/mholt/acmez/v3 v3.1.4
|
||||
github.com/moby/moby/api v1.53.0
|
||||
github.com/moby/moby/client v0.2.2
|
||||
github.com/ncruces/go-sqlite3 v0.30.5
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.30.2
|
||||
github.com/libtnb/chix/v2 v2.1.1
|
||||
github.com/libtnb/cron v0.5.2
|
||||
github.com/libtnb/gormstore v1.3.0
|
||||
github.com/libtnb/logrotate v0.1.2
|
||||
github.com/libtnb/sessions v1.5.0
|
||||
github.com/libtnb/sqlite v1.2.1
|
||||
github.com/libtnb/utils v1.2.2
|
||||
github.com/libtnb/validator v0.4.1
|
||||
github.com/libtnb/validator/contrib/openapi v0.2.0
|
||||
github.com/medama-io/go-useragent v1.2.4
|
||||
github.com/mholt/acmez/v3 v3.1.6
|
||||
github.com/moby/moby/api v1.55.0
|
||||
github.com/moby/moby/client v0.5.1
|
||||
github.com/orandin/slog-gorm v1.4.0
|
||||
github.com/pkg/sftp v1.13.10
|
||||
github.com/pkg/sftp v1.13.11
|
||||
github.com/pquerna/otp v1.5.0
|
||||
github.com/rhnvrm/simples3 v0.11.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/samber/lo v1.52.0
|
||||
github.com/sethvargo/go-limiter v1.1.0
|
||||
github.com/shirou/gopsutil/v4 v4.26.1
|
||||
github.com/samber/lo v1.53.0
|
||||
github.com/sethvargo/go-limiter v1.2.0
|
||||
github.com/shirou/gopsutil/v4 v4.26.6
|
||||
github.com/spf13/cast v1.10.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/studio-b12/gowebdav v0.12.0
|
||||
github.com/tufanbarisyildirim/gonginx v0.0.0-20250620092546-c3e307e36701
|
||||
github.com/urfave/cli/v3 v3.6.2
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.4
|
||||
golang.org/x/crypto v0.47.0
|
||||
golang.org/x/net v0.49.0
|
||||
gorm.io/gorm v1.31.1
|
||||
github.com/studio-b12/gowebdav v0.13.0
|
||||
github.com/tufanbarisyildirim/gonginx v0.0.0-20260220081509-8e17ce617db3
|
||||
github.com/urfave/cli/v3 v3.10.1
|
||||
github.com/valyala/fastjson v1.6.10
|
||||
github.com/wneessen/go-mail v0.8.1
|
||||
github.com/xuri/excelize/v2 v2.11.0
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.6
|
||||
golang.org/x/crypto v0.54.0
|
||||
golang.org/x/net v0.57.0
|
||||
golang.org/x/sync v0.22.0
|
||||
golang.org/x/sys v0.47.0
|
||||
gorm.io/gorm v1.31.2
|
||||
modernc.org/sqlite v1.55.0
|
||||
resty.dev/v3 v3.0.0-rc.3
|
||||
)
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
filippo.io/edwards25519 v1.2.0 // indirect
|
||||
github.com/G-Core/gcore-dns-sdk-go v0.3.3 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/bddjr/shuttingdown v0.1.0 // indirect
|
||||
github.com/boombuler/barcode v1.1.0 // indirect
|
||||
github.com/boyter/go-string v1.0.5 // indirect
|
||||
github.com/containerd/errdefs/pkg v0.3.0 // indirect
|
||||
github.com/distribution/reference v0.6.0 // indirect
|
||||
github.com/docker/go-connections v0.6.0 // indirect
|
||||
github.com/docker/go-connections v0.7.0 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/ebitengine/purego v0.9.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/ebitengine/purego v0.10.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/fxamacker/cbor/v2 v2.9.2 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/gofiber/schema v1.6.0 // indirect
|
||||
github.com/gookit/filter v1.2.3 // indirect
|
||||
github.com/gookit/goutil v0.7.3 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
|
||||
github.com/go-webauthn/x v0.2.6 // indirect
|
||||
github.com/gofiber/schema v1.8.2 // indirect
|
||||
github.com/gofiber/utils/v2 v2.2.0 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
||||
github.com/google/go-tpm v0.9.8 // indirect
|
||||
github.com/google/subcommands v1.2.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/imega/luaformatter v0.0.0-20211025140405-86b0a68d6bef // indirect
|
||||
github.com/jaevor/go-nanoid v1.4.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/kr/fs v0.1.0 // indirect
|
||||
github.com/libtnb/securecookie v1.2.0 // indirect
|
||||
github.com/libtnb/securecookie v1.4.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20251013123823-9fd1530e3ec3 // indirect
|
||||
github.com/mattn/go-isatty v0.0.21 // indirect
|
||||
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||
github.com/ncruces/julianday v1.0.0 // indirect
|
||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.1 // indirect
|
||||
github.com/philhofer/fwd v1.2.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/richardlehane/mscfb v1.0.7 // indirect
|
||||
github.com/richardlehane/msoleps v1.0.6 // indirect
|
||||
github.com/stretchr/objx v0.5.3 // indirect
|
||||
github.com/tetratelabs/wazero v1.11.0 // indirect
|
||||
github.com/tiendc/go-deepcopy v1.7.2 // indirect
|
||||
github.com/timtadh/data-structures v0.6.2 // indirect
|
||||
github.com/timtadh/lexmachine v0.2.3 // indirect
|
||||
github.com/tinylib/msgp v1.6.4 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.16 // indirect
|
||||
github.com/tklauser/numcpus v0.11.0 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
github.com/xuri/efp v0.0.1 // indirect
|
||||
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
golang.org/x/text v0.33.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
|
||||
go.opentelemetry.io/otel v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.35.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.35.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20260603202125-055de637280b // indirect
|
||||
golang.org/x/mod v0.37.0 // indirect
|
||||
golang.org/x/text v0.40.0 // indirect
|
||||
golang.org/x/tools v0.47.0 // indirect
|
||||
modernc.org/libc v1.74.1 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/mholt/acmez/v3 => github.com/libtnb/acmez/v3 v3.0.0-20260103184942-a835890fc93e
|
||||
github.com/moby/moby/client => github.com/libtnb/moby/client v0.0.0-20260127104057-d4b7902a560b
|
||||
github.com/rhnvrm/simples3 => github.com/devhaozi/simples3 v0.0.0-20260124160558-447c94ecedff
|
||||
github.com/stretchr/testify => github.com/libtnb/testify v0.0.0-20260103194301-c7a63ea79696
|
||||
github.com/mholt/acmez/v3 => github.com/libtnb/acmez/v3 v3.0.0-20260406165834-a264acd02292
|
||||
github.com/stretchr/testify => github.com/libtnb/testify v0.0.0-20260406170114-25da2dad39e7
|
||||
)
|
||||
|
||||
tool github.com/google/wire
|
||||
tool github.com/google/wire/cmd/wire
|
||||
|
||||
@@ -10,13 +10,13 @@ cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7
|
||||
cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
|
||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
code.pfad.fr/check v1.1.0 h1:GWvjdzhSEgHvEHe2uJujDcpmZoySKuHQNrZMfzfO0bE=
|
||||
code.pfad.fr/check v1.1.0/go.mod h1:NiUH13DtYsb7xp5wll0U4SXx7KhXQVCtRgdC96IPfoM=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
|
||||
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DeRuina/timberjack v1.3.9 h1:6UXZ1I7ExPGTX/1UNYawR58LlOJUHKBPiYC7WQ91eBo=
|
||||
github.com/DeRuina/timberjack v1.3.9/go.mod h1:RLoeQrwrCGIEF8gO5nV5b/gMD0QIy7bzQhBUgpp1EqE=
|
||||
github.com/G-Core/gcore-dns-sdk-go v0.3.3 h1:McILJSbJ5nOcT0MI0aBYhEuufCF329YbqKwFIN0RjCI=
|
||||
github.com/G-Core/gcore-dns-sdk-go v0.3.3/go.mod h1:35t795gOfzfVanhzkFyUXEzaBuMXwETmJldPpP28MN4=
|
||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||
@@ -24,11 +24,15 @@ github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/andybalholm/brotli v1.2.2 h1:HzTuoo2ErYQqf5qvcJInB8uvqSVxRttzkFexPWtnceM=
|
||||
github.com/andybalholm/brotli v1.2.2/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/bddjr/hlfhr v1.4.2 h1:ZkV42xi+jvI1goLAbkZHcY8Wxa2uBD1mK/JwL7o2LWw=
|
||||
github.com/bddjr/hlfhr v1.4.2/go.mod h1:oyIv4Q9JpCgZFdtH3KyTNWp7YYRWl4zl8k4ozrMAB4g=
|
||||
github.com/bddjr/hlfhr v1.6.1 h1:bzl0zsL2pl7Gvlbx6l8jZjjv9GbBTeOaX4/+RaXyNXc=
|
||||
github.com/bddjr/hlfhr v1.6.1/go.mod h1:cHRve//dit7d8ZCPUUFZAYW5WCm3LdMoiqX9i9GJdms=
|
||||
github.com/bddjr/shuttingdown v0.1.0 h1:1thUjnzTXNbzexEFkh638ebjln8F4KlqXfLIlBXfdbs=
|
||||
github.com/bddjr/shuttingdown v0.1.0/go.mod h1:+vG4Zp8uhFLT40DBABiA/XxJDHbzybe8RR72i29DFI4=
|
||||
github.com/beevik/ntp v1.5.0 h1:y+uj/JjNwlY2JahivxYvtmv4ehfi3h74fAuABB9ZSM4=
|
||||
github.com/beevik/ntp v1.5.0/go.mod h1:mJEhBrwT76w9D+IfOEGvuzyuudiW9E52U2BaTrMOYow=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
@@ -38,10 +42,14 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/boombuler/barcode v1.1.0 h1:ChaYjBR63fr4LFyGn8E8nt7dBSt3MiU3zMOZqFvVkHo=
|
||||
github.com/boombuler/barcode v1.1.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/boyter/go-string v1.0.5 h1:/xcOlWdgelLYLVkUU0xBLfioGjZ9KIMUMI/RXG138YY=
|
||||
github.com/boyter/go-string v1.0.5/go.mod h1:Mww9cDld2S2cdJ0tQffBhsZFMQRA2OJdcjWYZXvZ4Ss=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cilium/ebpf v0.22.0 h1:v2ktp0roffpMOj2MMf3idtCQZOsAoC4BJbAJN+ke2bY=
|
||||
github.com/cilium/ebpf v0.22.0/go.mod h1:CDzZbe2hC5JjlDC+CY3KFCzlYwN4gbxppYM+Z10bQt4=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
|
||||
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
|
||||
github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=
|
||||
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
|
||||
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
|
||||
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
|
||||
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
|
||||
@@ -59,51 +67,72 @@ github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfv
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dchest/captcha v1.1.0 h1:2kt47EoYUUkaISobUdTbqwx55xvKOJxyScVfw25xzhQ=
|
||||
github.com/dchest/captcha v1.1.0/go.mod h1:7zoElIawLp7GUMLcj54K9kbw+jEyvz2K0FDdRRYhvWo=
|
||||
github.com/devhaozi/simples3 v0.0.0-20260124160558-447c94ecedff h1:R8fAbRKWR+NVWIkjdK45CXS2cZzXQn8QuoM0Dij2Jso=
|
||||
github.com/devhaozi/simples3 v0.0.0-20260124160558-447c94ecedff/go.mod h1:c2xW30bukipkBlWNnXG1wDjq3gykQ6ww2AB/9NHMLMY=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
|
||||
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||
github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94=
|
||||
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
|
||||
github.com/docker/go-connections v0.7.0 h1:6SsRfJddP22WMrCkj19x9WKjEDTB+ahsdiGYf0mN39c=
|
||||
github.com/docker/go-connections v0.7.0/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q=
|
||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A=
|
||||
github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||
github.com/expr-lang/expr v1.17.7 h1:Q0xY/e/2aCIp8g9s/LGvMDCC5PxYlvHgDZRQ4y16JX8=
|
||||
github.com/expr-lang/expr v1.17.7/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/ebitengine/purego v0.10.0 h1:QIw4xfpWT6GWTzaW5XEKy3HXoqrJGx1ijYHzTF0/ISU=
|
||||
github.com/ebitengine/purego v0.10.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
|
||||
github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
||||
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
|
||||
github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
|
||||
github.com/fxamacker/cbor/v2 v2.9.2 h1:X4Ksno9+x3cz0TZv69ec1hxP/+tymuR8PXQJyDwfh78=
|
||||
github.com/fxamacker/cbor/v2 v2.9.2/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
|
||||
github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug=
|
||||
github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
|
||||
github.com/go-chi/httplog/v3 v3.3.0 h1:Gr6Y7nSzbpyCyRwKPOVKjDH3BH6TH5uvRNDsTZWDpvU=
|
||||
github.com/go-chi/httplog/v3 v3.3.0/go.mod h1:N/J1l5l1fozUrqIVuT8Z/HzNeSy8TF2EFyokPLe6y2w=
|
||||
github.com/go-chi/chi/v5 v5.3.1 h1:3j4HZLGZQ3JpMCrPJF/Jl3mYJfWLKBfNJ6quurUGCf8=
|
||||
github.com/go-chi/chi/v5 v5.3.1/go.mod h1:R+tYY2hNuVUUjxoPtqUdgBqevM9s9njzkTLutVsOCto=
|
||||
github.com/go-chi/httplog/v3 v3.4.0 h1:gO4fvt8HEtFwHq926HoKe1aV2DymfPJuZy4+U4zwT3I=
|
||||
github.com/go-chi/httplog/v3 v3.4.0/go.mod h1:tDhJo9G+F4mioDgX4pKbyA0uVZwCtHejoSsDkvJkFkU=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.5 h1:1OyorA5LtdQw12cyJDEHuTrEV3GiXiIhS4/QTTa/SM8=
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.5/go.mod h1:mj9ekk/7CPF3VjopaFvWKN2v7fN3D9d3eEOAXRhi/+M=
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.6 h1:VtX+l1Stj2v5RGubVQk0LS/8EPGXR+ldcOyCmlmKoyg=
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.6/go.mod h1:PZpedQc4tWaxn6kvXicwhinh3L0seLpMc5ReKRX5id4=
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 h1:CVLmWDhDVRa6Mi/IgCgaopNosCaHz7zrMeF9MlZRkrs=
|
||||
github.com/go-jose/go-jose/v4 v4.1.3/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
github.com/go-resty/resty/v2 v2.17.1 h1:x3aMpHK1YM9e4va/TMDRlusDDoZiQ+ViDu/WpA6xTM4=
|
||||
github.com/go-resty/resty/v2 v2.17.1/go.mod h1:kCKZ3wWmwJaNc7S29BRtUhJwy7iqmn+2mLtQrOyQlVA=
|
||||
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6 h1:teYtXy9B7y5lHTp8V9KPxpYRAVA7dozigQcMiBust1s=
|
||||
github.com/go-quicktest/qt v1.101.1-0.20240301121107-c6c8733fa1e6/go.mod h1:p4lGIVX+8Wa6ZPNDvqcxq36XpUDLh42FLetFU7odllI=
|
||||
github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw=
|
||||
github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/gofiber/schema v1.6.0 h1:rAgVDFwhndtC+hgV7Vu5ItQCn7eC2mBA4Eu1/ZTiEYY=
|
||||
github.com/gofiber/schema v1.6.0/go.mod h1:WNZWpQx8LlPSK7ZaX0OqOh+nQo/eW2OevsXs1VZfs/s=
|
||||
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
|
||||
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/go-webauthn/webauthn v0.17.4 h1:KFTSz3R2RYDiUn/0cDi3XTJgFenSG74eKTTHlqWhlxk=
|
||||
github.com/go-webauthn/webauthn v0.17.4/go.mod h1:pZk63EE/BdztlmyS4Yc+9H5g4a8blNlbtGmdHQHbZX8=
|
||||
github.com/go-webauthn/x v0.2.6 h1:TEyDuQAIiEgYpx60nKiBJIX/5nSUC8LxNbH+uf5U9uk=
|
||||
github.com/go-webauthn/x v0.2.6/go.mod h1:45bA7YEqyQhRcQJ/TiBb46Ww8yqHBGvgEhQ3WWF0aDo=
|
||||
github.com/gofiber/schema v1.8.2 h1:wq+LO2xEGlsqma/8Akp9PUebQ6vcsYmF0xYQ4F2ijvU=
|
||||
github.com/gofiber/schema v1.8.2/go.mod h1:iyAMJztdyky7Pk2U7bwUP3EHjzMqUNjZ/hglE0nYO/g=
|
||||
github.com/gofiber/utils/v2 v2.2.0 h1:YSSmCzQponq/f9uSOg2HtXC5qK1Dmor0o6DqaQVz8GE=
|
||||
github.com/gofiber/utils/v2 v2.2.0/go.mod h1:Ieopk6sQh7rbhQ12aBNCJtJuG0gxAg0nz63sFCrrOmE=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
@@ -120,26 +149,28 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
|
||||
github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba h1:qJEJcuLzH5KDR0gKc0zcktin6KSAwL7+jWKBYceddTc=
|
||||
github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba/go.mod h1:EFYHy8/1y2KfgTAsx7Luu7NGhoxtuVHnNo8jE7FikKc=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
|
||||
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
|
||||
github.com/google/wire v0.7.0/go.mod h1:n6YbUQD9cPKTnHXEBN2DXlOp/mVADhVErcMFb0v3J18=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/gookit/assert v0.1.1 h1:lh3GcawXe/p+cU7ESTZ5Ui3Sm/x8JWpIis4/1aF0mY0=
|
||||
github.com/gookit/assert v0.1.1/go.mod h1:jS5bmIVQZTIwk42uXl4lyj4iaaxx32tqH16CFj0VX2E=
|
||||
github.com/gookit/color v1.6.0 h1:JjJXBTk1ETNyqyilJhkTXJYYigHG24TM9Xa2M1xAhRA=
|
||||
github.com/gookit/color v1.6.0/go.mod h1:9ACFc7/1IpHGBW8RwuDm/0YEnhg3dwwXpoMsmtyHfjs=
|
||||
github.com/gookit/filter v1.2.3 h1:Zo7cBOtsVzAoa/jtf+Ury6zlsbJXqInFdUpbbnB2vMM=
|
||||
github.com/gookit/filter v1.2.3/go.mod h1:nFLJcOV8dRgS1iiX23gUQgmHUhpuS40qCvAGgIvA1pM=
|
||||
github.com/gookit/goutil v0.7.3 h1:nXDd/AB17nEjqVCNDGioDhVL/gVqdlqRMfFergKDjHE=
|
||||
github.com/gookit/goutil v0.7.3/go.mod h1:vJS9HXctYTCLtCsZot5L5xF+O1oR17cDYO9R0HxBmnU=
|
||||
github.com/gookit/validate v1.5.7-0.20260207022141-dc32dc1276cd h1:J6cF+xLHI6ZSPBB/XMLj9xbmWuUGw5Vxbs0wOaZ5HOo=
|
||||
github.com/gookit/validate v1.5.7-0.20260207022141-dc32dc1276cd/go.mod h1:2PY9IRPsKFS6brOHv6PKhZeuUD99Mh3BimDlOOXnGBg=
|
||||
github.com/gookit/color v1.6.1 h1:KoTnDxJPRgrL0SoX0f8rCFg2zI0t4E3GZZBMo2nN8LU=
|
||||
github.com/gookit/color v1.6.1/go.mod h1:9ACFc7/1IpHGBW8RwuDm/0YEnhg3dwwXpoMsmtyHfjs=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
@@ -157,11 +188,14 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
|
||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-version v1.8.0 h1:KAkNb1HAiZd1ukkxDFGmokVZe1Xy9HG6NUp+bPle2i4=
|
||||
github.com/hashicorp/go-version v1.8.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA=
|
||||
github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||
@@ -179,14 +213,16 @@ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
|
||||
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
|
||||
github.com/jsimonetti/rtnetlink/v2 v2.0.1 h1:xda7qaHDSVOsADNouv7ukSuicKZO7GgVUCXxpaIEIlM=
|
||||
github.com/jsimonetti/rtnetlink/v2 v2.0.1/go.mod h1:7MoNYNbb3UaDHtF8udiJo/RH6VsTKP1pqKLUTVCvToE=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
|
||||
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
@@ -200,18 +236,22 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leonelquinteros/gotext v1.7.2 h1:bDPndU8nt+/kRo1m4l/1OXiiy2v7Z7dfPQ9+YP7G1Mc=
|
||||
github.com/leonelquinteros/gotext v1.7.2/go.mod h1:9/haCkm5P7Jay1sxKDGJ5WIg4zkz8oZKw4ekNpALob8=
|
||||
github.com/lib/pq v1.11.1 h1:wuChtj2hfsGmmx3nf1m7xC2XpK6OtelS2shMY+bGMtI=
|
||||
github.com/lib/pq v1.11.1/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
|
||||
github.com/libdns/alidns v1.0.6-beta.3.0.20260121104221-597b1e580e21 h1:BGtptgrEJGjDQz63r4xkcQ/2ERXpna9WVUtrTtmW8d0=
|
||||
github.com/libdns/alidns v1.0.6-beta.3.0.20260121104221-597b1e580e21/go.mod h1:RECwyQ88e9VqQVtSrvX76o1ux3gQUKGzMgxICi+u7Ec=
|
||||
github.com/letsencrypt/challtestsrv v1.4.2 h1:0ON3ldMhZyWlfVNYYpFuWRTmZNnyfiL9Hh5YzC3JVwU=
|
||||
github.com/letsencrypt/challtestsrv v1.4.2/go.mod h1:GhqMqcSoeGpYd5zX5TgwA6er/1MbWzx/o7yuuVya+Wk=
|
||||
github.com/letsencrypt/pebble/v2 v2.10.0 h1:Wq6gYXlsY6ubqI3hhxsTzdyotvfdjFBxuwYqCLCnj/U=
|
||||
github.com/letsencrypt/pebble/v2 v2.10.0/go.mod h1:Sk8cmUIPcIdv2nINo+9PB4L+ZBhzY+F9A1a/h/xmWiQ=
|
||||
github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ=
|
||||
github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
|
||||
github.com/libdns/alidns v1.0.7 h1:0BhTUFlWIUyb5U7wujGqsyoeZkleUR/hMCtdZDS8Oc8=
|
||||
github.com/libdns/alidns v1.0.7/go.mod h1:RECwyQ88e9VqQVtSrvX76o1ux3gQUKGzMgxICi+u7Ec=
|
||||
github.com/libdns/cloudflare v0.2.2 h1:XWHv+C1dDcApqazlh08Q6pjytYLgR2a+Y3xrXFu0vsI=
|
||||
github.com/libdns/cloudflare v0.2.2/go.mod h1:w9uTmRCDlAoafAsTPnn2nJ0XHK/eaUMh86DUk8BWi60=
|
||||
github.com/libdns/cloudns v1.1.0 h1:W+1MadtxKySn3b5RITFTsXgTIvr5VoO5x97cewjlDcs=
|
||||
github.com/libdns/cloudns v1.1.0/go.mod h1:/22V6tYYDALDpM4pw/RGGJ+X2F1Luibty9kKpKvkqBM=
|
||||
github.com/libdns/cloudns v1.2.0 h1:V299bWj6HHTsXSzoEkRsKNBb9V/HGj3zp4OYzJ31JX8=
|
||||
github.com/libdns/cloudns v1.2.0/go.mod h1:zKx/cXy9W3f4bGjbEtOx+B435flBrz1uibNr3h27+aU=
|
||||
github.com/libdns/gcore v0.0.0-20250427050847-9964da923833 h1:/gsawtsq03cI7qgK65v16tYHIh40omL9YEzHWqnc63I=
|
||||
github.com/libdns/gcore v0.0.0-20250427050847-9964da923833/go.mod h1:jZJEV7pCTOJFlaUhHty+YwR05dzoSmInXK/vT3wOeVg=
|
||||
github.com/libdns/huaweicloud v1.0.0 h1:BQUIkOAjF++ouiANRIE3jdMlCfeiAAr6tGqb+8hM1jo=
|
||||
github.com/libdns/huaweicloud v1.0.0/go.mod h1:W+XywkW+C93fM50Ayklf6KuoCHZTqbrmFUEtpQnVvcU=
|
||||
github.com/libdns/huaweicloud v1.0.1 h1:TdfpPY//3/QPhEGCyvR8u2DTlGxzpyaIsqofH5kYFyA=
|
||||
github.com/libdns/huaweicloud v1.0.1/go.mod h1:lMHNSEqLZeuE4N28ytaqLZia3NPuaaz1ldAH/73bOQE=
|
||||
github.com/libdns/libdns v1.1.1 h1:wPrHrXILoSHKWJKGd0EiAVmiJbFShguILTg9leS/P/U=
|
||||
github.com/libdns/libdns v1.1.1/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
|
||||
github.com/libdns/namesilo v1.0.0 h1:Shwbj9YnSp4NR617sBOSfDkFozEnWInWCxNwrDvPkCg=
|
||||
@@ -222,29 +262,49 @@ github.com/libdns/tencentcloud v1.4.3 h1:xJHYLL1TdPeOtUr6Bu6dHTd1TU6/VFm7BFc2EAz
|
||||
github.com/libdns/tencentcloud v1.4.3/go.mod h1:Be9gY3tDa12DuAPU79RV9NZIcjY6qg5s7zKPsP26yAM=
|
||||
github.com/libdns/westcn v1.0.2 h1:PA2M3tME5/0T3klPMzSHvGk1EWnGNNkJiKxaJjFalnM=
|
||||
github.com/libdns/westcn v1.0.2/go.mod h1:iKpk8jjOU+793Yp8nHoihPTCR6N1KWtm4/r8BB9mVnk=
|
||||
github.com/libtnb/acmez/v3 v3.0.0-20260103184942-a835890fc93e h1:HPHmtFcR5VpTJTpDqG4+l16uJfSlpB/X0r3qq22znrk=
|
||||
github.com/libtnb/acmez/v3 v3.0.0-20260103184942-a835890fc93e/go.mod h1:L1wOU06KKvq7tswuMDwKdcHeKpFFgkppZy/y0DFxagQ=
|
||||
github.com/libtnb/chix v1.3.2 h1:LkA/+OaHeMyTiQoWEcCQKAMSKDZ0LxBXSENQO5d+OKk=
|
||||
github.com/libtnb/chix v1.3.2/go.mod h1:ItssStBa/ov7v4qujyYzORqIf7Z6DO7Q4carOM7pyAQ=
|
||||
github.com/libtnb/gormstore v1.1.1 h1:FG/3P4PuWM6/vB4weVJ31meiSaoeXns1NQlP66quKeg=
|
||||
github.com/libtnb/gormstore v1.1.1/go.mod h1:8A5QzeZxi1MpSmjUVsHTDAL6KnU84feIXMutFLPawwA=
|
||||
github.com/libtnb/moby/client v0.0.0-20260127104057-d4b7902a560b h1:73OlJdl4Zk6Ipnm7KKeE6yCjfd7nk0BhTArujx6WJCU=
|
||||
github.com/libtnb/moby/client v0.0.0-20260127104057-d4b7902a560b/go.mod h1:bBQRIiaGR9EZBC+x5hnwunNgcDOts7E1Oa7AowJwMFU=
|
||||
github.com/libtnb/securecookie v1.2.0 h1:2uc0PBDm0foeSTrcZ9QTX1IEjf6kFEwfgEYSIXQSKrA=
|
||||
github.com/libtnb/securecookie v1.2.0/go.mod h1:ja+wNGnQzYqcqXQnJWu6icsaWi5JEBwNEMJ2ReTVDxA=
|
||||
github.com/libtnb/sessions v1.2.2 h1:VTTzzeBDJEkJbaPaIU9C4bRj2oAqD0rgQ7UHFkkaNT4=
|
||||
github.com/libtnb/sessions v1.2.2/go.mod h1:qw+FWtBtrPDYCf6MfX0Lk5EhTArpvT72z5Ei4RUMTRg=
|
||||
github.com/libtnb/testify v0.0.0-20260103194301-c7a63ea79696 h1:GN0Y3DG27mMruX536k0jtCSLegjJb/gypzj5gZL6tRI=
|
||||
github.com/libtnb/testify v0.0.0-20260103194301-c7a63ea79696/go.mod h1:HeQeTfKU6tj2Lx1z79UacwYeDioo6M4ZD7BDDI6+rrg=
|
||||
github.com/libtnb/utils v1.2.1 h1:LJmReRREnpqfHyy9PZtNgBh3ZaIGct81b8ZaAsolMkM=
|
||||
github.com/libtnb/utils v1.2.1/go.mod h1:o6LEDeC42PXI21uLWdWJWTVYvR9BtAZfzzTGJVQoQiU=
|
||||
github.com/libtnb/acmez/v3 v3.0.0-20260406165834-a264acd02292 h1:FF1ZlwFFjpwT6CtBodr/NV4OMJPMC7plTmfzqhXrlSk=
|
||||
github.com/libtnb/acmez/v3 v3.0.0-20260406165834-a264acd02292/go.mod h1:5nTPosTGosLxF3+LU4ygbgMRFDhbAVpqMI4+a4aHLBY=
|
||||
github.com/libtnb/chix/v2 v2.1.1 h1:QQwHXUyPaUUp/KOwzXf2NB0IRKb9v2pqIdOIItzBPiE=
|
||||
github.com/libtnb/chix/v2 v2.1.1/go.mod h1:OEY9v0976U/IJzP6n8VdhgXH17VL2muo3EQWsIUyxm8=
|
||||
github.com/libtnb/cron v0.5.2 h1:Yy9a/S82bAS4KzE1SSMjNLtigPkejgMPUp9BHGeb1pw=
|
||||
github.com/libtnb/cron v0.5.2/go.mod h1:nrOHxS4Ernkn1E//vs64xzC58hGfoL0+lYSW2zsROGI=
|
||||
github.com/libtnb/gormstore v1.3.0 h1:OvVTYHZ9MCHI3Anf2ITtJLunAefyBQWG96EmHCE0eLM=
|
||||
github.com/libtnb/gormstore v1.3.0/go.mod h1:Z/n6VlVdLPmvunSM8sYGNHVebTTN5yUSTZsyNxW2IZc=
|
||||
github.com/libtnb/logrotate v0.1.2 h1:q9FLtYQYtzAlOB9bs91nPppqt3GNTUOonrBOivrtiOc=
|
||||
github.com/libtnb/logrotate v0.1.2/go.mod h1:yqC9N3C5mg0fBlquK+cWLB7xG5plQrP0ma84hMRj3ic=
|
||||
github.com/libtnb/securecookie v1.4.0 h1:SkKHO7T5I4aRGV7/6fnYYsleQDnnDzeAmTDA0GMPD98=
|
||||
github.com/libtnb/securecookie v1.4.0/go.mod h1:mg1i9HfstsYBGwCfQdU+3Z1GuieyZRAxbkFUnrzchJU=
|
||||
github.com/libtnb/sessions v1.5.0 h1:gvTRkSR8lpp1PB0Nms/kc+gh1BwJ411fxLjnZLYItLs=
|
||||
github.com/libtnb/sessions v1.5.0/go.mod h1:/Q/+lO7DcnJJEU1nL59ScPV/V8ct34F8BjoEMwwxjRw=
|
||||
github.com/libtnb/sqlite v1.2.1 h1:lrhN3yG49pj1gmtMMP6Es0lhKIkzDeqBul2EWOLyjpY=
|
||||
github.com/libtnb/sqlite v1.2.1/go.mod h1:pGq13BirCjkM6ihkWWxs0PGFhBiwUyA0PqdSmgDWfmM=
|
||||
github.com/libtnb/testify v0.0.0-20260406170114-25da2dad39e7 h1:ZzONsNhw69uC/wJQlMj66n1zfsRgKAElfJ//E9G380U=
|
||||
github.com/libtnb/testify v0.0.0-20260406170114-25da2dad39e7/go.mod h1:HeQeTfKU6tj2Lx1z79UacwYeDioo6M4ZD7BDDI6+rrg=
|
||||
github.com/libtnb/utils v1.2.2 h1:HUqgAIb+TIrZPXRytYB5XqzkEXG2U4a4/ZGpprNtL5A=
|
||||
github.com/libtnb/utils v1.2.2/go.mod h1:KUCx2+Phw3cLXOwuQDy6XwFOliaYuU1rpAuJQuHf+lQ=
|
||||
github.com/libtnb/validator v0.4.1 h1:TYDC1C1yp93d02huzCqEc1aU/u5PAtC3jqGPtEdZchU=
|
||||
github.com/libtnb/validator v0.4.1/go.mod h1:j08Lydxwy7ModkoKeYIHxvZvAtnzzdE8xi2J+SGVrgc=
|
||||
github.com/libtnb/validator/contrib/openapi v0.2.0 h1:y47A16Lqtkc9/uifRIJ2XC+Rkgghj2fmHPrclcPXPtA=
|
||||
github.com/libtnb/validator/contrib/openapi v0.2.0/go.mod h1:2vCdRniTmXWBtG4gro9B7s6ko4v3WdoSKjvhsWdTn3g=
|
||||
github.com/lufia/plan9stats v0.0.0-20251013123823-9fd1530e3ec3 h1:PwQumkgq4/acIiZhtifTV5OUqqiP82UAl0h87xj/l9k=
|
||||
github.com/lufia/plan9stats v0.0.0-20251013123823-9fd1530e3ec3/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs=
|
||||
github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
|
||||
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
|
||||
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
|
||||
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
|
||||
github.com/medama-io/go-useragent v1.2.4 h1:kDux3lCjZvBpccKus/goaZl6YMnrl9D8Tx/wb4HqRMI=
|
||||
github.com/medama-io/go-useragent v1.2.4/go.mod h1:H9GYWth4IN8vAFZh5LeARza7VwM4jK9uk7Tb9huVzLw=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
|
||||
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
@@ -255,17 +315,15 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
||||
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
||||
github.com/moby/moby/api v1.53.0 h1:PihqG1ncw4W+8mZs69jlwGXdaYBeb5brF6BL7mPIS/w=
|
||||
github.com/moby/moby/api v1.53.0/go.mod h1:8mb+ReTlisw4pS6BRzCMts5M49W5M7bKt1cJy/YbAqc=
|
||||
github.com/moby/moby/api v1.55.0 h1:2/sexvQyqIWS8pRSCFddBfpW2qE7vR7FCL+vN8pxwMc=
|
||||
github.com/moby/moby/api v1.55.0/go.mod h1:+RQ6wluLwtYaTd1WnPLykIDPekkuyD/ROWQClE83pzs=
|
||||
github.com/moby/moby/client v0.5.1 h1:tYNaJno4c0HXz12y5BiqEDy0rVTYkWzI26lGvnTMiJw=
|
||||
github.com/moby/moby/client v0.5.1/go.mod h1:odLstlZ6uSnfvAgVxMpvgmb8SUdd+siH2T0GBuxVAlM=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/ncruces/go-sqlite3 v0.30.5 h1:6usmTQ6khriL8oWilkAZSJM/AIpAlVL2zFrlcpDldCE=
|
||||
github.com/ncruces/go-sqlite3 v0.30.5/go.mod h1:0I0JFflTKzfs3Ogfv8erP7CCoV/Z8uxigVDNOR0AQ5E=
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.30.2 h1:FZ8mic14xTatssTkHCrelh9nPeFdXuzgMoNGkfuFbBU=
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.30.2/go.mod h1:W9WLBbqrrOIh2dqFZkeC/xKALG2LDIHY91jowahOdtI=
|
||||
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
|
||||
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
|
||||
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||
@@ -275,12 +333,16 @@ github.com/orandin/slog-gorm v1.4.0 h1:FgA8hJufF9/jeNSYoEXmHPPBwET2gwlF3B85JdpsT
|
||||
github.com/orandin/slog-gorm v1.4.0/go.mod h1:MoZ51+b7xE9lwGNPYEhxcUtRNrYzjdcKvA8QXQQGEPA=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
|
||||
github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
|
||||
github.com/pkg/sftp v1.13.10 h1:+5FbKNTe5Z9aspU88DPIKJ9z2KZoaGCu6Sr6kKR/5mU=
|
||||
github.com/pkg/sftp v1.13.10/go.mod h1:bJ1a7uDhrX/4OII+agvy28lzRvQrmIQuaHrcI1HbeGA=
|
||||
github.com/pkg/sftp v1.13.11 h1:0N92SLTB8JqASJB14ZLHHzFnBV8mG9zw4K7jghEFWuE=
|
||||
github.com/pkg/sftp v1.13.11/go.mod h1:uNkH9roSXglNJqM+glJJi+TQXQUm0fXFWqCFmT8hsN0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
|
||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||
@@ -295,21 +357,27 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/richardlehane/mscfb v1.0.7 h1:oeoiM0WE79vHwE8RpIYYvIAc8ajTH2mb6UZm55/+EB0=
|
||||
github.com/richardlehane/mscfb v1.0.7/go.mod h1:pe0+IUIc0AHh0+teNzBlJCtSyZdFOGgV4ZK9bsoV+Jo=
|
||||
github.com/richardlehane/msoleps v1.0.6 h1:9BvkpjvD+iUBalUY4esMwv6uBkfOip/Lzvd93jvR9gg=
|
||||
github.com/richardlehane/msoleps v1.0.6/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw=
|
||||
github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
|
||||
github.com/samber/lo v1.53.0 h1:t975lj2py4kJPQ6haz1QMgtId2gtmfktACxIXArw3HM=
|
||||
github.com/samber/lo v1.53.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sethvargo/go-limiter v1.1.0 h1:eLeZVQ2zqJOiEs03GguqmBVG6/T6lsZB+6PP1t7J6fA=
|
||||
github.com/sethvargo/go-limiter v1.1.0/go.mod h1:01b6tW25Ap+MeLYBuD4aHunMrJoNO5PVUFdS9rac3II=
|
||||
github.com/shirou/gopsutil/v4 v4.26.1 h1:TOkEyriIXk2HX9d4isZJtbjXbEjf5qyKPAzbzY0JWSo=
|
||||
github.com/shirou/gopsutil/v4 v4.26.1/go.mod h1:medLI9/UNAb0dOI9Q3/7yWSqKkj00u+1tgY8nvv41pc=
|
||||
github.com/sethvargo/go-limiter v1.2.0 h1:XKL1vsaQ2zztVJrnZSzpRWCq/aLQqMllJ/3D/0bt/cw=
|
||||
github.com/sethvargo/go-limiter v1.2.0/go.mod h1:RC+qY2R7PAK81mBCrZEJlUlKnXSIqqQ8B7G44UgZ/1E=
|
||||
github.com/shamaton/msgpack/v3 v3.2.0 h1:1q2Ms+MWmuRju+PuDMSFDB7p7621npeX4zprJN5Zck8=
|
||||
github.com/shamaton/msgpack/v3 v3.2.0/go.mod h1:sgBYvEiyz8JR1NC3yGRoPVME9xXovpnh3l/plW1nfRo=
|
||||
github.com/shirou/gopsutil/v4 v4.26.6 h1:Mzr/npDtQC/xpeEuQKHZt8Zo9CmPvhTj8nkR8w5TLDs=
|
||||
github.com/shirou/gopsutil/v4 v4.26.6/go.mod h1:LZ6ewCSkBqUpvSOf+LsTGnRinC6iaNUNMGBtDkJBaLQ=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
@@ -329,11 +397,11 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4=
|
||||
github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0=
|
||||
github.com/studio-b12/gowebdav v0.12.0 h1:kFRtQECt8jmVAvA6RHBz3geXUGJHUZA6/IKpOVUs5kM=
|
||||
github.com/studio-b12/gowebdav v0.12.0/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE=
|
||||
github.com/studio-b12/gowebdav v0.13.0 h1:OcwSg6IQHOFNdYHn3bPOHwSE8looG8N56Y5xTT1asqQ=
|
||||
github.com/studio-b12/gowebdav v0.13.0/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
|
||||
github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
|
||||
github.com/tiendc/go-deepcopy v1.7.2 h1:Ut2yYR7W9tWjTQitganoIue4UGxZwCcJy3orjrrIj44=
|
||||
github.com/tiendc/go-deepcopy v1.7.2/go.mod h1:4bKjNC2r7boYOkD2IOuZpYjmlDdzjbpTRyCx+goBCJQ=
|
||||
github.com/timtadh/data-structures v0.5.3/go.mod h1:9R4XODhJ8JdWFEI8P/HJKqxuJctfBQw6fDibMQny2oU=
|
||||
github.com/timtadh/data-structures v0.6.1/go.mod h1:uYUnI1cQi/5yMCc7s23I+x8Mn8BCMf4WgK+7/4QSEk4=
|
||||
github.com/timtadh/data-structures v0.6.2 h1:zybDnU5NLjJ7WKMDJpvVwczQuf1wSLBgdRHZ9O4AqJ0=
|
||||
@@ -342,45 +410,79 @@ github.com/timtadh/getopt v1.0.0/go.mod h1:L3EL6YN2G0eIAhYBo9b7SB9d/kEQmdnwthIlM
|
||||
github.com/timtadh/lexmachine v0.2.2/go.mod h1:GBJvD5OAfRn/gnp92zb9KTgHLB7akKyxmVivoYCcjQI=
|
||||
github.com/timtadh/lexmachine v0.2.3 h1:ZqlfHnfMcAygtbNM5Gv7jQf8hmM8LfVzDjfCrq235NQ=
|
||||
github.com/timtadh/lexmachine v0.2.3/go.mod h1:oK1NW+93fQSIF6s+J6sXBFWsCPCFbNmrwKV1i0aqvW0=
|
||||
github.com/tinylib/msgp v1.6.4 h1:mOwYbyYDLPj35mkA2BjjYejgJk9BuHxDdvRnb6v2ZcQ=
|
||||
github.com/tinylib/msgp v1.6.4/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
|
||||
github.com/tklauser/go-sysconf v0.3.16 h1:frioLaCQSsF5Cy1jgRBrzr6t502KIIwQ0MArYICU0nA=
|
||||
github.com/tklauser/go-sysconf v0.3.16/go.mod h1:/qNL9xxDhc7tx3HSRsLWNnuzbVfh3e7gh/BmM179nYI=
|
||||
github.com/tklauser/numcpus v0.11.0 h1:nSTwhKH5e1dMNsCdVBukSZrURJRoHbSEQjdEbY+9RXw=
|
||||
github.com/tklauser/numcpus v0.11.0/go.mod h1:z+LwcLq54uWZTX0u/bGobaV34u6V7KNlTZejzM6/3MQ=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/tufanbarisyildirim/gonginx v0.0.0-20250620092546-c3e307e36701 h1:JgeHIJzRSEdcuLXufZrni5+a4yDnBhQG+DdKhqCFhq0=
|
||||
github.com/tufanbarisyildirim/gonginx v0.0.0-20250620092546-c3e307e36701/go.mod h1:ALbEe81QPWOZjDKCKNWodG2iqCMtregG8+ebQgjx2+4=
|
||||
github.com/urfave/cli/v3 v3.6.2 h1:lQuqiPrZ1cIz8hz+HcrG0TNZFxU70dPZ3Yl+pSrH9A8=
|
||||
github.com/urfave/cli/v3 v3.6.2/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
github.com/tufanbarisyildirim/gonginx v0.0.0-20260220081509-8e17ce617db3 h1:ClWHRIz18WRVT3RD9y9uTwEWU9eEi+VYFEIumg05FLk=
|
||||
github.com/tufanbarisyildirim/gonginx v0.0.0-20260220081509-8e17ce617db3/go.mod h1:ALbEe81QPWOZjDKCKNWodG2iqCMtregG8+ebQgjx2+4=
|
||||
github.com/urfave/cli/v3 v3.10.1 h1:7Kx9H50hrHbRbyxgO1KP6/BcbiGRz0uYh5YyQ30JEEY=
|
||||
github.com/urfave/cli/v3 v3.10.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
github.com/valyala/fastjson v1.6.10 h1:/yjJg8jaVQdYR3arGxPE2X5z89xrlhS0eGXdv+ADTh4=
|
||||
github.com/valyala/fastjson v1.6.10/go.mod h1:e6FubmQouUNP73jtMLmcbxS6ydWIpOfhz34TSfO3JaE=
|
||||
github.com/wneessen/go-mail v0.8.1 h1:tVcncj02/QySVFw3zr/kXOzZcuFQqBNT6K+Rbgm/pcM=
|
||||
github.com/wneessen/go-mail v0.8.1/go.mod h1:dWZ61zadzCIyvB4y1/YzC5O7MrbbzBfPkARmbosdf8w=
|
||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
github.com/xuri/efp v0.0.1 h1:fws5Rv3myXyYni8uwj2qKjVaRP30PdjeYe2Y6FDsCL8=
|
||||
github.com/xuri/efp v0.0.1/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
|
||||
github.com/xuri/excelize/v2 v2.11.0 h1:HxaEFl6sRN2+8J5a8HaKq+0M4FsjBGMnWWtjOCPSG88=
|
||||
github.com/xuri/excelize/v2 v2.11.0/go.mod h1:jxFLbzaIwGQ5ufFNvYfUOHqXhfPaNmP14KWfmNz2Uak=
|
||||
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 h1:+C0TIdyyYmzadGaL/HBLbf3WdLgC29pgyhTjAT/0nuE=
|
||||
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 h1:sbiXRNDSWJOTobXh5HyQKjq6wUC5tNybqjIqDpAY4CU=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0/go.mod h1:69uWxva0WgAA/4bu2Yy70SLDBwZXuQ6PbBpbsa5iZrQ=
|
||||
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
|
||||
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
|
||||
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
|
||||
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
|
||||
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
|
||||
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
|
||||
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
|
||||
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
|
||||
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
|
||||
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
|
||||
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
|
||||
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 h1:Z/6YuSHTLOHfNFdb8zVZomZr7cqNgTJvA8+Qz75D8gU=
|
||||
golang.org/x/exp v0.0.0-20260112195511-716be5621a96/go.mod h1:nzimsREAkjBCIEFtHiYkrJyT+2uy9YZJB7H1k68CXZU=
|
||||
golang.org/x/exp v0.0.0-20260603202125-055de637280b h1:v1uXiEBHo8QA0LiGCo7UgHMzHT4Kdfpl2zmtH5vaP1Q=
|
||||
golang.org/x/exp v0.0.0-20260603202125-055de637280b/go.mod h1:d2fgXJLVs4dYDHUk5lwMIfzRzSrWCfGZb0ZqeLa/Vcw=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.38.0 h1:5l+q+Y9JDC7mBOMjo4/aPhMDcxEptsX+Tt3GgRQRPuE=
|
||||
golang.org/x/image v0.38.0/go.mod h1:/3f6vaXC+6CEanU4KJxbcUZyEePbyKbaLoDOe4ehFYY=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@@ -392,6 +494,8 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
|
||||
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -406,8 +510,8 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
||||
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
|
||||
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@@ -416,8 +520,8 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
|
||||
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -434,20 +538,18 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
|
||||
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0=
|
||||
golang.org/x/term v0.45.0/go.mod h1:9aqxs0blBcrm/n0L9QW0aRVD+ktan8ssZromtqJC43w=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
|
||||
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
|
||||
golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs=
|
||||
golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
||||
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -465,6 +567,8 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn
|
||||
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q=
|
||||
golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||
@@ -498,14 +602,46 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
|
||||
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
|
||||
gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ=
|
||||
gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8=
|
||||
gorm.io/gorm v1.31.2 h1:3o8FXNo9v9S858gil+3LlZA1LkCOzgb4g5BL64FgaCo=
|
||||
gorm.io/gorm v1.31.2/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
|
||||
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
||||
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
modernc.org/cc/v4 v4.29.0 h1:CXgwL8cvxmyzBQZzbSl/6xFtMCryb6u8IOqDci39cgc=
|
||||
modernc.org/cc/v4 v4.29.0/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
|
||||
modernc.org/ccgo/v4 v4.34.6 h1:sBgfIwyN0TQ9C5hwIeuqyeAKyMWnbvj2fvpF4L11uzU=
|
||||
modernc.org/ccgo/v4 v4.34.6/go.mod h1:SZ8YcN9NG7XVsQYdm6jYBvi8PQP1qi+kqB6OhjqI3Fk=
|
||||
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
|
||||
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
|
||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||
modernc.org/gc/v3 v3.1.4 h1:2g65LGVSmFQrXeITAw97x7hCRvZFcyE1uDP+7Vng7JI=
|
||||
modernc.org/gc/v3 v3.1.4/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||
modernc.org/libc v1.74.1 h1:bdR4VTKFMC4966QSNZ05XLGI/VwzVa2kTUX51Dm0riQ=
|
||||
modernc.org/libc v1.74.1/go.mod h1:uH4t5bOx3G3g9Xcmj10YKlTcVISlRDwv8VoQJG9n8Os=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
|
||||
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.55.0 h1:hIFh0MCH0rGinQ/4KYb5/UbCkRkb+UP+OkLCVWa5MTM=
|
||||
modernc.org/sqlite v1.55.0/go.mod h1:4ntCLuNmnH8+GNqjka1wNg7KJd5/Hi5FYp8K+XQ7GZw=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
|
||||
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
|
||||
resty.dev/v3 v3.0.0-rc.3 h1:k24LZ03Cb4Ue5e6O/Pfxu5TQRBBYGES6wm2wceia+Io=
|
||||
resty.dev/v3 v3.0.0-rc.3/go.mod h1:NTOerrC/4T7/FE6tXIZGIysXXBdgNqwMZuKtxpea9NM=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
|
||||
+35
-27
@@ -7,38 +7,39 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/bddjr/hlfhr"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"github.com/gookit/validate"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/libtnb/cron"
|
||||
|
||||
"github.com/acepanel/panel/pkg/config"
|
||||
"github.com/acepanel/panel/pkg/queue"
|
||||
"github.com/acepanel/panel/v3/pkg/config"
|
||||
"github.com/acepanel/panel/v3/pkg/tlscert"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type Ace struct {
|
||||
conf *config.Config
|
||||
router *chi.Mux
|
||||
server *hlfhr.Server
|
||||
reloader *tlscert.Reloader
|
||||
migrator *gormigrate.Gormigrate
|
||||
cron *cron.Cron
|
||||
queue *queue.Queue
|
||||
runner types.TaskRunner
|
||||
}
|
||||
|
||||
func NewAce(conf *config.Config, router *chi.Mux, server *hlfhr.Server, migrator *gormigrate.Gormigrate, cron *cron.Cron, queue *queue.Queue, _ *validate.Validation) *Ace {
|
||||
func NewAce(router *chi.Mux, conf *config.Config, cron *cron.Cron, migrator *gormigrate.Gormigrate, server *hlfhr.Server, reloader *tlscert.Reloader, runner types.TaskRunner) (*Ace, error) {
|
||||
return &Ace{
|
||||
conf: conf,
|
||||
router: router,
|
||||
server: server,
|
||||
reloader: reloader,
|
||||
migrator: migrator,
|
||||
cron: cron,
|
||||
queue: queue,
|
||||
}
|
||||
runner: runner,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Ace) Run() error {
|
||||
@@ -49,15 +50,17 @@ func (r *Ace) Run() error {
|
||||
fmt.Println("[DB] database migrated")
|
||||
|
||||
// start cron scheduler
|
||||
r.cron.Start()
|
||||
if err := r.cron.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("[CRON] cron scheduler started")
|
||||
|
||||
// create context for queue
|
||||
queueCtx, queueCancel := context.WithCancel(context.Background())
|
||||
defer queueCancel()
|
||||
// create context for runner
|
||||
runnerCtx, runnerCancel := context.WithCancel(context.Background())
|
||||
defer runnerCancel()
|
||||
|
||||
// start queue
|
||||
r.queue.Run(queueCtx)
|
||||
// start task runner
|
||||
r.runner.Run(runnerCtx)
|
||||
|
||||
// setup graceful shutdown
|
||||
quit := make(chan os.Signal, 1)
|
||||
@@ -66,15 +69,12 @@ func (r *Ace) Run() error {
|
||||
// run http server in goroutine
|
||||
serverErr := make(chan error, 1)
|
||||
go func() {
|
||||
if r.conf.HTTP.TLS {
|
||||
cert := filepath.Join(Root, "panel/storage/cert.pem")
|
||||
key := filepath.Join(Root, "panel/storage/cert.key")
|
||||
fmt.Println("[HTTP] listening and serving on port", r.conf.HTTP.Port, "with tls")
|
||||
if err := r.server.ListenAndServeTLS(cert, key); !errors.Is(err, http.ErrServerClosed) {
|
||||
fmt.Println("[HTTP] listening and serving on port", r.conf.HTTP.Port)
|
||||
if r.conf.HTTP.IsHTTPS() {
|
||||
if err := r.server.ListenAndServeTLS("", ""); !errors.Is(err, http.ErrServerClosed) {
|
||||
serverErr <- err
|
||||
}
|
||||
} else {
|
||||
fmt.Println("[HTTP] listening and serving on port", r.conf.HTTP.Port)
|
||||
if err := r.server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
|
||||
serverErr <- err
|
||||
}
|
||||
@@ -89,20 +89,28 @@ func (r *Ace) Run() error {
|
||||
return err
|
||||
}
|
||||
case sig := <-quit:
|
||||
fmt.Println("\n[APP] received signal:", sig)
|
||||
fmt.Println("[APP] received signal:", sig)
|
||||
}
|
||||
|
||||
// graceful shutdown
|
||||
fmt.Println("[APP] shutting down gracefully...")
|
||||
|
||||
// stop cron scheduler
|
||||
ctx := r.cron.Stop()
|
||||
<-ctx.Done()
|
||||
cronCtx, cronCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
_ = r.cron.Stop(cronCtx)
|
||||
cronCancel()
|
||||
fmt.Println("[CRON] cron scheduler stopped")
|
||||
|
||||
// stop queue
|
||||
queueCancel()
|
||||
fmt.Println("[QUEUE] queue stopped")
|
||||
// stop task runner
|
||||
runnerCancel()
|
||||
fmt.Println("[QUEUE] task runner stopped")
|
||||
|
||||
// close certificate reloader
|
||||
if r.reloader != nil {
|
||||
if err := r.reloader.Close(); err != nil {
|
||||
fmt.Println("[TLS] certificate reloader close error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// shutdown http server
|
||||
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
||||
+4
-10
@@ -5,10 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"github.com/gookit/color"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"github.com/acepanel/panel/pkg/apploader"
|
||||
)
|
||||
|
||||
type Cli struct {
|
||||
@@ -16,12 +13,12 @@ type Cli struct {
|
||||
migrator *gormigrate.Gormigrate
|
||||
}
|
||||
|
||||
func NewCli(cmd *cli.Command, migrator *gormigrate.Gormigrate, _ *apploader.Loader) *Cli {
|
||||
func NewCli(cmd *cli.Command, migrator *gormigrate.Gormigrate) (*Cli, error) {
|
||||
IsCli = true
|
||||
return &Cli{
|
||||
cmd: cmd,
|
||||
migrator: migrator,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Cli) Run() error {
|
||||
@@ -29,9 +26,6 @@ func (r *Cli) Run() error {
|
||||
// 这里不处理错误,这么做是为了在异常时用户可以用 fix 命令尝试修复
|
||||
_ = r.migrator.Migrate()
|
||||
|
||||
if err := r.cmd.Run(context.TODO(), os.Args); err != nil {
|
||||
color.Errorf("|-%v\n", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
// 错误必须向上返回,调用方据此以非零码退出,后台任务才能正确判定失败
|
||||
return r.cmd.Run(context.TODO(), os.Args)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package app
|
||||
|
||||
import "time"
|
||||
|
||||
// StartTime 面板启动时间
|
||||
var StartTime = time.Now()
|
||||
|
||||
// 面板状态常量
|
||||
const (
|
||||
StatusNormal = iota
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// HealthLevelError 需要用户立即处理
|
||||
const HealthLevelError = "error"
|
||||
|
||||
// HealthLevelWarning 提示性问题,通常已被系统自动降级处理
|
||||
const HealthLevelWarning = "warning"
|
||||
|
||||
// HealthIssue 单条健康问题
|
||||
// Key 为稳定标识符(如 database:stat),前端据此选择翻译文案
|
||||
// Message 为原始错误详情,供诊断参考
|
||||
type HealthIssue struct {
|
||||
Key string `json:"key"`
|
||||
Level string `json:"level"`
|
||||
Message string `json:"message"`
|
||||
Since time.Time `json:"since"`
|
||||
}
|
||||
|
||||
type healthRegistry struct {
|
||||
mu sync.RWMutex
|
||||
issues map[string]HealthIssue
|
||||
}
|
||||
|
||||
// Health 全局健康状态注册表,供各后台任务上报/清除故障
|
||||
var Health = &healthRegistry{issues: make(map[string]HealthIssue)}
|
||||
|
||||
// Report 上报或更新一条健康问题
|
||||
// 同 key 重复上报时保留首次上报时间,仅更新 message 和 level
|
||||
func (h *healthRegistry) Report(key, level, message string) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
if existing, ok := h.issues[key]; ok {
|
||||
existing.Level = level
|
||||
existing.Message = message
|
||||
h.issues[key] = existing
|
||||
return
|
||||
}
|
||||
h.issues[key] = HealthIssue{
|
||||
Key: key,
|
||||
Level: level,
|
||||
Message: message,
|
||||
Since: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
// Clear 清除指定 key 的健康问题
|
||||
func (h *healthRegistry) Clear(key string) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
delete(h.issues, key)
|
||||
}
|
||||
|
||||
// Snapshot 返回当前所有健康问题,按 Since 升序(越早发生越靠前)
|
||||
func (h *healthRegistry) Snapshot() []HealthIssue {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
|
||||
result := make([]HealthIssue, 0, len(h.issues))
|
||||
for _, issue := range h.issues {
|
||||
result = append(result, issue)
|
||||
}
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i].Since.Before(result[j].Since)
|
||||
})
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package acewaf
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func NewApp() (*App, error) {
|
||||
return &App{}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(_ chi.Router) {
|
||||
// WAF 管理路由由 route 贡献(route/waf.go)统一提供
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("acewaf")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
@@ -9,23 +9,23 @@ import (
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/pkg/tools"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/tools"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -36,6 +36,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/clear_error_log", s.ClearErrorLog)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("apache")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read(fmt.Sprintf("%s/server/apache/conf/httpd.conf", app.Root))
|
||||
if err != nil {
|
||||
|
||||
+43
-42
@@ -3,49 +3,50 @@ package apps
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
|
||||
"github.com/acepanel/panel/internal/apps/apache"
|
||||
"github.com/acepanel/panel/internal/apps/codeserver"
|
||||
"github.com/acepanel/panel/internal/apps/docker"
|
||||
"github.com/acepanel/panel/internal/apps/fail2ban"
|
||||
"github.com/acepanel/panel/internal/apps/frp"
|
||||
"github.com/acepanel/panel/internal/apps/gitea"
|
||||
"github.com/acepanel/panel/internal/apps/mariadb"
|
||||
"github.com/acepanel/panel/internal/apps/memcached"
|
||||
"github.com/acepanel/panel/internal/apps/minio"
|
||||
"github.com/acepanel/panel/internal/apps/mysql"
|
||||
"github.com/acepanel/panel/internal/apps/nginx"
|
||||
"github.com/acepanel/panel/internal/apps/openresty"
|
||||
"github.com/acepanel/panel/internal/apps/percona"
|
||||
"github.com/acepanel/panel/internal/apps/phpmyadmin"
|
||||
"github.com/acepanel/panel/internal/apps/podman"
|
||||
"github.com/acepanel/panel/internal/apps/postgresql"
|
||||
"github.com/acepanel/panel/internal/apps/pureftpd"
|
||||
"github.com/acepanel/panel/internal/apps/redis"
|
||||
"github.com/acepanel/panel/internal/apps/rsync"
|
||||
"github.com/acepanel/panel/internal/apps/s3fs"
|
||||
"github.com/acepanel/panel/internal/apps/supervisor"
|
||||
"github.com/acepanel/panel/v3/internal/apps/acewaf"
|
||||
"github.com/acepanel/panel/v3/internal/apps/apache"
|
||||
"github.com/acepanel/panel/v3/internal/apps/clickhouse"
|
||||
"github.com/acepanel/panel/v3/internal/apps/codeserver"
|
||||
"github.com/acepanel/panel/v3/internal/apps/docker"
|
||||
"github.com/acepanel/panel/v3/internal/apps/elasticsearch"
|
||||
"github.com/acepanel/panel/v3/internal/apps/fail2ban"
|
||||
"github.com/acepanel/panel/v3/internal/apps/frp"
|
||||
"github.com/acepanel/panel/v3/internal/apps/gitea"
|
||||
"github.com/acepanel/panel/v3/internal/apps/grafana"
|
||||
"github.com/acepanel/panel/v3/internal/apps/kafka"
|
||||
"github.com/acepanel/panel/v3/internal/apps/mariadb"
|
||||
"github.com/acepanel/panel/v3/internal/apps/memcached"
|
||||
"github.com/acepanel/panel/v3/internal/apps/minio"
|
||||
"github.com/acepanel/panel/v3/internal/apps/mongodb"
|
||||
"github.com/acepanel/panel/v3/internal/apps/mysql"
|
||||
"github.com/acepanel/panel/v3/internal/apps/nginx"
|
||||
"github.com/acepanel/panel/v3/internal/apps/openresty"
|
||||
"github.com/acepanel/panel/v3/internal/apps/opensearch"
|
||||
"github.com/acepanel/panel/v3/internal/apps/percona"
|
||||
"github.com/acepanel/panel/v3/internal/apps/pgadmin"
|
||||
"github.com/acepanel/panel/v3/internal/apps/phpmyadmin"
|
||||
"github.com/acepanel/panel/v3/internal/apps/podman"
|
||||
"github.com/acepanel/panel/v3/internal/apps/postgresql"
|
||||
"github.com/acepanel/panel/v3/internal/apps/prometheus"
|
||||
"github.com/acepanel/panel/v3/internal/apps/pureftpd"
|
||||
"github.com/acepanel/panel/v3/internal/apps/redis"
|
||||
"github.com/acepanel/panel/v3/internal/apps/rocketmq"
|
||||
"github.com/acepanel/panel/v3/internal/apps/rsync"
|
||||
"github.com/acepanel/panel/v3/internal/apps/s3fs"
|
||||
"github.com/acepanel/panel/v3/internal/apps/supervisor"
|
||||
"github.com/acepanel/panel/v3/internal/apps/valkey"
|
||||
)
|
||||
|
||||
var ProviderSet = wire.NewSet(
|
||||
apache.NewApp,
|
||||
codeserver.NewApp,
|
||||
docker.NewApp,
|
||||
fail2ban.NewApp,
|
||||
frp.NewApp,
|
||||
gitea.NewApp,
|
||||
mariadb.NewApp,
|
||||
memcached.NewApp,
|
||||
minio.NewApp,
|
||||
mysql.NewApp,
|
||||
nginx.NewApp,
|
||||
openresty.NewApp,
|
||||
percona.NewApp,
|
||||
phpmyadmin.NewApp,
|
||||
podman.NewApp,
|
||||
postgresql.NewApp,
|
||||
pureftpd.NewApp,
|
||||
redis.NewApp,
|
||||
rsync.NewApp,
|
||||
s3fs.NewApp,
|
||||
supervisor.NewApp,
|
||||
apache.NewApp, clickhouse.NewApp, codeserver.NewApp,
|
||||
docker.NewApp, elasticsearch.NewApp, fail2ban.NewApp,
|
||||
frp.NewApp, gitea.NewApp, grafana.NewApp,
|
||||
kafka.NewApp, mariadb.NewApp, memcached.NewApp,
|
||||
minio.NewApp, mongodb.NewApp, mysql.NewApp,
|
||||
nginx.NewApp, openresty.NewApp, opensearch.NewApp,
|
||||
percona.NewApp, pgadmin.NewApp, phpmyadmin.NewApp, podman.NewApp,
|
||||
postgresql.NewApp, prometheus.NewApp, pureftpd.NewApp,
|
||||
redis.NewApp, rocketmq.NewApp, rsync.NewApp,
|
||||
s3fs.NewApp, supervisor.NewApp, valkey.NewApp,
|
||||
acewaf.NewApp,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,332 @@
|
||||
package clickhouse
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
"go.yaml.in/yaml/v4"
|
||||
"resty.dev/v3"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
settingRepo biz.SettingRepo
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo, settingRepo biz.SettingRepo) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
settingRepo: settingRepo,
|
||||
databaseServerRepo: databaseServerRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
r.Get("/default_password", s.GetDefaultPassword)
|
||||
r.Post("/default_password", s.SetDefaultPassword)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("clickhouse-server")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// Load 获取 ClickHouse 运行状态
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, _ := systemctl.Status("clickhouse-server")
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
password, _ := s.settingRepo.Get(biz.SettingKeyClickHouseDefaultPassword)
|
||||
port := s.getPort()
|
||||
|
||||
client := resty.New().SetTimeout(10 * time.Second)
|
||||
defer func(client *resty.Client) { _ = client.Close() }(client)
|
||||
|
||||
// 获取版本
|
||||
versionResp, err := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/?query=SELECT+version()&user=default&password=%s", port, password))
|
||||
if err != nil || !versionResp.IsStatusSuccess() {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
version := strings.TrimSpace(string(versionResp.Bytes()))
|
||||
|
||||
// 获取运行时间
|
||||
uptimeResp, _ := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/?query=SELECT+uptime()&user=default&password=%s", port, password))
|
||||
uptime := strings.TrimSpace(string(uptimeResp.Bytes()))
|
||||
|
||||
// 获取当前查询数
|
||||
queriesResp, _ := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/?query=SELECT+value+FROM+system.metrics+WHERE+metric='Query'&user=default&password=%s", port, password))
|
||||
queries := strings.TrimSpace(string(queriesResp.Bytes()))
|
||||
|
||||
// 获取内存使用
|
||||
memResp, _ := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/?query=SELECT+value+FROM+system.metrics+WHERE+metric='MemoryTracking'&user=default&password=%s", port, password))
|
||||
memUsage := strings.TrimSpace(string(memResp.Bytes()))
|
||||
|
||||
// 获取数据库数量
|
||||
dbCountResp, _ := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/?query=SELECT+count()+FROM+system.databases&user=default&password=%s", port, password))
|
||||
dbCount := strings.TrimSpace(string(dbCountResp.Bytes()))
|
||||
|
||||
// 获取表数量
|
||||
tableCountResp, _ := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/?query=SELECT+count()+FROM+system.tables&user=default&password=%s", port, password))
|
||||
tableCount := strings.TrimSpace(string(tableCountResp.Bytes()))
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Version"), Value: version},
|
||||
{Name: s.t.Get("Uptime (seconds)"), Value: uptime},
|
||||
{Name: s.t.Get("Active Queries"), Value: queries},
|
||||
{Name: s.t.Get("Memory Usage (bytes)"), Value: memUsage},
|
||||
{Name: s.t.Get("Databases"), Value: dbCount},
|
||||
{Name: s.t.Get("Tables"), Value: tableCount},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(s.configPath())
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
// UpdateConfig 更新配置
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("clickhouse-server"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
_ = yaml.Unmarshal([]byte(raw), &cfg)
|
||||
if cfg == nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
tune := ConfigTune{
|
||||
ListenHost: s.getYAMLValue(cfg, "listen_host"),
|
||||
HTTPPort: s.getYAMLValue(cfg, "http_port"),
|
||||
TCPPort: s.getYAMLValue(cfg, "tcp_port"),
|
||||
MaxMemoryUsage: s.getYAMLValue(cfg, "max_memory_usage"),
|
||||
MaxThreads: s.getYAMLValue(cfg, "max_threads"),
|
||||
Path: s.getYAMLValue(cfg, "path"),
|
||||
TmpPath: s.getYAMLValue(cfg, "tmp_path"),
|
||||
LogLevel: s.getYAMLValue(cfg, "logger.level"),
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
if err = yaml.Unmarshal([]byte(raw), &cfg); err != nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
// ClickHouse 顶层键直接用平铺方式
|
||||
s.setYAMLValue(cfg, "listen_host", req.ListenHost)
|
||||
s.setYAMLValue(cfg, "http_port", req.HTTPPort)
|
||||
s.setYAMLValue(cfg, "tcp_port", req.TCPPort)
|
||||
s.setYAMLValue(cfg, "max_memory_usage", req.MaxMemoryUsage)
|
||||
s.setYAMLValue(cfg, "max_threads", req.MaxThreads)
|
||||
s.setYAMLValue(cfg, "path", req.Path)
|
||||
s.setYAMLValue(cfg, "tmp_path", req.TmpPath)
|
||||
// logger.level 是嵌套的
|
||||
s.setNestedYAMLValue(cfg, "logger.level", req.LogLevel)
|
||||
|
||||
data, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
if err = io.Write(s.configPath(), string(data), 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("clickhouse-server"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetDefaultPassword 获取 default 用户密码
|
||||
func (s *App) GetDefaultPassword(w http.ResponseWriter, r *http.Request) {
|
||||
password, err := s.settingRepo.Get(biz.SettingKeyClickHouseDefaultPassword)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get ClickHouse default password: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, password)
|
||||
}
|
||||
|
||||
// SetDefaultPassword 设置 default 用户密码
|
||||
func (s *App) SetDefaultPassword(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[SetDefaultPassword](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 计算 SHA256 哈希
|
||||
hash := sha256.Sum256([]byte(req.Password))
|
||||
hexHash := fmt.Sprintf("%x", hash)
|
||||
|
||||
// 读取 users.d/default.yaml 并更新密码
|
||||
raw, _ := io.Read(s.usersConfigPath())
|
||||
var cfg map[string]any
|
||||
if err = yaml.Unmarshal([]byte(raw), &cfg); err != nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
users, _ := cfg["users"].(map[string]any)
|
||||
if users == nil {
|
||||
users = make(map[string]any)
|
||||
cfg["users"] = users
|
||||
}
|
||||
def, _ := users["default"].(map[string]any)
|
||||
if def == nil {
|
||||
def = make(map[string]any)
|
||||
users["default"] = def
|
||||
}
|
||||
def["password_sha256_hex"] = hexHash
|
||||
out, _ := yaml.Marshal(cfg)
|
||||
if err = io.Write(s.usersConfigPath(), string(out), 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to write ClickHouse user config: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
// 重启服务使密码生效
|
||||
if err = systemctl.Restart("clickhouse-server"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 保存明文到面板数据库
|
||||
if err = s.settingRepo.Set(biz.SettingKeyClickHouseDefaultPassword, req.Password); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to save ClickHouse default password: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.databaseServerRepo.UpdatePassword("local_clickhouse", req.Password)
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// configPath 返回主配置文件路径
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/clickhouse/config/config.yaml", app.Root)
|
||||
}
|
||||
|
||||
// usersConfigPath 返回用户密码配置文件路径(users.d/ 由 ConfigProcessor 自动合并到 users.yaml)
|
||||
func (s *App) usersConfigPath() string {
|
||||
return fmt.Sprintf("%s/server/clickhouse/config/users.d/default.yaml", app.Root)
|
||||
}
|
||||
|
||||
// getPort 从配置中获取 HTTP 端口
|
||||
func (s *App) getPort() string {
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
_ = yaml.Unmarshal([]byte(raw), &cfg)
|
||||
if cfg != nil {
|
||||
if v := s.getYAMLValue(cfg, "http_port"); v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return "8123"
|
||||
}
|
||||
|
||||
// getYAMLValue 获取 YAML 值,支持嵌套键
|
||||
func (s *App) getYAMLValue(cfg map[string]any, key string) string {
|
||||
// 先尝试平铺键
|
||||
if val, ok := cfg[key]; ok {
|
||||
return cast.ToString(val)
|
||||
}
|
||||
// 回退到嵌套键
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
val, ok := cfg[parts[0]]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if len(parts) == 1 {
|
||||
return cast.ToString(val)
|
||||
}
|
||||
nested, ok := val.(map[string]any)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return s.getYAMLValue(nested, parts[1])
|
||||
}
|
||||
|
||||
// setYAMLValue 设置平铺 YAML 值
|
||||
func (s *App) setYAMLValue(cfg map[string]any, key string, value string) {
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
cfg[key] = value
|
||||
}
|
||||
|
||||
// setNestedYAMLValue 设置嵌套 YAML 值
|
||||
func (s *App) setNestedYAMLValue(cfg map[string]any, key string, value string) {
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
if len(parts) == 1 {
|
||||
cfg[parts[0]] = value
|
||||
return
|
||||
}
|
||||
nested, ok := cfg[parts[0]].(map[string]any)
|
||||
if !ok {
|
||||
nested = make(map[string]any)
|
||||
cfg[parts[0]] = nested
|
||||
}
|
||||
s.setNestedYAMLValue(nested, parts[1], value)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package clickhouse
|
||||
|
||||
// UpdateConfig 更新配置
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// SetDefaultPassword 设置 default 用户密码
|
||||
type SetDefaultPassword struct {
|
||||
Password string `form:"password" json:"password" validate:"required && password"`
|
||||
}
|
||||
|
||||
// ConfigTune ClickHouse 配置调整
|
||||
type ConfigTune struct {
|
||||
// 网络
|
||||
ListenHost string `form:"listen_host" json:"listen_host"`
|
||||
HTTPPort string `form:"http_port" json:"http_port" validate:"number && min:1 && max:65535"`
|
||||
TCPPort string `form:"tcp_port" json:"tcp_port" validate:"number && min:1 && max:65535"`
|
||||
// 性能
|
||||
MaxMemoryUsage string `form:"max_memory_usage" json:"max_memory_usage"`
|
||||
MaxThreads string `form:"max_threads" json:"max_threads"`
|
||||
// 路径
|
||||
Path string `form:"path" json:"path" validate:"unix_path"`
|
||||
TmpPath string `form:"tmp_path" json:"tmp_path" validate:"unix_path"`
|
||||
// 日志
|
||||
LogLevel string `form:"log_level" json:"log_level" validate:"in:trace,debug,information,warning,error"`
|
||||
}
|
||||
@@ -5,15 +5,16 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
func NewApp() (*App, error) {
|
||||
return &App{}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -21,6 +22,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("code-server")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, _ := io.Read("/root/.config/code-server/config.yaml")
|
||||
service.Success(w, config)
|
||||
|
||||
@@ -8,15 +8,16 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
func NewApp() (*App, error) {
|
||||
return &App{}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -26,6 +27,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/settings", s.UpdateSettings)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("docker")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read("/etc/docker/daemon.json")
|
||||
if err != nil {
|
||||
@@ -103,8 +109,8 @@ func (s *App) GetSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 从 exec-opts 中提取 cgroup-driver
|
||||
for _, opt := range daemonConfig.ExecOpts {
|
||||
if strings.HasPrefix(opt, "native.cgroupdriver=") {
|
||||
settings.CgroupDriver = strings.TrimPrefix(opt, "native.cgroupdriver=")
|
||||
if after, ok := strings.CutPrefix(opt, "native.cgroupdriver="); ok {
|
||||
settings.CgroupDriver = after
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,22 +12,22 @@ type LogOpts struct {
|
||||
|
||||
// Settings Docker daemon 设置
|
||||
type Settings struct {
|
||||
RegistryMirrors []string `json:"registry-mirrors,omitempty"` // 注册表镜像
|
||||
InsecureRegistries []string `json:"insecure-registries,omitempty"` // 非安全镜像仓库
|
||||
LiveRestore bool `json:"live-restore,omitempty"` // Live restore
|
||||
LogDriver string `json:"log-driver,omitempty"` // 日志驱动
|
||||
LogOpts LogOpts `json:"log-opts,omitempty"` // 日志配置选项
|
||||
CgroupDriver string `json:"cgroup-driver,omitempty"` // cgroup 驱动(从 exec-opts 中提取)
|
||||
Hosts []string `json:"hosts,omitempty"` // Socket 路径
|
||||
DataRoot string `json:"data-root,omitempty"` // 数据目录
|
||||
StorageDriver string `json:"storage-driver,omitempty"` // 存储驱动
|
||||
DNS []string `json:"dns,omitempty"` // DNS 配置
|
||||
FirewallBackend string `json:"firewall-backend,omitempty"` // 防火墙后端 (iptables/nftables)
|
||||
Iptables *bool `json:"iptables,omitempty"` // iptables 规则
|
||||
Ip6tables *bool `json:"ip6tables,omitempty"` // ip6tables 规则
|
||||
IpForward *bool `json:"ip-forward,omitempty"` // IP 转发
|
||||
IPv6 *bool `json:"ipv6,omitempty"` // IPv6 支持
|
||||
Bip string `json:"bip,omitempty"` // 默认 bridge 网络 IP 段
|
||||
RegistryMirrors []string `json:"registry-mirrors,omitempty"` // 注册表镜像
|
||||
InsecureRegistries []string `json:"insecure-registries,omitempty"` // 非安全镜像仓库
|
||||
LiveRestore bool `json:"live-restore,omitempty"` // Live restore
|
||||
LogDriver string `json:"log-driver,omitempty"` // 日志驱动
|
||||
LogOpts LogOpts `json:"log-opts"` // 日志配置选项
|
||||
CgroupDriver string `json:"cgroup-driver,omitempty" validate:"in:systemd,cgroupfs"` // cgroup 驱动(从 exec-opts 中提取)
|
||||
Hosts []string `json:"hosts,omitempty"` // Socket 路径
|
||||
DataRoot string `json:"data-root,omitempty"` // 数据目录
|
||||
StorageDriver string `json:"storage-driver,omitempty"` // 存储驱动
|
||||
DNS []string `json:"dns,omitempty"` // DNS 配置
|
||||
FirewallBackend string `json:"firewall-backend,omitempty" validate:"in:iptables,nftables"` // 防火墙后端 (iptables/nftables)
|
||||
Iptables *bool `json:"iptables,omitempty"` // iptables 规则
|
||||
Ip6tables *bool `json:"ip6tables,omitempty"` // ip6tables 规则
|
||||
IpForward *bool `json:"ip-forward,omitempty"` // IP 转发
|
||||
IPv6 *bool `json:"ipv6,omitempty"` // IPv6 支持
|
||||
Bip string `json:"bip,omitempty"` // 默认 bridge 网络 IP 段
|
||||
}
|
||||
|
||||
// UpdateSettings 更新设置请求
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
package elasticsearch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
"go.yaml.in/yaml/v4"
|
||||
"resty.dev/v3"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
return &App{t: t}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("elasticsearch")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("elasticsearch")
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get elasticsearch status: %v", err))
|
||||
return
|
||||
}
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
port := s.getPort()
|
||||
client := resty.New().SetTimeout(10 * time.Second)
|
||||
defer func(client *resty.Client) { _ = client.Close() }(client)
|
||||
resp, err := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/_cluster/health", port))
|
||||
if err != nil || !resp.IsStatusSuccess() {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
var health struct {
|
||||
ClusterName string `json:"cluster_name"`
|
||||
Status string `json:"status"`
|
||||
NumberOfNodes int `json:"number_of_nodes"`
|
||||
NumberOfDataNodes int `json:"number_of_data_nodes"`
|
||||
ActiveShards int `json:"active_shards"`
|
||||
ActivePrimaryShards int `json:"active_primary_shards"`
|
||||
RelocatingShards int `json:"relocating_shards"`
|
||||
UnassignedShards int `json:"unassigned_shards"`
|
||||
}
|
||||
if err = json.Unmarshal(resp.Bytes(), &health); err != nil {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Cluster Name"), Value: health.ClusterName},
|
||||
{Name: s.t.Get("Cluster Status"), Value: health.Status},
|
||||
{Name: s.t.Get("Number of Nodes"), Value: cast.ToString(health.NumberOfNodes)},
|
||||
{Name: s.t.Get("Number of Data Nodes"), Value: cast.ToString(health.NumberOfDataNodes)},
|
||||
{Name: s.t.Get("Active Shards"), Value: cast.ToString(health.ActiveShards)},
|
||||
{Name: s.t.Get("Active Primary Shards"), Value: cast.ToString(health.ActivePrimaryShards)},
|
||||
{Name: s.t.Get("Relocating Shards"), Value: cast.ToString(health.RelocatingShards)},
|
||||
{Name: s.t.Get("Unassigned Shards"), Value: cast.ToString(health.UnassignedShards)},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(s.configPath())
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("elasticsearch"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 ElasticSearch 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
_ = yaml.Unmarshal([]byte(raw), &cfg)
|
||||
if cfg == nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
// ES 9.x 不再在 jvm.options 中设置堆内存,改为 jvm.options.d/heap.options
|
||||
heapRaw, _ := io.Read(s.jvmHeapOptionsPath())
|
||||
heapInit, heapMax := s.parseJVMHeap(heapRaw)
|
||||
// 兼容旧版本:如果 heap.options 没有,尝试从 jvm.options 读取
|
||||
if heapInit == "" && heapMax == "" {
|
||||
jvmRaw, _ := io.Read(s.jvmOptionsPath())
|
||||
heapInit, heapMax = s.parseJVMHeap(jvmRaw)
|
||||
}
|
||||
|
||||
tune := ConfigTune{
|
||||
ClusterName: s.getYAMLValue(cfg, "cluster.name"),
|
||||
NodeName: s.getYAMLValue(cfg, "node.name"),
|
||||
NetworkHost: s.getYAMLValue(cfg, "network.host"),
|
||||
HTTPPort: s.getYAMLValue(cfg, "http.port"),
|
||||
DiscoveryType: s.getYAMLValue(cfg, "discovery.type"),
|
||||
PathData: s.getYAMLValue(cfg, "path.data"),
|
||||
PathLogs: s.getYAMLValue(cfg, "path.logs"),
|
||||
HeapInitSize: heapInit,
|
||||
HeapMaxSize: heapMax,
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新 ElasticSearch 配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 更新 YAML 配置
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
if err = yaml.Unmarshal([]byte(raw), &cfg); err != nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
s.setYAMLValue(cfg, "cluster.name", req.ClusterName)
|
||||
s.setYAMLValue(cfg, "node.name", req.NodeName)
|
||||
s.setYAMLValue(cfg, "network.host", req.NetworkHost)
|
||||
s.setYAMLValue(cfg, "http.port", req.HTTPPort)
|
||||
s.setYAMLValue(cfg, "discovery.type", req.DiscoveryType)
|
||||
s.setYAMLValue(cfg, "path.data", req.PathData)
|
||||
s.setYAMLValue(cfg, "path.logs", req.PathLogs)
|
||||
|
||||
data, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
if err = io.Write(s.configPath(), string(data), 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 更新 JVM 堆内存(写入 jvm.options.d/heap.options)
|
||||
if req.HeapInitSize != "" || req.HeapMaxSize != "" {
|
||||
heapRaw, _ := io.Read(s.jvmHeapOptionsPath())
|
||||
heapRaw = s.setJVMHeap(heapRaw, req.HeapInitSize, req.HeapMaxSize)
|
||||
if err = io.Write(s.jvmHeapOptionsPath(), heapRaw, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("elasticsearch"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// configPath 返回配置文件路径
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/elasticsearch/config/elasticsearch.yml", app.Root)
|
||||
}
|
||||
|
||||
// jvmOptionsPath 返回 JVM 选项文件路径
|
||||
func (s *App) jvmOptionsPath() string {
|
||||
return fmt.Sprintf("%s/server/elasticsearch/config/jvm.options", app.Root)
|
||||
}
|
||||
|
||||
// jvmHeapOptionsPath 返回 JVM 堆内存配置文件路径(ES 9.x 推荐方式)
|
||||
func (s *App) jvmHeapOptionsPath() string {
|
||||
return fmt.Sprintf("%s/server/elasticsearch/config/jvm.options.d/heap.options", app.Root)
|
||||
}
|
||||
|
||||
// getPort 从配置中获取 HTTP 端口
|
||||
func (s *App) getPort() string {
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
_ = yaml.Unmarshal([]byte(raw), &cfg)
|
||||
if cfg != nil {
|
||||
if v := s.getYAMLValue(cfg, "http.port"); v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return "9200"
|
||||
}
|
||||
|
||||
// getYAMLValue 获取 YAML 值,优先匹配平铺键(如 "path.data"),回退到嵌套键(如 path -> data)
|
||||
func (s *App) getYAMLValue(cfg map[string]any, key string) string {
|
||||
// 优先匹配平铺键(安装脚本用 sed 生成的格式)
|
||||
if val, ok := cfg[key]; ok {
|
||||
return cast.ToString(val)
|
||||
}
|
||||
// 回退到嵌套键
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
val, ok := cfg[parts[0]]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if len(parts) == 1 {
|
||||
return cast.ToString(val)
|
||||
}
|
||||
nested, ok := val.(map[string]any)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return s.getYAMLValue(nested, parts[1])
|
||||
}
|
||||
|
||||
// setYAMLValue 设置 YAML 值
|
||||
func (s *App) setYAMLValue(cfg map[string]any, key string, value string) {
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
// 使用平铺键,同时清理可能存在的嵌套键
|
||||
cfg[key] = value
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
if len(parts) == 2 {
|
||||
if nested, ok := cfg[parts[0]].(map[string]any); ok {
|
||||
delete(nested, parts[1])
|
||||
if len(nested) == 0 {
|
||||
delete(cfg, parts[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parseJVMHeap 从 jvm.options 中提取堆内存配置
|
||||
func (s *App) parseJVMHeap(content string) (initSize, maxSize string) {
|
||||
reInit := regexp.MustCompile(`(?m)^-Xms(\S+)`)
|
||||
reMax := regexp.MustCompile(`(?m)^-Xmx(\S+)`)
|
||||
if m := reInit.FindStringSubmatch(content); len(m) == 2 {
|
||||
initSize = m[1]
|
||||
}
|
||||
if m := reMax.FindStringSubmatch(content); len(m) == 2 {
|
||||
maxSize = m[1]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// setJVMHeap 替换 jvm.options 中的堆内存配置
|
||||
func (s *App) setJVMHeap(content string, initSize, maxSize string) string {
|
||||
if initSize != "" {
|
||||
re := regexp.MustCompile(`(?m)^-Xms\S+`)
|
||||
if re.MatchString(content) {
|
||||
content = re.ReplaceAllString(content, "-Xms"+initSize)
|
||||
} else {
|
||||
content += "\n-Xms" + initSize
|
||||
}
|
||||
}
|
||||
if maxSize != "" {
|
||||
re := regexp.MustCompile(`(?m)^-Xmx\S+`)
|
||||
if re.MatchString(content) {
|
||||
content = re.ReplaceAllString(content, "-Xmx"+maxSize)
|
||||
} else {
|
||||
content += "\n-Xmx" + maxSize
|
||||
}
|
||||
}
|
||||
return content
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package elasticsearch
|
||||
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigTune ElasticSearch 配置调整
|
||||
type ConfigTune struct {
|
||||
// 集群
|
||||
ClusterName string `form:"cluster_name" json:"cluster_name"`
|
||||
NodeName string `form:"node_name" json:"node_name"`
|
||||
NetworkHost string `form:"network_host" json:"network_host"`
|
||||
HTTPPort string `form:"http_port" json:"http_port"`
|
||||
DiscoveryType string `form:"discovery_type" json:"discovery_type"`
|
||||
// 路径
|
||||
PathData string `form:"path_data" json:"path_data"`
|
||||
PathLogs string `form:"path_logs" json:"path_logs"`
|
||||
// JVM
|
||||
HeapInitSize string `form:"heap_init_size" json:"heap_init_size"`
|
||||
HeapMaxSize string `form:"heap_max_size" json:"heap_max_size"`
|
||||
}
|
||||
@@ -8,15 +8,18 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/chix"
|
||||
"github.com/libtnb/chix/v2"
|
||||
"github.com/libtnb/utils/str"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/biz"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
@@ -24,11 +27,11 @@ type App struct {
|
||||
websiteRepo biz.WebsiteRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, website biz.WebsiteRepo) *App {
|
||||
func NewApp(t *gotext.Locale, websiteRepo biz.WebsiteRepo) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
websiteRepo: website,
|
||||
}
|
||||
websiteRepo: websiteRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -41,6 +44,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Get("/white_list", s.GetWhiteList)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("fail2ban")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// List 所有规则
|
||||
func (s *App) List(w http.ResponseWriter, r *http.Request) {
|
||||
raw, err := io.Read("/etc/fail2ban/jail.local")
|
||||
@@ -169,7 +177,7 @@ ignoreregex =
|
||||
switch jailName {
|
||||
case "ssh":
|
||||
filter = "sshd"
|
||||
port, err = shell.Execf("cat /etc/ssh/sshd_config | grep 'Port ' | awk '{print $2}'")
|
||||
port, err = shell.Execf("cat /etc/ssh/sshd_config | grep 'Port ' | awk '{print $2}' | paste -sd ','")
|
||||
case "mysql":
|
||||
filter = "mysqld-auth"
|
||||
port, err = shell.Execf("cat %s/server/mysql/conf/my.cnf | grep 'port' | head -n 1 | awk '{print $3}'", app.Root)
|
||||
@@ -270,18 +278,15 @@ func (s *App) BanList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
bannedIpList := strings.Split(bannedIp, " ")
|
||||
|
||||
var list []map[string]string
|
||||
for _, ip := range bannedIpList {
|
||||
if len(ip) > 0 {
|
||||
list = append(list, map[string]string{
|
||||
"name": req.Name,
|
||||
"ip": ip,
|
||||
})
|
||||
list := lo.FilterMap(bannedIpList, func(ip string, _ int) (map[string]string, bool) {
|
||||
if len(ip) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
if list == nil {
|
||||
list = []map[string]string{}
|
||||
}
|
||||
return map[string]string{
|
||||
"name": req.Name,
|
||||
"ip": ip,
|
||||
}, true
|
||||
})
|
||||
|
||||
service.Success(w, chix.M{
|
||||
"currently_ban": currentlyBan,
|
||||
|
||||
@@ -2,12 +2,12 @@ package fail2ban
|
||||
|
||||
type Add struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Type string `json:"type" validate:"required"`
|
||||
MaxRetry int `json:"maxretry" validate:"required"`
|
||||
FindTime int `json:"findtime" validate:"required"`
|
||||
BanTime int `json:"bantime" validate:"required"`
|
||||
WebsiteName string `json:"website_name"`
|
||||
WebsiteMode string `json:"website_mode"`
|
||||
Type string `json:"type" validate:"required && in:service,website"`
|
||||
MaxRetry int `json:"maxretry" validate:"required && min:1"`
|
||||
FindTime int `json:"findtime" validate:"required && min:1"`
|
||||
BanTime int `json:"bantime" validate:"required && min:1"`
|
||||
WebsiteName string `json:"website_name" validate:"required_if:Type,website"`
|
||||
WebsiteMode string `json:"website_mode" validate:"required_if:Type,website && in:cc,path"`
|
||||
WebsitePath string `json:"website_path"`
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type BanList struct {
|
||||
|
||||
type Unban struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
IP string `json:"ip" validate:"required"`
|
||||
IP string `json:"ip" validate:"required && ip"`
|
||||
}
|
||||
|
||||
type SetWhiteList struct {
|
||||
|
||||
@@ -6,16 +6,17 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
func NewApp() (*App, error) {
|
||||
return &App{}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -25,6 +26,12 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/user", s.UpdateUser)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
frps, _ := systemctl.Status("frps")
|
||||
frpc, _ := systemctl.Status("frpc")
|
||||
return types.AggregateAppStatus(frps, frpc)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[Name](r)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package frp
|
||||
|
||||
type Name struct {
|
||||
Name string `form:"name" json:"name" validate:"required|in:frps,frpc"`
|
||||
Name string `form:"name" json:"name" validate:"required && in:frps,frpc"`
|
||||
}
|
||||
|
||||
type UpdateConfig struct {
|
||||
Name string `form:"name" json:"name" validate:"required|in:frps,frpc"`
|
||||
Name string `form:"name" json:"name" validate:"required && in:frps,frpc"`
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
type UpdateUser struct {
|
||||
Name string `form:"name" json:"name" validate:"required|in:frps,frpc"`
|
||||
User string `form:"user" json:"user" validate:"required|regex:^[a-zA-Z0-9_-]+$"`
|
||||
Group string `form:"group" json:"group" validate:"required|regex:^[a-zA-Z0-9_-]+$"`
|
||||
Name string `form:"name" json:"name" validate:"required && in:frps,frpc"`
|
||||
User string `form:"user" json:"user" validate:"required && regex:\"^[a-zA-Z0-9_-]+$\""`
|
||||
Group string `form:"group" json:"group" validate:"required && regex:\"^[a-zA-Z0-9_-]+$\""`
|
||||
}
|
||||
|
||||
@@ -6,16 +6,17 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
func NewApp() (*App, error) {
|
||||
return &App{}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -23,6 +24,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("gitea")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, _ := io.Read(fmt.Sprintf("%s/server/gitea/app.ini", app.Root))
|
||||
service.Success(w, config)
|
||||
|
||||
@@ -0,0 +1,524 @@
|
||||
package grafana
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/samber/lo"
|
||||
"go.yaml.in/yaml/v4"
|
||||
"resty.dev/v3"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
return &App{t: t}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
// 数据源管理
|
||||
r.Get("/datasources", s.DataSourceList)
|
||||
r.Post("/datasources", s.CreateDataSource)
|
||||
r.Post("/datasources/{name}", s.UpdateDataSource)
|
||||
r.Delete("/datasources/{name}", s.DeleteDataSource)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("grafana")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("grafana")
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get grafana status: %v", err))
|
||||
return
|
||||
}
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
// 从 defaults.ini 获取端口
|
||||
config, _ := io.Read(s.configPath())
|
||||
port := s.getINIValue(config, "server", "http_port")
|
||||
if port == "" {
|
||||
port = "3000"
|
||||
}
|
||||
|
||||
client := resty.New().SetTimeout(10 * time.Second)
|
||||
defer func(client *resty.Client) { _ = client.Close() }(client)
|
||||
resp, err := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/api/health", port))
|
||||
if err != nil || !resp.IsStatusSuccess() {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
var health struct {
|
||||
Commit string `json:"commit"`
|
||||
Database string `json:"database"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if err = json.Unmarshal(resp.Bytes(), &health); err != nil {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Version"), Value: health.Version},
|
||||
{Name: "Commit", Value: health.Commit},
|
||||
{Name: s.t.Get("Database"), Value: health.Database},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
service.Success(w, config)
|
||||
}
|
||||
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("grafana"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 Grafana 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
get := func(section, key string) string {
|
||||
return s.getINIValue(config, section, key)
|
||||
}
|
||||
|
||||
tune := ConfigTune{
|
||||
// [server]
|
||||
HTTPPort: get("server", "http_port"),
|
||||
Domain: get("server", "domain"),
|
||||
RootURL: get("server", "root_url"),
|
||||
Protocol: get("server", "protocol"),
|
||||
// [database]
|
||||
DBType: get("database", "type"),
|
||||
DBHost: get("database", "host"),
|
||||
DBName: get("database", "name"),
|
||||
DBUser: get("database", "user"),
|
||||
DBPassword: get("database", "password"),
|
||||
// [security]
|
||||
AdminUser: get("security", "admin_user"),
|
||||
AdminPassword: get("security", "admin_password"),
|
||||
// [users]
|
||||
AllowSignUp: get("users", "allow_sign_up"),
|
||||
AutoAssignOrgRole: get("users", "auto_assign_org_role"),
|
||||
// [smtp]
|
||||
SMTPEnabled: get("smtp", "enabled"),
|
||||
SMTPHost: get("smtp", "host"),
|
||||
SMTPUser: get("smtp", "user"),
|
||||
SMTPPassword: get("smtp", "password"),
|
||||
SMTPFromAddress: get("smtp", "from_address"),
|
||||
// [log]
|
||||
LogMode: get("log", "mode"),
|
||||
LogLevel: get("log", "level"),
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新 Grafana 配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
// [server]
|
||||
config = s.setINIValue(config, "server", "http_port", req.HTTPPort)
|
||||
config = s.setINIValue(config, "server", "domain", req.Domain)
|
||||
config = s.setINIValue(config, "server", "root_url", req.RootURL)
|
||||
config = s.setINIValue(config, "server", "protocol", req.Protocol)
|
||||
// [database]
|
||||
config = s.setINIValue(config, "database", "type", req.DBType)
|
||||
config = s.setINIValue(config, "database", "host", req.DBHost)
|
||||
config = s.setINIValue(config, "database", "name", req.DBName)
|
||||
config = s.setINIValue(config, "database", "user", req.DBUser)
|
||||
config = s.setINIValue(config, "database", "password", req.DBPassword)
|
||||
// [security]
|
||||
config = s.setINIValue(config, "security", "admin_user", req.AdminUser)
|
||||
config = s.setINIValue(config, "security", "admin_password", req.AdminPassword)
|
||||
// [users]
|
||||
config = s.setINIValue(config, "users", "allow_sign_up", req.AllowSignUp)
|
||||
config = s.setINIValue(config, "users", "auto_assign_org_role", req.AutoAssignOrgRole)
|
||||
// [smtp]
|
||||
config = s.setINIValue(config, "smtp", "enabled", req.SMTPEnabled)
|
||||
config = s.setINIValue(config, "smtp", "host", req.SMTPHost)
|
||||
config = s.setINIValue(config, "smtp", "user", req.SMTPUser)
|
||||
config = s.setINIValue(config, "smtp", "password", req.SMTPPassword)
|
||||
config = s.setINIValue(config, "smtp", "from_address", req.SMTPFromAddress)
|
||||
// [log]
|
||||
config = s.setINIValue(config, "log", "mode", req.LogMode)
|
||||
config = s.setINIValue(config, "log", "level", req.LogLevel)
|
||||
|
||||
if err = io.Write(s.configPath(), config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("grafana"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// DataSourceList 获取数据源列表
|
||||
func (s *App) DataSourceList(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, s.getDatasourceList(s.readDatasources()))
|
||||
}
|
||||
|
||||
// CreateDataSource 创建数据源
|
||||
func (s *App) CreateDataSource(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[DataSource](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
cfg := s.readDatasources()
|
||||
|
||||
if lo.ContainsBy(s.getDatasourceList(cfg), func(item any) bool {
|
||||
ds, ok := item.(map[string]any)
|
||||
return ok && ds["name"] == req.Name
|
||||
}) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("datasource %s already exists", req.Name))
|
||||
return
|
||||
}
|
||||
|
||||
if req.IsDefault {
|
||||
s.clearDefault(cfg)
|
||||
}
|
||||
|
||||
list := s.getDatasourceList(cfg)
|
||||
list = append(list, s.buildDatasourceMap(req))
|
||||
cfg["datasources"] = list
|
||||
|
||||
if err = s.writeDatasources(cfg); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// UpdateDataSource 更新数据源
|
||||
func (s *App) UpdateDataSource(w http.ResponseWriter, r *http.Request) {
|
||||
oldName := chi.URLParam(r, "name")
|
||||
req, err := service.Bind[DataSource](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
cfg := s.readDatasources()
|
||||
list := s.getDatasourceList(cfg)
|
||||
|
||||
_, idx, found := lo.FindIndexOf(list, func(item any) bool {
|
||||
ds, ok := item.(map[string]any)
|
||||
return ok && ds["name"] == oldName
|
||||
})
|
||||
if !found {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("datasource %s not found", oldName))
|
||||
return
|
||||
}
|
||||
ds, _ := list[idx].(map[string]any)
|
||||
newDs := s.buildDatasourceMap(req)
|
||||
// 密码为空时保留原有 secureJsonData
|
||||
if req.Password == "" {
|
||||
if sec, exists := ds["secureJsonData"]; exists {
|
||||
newDs["secureJsonData"] = sec
|
||||
}
|
||||
}
|
||||
list[idx] = newDs
|
||||
|
||||
if req.IsDefault {
|
||||
s.clearDefault(cfg)
|
||||
lo.ForEach(list, func(item any, _ int) {
|
||||
if ds, ok := item.(map[string]any); ok && ds["name"] == req.Name {
|
||||
ds["isDefault"] = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if oldName != req.Name {
|
||||
s.addDeleteEntry(cfg, oldName)
|
||||
}
|
||||
|
||||
cfg["datasources"] = list
|
||||
|
||||
if err = s.writeDatasources(cfg); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// DeleteDataSource 删除数据源
|
||||
func (s *App) DeleteDataSource(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
cfg := s.readDatasources()
|
||||
list := s.getDatasourceList(cfg)
|
||||
|
||||
newList := lo.Filter(list, func(item any, _ int) bool {
|
||||
ds, ok := item.(map[string]any)
|
||||
return !ok || ds["name"] != name
|
||||
})
|
||||
found := len(newList) < len(list)
|
||||
if !found {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("datasource %s not found", name))
|
||||
return
|
||||
}
|
||||
|
||||
cfg["datasources"] = newList
|
||||
s.addDeleteEntry(cfg, name)
|
||||
|
||||
if err := s.writeDatasources(cfg); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// configPath 返回 Grafana 主配置文件路径
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/grafana/conf/defaults.ini", app.Root)
|
||||
}
|
||||
|
||||
// getINIValue 从 INI 配置中获取指定 section 下的 key 值
|
||||
func (s *App) getINIValue(content string, section string, key string) string {
|
||||
currentSection := ""
|
||||
for line := range strings.SplitSeq(content, "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") || strings.HasPrefix(trimmed, ";") {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(trimmed, "[") && strings.HasSuffix(trimmed, "]") {
|
||||
currentSection = strings.TrimSpace(trimmed[1 : len(trimmed)-1])
|
||||
continue
|
||||
}
|
||||
if currentSection != section {
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(trimmed, "=", 2)
|
||||
if len(parts) == 2 && strings.TrimSpace(parts[0]) == key {
|
||||
return strings.TrimSpace(parts[1])
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// setINIValue 在 INI 配置中设置指定 section 下的 key 值
|
||||
func (s *App) setINIValue(content string, section string, key string, value string) string {
|
||||
lines := strings.Split(content, "\n")
|
||||
result := make([]string, 0, len(lines))
|
||||
currentSection := ""
|
||||
found := false
|
||||
lastSectionLine := -1 // 目标 section 的最后一行索引
|
||||
|
||||
for i, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
|
||||
// 检测 section 头
|
||||
if strings.HasPrefix(trimmed, "[") && strings.HasSuffix(trimmed, "]") {
|
||||
// 如果离开目标 section 且未找到 key,在 section 末尾插入
|
||||
if currentSection == section && !found && lastSectionLine >= 0 {
|
||||
found = true
|
||||
if value != "" {
|
||||
// 在 section 末尾插入新行
|
||||
insertIdx := lastSectionLine + 1
|
||||
newLine := key + " = " + value
|
||||
result = append(result[:insertIdx+1], append([]string{newLine}, result[insertIdx+1:]...)...)
|
||||
}
|
||||
}
|
||||
currentSection = strings.TrimSpace(trimmed[1 : len(trimmed)-1])
|
||||
}
|
||||
|
||||
if currentSection == section {
|
||||
lastSectionLine = len(result)
|
||||
}
|
||||
|
||||
// 在目标 section 内匹配 key
|
||||
if currentSection == section && !found {
|
||||
checkLine := trimmed
|
||||
commented := false
|
||||
if strings.HasPrefix(checkLine, ";") {
|
||||
checkLine = strings.TrimSpace(checkLine[1:])
|
||||
commented = true
|
||||
} else if strings.HasPrefix(checkLine, "#") {
|
||||
checkLine = strings.TrimSpace(checkLine[1:])
|
||||
commented = true
|
||||
}
|
||||
parts := strings.SplitN(checkLine, "=", 2)
|
||||
if len(parts) == 2 && strings.TrimSpace(parts[0]) == key {
|
||||
found = true
|
||||
if value == "" {
|
||||
// 值为空时注释掉
|
||||
if !commented {
|
||||
result = append(result, ";"+line)
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
} else {
|
||||
result = append(result, key+" = "+value)
|
||||
}
|
||||
_ = i
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, line)
|
||||
}
|
||||
|
||||
// 如果在最后一个 section 中未找到 key
|
||||
if currentSection == section && !found {
|
||||
found = true
|
||||
if value != "" {
|
||||
result = append(result, key+" = "+value)
|
||||
}
|
||||
}
|
||||
|
||||
// section 不存在,在文件末尾追加
|
||||
if !found && value != "" {
|
||||
result = append(result, "")
|
||||
result = append(result, "["+section+"]")
|
||||
result = append(result, key+" = "+value)
|
||||
}
|
||||
|
||||
return strings.Join(result, "\n")
|
||||
}
|
||||
|
||||
// datasourcePath 返回 provisioning 数据源文件路径
|
||||
func (s *App) datasourcePath() string {
|
||||
return fmt.Sprintf("%s/server/grafana/conf/provisioning/datasources/panel.yml", app.Root)
|
||||
}
|
||||
|
||||
// readDatasources 读取 provisioning 文件
|
||||
func (s *App) readDatasources() map[string]any {
|
||||
raw, _ := io.Read(s.datasourcePath())
|
||||
if raw == "" {
|
||||
return map[string]any{
|
||||
"apiVersion": 1,
|
||||
"datasources": []any{},
|
||||
}
|
||||
}
|
||||
var cfg map[string]any
|
||||
if err := yaml.Unmarshal([]byte(raw), &cfg); err != nil {
|
||||
return map[string]any{
|
||||
"apiVersion": 1,
|
||||
"datasources": []any{},
|
||||
}
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
// writeDatasources 写入 provisioning 文件并重启 Grafana
|
||||
func (s *App) writeDatasources(cfg map[string]any) error {
|
||||
data, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = io.Write(s.datasourcePath(), string(data), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return systemctl.Restart("grafana")
|
||||
}
|
||||
|
||||
// getDatasourceList 从 cfg 中提取 datasources 切片
|
||||
func (s *App) getDatasourceList(cfg map[string]any) []any {
|
||||
ds, ok := cfg["datasources"].([]any)
|
||||
if !ok {
|
||||
return []any{}
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
||||
// buildDatasourceMap 从请求构建单条 datasource map
|
||||
func (s *App) buildDatasourceMap(req *DataSource) map[string]any {
|
||||
ds := map[string]any{
|
||||
"name": req.Name,
|
||||
"type": req.Type,
|
||||
"access": req.Access,
|
||||
"url": req.URL,
|
||||
"isDefault": req.IsDefault,
|
||||
"editable": true,
|
||||
}
|
||||
if req.Access == "" {
|
||||
ds["access"] = "proxy"
|
||||
}
|
||||
switch req.Type {
|
||||
case "mysql", "postgres", "influxdb", "mssql":
|
||||
if req.Database != "" {
|
||||
ds["database"] = req.Database
|
||||
}
|
||||
if req.User != "" {
|
||||
ds["user"] = req.User
|
||||
}
|
||||
if req.Password != "" {
|
||||
ds["secureJsonData"] = map[string]any{"password": req.Password}
|
||||
}
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
||||
// clearDefault 清除所有数据源的默认标记
|
||||
func (s *App) clearDefault(cfg map[string]any) {
|
||||
lo.ForEach(s.getDatasourceList(cfg), func(item any, _ int) {
|
||||
if ds, ok := item.(map[string]any); ok {
|
||||
ds["isDefault"] = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// addDeleteEntry 向 deleteDatasources 添加条目
|
||||
func (s *App) addDeleteEntry(cfg map[string]any, name string) {
|
||||
delList, _ := cfg["deleteDatasources"].([]any)
|
||||
delList = append(delList, map[string]any{"name": name, "orgId": 1})
|
||||
cfg["deleteDatasources"] = delList
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package grafana
|
||||
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigTune Grafana 配置调整
|
||||
type ConfigTune struct {
|
||||
// [server]
|
||||
HTTPPort string `form:"http_port" json:"http_port"`
|
||||
Domain string `form:"domain" json:"domain"`
|
||||
RootURL string `form:"root_url" json:"root_url"`
|
||||
Protocol string `form:"protocol" json:"protocol"`
|
||||
// [database]
|
||||
DBType string `form:"db_type" json:"db_type"`
|
||||
DBHost string `form:"db_host" json:"db_host"`
|
||||
DBName string `form:"db_name" json:"db_name"`
|
||||
DBUser string `form:"db_user" json:"db_user"`
|
||||
DBPassword string `form:"db_password" json:"db_password"`
|
||||
// [security]
|
||||
AdminUser string `form:"admin_user" json:"admin_user"`
|
||||
AdminPassword string `form:"admin_password" json:"admin_password"`
|
||||
// [users]
|
||||
AllowSignUp string `form:"allow_sign_up" json:"allow_sign_up"`
|
||||
AutoAssignOrgRole string `form:"auto_assign_org_role" json:"auto_assign_org_role"`
|
||||
// [smtp]
|
||||
SMTPEnabled string `form:"smtp_enabled" json:"smtp_enabled"`
|
||||
SMTPHost string `form:"smtp_host" json:"smtp_host"`
|
||||
SMTPUser string `form:"smtp_user" json:"smtp_user"`
|
||||
SMTPPassword string `form:"smtp_password" json:"smtp_password"`
|
||||
SMTPFromAddress string `form:"smtp_from_address" json:"smtp_from_address"`
|
||||
// [log]
|
||||
LogMode string `form:"log_mode" json:"log_mode"`
|
||||
LogLevel string `form:"log_level" json:"log_level"`
|
||||
}
|
||||
|
||||
// DataSource 数据源
|
||||
type DataSource struct {
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Type string `form:"type" json:"type" validate:"required && in:prometheus,mysql,postgres,influxdb,loki,elasticsearch,tempo,jaeger,zipkin,graphite,alertmanager,opentsdb,mssql,testdata,grafana-pyroscope-datasource,grafana-opensearch-datasource"`
|
||||
URL string `form:"url" json:"url" validate:"required"`
|
||||
Access string `form:"access" json:"access" validate:"in:proxy,direct"`
|
||||
IsDefault bool `form:"is_default" json:"is_default"`
|
||||
// 数据库类型专用
|
||||
Database string `form:"database" json:"database"`
|
||||
User string `form:"user" json:"user"`
|
||||
Password string `form:"password" json:"password"`
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package kafka
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
return &App{t: t}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("kafka")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("kafka")
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get kafka status: %v", err))
|
||||
return
|
||||
}
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Node ID"), Value: s.getPropertiesValue(config, "node.id")},
|
||||
{Name: s.t.Get("Listeners"), Value: s.getPropertiesValue(config, "listeners")},
|
||||
{Name: s.t.Get("Log Dirs"), Value: s.getPropertiesValue(config, "log.dirs")},
|
||||
{Name: s.t.Get("Num Partitions"), Value: s.getPropertiesValue(config, "num.partitions")},
|
||||
{Name: s.t.Get("Log Retention Hours"), Value: s.getPropertiesValue(config, "log.retention.hours")},
|
||||
{Name: s.t.Get("Log Segment Bytes"), Value: s.getPropertiesValue(config, "log.segment.bytes")},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(s.configPath())
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("kafka"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 Kafka 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
heapRaw, _ := io.Read(s.heapEnvPath())
|
||||
heapInit, heapMax := s.parseHeapEnv(heapRaw)
|
||||
|
||||
tune := ConfigTune{
|
||||
NodeID: s.getPropertiesValue(config, "node.id"),
|
||||
Listeners: s.getPropertiesValue(config, "listeners"),
|
||||
LogDirs: s.getPropertiesValue(config, "log.dirs"),
|
||||
NumPartitions: s.getPropertiesValue(config, "num.partitions"),
|
||||
RetentionHours: s.getPropertiesValue(config, "log.retention.hours"),
|
||||
LogSegmentBytes: s.getPropertiesValue(config, "log.segment.bytes"),
|
||||
HeapInitSize: heapInit,
|
||||
HeapMaxSize: heapMax,
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新 Kafka 配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
config = s.setPropertiesValue(config, "node.id", req.NodeID)
|
||||
config = s.setPropertiesValue(config, "listeners", req.Listeners)
|
||||
config = s.setPropertiesValue(config, "log.dirs", req.LogDirs)
|
||||
config = s.setPropertiesValue(config, "num.partitions", req.NumPartitions)
|
||||
config = s.setPropertiesValue(config, "log.retention.hours", req.RetentionHours)
|
||||
config = s.setPropertiesValue(config, "log.segment.bytes", req.LogSegmentBytes)
|
||||
|
||||
if err = io.Write(s.configPath(), config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 更新 JVM 堆内存
|
||||
if req.HeapInitSize != "" || req.HeapMaxSize != "" {
|
||||
heapRaw, _ := io.Read(s.heapEnvPath())
|
||||
heapRaw = s.setHeapEnv(heapRaw, req.HeapInitSize, req.HeapMaxSize)
|
||||
if err = io.Write(s.heapEnvPath(), heapRaw, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("kafka"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// configPath 返回配置文件路径
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/kafka/config/server.properties", app.Root)
|
||||
}
|
||||
|
||||
// heapEnvPath 返回 JVM 堆内存配置文件路径
|
||||
func (s *App) heapEnvPath() string {
|
||||
return fmt.Sprintf("%s/server/kafka/config/heap.env", app.Root)
|
||||
}
|
||||
|
||||
// getPropertiesValue 从 properties 内容中获取指定键的值
|
||||
func (s *App) getPropertiesValue(content string, key string) string {
|
||||
for line := range strings.SplitSeq(content, "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
}
|
||||
k, v, ok := strings.Cut(trimmed, "=")
|
||||
if ok && strings.TrimSpace(k) == key {
|
||||
return strings.TrimSpace(v)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// setPropertiesValue 在 properties 内容中设置指定键的值
|
||||
func (s *App) setPropertiesValue(content string, key string, value string) string {
|
||||
value = strings.ReplaceAll(value, "\n", "")
|
||||
value = strings.ReplaceAll(value, "\r", "")
|
||||
|
||||
lines := strings.Split(content, "\n")
|
||||
result := make([]string, 0, len(lines))
|
||||
found := false
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" {
|
||||
result = append(result, line)
|
||||
continue
|
||||
}
|
||||
checkLine := trimmed
|
||||
if strings.HasPrefix(checkLine, "#") {
|
||||
checkLine = strings.TrimSpace(checkLine[1:])
|
||||
}
|
||||
k, _, ok := strings.Cut(checkLine, "=")
|
||||
if ok && strings.TrimSpace(k) == key {
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if value == "" {
|
||||
if !strings.HasPrefix(trimmed, "#") {
|
||||
result = append(result, "#"+trimmed)
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
continue
|
||||
}
|
||||
result = append(result, key+"="+value)
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
}
|
||||
if !found && value != "" {
|
||||
result = append(result, key+"="+value)
|
||||
}
|
||||
return strings.Join(result, "\n")
|
||||
}
|
||||
|
||||
// parseHeapEnv 从 heap.env 中提取堆内存配置
|
||||
func (s *App) parseHeapEnv(content string) (initSize, maxSize string) {
|
||||
re := regexp.MustCompile(`KAFKA_HEAP_OPTS=(.+)`)
|
||||
m := re.FindStringSubmatch(content)
|
||||
if len(m) != 2 {
|
||||
return
|
||||
}
|
||||
opts := m[1]
|
||||
if mi := regexp.MustCompile(`-Xms(\S+)`).FindStringSubmatch(opts); len(mi) == 2 {
|
||||
initSize = mi[1]
|
||||
}
|
||||
if mx := regexp.MustCompile(`-Xmx(\S+)`).FindStringSubmatch(opts); len(mx) == 2 {
|
||||
maxSize = mx[1]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// setHeapEnv 设置 heap.env 中的堆内存配置
|
||||
func (s *App) setHeapEnv(content string, initSize, maxSize string) string {
|
||||
// 读取已有值作为默认
|
||||
oldInit, oldMax := s.parseHeapEnv(content)
|
||||
if initSize == "" {
|
||||
initSize = oldInit
|
||||
}
|
||||
if maxSize == "" {
|
||||
maxSize = oldMax
|
||||
}
|
||||
if initSize == "" {
|
||||
initSize = "1g"
|
||||
}
|
||||
if maxSize == "" {
|
||||
maxSize = "1g"
|
||||
}
|
||||
return fmt.Sprintf("KAFKA_HEAP_OPTS=-Xms%s -Xmx%s\n", initSize, maxSize)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package kafka
|
||||
|
||||
// UpdateConfig Kafka 配置更新
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigTune Kafka 配置调整
|
||||
type ConfigTune struct {
|
||||
// Broker
|
||||
NodeID string `form:"node_id" json:"node_id"` // node.id
|
||||
Listeners string `form:"listeners" json:"listeners"` // listeners
|
||||
LogDirs string `form:"log_dirs" json:"log_dirs"` // log.dirs
|
||||
NumPartitions string `form:"num_partitions" json:"num_partitions"` // num.partitions
|
||||
RetentionHours string `form:"retention_hours" json:"retention_hours"` // log.retention.hours
|
||||
LogSegmentBytes string `form:"log_segment_bytes" json:"log_segment_bytes"` // log.segment.bytes
|
||||
// JVM
|
||||
HeapInitSize string `form:"heap_init_size" json:"heap_init_size"` // -Xms
|
||||
HeapMaxSize string `form:"heap_max_size" json:"heap_max_size"` // -Xmx
|
||||
}
|
||||
@@ -2,22 +2,24 @@ package mariadb
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/internal/apps/mysql"
|
||||
"github.com/acepanel/panel/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/apps/mysql"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
mysql *mysql.App
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, setting biz.SettingRepo, databaseServer biz.DatabaseServerRepo) *App {
|
||||
func NewApp(mysqlApp *mysql.App) (*App, error) {
|
||||
return &App{
|
||||
mysql: mysql.NewApp(t, setting, databaseServer),
|
||||
}
|
||||
mysql: mysqlApp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
s.mysql.Route(r)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
return s.mysql.Status()
|
||||
}
|
||||
|
||||
@@ -10,20 +10,20 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -34,6 +34,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("memcached")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("memcached")
|
||||
if err != nil {
|
||||
@@ -170,8 +175,8 @@ func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// getExecStartArg 从 systemd service 文件的 ExecStart 行中获取指定参数值
|
||||
func (s *App) getExecStartArg(content string, flag string) string {
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if !strings.HasPrefix(trimmed, "ExecStart=") {
|
||||
continue
|
||||
|
||||
@@ -6,10 +6,10 @@ type UpdateConfig struct {
|
||||
|
||||
// ConfigTune Memcached 配置调整
|
||||
type ConfigTune struct {
|
||||
Port string `form:"port" json:"port"`
|
||||
UDPPort string `form:"udp_port" json:"udp_port"`
|
||||
Port string `form:"port" json:"port" validate:"number && min:1 && max:65535"`
|
||||
UDPPort string `form:"udp_port" json:"udp_port" validate:"number && min:1 && max:65535"`
|
||||
ListenAddress string `form:"listen_address" json:"listen_address"`
|
||||
Memory string `form:"memory" json:"memory"`
|
||||
MaxConnections string `form:"max_connections" json:"max_connections"`
|
||||
Threads string `form:"threads" json:"threads"`
|
||||
Memory string `form:"memory" json:"memory" validate:"number && min:1"`
|
||||
MaxConnections string `form:"max_connections" json:"max_connections" validate:"number && min:1"`
|
||||
Threads string `form:"threads" json:"threads" validate:"number && min:1"`
|
||||
}
|
||||
|
||||
@@ -5,15 +5,16 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
func NewApp() (*App, error) {
|
||||
return &App{}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -21,6 +22,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/env", s.UpdateEnv)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("minio")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) GetEnv(w http.ResponseWriter, r *http.Request) {
|
||||
env, _ := io.Read("/etc/default/minio")
|
||||
service.Success(w, env)
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
package mongodb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
"go.yaml.in/yaml/v4"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
settingRepo biz.SettingRepo
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo, settingRepo biz.SettingRepo) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
settingRepo: settingRepo,
|
||||
databaseServerRepo: databaseServerRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
r.Get("/admin_password", s.GetAdminPassword)
|
||||
r.Post("/admin_password", s.SetAdminPassword)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("mongod")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// Load 获取 MongoDB 运行状态
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, _ := systemctl.Status("mongod")
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
password, _ := s.settingRepo.Get(biz.SettingKeyMongoDBAdminPassword)
|
||||
raw, err := shell.Execf(`mongosh --quiet --eval "JSON.stringify(db.serverStatus())" -u admin -p '%s' --authenticationDatabase admin 2>/dev/null`, password)
|
||||
if err != nil {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
var status2 struct {
|
||||
Uptime int `json:"uptime"`
|
||||
Connections struct {
|
||||
Current int `json:"current"`
|
||||
TotalCreated int `json:"totalCreated"`
|
||||
} `json:"connections"`
|
||||
OpCounters struct {
|
||||
Query int `json:"query"`
|
||||
Insert int `json:"insert"`
|
||||
Update int `json:"update"`
|
||||
Delete int `json:"delete"`
|
||||
} `json:"opcounters"`
|
||||
Mem struct {
|
||||
Resident int `json:"resident"`
|
||||
} `json:"mem"`
|
||||
StorageEngine struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"storageEngine"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if err = json.Unmarshal([]byte(raw), &status2); err != nil {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Version"), Value: status2.Version},
|
||||
{Name: s.t.Get("Uptime (seconds)"), Value: cast.ToString(status2.Uptime)},
|
||||
{Name: s.t.Get("Current Connections"), Value: cast.ToString(status2.Connections.Current)},
|
||||
{Name: s.t.Get("Total Connections Created"), Value: cast.ToString(status2.Connections.TotalCreated)},
|
||||
{Name: s.t.Get("Query Operations"), Value: cast.ToString(status2.OpCounters.Query)},
|
||||
{Name: s.t.Get("Insert Operations"), Value: cast.ToString(status2.OpCounters.Insert)},
|
||||
{Name: s.t.Get("Update Operations"), Value: cast.ToString(status2.OpCounters.Update)},
|
||||
{Name: s.t.Get("Delete Operations"), Value: cast.ToString(status2.OpCounters.Delete)},
|
||||
{Name: s.t.Get("Resident Memory (MB)"), Value: cast.ToString(status2.Mem.Resident)},
|
||||
{Name: s.t.Get("Storage Engine"), Value: status2.StorageEngine.Name},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(s.configPath())
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
// UpdateConfig 更新配置
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("mongod"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
_ = yaml.Unmarshal([]byte(raw), &cfg)
|
||||
if cfg == nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
tune := ConfigTune{
|
||||
DbPath: s.getYAMLValue(cfg, "storage.dbPath"),
|
||||
CacheSizeGB: s.getYAMLValue(cfg, "storage.wiredTiger.engineConfig.cacheSizeGB"),
|
||||
Port: s.getYAMLValue(cfg, "net.port"),
|
||||
BindIp: s.getYAMLValue(cfg, "net.bindIp"),
|
||||
SystemLogPath: s.getYAMLValue(cfg, "systemLog.path"),
|
||||
Authorization: s.getYAMLValue(cfg, "security.authorization"),
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
if err = yaml.Unmarshal([]byte(raw), &cfg); err != nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
s.setNestedYAMLValue(cfg, "storage.dbPath", req.DbPath)
|
||||
s.setNestedYAMLValue(cfg, "storage.wiredTiger.engineConfig.cacheSizeGB", req.CacheSizeGB)
|
||||
s.setNestedYAMLValue(cfg, "net.port", req.Port)
|
||||
s.setNestedYAMLValue(cfg, "net.bindIp", req.BindIp)
|
||||
s.setNestedYAMLValue(cfg, "systemLog.path", req.SystemLogPath)
|
||||
s.setNestedYAMLValue(cfg, "security.authorization", req.Authorization)
|
||||
|
||||
data, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
if err = io.Write(s.configPath(), string(data), 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("mongod"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetAdminPassword 获取 admin 密码
|
||||
func (s *App) GetAdminPassword(w http.ResponseWriter, r *http.Request) {
|
||||
password, err := s.settingRepo.Get(biz.SettingKeyMongoDBAdminPassword)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get MongoDB admin password: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, password)
|
||||
}
|
||||
|
||||
// SetAdminPassword 设置 admin 密码
|
||||
func (s *App) SetAdminPassword(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[SetAdminPassword](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
oldPassword, _ := s.settingRepo.Get(biz.SettingKeyMongoDBAdminPassword)
|
||||
|
||||
// 尝试用旧密码连接修改
|
||||
_, err = shell.Execf(`mongosh --quiet -u admin -p '%s' --authenticationDatabase admin --eval "db.changeUserPassword('admin', '%s')"`, oldPassword, req.Password)
|
||||
if err != nil {
|
||||
// 回退:停止服务,无认证模式修改
|
||||
_ = systemctl.Stop("mongod")
|
||||
_, _ = shell.Execf(`su -s /bin/bash mongod -c "mongod --config %s --noauth --fork --logpath /tmp/mongod_reset.log"`, s.configPath())
|
||||
_, resetErr := shell.Execf(`mongosh --quiet --eval "db.getSiblingDB('admin').changeUserPassword('admin', '%s')"`, req.Password)
|
||||
_, _ = shell.Execf(`su -s /bin/bash mongod -c "mongod --config %s --shutdown" 2>/dev/null; pkill -f 'mongod --config.*--noauth' 2>/dev/null`, s.configPath())
|
||||
_ = systemctl.Start("mongod")
|
||||
if resetErr != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to set MongoDB admin password: %v", resetErr))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = s.settingRepo.Set(biz.SettingKeyMongoDBAdminPassword, req.Password); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to save MongoDB admin password: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
_ = s.databaseServerRepo.UpdatePassword("local_mongodb", req.Password)
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// configPath 返回配置文件路径
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/mongodb/mongod.conf", app.Root)
|
||||
}
|
||||
|
||||
// getYAMLValue 获取嵌套 YAML 值,支持 dot notation
|
||||
func (s *App) getYAMLValue(cfg map[string]any, key string) string {
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
val, ok := cfg[parts[0]]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if len(parts) == 1 {
|
||||
return cast.ToString(val)
|
||||
}
|
||||
nested, ok := val.(map[string]any)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return s.getYAMLValue(nested, parts[1])
|
||||
}
|
||||
|
||||
// setNestedYAMLValue 设置嵌套 YAML 值,逐层创建 map
|
||||
func (s *App) setNestedYAMLValue(cfg map[string]any, key string, value string) {
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
if len(parts) == 1 {
|
||||
cfg[parts[0]] = value
|
||||
return
|
||||
}
|
||||
nested, ok := cfg[parts[0]].(map[string]any)
|
||||
if !ok {
|
||||
nested = make(map[string]any)
|
||||
cfg[parts[0]] = nested
|
||||
}
|
||||
s.setNestedYAMLValue(nested, parts[1], value)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package mongodb
|
||||
|
||||
// UpdateConfig 更新配置
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// SetAdminPassword 设置 admin 密码
|
||||
type SetAdminPassword struct {
|
||||
Password string `form:"password" json:"password" validate:"required && password"`
|
||||
}
|
||||
|
||||
// ConfigTune MongoDB 配置调整
|
||||
type ConfigTune struct {
|
||||
// 存储
|
||||
DbPath string `form:"db_path" json:"db_path" validate:"unix_path"`
|
||||
CacheSizeGB string `form:"cache_size_gb" json:"cache_size_gb"`
|
||||
// 网络
|
||||
Port string `form:"port" json:"port" validate:"number && min:1 && max:65535"`
|
||||
BindIp string `form:"bind_ip" json:"bind_ip"`
|
||||
// 日志
|
||||
SystemLogPath string `form:"system_log_path" json:"system_log_path" validate:"unix_path"`
|
||||
// 安全
|
||||
Authorization string `form:"authorization" json:"authorization" validate:"in:enabled,disabled"`
|
||||
}
|
||||
+28
-62
@@ -7,19 +7,19 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/biz"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/db"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/pkg/tools"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/db"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/tools"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
@@ -28,27 +28,30 @@ type App struct {
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, setting biz.SettingRepo, databaseServer biz.DatabaseServerRepo) *App {
|
||||
func NewApp(t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo, settingRepo biz.SettingRepo) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
settingRepo: setting,
|
||||
databaseServerRepo: databaseServer,
|
||||
}
|
||||
settingRepo: settingRepo,
|
||||
databaseServerRepo: databaseServerRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Post("/clear_log", s.ClearLog)
|
||||
r.Get("/slow_log", s.SlowLog)
|
||||
r.Post("/clear_slow_log", s.ClearSlowLog)
|
||||
r.Get("/root_password", s.GetRootPassword)
|
||||
r.Post("/root_password", s.SetRootPassword)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("mysqld")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read(app.Root + "/server/mysql/conf/my.cnf")
|
||||
@@ -194,31 +197,11 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, load)
|
||||
}
|
||||
|
||||
// ClearLog 清空日志
|
||||
func (s *App) ClearLog(w http.ResponseWriter, r *http.Request) {
|
||||
if err := systemctl.LogClear("mysqld"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// SlowLog 获取慢查询日志
|
||||
func (s *App) SlowLog(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, fmt.Sprintf("%s/server/mysql/mysql-slow.log", app.Root))
|
||||
}
|
||||
|
||||
// ClearSlowLog 清空慢查询日志
|
||||
func (s *App) ClearSlowLog(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := shell.Execf("cat /dev/null > %s/server/mysql/mysql-slow.log", app.Root); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetRootPassword 获取root密码
|
||||
func (s *App) GetRootPassword(w http.ResponseWriter, r *http.Request) {
|
||||
rootPassword, err := s.settingRepo.Get(biz.SettingKeyMySQLRootPassword)
|
||||
@@ -239,7 +222,7 @@ func (s *App) SetRootPassword(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
oldRootPassword, _ := s.settingRepo.Get(biz.SettingKeyMySQLRootPassword)
|
||||
mysql, err := db.NewMySQL("root", oldRootPassword, s.getSock(), "unix")
|
||||
mysql, err := db.NewMySQL(r.Context(), "root", oldRootPassword, s.getSock(), "unix")
|
||||
if err != nil {
|
||||
// 尝试安全模式直接改密
|
||||
if err = db.MySQLResetRootPassword(req.Password); err != nil {
|
||||
@@ -264,30 +247,6 @@ func (s *App) SetRootPassword(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
func (s *App) getSock() string {
|
||||
if io.Exists("/tmp/mysql.sock") {
|
||||
return "/tmp/mysql.sock"
|
||||
}
|
||||
if io.Exists(app.Root + "/server/mysql/config/my.cnf") {
|
||||
config, _ := io.Read(app.Root + "/server/mysql/config/my.cnf")
|
||||
re := regexp.MustCompile(`socket\s*=\s*(['"]?)([^'"]+)`)
|
||||
matches := re.FindStringSubmatch(config)
|
||||
if len(matches) > 2 {
|
||||
return matches[2]
|
||||
}
|
||||
}
|
||||
if io.Exists("/etc/my.cnf") {
|
||||
config, _ := io.Read("/etc/my.cnf")
|
||||
re := regexp.MustCompile(`socket\s*=\s*(['"]?)([^'"]+)`)
|
||||
matches := re.FindStringSubmatch(config)
|
||||
if len(matches) > 2 {
|
||||
return matches[2]
|
||||
}
|
||||
}
|
||||
|
||||
return "/tmp/mysql.sock"
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 MySQL 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read(app.Root + "/server/mysql/conf/my.cnf")
|
||||
@@ -386,10 +345,17 @@ func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
func (s *App) getSock() string {
|
||||
if sock := db.MySQLSocket(app.Root+"/server/mysql/config/my.cnf", "/etc/my.cnf"); sock != "" {
|
||||
return sock
|
||||
}
|
||||
return "/tmp/mysql.sock"
|
||||
}
|
||||
|
||||
// getINIValue 从 INI 格式内容中获取指定键的值
|
||||
func (s *App) getINIValue(content string, key string) string {
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, ";") || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
|
||||
@@ -5,38 +5,38 @@ type UpdateConfig struct {
|
||||
}
|
||||
|
||||
type SetRootPassword struct {
|
||||
Password string `form:"password" json:"password" validate:"required|password"`
|
||||
Password string `form:"password" json:"password" validate:"required && password"`
|
||||
}
|
||||
|
||||
// ConfigTune MySQL 配置调整
|
||||
type ConfigTune struct {
|
||||
// 常规设置
|
||||
Port string `form:"port" json:"port"`
|
||||
MaxConnections string `form:"max_connections" json:"max_connections"`
|
||||
MaxConnectErrors string `form:"max_connect_errors" json:"max_connect_errors"`
|
||||
Port string `form:"port" json:"port" validate:"number && min:1 && max:65535"`
|
||||
MaxConnections string `form:"max_connections" json:"max_connections"`
|
||||
MaxConnectErrors string `form:"max_connect_errors" json:"max_connect_errors"`
|
||||
DefaultStorageEngine string `form:"default_storage_engine" json:"default_storage_engine"`
|
||||
TableOpenCache string `form:"table_open_cache" json:"table_open_cache"`
|
||||
MaxAllowedPacket string `form:"max_allowed_packet" json:"max_allowed_packet"`
|
||||
OpenFilesLimit string `form:"open_files_limit" json:"open_files_limit"`
|
||||
TableOpenCache string `form:"table_open_cache" json:"table_open_cache"`
|
||||
MaxAllowedPacket string `form:"max_allowed_packet" json:"max_allowed_packet"`
|
||||
OpenFilesLimit string `form:"open_files_limit" json:"open_files_limit"`
|
||||
// 性能调整
|
||||
KeyBufferSize string `form:"key_buffer_size" json:"key_buffer_size"`
|
||||
SortBufferSize string `form:"sort_buffer_size" json:"sort_buffer_size"`
|
||||
ReadBufferSize string `form:"read_buffer_size" json:"read_buffer_size"`
|
||||
ReadRndBufferSize string `form:"read_rnd_buffer_size" json:"read_rnd_buffer_size"`
|
||||
JoinBufferSize string `form:"join_buffer_size" json:"join_buffer_size"`
|
||||
ThreadCacheSize string `form:"thread_cache_size" json:"thread_cache_size"`
|
||||
ThreadStack string `form:"thread_stack" json:"thread_stack"`
|
||||
TmpTableSize string `form:"tmp_table_size" json:"tmp_table_size"`
|
||||
MaxHeapTableSize string `form:"max_heap_table_size" json:"max_heap_table_size"`
|
||||
MyisamSortBufferSize string `form:"myisam_sort_buffer_size" json:"myisam_sort_buffer_size"`
|
||||
KeyBufferSize string `form:"key_buffer_size" json:"key_buffer_size"`
|
||||
SortBufferSize string `form:"sort_buffer_size" json:"sort_buffer_size"`
|
||||
ReadBufferSize string `form:"read_buffer_size" json:"read_buffer_size"`
|
||||
ReadRndBufferSize string `form:"read_rnd_buffer_size" json:"read_rnd_buffer_size"`
|
||||
JoinBufferSize string `form:"join_buffer_size" json:"join_buffer_size"`
|
||||
ThreadCacheSize string `form:"thread_cache_size" json:"thread_cache_size"`
|
||||
ThreadStack string `form:"thread_stack" json:"thread_stack"`
|
||||
TmpTableSize string `form:"tmp_table_size" json:"tmp_table_size"`
|
||||
MaxHeapTableSize string `form:"max_heap_table_size" json:"max_heap_table_size"`
|
||||
MyisamSortBufferSize string `form:"myisam_sort_buffer_size" json:"myisam_sort_buffer_size"`
|
||||
// InnoDB
|
||||
InnodbBufferPoolSize string `form:"innodb_buffer_pool_size" json:"innodb_buffer_pool_size"`
|
||||
InnodbLogBufferSize string `form:"innodb_log_buffer_size" json:"innodb_log_buffer_size"`
|
||||
InnodbFlushLogAtTrxCommit string `form:"innodb_flush_log_at_trx_commit" json:"innodb_flush_log_at_trx_commit"`
|
||||
InnodbLockWaitTimeout string `form:"innodb_lock_wait_timeout" json:"innodb_lock_wait_timeout"`
|
||||
InnodbMaxDirtyPagesPct string `form:"innodb_max_dirty_pages_pct" json:"innodb_max_dirty_pages_pct"`
|
||||
InnodbReadIoThreads string `form:"innodb_read_io_threads" json:"innodb_read_io_threads"`
|
||||
InnodbWriteIoThreads string `form:"innodb_write_io_threads" json:"innodb_write_io_threads"`
|
||||
InnodbBufferPoolSize string `form:"innodb_buffer_pool_size" json:"innodb_buffer_pool_size"`
|
||||
InnodbLogBufferSize string `form:"innodb_log_buffer_size" json:"innodb_log_buffer_size"`
|
||||
InnodbFlushLogAtTrxCommit string `form:"innodb_flush_log_at_trx_commit" json:"innodb_flush_log_at_trx_commit" validate:"in:0,1,2"`
|
||||
InnodbLockWaitTimeout string `form:"innodb_lock_wait_timeout" json:"innodb_lock_wait_timeout"`
|
||||
InnodbMaxDirtyPagesPct string `form:"innodb_max_dirty_pages_pct" json:"innodb_max_dirty_pages_pct"`
|
||||
InnodbReadIoThreads string `form:"innodb_read_io_threads" json:"innodb_read_io_threads"`
|
||||
InnodbWriteIoThreads string `form:"innodb_write_io_threads" json:"innodb_write_io_threads"`
|
||||
// 日志
|
||||
SlowQueryLog string `form:"slow_query_log" json:"slow_query_log"`
|
||||
LongQueryTime string `form:"long_query_time" json:"long_query_time"`
|
||||
|
||||
+20
-13
@@ -8,27 +8,28 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
"resty.dev/v3"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/pkg/tools"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/tools"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -50,6 +51,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Delete("/stream/upstreams/{name}", s.DeleteStreamUpstream)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("nginx")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read(fmt.Sprintf("%s/server/nginx/conf/nginx.conf", app.Root))
|
||||
if err != nil {
|
||||
@@ -96,8 +102,9 @@ func (s *App) ClearErrorLog(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
client := resty.New().SetTimeout(10 * time.Second)
|
||||
defer func(client *resty.Client) { _ = client.Close() }(client)
|
||||
resp, err := client.R().Get("http://127.0.0.1/nginx_status")
|
||||
if err != nil || !resp.IsSuccess() {
|
||||
if err != nil || !resp.IsStatusSuccess() {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
@@ -271,8 +278,8 @@ func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// getNginxValue 从 Nginx 配置内容中获取指定指令的值
|
||||
func (s *App) getNginxValue(content string, key string) string {
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
|
||||
@@ -9,14 +9,14 @@ type UpdateConfig struct {
|
||||
// ConfigTune Nginx 配置调整
|
||||
type ConfigTune struct {
|
||||
// 常规设置
|
||||
WorkerProcesses string `form:"worker_processes" json:"worker_processes"`
|
||||
WorkerConnections string `form:"worker_connections" json:"worker_connections"`
|
||||
KeepaliveTimeout string `form:"keepalive_timeout" json:"keepalive_timeout"`
|
||||
ClientMaxBodySize string `form:"client_max_body_size" json:"client_max_body_size"`
|
||||
ClientBodyBufferSize string `form:"client_body_buffer_size" json:"client_body_buffer_size"`
|
||||
ClientHeaderBufferSize string `form:"client_header_buffer_size" json:"client_header_buffer_size"`
|
||||
WorkerProcesses string `form:"worker_processes" json:"worker_processes"`
|
||||
WorkerConnections string `form:"worker_connections" json:"worker_connections"`
|
||||
KeepaliveTimeout string `form:"keepalive_timeout" json:"keepalive_timeout"`
|
||||
ClientMaxBodySize string `form:"client_max_body_size" json:"client_max_body_size"`
|
||||
ClientBodyBufferSize string `form:"client_body_buffer_size" json:"client_body_buffer_size"`
|
||||
ClientHeaderBufferSize string `form:"client_header_buffer_size" json:"client_header_buffer_size"`
|
||||
ServerNamesHashBucketSize string `form:"server_names_hash_bucket_size" json:"server_names_hash_bucket_size"`
|
||||
ServerTokens string `form:"server_tokens" json:"server_tokens"`
|
||||
ServerTokens string `form:"server_tokens" json:"server_tokens"`
|
||||
// Gzip 压缩
|
||||
Gzip string `form:"gzip" json:"gzip"`
|
||||
GzipMinLength string `form:"gzip_min_length" json:"gzip_min_length"`
|
||||
@@ -39,22 +39,22 @@ type ConfigTune struct {
|
||||
}
|
||||
|
||||
type StreamServer struct {
|
||||
Name string `form:"name" json:"name" validate:"required|regex:^[a-zA-Z0-9_-]+$"` // 配置名称,用于文件命名
|
||||
Listen string `form:"listen" json:"listen" validate:"required"` // 监听地址,如: "12345", "0.0.0.0:12345", "[::]:12345"
|
||||
UDP bool `form:"udp" json:"udp"` // 是否 UDP 协议
|
||||
ProxyPass string `form:"proxy_pass" json:"proxy_pass" validate:"required"` // 代理地址,如: "127.0.0.1:3306", "upstream_name"
|
||||
ProxyProtocol bool `form:"proxy_protocol" json:"proxy_protocol"` // 是否启用 PROXY 协议
|
||||
ProxyTimeout time.Duration `form:"proxy_timeout" json:"proxy_timeout"` // 代理超时时间
|
||||
ProxyConnectTimeout time.Duration `form:"proxy_connect_timeout" json:"proxy_connect_timeout"` // 代理连接超时时间
|
||||
SSL bool `form:"ssl" json:"ssl"` // 是否启用 SSL
|
||||
SSLCertificate string `form:"ssl_certificate" json:"ssl_certificate" validate:"requiredIf:SSL,true"` // SSL 证书路径
|
||||
SSLCertificateKey string `form:"ssl_certificate_key" json:"ssl_certificate_key" validate:"requiredIf:SSL,true"` // SSL 私钥路径
|
||||
Name string `form:"name" json:"name" validate:"required && regex:\"^[a-zA-Z0-9_-]+$\""` // 配置名称,用于文件命名
|
||||
Listen string `form:"listen" json:"listen" validate:"required"` // 监听地址,如: "12345", "0.0.0.0:12345", "[::]:12345"
|
||||
UDP bool `form:"udp" json:"udp"` // 是否 UDP 协议
|
||||
ProxyPass string `form:"proxy_pass" json:"proxy_pass" validate:"required"` // 代理地址,如: "127.0.0.1:3306", "upstream_name"
|
||||
ProxyProtocol bool `form:"proxy_protocol" json:"proxy_protocol"` // 是否启用 PROXY 协议
|
||||
ProxyTimeout time.Duration `form:"proxy_timeout" json:"proxy_timeout"` // 代理超时时间
|
||||
ProxyConnectTimeout time.Duration `form:"proxy_connect_timeout" json:"proxy_connect_timeout"` // 代理连接超时时间
|
||||
SSL bool `form:"ssl" json:"ssl"` // 是否启用 SSL
|
||||
SSLCertificate string `form:"ssl_certificate" json:"ssl_certificate" validate:"required_if:SSL,true"` // SSL 证书路径
|
||||
SSLCertificateKey string `form:"ssl_certificate_key" json:"ssl_certificate_key" validate:"required_if:SSL,true"` // SSL 私钥路径
|
||||
}
|
||||
|
||||
type StreamUpstream struct {
|
||||
Name string `form:"name" json:"name" validate:"required|regex:^[a-zA-Z0-9_-]+$"` // 上游名称
|
||||
Servers map[string]string `form:"servers" json:"servers" validate:"required"` // 上游服务器及配置,如: map["127.0.0.1:3306"] = "weight=5"
|
||||
Algo string `form:"algo" json:"algo"` // 负载均衡算法,如: "least_conn", "hash $remote_addr"
|
||||
Resolver []string `form:"resolver" json:"resolver"` // DNS 解析器,如: ["8.8.8.8", "ipv6=off"]
|
||||
ResolverTimeout time.Duration `form:"resolver_timeout" json:"resolver_timeout"` // DNS 解析超时时间
|
||||
Name string `form:"name" json:"name" validate:"required && regex:\"^[a-zA-Z0-9_-]+$\""` // 上游名称
|
||||
Servers map[string]string `form:"servers" json:"servers" validate:"required"` // 上游服务器及配置,如: map["127.0.0.1:3306"] = "weight=5"
|
||||
Algo string `form:"algo" json:"algo"` // 负载均衡算法,如: "least_conn", "hash $remote_addr"
|
||||
Resolver []string `form:"resolver" json:"resolver"` // DNS 解析器,如: ["8.8.8.8", "ipv6=off"]
|
||||
ResolverTimeout time.Duration `form:"resolver_timeout" json:"resolver_timeout"` // DNS 解析超时时间
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
webserverNginx "github.com/acepanel/panel/pkg/webserver/nginx"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
webserverNginx "github.com/acepanel/panel/v3/pkg/webserver/nginx"
|
||||
)
|
||||
|
||||
// ListStreamServers 获取 Stream Server 列表
|
||||
@@ -547,34 +548,31 @@ func (s *App) saveStreamServerConfig(filePath string, server *StreamServer) erro
|
||||
// saveStreamUpstreamConfig 生成并保存 Stream Upstream 配置
|
||||
func (s *App) saveStreamUpstreamConfig(filePath string, upstream *StreamUpstream) error {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(fmt.Sprintf("upstream %s {\n", upstream.Name))
|
||||
_, _ = fmt.Fprintf(&sb, "upstream %s {\n", upstream.Name)
|
||||
|
||||
// 负载均衡算法
|
||||
if upstream.Algo != "" {
|
||||
sb.WriteString(fmt.Sprintf(" %s;\n", upstream.Algo))
|
||||
_, _ = fmt.Fprintf(&sb, " %s;\n", upstream.Algo)
|
||||
}
|
||||
|
||||
// resolver 配置
|
||||
if len(upstream.Resolver) > 0 {
|
||||
sb.WriteString(fmt.Sprintf(" resolver %s;\n", strings.Join(upstream.Resolver, " ")))
|
||||
_, _ = fmt.Fprintf(&sb, " resolver %s;\n", strings.Join(upstream.Resolver, " "))
|
||||
if upstream.ResolverTimeout > 0 {
|
||||
sb.WriteString(fmt.Sprintf(" resolver_timeout %s;\n", formatNginxDuration(upstream.ResolverTimeout)))
|
||||
_, _ = fmt.Fprintf(&sb, " resolver_timeout %s;\n", formatNginxDuration(upstream.ResolverTimeout))
|
||||
}
|
||||
}
|
||||
|
||||
// 服务器列表
|
||||
var addrs []string
|
||||
for addr := range upstream.Servers {
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
addrs := lo.Keys(upstream.Servers)
|
||||
sort.Strings(addrs)
|
||||
|
||||
for _, addr := range addrs {
|
||||
options := upstream.Servers[addr]
|
||||
if options != "" {
|
||||
sb.WriteString(fmt.Sprintf(" server %s %s;\n", addr, options))
|
||||
_, _ = fmt.Fprintf(&sb, " server %s %s;\n", addr, options)
|
||||
} else {
|
||||
sb.WriteString(fmt.Sprintf(" server %s;\n", addr))
|
||||
_, _ = fmt.Fprintf(&sb, " server %s;\n", addr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,27 @@ package openresty
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/internal/apps/nginx"
|
||||
"github.com/acepanel/panel/v3/internal/apps/nginx"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
nginx *nginx.App
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(nginxApp *nginx.App) (*App, error) {
|
||||
return &App{
|
||||
nginx: nginx.NewApp(t),
|
||||
}
|
||||
nginx: nginxApp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
s.nginx.Route(r)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("nginx")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package opensearch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
"go.yaml.in/yaml/v4"
|
||||
"resty.dev/v3"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
|
||||
return &App{t: t}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("opensearch")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("opensearch")
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get opensearch status: %v", err))
|
||||
return
|
||||
}
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
port := s.getPort()
|
||||
client := resty.New().SetTimeout(10 * time.Second)
|
||||
defer func(client *resty.Client) { _ = client.Close() }(client)
|
||||
resp, err := client.R().Get(fmt.Sprintf("http://127.0.0.1:%s/_cluster/health", port))
|
||||
if err != nil || !resp.IsStatusSuccess() {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
var health struct {
|
||||
ClusterName string `json:"cluster_name"`
|
||||
Status string `json:"status"`
|
||||
NumberOfNodes int `json:"number_of_nodes"`
|
||||
NumberOfDataNodes int `json:"number_of_data_nodes"`
|
||||
ActiveShards int `json:"active_shards"`
|
||||
ActivePrimaryShards int `json:"active_primary_shards"`
|
||||
RelocatingShards int `json:"relocating_shards"`
|
||||
UnassignedShards int `json:"unassigned_shards"`
|
||||
}
|
||||
if err = json.Unmarshal(resp.Bytes(), &health); err != nil {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Cluster Name"), Value: health.ClusterName},
|
||||
{Name: s.t.Get("Cluster Status"), Value: health.Status},
|
||||
{Name: s.t.Get("Number of Nodes"), Value: cast.ToString(health.NumberOfNodes)},
|
||||
{Name: s.t.Get("Number of Data Nodes"), Value: cast.ToString(health.NumberOfDataNodes)},
|
||||
{Name: s.t.Get("Active Shards"), Value: cast.ToString(health.ActiveShards)},
|
||||
{Name: s.t.Get("Active Primary Shards"), Value: cast.ToString(health.ActivePrimaryShards)},
|
||||
{Name: s.t.Get("Relocating Shards"), Value: cast.ToString(health.RelocatingShards)},
|
||||
{Name: s.t.Get("Unassigned Shards"), Value: cast.ToString(health.UnassignedShards)},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(s.configPath())
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("opensearch"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 OpenSearch 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
_ = yaml.Unmarshal([]byte(raw), &cfg)
|
||||
if cfg == nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
jvmRaw, _ := io.Read(s.jvmOptionsPath())
|
||||
heapInit, heapMax := s.parseJVMHeap(jvmRaw)
|
||||
|
||||
tune := ConfigTune{
|
||||
ClusterName: s.getYAMLValue(cfg, "cluster.name"),
|
||||
NodeName: s.getYAMLValue(cfg, "node.name"),
|
||||
NetworkHost: s.getYAMLValue(cfg, "network.host"),
|
||||
HTTPPort: s.getYAMLValue(cfg, "http.port"),
|
||||
DiscoveryType: s.getYAMLValue(cfg, "discovery.type"),
|
||||
PathData: s.getYAMLValue(cfg, "path.data"),
|
||||
PathLogs: s.getYAMLValue(cfg, "path.logs"),
|
||||
HeapInitSize: heapInit,
|
||||
HeapMaxSize: heapMax,
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新 OpenSearch 配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
if err = yaml.Unmarshal([]byte(raw), &cfg); err != nil {
|
||||
cfg = make(map[string]any)
|
||||
}
|
||||
|
||||
s.setYAMLValue(cfg, "cluster.name", req.ClusterName)
|
||||
s.setYAMLValue(cfg, "node.name", req.NodeName)
|
||||
s.setYAMLValue(cfg, "network.host", req.NetworkHost)
|
||||
s.setYAMLValue(cfg, "http.port", req.HTTPPort)
|
||||
s.setYAMLValue(cfg, "discovery.type", req.DiscoveryType)
|
||||
s.setYAMLValue(cfg, "path.data", req.PathData)
|
||||
s.setYAMLValue(cfg, "path.logs", req.PathLogs)
|
||||
|
||||
data, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
if err = io.Write(s.configPath(), string(data), 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if req.HeapInitSize != "" || req.HeapMaxSize != "" {
|
||||
jvmRaw, _ := io.Read(s.jvmOptionsPath())
|
||||
jvmRaw = s.setJVMHeap(jvmRaw, req.HeapInitSize, req.HeapMaxSize)
|
||||
if err = io.Write(s.jvmOptionsPath(), jvmRaw, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("opensearch"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/opensearch/config/opensearch.yml", app.Root)
|
||||
}
|
||||
|
||||
func (s *App) jvmOptionsPath() string {
|
||||
return fmt.Sprintf("%s/server/opensearch/config/jvm.options", app.Root)
|
||||
}
|
||||
|
||||
func (s *App) getPort() string {
|
||||
raw, _ := io.Read(s.configPath())
|
||||
var cfg map[string]any
|
||||
_ = yaml.Unmarshal([]byte(raw), &cfg)
|
||||
if cfg != nil {
|
||||
if v := s.getYAMLValue(cfg, "http.port"); v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return "9200"
|
||||
}
|
||||
|
||||
// getYAMLValue 获取 YAML 值,优先匹配平铺键(如 "path.data"),回退到嵌套键(如 path -> data)
|
||||
func (s *App) getYAMLValue(cfg map[string]any, key string) string {
|
||||
// 优先匹配平铺键(安装脚本用 sed 生成的格式)
|
||||
if val, ok := cfg[key]; ok {
|
||||
return cast.ToString(val)
|
||||
}
|
||||
// 回退到嵌套键
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
val, ok := cfg[parts[0]]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if len(parts) == 1 {
|
||||
return cast.ToString(val)
|
||||
}
|
||||
nested, ok := val.(map[string]any)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return s.getYAMLValue(nested, parts[1])
|
||||
}
|
||||
|
||||
// setYAMLValue 设置 YAML 值
|
||||
func (s *App) setYAMLValue(cfg map[string]any, key string, value string) {
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
// 使用平铺键,同时清理可能存在的嵌套键
|
||||
cfg[key] = value
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
if len(parts) == 2 {
|
||||
if nested, ok := cfg[parts[0]].(map[string]any); ok {
|
||||
delete(nested, parts[1])
|
||||
if len(nested) == 0 {
|
||||
delete(cfg, parts[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *App) parseJVMHeap(content string) (initSize, maxSize string) {
|
||||
reInit := regexp.MustCompile(`(?m)^-Xms(\S+)`)
|
||||
reMax := regexp.MustCompile(`(?m)^-Xmx(\S+)`)
|
||||
if m := reInit.FindStringSubmatch(content); len(m) == 2 {
|
||||
initSize = m[1]
|
||||
}
|
||||
if m := reMax.FindStringSubmatch(content); len(m) == 2 {
|
||||
maxSize = m[1]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *App) setJVMHeap(content string, initSize, maxSize string) string {
|
||||
if initSize != "" {
|
||||
re := regexp.MustCompile(`(?m)^-Xms\S+`)
|
||||
if re.MatchString(content) {
|
||||
content = re.ReplaceAllString(content, "-Xms"+initSize)
|
||||
} else {
|
||||
content += "\n-Xms" + initSize
|
||||
}
|
||||
}
|
||||
if maxSize != "" {
|
||||
re := regexp.MustCompile(`(?m)^-Xmx\S+`)
|
||||
if re.MatchString(content) {
|
||||
content = re.ReplaceAllString(content, "-Xmx"+maxSize)
|
||||
} else {
|
||||
content += "\n-Xmx" + maxSize
|
||||
}
|
||||
}
|
||||
return content
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package opensearch
|
||||
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigTune OpenSearch 配置调整
|
||||
type ConfigTune struct {
|
||||
// 集群
|
||||
ClusterName string `form:"cluster_name" json:"cluster_name"`
|
||||
NodeName string `form:"node_name" json:"node_name"`
|
||||
NetworkHost string `form:"network_host" json:"network_host"`
|
||||
HTTPPort string `form:"http_port" json:"http_port"`
|
||||
DiscoveryType string `form:"discovery_type" json:"discovery_type"`
|
||||
// 路径
|
||||
PathData string `form:"path_data" json:"path_data"`
|
||||
PathLogs string `form:"path_logs" json:"path_logs"`
|
||||
// JVM
|
||||
HeapInitSize string `form:"heap_init_size" json:"heap_init_size"`
|
||||
HeapMaxSize string `form:"heap_max_size" json:"heap_max_size"`
|
||||
}
|
||||
@@ -2,22 +2,24 @@ package percona
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/internal/apps/mysql"
|
||||
"github.com/acepanel/panel/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/apps/mysql"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
mysql *mysql.App
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, setting biz.SettingRepo, databaseServer biz.DatabaseServerRepo) *App {
|
||||
func NewApp(mysqlApp *mysql.App) (*App, error) {
|
||||
return &App{
|
||||
mysql: mysql.NewApp(t, setting, databaseServer),
|
||||
}
|
||||
mysql: mysqlApp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
s.mysql.Route(r)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
return s.mysql.Status()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,548 @@
|
||||
package pgadmin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
stdio "io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/chix/v2"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/config"
|
||||
"github.com/acepanel/panel/v3/pkg/firewall"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
conf *config.Config
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(conf *config.Config, t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
conf: conf,
|
||||
databaseServerRepo: databaseServerRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// pgadminLanguage 面板语言映射为 pgAdmin 语言代码
|
||||
func (s *App) pgadminLanguage() string {
|
||||
switch s.conf.App.Locale {
|
||||
case "":
|
||||
return ""
|
||||
case "zh_CN":
|
||||
return "zh_Hans_CN"
|
||||
case "zh_TW":
|
||||
return "zh_Hant_TW"
|
||||
default:
|
||||
return s.conf.App.Locale
|
||||
}
|
||||
}
|
||||
|
||||
// clientIP 获取请求来源 IP,面板位于反代之后时优先取配置的 IP 头
|
||||
func (s *App) clientIP(r *http.Request) string {
|
||||
ip := r.RemoteAddr
|
||||
if header := s.conf.HTTP.IPHeader; header != "" && r.Header.Get(header) != "" {
|
||||
ip = strings.TrimSpace(strings.Split(r.Header.Get(header), ",")[0])
|
||||
}
|
||||
if host, _, err := net.SplitHostPort(ip); err == nil {
|
||||
ip = host
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/info", s.Info)
|
||||
r.Post("/port", s.UpdatePort)
|
||||
r.Post("/login", s.Login)
|
||||
r.Post("/update_username", s.UpdateUsername)
|
||||
r.Post("/reset_password", s.ResetPassword)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("pgadmin")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) path() string {
|
||||
return fmt.Sprintf("%s/server/pgadmin", app.Root)
|
||||
}
|
||||
|
||||
// port 从 systemd 环境文件中解析监听端口
|
||||
func (s *App) port() (uint, error) {
|
||||
conf, err := io.Read(fmt.Sprintf("%s/pgadmin.conf", s.path()))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
match := regexp.MustCompile(`PGADMIN_LISTEN=.+:(\d+)`).FindStringSubmatch(conf)
|
||||
if len(match) < 2 {
|
||||
return 0, errors.New(s.t.Get("pgAdmin port not found"))
|
||||
}
|
||||
|
||||
return cast.ToUint(match[1]), nil
|
||||
}
|
||||
|
||||
// credential 读取安装时生成的初始凭据(邮箱与密码)
|
||||
func (s *App) credential() (string, string) {
|
||||
raw, err := io.Read(fmt.Sprintf("%s/credential", s.path()))
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
lines := strings.Split(strings.TrimSpace(raw), "\n")
|
||||
if len(lines) < 2 {
|
||||
return strings.TrimSpace(lines[0]), ""
|
||||
}
|
||||
|
||||
return strings.TrimSpace(lines[0]), strings.TrimSpace(lines[1])
|
||||
}
|
||||
|
||||
func (s *App) Info(w http.ResponseWriter, r *http.Request) {
|
||||
port, err := s.port()
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
email, password := s.credential()
|
||||
|
||||
service.Success(w, chix.M{
|
||||
"port": port,
|
||||
"email": email,
|
||||
"password": password,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *App) UpdatePort(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdatePort](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
conf := fmt.Sprintf("%s/pgadmin.conf", s.path())
|
||||
content, err := io.Read(conf)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
content = regexp.MustCompile(`PGADMIN_LISTEN=(.+):\d+`).ReplaceAllString(content, "PGADMIN_LISTEN=${1}:"+cast.ToString(req.Port))
|
||||
if err = io.Write(conf, content, 0600); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
fw := firewall.NewFirewall()
|
||||
err = fw.Port(firewall.FireInfo{
|
||||
Type: firewall.TypeNormal,
|
||||
PortStart: req.Port,
|
||||
PortEnd: req.Port,
|
||||
Strategy: firewall.StrategyAccept,
|
||||
Direction: firewall.DirectionIn,
|
||||
}, firewall.OperationAdd)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("pgadmin"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to restart pgAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// serversFile pgAdmin dump-servers/load-servers 的 JSON 结构
|
||||
type serversFile struct {
|
||||
Servers map[string]serverEntry `json:"Servers"`
|
||||
}
|
||||
|
||||
type serverEntry struct {
|
||||
Name string `json:"Name"`
|
||||
Group string `json:"Group"`
|
||||
Host string `json:"Host"`
|
||||
Port int `json:"Port"`
|
||||
MaintenanceDB string `json:"MaintenanceDB"`
|
||||
Username string `json:"Username"`
|
||||
SSLMode string `json:"SSLMode,omitempty"`
|
||||
PassFile string `json:"PassFile,omitempty"`
|
||||
}
|
||||
|
||||
// escapePgpass 转义 pgpass 字段中的反斜杠与冒号
|
||||
func escapePgpass(s string) string {
|
||||
return strings.NewReplacer(`\`, `\\`, `:`, `\:`).Replace(s)
|
||||
}
|
||||
|
||||
// existingServers 只读 pgAdmin 配置库查询 Servers 组内已注册的服务器
|
||||
// CLI 每次调用都要冷启动整个 pgAdmin 应用,直读库快数个量级
|
||||
func (s *App) existingServers(email string) (map[string]struct{}, error) {
|
||||
db, err := sql.Open("sqlite", fmt.Sprintf("file:%s/data/pgadmin.db?mode=ro", s.path()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = db.Close() }()
|
||||
|
||||
rows, err := db.Query(`SELECT s.host, s.port, s.username FROM server s
|
||||
JOIN servergroup g ON s.servergroup_id = g.id
|
||||
JOIN "user" u ON s.user_id = u.id
|
||||
WHERE u.email = ? AND g.name = 'Servers'`, email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
existing := make(map[string]struct{})
|
||||
for rows.Next() {
|
||||
var host, username sql.NullString
|
||||
var port sql.NullInt64
|
||||
if err = rows.Scan(&host, &port, &username); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
existing[fmt.Sprintf("%s:%d:%s", host.String, port.Int64, username.String)] = struct{}{}
|
||||
}
|
||||
return existing, rows.Err()
|
||||
}
|
||||
|
||||
// dumpExistingServers 通过 CLI 导出查询已注册服务器,直读配置库失败时的回退路径
|
||||
func (s *App) dumpExistingServers(email string) map[string]struct{} {
|
||||
dump := filepath.Join(os.TempDir(), "pgadmin-servers.json")
|
||||
defer func() { _ = io.Remove(dump) }()
|
||||
_, _ = shell.Execf("%s/cli dump-servers '%s' --user '%s'", s.path(), dump, email)
|
||||
|
||||
existing := make(map[string]struct{})
|
||||
if raw, err := io.Read(dump); err == nil {
|
||||
var dumped serversFile
|
||||
if err = json.Unmarshal([]byte(raw), &dumped); err == nil {
|
||||
for _, item := range dumped.Servers {
|
||||
// 只认默认 Servers 组内的条目,历史版本同步进其他分组的会在此组补齐
|
||||
if item.Group != "Servers" {
|
||||
continue
|
||||
}
|
||||
existing[fmt.Sprintf("%s:%d:%s", item.Host, item.Port, item.Username)] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
return existing
|
||||
}
|
||||
|
||||
// syncServers 将面板中全部 PostgreSQL 服务器合并注册到 pgAdmin,凭据写入 pgpass 实现免密
|
||||
// 仅追加 pgAdmin 中缺失的服务器,不影响用户在 pgAdmin 中手动添加的内容
|
||||
func (s *App) syncServers(ctx context.Context, email string) error {
|
||||
servers, _, err := s.databaseServerRepo.List(ctx, 1, 10000, string(biz.DatabaseTypePostgresql))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(servers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pgAdmin server 模式下 PassFile 以用户 storage 目录为根,目录名为邮箱 @ 转 _
|
||||
storageDir := fmt.Sprintf("%s/data/storage/%s", s.path(), strings.ReplaceAll(email, "@", "_"))
|
||||
pgpass := filepath.Join(storageDir, "pgpass")
|
||||
|
||||
// 重写 pgpass 中面板服务器的凭据行,保留其他行
|
||||
prefixes := make([]string, 0, len(servers))
|
||||
entries := make([]string, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
prefix := fmt.Sprintf("%s:%d:*:%s:", escapePgpass(server.Host), server.Port, escapePgpass(server.Username))
|
||||
prefixes = append(prefixes, prefix)
|
||||
entries = append(entries, prefix+escapePgpass(server.Password))
|
||||
}
|
||||
var lines []string
|
||||
if raw, err := io.Read(pgpass); err == nil {
|
||||
for line := range strings.SplitSeq(strings.TrimSpace(raw), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
panelOwned := false
|
||||
for _, prefix := range prefixes {
|
||||
if strings.HasPrefix(line, prefix) {
|
||||
panelOwned = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !panelOwned {
|
||||
lines = append(lines, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
lines = append(lines, entries...)
|
||||
if err = os.MkdirAll(storageDir, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = io.Write(pgpass, strings.Join(lines, "\n")+"\n", 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 查询 pgAdmin 已有服务器用于查缺,直读配置库,异常时回退 CLI 导出
|
||||
existing, err := s.existingServers(email)
|
||||
if err != nil {
|
||||
existing = s.dumpExistingServers(email)
|
||||
}
|
||||
|
||||
// 一次性合并导入缺失的服务器
|
||||
missing := make(map[string]serverEntry)
|
||||
for i, server := range servers {
|
||||
if _, ok := existing[fmt.Sprintf("%s:%d:%s", server.Host, server.Port, server.Username)]; ok {
|
||||
continue
|
||||
}
|
||||
missing[cast.ToString(i+1)] = serverEntry{
|
||||
Name: server.Name,
|
||||
Group: "Servers",
|
||||
Host: server.Host,
|
||||
Port: int(server.Port),
|
||||
MaintenanceDB: "postgres",
|
||||
Username: server.Username,
|
||||
SSLMode: "prefer",
|
||||
PassFile: "/pgpass",
|
||||
}
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
load := filepath.Join(os.TempDir(), "pgadmin-servers-add.json")
|
||||
defer func() { _ = io.Remove(load) }()
|
||||
payload, err := json.Marshal(serversFile{Servers: missing})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = io.Write(load, string(payload), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
if out, err := shell.Execf("%s/cli load-servers '%s' --user '%s'", s.path(), load, email); err != nil {
|
||||
return errors.Join(err, errors.New(out))
|
||||
}
|
||||
// CLI 以 root 运行,修正数据目录属主避免服务写入失败
|
||||
if _, err = shell.Execf("chown -R www:www %s/data", s.path()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 常态路径仅写入了 pgpass,精确修正属主即可
|
||||
if err = io.Chown(storageDir, "www", "www"); err != nil {
|
||||
return err
|
||||
}
|
||||
return io.Chown(pgpass, "www", "www")
|
||||
}
|
||||
|
||||
// Login 同步面板全部 PostgreSQL 服务器后代理登录 pgAdmin 并将会话 Cookie 转发给浏览器
|
||||
// 面板与 pgAdmin 同主机不同端口,Cookie 按主机共享,浏览器凭转发的 Cookie 即为已登录态
|
||||
func (s *App) Login(w http.ResponseWriter, r *http.Request) {
|
||||
port, err := s.port()
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
email, password := s.credential()
|
||||
if email == "" || password == "" {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("pgAdmin credential file not found"))
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.syncServers(r.Context(), email); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to sync servers to pgAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
}
|
||||
|
||||
// 透传浏览器 IP 与 UA,pgAdmin 增强 Cookie 保护将会话绑定到 sha256(IP|UA),
|
||||
// 伪装成浏览器身份登录后浏览器直连即可通过校验,无需关闭该保护
|
||||
clientIP := s.clientIP(r)
|
||||
clientUA := r.UserAgent()
|
||||
|
||||
// 获取登录页以取得会话 Cookie 与 CSRF token
|
||||
loginURL := fmt.Sprintf("http://127.0.0.1:%d/login", port)
|
||||
pageReq, err := http.NewRequestWithContext(r.Context(), http.MethodGet, loginURL, nil)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
pageReq.Header.Set("User-Agent", clientUA)
|
||||
pageReq.Header.Set("X-Forwarded-For", clientIP)
|
||||
pageResp, err := client.Do(pageReq)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to request pgAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
defer func() { _ = pageResp.Body.Close() }()
|
||||
page, err := stdio.ReadAll(stdio.LimitReader(pageResp.Body, 4<<20))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to request pgAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
// 登录页为 React 渲染,CSRF token 在内嵌 JSON 中,保留 input 形态兼容旧版本
|
||||
csrf := regexp.MustCompile(`"csrfToken":\s*"([^"]+)"`).FindStringSubmatch(string(page))
|
||||
if len(csrf) < 2 {
|
||||
csrf = regexp.MustCompile(`name="csrf_token"[^>]*value="([^"]+)"`).FindStringSubmatch(string(page))
|
||||
}
|
||||
if len(csrf) < 2 {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to parse pgAdmin login page"))
|
||||
return
|
||||
}
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("csrf_token", csrf[1])
|
||||
form.Set("email", email)
|
||||
form.Set("password", password)
|
||||
// 语言跟随面板设置,pgAdmin 会将 language 字段固化进会话
|
||||
if lang := s.pgadminLanguage(); lang != "" {
|
||||
form.Set("language", lang)
|
||||
}
|
||||
|
||||
loginReq, err := http.NewRequestWithContext(r.Context(), http.MethodPost, fmt.Sprintf("http://127.0.0.1:%d/authenticate/login", port), strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
loginReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
loginReq.Header.Set("User-Agent", clientUA)
|
||||
loginReq.Header.Set("X-Forwarded-For", clientIP)
|
||||
for _, cookie := range pageResp.Cookies() {
|
||||
loginReq.AddCookie(cookie)
|
||||
}
|
||||
|
||||
loginResp, err := client.Do(loginReq)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to request pgAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
defer func() { _ = loginResp.Body.Close() }()
|
||||
_, _ = stdio.Copy(stdio.Discard, stdio.LimitReader(loginResp.Body, 4<<20))
|
||||
|
||||
// 登录成功时 pgAdmin 返回 302 且跳转目标不是登录页
|
||||
location := loginResp.Header.Get("Location")
|
||||
if loginResp.StatusCode != http.StatusFound || strings.Contains(location, "/login") {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to login pgAdmin, please check the credential of pgAdmin"))
|
||||
return
|
||||
}
|
||||
|
||||
// 改写 SameSite 以兼容面板 https 跳转 http 的场景
|
||||
for _, cookie := range append(pageResp.Cookies(), loginResp.Cookies()...) {
|
||||
cookie.SameSite = http.SameSiteLaxMode
|
||||
cookie.Secure = false
|
||||
http.SetCookie(w, cookie)
|
||||
}
|
||||
|
||||
service.Success(w, chix.M{
|
||||
"port": port,
|
||||
})
|
||||
}
|
||||
|
||||
// ResetPassword 通过 CLI 重置管理员密码并同步凭据文件
|
||||
// UpdateUsername 修改管理员账号,迁移服务器配置与用户存储目录
|
||||
func (s *App) UpdateUsername(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateUsername](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
oldEmail, password := s.credential()
|
||||
if oldEmail == "" || password == "" {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("pgAdmin credential file not found"))
|
||||
return
|
||||
}
|
||||
if req.Username == oldEmail {
|
||||
service.Success(w, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// 以当前密码创建新管理员账号
|
||||
if out, err := shell.Execf("%s/cli add-user '%s' '%s' --admin", s.path(), req.Username, password); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to create new account: %v", errors.Join(err, errors.New(out))))
|
||||
return
|
||||
}
|
||||
|
||||
// 迁移服务器连接配置到新账号
|
||||
dump := filepath.Join(os.TempDir(), "pgadmin-servers-migrate.json")
|
||||
defer func() { _ = io.Remove(dump) }()
|
||||
_, _ = shell.Execf("%s/cli dump-servers '%s' --user '%s'", s.path(), dump, oldEmail)
|
||||
if io.Exists(dump) {
|
||||
_, _ = shell.Execf("%s/cli load-servers '%s' --user '%s'", s.path(), dump, req.Username)
|
||||
}
|
||||
|
||||
// 删除旧账号
|
||||
if out, err := shell.Execf("%s/cli delete-user '%s' --yes", s.path(), oldEmail); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to delete old account: %v", errors.Join(err, errors.New(out))))
|
||||
return
|
||||
}
|
||||
|
||||
// 迁移用户存储目录(pgpass 等),目录名为邮箱 @ 转 _
|
||||
oldDir := fmt.Sprintf("%s/data/storage/%s", s.path(), strings.ReplaceAll(oldEmail, "@", "_"))
|
||||
newDir := fmt.Sprintf("%s/data/storage/%s", s.path(), strings.ReplaceAll(req.Username, "@", "_"))
|
||||
if io.Exists(oldDir) && !io.Exists(newDir) {
|
||||
_ = os.Rename(oldDir, newDir)
|
||||
}
|
||||
|
||||
// CLI 以 root 运行,修正数据目录属主避免服务写入失败
|
||||
if _, err = shell.Execf("chown -R www:www %s/data", s.path()); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 更新凭据文件,下次登录按新账号重新同步
|
||||
if err = io.Write(fmt.Sprintf("%s/credential", s.path()), req.Username+"\n"+password+"\n", 0600); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
func (s *App) ResetPassword(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ResetPassword](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
email, _ := s.credential()
|
||||
if email == "" {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("pgAdmin credential file not found"))
|
||||
return
|
||||
}
|
||||
|
||||
// cli 为安装脚本生成的稳定入口,屏蔽上游命令名随大版本变化
|
||||
if out, err := shell.Execf("%s/cli update-user '%s' --password '%s'", s.path(), email, req.Password); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to reset password: %v", errors.Join(err, errors.New(out))))
|
||||
return
|
||||
}
|
||||
// CLI 以 root 运行,修正数据目录属主避免服务写入失败
|
||||
if _, err = shell.Execf("chown -R www:www %s/data", s.path()); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(fmt.Sprintf("%s/credential", s.path()), email+"\n"+req.Password+"\n", 0600); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package pgadmin
|
||||
|
||||
type UpdatePort struct {
|
||||
Port uint `form:"port" json:"port" validate:"required && number && min:1 && max:65535"`
|
||||
}
|
||||
|
||||
type ResetPassword struct {
|
||||
Password string `form:"password" json:"password" validate:"required && password"`
|
||||
}
|
||||
|
||||
type UpdateUsername struct {
|
||||
Username string `form:"username" json:"username" validate:"required && email"`
|
||||
}
|
||||
+191
-22
@@ -1,47 +1,67 @@
|
||||
package phpmyadmin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
stdio "io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/chix"
|
||||
"github.com/libtnb/chix/v2"
|
||||
"github.com/libtnb/utils/str"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/firewall"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/config"
|
||||
"github.com/acepanel/panel/v3/pkg/firewall"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
t *gotext.Locale
|
||||
conf *config.Config
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(conf *config.Config, t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo) (*App, error) {
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
t: t,
|
||||
conf: conf,
|
||||
databaseServerRepo: databaseServerRepo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/info", s.Info)
|
||||
r.Post("/port", s.UpdatePort)
|
||||
r.Post("/login", s.Login)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
}
|
||||
|
||||
func (s *App) Info(w http.ResponseWriter, r *http.Request) {
|
||||
// Status phpMyAdmin 由 nginx 站点承载,运行状态与 nginx 一致
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("nginx")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// info 获取 phpMyAdmin 的访问目录与端口
|
||||
func (s *App) info() (string, int, error) {
|
||||
files, err := os.ReadDir(fmt.Sprintf("%s/server/phpmyadmin", app.Root))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("phpMyAdmin directory not found"))
|
||||
return
|
||||
return "", 0, errors.New(s.t.Get("phpMyAdmin directory not found"))
|
||||
}
|
||||
|
||||
var phpmyadmin string
|
||||
@@ -51,24 +71,173 @@ func (s *App) Info(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
if len(phpmyadmin) == 0 {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("phpMyAdmin directory not found"))
|
||||
return
|
||||
return "", 0, errors.New(s.t.Get("phpMyAdmin directory not found"))
|
||||
}
|
||||
|
||||
conf, err := io.Read(fmt.Sprintf("%s/sites/phpmyadmin/config/nginx.conf", app.Root))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
return "", 0, err
|
||||
}
|
||||
match := regexp.MustCompile(`listen\s+(\d+);`).FindStringSubmatch(conf)
|
||||
if len(match) == 0 {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("phpMyAdmin port not found"))
|
||||
return "", 0, errors.New(s.t.Get("phpMyAdmin port not found"))
|
||||
}
|
||||
|
||||
return phpmyadmin, cast.ToInt(match[1]), nil
|
||||
}
|
||||
|
||||
func (s *App) Info(w http.ResponseWriter, r *http.Request) {
|
||||
path, port, err := s.info()
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, chix.M{
|
||||
"path": phpmyadmin,
|
||||
"port": cast.ToInt(match[1]),
|
||||
"path": path,
|
||||
"port": port,
|
||||
})
|
||||
}
|
||||
|
||||
// ensureConfig 为存量安装补写 config.inc.php,允许登录到任意 MySQL 服务器
|
||||
func (s *App) ensureConfig(path string) error {
|
||||
config := fmt.Sprintf("%s/server/phpmyadmin/%s/config.inc.php", app.Root, path)
|
||||
if io.Exists(config) {
|
||||
return nil
|
||||
}
|
||||
|
||||
content := fmt.Sprintf(`<?php
|
||||
declare(strict_types=1);
|
||||
$cfg['blowfish_secret'] = '%s';
|
||||
$cfg['AllowArbitraryServer'] = true;
|
||||
`, str.Random(32))
|
||||
return io.Write(config, content, 0644)
|
||||
}
|
||||
|
||||
// Login 代理登录 phpMyAdmin 并将会话 Cookie 转发给浏览器
|
||||
// 面板与 phpMyAdmin 同主机不同端口,Cookie 按主机共享,浏览器凭转发的 Cookie 即为已登录态
|
||||
func (s *App) Login(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[Login](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
server, err := s.databaseServerRepo.Get(r.Context(), req.ServerID)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
if server.Type != biz.DatabaseTypeMysql {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("server %s is not a MySQL server", server.Name))
|
||||
return
|
||||
}
|
||||
|
||||
path, port, err := s.info()
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.ensureConfig(path); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
loginURL := fmt.Sprintf("http://127.0.0.1:%d/%s/index.php?route=/", port, path)
|
||||
client := &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
}
|
||||
|
||||
// 获取登录页以取得会话 Cookie 与 CSRF token
|
||||
// 转发浏览器语言,避免语言协商落空后回落英文
|
||||
pageReq, err := http.NewRequestWithContext(r.Context(), http.MethodGet, loginURL, nil)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
pageReq.Header.Set("Accept-Language", r.Header.Get("Accept-Language"))
|
||||
pageResp, err := client.Do(pageReq)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to request phpMyAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
defer func() { _ = pageResp.Body.Close() }()
|
||||
page, err := stdio.ReadAll(stdio.LimitReader(pageResp.Body, 4<<20))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to request phpMyAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
token := regexp.MustCompile(`name="token" value="([^"]+)"`).FindStringSubmatch(string(page))
|
||||
session := regexp.MustCompile(`name="set_session" value="([^"]+)"`).FindStringSubmatch(string(page))
|
||||
if len(token) < 2 {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to parse phpMyAdmin login page"))
|
||||
return
|
||||
}
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("route", "/")
|
||||
// 语言跟随面板设置,登录后固化进 phpMyAdmin 会话
|
||||
if s.conf.App.Locale != "" {
|
||||
form.Set("lang", s.conf.App.Locale)
|
||||
}
|
||||
form.Set("token", html.UnescapeString(token[1]))
|
||||
if len(session) >= 2 {
|
||||
form.Set("set_session", html.UnescapeString(session[1]))
|
||||
}
|
||||
form.Set("pma_username", server.Username)
|
||||
form.Set("pma_password", server.Password)
|
||||
form.Set("server", "1")
|
||||
// 本地默认端口走 phpMyAdmin 默认配置(socket 连接),其余场景显式指定目标服务器
|
||||
// host 为 localhost 但端口非默认时须用 127.0.0.1 强制走 TCP,否则 mysqli 会忽略端口走 socket
|
||||
isLocal := server.Host == "localhost" || server.Host == "127.0.0.1"
|
||||
if !isLocal || server.Port != 3306 {
|
||||
host := server.Host
|
||||
if host == "localhost" {
|
||||
host = "127.0.0.1"
|
||||
}
|
||||
form.Set("pma_servername", fmt.Sprintf("%s %d", host, server.Port))
|
||||
}
|
||||
|
||||
loginReq, err := http.NewRequestWithContext(r.Context(), http.MethodPost, loginURL, strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
loginReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
loginReq.Header.Set("Accept-Language", r.Header.Get("Accept-Language"))
|
||||
for _, cookie := range pageResp.Cookies() {
|
||||
loginReq.AddCookie(cookie)
|
||||
}
|
||||
|
||||
loginResp, err := client.Do(loginReq)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to request phpMyAdmin: %v", err))
|
||||
return
|
||||
}
|
||||
defer func() { _ = loginResp.Body.Close() }()
|
||||
_, _ = stdio.Copy(stdio.Discard, stdio.LimitReader(loginResp.Body, 4<<20))
|
||||
|
||||
// 登录成功时 phpMyAdmin 返回 302 并携带会话 Cookie
|
||||
if loginResp.StatusCode != http.StatusFound {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to login phpMyAdmin, please check the credentials and status of server %s", server.Name))
|
||||
return
|
||||
}
|
||||
|
||||
// 改写 SameSite 以兼容面板 https 跳转 http 的场景
|
||||
for _, cookie := range append(pageResp.Cookies(), loginResp.Cookies()...) {
|
||||
cookie.SameSite = http.SameSiteLaxMode
|
||||
cookie.Secure = false
|
||||
http.SetCookie(w, cookie)
|
||||
}
|
||||
|
||||
service.Success(w, chix.M{
|
||||
"path": path,
|
||||
"port": port,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -95,8 +264,8 @@ func (s *App) UpdatePort(w http.ResponseWriter, r *http.Request) {
|
||||
Type: firewall.TypeNormal,
|
||||
PortStart: req.Port,
|
||||
PortEnd: req.Port,
|
||||
Direction: firewall.DirectionIn,
|
||||
Strategy: firewall.StrategyAccept,
|
||||
Direction: firewall.DirectionIn,
|
||||
}, firewall.OperationAdd)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
|
||||
@@ -5,5 +5,9 @@ type UpdateConfig struct {
|
||||
}
|
||||
|
||||
type UpdatePort struct {
|
||||
Port uint `form:"port" json:"port" validate:"required|number|min:1|max:65535"`
|
||||
Port uint `form:"port" json:"port" validate:"required && number && min:1 && max:65535"`
|
||||
}
|
||||
|
||||
type Login struct {
|
||||
ServerID uint `form:"server_id" json:"server_id" validate:"required"`
|
||||
}
|
||||
|
||||
@@ -5,15 +5,16 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct{}
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
func NewApp() (*App, error) {
|
||||
return &App{}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -23,6 +24,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/storage_config", s.UpdateStorageConfig)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("podman")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) GetRegistryConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read("/etc/containers/registries.conf")
|
||||
if err != nil {
|
||||
|
||||
@@ -4,20 +4,21 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/acepanel/panel/pkg/db"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/biz"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/db"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
@@ -26,12 +27,15 @@ type App struct {
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, setting biz.SettingRepo, databaseServer biz.DatabaseServerRepo) *App {
|
||||
func NewApp(t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo, settingRepo biz.SettingRepo) (*App, error) {
|
||||
|
||||
setting := settingRepo
|
||||
databaseServer := databaseServerRepo
|
||||
return &App{
|
||||
t: t,
|
||||
settingRepo: setting,
|
||||
databaseServerRepo: databaseServer,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -41,17 +45,21 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/user_config", s.UpdateUserConfig)
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/log", s.Log)
|
||||
r.Post("/clear_log", s.ClearLog)
|
||||
r.Get("/postgres_password", s.GetPostgresPassword)
|
||||
r.Post("/postgres_password", s.SetPostgresPassword)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("postgresql")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// GetConfig 获取配置
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
// 获取配置
|
||||
config, err := io.Read(fmt.Sprintf("%s/server/postgresql/data/postgresql.conf", app.Root))
|
||||
config, err := io.Read(s.configPath())
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
@@ -68,13 +76,14 @@ func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(fmt.Sprintf("%s/server/postgresql/data/postgresql.conf", app.Root), req.Config, 0644); err != nil {
|
||||
oldPort := s.getPort()
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Reload("postgresql"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to reload PostgreSQL: %v", err))
|
||||
if err = s.applyConfig(req.Config, oldPort); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to apply PostgreSQL config: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -132,13 +141,15 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to set PGPASSWORD env: %v", err))
|
||||
return
|
||||
}
|
||||
defer func() { _ = os.Unsetenv("PGPASSWORD") }()
|
||||
|
||||
start, err := shell.Execf(`psql -h 127.0.0.1 -U postgres -t -c "select pg_postmaster_start_time();" | head -1 | cut -d'.' -f1`)
|
||||
port := s.getPort()
|
||||
start, err := shell.Execf(`psql -h 127.0.0.1 -p %d -U postgres -t -c "select pg_postmaster_start_time();" | head -1 | cut -d'.' -f1`, port)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get PostgreSQL start time: %v", err))
|
||||
return
|
||||
}
|
||||
pid, err := shell.Execf(`psql -h 127.0.0.1 -U postgres -t -c "select pg_backend_pid();"`)
|
||||
pid, err := shell.Execf(`psql -h 127.0.0.1 -p %d -U postgres -t -c "select pg_backend_pid();"`, port)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get PostgreSQL backend pid: %v", err))
|
||||
return
|
||||
@@ -148,22 +159,17 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get PostgreSQL process: %v", err))
|
||||
return
|
||||
}
|
||||
connections, err := shell.Execf(`psql -h 127.0.0.1 -U postgres -t -c "SELECT count(*) FROM pg_stat_activity WHERE NOT pid=pg_backend_pid();"`)
|
||||
connections, err := shell.Execf(`psql -h 127.0.0.1 -p %d -U postgres -t -c "SELECT count(*) FROM pg_stat_activity WHERE NOT pid=pg_backend_pid();"`, port)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get PostgreSQL connections: %v", err))
|
||||
return
|
||||
}
|
||||
storage, err := shell.Execf(`psql -h 127.0.0.1 -U postgres -t -c "select pg_size_pretty(pg_database_size('postgres'));"`)
|
||||
storage, err := shell.Execf(`psql -h 127.0.0.1 -p %d -U postgres -t -c "select pg_size_pretty(pg_database_size('postgres'));"`, port)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get PostgreSQL database size: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.Unsetenv("PGPASSWORD"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to unset PGPASSWORD env: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Start Time"), Value: start},
|
||||
{Name: s.t.Get("Process PID"), Value: pid},
|
||||
@@ -175,19 +181,15 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
// Log 获取日志
|
||||
// Log 获取应用日志路径列表
|
||||
func (s *App) Log(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, fmt.Sprintf("%s/server/postgresql/logs/postgresql-%s.log", app.Root, time.Now().Format(time.DateOnly)))
|
||||
}
|
||||
|
||||
// ClearLog 清空日志
|
||||
func (s *App) ClearLog(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := shell.Execf("rm -rf %s/server/postgresql/logs/postgresql-*.log", app.Root); err != nil {
|
||||
paths, err := filepath.Glob(fmt.Sprintf("%s/server/postgresql/logs/postgresql-*.log", app.Root))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
service.Success(w, paths)
|
||||
}
|
||||
|
||||
// GetPostgresPassword 获取 postgres 用户密码
|
||||
@@ -210,10 +212,11 @@ func (s *App) SetPostgresPassword(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
oldPassword, _ := s.settingRepo.Get(biz.SettingKeyPostgresPassword)
|
||||
postgres, err := db.NewPostgres("postgres", oldPassword, "127.0.0.1", 5432)
|
||||
port := s.getPort()
|
||||
postgres, err := db.NewPostgres(r.Context(), "postgres", oldPassword, "127.0.0.1", port)
|
||||
if err != nil {
|
||||
// 直接修改密码
|
||||
if _, err = shell.Execf(`su - postgres -c "psql -c \"ALTER USER postgres WITH PASSWORD '%s';\""`, req.Password); err != nil {
|
||||
if _, err = shell.Execf(`su - postgres -c "psql -p %d -c \"ALTER USER postgres WITH PASSWORD '%s';\""`, port, req.Password); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to set postgres password: %v", err))
|
||||
return
|
||||
}
|
||||
@@ -237,7 +240,7 @@ func (s *App) SetPostgresPassword(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// GetConfigTune 获取 PostgreSQL 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read(fmt.Sprintf("%s/server/postgresql/data/postgresql.conf", app.Root))
|
||||
config, err := io.Read(s.configPath())
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
@@ -284,7 +287,8 @@ func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
confPath := fmt.Sprintf("%s/server/postgresql/data/postgresql.conf", app.Root)
|
||||
confPath := s.configPath()
|
||||
oldPort := s.getPort()
|
||||
config, err := io.Read(confPath)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
@@ -324,18 +328,52 @@ func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Reload("postgresql"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to reload PostgreSQL: %v", err))
|
||||
if err = s.applyConfig(config, oldPort); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to apply PostgreSQL config: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/postgresql/data/postgresql.conf", app.Root)
|
||||
}
|
||||
|
||||
// getPort 读取 PostgreSQL 端口
|
||||
func (s *App) getPort() uint {
|
||||
config, err := io.Read(s.configPath())
|
||||
if err != nil {
|
||||
return 5432
|
||||
}
|
||||
return s.parsePort(config)
|
||||
}
|
||||
|
||||
// parsePort 从 config 内容解析端口,未配置时返回默认值
|
||||
func (s *App) parsePort(config string) uint {
|
||||
port := cast.ToUint(s.getPGValue(config, "port"))
|
||||
if port == 0 {
|
||||
return 5432
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
||||
// applyConfig 让 PostgreSQL 配置生效
|
||||
func (s *App) applyConfig(newConfig string, oldPort uint) error {
|
||||
newPort := s.parsePort(newConfig)
|
||||
if oldPort == newPort {
|
||||
return systemctl.Reload("postgresql")
|
||||
}
|
||||
if err := systemctl.Restart("postgresql"); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.databaseServerRepo.UpdatePort("local_postgresql", newPort)
|
||||
}
|
||||
|
||||
// getPGValue 从 PostgreSQL 配置内容中获取指定键的值
|
||||
func (s *App) getPGValue(content string, key string) string {
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
@@ -397,13 +435,13 @@ func (s *App) setPGValue(content string, key string, value string) string {
|
||||
}
|
||||
continue
|
||||
}
|
||||
result = append(result, key+" = "+value)
|
||||
result = append(result, key+" = '"+value+"'")
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
}
|
||||
if !found && value != "" {
|
||||
result = append(result, key+" = "+value)
|
||||
result = append(result, key+" = '"+value+"'")
|
||||
}
|
||||
return strings.Join(result, "\n")
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ type UpdateConfig struct {
|
||||
}
|
||||
|
||||
type SetPostgresPassword struct {
|
||||
Password string `form:"password" json:"password" validate:"required|password"`
|
||||
Password string `form:"password" json:"password" validate:"required && password"`
|
||||
}
|
||||
|
||||
// ConfigTune PostgreSQL 配置调整
|
||||
type ConfigTune struct {
|
||||
// 连接设置
|
||||
ListenAddresses string `form:"listen_addresses" json:"listen_addresses"`
|
||||
Port string `form:"port" json:"port"`
|
||||
Port string `form:"port" json:"port" validate:"number && min:1 && max:65535"`
|
||||
MaxConnections string `form:"max_connections" json:"max_connections"`
|
||||
SuperuserReservedConnections string `form:"superuser_reserved_connections" json:"superuser_reserved_connections"`
|
||||
// 内存设置
|
||||
|
||||
@@ -0,0 +1,436 @@
|
||||
package prometheus
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cast"
|
||||
"go.yaml.in/yaml/v4"
|
||||
"resty.dev/v3"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/config"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
conf *config.Config
|
||||
taskRepo biz.TaskRepo
|
||||
}
|
||||
|
||||
func NewApp(conf *config.Config, t *gotext.Locale, taskRepo biz.TaskRepo) (*App, error) {
|
||||
|
||||
return &App{t: t, conf: conf, taskRepo: taskRepo}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
// Alertmanager 配置
|
||||
r.Get("/alertmanager_config", s.GetAlertmanagerConfig)
|
||||
r.Post("/alertmanager_config", s.UpdateAlertmanagerConfig)
|
||||
// Exporters 管理
|
||||
r.Get("/exporters", s.ExporterList)
|
||||
r.Post("/exporters", s.InstallExporter)
|
||||
r.Delete("/exporters", s.UninstallExporter)
|
||||
r.Post("/exporters/{slug}/start", s.StartExporter)
|
||||
r.Post("/exporters/{slug}/stop", s.StopExporter)
|
||||
r.Post("/exporters/{slug}/restart", s.RestartExporter)
|
||||
r.Get("/exporters/{slug}/config", s.GetExporterConfig)
|
||||
r.Post("/exporters/{slug}/config", s.UpdateExporterConfig)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
prom, _ := systemctl.Status("prometheus")
|
||||
alert, _ := systemctl.Status("alertmanager")
|
||||
return types.AggregateAppStatus(prom, alert)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("prometheus")
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get prometheus status: %v", err))
|
||||
return
|
||||
}
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
client := resty.New().SetTimeout(10 * time.Second)
|
||||
defer func(client *resty.Client) { _ = client.Close() }(client)
|
||||
resp, err := client.R().Get("http://127.0.0.1:9090/api/v1/status/runtimeinfo")
|
||||
if err != nil || !resp.IsStatusSuccess() {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
var result struct {
|
||||
Data struct {
|
||||
StartTime string `json:"startTime"`
|
||||
GoroutineCount int `json:"goroutineCount"`
|
||||
GOMAXPROCS int `json:"GOMAXPROCS"`
|
||||
StorageRetention string `json:"storageRetention"`
|
||||
ReloadConfigSuccess bool `json:"reloadConfigSuccess"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err = json.Unmarshal(resp.Bytes(), &result); err != nil {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("Start Time"), Value: result.Data.StartTime},
|
||||
{Name: s.t.Get("Storage Retention"), Value: result.Data.StorageRetention},
|
||||
{Name: s.t.Get("Goroutine Count"), Value: cast.ToString(result.Data.GoroutineCount)},
|
||||
{Name: "GOMAXPROCS", Value: cast.ToString(result.Data.GOMAXPROCS)},
|
||||
{Name: s.t.Get("Config Reload Success"), Value: cast.ToString(result.Data.ReloadConfigSuccess)},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(fmt.Sprintf("%s/server/prometheus/prometheus.yml", app.Root))
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(fmt.Sprintf("%s/server/prometheus/prometheus.yml", app.Root), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("prometheus"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 Prometheus 全局配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(fmt.Sprintf("%s/server/prometheus/prometheus.yml", app.Root))
|
||||
|
||||
var cfg struct {
|
||||
Global struct {
|
||||
ScrapeInterval string `yaml:"scrape_interval"`
|
||||
EvaluationInterval string `yaml:"evaluation_interval"`
|
||||
ScrapeTimeout string `yaml:"scrape_timeout"`
|
||||
} `yaml:"global"`
|
||||
}
|
||||
_ = yaml.Unmarshal([]byte(conf), &cfg)
|
||||
|
||||
tune := ConfigTune{
|
||||
ScrapeInterval: cfg.Global.ScrapeInterval,
|
||||
EvaluationInterval: cfg.Global.EvaluationInterval,
|
||||
ScrapeTimeout: cfg.Global.ScrapeTimeout,
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新 Prometheus 全局配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
confPath := fmt.Sprintf("%s/server/prometheus/prometheus.yml", app.Root)
|
||||
raw, _ := io.Read(confPath)
|
||||
|
||||
var cfg map[string]any
|
||||
if err = yaml.Unmarshal([]byte(raw), &cfg); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
global, ok := cfg["global"].(map[string]any)
|
||||
if !ok {
|
||||
global = make(map[string]any)
|
||||
}
|
||||
|
||||
if req.ScrapeInterval != "" {
|
||||
global["scrape_interval"] = req.ScrapeInterval
|
||||
}
|
||||
if req.EvaluationInterval != "" {
|
||||
global["evaluation_interval"] = req.EvaluationInterval
|
||||
}
|
||||
if req.ScrapeTimeout != "" {
|
||||
global["scrape_timeout"] = req.ScrapeTimeout
|
||||
}
|
||||
cfg["global"] = global
|
||||
|
||||
data, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(confPath, string(data), 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("prometheus"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetAlertmanagerConfig 获取 Alertmanager 配置
|
||||
func (s *App) GetAlertmanagerConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(fmt.Sprintf("%s/server/prometheus/alertmanager/alertmanager.yml", app.Root))
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
// UpdateAlertmanagerConfig 更新 Alertmanager 配置
|
||||
func (s *App) UpdateAlertmanagerConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(fmt.Sprintf("%s/server/prometheus/alertmanager/alertmanager.yml", app.Root), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("alertmanager"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// ExporterList 获取 Exporter 列表及状态
|
||||
func (s *App) ExporterList(w http.ResponseWriter, r *http.Request) {
|
||||
exporters := s.getExporters()
|
||||
for i := range exporters {
|
||||
exporters[i].Installed = io.Exists(fmt.Sprintf("%s/server/prometheus/exporters/%s", app.Root, exporters[i].Slug))
|
||||
if exporters[i].Installed {
|
||||
running, _ := systemctl.Status("prometheus-" + exporters[i].Slug)
|
||||
exporters[i].Running = running
|
||||
}
|
||||
}
|
||||
|
||||
service.Success(w, exporters)
|
||||
}
|
||||
|
||||
// InstallExporter 安装 Exporter(异步任务)
|
||||
func (s *App) InstallExporter(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ExporterSlug](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !s.checkExporter(req.Slug) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s does not exist", req.Slug))
|
||||
return
|
||||
}
|
||||
|
||||
cmd := fmt.Sprintf(`curl -sSLm 10 --retry 3 'https://%s/prometheus/exporters/exporter.sh' | bash -s -- 'install' '%s'`, s.conf.App.DownloadEndpoint, url.PathEscape(req.Slug))
|
||||
|
||||
task := new(biz.Task)
|
||||
task.Key = "prometheus:exporter:" + req.Slug
|
||||
task.Name = s.t.Get("Install Prometheus exporter %s", req.Slug)
|
||||
task.Status = biz.TaskStatusWaiting
|
||||
task.Shell = cmd
|
||||
if err = s.taskRepo.Push(task); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// UninstallExporter 卸载 Exporter(异步任务)
|
||||
func (s *App) UninstallExporter(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ExporterSlug](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !s.checkExporter(req.Slug) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s does not exist", req.Slug))
|
||||
return
|
||||
}
|
||||
|
||||
cmd := fmt.Sprintf(`curl -sSLm 10 --retry 3 'https://%s/prometheus/exporters/exporter.sh' | bash -s -- 'uninstall' '%s'`, s.conf.App.DownloadEndpoint, url.PathEscape(req.Slug))
|
||||
|
||||
task := new(biz.Task)
|
||||
task.Key = "prometheus:exporter:" + req.Slug
|
||||
task.Name = s.t.Get("Uninstall Prometheus exporter %s", req.Slug)
|
||||
task.Status = biz.TaskStatusWaiting
|
||||
task.Shell = cmd
|
||||
if err = s.taskRepo.Push(task); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// StartExporter 启动 Exporter
|
||||
func (s *App) StartExporter(w http.ResponseWriter, r *http.Request) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
if !s.checkExporter(slug) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s does not exist", slug))
|
||||
return
|
||||
}
|
||||
|
||||
if err := systemctl.Start("prometheus-" + slug); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// StopExporter 停止 Exporter
|
||||
func (s *App) StopExporter(w http.ResponseWriter, r *http.Request) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
if !s.checkExporter(slug) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s does not exist", slug))
|
||||
return
|
||||
}
|
||||
|
||||
if err := systemctl.Stop("prometheus-" + slug); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// RestartExporter 重启 Exporter
|
||||
func (s *App) RestartExporter(w http.ResponseWriter, r *http.Request) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
if !s.checkExporter(slug) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s does not exist", slug))
|
||||
return
|
||||
}
|
||||
|
||||
if err := systemctl.Restart("prometheus-" + slug); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetExporterConfig 获取 Exporter 配置
|
||||
func (s *App) GetExporterConfig(w http.ResponseWriter, r *http.Request) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
if !s.checkExporter(slug) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s does not exist", slug))
|
||||
return
|
||||
}
|
||||
|
||||
confPath := s.getExporterConfigPath(slug)
|
||||
if confPath == "" {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s has no configuration file", slug))
|
||||
return
|
||||
}
|
||||
|
||||
conf, _ := io.Read(confPath)
|
||||
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
// UpdateExporterConfig 更新 Exporter 配置
|
||||
func (s *App) UpdateExporterConfig(w http.ResponseWriter, r *http.Request) {
|
||||
slug := chi.URLParam(r, "slug")
|
||||
if !s.checkExporter(slug) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s does not exist", slug))
|
||||
return
|
||||
}
|
||||
|
||||
confPath := s.getExporterConfigPath(slug)
|
||||
if confPath == "" {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("exporter %s has no configuration file", slug))
|
||||
return
|
||||
}
|
||||
|
||||
req, err := service.Bind[ExporterConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(confPath, req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("prometheus-" + slug); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// getExporters 返回所有 exporter 定义
|
||||
func (s *App) getExporters() []Exporter {
|
||||
return []Exporter{
|
||||
{Name: "Node Exporter", Slug: "node_exporter", Description: s.t.Get("Hardware and OS metrics")},
|
||||
{Name: "Nginx Exporter", Slug: "nginx_exporter", Description: s.t.Get("Nginx metrics")},
|
||||
{Name: "MySQL Exporter", Slug: "mysqld_exporter", Description: s.t.Get("MySQL database metrics"), HasConfig: true},
|
||||
{Name: "PostgreSQL Exporter", Slug: "postgres_exporter", Description: s.t.Get("PostgreSQL database metrics"), HasConfig: true},
|
||||
{Name: "MongoDB Exporter", Slug: "mongodb_exporter", Description: s.t.Get("MongoDB metrics"), HasConfig: true},
|
||||
{Name: "Elasticsearch Exporter", Slug: "elasticsearch_exporter", Description: s.t.Get("Elasticsearch metrics"), HasConfig: true},
|
||||
{Name: "Redis Exporter", Slug: "redis_exporter", Description: s.t.Get("Redis metrics"), HasConfig: true},
|
||||
{Name: "Memcached Exporter", Slug: "memcached_exporter", Description: s.t.Get("Memcached metrics")},
|
||||
{Name: "Kafka Exporter", Slug: "kafka_exporter", Description: s.t.Get("Kafka metrics"), HasConfig: true},
|
||||
}
|
||||
}
|
||||
|
||||
// getExporterConfigPath 获取 exporter 配置文件路径
|
||||
func (s *App) getExporterConfigPath(slug string) string {
|
||||
base := fmt.Sprintf("%s/server/prometheus/exporters/%s", app.Root, slug)
|
||||
switch slug {
|
||||
case "redis_exporter", "postgres_exporter", "elasticsearch_exporter", "mongodb_exporter", "kafka_exporter":
|
||||
return base + "/env"
|
||||
case "mysqld_exporter":
|
||||
return base + "/.my.cnf"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// checkExporter 检查 slug 是否有效
|
||||
func (s *App) checkExporter(slug string) bool {
|
||||
return lo.ContainsBy(s.getExporters(), func(e Exporter) bool {
|
||||
return e.Slug == slug
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package prometheus
|
||||
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigTune Prometheus 全局配置调整
|
||||
type ConfigTune struct {
|
||||
ScrapeInterval string `form:"scrape_interval" json:"scrape_interval"`
|
||||
EvaluationInterval string `form:"evaluation_interval" json:"evaluation_interval"`
|
||||
ScrapeTimeout string `form:"scrape_timeout" json:"scrape_timeout"`
|
||||
}
|
||||
|
||||
// Exporter Prometheus Exporter 信息
|
||||
type Exporter struct {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Description string `json:"description"`
|
||||
Installed bool `json:"installed"`
|
||||
Running bool `json:"running"`
|
||||
HasConfig bool `json:"has_config"`
|
||||
}
|
||||
|
||||
// ExporterSlug Exporter 操作请求
|
||||
type ExporterSlug struct {
|
||||
Slug string `form:"slug" json:"slug" validate:"required"`
|
||||
}
|
||||
|
||||
// ExporterConfig Exporter 配置更新请求
|
||||
type ExporterConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
@@ -8,25 +8,28 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/chix"
|
||||
"github.com/libtnb/chix/v2"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/firewall"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/firewall"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -40,6 +43,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("pure-ftpd")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// List 获取用户列表
|
||||
func (s *App) List(w http.ResponseWriter, r *http.Request) {
|
||||
listRaw, err := shell.Execf("pure-pw list")
|
||||
@@ -50,19 +58,17 @@ func (s *App) List(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
listArr := strings.Split(listRaw, "\n")
|
||||
var users []User
|
||||
for _, v := range listArr {
|
||||
userRe := regexp.MustCompile(`(\S+)\s+(\S+)`)
|
||||
users := lo.FilterMap(strings.Split(listRaw, "\n"), func(v string, _ int) (User, bool) {
|
||||
if len(v) == 0 {
|
||||
continue
|
||||
return User{}, false
|
||||
}
|
||||
|
||||
match := regexp.MustCompile(`(\S+)\s+(\S+)`).FindStringSubmatch(v)
|
||||
users = append(users, User{
|
||||
match := userRe.FindStringSubmatch(v)
|
||||
return User{
|
||||
Username: match[1],
|
||||
Path: strings.Replace(match[2], "/./", "/", 1),
|
||||
})
|
||||
}
|
||||
}, true
|
||||
})
|
||||
|
||||
paged, total := service.Paginate(r, users)
|
||||
|
||||
@@ -182,8 +188,8 @@ func (s *App) UpdatePort(w http.ResponseWriter, r *http.Request) {
|
||||
Type: firewall.TypeNormal,
|
||||
PortStart: req.Port,
|
||||
PortEnd: req.Port,
|
||||
Direction: firewall.DirectionIn,
|
||||
Strategy: firewall.StrategyAccept,
|
||||
Direction: firewall.DirectionIn,
|
||||
}, firewall.OperationAdd)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
@@ -259,8 +265,8 @@ func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// getFTPValue 从 Pure-FTPd 配置内容中获取指定键的值
|
||||
func (s *App) getFTPValue(content string, key string) string {
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
|
||||
@@ -2,7 +2,7 @@ package pureftpd
|
||||
|
||||
type Create struct {
|
||||
Username string `form:"username" json:"username" validate:"required"`
|
||||
Password string `form:"password" json:"password" validate:"required|password"`
|
||||
Password string `form:"password" json:"password" validate:"required && password"`
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
}
|
||||
|
||||
@@ -12,21 +12,21 @@ type Delete struct {
|
||||
|
||||
type ChangePassword struct {
|
||||
Username string `form:"username" json:"username" validate:"required"`
|
||||
Password string `form:"password" json:"password" validate:"required|password"`
|
||||
Password string `form:"password" json:"password" validate:"required && password"`
|
||||
}
|
||||
|
||||
type UpdatePort struct {
|
||||
Port uint `form:"port" json:"port" validate:"required|number|min:1|max:65535"`
|
||||
Port uint `form:"port" json:"port" validate:"required && number && min:1 && max:65535"`
|
||||
}
|
||||
|
||||
// ConfigTune Pure-FTPd 配置调整
|
||||
type ConfigTune struct {
|
||||
MaxClientsNumber string `form:"max_clients_number" json:"max_clients_number"`
|
||||
MaxClientsPerIP string `form:"max_clients_per_ip" json:"max_clients_per_ip"`
|
||||
MaxIdleTime string `form:"max_idle_time" json:"max_idle_time"`
|
||||
MaxClientsNumber string `form:"max_clients_number" json:"max_clients_number" validate:"number && min:1"`
|
||||
MaxClientsPerIP string `form:"max_clients_per_ip" json:"max_clients_per_ip" validate:"number && min:1"`
|
||||
MaxIdleTime string `form:"max_idle_time" json:"max_idle_time" validate:"number && min:0"`
|
||||
MaxLoad string `form:"max_load" json:"max_load"`
|
||||
PassivePortRange string `form:"passive_port_range" json:"passive_port_range"`
|
||||
AnonymousOnly string `form:"anonymous_only" json:"anonymous_only"`
|
||||
NoAnonymous string `form:"no_anonymous" json:"no_anonymous"`
|
||||
MaxDiskUsage string `form:"max_disk_usage" json:"max_disk_usage"`
|
||||
AnonymousOnly string `form:"anonymous_only" json:"anonymous_only" validate:"in:yes,no"`
|
||||
NoAnonymous string `form:"no_anonymous" json:"no_anonymous" validate:"in:yes,no"`
|
||||
MaxDiskUsage string `form:"max_disk_usage" json:"max_disk_usage" validate:"number && min:1 && max:100"`
|
||||
}
|
||||
|
||||
+32
-20
@@ -8,23 +8,29 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
t *gotext.Locale
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo) (*App, error) {
|
||||
|
||||
databaseServer := databaseServerRepo
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
t: t,
|
||||
databaseServerRepo: databaseServer,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -35,6 +41,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("redis")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("redis")
|
||||
if err != nil {
|
||||
@@ -53,7 +64,7 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
re := regexp.MustCompile(`^requirepass\s+(.+)`)
|
||||
re := regexp.MustCompile(`(?m)^requirepass\s+(.+)`)
|
||||
matches := re.FindStringSubmatch(config)
|
||||
if len(matches) == 2 {
|
||||
withPassword = " -a " + matches[1]
|
||||
@@ -65,15 +76,13 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
infoLines := strings.Split(raw, "\n")
|
||||
dataRaw := make(map[string]string)
|
||||
|
||||
for _, item := range infoLines {
|
||||
dataRaw := lo.SliceToMap(strings.Split(raw, "\n"), func(item string) (string, string) {
|
||||
parts := strings.Split(item, ":")
|
||||
if len(parts) == 2 {
|
||||
dataRaw[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
|
||||
if len(parts) != 2 {
|
||||
return "", ""
|
||||
}
|
||||
}
|
||||
return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
|
||||
})
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("TCP Port"), Value: dataRaw["tcp_port"]},
|
||||
@@ -184,13 +193,16 @@ func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// 同步密码到数据库服务器记录
|
||||
_ = s.databaseServerRepo.UpdatePassword("local_redis", req.Requirepass)
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// getRedisValue 从 Redis 配置内容中获取指定键的值
|
||||
func (s *App) getRedisValue(content string, key string) string {
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
|
||||
@@ -8,15 +8,15 @@ type UpdateConfig struct {
|
||||
type ConfigTune struct {
|
||||
// 常规设置
|
||||
Bind string `form:"bind" json:"bind"`
|
||||
Port string `form:"port" json:"port"`
|
||||
Databases string `form:"databases" json:"databases"`
|
||||
Port string `form:"port" json:"port" validate:"number && min:1 && max:65535"`
|
||||
Databases string `form:"databases" json:"databases" validate:"number && min:1"`
|
||||
Requirepass string `form:"requirepass" json:"requirepass"`
|
||||
Timeout string `form:"timeout" json:"timeout"`
|
||||
TCPKeepalive string `form:"tcp_keepalive" json:"tcp_keepalive"`
|
||||
Timeout string `form:"timeout" json:"timeout" validate:"number"`
|
||||
TCPKeepalive string `form:"tcp_keepalive" json:"tcp_keepalive" validate:"number"`
|
||||
// 内存
|
||||
Maxmemory string `form:"maxmemory" json:"maxmemory"`
|
||||
MaxmemoryPolicy string `form:"maxmemory_policy" json:"maxmemory_policy"`
|
||||
MaxmemoryPolicy string `form:"maxmemory_policy" json:"maxmemory_policy" validate:"in:noeviction,allkeys-lru,allkeys-lfu,allkeys-random,volatile-lru,volatile-lfu,volatile-random,volatile-ttl"`
|
||||
// 持久化
|
||||
Appendonly string `form:"appendonly" json:"appendonly"`
|
||||
Appendfsync string `form:"appendfsync" json:"appendfsync"`
|
||||
Appendonly string `form:"appendonly" json:"appendonly" validate:"in:yes,no"`
|
||||
Appendfsync string `form:"appendfsync" json:"appendfsync" validate:"in:always,everysec,no"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
package rocketmq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
|
||||
return &App{t: t}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
namesrv, _ := systemctl.Status("rocketmq-namesrv")
|
||||
broker, _ := systemctl.Status("rocketmq-broker")
|
||||
return types.AggregateAppStatus(namesrv, broker)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
namesrvStatus, _ := systemctl.Status("rocketmq-namesrv")
|
||||
brokerStatus, _ := systemctl.Status("rocketmq-broker")
|
||||
|
||||
namesrvStr := "stopped"
|
||||
if namesrvStatus {
|
||||
namesrvStr = "running"
|
||||
}
|
||||
brokerStr := "stopped"
|
||||
if brokerStatus {
|
||||
brokerStr = "running"
|
||||
}
|
||||
|
||||
if !namesrvStatus && !brokerStatus {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("NameServer Status"), Value: namesrvStr},
|
||||
{Name: s.t.Get("Broker Status"), Value: brokerStr},
|
||||
{Name: s.t.Get("Broker Name"), Value: s.getPropertiesValue(config, "brokerName")},
|
||||
{Name: s.t.Get("Listen Port"), Value: s.getPropertiesValue(config, "listenPort")},
|
||||
{Name: s.t.Get("NameServer Address"), Value: s.getPropertiesValue(config, "namesrvAddr")},
|
||||
{Name: s.t.Get("Broker Role"), Value: s.getPropertiesValue(config, "brokerRole")},
|
||||
{Name: s.t.Get("Flush Disk Type"), Value: s.getPropertiesValue(config, "flushDiskType")},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
conf, _ := io.Read(s.configPath())
|
||||
service.Success(w, conf)
|
||||
}
|
||||
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(s.configPath(), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.restartServices(); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 RocketMQ 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
config, _ := io.Read(s.configPath())
|
||||
heapRaw, _ := io.Read(s.heapEnvPath())
|
||||
|
||||
namesrvInit, namesrvMax := s.parseHeapLine(heapRaw, "ROCKETMQ_NAMESRV_HEAP")
|
||||
brokerInit, brokerMax := s.parseHeapLine(heapRaw, "ROCKETMQ_BROKER_HEAP")
|
||||
|
||||
tune := ConfigTune{
|
||||
BrokerName: s.getPropertiesValue(config, "brokerName"),
|
||||
ListenPort: s.getPropertiesValue(config, "listenPort"),
|
||||
NamesrvAddr: s.getPropertiesValue(config, "namesrvAddr"),
|
||||
BrokerRole: s.getPropertiesValue(config, "brokerRole"),
|
||||
FlushDiskType: s.getPropertiesValue(config, "flushDiskType"),
|
||||
StorePathRootDir: s.getPropertiesValue(config, "storePathRootDir"),
|
||||
StorePathCommitLog: s.getPropertiesValue(config, "storePathCommitLog"),
|
||||
MaxMessageSize: s.getPropertiesValue(config, "maxMessageSize"),
|
||||
NamesrvHeapInitSize: namesrvInit,
|
||||
NamesrvHeapMaxSize: namesrvMax,
|
||||
BrokerHeapInitSize: brokerInit,
|
||||
BrokerHeapMaxSize: brokerMax,
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新 RocketMQ 配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
config, _ := io.Read(s.configPath())
|
||||
|
||||
config = s.setPropertiesValue(config, "brokerName", req.BrokerName)
|
||||
config = s.setPropertiesValue(config, "listenPort", req.ListenPort)
|
||||
config = s.setPropertiesValue(config, "namesrvAddr", req.NamesrvAddr)
|
||||
config = s.setPropertiesValue(config, "brokerRole", req.BrokerRole)
|
||||
config = s.setPropertiesValue(config, "flushDiskType", req.FlushDiskType)
|
||||
config = s.setPropertiesValue(config, "storePathRootDir", req.StorePathRootDir)
|
||||
config = s.setPropertiesValue(config, "storePathCommitLog", req.StorePathCommitLog)
|
||||
config = s.setPropertiesValue(config, "maxMessageSize", req.MaxMessageSize)
|
||||
|
||||
if err = io.Write(s.configPath(), config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 更新 JVM 堆内存
|
||||
if req.NamesrvHeapInitSize != "" || req.NamesrvHeapMaxSize != "" || req.BrokerHeapInitSize != "" || req.BrokerHeapMaxSize != "" {
|
||||
heapRaw, _ := io.Read(s.heapEnvPath())
|
||||
heapRaw = s.setHeapEnv(heapRaw, *req)
|
||||
if err = io.Write(s.heapEnvPath(), heapRaw, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = s.restartServices(); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// restartServices 重启 NameServer 和 Broker 服务
|
||||
func (s *App) restartServices() error {
|
||||
if err := systemctl.Restart("rocketmq-namesrv"); err != nil {
|
||||
return err
|
||||
}
|
||||
return systemctl.Restart("rocketmq-broker")
|
||||
}
|
||||
|
||||
// configPath 返回 broker 配置文件路径
|
||||
func (s *App) configPath() string {
|
||||
return fmt.Sprintf("%s/server/rocketmq/conf/broker.conf", app.Root)
|
||||
}
|
||||
|
||||
// heapEnvPath 返回 JVM 堆内存配置文件路径
|
||||
func (s *App) heapEnvPath() string {
|
||||
return fmt.Sprintf("%s/server/rocketmq/conf/heap.env", app.Root)
|
||||
}
|
||||
|
||||
// getPropertiesValue 从 properties 内容中获取指定键的值
|
||||
func (s *App) getPropertiesValue(content string, key string) string {
|
||||
for line := range strings.SplitSeq(content, "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
}
|
||||
k, v, ok := strings.Cut(trimmed, "=")
|
||||
if ok && strings.TrimSpace(k) == key {
|
||||
return strings.TrimSpace(v)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// setPropertiesValue 在 properties 内容中设置指定键的值
|
||||
func (s *App) setPropertiesValue(content string, key string, value string) string {
|
||||
value = strings.ReplaceAll(value, "\n", "")
|
||||
value = strings.ReplaceAll(value, "\r", "")
|
||||
|
||||
lines := strings.Split(content, "\n")
|
||||
result := make([]string, 0, len(lines))
|
||||
found := false
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" {
|
||||
result = append(result, line)
|
||||
continue
|
||||
}
|
||||
checkLine := trimmed
|
||||
if strings.HasPrefix(checkLine, "#") {
|
||||
checkLine = strings.TrimSpace(checkLine[1:])
|
||||
}
|
||||
k, _, ok := strings.Cut(checkLine, "=")
|
||||
if ok && strings.TrimSpace(k) == key {
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if value == "" {
|
||||
if !strings.HasPrefix(trimmed, "#") {
|
||||
result = append(result, "#"+trimmed)
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
continue
|
||||
}
|
||||
result = append(result, key+"="+value)
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
}
|
||||
if !found && value != "" {
|
||||
result = append(result, key+"="+value)
|
||||
}
|
||||
return strings.Join(result, "\n")
|
||||
}
|
||||
|
||||
// parseHeapLine 从 heap.env 中提取指定环境变量的堆内存配置
|
||||
func (s *App) parseHeapLine(content string, envKey string) (initSize, maxSize string) {
|
||||
re := regexp.MustCompile(envKey + `=(.+)`)
|
||||
m := re.FindStringSubmatch(content)
|
||||
if len(m) != 2 {
|
||||
return
|
||||
}
|
||||
opts := m[1]
|
||||
if mi := regexp.MustCompile(`-Xms(\S+)`).FindStringSubmatch(opts); len(mi) == 2 {
|
||||
initSize = mi[1]
|
||||
}
|
||||
if mx := regexp.MustCompile(`-Xmx(\S+)`).FindStringSubmatch(opts); len(mx) == 2 {
|
||||
maxSize = mx[1]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// setHeapEnv 设置 heap.env 中的堆内存配置
|
||||
func (s *App) setHeapEnv(content string, req ConfigTune) string {
|
||||
// 读取已有值作为默认
|
||||
oldNsInit, oldNsMax := s.parseHeapLine(content, "ROCKETMQ_NAMESRV_HEAP")
|
||||
oldBrInit, oldBrMax := s.parseHeapLine(content, "ROCKETMQ_BROKER_HEAP")
|
||||
|
||||
nsInit := req.NamesrvHeapInitSize
|
||||
if nsInit == "" {
|
||||
nsInit = oldNsInit
|
||||
}
|
||||
if nsInit == "" {
|
||||
nsInit = "512m"
|
||||
}
|
||||
nsMax := req.NamesrvHeapMaxSize
|
||||
if nsMax == "" {
|
||||
nsMax = oldNsMax
|
||||
}
|
||||
if nsMax == "" {
|
||||
nsMax = "512m"
|
||||
}
|
||||
|
||||
brInit := req.BrokerHeapInitSize
|
||||
if brInit == "" {
|
||||
brInit = oldBrInit
|
||||
}
|
||||
if brInit == "" {
|
||||
brInit = "1g"
|
||||
}
|
||||
brMax := req.BrokerHeapMaxSize
|
||||
if brMax == "" {
|
||||
brMax = oldBrMax
|
||||
}
|
||||
if brMax == "" {
|
||||
brMax = "1g"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("ROCKETMQ_NAMESRV_HEAP=-Xms%s -Xmx%s\nROCKETMQ_BROKER_HEAP=-Xms%s -Xmx%s\n", nsInit, nsMax, brInit, brMax)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package rocketmq
|
||||
|
||||
// UpdateConfig RocketMQ 配置更新
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigTune RocketMQ 配置调整
|
||||
type ConfigTune struct {
|
||||
// Broker 基础
|
||||
BrokerName string `form:"broker_name" json:"broker_name"` // brokerName
|
||||
ListenPort string `form:"listen_port" json:"listen_port" validate:"number && min:1 && max:65535"` // listenPort
|
||||
NamesrvAddr string `form:"namesrv_addr" json:"namesrv_addr"` // namesrvAddr
|
||||
BrokerRole string `form:"broker_role" json:"broker_role" validate:"in:ASYNC_MASTER,SYNC_MASTER,SLAVE"` // brokerRole
|
||||
FlushDiskType string `form:"flush_disk_type" json:"flush_disk_type" validate:"in:ASYNC_FLUSH,SYNC_FLUSH"` // flushDiskType
|
||||
// 存储
|
||||
StorePathRootDir string `form:"store_path_root_dir" json:"store_path_root_dir" validate:"unix_path"` // storePathRootDir
|
||||
StorePathCommitLog string `form:"store_path_commit_log" json:"store_path_commit_log" validate:"unix_path"` // storePathCommitLog
|
||||
MaxMessageSize string `form:"max_message_size" json:"max_message_size" validate:"number"` // maxMessageSize
|
||||
// JVM - NameServer
|
||||
NamesrvHeapInitSize string `form:"namesrv_heap_init_size" json:"namesrv_heap_init_size"` // -Xms (namesrv)
|
||||
NamesrvHeapMaxSize string `form:"namesrv_heap_max_size" json:"namesrv_heap_max_size"` // -Xmx (namesrv)
|
||||
// JVM - Broker
|
||||
BrokerHeapInitSize string `form:"broker_heap_init_size" json:"broker_heap_init_size"` // -Xms (broker)
|
||||
BrokerHeapMaxSize string `form:"broker_heap_max_size" json:"broker_heap_max_size"` // -Xmx (broker)
|
||||
}
|
||||
@@ -8,23 +8,25 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/chix"
|
||||
"github.com/libtnb/chix/v2"
|
||||
"github.com/libtnb/utils/str"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -36,6 +38,11 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("rsyncd")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) List(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read("/etc/rsyncd.conf")
|
||||
if err != nil {
|
||||
|
||||
+19
-20
@@ -9,22 +9,25 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/chix"
|
||||
"github.com/libtnb/chix/v2"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
|
||||
return &App{
|
||||
t: t,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
@@ -33,6 +36,10 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Delete("/mounts", s.Delete)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
return types.AppStatusNA
|
||||
}
|
||||
|
||||
// List 所有 S3fs 挂载
|
||||
func (s *App) List(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := s.mounts()
|
||||
@@ -81,11 +88,9 @@ func (s *App) Create(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range list {
|
||||
if item.Path == req.Path {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("mount path already exists"))
|
||||
return
|
||||
}
|
||||
if lo.ContainsBy(list, func(item Mount) bool { return item.Path == req.Path }) {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("mount path already exists"))
|
||||
return
|
||||
}
|
||||
|
||||
id := time.Now().UnixMicro()
|
||||
@@ -128,14 +133,8 @@ func (s *App) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var mount Mount
|
||||
for _, item := range list {
|
||||
if item.ID == req.ID {
|
||||
mount = item
|
||||
break
|
||||
}
|
||||
}
|
||||
if mount.ID == 0 {
|
||||
mount, ok := lo.Find(list, func(item Mount) bool { return item.ID == req.ID })
|
||||
if !ok {
|
||||
service.Error(w, http.StatusUnprocessableEntity, s.t.Get("mount not found"))
|
||||
return
|
||||
}
|
||||
@@ -178,7 +177,7 @@ func (s *App) mounts() ([]Mount, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, id := range strings.Split(ids, "\n") {
|
||||
for id := range strings.SplitSeq(ids, "\n") {
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ type Create struct {
|
||||
Ak string `form:"ak" json:"ak" validate:"required"`
|
||||
Sk string `form:"sk" json:"sk" validate:"required"`
|
||||
Bucket string `form:"bucket" json:"bucket" validate:"required"`
|
||||
URL string `form:"url" json:"url" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
URL string `form:"url" json:"url" validate:"required && url"`
|
||||
Path string `form:"path" json:"path" validate:"required && unix_path"`
|
||||
}
|
||||
|
||||
type Delete struct {
|
||||
|
||||
@@ -6,14 +6,15 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/chix"
|
||||
"github.com/libtnb/chix/v2"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/internal/service"
|
||||
"github.com/acepanel/panel/pkg/io"
|
||||
"github.com/acepanel/panel/pkg/os"
|
||||
"github.com/acepanel/panel/pkg/shell"
|
||||
"github.com/acepanel/panel/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/os"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
@@ -21,7 +22,8 @@ type App struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale) *App {
|
||||
func NewApp(t *gotext.Locale) (*App, error) {
|
||||
|
||||
var name string
|
||||
if os.IsRHEL() {
|
||||
name = "supervisord"
|
||||
@@ -32,12 +34,11 @@ func NewApp(t *gotext.Locale) *App {
|
||||
return &App{
|
||||
t: t,
|
||||
name: name,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/service", s.Service)
|
||||
r.Post("/clear_log", s.ClearLog)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/processes", s.Processes)
|
||||
@@ -45,7 +46,6 @@ func (s *App) Route(r chi.Router) {
|
||||
r.Post("/processes/{process}/stop", s.StopProcess)
|
||||
r.Post("/processes/{process}/restart", s.RestartProcess)
|
||||
r.Get("/processes/{process}/log", s.ProcessLog)
|
||||
r.Post("/processes/{process}/clear_log", s.ClearProcessLog)
|
||||
r.Get("/processes/{process}", s.ProcessConfig)
|
||||
r.Post("/processes/{process}", s.UpdateProcessConfig)
|
||||
r.Delete("/processes/{process}", s.DeleteProcess)
|
||||
@@ -57,14 +57,9 @@ func (s *App) Service(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, s.name)
|
||||
}
|
||||
|
||||
// ClearLog 清空日志
|
||||
func (s *App) ClearLog(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := shell.Execf(`cat /dev/null > /var/log/supervisor/supervisord.log`); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status(s.name)
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
// GetConfig 获取配置
|
||||
@@ -114,31 +109,35 @@ func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Processes 进程列表
|
||||
func (s *App) Processes(w http.ResponseWriter, r *http.Request) {
|
||||
out, err := shell.Execf(`supervisorctl status | awk '{print $1}'`)
|
||||
if err != nil {
|
||||
out, err := shell.Execf(`supervisorctl status`)
|
||||
if err != nil && out == "" {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var processes []Process
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
if len(line) == 0 {
|
||||
for line := range strings.SplitSeq(out, "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
var p Process
|
||||
p.Name = line
|
||||
if status, err := shell.Execf(`supervisorctl status '%s' | awk '{print $2}'`, line); err == nil {
|
||||
p.Status = status
|
||||
p := Process{
|
||||
Name: fields[0],
|
||||
Status: fields[1],
|
||||
Pid: "-",
|
||||
Uptime: "-",
|
||||
}
|
||||
// RUNNING 行格式:name RUNNING pid 1234, uptime 1:23:45 (超过 1 天为 "1 day, 1:23:45")
|
||||
if p.Status == "RUNNING" {
|
||||
pid, _ := shell.Execf(`supervisorctl status '%s' | awk '{print $4}'`, line)
|
||||
p.Pid = strings.ReplaceAll(pid, ",", "")
|
||||
uptime, _ := shell.Execf(`supervisorctl status '%s' | awk '{print $6}'`, line)
|
||||
p.Uptime = uptime
|
||||
} else {
|
||||
p.Pid = "-"
|
||||
p.Uptime = "-"
|
||||
if _, rest, ok := strings.Cut(line, "pid "); ok {
|
||||
if pid, _, ok := strings.Cut(rest, ","); ok {
|
||||
p.Pid = pid
|
||||
}
|
||||
}
|
||||
if _, uptime, ok := strings.Cut(line, "uptime "); ok {
|
||||
p.Uptime = uptime
|
||||
}
|
||||
}
|
||||
processes = append(processes, p)
|
||||
}
|
||||
@@ -159,7 +158,7 @@ func (s *App) StartProcess(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if out, err := shell.Execf(`supervisorctl start %s`, req.Process); err != nil {
|
||||
if out, err := shell.Execf(`supervisorctl start '%s'`, req.Process); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v %s", err, out)
|
||||
return
|
||||
}
|
||||
@@ -175,7 +174,7 @@ func (s *App) StopProcess(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if out, err := shell.Execf(`supervisorctl stop %s`, req.Process); err != nil {
|
||||
if out, err := shell.Execf(`supervisorctl stop '%s'`, req.Process); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v %s", err, out)
|
||||
return
|
||||
}
|
||||
@@ -191,7 +190,7 @@ func (s *App) RestartProcess(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if out, err := shell.Execf(`supervisorctl restart %s`, req.Process); err != nil {
|
||||
if out, err := shell.Execf(`supervisorctl restart '%s'`, req.Process); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v %s", err, out)
|
||||
return
|
||||
}
|
||||
@@ -207,11 +206,12 @@ func (s *App) ProcessLog(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
name := programName(req.Process)
|
||||
var logPath string
|
||||
if os.IsRHEL() {
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisord.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, req.Process)
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisord.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, name)
|
||||
} else {
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisor/conf.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, req.Process)
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisor/conf.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, name)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -222,34 +222,6 @@ func (s *App) ProcessLog(w http.ResponseWriter, r *http.Request) {
|
||||
service.Success(w, logPath)
|
||||
}
|
||||
|
||||
// ClearProcessLog 清空进程日志
|
||||
func (s *App) ClearProcessLog(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ProcessName](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var logPath string
|
||||
if os.IsRHEL() {
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisord.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, req.Process)
|
||||
} else {
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisor/conf.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, req.Process)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get log path for process %s: %v", req.Process, err))
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = shell.Execf(`cat /dev/null > '%s'`, logPath); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// ProcessConfig 获取进程配置
|
||||
func (s *App) ProcessConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ProcessName](r)
|
||||
@@ -258,11 +230,12 @@ func (s *App) ProcessConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
name := programName(req.Process)
|
||||
var config string
|
||||
if os.IsRHEL() {
|
||||
config, err = io.Read(`/etc/supervisord.d/` + req.Process + `.conf`)
|
||||
config, err = io.Read(`/etc/supervisord.d/` + name + `.conf`)
|
||||
} else {
|
||||
config, err = io.Read(`/etc/supervisor/conf.d/` + req.Process + `.conf`)
|
||||
config, err = io.Read(`/etc/supervisor/conf.d/` + name + `.conf`)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -281,10 +254,11 @@ func (s *App) UpdateProcessConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
name := programName(req.Process)
|
||||
if os.IsRHEL() {
|
||||
err = io.Write(`/etc/supervisord.d/`+req.Process+`.conf`, req.Config, 0644)
|
||||
err = io.Write(`/etc/supervisord.d/`+name+`.conf`, req.Config, 0644)
|
||||
} else {
|
||||
err = io.Write(`/etc/supervisor/conf.d/`+req.Process+`.conf`, req.Config, 0644)
|
||||
err = io.Write(`/etc/supervisor/conf.d/`+name+`.conf`, req.Config, 0644)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -294,7 +268,7 @@ func (s *App) UpdateProcessConfig(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
_, _ = shell.Execf(`supervisorctl reread`)
|
||||
_, _ = shell.Execf(`supervisorctl update`)
|
||||
_, _ = shell.Execf(`supervisorctl restart '%s'`, req.Process)
|
||||
_, _ = shell.Execf(`supervisorctl restart '%s:'`, name)
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
@@ -307,9 +281,14 @@ func (s *App) CreateProcess(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
processName := `%(program_name)s`
|
||||
if req.Num > 1 {
|
||||
processName = `%(program_name)s_%(process_num)02d`
|
||||
}
|
||||
|
||||
config := `[program:` + req.Name + `]
|
||||
command=` + req.Command + `
|
||||
process_name=%(program_name)s
|
||||
process_name=` + processName + `
|
||||
directory=` + req.Path + `
|
||||
autostart=true
|
||||
autorestart=true
|
||||
@@ -320,20 +299,26 @@ stdout_logfile=/var/log/supervisor/` + req.Name + `.log
|
||||
stdout_logfile_maxbytes=2MB
|
||||
`
|
||||
|
||||
var confPath string
|
||||
if os.IsRHEL() {
|
||||
err = io.Write(`/etc/supervisord.d/`+req.Name+`.conf`, config, 0644)
|
||||
confPath = `/etc/supervisord.d/` + req.Name + `.conf`
|
||||
} else {
|
||||
err = io.Write(`/etc/supervisor/conf.d/`+req.Name+`.conf`, config, 0644)
|
||||
confPath = `/etc/supervisor/conf.d/` + req.Name + `.conf`
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if io.Exists(confPath) {
|
||||
service.Error(w, http.StatusConflict, s.t.Get("process %s already exists", req.Name))
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(confPath, config, 0644); err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = shell.Execf(`supervisorctl reread`)
|
||||
_, _ = shell.Execf(`supervisorctl update`)
|
||||
_, _ = shell.Execf(`supervisorctl start '%s'`, req.Name)
|
||||
_, _ = shell.Execf(`supervisorctl start '%s:'`, req.Name)
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
@@ -346,29 +331,30 @@ func (s *App) DeleteProcess(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if out, err := shell.Execf(`supervisorctl stop '%s'`, req.Process); err != nil {
|
||||
name := programName(req.Process)
|
||||
if out, err := shell.Execf(`supervisorctl stop '%s:'`, name); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v %s", err, out)
|
||||
return
|
||||
}
|
||||
|
||||
var logPath string
|
||||
if os.IsRHEL() {
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisord.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, req.Process)
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisord.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, name)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get log path for process %s: %v", req.Process, err))
|
||||
return
|
||||
}
|
||||
if err = io.Remove(`/etc/supervisord.d/` + req.Process + `.conf`); err != nil {
|
||||
if err = io.Remove(`/etc/supervisord.d/` + name + `.conf`); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisor/conf.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, req.Process)
|
||||
logPath, err = shell.Execf(`cat '/etc/supervisor/conf.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, name)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get log path for process %s: %v", req.Process, err))
|
||||
return
|
||||
}
|
||||
if err = io.Remove(`/etc/supervisor/conf.d/` + req.Process + `.conf`); err != nil {
|
||||
if err = io.Remove(`/etc/supervisor/conf.d/` + name + `.conf`); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
@@ -383,3 +369,8 @@ func (s *App) DeleteProcess(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
func programName(process string) string {
|
||||
name, _, _ := strings.Cut(process, ":")
|
||||
return name
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type ProcessName struct {
|
||||
type CreateProcess struct {
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
User string `form:"user" json:"user" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required && unix_path"`
|
||||
Command string `form:"command" json:"command" validate:"required"`
|
||||
Num int `form:"num" json:"num" validate:"required|min:1"`
|
||||
Num int `form:"num" json:"num" validate:"required && min:1"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
package valkey
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/biz"
|
||||
"github.com/acepanel/panel/v3/internal/service"
|
||||
"github.com/acepanel/panel/v3/pkg/io"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
t *gotext.Locale
|
||||
databaseServerRepo biz.DatabaseServerRepo
|
||||
}
|
||||
|
||||
func NewApp(t *gotext.Locale, databaseServerRepo biz.DatabaseServerRepo) (*App, error) {
|
||||
|
||||
databaseServer := databaseServerRepo
|
||||
return &App{
|
||||
t: t,
|
||||
databaseServerRepo: databaseServer,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *App) Route(r chi.Router) {
|
||||
r.Get("/load", s.Load)
|
||||
r.Get("/config", s.GetConfig)
|
||||
r.Post("/config", s.UpdateConfig)
|
||||
r.Get("/config_tune", s.GetConfigTune)
|
||||
r.Post("/config_tune", s.UpdateConfigTune)
|
||||
}
|
||||
|
||||
func (s *App) Status() string {
|
||||
ok, _ := systemctl.Status("valkey")
|
||||
return types.AggregateAppStatus(ok)
|
||||
}
|
||||
|
||||
func (s *App) Load(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := systemctl.Status("valkey")
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get valkey status: %v", err))
|
||||
return
|
||||
}
|
||||
if !status {
|
||||
service.Success(w, []types.NV{})
|
||||
return
|
||||
}
|
||||
|
||||
// 检查 Valkey 密码
|
||||
withPassword := ""
|
||||
config, err := io.Read(fmt.Sprintf("%s/server/valkey/valkey.conf", app.Root))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
re := regexp.MustCompile(`(?m)^requirepass\s+(.+)`)
|
||||
matches := re.FindStringSubmatch(config)
|
||||
if len(matches) == 2 {
|
||||
withPassword = " -a " + matches[1]
|
||||
}
|
||||
|
||||
raw, err := shell.Execf("valkey-cli%s info", withPassword)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get valkey info: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
dataRaw := lo.SliceToMap(strings.Split(raw, "\n"), func(item string) (string, string) {
|
||||
parts := strings.Split(item, ":")
|
||||
if len(parts) != 2 {
|
||||
return "", ""
|
||||
}
|
||||
return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
|
||||
})
|
||||
|
||||
data := []types.NV{
|
||||
{Name: s.t.Get("TCP Port"), Value: dataRaw["tcp_port"]},
|
||||
{Name: s.t.Get("Uptime in Days"), Value: dataRaw["uptime_in_days"]},
|
||||
{Name: s.t.Get("Connected Clients"), Value: dataRaw["connected_clients"]},
|
||||
{Name: s.t.Get("Total Allocated Memory"), Value: dataRaw["used_memory_human"]},
|
||||
{Name: s.t.Get("Total Memory Usage"), Value: dataRaw["used_memory_rss_human"]},
|
||||
{Name: s.t.Get("Peak Memory Usage"), Value: dataRaw["used_memory_peak_human"]},
|
||||
{Name: s.t.Get("Memory Fragmentation Ratio"), Value: dataRaw["mem_fragmentation_ratio"]},
|
||||
{Name: s.t.Get("Total Connections Received"), Value: dataRaw["total_connections_received"]},
|
||||
{Name: s.t.Get("Total Commands Processed"), Value: dataRaw["total_commands_processed"]},
|
||||
{Name: s.t.Get("Commands Per Second"), Value: dataRaw["instantaneous_ops_per_sec"]},
|
||||
{Name: s.t.Get("Keyspace Hits"), Value: dataRaw["keyspace_hits"]},
|
||||
{Name: s.t.Get("Keyspace Misses"), Value: dataRaw["keyspace_misses"]},
|
||||
{Name: s.t.Get("Latest Fork Time (ms)"), Value: dataRaw["latest_fork_usec"]},
|
||||
}
|
||||
|
||||
service.Success(w, data)
|
||||
}
|
||||
|
||||
func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read(fmt.Sprintf("%s/server/valkey/valkey.conf", app.Root))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, config)
|
||||
}
|
||||
|
||||
func (s *App) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[UpdateConfig](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = io.Write(fmt.Sprintf("%s/server/valkey/valkey.conf", app.Root), req.Config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("valkey"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// GetConfigTune 获取 Valkey 配置调整参数
|
||||
func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
config, err := io.Read(fmt.Sprintf("%s/server/valkey/valkey.conf", app.Root))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
tune := ConfigTune{
|
||||
Bind: s.getValkeyValue(config, "bind"),
|
||||
Port: s.getValkeyValue(config, "port"),
|
||||
Databases: s.getValkeyValue(config, "databases"),
|
||||
Requirepass: s.getValkeyValue(config, "requirepass"),
|
||||
Timeout: s.getValkeyValue(config, "timeout"),
|
||||
TCPKeepalive: s.getValkeyValue(config, "tcp-keepalive"),
|
||||
Maxmemory: s.getValkeyValue(config, "maxmemory"),
|
||||
MaxmemoryPolicy: s.getValkeyValue(config, "maxmemory-policy"),
|
||||
Appendonly: s.getValkeyValue(config, "appendonly"),
|
||||
Appendfsync: s.getValkeyValue(config, "appendfsync"),
|
||||
}
|
||||
|
||||
service.Success(w, tune)
|
||||
}
|
||||
|
||||
// UpdateConfigTune 更新 Valkey 配置调整参数
|
||||
func (s *App) UpdateConfigTune(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := service.Bind[ConfigTune](r)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
confPath := fmt.Sprintf("%s/server/valkey/valkey.conf", app.Root)
|
||||
config, err := io.Read(confPath)
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
config = s.setValkeyValue(config, "bind", req.Bind)
|
||||
config = s.setValkeyValue(config, "port", req.Port)
|
||||
config = s.setValkeyValue(config, "databases", req.Databases)
|
||||
config = s.setValkeyValue(config, "requirepass", req.Requirepass)
|
||||
config = s.setValkeyValue(config, "timeout", req.Timeout)
|
||||
config = s.setValkeyValue(config, "tcp-keepalive", req.TCPKeepalive)
|
||||
config = s.setValkeyValue(config, "maxmemory", req.Maxmemory)
|
||||
config = s.setValkeyValue(config, "maxmemory-policy", req.MaxmemoryPolicy)
|
||||
config = s.setValkeyValue(config, "appendonly", req.Appendonly)
|
||||
config = s.setValkeyValue(config, "appendfsync", req.Appendfsync)
|
||||
|
||||
if err = io.Write(confPath, config, 0644); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = systemctl.Restart("valkey"); err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 同步密码到数据库服务器记录
|
||||
_ = s.databaseServerRepo.UpdatePassword("local_valkey", req.Requirepass)
|
||||
|
||||
service.Success(w, nil)
|
||||
}
|
||||
|
||||
// getValkeyValue 从 Valkey 配置内容中获取指定键的值
|
||||
func (s *App) getValkeyValue(content string, key string) string {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
}
|
||||
parts := strings.Fields(trimmed)
|
||||
if len(parts) >= 2 && parts[0] == key {
|
||||
return strings.Join(parts[1:], " ")
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// setValkeyValue 在 Valkey 配置内容中设置指定键的值
|
||||
func (s *App) setValkeyValue(content string, key string, value string) string {
|
||||
value = strings.ReplaceAll(value, "\n", "")
|
||||
value = strings.ReplaceAll(value, "\r", "")
|
||||
|
||||
lines := strings.Split(content, "\n")
|
||||
result := make([]string, 0, len(lines))
|
||||
found := false
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" {
|
||||
result = append(result, line)
|
||||
continue
|
||||
}
|
||||
checkLine := trimmed
|
||||
if strings.HasPrefix(checkLine, "#") {
|
||||
checkLine = strings.TrimSpace(checkLine[1:])
|
||||
}
|
||||
parts := strings.Fields(checkLine)
|
||||
if len(parts) >= 1 && parts[0] == key {
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if value == "" {
|
||||
if !strings.HasPrefix(trimmed, "#") {
|
||||
result = append(result, "# "+trimmed)
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
continue
|
||||
}
|
||||
result = append(result, key+" "+value)
|
||||
} else {
|
||||
result = append(result, line)
|
||||
}
|
||||
}
|
||||
if !found && value != "" {
|
||||
result = append(result, key+" "+value)
|
||||
}
|
||||
return strings.Join(result, "\n")
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package valkey
|
||||
|
||||
type UpdateConfig struct {
|
||||
Config string `form:"config" json:"config" validate:"required"`
|
||||
}
|
||||
|
||||
// ConfigTune Valkey 配置调整
|
||||
type ConfigTune struct {
|
||||
// 常规设置
|
||||
Bind string `form:"bind" json:"bind"`
|
||||
Port string `form:"port" json:"port" validate:"number && min:1 && max:65535"`
|
||||
Databases string `form:"databases" json:"databases" validate:"number && min:1"`
|
||||
Requirepass string `form:"requirepass" json:"requirepass"`
|
||||
Timeout string `form:"timeout" json:"timeout" validate:"number"`
|
||||
TCPKeepalive string `form:"tcp_keepalive" json:"tcp_keepalive" validate:"number"`
|
||||
// 内存
|
||||
Maxmemory string `form:"maxmemory" json:"maxmemory"`
|
||||
MaxmemoryPolicy string `form:"maxmemory_policy" json:"maxmemory_policy" validate:"in:noeviction,allkeys-lru,allkeys-lfu,volatile-lru,volatile-lfu,allkeys-random,volatile-random,volatile-ttl"`
|
||||
// 持久化
|
||||
Appendonly string `form:"appendonly" json:"appendonly" validate:"in:yes,no"`
|
||||
Appendfsync string `form:"appendfsync" json:"appendfsync" validate:"in:always,everysec,no"`
|
||||
}
|
||||
@@ -0,0 +1,984 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/samber/lo"
|
||||
lop "github.com/samber/lo/parallel"
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/apploader"
|
||||
"github.com/acepanel/panel/v3/pkg/shell"
|
||||
"github.com/acepanel/panel/v3/pkg/sshlog"
|
||||
"github.com/acepanel/panel/v3/pkg/systemctl"
|
||||
"github.com/acepanel/panel/v3/pkg/tools"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
// 告警指标类型
|
||||
const (
|
||||
AlertTypeCPU = "cpu" // CPU 使用率 %
|
||||
AlertTypeMemory = "memory" // 内存使用率 %
|
||||
AlertTypeSwap = "swap" // Swap 使用率 %
|
||||
AlertTypeLoad1 = "load1" // 1 分钟平均负载
|
||||
AlertTypeLoad5 = "load5" // 5 分钟平均负载
|
||||
AlertTypeLoad15 = "load15" // 15 分钟平均负载
|
||||
AlertTypeDisk = "disk" // 磁盘使用率 %,目标为挂载点
|
||||
AlertTypeDiskInode = "disk_inode" // 磁盘 inode 使用率 %,目标为挂载点
|
||||
AlertTypeDiskRead = "disk_read" // 磁盘读取速率 MB/s,目标为设备名
|
||||
AlertTypeDiskWrite = "disk_write" // 磁盘写入速率 MB/s,目标为设备名
|
||||
AlertTypeNetIn = "net_in" // 网卡下行速率 MB/s,目标为网卡名
|
||||
AlertTypeNetOut = "net_out" // 网卡上行速率 MB/s,目标为网卡名
|
||||
AlertTypeWebsite5xx = "website_5xx" // 网站本小时 5xx 次数,目标为网站名
|
||||
AlertTypeWebsiteError = "website_error" // 网站本小时错误率 %,目标为网站名
|
||||
AlertTypeService = "service" // 服务未运行,目标为服务名
|
||||
AlertTypeProject = "project" // 项目未运行,目标为项目名
|
||||
AlertTypeContainer = "container" // 容器未运行,目标为容器名
|
||||
AlertTypeApp = "app" // 应用未运行,目标为应用标识
|
||||
AlertTypeDatabase = "database" // 数据库服务器不可达,目标为服务器名
|
||||
AlertTypeCertExpire = "cert_expire" // 证书剩余天数,目标为域名
|
||||
AlertTypeWebsiteExpire = "website_expire" // 网站剩余天数,目标为网站名
|
||||
)
|
||||
|
||||
// statusAlertTypes 状态类指标,语义固定为「不在运行」,不需要运算符与阈值
|
||||
var statusAlertTypes = []string{AlertTypeService, AlertTypeProject, AlertTypeContainer, AlertTypeApp, AlertTypeDatabase}
|
||||
|
||||
// IsStatusAlert 是否为状态类指标
|
||||
func IsStatusAlert(typ string) bool {
|
||||
return slices.Contains(statusAlertTypes, typ)
|
||||
}
|
||||
|
||||
const (
|
||||
// alertRetryDelay 通知发送失败后的重试间隔
|
||||
alertRetryDelay = 5 * time.Minute
|
||||
// sshFailThreshold 单次检查窗口内触发爆破告警的失败次数
|
||||
sshFailThreshold uint = 5
|
||||
// sshFailSilence 同一来源两次爆破告警的最小间隔
|
||||
sshFailSilence = 30 * time.Minute
|
||||
)
|
||||
|
||||
// 告警比较运算符
|
||||
const (
|
||||
AlertOperatorGT = "gt"
|
||||
AlertOperatorGTE = "gte"
|
||||
AlertOperatorLT = "lt"
|
||||
AlertOperatorLTE = "lte"
|
||||
)
|
||||
|
||||
// AlertRule 告警规则
|
||||
type AlertRule struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"not null;default:''" json:"name"`
|
||||
Type string `gorm:"not null;default:''" json:"type"`
|
||||
Target string `gorm:"not null;default:''" json:"target"` // 挂载点/网卡/磁盘/服务名/域名,空表示全部
|
||||
Operator string `gorm:"not null;default:'gt'" json:"operator"` // gt/gte/lt/lte
|
||||
Threshold float64 `gorm:"not null;default:0" json:"threshold"`
|
||||
Duration uint `gorm:"not null;default:1" json:"duration"` // 连续满足次数
|
||||
Silence uint `gorm:"not null;default:30" json:"silence"` // 静默期(分钟)
|
||||
Channels []uint `gorm:"serializer:json" json:"channels"` // 通知渠道 ID
|
||||
Enabled bool `gorm:"not null;default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Alert 告警记录
|
||||
type Alert struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
RuleID uint `gorm:"not null;default:0;index" json:"rule_id"`
|
||||
RuleName string `gorm:"not null;default:''" json:"rule_name"`
|
||||
Type string `gorm:"not null;default:''" json:"type"`
|
||||
Target string `gorm:"not null;default:''" json:"target"`
|
||||
Value float64 `gorm:"not null;default:0" json:"value"`
|
||||
Message string `gorm:"not null;default:''" json:"message"`
|
||||
Notified bool `gorm:"not null;default:false" json:"notified"`
|
||||
CreatedAt time.Time `gorm:"index" json:"created_at"`
|
||||
}
|
||||
|
||||
// AlertMetric 单个目标的取值
|
||||
type AlertMetric struct {
|
||||
Target string
|
||||
Value float64
|
||||
}
|
||||
|
||||
type AlertRepo interface {
|
||||
ListRules(page, limit uint) ([]*AlertRule, int64, error)
|
||||
AllRules() ([]*AlertRule, error)
|
||||
GetRule(id uint) (*AlertRule, error)
|
||||
CreateRule(rule *AlertRule) error
|
||||
UpdateRule(rule *AlertRule) error
|
||||
DeleteRule(id uint) error
|
||||
AddAlert(alert *Alert) error
|
||||
ListAlerts(page, limit uint) ([]*Alert, int64, error)
|
||||
ClearAlerts() error
|
||||
ClearAlertsBefore(t time.Time) error
|
||||
CertExpiry() ([]*AlertMetric, error)
|
||||
WebsiteExpiry() ([]*AlertMetric, error)
|
||||
ProjectNames() ([]string, error)
|
||||
DatabaseServers() ([]*DatabaseServer, error)
|
||||
WebsiteHourStats() ([]*WebsiteHourStat, error)
|
||||
}
|
||||
|
||||
// WebsiteHourStat 网站当前小时的请求统计
|
||||
type WebsiteHourStat struct {
|
||||
Site string
|
||||
Requests uint64
|
||||
Errors uint64
|
||||
Status5xx uint64
|
||||
}
|
||||
|
||||
// ioSnapshot 网卡/磁盘累计计数快照及据此算出的速率(字节/秒)
|
||||
type ioSnapshot struct {
|
||||
in uint64
|
||||
out uint64
|
||||
inRate uint64
|
||||
outRate uint64
|
||||
at time.Time
|
||||
}
|
||||
|
||||
type AlertUsecase struct {
|
||||
repo AlertRepo
|
||||
notify *NotifyUsecase
|
||||
setting SettingRepo
|
||||
container ContainerRepo
|
||||
app AppRepo
|
||||
database DatabaseServerRepo
|
||||
loader *apploader.Loader
|
||||
log *slog.Logger
|
||||
t *gotext.Locale
|
||||
|
||||
mu sync.Mutex
|
||||
hits map[string]uint // 连续命中次数
|
||||
fired map[string]time.Time // 上次通知时间
|
||||
netSnaps map[string]ioSnapshot // 网卡累计流量快照
|
||||
diskSnaps map[string]ioSnapshot // 磁盘累计 IO 快照
|
||||
healthKeys map[string]struct{} // 已通知的健康问题
|
||||
sshFired map[string]time.Time // SSH 爆破上次通知时间
|
||||
sshAt time.Time // SSH 日志上次检查时间
|
||||
dbProbe map[string]bool // 本轮数据库连通性探测结果
|
||||
cleanedAt time.Time
|
||||
}
|
||||
|
||||
func NewAlertUsecase(notifyUsecase *NotifyUsecase, loader *apploader.Loader, t *gotext.Locale, log *slog.Logger, alertRepo AlertRepo, appRepo AppRepo, containerRepo ContainerRepo, databaseServerRepo DatabaseServerRepo, settingRepo SettingRepo) (*AlertUsecase, error) {
|
||||
return &AlertUsecase{
|
||||
repo: alertRepo,
|
||||
notify: notifyUsecase,
|
||||
setting: settingRepo,
|
||||
container: containerRepo,
|
||||
app: appRepo,
|
||||
database: databaseServerRepo,
|
||||
loader: loader,
|
||||
log: log,
|
||||
t: t,
|
||||
hits: make(map[string]uint),
|
||||
fired: make(map[string]time.Time),
|
||||
netSnaps: make(map[string]ioSnapshot),
|
||||
diskSnaps: make(map[string]ioSnapshot),
|
||||
healthKeys: make(map[string]struct{}),
|
||||
sshFired: make(map[string]time.Time),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) ListRules(page, limit uint) ([]*AlertRule, int64, error) {
|
||||
return uc.repo.ListRules(page, limit)
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) GetRule(id uint) (*AlertRule, error) {
|
||||
return uc.repo.GetRule(id)
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) CreateRule(ctx context.Context, req *request.AlertRuleCreate) (*AlertRule, error) {
|
||||
rule := &AlertRule{
|
||||
Name: req.Name,
|
||||
Type: req.Type,
|
||||
Target: req.Target,
|
||||
Operator: req.Operator,
|
||||
Threshold: req.Threshold,
|
||||
Duration: req.Duration,
|
||||
Silence: req.Silence,
|
||||
Channels: req.Channels,
|
||||
Enabled: req.Enabled,
|
||||
}
|
||||
normalizeRule(rule)
|
||||
|
||||
if err := uc.repo.CreateRule(rule); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uc.log.Info("alert rule created", slog.String("type", OperationTypeMonitor), slog.Uint64("operator_id", operatorID(ctx)), slog.String("name", req.Name))
|
||||
|
||||
return rule, nil
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) UpdateRule(ctx context.Context, req *request.AlertRuleUpdate) error {
|
||||
rule, err := uc.repo.GetRule(req.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rule.Name = req.Name
|
||||
rule.Type = req.Type
|
||||
rule.Target = req.Target
|
||||
rule.Operator = req.Operator
|
||||
rule.Threshold = req.Threshold
|
||||
rule.Duration = req.Duration
|
||||
rule.Silence = req.Silence
|
||||
rule.Channels = req.Channels
|
||||
rule.Enabled = req.Enabled
|
||||
normalizeRule(rule)
|
||||
|
||||
if err = uc.repo.UpdateRule(rule); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 规则变更后重置命中状态,避免沿用旧阈值的计数
|
||||
uc.mu.Lock()
|
||||
uc.clearState(rule.ID)
|
||||
uc.mu.Unlock()
|
||||
|
||||
uc.log.Info("alert rule updated", slog.String("type", OperationTypeMonitor), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(req.ID)), slog.String("name", req.Name))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) DeleteRule(ctx context.Context, id uint) error {
|
||||
rule, err := uc.repo.GetRule(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = uc.repo.DeleteRule(id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uc.mu.Lock()
|
||||
uc.clearState(id)
|
||||
uc.mu.Unlock()
|
||||
|
||||
uc.log.Info("alert rule deleted", slog.String("type", OperationTypeMonitor), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(id)), slog.String("name", rule.Name))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) ListAlerts(page, limit uint) ([]*Alert, int64, error) {
|
||||
return uc.repo.ListAlerts(page, limit)
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) ClearAlerts() error {
|
||||
return uc.repo.ClearAlerts()
|
||||
}
|
||||
|
||||
// Evaluate 评估全部启用的规则,命中则记录并通知
|
||||
func (uc *AlertUsecase) Evaluate(ctx context.Context) error {
|
||||
rules, err := uc.repo.AllRules()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 探测结果按轮缓存,进入新一轮先失效
|
||||
uc.mu.Lock()
|
||||
uc.dbProbe = nil
|
||||
uc.mu.Unlock()
|
||||
|
||||
uc.cleanup()
|
||||
uc.checkHealth(ctx)
|
||||
uc.checkSSH(ctx)
|
||||
|
||||
var enabled []*AlertRule
|
||||
for _, rule := range rules {
|
||||
if rule.Enabled {
|
||||
enabled = append(enabled, rule)
|
||||
}
|
||||
}
|
||||
if len(enabled) == 0 {
|
||||
uc.mu.Lock()
|
||||
clear(uc.hits)
|
||||
clear(uc.fired)
|
||||
uc.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
info := tools.CurrentInfo(nil, nil)
|
||||
now := time.Now()
|
||||
uc.updateSnapshots(info, now)
|
||||
|
||||
alive := make(map[string]struct{})
|
||||
for _, rule := range enabled {
|
||||
metrics, err := uc.collect(ctx, rule, info)
|
||||
if err != nil {
|
||||
uc.log.Warn("failed to collect alert metric", slog.String("rule", rule.Name), slog.Any("err", err))
|
||||
continue
|
||||
}
|
||||
|
||||
for _, metric := range metrics {
|
||||
key := stateKey(rule.ID, metric.Target)
|
||||
alive[key] = struct{}{}
|
||||
uc.evaluateMetric(ctx, rule, metric, key, now)
|
||||
}
|
||||
}
|
||||
|
||||
// 清理已消失的目标状态
|
||||
uc.mu.Lock()
|
||||
for key := range uc.hits {
|
||||
if _, ok := alive[key]; !ok {
|
||||
delete(uc.hits, key)
|
||||
}
|
||||
}
|
||||
uc.mu.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) evaluateMetric(ctx context.Context, rule *AlertRule, metric *AlertMetric, key string, now time.Time) {
|
||||
uc.mu.Lock()
|
||||
if !matchThreshold(rule, metric.Value) {
|
||||
delete(uc.hits, key)
|
||||
uc.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
uc.hits[key]++
|
||||
hits := uc.hits[key]
|
||||
duration := max(rule.Duration, 1)
|
||||
if hits < duration {
|
||||
uc.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
// 静默期内不重复告警
|
||||
if last, ok := uc.fired[key]; ok && now.Sub(last) < time.Duration(rule.Silence)*time.Minute {
|
||||
uc.mu.Unlock()
|
||||
return
|
||||
}
|
||||
uc.fired[key] = now
|
||||
uc.mu.Unlock()
|
||||
|
||||
alert := &Alert{
|
||||
RuleID: rule.ID,
|
||||
RuleName: rule.Name,
|
||||
Type: rule.Type,
|
||||
Target: metric.Target,
|
||||
Value: metric.Value,
|
||||
Message: uc.buildMessage(rule, metric),
|
||||
}
|
||||
|
||||
sent, err := uc.notify.Send(ctx, rule.Channels, uc.t.Get("[AcePanel] Alert: %s", rule.Name), NotifyBody(alert.Message, [][2]string{
|
||||
{uc.t.Get("Rule"), rule.Name},
|
||||
{uc.t.Get("Metric"), uc.metricLabel(rule.Type, metric.Target)},
|
||||
{uc.t.Get("Current Value"), uc.formatValue(rule.Type, metric.Value)},
|
||||
{uc.t.Get("Threshold"), uc.formatValue(rule.Type, rule.Threshold)},
|
||||
{uc.t.Get("Time"), now.Format(time.DateTime)},
|
||||
}))
|
||||
if err != nil {
|
||||
uc.log.Warn("failed to send alert notification", slog.String("rule", rule.Name), slog.Any("err", err))
|
||||
}
|
||||
alert.Notified = sent > 0
|
||||
|
||||
// 一条都没送达时缩短静默期,让下一轮重试,避免临时故障吞掉整个静默窗口
|
||||
if len(rule.Channels) > 0 && sent == 0 {
|
||||
uc.mu.Lock()
|
||||
uc.fired[key] = now.Add(alertRetryDelay - time.Duration(rule.Silence)*time.Minute)
|
||||
uc.mu.Unlock()
|
||||
}
|
||||
|
||||
if err := uc.repo.AddAlert(alert); err != nil {
|
||||
uc.log.Warn("failed to save alert record", slog.String("rule", rule.Name), slog.Any("err", err))
|
||||
}
|
||||
}
|
||||
|
||||
// collect 采集规则对应的目标取值
|
||||
func (uc *AlertUsecase) collect(ctx context.Context, rule *AlertRule, info types.CurrentInfo) ([]*AlertMetric, error) {
|
||||
switch rule.Type {
|
||||
case AlertTypeCPU:
|
||||
return []*AlertMetric{{Value: info.Percent}}, nil
|
||||
|
||||
case AlertTypeMemory:
|
||||
if info.Mem == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return []*AlertMetric{{Value: info.Mem.UsedPercent}}, nil
|
||||
|
||||
case AlertTypeSwap:
|
||||
if info.Swap == nil || info.Swap.Total == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return []*AlertMetric{{Value: info.Swap.UsedPercent}}, nil
|
||||
|
||||
case AlertTypeLoad1, AlertTypeLoad5, AlertTypeLoad15:
|
||||
if info.Load == nil {
|
||||
return nil, nil
|
||||
}
|
||||
switch rule.Type {
|
||||
case AlertTypeLoad1:
|
||||
return []*AlertMetric{{Value: info.Load.Load1}}, nil
|
||||
case AlertTypeLoad5:
|
||||
return []*AlertMetric{{Value: info.Load.Load5}}, nil
|
||||
default:
|
||||
return []*AlertMetric{{Value: info.Load.Load15}}, nil
|
||||
}
|
||||
|
||||
case AlertTypeDisk, AlertTypeDiskInode:
|
||||
metrics := make([]*AlertMetric, 0)
|
||||
for _, usage := range info.DiskUsage {
|
||||
if rule.Target != "" && rule.Target != usage.Path {
|
||||
continue
|
||||
}
|
||||
value := usage.UsedPercent
|
||||
if rule.Type == AlertTypeDiskInode {
|
||||
value = usage.InodesUsedPercent
|
||||
}
|
||||
metrics = append(metrics, &AlertMetric{Target: usage.Path, Value: value})
|
||||
}
|
||||
return metrics, nil
|
||||
|
||||
case AlertTypeNetIn, AlertTypeNetOut, AlertTypeDiskRead, AlertTypeDiskWrite:
|
||||
return uc.rateMetrics(rule), nil
|
||||
|
||||
case AlertTypeWebsite5xx, AlertTypeWebsiteError:
|
||||
stats, err := uc.repo.WebsiteHourStats()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metrics := make([]*AlertMetric, 0, len(stats))
|
||||
for _, item := range stats {
|
||||
if rule.Target != "" && rule.Target != item.Site {
|
||||
continue
|
||||
}
|
||||
if rule.Type == AlertTypeWebsite5xx {
|
||||
metrics = append(metrics, &AlertMetric{Target: item.Site, Value: float64(item.Status5xx)})
|
||||
continue
|
||||
}
|
||||
// 无请求时错误率无意义
|
||||
if item.Requests == 0 {
|
||||
continue
|
||||
}
|
||||
metrics = append(metrics, &AlertMetric{Target: item.Site, Value: float64(item.Errors) / float64(item.Requests) * 100})
|
||||
}
|
||||
return metrics, nil
|
||||
|
||||
case AlertTypeService:
|
||||
if rule.Target == "" {
|
||||
return nil, nil
|
||||
}
|
||||
return []*AlertMetric{{Target: rule.Target, Value: notRunning(systemctl.Status(rule.Target))}}, nil
|
||||
|
||||
case AlertTypeProject:
|
||||
names, err := uc.repo.ProjectNames()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 项目即 systemd 单元,单元名与项目名一致
|
||||
return lop.Map(filterNames(rule.Target, names), func(name string, _ int) *AlertMetric {
|
||||
return &AlertMetric{Target: name, Value: notRunning(systemctl.Status(name))}
|
||||
}), nil
|
||||
|
||||
case AlertTypeContainer:
|
||||
containers, err := uc.container.ListAll(containerSock(uc.setting))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metrics := make([]*AlertMetric, 0, len(containers))
|
||||
for _, item := range containers {
|
||||
if rule.Target != "" && rule.Target != item.Name {
|
||||
continue
|
||||
}
|
||||
value := float64(0)
|
||||
if item.State != "running" {
|
||||
value = 1
|
||||
}
|
||||
metrics = append(metrics, &AlertMetric{Target: item.Name, Value: value})
|
||||
}
|
||||
return metrics, nil
|
||||
|
||||
case AlertTypeApp:
|
||||
installed, err := uc.app.Installed()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
targets := lo.Filter(installed, func(item *App, _ int) bool {
|
||||
if rule.Target != "" && rule.Target != item.Slug {
|
||||
return false
|
||||
}
|
||||
_, ok := uc.loader.Get(item.Slug)
|
||||
return ok
|
||||
})
|
||||
// 状态查询逐个访问 systemd,并发采集
|
||||
return lo.Compact(lop.Map(targets, func(item *App, _ int) *AlertMetric {
|
||||
a, _ := uc.loader.Get(item.Slug)
|
||||
status := a.Status()
|
||||
// 无 systemd 服务的应用没有运行状态
|
||||
if status == types.AppStatusNA {
|
||||
return nil
|
||||
}
|
||||
value := float64(0)
|
||||
if status != types.AppStatusRunning {
|
||||
value = 1
|
||||
}
|
||||
return &AlertMetric{Target: item.Slug, Value: value}
|
||||
})), nil
|
||||
|
||||
case AlertTypeDatabase:
|
||||
servers, err := uc.repo.DatabaseServers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reachable := uc.probeDatabases(ctx, servers)
|
||||
|
||||
metrics := make([]*AlertMetric, 0, len(servers))
|
||||
for _, item := range servers {
|
||||
if rule.Target != "" && rule.Target != item.Name {
|
||||
continue
|
||||
}
|
||||
value := float64(0)
|
||||
if !reachable[item.Name] {
|
||||
value = 1
|
||||
}
|
||||
metrics = append(metrics, &AlertMetric{Target: item.Name, Value: value})
|
||||
}
|
||||
return metrics, nil
|
||||
|
||||
case AlertTypeCertExpire:
|
||||
metrics, err := uc.repo.CertExpiry()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return filterTarget(rule.Target, metrics), nil
|
||||
|
||||
case AlertTypeWebsiteExpire:
|
||||
metrics, err := uc.repo.WebsiteExpiry()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return filterTarget(rule.Target, metrics), nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unsupported alert type: %s", rule.Type)
|
||||
}
|
||||
|
||||
// notRunning 将运行状态转为告警取值,未运行记为 1,配合 normalizeRule 的 >=1 判定
|
||||
func notRunning(running bool, _ error) float64 {
|
||||
if running {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
// filterNames 按目标名筛选,目标为空表示全部
|
||||
func filterNames(target string, names []string) []string {
|
||||
if target == "" {
|
||||
return names
|
||||
}
|
||||
if slices.Contains(names, target) {
|
||||
return []string{target}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// filterTarget 按目标名筛选,目标为空表示全部
|
||||
// 证书目标是逗号分隔的多域名,允许用其中任一域名命中
|
||||
func filterTarget(target string, metrics []*AlertMetric) []*AlertMetric {
|
||||
if target == "" {
|
||||
return metrics
|
||||
}
|
||||
|
||||
filtered := make([]*AlertMetric, 0)
|
||||
for _, metric := range metrics {
|
||||
if metric.Target == target || slices.Contains(strings.Split(metric.Target, ","), target) {
|
||||
filtered = append(filtered, metric)
|
||||
}
|
||||
}
|
||||
|
||||
return filtered
|
||||
}
|
||||
|
||||
// probeDatabases 并发探测数据库连通性,结果在本轮评估内复用,避免多条规则重复整批探测
|
||||
// 单台耗时上限由 pkg/db 各驱动的连接超时保证(5~10 秒),并发后整批不会拖长分钟级评估
|
||||
func (uc *AlertUsecase) probeDatabases(ctx context.Context, servers []*DatabaseServer) map[string]bool {
|
||||
uc.mu.Lock()
|
||||
cached := uc.dbProbe
|
||||
uc.mu.Unlock()
|
||||
if cached != nil {
|
||||
return cached
|
||||
}
|
||||
|
||||
probe := lo.FromEntries(lop.Map(servers, func(item *DatabaseServer, _ int) lo.Entry[string, bool] {
|
||||
return lo.Entry[string, bool]{Key: item.Name, Value: uc.database.CheckServer(ctx, item)}
|
||||
}))
|
||||
|
||||
uc.mu.Lock()
|
||||
uc.dbProbe = probe
|
||||
uc.mu.Unlock()
|
||||
|
||||
return probe
|
||||
}
|
||||
|
||||
// rateMetrics 从快照读取速率指标(MB/s)
|
||||
func (uc *AlertUsecase) rateMetrics(rule *AlertRule) []*AlertMetric {
|
||||
uc.mu.Lock()
|
||||
defer uc.mu.Unlock()
|
||||
|
||||
snaps := uc.netSnaps
|
||||
if rule.Type == AlertTypeDiskRead || rule.Type == AlertTypeDiskWrite {
|
||||
snaps = uc.diskSnaps
|
||||
}
|
||||
|
||||
metrics := make([]*AlertMetric, 0, len(snaps))
|
||||
for name, snap := range snaps {
|
||||
if rule.Target != "" && rule.Target != name {
|
||||
continue
|
||||
}
|
||||
value := snap.inRate
|
||||
if rule.Type == AlertTypeNetOut || rule.Type == AlertTypeDiskWrite {
|
||||
value = snap.outRate
|
||||
}
|
||||
metrics = append(metrics, &AlertMetric{Target: name, Value: float64(value) / 1024 / 1024})
|
||||
}
|
||||
|
||||
return metrics
|
||||
}
|
||||
|
||||
// updateSnapshots 用两次采集的累计值计算速率,结果暂存于快照
|
||||
func (uc *AlertUsecase) updateSnapshots(info types.CurrentInfo, now time.Time) {
|
||||
uc.mu.Lock()
|
||||
defer uc.mu.Unlock()
|
||||
|
||||
nets := make(map[string]ioSnapshot, len(info.Net))
|
||||
for _, item := range info.Net {
|
||||
if item.Name == "lo" {
|
||||
continue
|
||||
}
|
||||
nets[item.Name] = rateOf(uc.netSnaps[item.Name], item.BytesRecv, item.BytesSent, now)
|
||||
}
|
||||
uc.netSnaps = nets
|
||||
|
||||
disks := make(map[string]ioSnapshot, len(info.DiskIO))
|
||||
for _, item := range info.DiskIO {
|
||||
disks[item.Name] = rateOf(uc.diskSnaps[item.Name], item.ReadBytes, item.WriteBytes, now)
|
||||
}
|
||||
uc.diskSnaps = disks
|
||||
}
|
||||
|
||||
// checkHealth 上报新出现的面板健康问题,问题恢复后重新出现会再次通知
|
||||
// 同步发送并只在送达后记入去重集合,否则一次发送失败就会让持续存在的问题再也不告警
|
||||
func (uc *AlertUsecase) checkHealth(ctx context.Context) {
|
||||
issues := app.Health.Snapshot()
|
||||
|
||||
uc.mu.Lock()
|
||||
fresh := make([]app.HealthIssue, 0, len(issues))
|
||||
notified := make(map[string]struct{}, len(issues))
|
||||
for _, issue := range issues {
|
||||
if _, ok := uc.healthKeys[issue.Key]; ok {
|
||||
notified[issue.Key] = struct{}{}
|
||||
continue
|
||||
}
|
||||
fresh = append(fresh, issue)
|
||||
}
|
||||
// 已消失的问题在此被丢弃,恢复后再次出现会重新通知
|
||||
uc.healthKeys = notified
|
||||
uc.mu.Unlock()
|
||||
|
||||
for _, issue := range fresh {
|
||||
if err := uc.notify.SendEventSync(ctx, NotifyEventHealth, uc.t.Get("[AcePanel] Panel Health Issue"), NotifyBody(uc.t.Get("panel reported a health issue"), [][2]string{
|
||||
{uc.t.Get("Item"), issue.Key},
|
||||
{uc.t.Get("Level"), issue.Level},
|
||||
{uc.t.Get("Detail"), issue.Message},
|
||||
{uc.t.Get("Time"), issue.Since.Format(time.DateTime)},
|
||||
})); err != nil {
|
||||
uc.log.Warn("failed to send health notification", slog.String("item", issue.Key), slog.Any("err", err))
|
||||
continue
|
||||
}
|
||||
|
||||
uc.mu.Lock()
|
||||
uc.healthKeys[issue.Key] = struct{}{}
|
||||
uc.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// checkSSH 增量检查 sshd 日志,上报登录成功与爆破尝试
|
||||
func (uc *AlertUsecase) checkSSH(ctx context.Context) {
|
||||
now := time.Now()
|
||||
|
||||
uc.mu.Lock()
|
||||
since := uc.sshAt
|
||||
uc.sshAt = now
|
||||
uc.mu.Unlock()
|
||||
|
||||
// 首次仅记录时间,避免面板启动时把历史日志全推一遍
|
||||
if since.IsZero() {
|
||||
return
|
||||
}
|
||||
|
||||
raw, err := shell.ExecfWithContext(ctx, `journalctl -u sshd -u ssh --no-pager -o json --since "@%d" 2>/dev/null`, since.Unix())
|
||||
if err != nil {
|
||||
// 读取失败则回退检查点,下一轮重扫该窗口,避免丢掉这段时间的登录记录
|
||||
uc.mu.Lock()
|
||||
uc.sshAt = since
|
||||
uc.mu.Unlock()
|
||||
return
|
||||
}
|
||||
if raw == "" {
|
||||
return
|
||||
}
|
||||
|
||||
failures := make(map[string]uint)
|
||||
scanner := bufio.NewScanner(strings.NewReader(raw))
|
||||
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
|
||||
for scanner.Scan() {
|
||||
var entry struct {
|
||||
Message string `json:"MESSAGE"`
|
||||
}
|
||||
if json.Unmarshal(scanner.Bytes(), &entry) != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
record := sshlog.ParseMessage(entry.Message)
|
||||
if record == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
switch record.Status {
|
||||
case sshlog.StatusAccepted:
|
||||
uc.notify.SendEvent(NotifyEventSSHLogin, uc.t.Get("[AcePanel] SSH Login"), NotifyBody(uc.t.Get("SSH login succeeded"), [][2]string{
|
||||
{uc.t.Get("Username"), record.User},
|
||||
{uc.t.Get("IP"), record.IP},
|
||||
{uc.t.Get("Method"), record.Method},
|
||||
{uc.t.Get("Time"), now.Format(time.DateTime)},
|
||||
}))
|
||||
case sshlog.StatusFailed, sshlog.StatusInvalidUser:
|
||||
failures[record.IP]++
|
||||
}
|
||||
}
|
||||
|
||||
for ip, count := range failures {
|
||||
if count < sshFailThreshold || !uc.sshShouldFire(ip, now) {
|
||||
continue
|
||||
}
|
||||
uc.notify.SendEvent(NotifyEventSSHBruteforce, uc.t.Get("[AcePanel] SSH Brute-force Attempts"), NotifyBody(uc.t.Get("too many failed SSH login attempts"), [][2]string{
|
||||
{uc.t.Get("IP"), ip},
|
||||
{uc.t.Get("Failed Attempts"), cast.ToString(count)},
|
||||
{uc.t.Get("Time"), now.Format(time.DateTime)},
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
// sshShouldFire 判断某来源是否已过静默期,并顺带清理过期记录
|
||||
func (uc *AlertUsecase) sshShouldFire(ip string, now time.Time) bool {
|
||||
uc.mu.Lock()
|
||||
defer uc.mu.Unlock()
|
||||
|
||||
for key, at := range uc.sshFired {
|
||||
if now.Sub(at) > sshFailSilence {
|
||||
delete(uc.sshFired, key)
|
||||
}
|
||||
}
|
||||
|
||||
if at, ok := uc.sshFired[ip]; ok && now.Sub(at) < sshFailSilence {
|
||||
return false
|
||||
}
|
||||
uc.sshFired[ip] = now
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// cleanup 按保留天数清理历史告警记录
|
||||
func (uc *AlertUsecase) cleanup() {
|
||||
uc.mu.Lock()
|
||||
if time.Since(uc.cleanedAt) < 6*time.Hour {
|
||||
uc.mu.Unlock()
|
||||
return
|
||||
}
|
||||
uc.cleanedAt = time.Now()
|
||||
uc.mu.Unlock()
|
||||
|
||||
days, err := uc.setting.GetInt(SettingKeyAlertLogDays, 30)
|
||||
if err != nil || days <= 0 {
|
||||
return
|
||||
}
|
||||
if err = uc.repo.ClearAlertsBefore(time.Now().AddDate(0, 0, -days)); err != nil {
|
||||
uc.log.Warn("failed to clear expired alerts", slog.Any("err", err))
|
||||
}
|
||||
}
|
||||
|
||||
// clearState 清除某条规则的运行时状态,调用前需持有锁
|
||||
func (uc *AlertUsecase) clearState(ruleID uint) {
|
||||
prefix := fmt.Sprintf("%d:", ruleID)
|
||||
for key := range uc.hits {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
delete(uc.hits, key)
|
||||
}
|
||||
}
|
||||
for key := range uc.fired {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
delete(uc.fired, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) buildMessage(rule *AlertRule, metric *AlertMetric) string {
|
||||
label := uc.metricLabel(rule.Type, metric.Target)
|
||||
|
||||
switch rule.Type {
|
||||
case AlertTypeService:
|
||||
return uc.t.Get("service %s is not running", metric.Target)
|
||||
case AlertTypeProject:
|
||||
return uc.t.Get("project %s is not running", metric.Target)
|
||||
case AlertTypeContainer:
|
||||
return uc.t.Get("container %s is not running", metric.Target)
|
||||
case AlertTypeApp:
|
||||
return uc.t.Get("app %s is not running", metric.Target)
|
||||
case AlertTypeDatabase:
|
||||
return uc.t.Get("database server %s is unreachable", metric.Target)
|
||||
case AlertTypeCertExpire:
|
||||
return uc.t.Get("certificate %s expires in %s days", metric.Target, uc.formatValue(rule.Type, metric.Value))
|
||||
case AlertTypeWebsiteExpire:
|
||||
return uc.t.Get("website %s expires in %s days", metric.Target, uc.formatValue(rule.Type, metric.Value))
|
||||
}
|
||||
|
||||
return uc.t.Get("%s is %s, %s threshold %s", label, uc.formatValue(rule.Type, metric.Value), uc.operatorLabel(rule.Operator), uc.formatValue(rule.Type, rule.Threshold))
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) metricLabel(typ, target string) string {
|
||||
var label string
|
||||
switch typ {
|
||||
case AlertTypeCPU:
|
||||
label = uc.t.Get("CPU usage")
|
||||
case AlertTypeMemory:
|
||||
label = uc.t.Get("memory usage")
|
||||
case AlertTypeSwap:
|
||||
label = uc.t.Get("swap usage")
|
||||
case AlertTypeLoad1:
|
||||
label = uc.t.Get("1 minute load")
|
||||
case AlertTypeLoad5:
|
||||
label = uc.t.Get("5 minutes load")
|
||||
case AlertTypeLoad15:
|
||||
label = uc.t.Get("15 minutes load")
|
||||
case AlertTypeDisk:
|
||||
label = uc.t.Get("disk usage")
|
||||
case AlertTypeDiskInode:
|
||||
label = uc.t.Get("disk inode usage")
|
||||
case AlertTypeDiskRead:
|
||||
label = uc.t.Get("disk read speed")
|
||||
case AlertTypeDiskWrite:
|
||||
label = uc.t.Get("disk write speed")
|
||||
case AlertTypeNetIn:
|
||||
label = uc.t.Get("network download speed")
|
||||
case AlertTypeNetOut:
|
||||
label = uc.t.Get("network upload speed")
|
||||
case AlertTypeWebsite5xx:
|
||||
label = uc.t.Get("website 5xx responses this hour")
|
||||
case AlertTypeWebsiteError:
|
||||
label = uc.t.Get("website error rate this hour")
|
||||
case AlertTypeService:
|
||||
label = uc.t.Get("service status")
|
||||
case AlertTypeProject:
|
||||
label = uc.t.Get("project status")
|
||||
case AlertTypeContainer:
|
||||
label = uc.t.Get("container status")
|
||||
case AlertTypeApp:
|
||||
label = uc.t.Get("app status")
|
||||
case AlertTypeDatabase:
|
||||
label = uc.t.Get("database server status")
|
||||
case AlertTypeCertExpire:
|
||||
label = uc.t.Get("certificate expiry")
|
||||
case AlertTypeWebsiteExpire:
|
||||
label = uc.t.Get("website expiry")
|
||||
default:
|
||||
label = typ
|
||||
}
|
||||
|
||||
if target != "" {
|
||||
return fmt.Sprintf("%s (%s)", label, target)
|
||||
}
|
||||
|
||||
return label
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) operatorLabel(operator string) string {
|
||||
switch operator {
|
||||
case AlertOperatorGTE:
|
||||
return uc.t.Get("greater than or equal to")
|
||||
case AlertOperatorLT:
|
||||
return uc.t.Get("less than")
|
||||
case AlertOperatorLTE:
|
||||
return uc.t.Get("less than or equal to")
|
||||
default:
|
||||
return uc.t.Get("greater than")
|
||||
}
|
||||
}
|
||||
|
||||
func (uc *AlertUsecase) formatValue(typ string, value float64) string {
|
||||
switch typ {
|
||||
case AlertTypeCPU, AlertTypeMemory, AlertTypeSwap, AlertTypeDisk, AlertTypeDiskInode, AlertTypeWebsiteError:
|
||||
return fmt.Sprintf("%.2f%%", value)
|
||||
case AlertTypeNetIn, AlertTypeNetOut, AlertTypeDiskRead, AlertTypeDiskWrite:
|
||||
return fmt.Sprintf("%.2f MB/s", value)
|
||||
case AlertTypeCertExpire, AlertTypeWebsiteExpire, AlertTypeWebsite5xx:
|
||||
return fmt.Sprintf("%.0f", value)
|
||||
}
|
||||
|
||||
if IsStatusAlert(typ) {
|
||||
return uc.t.Get("not running")
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.2f", value)
|
||||
}
|
||||
|
||||
// normalizeRule 补齐规则的默认值,状态类规则固定为「不在运行」
|
||||
func normalizeRule(rule *AlertRule) {
|
||||
if IsStatusAlert(rule.Type) {
|
||||
rule.Operator = AlertOperatorGTE
|
||||
rule.Threshold = 1
|
||||
}
|
||||
if rule.Duration < 1 {
|
||||
rule.Duration = 1
|
||||
}
|
||||
}
|
||||
|
||||
func matchThreshold(rule *AlertRule, value float64) bool {
|
||||
switch rule.Operator {
|
||||
case AlertOperatorGTE:
|
||||
return value >= rule.Threshold
|
||||
case AlertOperatorLT:
|
||||
return value < rule.Threshold
|
||||
case AlertOperatorLTE:
|
||||
return value <= rule.Threshold
|
||||
default:
|
||||
return value > rule.Threshold
|
||||
}
|
||||
}
|
||||
|
||||
// rateOf 依据上次累计值计算每秒增量,首次采集速率为 0
|
||||
func rateOf(prev ioSnapshot, in, out uint64, now time.Time) ioSnapshot {
|
||||
snap := ioSnapshot{in: in, out: out, at: now}
|
||||
if prev.at.IsZero() {
|
||||
return snap
|
||||
}
|
||||
|
||||
elapsed := now.Sub(prev.at).Seconds()
|
||||
if elapsed < 1 {
|
||||
elapsed = 1
|
||||
}
|
||||
if in >= prev.in {
|
||||
snap.inRate = uint64(float64(in-prev.in) / elapsed)
|
||||
}
|
||||
if out >= prev.out {
|
||||
snap.outRate = uint64(float64(out-prev.out) / elapsed)
|
||||
}
|
||||
|
||||
return snap
|
||||
}
|
||||
|
||||
func stateKey(ruleID uint, target string) string {
|
||||
return fmt.Sprintf("%d:%s", ruleID, target)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package biz
|
||||
|
||||
import "testing"
|
||||
|
||||
// 多域名证书的目标是逗号分隔的域名列表,用其中任一域名都应能命中规则
|
||||
func TestFilterTargetMatchesAnyCertDomain(t *testing.T) {
|
||||
metrics := []*AlertMetric{
|
||||
{Target: "a.example.com,b.example.com", Value: 5},
|
||||
{Target: "c.example.com", Value: 30},
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
target string
|
||||
want int
|
||||
}{
|
||||
{"", 2},
|
||||
{"a.example.com", 1},
|
||||
{"b.example.com", 1},
|
||||
{"c.example.com", 1},
|
||||
{"a.example.com,b.example.com", 1},
|
||||
{"missing.example.com", 0},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
if got := filterTarget(c.target, metrics); len(got) != c.want {
|
||||
t.Fatalf("target %q matched %d metrics, want %d", c.target, len(got), c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
+295
-10
@@ -1,10 +1,17 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/acepanel/panel/pkg/api"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/pkg/api"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
@@ -18,19 +25,297 @@ type App struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// AppCustom 自定义编译参数(前置脚本在 configure 前执行,参数追加到 configure 末尾)
|
||||
type AppCustom struct {
|
||||
PreScript string `json:"pre_script"`
|
||||
Args string `json:"args"`
|
||||
}
|
||||
|
||||
// 支持自定义编译参数的应用与环境类型(源码编译类)
|
||||
var (
|
||||
customCompileApps = []string{"apache", "memcached", "nginx", "openresty", "pureftpd", "s3fs"}
|
||||
customCompileEnvTypes = []string{"php", "python"}
|
||||
)
|
||||
|
||||
// CustomCompileApp 判断应用是否支持自定义编译参数
|
||||
func CustomCompileApp(slug string) bool {
|
||||
return slices.Contains(customCompileApps, slug)
|
||||
}
|
||||
|
||||
// CustomCompileEnv 判断环境类型是否支持自定义编译参数
|
||||
func CustomCompileEnv(typ string) bool {
|
||||
return slices.Contains(customCompileEnvTypes, typ)
|
||||
}
|
||||
|
||||
type AppRepo interface {
|
||||
Categories() []types.LV
|
||||
All() api.Apps
|
||||
Get(slug string) (*api.App, error)
|
||||
UpdateExist(slug string) bool
|
||||
Installed() ([]*App, error)
|
||||
GetInstalled(slug string) (*App, error)
|
||||
GetInstalledAll(query string, cond ...string) ([]*App, error)
|
||||
GetHomeShow() ([]map[string]string, error)
|
||||
ListHomeShow() ([]*App, error)
|
||||
IsInstalled(query string, cond ...any) (bool, error)
|
||||
Install(channel, slug string) error
|
||||
UnInstall(slug string) error
|
||||
Update(slug string) error
|
||||
UpdateShow(slug string, show bool) error
|
||||
UpdateOrder(slugs []string) error
|
||||
DownloadCallback(slug string)
|
||||
CheckPanelVersion() error
|
||||
ResolveScript(item *api.App, matchChannel, action, execVersion string) (string, error)
|
||||
ExecScript(script string) error
|
||||
PreCheck(item *api.App, catalog api.Apps) error
|
||||
GetCustom(slug string) (*AppCustom, error)
|
||||
SaveCustom(slug string, custom *AppCustom) error
|
||||
}
|
||||
|
||||
type AppUsecase struct {
|
||||
repo AppRepo
|
||||
cache CacheRepo
|
||||
task TaskRepo
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewAppUsecase(t *gotext.Locale, appRepo AppRepo, cacheRepo CacheRepo, taskRepo TaskRepo) (*AppUsecase, error) {
|
||||
return &AppUsecase{
|
||||
repo: appRepo,
|
||||
cache: cacheRepo,
|
||||
task: taskRepo,
|
||||
t: t,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) Categories() []types.LV {
|
||||
cached, err := uc.cache.Get(CacheKeyCategories)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var categories api.Categories
|
||||
if err = json.Unmarshal([]byte(cached), &categories); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
slices.SortFunc(categories, func(a, b *api.Category) int {
|
||||
return a.Order - b.Order
|
||||
})
|
||||
|
||||
return lo.Map(categories, func(item *api.Category, _ int) types.LV {
|
||||
return types.LV{Label: item.Name, Value: item.Slug}
|
||||
})
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) All() api.Apps {
|
||||
cached, err := uc.cache.Get(CacheKeyApps)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var apps api.Apps
|
||||
if err = json.Unmarshal([]byte(cached), &apps); err != nil {
|
||||
return nil
|
||||
}
|
||||
return apps
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) Get(slug string) (*api.App, error) {
|
||||
for item := range slices.Values(uc.All()) {
|
||||
if item.Slug == slug {
|
||||
return item, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New(uc.t.Get("app %s not found", slug))
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) UpdateExist(slug string) bool {
|
||||
item, err := uc.Get(slug)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
installed, err := uc.repo.GetInstalled(slug)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for channel := range slices.Values(item.Channels) {
|
||||
if channel.Slug == installed.Channel {
|
||||
if channel.Version != installed.Version {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) Installed() ([]*App, error) {
|
||||
return uc.repo.Installed()
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) GetInstalled(slug string) (*App, error) {
|
||||
return uc.repo.GetInstalled(slug)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) GetInstalledAll(query string, cond ...string) ([]*App, error) {
|
||||
return uc.repo.GetInstalledAll(query, cond...)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) GetHomeShow() ([]map[string]string, error) {
|
||||
apps, err := uc.repo.ListHomeShow()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filtered := make([]map[string]string, 0)
|
||||
for item := range slices.Values(apps) {
|
||||
loaded, err := uc.Get(item.Slug)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, map[string]string{
|
||||
"name": loaded.Name,
|
||||
"description": loaded.Description,
|
||||
"slug": loaded.Slug,
|
||||
"version": item.Version,
|
||||
})
|
||||
}
|
||||
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) IsInstalled(query string, cond ...any) (bool, error) {
|
||||
return uc.repo.IsInstalled(query, cond...)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) Install(channel, slug string) error {
|
||||
item, err := uc.Get(slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 恢复原编排:非法面板版本应在存在性检查前报错
|
||||
if err = uc.repo.CheckPanelVersion(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if installed, _ := uc.repo.IsInstalled(slug); installed {
|
||||
return errors.New(uc.t.Get("app %s already installed", slug))
|
||||
}
|
||||
|
||||
script, err := uc.repo.ResolveScript(item, channel, "install", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = uc.repo.PreCheck(item, uc.All()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uc.repo.DownloadCallback(slug)
|
||||
|
||||
if app.IsCli {
|
||||
return uc.repo.ExecScript(script)
|
||||
}
|
||||
|
||||
task := new(Task)
|
||||
task.Key = "app:" + slug
|
||||
task.Name = uc.t.Get("Install app %s", item.Name)
|
||||
task.Status = TaskStatusWaiting
|
||||
task.Shell = script
|
||||
|
||||
return uc.task.Push(task)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) UnInstall(slug string) error {
|
||||
item, err := uc.Get(slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 恢复原编排:非法面板版本应在存在性检查前报错
|
||||
if err = uc.repo.CheckPanelVersion(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if installed, _ := uc.repo.IsInstalled(slug); !installed {
|
||||
return errors.New(uc.t.Get("app %s not installed", item.Name))
|
||||
}
|
||||
installed, err := uc.repo.GetInstalled(slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
script, err := uc.repo.ResolveScript(item, installed.Channel, "uninstall", installed.Version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = uc.repo.PreCheck(item, uc.All()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if app.IsCli {
|
||||
return uc.repo.ExecScript(script)
|
||||
}
|
||||
|
||||
task := new(Task)
|
||||
task.Key = "app:" + slug
|
||||
task.Name = uc.t.Get("Uninstall app %s", item.Name)
|
||||
task.Status = TaskStatusWaiting
|
||||
task.Shell = script
|
||||
|
||||
return uc.task.Push(task)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) Update(slug string) error {
|
||||
item, err := uc.Get(slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 恢复原编排:非法面板版本应在存在性检查前报错
|
||||
if err = uc.repo.CheckPanelVersion(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if installed, _ := uc.repo.IsInstalled(slug); !installed {
|
||||
return errors.New(uc.t.Get("app %s not installed", item.Name))
|
||||
}
|
||||
installed, err := uc.repo.GetInstalled(slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
script, err := uc.repo.ResolveScript(item, installed.Channel, "update", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = uc.repo.PreCheck(item, uc.All()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uc.repo.DownloadCallback(slug)
|
||||
|
||||
if app.IsCli {
|
||||
return uc.repo.ExecScript(script)
|
||||
}
|
||||
|
||||
task := new(Task)
|
||||
task.Key = "app:" + slug
|
||||
task.Name = uc.t.Get("Update app %s", item.Name)
|
||||
task.Status = TaskStatusWaiting
|
||||
task.Shell = script
|
||||
|
||||
return uc.task.Push(task)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) UpdateShow(slug string, show bool) error {
|
||||
return uc.repo.UpdateShow(slug, show)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) GetCustom(slug string) (*AppCustom, error) {
|
||||
return uc.repo.GetCustom(slug)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) SaveCustom(slug string, custom *AppCustom) error {
|
||||
return uc.repo.SaveCustom(slug, custom)
|
||||
}
|
||||
|
||||
func (uc *AppUsecase) UpdateOrder(slugs []string) error {
|
||||
return uc.repo.UpdateOrder(slugs)
|
||||
}
|
||||
|
||||
+117
-11
@@ -2,31 +2,137 @@ package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type BackupType string
|
||||
|
||||
const (
|
||||
BackupTypePath BackupType = "path"
|
||||
BackupTypeWebsite BackupType = "website"
|
||||
BackupTypeMySQL BackupType = "mysql"
|
||||
BackupTypePostgres BackupType = "postgres"
|
||||
BackupTypeRedis BackupType = "redis"
|
||||
BackupTypePanel BackupType = "panel"
|
||||
BackupTypePath BackupType = "path"
|
||||
BackupTypeWebsite BackupType = "website"
|
||||
BackupTypeMySQL BackupType = "mysql"
|
||||
BackupTypePostgres BackupType = "postgresql"
|
||||
BackupTypeClickHouse BackupType = "clickhouse"
|
||||
BackupTypeRedis BackupType = "redis"
|
||||
BackupTypeValkey BackupType = "valkey"
|
||||
BackupTypePanel BackupType = "panel"
|
||||
)
|
||||
|
||||
type BackupRepo interface {
|
||||
List(typ BackupType) ([]*types.BackupFile, error)
|
||||
GetStorage(id uint) (*BackupStorage, error)
|
||||
Create(ctx context.Context, typ BackupType, target string, account uint) error
|
||||
CreatePanel() error
|
||||
Delete(ctx context.Context, typ BackupType, name string) error
|
||||
Restore(ctx context.Context, typ BackupType, backup, target string) error
|
||||
Delete(typ BackupType, name string) error
|
||||
Restore(typ BackupType, backup, target string) error
|
||||
ClearExpired(path, prefix string, save uint) error
|
||||
ClearStorageExpired(account uint, typ BackupType, prefix string, save uint) error
|
||||
CutoffLog(path, target string) error
|
||||
CutoffLog(path, target string) (string, error)
|
||||
CutoffUpload(account uint, typ BackupType, name string, files []string) error
|
||||
GetDefaultPath(typ BackupType) string
|
||||
FixPanel() error
|
||||
UpdatePanel(version, url, checksum string) error
|
||||
UpdatePanel(version, url, checksum string, progress func(string)) error
|
||||
}
|
||||
|
||||
type BackupUsecase struct {
|
||||
repo BackupRepo
|
||||
log *slog.Logger
|
||||
notify *NotifyUsecase
|
||||
t *gotext.Locale
|
||||
}
|
||||
|
||||
func NewBackupUsecase(notifyUsecase *NotifyUsecase, t *gotext.Locale, log *slog.Logger, backupRepo BackupRepo) (*BackupUsecase, error) {
|
||||
return &BackupUsecase{
|
||||
repo: backupRepo,
|
||||
log: log,
|
||||
notify: notifyUsecase,
|
||||
t: t,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) List(typ BackupType) ([]*types.BackupFile, error) {
|
||||
return uc.repo.List(typ)
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) Create(ctx context.Context, typ BackupType, target string, account uint) error {
|
||||
err := uc.repo.Create(ctx, typ, target, account)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 定时备份由 CLI 执行,命令返回即退出,异步通知来不及发出,必须同步发送
|
||||
if sendErr := uc.notify.SendEventSync(ctx, NotifyEventBackup, uc.t.Get("[AcePanel] Backup Failed"), NotifyBody(uc.t.Get("backup task failed"), [][2]string{
|
||||
{uc.t.Get("Type"), string(typ)},
|
||||
{uc.t.Get("Target"), target},
|
||||
{uc.t.Get("Error"), err.Error()},
|
||||
{uc.t.Get("Time"), time.Now().Format(time.DateTime)},
|
||||
})); sendErr != nil {
|
||||
uc.log.Warn("failed to send backup failure notification", slog.Any("err", sendErr))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) CreatePanel() error {
|
||||
return uc.repo.CreatePanel()
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) Delete(ctx context.Context, typ BackupType, name string) error {
|
||||
if err := uc.repo.Delete(typ, name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("backup deleted", slog.String("type", OperationTypeBackup), slog.Uint64("operator_id", operatorID(ctx)), slog.String("backup_type", string(typ)), slog.String("name", name))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) Restore(ctx context.Context, typ BackupType, backup, target string) error {
|
||||
if err := uc.repo.Restore(typ, backup, target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("backup restored",
|
||||
slog.String("type", OperationTypeBackup),
|
||||
slog.Uint64("operator_id", operatorID(ctx)),
|
||||
slog.String("backup_type", string(typ)),
|
||||
slog.String("target", target),
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) ClearExpired(path, prefix string, save uint) error {
|
||||
return uc.repo.ClearExpired(path, prefix, save)
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) ClearStorageExpired(account uint, typ BackupType, prefix string, save uint) error {
|
||||
return uc.repo.ClearStorageExpired(account, typ, prefix, save)
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) CutoffLog(path, target string) (string, error) {
|
||||
return uc.repo.CutoffLog(path, target)
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) CutoffUpload(account uint, typ BackupType, name string, files []string) error {
|
||||
return uc.repo.CutoffUpload(account, typ, name, files)
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) GetDefaultPath(typ BackupType) string {
|
||||
return uc.repo.GetDefaultPath(typ)
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) FixPanel() error {
|
||||
return uc.repo.FixPanel()
|
||||
}
|
||||
|
||||
func (uc *BackupUsecase) UpdatePanel(version, url, checksum string, progress func(string)) error {
|
||||
return uc.repo.UpdatePanel(version, url, checksum, progress)
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@ package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/libtnb/utils/crypt"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/acepanel/panel/internal/app"
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type BackupStorageType string
|
||||
@@ -129,9 +131,110 @@ func (r *BackupStorage) AfterFind(tx *gorm.DB) error {
|
||||
}
|
||||
|
||||
type BackupAccountRepo interface {
|
||||
List(page, limit uint) ([]*BackupStorage, int64, error)
|
||||
Get(id uint) (*BackupStorage, error)
|
||||
Create(ctx context.Context, req *request.BackupStorageCreate) (*BackupStorage, error)
|
||||
Update(ctx context.Context, req *request.BackupStorageUpdate) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
ListPaged(page, limit uint) ([]*BackupStorage, int64, error)
|
||||
GetByID(id uint) (*BackupStorage, error)
|
||||
Create(account *BackupStorage) error
|
||||
Update(account *BackupStorage) error
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
type BackupAccountUsecase struct {
|
||||
repo BackupAccountRepo
|
||||
setting SettingRepo
|
||||
t *gotext.Locale
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func NewBackupAccountUsecase(t *gotext.Locale, log *slog.Logger, backupAccountRepo BackupAccountRepo, settingRepo SettingRepo) (*BackupAccountUsecase, error) {
|
||||
return &BackupAccountUsecase{
|
||||
repo: backupAccountRepo,
|
||||
setting: settingRepo,
|
||||
t: t,
|
||||
log: log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (uc *BackupAccountUsecase) List(page, limit uint) ([]*BackupStorage, int64, error) {
|
||||
// 本地存储
|
||||
localStorage, err := uc.Get(0)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
dbAccounts, total, err := uc.repo.ListPaged(page, limit)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
accounts := make([]*BackupStorage, 0, len(dbAccounts)+1)
|
||||
if page == 1 {
|
||||
accounts = append(accounts, localStorage)
|
||||
}
|
||||
accounts = append(accounts, dbAccounts...)
|
||||
|
||||
return accounts, total + 1, nil
|
||||
}
|
||||
|
||||
func (uc *BackupAccountUsecase) Get(id uint) (*BackupStorage, error) {
|
||||
if id == 0 {
|
||||
path, err := uc.setting.Get(SettingKeyBackupPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BackupStorage{
|
||||
ID: 0,
|
||||
Type: BackupStorageTypeLocal,
|
||||
Name: uc.t.Get("Local Storage"),
|
||||
Info: types.BackupStorageInfo{
|
||||
Path: path,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return uc.repo.GetByID(id)
|
||||
}
|
||||
|
||||
func (uc *BackupAccountUsecase) Create(ctx context.Context, req *request.BackupStorageCreate) (*BackupStorage, error) {
|
||||
account := &BackupStorage{
|
||||
Type: BackupStorageType(req.Type),
|
||||
Name: req.Name,
|
||||
Info: req.Info,
|
||||
}
|
||||
|
||||
if err := uc.repo.Create(account); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uc.log.Info("backup storage created", slog.String("type", OperationTypeBackup), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(account.ID)), slog.String("account_type", req.Type), slog.String("name", req.Name))
|
||||
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (uc *BackupAccountUsecase) Update(ctx context.Context, req *request.BackupStorageUpdate) error {
|
||||
account, err := uc.Get(req.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
account.Type = BackupStorageType(req.Type)
|
||||
account.Name = req.Name
|
||||
account.Info = req.Info
|
||||
|
||||
if err = uc.repo.Update(account); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uc.log.Info("backup storage updated", slog.String("type", OperationTypeBackup), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(req.ID)), slog.String("account_type", req.Type))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *BackupAccountUsecase) Delete(ctx context.Context, id uint) error {
|
||||
if err := uc.repo.Delete(id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uc.log.Info("backup storage deleted", slog.String("type", OperationTypeBackup), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(id)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package biz
|
||||
|
||||
import "github.com/google/wire"
|
||||
|
||||
var ProviderSet = wire.NewSet(
|
||||
NewAlertUsecase, NewAppUsecase, NewBackupUsecase, NewBackupAccountUsecase,
|
||||
NewCacheUsecase, NewCertUsecase, NewCertAccountUsecase,
|
||||
NewCertDNSUsecase, NewContainerUsecase, NewContainerComposeUsecase,
|
||||
NewContainerImageUsecase, NewContainerNetworkUsecase, NewContainerVolumeUsecase,
|
||||
NewCronUsecase, NewDatabaseUsecase, NewDatabaseRedisUsecase,
|
||||
NewDatabaseElasticsearchUsecase, NewDatabaseServerUsecase, NewDatabaseUserUsecase,
|
||||
NewEnvironmentUsecase, NewFileShareUsecase, NewLogUsecase, NewMonitorUsecase,
|
||||
NewNotifyUsecase, NewProjectUsecase, NewSafeUsecase, NewScanEventUsecase,
|
||||
NewSettingUsecase, NewSSHUsecase, NewTamperUsecase, NewTaskUsecase,
|
||||
NewTemplateUsecase, NewUserUsecase, NewUserPasskeyUsecase,
|
||||
NewUserTokenUsecase, NewWebHookUsecase, NewWebsiteUsecase,
|
||||
NewWebsiteStatUsecase, NewWafUsecase,
|
||||
)
|
||||
+89
-5
@@ -1,6 +1,13 @@
|
||||
package biz
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/acepanel/panel/v3/pkg/api"
|
||||
"github.com/acepanel/panel/v3/pkg/apploader"
|
||||
)
|
||||
|
||||
type CacheKey string
|
||||
|
||||
@@ -21,8 +28,85 @@ type Cache struct {
|
||||
type CacheRepo interface {
|
||||
Get(key CacheKey, defaultValue ...string) (string, error)
|
||||
Set(key CacheKey, value string) error
|
||||
UpdateCategories() error
|
||||
UpdateApps() error
|
||||
UpdateEnvironments() error
|
||||
UpdateTemplates() error
|
||||
FetchCategories() (*api.Categories, error)
|
||||
FetchApps() (*api.Apps, error)
|
||||
FetchEnvironments() (*api.Environments, error)
|
||||
FetchTemplates() (*api.Templates, error)
|
||||
}
|
||||
|
||||
type CacheUsecase struct {
|
||||
repo CacheRepo
|
||||
}
|
||||
|
||||
func NewCacheUsecase(repo CacheRepo) *CacheUsecase {
|
||||
return &CacheUsecase{repo: repo}
|
||||
}
|
||||
|
||||
func (uc *CacheUsecase) Get(key CacheKey, defaultValue ...string) (string, error) {
|
||||
return uc.repo.Get(key, defaultValue...)
|
||||
}
|
||||
|
||||
func (uc *CacheUsecase) Set(key CacheKey, value string) error {
|
||||
return uc.repo.Set(key, value)
|
||||
}
|
||||
|
||||
func (uc *CacheUsecase) UpdateCategories() error {
|
||||
categories, err := uc.repo.FetchCategories()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(categories)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return uc.repo.Set(CacheKeyCategories, string(encoded))
|
||||
}
|
||||
|
||||
func (uc *CacheUsecase) UpdateApps() error {
|
||||
remote, err := uc.repo.FetchApps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 去除本地不存在的应用
|
||||
*remote = slices.Clip(slices.DeleteFunc(*remote, func(item *api.App) bool {
|
||||
return !slices.Contains(apploader.SupportedSlugs(), item.Slug)
|
||||
}))
|
||||
|
||||
encoded, err := json.Marshal(remote)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return uc.repo.Set(CacheKeyApps, string(encoded))
|
||||
}
|
||||
|
||||
func (uc *CacheUsecase) UpdateEnvironments() error {
|
||||
environments, err := uc.repo.FetchEnvironments()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(environments)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return uc.repo.Set(CacheKeyEnvironment, string(encoded))
|
||||
}
|
||||
|
||||
func (uc *CacheUsecase) UpdateTemplates() error {
|
||||
templates, err := uc.repo.FetchTemplates()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(templates)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return uc.repo.Set(CacheKeyTemplates, string(encoded))
|
||||
}
|
||||
|
||||
+394
-18
@@ -2,22 +2,32 @@ package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
mholtacme "github.com/mholt/acmez/v3/acme"
|
||||
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/acepanel/panel/pkg/acme"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/app"
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/acme"
|
||||
pkgcert "github.com/acepanel/panel/v3/pkg/cert"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type Cert struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
AccountID uint `gorm:"not null;default:0" json:"account_id"` // 关联的 ACME 账户 ID
|
||||
WebsiteID uint `gorm:"not null;default:0" json:"website_id"` // 关联的网站 ID
|
||||
DNSID uint `gorm:"not null;default:0" json:"dns_id"` // 关联的 DNS ID
|
||||
Type string `gorm:"not null;default:''" json:"type"` // 证书类型 (P256, P384, 2048, 3072, 4096)
|
||||
Domains []string `gorm:"not null;default:'[]';serializer:json" json:"domains"`
|
||||
AccountID uint `gorm:"not null;default:0" json:"account_id"` // 关联的 ACME 账户 ID
|
||||
WebsiteID uint `gorm:"not null;default:0" json:"website_id"` // 关联的网站 ID
|
||||
DNSID uint `gorm:"not null;default:0" json:"dns_id"` // 关联的 DNS ID
|
||||
Type string `gorm:"not null;default:''" json:"type"` // 证书类型 (P256, P384, 2048, 3072, 4096)
|
||||
Domains []string `gorm:"not null;default:'[]';serializer:json" json:"domains"` // 域名
|
||||
Alias map[string]string `gorm:"not null;default:'{}';serializer:json" json:"alias"` // DNS 验证别名
|
||||
AutoRenewal bool `gorm:"not null;default:false" json:"auto_renewal"` // 自动续签
|
||||
RenewalInfo mholtacme.RenewalInfo `gorm:"not null;default:'{}';serializer:json" json:"renewal_info"` // 续签信息
|
||||
CertURL string `gorm:"not null;default:''" json:"cert_url"` // 证书 URL (续签时使用)
|
||||
@@ -36,14 +46,380 @@ type CertRepo interface {
|
||||
List(page, limit uint) ([]*types.CertList, int64, error)
|
||||
Get(id uint) (*Cert, error)
|
||||
GetByWebsite(WebsiteID uint) (*Cert, error)
|
||||
Upload(ctx context.Context, req *request.CertUpload) (*Cert, error)
|
||||
Create(ctx context.Context, req *request.CertCreate) (*Cert, error)
|
||||
Update(ctx context.Context, req *request.CertUpdate) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
ObtainAuto(id uint) (*acme.Certificate, error)
|
||||
ObtainPanel(account *CertAccount, ips []string) ([]byte, []byte, error)
|
||||
ObtainSelfSigned(id uint) error
|
||||
Renew(id uint) (*acme.Certificate, error)
|
||||
RefreshRenewalInfo(id uint) (mholtacme.RenewalInfo, error)
|
||||
Deploy(ID, WebsiteID uint) error
|
||||
Create(req *request.CertCreate) (*Cert, error)
|
||||
CreateUploaded(cert *Cert) error
|
||||
Update(req *request.CertUpdate) error
|
||||
Delete(id uint) error
|
||||
Save(cert *Cert) error
|
||||
GetClient(cert *Cert) (*acme.Client, error)
|
||||
GenerateSelfSigned(domains []string) ([]byte, []byte, error)
|
||||
RunScript(cert *Cert) error
|
||||
ObtainPanel(account *CertAccount, ips []string, webServer string) ([]byte, []byte, error)
|
||||
LoadWebsite(WebsiteID uint) (*Website, error)
|
||||
WriteCertFiles(cert *Cert, certPath, keyPath string) error
|
||||
EnableWebsiteSSL(website *Website, certPath, keyPath, webServer string, tlsVersions []string) error
|
||||
ReloadWebserver(webServer string) error
|
||||
}
|
||||
|
||||
type CertUsecase struct {
|
||||
repo CertRepo
|
||||
setting SettingRepo
|
||||
t *gotext.Locale
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func NewCertUsecase(t *gotext.Locale, log *slog.Logger, certRepo CertRepo, settingRepo SettingRepo) (*CertUsecase, error) {
|
||||
return &CertUsecase{
|
||||
repo: certRepo,
|
||||
setting: settingRepo,
|
||||
t: t,
|
||||
log: log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) List(page, limit uint) ([]*types.CertList, int64, error) {
|
||||
return uc.repo.List(page, limit)
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Get(id uint) (*Cert, error) {
|
||||
return uc.repo.Get(id)
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) GetByWebsite(WebsiteID uint) (*Cert, error) {
|
||||
return uc.repo.GetByWebsite(WebsiteID)
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Upload(ctx context.Context, req *request.CertUpload) (*Cert, error) {
|
||||
info, err := pkgcert.ParseCert([]byte(req.Cert))
|
||||
if err != nil {
|
||||
return nil, errors.New(uc.t.Get("failed to parse certificate: %v", err))
|
||||
}
|
||||
if _, err = pkgcert.ParseKey([]byte(req.Key)); err != nil {
|
||||
return nil, errors.New(uc.t.Get("failed to parse private key: %v", err))
|
||||
}
|
||||
|
||||
// 合并 DNSNames 和 IPAddresses
|
||||
domains := info.DNSNames
|
||||
for _, ip := range info.IPAddresses {
|
||||
domains = append(domains, ip.String())
|
||||
}
|
||||
|
||||
cert := &Cert{
|
||||
Type: "upload",
|
||||
Domains: domains,
|
||||
Cert: req.Cert,
|
||||
Key: req.Key,
|
||||
}
|
||||
if err = uc.repo.CreateUploaded(cert); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert uploaded", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(cert.ID)))
|
||||
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Create(ctx context.Context, req *request.CertCreate) (*Cert, error) {
|
||||
cert, err := uc.repo.Create(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert created", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(cert.ID)), slog.String("cert_type", req.Type))
|
||||
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Update(ctx context.Context, req *request.CertUpdate) error {
|
||||
info, err := pkgcert.ParseCert([]byte(req.Cert))
|
||||
if err == nil && req.Type == "upload" {
|
||||
// 合并 DNSNames 和 IPAddresses
|
||||
req.Domains = info.DNSNames
|
||||
for _, ip := range info.IPAddresses {
|
||||
req.Domains = append(req.Domains, ip.String())
|
||||
}
|
||||
}
|
||||
if req.Type == "upload" && req.AutoRenewal {
|
||||
return errors.New(uc.t.Get("upload certificate cannot be set to auto renewal"))
|
||||
}
|
||||
|
||||
if err = uc.repo.Update(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert updated", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(req.ID)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Delete(ctx context.Context, id uint) error {
|
||||
if err := uc.repo.Delete(id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert deleted", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(id)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) ObtainAuto(id uint) (*acme.Certificate, error) {
|
||||
return uc.ObtainAutoWithProgressCallback(context.Background(), id, nil)
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) ObtainAutoWithProgressCallback(ctx context.Context, id uint, progressCallback func(string)) (*acme.Certificate, error) {
|
||||
report := func(msg string) {
|
||||
if progressCallback != nil {
|
||||
progressCallback(msg)
|
||||
}
|
||||
}
|
||||
|
||||
report(uc.t.Get("initializing ACME client"))
|
||||
cert, err := uc.repo.Get(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client, err := uc.repo.GetClient(cert)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
webServer, _ := uc.setting.Get(SettingKeyWebserver)
|
||||
|
||||
if cert.DNS != nil {
|
||||
client.UseDns(cert.DNS.Type, cert.DNS.Data, acme.DnsOption{
|
||||
Alias: cert.Alias,
|
||||
DnsServer: cert.DNS.Data.DnsServer,
|
||||
SkipVerify: cert.DNS.Data.SkipVerify,
|
||||
ProgressCallback: progressCallback,
|
||||
})
|
||||
} else {
|
||||
if cert.Website == nil {
|
||||
return nil, errors.New(uc.t.Get("this certificate is not associated with a website and cannot be obtained. You can try to obtain it manually"))
|
||||
}
|
||||
hasWildcard := slices.ContainsFunc(cert.Domains, func(d string) bool {
|
||||
return strings.Contains(d, "*")
|
||||
})
|
||||
if hasWildcard {
|
||||
return nil, errors.New(uc.t.Get("wildcard domains cannot use HTTP verification"))
|
||||
}
|
||||
conf := fmt.Sprintf("%s/sites/%s/config/site/001-acme.conf", app.Root, cert.Website.Name)
|
||||
client.UseHTTP(conf, webServer)
|
||||
}
|
||||
|
||||
report(uc.t.Get("issuing certificate, domains: %s", strings.Join(cert.Domains, ", ")))
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
|
||||
defer cancel()
|
||||
ssl, err := client.ObtainCertificate(ctx, cert.Domains, acme.KeyType(cert.Type))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
report(uc.t.Get("obtaining and saving certificate"))
|
||||
cert.RenewalInfo = *ssl.RenewalInfo
|
||||
cert.CertURL = ssl.URL
|
||||
cert.Cert = string(ssl.ChainPEM)
|
||||
cert.Key = string(ssl.PrivateKey)
|
||||
if err = uc.repo.Save(cert); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if cert.Website != nil {
|
||||
report(uc.t.Get("deploying certificate to website"))
|
||||
return &ssl, uc.Deploy(cert.ID, cert.WebsiteID, false)
|
||||
}
|
||||
|
||||
if err = uc.repo.RunScript(cert); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ssl, nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) ObtainPanel(account *CertAccount, ips []string) ([]byte, []byte, error) {
|
||||
webServer, _ := uc.setting.Get(SettingKeyWebserver)
|
||||
return uc.repo.ObtainPanel(account, ips, webServer)
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) ObtainSelfSigned(id uint) error {
|
||||
cert, err := uc.repo.Get(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
crt, key, err := uc.repo.GenerateSelfSigned(cert.Domains)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cert.Cert = string(crt)
|
||||
cert.Key = string(key)
|
||||
if err = uc.repo.Save(cert); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cert.Website != nil {
|
||||
return uc.Deploy(cert.ID, cert.WebsiteID, false)
|
||||
}
|
||||
|
||||
if err = uc.repo.RunScript(cert); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Renew(id uint) (*acme.Certificate, error) {
|
||||
return uc.RenewWithProgressCallback(context.Background(), id, nil)
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) RenewWithProgressCallback(ctx context.Context, id uint, progressCallback func(string)) (*acme.Certificate, error) {
|
||||
report := func(msg string) {
|
||||
if progressCallback != nil {
|
||||
progressCallback(msg)
|
||||
}
|
||||
}
|
||||
|
||||
report(uc.t.Get("preparing renewal"))
|
||||
cert, err := uc.repo.Get(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client, err := uc.repo.GetClient(cert)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if cert.CertURL == "" {
|
||||
return nil, errors.New(uc.t.Get("this certificate has not been obtained successfully and cannot be renewed"))
|
||||
}
|
||||
|
||||
webServer, _ := uc.setting.Get(SettingKeyWebserver)
|
||||
|
||||
if cert.DNS != nil {
|
||||
client.UseDns(cert.DNS.Type, cert.DNS.Data, acme.DnsOption{
|
||||
Alias: cert.Alias,
|
||||
DnsServer: cert.DNS.Data.DnsServer,
|
||||
SkipVerify: cert.DNS.Data.SkipVerify,
|
||||
ProgressCallback: progressCallback,
|
||||
})
|
||||
} else {
|
||||
if cert.Website == nil {
|
||||
return nil, errors.New(uc.t.Get("this certificate is not associated with a website and cannot be obtained. You can try to obtain it manually"))
|
||||
} else {
|
||||
for _, domain := range cert.Domains {
|
||||
if strings.Contains(domain, "*") {
|
||||
return nil, errors.New(uc.t.Get("wildcard domains cannot use HTTP verification"))
|
||||
}
|
||||
}
|
||||
conf := fmt.Sprintf("%s/sites/%s/config/site/001-acme.conf", app.Root, cert.Website.Name)
|
||||
client.UseHTTP(conf, webServer)
|
||||
}
|
||||
}
|
||||
|
||||
report(uc.t.Get("renewing certificate, domains: %s", strings.Join(cert.Domains, ", ")))
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
|
||||
defer cancel()
|
||||
ssl, err := client.RenewCertificate(ctx, cert.CertURL, cert.Domains, acme.KeyType(cert.Type))
|
||||
if err != nil {
|
||||
// 续签失败,尝试重签
|
||||
report(uc.t.Get("renewal failed, attempting re-issuance"))
|
||||
ssl, err = client.ObtainCertificate(ctx, cert.Domains, acme.KeyType(cert.Type))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
report(uc.t.Get("obtaining and saving certificate"))
|
||||
cert.RenewalInfo = *ssl.RenewalInfo
|
||||
cert.CertURL = ssl.URL
|
||||
cert.Cert = string(ssl.ChainPEM)
|
||||
cert.Key = string(ssl.PrivateKey)
|
||||
if err = uc.repo.Save(cert); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if cert.Website != nil {
|
||||
report(uc.t.Get("deploying certificate to website"))
|
||||
return &ssl, uc.Deploy(cert.ID, cert.WebsiteID, false)
|
||||
}
|
||||
|
||||
return &ssl, nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) RefreshRenewalInfo(id uint) (mholtacme.RenewalInfo, error) {
|
||||
cert, err := uc.repo.Get(id)
|
||||
if err != nil {
|
||||
return mholtacme.RenewalInfo{}, err
|
||||
}
|
||||
client, err := uc.repo.GetClient(cert)
|
||||
if err != nil {
|
||||
return mholtacme.RenewalInfo{}, err
|
||||
}
|
||||
|
||||
crt, err := pkgcert.ParseCert([]byte(cert.Cert))
|
||||
if err != nil {
|
||||
return mholtacme.RenewalInfo{}, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||
defer cancel()
|
||||
renewInfo, err := client.GetRenewalInfo(ctx, crt)
|
||||
if err != nil {
|
||||
return mholtacme.RenewalInfo{}, err
|
||||
}
|
||||
|
||||
cert.RenewalInfo = renewInfo
|
||||
if err = uc.repo.Save(cert); err != nil {
|
||||
return mholtacme.RenewalInfo{}, err
|
||||
}
|
||||
|
||||
return renewInfo, nil
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Deploy(ID, WebsiteID uint, enableHTTPS bool) error {
|
||||
cert, err := uc.repo.Get(ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cert.Cert == "" || cert.Key == "" {
|
||||
return errors.New(uc.t.Get("this certificate has not been obtained successfully and cannot be deployed"))
|
||||
}
|
||||
|
||||
website, err := uc.repo.LoadWebsite(WebsiteID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configDir := filepath.Join(app.Root, "sites", website.Name, "config")
|
||||
certPath := filepath.Join(configDir, "fullchain.pem")
|
||||
keyPath := filepath.Join(configDir, "private.key")
|
||||
if err = uc.repo.WriteCertFiles(cert, certPath, keyPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 开启 HTTPS
|
||||
if enableHTTPS && !website.SSL {
|
||||
// 原 getVhost 首步读 webserver 设置并传播错误,保持该语义
|
||||
webServer, err := uc.setting.Get(SettingKeyWebserver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tlsVersions, _ := uc.setting.GetSlice(SettingKeyWebsiteTLSVersions)
|
||||
if err = uc.repo.EnableWebsiteSSL(website, certPath, keyPath, webServer, tlsVersions); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
webServer, _ := uc.setting.Get(SettingKeyWebserver)
|
||||
return uc.repo.ReloadWebserver(webServer)
|
||||
}
|
||||
|
||||
func (uc *CertUsecase) Save(cert *Cert) error {
|
||||
return uc.repo.Save(cert)
|
||||
}
|
||||
|
||||
@@ -2,15 +2,21 @@ package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/acme"
|
||||
"github.com/acepanel/panel/v3/pkg/cert"
|
||||
)
|
||||
|
||||
type CertAccount struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Email string `gorm:"not null;default:''" json:"email"`
|
||||
CA string `gorm:"not null;default:'letsencrypt'" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass)
|
||||
CA string `gorm:"not null;default:'letsencrypt'" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google)
|
||||
Kid string `gorm:"not null;default:''" json:"kid"`
|
||||
HmacEncoded string `gorm:"not null;default:''" json:"hmac_encoded"`
|
||||
PrivateKey string `gorm:"not null;default:''" json:"private_key"`
|
||||
@@ -23,9 +29,188 @@ type CertAccount struct {
|
||||
|
||||
type CertAccountRepo interface {
|
||||
List(page, limit uint) ([]*CertAccount, int64, error)
|
||||
GetDefault(userID uint) (*CertAccount, error)
|
||||
Get(id uint) (*CertAccount, error)
|
||||
Create(ctx context.Context, req *request.CertAccountCreate) (*CertAccount, error)
|
||||
Update(ctx context.Context, req *request.CertAccountUpdate) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
GetByCAEmail(ca, email string) (*CertAccount, error)
|
||||
Create(account *CertAccount) error
|
||||
Save(account *CertAccount) error
|
||||
Delete(id uint) error
|
||||
GetGoogleEAB() (*acme.EAB, error)
|
||||
GetZeroSSLEAB(email string) (*acme.EAB, error)
|
||||
RegisterAccount(email, ca string, eab *acme.EAB, keyType acme.KeyType) (*acme.Client, error)
|
||||
}
|
||||
|
||||
type CertAccountUsecase struct {
|
||||
repo CertAccountRepo
|
||||
userRepo UserRepo
|
||||
t *gotext.Locale
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func NewCertAccountUsecase(t *gotext.Locale, log *slog.Logger, certAccountRepo CertAccountRepo, userRepo UserRepo) (*CertAccountUsecase, error) {
|
||||
return &CertAccountUsecase{
|
||||
repo: certAccountRepo,
|
||||
userRepo: userRepo,
|
||||
t: t,
|
||||
log: log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (uc *CertAccountUsecase) List(page, limit uint) ([]*CertAccount, int64, error) {
|
||||
return uc.repo.List(page, limit)
|
||||
}
|
||||
|
||||
func (uc *CertAccountUsecase) GetDefault(userID uint) (*CertAccount, error) {
|
||||
user, err := uc.userRepo.Get(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
account, err := uc.repo.GetByCAEmail("letsencrypt", user.Email)
|
||||
if err == nil {
|
||||
return account, nil
|
||||
}
|
||||
|
||||
req := &request.CertAccountCreate{
|
||||
CA: "letsencrypt",
|
||||
Email: user.Email,
|
||||
KeyType: string(acme.KeyEC256),
|
||||
}
|
||||
|
||||
return uc.Create(context.Background(), req)
|
||||
}
|
||||
|
||||
func (uc *CertAccountUsecase) Get(id uint) (*CertAccount, error) {
|
||||
return uc.repo.Get(id)
|
||||
}
|
||||
|
||||
func (uc *CertAccountUsecase) Create(ctx context.Context, req *request.CertAccountCreate) (*CertAccount, error) {
|
||||
account := new(CertAccount)
|
||||
account.CA = req.CA
|
||||
account.Email = req.Email
|
||||
account.Kid = req.Kid
|
||||
account.HmacEncoded = req.HmacEncoded
|
||||
account.KeyType = req.KeyType
|
||||
|
||||
var err error
|
||||
var client *acme.Client
|
||||
switch account.CA {
|
||||
case "googlecn":
|
||||
eab, eabErr := uc.repo.GetGoogleEAB()
|
||||
if eabErr != nil {
|
||||
return nil, eabErr
|
||||
}
|
||||
account.Kid = eab.KeyID
|
||||
account.HmacEncoded = eab.MACKey
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CAGoogleCN, eab, acme.KeyType(account.KeyType))
|
||||
case "google":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CAGoogle, &acme.EAB{KeyID: account.Kid, MACKey: account.HmacEncoded}, acme.KeyType(account.KeyType))
|
||||
case "letsencrypt":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CALetsEncrypt, nil, acme.KeyType(account.KeyType))
|
||||
case "litessl":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CALiteSSL, &acme.EAB{KeyID: account.Kid, MACKey: account.HmacEncoded}, acme.KeyType(account.KeyType))
|
||||
case "zerossl":
|
||||
eab, eabErr := uc.repo.GetZeroSSLEAB(account.Email)
|
||||
if eabErr != nil {
|
||||
return nil, eabErr
|
||||
}
|
||||
account.Kid = eab.KeyID
|
||||
account.HmacEncoded = eab.MACKey
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CAZeroSSL, eab, acme.KeyType(account.KeyType))
|
||||
case "sslcom":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CASSLcom, &acme.EAB{KeyID: account.Kid, MACKey: account.HmacEncoded}, acme.KeyType(account.KeyType))
|
||||
default:
|
||||
return nil, errors.New(uc.t.Get("unsupported CA"))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New(uc.t.Get("failed to register account: %v", err))
|
||||
}
|
||||
|
||||
privateKey, err := cert.EncodeKey(client.Account.PrivateKey)
|
||||
if err != nil {
|
||||
return nil, errors.New(uc.t.Get("failed to get private key"))
|
||||
}
|
||||
account.PrivateKey = string(privateKey)
|
||||
|
||||
if err = uc.repo.Create(account); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert account created", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(account.ID)), slog.String("ca", req.CA), slog.String("email", req.Email))
|
||||
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (uc *CertAccountUsecase) Update(ctx context.Context, req *request.CertAccountUpdate) error {
|
||||
account, err := uc.repo.Get(req.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
account.CA = req.CA
|
||||
account.Email = req.Email
|
||||
account.Kid = req.Kid
|
||||
account.HmacEncoded = req.HmacEncoded
|
||||
account.KeyType = req.KeyType
|
||||
|
||||
var client *acme.Client
|
||||
switch account.CA {
|
||||
case "googlecn":
|
||||
eab, eabErr := uc.repo.GetGoogleEAB()
|
||||
if eabErr != nil {
|
||||
return eabErr
|
||||
}
|
||||
account.Kid = eab.KeyID
|
||||
account.HmacEncoded = eab.MACKey
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CAGoogleCN, eab, acme.KeyType(account.KeyType))
|
||||
case "google":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CAGoogle, &acme.EAB{KeyID: account.Kid, MACKey: account.HmacEncoded}, acme.KeyType(account.KeyType))
|
||||
case "letsencrypt":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CALetsEncrypt, nil, acme.KeyType(account.KeyType))
|
||||
case "litessl":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CALiteSSL, &acme.EAB{KeyID: account.Kid, MACKey: account.HmacEncoded}, acme.KeyType(account.KeyType))
|
||||
case "zerossl":
|
||||
eab, eabErr := uc.repo.GetZeroSSLEAB(account.Email)
|
||||
if eabErr != nil {
|
||||
return eabErr
|
||||
}
|
||||
account.Kid = eab.KeyID
|
||||
account.HmacEncoded = eab.MACKey
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CAZeroSSL, eab, acme.KeyType(account.KeyType))
|
||||
case "sslcom":
|
||||
client, err = uc.repo.RegisterAccount(account.Email, acme.CASSLcom, &acme.EAB{KeyID: account.Kid, MACKey: account.HmacEncoded}, acme.KeyType(account.KeyType))
|
||||
default:
|
||||
return errors.New(uc.t.Get("unsupported CA"))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.New(uc.t.Get("failed to register account: %v", err))
|
||||
}
|
||||
|
||||
privateKey, err := cert.EncodeKey(client.Account.PrivateKey)
|
||||
if err != nil {
|
||||
return errors.New(uc.t.Get("failed to get private key: %v", err))
|
||||
}
|
||||
account.PrivateKey = string(privateKey)
|
||||
|
||||
if err = uc.repo.Save(account); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert account updated", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(req.ID)), slog.String("ca", req.CA))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *CertAccountUsecase) Delete(ctx context.Context, id uint) error {
|
||||
if err := uc.repo.Delete(id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert account deleted", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(id)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/acepanel/panel/pkg/acme"
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/acme"
|
||||
)
|
||||
|
||||
type CertDNS struct {
|
||||
@@ -22,7 +23,63 @@ type CertDNS struct {
|
||||
type CertDNSRepo interface {
|
||||
List(page, limit uint) ([]*CertDNS, int64, error)
|
||||
Get(id uint) (*CertDNS, error)
|
||||
Create(ctx context.Context, req *request.CertDNSCreate) (*CertDNS, error)
|
||||
Update(ctx context.Context, req *request.CertDNSUpdate) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
Create(req *request.CertDNSCreate) (*CertDNS, error)
|
||||
Update(req *request.CertDNSUpdate) error
|
||||
Delete(id uint) error
|
||||
}
|
||||
|
||||
type CertDNSUsecase struct {
|
||||
repo CertDNSRepo
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func NewCertDNSUsecase(repo CertDNSRepo, log *slog.Logger) *CertDNSUsecase {
|
||||
return &CertDNSUsecase{repo: repo, log: log}
|
||||
}
|
||||
|
||||
func (uc *CertDNSUsecase) List(page, limit uint) ([]*CertDNS, int64, error) {
|
||||
return uc.repo.List(page, limit)
|
||||
}
|
||||
|
||||
func (uc *CertDNSUsecase) Get(id uint) (*CertDNS, error) {
|
||||
return uc.repo.Get(id)
|
||||
}
|
||||
|
||||
func (uc *CertDNSUsecase) Create(ctx context.Context, req *request.CertDNSCreate) (*CertDNS, error) {
|
||||
certDNS, err := uc.repo.Create(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert dns created", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(certDNS.ID)), slog.String("name", req.Name))
|
||||
|
||||
return certDNS, nil
|
||||
}
|
||||
|
||||
func (uc *CertDNSUsecase) Update(ctx context.Context, req *request.CertDNSUpdate) error {
|
||||
if err := uc.repo.Update(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert dns updated", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(req.ID)), slog.String("name", req.Name))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uc *CertDNSUsecase) Delete(ctx context.Context, id uint) error {
|
||||
certDNS, err := uc.repo.Get(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = uc.repo.Delete(id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
uc.log.Info("cert dns deleted", slog.String("type", OperationTypeCert), slog.Uint64("operator_id", operatorID(ctx)), slog.Uint64("id", uint64(id)), slog.String("name", certDNS.Name))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
+115
-15
@@ -1,22 +1,122 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type ContainerRepo interface {
|
||||
ListAll() ([]types.Container, error)
|
||||
ListByName(name string) ([]types.Container, error)
|
||||
Create(req *request.ContainerCreate) (string, error)
|
||||
Remove(id string) error
|
||||
Start(id string) error
|
||||
Stop(id string) error
|
||||
Restart(id string) error
|
||||
Pause(id string) error
|
||||
Unpause(id string) error
|
||||
Kill(id string) error
|
||||
Rename(id string, newName string) error
|
||||
Logs(id string) (string, error)
|
||||
Prune() error
|
||||
ListAll(sock string) ([]types.Container, error)
|
||||
Inspect(sock string, id string) (any, error)
|
||||
Create(sock string, req *request.ContainerCreate) (string, error)
|
||||
Remove(sock string, id string) error
|
||||
Start(sock string, id string) error
|
||||
Stop(sock string, id string) error
|
||||
Restart(sock string, id string) error
|
||||
Pause(sock string, id string) error
|
||||
Unpause(sock string, id string) error
|
||||
Kill(sock string, id string) error
|
||||
Rename(sock string, id string, newName string) error
|
||||
Logs(sock string, id string, tail int) (string, error)
|
||||
Prune(sock string) error
|
||||
}
|
||||
|
||||
type ContainerUsecase struct {
|
||||
repo ContainerRepo
|
||||
setting SettingRepo
|
||||
}
|
||||
|
||||
func NewContainerUsecase(repo ContainerRepo, setting SettingRepo) *ContainerUsecase {
|
||||
return &ContainerUsecase{repo: repo, setting: setting}
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) ListAll() ([]types.Container, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.ListAll(sock)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) ListByName(name string) ([]types.Container, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
containers, err := uc.repo.ListAll(sock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
containers = slices.DeleteFunc(containers, func(item types.Container) bool {
|
||||
return !strings.Contains(item.Name, name)
|
||||
})
|
||||
|
||||
return containers, nil
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Inspect(id string) (any, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Inspect(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Create(req *request.ContainerCreate) (string, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Create(sock, req)
|
||||
}
|
||||
|
||||
// Update 删除旧容器后按新配置重建同名容器
|
||||
func (uc *ContainerUsecase) Update(id string, req *request.ContainerCreate) (string, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
if err := uc.repo.Remove(sock, id); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return uc.repo.Create(sock, req)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Remove(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Remove(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Start(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Start(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Stop(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Stop(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Restart(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Restart(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Pause(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Pause(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Unpause(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Unpause(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Kill(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Kill(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Rename(id string, newName string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Rename(sock, id, newName)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Logs(id string, tail int) (string, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Logs(sock, id, tail)
|
||||
}
|
||||
|
||||
func (uc *ContainerUsecase) Prune() error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Prune(sock)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package biz
|
||||
|
||||
import "github.com/acepanel/panel/pkg/types"
|
||||
import "github.com/acepanel/panel/v3/pkg/types"
|
||||
|
||||
type ContainerComposeRepo interface {
|
||||
List() ([]types.ContainerCompose, error)
|
||||
@@ -9,5 +9,44 @@ type ContainerComposeRepo interface {
|
||||
Update(name, compose string, envs []types.KV) error
|
||||
Up(name string, force bool) error
|
||||
Down(name string) error
|
||||
Remove(name string) error
|
||||
RemoveDir(name string) error
|
||||
}
|
||||
|
||||
type ContainerComposeUsecase struct {
|
||||
repo ContainerComposeRepo
|
||||
}
|
||||
|
||||
func NewContainerComposeUsecase(repo ContainerComposeRepo) *ContainerComposeUsecase {
|
||||
return &ContainerComposeUsecase{repo: repo}
|
||||
}
|
||||
|
||||
func (uc *ContainerComposeUsecase) List() ([]types.ContainerCompose, error) {
|
||||
return uc.repo.List()
|
||||
}
|
||||
|
||||
func (uc *ContainerComposeUsecase) Get(name string) (string, []types.KV, error) {
|
||||
return uc.repo.Get(name)
|
||||
}
|
||||
|
||||
func (uc *ContainerComposeUsecase) Create(name, compose string, envs []types.KV) error {
|
||||
return uc.repo.Create(name, compose, envs)
|
||||
}
|
||||
|
||||
func (uc *ContainerComposeUsecase) Update(name, compose string, envs []types.KV) error {
|
||||
return uc.repo.Update(name, compose, envs)
|
||||
}
|
||||
|
||||
func (uc *ContainerComposeUsecase) Up(name string, force bool) error {
|
||||
return uc.repo.Up(name, force)
|
||||
}
|
||||
|
||||
func (uc *ContainerComposeUsecase) Down(name string) error {
|
||||
return uc.repo.Down(name)
|
||||
}
|
||||
|
||||
func (uc *ContainerComposeUsecase) Remove(name string) error {
|
||||
if err := uc.repo.Down(name); err != nil {
|
||||
return err
|
||||
}
|
||||
return uc.repo.RemoveDir(name)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,48 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type ContainerImageRepo interface {
|
||||
List() ([]types.ContainerImage, error)
|
||||
Exist(name string) (bool, error)
|
||||
Pull(req *request.ContainerImagePull) error
|
||||
Remove(id string) error
|
||||
Prune() error
|
||||
List(sock string) ([]types.ContainerImage, error)
|
||||
Exist(sock string, name string) (bool, error)
|
||||
Pull(sock string, req *request.ContainerImagePull) error
|
||||
Remove(sock string, id string) error
|
||||
Prune(sock string) error
|
||||
}
|
||||
|
||||
type ContainerImageUsecase struct {
|
||||
repo ContainerImageRepo
|
||||
setting SettingRepo
|
||||
}
|
||||
|
||||
func NewContainerImageUsecase(repo ContainerImageRepo, setting SettingRepo) *ContainerImageUsecase {
|
||||
return &ContainerImageUsecase{repo: repo, setting: setting}
|
||||
}
|
||||
|
||||
func (uc *ContainerImageUsecase) List() ([]types.ContainerImage, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.List(sock)
|
||||
}
|
||||
|
||||
func (uc *ContainerImageUsecase) Exist(name string) (bool, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Exist(sock, name)
|
||||
}
|
||||
|
||||
func (uc *ContainerImageUsecase) Pull(req *request.ContainerImagePull) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Pull(sock, req)
|
||||
}
|
||||
|
||||
func (uc *ContainerImageUsecase) Remove(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Remove(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerImageUsecase) Prune() error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Prune(sock)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,42 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type ContainerNetworkRepo interface {
|
||||
List() ([]types.ContainerNetwork, error)
|
||||
Create(req *request.ContainerNetworkCreate) (string, error)
|
||||
Remove(id string) error
|
||||
Prune() error
|
||||
List(sock string) ([]types.ContainerNetwork, error)
|
||||
Create(sock string, req *request.ContainerNetworkCreate) (string, error)
|
||||
Remove(sock string, id string) error
|
||||
Prune(sock string) error
|
||||
}
|
||||
|
||||
type ContainerNetworkUsecase struct {
|
||||
repo ContainerNetworkRepo
|
||||
setting SettingRepo
|
||||
}
|
||||
|
||||
func NewContainerNetworkUsecase(repo ContainerNetworkRepo, setting SettingRepo) *ContainerNetworkUsecase {
|
||||
return &ContainerNetworkUsecase{repo: repo, setting: setting}
|
||||
}
|
||||
|
||||
func (uc *ContainerNetworkUsecase) List() ([]types.ContainerNetwork, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.List(sock)
|
||||
}
|
||||
|
||||
func (uc *ContainerNetworkUsecase) Create(req *request.ContainerNetworkCreate) (string, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Create(sock, req)
|
||||
}
|
||||
|
||||
func (uc *ContainerNetworkUsecase) Remove(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Remove(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerNetworkUsecase) Prune() error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Prune(sock)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,42 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"github.com/acepanel/panel/internal/http/request"
|
||||
"github.com/acepanel/panel/pkg/types"
|
||||
"github.com/acepanel/panel/v3/internal/request"
|
||||
"github.com/acepanel/panel/v3/pkg/types"
|
||||
)
|
||||
|
||||
type ContainerVolumeRepo interface {
|
||||
List() ([]types.ContainerVolume, error)
|
||||
Create(req *request.ContainerVolumeCreate) (string, error)
|
||||
Remove(id string) error
|
||||
Prune() error
|
||||
List(sock string) ([]types.ContainerVolume, error)
|
||||
Create(sock string, req *request.ContainerVolumeCreate) (string, error)
|
||||
Remove(sock string, id string) error
|
||||
Prune(sock string) error
|
||||
}
|
||||
|
||||
type ContainerVolumeUsecase struct {
|
||||
repo ContainerVolumeRepo
|
||||
setting SettingRepo
|
||||
}
|
||||
|
||||
func NewContainerVolumeUsecase(repo ContainerVolumeRepo, setting SettingRepo) *ContainerVolumeUsecase {
|
||||
return &ContainerVolumeUsecase{repo: repo, setting: setting}
|
||||
}
|
||||
|
||||
func (uc *ContainerVolumeUsecase) List() ([]types.ContainerVolume, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.List(sock)
|
||||
}
|
||||
|
||||
func (uc *ContainerVolumeUsecase) Create(req *request.ContainerVolumeCreate) (string, error) {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Create(sock, req)
|
||||
}
|
||||
|
||||
func (uc *ContainerVolumeUsecase) Remove(id string) error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Remove(sock, id)
|
||||
}
|
||||
|
||||
func (uc *ContainerVolumeUsecase) Prune() error {
|
||||
sock := containerSock(uc.setting)
|
||||
return uc.repo.Prune(sock)
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user