#!/star/Perl/bin/perl

require 'server.pl';
$baseURL="http://surveys.roe.ac.uk/wsa/";
$baseDisk="/home/mar/";#"/thoth/www/wsa/";
#$logDir="/thoth/www/wsa/tmp/logs/";
$logDir=$TMPWEB."logs/";

$webDirSubs="/thoth/www/wsa/";
$cgiURLSubs="http://surveys.roe.ac.uk/~mar/cgi-bin/";
#$logDir="/home/mar/thoth/cgi-bin/";
$diskFile=$baseDisk."disksOffline.txt";
sub cgiLog {
    my $cgiName=$_[0];
    my $ip=$_[1];
    my $bytesSent=$_[2];
    my $extra=$_[3];
    my $err=$_[4];
    my $logString=$cgiName.",".$ip.",".$bytesSent.",".$extra.",".$err;
($sec,$min,$hour,$day,$mon,$year,$a1,$a2,$a3) = localtime (time);

$year=$year+1900;

$thisMonth= (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
$mon++;
$timeStamp=sprintf("%02d",$day)."/".$thisMonth."/".$year." ".sprintf("%02d",$hour).":".sprintf("%02d",$min).":".sprintf("%02d",$sec);
$logFile=$logDir."cgi".$year."_".sprintf("%02d",$mon)."_".sprintf("%02d",$day).".log";
$logString=$timeStamp.",".$logString;
open(LOGFILE, ">> $logFile") || die "cant open logfile: $!";
print LOGFILE "$logString\n";
close(LOGFILE);
} 

sub isDiskOnline {
	my $path=$_[0];
	$pos1=index($path,"/",0);
	$pos2=index($path,"/",$pos1+1);
	if ($pos1 >=0 && $pos2 > $pos1) {
	$disk=substr($path,$pos1,$pos2-$pos1);
	if (-e $diskFile) {
		open (DISKFILE, "< $diskFile") || die return 1;
		while (<DISKFILE>) {
			if (/$disk/) {
				#print "match \n";
				return 0;
			}
		}
	#print "$disk \n";
	return 1;
	}
	}
	else {
		return 1;
	}
	return ($pos1,$pos2);
	
}

