Two questions:
1 - How to add site home (index.pl?page=home) as the default if *no* param given, but still fail if *bad* param given?
2 - Untainting regexp that will reject if non-word character anywhere in provided param, not just if non-word char is first character.
All suggestions welcome and appreciated.
cheers,
Don
striving for Perl Adept
(it's pronounced "why-bick")
# Read in URL file query and untaint # one or more word characters if ($query = param('page') =~ /(\w+)/) { $urlist = $1; } else {die "Please request pages by alphanumeric name only. You might find what you're looking for by starting at site home of http://host.dom/index.pl?page=home\n"; } # Build array of urlist files # Confirm that supplied param is valid file opendir DIR, "$confdir/"; my @files = grep { $_ ne '.' && $_ ne '..' && } readdir DIR; closedir DIR; unless (grep{$_ eq $urlist} @files) { die "You requested a page that does not exist. You might find what you're looking for by starting at site home of http://host.dom/index.pl?page=home\n"; } # read lists of page URLs from external file # loop through lists, parsing for HTML::Template use unless (my $return = do "$confdir/$urlist") { die "Cannot parse $urlist: $@" if $@; die "Cannot do $urlist: $!" unless defined $return; die "Cannot run $urlist" unless $return; } for (my $i = 0; $i < $#url_array; $i+=2) { my($loop, $aref) = @url_array[$i, $i+1]; my @vars; for (my $j = 0; $j < $#{$aref}; $j+=2) { my($name, $url) = @{$aref}[$j, $j+1]; push @vars, { name => $name, url => $url }; } $template->param($loop, [ @vars ]); }
In reply to Default CGI.pm param() if none provided? by ybiC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |