zeus
4 years ago
43 changed files with 2259 additions and 643 deletions
@ -1,2 +1,5 @@ |
|||
# swarmlab-hybrid |
|||
|
|||
jq |
|||
sudo apt install wireguard |
|||
|
|||
|
@ -0,0 +1,9 @@ |
|||
|
|||
|
|||
wg genkey | tee ./privatekey | wg pubkey > ./publickey |
|||
|
|||
privatekey=$(head -1 ./privatekey) |
|||
publickey=$(head -1 ./publickey) |
|||
|
|||
jq --arg key0 'private' --arg private $privatekey --arg key1 'public' --arg public $publickey '. | .[$key0]=$private | .[$key1]=$public ' <<<'{}' > ./keys.json |
|||
|
@ -0,0 +1,4 @@ |
|||
{ |
|||
"private": "EDcHFoG5cE/110wPaYgVjNdtHkULRMDE9vECia/4I3g=", |
|||
"public": "hQ4VKJePvguRkcGOOaT7fcKNE2HyYGqBoacByNNd7Xo=" |
|||
} |
@ -1 +1 @@ |
|||
6CdrILpdZcm1OfOecSQSgaI90sLNOTVW9zO9Dac5b0w= |
|||
kCoimlkUSkb4MaEVoI4ePThzKDYNZF9A/4d0L1u3q38= |
|||
|
@ -1 +1 @@ |
|||
fEirlFuleXLeY2pgsCVb8G16DEVXJVGJuXdifX1+/wY= |
|||
R97cS/PXC5N1dxom0pODyNhqnXfyIUqg04Fu1OU0fGs= |
|||
|
@ -0,0 +1,44 @@ |
|||
|
|||
function swarmlab_ifup() { |
|||
swarmlab=$(/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/status.sh wg0 | jq .swarmlab) |
|||
tempswarm="${swarmlab%\"}" |
|||
tempswarm="${tempswarm#\"}" |
|||
swarmlab=$tempswarm |
|||
echo $swarmlab |
|||
} |
|||
function hybrid_ifup() { |
|||
hybrid=$(/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/status.sh wg0 | jq .hybrid) |
|||
tempswarm1="${hybrid%\"}" |
|||
tempswarm1="${tempswarm1#\"}" |
|||
hybrid=$tempswarm1 |
|||
echo $hybrid |
|||
} |
|||
|
|||
hybrid=$(hybrid_ifup) |
|||
if [ $hybrid == 'NotOnline' ]; then |
|||
/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/swarmlab-connect.sh |
|||
sleep 2 |
|||
hybrid1=$(hybrid_ifup) |
|||
if [ $hybrid1 == 'NotOnline' ]; then |
|||
echo "Failed to start wg0 network interface" |
|||
else |
|||
echo "Swarmlab hybrid $hybrid" |
|||
fi |
|||
else |
|||
echo "Swarmlab hybrid $hybrid" |
|||
fi |
|||
|
|||
swarmlab=$(swarmlab_ifup) |
|||
if [ $swarmlab != 'active' ]; then |
|||
sleep 1 |
|||
swarmlab1=$(swarmlab_ifup) |
|||
if [ $swarmlab1 != 'active' ]; then |
|||
echo "Failed to connect on swarmlab master" |
|||
echo "Exec " |
|||
echo "/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/reload-swarmlab.sh" |
|||
echo "Please try again" |
|||
fi |
|||
else |
|||
echo "Swarmlab master $swarmlab" |
|||
fi |
|||
|
@ -0,0 +1,43 @@ |
|||
|
|||
function swarmlab_ifup() { |
|||
swarmlab=$(/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/status.sh wg0 | jq .swarmlab) |
|||
tempswarm="${swarmlab%\"}" |
|||
tempswarm="${tempswarm#\"}" |
|||
swarmlab=$tempswarm |
|||
echo $swarmlab |
|||
} |
|||
function hybrid_ifup() { |
|||
hybrid=$(/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/status.sh wg0 | jq .hybrid) |
|||
tempswarm1="${hybrid%\"}" |
|||
tempswarm1="${tempswarm1#\"}" |
|||
hybrid=$tempswarm1 |
|||
echo $hybrid |
|||
} |
|||
|
|||
hybrid=$(hybrid_ifup) |
|||
if [ $hybrid == 'NotOnline' ]; then |
|||
/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/swarmlab-connect.sh |
|||
sleep 2 |
|||
hybrid1=$(hybrid_ifup) |
|||
if [ $hybrid1 == 'NotOnline' ]; then |
|||
echo "Failed to start wg0 network interface" |
|||
else |
|||
echo "Swarmlab hybrid $hybrid" |
|||
fi |
|||
else |
|||
echo "Swarmlab hybrid $hybrid" |
|||
fi |
|||
|
|||
swarmlab=$(swarmlab_ifup) |
|||
if [ $swarmlab != 'active' ]; then |
|||
sleep 1 |
|||
swarmlab1=$(swarmlab_ifup) |
|||
if [ $swarmlab1 != 'active' ]; then |
|||
echo "Failed to connect on swarmlab master" |
|||
echo "Exec " |
|||
echo "/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/reload-swarmlab.sh" |
|||
echo "Please try again" |
|||
fi |
|||
else |
|||
echo "Swarmlab master $swarmlab" |
|||
fi |
@ -0,0 +1,23 @@ |
|||
function hybrid_ifup() { |
|||
hybrid=$(/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/status.sh wg0 | jq .hybrid) |
|||
tempswarm1="${hybrid%\"}" |
|||
tempswarm1="${tempswarm1#\"}" |
|||
hybrid=$tempswarm1 |
|||
echo $hybrid |
|||
} |
|||
|
|||
hybrid=$(hybrid_ifup) |
|||
if [ $hybrid == 'NotOnline' ]; then |
|||
echo "Swarmlab hybrid $hybrid" |
|||
else |
|||
ip link set wg0 down |
|||
ip link del wg0 |
|||
sleep 3 |
|||
hybrid1=$(hybrid_ifup) |
|||
if [ $hybrid1 == 'NotOnline' ]; then |
|||
echo "Swarmlab hybrid $hybrid" |
|||
else |
|||
echo "Swarmlab hybrid $hybrid" |
|||
fi |
|||
fi |
|||
|
@ -0,0 +1,23 @@ |
|||
|
|||
function hybrid_ifup() { |
|||
hybrid=$(/bin/bash /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/status.sh wg0 | jq .hybrid) |
|||
tempswarm1="${hybrid%\"}" |
|||
tempswarm1="${tempswarm1#\"}" |
|||
hybrid=$tempswarm1 |
|||
echo $hybrid |
|||
} |
|||
|
|||
hybrid=$(hybrid_ifup) |
|||
if [ $hybrid == 'NotOnline' ]; then |
|||
echo "Swarmlab hybrid $hybrid" |
|||
else |
|||
ip link set wg0 down |
|||
ip link del wg0 |
|||
sleep 3 |
|||
hybrid1=$(hybrid_ifup) |
|||
if [ $hybrid1 == 'NotOnline' ]; then |
|||
echo "Swarmlab hybrid $hybrid" |
|||
else |
|||
echo "Swarmlab hybrid $hybrid" |
|||
fi |
|||
fi |
@ -0,0 +1 @@ |
|||
uHuqIEOoQTsESNhiz7Uu1COJlbIHdruBiMUG1GvBTHM= |
@ -0,0 +1 @@ |
|||
ol5eKuHsOOAY9mWpVnsVTG+EODv8Hcl8bMobkNx4Si8= |
@ -0,0 +1,16 @@ |
|||
|
|||
function ifup { |
|||
if [[ ! -d /sys/class/net/${1} ]]; then |
|||
#printf 'No such interface: %s\n' "$1" >&2 |
|||
return 1 |
|||
else |
|||
[[ $(</sys/class/net/${1}/operstate) == up ]] |
|||
fi |
|||
} |
|||
|
|||
if ifup $1; then |
|||
echo Online |
|||
else |
|||
echo 'Not online' |
|||
fi |
|||
|
@ -0,0 +1,37 @@ |
|||
|
|||
|
|||
function ifup { |
|||
if [[ ! -d /sys/class/net/${1} ]]; then |
|||
return 1 |
|||
else |
|||
[[ $(</sys/class/net/${1}/carrier) == 1 ]] |
|||
fi |
|||
} |
|||
|
|||
if ifup $1; then |
|||
hybridswarm='Online' |
|||
else |
|||
hybridswarm='NotOnline' |
|||
fi |
|||
|
|||
|
|||
dockerswarm=$(docker info --format "{{json .}}" | jq .Swarm.LocalNodeState) |
|||
tempswarm="${dockerswarm%\"}" |
|||
tempswarm="${tempswarm#\"}" |
|||
dockerswarm=$tempswarm |
|||
|
|||
dockerswarmid=$(docker info --format "{{json .}}" | jq .Swarm.NodeID) |
|||
tempswarm1="${dockerswarmid%\"}" |
|||
tempswarm1="${tempswarm1#\"}" |
|||
swarmlabid=$tempswarm1 |
|||
#echo $dockerswarm |
|||
#echo $hybridswarm |
|||
#echo $swarmlabid |
|||
|
|||
#jq --arg key0 'swarmlab' --arg swarmlab $dockerswarm --arg key1 'hybrid' --arg hybrid $hybridswarm --arg key2 'swarmlabid' --arg swarmlabid $swarmlabid'. | .[$key0]=$swarmlab | .[$key1]=$hybrid | .[$key2]=$swarmlabid' <<<'{}' |
|||
jq \ |
|||
--arg key0 'swarmlab' --arg swarmlab $dockerswarm \ |
|||
--arg key1 'hybrid' --arg hybrid $hybridswarm \ |
|||
--arg key2 'swarmlabid' --arg swarmlabid $swarmlabid \ |
|||
'. | .[$key0]=$swarmlab | .[$key1]=$hybrid | .[$key2]=$swarmlabid' <<<'{}' |
|||
|
@ -0,0 +1,33 @@ |
|||
|
|||
DEV_NAME=wg0 |
|||
INTERFACE_IP=10.13.13.2/16 |
|||
INTERFACE_IProute=10.13.13.2 |
|||
ENDPOINT_IP=83.212.77.133 |
|||
|
|||
ip link set $DEV_NAME down |
|||
ip link del $DEV_NAME |
|||
# add wireguard interface |
|||
ip link add $DEV_NAME type wireguard |
|||
|
|||
# set wireguard conf |
|||
wg setconf $DEV_NAME /data/appl/ok/swarmlab-hybrid-agent/src-local/hybrid/connect/$DEV_NAME.conf |
|||
|
|||
# assign ip to wireguard interface |
|||
ip addr add $INTERFACE_IP dev $DEV_NAME |
|||
|
|||
# set sysctl |
|||
sysctl -w net.ipv4.conf.all.rp_filter=2 |
|||
|
|||
# set mtu for wireguard interface |
|||
ip link set mtu 1420 up dev $DEV_NAME |
|||
|
|||
# bring wireguard interface up |
|||
ip link set up dev $DEV_NAME |
|||
|
|||
# add route |
|||
ip route add default via $INTERFACE_IProute metric 2 table 200 |
|||
ip route show table 200 | grep -w $INTERFACE_IProute |
|||
|
|||
# add local lan route |
|||
ip rule add table main suppress_prefixlength 0 |
|||
ip rule show | grep -w "suppress_prefixlength" |
@ -0,0 +1,38 @@ |
|||
|
|||
DEV_NAME=wg0 |
|||
#INTERFACE_IP=10.13.13.2/24 |
|||
INTERFACE_IP=10.13.13.2/16 |
|||
INTERFACE_IProute=10.13.13.2 |
|||
ENDPOINT_IP=`grep Endpoint /etc/wireguard/$DEV_NAME.conf | awk '{print $3}' | cut -d: -f1` |
|||
|
|||
echo "ip $INTERFACE_IP" |
|||
|
|||
ip link set $DEV_NAME down |
|||
ip link del $DEV_NAME |
|||
# add wireguard interface |
|||
ip link add $DEV_NAME type wireguard |
|||
|
|||
# set wireguard conf |
|||
wg setconf $DEV_NAME /etc/wireguard/$DEV_NAME.conf |
|||
|
|||
|
|||
# assign ip to wireguard interface |
|||
ip addr add $INTERFACE_IP dev $DEV_NAME |
|||
|
|||
# set sysctl |
|||
sysctl -w net.ipv4.conf.all.rp_filter=2 |
|||
|
|||
# set mtu for wireguard interface |
|||
ip link set mtu 1420 up dev $DEV_NAME |
|||
|
|||
# bring wireguard interface up |
|||
ip link set up dev $DEV_NAME |
|||
|
|||
# add route |
|||
ip route add default via $INTERFACE_IProute metric 2 table 200 |
|||
ip route show table 200 | grep -w $INTERFACE_IProute |
|||
|
|||
# add local lan route |
|||
ip rule add table main suppress_prefixlength 0 |
|||
ip rule show | grep -w "suppress_prefixlength" |
|||
|
@ -0,0 +1,2 @@ |
|||
|
|||
docker swarm join --token SWMTKN-1-3099nls9my5ns1s0mnmwkx41mhpawl80hwjjbskbll7nghqhgn-asu68y4lhd1qlbpxr6oosk6wl 10.13.13.1:2377 |
@ -0,0 +1,10 @@ |
|||
[Interface] |
|||
PrivateKey = kJd3ga9/1b5NalONMP+CuezTZB+ZmaQVdzM7jLYUe30= |
|||
ListenPort = 51820 |
|||
|
|||
[Peer] |
|||
PublicKey = WAuzcpIf1obckeLP94owls31j58LP2k+yIAasx9VFU8= |
|||
Endpoint = 83.212.77.133:51820 |
|||
AllowedIPs = 10.13.13.0/16, 0.0.0.0/0, ::/0 |
|||
PersistentKeepalive = 30 |
|||
|
@ -0,0 +1,11 @@ |
|||
[Interface] |
|||
PrivateKey = CCJXNalGbNIDK5oz5IG8lGuQFATfEcSILw7tWqNO9U4 |
|||
ListenPort = 51820 |
|||
|
|||
[Peer] |
|||
#PublicKey = WAuzcpIf1obckeLP94owls31j58LP2k+yIAasx9VFU8= |
|||
PublicKey = yMTjzSFQloNH22v+sN9k4cIaOUujq/m+vB2HJdJM7GI= |
|||
Endpoint = 83.212.77.133:51820 |
|||
AllowedIPs = 10.13.13.0/24, 0.0.0.0/0, ::/0 |
|||
PersistentKeepalive = 30 |
|||
|
@ -0,0 +1,10 @@ |
|||
[Interface] |
|||
PrivateKey = kJd3ga9/1b5NalONMP+CuezTZB+ZmaQVdzM7jLYUe30= |
|||
ListenPort = 51820 |
|||
|
|||
[Peer] |
|||
PublicKey = WAuzcpIf1obckeLP94owls31j58LP2k+yIAasx9VFU8= |
|||
Endpoint = 83.212.77.133:51820 |
|||
AllowedIPs = 10.13.13.0/16, 0.0.0.0/0, ::/0 |
|||
PersistentKeepalive = 30 |
|||
|
@ -0,0 +1,9 @@ |
|||
|
|||
|
|||
wg genkey | tee ./privatekey | wg pubkey > ./publickey |
|||
|
|||
privatekey=$(head -1 ./privatekey) |
|||
publickey=$(head -1 ./publickey) |
|||
|
|||
jq --arg key0 'private' --arg private $privatekey --arg key1 'public' --arg public $publickey '. | .[$key0]=$private | .[$key1]=$public ' <<<'{}' | tee ./keys.json |
|||
|
@ -0,0 +1,2 @@ |
|||
docker swarm join --token SWMTKN-1-3099nls9my5ns1s0mnmwkx41mhpawl80hwjjbskbll7nghqhgn-asu68y4lhd1qlbpxr6oosk6wl 10.13.13.1:2377 |
|||
|
@ -0,0 +1 @@ |
|||
"{\"status\":\"off\",\"privatekey\":\"kJd3ga9/1b5NalONMP+CuezTZB+ZmaQVdzM7jLYUe30=\",\"publickey\":\"jf4fC0tmGe4Ioz+dY5c/AksqicZGGqJIH1OncOUIuj8=\",\"server_ip\":\"83.212.77.133:51820\",\"workerkey\":\"SWMTKN-1-3099nls9my5ns1s0mnmwkx41mhpawl80hwjjbskbll7nghqhgn-asu68y4lhd1qlbpxr6oosk6wl\",\"allowed_ips\":\"10.13.13.0/16, 0.0.0.0/0, ::/0\",\"swarmlab_public_wgkey\":\"WAuzcpIf1obckeLP94owls31j58LP2k+yIAasx9VFU8=\",\"wg_ip\":\"10.13.13.2\",\"swarm_ip\":\"10.13.13.1:2377\",\"wg_port\":\"51820\"}" |
@ -0,0 +1 @@ |
|||
EEQqA/IEqbKRHuo8Har5JsjatOYY++JMmiU/QEr4zlw= |
@ -0,0 +1 @@ |
|||
iAn+EwqtojVrIV58N5jpnjlHeqCYhGKS8gHpaHuieBA= |
@ -0,0 +1,29 @@ |
|||
#!/bin/sh |
|||
|
|||
if [ $# -lt 3 ]; then |
|||
echo "This script will create a veth pair, attach one end to an OVS bridge," |
|||
echo "and another end to the specified container as a virtual NIC." |
|||
echo "" |
|||
echo "Usage: $0 <CONTAINER> <VETH> <PEER> <OVS BRIDGE>" |
|||
echo "Example: $0 test-container-1 veth-1 peer-1 br-int" |
|||
exit 1 |
|||
fi |
|||
|
|||
CONTAINER=$1 |
|||
VETH=$2 |
|||
PEER=$3 |
|||
OVS_BR=$4 |
|||
NETNS=`sudo docker inspect -f '{{.State.Pid}}' $CONTAINER` |
|||
|
|||
echo "add veth pair[$VETH <--> $PEER] to container[$CONTAINER] in netns[$NETNS]" |
|||
ip link delete $VETH || true |
|||
ip link add $VETH type veth peer name $PEER |
|||
|
|||
echo "add port to ovs bridge $OVS_BR" |
|||
ovs-vsctl add-port $OVS_BR $VETH |
|||
|
|||
echo "move $PEER to netns $NETNS" |
|||
ip link set $PEER netns $NETNS |
|||
ip netns exec $NETNS ip link set dev $PEER up |
|||
|
|||
echo "done" |
@ -0,0 +1,26 @@ |
|||
#!/bin/sh |
|||
|
|||
if [ $# -lt 3 ]; then |
|||
echo "This script will add an OVS internal port to an OVS bridge," |
|||
echo "then assign the port to the specified container as a virtual NIC." |
|||
echo "" |
|||
echo "Usage: $0 <CONTAINER> <NIC NAME> <OVS BRIDGE>" |
|||
echo "Example: $0 test-container-1 vnic-1 br-int" |
|||
exit 1 |
|||
fi |
|||
|
|||
CONTAINER=$1 |
|||
PORT=$2 |
|||
OVS_BR=$3 |
|||
NETNS=`sudo docker inspect -f '{{.State.Pid}}' $CONTAINER` |
|||
echo "add port[$PORT] to container[$CONTAINER] in netns[$NETNS]" |
|||
|
|||
echo "add port to ovs bridge $OVS_BR" |
|||
ovs-vsctl add-port $OVS_BR $PORT -- set Interface $PORT type=internal |
|||
#ovs-vsctl add-port br-int vnic-1 -- set Interface vnic-1 type=internal |
|||
|
|||
echo "move $PORT to netns $NETNS" |
|||
ip link set $PORT netns $NETNS |
|||
ip netns exec $NETNS ip link set dev $PORT up |
|||
|
|||
echo "done" |
@ -0,0 +1,24 @@ |
|||
#!/bin/bash |
|||
|
|||
if [ $# -ne 1 ]; then |
|||
echo "Usage: $0 <container id or name>" |
|||
exit 1 |
|||
fi |
|||
|
|||
echo "expose container $1 netns" |
|||
NETNS=`sudo docker inspect -f '{{.State.Pid}}' $1` |
|||
|
|||
if [ ! -d /var/run/netns ]; then |
|||
mkdir /var/run/netns |
|||
fi |
|||
if [ -f /var/run/netns/$NETNS ]; then |
|||
rm -rf /var/run/netns/$NETNS |
|||
fi |
|||
|
|||
ln -s /proc/$NETNS/ns/net /var/run/netns/$NETNS |
|||
echo "done. netns: $NETNS" |
|||
|
|||
echo "=============================" |
|||
echo "current network namespaces: " |
|||
echo "=============================" |
|||
ip netns |
@ -1,48 +0,0 @@ |
|||
var path = require('path'); |
|||
var app = require('express')(); |
|||
var http = require('http').Server(app); |
|||
var io = require('socket.io')(http); |
|||
|
|||
const socketAuth = require('socketio-auth'); |
|||
|
|||
socketoptions = { |
|||
secure:true, |
|||
reconnect: true, |
|||
rejectUnauthorized : false |
|||
}; |
|||
|
|||
|
|||
// Client
|
|||
var io2 = require('socket.io-client'); |
|||
var socket = io2.connect('https://83.212.78.17:3088', socketoptions); |
|||
|
|||
socket.on('connection', s => { |
|||
console.error('socket2 connection'); |
|||
var id = s.id |
|||
|
|||
|
|||
var roomiot = 'iot' |
|||
socket.emit('iot', roomiot); |
|||
|
|||
socket.emit('subscribe', roomiot); |
|||
|
|||
socket.emit('pingServerEmit', roomiot); |
|||
|
|||
|
|||
s.on('message', function (data) { |
|||
console.log('from room1 '+data); |
|||
}); |
|||
s.on('iot', function (data) { |
|||
console.log('from room1 '+data); |
|||
}); |
|||
}); |
|||
|
|||
var roomiot = 'iot' |
|||
socket.emit('action', roomiot); |
|||
|
|||
socket.on('message', function (data) { |
|||
console.log('from room '+data); |
|||
}); |
|||
|
|||
|
|||
|
@ -1,32 +0,0 @@ |
|||
options = { |
|||
secure:true, |
|||
reconnect: true, |
|||
rejectUnauthorized : false |
|||
}; |
|||
|
|||
// Client
|
|||
var io2 = require('socket.io-client'); |
|||
var socket = io2.connect('http://localhost:8084', options); |
|||
//var socket = io2.connect('https://service.swarmlab.io:55583');
|
|||
|
|||
var msg2 = "hello"; |
|||
socket.emit('pingServer', msg2); |
|||
|
|||
|
|||
|
|||
//var socket = require('socket.io-client')('httpis://localhost:8099');
|
|||
socket.on('connect', function(){ |
|||
console.error('connect ...'); |
|||
//socket.emit("adhoc", 'Hallo World!')
|
|||
}); |
|||
socket.on('customEmit', function(data){ |
|||
console.error('customEmit '+data); |
|||
//socket.emit("adhoc", 'Hallo World!')
|
|||
|
|||
}); |
|||
socket.on('disconnect', function(){ |
|||
console.error('disconnect'); |
|||
|
|||
}); |
|||
//socket.emit("adhoc", 'Hallo World!')
|
|||
|
@ -1,40 +0,0 @@ |
|||
|
|||
var fs = require( 'fs' ); |
|||
var app = require('express')(); |
|||
var https = require('https'); |
|||
var server = https.createServer({ |
|||
key: fs.readFileSync('./llo/swarmlab.key'), |
|||
cert: fs.readFileSync('./llo/swarmlab.crt'), |
|||
//ca: fs.readFileSync('./test_ca.crt'),
|
|||
requestCert: false, |
|||
rejectUnauthorized: false |
|||
},app); |
|||
|
|||
|
|||
server.listen(3000, () => console.error('listening on https://localhost:3000/')); |
|||
var io = require('socket.io').listen(server); |
|||
console.error('socket.io example'); |
|||
|
|||
|
|||
|
|||
io.on('connection', s => { |
|||
if( typeof s !== "undefined" ){ |
|||
console.error('socket connection'); |
|||
} |
|||
|
|||
s.on('actionstart', obj => { |
|||
console.error('fromclient '+obj); |
|||
socket.emit("log", obj) |
|||
}); |
|||
/* |
|||
s.on('s1', function(room) { |
|||
console.log('leaving room', room); |
|||
}) |
|||
*/ |
|||
s.on('s1', () => { |
|||
console.log('hi from server'); |
|||
}); // listen to the event
|
|||
|
|||
|
|||
}); |
|||
|
@ -1,381 +0,0 @@ |
|||
"use strict" |
|||
|
|||
var pathmodule = require('path'); |
|||
var app = require('express')(); |
|||
var http = require('http').Server(app); |
|||
var https = require('https'); |
|||
var CONFIG = require( pathmodule.resolve( __dirname, "runconfig.js" ) ); |
|||
const io = require("socket.io")(http, { |
|||
// pingTimeout: 30000,
|
|||
// allowUpgrades: false,
|
|||
// serveClient: false,
|
|||
// pingInterval: 10000,
|
|||
// //transports: [ 'websocket', 'polling' ],
|
|||
// transports: [ 'polling', 'websocket' ],
|
|||
cors: { |
|||
origin: "http://localhost:8080", |
|||
methods: ["GET", "POST"], |
|||
allowedHeaders: ["my-custom-header"], |
|||
credentials: true |
|||
}, |
|||
cookie: { |
|||
name: "test", |
|||
httpOnly: false, |
|||
path: "/custom" |
|||
} |
|||
}); |
|||
|
|||
const { DateTime } = require("luxon"); |
|||
|
|||
|
|||
var async = require("async"); |
|||
const { check, validationResult } = require('express-validator'); |
|||
const urlExistSync = require("url-exist-sync"); |
|||
|
|||
var express = require('express'); |
|||
app.use(express.json()); |
|||
|
|||
const axios = require('axios'); |
|||
axios.defaults.timeout = 30000 |
|||
|
|||
const helmet = require('helmet'); |
|||
app.use(helmet()); |
|||
|
|||
const cors = require('cors') |
|||
const whitelist = [ |
|||
'http://localhost:8080', |
|||
'http://localhost:3080', |
|||
'http://localhost:3081', |
|||
'http://localhost:3082' |
|||
] |
|||
const corsOptions = { |
|||
credentials: true, |
|||
methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'], |
|||
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
|
|||
allowedHeaders: [ |
|||
'Content-Type', |
|||
'Authorization', |
|||
'X-Requested-With', |
|||
'device-remember-token', |
|||
'Access-Control-Allow-Origin', |
|||
'Access-Control-Allow-Headers', |
|||
'Origin', |
|||
'Accept' |
|||
], |
|||
origin: function(origin, callback) { |
|||
if (whitelist.indexOf(origin) !== -1) { |
|||
callback(null, true) |
|||
} else { |
|||
callback(null, true) |
|||
//callback(new Error('Not allowed by CORS'))
|
|||
} |
|||
} |
|||
} |
|||
app.use(cors) |
|||
|
|||
|
|||
|
|||
// ***************************************************
|
|||
// checktoken
|
|||
// ***************************************************
|
|||
|
|||
async function checkToken(token) { |
|||
const agent = new https.Agent({ |
|||
rejectUnauthorized: false, |
|||
}); |
|||
const instance = axios.create({ |
|||
baseURL: 'https://api.swarmlab.io', |
|||
withCredentials: true, |
|||
rejectUnauthorized: false, |
|||
crossdomain: true, |
|||
httpsAgent: agent, |
|||
headers: { |
|||
'Accept': 'application/json', |
|||
'Content-Type': 'multipart/form-data', |
|||
'Authorization': 'Bearer '+token |
|||
} |
|||
}) |
|||
try { |
|||
var pipelines = { |
|||
"source":'ssologin' |
|||
} |
|||
var params = { |
|||
pipeline: pipelines |
|||
} |
|||
|
|||
var options = { |
|||
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, |
|||
}; |
|||
|
|||
instance.defaults.timeout = 30000; |
|||
const res = await instance.post('/istokenvalidsso',params,options); |
|||
if(res.status == 200){ |
|||
//console.log("check " +JSON.stringify(res.data))
|
|||
return res.data |
|||
}else{ |
|||
console.log("noerror: " + res) |
|||
return res.status |
|||
|
|||
} |
|||
} |
|||
catch (err) { |
|||
console.error("error: "+err); |
|||
var error = new Object(); |
|||
error.action = '401' |
|||
return error |
|||
} |
|||
} |
|||
|
|||
|
|||
function convertDateToUTC(date) { |
|||
return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(),date.getUTCMilliseconds()); |
|||
} |
|||
|
|||
// ***************************************************
|
|||
// get pipelines
|
|||
// ***************************************************
|
|||
|
|||
async function getpipelines(token,pipelinename) { |
|||
const agent = new https.Agent({ |
|||
rejectUnauthorized: false, |
|||
}); |
|||
const instance = axios.create({ |
|||
baseURL: 'https://api.swarmlab.io', |
|||
withCredentials: true, |
|||
rejectUnauthorized: false, |
|||
crossdomain: true, |
|||
httpsAgent: agent, |
|||
headers: { |
|||
'Accept': 'application/json', |
|||
'Content-Type': 'multipart/form-data', |
|||
'Authorization': 'Bearer '+token |
|||
} |
|||
}) |
|||
/* |
|||
var params = { |
|||
playbook: value |
|||
} |
|||
var options = { |
|||
params: params, |
|||
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, |
|||
}; |
|||
|
|||
const playbook = await api.GET('playbookCode',options); |
|||
return playbook |
|||
*/ |
|||
try { |
|||
|
|||
var pipelines = { |
|||
"querytokenFilter":CONFIG.api.token, |
|||
"filter":pipelinename |
|||
} |
|||
//var params = {
|
|||
// pipeline: pipelines
|
|||
// }
|
|||
var params = { |
|||
querytokenFilter:CONFIG.api.token, |
|||
filter:pipelinename |
|||
} |
|||
|
|||
var options = { |
|||
params: params, |
|||
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, |
|||
}; |
|||
|
|||
//https://api.swarmlab.io/gettutorlabrooms?sort=pipelinename%7Casc&page=1&per_page=5&filter=&type=scripts&tutor=yes
|
|||
instance.defaults.timeout = 30000; |
|||
//const res = await instance.get('/getplaygrounds',params,options);
|
|||
const res = await instance.get('/getplaygrounds',options); |
|||
if(res.status == 200){ |
|||
return res.data |
|||
}else{ |
|||
console.log("noerror: " + res) |
|||
return await res.status |
|||
|
|||
} |
|||
} |
|||
catch (err) { |
|||
console.error("error: "+err); |
|||
var error = new Object(); |
|||
error.action = '401' |
|||
return await error |
|||
} |
|||
} |
|||
|
|||
// ***************************************************
|
|||
// get user pipelines
|
|||
// ***************************************************
|
|||
|
|||
async function getuserpipelines(token,user,swarmlabname) { |
|||
var pipelinename = user |
|||
const agent = new https.Agent({ |
|||
rejectUnauthorized: false, |
|||
}); |
|||
const instance = axios.create({ |
|||
baseURL: 'https://api.swarmlab.io', |
|||
withCredentials: true, |
|||
rejectUnauthorized: false, |
|||
crossdomain: true, |
|||
httpsAgent: agent, |
|||
headers: { |
|||
'Accept': 'application/json', |
|||
'Content-Type': 'multipart/form-data', |
|||
'Authorization': 'Bearer '+token |
|||
} |
|||
}) |
|||
try { |
|||
|
|||
var pipelines = { |
|||
"querytokenFilter":CONFIG.api.token, |
|||
"filter":pipelinename, |
|||
swarmlabname:swarmlabname |
|||
} |
|||
//var params = {
|
|||
// pipeline: pipelines
|
|||
// }
|
|||
var params = { |
|||
querytokenFilter:CONFIG.api.token, |
|||
filter:pipelinename, |
|||
swarmlabname:swarmlabname |
|||
} |
|||
|
|||
var options = { |
|||
params: params, |
|||
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, |
|||
}; |
|||
|
|||
instance.defaults.timeout = 30000; |
|||
const res = await instance.get('/getuserplaygrounds',options); |
|||
if(res.status == 200){ |
|||
return res.data |
|||
}else{ |
|||
console.log("noerror: " + res) |
|||
return await res.status |
|||
|
|||
} |
|||
} |
|||
catch (err) { |
|||
console.error("error: "+err); |
|||
var error = new Object(); |
|||
error.action = '401' |
|||
error.error = err |
|||
return await error |
|||
} |
|||
} |
|||
|
|||
|
|||
global.online='ob'; |
|||
global.pipelines=[]; |
|||
|
|||
|
|||
// ***************************************************
|
|||
// rest get
|
|||
// ***************************************************
|
|||
|
|||
|
|||
|
|||
|
|||
app.get('/run', (req, res, next) => { |
|||
|
|||
(async() => { |
|||
|
|||
var RES = new Object(); |
|||
RES.code = req.query["action"] |
|||
RES.token = req.query["token"] |
|||
RES.error = false |
|||
RES.error_msg = "ok" |
|||
res.json(RES) |
|||
})() |
|||
|
|||
}); |
|||
|
|||
|
|||
// ***************************************************
|
|||
// socket
|
|||
// ***************************************************
|
|||
|
|||
//function getSHA256ofJSON(input){
|
|||
// return require("crypto").createHash("sha256").update(JSON.stringify(input)).digest("hex");
|
|||
//}
|
|||
|
|||
function sleep(ms) { |
|||
return new Promise(resolve => setTimeout(resolve, ms)); |
|||
} |
|||
|
|||
function getSHA256ofJSON(data, inputEncoding, encoding){ |
|||
if (!data) { |
|||
return ''; |
|||
} |
|||
inputEncoding = inputEncoding || 'utf-8'; |
|||
encoding = encoding || 'hex'; |
|||
const hash = require("crypto").createHash('md5'); |
|||
return hash.update(JSON.stringify(data), inputEncoding).digest(encoding); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
io.on('connection', s => { |
|||
console.error('socket connection'); |
|||
|
|||
// ------------------------------
|
|||
// --- set
|
|||
// ------------------------------
|
|||
var usersession = new Object(); |
|||
usersession.SOCKET = {}; |
|||
usersession.SOCKET.error = {}; |
|||
console.error('socket ...'); |
|||
//s.auth = false;
|
|||
s.auth = true; |
|||
|
|||
// ------------------------------
|
|||
// --- authenticate
|
|||
// ------------------------------
|
|||
s.on('authenticate', function(data){ |
|||
const token = data |
|||
//console.log('invalid 1 ' + token);
|
|||
console.log("check " +JSON.stringify(data)) |
|||
(async() => { |
|||
//var isvalid = await checkToken(token);
|
|||
//
|
|||
/* |
|||
if(isvalid.action == 'ok'){ |
|||
console.log("Authserver ok ", s.id + ' - ' + token); |
|||
usersession.SOCKET.user = isvalid.user |
|||
usersession.SOCKET.scope = isvalid.scope // space delimeter
|
|||
usersession.SOCKET.token = isvalid.token |
|||
s.auth = true; |
|||
}else{ |
|||
console.log("Authserver no ", s.id + ' - ' + token); |
|||
s.auth = false; |
|||
} |
|||
*/ |
|||
s.auth = true; |
|||
})() |
|||
}); |
|||
/* |
|||
setTimeout(function(){ |
|||
if (!s.auth) { |
|||
console.log("Disconnecting timeout socket ", s.id); |
|||
//s.disconnect('unauthorized');
|
|||
}else{ |
|||
var room = usersession.SOCKET.user |
|||
//s.on("subscribe", function (room) {
|
|||
s.join(room); |
|||
console.log("joining rooom", s.rooms); |
|||
console.log(room + ' created ') |
|||
// });
|
|||
} |
|||
}, 30000); |
|||
*/ |
|||
|
|||
var id = s.id |
|||
s.on('action', obj => { |
|||
console.error('from client '+ s.id + ' obj ' + obj); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
http.listen(3000, () => console.error('listening on http://localhost:3000/')); |
|||
console.error('socket.io example'); |
@ -1,29 +0,0 @@ |
|||
var path = require('path'); |
|||
var app = require('express')(); |
|||
var http = require('http').Server(app); |
|||
var io = require('socket.io')(http); |
|||
|
|||
/* |
|||
// server side code
|
|||
io.sockets.on('connection', function(socket) { |
|||
socket.on('create', function(room) { |
|||
socket.join(room); |
|||
}); |
|||
}); |
|||
|
|||
*/ |
|||
|
|||
|
|||
io.on('connection', s => { |
|||
|
|||
s.on("iot", function (room) { |
|||
s.join(room); |
|||
console.error('hi'); |
|||
s.to(room).emit('message', 'hi from server'); |
|||
io.emit('iotdata', 'hi from server'); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
|
|||
http.listen(8084, () => console.error('listening on http://localhost:8084/')); |
@ -1,32 +0,0 @@ |
|||
"use strict" |
|||
|
|||
var app = require('express')(); |
|||
var http = require('http').Server(app); |
|||
var https = require('https'); |
|||
|
|||
var express = require('express'); |
|||
app.use(express.json()); |
|||
|
|||
const helmet = require('helmet'); |
|||
app.use(helmet()); |
|||
|
|||
const cors = require('cors') |
|||
app.use(cors) |
|||
|
|||
app.get('/run', (req, res, next) => { |
|||
console.log('hi'); |
|||
|
|||
(async() => { |
|||
|
|||
var RES = new Object(); |
|||
RES.code = req.query["action"] |
|||
RES.token = req.query["token"] |
|||
RES.error = false |
|||
RES.error_msg = "ok" |
|||
res.json(RES) |
|||
})() |
|||
|
|||
}); |
|||
|
|||
http.listen(3000, () => console.error('listening on http://localhost:3000/')); |
|||
console.error('socket.io example'); |
@ -1,38 +0,0 @@ |
|||
|
|||
var app = require('express')(); |
|||
var fs = require('fs'); |
|||
|
|||
const cors = require('cors') |
|||
const helmet = require('helmet'); |
|||
//app.use(cors)
|
|||
app.use(helmet()); |
|||
|
|||
var options = { |
|||
key: fs.readFileSync('./llo/swarmlab.key'), |
|||
cert: fs.readFileSync('./llo/swarmlab.crt') |
|||
}; |
|||
var serverPort = 3000; |
|||
|
|||
var https = require('https').Server(options, app); |
|||
//var server = https.createServer(options, app);
|
|||
|
|||
|
|||
|
|||
app.get('/run', (req, res, next) => { |
|||
console.log('hi'); |
|||
|
|||
(async() => { |
|||
|
|||
var RES = new Object(); |
|||
RES.code = req.query["action"] |
|||
RES.token = req.query["token"] |
|||
RES.error = false |
|||
RES.error_msg = "ok" |
|||
//res.json(RES)
|
|||
res.send(RES) |
|||
})() |
|||
|
|||
}); |
|||
|
|||
https.listen(3000, () => console.error('listening on http://localhost:3000/')); |
|||
console.error('socket.io example'); |
@ -0,0 +1,55 @@ |
|||
<template> |
|||
<card class="card-user" style="max-height:100%"> |
|||
|
|||
<div class="row" > |
|||
<div class="col-7 order-first " > |
|||
<br> |
|||
<myconnect-manage-server> |
|||
|
|||
</myconnect-manage-server> |
|||
</div> |
|||
|
|||
<div class="col-5 order-last" > |
|||
<br> |
|||
<adhoc-view> |
|||
|
|||
</adhoc-view> |
|||
</div> |
|||
</div> |
|||
|
|||
|
|||
</card> |
|||
</template> |
|||
<script> |
|||
import {mapState, mapGetters, mapActions} from 'vuex' |
|||
//import ViewNetwork from "./mynetwork/mytable.vue"; |
|||
import AdhocView from "./mynetwork/AdhocView.vue"; |
|||
import card from '@/components/Card.vue' |
|||
//import DockerServices from "./mynetwork/dockerservices.vue"; |
|||
import MyconnectManageServer from "./manageservices/manage-service.vue"; |
|||
export default { |
|||
components: { |
|||
AdhocView, |
|||
card, |
|||
MyconnectManageServer |
|||
}, |
|||
data () { |
|||
return { |
|||
loading: false, |
|||
consoleView: 'off', |
|||
productIndex: 1 |
|||
} |
|||
}, |
|||
mounted() { |
|||
}, |
|||
beforeDestroy () { |
|||
}, |
|||
|
|||
|
|||
created () { |
|||
} |
|||
}; |
|||
</script> |
|||
<style> |
|||
</style> |
|||
|
@ -0,0 +1,670 @@ |
|||
<template> |
|||
<card class="card-user" style="max-height:100%"> |
|||
<div class="author"> |
|||
<img class="avatar border-white" src="@/assets/img/docker.png" alt="..."> |
|||
</div> |
|||
|
|||
<b-container fluid class="bv-example-row"> |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
<div class="input-group input-group-sm sm-3"> |
|||
<div class="input-group-prepend"> |
|||
<button |
|||
class="btn btn-outline-primary" |
|||
round |
|||
type="button" |
|||
@click="onAction('add')" |
|||
> |
|||
Add Network Node</button> |
|||
</div> |
|||
|
|||
<input type="text" |
|||
class="form-control" |
|||
aria-label="Small" aria-describedby="inputGroup-sizing-sm" |
|||
placeholder="Search" |
|||
v-model="searchFor" |
|||
@keyup.enter="setFilter" |
|||
> |
|||
|
|||
<div class="input-group-append"> |
|||
<button |
|||
class="btn btn-outline-primary" |
|||