Mercurial > hgrepos > hgweb.cgi > imapext
comparison APOPtools/apoppasswd @ 4:d741b3ecc917 draft
imapext-2007f
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 30 Oct 2014 00:03:05 +0900 |
parents | 28a55bc1110c |
children |
comparison
equal
deleted
inserted
replaced
3:2366b362676d | 4:d741b3ecc917 |
---|---|
206 print "Cannot output to $APOPFILE\nBye\n"; | 206 print "Cannot output to $APOPFILE\nBye\n"; |
207 exit 1; | 207 exit 1; |
208 } | 208 } |
209 exit 0; | 209 exit 0; |
210 } | 210 } |
211 #!/usr/local/bin/perl | |
212 # Customize these variables. | |
213 # If you change APOPFILEBASE, change the same variable in apopcall.c too. | |
214 # See http://www.gentei.org/~yuuji/software/imapext/ | |
215 | |
216 $HOME=$ENV{"HOME"}; | |
217 | |
218 $DEFAULTMAILDIR = "Maildir"; # Must be same as ../src/osdep/unix/Makefile | |
219 | |
220 $APOPFILEBASE = ".apop"; # "$HOME/$APOPFILEBASE" is the password file | |
221 # $APOPFILEBASE = "$DEFAULTMAILDIR/apop"; | |
222 # $APOPFILEBASE = "Mail/apop"; | |
223 | |
224 $ENCODER = "cat"; | |
225 # $ENCODER = "gzip"; | |
226 # $ENCODER = "uuencode $$|gzip"; | |
227 | |
228 $DECODER = "cat"; | |
229 # $DECODER = "gzip -dc"; | |
230 # $DECODER = "gzip -dc | uudecode"; | |
231 | |
232 $DOTQMAIL = ".qmail"; # qmail | |
233 # $DOTQMAIL = ".forward"; # Postfix | |
234 | |
235 $XADDR_DELIM = "-"; # qmail | |
236 # $XADDR_DELIM = "+"; # Postfix | |
237 | |
238 $HERE = "."; # qmail | |
239 # $HERE = "~"; # Postfix | |
240 | |
241 $EXT = ""; | |
242 $force = 0; | |
243 $base = 0; | |
244 | |
245 $APOPFILE = "$HOME/$APOPFILEBASE"; | |
246 | |
247 sub handler { | |
248 system "stty echo"; | |
249 print STDERR "Abort:\n"; | |
250 exit 1; | |
251 } | |
252 | |
253 $SIG{'INT'} = $SIG{'KILL'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'handler'; | |
254 | |
255 while ($_=$ARGV[0], /^-.+/ && shift) { | |
256 if (/^-e/) { | |
257 $APOPFILE .= $XADDR_DELIM . ($EXT=shift); | |
258 } elsif (/^-b/) { | |
259 $base++; | |
260 } elsif (/^-c/) { | |
261 $create++; | |
262 } elsif (/^-s/) { | |
263 $stream++; | |
264 # and exit; | |
265 } elsif (/^-h/) { | |
266 &usage; # and exit | |
267 } | |
268 } | |
269 | |
270 sub checkmaildir { | |
271 local($dotqmail) = ("$HOME/$DOTQMAIL"); | |
272 local($maildir) = ($DEFAULTMAILDIR); # default | |
273 $dotqmail .= "$XADDR_DELIM$EXT" if $EXT; | |
274 $maildir .= "-$EXT" if $EXT; | |
275 unless (-f "$dotqmail") { | |
276 if ($create) { | |
277 if (open(DQMAIL, "> $dotqmail")) { | |
278 print DQMAIL "$HERE/$maildir/\n"; | |
279 print "File [$dotqmail] created\n"; | |
280 close(DQMAIL); | |
281 } | |
282 } else { | |
283 print "$dotqmail file does not exist.\n"; # should go to stdout | |
284 print "Your should create $maildir first!\n"; | |
285 print "(-c option automatically makes it)\n"; | |
286 exit 1; | |
287 } | |
288 } | |
289 if (-s $dotqmail) { | |
290 $maildir=''; | |
291 if (open(DQMAIL, "< $dotqmail")) { | |
292 while (<DQMAIL>) { | |
293 s/[\r\n \t]*$//g; | |
294 next if /#/; | |
295 next unless m,\./.*/,; | |
296 chop; # strip trailing "/" | |
297 $maildir = $_; | |
298 last; | |
299 } | |
300 close(DQMAIL); | |
301 $maildir = $DEFAULTMAILDIR if $maildir eq ''; | |
302 unless (-d "$HOME/$maildir" | |
303 && -d "$HOME/$maildir/new" | |
304 && -d "$HOME/$maildir/cur" | |
305 && -d "$HOME/$maildir/tmp") { | |
306 if ($create) { | |
307 mkdir "$HOME/$maildir", 0700; | |
308 mkdir "$HOME/$maildir/new", 0700; | |
309 mkdir "$HOME/$maildir/cur", 0700; | |
310 mkdir "$HOME/$maildir/tmp", 0700; | |
311 print "Maildir [$maildir/] created\n"; | |
312 } else { | |
313 print "Maildir($maildir) does not exist\n"; | |
314 print "Your should do maildirmake $maildir first!\n"; | |
315 print "(-c option automatically makes it)\n"; | |
316 exit 1; | |
317 } | |
318 } | |
319 } | |
320 } | |
321 } | |
322 | |
323 sub usage { | |
324 local($mydir, $myname) = ($0 =~ m,(.*)/(.*),); | |
325 print<<_EOU_; | |
326 $myname Change Mail password for imap-4.7+qmailapop | |
327 Usage: $myname [options] | |
328 Options are... | |
329 -e EXT Set target email address to "user-EXT" | |
330 -c If no .qmail file and Maildir, create them | |
331 | |
332 _EOU_ | |
333 exit 0; | |
334 } | |
335 | |
336 if ($stream) { | |
337 &stream; | |
338 exit; # not reached | |
339 } | |
340 $OK=0; | |
341 until ($OK) { | |
342 system "stty -echo"; | |
343 print STDERR "Enter APOP Password: "; | |
344 $new1 = <>; | |
345 print STDERR "\n"; | |
346 if (length($new1) == 1) { | |
347 print STDERR "Canceled\n"; | |
348 exit 1; | |
349 } elsif (length($new1) < 9) { | |
350 print STDERR "Password is too short! Please use more than 8 chars.\n"; | |
351 next; | |
352 } | |
353 print STDERR "Again APOP Password: "; | |
354 $new2 = <>; | |
355 if ($new1 eq $new2) { | |
356 $OK=1; | |
357 } else { | |
358 print STDERR "\nPassword mismatch! Try again.\n"; | |
359 } | |
360 } | |
361 #OK | |
362 &checkmaildir; | |
363 system "stty echo"; | |
364 open(NP, "| $ENCODER > $APOPFILE") || die "Cannot write on $APOPFILE\n"; | |
365 print NP "$new1"; | |
366 close(NP); | |
367 chmod 0600, $APOPFILE; | |
368 print STDERR "\nUpdated APOP password successfully.\n"; | |
369 | |
370 sub stream { # Must match with old password | |
371 local($PASS, $old, $new1, $new2, $master) = (0); | |
372 local($masterfile) = ($APOPFILE); | |
373 $masterfile = "$HOME/$APOPFILEBASE" if $base; | |
374 exit 1 if ($> == 0); | |
375 while (<>) { | |
376 chop; | |
377 if (/^PASS (.*)$/i) { | |
378 $old = $1; | |
379 } elsif (/^NEW (.*)/i) { | |
380 $new1 = $1; | |
381 } elsif (/^NEW2 (.*)/i) { | |
382 $new2 = $1; | |
383 } | |
384 last if ("$new1" ne "" && "$new2" ne ""); | |
385 } | |
386 if (-s $APOPFILE || ($base && -f $masterfile)) { # Already exist | |
387 if (open(OLD, "$DECODER $masterfile |")) { | |
388 ($master = <OLD>) =~ s/[\n\r]$//g; | |
389 close(OLD); | |
390 } else { | |
391 print "Old password file corrupted.\n"; | |
392 print "Please ask to administrator.\n"; | |
393 exit 1; | |
394 } | |
395 if ($master ne $old) { | |
396 print "Illegal password\nBye\n"; | |
397 exit 1; | |
398 } | |
399 } | |
400 if ($new1 ne $new2) { | |
401 print "Password(new) mismatch\nBye\n"; | |
402 exit 1; | |
403 } | |
404 # OK, now begin to create! | |
405 &checkmaildir; | |
406 if (open(P, "| $ENCODER > $APOPFILE")) { | |
407 # open success | |
408 print P "$new1\n"; | |
409 close(P); | |
410 chmod 0600, $APOPFILE; | |
411 if (-s $APOPFILE) { | |
412 print "Success!\n"; | |
413 exit 0; | |
414 } | |
415 } else { | |
416 print "Cannot output to $APOPFILE\nBye\n"; | |
417 exit 1; | |
418 } | |
419 exit 0; | |
420 } |