Add HTTP port to config file
This commit is contained in:
parent
b9f3db7998
commit
df795bf0ce
|
|
@ -22,7 +22,7 @@ const (
|
||||||
TRANSACTION_ID = "transaction_id"
|
TRANSACTION_ID = "transaction_id"
|
||||||
|
|
||||||
ROUTE_ROOT = "/"
|
ROUTE_ROOT = "/"
|
||||||
ROUTE_AUTH = "/toto"
|
ROUTE_AUTH = "/auth"
|
||||||
|
|
||||||
RETURN_VALUE_OK = "OK"
|
RETURN_VALUE_OK = "OK"
|
||||||
RETURN_VALUE_NOK = "NOK"
|
RETURN_VALUE_NOK = "NOK"
|
||||||
|
|
@ -35,7 +35,6 @@ var (
|
||||||
TimeoutSec = 60
|
TimeoutSec = 60
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO
|
// TODO
|
||||||
fmt.Fprintf(w, "Welcome to HTTP authentification over XMPP")
|
fmt.Fprintf(w, "Welcome to HTTP authentification over XMPP")
|
||||||
|
|
@ -58,16 +57,14 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ChanRequest <- chanAnswer
|
ChanRequest <- chanAnswer
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case answer = <- chanAnswer:
|
case answer = <-chanAnswer:
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
case <- time.After(time.Duration(TimeoutSec) * time.Second):
|
case <-time.After(time.Duration(TimeoutSec) * time.Second):
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
delete(xmpp.WaitMessageAnswers, transaction)
|
delete(xmpp.WaitMessageAnswers, transaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
log.Printf("%sRunning", LogInfo)
|
log.Printf("%sRunning", LogInfo)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,5 @@ xmpp_server_port=5347
|
||||||
xmpp_hostname=xmppsteam.kingpenguin.tk
|
xmpp_hostname=xmppsteam.kingpenguin.tk
|
||||||
xmpp_secret=xmpp4steam_password
|
xmpp_secret=xmpp4steam_password
|
||||||
xmpp_debug=true
|
xmpp_debug=true
|
||||||
|
|
||||||
|
http_port=9090
|
||||||
|
|
|
||||||
10
main.go
10
main.go
|
|
@ -35,6 +35,11 @@ func init() {
|
||||||
log.Println("Define HTTP timeout to %d second", httpTimeout)
|
log.Println("Define HTTP timeout to %d second", httpTimeout)
|
||||||
http.TimeoutSec = httpTimeout
|
http.TimeoutSec = httpTimeout
|
||||||
}
|
}
|
||||||
|
httpPort, err := strconv.Atoi(mapConfig["http_port"])
|
||||||
|
if err == nil {
|
||||||
|
log.Println("Define HTTP port to %d", httpPort)
|
||||||
|
http.HttpPortBind = httpPort
|
||||||
|
}
|
||||||
|
|
||||||
// XMPP config
|
// XMPP config
|
||||||
xmpp.Addr = mapConfig["xmpp_server_address"] + ":" + mapConfig["xmpp_server_port"]
|
xmpp.Addr = mapConfig["xmpp_server_address"] + ":" + mapConfig["xmpp_server_port"]
|
||||||
|
|
@ -43,7 +48,6 @@ func init() {
|
||||||
xmpp.Debug = mapConfig["xmpp_debug"] == "true"
|
xmpp.Debug = mapConfig["xmpp_debug"] == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func request() {
|
func request() {
|
||||||
for {
|
for {
|
||||||
client := new(xmpp.Client)
|
client := new(xmpp.Client)
|
||||||
|
|
@ -53,7 +57,7 @@ func request() {
|
||||||
client.Domain = getChanString(http.ChanRequest)
|
client.Domain = getChanString(http.ChanRequest)
|
||||||
client.Transaction = getChanString(http.ChanRequest)
|
client.Transaction = getChanString(http.ChanRequest)
|
||||||
|
|
||||||
chanResult := <- http.ChanRequest
|
chanResult := <-http.ChanRequest
|
||||||
if v, ok := chanResult.(chan bool); ok {
|
if v, ok := chanResult.(chan bool); ok {
|
||||||
client.ChanReply = v
|
client.ChanReply = v
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +68,7 @@ func request() {
|
||||||
|
|
||||||
func getChanString(c chan interface{}) string {
|
func getChanString(c chan interface{}) string {
|
||||||
ret := ""
|
ret := ""
|
||||||
i := <- c
|
i := <-c
|
||||||
if v, ok := i.(string); ok {
|
if v, ok := i.(string); ok {
|
||||||
ret = v
|
ret = v
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ type Client struct {
|
||||||
ChanReply chan bool
|
ChanReply chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (client *Client) QueryClient() {
|
func (client *Client) QueryClient() {
|
||||||
log.Printf("%sQuery JID %s", LogInfo, client.JID)
|
log.Printf("%sQuery JID %s", LogInfo, client.JID)
|
||||||
clientJID, _ := xmpp.ParseJID(client.JID)
|
clientJID, _ := xmpp.ParseJID(client.JID)
|
||||||
|
|
@ -41,7 +40,7 @@ func (client *Client) askViaMessage() {
|
||||||
m := xmpp.Message{From: jid.Domain, To: client.JID, Type: "normal"}
|
m := xmpp.Message{From: jid.Domain, To: client.JID, Type: "normal"}
|
||||||
|
|
||||||
m.Thread = xmpp.SessionID()
|
m.Thread = xmpp.SessionID()
|
||||||
m.Body = "Auth request for "+client.Domain+".\nTransaction identifier is: "+client.Transaction+"\nReply to this message to confirm the request."
|
m.Body = "Auth request for " + client.Domain + ".\nTransaction identifier is: " + client.Transaction + "\nReply to this message to confirm the request."
|
||||||
m.Confir = &xmpp.Confirm{Id: client.Transaction, Method: client.Method, URL: client.Domain}
|
m.Confir = &xmpp.Confirm{Id: client.Transaction, Method: client.Method, URL: client.Domain}
|
||||||
|
|
||||||
log.Printf("%sSenp message %v", LogInfo, m)
|
log.Printf("%sSenp message %v", LogInfo, m)
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,6 @@ var (
|
||||||
Debug = true
|
Debug = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
log.Printf("%sRunning", LogInfo)
|
log.Printf("%sRunning", LogInfo)
|
||||||
// Create stream and configure it as a component connection.
|
// Create stream and configure it as a component connection.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue