51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/spf13/viper"
|
|
"gopkg.in/macaron.v1"
|
|
)
|
|
|
|
func upsPage(ctx *macaron.Context) {
|
|
ctx.Data["host"] = viper.GetString("Ups.Host")
|
|
ctx.Data["upsname"] = viper.GetString("Ups.Name")
|
|
ctx.Data["username"] = viper.GetString("Ups.Username")
|
|
ctx.Data["password"] = viper.GetString("Ups.Password")
|
|
|
|
// if ups == nil {
|
|
// ctx.Data["serverstatus"] = "Disconnected"
|
|
// ctx.Data["upsstatus"] = "unknown"
|
|
// } else {
|
|
ctx.Data["serverstatus"] = "Connected"
|
|
ctx.Data["upsstatus"] = upsVars["ups.status"].Value
|
|
ctx.Data["upsmfr"] = upsVars["device.mfr"].Value
|
|
ctx.Data["upsmodel"] = upsVars["device.model"].Value
|
|
ctx.Data["upsserial"] = upsVars["device.serial"].Value
|
|
ctx.Data["upsload"] = upsVars["ups.load"].Value
|
|
ctx.Data["upscharge"] = upsVars["battery.charge"].Value
|
|
|
|
// }
|
|
|
|
ctx.HTML(200, "ups")
|
|
}
|
|
|
|
type UPSPostForm struct {
|
|
Host string `form:"host" binding:"Required"`
|
|
UpsName string `form:"upsname" binding:"Required"`
|
|
Username string `form:"username" binding:"Required"`
|
|
Password string `form:"password" binding:"Required"`
|
|
}
|
|
|
|
func upsPost(ctx *macaron.Context, f UPSPostForm) {
|
|
viper.Set("Ups.Host", strings.ToLower(strings.TrimSpace(f.Host)))
|
|
viper.Set("Ups.Name", strings.TrimSpace(f.UpsName))
|
|
viper.Set("Ups.Username", strings.TrimSpace(f.Username))
|
|
viper.Set("Ups.Password", f.Password)
|
|
|
|
viper.WriteConfig()
|
|
UpsReconfigure()
|
|
|
|
upsPage(ctx)
|
|
}
|