您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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