Merge branch 'develop' into coretk-enhance/error-dialog
This commit is contained in:
commit
80f47a5d4c
22 changed files with 599 additions and 343 deletions
|
@ -527,6 +527,10 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
"%s handling message:\n%s", threading.currentThread().getName(), message
|
||||
)
|
||||
|
||||
# provide to sdt, if enabled
|
||||
if self.session and self.session.sdt.is_enabled():
|
||||
self.session.sdt.handle_distributed(message)
|
||||
|
||||
if message.message_type not in self.message_handlers:
|
||||
logging.error("no handler for message type: %s", message.type_str())
|
||||
return
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
import netaddr
|
||||
|
||||
from core.config import Configuration
|
||||
from core.configservice.base import ConfigService, ConfigServiceMode
|
||||
from core.emulator.enumerations import ConfigDataTypes
|
||||
|
||||
GROUP_NAME = "Security"
|
||||
|
||||
|
@ -16,11 +20,30 @@ class VpnClient(ConfigService):
|
|||
validate = ["pidof openvpn"]
|
||||
shutdown = ["killall openvpn"]
|
||||
validation_mode = ConfigServiceMode.BLOCKING
|
||||
default_configs = []
|
||||
default_configs = [
|
||||
Configuration(
|
||||
_id="keydir",
|
||||
_type=ConfigDataTypes.STRING,
|
||||
label="Key Dir",
|
||||
default="/etc/core/keys",
|
||||
),
|
||||
Configuration(
|
||||
_id="keyname",
|
||||
_type=ConfigDataTypes.STRING,
|
||||
label="Key Name",
|
||||
default="client1",
|
||||
),
|
||||
Configuration(
|
||||
_id="server",
|
||||
_type=ConfigDataTypes.STRING,
|
||||
label="Server",
|
||||
default="10.0.2.10",
|
||||
),
|
||||
]
|
||||
modes = {}
|
||||
|
||||
|
||||
class VPNServer(ConfigService):
|
||||
class VpnServer(ConfigService):
|
||||
name = "VPNServer"
|
||||
group = GROUP_NAME
|
||||
directories = []
|
||||
|
@ -31,9 +54,39 @@ class VPNServer(ConfigService):
|
|||
validate = ["pidof openvpn"]
|
||||
shutdown = ["killall openvpn"]
|
||||
validation_mode = ConfigServiceMode.BLOCKING
|
||||
default_configs = []
|
||||
default_configs = [
|
||||
Configuration(
|
||||
_id="keydir",
|
||||
_type=ConfigDataTypes.STRING,
|
||||
label="Key Dir",
|
||||
default="/etc/core/keys",
|
||||
),
|
||||
Configuration(
|
||||
_id="keyname",
|
||||
_type=ConfigDataTypes.STRING,
|
||||
label="Key Name",
|
||||
default="server",
|
||||
),
|
||||
Configuration(
|
||||
_id="subnet",
|
||||
_type=ConfigDataTypes.STRING,
|
||||
label="Subnet",
|
||||
default="10.0.200.0",
|
||||
),
|
||||
]
|
||||
modes = {}
|
||||
|
||||
def data(self) -> Dict[str, Any]:
|
||||
address = None
|
||||
for ifc in self.node.netifs():
|
||||
if getattr(ifc, "control", False):
|
||||
continue
|
||||
for x in ifc.addrlist:
|
||||
addr = x.split("/")[0]
|
||||
if netaddr.valid_ipv4(addr):
|
||||
address = addr
|
||||
return dict(address=address)
|
||||
|
||||
|
||||
class IPsec(ConfigService):
|
||||
name = "IPsec"
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
# OpenVPN software and a virtual TUN/TAP device.
|
||||
|
||||
# directory containing the certificate and key described below
|
||||
keydir=/etc/core/keys
|
||||
keydir=${config["keydir"]}
|
||||
|
||||
# the name used for a "$keyname.crt" certificate and "$keyname.key" private key.
|
||||
keyname=client1
|
||||
keyname=${config["keyname"]}
|
||||
|
||||
# the public IP address of the VPN server this client should connect with
|
||||
vpnserver="10.0.2.10"
|
||||
vpnserver=${config["server"]}
|
||||
|
||||
# optional next hop for adding a static route to reach the VPN server
|
||||
nexthop="10.0.1.1"
|
||||
#nexthop="10.0.1.1"
|
||||
|
||||
# --------- END CUSTOMIZATION --------
|
||||
|
||||
|
|
|
@ -7,29 +7,29 @@
|
|||
|
||||
# directory containing the certificate and key described below, in addition to
|
||||
# a CA certificate and DH key
|
||||
keydir=/etc/core/keys
|
||||
keydir=${config["keydir"]}
|
||||
|
||||
# the name used for a "$keyname.crt" certificate and "$keyname.key" private key.
|
||||
keyname=server2
|
||||
keyname=${config["keyname"]}
|
||||
|
||||
# the VPN subnet address from which the client VPN IP (for the TUN/TAP)
|
||||
# will be allocated
|
||||
vpnsubnet=10.0.200.0
|
||||
vpnsubnet=${config["subnet"]}
|
||||
|
||||
# public IP address of this vpn server (same as VPNClient vpnserver= setting)
|
||||
vpnserver=10.0.2.10
|
||||
vpnserver=${address}
|
||||
|
||||
# optional list of private subnets reachable behind this VPN server
|
||||
# each subnet and next hop is separated by a space
|
||||
# "<subnet1>,<nexthop1> <subnet2>,<nexthop2> ..."
|
||||
privatenets="10.0.11.0,10.0.10.1 10.0.12.0,10.0.10.1"
|
||||
#privatenets="10.0.11.0,10.0.10.1 10.0.12.0,10.0.10.1"
|
||||
|
||||
# optional list of VPN clients, for statically assigning IP addresses to
|
||||
# clients; also, an optional client subnet can be specified for adding static
|
||||
# routes via the client
|
||||
# Note: VPN addresses x.x.x.0-3 are reserved
|
||||
# "<keyname>,<vpnIP>,<subnetIP> <keyname>,<vpnIP>,<subnetIP> ..."
|
||||
vpnclients="client1KeyFilename,10.0.200.5,10.0.0.0 client2KeyFilename,,"
|
||||
#vpnclients="client1KeyFilename,10.0.200.5,10.0.0.0 client2KeyFilename,,"
|
||||
|
||||
# NOTE: you may need to enable the StaticRoutes service on nodes within the
|
||||
# private subnet, in order to have routes back to the client.
|
||||
|
@ -73,7 +73,7 @@ cat << EOF
|
|||
# openvpn server config
|
||||
local $vpnserver
|
||||
server $vpnsubnet 255.255.255.0
|
||||
push redirect-gateway def1
|
||||
push "redirect-gateway def1"
|
||||
EOF
|
||||
)> $PWD/server.conf
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ def check_directory():
|
|||
},
|
||||
"servers": [{"name": "example", "address": "127.0.0.1", "port": 50051}],
|
||||
"nodes": [],
|
||||
"recentfiles": [],
|
||||
"observers": [{"name": "hello", "cmd": "echo hello"}],
|
||||
}
|
||||
save(config)
|
||||
|
|
|
@ -24,6 +24,8 @@ from core.gui.dialogs.sessions import SessionsDialog
|
|||
from core.gui.dialogs.throughput import ThroughputDialog
|
||||
from core.gui.task import BackgroundTask
|
||||
|
||||
MAX_FILES = 3
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
@ -86,6 +88,7 @@ class MenuAction:
|
|||
defaultextension=".xml",
|
||||
)
|
||||
if file_path:
|
||||
self.add_recent_file_to_gui_config(file_path)
|
||||
self.app.core.save_xml(file_path)
|
||||
|
||||
def file_open_xml(self, event: tk.Event = None):
|
||||
|
@ -101,6 +104,7 @@ class MenuAction:
|
|||
|
||||
def open_xml_task(self, filename):
|
||||
if filename:
|
||||
self.add_recent_file_to_gui_config(filename)
|
||||
self.app.core.xml_file = filename
|
||||
self.app.core.xml_dir = str(os.path.dirname(filename))
|
||||
self.prompt_save_running_session()
|
||||
|
@ -170,3 +174,21 @@ class MenuAction:
|
|||
def config_throughput(self):
|
||||
dialog = ThroughputDialog(self.app, self.app)
|
||||
dialog.show()
|
||||
|
||||
def add_recent_file_to_gui_config(self, file_path):
|
||||
recent_files = self.app.guiconfig["recentfiles"]
|
||||
num_files = len(recent_files)
|
||||
if num_files == 0:
|
||||
recent_files.insert(0, file_path)
|
||||
elif 0 < num_files <= MAX_FILES:
|
||||
if file_path in recent_files:
|
||||
recent_files.remove(file_path)
|
||||
recent_files.insert(0, file_path)
|
||||
else:
|
||||
if num_files == MAX_FILES:
|
||||
recent_files.pop()
|
||||
recent_files.insert(0, file_path)
|
||||
else:
|
||||
logging.error("unexpected number of recent files")
|
||||
self.app.save_config()
|
||||
self.app.menubar.update_recent_files()
|
||||
|
|
|
@ -24,6 +24,7 @@ class Menubar(tk.Menu):
|
|||
self.master.config(menu=self)
|
||||
self.app = app
|
||||
self.menuaction = action.MenuAction(app, master)
|
||||
self.recent_menu = None
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
|
@ -58,9 +59,12 @@ class Menubar(tk.Menu):
|
|||
menu.add_command(label="Reload", underline=0, state=tk.DISABLED)
|
||||
self.app.bind_all("<Control-s>", self.save)
|
||||
|
||||
# some hard code values for testing
|
||||
recent = tk.Menu(menu)
|
||||
menu.add_cascade(label="Recent files", menu=recent)
|
||||
self.recent_menu = tk.Menu(menu)
|
||||
for i in self.app.guiconfig["recentfiles"]:
|
||||
self.recent_menu.add_command(
|
||||
label=i, command=partial(self.open_recent_files, i)
|
||||
)
|
||||
menu.add_cascade(label="Recent files", menu=self.recent_menu)
|
||||
menu.add_separator()
|
||||
menu.add_command(label="Export Python script...", state=tk.DISABLED)
|
||||
menu.add_command(label="Execute XML or Python script...", state=tk.DISABLED)
|
||||
|
@ -422,7 +426,14 @@ class Menubar(tk.Menu):
|
|||
else:
|
||||
logging.warning("File does not exist %s", filename)
|
||||
|
||||
def save(self):
|
||||
def update_recent_files(self):
|
||||
self.recent_menu.delete(0, tk.END)
|
||||
for i in self.app.guiconfig["recentfiles"]:
|
||||
self.recent_menu.add_command(
|
||||
label=i, command=partial(self.open_recent_files, i)
|
||||
)
|
||||
|
||||
def save(self, event=None):
|
||||
xml_file = self.app.core.xml_file
|
||||
if xml_file:
|
||||
self.app.core.save_xml(xml_file)
|
||||
|
|
|
@ -242,8 +242,8 @@ class Sdt:
|
|||
if self.sock is None:
|
||||
return False
|
||||
try:
|
||||
logging.info("sdt: %s", cmdstr)
|
||||
self.sock.sendall(f"{cmdstr}\n")
|
||||
cmd = f"{cmdstr}\n".encode()
|
||||
self.sock.sendall(cmd)
|
||||
return True
|
||||
except IOError:
|
||||
logging.exception("SDT connection error")
|
||||
|
|
|
@ -13,13 +13,13 @@ keyname=client1
|
|||
vpnserver="10.0.2.10"
|
||||
|
||||
# optional next hop for adding a static route to reach the VPN server
|
||||
nexthop="10.0.1.1"
|
||||
#nexthop="10.0.1.1"
|
||||
|
||||
# --------- END CUSTOMIZATION --------
|
||||
|
||||
# validate addresses
|
||||
if [ "$(dpkg -l | grep " sipcalc ")" = "" ]; then
|
||||
echo "WARNING: ip validation disabled because package sipcalc not installed
|
||||
echo "WARNING: ip validation disabled because package sipcalc not installed
|
||||
" > $PWD/vpnclient.log
|
||||
else
|
||||
if [ "$(sipcalc "$vpnserver" "$nexthop" | grep ERR)" != "" ]; then
|
||||
|
@ -59,5 +59,5 @@ verb 4
|
|||
daemon
|
||||
EOF
|
||||
) > client.conf
|
||||
|
||||
|
||||
openvpn --config client.conf
|
||||
|
|
|
@ -12,7 +12,7 @@ keydir=/etc/core/keys
|
|||
# the name used for a "$keyname.crt" certificate and "$keyname.key" private key.
|
||||
keyname=server2
|
||||
|
||||
# the VPN subnet address from which the client VPN IP (for the TUN/TAP)
|
||||
# the VPN subnet address from which the client VPN IP (for the TUN/TAP)
|
||||
# will be allocated
|
||||
vpnsubnet=10.0.200.0
|
||||
|
||||
|
@ -22,18 +22,18 @@ vpnserver=10.0.2.10
|
|||
# optional list of private subnets reachable behind this VPN server
|
||||
# each subnet and next hop is separated by a space
|
||||
# "<subnet1>,<nexthop1> <subnet2>,<nexthop2> ..."
|
||||
privatenets="10.0.11.0,10.0.10.1 10.0.12.0,10.0.10.1"
|
||||
#privatenets="10.0.11.0,10.0.10.1 10.0.12.0,10.0.10.1"
|
||||
|
||||
# optional list of VPN clients, for statically assigning IP addresses to
|
||||
# clients; also, an optional client subnet can be specified for adding static
|
||||
# routes via the client
|
||||
# Note: VPN addresses x.x.x.0-3 are reserved
|
||||
# "<keyname>,<vpnIP>,<subnetIP> <keyname>,<vpnIP>,<subnetIP> ..."
|
||||
vpnclients="client1KeyFilename,10.0.200.5,10.0.0.0 client2KeyFilename,,"
|
||||
#vpnclients="client1KeyFilename,10.0.200.5,10.0.0.0 client2KeyFilename,,"
|
||||
|
||||
# NOTE: you may need to enable the StaticRoutes service on nodes within the
|
||||
# private subnet, in order to have routes back to the client.
|
||||
# /sbin/ip ro add <vpnsubnet>/24 via <vpnServerRemoteInterface>
|
||||
# /sbin/ip ro add <vpnsubnet>/24 via <vpnServerRemoteInterface>
|
||||
# /sbin/ip ro add <vpnClientSubnet>/24 via <vpnServerRemoteInterface>
|
||||
|
||||
# -------- END CUSTOMIZATION --------
|
||||
|
@ -60,7 +60,7 @@ else
|
|||
$vpnsubnet or $vpnserver " >> $PWD/vpnserver.log
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# create client vpn ip pool file
|
||||
(
|
||||
cat << EOF
|
||||
|
@ -73,7 +73,7 @@ cat << EOF
|
|||
# openvpn server config
|
||||
local $vpnserver
|
||||
server $vpnsubnet 255.255.255.0
|
||||
push redirect-gateway def1
|
||||
push "redirect-gateway def1"
|
||||
EOF
|
||||
)> $PWD/server.conf
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue