weblicate 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mike Bailey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,33 @@
1
+ = weblicate
2
+
3
+ Replicate a website.
4
+
5
+ Weblicate creates a copy of a web page, complete with third party assets, to be run on your own webserver.
6
+ When given a HAR file, weblicate writes all assets to local disk. It appends a domain to the end of all
7
+ URLs so you can simulate external requests from sites like doubleclick and google.
8
+
9
+ == Installation
10
+
11
+ You need Ruby and RubyGems installed
12
+
13
+ sudo gem install weblicate
14
+
15
+ == Usage
16
+
17
+ Running the following command:
18
+
19
+ weblicate www.cnn.com.har usa.weblicate.info
20
+
21
+ generates the following output:
22
+
23
+ files-usa.weblicate.info # All files and assets for the page
24
+ hosts-usa.weblicate.info # Entries that can be added to your local hosts file
25
+
26
+ You also get these if you want the outside world to be able to see your weblicant:
27
+
28
+ dns-usa.weblicate.info # A script to create DNS entries (on Slicehost.com)
29
+ vhosts-usa.weblicate.info # Apache vhosts entries for all domains
30
+
31
+ == Copyright
32
+
33
+ Copyright (c) 2010 Mike Bailey. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "weblicate"
8
+ gem.version = '0.0.2'
9
+ gem.summary = %Q{Replicate a website}
10
+ gem.description = %Q{Replicate a website based on a HAR file}
11
+ gem.email = "mike@bailey.net.au"
12
+ gem.homepage = "http://github.com/mbailey/weblicate"
13
+ gem.authors = ["Mike Bailey"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "weblicate #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/bin/weblicate ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'weblicate'
4
+
5
+ harfile = ARGV[0]
6
+ dest_domain = ARGV[1] || nil
7
+
8
+ a = Har.new harfile, :dest_domain => dest_domain
9
+ a.get_files
10
+ File.open('hosts-' + a.dest_domain, 'w') { |file| file.write(a.hosts_file) }
11
+ File.open('vhosts-' + a.dest_domain, 'w') { |file| file.write(a.vhosts) }
12
+ File.open('dns-' + a.dest_domain, 'w') { |file| file.write(a.dns) }
13
+
14
+ puts "Now run these commands..."
15
+ puts "rsync -avz files-#{a.dest_domain}/ #{a.dest_domain}:/var/www/weblicate/"
16
+ puts "sh dns-#{a.dest_domain}"
17
+ puts "scp vhosts-#{a.dest_domain} #{a.dest_domain}:/etc/apache2/apps/"
@@ -0,0 +1,92 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'uri'
4
+ require 'net/http'
5
+
6
+ # put file bundle into a dir
7
+ # append our own hostname onto it
8
+
9
+ class Har
10
+
11
+ attr_accessor :dest_domain
12
+
13
+ def initialize(harfile, options={})
14
+ @dest_domain = options[:dest_domain] || 'local'
15
+
16
+ if File.exists? harfile
17
+ contents = File.read(harfile)
18
+ else
19
+ contents = harfile
20
+ end
21
+ @har = JSON.parse(contents)
22
+ end
23
+
24
+ def hosts
25
+ @har['log']['entries'].collect{ |e|
26
+ e['request']['headers'].select{|h|
27
+ h['name'] == 'Host'
28
+ }.first['value']
29
+ }.uniq.sort
30
+ end
31
+
32
+ def entries
33
+ @har['log']['entries']
34
+ end
35
+
36
+ def files
37
+ @har['log']['entries'].collect{|e| e['request']['url']}
38
+ end
39
+
40
+ def get_files
41
+ # files.each {|file| get_file(file)}
42
+ entries.each do |entry|
43
+ if entry['response']['content']['text']
44
+ contents = entry['response']['content']['text']
45
+ else
46
+ contents = `curl -s '#{entry['request']['url']}'`
47
+ end
48
+ hosts.each { |host| contents.gsub! host, host+'.'+@dest_domain }
49
+ save_file entry['request']['url'], contents
50
+ end
51
+ end
52
+
53
+ def save_file(url, contents)
54
+ uri = URI.parse(url)
55
+ dest = File.join("files-#{@dest_domain}", uri.host+'.'+@dest_domain, uri.path)
56
+ dest << 'index.html' if dest[-1,1] == '/'
57
+ FileUtils.mkdir_p File.dirname dest
58
+ File.open(dest, "w") { |file| file.write contents }
59
+ rescue
60
+ puts "Failed to parse url (#{url})"
61
+ end
62
+
63
+ def vhosts
64
+ hosts.collect do |host|
65
+ <<-EOF
66
+ <VirtualHost *:80>
67
+ ServerName #{host}.#{@dest_domain}
68
+ DocumentRoot /var/www/weblicate/#{host}.#{@dest_domain}
69
+ <Directory /var/www/weblicate/#{host}.#{@dest_domain}>
70
+ Order allow,deny
71
+ Allow from all
72
+ </Directory>
73
+ </VirtualHost>
74
+ EOF
75
+ end
76
+ end
77
+
78
+ def hosts_file
79
+ hosts.collect do |host|
80
+ "127.0.0.1 #{host}.#{@dest_domain}\n"
81
+ end
82
+ end
83
+
84
+ def dns
85
+ hosts.collect do |host|
86
+ zone = @dest_domain.sub /^.*?\./, ''
87
+ name = host + '.' + @dest_domain.sub('.'+zone, '')
88
+ "slicehost-dns add_cname #{zone} #{name} #{@dest_domain}.\n"
89
+ end
90
+ end
91
+
92
+ end
data/lib/weblicate.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'weblicate/har.rb'
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'weblicate'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestWeblicate < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weblicate
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Mike Bailey
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-18 00:00:00 +10:00
19
+ default_executable: weblicate
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Replicate a website based on a HAR file
36
+ email: mike@bailey.net.au
37
+ executables:
38
+ - weblicate
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - bin/weblicate
51
+ - lib/weblicate.rb
52
+ - lib/weblicate/har.rb
53
+ - test/helper.rb
54
+ - test/test_weblicate.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/mbailey/weblicate
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Replicate a website
89
+ test_files:
90
+ - test/helper.rb
91
+ - test/test_weblicate.rb