Op verzoek van Tim ook file:// urls aankunnen
This commit is contained in:
parent
d80217a5e9
commit
3305750de2
1 changed files with 43 additions and 32 deletions
|
|
@ -160,37 +160,48 @@ end
|
|||
def fetch(uri_str, limit = 10)
|
||||
# You should choose better exception.
|
||||
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
||||
|
||||
host = URI.parse(uri_str).host
|
||||
port = URI.parse(uri_str).port
|
||||
path = URI.parse(uri_str).path
|
||||
query = URI.parse(uri_str).query
|
||||
|
||||
http = Net::HTTP.new(host, port)
|
||||
http.use_ssl = @use_ssl
|
||||
if query
|
||||
req = Net::HTTP::Get.new("#{URI.escape(path)}?#{URI.escape(query)}")
|
||||
if URI.parse(uri_str).scheme.to_s == "file"
|
||||
response = ""
|
||||
if FileTest.exists?(URI.parse(uri_str).path)
|
||||
File.open(URI.parse(uri_str).path).each_line{|line|
|
||||
response += line
|
||||
}
|
||||
else
|
||||
raise "Not found"
|
||||
end
|
||||
response
|
||||
else
|
||||
req = Net::HTTP::Get.new("#{URI.escape(path)}")
|
||||
end
|
||||
req.basic_auth @user, @pass
|
||||
response = http.request(req)
|
||||
case response
|
||||
when Net::HTTPSuccess then response
|
||||
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
|
||||
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
|
||||
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
|
||||
when Net::HTTPForbidden then puts "403 Forbidden #{uri_str}"
|
||||
i# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
|
||||
else
|
||||
response.error!
|
||||
host = URI.parse(uri_str).host
|
||||
port = URI.parse(uri_str).port
|
||||
path = URI.parse(uri_str).path
|
||||
query = URI.parse(uri_str).query
|
||||
|
||||
http = Net::HTTP.new(host, port)
|
||||
http.use_ssl = @use_ssl
|
||||
if query
|
||||
req = Net::HTTP::Get.new("#{URI.escape(path)}?#{URI.escape(query)}")
|
||||
else
|
||||
req = Net::HTTP::Get.new("#{URI.escape(path)}")
|
||||
end
|
||||
req.basic_auth @user, @pass
|
||||
response = http.request(req)
|
||||
case response
|
||||
when Net::HTTPSuccess then response.body
|
||||
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
|
||||
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
|
||||
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"
|
||||
when Net::HTTPForbidden then puts "403 Forbidden #{uri_str}"
|
||||
# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
|
||||
else
|
||||
response.error!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def svnparse(url)
|
||||
puts "\n#{url}"
|
||||
begin
|
||||
body = fetch("#{url}/.svn/entries").body
|
||||
body = fetch("#{url}/.svn/entries")
|
||||
rescue
|
||||
end
|
||||
if body.nil?
|
||||
|
|
@ -255,7 +266,7 @@ def cvsparse(url)
|
|||
puts "\n#{url}"
|
||||
body=[]
|
||||
begin
|
||||
body = fetch("#{url}/CVS/Entries").body
|
||||
body = fetch("#{url}/CVS/Entries")
|
||||
rescue
|
||||
end
|
||||
if body.nil?
|
||||
|
|
@ -281,7 +292,7 @@ def dsparse(url)
|
|||
ds = DSParse.new
|
||||
dirs = Array.new
|
||||
begin
|
||||
body = fetch("#{url}/.DS_Store").body
|
||||
body = fetch("#{url}/.DS_Store")
|
||||
rescue
|
||||
end
|
||||
if body.nil?
|
||||
|
|
@ -298,7 +309,7 @@ def dsparse(url)
|
|||
if entries[x] == '.' or entries[x] == '..'
|
||||
next
|
||||
end
|
||||
body = fetch("#{url}/#{entries[x]}/.DS_Store").body
|
||||
body = fetch("#{url}/#{entries[x]}/.DS_Store")
|
||||
dscheck = DSParse.new
|
||||
dscheck.readstring(body)
|
||||
if dscheck.isds?
|
||||
|
|
@ -317,7 +328,7 @@ end
|
|||
def checksvn(url)
|
||||
begin
|
||||
puts "==================================================="
|
||||
body = fetch("#{url}/.svn/entries").body
|
||||
body = fetch("#{url}/.svn/entries")
|
||||
puts "Subversion info found:"
|
||||
svnparse(url)
|
||||
rescue
|
||||
|
|
@ -327,7 +338,7 @@ end
|
|||
def checkcvs(url)
|
||||
begin
|
||||
puts "==================================================="
|
||||
body = fetch("#{url}/CVS/Entries").body
|
||||
body = fetch("#{url}/CVS/Entries")
|
||||
puts "CVS info found:"
|
||||
cvsparse(url)
|
||||
rescue
|
||||
|
|
@ -337,7 +348,7 @@ end
|
|||
def checkds(url)
|
||||
begin
|
||||
puts "==================================================="
|
||||
body = fetch("#{url}/.DS_Store").body
|
||||
body = fetch("#{url}/.DS_Store")
|
||||
puts ".DS_Store file found:"
|
||||
dsparse(url)
|
||||
rescue
|
||||
|
|
@ -348,7 +359,7 @@ options = cmdline
|
|||
if options["-u"].nil?
|
||||
usage
|
||||
else
|
||||
if ! options["-u"].match(/^http/)
|
||||
if ! options["-u"].match(/^(http|file)/)
|
||||
options["-u"] = "http://#{options["-u"]}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue