|
@@ -9,6 +9,7 @@ import (
|
|
|
"os"
|
|
"os"
|
|
|
"os/exec"
|
|
"os/exec"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
+ "time"
|
|
|
|
|
|
|
|
"hnyfkj.com.cn/rtu/linux/utils/jsonrpc2"
|
|
"hnyfkj.com.cn/rtu/linux/utils/jsonrpc2"
|
|
|
)
|
|
)
|
|
@@ -253,3 +254,38 @@ func serviceLogLevelHandler(port int) http.HandlerFunc {
|
|
|
serviceLogLevel(w, r, port)
|
|
serviceLogLevel(w, r, port)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func DownloadNetworkLog(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
+ filename := fmt.Sprintf("network.log.%s.tar.gz", time.Now().Format("20060102150405"))
|
|
|
|
|
+ tmpFile := "/tmp/" + filename
|
|
|
|
|
+
|
|
|
|
|
+ cmd := exec.Command("tar", "-czf", tmpFile, "-C", "/opt/yfkj/networkd.service/log", ".")
|
|
|
|
|
+ if out, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
|
+ http.Error(w, string(out), http.StatusInternalServerError)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ defer os.Remove(tmpFile)
|
|
|
|
|
+
|
|
|
|
|
+ w.Header().Set("Content-Type", "application/gzip")
|
|
|
|
|
+ w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
|
|
|
|
|
+
|
|
|
|
|
+ http.ServeFile(w, r, tmpFile)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func RestartNetworkService(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
+ if r.Method != http.MethodPost {
|
|
|
|
|
+ http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cmd := exec.Command("systemctl", "restart", "yfkj-networkd.service")
|
|
|
|
|
+
|
|
|
|
|
+ if out, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
|
+ http.Error(w, string(out)+err.Error(), http.StatusInternalServerError)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
+ w.Write([]byte(`{"status":"ok"}`))
|
|
|
|
|
+}
|