Module: HTTPS

Defined in:
lib/https.rb

Overview

Created by me on 2007-12-28.

Copyright (c) 2007. All pwnage reserved.

Class Method Summary collapse

Class Method Details

.cleanObject

def fetch_fat

  array = []
  start = 0
  jump = @url.length / @opts[:threads]
  finish = -1                     # -1 so that start becomes 0

  @opts[:threads].times do |t|
    start = finish + 1
    finish = (start + jump) - 1
    array << [start, finish, t + 1]
  end

  array.each_simultaneously { |d, b, w|
    puts "[LOG] Setting up a new thread..." if @opts[:verbose]
    open("/tmp/part#{w}", "w") do |f|
      http = Net::HTTP.new(@url.host, @url.port)
      c = http.start do |http|
        a = Net::HTTP::Get.new(@url.page)
        a.range = (d..b)
        http.request(a)
      end
      f.write(c.body)
    end
  }
end

82
83
84
85
# File 'lib/https.rb', line 82

def clean
  mash_files
  remove_extra_files
end

.fetchObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/https.rb', line 26

def fetch
  array = []
  start = 0
  jump = @url.length / @opts[:threads]
  finish = -1                     # -1 so that start becomes 0

  @opts[:threads].times do |t|
    start = finish + 1
    finish = (start + jump) - 1
    array << [start, finish, t + 1]
  end

  array.each_simultaneously { |d, b, w|
    puts "[LOG] Setting up a new thread..." if @opts[:verbose]
    p @opts[:out]
    open(@opts[:out], "a+") do |f|
      f.seek(d)
      http = Net::HTTP.new(@url.host, @url.port)
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      c = http.start do |http|
        a = Net::HTTP::Get.new(@url.page)
        a.range = (d..b)
        http.request(a)
      end
      f.write(c.body)
    end
  }
end

.mash_filesObject


101
102
103
104
105
106
107
108
109
110
111
# File 'lib/https.rb', line 101

def mash_files
  open(@opts[:out], "a") do |f|
    files = Dir["/tmp/part*"].sort_by { |word|
      word.scan(/\d+/)[0].to_i
    }
    files.each do |part|
      puts "[LOG] Reading #{part}" if @opts[:verbose]
      f.print open(part, "r").read
    end
  end
end

.prepObject


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/https.rb', line 13

def prep
  req = Net::HTTP.new(@url.host, @url.port)
  req.use_ssl = true
  len = req.request_head(@url.page)['content-length']
  @url.length = len.to_i

  if len.nil?
    @opts[:threads] = 1
    puts "--> Uhoh! Server isn't cooperating..."
    puts "--> Changing threadcount to 1"
  end
end

.remove_extra_filesObject


87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/https.rb', line 87

def remove_extra_files
  puts "[LOG] Writing #{@opts[:out]}" if @opts[:verbose]

  Dir["/tmp/part*"].each do |part|
    File.delete(part)
    puts "[LOG] Removing #{part}" if @opts[:verbose]
  end

  if @opts[:clean]
    File.delete(@opts[:out])
    puts "[LOG] Removing #{@opts[:out]}" if @opts[:verbose]
  end
end

.setup(opts, uri) ⇒ Object


8
9
10
11
# File 'lib/https.rb', line 8

def setup(opts, uri)
  @opts = opts
  @url = uri
end