Add HTTP port to config file

This commit is contained in:
Chteufleur 2016-06-20 19:20:13 +02:00
parent b9f3db7998
commit df795bf0ce
5 changed files with 132 additions and 132 deletions

View File

@ -22,7 +22,7 @@ const (
TRANSACTION_ID = "transaction_id"
ROUTE_ROOT = "/"
ROUTE_AUTH = "/toto"
ROUTE_AUTH = "/auth"
RETURN_VALUE_OK = "OK"
RETURN_VALUE_NOK = "NOK"
@ -35,7 +35,6 @@ var (
TimeoutSec = 60
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
// TODO
fmt.Fprintf(w, "Welcome to HTTP authentification over XMPP")
@ -58,16 +57,14 @@ func authHandler(w http.ResponseWriter, r *http.Request) {
ChanRequest <- chanAnswer
select {
case answer = <- chanAnswer:
case answer = <-chanAnswer:
w.WriteHeader(http.StatusOK)
case <- time.After(time.Duration(TimeoutSec) * time.Second):
case <-time.After(time.Duration(TimeoutSec) * time.Second):
w.WriteHeader(http.StatusForbidden)
delete(xmpp.WaitMessageAnswers, transaction)
}
}
func Run() {
log.Printf("%sRunning", LogInfo)

View File

@ -4,3 +4,5 @@ xmpp_server_port=5347
xmpp_hostname=xmppsteam.kingpenguin.tk
xmpp_secret=xmpp4steam_password
xmpp_debug=true
http_port=9090

10
main.go
View File

@ -35,6 +35,11 @@ func init() {
log.Println("Define HTTP timeout to %d second", 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.Addr = mapConfig["xmpp_server_address"] + ":" + mapConfig["xmpp_server_port"]
@ -43,7 +48,6 @@ func init() {
xmpp.Debug = mapConfig["xmpp_debug"] == "true"
}
func request() {
for {
client := new(xmpp.Client)
@ -53,7 +57,7 @@ func request() {
client.Domain = getChanString(http.ChanRequest)
client.Transaction = getChanString(http.ChanRequest)
chanResult := <- http.ChanRequest
chanResult := <-http.ChanRequest
if v, ok := chanResult.(chan bool); ok {
client.ChanReply = v
}
@ -64,7 +68,7 @@ func request() {
func getChanString(c chan interface{}) string {
ret := ""
i := <- c
i := <-c
if v, ok := i.(string); ok {
ret = v
}

View File

@ -16,7 +16,6 @@ type Client struct {
ChanReply chan bool
}
func (client *Client) QueryClient() {
log.Printf("%sQuery JID %s", LogInfo, 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.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}
log.Printf("%sSenp message %v", LogInfo, m)

View File

@ -32,8 +32,6 @@ var (
Debug = true
)
func Run() {
log.Printf("%sRunning", LogInfo)
// Create stream and configure it as a component connection.