zeus
4 years ago
43 changed files with 2259 additions and 643 deletions
@ -1,2 +1,5 @@ |
|||||
# swarmlab-hybrid |
# 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" |
||||
|
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> |
@ -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> |
||||
|
|
@ -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> |
Loading…
Reference in new issue