c has asked for the wisdom of the Perl Monks concerning the following question:
The script take the input from a form, which consists of username, old password and new password; and then attempts to change the listed username from oldpw to newpw.
#!/usr/bin/perl -w use strict; use Apache::Htpasswd; my $htpasswd = "/etc/htsec/motion.ht"; my $method = new Apache::Htpasswd($htpasswd); my %formdata; my @pairs; my $buffer; my $pair; my @getpairs; my $key; my $value; &parseform(); if ($formdata{username}) { $method->htpasswd($formdata{username}, $formdata{newpw}, $formdata{o +ldpw}); } print <<HTML; Content-type: text/html\n\n <html> <head><title>Password Administration</title></head> <body bgcolor="#FFFFFF"> <form method = "post" action = "https://www.lunarmedia.net/motion/ch +pass.cgi"> Username: <input type="text" length="30" name="username"><br> Password: <input type="password" length="30" name="oldpw"><br +> New Password: <input type="password" length="30" name="newpw" +><br> <input type="submit" value="Go!"><br> </body> </html> HTML sub parseform { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); if ($ENV{'QUERY_STRING'}) { @getpairs =split(/&/, $ENV{'QUERY_STRING'}); push(@pairs,@getpairs); } } else { print "Content-type: text/html\n\n"; print "<P>Use Post or Get"; } foreach $pair (@pairs) { ($key, $value) = split (/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1)) +/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1 +))/eg; $value =~ s/<!--(.|\n)*-->//g; if ($formdata{$key}) { $formdata{$key} .= ", $value"; } else { $formdata{$key} = $value; } } }
This is the uber bland code where I really just want to see the script change the password in the .htpasswd file listed. The htpasswd file has 644 perms with 'nobody' as the file owner (nobody being the account the webserver is running as)
I'm just starting to wield the perl sword with some skill, but this module business still has me back in the monastery asking master po for wisdom
humbly -c
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Apache::Htpasswd syntax questions
by thatguy (Parson) on Aug 04, 2001 at 08:34 UTC | |
by KM (Priest) on Aug 04, 2001 at 22:05 UTC | |
Re: Apache::Htpasswd syntax questions
by tadman (Prior) on Aug 04, 2001 at 08:31 UTC | |
by c (Hermit) on Aug 04, 2001 at 09:06 UTC | |
Re: Apache::Htpasswd syntax questions
by chromatic (Archbishop) on Aug 05, 2001 at 00:27 UTC |