Skip to content

Commit

Permalink
Merge pull request #21 from klementng/dev
Browse files Browse the repository at this point in the history
Bugfixes & Dependencies version update
  • Loading branch information
klementng committed Jun 19, 2024
2 parents 4dcb56c + 460e099 commit 8062bc8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ _Using source code_
Additional Options:

```text
usage: main.py [-h] [--config CONFIG] [--clean] [--nogui] [--log_level LOG_LEVEL]
usage: main.py [-h] [--config CONFIG] [--clean] [--export] [--nogui] [--log_level LOG_LEVEL]
Wireguard over wstunnel
Expand All @@ -70,7 +70,8 @@ options:
--config CONFIG, -c CONFIG
path to program config
--clean clean wireguard tunnel that are not properly stopped
--nogui start with no gui interface
--export export wireguard config and exit
--nogui start with no gui
--log_level LOG_LEVEL
set logging level
```
Expand Down
19 changes: 8 additions & 11 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ def start(self):
self.log.critical(
"Unable to start wstunnel. Process return a status code of: %s. %s",
self.process.returncode,
self.process.stderr.read()
self.process.stderr.read(),
)
return False

def _poll_is_stopped(self, timeout, poll_interval=0.05):
def _poll_is_stopped_for(self, timeout, poll_interval=0.05):

end = time.time() + timeout
while time.time() < end:
Expand All @@ -230,25 +230,22 @@ def stop(self):
self.log.info("Stopping...")

if platform.system() == "Windows":
self.log.info("Stopping using CTRL_C_EVENT")
self.process.send_signal(signal.CTRL_C_EVENT)

if not self._poll_is_stopped(3):
self.log.info("Stopping using CTRL_BREAK_EVENT")
self.process.send_signal(signal.CTRL_BREAK_EVENT)
self.log.info("Stopping using CTRL_BREAK_EVENT")
self.process.send_signal(signal.CTRL_BREAK_EVENT)

else:
self.log.info("Stopping using SIGTERM")
self.process.terminate()

if not self._poll_is_stopped(3):
if not self._poll_is_stopped_for(3):
self.log.info("Stopping using SIGKILL")

if platform.system() == "Windows":
self.process.kill()
else:
os.killpg(os.getpgid(self.process.pid), signal.SIGKILL) # type: ignore

if self._poll_is_stopped(3):
if self._poll_is_stopped_for(3):
self.log.info("Stopped!")
return True
else:
Expand Down Expand Up @@ -431,7 +428,7 @@ def start(self):

if status.returncode == 0:
self.log.info("Started wireguard!")
return self.is_running
return True
else:
self.log.critical(
f"Unable to start wireguard. Program return status code of: {status.returncode}"
Expand Down
1 change: 0 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import tkinter as tk

import pystray
from PIL import Image

Expand Down
9 changes: 8 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,21 @@ def cleanup():
)

parser.add_argument("--log_level", help="set logging level", default="INFO")
parser.add_argument("--log_file", help="set logfile path", default="output.log")
args = parser.parse_args()

logging.root.setLevel(args.log_level)

if args.log_file != "":
fn = logging.FileHandler(args.log_file)
fn.setFormatter(logging.Formatter("%(levelname)s - %(name)s - %(message)s"))
logging.root.addHandler(fn)

helper.elevate_user()

try:

if args.nogui is False:
if args.nogui is False and args.export is False:
root = CoreGUI(helper.get_assets_path("assets/icon.png"))

stop_event = threading.Event()
Expand All @@ -241,3 +247,4 @@ def cleanup():

finally:
cleanup()
time.sleep(1)
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pillow==10.2.0
pillow==10.3.0
psutil==5.9.8
pystray==0.19.5
PyYAML==6.0.1
requests==2.31.0
requests==2.32.3
safe_exit==0.1.2
wgconfig==1.0.1
wgconfig==1.0.2

0 comments on commit 8062bc8

Please sign in to comment.