author | Michael Krelin <hacker@klever.net> | 2014-07-01 17:49:10 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2014-07-01 17:49:10 (UTC) |
commit | a6e5df547739ac91055ae0ae4928447c9ec50a98 (patch) (side-by-side diff) | |
tree | e5d2e63d8c782bb471fa95bd8c7d6d21e3c322b0 | |
parent | b9ee39b810aae10da83534776028585309b53a24 (diff) | |
download | clipperz-a6e5df547739ac91055ae0ae4928447c9ec50a98.zip clipperz-a6e5df547739ac91055ae0ae4928447c9ec50a98.tar.gz clipperz-a6e5df547739ac91055ae0ae4928447c9ec50a98.tar.bz2 |
-rw-r--r-- | backend/node/src/app.js | 7 | ||||
-rw-r--r-- | backend/node/src/clipperz.js | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/backend/node/src/app.js b/backend/node/src/app.js index bbc62f8..09dcfac 100644 --- a/backend/node/src/app.js +++ b/backend/node/src/app.js @@ -14,38 +14,39 @@ var LOGGER = BUNYAN.createLogger({ var EXPRESS = require('express'); var HTTP = require('http'); var PATH = require('path'); var CLIPPERZ = require('./clipperz'); var CONF = require('./conf'); var clipperz = CLIPPERZ({ psql: CONF.psql||'postgresql:///clipperz', logger: LOGGER, dump_template: PATH.join(__dirname,'htdocs/beta/index.html') }); var app = EXPRESS(); app.set('port', process.env.PORT || 3000); app.use(require('morgan')('dev')); app.use(require('body-parser').urlencoded({extended:true})); app.use(require('cookie-parser')('your secret here')); app.use(require('express-session')({secret:'99 little bugs in the code', key:'sid', store: clipperz.session_store(), resave: false, saveUninitialized: false })); -app.post('/json',clipperz.json); -app.get('/dump',clipperz.dump); +/* Like this: */ +app.use(clipperz.router); +/* Or this: */ +app.use('/clz/',clipperz.router); -app.use(EXPRESS.static(PATH.join(__dirname, 'htdocs/'))); if ('development' == app.get('env')) { app.use(require('express-error-with-sources')()); } HTTP.createServer(app).listen(app.get('port'), function(){ LOGGER.info({port:app.get('port')},"Listener established"); }); diff --git a/backend/node/src/clipperz.js b/backend/node/src/clipperz.js index 842de31..2a3df73 100644 --- a/backend/node/src/clipperz.js +++ b/backend/node/src/clipperz.js @@ -1,28 +1,30 @@ var FS = require('fs'); var CRYPTO = require('crypto'); var BIGNUM = require('bignum'); var ASYNC = require('async'); +var EXPRESS = require('express'); +var PATH = require('path'); var express_store = require('express-session').Store; function clipperz_hash(v) { return CRYPTO.createHash('sha256').update( CRYPTO.createHash('sha256').update(v).digest('binary') ).digest('hex'); }; function clipperz_random() { for(var r = '';r.length<64;r+=''+BIGNUM(Math.floor(Math.random()*1e18)).toString(16)); return r.substr(0,64); }; function clipperz_store(PG) { var rv = function(o) { express_store.call(this,o); } rv.prototype.get = function(sid,cb) { PG.Q( "SELECT s_data FROM clipperz.thesession WHERE s_id=$1",[sid], function(e,r) { cb(e,(e||!r.rowCount)?null:JSON.parse(r.rows[0].s_data)); } ) }; rv.prototype.set = function(sid,data,cb) { var d = JSON.stringify(data); PG.Q( "UPDATE clipperz.thesession SET s_data=$1, s_mtime=current_timestamp" +" WHERE s_id=$2",[d,sid], function(e,r) { if(e) return cb(e); @@ -558,27 +560,31 @@ var CLIPPERZ = module.exports = function(CONFIG) { }, html: function(cb) { FS.readFile(CONFIG.dump_template,{encoding:'utf-8'},cb); } },function(e,r) { if(e) return cb(e); var d = new Date(); res.attachment('Clipperz_'+d.getFullYear()+'_'+(d.getMonth()+1)+'_'+d.getDate()+'.html'); var ojs = { users: { catchAllUser: { __masterkey_test_value__: 'masterkey', s: n123, v: n123 } } }; r.u.d.records = r.records; ojs.users[r.u.u] = r.u.d; res.send(r.html.replace('/*offline_data_placeholder*/', "_clipperz_dump_data_="+JSON.stringify(ojs) +";" +"Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.Offline();" +"Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();")); }); } }; rv.__defineGetter__('session_store',function(){ return function(o) { return new (clipperz_store(PG))(o) } }); + (rv.router = require('express').Router()) + .post('/json',rv.json).get('/dump',rv.dump) + .use(EXPRESS.static(PATH.join(__dirname,'htdocs/'))); + return rv; }; |