chiark / gitweb /
user registration first half
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 1 Sep 2000 20:38:43 +0000 (20:38 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 1 Sep 2000 20:38:43 +0000 (20:38 +0000)
.cvsignore
bot.tcl

index 170a88f746b44ca518ee414bc93aafc3ff246db4..f40c7c1667c37f7e3630928752b6ffc33b8f4eb1 100644 (file)
@@ -1 +1,2 @@
 summon
+users
diff --git a/bot.tcl b/bot.tcl
index 95febc412a389a8c4e42efe67dc064c5c656b804..f03c1832e6f86a361aa68a357e13db9d8b2397e7 100755 (executable)
--- a/bot.tcl
+++ b/bot.tcl
@@ -3,6 +3,17 @@
 set host chiark
 set port 6667
 if {![info exists nick]} { set nick Blight }
+set ownmailaddr blight@chiark.greenend.org.uk
+set ownfullname "here to Help"
+
+if {![info exists globalsecret]} {
+    set gsfile [open /dev/urandom r]
+    fconfigure $gsfile -translation binary
+    set globalsecret [read $gsfile 32]
+    binary scan $globalsecret H* globalsecret
+    close $gsfile
+    unset gsfile
+}
 
 proc sendout {command args} {
     global sock
@@ -374,16 +385,20 @@ proc def_ucmd {cmdname body} {
 proc ucmdr {priv pub args} {
     return -code return [concat [list $priv $pub] $args]
 }
-    
-def_ucmd help {
-    ta_nomore
+
+proc ucmd_sendhelp {} {
     ucmdr \
 {Commands currently understood:
-help              get this list of commands
-seen <nick>       ask after someone (I'll tell them you asked)
-summon <username> invite a logged-on user onto IRC} {}
+ help              get this list of commands
+ seen <nick>       ask after someone (I'll tell them you asked)
+ summon <username> invite a logged-on user onto IRC
+Send commands to be by /msg, or say them in channel with ! in front.} {}
 }
 
+def_ucmd help { ta_nomore; ucmd_sendhelp }
+
+def_ucmd ? { ta_nomore; ucmd_sendhelp }
+
 proc manyset {list args} {
     foreach val $list var $args {
        upvar 1 $var my
@@ -434,6 +449,62 @@ def_ucmd summon {
     }
 }
 
+def_ucmd newuser {
+    global ownmailaddr ownfullname nick globalsecret
+    prefix_nick
+    if {[ischan $dest]} {
+       error "You must register privately."
+    }
+    binary scan [irctolower $n] H* nhex
+    if {[file exists users/$nhex]} {
+       error "You (or someone else) have already registered the nick $n."
+    }
+    set ownermail [ta_word]
+
+    set now [clock seconds]
+    set small 100000
+    set mult 6
+    set ksecs [expr {$now / $small}]
+    set kmod [expr {$ksecs % $mult}]
+
+    if {[string length $text]} {
+       if {![regexp -nocase {^([0-5])([0-9a-f]+)$} $text pass_sup kmod]} {
+       }
+       set ksecs [expr {(($ksecs - $kmod) / $mult) * 6 + $kmod}]
+    }
+    set tohash "$ksecs\n$ownermail\n"
+    set hash [exec md5sum << $tohash]
+    set passwd "$kmod[string range $hash 0 15]"
+
+    if {[info exists pass_sup]} {
+       if {"$passwd" != "$pass_sup"} {
+           error "Incorrect registration password."
+       }
+       sendaction $n "ignores your ok"
+    } else {
+       set mailmsg \
+"From: $ownmailaddr ($ownfullname)
+Subject: $nick registration
+To: $ownermail
+
+Thanks for starting the registration process.  You must now issue the
+`newuser' command with both the same email address again, and your
+registration password from this mail.
+
+Nick:          $n
+Email address: $ownermail
+Password:      $passwd
+
+This password will be valid for approximately the next 600ks
+(or until I am restarted).
+
+For example,
+ /msg $nick newuser $ownermail $passwd"
+        exec /usr/sbin/sendmail -odi -oee -oi -t << $mailmsg
+        sendaction $n "has sent your registration mail to $ownermail."
+    }
+}
+
 def_ucmd seen {
     global lastseen nick
     prefix_nick
@@ -472,7 +543,7 @@ if {![info exists sock]} {
     #fconfigure $sock -translation binary
     fconfigure $sock -translation crlf
 
-    sendout USER guest 0 * "chiark testing bot"
+    sendout USER guest 0 * $ownfullname
     sendout NICK $nick
     fileevent $sock readable onread
 }