-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Dhi13man/feature/global-protect
Release v0.0.2 | Global Protect Integration, data model decoupling and Zope Interfaces removal
- Loading branch information
Showing
25 changed files
with
726 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Releases | ||
|
||
## [0.0.2] - 16th June 2024 | ||
|
||
1. Integrated one-step [Palo Alto Global Protect](https://docs.paloaltonetworks.com/globalprotect) VPN connection/disconnection. | ||
2. Decoupled VPN Config and VPN Data Models for future flexibility. | ||
3. Removed unnecessary Zope Interfaces dependency as it does not seem worth the maintenance effort. | ||
4. Upgraded `pyinstaller` dependency to leave vulnerable version. | ||
|
||
## [0.0.1] - 25th March 2023 | ||
|
||
Initial implementation of the base features of the auto_vpn_connect script: | ||
|
||
1. Connect/Disconnect and set up Auto-Connect to Pritunl VPNs. | ||
2. Save PINs, Tokens and auto fetch TOTPs using pyotp by providing the TOTP URL to minimise the effort to connect to VPNs, after a one-time setup. | ||
3. Set up customisable JSON VPN profiles and configs to customise where various CLIs and dependencies might be located | ||
4. Extensibility to add other VPN clients with ease. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pyotp==2.8.0 | ||
zope.interface==5.5.2 | ||
pyinstaller==5.11.0 | ||
pyinstaller==6.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
''' | ||
Abstract class for VPN data. | ||
''' | ||
|
||
from abc import ABC | ||
|
||
from src.enums.vpn_type import VpnType, VpnTypeVisitor, T | ||
|
||
|
||
class AbstractVpnConfig(ABC): | ||
''' | ||
Abstract class for VPN data. | ||
''' | ||
|
||
_vpn_type_key: str = 'vpn_type' | ||
_vpn_type: VpnType = VpnType.NONE | ||
|
||
def get_vpn_type(self) -> VpnType: | ||
''' | ||
Get the type of the VPN. | ||
Returns: | ||
VpnType: Type of the VPN | ||
''' | ||
return AbstractVpnConfig._vpn_type | ||
|
||
def visit(self, visitor: 'VpnTypeVisitor[T]') -> T: | ||
''' | ||
Visit the VPN with a VpnTypeVisitor. | ||
Args: | ||
visitor (VpnTypeVisitor): Visitor to visit the Pritunl VPN with | ||
''' | ||
return visitor.visit_none() | ||
|
||
def to_json(self) -> dict: | ||
''' | ||
Convert the VPN data to a JSON string. | ||
Returns: | ||
str: JSON string of the VPN data | ||
''' | ||
return {AbstractVpnConfig._vpn_type_key: self.get_vpn_type().value} | ||
|
||
@staticmethod | ||
def from_json(json: dict) -> 'AbstractVpnConfig': | ||
''' | ||
Create a VPN data object from a JSON string. | ||
Args: | ||
json (dict): JSON string of the VPN data | ||
''' | ||
vpn_type: VpnType = VpnType(json.get(AbstractVpnConfig._vpn_type_key, VpnType.NONE)) | ||
if vpn_type != AbstractVpnConfig._vpn_type: | ||
raise ValueError(f'Invalid VPN type {vpn_type}') | ||
return AbstractVpnConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
''' | ||
Abstract class for VPN data. | ||
''' | ||
|
||
from src.enums.vpn_type import VpnType, VpnTypeVisitor, T | ||
from src.models.vpn_config.abstract_vpn_config import AbstractVpnConfig | ||
|
||
class GlobalProtectVpnConfig(AbstractVpnConfig): | ||
''' | ||
Abstract class for VPN data. | ||
Attributes: | ||
vpn_id (str): ID of the VPN | ||
''' | ||
|
||
_vpn_type: VpnType = VpnType.GLOBAL_PROTECT | ||
_service_load_command_key: str = "service_load_command" | ||
_service_unload_command_key: str = "service_unload_command" | ||
_process_kill_command_key: str = "process_kill_command" | ||
_default_service_load_command: str = ( | ||
"launchctl load /Library/LaunchAgents/com.paloaltonetworks.gp.pangpa.plist" | ||
) | ||
_default_service_unload_command: str = ( | ||
"launchctl unload /Library/LaunchAgents/com.paloaltonetworks.gp.pangpa.plist" | ||
) | ||
_default_process_kill_command: str = "pkill -9 -f GlobalProtect" | ||
|
||
def __init__( | ||
self, | ||
service_load_command: str = _default_service_load_command, | ||
service_unload_command: str = _default_service_unload_command, | ||
process_kill_command: str = _default_process_kill_command | ||
): | ||
self.service_load_command: str = service_load_command | ||
self.service_unload_command: str = service_unload_command | ||
self.process_kill_command: str = process_kill_command | ||
|
||
def get_vpn_type(self) -> VpnType: | ||
''' | ||
Get the type of the VPN. | ||
Returns: | ||
VpnType: Type of the VPN | ||
''' | ||
return GlobalProtectVpnConfig._vpn_type | ||
|
||
def visit(self, visitor: 'VpnTypeVisitor[T]') -> T: | ||
''' | ||
Visit the VPN with a VpnTypeVisitor. | ||
Args: | ||
visitor (VpnTypeVisitor): Visitor to visit the Pritunl VPN with | ||
''' | ||
return visitor.visit_global_protect() | ||
|
||
def to_json(self) -> dict: | ||
''' | ||
Convert the VPN data to a JSON string. | ||
Returns: | ||
str: JSON string of the VPN data | ||
''' | ||
return { | ||
GlobalProtectVpnConfig._vpn_type_key: self.get_vpn_type().value, | ||
GlobalProtectVpnConfig._service_load_command_key: self.service_load_command, | ||
GlobalProtectVpnConfig._service_unload_command_key: self.service_unload_command, | ||
GlobalProtectVpnConfig._process_kill_command_key: self.process_kill_command | ||
} | ||
|
||
@staticmethod | ||
def from_json(json: dict) -> 'GlobalProtectVpnConfig': | ||
''' | ||
Create a VPN data object from a JSON string. | ||
Args: | ||
json (dict): JSON string of the VPN data | ||
''' | ||
vpn_type: VpnType = VpnType( | ||
json.get(GlobalProtectVpnConfig._vpn_type_key, VpnType.GLOBAL_PROTECT) | ||
) | ||
if vpn_type != GlobalProtectVpnConfig._vpn_type: | ||
raise ValueError(f'Invalid VPN type {vpn_type}') | ||
return GlobalProtectVpnConfig( | ||
service_load_command=json.get(GlobalProtectVpnConfig._service_load_command_key), | ||
service_unload_command=json.get(GlobalProtectVpnConfig._service_unload_command_key), | ||
process_kill_command=json.get(GlobalProtectVpnConfig._process_kill_command_key) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
''' | ||
Abstract class for VPN data. | ||
''' | ||
|
||
from src.enums.vpn_type import VpnType, VpnTypeVisitor, T | ||
from src.models.vpn_config.abstract_vpn_config import AbstractVpnConfig | ||
|
||
class PritunlVpnConfig(AbstractVpnConfig): | ||
''' | ||
Abstract class for VPN data. | ||
Attributes: | ||
vpn_id (str): ID of the VPN | ||
''' | ||
|
||
_vpn_type: VpnType = VpnType.PRITUNL | ||
_cli_path_key: str = "cli_path" | ||
_default_cli_path: str = "/Applications/Pritunl.app/Contents/Resources/pritunl-client" | ||
|
||
def __init__(self, cli_path: str=_default_cli_path) -> None: | ||
self.cli_path = cli_path | ||
|
||
def get_vpn_type(self) -> VpnType: | ||
''' | ||
Get the type of the VPN. | ||
Returns: | ||
VpnType: Type of the VPN | ||
''' | ||
return PritunlVpnConfig._vpn_type | ||
|
||
def visit(self, visitor: 'VpnTypeVisitor[T]') -> T: | ||
''' | ||
Visit the VPN with a VpnTypeVisitor. | ||
Args: | ||
visitor (VpnTypeVisitor): Visitor to visit the Pritunl VPN with | ||
''' | ||
return visitor.visit_pritunl() | ||
|
||
def to_json(self) -> dict: | ||
''' | ||
Convert the VPN data to a JSON string. | ||
Returns: | ||
str: JSON string of the VPN data | ||
''' | ||
return { | ||
PritunlVpnConfig._vpn_type_key: self.get_vpn_type().value, | ||
PritunlVpnConfig._cli_path_key: self.cli_path | ||
} | ||
|
||
@staticmethod | ||
def from_json(json: dict) -> 'PritunlVpnConfig': | ||
''' | ||
Create a VPN data object from a JSON string. | ||
Args: | ||
json (dict): JSON string of the VPN data | ||
''' | ||
vpn_type: VpnType = VpnType(json.get(PritunlVpnConfig._vpn_type_key, VpnType.PRITUNL)) | ||
if vpn_type != PritunlVpnConfig._vpn_type: | ||
raise ValueError(f'Invalid VPN type {vpn_type}') | ||
return PritunlVpnConfig(cli_path=json.get(PritunlVpnConfig._cli_path_key)) |
Oops, something went wrong.