if @meta["Coquelicot"].nil? or @meta["Coquelicot"] != COQUELICOT_VERSION then
raise "unknown file"
end
- @expire_at = Time.at(@meta['Expire-at'].to_i)
+ @expire_at = Time.at(@meta['Expire-at'])
end
def init_decrypt_cipher(pass)
def gen_random_pass
gen_random_base32(options.random_pass_length)
end
+def remap_base32_extra_characters(str)
+ map = {}
+ FILENAME_CHARS.each { |c| map[c] = c; map[c.upcase] = c }
+ map.merge!({ '1' => 'l', '0' => 'o' })
+ result = ''
+ str.each_char { |c| result << map[c] }
+ result
+end
def password_match?(password)
return TRUE if settings.upload_password.nil?
haml :index
end
+get '/random_pass' do
+ "#{gen_random_pass}"
+end
+
get '/ready/:link' do |link|
link, pass = link.split '-' if link.include? '-'
- unless depot.file_exists? link then
+ begin
+ file = depot.get_file(link, nil)
+ rescue Errno::ENOENT => ex
not_found
end
- base = request.url.gsub(/\/ready\/[^\/]*$/, '')
- @url = "#{base}/#{link}-#{pass}" unless pass.nil?
- @url ||= "#{base}/#{link}"
+ @expire_at = file.expire_at
+ @base = request.url.gsub(/\/ready\/[^\/]*$/, '')
+ @name = "#{link}"
+ unless pass.nil?
+ @name << "-#{pass}"
+ @unprotected = true
+ end
+ @url = "#{@base}/#{@name}"
haml :ready
end
src = params[:file][:tempfile]
link = depot.add_file(
src, pass,
- { "Expire-at" => expire_at.strftime('%s'),
+ { "Expire-at" => expire_at.to_i,
"Filename" => params[:file][:filename],
"Length" => src.stat.size,
"Content-Type" => params[:file][:type]
end
get '/:link-:pass' do |link, pass|
+ link = remap_base32_extra_characters(link)
+ pass = remap_base32_extra_characters(pass)
not_found unless send_stored_file(link, pass)
end
get '/:link' do |link|
+ link = remap_base32_extra_characters(link)
not_found unless depot.file_exists? link
@link = link
haml :enter_file_key
__END__
@@ layout
+!!! XML
+!!! Strict
%html
%head
%title coquelicot
%script{ :type => 'text/javascript', :src => 'javascripts/jquery.min.js' }
%script{ :type => 'text/javascript', :src => 'javascripts/jquery.lightBoxFu.js' }
%script{ :type => 'text/javascript', :src => 'javascripts/jquery.uploadProgress.js' }
+ :javascript
+ var generateRandomPassword = 'Generate random';
+ var generatingRandomPassword = 'Generating…';
%script{ :type => 'text/javascript', :src => 'javascripts/coquelicot.js' }
%body
#container
= yield
+ #footer
+ %span Coquelicot © 2010 potager.org
+ %span
+ —
+ %a{ :href => 'http://www.gnu.org/licenses/agpl.txt' } AGPLv3
+ —
+ %span
+ %code git clone #{base_href}coquelicot.git
@@ index
-%h1 Upload!
+%h1 Share a file!
- unless @error.nil?
.error= @error
%form#upload{ :enctype => 'multipart/form-data',
:action => 'upload', :method => 'post' }
.field
- %input{ :type => 'file', :name => 'file' }
+ %label{ :for => 'upload_password' } Upload password:
+ %input.input{ :type => 'password', :id => 'upload_password', :name => 'upload_password' }
.field
- %select{ :name => 'expire' }
+ %label{ :for => 'file' } File:
+ %input.input{ :type => 'file', id => 'file', :name => 'file' }
+ .field
+ %label{ :for => 'expire' } Available for:
+ %select.input{ :id => 'expire',:name => 'expire' }
%option{ :value => 5 } 5 minutes
%option{ :value => 60 } 1 hour
%option{ :value => 60 * 24 } 1 day
%option{ :value => 60 * 24 * 7 } 1 week
%option{ :value => 60 * 24 * 30 } 1 month
.field
- %input{ :type => 'submit', :value => 'Send file' }
+ %label{ :for => 'file_key' } Download password:
+ %input.input{ :type => 'password', :id => 'file_key', :name => 'file_key' }
+ .field
+ .submit
+ %input.submit{ :type => 'submit', :value => 'Share!' }
@@ ready
%h1 Pass this on!
-.url
- %a{ :href => @url }= @url
+#content
+ .url
+ %a{ :href => @url }
+ %span.base> #{@base}/
+ %span.name= @name
+ - unless @unprotected
+ %p A password is required to download this file.
+ %p The file will be available until #{@expire_at}.
+ .again
+ %a{ :href => base_href } Share another file…
@@ enter_file_key
-%h1 Enter file key…
-%form{ :action => @link, :method => 'post' }
- .field
- %input{ :type => 'text', :id => 'file_key', :name => 'file_key' }
- .field
- %input{ :type => 'submit', :value => 'Get file' }
+%h1 Enter download password…
+#content
+ %form{ :action => @link, :method => 'post' }
+ .field
+ %label{ :for => 'file_key' } Password:
+ %input{ :type => 'text', :id => 'file_key', :name => 'file_key' }
+ .field
+ .submit
+ %input{ :type => 'submit', :value => 'Get file' }
@@ expired
%h1 Too late…
-%p Sorry, file has expired.
+#content
+ %p Sorry, file has expired.
@@ style
$green: #00ff26
a, a:visited
text-decoration: underline
- color: white
+ color: blue
.error
background-color: red
color: white
border: black solid 1px
+h1
+ margin-top: 0.1ex
+ border-bottom: solid 1px #ccc
+ text-align: center
+
+#container
+ width: 550px
+ margin: 2em auto
+ -moz-border-radius: 25px
+ -webkit-border-radius: 25px
+ background: white
+ border: solid 1px black
+ padding: 5px 25px
+
+.url
+ text-align: center
+
+.url a
+ text-decoration: none
+ color: black
+
+.url .base
+ display: block
+ font-size: small
+
+.url .name
+ display: block
+ font-size: x-large
+ white-space: nowrap
+
+.again
+ margin-top: 1ex
+ text-align: right
+
+.field label
+ float: left
+ width: 12em
+ text-align: right
+
+.input, .random-pass
+ float: left
+ width: 15em
+
+.random-pass
+ font-family: monospace
+ font-size: large
+ color: black
+
+#gen_pass
+ font-size: small
+
+.field
+ clear: left
+
+.submit
+ text-align: center
+
#progress
margin: 8px
width: 220px
background: url('images/ajax-loader.gif') no-repeat
width: 0px
height: 19px
+
+#footer
+ margin-top: 7em
+ padding-top: 1em
+ border-top: dashed 1px black
+ text-align: center
+ font-size: small