From 2b2193e255e55fe55dedf7dce0e6bdc22f4860ee Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 19 八月 2023 19:39:11 +0800
Subject: [PATCH] 修改网络设调用禁用或停用脚本

---
 api/v1/config.go |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/api/v1/config.go b/api/v1/config.go
index 43065ad..96a1c3e 100644
--- a/api/v1/config.go
+++ b/api/v1/config.go
@@ -1,6 +1,7 @@
 package v1
 
 import (
+	"apsClient/conf"
 	"apsClient/model"
 	"apsClient/model/request"
 	_ "apsClient/model/response"
@@ -8,6 +9,8 @@
 	"apsClient/pkg/ecode"
 	"apsClient/pkg/logx"
 	"apsClient/service"
+	"apsClient/utils"
+	"fmt"
 	"github.com/gin-gonic/gin"
 )
 
@@ -56,13 +59,29 @@
 		ctx.FailWithMsg(ecode.UnknownErr, "鑾峰彇缃戠粶閰嶇疆澶辫触")
 		return
 	}
-
 	err = service.NewConfigService().SetNetConfig(params.Id, &params)
 	if err != nil {
 		logx.Errorf("SetNetConfig error: %v", err.Error())
 		ctx.FailWithMsg(ecode.DBErr, "璁剧疆澶辫触")
 		return
 	}
+	if conf.Conf.System.NetSetShellPath == "" || conf.Conf.System.NetUpShellName == "" || conf.Conf.System.NetDownShellName == "" {
+		ctx.FailWithMsg(ecode.DBErr, "璇峰厛閰嶇疆缃戠粶璁剧疆璺緞鍜岃剼鏈悕")
+		return
+	}
+	var shName string
+	if params.Status == model.NetConfigStatusEnabled {
+		shName = conf.Conf.System.NetUpShellName
+	} else {
+		shName = conf.Conf.System.NetDownShellName
+	}
+	sh := fmt.Sprintf("%s %v %v %v", shName, params.IP, params.MASK, params.Gateway)
+	err = utils.Cmd(conf.Conf.System.NetSetShellPath, sh)
+	if err != nil {
+		logx.Errorf("network update failed: %v", err.Error())
+		ctx.FailWithMsg(ecode.UnknownErr, "缃戠粶璁剧疆澶辫触")
+		return
+	}
 	ctx.Ok()
 }
 

--
Gitblit v1.8.0