diff --git a/README.md b/README.md index 73f87f6..ead41a5 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Provide an HTTP anthentification over XMPP. Implementation of [XEP-0070](https://xmpp.org/extensions/xep-0070.html). +Can be run as a XMPP client or XMPP component. + ## Compilation ### Dependencies @@ -16,14 +18,14 @@ go get git.kingpenguin.tk/chteufleur/HTTPAuthentificationOverXMPP.git ``` ### Configure -Configure the gateway by editing the ``httpAuth.cfg`` file in order to give all XMPP component and HTTP server informations. +Configure the gateway by editing the ``httpAuth.cfg`` file in order to give all XMPP and HTTP server informations. An example of the config file can be found in [the repos](https://git.kingpenguin.tk/chteufleur/HTTPAuthentificationOverXMPP/src/master/httpAuth.cfg). XMPP * xmpp_server_address : Component server address connection (default: 127.0.0.1) * xmpp_server_port : Component server port connection (default: 5347) - * xmpp_hostname : Component hostname - * xmpp_secret : Component password + * __xmpp_jid__ : Account JID + * __xmpp_secret__ : Account password * xmpp_debug : Enable debug log at true (default: false) HTTP @@ -33,6 +35,7 @@ HTTP * https_key_path : Path to the key file (default: ./key.pem) * http_timeoute_sec : Define a timeout if user did not give an answer to the request (default: 60) +__Bold config__ are mandatory. ### Usage To ask authorization, just send an HTTP request to the path ``/auth`` with parameters: diff --git a/httpAuth.cfg b/httpAuth.cfg index 54fb7c8..c5d81b4 100644 --- a/httpAuth.cfg +++ b/httpAuth.cfg @@ -1,15 +1,10 @@ # XMPP informations (component) xmpp_server_address=192.168.1.2 xmpp_server_port=5347 -xmpp_hostname=xmppsteam.kingpenguin.tk +xmpp_jid=xmppsteam.kingpenguin.tk xmpp_secret=xmpp4steam_password xmpp_debug=true -# XMPP informations (client) -#xmpp_hostname=toto@jabber.fr -#xmpp_secret=totoPwd -#xmpp_debug=true - # HTTP informations http_port=9090 https_port=9093 diff --git a/main.go b/main.go index 03d77c1..8938697 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( ) const ( - Version = "v0.3.1" + Version = "v0.4" configurationFilePath = "httpAuth.cfg" ) @@ -60,20 +60,11 @@ func init() { xmpp.Port = xmpp_server_port } - xmpp.JidStr = mapConfig["xmpp_hostname"] + xmpp.JidStr = mapConfig["xmpp_jid"] xmpp.Secret = mapConfig["xmpp_secret"] xmpp.Debug = mapConfig["xmpp_debug"] == "true" } -func getChanString(c chan interface{}) string { - ret := "" - i := <-c - if v, ok := i.(string); ok { - ret = v - } - return ret -} - func main() { go http.Run() diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go index e280e68..c9bda83 100644 --- a/xmpp/xmpp.go +++ b/xmpp/xmpp.go @@ -11,11 +11,14 @@ const ( LogInfo = "\t[XMPP INFO]\t" LogError = "\t[XMPP ERROR]\t" LogDebug = "\t[XMPP DEBUG]\t" + + DEFAULT_SERVER_ADDRESS = "127.0.0.1" + DEFAULT_SERVER_PORT = "5347" ) var ( - Addr = "127.0.0.1" - Port = "5347" + Addr = "" + Port = "" JidStr = "" Secret = "" @@ -46,11 +49,24 @@ func Run() { if isComponent { // component + if Addr == "" { + Addr = DEFAULT_SERVER_ADDRESS + } + if Port == "" { + Port = DEFAULT_SERVER_PORT + } addr = Addr + ":" + Port } else { // client - addrs := must(xmpp.HomeServerAddrs(jid)).([]string) - addr = addrs[0] + if Addr == "" { + addrs := must(xmpp.HomeServerAddrs(jid)).([]string) + addr = addrs[0] + } else { + if Port == "" { + Port = DEFAULT_SERVER_PORT + } + addr = Addr + ":" + Port + } } log.Printf("%sConnecting to %s", LogInfo, addr)