mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
fix #741
This commit is contained in:
parent
e10a5f07de
commit
05cb80507f
4 changed files with 130 additions and 1 deletions
107
irc/hostserv.go
107
irc/hostserv.go
|
|
@ -121,6 +121,51 @@ for the rejection.`,
|
|||
maxParams: 2,
|
||||
unsplitFinalParam: true,
|
||||
},
|
||||
"forbid": {
|
||||
handler: hsForbidHandler,
|
||||
help: `Syntax: $bFORBID <user>$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 <user>$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 <vhost>
|
||||
|
||||
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,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -218,6 +263,11 @@ 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 {
|
||||
|
|
@ -316,3 +366,60 @@ 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("Successfully forbidden vhosts to user %s"), user))
|
||||
} else {
|
||||
hsNotice(rb, fmt.Sprintf(client.t("Successfully permitted vhosts for user %s"), 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 i, vhost := range vhostConfig.OfferList {
|
||||
hsNotice(rb, fmt.Sprintf("%d. %s", i+1, vhost))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hsTakeHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
|
||||
vhost := params[0]
|
||||
found := false
|
||||
for _, offered := range server.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
|
||||
}
|
||||
|
||||
_, err := server.accounts.VHostSet(client.Account(), vhost)
|
||||
if err != nil {
|
||||
hsNotice(rb, client.t("An error occurred"))
|
||||
} else if vhost != "" {
|
||||
hsNotice(rb, client.t("Successfully set vhost"))
|
||||
} else {
|
||||
hsNotice(rb, client.t("Successfully cleared vhost"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue