split require_config into own sub, so we now read global
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 3 Nov 2008 22:26:57 +0000 (22:26 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 3 Nov 2008 22:26:57 +0000 (22:26 +0000)
and local config (within directory)

git-svn-id: svn://svn.rot13.org/SQL2XLS@18 2e857b76-582b-47e5-ad5c-b3ba0f0ee29b

sql2xls.cgi

index 73cbcf8..15ba1e1 100755 (executable)
@@ -85,15 +85,21 @@ our $debug = 1;
 my $sql_dir = $ENV{SCRIPT_FILENAME} || '.';
 $sql_dir =~ s,/[^/]+$,,;
 
-my $config_path = $1 if "$sql_dir/config.pl" =~ m/^(.+)$/; # untaint
-warn "# using $config_path\n";
-require $config_path if -e $config_path;
+sub require_config {
+       my $config_path = $1 if "$sql_dir/config.pl" =~ m/^(.+)$/; # untaint
+       warn "# using $config_path\n";
+       require $config_path if -e $config_path;
+}
+
+require_config;
 
 my $reports_path = $ENV{PATH_INFO};
 $reports_path =~ s/\.\.//g; # some protection against path exploits
 $reports_path ||= shift @ARGV; # for CLI invocation
 $sql_dir .= "/$reports_path" if -e "$sql_dir/$reports_path";
 
+require_config;
+
 warn "# reading SQL queries from $sql_dir\n" if $debug;
 
 opendir(DIR, $sql_dir) || die "can't opendir $sql_dir: $!";