Re: code evaluation in regexp failing intermittantly

2002-10-26 Thread Rodney Hampton
Gang,

I'm forwarding this to the list.  Sorry Danny for sending it to your 
personally.

Rodney Hampton

Danny Rathjens wrote:

Looks like you accidentally replied to just me instead of the group.
Don't ask me why we don't have a reply-to header on the list, ;)

Rodney Hampton wrote:


Perrin, Danny, et. al.

I looked over the comparison document as well as the perldocs on all 
the templating systems I could find on CPAN before embarking on this 
journey.
I really only need 3 tags: one to link the templates together, one to 
bring in images, and one to call code that can by dynamically 
inserted.  Every item in my application's database (templates, 
images, and other files) has user and group permissions that need to 
be checked on access. Thus, any templating system that did caching is 
pretty much out of the running because as soon as I revoke a user's 
privileges or change permissions on the item, I want access to change 
immediately.  Also, when an advertiser makes a change to one of 
his/her templates, it needs to propogate immediately. Additionally, I 
need to track users so I had to be able to establish and maintain a 
session so this was a definate requirement.  Also, I needed to be 
able to selectively protect certain areas of the application with 
login screens (not necessarily the same one depending on where you 
navigate).  This is the underlying architecture for a client I have 
but I intend to make it modular enough to use for future projects.  
I've done some benchmarking on what I've built already and am 
satisfied with the results.  I seem to be able to serve up 30 
concurrent connections sending dynamic content all day long and have 
it sever between 25-35 requests per second at around 300 - 375 
Kbytes/sec.  I've compiled mod_perl with DSO and it's never shown any 
memory leaks for me (YMMV).  That was done on a 851Mhz Dell Latitude 
laptop with 128MB RAM and I ran apache benchmark from this box as 
well (which skews my results but shows it can handle the load).  The 
production server need only handle up to 50,000 users per day and it 
will be on much better hardware so I think I'm in fine shape so far. 
I'd like to think that I'm heading in the right direction.  Believe 
me, I prefer to pull down modules from CPAN when possible.   For 
example, I would eventually like to chain my PerlHandlers and zip up 
the content before delivery.  There are modules to do that already so 
I won't be rewritting Apache::Filter from scratch for instance.   I'd 
also like to pretty up the html before outputting it to the client 
browser - I'm pretty sure there's a module in there for that as well.

Anyway, I'm not trying to say that what I'm doing is better or worse 
than what has come before.  I just happen to have different 
requirements and I didn't think that the other systems out there were 
going to be both lightweight and allow me to meet my need for access 
control.

Rodney Hampton
Danny Rathjens wrote:

Very useful document comparing templating systems:

  http://perl.apache.org/docs/tutorials/tmpl/comparison/comparison.html

Perrin Harkins wrote:


Rodney Hampton wrote:


Let me preface it by stating that I'm building a very simple 
templating application.




[...]


Not satisfied, I wanted to make it possible to do something like:
<% code_ref Util::Test_Util::test_expand %>
and have it swap in the text output from the sub into the 
template. That way, unlike other templating applications, I could 
get away from writing my own mini language and use the full power 
of perl in a sub called by a simple tag in the template.




Do you realize that almost every templating system on CPAN already 
does this?  If you are doing this because you think you've hit on a 
new feature, stop now and download one of those.  If you're doing 
it because hacking perl is fun and you're in no rush, then go ahead 
and have a good time.

- Perrin






Re: code evaluation in regexp failing intermittantly

2002-10-23 Thread Rodney Hampton
Thanks to some help, the answer was simply to enclose all my code 
evaluation regexp statements with eval q{}; (strangely, even those 
within an eval block already needed this same kick in the pants)
I think I'm back on track now.  Sorry for the lengthy post.

Regards,



Rodney Hampton

Rodney Hampton wrote:

 
And it works in mod_perl, but only sometimes.  I've pulled down output 
using lynx, wget, Mozilla, Konquerer, and IE.  I've made sure no 
content caching is occurring.  After shoving a few print STDERR in my 
perlHandler View.pm (also attached), I've found that it is as if 
mod_perl is ignoring the code evaluation regexp from time to time.  
Sometimes it does it, sometimes not.







code evaluation in regexp failing intermittantly

2002-10-23 Thread Rodney Hampton
Please bear with me.  I have a really weird question.  Let me preface it 
by stating that I'm building a very simple templating application.  I 
asked on perlmonks whether or not code evaluation in regexp is going to 
be deprecated and the answer I got was that this feature wasn't going 
away.  I've scripted a regexp that basically takes <% link_name 
template_faq %> and replaces this with template_faq
where template_faq is the name of the template and 12 is the template id 
in the database.  Pretty simple.

Next, I did something else pretty cool IMHO, and made it possible to do 
<% img_src_name some_image %> and have it replace this with
the approrpiate  tag thanks to a little 
magic from Image::Size.

Not satisfied, I wanted to make it possible to do something like:
<% code_ref Util::Test_Util::test_expand %>
and have it swap in the text output from the sub into the template. 
That way, unlike other templating applications, I could get away from 
writing my own mini language and use the full power of perl in a sub 
called by a simple tag in the template.  I only need to make sure that 
these code subroutines always return an expected set of values to 
indicate success or failure -- in other words, never call die in the 
subroutine.  

All of this stuff works flawlessly from the command line (see 
test_parse.pl attached).
And it works in mod_perl, but only sometimes.  I've pulled down output 
using lynx, wget, Mozilla, Konquerer, and IE.  I've made sure no content 
caching is occurring.  After shoving a few print STDERR in my 
perlHandler View.pm (also attached), I've found that it is as if 
mod_perl is ignoring the
code evaluation regexp from time to time.  Sometimes it does it, 
sometimes not.

I can provide logs to substantiate this.  I'm at a loss for why mod_perl 
would do this.  I had thought garbage collection might be failing on my 
$file variable but I've explicitly undefined it in the handler and still 
nada.

Please forgive the beta quality of the code, but I'm just trying to get 
this to work.  I'll pretty it up and break it into subs later.

My environment is thus:
Apache/1.3.26 (Unix) mod_perl/1.27 PHP/4.2.3
RedHat Linux 7.3 kernel 2.4.18-10
Dell Latitude Notebook
I can provide compile options I used to build apache, mod_perl, mod_ssl, 
and php if this is necessary.

Can any of you gurus please help!





Rodney Hampton






package Application::View;

#PerlHandler
###
# Copyright (C) 2000-2002  R.A. Hampton and Associates
# All Rights Reserved.  Proprietary and Confidential.
#==
# $Id: View.pm,v 1.21 2002/10/23 08:01:54 rhampton Exp $
#--
# Tag:         $Name:  $
# Revision:    $Revision: 1.21 $
# Date:        $Date: 2002/10/23 08:01:54 $
# Author:      $Author: rhampton $
# Description:

use strict;
use Apache::Constants   qw/ :common /;
use Util::Constants qw/ :errors /;
use Util::Parse_Handler qw/ ph_parse_input ph_abort /;
use Util::Outputqw/ expandStruct /;#necessary for code_ref eval
use Rendering::Common qw/ common_html_header common_html_footer common_session_utility 
common_return_rendering_object/;
use Disk::Disk_Object_Read; #read-only disk object
use Business_Logic::User_Object;
use Business_Logic::Item_Object;
use IO::File;
use Image::Size qw/ html_imgsize /;
use Safe;

## BEGIN handler
sub handler {
my $r = shift;

##BEGIN figure out if we are under /ceoadmin or /advertiser so we can react 
accordingly later
my $code;
my $href;
my $ceoadmin_flag=0;
my $advertiser_flag=0;
my $action = $r->uri;
#must strip of the leading slash
$action =~ s/^\///;
my ( $type, @directions ) = (split /\//, $action);
if ($type eq 'ceoadmin'){$ceoadmin_flag=1;}
if ($type eq 'advertiser'){$advertiser_flag=1;}
##END figure out if we are under /ceoadmin or /advertiser so we can react 
accordingly later

##BEGIN parse inputs
my ($input,$msg_i) = ph_parse_input (
r   => $r, 
args_list => ['q_act','q_srn'],
);

unless($input) {
ph_abort($r,"Error parsing http arguments:",$msg_i);
return DONE;
}
##END parse inputs

##BEGIN instantiate disk_object_read - database handle comes along for the ride
my 
($disk_object,$disk_object_error)=Disk::Disk_Object_Read->new();#file_id not 
identified at this poi

Apache::Session - suggestion for man page

2002-10-16 Thread Rodney Hampton

1)I am using Apache::Session::File to maintain state information (just a 
user_id and a few small items).

2)The man page for Apache::Session indicates that the following regexp 
should be used to find the session cookie.
$cookie =~ s/SESSION_ID=(\w*)/$1/;

3)This $cookie value is then used in a tie statement.  I was having 
intermittant trouble with MD5.pm dying and giving me internal server errors.
The log file looked like this:
[Wed Oct 16 21:45:47 2002] [error] Died at 
/usr/lib/perl5/site_perl/5.6.1/Apache/Session/Generate/MD5.pm line 40.

4)I found that when I had multiple cookies MD5 would always bomb out 
because the regexp was just stripping out the words SESSION_ID=

5)I added a few print STDERR statements and the log file looked like this:
in common_session_utility 0
cookie is 
laptop=P&admin&Hash&9fa0065cd19a168c598a6ada6ec11917&U&Administrator; 
SESSION_ID=d1a16efb540ac0cb16236f7782183c12
cookie is 
laptop=P&admin&Hash&9fa0065cd19a168c598a6ada6ec11917&U&Administrator; 
d1a16efb540ac0cb16236f7782183c12 after regexp
in common_session_utility 1
IN GENERATE MD5 session date is 
laptop=P&admin&Hash&9fa0065cd19a168c598a6ada6ec11917&U&Administrator; 
d1a16efb540ac0cb16236f7782183c12
[Wed Oct 16 21:45:47 2002] [error] Died at 
/usr/lib/perl5/site_perl/5.6.1/Apache/Session/Generate/MD5.pm line 40.

6)After I changed the regexp, things started working well enough.
 $cookie =~ s/^.*SESSION_ID=(\w*).*$/$1/;

7)I suggest that the man page for Apache::Session so that the regexp 
example accomodates sites with multiple cookies being set.

I hope this makes some sense.

Regards,




Rodney Hampton




Re: $r->requires

2002-10-16 Thread Rodney Hampton

Geoffrey Young wrote:

>
> $r->requires() is read-only.  conditional authentication is a bit 
> counterintuitive - you can't set up authentication where it doesn't 
> already exist because Apache won't run the authentication phase 
> without a Require directive in your httpd.conf.  the solution is to 
> turn on authentication for everything, then turn it off where you 
> don't need/want it.  see recipe 13.5 in the cookbook for more details. 
>  the code for 13.5 can be found here:
>
Geoffrey,

Thanks for the tip.  Allow me to flesh out this example a bit and the 
solution I employed (thanks to Kip Cranford for having some helpful code 
I was able to look at).  Basically I'm creating a site where /admin and 
/advertiser should have login forms for administrative users and 
advertisers respectively while everything under / should not require any 
type of access control.  

Within the PerlTransHandler:

my $action = $r->uri;
#must strip of the leading slash
$action =~ s/^\///;
my ( $type, @directions ) = (split /\//, $action);

if ($type eq 'admin'){
my ( $ret, $error_data ) = check_handlers( ['Apache::Control_admin'] );
if ($ret) {
  $r->set_handlers( 'PerlAccessHandler' => [\&_check_access] );
  $r->push_handlers( 'PerlTransHandler' => 'Apache::Control_admin' );
  $r->filename( $r->server_root_relative . "htdocs" );
  return DECLINED;
} else {
  $r->pnotes( 'ap_error_data_h', $error_data );
  my $redir = "http://"; . $r->pnotes('ap_server_name_s') . "/error";
  $log->debug("Doing internal redirect to /error");
  $r->internal_redirect($redir);
  $r->filename( $r->server_root_relative . "" );
  return DONE;
} ## end else
#end type eq ceoadmin
  }elsif ($type eq 'advertiser' ){
blah blah blah

Despite not having a location tag anywhere, nor a require valid-user 
directive, the above code
is able to accomplish my objective: loading an AccessHandler on the fly 
from the TransHandler for specific urls on my site.  Although, I must 
admit that I'm not sure why it is working.  _check_access is within the 
same TransHandler module
so my assumption is that the reference to this sub gets executed 
immediately and the result (OK DONE or DECLINED) gets shoved into the 
set_handlers('PerlAccessHandler' => 'result gets shoved here') and then 
my stacked TransHandler proceeds to the next module 
(Apache::Control_admin).

Any explanation of why this actually works would be appreciated.

Rodney Hampton





$r->requires

2002-10-16 Thread Rodney Hampton

Does anyone have an example of how to use $r->requires?
I cannot find Apache::AuthzAge for an example of its use.
I'm trying to handle all my location directive specific stuff in a 
TransHandler and simply want to
set require valid-user for some specific paths.

Thanks,



Rodney Hampton




Re: Question...

2002-02-14 Thread Rodney Hampton

Actually, you can use the onUnload handler in the body tag.
http://developer.netscape.com/docs/manuals/communicator/jsref/evnt24.htm

Rodney Hampton

Jon Robison wrote:
> 
> On page leave?  Well I think you can of course use javascript on all the
> links on the page, but I don't believe you can do much about the user
> typing in a new url in the browser. . .
> but that's just IMHO.
> 
> --Jon
> 
> Ryan Parr wrote:
> >
> > I think I'm missing something...
> >
> > If you set a session cookie (i.e. one with no expiry time) then the cookie
> > will be deleted immediately upon browser close, forcing the user to login
> > again if they've closed their browser instance.
> >
> > If you don't use cookies and allow basic auth then the exact same behavior
> > is called, forcing the user to re-login only if they've closed that browser
> > instance.
> >
> > Is there someway to expire cookies on page leave, or is this the smartass
> > thing you were referring to? :)
> >
> > -- Ryan Parr
> >
> > - Original Message -
> > From: "Jon Robison" <[EMAIL PROTECTED]>
> > To: "Ron Beck" <[EMAIL PROTECTED]>
> > Cc: <[EMAIL PROTECTED]>
> > Sent: Tuesday, February 12, 2002 12:28 PM
> > Subject: Re: Question...
> >
> > > Cookies!
> > >
> > > /me is in smartass mode today.
> > >
> > > --Jon
> > >
> > > Ron Beck wrote:
> > > >
> > > > Hello all,
> > > > I need to know how to clear the $ENV variables.  For example, I use a
> > > > .htaccess file for specific directories which requires the user to enter
> > > > userID and password.  When they exit the page, I want them to have to
> > > > re-enter userID and passwd if they enter the page again.  Does anyone
> > > > know how this is accomplished?
> > > >
> > > > TIA,
> > > > Ron