Skip to content

Commit

Permalink
Rewrite to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartFinn committed Aug 8, 2016
1 parent b7b53fd commit c81ed00
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
8 changes: 4 additions & 4 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: unetlab-x-integration
Priority: extra
Section: net
Installed-Size: 755
Installed-Size: 1396
Maintainer: Sergei Eremenko <[email protected]>
Architecture: all
Version: 0.1.2
Depends: telnet, wireshark, ssh-askpass-gnome | ssh-askpass, xterm | x-terminal-emulator
Recommends: vinagre, docker-engine | docker.io
Version: 0.2.0
Depends: python, ssh-askpass-gnome | ssh-askpass, telnet, vinagre, wireshark, xterm | x-terminal-emulator
Recommends: docker-engine | docker.io
Homepage: http://smartfinn.github.io/unetlab-x-integration/
Description: a tool which helps UNetLab to integrate with Ubuntu/Debian
This package provides the following protocols:
Expand Down
65 changes: 42 additions & 23 deletions unetlab-x-integration
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
#!/bin/bash

URI=(`echo $1 | \
sed -r 's%^(.*)://([a-Z0-9\\-\\.]+):?([0-9]+)?/?(.*)$%x\1 x\2 x\3 x\4%'`)

URI_SCHEME=${URI[0]#x}
URI_HOST=${URI[1]#x}
URI_PORT=${URI[2]#x}
URI_PATH=${URI[3]#x}

case "$URI_SCHEME" in
telnet)
x-terminal-emulator -e "telnet $URI_HOST $URI_PORT"
;;
capture)
ssh -l root $URI_HOST tcpdump -s 0 -U -n -i $URI_PATH -w - | \
wireshark -k -i -
;;
docker)
x-terminal-emulator -e "docker -H $URI_HOST:$URI_PORT attach \
${URI_PATH%%\?*}"
;;
esac
#!/usr/bin/env python
# See https://github.com/SmartFinn/unetlab-x-integration/

from __future__ import print_function
from subprocess import Popen

import sys


def main(argv):
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse

u = urlparse(argv)

d = {
'host': u.hostname,
'port': u.port,
'path': u.path.lstrip('/'),
}

if u.scheme == 'capture':
Popen('ssh -l root {host} tcpdump -s 0 -U -n -i {path} -w - | \
wireshark -k -i -'.format(**d), shell=True)
elif u.scheme == 'docker':
Popen('x-terminal-emulator -e \
"docker -H {host}:{port} attach {path}"'.format(**d), shell=True)
elif u.scheme == 'telnet':
Popen('x-terminal-emulator -e "telnet {host} {port}"'.format(**d),
shell=True)
else:
return 'URL "{}" is currently not supported.'.format(u.geturl())


if __name__ == '__main__':
try:
sys.exit(main(sys.argv[1]))
except IndexError:
print('usage:', __file__, '<url>', file=sys.stderr)
sys.exit(1)

0 comments on commit c81ed00

Please sign in to comment.