From c10765bfab69c9d2abdb96bf05a6662088cf8b3f Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 29 Dec 2006 13:02:28 +0000 Subject: [PATCH] use Tie::File instead of hardcoded regex for valid pages --- ND.pm | 25 +++++++++++++------------ pages | 18 ++++++++++++++++++ startup.pl | 4 ++++ 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 pages diff --git a/ND.pm b/ND.pm index c2bb6c0..d62a7ea 100755 --- a/ND.pm +++ b/ND.pm @@ -26,9 +26,13 @@ use DBD::Pg qw(:pg_types); use Apache2::Request; use ND::Include; use ND::DB; +use Tie::File; +use Fcntl 'O_RDONLY'; use strict; use warnings FATAL => 'all'; +tie our @PAGES, 'Tie::File', "/var/www/ndawn/code/pages", mode => O_RDONLY or die $!; + sub handler { local $ND::r = shift; local $ND::req = Apache2::Request->new($ND::r, POST_MAX => "1M"); @@ -77,13 +81,10 @@ sub page { our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)'); - my $page = 'main'; - if ($ND::PAGE =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids|editRaid|calls|intel|users|alliances|memberIntel|resources|planetNaps)$/){ - $page = $1; - } + $ND::PAGE = 'main' unless grep { /^$ND::PAGE$/ } @PAGES; our $XML = 0; - $XML = 1 if param('xml') and $page =~ /^(raids)$/; + $XML = 1 if param('xml') and $ND::PAGE =~ /^(raids)$/; our $AJAX = 1; @@ -91,17 +92,17 @@ sub page { if ($XML){ $type = 'text/xml'; $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl", cache => 1); - $ND::BODY = HTML::Template->new(filename => "templates/${page}.xml.tmpl", cache => 1); + $ND::BODY = HTML::Template->new(filename => "templates/$ND::PAGE.xml.tmpl", cache => 1); }else{ - $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl", global_vars => 1, cache => 1); - $ND::BODY->param(PAGE => $page); + $ND::BODY = HTML::Template->new(filename => "templates/$ND::PAGE.tmpl", global_vars => 1, cache => 1); + $ND::BODY->param(PAGE => $ND::PAGE); } - unless (my $return = do "${page}.pl"){ - $error .= "

couldn't parse $page: $@

" if $@; - $error .= "

couldn't do $page: $!

" unless defined $return; - $error .= "

couldn't run $page

" unless $return; + unless (my $return = do "$ND::PAGE.pl"){ + $error .= "

couldn't parse $ND::page: $@

" if $@; + $error .= "

couldn't do $ND::page: $!

" unless defined $return; + $error .= "

couldn't run $ND::page

" unless $return; } unless ($XML){ diff --git a/pages b/pages new file mode 100644 index 0000000..13b0138 --- /dev/null +++ b/pages @@ -0,0 +1,18 @@ +main +check +motd +points +covop +top100 +launchConfirmation +addintel +defrequest +raids +editRaid +calls +intel +users +alliances +memberIntel +resources +planetNaps diff --git a/startup.pl b/startup.pl index eb3bfe8..cf9b748 100644 --- a/startup.pl +++ b/startup.pl @@ -1,6 +1,7 @@ use lib qw(/var/www/ndawn/code/); use POSIX; + use CGI qw/:standard/; use HTML::Template; @@ -8,8 +9,11 @@ use Apache::DBI(); DBI->install_driver("Pg"); use DBI; use DBD::Pg qw(:pg_types); + use DB; use ND::Include; +use Tie::File; + 1; -- 2.39.2