Browse Source

Merge pull request #185 from slingamn/proxypatch.1

tweaks to webirc functionality
tags/v0.11.0-beta
Daniel Oaks 6 years ago
parent
commit
10b4ec243b
No account linked to committer's email address
2 changed files with 19 additions and 5 deletions
  1. 8
    5
      irc/gateways.go
  2. 11
    0
      irc/utils/net.go

+ 8
- 5
irc/gateways.go View File

41
 // WEBIRC <password> <gateway> <hostname> <ip> [:flag1 flag2=x flag3]
41
 // WEBIRC <password> <gateway> <hostname> <ip> [:flag1 flag2=x flag3]
42
 func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
42
 func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
43
 	// only allow unregistered clients to use this command
43
 	// only allow unregistered clients to use this command
44
-	if client.registered {
44
+	if client.registered || client.proxiedIP != "" {
45
 		return false
45
 		return false
46
 	}
46
 	}
47
 
47
 
58
 				key = x
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
 // http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
96
 // http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
94
 func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
97
 func proxyHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
95
 	// only allow unregistered clients to use this command
98
 	// only allow unregistered clients to use this command
96
-	if client.registered {
99
+	if client.registered || client.proxiedIP != "" {
97
 		return false
100
 		return false
98
 	}
101
 	}
99
 
102
 

+ 11
- 0
irc/utils/net.go View File

25
 	return LookupHostname(IPString(addr))
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
 // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
39
 // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
29
 func LookupHostname(addr string) string {
40
 func LookupHostname(addr string) string {
30
 	names, err := net.LookupAddr(addr)
41
 	names, err := net.LookupAddr(addr)

Loading…
Cancel
Save