Skip to content
Browse files

Fixed code from last update

  • Loading branch information...
1 parent 9a5b65c commit c1740b0626c5d159712ce6a67bbc4741607e984c @ksexton ksexton committed Mar 6, 2012
View
1 .gitignore
@@ -15,6 +15,7 @@ doc/
.project
.DS_Store
*.get.*
+examples/*
files/*
test/*
View
2 examples/receive_file.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
require '../lib/std'
-Std::Receive.new("fcynuv").perform
+Std::Receive.new("ab8bt0").perform
View
11 lib/dns_update.rb
@@ -1,11 +0,0 @@
-class DNSUpdate
-
- @queue = :sendtodns
-
- def self.perform(key,records)
- IO.popen("nsupdate -v -k #{key}", 'w') do |io|
- io.puts records
- puts records
- end
- end
-end
View
85 lib/generate_records.rb
@@ -1,85 +0,0 @@
-module SendToDns
- module GenerateRecords
-
- def block(record, size)
- @logger.info "In block"
- iterator = 0
- block = Array.new
- tempblock = ""
- record.lines.each do |line|
- iterator = iterator + 1
- tempblock << line
- if iterator == size
- block << tempblock
-
- tempblock = ""
- iterator = 0
- end
- end
- block << tempblock
- @logger.debug "Leaving block #{block.size}"
- return block
- end
-
- def zoneblock(file,recordsize=40,blocksize=1)
- @logger.debug "In zoneblock working on #{file}"
- holder = Array.new
- interval = 0
- @logger.debug "Reading file with IO.read"
- filecontents = IO.read("#{@stagedirectory}#{file}")
- @logger.debug "recordblock = block(file,recordsize)"
- recordblock = block(filecontents,recordsize)
- @logger.debug "#{recordblock.class}"
- recordblock.each do |i|
- record = ""
- i.each_line do |line|
- record = record + "\"#{line.gsub(/\s+/, ' ').lstrip.rstrip}\" "
- end
-
-
- record_update = record_fluff(interval,file,domain,record)
-
- holder << record_update
-
- interval = interval + 1
- end
- @logger.error "Returning an #{holder.class}"
- return holder
- end
-
- def record_fluff(interval,file,domain,record)
- record_update = "update add #{interval}.#{file}.#{domain}. 604800 A 192.168.1.100\n" +
- "update add #{interval}.#{file}.#{domain}. 604800 TXT #{record}"
- end
-
- def nsupdate(updateblock)
- zonevalue = "server #{@nameserver}\n" +
- "zone #{@domain}\n" +
- "#{updateblock}\n" +
- "show\n" +
- "send\n"
- return zonevalue
- end
-
- def send_block(blocklength)
- @filelist.each do |file|
- @logger.debug "Working on #{file} with md5 #{@md5list[file]}"
- block = self.zoneblock(file)
- block << record_fluff("fileid", "#{@randomname}", domain, "\"#{@file},#{@filelist.first},#{@filelist.last},#{@main_md5}\"")
- block << record_fluff("fileid", file, domain, "\"#{file},#{block.length.to_i - 2},#{@md5list[file]}\"")
- while block.length > 0
- if block.slice(blocklength) != nil
- cut = block.slice!(0..blocklength)
- else
- cut = block.slice!(0..-1)
- end
- # Resque.enqueue(DNSUpdate, @key, nsupdate(cut.join("\n")))
- result = Parallel.map(['a', 'b', 'c']) do |one_letter|
- DNSUpdate.perform(@key, cut.join)
- end
- end
- end
- end
-
- end
-end
View
26 lib/std/encode/file.rb
@@ -27,6 +27,7 @@ def copyfile(file=@file)
def renamefile(file=@file)
@logger.debug "Renaming #{file} to #{randomname}"
+ puts "#{@stage_directory}/#{file}","#{@stage_directory}/#{randomname}"
FileUtils.mv("#{@stage_directory}/#{file}","#{@stage_directory}/#{randomname}")
end
@@ -46,9 +47,16 @@ def changedir()
end
def uuencode()
- `#{changedir}; rm #{randomname}`;
+ filenum = 0
+ `#{changedir}; rm #{randomname}`;
+ pp filelist
filelist.each do |i|
- command = "#{changedir}; mkdir -p tmp; uuencode -m -o ./tmp/#{i} #{i} #{i}; mv tmp/* ./; rmdir tmp"
+ filename = i.split("/").last
+ puts filename
+ filenum += 1
+ puts "i: #{i}"
+ command = "#{changedir}; uuencode -m -o #{i}.uu #{i} #{filename}; rm #{filename}; mv #{filename}.uu #{filename}"
+ puts command
`#{command}`
@logger.debug "#{command}"
@@ -70,27 +78,37 @@ def numberfiles()
end
def stage(file=@file)
+ puts "maketemp"
maketemp
+ puts "copyfile"
copyfile
+ puts "generate_md5"
@main_md5 = generate_md5(file)
+ puts "renamefile"
renamefile
+ puts "splitfile"
splitfile
+ puts "uuencode"
uuencode
+ puts "md5list"
md5list
+ puts "numberfiles"
numberfiles
+ puts "filelist"
filelist
end
def md5list()
@md5list = Hash.new
filelist.each do |i|
- @md5list[i] = generate_md5(i)
+ filename = i.split("/").last
+ @md5list[filename] = generate_md5(filename)
end
return @md5list
end
def filelist()
- Dir.glob(@stage_directory)
+ Dir.glob("#{@stage_directory}*")
end
end
end
View
3 lib/std/transmit/dns_update.rb
@@ -5,7 +5,8 @@ class DNSUpdate
def self.perform(key,records)
IO.popen("nsupdate -v -k #{key}", 'w') do |io|
io.puts records
- puts records
+ #puts records
+ #sleep 1
end
end
end
View
21 lib/std/transmit/generate_records.rb
@@ -26,7 +26,7 @@ def zoneblock(file,recordsize=40,blocksize=1)
holder = Array.new
interval = 0
@logger.debug "Reading file with IO.read"
- filecontents = IO.read("#{@stagedirectory}#{file}")
+ filecontents = IO.read("#{@stage_directory}#{file}")
@logger.debug "recordblock = block(file,recordsize)"
recordblock = block(filecontents,recordsize)
@logger.debug "#{recordblock.class}"
@@ -50,6 +50,8 @@ def zoneblock(file,recordsize=40,blocksize=1)
def record_fluff(interval,file,domain,record)
record_update = "update add #{interval}.#{file}.#{domain}. 604800 A 192.168.1.100\n" +
"update add #{interval}.#{file}.#{domain}. 604800 TXT #{record}"
+ #puts record_update
+
end
def nsupdate(updateblock)
@@ -62,21 +64,22 @@ def nsupdate(updateblock)
end
def send_block(blocklength)
- @filelist.each do |file|
- @logger.debug "Working on #{file} with md5 #{@md5list[file]}"
- block = self.zoneblock(file)
- block << record_fluff("fileid", "#{@randomname}", domain, "\"#{@file},#{@filelist.first},#{@filelist.last},#{@main_md5}\"")
- block << record_fluff("fileid", file, domain, "\"#{file},#{block.length.to_i - 2},#{@md5list[file]}\"")
+ filelist.each do |file|
+ filename = file.split("/").last
+ @logger.debug "Working on #{filename} with md5 #{@md5list[filename]}"
+ block = self.zoneblock(filename)
+ block << record_fluff("fileid", @randomname, domain, "\"#{@file},#{filelist.first.split("/").last},#{filelist.last.split("/").last},#{@main_md5}\"")
+ block << record_fluff("fileid", filename, domain, "\"#{filename},#{block.length.to_i - 2},#{@md5list[filename]}\"")
while block.length > 0
if block.slice(blocklength) != nil
cut = block.slice!(0..blocklength)
else
cut = block.slice!(0..-1)
end
# Resque.enqueue(DNSUpdate, @key, nsupdate(cut.join("\n")))
- result = Parallel.map(['a', 'b', 'c']) do |one_letter|
- DNSUpdate.perform(@key, cut.join)
- end
+ #result = Parallel.map(['a', 'b', 'c']) do |one_letter|
+ DNSUpdate.perform(@key, nsupdate(cut.join("\n")))
+ #end
end
end
end
View
8 lib/std/transmit/send_to_dns.rb
@@ -1,7 +1,7 @@
-require "./lib/file"
-require "./lib/generate_records"
-require "./lib/push_file"
-require "./lib/dns_update"
+require "./lib/std/encode/file"
+require "./lib/std/transmit/generate_records"
+require "./lib/std/transmit/push_file"
+require "./lib/std/transmit/dns_update"
require "pp"
module SendToDns
View
5 send.rb
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
-require "./lib/send_to_dns"
+require "./lib/std/transmit/send_to_dns"
require "logging"
require "resque"
require "parallel"
@@ -27,7 +27,8 @@
nameserver = "ns1.sendtodns.org"
domain = "sendtodns.org"
key = "./keys/private"
-file = "file.img"
+#file = "file.img"
+file = "asterisk-1.8.9.0.tar.gz"
foo = PushFile.new(domain, nameserver, key, file)

0 comments on commit c1740b0

Please sign in to comment.
Something went wrong with that request. Please try again.