Browse Source

template

master
zeus 3 years ago
parent
commit
20d5c64a19
  1. 1
      install/usr/share/swarmlab.io/sec/project/courses/README
  2. 31
      install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/client.js
  3. 109
      install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/mongo.js
  4. 24
      install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/server.js
  5. 8
      install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/package.json
  6. 107
      install/usr/share/swarmlab.io/sec/project/courses/nodeAppServer/app/app.js
  7. 1099
      install/usr/share/swarmlab.io/sec/project/courses/nodeAppServer/package-lock.json
  8. 7
      install/usr/share/swarmlab.io/sec/project/courses/nodeAppServer/package.json
  9. 121
      install/usr/share/swarmlab.io/sec/project/data-www/index.html
  10. 1
      install/usr/share/swarmlab.io/sec/project/hello_world.sh
  11. 43
      install/usr/share/swarmlab.io/sec/swarmlab-sec
  12. 23
      swarmlab-index.js

1
install/usr/share/swarmlab.io/sec/project/courses/README

@ -1 +0,0 @@
Course examples

31
install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/client.js

@ -1,31 +0,0 @@
const app = require('express')();
const http = require('http').Server(app);
var path = require('path');
options = {
secure:true,
reconnect: true,
rejectUnauthorized : false
};
var io2 = require('socket.io-client');
var socket = io2.connect('http://localhost:8084', options);
var msg2 = "c= 120";
socket.emit('log', msg2);
/*
var io = require('socket.io')(http);
app.get('/log', (req, res) => {
socket.emit('log', 'send from get');
res.send('<h1>send</h1>');
});
http.listen(8085, () => {
console.log('listening on *:8085');
});
*/

109
install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/mongo.js

@ -1,109 +0,0 @@
var path = require('path');
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
const MongoClient = require('mongodb').MongoClient;
app.get('/test', (req, res) => {
var user="swarmlab"
var pass="swarmlab"
/*
use admin
db.createUser(
{
user: "test1",
pwd: 'newpass', // Or "<cleartext password>"
roles: [ { role: "readWrite", db: "app_swarmlab" } ],
authenticationRestrictions: [ {
clientSource: ["192.168.1.7"],
serverAddress: ["192.168.80.2", "192.168.80.3", "192.168.80.4"]
} ]
}
)
*/
var mongourl = "mongodb://"+user+":"+pass+"@swarmlabmongo1:27017,swarmlabmongo2:27017,swarmlabmongo1:27017/app_swarmlab?replicaSet=rs0&authSource=admin&w=1"
const OPTS = {
useNewUrlParser: true,
useUnifiedTopology: true,
//poolSize: 10,
tls: false
};
const client = new MongoClient(mongourl,OPTS);
client.on('serverDescriptionChanged', function(event) {
console.log('received serverDescriptionChanged');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverHeartbeatStarted', function(event) {
console.log('received serverHeartbeatStarted');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverHeartbeatSucceeded', function(event) {
console.log('received serverHeartbeatSucceeded');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverHeartbeatFailed', function(event) {
console.log('received serverHeartbeatFailed');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverOpening', function(event) {
console.log('received serverOpening');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverClosed', function(event) {
console.log('received serverClosed');
console.log(JSON.stringify(event, null, 2));
});
client.on('topologyOpening', function(event) {
console.log('received topologyOpening');
console.log(JSON.stringify(event, null, 2));
});
client.on('topologyClosed', function(event) {
console.log('received topologyClosed');
console.log(JSON.stringify(event, null, 2));
});
client.on('topologyDescriptionChanged', function(event) {
console.log('received topologyDescriptionChanged');
console.log(JSON.stringify(event, null, 2));
});
client.connect(function(err, client) {
if(err) throw err;
const db = client.db('app_swarmlab');
db.collection('logs').find({}).toArray()
.then(item => {
console.log('item '+JSON.stringify(item))
for (let i in item) {
console.log(JSON.stringify('items' + item[i]))
}
})
});
res.send('<h1>Hello world!</h1>');
});
io.on('connection', s => {
console.error('socket connection');
s.on('log', (data, room) => {
console.log('broadcast', data);
});
});
http.listen(8084, () => console.error('listening on http://localhost:8084/'));
console.error('socket.io example');

24
install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/server.js

@ -1,24 +0,0 @@
var path = require('path');
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', (req, res) => {
res.send('<h1>Hello world!</h1>');
});
io.on('connection', s => {
console.error('socket connection');
s.on('log', (data, room) => {
console.log('broadcast', data);
});
});
http.listen(8084, () => console.error('listening on http://localhost:8084/'));
console.error('socket.io example');

8
install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/package.json

@ -1,8 +0,0 @@
{
"dependencies": {
"express": "^4.17.1",
"mongodb": "^3.6.5",
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.0"
}
}

107
install/usr/share/swarmlab.io/sec/project/courses/nodeAppServer/app/app.js

@ -1,107 +0,0 @@
var express = require('express');
var http = require('http');
const MongoClient = require('mongodb').MongoClient;
var PORT = 8085;
var app = express();
app.get('/', function(req, res) {
var RES ={}
var message = req.query["log"]
// Connection URL
var database = "app_swarmlab"
var user = "swarmlab"
var password = "swarmlab"
var collection = "logs"
var replica_set = "rs0"
var nodes = "swarmlabmongo1:27017,swarmlabmongo2:27017,swarmlabmongo3:27017"
//var url = `mongodb://${user}:${password}@${nodes}/${database}?replicaSet=${replica_set}&authSource=admin`
var mongourl = "mongodb://"+user+":"+password+"@swarmlabmongo1:27017,swarmlabmongo2:27017,swarmlabmongo3:27017/app_swarmlab?replicaSet=rs0&authSource=admin&w=1"
const OPTS = {
useNewUrlParser: true,
useUnifiedTopology: true,
//poolSize: 10,
tls: false
};
const client = new MongoClient(mongourl,OPTS);
client.on('serverDescriptionChanged', function(event) {
console.log('received serverDescriptionChanged');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverHeartbeatStarted', function(event) {
console.log('received serverHeartbeatStarted');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverHeartbeatSucceeded', function(event) {
console.log('received serverHeartbeatSucceeded');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverHeartbeatFailed', function(event) {
console.log('received serverHeartbeatFailed');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverOpening', function(event) {
console.log('received serverOpening');
console.log(JSON.stringify(event, null, 2));
});
client.on('serverClosed', function(event) {
console.log('received serverClosed');
console.log(JSON.stringify(event, null, 2));
});
client.on('topologyOpening', function(event) {
console.log('received topologyOpening');
console.log(JSON.stringify(event, null, 2));
});
client.on('topologyOpening', function(event) {
console.log('received topologyOpening');
console.log(JSON.stringify(event, null, 2));
});
client.on('topologyClosed', function(event) {
console.log('received topologyClosed');
console.log(JSON.stringify(event, null, 2));
});
client.on('topologyDescriptionChanged', function(event) {
console.log('received topologyDescriptionChanged');
console.log(JSON.stringify(event, null, 2));
});
client.connect(function(err, client) {
if(err) throw err;
const db = client.db('app_swarmlab');
db.collection('logs').find({}).toArray()
.then(item => {
console.log('item '+JSON.stringify(item))
for (let i in item) {
console.log(JSON.stringify('items' + item[i]))
}
res.send({message: message, data:item});
})
});
});
app.post('/', function(req, res) {
var message = req.body["log"]
console.log(JSON.stringify(message))
//console.log(req)
res.send({message: message});
});
http.Server(app).listen(PORT, function() {
console.log("HTTP server listening on port %s", PORT);
});

1099
install/usr/share/swarmlab.io/sec/project/courses/nodeAppServer/package-lock.json

File diff suppressed because it is too large

7
install/usr/share/swarmlab.io/sec/project/courses/nodeAppServer/package.json

@ -1,7 +0,0 @@
{
"main": "app.js",
"dependencies": {
"express": "^4.17.1",
"mongodb": "^3.6.6"
}
}

121
install/usr/share/swarmlab.io/sec/project/data-www/index.html

@ -1,121 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Page for the Nginx HTTP Server on Swarmlab.io</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: #fff;
color: #000;
font-size: 0.9em;
font-family: sans-serif,helvetica;
margin: 0;
padding: 0;
}
:link {
color: #c00;
}
:visited {
color: #c00;
}
a:hover {
color: #f50;
}
h1 {
text-align: center;
margin: 0;
padding: 0.6em 2em 0.4em;
background-color: #294172;
color: #fff;
font-weight: normal;
font-size: 1.75em;
border-bottom: 2px solid #000;
}
h1 strong {
font-weight: bold;
font-size: 1.5em;
}
h2 {
text-align: center;
background-color: #3C6EB4;
font-size: 1.1em;
font-weight: bold;
color: #fff;
margin: 0;
padding: 0.5em;
border-bottom: 2px solid #294172;
}
hr {
display: none;
}
.content {
padding: 1em 5em;
}
.alert {
border: 2px solid #000;
}
img {
border: 2px solid #fff;
padding: 2px;
margin: 2px;
}
a:hover img {
border: 2px solid #294172;
}
.logos {
margin: 1em;
text-align: center;
}
/*]]>*/
</style>
</head>
<body>
<h1>Welcome to <strong>nginx</strong> on Swarmlab.io!</h1>
<div class="content">
<p>This page is used to test the proper operation of the
<strong>nginx</strong> HTTP server after it has been
installed. If you can read this page, it means that the
web server installed at this site is working
properly.</p>
<div class="alert">
<h2>Website Administrator</h2>
<div class="content">
<p>This is the default <tt>index.html</tt> page that
is distributed with <strong>nginx</strong> on
Swarmlab.io. It is located in
<tt>/data/www</tt>.</p>
<p>You should now put your content in a location of
your choice and edit the <tt>root</tt> configuration
directive in the <strong>nginx</strong>
configuration file
<tt>/etc/nginx/nginx.conf</tt>.</p>
<a href="https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/">
<img
src="nginx-logo.png"
alt="[ Powered by nginx ]"
width="121" height="32" />More info here</a>
</div>
</div>
<div class="logos">
<a href="http://nginx.com/"><img
src="nginx-logo.png"
alt="[ Powered by nginx ]"
width="121" height="32" /></a>
<a href="http://swarmlab.io"><img
src="poweredby.png"
alt="[ Powered by Swarmlab.io ]"
width="88" height="31" /></a>
</div>
</div>
</body>
</html>

1
install/usr/share/swarmlab.io/sec/project/hello_world.sh

@ -1 +0,0 @@
echo "Hello World"

43
install/usr/share/swarmlab.io/sec/swarmlab-sec

@ -24,9 +24,29 @@
# Origin: https://github.com/NLKNguyen/alpine-mpich
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
TARGET="$(readlink "$SOURCE")"
if [[ $TARGET == /* ]]; then
SOURCE="$TARGET"
else
DIR="$( dirname "$SOURCE" )"
SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
fi
done
SRPATH="$( dirname "$SOURCE" )"
SFPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
if [ "$SFPATH" != "$SRPATH" ]; then
RDIR=$SRPATH # relativ path directory
fi
cwdir=$PWD
wdir=$SFPATH
set -e
DOCKERuser="docker"
# edit it - EDIT-BEGIN
@ -55,9 +75,29 @@ DOCKERuser="docker"
IMAGE_local="microservice-xelatexthesis"
IMAGE_origin="hub.swarmlab.io:5480/xelatex-basegui"
GIT_origin="https://git.swarmlab.io:3000/swarmlab/swarmlab-microservice-example.git"
service_GUI=true
service_WEB=true
service_URL=http
DOCKERuser="docker"
# edit it - EDIT_END
# you do not need to edit it - BEGIN
cat << FOE > swarmlab-index.js
export const myApiConfig = [
{
"swarmlabname": "$IMAGE_local",
"git": "$GIT_origin",
"gui": $service_GUI,
"web": $service_WEB,
"url": "$service_URL",
"version": 0,
"port": 0
}
];
FOE
APTPARAM=" --no-install-recommends "
HYBRID_NETWORK=$IMAGE_local
bootstrap="sec_bootstrap"
@ -315,7 +355,6 @@ fi
/bin/mkdir -p $Wdir/logs
/bin/cp -rf $DIR/project/bin $Wdir/project
/bin/cp -rf $DIR/project/config $Wdir/project
/bin/cp -f $DIR/project/hello_world.sh $Wdir/project
/bin/cp -f $DIR/$bootstrap $Wdir/$bootstrap
/bin/cp -f $DIR/$hostnames $Wdir/$hostnames
/bin/cp -f $DIR/$hostnames_get $Wdir/$hostnames_get

23
install/usr/share/swarmlab.io/sec/swarmlab-config.js → swarmlab-index.js

@ -1,4 +1,23 @@
/*
*
* Application index
*
* url = http or https
*
*/
export const myApiIndex = [
{
"swarmlabname": "microservice-etherpad",
"info": 'http',
"version": 0,
"port": 0
}
];
/*
*
* Config4Web interface
@ -9,7 +28,7 @@
*
*/
export const ApiConfigWEB = [
export const myApiConfigWEB = [
{
"name": "microservice-etherpad",
"automated": true,
@ -29,7 +48,7 @@ export const ApiConfigWEB = [
* port = 0 // Auto
*
*/
export const ApiConfigGUI = [
export const myApiConfigGUI = [
{
"name": "microservice-firefox",
"automated": true,
Loading…
Cancel
Save