選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

gateways.go 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (c) 2012-2014 Jeremy Latt
  2. // Copyright (c) 2014-2015 Edmund Huber
  3. // Copyright (c) 2017 Daniel Oaks <daniel@danieloaks.net>
  4. // released under the MIT license
  5. package irc
  6. import (
  7. "errors"
  8. "fmt"
  9. "net"
  10. "github.com/oragono/oragono/irc/modes"
  11. "github.com/oragono/oragono/irc/passwd"
  12. "github.com/oragono/oragono/irc/utils"
  13. )
  14. type webircConfig struct {
  15. PasswordString string `yaml:"password"`
  16. Password []byte `yaml:"password-bytes"`
  17. Fingerprint string
  18. Hosts []string
  19. }
  20. // Populate fills out our password or fingerprint.
  21. func (wc *webircConfig) Populate() (err error) {
  22. if wc.Fingerprint == "" && wc.PasswordString == "" {
  23. return errors.New("Fingerprint or password needs to be specified")
  24. }
  25. if wc.PasswordString != "" {
  26. var password []byte
  27. password, err = passwd.DecodePasswordHash(wc.PasswordString)
  28. wc.Password = password
  29. }
  30. return err
  31. }
  32. func isGatewayAllowed(addr net.Addr, gatewaySpec string) bool {
  33. // "localhost" includes any loopback IP or unix domain socket
  34. if gatewaySpec == "localhost" {
  35. return utils.AddrIsLocal(addr)
  36. }
  37. ip := utils.AddrToIP(addr)
  38. if ip == nil {
  39. return false
  40. }
  41. // exact IP match
  42. if ip.String() == gatewaySpec {
  43. return true
  44. }
  45. // CIDR match
  46. _, gatewayNet, err := net.ParseCIDR(gatewaySpec)
  47. if err != nil {
  48. return false
  49. }
  50. return gatewayNet.Contains(ip)
  51. }
  52. // ApplyProxiedIP applies the given IP to the client.
  53. func (client *Client) ApplyProxiedIP(proxiedIP string, tls bool) (exiting bool) {
  54. // ensure IP is sane
  55. parsedProxiedIP := net.ParseIP(proxiedIP)
  56. if parsedProxiedIP == nil {
  57. client.Quit(fmt.Sprintf(client.t("Proxied IP address is not valid: [%s]"), proxiedIP))
  58. return true
  59. }
  60. isBanned, banMsg := client.server.checkBans(parsedProxiedIP)
  61. if isBanned {
  62. client.Quit(banMsg)
  63. return true
  64. }
  65. // given IP is sane! override the client's current IP
  66. client.proxiedIP = parsedProxiedIP
  67. client.rawHostname = utils.LookupHostname(proxiedIP)
  68. client.hostname = client.rawHostname
  69. // set tls info
  70. client.certfp = ""
  71. if tls {
  72. client.flags[modes.TLS] = true
  73. } else {
  74. delete(client.flags, modes.TLS)
  75. }
  76. return false
  77. }