Skip to content

Commit

Permalink
@mbridak Add trapping for bad ipv4 address
Browse files Browse the repository at this point in the history
  • Loading branch information
mbridak committed Nov 12, 2024
1 parent 7acee83 commit 9c2fc06
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
11 changes: 11 additions & 0 deletions not1mm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,19 @@ def keyPressEvent(self, event) -> None: # pylint: disable=invalid-name
Returns:
-------
None
Control
QWRTYIOPSFGHJLBNM,./;'[]//-
shift control
ABCDEFGHIJKLMNOPQRSTUVWXY
"""
modifier = event.modifiers()
# the_key = event.key()

# print(f"Modifier is {modifier=} Key is {the_key=}")

if (
event.key() == Qt.Key.Key_Equal
and modifier == Qt.KeyboardModifier.ControlModifier
Expand Down
38 changes: 36 additions & 2 deletions not1mm/lib/cat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ def __init__(self, interface: str, host: str, port: int) -> None:
}

if self.interface == "flrig":
target = f"http://{host}:{port}"
if not self.__check_sane_ip(self.host):
self.online = False
return

target = f"http://{self.host}:{self.port}"
logger.debug("%s", target)
self.server = xmlrpc.client.ServerProxy(target)
self.online = True
Expand All @@ -91,23 +95,44 @@ def __init__(self, interface: str, host: str, port: int) -> None:
ConnectionRefusedError,
xmlrpc.client.Fault,
http.client.BadStatusLine,
socket.error,
socket.gaierror,
):
self.online = False
elif self.interface == "rigctld":
if not self.__check_sane_ip(self.host):
self.online = False
return
self.__initialize_rigctrld()
elif self.interface == "fake":
self.online = True
logger.debug("Using Fake Rig")
return

def __check_sane_ip(self, ip: str) -> bool:
"""check if IP address look normal"""
x = ip.split()
if len(x) != 4:
return False
for y in x:
if not y.isnumeric():
return False
return True

def __initialize_rigctrld(self):
try:
self.rigctrlsocket = socket.socket()
self.rigctrlsocket.settimeout(0.2)
self.rigctrlsocket.connect((self.host, self.port))
logger.debug("Connected to rigctrld")
self.online = True
except (ConnectionRefusedError, TimeoutError, OSError) as exception:
except (
ConnectionRefusedError,
TimeoutError,
OSError,
socket.error,
socket.gaierror,
) as exception:
self.rigctrlsocket = None
self.online = False
logger.debug("%s", f"{exception}")
Expand Down Expand Up @@ -233,6 +258,7 @@ def __getvfo_flrig(self) -> str:
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug(f"{exception=}")
Expand Down Expand Up @@ -280,6 +306,7 @@ def __getmode_flrig(self) -> str:
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug("%s", f"{exception}")
Expand Down Expand Up @@ -329,6 +356,7 @@ def __getbw_flrig(self):
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug("getbw_flrig: %s", f"{exception}")
Expand Down Expand Up @@ -453,6 +481,7 @@ def __get_mode_list_flrig(self):
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug("%s", f"{exception}")
Expand Down Expand Up @@ -502,6 +531,7 @@ def __setvfo_flrig(self, freq: str) -> bool:
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug("setvfo_flrig: %s", f"{exception}")
Expand Down Expand Up @@ -547,6 +577,7 @@ def __setmode_flrig(self, mode: str) -> bool:
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug(f"{exception=}")
Expand Down Expand Up @@ -590,6 +621,7 @@ def __setpower_flrig(self, power):
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug("setpower_flrig: %s", f"{exception}")
Expand Down Expand Up @@ -648,6 +680,7 @@ def __ptt_on_flrig(self):
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug("%s", f"{exception}")
Expand Down Expand Up @@ -686,6 +719,7 @@ def __ptt_off_flrig(self):
http.client.BadStatusLine,
http.client.CannotSendRequest,
http.client.ResponseNotReady,
AttributeError,
) as exception:
self.online = False
logger.debug("%s", f"{exception}")
Expand Down

0 comments on commit 9c2fc06

Please sign in to comment.