Compare commits
2 Commits
ea30512e65
...
26baa07126
| Author | SHA1 | Date |
|---|---|---|
|
|
26baa07126 | |
|
|
a601d25b35 |
|
|
@ -44,7 +44,7 @@ func (c *MainController) Prepare() {
|
||||||
|
|
||||||
func (c *MainController) Get() {
|
func (c *MainController) Get() {
|
||||||
c.Data["sensors"] = getLastTemps()
|
c.Data["sensors"] = getLastTemps()
|
||||||
c.TplNames = "index.tpl"
|
c.TplName = "index.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLastTemps() []SensorPrint {
|
func getLastTemps() []SensorPrint {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func (c *LoginController) Get() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.TplNames = "login.tpl"
|
c.TplName = "login.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LoginController) Post() {
|
func (c *LoginController) Post() {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func (c *ViewRelayController) Get() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.TplNames = "relay.tpl"
|
c.TplName = "relay.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ViewRelayController) Post() {
|
func (c *ViewRelayController) Post() {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ func (c *SensorsController) Get() {
|
||||||
c.Data["sensors"] = sensors
|
c.Data["sensors"] = sensors
|
||||||
c.Data["relays"] = relays
|
c.Data["relays"] = relays
|
||||||
c.Data["compteurs"] = compteurs
|
c.Data["compteurs"] = compteurs
|
||||||
c.TplNames = "sensors.tpl"
|
c.TplName = "sensors.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SensorsController) Post() {
|
func (c *SensorsController) Post() {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ func (c *ViewTeleinfoController) Get() {
|
||||||
c.Data["dataPower"] = template.JS(dataPower)
|
c.Data["dataPower"] = template.JS(dataPower)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.TplNames = "teleinfo.tpl"
|
c.TplName = "teleinfo.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func (c *UserController) Prepare() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *UserController) Get() {
|
func (c *UserController) Get() {
|
||||||
c.TplNames = "user.tpl"
|
c.TplName = "user.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *UserController) Post() {
|
func (c *UserController) Post() {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ type WebSocketController struct {
|
||||||
func (c *WebSocketController) Prepare() {
|
func (c *WebSocketController) Prepare() {
|
||||||
sess := c.GetSession(variables.SessionName)
|
sess := c.GetSession(variables.SessionName)
|
||||||
if sess == nil {
|
if sess == nil {
|
||||||
c.Redirect(variables.LoginRouteNoRegex+variables.UserRoute, 302)
|
c.Redirect(variables.LoginRouteNoRegex+variables.ViewLogRoute, 302)
|
||||||
} else {
|
} else {
|
||||||
c.Data["IsAuthentificated"] = true
|
c.Data["IsAuthentificated"] = true
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ func (c *WebSocketController) Prepare() {
|
||||||
// Get method handles GET requests for WebSocketController.
|
// Get method handles GET requests for WebSocketController.
|
||||||
func (c *WebSocketController) Get() {
|
func (c *WebSocketController) Get() {
|
||||||
c.Data["hostWS"] = "ws://"+c.Ctx.Request.Host+variables.WebSocketLogRoute
|
c.Data["hostWS"] = "ws://"+c.Ctx.Request.Host+variables.WebSocketLogRoute
|
||||||
c.TplNames = "watchlog.tpl"
|
c.TplName = "watchlog.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (c *ViewTempController) Get() {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["dataTemp"] = template.JS(dataTemp)
|
c.Data["dataTemp"] = template.JS(dataTemp)
|
||||||
c.TplNames = "temp.tpl"
|
c.TplName = "temp.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
32
main.go
32
main.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
_ "git.kingpenguin.tk/chteufleur/datahouse.git/routers"
|
_ "git.kingpenguin.tk/chteufleur/datahouse.git/routers"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/xmpp"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/xmpp"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/watchlog"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/watchlog"
|
||||||
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
|
|
@ -14,6 +15,8 @@ import (
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -26,12 +29,12 @@ func init() {
|
||||||
db := ""
|
db := ""
|
||||||
if database.DatabaseInstance == database.MySQL {
|
if database.DatabaseInstance == database.MySQL {
|
||||||
// MySQL
|
// MySQL
|
||||||
orm.RegisterDriver(database.MySQL, orm.DR_MySQL)
|
orm.RegisterDriver(database.MySQL, orm.DRMySQL)
|
||||||
url = database.UserDB + ":" + database.PwdDB + "@/" + database.DataBase + "?charset=utf8"
|
url = database.UserDB + ":" + database.PwdDB + "@/" + database.DataBase + "?charset=utf8"
|
||||||
db = "mysql"
|
db = "mysql"
|
||||||
} else {
|
} else {
|
||||||
// SQLite
|
// SQLite
|
||||||
orm.RegisterDriver(database.SQLITE, orm.DR_Sqlite)
|
orm.RegisterDriver(database.SQLITE, orm.DRSqlite)
|
||||||
url = "datahouse.db"
|
url = "datahouse.db"
|
||||||
db = "sqlite3"
|
db = "sqlite3"
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +57,32 @@ func main() {
|
||||||
if !user.IsUserExist("admin") {
|
if !user.IsUserExist("admin") {
|
||||||
user.AddUser("admin", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
|
user.AddUser("admin", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
go xmpp_manager.Run()
|
go xmpp_manager.Run()
|
||||||
go watchlog.Run()
|
go watchlog.Run()
|
||||||
|
*/
|
||||||
|
go reborn()
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
models.ChanRuns <- xmpp_manager.EndRun
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
models.ChanRuns <- watchlog.EndRun
|
||||||
|
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reborn() {
|
||||||
|
for {
|
||||||
|
action := <- models.ChanRuns
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case xmpp_manager.EndRun:
|
||||||
|
go xmpp_manager.Run()
|
||||||
|
log.Info("XMPP Started")
|
||||||
|
|
||||||
|
case watchlog.EndRun:
|
||||||
|
go watchlog.Run()
|
||||||
|
log.Info("Watchlog Started")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,15 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/hpcloud/tail"
|
"github.com/hpcloud/tail"
|
||||||
|
|
||||||
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models"
|
||||||
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
||||||
|
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
EndRun = "EndRunWatchlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -19,6 +25,8 @@ func Run() {
|
||||||
for line := range t.Lines {
|
for line := range t.Lines {
|
||||||
broadcastWebSocket(line.Text)
|
broadcastWebSocket(line.Text)
|
||||||
}
|
}
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
|
models.ChanRuns <- EndRun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
22
xmpp/xmpp.go
22
xmpp/xmpp.go
|
|
@ -6,10 +6,9 @@ import (
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
|
|
||||||
"git.kingpenguin.tk/chteufleur/go-xmpp.git"
|
"git.kingpenguin.tk/chteufleur/go-xmpp.git"
|
||||||
|
"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"
|
||||||
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -29,6 +28,8 @@ const (
|
||||||
Type_unsubscribed = "unsubscribed"
|
Type_unsubscribed = "unsubscribed"
|
||||||
Type_probe = "probe"
|
Type_probe = "probe"
|
||||||
Type_error = "error"
|
Type_error = "error"
|
||||||
|
|
||||||
|
EndRun = "EndRunXMPP"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -42,7 +43,7 @@ var (
|
||||||
stream = new(xmpp.Stream)
|
stream = new(xmpp.Stream)
|
||||||
client = new(xmpp.XMPP)
|
client = new(xmpp.XMPP)
|
||||||
|
|
||||||
Debug = false
|
Debug = true
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -59,14 +60,14 @@ func must(v interface{}, err error) interface{} {
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
// Create stream and configure it as a component connection.
|
// Create stream and configure it as a component connection.
|
||||||
|
log.Info("XMPP Run()")
|
||||||
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
jid = must(xmpp.ParseJID(JidStr)).(xmpp.JID)
|
||||||
stream = must(xmpp.NewStream(jid.Domain+":"+serverPort, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
stream = must(xmpp.NewStream(jid.Domain+":"+serverPort, &xmpp.StreamConfig{LogStanzas: Debug})).(*xmpp.Stream)
|
||||||
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
client = must(xmpp.NewClientXMPP(stream, jid, passwdStr, &xmpp.ClientConfig{InsecureSkipVerify: true})).(*xmpp.XMPP)
|
||||||
|
|
||||||
mainXMPP()
|
mainXMPP()
|
||||||
|
log.Debug("xmpp.Run Ended")
|
||||||
time.Sleep(5 * time.Second)
|
models.ChanRuns <- EndRun
|
||||||
Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -75,11 +76,6 @@ func mainXMPP() {
|
||||||
|
|
||||||
for x := range client.In {
|
for x := range client.In {
|
||||||
switch v := x.(type) {
|
switch v := x.(type) {
|
||||||
case *xmpp.Presence:
|
|
||||||
|
|
||||||
case *xmpp.Message:
|
|
||||||
log.Info("Message received : %s", v.Body)
|
|
||||||
|
|
||||||
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 {
|
||||||
|
|
@ -94,6 +90,10 @@ func mainXMPP() {
|
||||||
log.Info("recv: %v", x)
|
log.Info("recv: %v", x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send deconnexion
|
||||||
|
SendPresence(Status_offline, Type_unavailable, "")
|
||||||
|
log.Debug("mainXMPP Ended")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue