From 2dfd9673f9e9ef2caa749bbf78c9400ce6f56451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Avond?= Date: Fri, 6 Jun 2025 23:03:20 +0200 Subject: [PATCH 1/5] Modifications README --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dc2c336..4b8cba9 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,37 @@ # ssh_tunnel_wrapper + wrapper for opening web app using ssh tunnel Wrapper is a tool that users can run on their PC or laptop. It creates an SSH tunnel and opens the web app behind ssh in its window automatically. +## Linux To compile for Linux (Ubuntu), run: +```shell sudo apt-get install libpython3.12-dev - pip install pyinstaller - pyinstaller --enable-shared --onefile ssh_tunnel_wrapper.py +``` +## Windows -Windows: - +```powershell pyinstaller --hidden-import=babel --hidden-import=babel.numbers ssh_tunnel_wrapper.py +``` + +## Configuration -settings.ini format: +```settings.ini``` format: +```dosini [DEFAULT] ssh_host = ssh_host - ssh_user = ssh_user - local_port = local_port - remote_host = remote_host # internal IP address behind ssh - remote_port = remote_port # port of web app - ssh_private_key_path = /home/user1/.ssh/id_rsa +``` From 51f31d426fde89f661832bfbbd59e6a65c5cb15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Avond?= Date: Fri, 6 Jun 2025 23:04:25 +0200 Subject: [PATCH 2/5] Tests avec python-venv --- .gitignore | 1 + requirements.txt | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21d0b89 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ca450ea --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +PyQt5 +PyQtWebEngine +sshtunnel +Babel +paramiko \ No newline at end of file From f705679d9e86e1df6f4ef940bac7163766bf89d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Avond?= Date: Fri, 6 Jun 2025 23:07:44 +0200 Subject: [PATCH 3/5] Help avec Virtualenv --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b8cba9..8c04a64 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ wrapper for opening web app using ssh tunnel Wrapper is a tool that users can run on their PC or laptop. It creates an SSH tunnel and opens the web app behind ssh in its window automatically. -## Linux +## Pyinstaller + +### Linux To compile for Linux (Ubuntu), run: @@ -14,13 +16,22 @@ pip install pyinstaller pyinstaller --enable-shared --onefile ssh_tunnel_wrapper.py ``` -## Windows +### Windows ```powershell pyinstaller --hidden-import=babel --hidden-import=babel.numbers ssh_tunnel_wrapper.py ``` +## Python venv module + +```shell +cd ssh_tunnel_wrapper/ +python3 -m venv .venv/ +.venv/bin/activate +pip3 install -r requirements.txt +``` + ## Configuration ```settings.ini``` format: From 08445386342f95a7327535b5476847e1da86b024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Avond?= Date: Fri, 6 Jun 2025 23:14:44 +0200 Subject: [PATCH 4/5] Simplification en se basant sur le fichier ~/.ssh/config --- README.md | 13 ++++---- ssh_tunnel_wrapper.py | 74 +------------------------------------------ 2 files changed, 7 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 8c04a64..9f3f3e2 100644 --- a/README.md +++ b/README.md @@ -34,15 +34,14 @@ pip3 install -r requirements.txt ## Configuration -```settings.ini``` format: +Configuration is based on your ```~/.ssh/config``` file. ```dosini [DEFAULT] -ssh_host = ssh_host -ssh_user = ssh_user -local_port = local_port -remote_host = remote_host # internal IP address behind ssh -remote_port = remote_port # port of web app -ssh_private_key_path = /home/user1/.ssh/id_rsa +ssh_host = ssh_host # as defined in ssh_config +local_port = local_port # Port listened on 127.0.0.1 +remote_host = remote_host # internal IP address or hostname +remote_port = remote_port # port of web app + ``` diff --git a/ssh_tunnel_wrapper.py b/ssh_tunnel_wrapper.py index da86e01..17c52cc 100644 --- a/ssh_tunnel_wrapper.py +++ b/ssh_tunnel_wrapper.py @@ -23,36 +23,6 @@ def settings_check_alert(InformativeText): print(f"ssh tunnel wrapper | application version: {formatted_date}") exit(1) -def is_positive_integer(value): - try: - int_value = int(value) - if int_value > 0: - return True - else: - return False - except ValueError: - return False - -def is_valid_ip(ssh_host): - try: - ipaddress.ip_address(ssh_host) - return True - except ValueError: - return False - -def is_valid_private_key(path): - try: - key = paramiko.RSAKey(filename=path) - return True - except paramiko.SSHException: - return False - -def is_valid_unix_username(username): - if re.match(r'^[a-z][a-z0-9_-]{0,31}$', username): - return True - else: - return False - def format_date_now(): suffix = None now = datetime.now() @@ -91,54 +61,12 @@ def load_url(self): config.read('settings.ini') ssh_host = config.get('DEFAULT', 'ssh_host') -ssh_user = config.get('DEFAULT', 'ssh_user') local_port = config.get('DEFAULT', 'local_port') remote_host = config.get('DEFAULT', 'remote_host') remote_port = config.get('DEFAULT', 'remote_port') -ssh_private_key_path = config.get('DEFAULT', 'ssh_private_key_path') - -if ssh_host == 'ssh_host': - settings_check_alert(InformativeText = "The 'ssh_host' in file 'settings.ini' is not set!") -if ssh_user == 'ssh_user': - settings_check_alert(InformativeText = "The 'ssh_user' in file 'settings.ini' is not set!") -if local_port == 'local_port': - settings_check_alert(InformativeText = "The 'local_port' in file 'settings.ini' is not set!") -if remote_host == 'remote_host': - settings_check_alert(InformativeText = "The 'remote_host' in file 'settings.ini' is not set!") -if remote_port == 'remote_port': - settings_check_alert(InformativeText = "The 'remote_port' in file 'settings.ini' is not set!") -if ssh_private_key_path == 'ssh_private_key_path': - settings_check_alert(InformativeText = "The 'ssh_private_key_path' in file 'settings.ini' is not set!") - -if is_positive_integer(local_port): - local_port = int(local_port) -else: - settings_check_alert(InformativeText = "The 'local_port' in file 'settings.ini' must be positive integer!") - -if is_positive_integer(remote_port): - remote_port = int(remote_port) -else: - settings_check_alert(InformativeText = "The 'remote_port' in file 'settings.ini' must be positive integer!") - -if not is_valid_ip(ssh_host): - settings_check_alert(InformativeText = "The 'ssh_host' in file 'settings.ini' must be valid IP address!") - -if not is_valid_ip(remote_host): - settings_check_alert(InformativeText = "The 'remote_host' in file 'settings.ini' must be valid IP address!") - -if not os.path.isfile(ssh_private_key_path): - settings_check_alert(InformativeText = f"The file {ssh_private_key_path} does not exist!") - -if not is_valid_private_key(ssh_private_key_path): - settings_check_alert(InformativeText = f"The file {ssh_private_key_path} should be valid private ssh key!") - -if not is_valid_unix_username(ssh_user): - settings_check_alert(InformativeText = f"The 'ssh_user' should be valid unix username!") with SSHTunnelForwarder( - (ssh_host, 22), - ssh_username=ssh_user, - ssh_private_key=ssh_private_key_path, + ssh_host, remote_bind_address=(remote_host, remote_port), local_bind_address=('127.0.0.1', local_port) ) as tunnel: From b4c6db3cbd38b7378c093a2dccbd00e81d39036c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Avond?= Date: Fri, 6 Jun 2025 23:22:56 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Ne=20pas=20laisser=20le=20settings.ini=20da?= =?UTF-8?q?ns=20le=20d=C3=A9pot=20(dangereux=20pendant=20les=20tests)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.md | 2 ++ settings.ini | 7 ------- 3 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 settings.ini diff --git a/.gitignore b/.gitignore index 21d0b89..5b0fb39 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .venv/ +settings.ini \ No newline at end of file diff --git a/README.md b/README.md index 9f3f3e2..9e19619 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ pip3 install -r requirements.txt Configuration is based on your ```~/.ssh/config``` file. +Create file `settings.ini` + ```dosini [DEFAULT] diff --git a/settings.ini b/settings.ini deleted file mode 100644 index cc37ef7..0000000 --- a/settings.ini +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] -ssh_host = ssh_host -ssh_user = ssh_user -local_port = local_port -remote_host = remote_host -remote_port = remote_port -ssh_private_key_path = /home/user1/.ssh/id_rsa