END
our $usage2 = <<'END';
actions
- create [REDIRECT] [#COMMENT] (default for REDIRECT is your username)
- choose [REDIRECT] [#COMMENT] (interactively see and allocate suggestions)
+ create [GENOPTS] [REDIRECT] [#COMMENT] (default for REDIRECT is username)
+ choose [GENOPTS] [REDIRECT] [#COMMENT] (generate and interactively allocate)
update ADDR [REDIRECT] [#COMMENT]
show ADDR
list
use DBI;
use POSIX;
-our $randlength = 6;
+our $minrandlength = 6;
+our $randlength;
+our $maxrandlength = 50;
+
our $maxperuser = 10000;
our $qualdom;
our $dbh;
binmode R;
}
+sub genopt_alphanum {
+ local ($_) = @_;
+ if (m/^-l(\d+)$/) {
+ $randlength = $1;
+ die "length out of range $minrandlength..$maxrandlength\n"
+ unless ($minrandlength<=$randlength &&
+ $randlength<=$maxrandlength);
+ } else {
+ die "unknown alphanumeric generation option\n";
+ }
+}
+
+sub gendefaults_alphanum {
+ $randlength ||= $minrandlength;
+}
+
+sub genopts {
+ while (@ARGV && $ARGV[0] =~ m/^-/) {
+ my $arg = shift @ARGV;
+ last if $arg =~ m/^--?$/;
+ { no strict qw(refs); &{"genopt_$genmethod"}($arg); }
+ }
+ { no strict qw(refs); &{"gendefaults_$genmethod"}(); }
+}
+
sub action_create {
+ genopts;
my $newrow = rhsargs({'redirect'=>$user, 'comment'=>''});
prepare_create();
$newrow->{'user'} = $user;
}
sub action_choose {
+ genopts;
my $template = rhsargs({'redirect'=>$user, 'comment'=>''});
$template->{'user'} = $user;
prepare_create();
for (;;) {
last unless m/^-./;
if (s/^-l(\d+)$//) {
- $randlength = $1;
+ $minrandlength = $1;
} elsif (s/^-m(\d+)$//) {
$maxperuser = $1;
} elsif (s/^-d(\S+)$//) {