Skip to content

Commit

Permalink
Showing 7 changed files with 256 additions and 1 deletion.
46 changes: 46 additions & 0 deletions app/http/controllers/plugins/rsync_controller.go
Original file line number Diff line number Diff line change
@@ -346,3 +346,49 @@ secrets file = /etc/rsyncd.secrets

return controllers.Success(ctx, nil)
}

// GetConfig
//
// @Summary 获取配置
// @Description 获取 Rsync 配置
// @Tags 插件-Rsync
// @Produce json
// @Security BearerToken
// @Success 200 {object} controllers.SuccessResponse
// @Router /plugins/rsync/config [get]
func (r *RsyncController) GetConfig(ctx http.Context) http.Response {
config, err := tools.Read("/etc/rsyncd.conf")
if err != nil {
return controllers.Error(ctx, http.StatusInternalServerError, err.Error())
}

return controllers.Success(ctx, config)
}

// UpdateConfig
//
// @Summary 更新配置
// @Description 更新 Rsync 配置
// @Tags 插件-Rsync
// @Produce json
// @Security BearerToken
// @Param data body requests.UpdateConfig true "request"
// @Success 200 {object} controllers.SuccessResponse
// @Router /plugins/rsync/config [post]
func (r *RsyncController) UpdateConfig(ctx http.Context) http.Response {
var updateRequest requests.UpdateConfig
sanitize := controllers.Sanitize(ctx, &updateRequest)
if sanitize != nil {
return sanitize
}

if err := tools.Write("/etc/rsyncd.conf", updateRequest.Config, 0644); err != nil {
return controllers.Error(ctx, http.StatusInternalServerError, err.Error())
}

if err := tools.ServiceRestart("rsyncd"); err != nil {
return controllers.Error(ctx, http.StatusInternalServerError, err.Error())
}

return controllers.Success(ctx, nil)
}
32 changes: 32 additions & 0 deletions app/http/requests/plugins/rsync/update_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package requests

import (
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/validation"
)

type UpdateConfig struct {
Config string `form:"config" json:"config"`
}

func (r *UpdateConfig) Authorize(ctx http.Context) error {
return nil
}

func (r *UpdateConfig) Rules(ctx http.Context) map[string]string {
return map[string]string{
"config": "required|string",
}
}

func (r *UpdateConfig) Messages(ctx http.Context) map[string]string {
return map[string]string{}
}

func (r *UpdateConfig) Attributes(ctx http.Context) map[string]string {
return map[string]string{}
}

func (r *UpdateConfig) PrepareForValidation(ctx http.Context, data validation.Data) error {
return nil
}
67 changes: 67 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1661,6 +1661,65 @@ const docTemplate = `{
}
}
},
"/plugins/rsync/config": {
"get": {
"security": [
{
"BearerToken": []
}
],
"description": "获取 Rsync 配置",
"produces": [
"application/json"
],
"tags": [
"插件-Rsync"
],
"summary": "获取配置",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controllers.SuccessResponse"
}
}
}
},
"post": {
"security": [
{
"BearerToken": []
}
],
"description": "更新 Rsync 配置",
"produces": [
"application/json"
],
"tags": [
"插件-Rsync"
],
"summary": "更新配置",
"parameters": [
{
"description": "request",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateConfig"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controllers.SuccessResponse"
}
}
}
}
},
"/plugins/rsync/modules": {
"get": {
"security": [
@@ -2455,6 +2514,14 @@ const docTemplate = `{
}
}
},
"requests.UpdateConfig": {
"type": "object",
"properties": {
"config": {
"type": "string"
}
}
},
"requests.UserStore": {
"type": "object",
"properties": {
67 changes: 67 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1654,6 +1654,65 @@
}
}
},
"/plugins/rsync/config": {
"get": {
"security": [
{
"BearerToken": []
}
],
"description": "获取 Rsync 配置",
"produces": [
"application/json"
],
"tags": [
"插件-Rsync"
],
"summary": "获取配置",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controllers.SuccessResponse"
}
}
}
},
"post": {
"security": [
{
"BearerToken": []
}
],
"description": "更新 Rsync 配置",
"produces": [
"application/json"
],
"tags": [
"插件-Rsync"
],
"summary": "更新配置",
"parameters": [
{
"description": "request",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateConfig"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controllers.SuccessResponse"
}
}
}
}
},
"/plugins/rsync/modules": {
"get": {
"security": [
@@ -2448,6 +2507,14 @@
}
}
},
"requests.UpdateConfig": {
"type": "object",
"properties": {
"config": {
"type": "string"
}
}
},
"requests.UserStore": {
"type": "object",
"properties": {
41 changes: 41 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -350,6 +350,11 @@ definitions:
waf_mode:
type: string
type: object
requests.UpdateConfig:
properties:
config:
type: string
type: object
requests.UserStore:
properties:
ca:
@@ -1473,6 +1478,42 @@ paths:
summary: 更新备注
tags:
- 网站管理
/plugins/rsync/config:
get:
description: 获取 Rsync 配置
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.SuccessResponse'
security:
- BearerToken: []
summary: 获取配置
tags:
- 插件-Rsync
post:
description: 更新 Rsync 配置
parameters:
- description: request
in: body
name: data
required: true
schema:
$ref: '#/definitions/requests.UpdateConfig'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.SuccessResponse'
security:
- BearerToken: []
summary: 更新配置
tags:
- 插件-Rsync
/plugins/rsync/modules:
get:
description: 列出所有 Rsync 模块
2 changes: 2 additions & 0 deletions routes/plugin.go
Original file line number Diff line number Diff line change
@@ -292,6 +292,8 @@ func Plugin() {
route.Post("modules", rsyncController.Create)
route.Post("modules/{name}", rsyncController.Update)
route.Delete("modules/{name}", rsyncController.Destroy)
route.Get("config", rsyncController.GetConfig)
route.Post("config", rsyncController.UpdateConfig)
})
r.Prefix("toolbox").Group(func(route route.Router) {
toolboxController := plugins.NewToolBoxController()
2 changes: 1 addition & 1 deletion scripts/rsync/install.sh
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ log file = /var/log/rsyncd.log
EOF

touch /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.conf
chmod 644 /etc/rsyncd.conf
chmod 600 /etc/rsyncd.secrets

# 写入服务文件

0 comments on commit 5a3a1e6

Please sign in to comment.