Values of an array..
I dunno if it's an array or a reference ot an array anymore, heh. Whats happening, is instead of this thing pulling all 3 of my domains from a database, it's pulling the first domain in the list as many times as I have domains for. So when I only had 2 domains in the db for myself, it listed hte first twice. I added a 3rd ot test the theory, and behold, I get hte first one 3 times. Here is some massive subroutinage.. sub post_search_form { my $state = shift; my %args = $state-{q}; $state-{template} = 'generic.tmpl'; $state-{title} = User Search; my $blah = ; my $where; my %search; $search{USER} = $state-{q}{user} if $state-{q}{user}; $search{ISP} = $state-{q}{isp} if $state-{q}{isp}; $search{PWORD} = $state-{q}{pword} if $state-{q}{pword}; if ($state-{q}{name}) { ($search{FIRST}, $search{LAST}) = split( ,$state-{q}{name}); } $search{H_PHONE} = $search{W_PHONE} = $search{D_PHONE} = $search{C_PHONE} = $state-{q}{phone} if $state-{q}{phone}; $search{EMAIL1} = $search{EMAIL2} = $search{EMAIL3} = $search{EMAIL4} = $state-{q}{email} if $state-{q}{email}; $search{STATICIP} = $state-{q}{staticip} if $state-{q}{staticip}; $search{DOMAIN} = $state-{q}{domain} if $state-{q}{domain}; $search{ACCNUM} = $state-{q}{accnum} if $state-{q}{accnum}; foreach (keys %search) { if ($_ eq DOMAIN) { $where .= domain.$_ LIKE \\%$search{$_}\%\ AND ; } elsif ($_ eq m/PHONE/) { $where =~ s/ AND $/ OR /; $where .= users.$_ LIKE \\%$search{$_}\%\ OR ; } else { $where .= users.$_ LIKE \\%$search{$_}\%\ AND ; } } $where =~ s/ OR $//; $where =~ s/ AND $//; my %user_list = get_users($where); foreach (keys %user_list) { my $user = $_; foreach (@{$user_list{$user}{DOMAIN}}) { $user_list{$user}{DOMAINS} .= $user_list{$user}{DOMAIN}[$_],; } chop($user_list{$user}{DOMAINS}); $blah .= trtd$_/tdtd$user_list{$_}{ISP}/tdtd$user_list{$_}{PWORD}/tdt d$user_list{$_}{FIRST} $user_list{$_}{LAST}/tdtd$user_list{$_}{H_PHONE},$user_list{$_}{W_PHONE} ,$user_list{$_}{C_PHONE},$user_list{$_}{D_PHONE}/tdtd$user_list{$_}{EMAI L1},$user_list{$_}{EMAIL2},$user_list{$_}{EMAIL3},$user_list{$_}{EMAIL4}/td td$user_list{$_}{STATICIP}/tdtd$user_list{$_}{DOMAINS}/tdtd$user_ list{$_}{ACCNUM}/td/tr; } $args{body} =EOF; center table width=100% border=1 trtduser/tdtdisp/tdtdpassword/tdtdname/tdtdphone/tdtd email/tdtd static ip/tdtddomain/tdtdservice number/td/tr $blah /table /center EOF return output_html($state, %args); } sub get_users { my $where = shift; my %search; my %user_list; my $sth = $Sql-select(ISP,USER,PWORD,FIRST,LAST,H_PHONE,W_PHONE,C_PHONE,D_PHONE,EMAI L1,EMAIL2,EMAIL3,EMAIL4,STATICIP,ACCNUM,users,$where); while (my $row = $sth-fetchrow_hashref) { $user_list{$row-{USER}} = { ISP = $row-{ISP}, PWORD = $row-{PWORD}, FIRST = $row-{FIRST}, LAST= $row-{LAST}, H_PHONE = $row-{H_PHONE}, W_PHONE = $row-{W_PHONE}, C_PHONE = $row-{C_PHONE}, D_PHONE = $row-{D_PHONE}, EMAIL = $row-{EMAIL}, STATICIP= $row-{STATICIP}, ACCNUM = $row-{ACCNUM}, }; } foreach my $user (keys %user_list) { $sth = $Sql-select(DOMAIN,domain,USER='$user'); while (my $row = $sth-fetchrow_hashref) { push @{$user_list{$user}{DOMAIN}}, $row-{DOMAIN}; warn $row-{DOMAIN}; } } return %user_list; } That warn statement in sub get_users generates this in my error_log file www.blah.org at /home/httpd/ttms/perl/SQLCrap.pm line 145. www.boop.com at /home/httpd/ttms/perl/SQLCrap.pm line 145. www.fucker.com at /home/httpd/ttms/perl/SQLCrap.pm line 145. And yet displayed on the webpage is www.blah.org,www.blah.org,www.blah.org So uh... what am I doing wrong? Dennis
Re: Values of an array..
shouldnt 'my $user' be outside the foreach loop? No, it's supposed to be changed each iteration through the loop. Basically it saves $_ to something else, so the next foreach loop doesn't overwrite it, since I need it's value as a key for the hash the next loop creates. Dennis
Re: Values of an array..
Dennis Stout wrote ... my %user_list = get_users($where); foreach (keys %user_list) { my $user = $_; foreach (@{$user_list{$user}{DOMAIN}}) { $user_list{$user}{DOMAINS} .= $user_list{$user}{DOMAIN}[$_],; } chop($user_list{$user}{DOMAINS}); ... $user_list{$user}{DOMAINS} .= $user_list{$user}{DOMAIN}[$_],; That line is the culprit. $_ contains each domain name as a text string. Which evaluates to 0 when used as an integer, which then gives the first entry in the array. Thus you get the first entry in the array as many times as you have entries in the array. Try changing that to a regular (indexed) for loop and that should fix it. Good eye, I was too busy thinking of hashes and things. I hate array's. Should just be $user_list{$user}{DOMAINS .= $_,; huh? Thanks Dennis
Variables
In this project I'm making (database), I have several variables with a potential for a large amount of information to be held in them. They're all hashes. Some are hashes of hashes... There is a tech_list, which holds information about each technician. There is a queue_list which holds an ID and a queue name (to interact with a db) There is a list of ISP's (we're the help desk for 3, and constantly looking for more) There is a list of service plans (dialup, 256k/512k/768k dsl..) There is a list of operating systems.. A list of browsers... All the lists have an ID component and a name component, so it's used in the context of DEFANGED_select name=osDEFANGED_option value=$_$list{$_}/DEFANGED_option/DEFANGED_select (where $_ is the current iteration of a foreach loop and everything in the option tags is created as it iterates...) Is there a way I could get these variables populated on server start and never loaded again unless the database was changed? So in my subroutine for posting an event that changed it I could call repopulate_queue_hash and have it redo the hash, so changes still happened without a restart, but the hash itself is just passed from the root apache process to the children? I know this means that each child would retain the old hash util it died and another one respawned, meaning some people would see the change and others wouldn't until it fully propogated, but I can make that happen easily enough by decreasing the number of requests per child... I know that happens at some performance loss, but I think the loss of performance in Apache would be less than the loss of performance generating the same hash over and over again, which will grow to be huge after time. Consider 350 users using this thing for a solid 16 hours a day, and a hundred or so using it the other 8. Thanks Dennis
Re: Variables
Is there a way I could get these variables populated on server start and never loaded again unless the database was changed? So in my subroutine for posting an event that changed it I could call repopulate_queue_hash and have it redo the hash, so changes still happened without a restart, but the hash itself is just passed from the root apache process to the children? You can load it into globals at startup and their values will be shared by all children until you write to them. You could also load it So in startup.perl put my %queue_list = list_queues; my %tech_list = list_techs; and so on? Then each process would get a copy of the hash? separately in each child process in the init hook. However, you'd If I did that, then I'd want a few children processes at a time and also with a few amount of requests per child... Boy am I ever glad this'll be moved off my box once it's finsihed ;) probably be better off using MLDBM::Sync, so that all changes are shared immediately. It's quite fast, and since it uses a tied interface it would be easy to switch your code to use globals if it turns out not be fast enough. After reading the perldoc for MLDBM, and reviewing my deadline for the project of today, I think I'll just use globals for now. But once I meet get the management satisified, I'll be moved into a enhancment phase of hte project, instead of a devel phase, and I'll implement it then to see how well it works. Thanks :)
Re: does pnotes() work at all in 1.27?
No progress yet. I just tested pnotes in the same handler and it works. Tested it again by setting a value in the content handler and trying to retreive it it my logging handler and no luck. It looks like I start work on finding out about your problem tonight instead of last night. Funny story: I did a field call this morning in Palmer, had to do a line test for DSL. Then I had to do another one down Knik Goose Bay road (I know you have no idea of these locations, but thats roughly 30 miles there...). About 25 miles out of Palmer, I hear this ti-ti-ti-ti-thwou - whack vaguely somewhere above and behind me. Anwyays, get to the location, customers mahcine is up and running on DSL, so no line test neccessary. On my way back to Palmer, I see this laptop on the side of the road... I pull over, and guess what I left sitting on the van in Palmer? W. Ever seen remains of a laptop after hitting pavement at 55mph? I can't believe it stayed up there for so long. I was stopping at all kinds of stop lights/signs and stuff, and reaching speeds of 80mph around curves :D Alright, so this wasn't mod_perl related. A bunch of techies can laugh over this tho, and humor is a good thing :) Dennis
Re: does pnotes() work at all in 1.27?
Has anyone gotten $r-pnotes() to work under Apache 1.3.27 and mod_perl 1.27? A simple yes will do because then at least I'll know if it's my mistake or a bug. I'll work on it when I get home again. weee, thursday, gotta have this project done monday.. *sigh* The good news, is that I run Apache 1.3.27 and mod_perl 1.27. Anyways, thought you might like to know I'll work on it and someone out there HAS read your email :) Dennis
cookies
Okay, so technically this isn't really mod_perl speific... but the cookie is being set with mod_perl and it's a huge mod_perl program being affected by this:) I have a cookie, the domain is set to .stout.dyndns.org (with the leading .). I set the cookie just fine now (thanks to those helping me on thatr) I had a problem parsing the cookie. Added some debugging (okay, warn lines up the yingyang) and after cycling through the headers and warning them out to the errorlog... I never saw any cookie info. So... If the website is ttms.stout.dyndns.org shouldn't the cookie domain be .stout.dyndns.org? *sigh* 6 more days to finish this database. I doubt I'll make it. Dennis
Re: cookies
One possibility: Check the -path option. It's supposed to set it to '/' by default if you dont specify it, but it doesn't. I discovered this about 20 minutes ago with a similar bug. So manually specify something like: my $cookie = Apache::Cookie-new($r, -name = 'cookiename', -value = 'someval', -expires = '+7d', -domain = '.dontvisitus.org', -path = '/', ); what I have is this: sub set_auth_cookie { my $state = shift; my $val = build_auth_string($state); my $c = Apache::Cookie-new($state-{r}, -name = 'ttms_user', -value = $val, -expires= time + 86400*30*7, -domain = $Cookie_Domain, -path = '/', ); $state-{cookie_out} = $c; } This is called by various other routines, and $state is a hash = {r = $r, q = \%q }, where q is a hash = {$r-args, $r-content}. build_auth_string is another subroutine that makes a 446bit encryption string thats encoded with mime::base64... I got a path. Does that get sent to all webpages ever, or just ones underh te / directory? In otherwords, does hte cookie get sent when accessing /login.html and not when accessing /admin/view_techs.html? All the pages on this domain are generated dynamically with a custom built dispatch table and some awesome subroutinage. Does that matter? Maybe I should read the complete netscape cookie specification :/ I know the cookie is set because it tells me when it expires and when it was last accessed and what not on the box I browse to it with. (win2k... blah) And the program itself is running in a Linux environment :) Time for more warnage in the routines... If anyone wants sourcecode to look at, email me. It's much to big to just post to the list. Dennis
Re: cookies
Well I'll be damned. My computer at home does the cookie thing perfectly well. My workstation at work does not do cookies. So my mod_perl creation is working fine as far as getting the cookies. rant YAY FOR WIN2K DOMAINS AND ADMIN WHO USE HELP DESK TECHS TO PROGRAM TICKETING SYSTEMS FOR DSL, DIGITAL TV, AND DOMAINS! /rant I still have a problem tho. The cookie string itself is not being passed along. Instead, I am getting Apache::Cookie=SCALAR(0x9115c24). I imagine somewhere I need to do something like -as_string or something. blah Thanks for helping, sorry I didn't spot that the error was infact, in the dumbterminal called a win2k box I was using, and not in any actual code Dennis Stout - Original Message - From: Dennis Stout [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 16, 2003 13 13 Subject: cookies Okay, so technically this isn't really mod_perl speific... but the cookie is being set with mod_perl and it's a huge mod_perl program being affected by this:) I have a cookie, the domain is set to .stout.dyndns.org (with the leading .). I set the cookie just fine now (thanks to those helping me on thatr) I had a problem parsing the cookie. Added some debugging (okay, warn lines up the yingyang) and after cycling through the headers and warning them out to the errorlog... I never saw any cookie info. So... If the website is ttms.stout.dyndns.org shouldn't the cookie domain be .stout.dyndns.org? *sigh* 6 more days to finish this database. I doubt I'll make it. Dennis
Re: cookies
*pounds head against brick wall* why must it work against me??? A cookie for anyone who solves this. sub handler { my $r = shift; my $result = undef; eval { $result = inner_handler($r) }; return $result unless $@; warn Uncaught Exception: $@; return SERVER_ERROR; } sub inner_handler { my $r = shift; my %q = ($r-args, $r-content); my %state = (r = $r, q = \%q); $state{title} = ''; $state{template} = ''; $state{auth_status} = password_boxes(\%state); # warn %ENV: \n; # foreach (keys %ENV) { # warn $_ = $ENV{$_}\n; # } # my %headers = $r-headers_in; # warn Headers: \n; # foreach (keys %headers) { # warn $_: $headers{$_}\n; # } my $cookie = Apache::Cookie-fetch; warn z - $cookie-value; validate_auth_cookie(\%state, $cookie); my $function = $r-uri; if (($state{login_user} eq '') and ($function ne '/login.cgi')) { $function = '/login.html'; } my $func = $Dispatch{$function} || $Dispatch{DEFAULT}; return DECLINED unless $func; return $func-(\%state); } Upon accessing a page (therefore generating lots of warning info in logs...) I get this in my error log. z - HASH(0x916ea08)-value at /home/httpd/ttms/perl/RequestHandler.pm line 108. (the z is there so I know where at in my code the line in the log file is being generated. I like z's and a's more than I do some/long/path/and/filename line 108) I have tried using $cookie as a value in and of itself, I've tried $cookie-{ttms_user} (the name of hte cookie is ttms_user), I've tried changing $cookie to %cookie and doing a $cookie{ttms_user} .. I might break down, declare this a bug, and use $ENV{HTTP_COOKIE} instead. Any ideas how to fix this to return to me the cookie itself? Thanks. Dennis - Original Message - From: Dennis Stout [EMAIL PROTECTED] To: Dennis Stout [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 16, 2003 20 13 Subject: Re: cookies Well I'll be damned. My computer at home does the cookie thing perfectly well. My workstation at work does not do cookies. So my mod_perl creation is working fine as far as getting the cookies. rant YAY FOR WIN2K DOMAINS AND ADMIN WHO USE HELP DESK TECHS TO PROGRAM TICKETING SYSTEMS FOR DSL, DIGITAL TV, AND DOMAINS! /rant I still have a problem tho. The cookie string itself is not being passed along. Instead, I am getting Apache::Cookie=SCALAR(0x9115c24). I imagine somewhere I need to do something like -as_string or something. blah Thanks for helping, sorry I didn't spot that the error was infact, in the dumbterminal called a win2k box I was using, and not in any actual code Dennis Stout - Original Message - From: Dennis Stout [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 16, 2003 13 13 Subject: cookies Okay, so technically this isn't really mod_perl speific... but the cookie is being set with mod_perl and it's a huge mod_perl program being affected by this:) I have a cookie, the domain is set to .stout.dyndns.org (with the leading .). I set the cookie just fine now (thanks to those helping me on thatr) I had a problem parsing the cookie. Added some debugging (okay, warn lines up the yingyang) and after cycling through the headers and warning them out to the errorlog... I never saw any cookie info. So... If the website is ttms.stout.dyndns.org shouldn't the cookie domain be .stout.dyndns.org? *sigh* 6 more days to finish this database. I doubt I'll make it. Dennis
Re: cookies
w00t! ttms_user: mp2Ti5p1JkhCObm9LKBFGsiAltop8aAWwl6vLLDr/3rtb09MRzZrEg== Here, your $cookie = Apache::Cookie-new($state-{r}, -name = 'Mark', -value = 'AWESOME!!!', -expires= time + 86400*30*7, -domain = '.dyndns.org', -path = '/', ); (okay, I made up your, it sounds better than my, and sinec this is fake nayways... heh) oop, looking at that, I should set the domain to something more sane again, like stout.dyndns.org. :P Dennis P.S. Does anyone else try to use Outlook Express like vi and get odd error messages after a days worth of coding? - Original Message - From: Mark Maunder [EMAIL PROTECTED] To: Dennis Stout [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 16, 2003 20 33 Subject: Re: cookies From perldoc CGI::Cookie # fetch existing cookies %cookies = fetch CGI::Cookie; $id = $cookies{'ID'}-value; #You're doing $cookies-value; ID == the name that you used when you set the cookie. On Wed, 2003-07-16 at 21:27, Dennis Stout wrote: *pounds head against brick wall* why must it work against me??? A cookie for anyone who solves this. sub handler { my $r = shift; my $result = undef; eval { $result = inner_handler($r) }; return $result unless $@; warn Uncaught Exception: $@; return SERVER_ERROR; } sub inner_handler { my $r = shift; my %q = ($r-args, $r-content); my %state = (r = $r, q = \%q); $state{title} = ''; $state{template} = ''; $state{auth_status} = password_boxes(\%state); # warn %ENV: \n; # foreach (keys %ENV) { # warn $_ = $ENV{$_}\n; # } # my %headers = $r-headers_in; # warn Headers: \n; # foreach (keys %headers) { # warn $_: $headers{$_}\n; # } my $cookie = Apache::Cookie-fetch; warn z - $cookie-value; validate_auth_cookie(\%state, $cookie); my $function = $r-uri; if (($state{login_user} eq '') and ($function ne '/login.cgi')) { $function = '/login.html'; } my $func = $Dispatch{$function} || $Dispatch{DEFAULT}; return DECLINED unless $func; return $func-(\%state); } Upon accessing a page (therefore generating lots of warning info in logs...) I get this in my error log. z - HASH(0x916ea08)-value at /home/httpd/ttms/perl/RequestHandler.pm line 108. (the z is there so I know where at in my code the line in the log file is being generated. I like z's and a's more than I do some/long/path/and/filename line 108) I have tried using $cookie as a value in and of itself, I've tried $cookie-{ttms_user} (the name of hte cookie is ttms_user), I've tried changing $cookie to %cookie and doing a $cookie{ttms_user} .. I might break down, declare this a bug, and use $ENV{HTTP_COOKIE} instead. Any ideas how to fix this to return to me the cookie itself? Thanks. Dennis - Original Message - From: Dennis Stout [EMAIL PROTECTED] To: Dennis Stout [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 16, 2003 20 13 Subject: Re: cookies Well I'll be damned. My computer at home does the cookie thing perfectly well. My workstation at work does not do cookies. So my mod_perl creation is working fine as far as getting the cookies. rant YAY FOR WIN2K DOMAINS AND ADMIN WHO USE HELP DESK TECHS TO PROGRAM TICKETING SYSTEMS FOR DSL, DIGITAL TV, AND DOMAINS! /rant I still have a problem tho. The cookie string itself is not being passed along. Instead, I am getting Apache::Cookie=SCALAR(0x9115c24). I imagine somewhere I need to do something like -as_string or something. blah Thanks for helping, sorry I didn't spot that the error was infact, in the dumbterminal called a win2k box I was using, and not in any actual code Dennis Stout - Original Message - From: Dennis Stout [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 16, 2003 13 13 Subject: cookies Okay, so technically this isn't really mod_perl speific... but the cookie is being set with mod_perl and it's a huge mod_perl program being affected by this:) I have a cookie, the domain is set to .stout.dyndns.org (with the leading .). I set the cookie just fine now (thanks to those helping me on thatr) I had a problem parsing the cookie. Added some debugging (okay, warn lines up the yingyang) and after cycling through the headers and warning them out to the errorlog... I never saw any cookie info. So... If the website is ttms.stout.dyndns.org shouldn't the cookie domain be .stout.dyndns.org
Re: cookies
Cool dude. Now if you know why $r-pnotes() isn't working under apache/modperl .27 you'll make my day! Got some source code to show me what you're doing with it? Otherwise I'll just have to cut and paste the mod_perl API book to you ;) hehehehe. Dennis
Re: cookies
WOOO! I went to the ttms site, logged in, AND IT AUTHNTICATED ME AND GAVE ME PAGES!! :D Aight, drink of choice is on me tonight :D I can't beleive it! 3 weeks on this bloody thing and I got it to finally Authenticat me =D Course, I had to disable things in order to get it to give me a cookie to authenticate with, but a few if's will fix that :D I'm happy, I'm happy, I'm happy! I might actually meet deadline :D w00t! er... *ahem* My thanks to all of you, and special thanks to Mark who helped me the most :D Dennis
Re: pnotes and notes not working from Apache::Registry to handler
I'm trying to store data about a user who has authenticated in $r-pnotes so that a perl logging phase handler can stick the user_id in the db. I call $r-pnotes('keyname' = 'somevalue'); in an apache registry script, and then call $r-pnotes('keyname') in the logging handler later on during the logging phase, but am getting nothing back. No errors, just undef. I've tried notes too, and no luck their either. I'm using Apache::Request btw. I've also tried retreiving a tied hash using $r-pnotes() and there are no key/values in that either. the mod_perl API book specifically said pnotes is the way to communicate between handlers. As I have hte PDF version, I can't exactly cut paste it easily... pnotes gets cleared after every request, so good thinking on trying notes, as it apearently doesn't. the basic usage is this: $r-pnotes(MY_HANDLER = [qw(one two)]); my $val = $r-pnotes(MY_HANDLER); print $val-[0]; # prints one So basically, $r-pnotes(MY_HANDLER = [qw(one two)]); will create a hash where MY_HANDLER is a key to an anonymous array. my $val = $r-pnotes(MY_HANDLER); sets $val to be the reference to that array. print $val-[0]; dereferences the first spot in the array reference. The dereferencing thing is key here. $val[0] will throw errors about globals not being declared as arrays or something of that sort. Did I forget to compile apache or mod_perl with an option of some sort? I can't think of any other explanation. I compiled mod_perl with EVERYTHING=1 There is the problem right there. It needs to be compiled with EVERYTHING=1 PLUS_THAT_OTHER_LITTLE_THING_NOT_INCLUDED_IN_EVERYTHING=1. :P Dennis
Re: [admin] please trim the quoted text in replies to a minimum
Of course don't jump to the other exteme edge and overtrim. Use your common sense as a guide to how much is enough to keep the sufficient context. I remember once upon a lot of bluemoons ago, in the days when FidoNet took place over phone line and 2400baud modems, when client readers would actually warn you about sending a message that contained more than x percent quoted material, and would automagically put your cursor underneath the original text instead of above it! *sigh* ... Good old days, 1:17/71 was me :D Dennis
Re: must I use mod-perl
Install it if you have a lot of time. It took me week to config it and month for rewritting scripts. If you're using a system that has some sort of packages, then there are probably mod_perl packages for it. Installing mod_perl on a Debian GNU/Linux systems takes about as long as the download plus 1 minute. If you know what you're doing, it doesn't take long either. I downloaded source for Apache, PHP, and mod_perl and compiled it all and had it working in about the time it took to download it + compile time + about 5 minutes. There is no config to mod_perl really. Either it's there or it isn't. Dennis
Re: mod_perl 2.0 and cookies
So I've decided to dive headlong into 2.0. So far I like it but find the documentation lacking and there seems to be a lot missing. I tried Apache::Cookie with it, no dice. It gave an error to the effect that it didn't know what bootstrap was (I think that was it). Apache::Cookie made inserting cookies in mod_perl 1.0 so easy which in turn made life easier for programming. However I have scoured the documentation on how to insert a cookie into the header and the only thing I could come up with is that you use a filter to do it. Somehow I don't think that this is right and I am completely off. Could someone enlighten me as to how cookies work in MP2? If I can get past this I can figure out the rest on my own and maybe write a little documentation if I can understand it enough to do so. From what I've figured out through experiementing, tho I'd find out a lot more by reading source and I'd be a bit more accurate in this... But I think mod_perl 2 is just simply lacking all together. I think the docs are lacking info because the program is lacking hte feature! Course, this only means I havern't figured out how to use the features, if they are there. But, to me, mod_perl x+1 should be backwards compatible with mod_perl x, if it isn't, then it's broken. (in my opinion..) Dennis
Fw: select multiple
This is the original email I sent out, regarding my multiple selects... S.T.O.U.T. = Synthetic Technician Optimized for Ultimate Troublshooting - Original Message - From: Dennis Stout [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 10, 2003 11 39 Subject: select multiple Beginners-CGI; If I have a form with a lot of values (such as Tech ID, Tech Name, Tech Queues..) and one of the fields is a select multiple, with a varied amount of options selected, how are those values sent to the cgi script? Is it something like ?queue=lvl1,lvl2,admin,sysadfoo=bar or what? Thanks Dennis -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: select multiple
Because there is no way to create a delimiter that the potential data doesn't contain, the browser doesn't have the option to choose an arbitrary delimiter like a comma, or the like. So (though I can't speak for all browsers most will do the same) each value is passed with the same key, so your string ends up like: ?queue=lvl1queue=lvl2queue=adminqueue=sysadfoo=bar This punts the problem to the server side (or whatever does the query string parsing) so there are multiple ways to handle it, build a complex data structure that stores an array reference for any multi-valued keys, store the keys with some known delimiter (aka cgi-lib.pl used to use the null character \0). So it depends on your request parser, some provide multiple manners (I think the standard CGI does). Have a look at the respective docs for how your parser handles it, unless you are writing a parser...but then why do that with so many good freely available ones? Interesting. So in mod_perl, I would use $r-args{__what__} to get to it? Heh. I'll email the mod_perl list.. Dennis
Re: select multiple
ARHG. I want to stay as far away from use CGI; as possible =/ *sigh* mod_perl and the methods available in the apache request object shuold beable to replace CGI.pm entirely, especially when you have a highly customized RequestHandler :/ Guess I'll see what happens, since I need cookie headers to work AND now multiple values for one param. S.T.O.U.T. = Synthetic Technician Optimized for Ultimate Troublshooting - Original Message - From: Chris Faust [EMAIL PROTECTED] To: Dennis Stout [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, July 10, 2003 16 30 Subject: Re: select multiple CGI.pm does the trick for me, the multi values are seperated by \0 select name=yadda multi DEFANGED_optionyadda1 DEFANGED_optionyadda2 DEFANGED_optionyadda3 /DEFANGED_select my $CGI = new CGI(); %form_data = $CGI-Vars; @options = split(\0,$form_data{'yadda'}); $options[0] = yadda1, $options[1] = yadda2 etc . Not usable live code obviously, but you should see the idea... -Chris - Original Message - From: Dennis Stout [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, July 10, 2003 4:52 PM Subject: Re: select multiple Interesting. So in mod_perl, I would use $r-args{__what__} to get to it? Heh. I'll email the mod_perl list.. Dennis
Re: select multiple
mod_perl and the methods available in the apache request object shuold beable to replace CGI.pm entirely, especially when you have a highly customized RequestHandler :/ Guess I'll see what happens, since I need cookie headers to work AND now multiple values for one param. Have you looked at Apache::Request? Reading documentation.. and it looks like $r-param is what I need :) Thanks! --- perldoc Apache::Request --- param Get or set request parameters (using case-insensitive keys) by mimicing the OO interface of CGI::param. Unlike the CGI.pm version, Apache::Request's param method is very fast- it's now quicker than even mod_perl's native Apache-args method. However, CGI.pm's -attr = $val type arguments are not sup- ported. # similar to CGI.pm my $value = $apr-param('foo'); my @values = $apr-param('foo'); my @params = $apr-param; # the following differ slightly from CGI.pm # assigns multiple values to 'foo' $apr-param('foo' = [qw(one two three)]); # returns ref to underlying apache table object my $table = $apr-param; # identical to $apr-parms - see below parms Get or set the underlying apache parameter table of the Apache::Request object. When invoked without arguments, parms returns a reference to an Apache::Table object that is tied to the Apache::Request object's parameter table. If called with an Apache::Table reference as as argument, the Apache::Request object's parameter table is replaced by the argument's table. # $apache_table references an Apache::Table object $apr-parms($apache_table); # sets $apr's parameter table # returns ref to Apache::Table object provided by $apache_table my $table = $apr-parms;
Re: Apache config problem .. please help
I made a simple mod_perl change to the config and when restarting Apache I got this error: (98)Address already in use: make_sock: could not bind to address 0.0.0.0:2250 no listening sockets available, shutting down /usr/local/apache/bin/apachectl: line 87: 16512 Segmentation fault $HTTPD $ARGV I then backed out the change and retried, got the same error. killall httpd then try it again :) Dennis
Re: Please help newbie with Module problem.
however when I run the following code #!c:/perl/bin/perl -w use Apache (); use Apache::Request (); use CGI::Carp qw(fatalsToBrowser); my $r = Apache::Request-new(shift); # my $apr = Apache::Request-new($r); print Content-type:text/html\n\n; print Hello, World...\n; print $r; print @INC; I receive the message Can't locate object method new via package Apache::Request (perhaps you forgot to load Apache::Request?) at c:\apache\cgi-bin\ap2.pl line 6. mod_perl sends $r to the handler() subroutine by default. That is, if you're using it in a PerlHandler context, like you should with anything that uses Apache::Request. Therefore, th ollowing should work for you. #!/usr/bin/perl -w use strict; use Apache::Constants qw(:common); sub handler { my $r = shift; my $result = undef; eval { $result = inner_handler($r) }; return $result unless $@; warn Uncaught Exception: $@; return SERVER_ERROR; } sub inner_handler { my $r = shift; $r-content-type('text/html'); $r-status(200); my $html = htmlheadtitleHello World!/title/headbodycenterYou Tried To Access URI: . $r-uri ./center/body/html; $r-send_http_header; print $html; }
Re: Please help newbie with Module problem.
this, however the line $r-content-type('text/html'); seems to be giving my compiler some problems. You could'nt just give me a hint on My mistake, shift key didn't get pressed hard enough =P $r-content_type('text/html'); Dennis
Re: Please help newbie with Module problem.
You can send me- er, the Help Dennis Move out of Alaska charity money by giving your credit card number to *grin* Thank you, I'm sure Randy would agree when I say it's nice to be appreciated :) Dennis Stout S.T.O.U.T. = Synthetic Technician Optimized for Ultimate Troublshooting - Original Message - From: Matt Corbett [EMAIL PROTECTED] To: 'Dennis Stout' [EMAIL PROTECTED]; 'Randy Kobes' [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, July 02, 2003 11 55 Subject: RE: Please help newbie with Module problem. Dennis and Randy and others on the list that gave advice, Thank you so much for both your help. This has sorted out the problem. I copied the *.pl files to the c:\apache\perl directory and before I made the change to the httpd.conf file I tried it tham again and it's perfect. If either or both of you can recommend a good charity I will make a small donation for your time. Again thanks Matt -Original Message- From: Dennis Stout [mailto:[EMAIL PROTECTED] Sent: 02 July 2003 19:28 To: Matt Corbett Subject: Re: Please help newbie with Module problem. I don't have a PerlHandler set in my httpd.conf. How should I set this. Edit whatever form of an httpd.conf file that Apache has under Win32 (should be hte same, location I don't know). mv the script out of the cgi-bin and into somewhere else, like C:/Apache/perl Let's say the name is RequestHandler.pm In httpd, add this line: VirtualHost blah.yourdomain.whatever:80 Location / SetHandler perl-script PerlHandler RequestHandler /Location /VirtualHost Restart Apache, and any access to blah.yourdomain.whatever/ should get trapped in there. You may need to add the other standard apache directives to that, like ServerName blah.yourdomain.whatever and so on, but probably not. I think we are so close I can almost feel it. Yes, we are. The code I sent you is hte core of hte project I'm currently programming, which includes an entire dispatch table. Now if only I could get it to grab the right friggin string from a SQL server to authenticate :| -Original Message- From: Dennis Stout [mailto:[EMAIL PROTECTED] Sent: 02 July 2003 18:57 To: Matt Corbett Subject: Re: Please help newbie with Module problem. Hrm. Off the top of my head, I've not a clue. Did you setup Apache with a PerlHandler /path/to/file_with_script.perl directive? S.T.O.U.T. = Synthetic Technician Optimized for Ultimate Troublshooting - Original Message - From: Matt Corbett [EMAIL PROTECTED] To: 'Dennis Stout' [EMAIL PROTECTED] Sent: Wednesday, July 02, 2003 09 49 Subject: RE: Please help newbie with Module problem. Thanks Dennis, It's now giving me Premature end of script headers:. Can you help me again. Matt -Original Message- From: Dennis Stout [mailto:[EMAIL PROTECTED] Sent: 02 July 2003 17:46 To: Matt Corbett; [EMAIL PROTECTED] Subject: Re: Please help newbie with Module problem. this, however the line $r-content-type('text/html'); seems to be giving my compiler some problems. You could'nt just give me a hint on My mistake, shift key didn't get pressed hard enough =P $r-content_type('text/html'); Dennis
If (!$one_thing) {$other;}
This is irking me. $state preserves information about the request and so on. Now, $r-whatever_method works just fine.. EXCEPT for sending headers. When I visit my site, I get my nifty login page, and that is all. Always the login page. I telnetted into the thing to see what kinds of cookie strings I was getting back and... NO HEADERS! No Content-type: 's or nothing. $r-send_http_header; must be broken, eh? How to fix?? =P I'll spare all of your eyes by not sending complete source, but here's the basic idea. #!/usr/bin/perl package RequestHandler; use strict; # snipped out a lot of use vars qw();'s and $val = blah. sub handler { my $r = shift; my $result = undef; eval { $result = inner_handler($r) }; return $result unless $@; warn Uncaught Exception: $@; return SERVER_ERROR; } sub inner_handler { my $r = shift; my %q = ($r-args, $r-content); my %state = (r = $r, q = \%q); $state{login_user} = ''; $state{login_pass} = ''; $state{title} = ''; $state{template} = ''; $state{auth_status} = password_boxes(\%state); validate_auth_cookie(\%state); my $function = $r-uri; $function = '/login.html' if $state{login_user} eq ''; my $func = $Dispatch{$function} || $Dispatch{DEFAULT}; return $func-(\%state); } sub output_html { my $state = shift; my %args = @_; my $title = $state-{title}; my $r = $state-{r}; $r-status(200); my $template = HTML::Template-new( filename= $Template_Dir/$state-{template}, die_on_bad_params = 0, ); $template-param(TITLE = $title); eval { foreach (keys %args) { $template-param($_ = $args{$_}); }}; $template-param(ERRORS = $@) if $@; $r-header_out( 'Set-Cookie' = $state-{cookie_out} ) if $state-{cookie_out}; $r-send_http_header('text/html'); print $template-output(); } sub get_password { my $state = shift; my $row = $Sql-select_hashref('DECODE(PWORD,\'blah\')', 'techs', TECH=\$state-{ q}-{login_user}\); return $row-{DECODE(PWORD,'blah')}; } sub build_auth_string { my $state = shift; my $ip = shift || $ENV{REMOTE_ADDR}; my $time = shift || time; my $login = $state-{login_user}; my $password = $state-{login_pass}; my $val = join ::, $login, $ip, $password, $time; # Iterate thru by 8 byte hunks. # with the added 8 spaces, do not do the last hunk # which will be all spaces my $blown; my $pos; for ( $pos = 0; (($pos + 8) length($val) ) ; $pos+=8 ) { $blown .= $cipher-encrypt(substr($val, $pos, 8)); # encrypt this without temp vars } my $enc = encode_base64($blown,); $enc; } sub parse_auth_string { my $state = shift; my $cookie = shift; return unless $cookie; return if $cookie =~ /logged_out/; my $unenc= decode_base64($cookie); my $unblown; # start at 8, take 8 bytes at a time # $unenc should be exactly a multiple of 8 bytes. my $pos; for ( $pos = 0; $poslength($unenc); $pos += 8) { $unblown .= $cipher-decrypt(substr($unenc, $pos, 8)); } my ($login, $ip, $password, $time)=split ( /::/, $unblown, 4); } sub get_auth_cookie { my $state=shift; my $cookie = TTMSCGI-parse_cookie($ENV{HTTP_COOKIE})-{ttms_user}; my($login, $ip, $password, $time) = parse_auth_string($state, $cookie); ($login, $ip, $password, $time); } sub set_auth_cookie { my $state = shift; my $val = build_auth_string($state); my $c = TTMSCGI-build_cookie( name= 'ttms_user', value = $val, expires = time + 86400*30*7, domain = $Cookie_Domain, path= '/', ); $state-{cookie_out} = $c; } sub build_logout_cookie { TTMSCGI-build_cookie( name = 'ttms_user', value = logged_out, expires= time - 86400, domain = $Cookie_Domain, path = '/' ); } sub set_logout_cookie { my $state = shift; $state-{cookie_out} = build_logout_cookie($state); } sub validate_auth_cookie { my $state = shift; my ($login, $ip, $pass, $time) = get_auth_cookie($state); return unless $login $pass; my $checkpass = get_password($state); if ($pass eq $checkpass) { $state-{login_user} = $login; $state-{login_pass} = $pass; $state-{auth_status} = Logged in as $state-{login_user}; return; } return; }
if (!$one_thing) { $other; }
I suppose the subroutine that makes the call to it would help too. I'll spare you all the dispatch routine as it's quite lengthy, but basically the DispatchTbl::* generates webpages dynamically depending on the uri caught by RequestHandler::handler();. sub post_login_form { my $state = shift; my %args = $state-{q}; $state-{template} = 'generic.tmpl'; $state-{title} = 'TTMS Login'; my $checkpass = get_password($state); if ($checkpass eq $state-{q}{login_pass}) { $state-{login_user} = $state-{q}{login_user}; $state-{login_pass} = $state-{q}{login_pass}; $state-{auth_status} = Logged in as $state-{login_user}; set_auth_cookie($state); $args{body} = Good Morning, Dave.; } else { set_logout_cookie($state); $args{body} = I'm afraid I can't let you do that, Dave.; } return output_html($state, %args); }
Re: If (!$one_thing) {$other;}
Not likely. Your syntax looks okay to me. It probably isn't being called for some reason, or else $r is not what you think it is. Throw in some debug statements and find out what's actually happening there. Okay, I put in some code to take the generated headers and enter them into the body of the page. This had an odd effect. I got headers at hte TOP of hte page, before the html tags, and here is what it reads: HTTP/1.1 200 OK Date: Wed, 02 Jul 2003 22:33:52 GMT Server: Apache/1.3.27 (Unix) mod_perl/1.27 Connection: close Content-Type: text/html Set-Cookie: So the cookie it's trying to set is wrong, but I can work on that later. Why is it not sending it normally? More importantly, why am I seeing this when I view source? I'm not supposed to ever see header info. Dennis
Re: If (!$one_thing) {$other;}
Not likely. Your syntax looks okay to me. It probably isn't being called for some reason, or else $r is not what you think it is. Throw in some debug statements and find out what's actually happening there. Okay, I put in some code to take the generated headers and enter them into the body of the page. This had an odd effect. I bet I have a login problem. User tries to do whatever. Gets asked to login. Fills in login form, hits submit, but posting is a request in and of itself. So the request for the cgi is made, user doesn;'t have a valid cookie yet, gets redirected to the login page ... Dennis
Re: If (!$one_thing) {$other;}
On Wed, 2003-07-02 at 21:24, Dennis Stout wrote: Okay, I put in some code to take the generated headers and enter them into the body of the page. This had an odd effect. I bet I have a login problem. Whoops. logic problem. YAY, maybe the core of all my problems is vast amounts of typo's caused by carpal tunnel =/ You lost me. You were having problems with headers not being sent, right? That probably means that either $r is not the Apache object you think it is, or your program is not actually calling send_http_header. Have you done enough debugging to rule both of those things out? $r is indeed the correct Apache object. Where I believe hte problem exists is in the PerlSendHeaders dealybob John mentioned in a private email to me... I'm currently taking a break from that section of hte program and have disabled it with a series of #'s for now... I'm going to work more directly with the SQL interface I'm making. I think I'll junk what I have and write a new one from scratch I think when I'm done and get this roled out, I'll work on making something very similar but completely database driven. All the functions in the dispatch table will be brought in through a single SQL statement called in an eval context. I might work on that once I have sufficiently pounded my brain with enough beer. m, 4 day weekend Dennis
Re: If (!$one_thing) {$other;}
I think when I'm done and get this roled out, I'll work on making something very similar but completely database driven. All the functions in the dispatch table will be brought in through a single SQL statement called in an eval context. This also means I can write a small subroutine to eval a form that's been posted, and given the authentication passes, add code to the thing while it's running, AND save the code to the DB so it'll be around for reboots. Wouldn't that just be awesome? A totally dynamic web driven database that can be completely reconfigured on the fly. I wonder if using Perl/Perl sections in the httpd.conf file, if a guy could put the entire RequestHandler in a database as well heh I spose that might take some work, probably with vi and gcc, on apache source files. Dennis