Compare commits
No commits in common. "26baa07126699fd4637e02a43ac620258d8dbd5d" and "ea30512e65d3da7d92080c2774359860b870d6c2" have entirely different histories.
26baa07126
...
ea30512e65
|
|
@ -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.TplName = "index.tpl"
|
c.TplNames = "index.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLastTemps() []SensorPrint {
|
func getLastTemps() []SensorPrint {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func (c *LoginController) Get() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.TplName = "login.tpl"
|
c.TplNames = "login.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LoginController) Post() {
|
func (c *LoginController) Post() {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func (c *ViewRelayController) Get() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.TplName = "relay.tpl"
|
c.TplNames = "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.TplName = "sensors.tpl"
|
c.TplNames = "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.TplName = "teleinfo.tpl"
|
c.TplNames = "teleinfo.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func (c *UserController) Prepare() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *UserController) Get() {
|
func (c *UserController) Get() {
|
||||||
c.TplName = "user.tpl"
|
c.TplNames = "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.ViewLogRoute, 302)
|
c.Redirect(variables.LoginRouteNoRegex+variables.UserRoute, 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.TplName = "watchlog.tpl"
|
c.TplNames = "watchlog.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (c *ViewTempController) Get() {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["dataTemp"] = template.JS(dataTemp)
|
c.Data["dataTemp"] = template.JS(dataTemp)
|
||||||
c.TplName = "temp.tpl"
|
c.TplNames = "temp.tpl"
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
32
main.go
32
main.go
|
|
@ -7,7 +7,6 @@ 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"
|
||||||
|
|
@ -15,8 +14,6 @@ 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 (
|
||||||
|
|
@ -29,12 +26,12 @@ func init() {
|
||||||
db := ""
|
db := ""
|
||||||
if database.DatabaseInstance == database.MySQL {
|
if database.DatabaseInstance == database.MySQL {
|
||||||
// MySQL
|
// MySQL
|
||||||
orm.RegisterDriver(database.MySQL, orm.DRMySQL)
|
orm.RegisterDriver(database.MySQL, orm.DR_MySQL)
|
||||||
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.DRSqlite)
|
orm.RegisterDriver(database.SQLITE, orm.DR_Sqlite)
|
||||||
url = "datahouse.db"
|
url = "datahouse.db"
|
||||||
db = "sqlite3"
|
db = "sqlite3"
|
||||||
}
|
}
|
||||||
|
|
@ -57,32 +54,7 @@ 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,15 +4,9 @@ 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 (
|
||||||
|
|
@ -25,8 +19,6 @@ 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,9 +6,10 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,8 +29,6 @@ const (
|
||||||
Type_unsubscribed = "unsubscribed"
|
Type_unsubscribed = "unsubscribed"
|
||||||
Type_probe = "probe"
|
Type_probe = "probe"
|
||||||
Type_error = "error"
|
Type_error = "error"
|
||||||
|
|
||||||
EndRun = "EndRunXMPP"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -43,7 +42,7 @@ var (
|
||||||
stream = new(xmpp.Stream)
|
stream = new(xmpp.Stream)
|
||||||
client = new(xmpp.XMPP)
|
client = new(xmpp.XMPP)
|
||||||
|
|
||||||
Debug = true
|
Debug = false
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -60,14 +59,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")
|
|
||||||
models.ChanRuns <- EndRun
|
time.Sleep(5 * time.Second)
|
||||||
|
Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -76,6 +75,11 @@ 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 {
|
||||||
|
|
@ -90,10 +94,6 @@ 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