#!/usr/bin/perl # # $Id: bugsitecfg.pl,v 1.3 2004/01/29 07:57:04 jeffo Exp $ # # Source File: bugsitecfg.pl $pathsep="/"; $docroot = "/usr/local/httpd/defects"; $pubroot = $docroot; $resptmplt = $docroot; $dataroot = "/usr/local/httpd/defects/data"; $graphroot = join($pathsep, "\.\.", "graphic"); $cgiurl = "/cgi-bin"; $acceptpost = 1; $acceptget = 1; sub app_initialize { # set variables from query parameters based on the request method $reqmeth = $ENV{'REQUEST_METHOD'}; @cookies = split(/\;/,$ENV{'HTTP_COOKIE'}); foreach $cookie (@cookies) { ($nm, $vlu) = split(/=/, $cookie); $nm =~ s/ //g; $vlu =~ tr/+/ /; $vlu =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $COOKIES{$nm} = $vlu; } if ($reqmeth =~ /POST/i) { if ($acceptpost) { read (STDIN, $qstr, $ENV{'CONTENT_LENGTH'});} } else { if ($reqmeth =~ /GET/i) { if ($acceptget) { $qstr=$ENV{'QUERY_STRING'};} } } if ($qstr) { $contenttype=$ENV{'CONTENT_TYPE'}; if ($contenttype =~ 'multipart/form-data') { $srch="boundary\="; ($trash,$boundary) = split(/$srch/, $contenttype); ($boundary, $trash) = split(/ /, $boundary); $endboundary = join('', $boundary, "\-\-"); $boundary = join('', $boundary, "\r\n"); ($qstr, $trash) = split(/$endboundary/, $qstr); @parts = split(/$boundary/, $qstr); $trash = shift @parts; $consep = "\r\n\r\n"; foreach $part (@parts) { ($contype, $content) = split(/$consep/, $part); if ($contype ne '') { chop($content); chop($content); $contype =~ s/\: /=/g; $contype =~ s/\r\n/; /g; @lines = split(/\; /, $contype); $nme = ""; $fname = ""; $ftype = ""; foreach $line (@lines) { $line =~ s/\"//g; ($nm,$vlu) = split(/=/, $line); $vlu =~ tr/+/ /; $vlu =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; if ($nm eq 'filename') { @segs = split(/\./, $vlu); $ftype = $segs[$#segs]; } else { if ($nm eq 'name') { $nme = $vlu; } } } if ($ftype eq '') { $content =~ s/\r\n//g; $content =~ tr/+/ /; $content =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $FORM{$nme} = $content; } else { $content =~ s/(.*)\r\n/$1/; $outfile=join($pathsep, $dataroot, "$nme.$ftype"); open (OUTFILE, ">$outfile") or $msg="failed"; if ($msg ne "failed") { binmode(OUTFILE); print OUTFILE $content; close OUTFILE; } } } } } else { # parse request parameters into variables @parameters = split(/&/, $qstr); foreach $pair (@parameters) { ($nm, $vlu) = split(/=/, $pair); $vlu =~ tr/+/ /; $vlu =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $FORM{$nm} = $vlu; } unless ($language) {$FORM{'lng'}="us";} } return 1; } else { return 0; } } sub verifyaccess { $FORM{'uac'} = ""; $tmpfile = "admin.dat"; @pairs = &get_data($tmpfile); foreach $pair (@pairs) { chop ($pair); ($id, $pw, $pv, $clid, $lstid, $eml) = split(/&/, $pair); if ($id eq $FORM{'uid'}) { if ($pw eq $FORM{'pwd'}) { return 1; } } } return 0; } sub retrieve_email_address { $tmpfile = "admin.dat"; @pairs = &get_data($tmpfile); foreach $pair (@pairs) { chop ($pair); ($id, $pw, $pv, $clid, $lstid, $eml) = split(/&/, $pair); if ($id eq $FORM{'uid'}) { # $eml =~ s/\@/\\\@/; return $eml; } } return ""; } sub xlatline { $xltline = $_[0]; if ($xltline =~ /<%=(.*)%>/ ) { if ($xltline =~ /<%=FORM\.(.*)%>/i ) { for (keys %FORM) { $repl = $FORM{$_}; $srch1 = join('', "<%=FORM.", $_, "%>"); $xltline =~ s/$srch1/$repl/g; } } $xltline =~ s/<%=(.*)%>//g; print "$xltline"; } else { print "$xltline"; } return $xltline; } sub get_data { $tmpfile = join($pathsep, $dataroot, "$_[0]"); open (TMPFILE, "<$tmpfile"); @locallines = ; close TMPFILE; return @locallines; } sub get_template { $tmpfile = join($pathsep, $docroot, "$_[0].htt"); open (TMPFILE, "<$tmpfile"); @locallines = ; close TMPFILE; return @locallines; } sub show_template { @lines = &get_template($_[0]); foreach $line (@lines) { $line = &xlatline($line); } } sub get_report { $trash = join($pathsep, $dataroot, $_[0]); @lines = &get_data($_[0]); foreach $line (@lines) { chop ($line); ($nm,$vlu) = split(/=/, $line); $vlu =~ tr/+/ /; $vlu =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $vlu =~ s/
/\r\n/g; $REPORT{$nm} = $vlu; } @lines = (); } sub put_report { $updtrep = 0; if ($_[0] eq '') { opendir (DIR, $dataroot); @dots = readdir(DIR); closedir DIR; $rptfile = "rptdefect.000"; foreach $dot (@dots) { if ($dot =~ /rptdefect./ ) { ($trash, $dno) = split(/\./, $dot); ($trash, $rno) = split(/\./, $rptfile); if ($dno > $rno) { $rptfile = $dot; } } } @dots =(); ($fnm,$cnt) = split(/\./, $rptfile); $cnt++; $rptfile = sprintf("%s.%03d", $fnm, $cnt); $REPORT{'reportno'}=$rptfile; $updtrep = 0; } else { $REPORT{'reportno'}=$_[0]; $updtrep = 1; } $tmpfile = join($pathsep, $dataroot, $REPORT{'reportno'}); open (TMPFILE, ">$tmpfile"); for (keys %REPORT) { $vlu = $REPORT{$_}; $vlu =~ tr/ /+/; $vlu =~ s/\r\n/
/g; $vlu =~ s/([&!#^~=])/unpack("C",hex($1))/eg; print TMPFILE "$_=$vlu\n"; } close TMPFILE; $chmodok = chmod 0666, $tmpfile; $emailaddress = &retrieve_email_address(); if ($emailaddress ne '') { if ($updtrep) { &send_change_notice($emailaddress); } else { &send_post_notice($emailaddress); } } } sub show_detail { $time = time; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
Number:\n"; print " $REPORT{'reportno'}\n"; print "
Submitted by:\n"; print " \n"; print " Status: \n"; print "
Title:\n"; print " \n"; print "
Description:\n"; print " \n"; print "
Additional Details:\n"; print " \n"; print "
Fix/Work Around:\n"; print " \n"; print "
 \n"; print " \n"; print "
\n"; print "
\n"; print "\n"; print "\n"; } sub send_mail { open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or $msg2 = "Can't fork for sendmail: $!\n"; print SENDMAIL <<"EOF"; From: $_[0] To: $_[1] Subject: $_[2] $_[3] EOF close(SENDMAIL) or $msg2 = "sendmail didn't close nicely"; } sub send_post_notice { $mmautontfyfrom=$_[0]; $mmautontfyto="support\@test-central.com"; $mmdate = &format_date_time("dd-mmm-yyyy", "1", "0"); $mmtime = &format_date_time("hh:nn:ss", "1", "0"); $mmsubj = "Test Central Bug List Entry"; $mmbody = "Date: $mmdate Report Number: $REPORT{'reportno'} Submitted by: $REPORT{'submittedby'} Title: $REPORT{'title'} Description: $REPORT{'desc'} "; &send_mail($mmautontfyfrom, $mmautontfyto, $mmsubj, $mmbody); } sub send_change_notice { $mmautontfyfrom="support\@test-central.com"; $mmautontfyto=$_[0]; $mmdate = &format_date_time("dd-mmm-yyyy", "1", "0"); $mmtime = &format_date_time("hh:nn:ss", "1", "0"); $mmsubj = "Test Central Bug Entry Reclassification"; $mmbody = "Date: $mmdate The Test-Central Bug report $REPORT{'reportno'} you filed has been reclassified as follows: Title: $REPORT{'title'} Status Changed: $REPORT{'status'} Corrective Action: $REPORT{'fix'} "; &send_mail($mmautontfyfrom, $mmautontfyto, $mmsubj, $mmbody); } sub format_date_time { $sformatted = $_[0]; if ($_[1] == '1') { if ($_[2]=='-1') { @tmvalues = gmtime(time-1000); } else { if ($_[2]=='-10000') { @tmvalues = gmtime($_[3]); } else { @tmvalues = gmtime(time+$_[2]); } } } else { if ($_[2]=='-1') { @tmvalues = localtime(time-1000); } else { if ($_[2]=='-10000') { @tmvalues = localtime($_[3]); } else { @tmvalues = localtime(time+$_[2]); } } } $ss = sprintf( "%02d", $tmvalues[0]); $nn = sprintf( "%02d", $tmvalues[1]); $h = sprintf( "%d", $tmvalues[2]); $hh = sprintf( "%02d", $tmvalues[2]); $dd = sprintf( "%02d", $tmvalues[3]); $mm = sprintf( "%02d", $tmvalues[4]+1); $mmm = format_month($tmvalues[4], "0"); $mmmm = format_month($tmvalues[4], "1"); $yy = format_year($tmvalues[5], "0"); $yyyy = format_year($tmvalues[5], "1"); $ddd = format_day_of_week($tmvalues[6], "0"); $dddd = format_day_of_week($tmvalues[6], "1"); $sformatted =~ s/ss/$ss/ig; $sformatted =~ s/nn/$nn/ig; $sformatted =~ s/hh/$hh/ig; $sformatted =~ s/h/$h/ig; $sformatted =~ s/dddd/$dddd/ig; $sformatted =~ s/ddd/$ddd/ig; $sformatted =~ s/dd/$dd/ig; $sformatted =~ s/mmmm/$mmmm/ig; $sformatted =~ s/mmm/$mmm/ig; $sformatted =~ s/mm/$mm/ig; $sformatted =~ s/yyyy/$yyyy/ig; $sformatted =~ s/yy/$yy/ig; return $sformatted; } sub format_day_of_week { @dayarray = ( ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] ); return $dayarray[$_[1]][$_[0]]; } sub format_month { @montharray = ( ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] ); return $montharray[$_[1]][$_[0]]; } sub format_year { if ($_[0] > '99') { if ($_[1] == '0') { return sprintf("%02d", $_[0]-100); } else { return sprintf("%04d", $_[0]+1900); } } else { if ($_[1] == '0') { return sprintf("%02d", $_[0]); } else { return sprintf("%04d", $_[0]+1900); } } } # end with True because this is a require file 1