Commit da857afa authored by bbaetz%acm.org's avatar bbaetz%acm.org

Bug 208604 - Make data/template dir locations configurable

parent 63790559
......@@ -32,6 +32,8 @@ package Bugzilla::BugMail;
use RelationSet;
use Bugzilla::Config qw(:DEFAULT $datadir);
# This code is really ugly. It was a commandline interface, then it was moved
# There are package-global variables which we rely on ProcessOneBug to clean
# up each time, and other sorts of fun.
......@@ -66,7 +68,7 @@ sub AUTOLOAD {
}
# This is run when we load the package
if (open(NOMAIL, "<data/nomail")) {
if (open(NOMAIL, '<', "$datadir/nomail")) {
while (<NOMAIL>) {
$nomail{trim($_)} = 1;
}
......
......@@ -34,6 +34,29 @@ use base qw(Exporter);
use Bugzilla::Util;
# Under mod_perl, get this from a .htaccess config variable,
# and/or default from the current 'real' dir
# At some stage after this, it may be possible for these dir locations
# to go into localconfig. localconfig can't be specified in a config file,
# except possibly with mod_perl. If you move localconfig, you need to change
# the define here.
# $libpath is really only for mod_perl; its not yet possible to move the
# .pms elsewhere.
# $webdotdir must be in the webtree somewhere. Even if you use a local dot,
# we output images to there. Also, if $webdot dir is not relative to the
# bugzilla root directory, you'll need to change showdependancygraph.cgi to
# set image_url to the correct location.
# The script should really generate these graphs directly...
# Note that if $libpath is changed, some stuff will break, notably dependancy
# graphs (since the path will be wrong in the HTML). This will be fixed at
# some point.
our $libpath = '.';
our $localconfig = "$libpath/localconfig";
our $datadir = "$libpath/data";
our $templatedir = "$libpath/template";
our $webdotdir = "$datadir/webdot";
# Module stuff
@Bugzilla::Config::EXPORT = qw(Param);
......@@ -42,13 +65,15 @@ use Bugzilla::Util;
# when it shouldn't
# ChmodDataFile is here until that stuff all moves out of globals.pl
# into this file
@Bugzilla::Config::EXPORT_OK = qw($contenttypes ChmodDataFile);
@Bugzilla::Config::EXPORT_OK = qw(ChmodDataFile);
%Bugzilla::Config::EXPORT_TAGS =
(
admin => [qw(GetParamList UpdateParams SetParam WriteParams)],
db => [qw($db_host $db_port $db_name $db_user $db_pass $db_sock)],
locations => [qw($libpath $localconfig $datadir $templatedir $webdotdir)],
);
Exporter::export_ok_tags('admin', 'db');
Exporter::export_ok_tags('admin', 'db', 'locations');
# Bugzilla version
$Bugzilla::Config::VERSION = "2.17.6";
......@@ -74,23 +99,24 @@ my %param;
# XXX - mod_perl - need to register Apache init handler for params
sub _load_datafiles {
# read in localconfig variables
do 'localconfig';
do $localconfig;
if (-e 'data/params') {
if (-e "$datadir/params") {
# Handle reading old param files by munging the symbol table
# Don't have to do this if we use safe mode, since its evaled
# in a sandbox where $foo is in the same module as $::foo
#local *::param = \%param;
# Note that checksetup.pl sets file permissions on 'data/params'
# Note that checksetup.pl sets file permissions on '$datadir/params'
# Using Safe mode is _not_ a guarantee of safety if someone does
# manage to write to the file. However, it won't hurt...
# See bug 165144 for not needing to eval this at all
my $s = new Safe;
$s->rdo('data/params');
die "Error evaluating data/params: $@" if $@;
$s->rdo("$datadir/params");
die "Error reading $datadir/params: $!" if $!;
die "Error evaluating $datadir/params: $@" if $@;
# Now read the param back out from the sandbox
%param = %{$s->varglob('param')};
......@@ -226,17 +252,17 @@ sub WriteParams {
require File::Temp;
my ($fh, $tmpname) = File::Temp::tempfile('params.XXXXX',
DIR => 'data' );
DIR => $datadir );
print $fh (Data::Dumper->Dump([ \%param ], [ '*param' ]))
|| die "Can't write param file: $!";
close $fh;
rename $tmpname, "data/params"
|| die "Can't rename $tmpname to data/params: $!";
rename $tmpname, "$datadir/params"
|| die "Can't rename $tmpname to $datadir/params: $!";
ChmodDataFile('data/params', 0666);
ChmodDataFile("$datadir/params", 0666);
}
# Some files in the data directory must be world readable iff we don't have
......@@ -248,7 +274,7 @@ sub WriteParams {
sub ChmodDataFile {
my ($file, $mask) = @_;
my $perm = 0770;
if ((stat('data'))[2] & 0002) {
if ((stat($datadir))[2] & 0002) {
$perm = 0777;
}
$perm = $perm & $mask;
......@@ -321,10 +347,6 @@ Bugzilla::Config - Configuration parameters for Bugzilla
use Bugzilla::Config qw(:db);
print "Connecting to $db_name as $db_user with $db_pass\n";
# This variable does not belong in localconfig, and needs to go
# somewhere better
use Bugzilla::Config($contenttypes)
=head1 DESCRIPTION
This package contains ways to access Bugzilla configuration parameters.
......
......@@ -135,9 +135,9 @@ sub connect_shadow {
}
sub connect_main {
my $dsn = "DBI:mysql:host=$::db_host;database=$::db_name;port=$::db_port";
my $dsn = "DBI:mysql:host=$db_host;database=$db_name;port=$db_port";
$dsn .= ";mysql_socket=$::db_sock" if $::db_sock;
$dsn .= ";mysql_socket=$db_sock" if $db_sock;
return _connect($dsn);
}
......
......@@ -29,7 +29,7 @@ package Bugzilla::Template;
use strict;
use Bugzilla::Config;
use Bugzilla::Config qw(:DEFAULT $templatedir $datadir);
use Bugzilla::Util;
# for time2str - replace by TT Date plugin??
......@@ -37,6 +37,7 @@ use Date::Format ();
use base qw(Template);
# XXX - mod_perl
my $template_include_path;
# Make an ordered list out of a HTTP Accept-Language header see RFC 2616, 14.4
......@@ -69,13 +70,16 @@ sub sortAcceptLanguage {
# If no Accept-Language is present it uses the defined default
sub getTemplateIncludePath () {
# Return cached value if available
# XXXX - mod_perl!
if ($template_include_path) {
return $template_include_path;
}
my $languages = trim(Param('languages'));
if (not ($languages =~ /,/)) {
return $template_include_path =
["template/$languages/custom", "template/$languages/default"];
["$templatedir/$languages/custom",
"$templatedir/$languages/default"];
}
my @languages = sortAcceptLanguage($languages);
my @accept_language = sortAcceptLanguage($ENV{'HTTP_ACCEPT_LANGUAGE'} || "" );
......@@ -92,7 +96,9 @@ sub getTemplateIncludePath () {
}
push(@usedlanguages, Param('defaultlanguage'));
return $template_include_path =
[map(("template/$_/custom", "template/$_/default"), @usedlanguages)];
[map(("$templatedir/$_/custom",
"$templatedir/$_/default"),
@usedlanguages)];
}
......@@ -177,7 +183,7 @@ sub create {
PRE_CHOMP => 1,
TRIM => 1,
COMPILE_DIR => 'data/',
COMPILE_DIR => "$datadir/template",
# Functions for processing text within templates in various ways.
# IMPORTANT! When adding a filter here that does not override a
......@@ -321,4 +327,3 @@ C<Bugzilla-E<gt>instance-E<gt>template> to get an already created module.
=head1 SEE ALSO
L<Bugzilla>, L<Template>
......@@ -47,6 +47,8 @@ sub is_tainted {
}
sub trick_taint {
require Carp;
Carp::confess("Undef to trick_taint") unless defined $_[0];
$_[0] =~ /^(.*)$/s;
$_[0] = $1;
return (defined($_[0]));
......
......@@ -38,6 +38,7 @@ use Bugzilla::Search;
use Bugzilla::User;
use Bugzilla;
use Bugzilla::Config qw(:DEFAULT $datadir);
# Turn off output buffering (probably needed when displaying output feedback
# in the regenerate mode.)
......@@ -66,7 +67,7 @@ push( @myproducts, "-All-", @::legal_product );
my $tstart = time;
foreach (@myproducts) {
my $dir = "data/mining";
my $dir = "$datadir/mining";
&check_data_dir ($dir);
......@@ -87,8 +88,8 @@ CollectSeriesData();
# Generate a static RDF file containing the default view of the duplicates data.
open(CGI, "GATEWAY_INTERFACE=cmdline REQUEST_METHOD=GET QUERY_STRING=ctype=rdf ./duplicates.cgi |")
|| die "can't fork duplicates.cgi: $!";
open(RDF, ">data/duplicates.tmp")
|| die "can't write to data/duplicates.tmp: $!";
open(RDF, ">$datadir/duplicates.tmp")
|| die "can't write to $datadir/duplicates.tmp: $!";
my $headers_done = 0;
while (<CGI>) {
print RDF if $headers_done;
......@@ -96,9 +97,9 @@ while (<CGI>) {
}
close CGI;
close RDF;
if (-s "data/duplicates.tmp") {
rename("data/duplicates.rdf", "data/duplicates-old.rdf");
rename("data/duplicates.tmp", "data/duplicates.rdf");
if (-s "$datadir/duplicates.tmp") {
rename("$datadir/duplicates.rdf", "$datadir/duplicates-old.rdf");
rename("$datadir/duplicates.tmp", "$datadir/duplicates.rdf");
}
sub check_data_dir {
......@@ -182,11 +183,11 @@ sub calculate_dupes {
# Save % count here in a date-named file
# so we can read it back in to do changed counters
# First, delete it if it exists, so we don't add to the contents of an old file
if (my @files = <data/duplicates/dupes$today*>) {
if (my @files = <$datadir/duplicates/dupes$today*>) {
unlink @files;
}
dbmopen(%count, "data/duplicates/dupes$today", 0644) || die "Can't open DBM dupes file: $!";
dbmopen(%count, "$datadir/duplicates/dupes$today", 0644) || die "Can't open DBM dupes file: $!";
# Create a hash with key "a bug number", value "bug which that bug is a
# direct dupe of" - straight from the duplicates table.
......
......@@ -37,7 +37,7 @@
#
# You need to work with bug_email.pl the MIME::Parser installed.
#
# $Id: bug_email.pl,v 1.16 2003/08/22 14:59:13 justdave%syndicomm.com Exp $
# $Id: bug_email.pl,v 1.17 2003/11/22 03:50:41 bbaetz%acm.org Exp $
###############################################################
# 02/12/2000 (SML)
......@@ -69,12 +69,15 @@
use strict;
use MIME::Parser;
chdir '..'; # this script lives in contrib
push @INC, "contrib/.";
push @INC, ".";
BEGIN {
chdir '..'; # this script lives in contrib
push @INC, "contrib/.";
push @INC, ".";
}
require "globals.pl";
require "BugzillaEmail.pm";
use BugzillaEmail;
use Bugzilla::Config qw(:DEFAULT $datadir);
use lib ".";
use lib "../";
......@@ -137,8 +140,8 @@ sub storeAttachments( $$ )
print "Error while reading attachment $decoded_file!\n";
next;
}
# print "unlinking data/mimedump-tmp/$decoded_file";
# unlink "data/mimedump-tmp/$decoded_file";
# print "unlinking $datadir/mimedump-tmp/$decoded_file";
# unlink "$datadir/mimedump-tmp/$decoded_file";
} else {
# data is in the scalar
$data = $decoded_file;
......@@ -248,7 +251,7 @@ sub Reply( $$$$ ) {
die "Cannot find sender-email-address" unless defined( $Sender );
if( $test ) {
open( MAIL, ">>data/bug_email_test.log" );
open( MAIL, '>>', "$datadir/bug_email_test.log" );
}
else {
open( MAIL, "| /usr/sbin/sendmail -t" );
......@@ -697,10 +700,10 @@ my $parser = new MIME::Parser;
# Create and set the output directory:
# FIXME: There should be a $BUGZILLA_HOME variable (SML)
(-d "data/mimedump-tmp") or mkdir "data/mimedump-tmp",0755 or die "mkdir: $!";
(-w "data/mimedump-tmp") or die "can't write to directory";
(-d "$datadir/mimedump-tmp") or mkdir "$datadir/mimedump-tmp",0755 or die "mkdir: $!";
(-w "$datadir/mimedump-tmp") or die "can't write to directory";
$parser->output_dir("data/mimedump-tmp");
$parser->output_dir("$datadir/mimedump-tmp");
# Read the MIME message:
my $entity = $parser->read(\*STDIN) or die "couldn't parse MIME stream";
......
......@@ -31,11 +31,15 @@
use strict;
use MIME::Parser;
chdir ".."; # this script lives in contrib, change to main
push @INC, "contrib";
push @INC, "."; # this script lives in contrib
BEGIN {
chdir ".."; # this script lives in contrib, change to main
push @INC, "contrib";
push @INC, "."; # this script lives in contrib
}
require "globals.pl";
require "BugzillaEmail.pm";
use BugzillaEmail;
use Bugzilla::Config qw(:DEFAULT $datadir);
# Create a new MIME parser:
my $parser = new MIME::Parser;
......@@ -44,10 +48,10 @@ my $Comment = "";
# Create and set the output directory:
# FIXME: There should be a $BUGZILLA_HOME variable (SML)
(-d "data/mimedump-tmp") or mkdir "data/mimedump-tmp",0755 or die "mkdir: $!";
(-w "data/mimedump-tmp") or die "can't write to directory";
(-d "$datadir/mimedump-tmp") or mkdir "$datadir/mimedump-tmp",0755 or die "mkdir: $!";
(-w "$datadir/mimedump-tmp") or die "can't write to directory";
$parser->output_dir("data/mimedump-tmp");
$parser->output_dir("$datadir/mimedump-tmp");
# Read the MIME message:
my $entity = $parser->read(\*STDIN) or die "couldn't parse MIME stream";
......
......@@ -49,6 +49,8 @@ use strict;
use vars qw(@param_list);
use File::Spec; # for find_languages
use Bugzilla::Config qw(:DEFAULT $templatedir $webdotdir);
# Checking functions for the various values
# Some generic checking functions are included in Bugzilla::Config
......@@ -98,10 +100,10 @@ sub check_webdotbase {
return "The file path \"$value\" is not a valid executable. Please specify the complete file path to 'dot' if you intend to generate graphs locally.";
}
# Check .htaccess allows access to generated images
if(-e "data/webdot/.htaccess") {
open HTACCESS, "data/webdot/.htaccess";
if(-e "$webdotdir/.htaccess") {
open HTACCESS, "$webdotdir/.htaccess";
if(! grep(/ \\\.png\$/,<HTACCESS>)) {
return "Dependency graph images are not accessible.\nAssuming that you have not modified the file, delete data/webdot/.htaccess and re-run checksetup.pl to rectify.\n";
return "Dependency graph images are not accessible.\nAssuming that you have not modified the file, delete $webdotdir/.htaccess and re-run checksetup.pl to rectify.\n";
}
close HTACCESS;
}
......@@ -155,8 +157,8 @@ sub check_languages {
return "You need to specify a language tag."
}
foreach my $language (@languages) {
if( ! -d "template/$language/custom"
&& ! -d "template/$language/default") {
if( ! -d "$templatedir/$language/custom"
&& ! -d "$templatedir/$language/default") {
return "The template directory for $language does not exist";
}
}
......@@ -165,7 +167,7 @@ sub check_languages {
sub find_languages {
my @languages = ();
opendir(DIR, "template") || return "Can't open 'template' directory: $!";
opendir(DIR, $templatedir) || return "Can't open 'template' directory: $!";
my @langdirs = grep { /^[a-z-]+$/i } readdir(DIR);
closedir DIR;
......@@ -702,7 +704,7 @@ You will get this message once a day until you\'ve dealt with these bugs!
</ul>
The default value is a publically-accessible webdot server. If you change
this value, make certain that the webdot server can read files from your
data/webdot directory. On Apache you do this by editing the .htaccess file,
webdot directory. On Apache you do this by editing the .htaccess file,
for other systems the needed measures may vary. You can run checksetup.pl
to recreate the .htaccess file if it has been lost.',
type => 't',
......
......@@ -26,7 +26,7 @@ use strict;
use lib qw(.);
use Bugzilla;
use Bugzilla::Config qw(:DEFAULT :admin);
use Bugzilla::Config qw(:DEFAULT :admin $datadir);
require "CGI.pl";
......@@ -111,7 +111,7 @@ foreach my $i (GetParamList()) {
WriteParams();
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "<p>OK, done.</p>\n";
print $howto;
......
......@@ -36,6 +36,7 @@ use vars qw($buffer);
use Bugzilla;
use Bugzilla::Search;
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Constants;
my $cgi = Bugzilla->cgi;
......@@ -116,10 +117,10 @@ my $yesterday = days_ago(1);
use Errno;
use Fcntl;
if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$today",
if (!tie(%dbmcount, 'AnyDBM_File', "$datadir/duplicates/dupes$today",
O_RDONLY, 0644)) {
if ($!{ENOENT}) {
if (!tie(%dbmcount, 'AnyDBM_File', "data/duplicates/dupes$yesterday",
if (!tie(%dbmcount, 'AnyDBM_File', "$datadir/duplicates/dupes$yesterday",
O_RDONLY, 0644)) {
my $vars = { today => $today };
if ($!{ENOENT}) {
......@@ -163,7 +164,7 @@ my $dobefore = 0;
my %delta;
my $whenever = days_ago($changedsince);
if (!tie(%before, 'AnyDBM_File', "data/duplicates/dupes$whenever",
if (!tie(%before, 'AnyDBM_File', "$datadir/duplicates/dupes$whenever",
O_RDONLY, 0644)) {
# Ignore file not found errors
if (!$!{ENOENT}) {
......
......@@ -31,6 +31,7 @@ use lib ".";
require "CGI.pl";
require "globals.pl";
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Series;
# Shut up misguided -w warnings about "used only once". For some reason,
......@@ -471,7 +472,7 @@ if ($action eq 'new') {
}
# Make versioncache flush
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "OK, done.<p>\n";
if ($product) {
......@@ -666,7 +667,7 @@ if ($action eq 'delete') {
print "Components deleted.<P>\n";
SendSQL("UNLOCK TABLES");
unlink "data/versioncache";
unlink "$datadir/versioncache";
PutTrailer($localtrailer);
exit;
}
......@@ -836,7 +837,7 @@ if ($action eq 'update') {
SendSQL("UPDATE components SET name=" . SqlQuote($component) .
"WHERE id=$component_id");
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "Updated component name.<BR>\n";
}
SendSQL("UNLOCK TABLES");
......
......@@ -25,6 +25,8 @@ use lib ".";
require "CGI.pl";
use Bugzilla::Config qw(:DEFAULT $datadir);
use vars qw($template $vars);
my $localtrailer = "<A HREF=\"editkeywords.cgi\">edit</A> more keywords";
......@@ -240,7 +242,7 @@ if ($action eq 'new') {
SqlQuote($description) . ")");
# Make versioncache flush
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "OK, done.<p>\n";
PutTrailer("<a href=\"editkeywords.cgi\">edit</a> more keywords",
......@@ -328,7 +330,7 @@ if ($action eq 'update') {
" WHERE id = $id");
# Make versioncache flush
unlink "data/versioncache";
unlink "$datadir/versioncache";
print Bugzilla->cgi->header();
......@@ -373,7 +375,7 @@ if ($action eq 'delete') {
SendSQL("DELETE FROM keyworddefs WHERE id = $id");
# Make versioncache flush
unlink "data/versioncache";
unlink "$datadir/versioncache";
print Bugzilla->cgi->header();
......
......@@ -19,8 +19,7 @@ use lib ".";
require "CGI.pl";
require "globals.pl";
use Bugzilla::Config qw(:DEFAULT $datadir);
# TestProduct: just returns if the specified product does exists
# CheckProduct: same check, optionally emit an error text
......@@ -315,7 +314,7 @@ if ($action eq 'new') {
SqlQuote($milestone) . ", $product_id, $sortkey)");
# Make versioncache flush
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "OK, done.<p>\n";
PutTrailer("<A HREF=\"editmilestones.cgi?product=$product&amp;action=add\">add</a> another milestone or $localtrailer");
......@@ -456,7 +455,7 @@ if ($action eq 'delete') {
print "Milestone deleted.<P>\n";
SendSQL("UNLOCK TABLES");
unlink "data/versioncache";
unlink "$datadir/versioncache";
PutTrailer($localtrailer);
exit;
}
......@@ -523,7 +522,7 @@ if ($action eq 'update') {
SendSQL("UPDATE milestones SET sortkey=$sortkey
WHERE product_id=" . $product_id . "
AND value=" . SqlQuote($milestoneold));
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "Updated sortkey.<BR>\n";
}
if ($milestone ne $milestoneold) {
......@@ -552,7 +551,7 @@ if ($action eq 'update') {
"SET defaultmilestone = " . SqlQuote($milestone) .
" WHERE id = $product_id" .
" AND defaultmilestone = " . SqlQuote($milestoneold));
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "Updated milestone.<BR>\n";
}
SendSQL("UNLOCK TABLES");
......
......@@ -35,6 +35,8 @@ require "CGI.pl";
require "globals.pl";
use Bugzilla::Series;
use Bugzilla::Config qw(:DEFAULT $datadir);
# Shut up misguided -w warnings about "used only once". "use vars" just
# doesn't work for me.
use vars qw(@legal_bug_status @legal_resolution);
......@@ -432,7 +434,7 @@ if ($action eq 'new') {
}
# Make versioncache flush
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "OK, done.<p>\n";
PutTrailer($localtrailer,
......@@ -675,7 +677,7 @@ if ($action eq 'delete') {
SendSQL("UNLOCK TABLES");
unlink "data/versioncache";
unlink "$datadir/versioncache";
PutTrailer($localtrailer);
exit;
}
......@@ -1200,7 +1202,7 @@ if ($action eq 'update') {
print "Updated product name.<BR>\n";
}
unlink "data/versioncache";
unlink "$datadir/versioncache";
SendSQL("UNLOCK TABLES");
if ($checkvotes) {
......
......@@ -32,8 +32,7 @@ use lib ".";
require "CGI.pl";
require "globals.pl";
use Bugzilla::Config qw(:DEFAULT $datadir);
# TestProduct: just returns if the specified product does exists
# CheckProduct: same check, optionally emit an error text
......@@ -317,7 +316,7 @@ if ($action eq 'new') {
SqlQuote($version) . ", $product_id)");
# Make versioncache flush
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "OK, done.<p>\n";
PutTrailer("<A HREF=\"editversions.cgi?product=$product&amp;action=add\">add</a> another version or $localtrailer");
......@@ -446,7 +445,7 @@ if ($action eq 'delete') {
print "Version deleted.<P>\n";
SendSQL("UNLOCK TABLES");
unlink "data/versioncache";
unlink "$datadir/versioncache";
PutTrailer($localtrailer);
exit;
}
......@@ -527,7 +526,7 @@ if ($action eq 'update') {
SET value=" . SqlQuote($version) . "
WHERE product_id = $product_id
AND value=" . SqlQuote($versionold));
unlink "data/versioncache";
unlink "$datadir/versioncache";
print "Updated version.<BR>\n";
}
SendSQL("UNLOCK TABLES");
......
......@@ -32,7 +32,7 @@ use Bugzilla::DB qw(:DEFAULT :deprecated);
use Bugzilla::Constants;
use Bugzilla::Util;
# Bring ChmodDataFile in until this is all moved to the module
use Bugzilla::Config qw(:DEFAULT ChmodDataFile);
use Bugzilla::Config qw(:DEFAULT ChmodDataFile $localconfig $datadir);
# Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here.
......@@ -68,7 +68,7 @@ sub globals_pl_sillyness {
# XXX - Move this to Bugzilla::Config once code which uses these has moved out
# of globals.pl
do 'localconfig';
do $localconfig;
use DBI;
......@@ -242,7 +242,7 @@ sub GenerateVersionTable {
require File::Temp;
my ($fh, $tmpname) = File::Temp::tempfile("versioncache.XXXXX",
DIR => "data");
DIR => "$datadir");
print $fh "#\n";
print $fh "# DO NOT EDIT!\n";
......@@ -322,8 +322,8 @@ sub GenerateVersionTable {
print $fh "1;\n";
close $fh;
rename $tmpname, "data/versioncache" || die "Can't rename $tmpname to versioncache";
ChmodDataFile('data/versioncache', 0666);
rename $tmpname, "$datadir/versioncache" || die "Can't rename $tmpname to versioncache";
ChmodDataFile("$datadir/versioncache", 0666);
}
......@@ -349,8 +349,8 @@ sub ModTime {
$::VersionTableLoaded = 0;
sub GetVersionTable {
return if $::VersionTableLoaded;
my $mtime = ModTime("data/versioncache");
if (!defined $mtime || $mtime eq "" || !-r "data/versioncache") {
my $mtime = ModTime("$datadir/versioncache");
if (!defined $mtime || $mtime eq "" || !-r "$datadir/versioncache") {
$mtime = 0;
}
if (time() - $mtime > 3600) {
......@@ -358,13 +358,13 @@ sub GetVersionTable {
Token::CleanTokenTable() if Bugzilla->dbwritesallowed;
GenerateVersionTable();
}
require 'data/versioncache';
require "$datadir/versioncache";
if (!defined %::versions) {
GenerateVersionTable();
do 'data/versioncache';
do "$datadir/versioncache";
if (!defined %::versions) {
die "Can't generate file data/versioncache";
die "Can't generate file $datadir/versioncache";
}
}
$::VersionTableLoaded = 1;
......
......@@ -60,6 +60,7 @@ chdir $::path;
use lib ($::path);
use Bugzilla;
use Bugzilla::Config qw(:DEFAULT $datadir);
use XML::Parser;
use Data::Dumper;
......@@ -126,7 +127,7 @@ sub MailMessage {
sub Log {
my ($str) = (@_);
Lock();
open(FID, ">>data/maillog") || die "Can't write to data/maillog";
open(FID, ">>$datadir/maillog") || die "Can't write to $datadir/maillog";
print FID time2str("%D %H:%M", time()) . ": $str\n";
close FID;
Unlock();
......@@ -135,13 +136,13 @@ sub Log {
sub Lock {
if ($::lockcount <= 0) {
$::lockcount = 0;
open(LOCKFID, ">>data/maillock") || die "Can't open data/maillock: $!";
open(LOCKFID, ">>$datadir/maillock") || die "Can't open $datadir/maillock: $!";
my $val = flock(LOCKFID,2);
if (!$val) { # '2' is magic 'exclusive lock' const.
print Bugzilla->cgi->header();
print "Lock failed: $val\n";
}
chmod 0666, "data/maillock";
chmod 0666, "$datadir/maillock";
}
$::lockcount++;
}
......
......@@ -32,6 +32,7 @@ use vars qw($template $userid %COOKIE);
use Bug;
use Bugzilla;
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::BugMail;
$::lockcount = 0;
......@@ -50,7 +51,7 @@ my $cgi = Bugzilla->cgi;
sub Log {
my ($str) = (@_);
Lock();
open(FID, ">>data/maillog") || die "Can't write to data/maillog";
open(FID, ">>$datadir/maillog") || die "Can't write to $datadir/maillog";
print FID time2str("%D %H:%M", time()) . ": $str\n";
close FID;
Unlock();
......@@ -59,13 +60,13 @@ sub Log {
sub Lock {
if ($::lockcount <= 0) {
$::lockcount = 0;
open(LOCKFID, ">>data/maillock") || die "Can't open data/maillock: $!";
open(LOCKFID, ">>$datadir/maillock") || die "Can't open $datadir/maillock: $!";
my $val = flock(LOCKFID,2);
if (!$val) { # '2' is magic 'exclusive lock' const.
print $cgi->header();
print "Lock failed: $val\n";
}
chmod 0666, "data/maillock";
chmod 0666, "$datadir/maillock";
}
$::lockcount++;
}
......
......@@ -23,7 +23,7 @@
###############################################################################
# This CGI is a general template display engine. To display templates using it,
# put them in the "pages" subdirectory of template/en/default, call them
# put them in the "pages" subdirectory of en/default, call them
# "foo.<ctype>.tmpl" and use the URL page.cgi?id=foo.<ctype> , where <ctype> is
# a content-type, e.g. html.
###############################################################################
......
......@@ -37,6 +37,8 @@ use strict;
use lib qw(.);
use Bugzilla::Config qw(:DEFAULT $datadir);
require "CGI.pl";
use vars qw(%FORM); # globals from CGI.pl
......@@ -48,7 +50,7 @@ $@ && ThrowCodeError("gd_not_installed");
eval "use Chart::Lines";
$@ && ThrowCodeError("chart_lines_not_installed");
my $dir = "data/mining";
my $dir = "$datadir/mining";
my $graph_dir = "graphs";
use Bugzilla;
......
......@@ -27,6 +27,7 @@ use lib qw(.);
use File::Temp;
use Bugzilla;
use Bugzilla::Config qw(:DEFAULT $webdotdir);
require "CGI.pl";
......@@ -85,7 +86,7 @@ if (!defined($::FORM{'id'}) && !defined($::FORM{'doall'})) {
my ($fh, $filename) = File::Temp::tempfile("XXXXXXXXXX",
SUFFIX => '.dot',
DIR => "data/webdot");
DIR => $webdotdir);
my $urlbase = Param('urlbase');
print $fh "digraph G {";
......@@ -189,7 +190,7 @@ if ($webdotbase =~ /^https?:/) {
my $dotfh;
my ($pngfh, $pngfilename) = File::Temp::tempfile("XXXXXXXXXX",
SUFFIX => '.png',
DIR => 'data/webdot');
DIR => $webdotdir);
open (DOT, '-|') or exec ($webdotbase, "-Tpng", $filename);
print $pngfh $_ while <DOT>;
close DOT;
......@@ -198,7 +199,7 @@ if ($webdotbase =~ /^https?:/) {
my ($mapfh, $mapfilename) = File::Temp::tempfile("XXXXXXXXXX",
SUFFIX => '.map',
DIR => 'data/webdot');
DIR => $webdotdir);
open (DOT, '-|') or exec ($webdotbase, "-Tismap", $filename);
print $mapfh $_ while <DOT>;
close DOT;
......@@ -209,15 +210,16 @@ if ($webdotbase =~ /^https?:/) {
# Cleanup any old .dot files created from previous runs.
my $since = time() - 24 * 60 * 60;
# Can't use glob, since even calling that fails taint checks for perl < 5.6
opendir(DIR, "data/webdot/");
my @files = grep { /\.dot$|\.png$|\.map$/ && -f "data/webdot/$_" } readdir(DIR);
opendir(DIR, $webdotdir);
my @files = grep { /\.dot$|\.png$|\.map$/ && -f "$webdotdir/$_" } readdir(DIR);
closedir DIR;
foreach my $f (@files)
{
$f = "data/webdot/$f";
$f = "$webdotdir/$f";
# Here we are deleting all old files. All entries are from the
# data/webdot/ directory. Since we're deleting the file (not following
# $webdot directory. Since we're deleting the file (not following
# symlinks), this can't escape to delete anything it shouldn't
# (unless someone moves the location of $webdotdir, of course)
trick_taint($f);
if (ModTime($f) < $since) {
unlink $f;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment