Browse Source

add hybrid ssh

master
zeus 3 years ago
parent
commit
5dde85410e
  1. 3
      README.md
  2. 9
      hybrid/create-keys.sh
  3. 4
      hybrid/keys.json
  4. 2
      hybrid/privatekey
  5. 2
      hybrid/publickey
  6. 44
      src-local/hybrid/connect/join-backup.sh
  7. 43
      src-local/hybrid/connect/join.sh
  8. 23
      src-local/hybrid/connect/leave-backup.sh
  9. 23
      src-local/hybrid/connect/leave.sh
  10. 1
      src-local/hybrid/connect/privatekey
  11. 1
      src-local/hybrid/connect/publickey
  12. 16
      src-local/hybrid/connect/status-wg.sh
  13. 37
      src-local/hybrid/connect/status.sh
  14. 33
      src-local/hybrid/connect/swarmlab-connect.sh
  15. 38
      src-local/hybrid/connect/template-connect.sh
  16. 2
      src-local/hybrid/connect/template-swarm.sh
  17. 10
      src-local/hybrid/connect/template-wg0.conf
  18. 11
      src-local/hybrid/connect/wg-test.sh
  19. 10
      src-local/hybrid/connect/wg0.conf
  20. 9
      src-local/hybrid/create-keys.sh
  21. 2
      src-local/hybrid/join.sh
  22. 1
      src-local/hybrid/keys.json
  23. 1
      src-local/hybrid/privatekey
  24. 1
      src-local/hybrid/publickey
  25. 29
      src-local/hybrid/scripts/add-nic-veth-pair.sh
  26. 26
      src-local/hybrid/scripts/add-nic.sh
  27. 24
      src-local/hybrid/scripts/expose-netns.sh
  28. 48
      src-local/llo/bclient.js
  29. 32
      src-local/llo/client.js
  30. 40
      src-local/llo/iotclient.js
  31. 381
      src-local/llo/iotserver.js
  32. 285
      src-local/llo/new.js
  33. 29
      src-local/llo/pubsub.js
  34. 32
      src-local/llo/test.js
  35. 38
      src-local/llo/test1.js
  36. 45
      src/App.vue
  37. 55
      src/components/manageservices.vue
  38. 670
      src/components/manageservices/manage-service.vue
  39. 55
      src/components/myconnect-server.vue
  40. 396
      src/components/mynetwork/myconnect-server.vue
  41. 69
      src/components/mynetwork/mytable.vue
  42. 141
      src/store/modules/create_pipelineLLO.js
  43. 181
      viwsession/session1

3
README.md

@ -1,2 +1,5 @@
# swarmlab-hybrid
jq
sudo apt install wireguard

9
hybrid/create-keys.sh

@ -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

4
hybrid/keys.json

@ -0,0 +1,4 @@
{
"private": "EDcHFoG5cE/110wPaYgVjNdtHkULRMDE9vECia/4I3g=",
"public": "hQ4VKJePvguRkcGOOaT7fcKNE2HyYGqBoacByNNd7Xo="
}

2
hybrid/privatekey

@ -1 +1 @@
6CdrILpdZcm1OfOecSQSgaI90sLNOTVW9zO9Dac5b0w=
kCoimlkUSkb4MaEVoI4ePThzKDYNZF9A/4d0L1u3q38=

2
hybrid/publickey

@ -1 +1 @@
fEirlFuleXLeY2pgsCVb8G16DEVXJVGJuXdifX1+/wY=
R97cS/PXC5N1dxom0pODyNhqnXfyIUqg04Fu1OU0fGs=

44
src-local/hybrid/connect/join-backup.sh

@ -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

43
src-local/hybrid/connect/join.sh

@ -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

23
src-local/hybrid/connect/leave-backup.sh

@ -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

23
src-local/hybrid/connect/leave.sh

@ -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

1
src-local/hybrid/connect/privatekey

@ -0,0 +1 @@
uHuqIEOoQTsESNhiz7Uu1COJlbIHdruBiMUG1GvBTHM=

1
src-local/hybrid/connect/publickey

@ -0,0 +1 @@
ol5eKuHsOOAY9mWpVnsVTG+EODv8Hcl8bMobkNx4Si8=

16
src-local/hybrid/connect/status-wg.sh

@ -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

37
src-local/hybrid/connect/status.sh

@ -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' <<<'{}'

33
src-local/hybrid/connect/swarmlab-connect.sh

@ -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"

38
src-local/hybrid/connect/template-connect.sh

@ -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"

2
src-local/hybrid/connect/template-swarm.sh

@ -0,0 +1,2 @@
docker swarm join --token SWMTKN-1-3099nls9my5ns1s0mnmwkx41mhpawl80hwjjbskbll7nghqhgn-asu68y4lhd1qlbpxr6oosk6wl 10.13.13.1:2377

10
src-local/hybrid/connect/template-wg0.conf

@ -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

11
src-local/hybrid/connect/wg-test.sh

@ -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

10
src-local/hybrid/connect/wg0.conf

@ -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

9
src-local/hybrid/create-keys.sh

@ -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

2
src-local/hybrid/join.sh

@ -0,0 +1,2 @@
docker swarm join --token SWMTKN-1-3099nls9my5ns1s0mnmwkx41mhpawl80hwjjbskbll7nghqhgn-asu68y4lhd1qlbpxr6oosk6wl 10.13.13.1:2377

1
src-local/hybrid/keys.json

@ -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\"}"

1
src-local/hybrid/privatekey

@ -0,0 +1 @@
EEQqA/IEqbKRHuo8Har5JsjatOYY++JMmiU/QEr4zlw=

1
src-local/hybrid/publickey

@ -0,0 +1 @@
iAn+EwqtojVrIV58N5jpnjlHeqCYhGKS8gHpaHuieBA=

29
src-local/hybrid/scripts/add-nic-veth-pair.sh

@ -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"

26
src-local/hybrid/scripts/add-nic.sh

@ -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"

24
src-local/hybrid/scripts/expose-netns.sh

@ -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

48
src-local/llo/bclient.js

@ -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);
});

32
src-local/llo/client.js

@ -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!')

40
src-local/llo/iotclient.js

@ -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
});

381
src-local/llo/iotserver.js

@ -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');

285
src-local/llo/new.js

@ -208,6 +208,199 @@ app.get('/getservicesstatus', (req, res, next) => {
});
app.get('/get_config', (req, res, next) => {
var mypath = process.cwd()
var RES = new Object();
var found = 'yes'
RES.error = false
RES.error_msg = "ok"
RES.data = found;
RES.data = mypath
res.json(RES)
/*
exec('pwd', (err, stdout, stderr) => {
if (err) {
console.error(`exec error: ${err}`);
return;
}
if (stdout) {
var string = stdout.toString()
console.log(JSON.stringify(string))
var found = 'yes'
RES.error = false
RES.error_msg = "ok"
RES.data = found;
RES.data = string
res.json(RES)
}else{
var found = 'no'
RES.error = false
RES.error_msg = "ok"
RES.data = found;
res.json(RES)
}
});
*/
});
app.get('/create_config', (req, res, next) => {
var RES = new Object();
RES.value = req.query["value"]
console.log('value error '+JSON.stringify(RES.value))
//var showexec = `cd ./hybrid; /bin/bash ./create-keys.sh`
fs.writeFileSync('./hybrid/keys.json', JSON.stringify(RES.value));
RES.value = JSON.parse(RES.value);
var INTERFACE_IP=RES.value.wg_ip
var endpoint_tmp=RES.value.server_ip
var fields = endpoint_tmp.split(':');
var endpoint = fields[0];
var mypath = process.cwd()
var swarmlab_config_template = `
DEV_NAME=wg0
INTERFACE_IP=${INTERFACE_IP}/16
INTERFACE_IProute=${INTERFACE_IP}
ENDPOINT_IP=${endpoint}
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 ${mypath}/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"
`
fs.writeFileSync('./hybrid/connect/swarmlab-connect.sh', swarmlab_config_template);
var allowed_ips=RES.value.allowed_ips
var swarmlab_public_wgkey=RES.value.swarmlab_public_wgkey
var swarmlab_privatekey=RES.value.privatekey
var swarmlab_wg_port=RES.value.wg_port
var swarmlab_wg0_template = `[Interface]
PrivateKey = ${swarmlab_privatekey}
ListenPort = ${swarmlab_wg_port}
[Peer]
PublicKey = ${swarmlab_public_wgkey}
Endpoint = ${endpoint_tmp}
AllowedIPs = ${allowed_ips}
PersistentKeepalive = 30
`
fs.writeFileSync('./hybrid/connect/template-wg0.conf', swarmlab_wg0_template);
var swarmlab_swarm=RES.value.workerkey
var swarmlab_swarm_ip=RES.value.swarm_ip
var swarmlab_swarm_template = `
docker swarm join --token ${swarmlab_swarm} ${swarmlab_swarm_ip}
`
fs.writeFileSync('./hybrid/connect/template-swarm.sh', swarmlab_swarm_template);
var swarmlab_swarm_join_template = `
function swarmlab_ifup() {
swarmlab=$(/bin/bash ${mypath}/hybrid/connect/status.sh wg0 | jq .swarmlab)
tempswarm="\${swarmlab%\\"}"
tempswarm="\${tempswarm#\\"}"
swarmlab=$tempswarm
echo $swarmlab
}
function hybrid_ifup() {
hybrid=$(/bin/bash ${mypath}/hybrid/connect/status.sh wg0 | jq .hybrid)
tempswarm1="\${hybrid%\\"}"
tempswarm1="\${tempswarm1#\\"}"
hybrid=$tempswarm1
echo $hybrid
}
hybrid=$(hybrid_ifup)
if [ $hybrid == 'NotOnline' ]; then
/bin/bash ${mypath}/hybrid/connect/swarmlab-connect.sh
echo "Start wg0 network interface"
sleep 3
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
sleep 1
swarmlab=$(swarmlab_ifup)
if [ $swarmlab != 'active' ]; then
sleep 5
swarmlab1=$(swarmlab_ifup)
if [ $swarmlab1 != 'active' ]; then
echo "Failed to connect on swarmlab master"
echo "Exec "
echo "/bin/bash ${mypath}/hybrid/connect/reload-swarmlab.sh"
echo "Please try again"
fi
else
echo "Swarmlab master $swarmlab"
fi
`
fs.writeFileSync('./hybrid/connect/join.sh', swarmlab_swarm_join_template);
var swarmlab_swarm_leave_template = `
function hybrid_ifup() {
hybrid=$(/bin/bash ${mypath}/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
`
fs.writeFileSync('./hybrid/connect/leave.sh', swarmlab_swarm_leave_template);
RES.error = false
RES.error_msg = "ok"
res.json(RES)
});
function create_project(swarmlabname,project){
var services_path = './instance/'+swarmlabname+'/'+project
@ -244,6 +437,31 @@ function create_project(swarmlabname,project){
});
}
function myserverStatus(){
var serverStatus = '/bin/bash ./hybrid/connect/status.sh wg0';
exec(serverStatus, (err, stdout, stderr) => {
if (err) {
console.error(`exec error: ${err}`);
return;
}
if (stdout) {
var string = stdout.toString()
string = JSON.parse(string);
//var stringstr = string.replace(/^"(.*)"$/, '$1');
var n = {}
n.data = string
io.emit('message_hybrid_status', n);
}
});
}
myserverStatus();
setInterval(function(){
myserverStatus()
}, 30000)
let child = [];
var ppid = ''
io.on('connection', function(socket) {
@ -464,6 +682,73 @@ SSH_PORT=
//child[0].kill();
});
socket.on('create-wirequard', (value) => {
let rawdatafile = './hybrid/config.json'
var workerkey = value.workerkey
var privatekey = value.privatekey
var publickey = value.publickey
var server_ip = value.server_ip // 83.212.77.133:51820
var allowed_ips = value.allowed_ips // 10.13.13.0/16, 0.0.0.0/0, ::/0
var services_json = {
workerkey: workerkey,
privatekey: privatekey,
publickey: publickey,
server_ip: server_ip,
allowed_ips: allowed_ips
};
let datajson = JSON.stringify(services_json);
fs.writeFileSync(rawdatafile, datajson);
var services_path = ` ----------------
create a file
/etc/wireguard/wg0.conf
-----------------------
`
var ENV_service_file = `
create a file connect-server.sh
[Interface]
PrivateKey = ${privatekey}
ListenPort = 51820
[Peer]
PublicKey = ${publickey}
Endpoint = ${server_ip}
AllowedIPs = ${allowedOrigins}
PersistentKeepalive = 30
`
var n = {}
n.data = services_path
io.emit('message_out', n);
n.data = ENV_service_file
io.emit('message_out', n);
var n = {}
n.data = 'sudo bash ./connect-server.sh'
io.emit('message_close', n);
});
socket.on('get-serverconfig', () => {
let rawdatafile = './hybrid/keys.json'
if (fs.existsSync(rawdatafile)) {
let rawdata = fs.readFileSync(rawdatafile);
let config = JSON.parse(rawdata);
var n = {}
n.file = 'ok'
n.data = config
io.emit('message_config', n);
}else{
var n = {}
n.file = 'nodata'
n.data = 'nodata'
io.emit('message_config', n);
}
});
});
server.listen(serverPort, function() {

29
src-local/llo/pubsub.js

@ -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/'));

32
src-local/llo/test.js

@ -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');

38
src-local/llo/test1.js

@ -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');

45
src/App.vue

@ -11,7 +11,7 @@
<a class="nav-link" href="#"
@click="hybrid('services')"
>
Manage_Your_Lab_Instances</a>
Manage_Your_Local_LabInstances</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
@ -37,7 +37,9 @@
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
<a class="nav-link" href="#"
@click="hybrid('connect-server')"
>Config_hybrid_server</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
@ -45,7 +47,11 @@
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
<a class="nav-link" href="#"
@click="hybrid('manage_service')"
>
Manage_Your_hybrid_LabInstances</a>
</li>
</li>
</ul>
<ul class="nav navbar-nav flex-row justify-content-md-center justify-content-start flex-nowrap">
@ -84,7 +90,29 @@
</b-col>
</b-row>
<b-row
v-show="hybridmenou == 'connect-server'"
>
<b-col cols="12">
<connect-server
style="background-color: #f8f9fa"
>
</connect-server>
</b-col>
</b-row>
<b-row
v-show="hybridmenou == 'manage_service'"
>
<b-col cols="12">
<manage-services
style="background-color: #f8f9fa"
>
</manage-services>
</b-col>
</b-row>
</div>
@ -93,15 +121,18 @@
<script>
import "@/assets/css/themify-icons.css";
//import NetworkTable from "./components/mynetwork/mytable.vue";
import ConnectServer from "./components/myconnect-server.vue";
import NetworkTable from "./components/mynetwork.vue";
import ServicesTable from "./components/myservices.vue";
import ManageServices from "./components/manageservices.vue";
export default {
name: 'app',
components: {
NetworkTable,
ServicesTable
ServicesTable,
ConnectServer,
ManageServices
},
data() {
return {
@ -121,8 +152,12 @@ export default {
console.log(action)
if(action == 'bootstrap'){
this.$root.$emit('hybrid_refresh_dockerservices')
}else if(action == 'connect-server'){
this.$root.$emit('hybrid_connect_server')
}else if(action == 'services'){
this.$root.$emit('hybrid_refresh_availableservices')
}else if(action == 'manage_service'){
//this.$root.$emit('hybrid_manage_service')
}
}

55
src/components/manageservices.vue

@ -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>

670
src/components/manageservices/manage-service.vue

@ -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"
round
type="button"
@click="setFilter">
Go</button>
</div>
<div class="input-group-append">
<button class="btn btn-outline-secondary"
round
type="button"
@click="resetFilter">
Reset</button>
</div>
</div>
<!-- add newNODE -->
<card class="card-user" style="max-height:100%"
v-if="nodeadmin"
>
<br>
<div class="white h-20 flex-fixed-width-item"
<!-- add newROW ---------------------------------------------------- -->
<div class="row" >
<div class="col-3 order-first pr-md-1" >
<input type="text"
class="form-control"
aria-label="Small" aria-describedby="inputGroup-sizing-sm"
placeholder="Name"
v-model="nodename"
>
</div> <!-- coll -->
<div class="col-3 pr-md-1" >
<ValidationProvider name="nodeid" rules="required|alpha_num" ref="provider"
v-slot="{ valid, errors, ariaMsg, ariaInput }"
v-if="nodeadminupdate"
>
<input type="text"
class="form-control"
aria-label="Small" aria-describedby="inputGroup-sizing-sm"
placeholder="NodeId"
disabled
v-model="nodeid"
>
</ValidationProvider>
<ValidationProvider name="nodeid" rules="required|alpha_num" ref="provider"
v-slot="{ valid, errors, ariaMsg, ariaInput }"
v-else
>
<input type="text"
class="form-control"
aria-label="Small" aria-describedby="inputGroup-sizing-sm"
placeholder="NodeId"
v-model="nodeid"
data-vv-as='"Node id"'
data-vv-value-path="nodeid"
data-vv-name="nodeid"
>
<span>{{ errors[0] }}</span>
</ValidationProvider>
</div> <!-- coll -->
<div class="col-3 pr-md-1" >
<input type="text"
class="form-control"
aria-label="Small" aria-describedby="inputGroup-sizing-sm"
placeholder="IP"
v-model="nodeip"
>
</div> <!-- coll -->
</div> <!-- row -->
<!-- add newROW ---------------------------------------------------- -->
<div class="row" >
<div class="col-3 order-first pr-md-1" >
<input type="text"
class="form-control"
aria-label="Small" aria-describedby="inputGroup-sizing-sm"
placeholder="Role"
v-model="noderole"
>
</div> <!-- coll -->
<div class="col-3 pr-md-1" >
<input type="text"
class="form-control"
aria-label="Small" aria-describedby="inputGroup-sizing-sm"
placeholder="Zones"
v-model="nodezones"
>
</div> <!-- coll -->
<div class="col-3 pr-md-1" >
<input type="text"
class="form-control"
aria-label="Small" aria-describedby="inputGroup-sizing-sm"
placeholder="nodedesc"
v-model="nodedesc"
>
</div> <!-- coll -->
</div> <!-- row -->
<!-- add newROW ---------------------------------------------------- -->
<div class="row" >
<div class="col-2 pr-md-1" >
<div class="input-group input-group-sm sm-3">
<div class="input-group-append">
<button
class="btn btn-outline-primary"
round
type="button"
v-if="nodeadminupdate"
@click="onAction('update')">
update</button>
<button
class="btn btn-outline-primary"
round
type="button"
v-else
@click="onAction('addserver')">
add</button>
</div>
<div class="input-group-append">
<button class="btn btn-outline-secondary"
round
type="button"
@click="onAction('cancel')"
>
Cancel</button>
</div>
</div>
</div> <!-- coll -->
</div> <!-- row -->
</card> <!-- card -->
<!-- add newNODE -->
<div class="white h-100 flex-fixed-width-item"
<vuetable
ref="vuetable"
:key="vuetablekey"
:api-url='apiurl'
:api-mode="true"
:http-options="httpOptions"
:fields="fields"
:item-actions="itemActions"
:sort-order="sortOrder"
:show-sort-icons="true"
:multi-sort="multiSort"
:per-page="perpage"
pagination-path="links.pagination"
:pagination-component="paginationComponent"
:append-params="moreParams"
wrapper-class="vuetable-wrapper"
loading-class="loading"
detail-row-id="id"
@vuetable:pagination-data="onPaginationData"
@vuetable:load-success="loadsuccess"
:css="css.table"
>
<template slot="actions" slot-scope="props">
<div class="table-button-container">
<button
class="ti-pencil btn btn-outline-secondary btn-sm"
@click="onAction('edit', props.rowData, props.rowIndex)"
>
</button>
<button
round
class="ti-trash btn btn-outline-secondary btn-sm"
@click="onAction('rm', props.rowData, props.rowIndex)"
>
</button>
</div>
</template>
</vuetable>
<div class="vuetable-pagination ui basic segment grid">
<vuetable-pagination-info
ref="paginationInfo"
:css="css.paginationInfo"
>
</vuetable-pagination-info>
<vuetable-pagination
:css="css.pagination"
ref="pagination"
@vuetable-pagination:change-page="onChangePage"
>
</vuetable-pagination>
</div>
</b-container>
</card>
</template>
<script>
import store from '@/store/index'
import {mapState, mapGetters, mapActions,dispatch} from 'vuex'
import Vue from 'vue'
import {Vuetable, VuetablePaginationDropdown} from 'vuetable-2'
import card from '@/components/Card.vue'
import VuetablePaginationInfo from 'vuetable-2/src/components/VuetablePaginationInfo'
import VuetablePagination from 'vuetable-2/src/components/VuetablePagination'
import CssConfig from 'vuetable-2/src/components/VuetableCssConfig.js'
import {ApiConfig} from "@/config/index";
import { extend } from 'vee-validate';
import { required, alpha_num } from 'vee-validate/dist/rules';
// No message specified.
extend('alpha_num', alpha_num);
// Override the default message.
extend('required', {
...required,
message: 'This field is required'
});
export default {
components: {
card,
Vuetable,
VuetablePagination,
VuetablePaginationInfo,
VuetablePaginationDropdown
},
props: {
},
data() {
return{
token: '',
valid:false,
nodeadmin:false,
nodeadminupdate:false,
rowdata:{},
nodename:'',
nodeid:'',
nodeip:'',
noderole:'',
nodezones:'',
nodedesc:'',
playbookInfo: {},
token: '',
playbook: {
'title':'',
'name':'',
'description':''
},
container:{
name:'',
view:0
},
pipeline:{},
selected: '',
options: [
{ text: 'Packages', value: 'packages' },
{ text: 'Images', value: 'images' },
{ text: 'Scripts', value: 'scripts' }
],
showModal: false,
visibility: [],
active:false,
vuetablekey:0,
fielddata:{},
fields: [
{
name: 'name',
title: '<span class="orange"></span>Name',
sortField: 'name',
titleClass: 'text-center aligned',
visible:true,
dataClass: "center aligned",
width: '20%'
},
{
name: 'nodeid',
title: '<span class="text-warning">nodeid</span>',
titleClass: 'text-center aligned',
sortField: 'nodeid',
visible:true,
width: '20%'
},
{
name: 'ip',
title: '<span class="orange"></span>IP',
titleClass: 'text-center aligned',
sortField: 'swarmlabname',
visible:true,
width: '13%'
},
{
name: 'role',
title: '<span class="orange"></span>Role',
titleClass: 'text-center aligned',
sortField: 'role',
visible:true,
width: '15%',
formatter (value) {
const result = /^ondemand_playground/.test(value);
if (result) {
var v = '<p class="text-warning">Playground</p>'
return v
}else{
var v = '<p class="text-info">Lab</p>'
return v
}
}
},
{
name: 'zones',
title: '<span class="text-warning">Zones</span>',
sortField: 'zones',
titleClass: 'text-center aligned',
visible:true,
width: '20%'
},
{
name: 'status',
title: '<span class="orange"></span>Status',
titleClass: 'text-center aligned',
sortField: 'status',
visible:true,
width: '5%'
},
{
name: '__slot:actions',
title: 'Actions',
titleClass: 'text-center aligned',
dataClass: "text-center aligned",
width: '10%'
},
{
name: '_id',
title: '<span class="orange"></span>mongo',
visible:false
}
],
//apiurl:ApiConfig.url_80+"/swarmlabservices",
apiurl:ApiConfig.swarmlab_url_80+"/getswarmlabhybrid",
css: CssConfig,
perpage: 9,
searchFor: '',
sortOrder: [{
field: 'pipelinename',
direction: 'asc'
}],
multiSort: true,
paginationComponent: 'vuetable-pagination',
itemActions: [
{ name: 'view-item', label: '', icon: 'glyphicon glyphicon-zoom-in', class: 'btn btn-info', extra: {'title': 'View', 'data-toggle':"tooltip", 'data-placement': "left"} },
{ name: 'edit-item', label: '', icon: 'glyphicon glyphicon-pencil', class: 'btn btn-warning', extra: {title: 'Edit', 'data-toggle':"tooltip", 'data-placement': "top"} },
{ name: 'delete-item', label: '', icon: 'glyphicon glyphicon-remove', class: 'btn btn-danger', extra: {title: 'Delete', 'data-toggle':"tooltip", 'data-placement': "right" } }
],
moreParams: {
'filter': '',
'type': 'hybrid'
},
}
},
mounted() {
},
created() {
var url_string = window.location.href
var url = new URL(url_string);
this.token = url.searchParams.get("token");
console.log("token "+ this.token);
},
beforeDestroy () {
},
computed: {
httpOptions() {
var token = this.token
var p="headers: {Authorization: token}}"; //table props -> :http-options="httpOptions"
return {headers: {Authorization: 'Bearer ' + token}} //table props -> :http-options="httpOptions"
},
},
methods: {
onError (type,description) {
var winfo=description
var info='<h5>Bootstrap '+type+'</h5>'
this.$swal({
type: type,
html: info+winfo,
showCloseButton: true,
showLoaderOnConfirm: false,
allowOutsideClick: false,
cancelButtonText: 'No, cancel!',
showCancelButton: false,
showLoaderOnConfirm: false,
reverseButtons: true,
focusCancel: true,
confirmButtonText: 'Ok!'
})
},
setFilter () {
this.moreParams = {
'filter': this.searchFor,
'type': this.selected
}
Vue.nextTick( () => this.$refs.vuetable.refresh())
},
resetFilter () {
this.moreParams = {}
this.searchFor = ''
Vue.nextTick( () => this.$refs.vuetable.refresh())
},
onPaginationData (paginationData) {
this.$refs.pagination.setPaginationData(paginationData)
this.$refs.paginationInfo.setPaginationData(paginationData)
},
onChangePage (page) {
this.$refs.vuetable.changePage(page)
},
editRow(rowData) {
alert("You clicked edit on"+ JSON.stringify(rowData));
},
async onAction (action, data, index) {
if(action == 'edit' ){
this.nodeadmin = true
this.nodeadminupdate = true
this.nodeid = data.nodeid
this.nodeip = data.ip
this.nodename = data.name
this.noderole = data.role
this.nodezones = data.zones
this.nodedesc = data.description
console.log(JSON.stringify(data))
console.log(JSON.stringify(index))
}else if(action == 'update' ){
await this.$refs.provider.validate().then(success => {
if (success.valid) {
this.valid = true
console.log('valid '+JSON.stringify(success))
}else{
this.valid = false
console.log('no valid'+JSON.stringify(success))
}
});
if (this.valid) {
var log = await store.dispatch("pipelineLLO/swarmlabhybridadd",{
token:this.token,
action:'add',
nodeid: this.nodeid,
nodeip: this.nodeip,
nodename: this.nodename,
noderole: this.noderole,
nodezones: this.nodezones,
nodedesc: this.nodedesc
})
//console.log(this.nodename)
//console.log(this.nodeid)
//console.log(this.nodeip)
//console.log(this.noderole)
//console.log(this.nodezones)
//console.log(this.nodedesc)
Vue.nextTick( () => this.$refs.vuetable.refresh())
}
}else if(action == 'rm' ){
this.rowdata = data
this.$swal({
type: 'info',
html: 'info',
showCloseButton: true,
showLoaderOnConfirm: false,
allowOutsideClick: false,
cancelButtonText: 'No, cancel!',
showCancelButton: true,
showLoaderOnConfirm: false,
reverseButtons: true,
focusCancel: true,
confirmButtonText: 'Yes, Delete it!'
}).then((result)=> {
this.rmAndClose(result);
})
}else if(action == 'add' ){
this.nodeadmin = true
this.nodeadminupdate = false
}else if(action == 'addserver' ){
await this.$refs.provider.validate().then(success => {
if (success.valid) {
this.valid = true
console.log('valid '+JSON.stringify(success))
}else{
this.valid = false
console.log('no valid'+JSON.stringify(success))
}
});
if (this.valid) {
this.nodeadmin = false
this.nodeadminupdate = false
var log = await store.dispatch("pipelineLLO/swarmlabhybridadd",{
token:this.token,
action:'add',
nodeid: this.nodeid,
nodeip: this.nodeip,
nodename: this.nodename,
noderole: this.noderole,
nodezones: this.nodezones,
nodedesc: this.nodedesc
})
Vue.nextTick( () => this.$refs.vuetable.refresh())
console.log(JSON.stringify(log))
}
}else if(action == 'cancel' ){
this.nodeadmin = false
this.nodeadminupdate = false
}
},
async rmAndClose(result) {
var log = await store.dispatch("pipelineLLO/getswarmlabhybridinfo",{
token:this.token,
nodezones: this.rowdata.zones
})
if(result.value){
var log = await store.dispatch("pipelineLLO/swarmlabhybridrm",{
token:this.token,
action:'rm',
nodeid: this.rowdata.nodeid,
nodeip: this.rowdata.ip,
nodename: this.rowdata.name,
noderole: this.rowdata.role,
nodezones: this.rowdata.zones,
nodedesc: this.rowdata.description
})
Vue.nextTick( () => this.$refs.vuetable.refresh())
console.log(JSON.stringify(result))
console.log('rowdara '+JSON.stringify(this.rowdata))
}
},
async addAndClose(result) {
},
refreshVuetable() {
this.$nextTick(()=>{
this.vuetablekey += 1
})
},
playbookinfoShow(value) {
return this.visibility[value]=true
},
playbookinfo(value) {
return this.playbookInfo=value
},
rowClicked(row, event) {
return {
html: true,
title: () => { return 'Hello <b>Popover:</b> ' + (++this.counter) },
content: () => { return 'The date is:<br><em>' + new Date() + '</em>' }
}
},
loadsuccess(response) {
var data = response.data.data
this.fielddata=data
var n = data.length
n=n-1
},
},
actions: {
}
};
</script>
<style>
.flex-fixed-width-item {
flex: 0 0 100px;
}
.modalinfo {
z-index: 10000000 !important;
position:fixed;
}
/* a container with flex-direction column */
.vue-notifyjs.notifications{
.alert{
z-index: 100;
}
.list-move {
transition: transform 0.3s, opacity 0.4s;
}
.list-item {
display: inline-block;
margin-right: 10px;
}
.list-enter-active {
transition: transform 0.2s ease-in, opacity 0.4s ease-in;
}
.list-leave-active {
transition: transform 1s ease-out, opacity 0.4s ease-out;
}
.list-enter {
opacity: 0;
transform: scale(1.1);
}
.list-leave-to {
opacity: 0;
transform: scale(1.2, 0.7);
}
}
pre {
//background-color: rgb(255, 247, 229);
background-color: #eff0f1;
border: 1px solid blue;
//white-space: pre-line;
}
</style>

55
src/components/myconnect-server.vue

@ -0,0 +1,55 @@
<template>
<card class="card-user" style="max-height:100%">
<div class="row" >
<div class="col-7 order-first " >
<br>
<myconnect-server>
</myconnect-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 MyconnectServer from "./mynetwork/myconnect-server.vue";
export default {
components: {
AdhocView,
card,
MyconnectServer
},
data () {
return {
loading: false,
consoleView: 'off',
productIndex: 1
}
},
mounted() {
},
beforeDestroy () {
},
created () {
}
};
</script>
<style>
</style>

396
src/components/mynetwork/myconnect-server.vue

@ -0,0 +1,396 @@
<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="row text-center">
<div class="col-12">
<b>Hybrid server config</b>
</div>
</div>
<div class="row text-center">
<div class="col-12">
<br>
</div>
</div>
<div class="row">
<div class="col-3"><b>Node ID</b></div>
<div class="col-9"><i>{{ CONFIG.nodeid }}</i></div>
</div>
<div class="row">
<div class="col-3"><b>Swarmlab key</b></div>
<div class="col-9"><i>{{ CONFIG.workerkey }}</i></div>
</div>
<div class="row">
<div class="col-3"><b>Swarmlab PublicKey</b></div>
<div class="col-9"><i>{{ CONFIG.swarmlab_public_wgkey }}</i></div>
</div>
<div class="row">
<div class="col-3"><b>Swarmlab ip</b></div>
<div class="col-3"><i>{{ CONFIG.server_ip }}</i></div>
<div class="col-2"><b>Local IP</b></div>
<div class="col-4"><i>{{ CONFIG.wg_ip }}</i></div>
</div>
<div class="row">
<div class="col-3"><b>Private key</b></div>
<div class="col-3"><i>{{ CONFIG.privatekey }}</i></div>
<div class="col-2"><b>Public key</b></div>
<div class="col-4"><i>{{ CONFIG.publickey }}</i></div>
</div>
<div class="row">
<div class="col-12">
<br>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="input-group input-group-sm sm-3">
<div class="input-group-prepend">
<button
class="ti-info btn btn-outline-success"
round
type="button"
title="HowTo"
@click="onAction('register')"
>
</button>
<button
class="ti-settings btn btn-outline-info"
round
type="button"
title="Load config"
@click="onAction('load')"
> Load Settings
</button>
</div>
<div class="input-group-prepend">
<button
class="ti-widget btn btn-outline-info"
round
type="button"
title="Save config"
@click="onAction('save')"
> Save Settings
</button>
</div>
</div>
</div>
<div class="col-3">
<div class="input-group input-group-sm sm-3">
<div class="input-group-prepend"
>
<button
class="ti-link btn btn-outline-success"
round
type="button"
title="Connect"
@click="onAction('connect')"
> Connect
</button>
</div>
<div class="input-group-prepend"
>
<button
class="ti-unlink btn btn-outline-warning"
round
type="button"
title="Connect"
@click="onAction('disconnect')"
> Disconnect
</button>
</div>
</div>
</div> <!-- coll -->
<div class="col-3">
<div class="input-group input-group-sm sm-3">
<div class="input-group-prepend">
<button
v-if="isconnect"
class="ti-link btn btn-outline-success"
round
type="button"
title="Connect"
> Status online
</button>
<button
v-else
class="ti-unlink btn btn-outline-warning"
round
type="button"
title="Connect"
> Status offline
</button>
</div>
</div>
</div> <!-- coll -->
</div>
</div>
</b-container>
</card>
</template>
<script>
import store from '@/store/index'
import {mapState, mapGetters, mapActions,dispatch} from 'vuex'
import Vue from 'vue'
import {Vuetable, VuetablePaginationDropdown} from 'vuetable-2'
import card from '@/components/Card.vue'
import {ApiConfig} from "@/config/index";
export default {
components: {
card
},
props: {
},
data() {
return{
isconnect:false,
isstatus:false,
CONFIG:{
'status':'',
'privatekey':'',
'publickey':'',
'server_ip':'',
'nodeid':'',
'workerkey':'',
'allowed_ips':'',
'swarmlab_public_wgkey':'',
'wg_ip':'',
'swarm_ip':'',
'wg_port':''
},
token: ''
}
},
mounted() {
// from mytable.vue and socket
this.$root.$on('hybrid_connect_server_view', (value) => {
console.log('from mytable' + JSON.stringify(value))
this.CONFIG.status = value.status
this.CONFIG.workerkey = value.workerkey
this.CONFIG.swarmlab_public_wgkey = value.swarmlab_public_wgkey
this.CONFIG.server_ip = value.server_ip
this.CONFIG.allowed_ips = value.allowed_ips
this.CONFIG.wg_port = value.wg_port
this.CONFIG.wg_ip = value.wg_ip
this.CONFIG.swarm_ip = value.swarm_ip
this.CONFIG.privatekey = value.privatekey
this.CONFIG.publickey = value.publickey
if(this.CONFIG.status == 'on'){
this.isstatus = true
}else if(this.CONFIG.status == 'off'){
this.isstatus = false
}
}),
this.$root.$on('hybrid_server_status', (value) => {
this.serverstatus()
})
},
created() {
var url_string = window.location.href
var url = new URL(url_string);
this.token = url.searchParams.get("token");
console.log("token "+ this.token);
},
beforeDestroy () {
this.$root.$off('hybrid_connect_server_view')
this.$root.$off('hybrid_server_status')
},
computed: {
},
methods: {
async serverstatus(action){
var log = store.getters['pipelineLLO/getstatus']
console.log('status log ' + JSON.stringify(log))
//{"data":{"swarmlab":"active","hybrid":"Online"}}
if(log.data.swarmlab == 'active' && log.data.hybrid == 'Online'){
this.isstatus=true
this.isconnect=true
this.CONFIG.nodeid = log.data.swarmlabid
}else{
this.isstatus=false
this.isconnect=false
this.CONFIG.nodeid = 'null'
}
},
async onAction(action){
if(action == 'load'){
var log = await store.dispatch("pipelineLLO/swarmlabhybridconfig",{
token:this.token
})
console.log('settings ' + JSON.stringify(log))
this.CONFIG.status = log.data.data.status
this.CONFIG.workerkey = log.data.data.workerkey
this.CONFIG.swarmlab_public_wgkey = log.data.data.wg_public
this.CONFIG.server_ip = log.data.data.endpoint // 83.212.77.133:51820
this.CONFIG.allowed_ips = log.data.data.allowed_ip // 10.13.13.0/16, 0.0.0.0/0, ::/0
this.CONFIG.wg_port = log.data.data.wg_port // 10.13.13.0/16, 0.0.0.0/0, ::/0
this.CONFIG.wg_ip = log.data.data.wg_ip
this.CONFIG.swarm_ip = log.data.data.swarm_ip
this.CONFIG.privatekey = log.data.data.privatekey
this.CONFIG.publickey = log.data.data.publickey
if(this.CONFIG.status == 'on'){
this.isstatus = true
}else if(this.CONFIG.status == 'off'){
this.isstatus = false
}
console.log('swarm ' + JSON.stringify(log.data.data.workerkey))
console.log('start ' + JSON.stringify('load'))
}else if(action == 'connect'){
console.log('start ' + JSON.stringify('connect'))
var log = await store.dispatch("pipelineLLO/get_config",{
token:this.token
})
console.log('pwd ' + JSON.stringify(log))
this.isconnect = true
var winfopath = log.data.data
if(log.data.error_msg = 'ok'){
var winfo='sudo /bin/bash '
winfo += winfopath.trim()
winfo += '/hybrid/connect/join.sh'
}else{
var winfo='no exec file'
}
var info='<h5>Swarmlab Connect</h5><br>'
this.$swal({
type: 'info',
html: info+winfo,
showCloseButton: true,
showLoaderOnConfirm: false,
allowOutsideClick: false,
showLoaderOnConfirm: false,
reverseButtons: true,
focusCancel: true
})
}else if(action == 'save'){
var log = await store.dispatch("pipelineLLO/create_config",{
token:this.token,
value:this.CONFIG
})
console.log('start ' + JSON.stringify(log))
console.log('start ' + JSON.stringify('createkey'))
}else if(action == 'disconnect'){
console.log('start ' + JSON.stringify('disconnect'))
var log = await store.dispatch("pipelineLLO/get_config",{
token:this.token
})
console.log('pwd ' + JSON.stringify(log))
var winfopath = log.data.data
if(log.data.error_msg = 'ok'){
var winfo='sudo /bin/bash '
winfo += winfopath.trim()
winfo += '/hybrid/connect/leave.sh'
}else{
var winfo='no exec file'
}
var info='<h5>Swarmlab Disconnect</h5><br>'
this.$swal({
type: 'info',
html: info+winfo,
showCloseButton: true,
showLoaderOnConfirm: false,
allowOutsideClick: false,
showLoaderOnConfirm: false,
reverseButtons: true,
focusCancel: true
})
} else if(action == 'register'){
console.log('start ' + JSON.stringify('register'))
//var log = await store.dispatch("pipelineLLO/get_config",{
// token:this.token
//})
//console.log('pwd ' + JSON.stringify(log))
// var winfopath = log.data.data
var winfo=`Before you begin
<br>
Before you start using the Swarmlab Hybrid API, you need a hybrid enabled account and the Swarmlab API enabled.
<br>
To learn more, see Get Started with Hybrid Platform.
`
var info="<h5>Get API Key's</h5><br>"
this.$swal({
type: 'info',
html: info+winfo,
showCloseButton: true,
showLoaderOnConfirm: false,
allowOutsideClick: false,
showLoaderOnConfirm: false,
reverseButtons: true,
focusCancel: true
})
}
}
},
actions: {
}
};
</script>
<style>
.flex-fixed-width-item {
flex: 0 0 100px;
}
.modalinfo {
z-index: 10000000 !important;
position:fixed;
}
/* a container with flex-direction column */
.vue-notifyjs.notifications{
.alert{
z-index: 100;
}
.list-move {
transition: transform 0.3s, opacity 0.4s;
}
.list-item {
display: inline-block;
margin-right: 10px;
}
.list-enter-active {
transition: transform 0.2s ease-in, opacity 0.4s ease-in;
}
.list-leave-active {
transition: transform 1s ease-out, opacity 0.4s ease-out;
}
.list-enter {
opacity: 0;
transform: scale(1.1);
}
.list-leave-to {
opacity: 0;
transform: scale(1.2, 0.7);
}
}
pre {
//background-color: rgb(255, 247, 229);
background-color: #eff0f1;
border: 1px solid blue;
//white-space: pre-line;
}
</style>

69
src/components/mynetwork/mytable.vue

@ -138,6 +138,23 @@ export default {
},
data() {
return{
CONFIG:{
'status':'',
'workerkey':'',
'swarmlab_public_wgkey':'',
'server_ip':'',
'allowed_ips':'',
'wg_port':'',
'wg_ip':'',
'swarm_ip':'',
'privatekey':'',
'publickey':'',
'workerkey':'',
'privatekey':'',
'publickey':'',
'server_ip':''
},
CONFIGallowed_ips:'',
swarmlabname:'swarmlab-sec',
swarmlabname_port:'',
swarmlabname_size:3,
@ -182,6 +199,11 @@ export default {
//this.swarmlabname_port = data.port
this.onAction('install')
})
// from available services socket run here
this.$root.$on('hybrid_connect_server', (data) => {
//this.onAction('create-wirequard')
this.$socket.client.emit('get-serverconfig');
})
// from available services socket run here
this.$root.$on('hybrid_stop_instance', (data) => {
this.swarmlabname = data
@ -204,6 +226,8 @@ export default {
this.$root.$off('hybrid_show_info')
this.$root.$off('hybrid_start_instance')
this.$root.$off('hybrid_stop_instance')
this.$root.$off('hybrid_connect_server')
this.$root.$off('hybrid_install_instance')
},
computed: {
httpOptions() {
@ -243,6 +267,12 @@ export default {
// refresh adhocview.vue on console await
this.$root.$emit('SERVER_hybrid_table_start')
this.$socket.client.emit('container-stop', this.swarmlabname, this.hybridshowdata.ID);
}else if(action == 'create-wirequard'){
//this.CONFIGprivatekey = value.privatekey
//this.CONFIGpublickey = value.publickey
//this.CONFIGserver_ip = value.server_ip // 83.212.77.133:51820
//this.CONFIGallowed_ips = value.allowed_ips // 10.13.13.0/16, 0.0.0.0/0, ::/0
this.$socket.client.emit('create-wirequard', this.token);
}else if(action == 'stop'){
this.$socket.client.emit('stop', this.swarmlabname);
}
@ -440,6 +470,38 @@ export default {
async message(val) {
console.log(" socket message "+JSON.stringify(val))
},
async message_config(value) {
// server-config {"file":"ok","data":"{\"status\":\"on\",\"privatekey\":\"wLIMh+7NjGmryQB/zqXTpc1m0SwcqE0KuiI/nMgJYHs=\",\"publickey\":\"IpeD6JISIjUn1qjr1ga8I+mGaaEABgBZV+D/iI/pu2E=\",\"server_ip\":\"83.212.77.133:51820\",\"workerkey\":\"SWMTKN-1-3099nls9my5ns1s0mnmwkx41mhpawl80hwjjbskbll7nghqhgn-asu68y4lhd1qlbpxr6oosk6wl\",\"swarmlab_public_wgkey\":\"yMTjzSFQloNH22v+sN9k4cIaOUujq/m+vB2HJdJM7GI=\",\"wg_port\":\"51820\",\"allowed_ips\":\"10.13.13.0/16, 0.0.0.0/0, ::/0\"}"}
value.data = JSON.parse(value.data);
if(value.file == 'ok'){
console.log('server-value-file-ok ' + JSON.stringify(value.data.status))
this.CONFIG.status = value.data.status
this.CONFIG.workerkey = value.data.workerkey
this.CONFIG.swarmlab_public_wgkey = value.data.swarmlab_public_wgkey
this.CONFIG.server_ip = value.data.server_ip
this.CONFIG.allowed_ips = value.data.allowed_ips
this.CONFIG.wg_port = value.data.wg_port
this.CONFIG.wg_ip = value.data.wg_ip
this.CONFIG.swarm_ip = value.data.swarm_ip
this.CONFIG.privatekey = value.data.privatekey
this.CONFIG.publickey = value.data.publickey
}else if(value.file == 'nodata'){
this.CONFIG.status = ''
this.CONFIG.workerkey = ''
this.CONFIG.swarmlab_public_wgkey = ''
this.CONFIG.server_ip = ''
this.CONFIG.allowed_ips = ''
this.CONFIG.wg_port = ''
this.CONFIG.wg_ip = ''
this.CONFIG.swarm_ip = ''
this.CONFIG.privatekey = ''
this.CONFIG.publickey = ''
}
// send to myconnect-server.vue
console.log('server-config ' + JSON.stringify(value))
this.$root.$emit('hybrid_connect_server_view', this.CONFIG)
},
async message_out(val) {
console.log(" socket out "+JSON.stringify(val))
this.$root.$emit('hybrid_log_in',val)
@ -459,6 +521,13 @@ export default {
this.$root.$emit('hybrid_refresh_table')
// refresh adhocview.vue on console await console
this.$root.$emit('SERVER_hybrid_table_stop')
},
async message_hybrid_status(val) {
console.log(" message_hybrid_status "+JSON.stringify(val))
var obj = {}
obj.status = val
var res1 = await store.dispatch('pipelineLLO/setstatus', obj)
this.$root.$emit('hybrid_server_status',val)
}
},

141
src/store/modules/create_pipelineLLO.js

@ -5,7 +5,8 @@ import axios from 'axios'
export default {
namespaced: true,
state: {
token: ''
token: '',
status: {}
},
getters: {
gettoken (state, container) {
@ -13,12 +14,18 @@ export default {
},
getlog (state, container) {
return state.log
},
getstatus (state, container) {
return state.status
}
},
mutations: {
set_token (state, data) {
state.token=data;
},
set_status (state, data) {
state.status=data;
},
add_log (state, data) {
//console.log("js1 set "+JSON.stringify(data))
state.log.push(data);
@ -37,6 +44,10 @@ export default {
//console.log("container "+value)
commit('set_token', value.token)
},
setstatus({commit}, value) {
//console.log("container "+value)
commit('set_status', value.status)
},
async swarmlabstart({commit,rootGetters}, value) {
console.log('from '+JSON.stringify(value))
try {
@ -63,6 +74,43 @@ export default {
return R;
}
}
},
async swarmlabhybridadd({commit,rootGetters}, value) {
try {
var token = value.token
var params = {
action: value.action,
nodename: value.nodename,
nodeip: value.nodeip,
nodeid: value.nodeid,
noderole: value.noderole,
nodezones: value.nodezones,
nodedesc: value.nodedesc
}
var options = {
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
};
var p = await axios.post('https://api.swarmlab.io/swarmlabhybridadd',params,options);
if(p.error == "invalid_token"){
console.log(p)
console.log(JSON.stringify(p))
}else{
}
//console.log(value.token)
//console.log(value.swarmlabname)
console.log(JSON.stringify(p))
} catch (e) {
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
//console.log('error '+JSON.stringify(e))
window.location.href = 'https://api-login.swarmlab.io:8089';
}else{
var R = {
ERROR_str: e,
ERROR: 'yes'
}
return R;
}
}
},
async swarmlabhybridrm({commit,rootGetters}, value) {
try {
@ -155,6 +203,62 @@ export default {
return R;
}
}
},
async create_config({commit,rootGetters}, value) {
console.log('value '+JSON.stringify(value))
try {
var token = value.token
var params = {
value: value.value
}
var options = {
params: params,
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
};
var p = await axios.get('https://localhost:3000/create_config',options);
return p
} catch (e) {
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
//console.log('error '+JSON.stringify(e))
window.location.href = 'https://api-login.swarmlab.io:8089';
}else{
var R = {
ERROR_str: e,
ERROR: 'yes'
}
return R;
}
}
},
async get_config({commit,rootGetters}, value) {
console.log('value '+JSON.stringify(value))
try {
var token = value.token
var params = {
value: 'get'
}
var options = {
params: params,
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
};
var p = await axios.get('https://localhost:3000/get_config',options);
return p
} catch (e) {
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
//console.log('error '+JSON.stringify(e))
window.location.href = 'https://api-login.swarmlab.io:8089';
}else{
var R = {
ERROR_str: e,
ERROR: 'yes'
}
return R;
}
}
},
async getswarmlabinfo({commit,rootGetters}, value) {
try {
@ -177,7 +281,40 @@ export default {
window.location.href = 'https://api-login.swarmlab.io:8089';
}
}
}
},
async swarmlabhybridconfig({commit,rootGetters}, value) {
try {
var token = value.token
var params = {
action: 'add'
}
var options = {
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
};
var p = await axios.post('https://api.swarmlab.io/swarmlabhybridconfiginfo',params,options);
if(p.error == "invalid_token"){
console.log(p)
console.log(JSON.stringify(p))
}else{
}
//console.log(value.token)
//console.log(value.swarmlabname)
console.log(JSON.stringify(p))
return p
} catch (e) {
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
//console.log('error '+JSON.stringify(e))
window.location.href = 'https://api-login.swarmlab.io:8089';
}else{
var R = {
ERROR_str: e,
ERROR: 'yes'
}
return R;
}
}
},
}

181
viwsession/session1

@ -9,12 +9,17 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
endif
set shortmess=aoO
badd +1 /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/AdhocView.vue
badd +147 /data/appl/ok/swarmlab-hybrid-agent/src-local/llo/new.js
badd +8 /data/appl/ok/swarmlab-hybrid-agent/src-local/llo/new.js
badd +1 /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/mytable.vue
badd +50 /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/dockerservices.vue
badd +43 /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/availableservices.vue
badd +1 /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork.vue
badd +1 /data/appl/ok/swarmlab-hybrid-agent/src/store/modules/create_pipelineLLO.js
badd +1 /data/appl/ok/swarmlab-hybrid-agent/src/components/myservices.vue
badd +1 /data/appl/ok/swarmlab-hybrid-agent/src/App.vue
badd +1 /data/appl/ok/swarmlab-hybrid-agent/src/components/myconnect-server.vue
badd +0 /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/myconnect-server.vue
badd +0 /data/appl/ok/swarmlab-hybrid-agent/src/components/manageservices/manage-service.vue
argglobal
silent! argdel *
$argadd mynetwork.vue
@ -38,13 +43,13 @@ set nosplitright
wincmd t
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
exe '1resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 1resize ' . ((&columns * 99 + 100) / 200)
exe 'vert 1resize ' . ((&columns * 99 + 101) / 202)
exe '2resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 2resize ' . ((&columns * 99 + 100) / 200)
exe 'vert 2resize ' . ((&columns * 99 + 101) / 202)
exe '3resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 3resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 3resize ' . ((&columns * 102 + 101) / 202)
exe '4resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 4resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 4resize ' . ((&columns * 102 + 101) / 202)
argglobal
setlocal fdm=manual
setlocal fde=0
@ -55,11 +60,11 @@ setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 394 - ((12 * winheight(0) + 11) / 22)
let s:l = 395 - ((13 * winheight(0) + 11) / 22)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
394
395
normal! 015|
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components
wincmd w
@ -74,17 +79,16 @@ setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 190 - ((19 * winheight(0) + 11) / 22)
let s:l = 206 - ((14 * winheight(0) + 11) / 22)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
190
normal! 032|
206
normal! 06|
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components
wincmd w
argglobal
enew
file /data/appl/ok/swarmlab-hybrid-agent/src/components/myservices.vue
if bufexists('/data/appl/ok/swarmlab-hybrid-agent/src/components/myservices.vue') | buffer /data/appl/ok/swarmlab-hybrid-agent/src/components/myservices.vue | else | edit /data/appl/ok/swarmlab-hybrid-agent/src/components/myservices.vue | endif
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
@ -93,6 +97,13 @@ setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 34 - ((18 * winheight(0) + 11) / 22)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
34
normal! 0
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components
wincmd w
argglobal
@ -115,13 +126,13 @@ normal! 0
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components
wincmd w
exe '1resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 1resize ' . ((&columns * 99 + 100) / 200)
exe 'vert 1resize ' . ((&columns * 99 + 101) / 202)
exe '2resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 2resize ' . ((&columns * 99 + 100) / 200)
exe 'vert 2resize ' . ((&columns * 99 + 101) / 202)
exe '3resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 3resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 3resize ' . ((&columns * 102 + 101) / 202)
exe '4resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 4resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 4resize ' . ((&columns * 102 + 101) / 202)
tabedit /data/appl/ok/swarmlab-hybrid-agent/src-local/llo/new.js
set splitbelow splitright
wincmd _ | wincmd |
@ -136,11 +147,11 @@ set nosplitbelow
set nosplitright
wincmd t
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
exe 'vert 1resize ' . ((&columns * 99 + 100) / 200)
exe 'vert 1resize ' . ((&columns * 99 + 101) / 202)
exe '2resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 2resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 2resize ' . ((&columns * 102 + 101) / 202)
exe '3resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 3resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 3resize ' . ((&columns * 102 + 101) / 202)
argglobal
setlocal fdm=manual
setlocal fde=0
@ -151,12 +162,12 @@ setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 172 - ((29 * winheight(0) + 22) / 45)
let s:l = 386 - ((44 * winheight(0) + 22) / 45)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
172
normal! 09|
386
normal! 07|
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork
wincmd w
argglobal
@ -189,19 +200,19 @@ setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 317 - ((17 * winheight(0) + 11) / 22)
let s:l = 310 - ((9 * winheight(0) + 11) / 22)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
317
normal! 073|
310
normal! 013|
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components
wincmd w
exe 'vert 1resize ' . ((&columns * 99 + 100) / 200)
exe 'vert 1resize ' . ((&columns * 99 + 101) / 202)
exe '2resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 2resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 2resize ' . ((&columns * 102 + 101) / 202)
exe '3resize ' . ((&lines * 22 + 24) / 48)
exe 'vert 3resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 3resize ' . ((&columns * 102 + 101) / 202)
tabedit /data/appl/ok/swarmlab-hybrid-agent/src/store/modules/create_pipelineLLO.js
set splitbelow splitright
wincmd _ | wincmd |
@ -212,8 +223,110 @@ set nosplitbelow
set nosplitright
wincmd t
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
exe 'vert 1resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 2resize ' . ((&columns * 99 + 100) / 200)
exe 'vert 1resize ' . ((&columns * 101 + 101) / 202)
exe 'vert 2resize ' . ((&columns * 100 + 101) / 202)
argglobal
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 20 - ((19 * winheight(0) + 22) / 45)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
20
normal! 05|
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork
wincmd w
argglobal
if bufexists('/data/appl/ok/swarmlab-hybrid-agent/src/App.vue') | buffer /data/appl/ok/swarmlab-hybrid-agent/src/App.vue | else | edit /data/appl/ok/swarmlab-hybrid-agent/src/App.vue | endif
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 106 - ((20 * winheight(0) + 22) / 45)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
106
normal! 056|
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork
wincmd w
exe 'vert 1resize ' . ((&columns * 101 + 101) / 202)
exe 'vert 2resize ' . ((&columns * 100 + 101) / 202)
tabedit /data/appl/ok/swarmlab-hybrid-agent/src/components/myconnect-server.vue
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd w
set nosplitbelow
set nosplitright
wincmd t
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
exe 'vert 1resize ' . ((&columns * 101 + 101) / 202)
exe 'vert 2resize ' . ((&columns * 100 + 101) / 202)
argglobal
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 27 - ((26 * winheight(0) + 22) / 45)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
27
normal! 0
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork
wincmd w
argglobal
if bufexists('/data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/myconnect-server.vue') | buffer /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/myconnect-server.vue | else | edit /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork/myconnect-server.vue | endif
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=0
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
let s:l = 129 - ((30 * winheight(0) + 22) / 45)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
129
normal! 0
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork
wincmd w
exe 'vert 1resize ' . ((&columns * 101 + 101) / 202)
exe 'vert 2resize ' . ((&columns * 100 + 101) / 202)
tabedit /data/appl/ok/swarmlab-hybrid-agent/src/components/manageservices/manage-service.vue
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd w
set nosplitbelow
set nosplitright
wincmd t
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
exe 'vert 1resize ' . ((&columns * 101 + 101) / 202)
exe 'vert 2resize ' . ((&columns * 100 + 101) / 202)
argglobal
setlocal fdm=manual
setlocal fde=0
@ -234,7 +347,7 @@ lcd /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork
wincmd w
argglobal
enew
file /data/appl/ok/swarmlab-hybrid-agent/src/App.vue
file /data/appl/ok/swarmlab-hybrid-agent/src/components/manageservices.vue
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
@ -245,9 +358,9 @@ setlocal fdn=20
setlocal fen
lcd /data/appl/ok/swarmlab-hybrid-agent/src/components/mynetwork
wincmd w
exe 'vert 1resize ' . ((&columns * 100 + 100) / 200)
exe 'vert 2resize ' . ((&columns * 99 + 100) / 200)
tabnext 3
exe 'vert 1resize ' . ((&columns * 101 + 101) / 202)
exe 'vert 2resize ' . ((&columns * 100 + 101) / 202)
tabnext 5
set stal=1
if exists('s:wipebuf')
silent exe 'bwipe ' . s:wipebuf

Loading…
Cancel
Save