desviar 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/config/config.rb.example +5 -1
- data/desviar.gemspec +2 -0
- data/lib/desviar.rb +53 -7
- data/lib/model.rb +1 -1
- data/lib/version.rb +3 -3
- metadata +35 -3
data/README.md
CHANGED
@@ -56,15 +56,15 @@ Commands:
|
|
56
56
|
* /link/nnn - retrieve details
|
57
57
|
* /config - set runtime configuration
|
58
58
|
|
59
|
+
For scripting, the list, link and config commands can be modified with a _/json_ suffix (e.g. _/config/json_) to generate json instead of html output.
|
60
|
+
|
59
61
|
Here's an example of creating a new link via _curl_:
|
60
62
|
|
61
63
|
curl --digest --user desviar:password http://localhost:4567/create \
|
62
64
|
--data "redir_uri=http://localhost/test&expiration=1800&captcha=1¬es=testing"
|
63
65
|
|
64
66
|
Security notes:
|
65
|
-
Consider moving the default database location from /dev/shm/desviar, and set its permissions to 0600.
|
66
|
-
|
67
|
-
You can modify config.ru to direct log output to a different file.
|
67
|
+
Consider moving the default database location from /dev/shm/desviar, and set its permissions to 0600. You can modify config.ru to direct log output to a different file.
|
68
68
|
|
69
69
|
#### Features implemented ####
|
70
70
|
|
data/config/config.rb.example
CHANGED
@@ -25,6 +25,9 @@ $config = {
|
|
25
25
|
:msg_exp => "Default expiration interval, in seconds",
|
26
26
|
:exp => 900,
|
27
27
|
|
28
|
+
:msg_redir_retain => "Retention policy for URI - discard before saving db entry to be more secure",
|
29
|
+
:redir_retain => "keep",
|
30
|
+
|
28
31
|
:msg_authprompt => "AuthPrompt appears in the browser authentication dialog",
|
29
32
|
:authprompt => "Please Authenticate",
|
30
33
|
|
@@ -85,5 +88,6 @@ $optvals = {
|
|
85
88
|
Syslog::LOG_LOCAL3
|
86
89
|
],
|
87
90
|
:hashlength => [ 3, 4, 6, 8, 12, 24, 32, 48, 64 ],
|
88
|
-
:recordsmax => [ 50, 100, 150, 250, 500 ]
|
91
|
+
:recordsmax => [ 50, 100, 150, 250, 500 ],
|
92
|
+
:redir_retain => [ "keep", "discard" ]
|
89
93
|
}
|
data/desviar.gemspec
CHANGED
@@ -37,9 +37,11 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_dependency "dm-sqlite-adapter", ">= 1.2"
|
38
38
|
spec.add_dependency "dm-timestamps", ">= 1.2"
|
39
39
|
spec.add_dependency "dm-validations", ">= 1.2"
|
40
|
+
spec.add_dependency "multi_json", ">= 1.7"
|
40
41
|
spec.add_dependency "rack-recaptcha", ">= 0.6"
|
41
42
|
spec.add_dependency "rack-test", ">= 0.6"
|
42
43
|
spec.add_dependency "sinatra", ">= 1.4"
|
44
|
+
spec.add_dependency "sinatra-contrib", ">= 1.4"
|
43
45
|
spec.add_dependency "syntaxi", ">= 0.5"
|
44
46
|
spec.add_dependency "yajl-ruby", ">= 1.1"
|
45
47
|
end
|
data/lib/desviar.rb
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
12
12
|
|
13
13
|
require 'sinatra/base'
|
14
|
+
require 'sinatra/json'
|
14
15
|
require 'securerandom'
|
15
16
|
require 'dm-core'
|
16
17
|
require 'dm-migrations'
|
@@ -22,6 +23,7 @@ require 'net/http'
|
|
22
23
|
#require 'test/unit'
|
23
24
|
require 'rack/test'
|
24
25
|
require 'rack/recaptcha'
|
26
|
+
require 'multi_json'
|
25
27
|
|
26
28
|
if ENV['DESVIAR_CONFIG']
|
27
29
|
require ENV['DESVIAR_CONFIG']
|
@@ -42,6 +44,7 @@ module Desviar
|
|
42
44
|
DataMapper.setup(:default, $config[:dbmethod])
|
43
45
|
DataMapper.auto_upgrade! if DataMapper.respond_to?(:auto_upgrade!)
|
44
46
|
$config[:cryptkey] = SecureRandom.base64(32) if $config[:cryptkey].nil?
|
47
|
+
helpers Sinatra::JSON
|
45
48
|
end
|
46
49
|
|
47
50
|
get '/' do
|
@@ -56,23 +59,23 @@ module Desviar
|
|
56
59
|
|
57
60
|
# submit
|
58
61
|
post '/create' do
|
62
|
+
error 400 if params[:redir_uri].strip == ""
|
63
|
+
|
59
64
|
# Create a new data record, generating the random URI and omitting
|
60
65
|
# remote-access credentials if specified.
|
61
66
|
@desviar = Desviar::Model::Main.new(params.merge({
|
62
67
|
:temp_uri => "#{$config[:uriprefix]}#{SecureRandom.urlsafe_base64($config[:hashlength])[0,$config[:hashlength]]}#{$config[:urisuffix]}",
|
63
68
|
:expires_at => Time.now + params[:expiration].to_i,
|
64
69
|
:captcha_validated => false
|
65
|
-
}).delete_if {|key, val| key == "remoteuser" || key == "remotepw"})
|
70
|
+
}).delete_if {|key, val| key == "redir_uri" || key == "remoteuser" || key == "remotepw"})
|
66
71
|
|
67
72
|
# Cache the remote URI
|
68
|
-
object = URI.parse(
|
73
|
+
object = URI.parse(params[:redir_uri])
|
69
74
|
http = Net::HTTP.new(object.host, object.port)
|
70
|
-
http.use_ssl =
|
75
|
+
http.use_ssl = params[:redir_uri].index('https') == 0
|
71
76
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
72
77
|
req = Net::HTTP::Get.new(object.request_uri)
|
73
|
-
if params[:remoteuser] != ''
|
74
|
-
req.basic_auth params[:remoteuser], params[:remotepw]
|
75
|
-
end
|
78
|
+
req.basic_auth params[:remoteuser], params[:remotepw] if params[:remoteuser] != ''
|
76
79
|
response = http.request(req)
|
77
80
|
if !$config[:dbencrypt]
|
78
81
|
@desviar[:content] = response.body[0, $config[:contentmax]]
|
@@ -84,6 +87,8 @@ module Desviar
|
|
84
87
|
@desviar[:cipher_iv] = obj.iv
|
85
88
|
end
|
86
89
|
|
90
|
+
@desviar[:redir_uri] = $config[:redir_retain] == "keep" ? params[:redir_uri] : ""
|
91
|
+
|
87
92
|
# Insert the new record and display the new link
|
88
93
|
if @desviar.save
|
89
94
|
Desviar::Public::log "Created #{@desviar.id} #{@desviar.redir_uri} #{@desviar.expires_at} #{request.ip}"
|
@@ -103,6 +108,16 @@ module Desviar
|
|
103
108
|
end
|
104
109
|
end
|
105
110
|
|
111
|
+
# show link info - json format
|
112
|
+
get '/link/json/:id' do
|
113
|
+
@desviar = Desviar::Model::Main.get(params[:id])
|
114
|
+
if @desviar && DateTime.now < @desviar[:expires_at]
|
115
|
+
json @desviar.attributes.delete_if {|key, val| key == :content || key == :cipher_iv || key == :hmac}
|
116
|
+
else
|
117
|
+
error 404
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
106
121
|
# clean out expired records
|
107
122
|
get '/clean' do
|
108
123
|
# TODO: figure out the clean "native" way of DataMapper::Collection.destroy
|
@@ -121,17 +136,48 @@ module Desviar
|
|
121
136
|
|
122
137
|
# list of most recent records
|
123
138
|
get '/list' do
|
124
|
-
@desviar = Desviar::Model::Main.all(
|
139
|
+
@desviar = Desviar::Model::Main.all(
|
140
|
+
:limit => $config[:recordsmax],
|
141
|
+
:order => [ :created_at.desc ],
|
142
|
+
:fields => [ :id, :created_at, :expires_at, :redir_uri, :captcha, :notes ])
|
125
143
|
@total = @desviar.length
|
126
144
|
@count = [ @total, $config[:recordsmax] ].min
|
127
145
|
erb :list
|
128
146
|
end
|
129
147
|
|
148
|
+
# list - json
|
149
|
+
get '/list/json' do
|
150
|
+
@desviar = Desviar::Model::Main.all(
|
151
|
+
:limit => $config[:recordsmax],
|
152
|
+
:order => [ :created_at.desc ],
|
153
|
+
:fields => [ :id, :redir_uri, :temp_uri, :expiration, :captcha,
|
154
|
+
:notes, :owner, :created_at, :expires_at ])
|
155
|
+
list = Array.new
|
156
|
+
@desviar.each do |item|
|
157
|
+
list << {
|
158
|
+
:id => item.id, :redir_uri => item.redir_uri,
|
159
|
+
:temp_uri => item.temp_uri, :expiration => item.expiration,
|
160
|
+
:captcha => item.captcha, :notes => item.notes,
|
161
|
+
:owner => item.owner, :created_at => item.created_at,
|
162
|
+
:expires_at => item.expires_at }
|
163
|
+
end
|
164
|
+
json list
|
165
|
+
end
|
166
|
+
|
130
167
|
# configuration
|
131
168
|
get '/config' do
|
132
169
|
erb :config
|
133
170
|
end
|
134
171
|
|
172
|
+
# configuration - json
|
173
|
+
get '/config/json' do
|
174
|
+
json $config.reject { |opt, val|
|
175
|
+
opt.to_s.index('msg_') == 0 ||
|
176
|
+
$config[:hidden].include?(opt.to_s) ||
|
177
|
+
$config[:hashed].include?(opt.to_s)
|
178
|
+
}
|
179
|
+
end
|
180
|
+
|
135
181
|
# submit
|
136
182
|
post '/config' do
|
137
183
|
params['config'].each do |opt, val|
|
data/lib/model.rb
CHANGED
@@ -14,7 +14,7 @@ module Desviar
|
|
14
14
|
include DataMapper::Resource
|
15
15
|
|
16
16
|
property :id, Serial # primary serial key
|
17
|
-
property :redir_uri, String, :
|
17
|
+
property :redir_uri, String, :length => 255
|
18
18
|
property :temp_uri, String, :length => 64
|
19
19
|
property :expiration, Integer, :required => true
|
20
20
|
property :captcha, Boolean
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: desviar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dm-core
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '1.2'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: multi_json
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.7'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.7'
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
111
|
name: rack-recaptcha
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +155,22 @@ dependencies:
|
|
139
155
|
- - ! '>='
|
140
156
|
- !ruby/object:Gem::Version
|
141
157
|
version: '1.4'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: sinatra-contrib
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '1.4'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '1.4'
|
142
174
|
- !ruby/object:Gem::Dependency
|
143
175
|
name: syntaxi
|
144
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,7 +239,7 @@ files:
|
|
207
239
|
homepage: http://github.com/instantlinux/desviar
|
208
240
|
licenses: []
|
209
241
|
post_install_message: ! "------------------------------------------------------------------------------\nDesviar
|
210
|
-
v0.0.
|
242
|
+
v0.0.15\n\nTo configure, download from:\n https://raw.github.com/instantlinux/desviar/master/config/config.rb.example\ninto
|
211
243
|
a new file config.rb and export DESVIAR_CONFIG=<path>/config.rb.\n\nThanks for using
|
212
244
|
Desviar.\n------------------------------------------------------------------------------\n"
|
213
245
|
rdoc_options: []
|