commit 11fb50a2f12534b5c19fc165d77fd96924482043 Author: Maciej MaƂecki Date: Fri Mar 7 23:15:56 2014 +0100 Recommit everything because of credentials diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0bb81cb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results +node_modules +npm-debug.log +mochahelper.js + +.idea/ +.settings/ + +dist +.tmp +.sass-cache +app/bower_components +options.mine.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..78edf35a --- /dev/null +++ b/.jshintrc @@ -0,0 +1,35 @@ +{ + "white": false, + "node": true, + "browser": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "smarttabs": true, + "globals": { + "angular": true, + "document": true, + "nf": true, + "$":true, + "_":true, + "Highcharts": true, + "timeseries": true, + "describe": true, + "beforeEach": true, + "afterEach": true, + "it": true + } +} diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..ec42dcdd --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: node lib/app.js diff --git a/README.md b/README.md new file mode 100644 index 00000000..d4362196 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# lamassu-server + +Lamassu remote server. + +## Installation + +```sh +git clone git@github.com:lamassu/lamassu-server.git +cd lamassu-server +npm install +``` + +If you're working on this stack, you probably want to `npm link` +[`lamassu-atm-protocol`](https://github.com/lamassu/lamassu-atm-protocol). + +```sh +git clone git@github.com:lamassu/lamassu-atm-protocol.git +cd lamassu-atm-protocol +npm install +npm link +``` + +```sh +# Back in lamassu-server +npm link lamassu-atm-protocol +``` + +## Running +```sh +node lib/app.js --https +``` + +The https flag is required for local testing. When deployed to a PAAS environment - such as heroku, the https flag is not required, +as the SSL connection typically terminates on the load balancer and the application will see http only. + +## Deployment +Deployment of this application is described in +[`lamassu-admin`](https://github.com/lamassu/lamassu-admin) documentation. diff --git a/config/postgres.json b/config/postgres.json new file mode 100644 index 00000000..dae20ca4 --- /dev/null +++ b/config/postgres.json @@ -0,0 +1,6 @@ +{ + "user": "lamassu", + "pwd": "lamassu", + "host": "localhost", + "db": "lamassu" +} diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 00000000..75695dc4 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +git remote | grep heroku +if [ $? -ne 0 ]; then + echo "Creating Heroku application..." + heroku apps:create +fi + +if [ -n "$DATABASE_URL" ]; then + echo "Setting DATABASE_URL..." + heroku config:set DATABASE_URL="$DATABASE_URL" +fi + +echo "Deploying..." +git push heroku master diff --git a/lib/app.js b/lib/app.js new file mode 100644 index 00000000..a213303f --- /dev/null +++ b/lib/app.js @@ -0,0 +1,69 @@ +/*jshint globalstrict: true, white: false, unused:false */ +/*globals require, exports, console, module, process */ +/* + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +'use strict'; + +var path = require('path'); +var express = require('express'); +var argv = require('optimist').argv; +var app = express(); +var fs = require('fs'); +var argv = require('optimist').argv; +var LamassuConfig = require('lamassu-config'); +var atm = require('lamassu-atm-protocol'); +var format = require('util').format; + +var conString, dbConfig, config; + +if (process.env.DATABASE_URL) { + conString = process.env.DATABASE_URL; +} +else { + dbConfig = require('../config/postgres.json'); + conString = format('postgres://%s:%s@%s/%s', dbConfig.user, dbConfig.pwd, dbConfig.host, dbConfig.db); +} + +config = new LamassuConfig(conString); + +var port = process.env.PORT || 3000; +app.use(express.logger()); +app.use(express.favicon()); +app.use(express.bodyParser()); +app.use(express.methodOverride()); +app.use(express.cookieParser('your secret here')); +app.use(express.session()); + +config.load(function(err, conf) { + if (err) { console.log(err); process.exit(1); } + atm.init(app, conf.config); + + if (argv.https) { + var https = require('https'); + var testkeys = path.join(__dirname, '..', 'testkeys'); + var privateKey = fs.readFileSync(path.join(testkeys, 'privatekey.pem')); + var certificate = fs.readFileSync(path.join(testkeys, 'certificate.pem')); + var credentials = {key: privateKey, cert: certificate}; + https.createServer(credentials, app).listen(port, function () { + console.log('Express server listening on port ' + port + ' (https)'); + }); + } + else { + var http = require('http'); + http.createServer(app).listen(port, function () { + console.log('Express server listening on port ' + port + ' (http)'); + }); + } +}); diff --git a/package.json b/package.json new file mode 100644 index 00000000..d0e9c706 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "lamassu-server", + "description": "bitcoin atm client server protocol module", + "keywords": [], + "version": "0.0.1", + "license": "MIT", + "author": "Peter Elger (http://nearform.com/)", + "contributors": [ + "Peter Elger (http://peterelger.com/)" + ], + "engines": { + "node": "0.10.x" + }, + "dependencies": { + "express": "~3.4.7", + "optimist": "~0.6.0", + "lamassu-config": "~0.1.1", + "lamassu-atm-protocol": "git+https://github.com/lamassu/lamassu-atm-protocol.git" + }, + "repository": { + "type": "git", + "url": "https://github.com/lamassu/lamassu-server.git" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-jshint": "~0.6.0", + "load-grunt-tasks": "~0.1.0", + "chai": "~1.8.1", + "matchdep": "~0.3.0", + "mocha": "~1.13.0", + "grunt-mocha-test": "~0.7.0", + "grunt-mocha-cov": "0.0.7" + } +} diff --git a/testkeys/certificate.pem b/testkeys/certificate.pem new file mode 100644 index 00000000..542541e1 --- /dev/null +++ b/testkeys/certificate.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICozCCAgwCCQCSX2bhri8GETANBgkqhkiG9w0BAQUFADCBlTELMAkGA1UEBhMC +SUUxEjAQBgNVBAgTCVdhdGVyZm9yZDESMBAGA1UEBxMJV2F0ZXJmb3JkMREwDwYD +VQQKEwhuZWFyRm9ybTEMMAoGA1UECxMDZGV2MRQwEgYDVQQDEwtQZXRlciBFbGdl +cjEnMCUGCSqGSIb3DQEJARYYcGV0ZXIuZWxnZXJAbmVhcmZvcm0uY29tMB4XDTE0 +MDEyMDExMjc1NloXDTE0MDIxOTExMjc1NlowgZUxCzAJBgNVBAYTAklFMRIwEAYD +VQQIEwlXYXRlcmZvcmQxEjAQBgNVBAcTCVdhdGVyZm9yZDERMA8GA1UEChMIbmVh +ckZvcm0xDDAKBgNVBAsTA2RldjEUMBIGA1UEAxMLUGV0ZXIgRWxnZXIxJzAlBgkq +hkiG9w0BCQEWGHBldGVyLmVsZ2VyQG5lYXJmb3JtLmNvbTCBnzANBgkqhkiG9w0B +AQEFAAOBjQAwgYkCgYEAtZBpc6ZpF3rVSOq0D2zD2PMgR4hBzka0tD7coEDRWgjH +CFCtwtB97yuV3zq6V0zcApogXIIM6NQm6vcSAna9hqEiQCJV18GEAylC7Z/AW7HP +L63kYTMAXhdoztLFrkczUbtHwCB6wyUehszSzWaozpS9+ESpf/bPxMJjfhuqOvcC +AwEAATANBgkqhkiG9w0BAQUFAAOBgQCF3oZsXXC4QIm5Say8AVPYlhyb0liUSmr8 +owvESnPFy2PYFHMwzLCE4wnVsXcRq4gK0rXiiuBQsNEw/v93RfLWV4DLAlf9DoB2 +sO3LA/LSj4ptjZ4Dki5NKfTK9b6QJoQkc/u68hEEOe/WYZPIxdaeki4aVCcnrv1v +zJ9YTluP7w== +-----END CERTIFICATE----- diff --git a/testkeys/certrequest.csr b/testkeys/certrequest.csr new file mode 100644 index 00000000..9b36b045 --- /dev/null +++ b/testkeys/certrequest.csr @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIICBDCCAW0CAQAwgZUxCzAJBgNVBAYTAklFMRIwEAYDVQQIEwlXYXRlcmZvcmQx +EjAQBgNVBAcTCVdhdGVyZm9yZDERMA8GA1UEChMIbmVhckZvcm0xDDAKBgNVBAsT +A2RldjEUMBIGA1UEAxMLUGV0ZXIgRWxnZXIxJzAlBgkqhkiG9w0BCQEWGHBldGVy +LmVsZ2VyQG5lYXJmb3JtLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA +tZBpc6ZpF3rVSOq0D2zD2PMgR4hBzka0tD7coEDRWgjHCFCtwtB97yuV3zq6V0zc +ApogXIIM6NQm6vcSAna9hqEiQCJV18GEAylC7Z/AW7HPL63kYTMAXhdoztLFrkcz +UbtHwCB6wyUehszSzWaozpS9+ESpf/bPxMJjfhuqOvcCAwEAAaAuMBMGCSqGSIb3 +DQEJBzEGEwRhc2RmMBcGCSqGSIb3DQEJAjEKEwhuZWFyRm9ybTANBgkqhkiG9w0B +AQUFAAOBgQC0+vxHKcdpeiUYYXJjUVHUC9xSR19l+8F7FNtehXyGNoxmpMwmEVkM +J1TUokG/HgBoh9vy8TxleHldDdA+9jjWfaPHk8LaRIkNguJ9IMvv3yctjcCD39lJ +Yb1mQWOYaDOsgsEqiN/U2K6yUneYGGKIndA/PrEmd1aBMOTQ7R9Tvg== +-----END CERTIFICATE REQUEST----- diff --git a/testkeys/privatekey.pem b/testkeys/privatekey.pem new file mode 100644 index 00000000..a3e93ede --- /dev/null +++ b/testkeys/privatekey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQC1kGlzpmkXetVI6rQPbMPY8yBHiEHORrS0PtygQNFaCMcIUK3C +0H3vK5XfOrpXTNwCmiBcggzo1Cbq9xICdr2GoSJAIlXXwYQDKULtn8Bbsc8vreRh +MwBeF2jO0sWuRzNRu0fAIHrDJR6GzNLNZqjOlL34RKl/9s/EwmN+G6o69wIDAQAB +AoGAS35aen3tIJgwavs8F1XQMTsWZuffBNgddvzUW8XXxqnzqB9zwJdUZcgnrwQK +SxZoPKS9Y/mnSIA+FmDZGjEpKEeLrFePYz9UHpSW3j3vmLwWNTyAFl/DjqyrCIpE ++qB309t9NYEdd7LTeJyfIfideyEDAZUaQ2VsVDQDypYeoUECQQDrNstTpkv24MLA +4rFiXSSiC5IT86QuXbmXeHNTdChhqFS8C5LVKqt4Prpq4QvwQksiHJkipp5zvy2V +zfvfVTNnAkEAxZvnnYR5XyIPMVRQtlV0iskbvnQovJ4l3B7UfHeP9DZ9uhAR4MUo +ttJGjDjUMo78w381KEAqePpKn+RhF70R8QJADqwEUtt0sZmjjFSXrAMTXehK3GO+ +QgYmpYQl7Xa5bh4J6xDtv85Bk+aVykTvcbUw6pfOFZM/Hwk11rpak7vE0QJAEFGD +mvppm3WQk55G3AfKi/t3kw68nnbg4YCaQ30MIjqtv0O8djdR2Wcb9FBtFY/BR9Ol +bCGAYGUq7HFLo041wQJBAL2x2OvwnYYtXXOBY27tox3B1hDye7jRI5Q/IvcRB7YE +00q8L0XVaV4lmyd7tfFDQq/bfDUgTuwvkSPnQcpJDDw= +-----END RSA PRIVATE KEY-----