middleman-protect-emails 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +9 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/features/extension.feature +31 -0
- data/features/support/env.rb +8 -0
- data/fixtures/test-app/config.rb +1 -0
- data/fixtures/test-app/source/index.html +1 -0
- data/fixtures/test-app/source/with_body.html +1 -0
- data/fixtures/test-app/source/with_multiple_emails.html +1 -0
- data/fixtures/test-app/source/with_no_email.html +1 -0
- data/lib/middleman-protect-emails/extension.rb +67 -0
- data/lib/middleman-protect-emails/rot13_script.html +1 -0
- data/lib/middleman-protect-emails/version.rb +5 -0
- data/lib/middleman-protect-emails.rb +7 -0
- data/middleman-protect-emails.gemspec +25 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9092336bc246a62deb1d6a3a3c3ce38fc99fed7
|
4
|
+
data.tar.gz: 5e925a8bd83b277720d3ab16f680665613dab495
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c365af2cb55d34a1c4939991302f05276f809e46169e0f586f849dbd641a0fcdf196fc23c73f9f8a2ae4a8caf033bf020cf4e08083b5ba550cd4d772d3ceb64
|
7
|
+
data.tar.gz: 59fb71b6185287e946ca4aa020bed464169909ccd89c77ee78b55b259a68e674714ce44fe95affc050727d2cfb77638c17ddd1826d39860b88ffddcd9bf99ff7
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ankit Sardesai
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# middleman-protect-emails
|
2
|
+
|
3
|
+
[](https://travis-ci.org/amsardesai/middleman-protect-emails)
|
4
|
+
[](https://codeclimate.com/github/amsardesai/middleman-protect-emails)
|
5
|
+
[](https://codeclimate.com/github/amsardesai/middleman-protect-emails)
|
6
|
+
|
7
|
+
**middleman-protect-emails** is a [Middleman](http://middlemanapp.com) extension that encrypts email links on your page on the server-side and decodes them on the client-side, avoiding spam bots with no visible impacts to your users.
|
8
|
+
|
9
|
+
This gem makes use of the [ROT13](http://en.wikipedia.org/wiki/ROT13) encryption algorithm to encrypt email links. Users must have Javascript enabled on their computers for the decoding stage to work.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your Middleman application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'middleman-protect-emails'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then run:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
Implementing this gem is as simple as adding the following line to your project's `config.rb` file:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# config.rb
|
29
|
+
activate :protect_emails
|
30
|
+
```
|
31
|
+
|
32
|
+
You can also add it to your build-specific configuration:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
# config.rb
|
36
|
+
configure :build do
|
37
|
+
activate :protect_emails
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a [new pull request](../../pull/new/master)
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'cucumber/rake/task'
|
3
|
+
require 'rake/clean'
|
4
|
+
|
5
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
6
|
+
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
7
|
+
end
|
8
|
+
|
9
|
+
task test: ['cucumber']
|
10
|
+
task default: :test
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Feature: Email Protection
|
2
|
+
|
3
|
+
Scenario: Inserts script into the page
|
4
|
+
Given the Server is running at "test-app"
|
5
|
+
When I go to "/"
|
6
|
+
Then I should see "</script>"
|
7
|
+
|
8
|
+
Scenario: Shows obfuscated email on page
|
9
|
+
Given the Server is running at "test-app"
|
10
|
+
When I go to "/"
|
11
|
+
Then I should see "<a href='#email-protection-rznvy@rknzcyr.pbz'></a>"
|
12
|
+
|
13
|
+
Scenario: Inserts script into end of body if a body tag exists
|
14
|
+
Given the Server is running at "test-app"
|
15
|
+
When I go to "/with_body.html"
|
16
|
+
Then I should see:
|
17
|
+
"""
|
18
|
+
</script>
|
19
|
+
</body>
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: Does not insert script if there is no email on the page
|
23
|
+
Given the Server is running at "test-app"
|
24
|
+
When I go to "/with_no_email.html"
|
25
|
+
Then I should not see "</script>"
|
26
|
+
|
27
|
+
Scenario: Obfuscates multiple emails
|
28
|
+
Given the Server is running at "test-app"
|
29
|
+
When I go to "/with_multiple_emails.html"
|
30
|
+
Then I should see "<a href='#email-protection-rznvy1@rknzcyr.pbz'></a>"
|
31
|
+
Then I should see "<a href='#email-protection-rznvy2@rknzcyr.pbz'></a>"
|
@@ -0,0 +1,8 @@
|
|
1
|
+
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
2
|
+
require 'middleman-core'
|
3
|
+
require 'middleman-core/step_definitions'
|
4
|
+
|
5
|
+
require 'codeclimate-test-reporter'
|
6
|
+
CodeClimate::TestReporter.start
|
7
|
+
|
8
|
+
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-protect-emails')
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :protect_emails
|
@@ -0,0 +1 @@
|
|
1
|
+
<a href='mailto:email@example.com'></a>
|
@@ -0,0 +1 @@
|
|
1
|
+
<html><head></head><body><a href='mailto:email@example.com'></a></body></html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<html><head></head><body><a href='mailto:email1@example.com'></a><a href='mailto:email2@example.com'></a></body></html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<html><head></head><body>Hello!</body></html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'middleman-core/util'
|
2
|
+
|
3
|
+
class Middleman::ProtectEmailsExtension < ::Middleman::Extension
|
4
|
+
|
5
|
+
def initialize(app, options_hash={}, &block)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_configuration
|
10
|
+
app.use Middleware, middleman_app: app
|
11
|
+
end
|
12
|
+
|
13
|
+
class Middleware
|
14
|
+
def initialize(app, options = {})
|
15
|
+
@rack_app = app
|
16
|
+
@middleman_app = options[:middleman_app]
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
status, headers, response = @rack_app.call(env)
|
21
|
+
|
22
|
+
# Get path
|
23
|
+
path = ::Middleman::Util.full_path(env['PATH_INFO'], @middleman_app)
|
24
|
+
|
25
|
+
# Match only HTML documents
|
26
|
+
if path =~ /(^\/$)|(\.(htm|html)$)/
|
27
|
+
body = ::Middleman::Util.extract_response_text(response)
|
28
|
+
if body
|
29
|
+
status, headers, response = Rack::Response.new(rewrite_response(body), status, headers).finish
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
[status, headers, response]
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def rewrite_response(body)
|
39
|
+
# Keeps track of email replaces
|
40
|
+
replaced_email = false
|
41
|
+
|
42
|
+
# Replaces mailto links with ROT13 equivalent
|
43
|
+
# TODO: Don't replace plaintext mailto links
|
44
|
+
new_content = body.gsub /mailto:([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})/i do
|
45
|
+
replaced_email = true
|
46
|
+
email = $1.tr 'A-Za-z','N-ZA-Mn-za-m'
|
47
|
+
"#email-protection-#{email}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Don't do anything else if there are no emails on the page
|
51
|
+
return body unless replaced_email
|
52
|
+
|
53
|
+
# Reads decoding script
|
54
|
+
file = File.join(File.dirname(__FILE__), 'rot13_script.html')
|
55
|
+
script_content = File.read file
|
56
|
+
|
57
|
+
# Appends decoding script at end of body or end of page
|
58
|
+
if new_content =~ /<\/body>/i
|
59
|
+
new_content.gsub(/(<\/body>)/i) do
|
60
|
+
script_content + $1
|
61
|
+
end
|
62
|
+
else
|
63
|
+
new_content + script_content
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<script type="text/javascript">!function(){try{var a,b,c,d,g=document.getElementsByTagName("a");for(c=0;g.length-c;c++)try{b=g[c].getAttribute("href"),b&&b.indexOf("#email-protection-")>-1&&b.length>19&&(a="",d=19+b.indexOf("#email-protection-"),b.length>d&&(a=b.substr(18).replace(/[a-zA-Z]/g,function(a){return String.fromCharCode(("Z">=a?90:122)>=(a=a.charCodeAt(0)+13)?a:a-26)})),g[c].setAttribute("href","mailto:"+a))}catch(h){}}catch(h){}}();</script>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'middleman-protect-emails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'middleman-protect-emails'
|
8
|
+
spec.version = Middleman::ProtectEmails::VERSION
|
9
|
+
spec.authors = ['Ankit Sardesai']
|
10
|
+
spec.email = ['amsardesai@gmail.com']
|
11
|
+
spec.summary = %q{Middleman extension for email link protection and obfuscation}
|
12
|
+
spec.description = %q{Middleman extension for email link protection and obfuscation.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
spec.required_ruby_version = '>= 1.9.3'
|
20
|
+
|
21
|
+
spec.add_dependency 'middleman-core', '~> 3.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-protect-emails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ankit Sardesai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Middleman extension for email link protection and obfuscation.
|
56
|
+
email:
|
57
|
+
- amsardesai@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- features/extension.feature
|
69
|
+
- features/support/env.rb
|
70
|
+
- fixtures/test-app/config.rb
|
71
|
+
- fixtures/test-app/source/index.html
|
72
|
+
- fixtures/test-app/source/with_body.html
|
73
|
+
- fixtures/test-app/source/with_multiple_emails.html
|
74
|
+
- fixtures/test-app/source/with_no_email.html
|
75
|
+
- lib/middleman-protect-emails.rb
|
76
|
+
- lib/middleman-protect-emails/extension.rb
|
77
|
+
- lib/middleman-protect-emails/rot13_script.html
|
78
|
+
- lib/middleman-protect-emails/version.rb
|
79
|
+
- middleman-protect-emails.gemspec
|
80
|
+
homepage: ''
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.9.3
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.4.5
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Middleman extension for email link protection and obfuscation
|
104
|
+
test_files:
|
105
|
+
- features/extension.feature
|
106
|
+
- features/support/env.rb
|