Skip to content

Commit

Permalink
fixed regex and proc issue
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Mar 2, 2023
1 parent 9dced05 commit d16d894
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "vpnkillswitch"
version = "0.1.9"
version = "0.1.10"
authors = [
{ name="Good Boy", email="pythonic@rexbytes.com" },
]
Expand All @@ -22,7 +22,7 @@ classifiers = [
[project.urls]
"Homepage" = "https://github.com/RexBytes/vpnkillswitch"
"Bug Tracker" = "https://github.com/RexBytes/vpnkillswitch/issues"
"Download URL" ="https://github.com/RexBytes/vpnkillswitch/archive/refs/tags/v0.1.9.tar.gz"
"Download URL" ="https://github.com/RexBytes/vpnkillswitch/archive/refs/tags/v0.1.10.tar.gz"

[project.scripts]
vpnkillswitch = "vpnkillswitch:vpnkillswitch.vpnkillswitch"
Expand Down
30 changes: 19 additions & 11 deletions src/vpnkillswitch/systemipswitches.py
Expand Up @@ -39,7 +39,9 @@ def __init__(self):
self.systemctl = SystemCTL()
self.systemd = SystemD()

def switch_on(self, granular: bool = False, netclass: str = "C", interface: str = "tun+"):
def switch_on(
self, granular: bool = False, netclass: str = "C", interface: str = "tun+"
):
self.switch_flush()
self.switch_vpn(granular=granular, netclass=netclass, interface=interface)
self.switch_docker(granular=granular, interface=interface)
Expand Down Expand Up @@ -71,13 +73,15 @@ def switch_protect(self):
self.systembash.run_protect()
self.systemctl.protect_ctl_enable()

def switch_vpn(self, granular: bool = False, netclass: str = "C", interface: str = 'tun+'):
def switch_vpn(
self, granular: bool = False, netclass: str = "C", interface: str = "tun+"
):
self.systemd.openvpn(granular=granular, netclass=netclass, interface=interface)
self.systembash.run_vpn4()
self.systemctl.openvpn_ctl_enable()

def switch_docker(self, granular: bool = False, interface: str = "tun+"):
self.systemd.docker(granular,interface)
self.systemd.docker(granular, interface)
self.systembash.run_docker()
self.systemctl.docker_ctl_enable()

Expand Down Expand Up @@ -236,7 +240,9 @@ def synergy_off(self):
) = self.service_bash_text.synergy_off_text()
self.systemdfiles.writebash(synergy_off_bash_filepath, synergy_off_bashtext)

def openvpn(self, granular: bool = False, netclass: str = "C", interface: str = 'tun+'):
def openvpn(
self, granular: bool = False, netclass: str = "C", interface: str = "tun+"
):
vpn_service_filepath, vpn_servicetext = self.service_unit_text.openvpn()
if granular:
(
Expand All @@ -247,11 +253,13 @@ def openvpn(self, granular: bool = False, netclass: str = "C", interface: str =
(
vpn_bash_filepath,
vpn_bashtext,
) = self.service_bash_text.vpnkillswitch_text(netclass=netclass, interface=interface)
) = self.service_bash_text.vpnkillswitch_text(
netclass=netclass, interface=interface
)
self.systemdfiles.writebash(vpn_bash_filepath, vpn_bashtext)
self.systemdfiles.writeservice(vpn_service_filepath, vpn_servicetext)

def docker(self, granular: bool = False, interface: str = 'tun+'):
def docker(self, granular: bool = False, interface: str = "tun+"):
docker_service_filepath, docker_servicetext = self.service_unit_text.docker()
if granular:
(
Expand Down Expand Up @@ -444,7 +452,7 @@ def __init__(self):
function regex_build () {
escape_setting=$(escape_dots $1)
regex_result="^([^\S\\r\\n]|#|)+($escape_setting)([^\S\\r\\n]|[0-9]|#|[a-zA-Z])+$"
regex_result="^([^\S\\r\\n]|#|)+($escape_setting)([^\S\\r\\n]+=|=)([^\S\\r\\n]+[0-9]|[^\S\\r\\n]+|[0-9]|#|[a-zA-Z])+$"
echo $regex_result
}
Expand Down Expand Up @@ -488,12 +496,12 @@ def __init__(self):
}
function disable_proc_string () {
proc_string_disable=$1" 1"
proc_string_disable=$1"=1"
echo $proc_string_disable >> /etc/sysctl.conf
}
function enable_proc_string () {
proc_string_enable=$1" 0"
proc_string_enable=$1"=0"
echo $proc_string_enable >> /etc/sysctl.conf
}
Expand Down Expand Up @@ -652,7 +660,7 @@ def protect_text(self):
"""
return self.systemdfilepaths.protect_bash, text

def vpnkillswitch_text(self, netclass: str = "C", interface: str = 'tun+'):
def vpnkillswitch_text(self, netclass: str = "C", interface: str = "tun+"):
if netclass == "C":
netclassip = "192.168.0.0/16"
if netclass == "B":
Expand Down Expand Up @@ -753,7 +761,7 @@ def vpnkillswitch_g_text(self, netclass: str = "C"):
"""
return self.systemdfilepaths.vpn4_bash, text

def dockerkillswitch_text(self, interface: str = 'tun+'):
def dockerkillswitch_text(self, interface: str = "tun+"):
text = f"""#!/bin/bash
{self.bashfunctions}
{self.procfunctions}
Expand Down

0 comments on commit d16d894

Please sign in to comment.