forked from External/ergo
fix #1346
This commit is contained in:
parent
11ddffa7c5
commit
cf5a426f90
6 changed files with 35 additions and 359 deletions
145
irc/hostserv.go
145
irc/hostserv.go
|
|
@ -7,11 +7,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/goshuirc/irc-go/ircfmt"
|
||||
|
||||
"github.com/oragono/oragono/irc/sno"
|
||||
"github.com/oragono/oragono/irc/utils"
|
||||
)
|
||||
|
||||
|
|
@ -32,10 +30,6 @@ func hostservEnabled(config *Config) bool {
|
|||
return config.Accounts.VHosts.Enabled
|
||||
}
|
||||
|
||||
func hostservRequestsEnabled(config *Config) bool {
|
||||
return config.Accounts.VHosts.Enabled && config.Accounts.VHosts.UserRequests.Enabled
|
||||
}
|
||||
|
||||
var (
|
||||
hostservCommands = map[string]*serviceCommand{
|
||||
"on": {
|
||||
|
|
@ -56,17 +50,6 @@ OFF disables your vhost, if you have one approved.`,
|
|||
authRequired: true,
|
||||
enabled: hostservEnabled,
|
||||
},
|
||||
"request": {
|
||||
handler: hsRequestHandler,
|
||||
help: `Syntax: $bREQUEST <vhost>$b
|
||||
|
||||
REQUEST requests that a new vhost by assigned to your account. The request must
|
||||
then be approved by a server operator.`,
|
||||
helpShort: `$bREQUEST$b requests a new vhost, pending operator approval.`,
|
||||
authRequired: true,
|
||||
enabled: hostservRequestsEnabled,
|
||||
minParams: 1,
|
||||
},
|
||||
"status": {
|
||||
handler: hsStatusHandler,
|
||||
help: `Syntax: $bSTATUS [user]$b
|
||||
|
|
@ -96,39 +79,6 @@ DEL deletes a user's vhost.`,
|
|||
enabled: hostservEnabled,
|
||||
minParams: 1,
|
||||
},
|
||||
"waiting": {
|
||||
handler: hsWaitingHandler,
|
||||
help: `Syntax: $bWAITING$b
|
||||
|
||||
WAITING shows a list of pending vhost requests, which can then be approved
|
||||
or rejected.`,
|
||||
helpShort: `$bWAITING$b shows a list of pending vhost requests.`,
|
||||
capabs: []string{"vhosts"},
|
||||
enabled: hostservEnabled,
|
||||
},
|
||||
"approve": {
|
||||
handler: hsApproveHandler,
|
||||
help: `Syntax: $bAPPROVE <user>$b
|
||||
|
||||
APPROVE approves a user's vhost request.`,
|
||||
helpShort: `$bAPPROVE$b approves a user's vhost request.`,
|
||||
capabs: []string{"vhosts"},
|
||||
enabled: hostservEnabled,
|
||||
minParams: 1,
|
||||
},
|
||||
"reject": {
|
||||
handler: hsRejectHandler,
|
||||
help: `Syntax: $bREJECT <user> [<reason>]$b
|
||||
|
||||
REJECT rejects a user's vhost request, optionally giving them a reason
|
||||
for the rejection.`,
|
||||
helpShort: `$bREJECT$b rejects a user's vhost request.`,
|
||||
capabs: []string{"vhosts"},
|
||||
enabled: hostservEnabled,
|
||||
minParams: 1,
|
||||
maxParams: 2,
|
||||
unsplitFinalParam: true,
|
||||
},
|
||||
"setcloaksecret": {
|
||||
handler: hsSetCloakSecretHandler,
|
||||
help: `Syntax: $bSETCLOAKSECRET$b <secret> [code]
|
||||
|
|
@ -150,19 +100,6 @@ func hsNotice(rb *ResponseBuffer, text string) {
|
|||
rb.Add(nil, hsNickMask, "NOTICE", rb.target.Nick(), text)
|
||||
}
|
||||
|
||||
// hsNotifyChannel notifies the designated channel of new vhost activity
|
||||
func hsNotifyChannel(server *Server, message string) {
|
||||
chname := server.Config().Accounts.VHosts.UserRequests.Channel
|
||||
channel := server.channels.Get(chname)
|
||||
if channel == nil {
|
||||
return
|
||||
}
|
||||
chname = channel.Name()
|
||||
for _, client := range channel.Members() {
|
||||
client.Send(nil, hsNickMask, "PRIVMSG", chname, message)
|
||||
}
|
||||
}
|
||||
|
||||
func hsOnOffHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
enable := false
|
||||
if command == "on" {
|
||||
|
|
@ -181,29 +118,6 @@ func hsOnOffHandler(server *Server, client *Client, command string, params []str
|
|||
}
|
||||
}
|
||||
|
||||
func hsRequestHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
vhost := params[0]
|
||||
if validateVhost(server, vhost, false) != nil {
|
||||
hsNotice(rb, client.t("Invalid vhost"))
|
||||
return
|
||||
}
|
||||
|
||||
accountName := client.Account()
|
||||
_, err := server.accounts.VHostRequest(accountName, vhost, time.Duration(server.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 making another request"), throttled.timeRemaining))
|
||||
} else {
|
||||
hsNotice(rb, client.t("An error occurred"))
|
||||
}
|
||||
} else {
|
||||
hsNotice(rb, client.t("Your vhost request will be reviewed by an administrator"))
|
||||
chanMsg := fmt.Sprintf("Account %s requests vhost %s", accountName, vhost)
|
||||
hsNotifyChannel(server, chanMsg)
|
||||
server.snomasks.Send(sno.LocalVhosts, chanMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func hsStatusHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
var accountName string
|
||||
if len(params) > 0 {
|
||||
|
|
@ -237,13 +151,6 @@ func hsStatusHandler(server *Server, client *Client, command string, params []st
|
|||
} else {
|
||||
hsNotice(rb, fmt.Sprintf(client.t("Account %s has no vhost"), accountName))
|
||||
}
|
||||
if account.VHost.RequestedVHost != "" {
|
||||
hsNotice(rb, fmt.Sprintf(client.t("A request is pending for vhost: %s"), account.VHost.RequestedVHost))
|
||||
}
|
||||
if account.VHost.RejectedVHost != "" {
|
||||
hsNotice(rb, fmt.Sprintf(client.t("A request was previously made for vhost: %s"), account.VHost.RejectedVHost))
|
||||
hsNotice(rb, fmt.Sprintf(client.t("It was rejected for reason: %s"), account.VHost.RejectionReason))
|
||||
}
|
||||
}
|
||||
|
||||
func validateVhost(server *Server, vhost string, oper bool) error {
|
||||
|
|
@ -251,7 +158,7 @@ func validateVhost(server *Server, vhost string, oper bool) error {
|
|||
if len(vhost) > config.Accounts.VHosts.MaxLength {
|
||||
return errVHostTooLong
|
||||
}
|
||||
if !config.Accounts.VHosts.ValidRegexp.MatchString(vhost) {
|
||||
if !config.Accounts.VHosts.validRegexp.MatchString(vhost) {
|
||||
return errVHostBadCharacters
|
||||
}
|
||||
return nil
|
||||
|
|
@ -280,56 +187,6 @@ func hsSetHandler(server *Server, client *Client, command string, params []strin
|
|||
}
|
||||
}
|
||||
|
||||
func hsWaitingHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
requests, total := server.accounts.VHostListRequests(10)
|
||||
hsNotice(rb, fmt.Sprintf(client.t("There are %[1]d pending requests for vhosts (%[2]d displayed)"), total, len(requests)))
|
||||
for i, request := range requests {
|
||||
hsNotice(rb, fmt.Sprintf(client.t("%[1]d. User %[2]s requests vhost: %[3]s"), i+1, request.Account, request.RequestedVHost))
|
||||
}
|
||||
}
|
||||
|
||||
func hsApproveHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
user := params[0]
|
||||
|
||||
vhostInfo, err := server.accounts.VHostApprove(user)
|
||||
if err != nil {
|
||||
hsNotice(rb, client.t("An error occurred"))
|
||||
} else {
|
||||
hsNotice(rb, fmt.Sprintf(client.t("Successfully approved vhost request for %s"), user))
|
||||
chanMsg := fmt.Sprintf("Oper %[1]s approved vhost %[2]s for account %[3]s", client.Nick(), vhostInfo.ApprovedVHost, user)
|
||||
hsNotifyChannel(server, chanMsg)
|
||||
server.snomasks.Send(sno.LocalVhosts, chanMsg)
|
||||
for _, client := range server.accounts.AccountToClients(user) {
|
||||
client.Send(nil, hsNickMask, "NOTICE", client.Nick(), client.t("Your vhost request was approved by an administrator"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hsRejectHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
var reason string
|
||||
user := params[0]
|
||||
if len(params) > 1 {
|
||||
reason = params[1]
|
||||
}
|
||||
|
||||
vhostInfo, err := server.accounts.VHostReject(user, reason)
|
||||
if err != nil {
|
||||
hsNotice(rb, client.t("An error occurred"))
|
||||
} else {
|
||||
hsNotice(rb, fmt.Sprintf(client.t("Successfully rejected vhost request for %s"), user))
|
||||
chanMsg := fmt.Sprintf("Oper %s rejected vhost %s for account %s, with the reason: %v", client.Nick(), vhostInfo.RejectedVHost, user, reason)
|
||||
hsNotifyChannel(server, chanMsg)
|
||||
server.snomasks.Send(sno.LocalVhosts, chanMsg)
|
||||
for _, client := range server.accounts.AccountToClients(user) {
|
||||
if reason == "" {
|
||||
client.Send(nil, hsNickMask, "NOTICE", client.Nick(), client.t("Your vhost request was rejected by an administrator"))
|
||||
} else {
|
||||
client.Send(nil, hsNickMask, "NOTICE", client.Nick(), fmt.Sprintf(client.t("Your vhost request was rejected by an administrator. The reason given was: %s"), reason))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hsSetCloakSecretHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
secret := params[0]
|
||||
expectedCode := utils.ConfirmationCode(secret, server.ctime)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue