Browse Source

add a verification code to CS UNREGISTER

tags/v0.12.0
Shivaram Lingamneni 6 years ago
parent
commit
c3b66b5236
1 changed files with 20 additions and 3 deletions
  1. 20
    3
      irc/chanserv.go

+ 20
- 3
irc/chanserv.go View File

@@ -4,8 +4,11 @@
4 4
 package irc
5 5
 
6 6
 import (
7
+	"bytes"
7 8
 	"fmt"
9
+	"hash/crc32"
8 10
 	"sort"
11
+	"strconv"
9 12
 	"strings"
10 13
 
11 14
 	"github.com/goshuirc/irc-go/ircfmt"
@@ -51,9 +54,11 @@ remembered.`,
51 54
 		},
52 55
 		"unregister": {
53 56
 			handler: csUnregisterHandler,
54
-			help: `Syntax: $bUNREGISTER #channel$b
57
+			help: `Syntax: $bUNREGISTER #channel [code]$b
55 58
 
56
-UNREGISTER deletes a channel registration, allowing someone else to claim it.`,
59
+UNREGISTER deletes a channel registration, allowing someone else to claim it.
60
+To prevent accidental unregistrations, a verification code is required;
61
+invoking the command without a code will display the necessary code.`,
57 62
 			helpShort: `$bUNREGISTER$b deletes a channel registration.`,
58 63
 			enabled:   chanregEnabled,
59 64
 		},
@@ -258,7 +263,7 @@ func csRegisterHandler(server *Server, client *Client, command, params string, r
258 263
 }
259 264
 
260 265
 func csUnregisterHandler(server *Server, client *Client, command, params string, rb *ResponseBuffer) {
261
-	channelName := strings.TrimSpace(params)
266
+	channelName, verificationCode := utils.ExtractParam(params)
262 267
 	channelKey, err := CasefoldChannel(channelName)
263 268
 	if channelKey == "" || err != nil {
264 269
 		csNotice(rb, client.t("Channel name is not valid"))
@@ -282,6 +287,18 @@ func csUnregisterHandler(server *Server, client *Client, command, params string,
282 287
 	}
283 288
 
284 289
 	info := channel.ExportRegistration(0)
290
+	// verification code is the crc32 of the name, plus the registration time
291
+	var codeInput bytes.Buffer
292
+	codeInput.WriteString(info.Name)
293
+	codeInput.WriteString(strconv.FormatInt(info.RegisteredAt.Unix(), 16))
294
+	expectedCode := int(crc32.ChecksumIEEE(codeInput.Bytes()))
295
+	receivedCode, err := strconv.Atoi(verificationCode)
296
+	if err != nil || expectedCode != receivedCode {
297
+		csNotice(rb, client.t("$bWarning:$b Unregistering this channel will remove all stored channel attributes."))
298
+		csNotice(rb, fmt.Sprintf(client.t("To confirm channel unregistration, type: /CS UNREGISTER %s %d"), channelKey, expectedCode))
299
+		return
300
+	}
301
+
285 302
 	channel.SetUnregistered()
286 303
 	go server.channelRegistry.Delete(channelKey, info)
287 304
 	csNotice(rb, fmt.Sprintf(client.t("Channel %s is now unregistered"), channelKey))

Loading…
Cancel
Save