1998-06-17 01:43:24 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# The contents of this file are subject to the Netscape Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/NPL/
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
1998-06-17 01:43:24 +04:00
|
|
|
#
|
|
|
|
# The Original Code is the Bonsai CVS tool.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 02:33:56 +03:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
1998-06-17 01:43:24 +04:00
|
|
|
|
1999-04-09 18:22:53 +04:00
|
|
|
use DBD::mysql;
|
1998-06-17 01:43:24 +04:00
|
|
|
|
|
|
|
require 'header.pl';
|
|
|
|
|
|
|
|
$lockcount = 0;
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
|
|
|
|
sub Lock {
|
|
|
|
if ($lockcount <= 0) {
|
|
|
|
$lockcount = 0;
|
|
|
|
if (!open(LOCKFID, ">>data/lockfile")) {
|
|
|
|
mkdir "data", 0777;
|
|
|
|
chmod 0777, "data";
|
|
|
|
open(LOCKFID, ">>data/lockfile") || die "Can't open lockfile.";
|
|
|
|
}
|
|
|
|
my $val = flock(LOCKFID,2);
|
|
|
|
if (!$val) { # '2' is magic 'exclusive lock' const.
|
|
|
|
print "Lock failed: $val\n";
|
|
|
|
}
|
|
|
|
chmod 0666, "data/lockfile";
|
|
|
|
}
|
|
|
|
$lockcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub Unlock {
|
|
|
|
$lockcount--;
|
|
|
|
if ($lockcount <= 0) {
|
|
|
|
flock(LOCKFID,8); # '8' is magic 'unlock' const.
|
|
|
|
close LOCKFID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub loadConfigData {
|
|
|
|
if (@treelist > 0) {return;}
|
|
|
|
local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
|
|
|
$atime,$pmtime,$ctime,$blksize,$blocks) = stat("data/configdata.pl");
|
|
|
|
local $tmtime;
|
|
|
|
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
|
|
|
$atime,$tmtime,$ctime,$blksize,$blocks) = stat("data/configdata");
|
|
|
|
|
|
|
|
if ($pmtime eq "" || $pmtime < $tmtime) {
|
|
|
|
system "./perlifyconfig.tcl";
|
|
|
|
}
|
|
|
|
|
|
|
|
open(CONFIGDATA, "<data/configdata.pl") || die "Can't open configdata.pl";
|
|
|
|
while (<CONFIGDATA>) {
|
|
|
|
eval;
|
|
|
|
}
|
|
|
|
close CONFIGDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub pickDefaultRepository {
|
|
|
|
loadConfigData();
|
|
|
|
return $treeinfo{$treelist[0]}->{'repository'};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub getRepositoryList {
|
|
|
|
loadConfigData();
|
|
|
|
my @result = ();
|
|
|
|
TREELOOP: foreach my $i (@treelist) {
|
|
|
|
my $r = $treeinfo{$i}->{'repository'};
|
|
|
|
foreach my $j (@result) {
|
|
|
|
if ($j eq $r) {
|
|
|
|
next TREELOOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
push @result, $r;
|
|
|
|
}
|
|
|
|
return @result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub validateRepository {
|
|
|
|
my ($root) = @_;
|
|
|
|
my @list = getRepositoryList();
|
|
|
|
foreach my $r (@list) {
|
|
|
|
if ($r eq $root) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-04-30 22:38:50 +04:00
|
|
|
print "Invalid repository $root selected. Send mail to $cvsadmin if you think this should have worked.\n";
|
1998-06-17 01:43:24 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub ConnectToDatabase {
|
|
|
|
if ($dbh == "") {
|
1999-06-15 19:32:25 +04:00
|
|
|
$dbh = DBI->connect("bonsai","$mysqluser","$mysqlpassword","mysql") || die "Can't connect to database server -- $DBD::mysql::db_errstr";
|
1998-06-17 01:43:24 +04:00
|
|
|
}
|
|
|
|
return $dbh;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub formatSqlTime {
|
|
|
|
my $when = @_[0];
|
|
|
|
my($sec,$minute,$hour,$mday,$mon,$year) = localtime( $when );
|
|
|
|
return sprintf("%04d-%02d-%02d %02d:%02d:%02d",
|
|
|
|
$year + 1900, $mon + 1, $mday,
|
|
|
|
$hour, $minute, $sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub SqlQuote {
|
|
|
|
$_ = @_[0];
|
|
|
|
s/'/''/g;
|
|
|
|
s/\\/\\\\/g;
|
|
|
|
return $_;
|
|
|
|
}
|
1998-06-18 20:47:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
# Returns true if the given directory or filename is one of the hidden ones
|
|
|
|
# that we don't want to show users.
|
|
|
|
|
|
|
|
sub IsHidden {
|
|
|
|
my ($name) = (@_);
|
|
|
|
$name =~ s:///*:/:g; # Remove any multiple slashes.
|
|
|
|
if (!defined @hidelist) {
|
|
|
|
if (open(HIDE, "<data/hidelist")) {
|
|
|
|
while (<HIDE>) {
|
|
|
|
chop;
|
|
|
|
s/^\s*//g; # Strip leading whitespace
|
|
|
|
s/\s*$//g; # Strip trailing whitespace
|
|
|
|
if ( /^#/ || /^$/) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
push(@hidelist, $_);
|
|
|
|
}
|
|
|
|
close HIDE;
|
|
|
|
} else {
|
|
|
|
@hidelist = ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $item (@hidelist) {
|
|
|
|
if ($name =~ m/$item/) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub CheckHidden {
|
|
|
|
my ($name) = (@_);
|
|
|
|
if (IsHidden($name)) {
|
|
|
|
$| = 1;
|
|
|
|
print "";
|
|
|
|
die "Security violation; not allowed to access $name.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|