diff --git a/APIServer.exe b/APIServer.exe index 2fcbb5e..f7534c7 100644 Binary files a/APIServer.exe and b/APIServer.exe differ diff --git a/APIServer.exe~ b/APIServer.exe~ deleted file mode 100644 index d6b629f..0000000 Binary files a/APIServer.exe~ and /dev/null differ diff --git a/APIServer.go b/APIServer.go index 4e2f2db..71f5a5b 100644 --- a/APIServer.go +++ b/APIServer.go @@ -180,8 +180,10 @@ func startSvc() { http.HandleFunc("/", handleIndex) http.HandleFunc("/request/", handleRequest) http.HandleFunc("/fileinfo/", handleFileInfo) - http.HandleFunc("/getuutinfo/", handleGetUutInfo) http.HandleFunc("/setuutinfo/", handleSetUutInfo) + http.HandleFunc("/getuutinfo/", handleGetUutInfo) + http.HandleFunc("/getdefectinfo/", handleGetDefectInfo) + http.HandleFunc("/getofflineinfo/", handleGetOfflineInfo) logger.Printf("[MSG] Starting HTTP Server On Port: %s\r\n", cfg.Settings.ListenPort) err := http.ListenAndServe(":"+cfg.Settings.ListenPort, nil) if err != nil { @@ -339,41 +341,6 @@ func handleFileInfo(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%s", string(jsonObj)) } -func handleGetUutInfo(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - if r.RequestURI == "/favicon.ico" { - return - } - host := strings.Split(r.Host, ":")[0] - addr := strings.Split(r.RemoteAddr, ":")[0] - uri := r.RequestURI - rst := map[string]string{"RESULT": ""} - - if err := r.ParseForm(); err != nil { - logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error()) - rst["RESULT"] = "NG" - rst["ErrMsg"] = err.Error() - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", "")) - return - } - - params := make(map[string]string, 0) - if len(r.Form) > 0 { - for k, v := range r.Form { - params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0]) - } - } - ews := new(ews.EWS) - rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params) - if rst["RESULT"] != "OK" { - w.WriteHeader(http.StatusInternalServerError) - } else { - w.WriteHeader(http.StatusOK) - } - fmt.Fprintf(w, "%v", rst["ErrMsg"]) -} - func handleSetUutInfo(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() if r.RequestURI == "/favicon.ico" { @@ -413,6 +380,111 @@ func handleSetUutInfo(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", "")) } +func handleGetUutInfo(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + if r.RequestURI == "/favicon.ico" { + return + } + host := strings.Split(r.Host, ":")[0] + addr := strings.Split(r.RemoteAddr, ":")[0] + uri := r.RequestURI + rst := map[string]string{"RESULT": ""} + + if err := r.ParseForm(); err != nil { + logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error()) + rst["RESULT"] = "NG" + rst["ErrMsg"] = err.Error() + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", "")) + return + } + + params := make(map[string]string, 0) + if len(r.Form) > 0 { + for k, v := range r.Form { + params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0]) + } + } + ews := new(ews.EWS) + rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params) + if rst["RESULT"] != "OK" { + w.WriteHeader(http.StatusInternalServerError) + } else { + w.WriteHeader(http.StatusOK) + } + fmt.Fprintf(w, "%v", rst["ErrMsg"]) +} + +func handleGetDefectInfo(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + if r.RequestURI == "/favicon.ico" { + return + } + host := strings.Split(r.Host, ":")[0] + addr := strings.Split(r.RemoteAddr, ":")[0] + uri := r.RequestURI + rst := map[string]string{"RESULT": ""} + + if err := r.ParseForm(); err != nil { + logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error()) + rst["RESULT"] = "NG" + rst["ErrMsg"] = err.Error() + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", "")) + return + } + + params := make(map[string]string, 0) + if len(r.Form) > 0 { + for k, v := range r.Form { + params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0]) + } + } + ews := new(ews.EWS) + rst = ews.GetDefectUuts(cfg, logger, host, addr, uri, params) + if rst["RESULT"] != "OK" { + w.WriteHeader(http.StatusInternalServerError) + } else { + w.WriteHeader(http.StatusOK) + } + fmt.Fprintf(w, "%v", rst["ErrMsg"]) +} + +func handleGetOfflineInfo(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + if r.RequestURI == "/favicon.ico" { + return + } + host := strings.Split(r.Host, ":")[0] + addr := strings.Split(r.RemoteAddr, ":")[0] + uri := r.RequestURI + rst := map[string]string{"RESULT": ""} + + if err := r.ParseForm(); err != nil { + logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error()) + rst["RESULT"] = "NG" + rst["ErrMsg"] = err.Error() + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", "")) + return + } + + params := make(map[string]string, 0) + if len(r.Form) > 0 { + for k, v := range r.Form { + params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0]) + } + } + ews := new(ews.EWS) + rst = ews.GetOfflineUuts(cfg, logger, host, addr, uri, params) + if rst["RESULT"] != "OK" { + w.WriteHeader(http.StatusInternalServerError) + } else { + w.WriteHeader(http.StatusOK) + } + fmt.Fprintf(w, "%v", rst["ErrMsg"]) +} + func parseReqParams(r *http.Request) (map[string]string, error) { params := make(map[string]string, 0) if err := r.ParseForm(); err != nil { diff --git a/Index.html b/Index.html index e7114d0..bebb5ad 100644 --- a/Index.html +++ b/Index.html @@ -5,9 +5,11 @@