From 32c58c1e1f6c0ef0b06a1a32d2471655c8b14a11 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 17 Jul 2020 04:19:33 -0400 Subject: [PATCH] fix #1190 --- conventional.yaml | 4 -- default.yaml | 4 -- irc/accounts.go | 43 +---------------- irc/config.go | 7 --- irc/errors.go | 1 - irc/hostserv.go | 116 ---------------------------------------------- 6 files changed, 1 insertion(+), 174 deletions(-) diff --git a/conventional.yaml b/conventional.yaml index 5de408a0..87f1d8c1 100644 --- a/conventional.yaml +++ b/conventional.yaml @@ -451,10 +451,6 @@ accounts: # before they can request a new one. cooldown: 168h - # vhosts that users can take without approval, using `/HS TAKE` - offer-list: - #- "oragono.test" - # modes that are set by default when a user connects # if unset, no user modes will be set by default # +i is invisible (a user's channels are hidden from whois replies) diff --git a/default.yaml b/default.yaml index 59721bbe..8125e9a6 100644 --- a/default.yaml +++ b/default.yaml @@ -477,10 +477,6 @@ accounts: # before they can request a new one. cooldown: 168h - # vhosts that users can take without approval, using `/HS TAKE` - offer-list: - #- "oragono.test" - # modes that are set by default when a user connects # if unset, no user modes will be set by default # +i is invisible (a user's channels are hidden from whois replies) diff --git a/irc/accounts.go b/irc/accounts.go index 3603ac87..2946621d 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -1575,7 +1575,6 @@ func (am *AccountManager) ModifyAccountSettings(account string, munger settingsM type VHostInfo struct { ApprovedVHost string Enabled bool - Forbidden bool RequestedVHost string RejectedVHost string RejectionReason string @@ -1629,10 +1628,6 @@ func (am *AccountManager) VHostSet(account string, vhost string) (result VHostIn func (am *AccountManager) VHostRequest(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) { munger := func(input VHostInfo) (output VHostInfo, err error) { output = input - if input.Forbidden { - err = errVhostsForbidden - return - } // you can update your existing request, but if you were approved or rejected, // you can't spam a new request if output.RequestedVHost == "" { @@ -1651,32 +1646,6 @@ func (am *AccountManager) VHostRequest(account string, vhost string, cooldown ti return am.performVHostChange(account, munger) } -func (am *AccountManager) VHostTake(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) { - munger := func(input VHostInfo) (output VHostInfo, err error) { - output = input - if input.Forbidden { - err = errVhostsForbidden - return - } - // if you have a request pending, you can cancel it using take; - // otherwise, you're subject to the same throttling as if you were making a request - if output.RequestedVHost == "" { - err = output.checkThrottle(cooldown) - } - if err != nil { - return - } - output.ApprovedVHost = vhost - output.RequestedVHost = "" - output.RejectedVHost = "" - output.RejectionReason = "" - output.LastRequestTime = time.Now().UTC() - return - } - - return am.performVHostChange(account, munger) -} - func (am *AccountManager) VHostApprove(account string) (result VHostInfo, err error) { munger := func(input VHostInfo) (output VHostInfo, err error) { output = input @@ -1716,16 +1685,6 @@ func (am *AccountManager) VHostSetEnabled(client *Client, enabled bool) (result return am.performVHostChange(client.Account(), munger) } -func (am *AccountManager) VHostForbid(account string, forbid bool) (result VHostInfo, err error) { - munger := func(input VHostInfo) (output VHostInfo, err error) { - output = input - output.Forbidden = forbid - return - } - - return am.performVHostChange(account, munger) -} - func (am *AccountManager) performVHostChange(account string, munger vhostMunger) (result VHostInfo, err error) { account, err = CasefoldName(account) if err != nil || account == "" { @@ -1846,7 +1805,7 @@ func (am *AccountManager) applyVHostInfo(client *Client, info VHostInfo) { } vhost := "" - if info.Enabled && !info.Forbidden { + if info.Enabled { vhost = info.ApprovedVHost } oldNickmask := client.NickMaskString() diff --git a/irc/config.go b/irc/config.go index 1cb6de9f..fffa8543 100644 --- a/irc/config.go +++ b/irc/config.go @@ -315,7 +315,6 @@ type VHostConfig struct { Channel string Cooldown custime.Duration } `yaml:"user-requests"` - OfferList []string `yaml:"offer-list"` } type NickEnforcementMethod int @@ -1086,12 +1085,6 @@ func LoadConfig(filename string) (config *Config, err error) { config.Accounts.VHosts.ValidRegexp = defaultValidVhostRegex } - for _, vhost := range config.Accounts.VHosts.OfferList { - if !config.Accounts.VHosts.ValidRegexp.MatchString(vhost) { - return nil, fmt.Errorf("invalid offered vhost: %s", vhost) - } - } - config.Server.capValues[caps.SASL] = "PLAIN,EXTERNAL" if !config.Accounts.AuthenticationEnabled { config.Server.supportedCaps.Disable(caps.SASL) diff --git a/irc/errors.go b/irc/errors.go index 70c75af1..d9fd66f3 100644 --- a/irc/errors.go +++ b/irc/errors.go @@ -58,7 +58,6 @@ var ( errBanned = errors.New("IP or nickmask banned") errInvalidParams = utils.ErrInvalidParams errNoVhost = errors.New(`You do not have an approved vhost`) - errVhostsForbidden = errors.New(`An administrator has denied you the ability to use vhosts`) errLimitExceeded = errors.New("Limit exceeded") errNoop = errors.New("Action was a no-op") errCASFailed = errors.New("Compare-and-swap update of database value failed") diff --git a/irc/hostserv.go b/irc/hostserv.go index 7c983f12..1dc48459 100644 --- a/irc/hostserv.go +++ b/irc/hostserv.go @@ -129,51 +129,6 @@ for the rejection.`, maxParams: 2, unsplitFinalParam: true, }, - "forbid": { - handler: hsForbidHandler, - help: `Syntax: $bFORBID $b - -FORBID prevents a user from using any vhost, including ones on the offer list.`, - helpShort: `$bFORBID$b prevents a user from using vhosts.`, - capabs: []string{"vhosts"}, - enabled: hostservEnabled, - minParams: 1, - maxParams: 1, - }, - "permit": { - handler: hsForbidHandler, - help: `Syntax: $bPERMIT $b - -PERMIT undoes FORBID, allowing the user to TAKE vhosts again.`, - helpShort: `$bPERMIT$b allows a user to use vhosts again.`, - capabs: []string{"vhosts"}, - enabled: hostservEnabled, - minParams: 1, - maxParams: 1, - }, - "offerlist": { - handler: hsOfferListHandler, - help: `Syntax: $bOFFERLIST$b - -OFFERLIST lists vhosts that can be chosen without requiring operator approval; -to use one of the listed vhosts, take it with /HOSTSERV TAKE.`, - helpShort: `$bOFFERLIST$b lists vhosts that can be taken without operator approval.`, - enabled: hostservEnabled, - minParams: 0, - maxParams: 0, - }, - "take": { - handler: hsTakeHandler, - help: `Syntax: $bTAKE$b - -TAKE sets your vhost to one of the vhosts in the server's offer list; to see -the offered vhosts, use /HOSTSERV OFFERLIST.`, - helpShort: `$bTAKE$b sets your vhost to one of the options from the offer list.`, - enabled: hostservEnabled, - authRequired: true, - minParams: 1, - maxParams: 1, - }, "setcloaksecret": { handler: hsSetCloakSecretHandler, help: `Syntax: $bSETCLOAKSECRET$b [code] @@ -238,8 +193,6 @@ func hsRequestHandler(server *Server, client *Client, command string, params []s if err != nil { if throttled, ok := err.(*vhostThrottleExceeded); ok { hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before making another request"), throttled.timeRemaining)) - } else if err == errVhostsForbidden { - hsNotice(rb, client.t("An administrator has denied you the ability to use vhosts")) } else { hsNotice(rb, client.t("An error occurred")) } @@ -276,11 +229,6 @@ func hsStatusHandler(server *Server, client *Client, command string, params []st return } - if account.VHost.Forbidden { - hsNotice(rb, client.t("An administrator has denied you the ability to use vhosts")) - return - } - if account.VHost.ApprovedVHost != "" { hsNotice(rb, fmt.Sprintf(client.t("Account %[1]s has vhost: %[2]s"), accountName, account.VHost.ApprovedVHost)) if !account.VHost.Enabled { @@ -382,70 +330,6 @@ func hsRejectHandler(server *Server, client *Client, command string, params []st } } -func hsForbidHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) { - user := params[0] - forbidden := command == "forbid" - - _, err := server.accounts.VHostForbid(user, forbidden) - if err == errAccountDoesNotExist { - hsNotice(rb, client.t("No such account")) - } else if err != nil { - hsNotice(rb, client.t("An error occurred")) - } else { - if forbidden { - hsNotice(rb, fmt.Sprintf(client.t("User %s is no longer allowed to use vhosts"), user)) - } else { - hsNotice(rb, fmt.Sprintf(client.t("User %s is now allowed to use vhosts"), user)) - } - } -} - -func hsOfferListHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) { - vhostConfig := server.Config().Accounts.VHosts - if len(vhostConfig.OfferList) == 0 { - if vhostConfig.UserRequests.Enabled { - hsNotice(rb, client.t("The server does not offer any vhosts, but you can request one with /HOSTSERV REQUEST")) - } else { - hsNotice(rb, client.t("The server does not offer any vhosts")) - } - } else { - hsNotice(rb, client.t("The following vhosts are available and can be chosen with /HOSTSERV TAKE:")) - for _, vhost := range vhostConfig.OfferList { - hsNotice(rb, vhost) - } - } -} - -func hsTakeHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) { - config := server.Config() - vhost := params[0] - found := false - for _, offered := range config.Accounts.VHosts.OfferList { - if offered == vhost { - found = true - } - } - if !found { - hsNotice(rb, client.t("That vhost isn't being offered by the server")) - return - } - - account := client.Account() - _, err := server.accounts.VHostTake(account, vhost, time.Duration(config.Accounts.VHosts.UserRequests.Cooldown)) - if err != nil { - if throttled, ok := err.(*vhostThrottleExceeded); ok { - hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining)) - } else if err == errVhostsForbidden { - hsNotice(rb, client.t("An administrator has denied you the ability to use vhosts")) - } else { - hsNotice(rb, client.t("An error occurred")) - } - } else { - hsNotice(rb, client.t("Successfully set vhost")) - server.snomasks.Send(sno.LocalVhosts, fmt.Sprintf("Client %s (account %s) took vhost %s", client.Nick(), account, vhost)) - } -} - func hsSetCloakSecretHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) { secret := params[0] expectedCode := utils.ConfirmationCode(secret, server.ctime)