Solved

Apache::htpasswd

Posted on 2000-04-05
11
327 Views
Last Modified: 2013-12-25
Hi,
 
 Has anyone used the apache::Htpasswd module?
 
 I'm having trouble getting useful error messages.  Here is what the man page says about errors:
 
           # If something fails, check error
           $foo->error;
 
       error;
           If a method returns an error, or a method fails, the error can be retrived by calling error()
 
 I've tried this in various forms, and all I get back is something like this:
 Apache::Htpasswd=HASH(0x80c724c)
 
 When you set a new htpasswd the module is supposed to return 1 or undef, I get a string like
 this: Apache::Htpasswd=HASH(0x818a084)
 
 Those really don't help me put any kind of error testing or
 troubleshooting into my script.  Any help would be appreciated.
 
 Here is a link to the module if anyone would like to try and help me out:
 
 http://www.cpan.org/modules/by-module/Apache/Apache-Htpassword-1.2.readm
 e
 http://www.cpan.org/modules/by-module/Apache/Apache-Htpassword-1.2.tar.g
 z
 
My question:
1.  Is this the best solution, or is there a better way?
2.  Can you give a working example so I can see how it works?
 
 Thanks in advance,
 
 --John
 
0
Comment
Question by:jeacopgh
  • 7
  • 4
11 Comments
 

Author Comment

by:jeacopgh
Comment Utility
Adjusted points from 30 to 50
0
 

Author Comment

by:jeacopgh
Comment Utility
Forgot to mention I'm using RedHat Linux 6.1 and Apache/1.3.9.

Thanks.

--John
0
 
LVL 1

Expert Comment

by:mafweb
Comment Utility
Hi,

to me (not really knowing this module), it looks like $foo->error returns a hash, not a single variable.
You can check this by using:

$err=$foo->error;
foreach $key ($err) {
  print $key.":".$err{$key}.\n;
}

hope this works (haven't used perl for a while ;-()

maf
0
 

Author Comment

by:jeacopgh
Comment Utility
Hi,

Ok, I tried what maf said, this is the error I got:

Software error:

Can't call method "error" on an undefined value at
/home/httpd/cgi-bin/pwdprot/test2.cgi line 56.


This is line 56:
               $err=$foo->error();


Do I need to add anything else to the program?

Thanks,


--John

0
 
LVL 1

Expert Comment

by:mafweb
Comment Utility
I'm not sure, but from the docs, it looks like you should use

            $err=$foo->error;

maybe this helps,

maf
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:jeacopgh
Comment Utility
Hey,

Yeah, I tried that, too, got the same error:

Software error:

Can't call method "error" on an undefined value at
/home/httpd/cgi-bin/pwdprot/test2.cgi line 56.

Line 56:
                $err=$foo->error;



Thanks,

--John
0
 
LVL 1

Expert Comment

by:mafweb
Comment Utility
could you please send me the entire program???

maf
0
 

Author Comment

by:jeacopgh
Comment Utility
Ok, a couple of notes first:

1.  I know it's nasty, I'm not the greatest programmer.

2.  The goal is to create htaccess and htpasswd files the input form on the web.

Thanks maf!

#!/usr/bin/perl
use CGI;
CGI::ReadParse(*in);
use CGI::Carp qw(fatalsToBrowser);
sub BEGIN {
        unshift (@INC, "Htpasswd.pm");
                }
use Apache::Htpasswd;

# get input
$protectdir = $in{'protectdir'};
$authname = $in{'inputtext'};
$username = $in{'username'};
$pwdir = $in{'pwdir'};
$password = $in{'password'};
$password2 = $in{'password2'};

$protectfile = $pwdir . "\.htpasswd";

# make sure password was typed correctly both times
if ($password ne $password2) {
        print "Content-type: text/html\n\n";
        print "<html><body>";
        print "Error: Invalid New Password.";
        print "</body></html>";
        print "\n";
        die "Invalid New password";
   }  
   
open (OUTPUT, ">$protectdir/.htaccess") || die "can't open $protectdir/.htaccess in write mode";
<!-- Out to htaccess file -->
close (OUTPUT);


# touch the htpasswd so it exists
        system("touch $protectfile");

        $newpw = new Apache::Htpasswd("$protectfile");
        $newpw->htpasswd("$username", "$password");

                $err=$foo->error;

if ($err eq 1) {
        print "Content-type: text/html\n\n";
        print "<html><body>";
        print "Success\n<br>";
                foreach $key ($err) {
                print $key.":".$err{$key}.\n;
                }
        print "\n<br>";
        print $newpw;
        print "\n</body></html>\n";
} else {
        print "Content-type: text/html\n\n";
        print "<html><body>";
        print "Error\n<br>";
                foreach $key ($err) {
                print $key.":".$err{$key}.\n;
                }
        print "\n<br>";
        print $newpw;
        print "\n</body></html>\n";
}
0
 
LVL 1

Accepted Solution

by:
mafweb earned 75 total points
Comment Utility
oops, I think there was kind of a misunderstanding here...
$foo was meant to be replaced by the name of your Htpasswd object.
So the line should read:

        $err=$newpw->error();

or maybe

        $err=$newpw->error;

(as mentioned, I'm not really sure about the () here, but I think the first is right)
What you do here is create a new object
(newpw=new Apache::Htpasswd(..)), tell it to add a new entry
(next line) and finally "ask" it for any errors that might have occured.

hope this helps,

maf
0
 

Author Comment

by:jeacopgh
Comment Utility
Adjusted points from 50 to 75
0
 

Author Comment

by:jeacopgh
Comment Utility
maf,

Thanks, that did it.  About 20 more minutes on my part cleaning up the script and fixing the error checking and it's done!

Thanks for the help, for some reason I just couldn't figure that one out.

--John
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now