11package v1
22
33import (
4+ "encoding/base64"
5+
46 "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
57 "github.com/1Panel-dev/1Panel/backend/app/dto"
68 "github.com/1Panel-dev/1Panel/backend/constant"
@@ -27,10 +29,10 @@ func (b *BaseApi) LoadDeviceBaseInfo(c *gin.Context) {
2729// @Summary list time zone options
2830// @Description 获取系统可用时区选项
2931// @Accept json
30- // @Success 200 {Array} dto.TimeZoneOptions
32+ // @Success 200 {Array} string
3133// @Security ApiKeyAuth
3234// @Router /toolbox/device/zone/options [get]
33- func (b * BaseApi ) SearchTimeOption (c * gin.Context ) {
35+ func (b * BaseApi ) LoadTimeOption (c * gin.Context ) {
3436 list , err := deviceService .LoadTimeZone ()
3537 if err != nil {
3638 helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
@@ -40,14 +42,58 @@ func (b *BaseApi) SearchTimeOption(c *gin.Context) {
4042 helper .SuccessWithData (c , list )
4143}
4244
45+ // @Tags Device
46+ // @Summary load conf
47+ // @Description 获取系统配置文件
48+ // @Accept json
49+ // @Param request body dto.OperationWithName true "request"
50+ // @Success 200
51+ // @Security ApiKeyAuth
52+ // @Router /toolbox/device/conf [post]
53+ func (b * BaseApi ) LoadDeviceConf (c * gin.Context ) {
54+ var req dto.OperationWithName
55+ if err := helper .CheckBindAndValidate (& req , c ); err != nil {
56+ return
57+ }
58+
59+ list , err := deviceService .LoadConf (req .Name )
60+ if err != nil {
61+ helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
62+ return
63+ }
64+
65+ helper .SuccessWithData (c , list )
66+ }
67+
68+ // @Tags Device
69+ // @Summary Update device conf by file
70+ // @Description 通过文件修改配置
71+ // @Accept json
72+ // @Param request body dto.UpdateByNameAndFile true "request"
73+ // @Success 200 {object}
74+ // @Security ApiKeyAuth
75+ // @Router /toolbox/device/update/byconf [post]
76+ func (b * BaseApi ) UpdateDevicByFile (c * gin.Context ) {
77+ var req dto.UpdateByNameAndFile
78+ if err := helper .CheckBindAndValidate (& req , c ); err != nil {
79+ return
80+ }
81+ if err := deviceService .UpdateByConf (req ); err != nil {
82+ helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
83+ return
84+ }
85+
86+ helper .SuccessWithData (c , nil )
87+ }
88+
4389// @Tags Device
4490// @Summary Update device
4591// @Description 修改系统参数
4692// @Accept json
4793// @Param request body dto.SettingUpdate true "request"
48- // @Success 200 {object} dto.PageResult
94+ // @Success 200
4995// @Security ApiKeyAuth
50- // @Router /toolbox/device/conf [post]
96+ // @Router /toolbox/device/update/ conf [post]
5197// @x-panel-log {"bodyKeys":["key","value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改主机参数 [key] => [value]","formatEN":"update device conf [key] => [value]"}
5298func (b * BaseApi ) UpdateDeviceConf (c * gin.Context ) {
5399 var req dto.SettingUpdate
@@ -70,11 +116,11 @@ func (b *BaseApi) UpdateDeviceConf(c *gin.Context) {
70116// @Param request body {Array} true "request"
71117// @Success 200 {object} dto.PageResult
72118// @Security ApiKeyAuth
73- // @Router /toolbox/device/host [post]
119+ // @Router /toolbox/device/update/ host [post]
74120// @x-panel-log {"bodyKeys":["key","value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改主机 Host [key] => [value]","formatEN":"update device host [key] => [value]"}
75121func (b * BaseApi ) UpdateDeviceHost (c * gin.Context ) {
76122 var req []dto.HostHelper
77- if err := helper .CheckBindAndValidate (& req , c ); err != nil {
123+ if err := helper .CheckBind (& req , c ); err != nil {
78124 return
79125 }
80126
@@ -85,3 +131,55 @@ func (b *BaseApi) UpdateDeviceHost(c *gin.Context) {
85131
86132 helper .SuccessWithData (c , nil )
87133}
134+
135+ // @Tags Device
136+ // @Summary Update device passwd
137+ // @Description 修改系统密码
138+ // @Accept json
139+ // @Param request body dto.ChangePasswd true "request"
140+ // @Success 200
141+ // @Security ApiKeyAuth
142+ // @Router /toolbox/device/update/passwd [post]
143+ func (b * BaseApi ) UpdateDevicPasswd (c * gin.Context ) {
144+ var req dto.ChangePasswd
145+ if err := helper .CheckBindAndValidate (& req , c ); err != nil {
146+ return
147+ }
148+ if len (req .Passwd ) != 0 {
149+ password , err := base64 .StdEncoding .DecodeString (req .Passwd )
150+ if err != nil {
151+ helper .ErrorWithDetail (c , constant .CodeErrBadRequest , constant .ErrTypeInvalidParams , err )
152+ return
153+ }
154+ req .Passwd = string (password )
155+ }
156+ if err := deviceService .UpdatePasswd (req ); err != nil {
157+ helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
158+ return
159+ }
160+
161+ helper .SuccessWithData (c , nil )
162+ }
163+
164+ // @Tags Device
165+ // @Summary Check device DNS conf
166+ // @Description 检查系统 DNS 配置可用性
167+ // @Accept json
168+ // @Param request body dto.SettingUpdate true "request"
169+ // @Success 200
170+ // @Security ApiKeyAuth
171+ // @Router /toolbox/device/test/dns [post]
172+ func (b * BaseApi ) CheckDNS (c * gin.Context ) {
173+ var req dto.SettingUpdate
174+ if err := helper .CheckBindAndValidate (& req , c ); err != nil {
175+ return
176+ }
177+
178+ data , err := deviceService .CheckDNS (req .Key , req .Value )
179+ if err != nil {
180+ helper .ErrorWithDetail (c , constant .CodeErrInternalServer , constant .ErrTypeInternalServer , err )
181+ return
182+ }
183+
184+ helper .SuccessWithData (c , data )
185+ }
0 commit comments