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,7 +160,17 @@ end
|
||||||
def fetch(uri_str, limit = 10)
|
def fetch(uri_str, limit = 10)
|
||||||
# You should choose better exception.
|
# You should choose better exception.
|
||||||
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
||||||
|
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
|
||||||
host = URI.parse(uri_str).host
|
host = URI.parse(uri_str).host
|
||||||
port = URI.parse(uri_str).port
|
port = URI.parse(uri_str).port
|
||||||
path = URI.parse(uri_str).path
|
path = URI.parse(uri_str).path
|
||||||
|
|
@ -176,21 +186,22 @@ def fetch(uri_str, limit = 10)
|
||||||
req.basic_auth @user, @pass
|
req.basic_auth @user, @pass
|
||||||
response = http.request(req)
|
response = http.request(req)
|
||||||
case response
|
case response
|
||||||
when Net::HTTPSuccess then response
|
when Net::HTTPSuccess then response.body
|
||||||
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
|
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::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::HTTPForbidden then puts "403 Forbidden #{uri_str}"
|
||||||
i# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
|
# when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"
|
||||||
else
|
else
|
||||||
response.error!
|
response.error!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def svnparse(url)
|
def svnparse(url)
|
||||||
puts "\n#{url}"
|
puts "\n#{url}"
|
||||||
begin
|
begin
|
||||||
body = fetch("#{url}/.svn/entries").body
|
body = fetch("#{url}/.svn/entries")
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
if body.nil?
|
if body.nil?
|
||||||
|
|
@ -255,7 +266,7 @@ def cvsparse(url)
|
||||||
puts "\n#{url}"
|
puts "\n#{url}"
|
||||||
body=[]
|
body=[]
|
||||||
begin
|
begin
|
||||||
body = fetch("#{url}/CVS/Entries").body
|
body = fetch("#{url}/CVS/Entries")
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
if body.nil?
|
if body.nil?
|
||||||
|
|
@ -281,7 +292,7 @@ def dsparse(url)
|
||||||
ds = DSParse.new
|
ds = DSParse.new
|
||||||
dirs = Array.new
|
dirs = Array.new
|
||||||
begin
|
begin
|
||||||
body = fetch("#{url}/.DS_Store").body
|
body = fetch("#{url}/.DS_Store")
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
if body.nil?
|
if body.nil?
|
||||||
|
|
@ -298,7 +309,7 @@ def dsparse(url)
|
||||||
if entries[x] == '.' or entries[x] == '..'
|
if entries[x] == '.' or entries[x] == '..'
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
body = fetch("#{url}/#{entries[x]}/.DS_Store").body
|
body = fetch("#{url}/#{entries[x]}/.DS_Store")
|
||||||
dscheck = DSParse.new
|
dscheck = DSParse.new
|
||||||
dscheck.readstring(body)
|
dscheck.readstring(body)
|
||||||
if dscheck.isds?
|
if dscheck.isds?
|
||||||
|
|
@ -317,7 +328,7 @@ end
|
||||||
def checksvn(url)
|
def checksvn(url)
|
||||||
begin
|
begin
|
||||||
puts "==================================================="
|
puts "==================================================="
|
||||||
body = fetch("#{url}/.svn/entries").body
|
body = fetch("#{url}/.svn/entries")
|
||||||
puts "Subversion info found:"
|
puts "Subversion info found:"
|
||||||
svnparse(url)
|
svnparse(url)
|
||||||
rescue
|
rescue
|
||||||
|
|
@ -327,7 +338,7 @@ end
|
||||||
def checkcvs(url)
|
def checkcvs(url)
|
||||||
begin
|
begin
|
||||||
puts "==================================================="
|
puts "==================================================="
|
||||||
body = fetch("#{url}/CVS/Entries").body
|
body = fetch("#{url}/CVS/Entries")
|
||||||
puts "CVS info found:"
|
puts "CVS info found:"
|
||||||
cvsparse(url)
|
cvsparse(url)
|
||||||
rescue
|
rescue
|
||||||
|
|
@ -337,7 +348,7 @@ end
|
||||||
def checkds(url)
|
def checkds(url)
|
||||||
begin
|
begin
|
||||||
puts "==================================================="
|
puts "==================================================="
|
||||||
body = fetch("#{url}/.DS_Store").body
|
body = fetch("#{url}/.DS_Store")
|
||||||
puts ".DS_Store file found:"
|
puts ".DS_Store file found:"
|
||||||
dsparse(url)
|
dsparse(url)
|
||||||
rescue
|
rescue
|
||||||
|
|
@ -348,7 +359,7 @@ options = cmdline
|
||||||
if options["-u"].nil?
|
if options["-u"].nil?
|
||||||
usage
|
usage
|
||||||
else
|
else
|
||||||
if ! options["-u"].match(/^http/)
|
if ! options["-u"].match(/^(http|file)/)
|
||||||
options["-u"] = "http://#{options["-u"]}"
|
options["-u"] = "http://#{options["-u"]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue