Ver código fonte

Merge pull request #767 from slingamn/issue764_hstake_again

fix #764
tags/v2.0.0-rc1
Shivaram Lingamneni 4 anos atrás
pai
commit
806c4b0d68
Nenhuma conta vinculada ao e-mail do autor do commit
5 arquivos alterados com 53 adições e 15 exclusões
  1. 31
    5
      irc/accounts.go
  2. 1
    0
      irc/errors.go
  3. 14
    6
      irc/hostserv.go
  4. 6
    3
      irc/sno/constants.go
  5. 1
    1
      oragono.yaml

+ 31
- 5
irc/accounts.go Ver arquivo

@@ -1169,13 +1169,9 @@ func (vh *VHostInfo) checkThrottle(cooldown time.Duration) (err error) {
1169 1169
 // callback type implementing the actual business logic of vhost operations
1170 1170
 type vhostMunger func(input VHostInfo) (output VHostInfo, err error)
1171 1171
 
1172
-func (am *AccountManager) VHostSet(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
1172
+func (am *AccountManager) VHostSet(account string, vhost string) (result VHostInfo, err error) {
1173 1173
 	munger := func(input VHostInfo) (output VHostInfo, err error) {
1174 1174
 		output = input
1175
-		err = output.checkThrottle(cooldown)
1176
-		if err != nil {
1177
-			return
1178
-		}
1179 1175
 		output.Enabled = true
1180 1176
 		output.ApprovedVHost = vhost
1181 1177
 		return
@@ -1187,6 +1183,10 @@ func (am *AccountManager) VHostSet(account string, vhost string, cooldown time.D
1187 1183
 func (am *AccountManager) VHostRequest(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
1188 1184
 	munger := func(input VHostInfo) (output VHostInfo, err error) {
1189 1185
 		output = input
1186
+		if input.Forbidden {
1187
+			err = errVhostsForbidden
1188
+			return
1189
+		}
1190 1190
 		// you can update your existing request, but if you were approved or rejected,
1191 1191
 		// you can't spam a new request
1192 1192
 		if output.RequestedVHost == "" {
@@ -1205,6 +1205,32 @@ func (am *AccountManager) VHostRequest(account string, vhost string, cooldown ti
1205 1205
 	return am.performVHostChange(account, munger)
1206 1206
 }
1207 1207
 
1208
+func (am *AccountManager) VHostTake(account string, vhost string, cooldown time.Duration) (result VHostInfo, err error) {
1209
+	munger := func(input VHostInfo) (output VHostInfo, err error) {
1210
+		output = input
1211
+		if input.Forbidden {
1212
+			err = errVhostsForbidden
1213
+			return
1214
+		}
1215
+		// if you have a request pending, you can cancel it using take;
1216
+		// otherwise, you're subject to the same throttling as if you were making a request
1217
+		if output.RequestedVHost == "" {
1218
+			err = output.checkThrottle(cooldown)
1219
+		}
1220
+		if err != nil {
1221
+			return
1222
+		}
1223
+		output.ApprovedVHost = vhost
1224
+		output.RequestedVHost = ""
1225
+		output.RejectedVHost = ""
1226
+		output.RejectionReason = ""
1227
+		output.LastRequestTime = time.Now().UTC()
1228
+		return
1229
+	}
1230
+
1231
+	return am.performVHostChange(account, munger)
1232
+}
1233
+
1208 1234
 func (am *AccountManager) VHostApprove(account string) (result VHostInfo, err error) {
1209 1235
 	munger := func(input VHostInfo) (output VHostInfo, err error) {
1210 1236
 		output = input

+ 1
- 0
irc/errors.go Ver arquivo

@@ -50,6 +50,7 @@ var (
50 50
 	errBanned                         = errors.New("IP or nickmask banned")
51 51
 	errInvalidParams                  = utils.ErrInvalidParams
52 52
 	errNoVhost                        = errors.New(`You do not have an approved vhost`)
53
+	errVhostsForbidden                = errors.New(`An administrator has denied you the ability to use vhosts`)
53 54
 	errLimitExceeded                  = errors.New("Limit exceeded")
54 55
 	errNoop                           = errors.New("Action was a no-op")
55 56
 	errCASFailed                      = errors.New("Compare-and-swap update of database value failed")

+ 14
- 6
irc/hostserv.go Ver arquivo

@@ -7,6 +7,8 @@ import (
7 7
 	"errors"
8 8
 	"fmt"
9 9
 	"regexp"
10
+
11
+	"github.com/oragono/oragono/irc/sno"
10 12
 )
11 13
 
12 14
 const hostservHelp = `HostServ lets you manage your vhost (i.e., the string displayed
@@ -216,6 +218,8 @@ func hsRequestHandler(server *Server, client *Client, command string, params []s
216 218
 	if err != nil {
217 219
 		if throttled, ok := err.(*vhostThrottleExceeded); ok {
218 220
 			hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before making another request"), throttled.timeRemaining))
221
+		} else if err == errVhostsForbidden {
222
+			hsNotice(rb, client.t("An administrator has denied you the ability to use vhosts"))
219 223
 		} else {
220 224
 			hsNotice(rb, client.t("An error occurred"))
221 225
 		}
@@ -223,7 +227,7 @@ func hsRequestHandler(server *Server, client *Client, command string, params []s
223 227
 		hsNotice(rb, client.t("Your vhost request will be reviewed by an administrator"))
224 228
 		chanMsg := fmt.Sprintf("Account %s requests vhost %s", accountName, vhost)
225 229
 		hsNotifyChannel(server, chanMsg)
226
-		// TODO send admins a snomask of some kind
230
+		server.snomasks.Send(sno.LocalVhosts, chanMsg)
227 231
 	}
228 232
 }
229 233
 
@@ -298,7 +302,7 @@ func hsSetHandler(server *Server, client *Client, command string, params []strin
298 302
 	}
299 303
 	// else: command == "del", vhost == ""
300 304
 
301
-	_, err := server.accounts.VHostSet(user, vhost, 0)
305
+	_, err := server.accounts.VHostSet(user, vhost)
302 306
 	if err != nil {
303 307
 		hsNotice(rb, client.t("An error occurred"))
304 308
 	} else if vhost != "" {
@@ -326,6 +330,7 @@ func hsApproveHandler(server *Server, client *Client, command string, params []s
326 330
 		hsNotice(rb, fmt.Sprintf(client.t("Successfully approved vhost request for %s"), user))
327 331
 		chanMsg := fmt.Sprintf("Oper %[1]s approved vhost %[2]s for account %[3]s", client.Nick(), vhostInfo.ApprovedVHost, user)
328 332
 		hsNotifyChannel(server, chanMsg)
333
+		server.snomasks.Send(sno.LocalVhosts, chanMsg)
329 334
 		for _, client := range server.accounts.AccountToClients(user) {
330 335
 			client.Notice(client.t("Your vhost request was approved by an administrator"))
331 336
 		}
@@ -346,6 +351,7 @@ func hsRejectHandler(server *Server, client *Client, command string, params []st
346 351
 		hsNotice(rb, fmt.Sprintf(client.t("Successfully rejected vhost request for %s"), user))
347 352
 		chanMsg := fmt.Sprintf("Oper %s rejected vhost %s for account %s, with the reason: %v", client.Nick(), vhostInfo.RejectedVHost, user, reason)
348 353
 		hsNotifyChannel(server, chanMsg)
354
+		server.snomasks.Send(sno.LocalVhosts, chanMsg)
349 355
 		for _, client := range server.accounts.AccountToClients(user) {
350 356
 			if reason == "" {
351 357
 				client.Notice("Your vhost request was rejected by an administrator")
@@ -404,16 +410,18 @@ func hsTakeHandler(server *Server, client *Client, command string, params []stri
404 410
 		return
405 411
 	}
406 412
 
407
-	_, err := server.accounts.VHostSet(client.Account(), vhost, config.Accounts.VHosts.UserRequests.Cooldown)
413
+	account := client.Account()
414
+	_, err := server.accounts.VHostTake(account, vhost, config.Accounts.VHosts.UserRequests.Cooldown)
408 415
 	if err != nil {
409 416
 		if throttled, ok := err.(*vhostThrottleExceeded); ok {
410 417
 			hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))
418
+		} else if err == errVhostsForbidden {
419
+			hsNotice(rb, client.t("An administrator has denied you the ability to use vhosts"))
411 420
 		} else {
412 421
 			hsNotice(rb, client.t("An error occurred"))
413 422
 		}
414
-	} else if vhost != "" {
415
-		hsNotice(rb, client.t("Successfully set vhost"))
416 423
 	} else {
417
-		hsNotice(rb, client.t("Successfully cleared vhost"))
424
+		hsNotice(rb, client.t("Successfully set vhost"))
425
+		server.snomasks.Send(sno.LocalVhosts, fmt.Sprintf("Client %s (account %s) took vhost %s", client.Nick(), account, vhost))
418 426
 	}
419 427
 }

+ 6
- 3
irc/sno/constants.go Ver arquivo

@@ -9,7 +9,7 @@ type Mask rune
9 9
 
10 10
 // Notice mask types
11 11
 const (
12
-	LocalAccouncements Mask = 'a'
12
+	LocalAnnouncements Mask = 'a'
13 13
 	LocalConnects      Mask = 'c'
14 14
 	LocalChannels      Mask = 'j'
15 15
 	LocalKills         Mask = 'k'
@@ -19,12 +19,13 @@ const (
19 19
 	Stats              Mask = 't'
20 20
 	LocalAccounts      Mask = 'u'
21 21
 	LocalXline         Mask = 'x'
22
+	LocalVhosts        Mask = 'v'
22 23
 )
23 24
 
24 25
 var (
25 26
 	// NoticeMaskNames has readable names for our snomask types.
26 27
 	NoticeMaskNames = map[Mask]string{
27
-		LocalAccouncements: "ANNOUNCEMENT",
28
+		LocalAnnouncements: "ANNOUNCEMENT",
28 29
 		LocalConnects:      "CONNECT",
29 30
 		LocalChannels:      "CHANNEL",
30 31
 		LocalKills:         "KILL",
@@ -34,11 +35,12 @@ var (
34 35
 		Stats:              "STATS",
35 36
 		LocalAccounts:      "ACCOUNT",
36 37
 		LocalXline:         "XLINE",
38
+		LocalVhosts:        "VHOST",
37 39
 	}
38 40
 
39 41
 	// ValidMasks contains the snomasks that we support.
40 42
 	ValidMasks = map[Mask]bool{
41
-		LocalAccouncements: true,
43
+		LocalAnnouncements: true,
42 44
 		LocalConnects:      true,
43 45
 		LocalChannels:      true,
44 46
 		LocalKills:         true,
@@ -48,5 +50,6 @@ var (
48 50
 		Stats:              true,
49 51
 		LocalAccounts:      true,
50 52
 		LocalXline:         true,
53
+		LocalVhosts:        true,
51 54
 	}
52 55
 )

+ 1
- 1
oragono.yaml Ver arquivo

@@ -466,7 +466,7 @@ opers:
466 466
         vhost: "n"
467 467
 
468 468
         # modes are the modes to auto-set upon opering-up
469
-        modes: +is acjknoqtux
469
+        modes: +is acjknoqtuxv
470 470
 
471 471
         # operators can be authenticated either by password (with the /OPER command),
472 472
         # or by certificate fingerprint, or both. if a password hash is set, then a

Carregando…
Cancelar
Salvar