Solved

Apache::htpasswd

Posted on 2000-04-05
11
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 

Author Comment

by:jeacopgh
ID: 2687525
Adjusted points from 30 to 50
0
 

Author Comment

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

Thanks.

--John
0
 
LVL 1

Expert Comment

by:mafweb
ID: 2689439
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:jeacopgh
ID: 2689782
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
ID: 2689838
I'm not sure, but from the docs, it looks like you should use

            $err=$foo->error;

maybe this helps,

maf
0
 

Author Comment

by:jeacopgh
ID: 2689863
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
ID: 2690102
could you please send me the entire program???

maf
0
 

Author Comment

by:jeacopgh
ID: 2690158
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
ID: 2690268
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
ID: 2690495
Adjusted points from 50 to 75
0
 

Author Comment

by:jeacopgh
ID: 2690496
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 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