From 143d5fd4701073820da1920de52871007ee6f91e Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Thu, 29 Jan 2026 16:36:19 +0100 Subject: [PATCH] implemented basic structure and check()-method --- src/sub/access.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/src/sub/access.sh b/src/sub/access.sh index 49efa7f..24978bd 100755 --- a/src/sub/access.sh +++ b/src/sub/access.sh @@ -1,4 +1,85 @@ #!/bin/bash -echo "currently not implemented" +allow_mac(){ + echo "Allowing $MAC" + exit 0 +} + +check(){ + if command -v iptables &>/dev/null + then + echo "iptables is installed. Check passed. Bye." + exit 0; + else + echo "Please install iptables." + while [[ -z "$HAD_BEST_SUCCESS" ]]; do + read -p "Install now? [y/N] " QUESTION + if [[ -z "$QUESTION" ]] || [[ "$QUESTION" = "n" ]] || [[ "$QUESTION" = "N" ]]; then + echo "Alright, bye." + exit 0; + fi + if [[ "$QUESTION" = "y" ]] || [[ "$QUESTION" = "Y" ]]; then + HAD_BEST_SUCCESS="true" + echo "Trying to install iptables..." + if command -v apt &>/dev/null + then + sudo apt update + sudo apt install iptables -y + echo "Attempted to install iptables. Please execute the check again. Bye." + exit 0; + fi + + if command -v dnf &>/dev/null + then + sudo dnf update + sudo dnf install iptables -y + echo "Attempted to install iptables. Please execute the check again. Bye." + exit 0; + fi + + if command -v pacman &>/dev/null + then + sudo pacman -S iptables + echo "Attempted to install iptables. Please execute the check again. Bye." + exit 0; + fi + fi + done + + + + fi +} + + +deny_mac(){ + echo "Denying $MAC" + exit 0 +} + +show_help(){ + echo "-- HELP --" + echo " -a AA:AA:AA:AA:AA:AA | Allow the access for the given mac-address" + echo " -d AA:AA:AA:AA:AA:AA | Deny the access for the given mac-address" + echo " -y | Answer all questions with yes" + echo " -h | Show this help text" + echo " -v | Get Version Info" + echo " -c | Check the usability of this tool" + exit 0 +} + +while getopts ":a:d:vhyc" opt; do + case $opt in + a) MAC="$OPTARG"; allow_mac ;; + d) MAC="$OPTARG"; deny_mac ;; + v) exit 0 ;; + c) check ;; + h) show_help ;; + y) ALWAYS_YES="1" ;; + \?) echo "Unknown option: -$OPTARG" >&2; exit 1 ;; + :) echo "Option -$OPTARG needs an argument" >&2; exit 1 ;; + esac +done + +echo "Nothing to do." exit 0 \ No newline at end of file