#!/usr/local/bin/perl ############################################################################ # # blacklist.cgi # # A perl script to generate the html form for adding to and removing # sites from the blacklist. # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # ############################################################################ # CHANGE: specify the installed directory of traffic server here $ts_dir = "/home/inktomi/ts-3.5"; $blacklist_file = "$ts_dir/etc/trafficserver/plugins/blacklist.txt"; sub parse_form { local($pairs, $buffer); $request_method = $ENV{"REQUEST_METHOD"}; # These are global, but that $content_length = $ENV{"CONTENT_LENGTH"}; # might not be all bad. # If the method is the empty string, figure we're being invoked # from the shell for testing and so use the string from ARGV[0] if ($request_method eq "") { $buffer = $ARGV[0]; } elsif ($request_method eq "POST") { read(STDIN, $buffer, $content_length); # POST => read from STDIN } elsif ($request_method eq "GET") { $buffer = $ENV{"QUERY_STRING"}; # GET = > read from ENV variable } else { &ReportError("Unrecognized CGI method \"$request_method\"."); } # The following is the standard hack for decoding the pairs # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\r\n/\n/g; $FORM{$name} = $value; } } &parse_form; sub printForm { print "\n"; print "Inktomi Blacklist Plugin\n"; print "\n"; print "

Inktomi Blacklist Plugin

\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 "

Select the site that you want to be removed from the block list

Enter the site that you want to be added to the block list

\"Powered
\n"; print "
\n"; print "\n"; print "\n"; } if ($FORM{'submit'} eq "Remove") { $remove_site = $FORM{'remove_site'}; open(BLACKLIST, $blacklist_file); while () { $site = $_; chop $site; if ($site ne $remove_site) { push(@site_list, $site); } } close(BLACKLIST); open(BLACKLIST, ">$blacklist_file"); foreach $site (@site_list) { print BLACKLIST "$site\n"; } close(BLACKLIST); } elsif ($FORM{'submit'} eq "Add") { open(BLACKLIST, ">>$blacklist_file"); print BLACKLIST "$FORM{'add_site'}\n"; close(BLACKLIST); } &printForm(); exit(0);