Skip to content

Instantly share code, notes, and snippets.

@rsayers
Created November 16, 2009 21:28
Show Gist options
  • Save rsayers/236332 to your computer and use it in GitHub Desktop.
Save rsayers/236332 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'gopherclient'
$types ={
"0"=>"TXT",
"1"=>"DIR",
"2"=>"CSO",
"3"=>"ERR",
"4"=>"HEX",
"5"=>"ARC",
"6"=>"UUE",
"7"=>"QUE",
"8"=>"TEL",
"9"=>"BIN",
"g"=>"GFX",
"h"=>"HTM",
"s"=>"AUD"
}
get '/*' do |url|
url = "gopher.robsayers.com" if !url
output = "<form method='post' action='/go'><input size='40' name='url' value='#{url}'><input type='submit' value='Go'>"
output += "<pre>"
g=GopherClient.new
host,type,path=g.parseurl(url)
body=g.getdoc(url)
case type
when "0"
output += body
when "1"
res=[]
count=1
lines=body.split("\n")
lines.each do |l|
linedata = l.split("\t")
linetype=l[0]
desc=linedata[0][1,linedata[0].length-1]
if type=='i' || $types[linetype].nil?
output += desc + "\n"
else
output += "<a href='/#{linedata[2]}/#{linetype}#{linedata[1]}'>#{desc}</a>\n"
end
end
end
output
end
post '/go' do
redirect "/"+params[:url],303
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment