Procházet zdrojové kódy

Merge pull request #185 from slingamn/proxypatch.1

tweaks to webirc functionality
tags/v0.11.0-beta
Daniel Oaks před 6 roky
rodič
revize
10b4ec243b
Žádný účet není propojen s e-mailovou adresou tvůrce revize
2 změnil soubory, kde provedl 19 přidání a 5 odebrání
  1. 8
    5
      irc/gateways.go
  2. 11
    0
      irc/utils/net.go

+ 8
- 5
irc/gateways.go Zobrazit soubor

@@ -41,7 +41,7 @@ func (wc *webircConfig) Populate() (err error) {
41 41
 // WEBIRC <password> <gateway> <hostname> <ip> [:flag1 flag2=x flag3]
42 42
 func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
43 43
 	// only allow unregistered clients to use this command
44
-	if client.registered {
44
+	if client.registered || client.proxiedIP != "" {
45 45
 		return false
46 46
 	}
47 47
 
@@ -58,9 +58,12 @@ func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
58 58
 				key = x
59 59
 			}
60 60
 
61
-			// only accept "tls" flag if the gateway's connection to us is secure as well
62
-			if strings.ToLower(key) == "tls" && client.flags[TLS] {
63
-				secure = true
61
+			lkey := strings.ToLower(key)
62
+			if lkey == "tls" || lkey == "secure" {
63
+				// only accept "tls" flag if the gateway's connection to us is secure as well
64
+				if client.flags[TLS] || utils.AddrIsLocal(client.socket.conn.RemoteAddr()) {
65
+					secure = true
66
+				}
64 67
 			}
65 68
 		}
66 69
 	}
@@ -93,7 +96,7 @@ func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
93 96
 // http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
94 97
 func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
95 98
 	// only allow unregistered clients to use this command
96
-	if client.registered {
99
+	if client.registered || client.proxiedIP != "" {
97 100
 		return false
98 101
 	}
99 102
 

+ 11
- 0
irc/utils/net.go Zobrazit soubor

@@ -25,6 +25,17 @@ func AddrLookupHostname(addr net.Addr) string {
25 25
 	return LookupHostname(IPString(addr))
26 26
 }
27 27
 
28
+// AddrIsLocal returns whether the address is from a trusted local connection (loopback or unix).
29
+func AddrIsLocal(addr net.Addr) bool {
30
+	if tcpaddr, ok := addr.(*net.TCPAddr); ok {
31
+		return tcpaddr.IP.IsLoopback()
32
+	}
33
+	if _, ok := addr.(*net.UnixAddr); ok {
34
+		return true
35
+	}
36
+	return false
37
+}
38
+
28 39
 // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
29 40
 func LookupHostname(addr string) string {
30 41
 	names, err := net.LookupAddr(addr)

Načítá se…
Zrušit
Uložit