Compare commits
6 Commits
0d83871ec0
...
9d55cf5759
| Author | SHA1 | Date |
|---|---|---|
|
|
9d55cf5759 | |
|
|
f53cae8980 | |
|
|
c221349a9c | |
|
|
3147a064db | |
|
|
784ebdee22 | |
|
|
75b320680f |
|
|
@ -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).
|
More information on [ESP8266 Github](https://github.com/esp8266/Arduino).
|
||||||
|
|
||||||
## Help
|
## 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).
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,20 @@ import (
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LoginController struct {
|
type LoginController struct {
|
||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
UrlXmppAuth = "http://auth.xmpp.kingpenguin.tk/auth"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
func (c *LoginController) Prepare() {
|
func (c *LoginController) Prepare() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,7 +67,27 @@ func (c *LoginController) Post() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isLoginOK(lgn, pwd string) bool {
|
func isLoginOK(lgn, pwd string) bool {
|
||||||
ret := pwd != "" // Do not authorize empty password
|
ret := false
|
||||||
usr := user.GetUserByLogin(lgn)
|
if len(strings.Split(lgn, "@")) != 1 {
|
||||||
return ret && pwd == usr.Password
|
// 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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ func (c *SensorsController) PostCompteur() {
|
||||||
} else if isDelete != "" {
|
} else if isDelete != "" {
|
||||||
cpt := teleinfo.GetCompteurByAdresse(adresse)
|
cpt := teleinfo.GetCompteurByAdresse(adresse)
|
||||||
teleinfo.DeleteCompteur(cpt.Id)
|
teleinfo.DeleteCompteur(cpt.Id)
|
||||||
|
teleinfo.DeleteDataCompteur(cpt.AdresseCompteur)
|
||||||
c.Redirect("/sensors", 302)
|
c.Redirect("/sensors", 302)
|
||||||
} else {
|
} else {
|
||||||
c.Redirect("/404", 404)
|
c.Redirect("/404", 404)
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -64,7 +64,7 @@ func main() {
|
||||||
go reborn()
|
go reborn()
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
models.ChanRuns <- xmpp_manager.EndRun
|
// models.ChanRuns <- xmpp_manager.EndRun
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
models.ChanRuns <- watchlog.EndRun
|
models.ChanRuns <- watchlog.EndRun
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ String OPTARIF = "";
|
||||||
String BASE = "";
|
String BASE = "";
|
||||||
String HCHP = "";
|
String HCHP = "";
|
||||||
String HCHC = "";
|
String HCHC = "";
|
||||||
|
bool sendData = false;
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
|
||||||
// Wait for x second.
|
// Wait for x second.
|
||||||
|
|
@ -82,6 +83,7 @@ void sendDataToServer() {
|
||||||
nextInterval = DEFAULT_INTERVAL;
|
nextInterval = DEFAULT_INTERVAL;
|
||||||
}
|
}
|
||||||
nextInterval = millis() + nextInterval;
|
nextInterval = millis() + nextInterval;
|
||||||
|
sendData = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isDigitSelf(char c) {
|
bool isDigitSelf(char c) {
|
||||||
|
|
@ -188,12 +190,15 @@ void loop() {
|
||||||
}
|
}
|
||||||
if (label == "HCHC" && isNumberSelf(value)) {
|
if (label == "HCHC" && isNumberSelf(value)) {
|
||||||
HCHC = value;
|
HCHC = value;
|
||||||
|
sendData = true;
|
||||||
}
|
}
|
||||||
if (label == "HCHP" && isNumberSelf(value)) {
|
if (label == "HCHP" && isNumberSelf(value)) {
|
||||||
HCHP = value;
|
HCHP = value;
|
||||||
|
sendData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (millis() >= nextInterval) {
|
// if (millis() >= nextInterval) {
|
||||||
|
if (sendData && millis() >= nextInterval) {
|
||||||
sendDataToServer();
|
sendDataToServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
xmpp/xmpp.go
20
xmpp/xmpp.go
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/logs"
|
"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"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/relay"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
@ -79,7 +79,7 @@ func mainXMPP() {
|
||||||
case *xmpp.Iq:
|
case *xmpp.Iq:
|
||||||
// TODO check if the caller has privilege to ask
|
// TODO check if the caller has privilege to ask
|
||||||
switch v.PayloadName().Space {
|
switch v.PayloadName().Space {
|
||||||
case xmpp.NsDiscoItems:
|
case xmpp.NSDiscoItems:
|
||||||
execDiscoCommand(v)
|
execDiscoCommand(v)
|
||||||
|
|
||||||
case xmpp.NodeAdHocCommand:
|
case xmpp.NodeAdHocCommand:
|
||||||
|
|
@ -104,7 +104,7 @@ func SendPresence(status, tpye, message string) {
|
||||||
|
|
||||||
func execDiscoCommand(iq *xmpp.Iq) {
|
func execDiscoCommand(iq *xmpp.Iq) {
|
||||||
log.Info("Discovery item iq received")
|
log.Info("Discovery item iq received")
|
||||||
reply := iq.Response(xmpp.IqTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
discoItem := &xmpp.DiscoItems{Node: xmpp.NodeAdHocCommand}
|
discoItem := &xmpp.DiscoItems{Node: xmpp.NodeAdHocCommand}
|
||||||
|
|
||||||
relays := relay.GetAllRelay()
|
relays := relay.GetAllRelay()
|
||||||
|
|
@ -133,11 +133,11 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
||||||
if descriptionRelais == "" {
|
if descriptionRelais == "" {
|
||||||
descriptionRelais = relais.Mac
|
descriptionRelais = relais.Mac
|
||||||
}
|
}
|
||||||
if adHoc.SessionId == "" && adHoc.Action == xmpp.ActionAdHocExecute {
|
if adHoc.SessionID == "" && adHoc.Action == xmpp.ActionAdHocExecute {
|
||||||
// First step in the command
|
// First step in the command
|
||||||
if relais.Id != 0 {
|
if relais.Id != 0 {
|
||||||
reply := iq.Response(xmpp.IqTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionId: xmpp.SessionId()/*+";"+relais.Mac*/}
|
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocExecute, SessionID: xmpp.SessionID()/*+";"+relais.Mac*/}
|
||||||
|
|
||||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Commande relais "+descriptionRelais}
|
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocForm, Title: "Commande relais "+descriptionRelais}
|
||||||
field := &xmpp.AdHocField{Var: "command", Label: "Commande a executer", Type: "list-single"}
|
field := &xmpp.AdHocField{Var: "command", Label: "Commande a executer", Type: "list-single"}
|
||||||
|
|
@ -156,8 +156,8 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
||||||
|
|
||||||
err := relais.Toggle()
|
err := relais.Toggle()
|
||||||
|
|
||||||
reply := iq.Response(xmpp.IqTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionId: adHoc.SessionId}
|
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCompleted, SessionID: adHoc.SessionID}
|
||||||
|
|
||||||
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Commande relais "+descriptionRelais}
|
cmdXForm := &xmpp.AdHocXForm{Type: xmpp.TypeAdHocResult, Title: "Commande relais "+descriptionRelais}
|
||||||
cmd.XForm = *cmdXForm
|
cmd.XForm = *cmdXForm
|
||||||
|
|
@ -174,8 +174,8 @@ func execCommandAdHoc(iq *xmpp.Iq) {
|
||||||
client.Out <- reply
|
client.Out <- reply
|
||||||
} else if adHoc.Action == xmpp.ActionAdHocCancel {
|
} else if adHoc.Action == xmpp.ActionAdHocCancel {
|
||||||
// command canceled
|
// command canceled
|
||||||
reply := iq.Response(xmpp.IqTypeResult)
|
reply := iq.Response(xmpp.IQTypeResult)
|
||||||
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCanceled, SessionId: adHoc.SessionId}
|
cmd := &xmpp.AdHocCommand{Node: adHoc.Node, Status: xmpp.StatusAdHocCanceled, SessionID: adHoc.SessionID}
|
||||||
reply.PayloadEncode(cmd)
|
reply.PayloadEncode(cmd)
|
||||||
client.Out <- reply
|
client.Out <- reply
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue