forked from ali5h/encipher.it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencipher.coffee
More file actions
94 lines (81 loc) · 2.89 KB
/
Copy pathencipher.coffee
File metadata and controls
94 lines (81 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
settings = require './settings'
express = require 'express'
mailer = require 'mailer'
store = require './store'
# JS code to inject in page
bookmarklet_code = (version)->
if version
version = ".v#{version}"
else
version = ""
return "(function(){document.body.appendChild(document.createElement('script'))" +
".src='#{settings.BASE_URL}/javascripts/inject#{version}.js';})"
# Bookmarklet link
bookmarklet = (version)->
return "javascript:" + bookmarklet_code(version) + "();"
app = module.exports = express()
app.configure ->
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.set('view options', {layout:true})
app.use(express.static(__dirname + '/public'))
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(app.router)
app.use require('connect-assets')(buildDir: __dirname + '/public')
js.root = 'javascripts'
js('inject.js')
js('encipher.js')
js('compose.js')
app.configure 'development', ->
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }))
app.configure 'production', ->
app.use(express.errorHandler())
# Init mongo store
store.init(app)
app.get '/', (req, res)->
parts = (req._parsedUrl.query or "").match /(^[A-Za-z0-9]+)/
if parts
store.loadHash parts[0], (error, cipher)->
console.log "Hash", parts[0], "Body", cipher
res.render 'index',
title: 'You got encrypted Message'
cipher: cipher or (error and error.message)
encrypted: true
def_bookmarklet: bookmarklet()
else
res.render 'index',
title: 'Encipher.it – Encrypt text or email message in one click'
cipher: "Sample text"
encrypted: false
def_bookmarklet: bookmarklet()
app.get '/help', (req, res)->
res.render 'help', {
title: 'Encipher.it – How to encrypt email and text messages'
def_bookmarklet: bookmarklet()
}
app.get '/ios', (req, res)->
res.render 'ios', {
title: 'Encipher.it - Mobile version'
def_bookmarklet: bookmarklet('ios')
layout: false
}
app.post '/feedback', (req, res)->
name = req.param('name')
email = req.param('email')
message = req.param('message')
console.log "Feedback from #{name} <#{email}>: #{message}"
mailer.send {
'host' : "localhost",
'port' : "25",
'domain' : "localhost",
'to' : "anton@ermak.us",
'from' : email,
'subject' : "Feedback from #{name} (encipher.it)",
'body': message,
'username': 'decipher',
'authentication': false }, (err)->
err and console.log "Send feedback error: #{err.message}"
res.send( "success" )
app.listen(settings.PORT, settings.INTERFACE)
console.log("Express server listening on port %d", settings.PORT)