From 1d3c5aeeb1f2fa38261ea414b1e288bc29eeb912 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Sat, 21 Oct 2017 22:59:31 +0200 Subject: [PATCH] added Dockerfile, and implemented script to create Admin --- Dockerfile | 49 ++++++++++++++++++++++++++++ OLDDockerfile | 64 ++++++++++++++++++++++++++++++++++++ README.md | 2 ++ adminCreator.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 203 insertions(+) create mode 100644 Dockerfile create mode 100644 OLDDockerfile create mode 100644 adminCreator.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7adf026 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +FROM ubuntu:latest + +RUN apt-get update -y + +RUN apt-get install git -y +RUN apt-get install -y curl +RUN apt-get install -y wget + +#install Nodejs +RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - +RUN apt-get install -y nodejs +RUN apt-get install -y build-essential + +#install MongoDB +RUN \ + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 && \ + echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.4.list && \ + apt-get update && \ + apt-get install -y mongodb-org + +#install bower +RUN npm install -g bower + +RUN npm install -g forever + +#donwload commonroutesServer +RUN git clone https://github.com/arnaucode/commonroutesServer.git +RUN cd commonroutesServer +RUN npm install + +#run mongodb service +CMD service mongod start + +CMD cd commonroutesServer && \ + forever start server.js + +#commands to use: +#docker build -t containername . +#docker run -ti containername /bin/bash +#docker start -ti containername /bin/bash +#docker ps -a +#docker rm containernametodelete +#docker images +#docker rmi imagenametodelete +# delete all containers +#docker rm $(docker ps -a -q) +# delete all images +#docker rmi $(docker images -q) + diff --git a/OLDDockerfile b/OLDDockerfile new file mode 100644 index 0000000..a5268d0 --- /dev/null +++ b/OLDDockerfile @@ -0,0 +1,64 @@ +FROM ubuntu:latest + +RUN apt-get update -y + +RUN apt-get install git -y +RUN apt-get install -y curl +RUN apt-get install -y wget + +#install Nodejs +RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - +RUN apt-get install -y nodejs +RUN apt-get install -y build-essential + +#install MongoDB +RUN \ + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 && \ + echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.4.list && \ + apt-get update && \ + apt-get install -y mongodb-org + +#install bower +RUN npm install -g bower + +RUN npm install -g forever + +#donwload commonroutesServer +RUN git clone https://github.com/arnaucode/commonroutesServer.git +RUN cd commonroutesServer +RUN npm install + +#install Go +#ENV GOVERSION 1.6.2 +#ENV GOROOT /opt/go +#ENV GOPATH /root/.go +#RUN cd /opt && wget https://storage.googleapis.com/golang/go${GOVERSION}.linux-amd64.tar.gz && \ +# tar zxf go${GOVERSION}.linux-amd64.tar.gz && rm go${GOVERSION}.linux-amd64.tar.gz && \ +# ln -s /opt/go/bin/go /usr/bin/ && \ +# mkdir $GOPATH + +#download goImgServer +#RUN git clone https://github.com/arnaucode/goImgServer.git + +#run mongodb service +CMD service mongod start + +#CMD cd goImgServer && \ +# ./goImgServer & +#CMD cd + +CMD cd commonroutesServer && \ + forever start server.js + +#commands to use: +#docker build -t containername . +#docker run -ti containername /bin/bash +#docker start -ti containername /bin/bash +#docker ps -a +#docker rm containernametodelete +#docker images +#docker rmi imagenametodelete +# delete all containers +#docker rm $(docker ps -a -q) +# delete all images +#docker rmi $(docker images -q) diff --git a/README.md b/README.md index 8697317..45ac1ca 100755 --- a/README.md +++ b/README.md @@ -2,8 +2,10 @@ - server code: https://github.com/arnaucode/commonroutesServer - frontend app code: https://github.com/arnaucode/commonroutesApp +- frontend webapp code: https://github.com/arnaucode/commonroutesWebApp - images server: https://github.com/arnaucode/goImgServer - admin web: https://github.com/arnaucode/commonroutesAdminWeb +- landing page: https://github.com/arnaucode/commonroutesLandingPage **Backend:** diff --git a/adminCreator.js b/adminCreator.js new file mode 100644 index 0000000..81eb978 --- /dev/null +++ b/adminCreator.js @@ -0,0 +1,87 @@ +//File: controllers/userController.js +var mongoose = require('mongoose'); + +var config = require('./config'); +var adminConfig = require('./adminConfig'); // get our config file + +mongoose.Promise = global.Promise; +// Connection to DB +mongoose.connect(config.database, function(err, res) { + if (err) throw err; + console.log('Connected to Database'); +}); + + +var adminMdl = require('./models/adminModel')(app, mongoose); +var adminModel = mongoose.model('adminModel'); + + +/* */ +var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens +var express = require("express"); +var app = express(); +var config = require('./config'); // get our config file +app.set('superSecret', config.secret); // secret variable + +var crypto = require('crypto'); +/* */ + +var request = require('request'); + +var readlineSync = require('readline-sync'); + +var admin = new adminModel({}); + +console.log("Welcome to Common Routes"); +console.log("----------"); +console.log("This is the adminCreator.js"); + + +admin.username = readlineSync.question('Enter the admin name: '); +if ((admin.username == "")) { + console.log("username can't be empty"); + process.exit(0); +} +console.log('Hi ' + admin.username + '!'); + +var clearPassword = readlineSync.question('Enter the admin password: ', { + hideEchoBack: true // The typed text on screen is hidden by `*` (default). +}); +var clearPassword2 = readlineSync.question('Enter the admin password again: ', { + hideEchoBack: true // The typed text on screen is hidden by `*` (default). +}); +if (clearPassword != clearPassword2) { + console.log("passwords don't match"); + process.exit(0); +} +if (clearPassword=="undefined") { + console.log("Password can't be empty"); + process.exit(0); +} +if (clearPassword.length < 10) { + console.log("Please, choose a password with more than 10 characters"); + process.exit(0); +} +admin.password = crypto.createHash('sha256').update(clearPassword).digest('base64') + +admin.email = readlineSync.question('email: '); +admin.phone = readlineSync.question('phone: '); +admin.telegram = readlineSync.question('telegram: '); + +if (admin.email == undefined) { + console.log("username or email empty"); + process.exit(0); +} + +console.log(admin); + +admin.save(function(err, admin) { + if (err){ + console.log(err.message); + process.exit(0); + } + + console.log("admin created correctly"); + process.exit(0); +}); +process.exit(0); diff --git a/package.json b/package.json index fa7a3b3..c0715d8 100755 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "mongoose": "latest", "mongoose-unique-validator": "^1.0.2", "morgan": "latest", + "readline-sync": "^1.4.7", "request": "^2.81.0" } }