Skip to content

Commit

Permalink
Merge pull request #25 from hcrlab/upstream
Browse files Browse the repository at this point in the history
Upstream
  • Loading branch information
mayacakmak authored Jun 25, 2021
2 parents a763551 + fe369fa commit 21a18e3
Show file tree
Hide file tree
Showing 16 changed files with 536 additions and 2,091 deletions.
217 changes: 203 additions & 14 deletions README.md

Large diffs are not rendered by default.

48 changes: 38 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var helmet = require('helmet')

var redis = require('redis');
var session = require('express-session');
// https://github.com/tj/connect-redis
var RedisStore = require('connect-redis')(session);
Expand All @@ -24,21 +25,26 @@ var passportSocketIo = require('passport.socketio');
var cookieParser = require('cookie-parser');

// https://www.npmjs.com/package/connect-redis
// use redis for session store
//var sessionStore = new RedisStore({ client: redisUrl.connect(process.env.REDIS_URL) });
var sessionStore = new RedisStore(
{
host: "localhost",
port: 6379,
}
);
// start redis and create the redis store
// https://github.com/tj/connect-redis/blob/master/migration-to-v4.md
// No password, so removed this line for now.
// password: 'my secret',
let redisClient = redis.createClient({
host: 'localhost',
port: 6379,
db: 1,
});
redisClient.unref();
redisClient.on('error', console.log);

let sessionStore = new RedisStore({ client: redisClient });

/////////////////

mongoose.Promise = global.Promise;
console.log('start mongoose');

mongoose.connect('mongodb://localhost/node-auth', { useMongoClient: true})
mongoose.connect('mongodb://localhost/node-auth', {useNewUrlParser: true, useUnifiedTopology: true})
.then(() => console.log('connection successful'))
.catch((err) => console.error(err));

Expand All @@ -50,6 +56,28 @@ var app = express();
console.log('use helmet');
app.use(helmet());

var use_content_security_policy = true

if (use_content_security_policy) {
console.log('using a content security policy');
app.use(helmet.contentSecurityPolicy({
directives:{
defaultSrc:["'self'"],
scriptSrc:["'self'", "'unsafe-inline'", 'static.robotwebtools.org', 'robotwebtools.org', 'webrtc.github.io'],
connectSrc:["'self'", 'ws://localhost:9090'],
imgSrc: ["'self'", 'data:'],
styleSrc:["'self'"],
fontSrc:["'self'"]}}));
} else {
// Disable the content security policy. This is helpful during
// development, but risky when deployed.
console.log('WARNING: Not using a content security policy. This risky when deployed!');
app.use(
helmet({
contentSecurityPolicy: false,
})
);
}

/////////////////////////
//
Expand All @@ -67,7 +95,7 @@ function ensureSecure(req, res, next){
return next();
};
// handle port numbers if you need non defaults
res.redirect('https://' + req.hostname + req.url); // express 4.x
res.redirect('https://' + req.hostname + req.url);
};
/////////////////////////

Expand Down
39 changes: 39 additions & 0 deletions bash_scripts/start_server_production_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

echo "****************************************"
echo "attempt to bring up server production environment"

echo ""
echo "first making sure that the system is fully shutdown prior to bringing it up"
echo "./stop_server_production__env.sh"
./stop_server_production__env.sh

echo ""
echo "set environment variable for development environment"
echo "export HELLO_ROBOT_ENV=\"production\""
export HELLO_ROBOT_ENV="production"

echo ""
echo "attempting to start MongoDB..."
echo "sudo systemctl start mongod.service"
sudo systemctl start mongod.service

echo ""
echo "attempting to start Redis..."
echo "sudo systemctl start redis.service"
sudo systemctl start redis.service

echo ""
echo "attempting to start the web server..."
echo "cd /home/ubuntu/repos/stretch_web_interface/"
cd /home/ubuntu/repos/stretch_web_interface/
echo "sudo --preserve-env node ./bin/www &"
sudo --preserve-env node ./bin/www &

echo ""
echo "finished attempt to bring up server production environment"
echo "****************************************"




30 changes: 30 additions & 0 deletions bash_scripts/stop_server_production_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

echo "****************************************"
echo "attempt to stop server production environment"

echo ""
echo "remove environment variable for server production environment"
echo "unset HELLO_ROBOT_ENV"
sudo unset HELLO_ROBOT_ENV

echo ""
echo "attempting to stop MongoDB..."
echo "sudo systemctl stop mongod.service"
sudo systemctl stop mongod.service

echo ""
echo "attempting to stop Redis..."
echo "sudo systemctl stop redis.service"
sudo systemctl stop redis.service

echo ""
echo "attempting to stop the web server..."
echo "pkill -f \"node ./bin/www\""
sudo pkill -f "node ./bin/www"

echo ""
echo "finished attempt to stop the server production environment"
echo "****************************************"


9 changes: 6 additions & 3 deletions bash_scripts/web_interface_installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ echo "Installing rosbridge"
sudo apt-get --yes install ros-melodic-rosbridge-server
echo "Done."

# NODE 10
# NODE 14
echo ""
echo "Installing Node.js 10"
echo "Installing Node.js 14"
echo "Downloading from the Internet via curl."
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
echo "Installing nodejs with apt-get"
sudo apt-get install -y nodejs
echo "Done."
Expand All @@ -28,6 +28,9 @@ echo "Done."
echo ""
echo "Installing web-interface Node packages using npm."
cd ~/catkin_ws/src/stretch_web_interface/
echo "Update to latest version of npm."
npm install -g npm
echo "Install packages with npm."
npm install
echo "Done."

Expand Down
59 changes: 59 additions & 0 deletions bash_scripts/web_server_installation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

echo ""
echo "Starting web server installation script."

# APT UPDATE
echo ""
echo "Updating with apt."
sudo apt-get --yes update
echo "Done."

# NODE 14
echo ""
echo "Installing Node.js 14"
echo "Downloading from the Internet via curl."
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
echo "Installing nodejs with apt-get"
sudo apt-get install -y nodejs
echo "Done."

# PACKAGES VIA NPM
echo ""
echo "Installing web-interface Node packages using npm."
cd ~/repos/stretch_web_interface/
echo "Update to latest version of npm."
sudo npm install -g npm
echo "Install packages with npm."
sudo npm install
echo "Done."

# MONGODB
echo ""
echo "Installing MongoDB, which is used to store credentials for robot and operator logins."
sudo apt-get --yes install mongodb
echo "Done."

# CHECK MONGODB
echo ""
echo "Look at the following output to make sure the mongodb service is working."
systemctl status mongodb

# REDIS
echo ""
echo "Install redis for the web server."
sudo apt-get --yes install redis
echo "Done."

# COTURN
echo ""
echo "Install coturn for the web server."
sudo apt-get --yes install coturn
echo "Setup coturn.service."
sudo cp ~/repos/stretch_web_interface/coturn.service /etc/systemd/system/
echo "Done."


echo ""
echo "The web server installation script has finished."
echo ""
15 changes: 15 additions & 0 deletions coturn.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Coturn STUN and TURN server
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/var/run/turnserver.pid
ExecStart=/usr/bin/turnserver -c /etc/turnserver.conf -o -v
Restart=on-failure
IgnoreSIGPIPE=yes

[Install]
WantedBy=multi-user.target


Binary file modified images/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/mongodb_development_credentials.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 21a18e3

Please sign in to comment.