Re: Mod-Perl Installed next Q
You should be able to find just about all the answers here: http://perl.apache.org/guide -- >From: "Purcell, Scott" <[EMAIL PROTECTED]> >To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]> >Subject: Mod-Perl Installed next Q >Date: Fri, Jun 15, 2001, 4:43 PM > >Hello, >Thank you all and Ron for the link to savage.net to get my >Apache/Perl/ModPerl installed. >I was successful about 10 minutes ago and my machine looks happy. > >Well, now that the package is running, how do I use the persistant memory, >do the .pl files need to be named something different. Or how does this >mechanism work by putting them in the cgi-bin? Do I just call a module in my >code? I want to just play with the server but need to use the mod-perl >(persistant behavior). I have some clean code that I would like to move into >a bin dir and check. > >What does one have to do to make this occur. Any links, or examples would be >helpful. > >Thanks again, >Scott >
Re: That annoying DB guy again... ;-)
"Jonathan M. Hollin" wrote: > I know you all want me to go away, so I apologise for the noise. Anyway, at > http://perl.apache.org/guide/databases.html#Why_Relational_SQL_Databases > there is a reference to an "Apache::DBI" module. I DON'T have this module > installed - is this the reason why CGI connects work yet mod_perl requests > don't? I wonder... That should not be a problem. Apache::DBI just allows for persistent DB connections but DBI alone should work just fine > > > Kindest regards, > Jonathan M. Hollin > Digital-Word.com > > LATEST NEWS: Digital-Word.com releases e-gateway v3.0. See: > http://e-gateway.1-1IT.Net/ for further details... > > IMPORTANT: This e-mail and the information that it contains may be > confidential, legally privileged and protected by law. Access by the > intended recipient only is authorised. Any liability (in negligence or > otherwise) arising from any third party acting, or refraining from acting, > on any information contained in this e-mail is hereby excluded. If you are > not the intended recipient, please notify the sender immediately and do not > disclose the contents to any other person, use it for any purpose, or store > or copy the information in any medium. Copyright in this e-mail and > attachments created by us belongs to The Digital Word Company Limited: the > author also asserts the right to be identified as such and object to any > misuse. > > The Digital Word Company Limited. Registered in the United Kingdom, number: > 3416629. Registered Office: Batley Business & Technology Centre, > Technology Drive, Batley, WF17 6ER, England. > > Internet: http://v3.digital-word.com/
Re: Connection to MySQL DB fails when mod_perl enabled...
Ken Williams wrote: > [EMAIL PROTECTED] (Jonathan M. Hollin) wrote: > >:: Okay, last idea: you say you can connect to mysql from the command line, > >:: from regular CGI, and from PHP. I'm guessing that in all of those > >:: situations, you're acting as the same user (win2k user, not mysql user). > >:: However, under mod_perl you'll be acting as whatever user your web > >:: server runs as. That's probably the only real difference between > >:: mod_perl and the other situations. > >:: > >:: So if you can become that user and try connecting to the database, > >:: perhaps you can get more insight into the problem. > > > >I would like to try that (anything to get this working). Er... how do I do > >that? > > Under win2k, I have no idea. Under unix, you'd use "su" or a similar > identity-switching mechanism. You'll probably have to find a win2k > person to help with that. > > Let me also gently suggest that you should take this off-list, as there > have been a lot of messages on your topic already. But please post your resolution as it may be useful to someone else down the road. > > > ------ > Ken Williams Last Bastion of Euclidity > [EMAIL PROTECTED]The Math Forum
Re: Connection to MySQL DB fails when mod_perl enabled...
"Jonathan M. Hollin" wrote: > This is driving me crazy... is there anything special I need to do when > using DBI (DBD::MySQL) with mod_perl. A script that works just fine sans > mod_perl dies with error 500 (Internal Server Error) when mod_perl is > enabled for that file type: > > Web Server: Apache/1.3.19(Win32) mod_perl/1.24_01 on a Windows 2000 > server -- connecting to a MySQL 3.23.38-nt DB-server. > > Sample of httpd.conf: > > # BEGIN MOD_PERL CONFIG > LoadModule perl_module modules/ApacheModulePerl > ScriptAlias /perl-bin/ "perl-bin/" > PerlSendHeader On > > SetHandler perl-script > PerlHandler Apache::Registry > Options ExecCGI > > > > SetHandler perl-script > PerlHandler Apache::Registry > Options ExecCGI > > > > SetHandler perl-script > PerlHandler Apache::Registry > Options ExecCGI > > > # END MOD_PERL CONFIG > > Error Log entry: > > [Tue May 22 00:13:09 2001] nul: DBI->connect failed: Can't connect to MySQL > server on 'localhost' (10061) at e:/pad/htdocs/internet/system/frontpage.cgi > line 29 > [Tue May 22 00:13:09 2001] [error] Can't call method "prepare" on an > undefined value at e:/pad/htdocs/internet/system/frontpage.cgi line 30. > > Perl Code: > > use DBI(); > $driver = "mysql"; > $dsn = "DBI:$driver:database=shapeshifter;host=localhost"; > $dbh = DBI->connect($dsn, dbusrname, dbpassword); how bout adding a 'or die DBI->errstr' to the above line to find out whats happening. > > my $sth = $dbh->prepare("SELECT * FROM frontpage"); > $sth->execute(); > while (my $ref = $sth->fetchrow_hashref()) { > $body .= qq~Found a row: id = $ref->{'serial_number'}, name = > $ref->{'position'}~; > } > $sth->finish(); > $dbh->disconnect(); > > Any help appreciated. I have RTFMs but I can't reach any conclusions about > contention between mod_perl and MySQL... > > Kindest regards, > Jonathan M. Hollin > Digital-Word.com
Re: Pnotes not working
Thank you very much Vivek. That was exactly what was happening. I did manage to figure it out eventually. Thanks for your help. Mike Vivek Khera wrote: > >>>>> "MC" == Mike Cameron <[EMAIL PROTECTED]> writes: > > MC> package My::Main; > MC> sub handler{ > MC> my $r = new Apache::Request(shift); > MC> my $var = $r->pnotes("MY_HANDLER"); > MC> $r->log_error("This is var $var->[0]"); > MC> } > > Try this: > > my $var = ($r->prev || $r)->pnotes("MY_HANDLER"); > > You might be getting called as a subrequest rather than the main > request. > > -- > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > Vivek Khera, Ph.D.Khera Communications, Inc. > Internet: [EMAIL PROTECTED] Rockville, MD +1-240-453-8497 > AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/
Re: Authorization question and subdirectories
I got it working alright with the directive as follows SetHandler perl-script AuthType Consignline AuthName NONE PerlAuthenHandler Consignline::Shop::User PerlAuthzHandler Consignline::Shop::User->authorize require valid-user PerlHandler Consignline::Shop PerlSetVar DEBUG 6 PerlSetVar Config /home/user/Consignline.pm AuthName Admin require user administrator AuthName affiliate require group affiliate will the above not work the same using the location directive? It didn't for me unless I missed something obvious. Thanks for your responses. Chris Strom wrote: > Mike Cameron <[EMAIL PROTECTED]> writes: > > > Is it possible to have the same PerlAuthzHandler use different require's > > > > on a subdirectory once a user has been authorized for a parent > > directory? Here is what i would like to be acle to do: > > > > > > SetHandler perl-script > > AuthType MyAuth > > AuthName MyAuth > > PerlAuthenHandler MyAuth->authenticate > > PerlAuthzHandler MyAuth->authorize > > require valid-user > > How about: > > require valid-user administrator > > > > > shouldn't this be ? > > > > > > > SetHandler perl-script > > AuthType MyAuth > > AuthName MyAuthSupertight > > PerlAuthenHandler MyAuth->authenticate > > PerlAuthzHandler MyAuth->authorize > > require user administrator > > > > > > authenticate is working fine and when I debug the $r->requires in > > authorize it only returns the 'valid user' requirement and not the "user > > > > administrator" requirement even when i access /restricted. Right now > > the code in authorize just prints the requirements via $r->log_error() > > then returns OK; What am I missing? Why doesn't authorize see the > > second requirement for the URI /restricted?
Authorization question and subdirectories
Is it possible to have the same PerlAuthzHandler use different require's on a subdirectory once a user has been authorized for a parent directory? Here is what i would like to be acle to do: SetHandler perl-script AuthType MyAuth AuthName MyAuth PerlAuthenHandler MyAuth->authenticate PerlAuthzHandler MyAuth->authorize require valid-user SetHandler perl-script AuthType MyAuth AuthName MyAuthSupertight PerlAuthenHandler MyAuth->authenticate PerlAuthzHandler MyAuth->authorize require user administrator authenticate is working fine and when I debug the $r->requires in authorize it only returns the 'valid user' requirement and not the "user administrator" requirement even when i access /restricted. Right now the code in authorize just prints the requirements via $r->log_error() then returns OK; What am I missing? Why doesn't authorize see the second requirement for the URI /restricted?
Pnotes not working
I am having trouble getting pnotes to work and wonder if there is something obvious I am missing. in PerlAuthenHandler I have gone back to the Apache man page and tried to recreate the example given there but to no avail. Below is the code: package My::User; sub handler{ my $r = new Apache::Request(shift); $r->log_error("Are we actually here?"); $r->pnotes("MY_HANDLER" => [qw(one two three)]); } # seperate file package My::Main; sub handler{ my $r = new Apache::Request(shift); my $var = $r->pnotes("MY_HANDLER"); $r->log_error("This is var $var->[0]"); } in httpd.conf SetHandler perl-script AuthType test AuthName test PerlAuthenHandler My::User require valid-user PerlHandler My::Main when I check the error log it is hitting the My::User::handler but nothing is returned to $var in My::Main. if i just check $r->pnotes() it returns an empty hash ref. On another note i originally had My::User::handler named My::User::authenticate but when called from httpd.conf I got an error "Could not locate object method authenticate via package My::User." even though I did preload both My::Main and My::User in startup.pl and also added a PerlModule My::User to httpd.conf just to be sure. perhaps the two are related but I cannopt figure out either for the life of me. any help would be greatly appreciated. OS RH7.0 apache 1.3.14 mod_perl 1.24_01 php/4.03 mod_ssl/2.71 openSSL/0.9.6
Re: Global Variables Question
http://perl.apache.org/guide/porting.html#Configuration_Files_Writing_Dy Guide Good! "Warren D. Johnson" wrote: > Hello All, > > I apologize if this is in a FAQ somewhere. > > I have a script, lets call it test.pl. Test.pl requires in config.pl. > > Test.pl uses variables (via use vars) from config.pl. These variables are > defined and given values in config.pl. AFter the first usage of test.pl, > the variables we are pulling in from config.pl no longer have values. So > it's something like this: > > config.pl>>> > > use vars ($G_ROOTPATH); > $G_ROOTPATH = "/home/warren"; > > < > test.pl>>> > > require config.pl; > > use vars ($G_ROOTPATH); > # at this point, G_ROOTPATH is inherited from config.pl and has the value of > /home/warren > > <<< > On the first run of the script G_ROOTPATH in test.pl has the value of > home/warren... subsequent runs, it does not. > > I'm a little confused as to exact ways modperl handles global variables. > Anyone have a simple tweak for this? Or do I have to make a config package? > > Thanks in advance!
Re: AuthenHandler Problems
Dave Greco wrote: > I am having some serious problems with a custom AuthenHandler. Basically, > it looks up users/passwords/groups in a database. The problem is whenever I > encounter a bad password/username, I want the dialog box to reappear asking > for them. Instead, the 401 error page is being displayed. Below is the > config and most of the code: > > > Options Indexes ExecCGI > PerlAuthenHandler Apache::AuthDir > AuthType Basic > AuthName "show.gleim.com" > require valid-user > > > package Apache::AuthDir; > > use Apache::Constants qw(:common); > > use DBI; > $dbh = DBI->connect('DBI:mysql:SGC'); > > sub handler { > > $req = shift; > > > return OK unless $req->is_initial_req; > How about redirecting the error back to the original URI, that may work $req->custom_response(AUTH_REQUIRED,"/php/show.gleim.com"); > > my( $res, $passwd ) = $req->get_basic_auth_pw(); > return $res if $res != OK; > > my $user = $req->connection->user; > my $uri = $req->uri; > my $subr = $req->lookup_uri($uri); > my $filename = $subr->filename; > > # Matches /php/show.gleim.com/(oranges/) > $uri =~ /^\/php\/show.gleim.com\/(.*)$/; > $dir = $1; > > #$req->server->log_error("$dir - $user - $passwd"); > > # check user and password > if ( ! checkPassword($user, $passwd) ) { > $req->note_basic_auth_failure; > return AUTH_REQUIRED; > } > > if (-d $filename) { > # Remove any trailing / > $dir =~ s/\/$//; > > # check user and directory > if (! checkDirectory($user, $dir) ) { > #$req->server->log_error("$user tried to access $dir but > couldnt"); > return FORBIDDEN; > } > } > > if (-f $filename) { > if (! checkFile($user, $file) ) { > #$req->server->log_error("$user tried to access $file but > couldnt"); > return FORBIDDEN; > } > } > > # Else they are OK > $req->connection->auth_type('Basic'); > $req->connection->user($user); > return OK; > } > > > Dave Greco > [EMAIL PROTECTED] > Network Administrator > Gleim Publications, Inc. > (800) 87-GLEIM x312 > http://www.gleim.com >
Re: Authhandler
Kiran k wrote: > Hi , > I am having problems with the stacked handlers , i have enclosed the code below , > > the error i get is undefined value ($r) in sub authenticate > > package SetRealm1; > > use Apache; > use Apache::Constants qw(:common); > use DBI; > use diagnostics; > sub handler { > my $r = shift; > > $r->push_handlers(PerlAuthenHandler => \authenticate()); the push_handlers method does not pass the Apache request object as its first argument. > >## uri's are >return OK unless is_protected($r); >my $realm = get_realm($r); >my $authheader = 'Basic realm="'.$realm.'"'; >$r->header_out("WWW-Authenticate" ,$authheader); > >## Return 401 to browser and prompt for login >$r->status(AUTH_REQUIRED); >$r->send_http_header("text/html"); > > return AUTH_REQUIRED; > } > > sub get_realm { >my $r = shift; >return " Test".int(rand(100)) if ($r->uri =~ /\/test/); > } > > sub is_protected { > my $r = shift; > my @protected = ('\/test','\/icons'); > > for (@protected) { return 1 if ($r->uri =~ /$_/); } > return 0; > } > > sub authenticate { > my $r = shift; > Add this $r||=Apache->request; > > return OK unless $r->is_initial_req; > > my ($res,$password) = $r->get_basic_auth_pw; >$r->log_reason("res is $res pword is $password "); > return $res if $res != OK; > > my $username = $r->connection->user; >unless ($username && $pass) > { >$r->note_basic_auth_failure; >$r->log_reason("Did not provide username"); >return AUTH_REQUIRED; > } > ### check against database > >return OK; > > } > > 1; > > thanks in advance > > Kiran > > _ > Chat with your friends as soon as they come online. Get Rediff Bol at > http://bol.rediff.com
Re: access log and the request object
How about writing your own log handler PerlLogHandler My::LogModule or in your code $r->push_handler(PerlLogHandler => \&MyLoghandler); sub MyLoghandler{ my $r=Apache::Request; code to log info to file } the push_handler method does not pass the request object to the subroutine. Andrew Lau wrote: Hi, I am currently developing a Perl based apache module and was wondering if such a functionality was available. From within the module would it be possible to modify the request object so that the url that gets logged to the access.log is different from what the client actually requested? For example, if a client requested /file which was redirected to this module could it modify either the request object or some apache internal so that it gets written in the access log as /file?session=1234567890abcdef . I apologize if this is readily available from some FAQ as i have been unable to find this information. Thanks for your time. Sincerely, Andrew Lau Andrew Lau Massachusetts Institute of Technology 2000 [EMAIL PROTECTED] http://web.mit.edu/amlau/www
Re: Storable (lock_store lock_retrieve) question
Perrin Harkins wrote: > > I am currently using Storables lock_store and lock_retrieve to maintain > > a persistent data structure. I use a session_id as a key and each data > > structure has a last modified time that I use to expire it. I was under > > the impression that these two functions would be safe for concurrent > > access, but I seem to be getting 'bad hashes' returned after there is an > > attempt at concurrent access to the storable file. > > (You're not using NFS, right?) Correct > > > What are the specifics of your bad hashes? Are they actually corrupted, or > do they just contain data that's different from what you expected? The error(which i neglected to post, oops!) is --begin error message--- [error] Bad hash at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/_retrieve.al) line 275 at User.pm line 115 --end error message--- Where line 115 of User.pm is: my $hr=lock_retreive($file); > The > lock_retrieve function only locks the file while it is being read, so > there's nothing to stop a different process from running in and updating the > file while you are manipulating the data in memory. Then you store it and > overwrite whatever updates other processes may have done. If you want to > avoid this, you'll need to do your own locking, or just use Apache::Session. > - Perrin
Storable question (More info)
Sorry, I am running mod_perl 1.24_01, Apache 1.3.19, on Redhat 7.0 Storable 1.011
Storable (lock_store lock_retrieve) question
I am currently using Storables lock_store and lock_retrieve to maintain a persistent data structure. I use a session_id as a key and each data structure has a last modified time that I use to expire it. I was under the impression that these two functions would be safe for concurrent access, but I seem to be getting 'bad hashes' returned after there is an attempt at concurrent access to the storable file. Any pointers would be appreciated. Below is a simplified example of what I am doing. my $hr=lock_retrieve("my_file"); for(keys %{$hr}){ delete $hr->{$_} if ($hr->{$_}->{time} < time- $session_length) } # do stuff here $hr->{sid}->{other_stuff}=$whatever; # restore file lock_store($hr,"my_file"); P.S. Thanks to all who contribute regularly on this list. I find it most enlightening
Re: mod_perl based Authentication ...
Try this http://search.cpan.org/search?mode=module&query=Apache%3A%3AAuth I found browsing existing code and implementing existing modules really helps a guy understand the whole process. Sumit Babu wrote: > Hi, > I am very new to mod_perl, and would like to know > if there are any pointers that provide help/examples > for authentication for web sites. Although I am > familiar with the cgi scripting, I have not written > any kind of authentication on my own. So, if somebody > can give some good pointers to this it will be of > great help to me. > > Thanks for your time and help. I have joined this list > of-late and I am sorry if this is answered earlier. > > Regards, > > > > __ > Do You Yahoo!? > Get email at your own domain with Yahoo! Mail. > http://personal.mail.yahoo.com/?.refer=text
Re: Handler without handler()
I believe that you need to load your module first, either in a startup file or with PerlModule Me::MyHandler Gene Dascher wrote: > I have a handler that I want to contain all of my methods for access > control, authentication and authorization. I have created the file with 3 > different methods named access($$), authentication($$) and > authorization($$). I have these methods set up thusly in the httpd.conf > file: > > > PerlHandler Apache::Registry > AuthType Me::MyHandler > AuthName Me > PerlAccessHandler Me::MyHandler->access > PerlAuthenHandler Me::MyHandler->authenticate > PerlAuthzHandler Me::MyHandler->authorize > PerlInitHandler Apache::StatINC > PerlSetVar StatINCDebug On > require valid-user > > > Unfortunately, every time I try and access a cgi in that directory, I get > the following errors: > > Can't locate object method "access" via package "Me::MyHandler" > access.pm: Can't locate access.pm in @INC > > So I have a couple of questions: > 1) Can I write a handler that doesn't have a method named 'handler'? > 2) If so, what do I have to put in the httpd.conf file to allow Apache to > properly access the handler methods? > > Thanks, > > Gene Dascher
Re: push_handlers question
Thanks all. My real question was not so much HOW to fix but more WHY do i need to fix. I did not realize that using push_handlers would not send the Apache request to the method handler. Geoffrey Young wrote: > > -Original Message- > > From: Robert Landrum [mailto:[EMAIL PROTECTED]] > > Sent: Monday, March 05, 2001 11:19 AM > > To: Geoffrey Young; 'Mike Cameron' > > Cc: [EMAIL PROTECTED] > > Subject: RE: push_handlers question > > > > > > At 10:36 AM -0500 3/5/01, Geoffrey Young wrote: > > > > > Thanks for the suggestion, but what i really want to know is > > >> > why is the > > >> > request object passed if I call the module directly from > > >> > http.conf and not > > >> > when I use the push handlers method? Are the two methods not > > >> > functionally > > >> > equivalent? Everything works fine when the handler is set in > > >> > httpd.conf. > > >> > > >> according to the mod_perl pocket reference (p20) method > > >> handlers do not get > > >> the request object passed to them > > > > > >I should have said method handlers that are set up via > > push_handlers() don't > > >have the request object passed to them. > > > > > >for normal method handlers, > > >$self = shift; > > >$r = shift; > > > > > > > > Couldn't you fake it? > > > > $r->push_handlers( > > PerlHandler => sub{ unshift @_, Apache->request; goto > > &real_handler; } > > ); > > there's always more than one way :) > > --Geoff > > > > > Robert Landrum > > > > > > >[snip] > > > > > > > > > > -- > > "Will hack Perl for food." > >
Re: push_handlers question
Thanks for the suggestion, but what i really want to know is why is the request object passed if I call the module directly from http.conf and not when I use the push handlers method? Are the two methods not functionally equivalent? Everything works fine when the handler is set in httpd.conf. Mike Geoffrey Young wrote: > > -Original Message- > > From: Mike Cameron [mailto:[EMAIL PROTECTED]] > > Sent: Sunday, March 04, 2001 11:59 PM > > Cc: modperl > > Subject: push_handlers question > > > > > > I am trying to sub class Apache::AuthCookieURL and would like to use > > $r->push_handlers(PerlAuthenHandler => My::Class->authenticate); > > the push_handler is set in a handler called from httpd.conf on the > > PerlInitHandler phase but the authenticate routine does not > > seem to be getting > > the apache request object passed to it as I get a can't call > > dir_config on an > > udefined value error. > > my $r = Apache->request; > > HTH > > --Geoff > > > > > I'm sure I am missing something simple but can someone point > > it out to me. > > > > Thanks > >
push_handlers question
I am trying to sub class Apache::AuthCookieURL and would like to use $r->push_handlers(PerlAuthenHandler => My::Class->authenticate); the push_handler is set in a handler called from httpd.conf on the PerlInitHandler phase but the authenticate routine does not seem to be getting the apache request object passed to it as I get a can't call dir_config on an udefined value error. I'm sure I am missing something simple but can someone point it out to me. Thanks