summaryrefslogtreecommitdiff
path: root/pkg/auth/sip2
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/auth/sip2')
-rw-r--r--pkg/auth/sip2/auth.go17
-rw-r--r--pkg/auth/sip2/spec.go2
-rw-r--r--pkg/auth/sip2/telnet.go10
3 files changed, 21 insertions, 8 deletions
diff --git a/pkg/auth/sip2/auth.go b/pkg/auth/sip2/auth.go
index f5ad0a4..58441e4 100644
--- a/pkg/auth/sip2/auth.go
+++ b/pkg/auth/sip2/auth.go
@@ -16,6 +16,9 @@ const SipPassVar string = "VPNWEB_SIP_PASS"
const SipPortVar string = "VPNWEB_SIP_PORT"
const SipHostVar string = "VPNWEB_SIP_HOST"
const SipLibrLocVar string = "VPNWEB_SIP_LIBR_LOCATION"
+const SipTerminatorVar string = "VPNWEB_SIP_TERMINATOR"
+
+const SipDefaultTerminator string = "\r\n"
type Credentials struct {
User string
@@ -30,10 +33,18 @@ func getConfigFromEnv(envVar string) string {
return val
}
+func setupTerminatorFromEnv() {
+ config.FallbackToEnv(&TelnetTerminator, SipTerminatorVar, SipDefaultTerminator)
+ if TelnetTerminator == "\\r" {
+ TelnetTerminator = "\r"
+ } else if TelnetTerminator == "\\r\\n" {
+ TelnetTerminator = "\r\n"
+ }
+}
+
func SipAuthenticator(opts *config.Opts) http.HandlerFunc {
- /* TODO -- catch connection errors */
- log.Println("Initializing sip2 authenticator")
+ log.Println("Initializing SIP2 authenticator")
SipUser := getConfigFromEnv(SipUserVar)
SipPass := getConfigFromEnv(SipPassVar)
@@ -41,6 +52,8 @@ func SipAuthenticator(opts *config.Opts) http.HandlerFunc {
SipPort := getConfigFromEnv(SipPortVar)
SipLibrLoc := getConfigFromEnv(SipLibrLocVar)
+ setupTerminatorFromEnv()
+
sip := NewClient(SipHost, SipPort, SipLibrLoc)
ok, err := sip.Connect()
diff --git a/pkg/auth/sip2/spec.go b/pkg/auth/sip2/spec.go
index 60a14d9..ba7c356 100644
--- a/pkg/auth/sip2/spec.go
+++ b/pkg/auth/sip2/spec.go
@@ -111,7 +111,7 @@ func getParser() *Parser {
}
parser.parseMessage = func(msg string) *Message {
- txt := msg[:len(msg)-len(terminator)]
+ txt := msg[:len(msg)-len(TelnetTerminator)]
code, err := strconv.Atoi(txt[:2])
if nil != err {
log.Printf("Error parsing integer: %s\n", txt[:2])
diff --git a/pkg/auth/sip2/telnet.go b/pkg/auth/sip2/telnet.go
index b5abd5f..faa72ff 100644
--- a/pkg/auth/sip2/telnet.go
+++ b/pkg/auth/sip2/telnet.go
@@ -4,9 +4,10 @@ import (
"github.com/reiver/go-telnet"
)
-// TODO depends on how terminator is configured -- take it from config file
-// const terminator string = "\r\n"
-const terminator string = "\r"
+// The terminator can be configured differently for different SIP endpoints.
+// This gets set in sip2.auth according to an environment variable
+
+var TelnetTerminator string
func telnetRead(conn *telnet.Conn) (out string) {
var buffer [1]byte
@@ -21,7 +22,7 @@ func telnetRead(conn *telnet.Conn) (out string) {
} else {
out += string(recvData)
}
- if len(out) > 1 && out[len(out)-len(terminator):] == terminator {
+ if len(out) > 1 && out[len(out)-len(TelnetTerminator):] == TelnetTerminator {
break
}
}
@@ -35,7 +36,6 @@ func telnetSend(conn *telnet.Conn, command string) {
}
var crlfBuffer [2]byte = [2]byte{'\r', '\n'}
-
crlf := crlfBuffer[:]
conn.Write(commandBuffer)