Example #1
0
File: home.go Project: eaciit/live
func (this *HomeController) GetService() {
	r := this.Ctx.Request
	var service []m.ServiceNew
	// helper.PopulateAsObject(&service, "Service", bson.M{}, nil, 0, 0)
	// this.Json(helper.BuildResponse(true, service, ""))
	data := m.ServiceNew{}
	files, _ := ioutil.ReadDir(servicedbpath + "/")
	for _, f := range files {
		var extension = filepath.Ext(f.Name())
		if f.Name() != "sequenceService.json" && extension == ".json" {
			serviceFile, err := os.Open(servicedbpath + "/" + f.Name())
			if err != nil {
				fmt.Println(err)
			}
			jsonParser := json.NewDecoder(serviceFile)
			if err = jsonParser.Decode(&data); err != nil {
				fmt.Println(err)
			}
			service = append(service, data)
			defer serviceFile.Close()
			if len(arrsvc) == 0 {
				LogStatus := ConfigService(data, r.FormValue("Statuslive"))
				data.Service.LogStatus = LogStatus
			}
		}
	}
	this.Json(helper.BuildResponse(true, service, ""))
	// this.Json(helper.BuildResponse(true, nil, ""))
}
Example #2
0
File: home.go Project: eaciit/live
func (this *HomeController) StopServer() {
	r := this.Ctx.Request
	data := m.ServiceNew{}
	serviceFile, err := os.Open(servicedbpath + "/service" + r.FormValue("ID") + ".json")
	if err != nil {
		fmt.Println(err)
	}
	jsonParser := json.NewDecoder(serviceFile)
	if err = jsonParser.Decode(&data); err != nil {
		fmt.Println(err)
	}
	defer serviceFile.Close()

	f, err := os.Create(servicedbpath + "/service" + strconv.Itoa(data.Service.ID) + ".json")
	if err != nil {
		fmt.Println(err)
	}

	data.Service.DateStatus = time.Now()
	b, err := json.Marshal(data)
	n, err := io.WriteString(f, string(b))
	if err != nil {
		fmt.Println(n, err)
	}

	fmt.Println(arrsvc)
	for j := 0; j < len(arrsvc); j++ {
		if arrsvc[j].ID == data.Service.ID {
			arrsvc[j].svc.CommandStop.Exec()
		}
	}
	this.Json(helper.BuildResponse(true, nil, ""))
}
Example #3
0
File: home.go Project: eaciit/live
func (this *HomeController) RemoveService() {
	r := this.Ctx.Request
	err := os.Remove(servicedbpath + "/service" + r.FormValue("ID") + ".json")
	if err != nil {
		fmt.Println(err)
	}
	this.Json(helper.BuildResponse(true, r.FormValue("ID"), ""))
}
Example #4
0
File: home.go Project: eaciit/live
func (this *HomeController) GetLogService() {
	r := this.Ctx.Request
	var valLog string
	b, err := ioutil.ReadFile(servicedbpath + "/LogService" + r.FormValue("ID") + "%!(EXTRA string=" + r.FormValue("DateFilter") + ")")
	if err != nil {
		valLog = ""
		fmt.Println(err)
	} else {
		valLog = string(b)
	}
	this.Json(helper.BuildResponse(true, valLog, ""))
}
Example #5
0
File: home.go Project: eaciit/live
func (this *HomeController) GetDetailService() {
	r := this.Ctx.Request
	data := m.ServiceNew{}
	serviceFile, err := os.Open(servicedbpath + "/service" + r.FormValue("ID") + ".json")
	if err != nil {
		fmt.Println(err)
	}
	jsonParser := json.NewDecoder(serviceFile)
	if err = jsonParser.Decode(&data); err != nil {
		fmt.Println(err)
	}
	defer serviceFile.Close()
	this.Json(helper.BuildResponse(true, data, ""))
}
Example #6
0
File: home.go Project: eaciit/live
func (this *HomeController) StartService() {
	r := this.Ctx.Request
	data := m.ServiceNew{}
	serviceFile, err := os.Open(servicedbpath + "/service" + r.FormValue("ID") + ".json")
	if err != nil {
		fmt.Println(err)
	}
	jsonParser := json.NewDecoder(serviceFile)
	if err = jsonParser.Decode(&data); err != nil {
		fmt.Println(err)
	}
	defer serviceFile.Close()

	data.Service.DateStatus = time.Now()
	data.Service.StatusService = "Start"

	LogStatus := ConfigService(data, r.FormValue("Statuslive"))
	if LogStatus == "OK" {
		f, err := os.Create(servicedbpath + "/service" + strconv.Itoa(data.Service.ID) + ".json")
		if err != nil {
			fmt.Println(err)
		}
		data.Service.LogStatus = "Success"
		b, err := json.Marshal(data)
		n, err := io.WriteString(f, string(b))
		if err != nil {
			fmt.Println(n, err)
		}
		defer f.Close()
	} else if LogStatus == "Fail" {
		f, err := os.Create(servicedbpath + "/service" + strconv.Itoa(data.Service.ID) + ".json")
		if err != nil {
			fmt.Println(err)
		}
		data.Service.LogStatus = "Fail"
		data.Service.StatusService = "Stop"
		b, err := json.Marshal(data)
		n, err := io.WriteString(f, string(b))
		if err != nil {
			fmt.Println(n, err)
		}
		defer f.Close()
	}

	this.Json(helper.BuildResponse(true, LogStatus, ""))
}
Example #7
0
File: home.go Project: eaciit/live
func (this *HomeController) UpdateService() {
	dataservice := m.ServiceNew{}
	this.GetPayload(&dataservice)
	fmt.Println(dataservice.Ping.CommandParm)
	dataservice.Service.LastUpdate = time.Now()
	dataservice.Service.StatusService = "Stop"

	f, err := os.Create(servicedbpath + "/service" + strconv.Itoa(dataservice.Service.ID) + ".json")
	if err != nil {
		fmt.Println(err)
	}
	b, err := json.Marshal(dataservice)
	n, err := io.WriteString(f, string(b))
	if err != nil {
		fmt.Println(n, err)
	}
	this.Json(helper.BuildResponse(true, nil, ""))
}
Example #8
0
File: home.go Project: eaciit/live
func (this *HomeController) AddService() {
	// r := this.Ctx.Request
	filename := servicedbpath + "/sequenceService.json"
	if _, err := os.Stat(filename); err == nil {
		fmt.Printf("file exists; processing...")
		f, err := os.Open(filename)
		if err != nil {
			fmt.Println(err)
		}
		var seqData []m.SequenceService

		jsonParser := json.NewDecoder(f)
		if err = jsonParser.Decode(&seqData); err != nil {
			fmt.Println(err)
		}
		idService := seqData[0].Seq + 1

		f, err = os.Create(servicedbpath + "/service" + strconv.Itoa(idService) + ".json")
		if err != nil {
			fmt.Println(err)
		}

		dataservice := m.ServiceNew{}
		this.GetPayload(&dataservice)
		dataservice.Service.ID = idService
		dataservice.Service.LastUpdate = time.Now()
		dataservice.Service.DateStatus = time.Now()
		dataservice.Service.StatusService = "Stop"
		b, err := json.Marshal(dataservice)
		n, err := io.WriteString(f, string(b))

		if err != nil {
			fmt.Println(n, err)
		}

		f, err = os.Create(filename)
		if err != nil {
			fmt.Println(err)
		}
		n, err = io.WriteString(f, `[{"Title":"Service", "Seq": `+strconv.Itoa(idService)+`}]`)
		if err != nil {
			fmt.Println(n, err)
		}
		defer f.Close()
	} else {
		f, err := os.Create(filename)
		if err != nil {
			fmt.Println(err)
		}
		n, err := io.WriteString(f, `[{"Title":"Service", "Seq": 1}]`)
		if err != nil {
			fmt.Println(n, err)
		}

		f, err = os.Create(servicedbpath + "/service1.json")
		if err != nil {
			fmt.Println(err)
		}

		dataservice := m.ServiceNew{}
		this.GetPayload(&dataservice)
		fmt.Println(dataservice.Ping.CommandParm)
		dataservice.Service.ID = 1
		dataservice.Service.LastUpdate = time.Now()
		dataservice.Service.DateStatus = time.Now()
		dataservice.Service.StatusService = "Stop"
		b, err := json.Marshal(dataservice)
		n, err = io.WriteString(f, string(b))
		if err != nil {
			fmt.Println(n, err)
		}
		defer f.Close()
	}

	this.Json(helper.BuildResponse(true, nil, ""))
}