chiark / gitweb /
New secret ballot machinery
[modbot-mtm.git] / sballot / new-issue
1 #!/usr/bin/perl -w
2 #
3 # usage: .../new-ballot '[YNA]' 'Remove Bad Bozo from the moderation panel'
4 #                        ^ regexp, put into   /^(?:$regexp)$/io
5
6 use strict qw(refs vars);
7
8 BEGIN {
9     my $sballotdir= $0;        $sballotdir =~ s,/[^/]*$,,;
10     chdir $sballotdir or die "$sballotdir $!";
11     unshift @INC, '..';
12 };
13
14 use ModerationCommon;
15 use POSIX;
16
17 @ARGV==2 or die;
18 $ARGV[0] !~ m/^-/ or die;
19 my $regexp= shift @ARGV;
20 my $title= shift @ARGV;
21
22 readsettings();
23
24 system "rm -rf issues/new";
25 mkdir "issues" or $!==&EEXIST or die $!;
26 mkdir "issues/new",0770 or die $!;
27
28 stat "issues/new" or die $!;
29 my $issueid= time.'-'.((stat _)[1]);
30 my $issuedir= "issues/$issueid";
31
32 rename "issues/new", $issuedir or die $!;
33
34 open T, "> $issuedir/title" or die $!;
35 print T $title, "\n" or die $!;
36 print T $regexp, "\n" or die $!;
37 close T or die $!;
38
39
40 open S, "/dev/urandom" or die $!;
41
42 sub randhex () {
43     my $nonce;
44     sysread(S, $nonce, $hashlen) == $hashlen or die $!;
45     return unpack "H*", $nonce;
46 }
47
48 my @mods;
49
50 open M, "../moderators" or die $!;
51 while (<M>) {
52     next unless m/\S/;
53     next if m/^\#/;
54     m/^([A-Z]+)\s+(\S+)\s*$/ or die;
55     my $m= { Name => $1, Email => $2 };
56     $m->{Nonce}= randhex();     $m->{Ident}= hash($m->{Nonce});
57     $m->{Password}= randhex();  $m->{HashedPw}= hash($m->{Password});
58     push @mods, $m;
59 }
60 close M or die $!;
61
62
63 sendmail_start();
64 print P <<END or warn $!;
65 To: $setting{ABBREV} moderators <$setting{MODEMAIL}>
66 Subject: Secret ballot initiated for $setting{ABBREV}
67
68 The administrator of $setting{GROUP}
69 has initiated a new secret ballot on the question:
70   Issue ID: $issueid
71   Title: $title
72
73 Each moderator will be sent a private email telling them their
74 pseudonym and voting details.  
75
76 There will also be an announcement from the administrator confirming
77 that this is the live ballot (as if there are problems with the
78 software, it may be necessary to initiate several) and explaining what
79 to enter into the "vote" box on the voting page.  Please do not vote
80 until you've received that confirmation.
81
82 The moderators who will be able to vote are the following people:
83 END
84 foreach my $m (@mods) {
85     my $opqe= $m->{Email};
86     $opqe =~ s/\@/ (at) /;
87     printf P "  %-10s %s\n", $m->{Name}, $opqe or die $!;
88 }
89
90 print P <<END or die $!;
91 If you are not listed, or your email address is wrong, or you do not
92 receive the private login details email (which should arrive almost
93 immediately), please say so as soon as possible.
94
95 The pseudonyms which have been assigned are as follows:
96 END
97
98 @mods= sort { $a->{Ident} cmp $b->{Ident} } @mods;
99 foreach my $m (@mods) {
100     my $vfile= "$issuedir/v.$m->{Ident}";
101     open V, "> $vfile" or die "$vfile $!";
102     print V "$m->{HashedPw} not voted\n" or die $!;
103     close V or die $!;
104     print P "  ", $m->{Ident}, "\n" or die $!;
105 }
106
107 print P <<END or die $!;
108 (the pseudonyms have been sorted into numerical order)
109
110 Thanks for your attention.
111 moderation system robot
112 END
113
114 sendmail_finish();
115
116 foreach my $m (@mods) {
117     sendmail_start();
118     print P <<END or warn $!;
119 To: $setting{ABBREV} moderator $m->{Name} <$m->{Email}>
120 Subject: [$setting{ABBREV}] Secret ballot private info
121
122 The administrator of $setting{GROUP}
123 has initiated a new secret ballot on the question:
124   Issue ID: $issueid
125   Title: $title
126
127 Your login details for voting are:
128  Pseudonym: $m->{Ident}
129  Password:  $m->{Password}
130
131 These are confidential to you, valid only for this particular vote,
132 and cannot be regenerated if they are lost.  So please keep this email
133 but do not reveal it to anyone.  Reveal the password only to the
134 voting web page.
135
136 There will also be an announcement from the administrator confirming
137 that this is the live ballot (as if there are problems with the
138 software, it may be necessary to initiate several) and explaining what
139 to enter into the "vote" box on the voting page.  Please do not vote
140 until you've received that confirmation.
141
142 You may then cast (and change) your vote here:
143   $setting{CGIBASEURL}/g.$setting{ABBREV}/sballot?issue=$issueid
144
145 Thanks for your attention,
146 moderation system robot
147
148 Addendum for the paranoid:
149 Your pseudonym was generated from a nonce, as follows:
150   echo $m->{Nonce} | sha256sum
151 Only you know this nonce - it is not stored on the moderation system
152 server.  You should check that your vote is properly recorded and
153 complain if not: vote tallies will list which way each pseudonym
154 voted.
155 END
156     sendmail_finish();
157 }