#!/usr/bin/perl $dir = "infra"; #just path (no filename) $template_path = "/net/cs/htdocs/groups/ebu3b/cgi-bin"; # just path (no filename) $comments_file_path = "/net/cs/htdocs/groups/ebu3b/$dir"; # URL $url = "http://www-cse.ucsd.edu/groups/ebu3b/$dir/comm.html"; $topic = $vars{NAME}; #if ($topic =~ /^(.)/) { $first = $1 }; #$topic =~ s/([a-zA-Z]).*[ ]+//g; #$topic = "$first$topic"; #$topic =~ tr/[A-Z]/[a-z]/; $line = $ENV{QUERY_STRING}; if ($ENV{REQUEST_METHOD} ne "GET") { $line = ; } $line =~ s/\+/ /g; while ($line =~ /\%([A-F0-9]{2})/) { $hex = $1; $ch = chr(hex($hex)); $line =~ s/\%$hex/$ch/g; } $line =~ s/\n/
/g; $line =~ tr/\a\b\n\r/ /; @pairs = split(/&/, $line); foreach $var_val (@pairs) { if ($var_val =~ /([A-Z]+)=(.+)/) { $vars{$1} = $2; } } print "Content-type: text/html\n\n"; #print "$vars{FUNC}\n"; if ($vars{FUNC} eq "VIEW") { if (-f "$comments_file_path/comm.html") { print "\n"; print "\n"; print "\n"; } else { print "\n"; print " No Comments \n"; print "\n"; print " Sorry, No Comments have been made for $vars{NAME}\n"; #print "

Back\n"; print "

Back\n"; print "\n"; } } elsif ($vars{FUNC} eq "MAKE") { open (FD, "$template_path/form.tmpl") || die "$!"; foreach $current_line () { $current_line =~ s/\%NAME%/$vars{NAME}/g; print "$current_line"; } close(FD); } elsif ($vars{FUNC} eq "SUBMIT") { chomp($time = `date`); # file lock # for ($ctr = 0; (-f "/tmp\/$topic.tmp") && ($ctr < 3); $ctr++) # { # sleep(1); # } # # open(LOCK, ">/tmp\/$topic.tmp") || die; # close(LOCK); if (-f "$comments_file_path/comm.html") { open(FD, "$comments_file_path/comm.html") || die; @text = ; close(FD); } else { open(FD, "$template_path/apphtml.tmpl") || die; @text = ; close(FD); #$refer = "Back to Previous Page\n"; $refer = "Back to Previous Page\n"; $end = "\n"; foreach $line (@text) { $line =~ s/%NAME%/$vars{NAME}/g; if ($line =~ /END/){$line ="$refer$end";} } } #print "Hello\n"; open(FD, ">$comments_file_path/comm.html") || die; foreach $line (@text) { # if we move this to the end of the block # comments will be in first -> last order # as opposed to last -> first print FD "$line"; if ($line =~ /META DATA_BEGIN/) { $vars{COMMENTS} =~ tr/[\n\r]//; print FD "

\n"; print FD "\n"; print FD "$Comment by: $vars{USER} on $time\n"; #make this more readable in html file #perhaps newline every 80 chars print FD "

$vars{COMMENTS}
\n"; } } close(FD); unlink("/tmp\/$topic.tmp"); #$url .= "\/$topic/comm.html"; # $urln= "$ENV{HTTP_REFERER}"; print "\n"; print "\n"; print "\n"; }