#!/bin/awk -f # # @(#)$Id: go,v 1.7 2002/09/11 17:06:50 baron Exp $ (c) Peter Klausner # BEGIN { # customize... data = "/boot/home/twiki/data" url = "http://localhost/twiki" view = url "/view" search = "/?web=all&scope=text&search=" interwiki = data "/TWiki/InterWikis.txt" errorinfo = view "/TWiki/GoPlugin" if (ARGV[1] != "") { if (ARGV[2] != "") { wiki = ARGV[1] page = ARGV[2] } else page = ARGV[1] # and wiki is empty, fill w/referer } else if (ENVIRON["PATH_INFO"] != "") { n = split(ENVIRON["PATH_INFO"], path, "/") wiki = path[n - 1] page = path[n] } else if (ENVIRON["QUERY_STRING"] != "") { wiki = ENVIRON["QUERY_STRING"] sub("^.*wiki=", "", wiki); sub("&.*$", "", wiki) page = ENVIRON["QUERY_STRING"] sub("^.*page=", "", page); sub("&.*$", "", page) # no proper wiki=...&page=... given; try whatever var's there... if (page ~ "=") { wiki = "" # find out from referer later on sub("^.*=", "", page); sub("&.*$", "", page) } } else { err("no arguments found") } if (! match(wiki, "^[A-Za-z0-9]+$")) { # empty or special arg1/wiki if (match(page, "([.+:]|%..)")) { # alias web.interwiki:syntax ? wiki = substr(page, 1, RSTART-1) page = substr(page, RSTART+RLENGTH) gsub("%2F", "/", page) # undo URLencoding of "/" } else { # page normal -> try web=referer n = split(ENVIRON["HTTP_REFERER"], path, "/") wiki = path[n - 1] } } # (1) try local file try_file(wiki, page) # (2) try alias try_interwiki(wiki, page) # (3) try search print "Location: " url "/search/" wiki search page"\n" } function try_file(web, topic, _try_file, _n, _i) { _try_file = data "/" web "/" topic ".txt" if (getline < _try_file > 0) { print "Location: " view "/" web "/" topic "\n\n" exit } topic = tolower(topic) # no exact match, scan directory case insens. _n = 0 while ("ls " data "/" web | getline) { if (! match($0, "\.txt$")) \ continue _try_file = tolower($0) if (index(_try_file, topic)) { sub(".txt$", "") ls[++_n] = $0 } } if (_n == 0) { # no match at all return 0 } else if (_n == 1) { # one case insensitive match print "Location: " view "/" web "/" ls[1] "\n" exit } else { # offer selection of multiple matches print "Content-type: text/html" print "" print "