Browse Source

readme

master
zeus 4 years ago
parent
commit
92c29c4dea
  1. 82
      README.md
  2. 128
      llo/connect-new.js

82
README.md

@ -1,10 +1,10 @@
<img align="right" width="300" height="300" src="https://git.swarmlab.io:3000/swarmlab/venus-client/raw/branch/master/images/snowflake_256.png"> <img align="right" width="300" height="300" src="https://git.swarmlab.io:3000/zeus/swarmlab-hybrid/raw/branch/master/docs/images/hybrid-1.png">
# Swarmlab Venus # Swarmlab Venus
### **Welcome to Swarmlab.io** <br> ### **Welcome to VEnus Network Unification Service** <br>
## Swarmlab-venus Network Virtualization ## Swarmlab-venus Network Virtualization
### on-demand network environments ### on-demand network environments
@ -13,27 +13,53 @@
# on-demand sandbox environments # on-demand sandbox environments
* Virtual Labroom * Virtual Labroom
* Virtual Classroom * Virtual Classroom
* Proof-of-Concept (POC) * Proof-of-Concept (POC)
<br> <br>
### Table of contents ### Table of contents
1. [Features](#introduction)
2. [System requirements ](#systemrequirements) 2. [System requirements ](#systemrequirements)
3. [Prerequisites](#prerequisites) 3. [Prerequisites](#prerequisites)
4. [Installation](#installation) 4. [Installation](#installation)
5. [More info](#moreinfo)
<br> <br>
### <a name="introduction"></a>
## <b>Swarmlab Venus</b> is Swarmlabs hybrids syblin, diagnosed with the VPN disease.
Swarmlab venus provides the user with the unique abillity to create **virtual networks** and use them to project for a Virtual Classroom, an app of your own making or proof of concept. An all of that <b>using only a browser</b> of their choice.
## Why?
Ever imagined having a network environment to tryout stuff with your coworkers/costudents for work or just for fun?
Ever created a service that you would like to test on a real-world network?
Ever designed an Labroom/application you would like to distribute to your students/coworkers/potential clients?
Swarmlab venus comes to bridge the gap between you, your network/computer, the coder/developer of a service and the end user while at the same time meeting the needs for a real-world testing environment.
With venus you can now as part of the cloud work <b>independantly</b> but also stay <b>connected</b>.
The venus service allows us to utilize the power of Swarmlab itself but also combine it with the practiacally unlimited computing of our own machines.
## Another Swarmlab app. Why?
How does Swarmlab Venus differ from Swarmlab Hybrid?
Well swarmlab-hybrid forces server-client/containerized applications while venus allows for peer-to-peer connection! You can create and connect directly to a network with your coworkers, whithout needing a server.
Ofcourse you can use venus independantly or alongside swarmlab and all of its powerful features.
To sum up, you can now design, develop and test apps using swarlab-hybrid but you can also connect directly to other interested parties for testing or work purposes.
## System requirements<a name="systemrequirements"></a> ## System requirements<a name="systemrequirements"></a>
**Before** you create and configure a hybrid deployment using the swarmlab-agent client, your Local Machines need to meet certain requirements. **Before** you create and configure a venus deployment using the swarmlab-agent client, your Local Machines need to meet certain requirements.
> If you don't meet those requirements, you won't be able to complete the steps within the swarmlab-agent client and you won't be able to configure a network deployment between your Local Enviroment and Swarmlab Online Enviroment. > If you don't meet those requirements, you won't be able to complete the steps within the swarmlab-agent client and you won't be able to configure a network deployment between your Local Enviroment and Swarmlab Online Enviroment.
@ -50,7 +76,7 @@
- Minimum: 2 - Minimum: 2
- Recommended 4+ - Recommended 4+
- Disk Space - Disk Space
- 10 GB for internal requirements. - 5 GB for internal requirements.
- The amount of additional disk space soloemnly depends on you intended use. - The amount of additional disk space soloemnly depends on you intended use.
:warning: Since Docker uses hypervisor the host NEEDS TO HAVE VIRTUALIZATION ENABLED! :warning: Since Docker uses hypervisor the host NEEDS TO HAVE VIRTUALIZATION ENABLED!
@ -62,43 +88,18 @@
* node version >15 * node version >15
[Install Node](http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/nodejs/install-nodejs.adoc.html)
or run
```sh ```sh
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash - curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
sudo apt-get install -y nodejs sudo apt-get install -y nodejs
``` ```
* wireguard
[Install Wireguard](http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/wg/install-wg.adoc.html)
or run
```sh
sudo apt install wireguard jq
```
* docker * docker
[install docker](http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install-docker.adoc.html)
or run
```sh ```sh
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update sudo apt update
sudo apt install -y docker-ce sudo apt install -y docker-ce
sudo usermod -aG docker $USER # Please replace $USER with the user you want to run docker on sudo usermod -aG docker [USERNAME] # Please replace [USERNAME] with the user you want to run docker on
``` ```
:information_source: for kali specifically please visit the following link to install docker. :information_source: for kali specifically please visit the following link to install docker.
@ -113,13 +114,26 @@ https://linuxhint.com/install_docker_kali_linux/
sudo chmod +x /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
``` ```
* pm2 * pm2
```sh ```sh
sudo npm install -g pm2 sudo npm install -g pm2
``` ```
* wireguard
```sh
sudo apt install wireguard jq
```
<br>
### **MORE Installation info here**
[install docker](http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/docker/install-docker.adoc.html)
[Install Wireguard](http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/wg/install-wg.adoc.html)
[Install Node](http://docs.swarmlab.io/SwarmLab-HowTos/labs/Howtos/nodejs/install-nodejs.adoc.html)
<br> <br>

128
llo/connect-new.js

@ -56,6 +56,33 @@ var static_options = {
app.use('/', express.static('client', static_options)) app.use('/', express.static('client', static_options))
function myexec(res) {
var mypath = process.cwd()
var RES = new Object();
try {
var showexec = `${res}`
console.error('execi 1 ' + JSON.stringify(res));
const stdout = execSync(res, {
env: {
NODE_ENV: "production",
},
});
var datajson = stdout.toString()
//var datajson = JSON.parse(string);
RES.error = false
RES.error_msg = "ok"
RES.data = datajson;
console.error('exec ' + JSON.stringify(RES.data));
return RES
} catch (error) {
var datajson = error.toString()
return datajson
}
}
/* /*
* ********************************************************** * **********************************************************
@ -64,23 +91,41 @@ app.use('/', express.static('client', static_options))
*/ */
function wg_save_clientconf(res) { async function wg_save_clientconf(res) {
/* /*
res.publickey res.publickey
res.endpoint res.endpoint
res.serverip res.serverip
res.bootstrapstackid
res.netmask res.netmask
res.privatekey res.privatekey
res.allowedips res.allowedips
res.interfaceip res.interfaceip
res.endpointfpath res.endpointfpath
*/ */
const apptest = require('express')();
const servertest = apptest.listen(0, () => {
var newport = servertest.address().port
servertest.close();
fs.mkdir(`./hybrid/connect/${res.bootstrapstackid}`, { recursive: true }, (err) => {
if (err){
var RES = new Object();
RES.error = true
RES.error_msg = "error"
RES.validator_msg = 'write error'
RES.error_statuscode = "500"
RES.data = err
return RES
}else{
var endpointfpath = `${res.serverip}:${res.endpoint}` var endpointfpath = `${res.serverip}:${res.endpoint}`
var peerconfig =` var peerconfig =`
[Interface] [Interface]
PrivateKey = ${res.privatekey} PrivateKey = ${res.privatekey}
ListenPort = 51820 ListenPort = ${newport}
[Peer] [Peer]
PublicKey = ${res.publickey} PublicKey = ${res.publickey}
@ -89,14 +134,28 @@ var peerconfig =`
#AllowedIPs = 10.1.0.0/24, 0.0.0.0/0, ::/0 #AllowedIPs = 10.1.0.0/24, 0.0.0.0/0, ::/0
PersistentKeepalive = 30 PersistentKeepalive = 30
` `
try { try {
fs.writeFileSync('./hybrid/connect/wg0.conf', peerconfig); fs.writeFileSync(`./hybrid/connect/${res.bootstrapstackid}/wg0.conf`, peerconfig);
return 'ok' var RES1 = new Object();
RES1.error = false
RES1.error_msg = "ok"
RES1.validator_msg = 'ok'
RES1.error_statuscode = "200"
RES1.data = 'created'
return RES1
} catch (error) { } catch (error) {
var datajson = error.toString() var datajson = error.toString()
return datajson var RES1 = new Object();
RES1.error = true
RES1.error_msg = "error"
RES1.validator_msg = 'write error'
RES1.error_statuscode = "500"
RES1.data = datajson
return RES1
} }
}
});
})
} }
/* /*
@ -105,7 +164,7 @@ var peerconfig =`
* ********************************************************** * **********************************************************
*/ */
function wg_save_ifup_linux(res) { async function wg_save_ifup_linux(res) {
var mypath = process.cwd() var mypath = process.cwd()
var DEV_NAME = res.dev_name var DEV_NAME = res.dev_name
var INTERFACE_IP = res.INTERFACE_IP var INTERFACE_IP = res.INTERFACE_IP
@ -115,6 +174,7 @@ function wg_save_ifup_linux(res) {
res.publickey res.publickey
res.endpoint res.endpoint
res.serverip res.serverip
res.bootstrapstackid
res.netmask res.netmask
res.privatekey res.privatekey
res.allowedips res.allowedips
@ -137,13 +197,13 @@ function wg_save_ifup_linux(res) {
ip route show table 200 | grep -w ${INTERFACE_IProute} ip route show table 200 | grep -w ${INTERFACE_IProute}
ip rule add table main suppress_prefixlength 0 ip rule add table main suppress_prefixlength 0
` `
fs.writeFileSync('./hybrid/connect/ifup_linux', myExec); fs.writeFileSync(`./hybrid/connect/${res.bootstrapstackid}/ifup_linux`, myExec);
const myExec1 = ` const myExec1 = `
ip link set ${DEV_NAME} down ip link set ${DEV_NAME} down
ip link del ${DEV_NAME} ip link del ${DEV_NAME}
` `
fs.writeFileSync('./hybrid/connect/ifdown_linux', myExec1); fs.writeFileSync(`./hybrid/connect/${res.bootstrapstackid}/ifdown_linux`, myExec1);
return 'ok' return 'ok'
} catch (error) { } catch (error) {
@ -158,7 +218,7 @@ function wg_save_ifup_linux(res) {
* ********************************************************** * **********************************************************
*/ */
function wg_save_connect_linux(res) { async function wg_save_connect_linux(res) {
var mypath = process.cwd() var mypath = process.cwd()
var DEV_NAME = res.dev_name var DEV_NAME = res.dev_name
var INTERFACE_IP = res.INTERFACE_IP var INTERFACE_IP = res.INTERFACE_IP
@ -168,6 +228,7 @@ function wg_save_connect_linux(res) {
res.publickey res.publickey
res.endpoint res.endpoint
res.serverip res.serverip
res.bootstrapstackid
res.netmask res.netmask
res.privatekey res.privatekey
res.allowedips res.allowedips
@ -176,38 +237,38 @@ function wg_save_connect_linux(res) {
*/ */
try { try {
const myExec = ` const myExec = `
docker exec -it swarmlabwg /bin/bash -c "ip link set swarmlab0 down; ip link del swarmlab0" docker exec -it swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}"
sleep 1 sleep 1
docker stop swarmlabwg; docker container rm swarmlabwg docker stop swarmlabwg-${res.bootstrapstackid}; docker container rm swarmlabwg-${res.bootstrapstackid}
sleep 1 sleep 1
docker pull hub.swarmlab.io:5480/venusclient:latest docker pull hub.swarmlab.io:5480/venusclient:latest
sleep 1 sleep 1
docker run -d \ docker run -d \
--net=host \ --net=host \
--name=swarmlabwg \ --name=swarmlabwg-${res.bootstrapstackid} \
--cap-add=NET_ADMIN \ --cap-add=NET_ADMIN \
--cap-add=SYS_MODULE \ --cap-add=SYS_MODULE \
-e PUID=1000 \ -e PUID=1000 \
-e PGID=1000 \ -e PGID=1000 \
-e TZ=Europe/Athens \ -e TZ=Europe/Athens \
-p 51820:51820/udp \ -v ${mypath}/hybrid/connect/${res.bootstrapstackid}:/settingsclient \
-v ${mypath}/hybrid/connect:/settingsclient \
-v /lib/modules:/lib/modules \ -v /lib/modules:/lib/modules \
--restart unless-stopped \ --restart unless-stopped \
hub.swarmlab.io:5480/venus-alpine:latest hub.swarmlab.io:5480/venus-alpine:latest
` `
//-p 51820:51820/udp \
//docker exec -it swarmlabwg /bin/bash -c "pm2-runtime start /app/swarmlab-venus/client_ecosystem.config.js" //docker exec -it swarmlabwg /bin/bash -c "pm2-runtime start /app/swarmlab-venus/client_ecosystem.config.js"
//hub.swarmlab.io:5480/venusclient:latest //hub.swarmlab.io:5480/venusclient:latest
fs.writeFileSync('./hybrid/connect/swarmlabwg', myExec); fs.writeFileSync(`./hybrid/connect/${res.bootstrapstackid}/swarmlabwg`, myExec);
fs.writeFileSync('./hybrid/connect/swarmlabstatus', 'wgstatusclient=off'); fs.writeFileSync(`./hybrid/connect/${res.bootstrapstackid}/swarmlabstatus`, 'wgstatusclient=off');
const myExec1 = ` const myExec1 = `
docker exec -it swarmlabwg /bin/bash -c "ip link set swarmlab0 down; ip link del swarmlab0" docker exec -it swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}"
sleep 1 sleep 1
docker stop swarmlabwg; docker container rm swarmlabwg docker stop swarmlabwg-${res.bootstrapstackid}; docker container rm swarmlabwg-${res.bootstrapstackid}
sleep 1 sleep 1
` `
fs.writeFileSync('./hybrid/connect/swarmlabwgdown', myExec1); fs.writeFileSync(`./hybrid/connect/${res.bootstrapstackid}/swarmlabwgdown`, myExec1);
return 'ok' return 'ok'
@ -223,12 +284,14 @@ app.post('/hybrid_join_start', (req, res, next) => {
RES.publickey = req.body["publickey"] RES.publickey = req.body["publickey"]
RES.endpoint = req.body["endpointport"] RES.endpoint = req.body["endpointport"]
RES.serverip = req.body["serverip"] RES.serverip = req.body["serverip"]
RES.bootstrapstackid = req.body["bootstrapstackid"]
RES.netmask = req.body["netmask"] RES.netmask = req.body["netmask"]
RES.privatekey = req.body["privatekey"] RES.privatekey = req.body["privatekey"]
RES.allowedips = req.body["allowedips"] RES.allowedips = req.body["allowedips"]
RES.interfaceip = req.body["peer_ip"] RES.interfaceip = req.body["peer_ip"]
RES.endpointfpath = `${RES.serverip}:${RES.endpoint}` RES.endpointfpath = `${RES.serverip}:${RES.endpoint}`
RES.dev_name = 'swarmlab0' RES.dev_name = `swlab${RES.bootstrapstackid.slice(0, 10)}`
console.log(RES.dev_name)
RES.INTERFACE_IP = `${RES.interfaceip}/${RES.netmask}` RES.INTERFACE_IP = `${RES.interfaceip}/${RES.netmask}`
RES.INTERFACE_IProute = `${RES.interfaceip}` RES.INTERFACE_IProute = `${RES.interfaceip}`
@ -236,9 +299,11 @@ app.post('/hybrid_join_start', (req, res, next) => {
// ***************************************** // *****************************************
// *** save wg config file wg0.conf // *** save wg config file wg0.conf
// ***************************************** // *****************************************
RES.serverconf = wg_save_clientconf(RES) (async() => {
RES.serverrun = wg_save_ifup_linux(RES) RES.serverconf = await wg_save_clientconf(RES)
RES.serverconnect = wg_save_connect_linux(RES) RES.serverrun = await wg_save_ifup_linux(RES)
RES.serverconnect = await wg_save_connect_linux(RES)
})()
// ***************************************** // *****************************************
// *** save wg ifup linux // *** save wg ifup linux
// ***************************************** // *****************************************
@ -263,13 +328,14 @@ app.post('/hybrid_join_connect', (req, res, next) => {
var RES = new Object(); var RES = new Object();
RES.action = req.body["action"] RES.action = req.body["action"]
RES.bootstrapstackid = req.body["bootstrapstackid"]
try { try {
if(RES.action == "connect"){ if(RES.action == "connect"){
fs.writeFileSync('./hybrid/connect/swarmlabstatus', 'wgstatusclient=on'); fs.writeFileSync(`./hybrid/connect/${RES.bootstrapstackid}/swarmlabstatus`, 'wgstatusclient=on');
var showexecrm = `/bin/sh ./hybrid/connect/swarmlabwg` var showexecrm = `/bin/sh ./hybrid/connect/${RES.bootstrapstackid}/swarmlabwg`
execSync(showexecrm); execSync(showexecrm);
var showexec = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s ` var showexec = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s `
@ -284,7 +350,7 @@ app.post('/hybrid_join_connect', (req, res, next) => {
var datajson = JSON.parse(string); var datajson = JSON.parse(string);
var results = [] var results = []
var filter = "swarmlabwg" var filter = `swarmlabwg-${RES.bootstrapstackid}`
var grep = new RegExp(filter); var grep = new RegExp(filter);
var datalenth = datajson.length var datalenth = datajson.length
for (var i=0 ; i < datalenth ; i++) for (var i=0 ; i < datalenth ; i++)
@ -313,9 +379,9 @@ app.post('/hybrid_join_connect', (req, res, next) => {
} }
}); });
}else if( RES.action == "disconnect" ){ }else if( RES.action == "disconnect" ){
fs.writeFileSync('./hybrid/connect/swarmlabstatus', 'wgstatusclient=off'); fs.writeFileSync(`./hybrid/connect/${RES.bootstrapstackid}/swarmlabstatus`, 'wgstatusclient=off');
var showexecrm1 = `/bin/sh ./hybrid/connect/swarmlabwgdown` var showexecrm1 = `/bin/sh ./hybrid/connect/${RES.bootstrapstackid}/swarmlabwgdown`
execSync(showexecrm1); execSync(showexecrm1);
var showexec = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s ` var showexec = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s `
@ -330,7 +396,7 @@ app.post('/hybrid_join_connect', (req, res, next) => {
var datajson = JSON.parse(string); var datajson = JSON.parse(string);
var results = [] var results = []
var filter = "swarmlabwg" var filter = `swarmlabwg-${RES.bootstrapstackid}`
var grep = new RegExp(filter); var grep = new RegExp(filter);
var datalenth = datajson.length var datalenth = datajson.length
for (var i=0 ; i < datalenth ; i++) for (var i=0 ; i < datalenth ; i++)
@ -387,6 +453,7 @@ app.get('/getserviceshybridstatus', (req, res, next) => {
if (stdout) { if (stdout) {
var string = stdout.toString() var string = stdout.toString()
var datajson = JSON.parse(string); var datajson = JSON.parse(string);
/*
var search = RES.bootstrapstackname var search = RES.bootstrapstackname
var extenderror = new RegExp(search); var extenderror = new RegExp(search);
var found = 'no'; var found = 'no';
@ -397,6 +464,7 @@ app.get('/getserviceshybridstatus', (req, res, next) => {
found = 'yes'; found = 'yes';
} }
} }
*/
RES.error = false RES.error = false
RES.error_msg = "ok" RES.error_msg = "ok"
RES.test = datajson; RES.test = datajson;

Loading…
Cancel
Save