diff --git a/config_scripts/config_opnsense.py b/config_scripts/config_opnsense.py new file mode 100755 index 0000000..6a605e0 --- /dev/null +++ b/config_scripts/config_opnsense.py @@ -0,0 +1,258 @@ +#!/usr/bin/env python3 + +# scripts/config_pfsense.py +# +# Import/Export script for vIOS. +# +# @author Alain Degreffe +# @copyright 2016 Alain Degreffe +# @license http://www.gnu.org/licenses/gpl.html +# @link http://www.eve-ng.net/ +# @version 20181203 + +import getopt, multiprocessing, os, pexpect, re, sys, time + +conntimeout = 3 # Maximum time for console connection +expctimeout = 3 # Maximum time for each short expect +longtimeout = 30 # Maximum time for each long expect +timeout = 60 # Maximum run time (conntimeout is included) + +def node_login(handler): + # Send an empty line, and wait for the login prompt + i = -1 + while i == -1: + try: + handler.sendline('\r\n') + i = handler.expect([ + 'Enter an option:', + '.*OPNsense.*:~'], timeout = 5) + except: + i = -1 + + if i == 0: + # Need to send username and password + handler.sendline('8') + try: + handler.expect('.*root.*:', timeout = expctimeout) + return True + except: + print('ERROR: error waiting for "root:" prompt.') + node_quit(handler) + return False + + elif i == 1: + # nothing to do + return True + else: + # Unexpected output + node_quit(handler) + return False + +def node_quit(handler): + if handler.isalive() == True: + handler.sendline('exit\n') + handler.close() + +def config_get(handler): + + # Getting the config + handler.setwinsize(100, 120) + handler.sendline('cat /conf/config.xml | awk \'{print $0}\'\n') + #handler.sendline('cat `ls -rt /conf/backup/config-* | tail -1 `\n') + try: + handler.expect('', timeout = longtimeout) + except: + print('ERROR: error waiting for "#" prompt.') + node_quit(handler) + return False + config = handler.before.decode() + # Manipulating the config + config = re.sub('\r', '', config, flags=re.DOTALL) # Unix style + config = config + '\n'; + config = re.sub('.*<\?xml version=\"1.0\"\?>', '', config, flags=re.DOTALL) # Header + return config + +def config_put(handler): + while True: + try: + i = handler.expect('Do you want to set up VLANs now.*', timeout) + break + except: + return False + handler.sendline('') + handler.sendline('\n') + handler.sendline('mount -t cd9660 /dev/cd0 /mnt\n') + handler.sendline('cp /mnt/config.xml /conf/\n') + handler.sendline('exit\n') + while True: + try: + i = handler.expect('option:', timeout) + except: + return False + + return True + +def usage(): + print('Usage: %s ' %(sys.argv[0])); + print('Standard Options:'); + print('-a *Action can be:') + print(' - get: get the startup-configuration and push it to a file') + print(' - put: put the file as startup-configuration') + print('-f *File'); + print('-p *Console port'); + print('-t Timeout (default = %i)' %(timeout)); + print('* Mandatory option') + +def now(): + # Return current UNIX time in milliseconds + return int(round(time.time() * 1000)) + +def main(action, fiename, port): + try: + # Connect to the device + tmp = conntimeout + while (tmp > 0): + handler = pexpect.spawn('telnet 127.0.0.1 %i' %(port)) + time.sleep(0.1) + tmp = tmp - 0.1 + if handler.isalive() == True: + break + + if (handler.isalive() != True): + print('ERROR: cannot connect to port "%i".' %(port)) + node_quit(handler) + sys.exit(1) + + if action == 'get': + rc = node_login(handler) + if rc != True: + print('ERROR: failed to login.') + node_quit(handler) + sys.exit(1) + config = config_get(handler) + if config in [False, None]: + print('ERROR: failed to retrieve config.') + node_quit(handler) + sys.exit(1) + + try: + fd = open(filename, 'a') + fd.write(config) + fd.close() + except: + print('ERROR: cannot write config to file.') + node_quit(handler) + sys.exit(1) + elif action == 'put': + rc = config_put(handler) + if rc != True: + print('ERROR: failed to push config.') + node_quit(handler) + sys.exit(1) + + # Remove lock file + lock = '%s/.lock' %(os.path.dirname(filename)) + + if os.path.exists(lock): + os.remove(lock) + + # Mark as configured + configured = '%s/.configured' %(os.path.dirname(filename)) + if not os.path.exists(configured): + open(configured, 'a').close() + + node_quit(handler) + sys.exit(0) + + except Exception as e: + print('ERROR: got an exception') + print(type(e)) # the exception instance + print(e.args) # arguments stored in .args + print(e) # __str__ allows args to be printed directly, + node_quit(handler) + return False + +if __name__ == "__main__": + action = None + filename = None + port = None + + # Getting parameters from command line + try: + opts, args = getopt.getopt(sys.argv[1:], 'a:p:t:f:', ['action=', 'port=', 'timeout=', 'file=']) + except getopt.GetoptError as e: + usage() + sys.exit(3) + + for o, a in opts: + if o in ('-a', '--action'): + action = a + elif o in ('-f', '--file'): + filename = a + elif o in ('-p', '--port'): + try: + port = int(a) + except: + port = -1 + elif o in ('-t', '--timeout'): + try: + timeout = int(a) + except: + timeout = -1 + else: + print('ERROR: invalid parameter.') + + # Checking mandatory parameters + if action == None or port == None or filename == None: + usage() + print('ERROR: missing mandatory parameters.') + sys.exit(1) + if action not in ['get', 'put']: + usage() + print('ERROR: invalid action.') + sys.exit(1) + if timeout < 0: + usage() + print('ERROR: timeout must be 0 or higher.') + sys.exit(1) + if port < 0: + usage() + print('ERROR: port must be 32768 or higher.') + sys.exit(1) + if action == 'get' and os.path.exists(filename): + usage() + print('ERROR: destination file already exists.') + sys.exit(1) + if action == 'put' and not os.path.exists(filename): + usage() + print('ERROR: source file does not already exist.') + sys.exit(1) + if action == 'put': + try: + fd = open(filename, 'r') + config = fd.read() + fd.close() + except: + usage() + print('ERROR: cannot read from file.') + sys.exit(1) + + # Backgrounding the script + end_before = now() + timeout * 1000 + p = multiprocessing.Process(target=main, name="Main", args=(action, filename, port)) + p.start() + + while (p.is_alive() and now() < end_before): + # Waiting for the child process to end + time.sleep(1) + + if p.is_alive(): + # Timeout occurred + print('ERROR: timeout occurred.') + p.terminate() + sys.exit(127) + + if p.exitcode != 0: + sys.exit(127) + + sys.exit(0) diff --git a/html/templates/intel/linux-PacketFence.yml b/html/templates/intel/linux-PacketFence.yml new file mode 100644 index 0000000..246dbc3 --- /dev/null +++ b/html/templates/intel/linux-PacketFence.yml @@ -0,0 +1,41 @@ +# Copyright (c) 2016, Andrea Dainese +# Copyright (c) 2018, Alain Degreffe +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the UNetLab Ltd nor the name of EVE-NG Ltd nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--- +type: qemu +description: PacketFence +name: PacketFence +cpulimit: 1 +icon: Server.png +cpu: 4 +ram: 8192 +ethernet: 4 +console: vnc +shutdown: 1 +qemu_arch: x86_64 +qemu_version: 2.12.0 +qemu_nic: virtio-net-pci +qemu_options: -machine type=pc,accel=kvm -vga virtio -usbdevice tablet -boot order=cd +... diff --git a/html/templates/intel/linux-netem.yml b/html/templates/intel/linux-netem.yml new file mode 100644 index 0000000..a27b1d4 --- /dev/null +++ b/html/templates/intel/linux-netem.yml @@ -0,0 +1,41 @@ +# Copyright (c) 2016, Andrea Dainese +# Copyright (c) 2018, Alain Degreffe +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the UNetLab Ltd nor the name of EVE-NG Ltd nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--- +type: qemu +description: NetEM +name: NetEM +cpulimit: 1 +icon: Server.png +cpu: 1 +ram: 1024 +ethernet: 2 +console: vnc +shutdown: 1 +qemu_arch: x86_64 +qemu_version: 2.12.0 +qemu_nic: virtio-net-pci +qemu_options: -machine type=pc,accel=kvm -vga virtio -usbdevice tablet -boot order=cd +... diff --git a/html/templates/intel/opnsense.yml b/html/templates/intel/opnsense.yml new file mode 100644 index 0000000..26185c2 --- /dev/null +++ b/html/templates/intel/opnsense.yml @@ -0,0 +1,43 @@ +# Copyright (c) 2016, Andrea Dainese +# Copyright (c) 2018, Alain Degreffe +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the UNetLab Ltd nor the name of EVE-NG Ltd nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--- +type: qemu +config_script: config_opnsense.py +description: OPNsense +name: opnsense +cpulimit: 1 +icon: Firewall.png +cpu: 1 +ram: 2048 +ethernet: 4 +eth_format: vtnet{0} +console: vnc +qemu_arch: x86_64 +qemu_version: 2.12.0 +qemu_nic: virtio-net-pci +qemu_options: -machine type=pc,accel=kvm -nographic -usbdevice tablet -boot order=dc + -serial mon:stdio +... diff --git a/html/templates/intel/versafvnf20.yml b/html/templates/intel/versafvnf20.yml new file mode 100644 index 0000000..7db1b74 --- /dev/null +++ b/html/templates/intel/versafvnf20.yml @@ -0,0 +1,44 @@ +# Copyright (c) 2016, Andrea Dainese +# Copyright (c) 2019, Alain Degreffe +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the UNetLab Ltd nor the name of EVE-NG Ltd nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--- +type: qemu +description: Versa FlexVNF +name: vFlexVNF +cpulimit: 1 +icon: versaflex.png +cpu: 2 +ram: 4096 +ethernet: 8 +eth_name: +- eth-0/0 +eth_format: vni-0/{0} +console: telnet +shutdown: 1 +qemu_arch: x86_64 +qemu_version: 2.12.0 +qemu_nic: virtio-net-pci +qemu_options: -machine type=pc,accel=kvm -vga std -usbdevice tablet -boot order=dc -cpu host +... diff --git a/html/templates/intel/win.yml b/html/templates/intel/win.yml new file mode 100644 index 0000000..c3dd534 --- /dev/null +++ b/html/templates/intel/win.yml @@ -0,0 +1,41 @@ +# Copyright (c) 2016, Andrea Dainese +# Copyright (c) 2018, Alain Degreffe +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the UNetLab Ltd nor the name of EVE-NG Ltd nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--- +type: qemu +description: Windows +name: Win +cpulimit: 1 +icon: Desktop.png +cpu: 1 +ram: 4096 +ethernet: 1 +console: vnc +shutdown: 1 +qemu_arch: x86_64 +qemu_version: 4.1.0 +qemu_options: -machine type=pc,accel=kvm -cpu host,+pcid,+kvm_pv_unhalt,+kvm_pv_eoi,hv_spinlocks=0x1fff,hv_vapic,hv_time,hv_reset,hv_vpindex,hv_runtime,hv_relaxed,hv_synic,hv_stimer + -vga std -usbdevice tablet -boot order=cd -drive file=/opt/qemu/share/qemu/virtio-win-drivers.img,index=1,if=floppy,readonly +... diff --git a/html/templates/intel/winserver.yml b/html/templates/intel/winserver.yml new file mode 100644 index 0000000..1755c33 --- /dev/null +++ b/html/templates/intel/winserver.yml @@ -0,0 +1,40 @@ +# Copyright (c) 2016, Andrea Dainese +# Copyright (c) 2018, Alain Degreffe +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the UNetLab Ltd nor the name of EVE-NG Ltd nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--- +type: qemu +description: Windows Server +name: Winserver +cpulimit: 1 +icon: Server.png +cpu: 1 +ram: 8192 +ethernet: 1 +console: vnc +shutdown: 1 +qemu_arch: x86_64 +qemu_version: 4.1.0 +qemu_options: -machine type=pc,accel=kvm -cpu host,+fsgsbase -vga std -usbdevice tablet -boot order=dc -drive file=/opt/qemu/share/qemu/virtio-win-drivers.img,index=1,if=floppy,readonly +...