diff --git a/README.md b/README.md index fbd7d50..209bd4b 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,4 @@ Sensors code and schemas can be found in the sensors file. It requires Arduino I More information on [ESP8266 Github](https://github.com/esp8266/Arduino). ## Help -To get any help, please visit the XMPP conference room at ``datahouse@muc.kingpenguin.tk`` with your prefered client, or [with your browser](https://jappix.kingpenguin.tk/?r=datahouse@muc.kingpenguin.tk). +To get any help, please visit the XMPP conference room at [datahouse@muc.kingpenguin.tk](xmpp://datahouse@muc.kingpenguin.tk?join) with your prefered client, or [with your browser](https://jappix.kingpenguin.tk/?r=datahouse@muc.kingpenguin.tk). diff --git a/controllers/login.go b/controllers/login.go index 26d426b..b349000 100644 --- a/controllers/login.go +++ b/controllers/login.go @@ -5,12 +5,20 @@ import ( "git.kingpenguin.tk/chteufleur/datahouse.git/models/user" "git.kingpenguin.tk/chteufleur/datahouse.git/models/variables" + + "net/http" + "strings" ) type LoginController struct { beego.Controller } +const ( + UrlXmppAuth = "http://auth.xmpp.kingpenguin.tk/auth" +) + + func (c *LoginController) Prepare() { } @@ -59,7 +67,27 @@ func (c *LoginController) Post() { } func isLoginOK(lgn, pwd string) bool { - ret := pwd != "" // Do not authorize empty password - usr := user.GetUserByLogin(lgn) - return ret && pwd == usr.Password + ret := false + if len(strings.Split(lgn, "@")) != 1 { + // JID inside + log.Info("Auth by JID") + usr := user.GetUserByLogin(strings.Split(lgn, "/")[0]) + if usr.Id == 0 { + // User is not in database + ret = false + } else { + resp, _ := http.Get(UrlXmppAuth+"?domain=datahouse.kingpenguin.tk&method=POST&jid="+lgn+"&transaction_id="+pwd) + httpStatusCode := resp.StatusCode + if resp != nil && httpStatusCode == 200 { + ret = true + } else { + ret = false + } + } + } else { + log.Info("Standard auth") + usr := user.GetUserByLogin(lgn) + ret = pwd != "" && pwd == usr.Password + } + return ret } diff --git a/controllers/sensors.go b/controllers/sensors.go index 19bd2c8..1fc0925 100644 --- a/controllers/sensors.go +++ b/controllers/sensors.go @@ -103,6 +103,7 @@ func (c *SensorsController) PostCompteur() { } else if isDelete != "" { cpt := teleinfo.GetCompteurByAdresse(adresse) teleinfo.DeleteCompteur(cpt.Id) + teleinfo.DeleteDataCompteur(cpt.AdresseCompteur) c.Redirect("/sensors", 302) } else { c.Redirect("/404", 404) diff --git a/main.go b/main.go index 3328c50..a3ca752 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ func main() { go reborn() time.Sleep(1 * time.Second) - models.ChanRuns <- xmpp_manager.EndRun +// models.ChanRuns <- xmpp_manager.EndRun time.Sleep(1 * time.Second) models.ChanRuns <- watchlog.EndRun diff --git a/sensors/TeleInfo/TeleInfo.ino b/sensors/TeleInfo/TeleInfo.ino index c498f4e..804e86b 100644 --- a/sensors/TeleInfo/TeleInfo.ino +++ b/sensors/TeleInfo/TeleInfo.ino @@ -31,6 +31,7 @@ String OPTARIF = ""; String BASE = ""; String HCHP = ""; String HCHC = ""; +bool sendData = false; //---------------------------------------------------- // Wait for x second. @@ -82,6 +83,7 @@ void sendDataToServer() { nextInterval = DEFAULT_INTERVAL; } nextInterval = millis() + nextInterval; + sendData = false; } bool isDigitSelf(char c) { @@ -188,12 +190,15 @@ void loop() { } if (label == "HCHC" && isNumberSelf(value)) { HCHC = value; + sendData = true; } if (label == "HCHP" && isNumberSelf(value)) { HCHP = value; + sendData = true; } - if (millis() >= nextInterval) { +// if (millis() >= nextInterval) { + if (sendData && millis() >= nextInterval) { sendDataToServer(); } } diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index 1473e8c..dcde633 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -5,7 +5,7 @@ import ( "github.com/astaxie/beego" "github.com/astaxie/beego/logs" - "git.kingpenguin.tk/chteufleur/go-xmpp.git" + "git.kingpenguin.tk/chteufleur/go-xmpp.git/src/xmpp" "git.kingpenguin.tk/chteufleur/datahouse.git/models" "git.kingpenguin.tk/chteufleur/datahouse.git/models/relay" "git.kingpenguin.tk/chteufleur/datahouse.git/models/variables" @@ -79,7 +79,7 @@ func mainXMPP() { case *xmpp.Iq: // TODO check if the caller has privilege to ask switch v.PayloadName().Space { - case xmpp.NsDiscoItems: + case xmpp.NSDiscoItems: execDiscoCommand(v) case xmpp.NodeAdHocCommand: @@ -104,7 +104,7 @@ func SendPresence(status, tpye, message string) { func execDiscoCommand(iq *xmpp.Iq) { log.Info("Discovery item iq received") - reply := iq.Response(xmpp.IqTypeResult) + reply := iq.Response(xmpp.IQTypeResult) discoItem := &xmpp.DiscoItems{Node: xmpp.NodeAdHocCommand} relays := relay.GetAllRelay() @@ -133,11 +133,11 @@ func execCommandAdHoc(iq *xmpp.Iq) { if descriptionRelais == "" { descriptionRelais = relais.Mac } - if adHoc.SessionId == "" && adHoc.Action == xmpp.ActionAdHocExecute { + if adHoc.SessionID == "" && adHoc.Action == xmpp.ActionAdHocExecute { // First step in the command if relais.Id != 0 { - reply := iq.Response(xmpp.IqTypeResult) - cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionId: xmpp.SessionId()/*+";"+relais.Mac*/} + reply := iq.Response(xmpp.IQTypeResult) + cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionID: xmpp.SessionID()/*+";"+relais.Mac*/} cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Commande relais "+descriptionRelais} field := &xmpp.AdHocField{Var: "command", Label: "Commande a executer", Type: "list-single"} @@ -156,8 +156,8 @@ func execCommandAdHoc(iq *xmpp.Iq) { err := relais.Toggle() - reply := iq.Response(xmpp.IqTypeResult) - cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionId: adHoc.SessionId} + reply := iq.Response(xmpp.IQTypeResult) + cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionID: adHoc.SessionID} cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Commande relais "+descriptionRelais} cmd.XForm = *cmdXForm @@ -174,8 +174,8 @@ func execCommandAdHoc(iq *xmpp.Iq) { client.Out <- reply } else if adHoc.Action == xmpp.ActionAdHocCancel { // command canceled - reply := iq.Response(xmpp.IqTypeResult) - cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCanceled, SessionId: adHoc.SessionId} + reply := iq.Response(xmpp.IQTypeResult) + cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCanceled, SessionID: adHoc.SessionID} reply.PayloadEncode(cmd) client.Out <- reply }