Skip to content

feat: long-run prod patch with default IP check #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/strategies/eye/picamera_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ def get_frame(self) -> numpy.ndarray:
logger.error(
"An error occurred while capturing the frame: %s", error)
raise RuntimeError from error
return cv2.rotate(frame,
cv2.ROTATE_90_COUNTERCLOCKWISE)
return frame
13 changes: 11 additions & 2 deletions core/strategies/wifi/ipaddress_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
The strategy which searches for IP addresses.
"""
from core.strategies.wifi.base_wifi_strategy import BaseWiFiStrategy
from core.utils.datatypes import WiFiStrategyResult
from core.utils.datatypes import ConnectedDeviceResult, WiFiStrategyResult
from core.utils.logger import get_logger
from core.utils.program_launcher import PingCommands, run_program
from core.utils.program_launcher import ArpScanCommands, PingCommands, run_program

# Add logging support.
logger = get_logger(__name__)
Expand Down Expand Up @@ -37,3 +37,12 @@ def check_protectors(self) -> WiFiStrategyResult:
return WiFiStrategyResult(protector, True)
logger.debug("No protectors found.")
return WiFiStrategyResult(None, False)

# Internal methods
def _get_all_connected(self) -> list[ConnectedDeviceResult]:
"""This method returns a list of addresses of the clients connected to the network."""
output = run_program(ArpScanCommands.GET_CONNECTED_IP_ADDRESSES)
ip_addrs = output.split('\n')
ip_addrs = ip_addrs[:-1]
logger.debug("Connected devices: %s", str(ip_addrs))
return [ConnectedDeviceResult(mac_addr.upper()) for mac_addr in ip_addrs]
4 changes: 3 additions & 1 deletion core/utils/program_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from enum import Enum


class ICommand(Enum, str):
class ICommand(str, Enum):
"""Interface for program commands."""


Expand All @@ -15,6 +15,8 @@ class ArpScanCommands(ICommand):
INSTALL_PROGRAM = "sudo apt-get install arp-scan"
GET_CONNECTED_MAC_ADDRESSES = "sudo arp-scan --localnet "\
"| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'"
GET_CONNECTED_IP_ADDRESSES = "sudo arp-scan --localnet "\
"| grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'"


class PingCommands(ICommand):
Expand Down
4 changes: 2 additions & 2 deletions hss.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from core.strategies.eye.picamera_strategy import PiCameraStrategy
from core.strategies.notifier.telegram_strategy import TelegramStrategy
from core.strategies.notifier.whatsapp_strategy import WhatsappStrategy
from core.strategies.wifi.admin_panel_strategy import AdminPanelStrategy
from core.strategies.wifi.ipaddress_strategy import IpAddressStrategy
from core.utils.datatypes import Protector, TelegramReciever
from core.utils.fileio_adaptor import upload_to_fileio

Expand Down Expand Up @@ -44,7 +44,7 @@ def main():
reciever['chat_id']))

# Create a Protector within IpAddressStrategy.
network_strategy = AdminPanelStrategy(strategy_config['admin_panel_strategy'])
network_strategy = IpAddressStrategy()
for protector in config['protectors']:
network_strategy.add_protector(Protector(protector['name'],
protector['address']))
Expand Down
Loading