I am having some problems with the following script. This is my first attempt at using an object oriented module, so there is a huge learning curve factor going on here.
This is what i would call Alpha code. There is a lot of error checking that I have not included. I am really looking for more experience getting used to the module.

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:&nbsp;<input type="text" length="30" name="username"><br> Password:&nbsp;<input type="password" length="30" name="oldpw"><br +> New Password:&nbsp;<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


In reply to Apache::Htpasswd syntax questions by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.