From b02f6e0d8a1c26e0f82176a6e79e2405419575b7 Mon Sep 17 00:00:00 2001 From: Wolfram Schneider Date: Wed, 1 Apr 1998 18:24:19 +0000 Subject: [PATCH] Rewritten in perl5. The script use now the standard FreeBSD Web layout functions. --- data/cgi/url.cgi | 107 +++++++++++++++++++++++++++++++++-------------- en/cgi/url.cgi | 107 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 150 insertions(+), 64 deletions(-) diff --git a/data/cgi/url.cgi b/data/cgi/url.cgi index 28d1f1b164..7b6d3ba9e8 100755 --- a/data/cgi/url.cgi +++ b/data/cgi/url.cgi @@ -1,41 +1,84 @@ -#!/bin/sh +#!/usr/local/bin/perl -T +# # Copyright (c) Oct 1997 Wolfram Schneider . Berlin. # All rights reserved. # +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# # url.cgi - make plain text URLs clickable # -# $Id: url.cgi,v 1.3 1997-11-08 14:21:32 wosch Exp $ +# $Id: url.cgi,v 1.4 1998-04-01 18:24:19 wosch Exp $ -PATH=/bin:/usr/bin:/usr/local/bin; export PATH -url="$QUERY_STRING" -case "$url" in - http://*.freebsd.* | http://localhost/* );; - *) printf "Content-type: text/plain\n\n" - printf "Wrong url: \"$url\"\n" - printf "Only http://*.freebsd.* are allowed.\n"; - exit;; -esac +require LWP::UserAgent; -if lynx -dump -head "$url" 2>/dev/null | grep -q "text/plain" -then - printf "Content-type: text/html\n\n
\n"
-    lynx -source "$url" | 
-	perl -npe 's/,;]+)%$1%g;
-    s%([\w\-\.]+\@[\w\-\.]+\.[a-z]+)%$1%g;'
-    echo "
"; +$hsty_base = ''; - # add link to sources - case "$url" in - *pub/FreeBSD/FreeBSD-current/ports/*/*/pkg/DESCR) - echo -n "
Sources" - ;; - esac - echo "" -else - printf "Location: $url\n"; - printf "Content-type: text/plain\n\n"; -fi +require "./cgi-lib.pl"; +require "./cgi-style.pl"; + +$ua = new LWP::UserAgent; +$ua -> max_size(20*1024); + +$file = $ENV{'QUERY_STRING'}; +$uri = "$file"; + +if ($file !~ m%^http://[a-z_\-0-9]+\.freebsd\.(com|org)%i) { + &CgiError(("Wrong url", "Only http://*.freebsd.* is allowed.\n")); + exit(0); +} + + +$request = new HTTP::Request('GET', "$uri"); +$response = $ua->request($request); + +if ($response -> is_success) { + if ($response -> content_type eq "text/plain") { + print &short_html_header("bla"); + print "\n
\n
\n";
+	
+	my($content) = $response -> content;
+	$content =~ s/,;]+)%$1%g;
+	print $content;
+	print "
\n"; + + # Add 'source' link for freebsd ports + if ($file =~ + m%pub/FreeBSD/FreeBSD-current/(ports/[^/]+/[^/]+)/pkg/DESCR$%) { + print qq{
Sources\n}; + print qq{| Help\n}; + print qq{
\n}; + } + print &html_footer; + exit; + } else { + # no plain text, do a redirect + print "Location: $uri\n"; + print "Content-type: text/plain\n\n"; + } +} else { + # quick and dirty hack for non existings urls + print "Location: $uri\n"; + print "Content-type: text/plain\n\n"; +} diff --git a/en/cgi/url.cgi b/en/cgi/url.cgi index 28d1f1b164..7b6d3ba9e8 100755 --- a/en/cgi/url.cgi +++ b/en/cgi/url.cgi @@ -1,41 +1,84 @@ -#!/bin/sh +#!/usr/local/bin/perl -T +# # Copyright (c) Oct 1997 Wolfram Schneider . Berlin. # All rights reserved. # +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# # url.cgi - make plain text URLs clickable # -# $Id: url.cgi,v 1.3 1997-11-08 14:21:32 wosch Exp $ +# $Id: url.cgi,v 1.4 1998-04-01 18:24:19 wosch Exp $ -PATH=/bin:/usr/bin:/usr/local/bin; export PATH -url="$QUERY_STRING" -case "$url" in - http://*.freebsd.* | http://localhost/* );; - *) printf "Content-type: text/plain\n\n" - printf "Wrong url: \"$url\"\n" - printf "Only http://*.freebsd.* are allowed.\n"; - exit;; -esac +require LWP::UserAgent; -if lynx -dump -head "$url" 2>/dev/null | grep -q "text/plain" -then - printf "Content-type: text/html\n\n
\n"
-    lynx -source "$url" | 
-	perl -npe 's/,;]+)%$1%g;
-    s%([\w\-\.]+\@[\w\-\.]+\.[a-z]+)%$1%g;'
-    echo "
"; +$hsty_base = ''; - # add link to sources - case "$url" in - *pub/FreeBSD/FreeBSD-current/ports/*/*/pkg/DESCR) - echo -n "
Sources" - ;; - esac - echo "" -else - printf "Location: $url\n"; - printf "Content-type: text/plain\n\n"; -fi +require "./cgi-lib.pl"; +require "./cgi-style.pl"; + +$ua = new LWP::UserAgent; +$ua -> max_size(20*1024); + +$file = $ENV{'QUERY_STRING'}; +$uri = "$file"; + +if ($file !~ m%^http://[a-z_\-0-9]+\.freebsd\.(com|org)%i) { + &CgiError(("Wrong url", "Only http://*.freebsd.* is allowed.\n")); + exit(0); +} + + +$request = new HTTP::Request('GET', "$uri"); +$response = $ua->request($request); + +if ($response -> is_success) { + if ($response -> content_type eq "text/plain") { + print &short_html_header("bla"); + print "\n
\n
\n";
+	
+	my($content) = $response -> content;
+	$content =~ s/,;]+)%$1%g;
+	print $content;
+	print "
\n"; + + # Add 'source' link for freebsd ports + if ($file =~ + m%pub/FreeBSD/FreeBSD-current/(ports/[^/]+/[^/]+)/pkg/DESCR$%) { + print qq{
Sources\n}; + print qq{| Help\n}; + print qq{
\n}; + } + print &html_footer; + exit; + } else { + # no plain text, do a redirect + print "Location: $uri\n"; + print "Content-type: text/plain\n\n"; + } +} else { + # quick and dirty hack for non existings urls + print "Location: $uri\n"; + print "Content-type: text/plain\n\n"; +}