#!/usr/bin/perl # # cusi.pl: configurable unified search index # # $Id: cusi.pl,v 1.1 1994/11/04 18:42:49 mak Exp mak $ # # By Martijn Koster # # Now dual plexus module and CGI script # # Expects a URL in the "service" field with a '+', # replaces this '+' with the "query" field, and # refer's the client to that new URL with Location. # # Now also supports '_cusi-search-term-here_' instead of '+' # to combat a bug in Lynx. This is probably preferable in any case # # This allows easy creation of forms with menus and radio # buttons for send the same query to a number of different # search engines. # for an example. package cusi; # OK, so most browser don't handle VALUE, pain. # So until they do, people will need to use SUSI. # But I don't want to have to update that, so # I have added a SUSI compatibility mode to CUSI, # and use that instead of the current SUSI (which # I'll keep running on it's own, but not maintain). # This is simply a %services OPTION name to # VALUE translation table, required at load time. # # Note: you will need to adjust the require $map = "/data/httpd/lanet_htdocs/services/cusi/src/susi-map.pl"; if (-e $map) { # not really required, just for backward compatibility with broken clients. require $map; } &do_cusi($ENV{'QUERY_STRING'}); sub do_cusi_strict { undef(%services) if (defined %services); &do_cusi(@_); } sub do_cusi { local($query) = @_; if (!$query) { &error("Please specify a search term"); return; } for(split('&', $query)) { ($tag, $value) = split('=', $_, 2); if ($tag eq 'service') { $value =~ s/\+/ /g; $value =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; $service = $value; } elsif ($tag eq 'query') { $keywords = $value; } else { &error("Unknown tag: '$tag'."); } } if (!$keywords) { &error('Please specify a search term.'); return; } if ($service !~ /\w+:/) { &debug("invalid service tag: '$service'\n"); # doesn't look like a URL # either the browser doesn't support the VALUE, # or the VALUE is screwed. # SUSI compatibility mode if (defined %services && $services{$service}) { $service = $services{$service}; &debug("translated to: '$service'\n"); } } if ($service !~ /\w+:/) { # special-case Lynx # only temporarily; this makes the code # needlessly complicated $useragent = $ENV{'HTTP_USER_AGENT'}; # CGI if ($useragent =~ /Lynx/i && $service eq '') { &lynx_bug; return; } else { &error("The service encoding was bogus, '$service' is not a valid URL. There is either a bug in the HTML file you are using, your browser doesn't support the VALUE option attribute."); } } if($service=~s/_cusi-search-term-here_/$keywords/) { # uses the '_cusi-search-term-here_' } elsif($service=~s/\+/$keywords/) { # uses the + } else { &error(q!The service specified had no indicated position for search keywords to incorporated into the URL.!); } $service=~s/_cusi-plus_/\+/g; # to combat Lynx bug for David Rosen print <<"EOM"; Location: $service URI: $service Content-type: text/html This document has moved to $service EOM } sub error { local($msg) = @_; print <<"EOM"; Status: 400 Bad Request Content-type: text/plain $msg EOM } sub lynx_bug { print < Lynx Bug

Lynx Bug

Your version of Lynx has got a know bug in it, which is why the request from this form failed. You can use this radio-buttion CUSI in the US instead. The bug will be fixed in a future version of Lynx. EOM } sub debug { } 1;