From ee93c283c70feb26ec62e21ee09eac37f91d0f7b Mon Sep 17 00:00:00 2001 From: gabriel <89615327+gabriel-scripts@users.noreply.github.com> Date: Fri, 7 Mar 2025 19:58:16 +0000 Subject: [PATCH 1/7] feat: ssh and firewall manager --- .bashrc | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/.bashrc b/.bashrc index 5378cd2..800d0af 100644 --- a/.bashrc +++ b/.bashrc @@ -260,6 +260,85 @@ alias docker-clean=' \ ####################################################### # SPECIAL FUNCTIONS ####################################################### + +#firewall simple configuration +firewall() { + echo -e '(1) firewall status\n(2) reset firewall\n(3) reload firewall\n(4) list apps\n(5) allow (PORT)\n (6)deny (PORT)' + read option + case $option in + 1) + echo -e "sudo efw status \n" + sudo ufw status + ;; + 2) + echo -e "sudo ufw reset \n" + sudo ufw reset + ;; + 3) + echo -e "sudo ufw reload \n" + sudo ufw reload + ;; + 4) + echo -e "sudo ufw app list \n" + sudo ufw app list + ;; + 5) + echo -e "sudo ufw allow (PORT) \n digit a port: " + read option2 + sudo ufw allow $option2 + ;; + 6) + echo -e "sudo ufw deny (PORT) \n digit a port: " + read option2 + sudo ufw deny $option2 + ;; + *) + echo "Invalid option" + ;; + esac +} + +# SSH simple manager +configssh() { + echo -e 'SSH MANAGER:\n(1) start\n(2) stop\n(3)restart\n(4)status\n(5)config\n(6)connect to a SSH\n' + read option + case $option in + 1) + echo -e "sudo systemctl start ssh \n" + sudo systemctl start ssh + ;; + 2) + echo -e "sudo systemctl stop ssh \n" + sudo systemctl stop ssh + ;; + 3) + echo -e "sudo systemctl restart ssh \n" + sudo systemctl restart ssh + ;; + 4) + echo -e "sudo systemctl status ssh \n" + sudo systemctl status ssh + ;; + 5) + echo -e "sudo nano /etc/ssh/sshd_config \n" + sudo nano /etc/ssh/sshd_config + ;; + 6) + echo -e "ssh user@ip -p PORT \n digit user:" + read user + echo -e "digit ip: " + read ip + echo -e "digit PORT: " + read port + sudo ssh $user@$ip -p $port + ;; + *) + echo "Invalid option" + ;; + esac + +} + # Extracts any archive(s) (if unp isn't installed) extract() { for archive in "$@"; do @@ -565,7 +644,7 @@ phpconfig() { elif [ -f /etc/php5/apache2/php.ini ]; then sedit /etc/php5/apache2/php.ini else - echo "Error: php.ini file could not be found." + echo "Error: php.ini file could not be found."alias bashconfig="code ~/.bashrc" echo "Searching for possible locations:" sudo updatedb && locate php.ini fi @@ -631,7 +710,7 @@ function hb { fi } -####################################################### +#######################################################x # Set the ultimate amazing command prompt ####################################################### From 96209dd6be30376a08c5a06e8c22eae73487df2e Mon Sep 17 00:00:00 2001 From: gabriel <89615327+gabriel-scripts@users.noreply.github.com> Date: Fri, 7 Mar 2025 20:17:08 +0000 Subject: [PATCH 2/7] fix bashrc --- .bashrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.bashrc b/.bashrc index 800d0af..025ed39 100644 --- a/.bashrc +++ b/.bashrc @@ -644,7 +644,7 @@ phpconfig() { elif [ -f /etc/php5/apache2/php.ini ]; then sedit /etc/php5/apache2/php.ini else - echo "Error: php.ini file could not be found."alias bashconfig="code ~/.bashrc" + echo "Error: php.ini file could not be found." echo "Searching for possible locations:" sudo updatedb && locate php.ini fi @@ -710,7 +710,7 @@ function hb { fi } -#######################################################x +####################################################### # Set the ultimate amazing command prompt ####################################################### From 6f50801fd82d47151f09c11c7662488e03e6df1f Mon Sep 17 00:00:00 2001 From: gabriel <89615327+gabriel-scripts@users.noreply.github.com> Date: Sat, 8 Mar 2025 18:53:39 +0000 Subject: [PATCH 3/7] feat: fullupdate --- .bashrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index 025ed39..cf39ed1 100644 --- a/.bashrc +++ b/.bashrc @@ -155,7 +155,7 @@ alias freshclam='sudo freshclam' alias vi='nvim' alias svi='sudo vi' alias vis='nvim "+set si"' - +alias fullupdate="sudo apt update && sudo apt upgrade" # Change directory aliases alias home='cd ~' From f77fad769cd7fa057512d1405dd7f7da11f03533 Mon Sep 17 00:00:00 2001 From: gabriel <89615327+gabriel-scripts@users.noreply.github.com> Date: Sat, 8 Mar 2025 22:25:02 +0000 Subject: [PATCH 4/7] refactor: ssh and firewall manager --- .bashrc | 228 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 186 insertions(+), 42 deletions(-) diff --git a/.bashrc b/.bashrc index cf39ed1..0451d94 100644 --- a/.bashrc +++ b/.bashrc @@ -265,32 +265,80 @@ alias docker-clean=' \ firewall() { echo -e '(1) firewall status\n(2) reset firewall\n(3) reload firewall\n(4) list apps\n(5) allow (PORT)\n (6)deny (PORT)' read option + + if command -v ufw &>/dev/null; then + FIREWALL="ufw" + elif command -v firewall-cmd &>/dev/null; then + FIREWALL="firewalld" + elif command -v iptables &>/dev/null; then + FIREWALL="iptables" + else + echo "Fail, firewall not found." + return 1 + fi + case $option in 1) - echo -e "sudo efw status \n" - sudo ufw status + echo -e "Firewall status:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw status + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --state + else + sudo iptables -L + fi ;; 2) - echo -e "sudo ufw reset \n" - sudo ufw reset + echo -e "Reseting firewall:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw reset + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --reload + else + sudo iptables -F + fi ;; 3) - echo -e "sudo ufw reload \n" - sudo ufw reload + echo -e "Reloading firewall:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw reload + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --reload + else + echo "" + fi ;; 4) - echo -e "sudo ufw app list \n" - sudo ufw app list + echo -e "App list:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw app list + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --get-services + else + sudo iptables --list + fi ;; 5) - echo -e "sudo ufw allow (PORT) \n digit a port: " - read option2 - sudo ufw allow $option2 + read -p "Digit a port to allow:\n" allow_port + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw allow "$allow_port" + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --permanent --add-port="$allow_port/tcp" + sudo firewall-cmd --reload + else + sudo iptables -A INPUT -p tcp --dport "$allow_port" -j ACCEPT + fi ;; 6) - echo -e "sudo ufw deny (PORT) \n digit a port: " - read option2 - sudo ufw deny $option2 + read -p "Digit the port to deny:\n" deny_port + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw deny "$deny_port" + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --permanent --remove-port="$deny_port/tcp" + sudo firewall-cmd --reload + else + sudo iptables -A INPUT -p tcp --dport "$deny_port" -j DROP + fi ;; *) echo "Invalid option" @@ -300,43 +348,139 @@ firewall() { # SSH simple manager configssh() { - echo -e 'SSH MANAGER:\n(1) start\n(2) stop\n(3)restart\n(4)status\n(5)config\n(6)connect to a SSH\n' + echo -e 'SSH MANAGER:\n(1) start\n(2) stop\n(3) restart\n(4) status\n(5) config\n(6) connect to SSH\n' read option + + if command -v systemctl &>/dev/null; then + INIT_SYSTEM="systemd" + + elif [ -f /etc/init.d/ ] && [ "$(ls -A /etc/init.d/)" ]; then + INIT_SYSTEM="SysVinit" + + elif command -v rc-service &>/dev/null; then + INIT_SYSTEM="OpenRC" + + elif command -v sv &>/dev/null; then + INIT_SYSTEM="runit" + else + INIT_SYSTEM="Unknown" + fi + + echo "System init: $INIT_SYSTEM\n" + case $option in 1) - echo -e "sudo systemctl start ssh \n" - sudo systemctl start ssh - ;; + case $INIT_SYSTEM in + systemd) + echo -e "Starting SSH with systemd." + sudo systemctl start ssh + ;; + SysVinit) + echo -e "Starting SSH with SysVinit." + ;; + OpenRC) + echo -e "Starting SSH with OpenRC." + sudo rc-service sshd start + ;; + runit) + echo -e "Starting SSH with runit." + sudo sv start sshd + ;; + *) + echo "Unknown init system, unable to start SSH." + ;; + esac + ;; 2) - echo -e "sudo systemctl stop ssh \n" - sudo systemctl stop ssh - ;; + case $INIT_SYSTEM in + systemd) + echo -e "Stopping SSH with systemd." + sudo systemctl stop ssh + ;; + SysVinit) + echo -e "Stopping SSH with SysVinit." + sudo service ssh stop + ;; + OpenRC) + echo -e "Stopping SSH with OpenRC." + sudo rc-service sshd stop + ;; + runit) + echo -e "Stopping SSH with runit." + sudo sv stop sshd + ;; + *) + echo "Fail, unknown init system, unable to stop SSH." + ;; + esac + ;; 3) - echo -e "sudo systemctl restart ssh \n" - sudo systemctl restart ssh - ;; + case $INIT_SYSTEM in + systemd) + echo -e "Restarting SSH with systemd." + sudo systemctl restart ssh + ;; + SysVinit) + echo -e "Restarting SSH with SysVinit." + sudo service ssh restart + ;; + OpenRC) + echo -e "Restarting SSH with OpenRC." + sudo rc-service sshd restart + ;; + runit) + echo -e "Restarting SSH with runit." + sudo sv restart sshd + ;; + *) + echo "Unknown init system, unable to restart SSH." + ;; + esac + ;; 4) - echo -e "sudo systemctl status ssh \n" - sudo systemctl status ssh - ;; + case $INIT_SYSTEM in + systemd) + echo -e "Checking SSH status with systemd." + sudo systemctl status ssh + ;; + SysVinit) + echo -e "Checking SSH status with SysVinit." + sudo service ssh status + ;; + OpenRC) + echo -e "Checking SSH status with OpenRC." + sudo rc-service sshd status + ;; + runit) + echo -e "Checking SSH status with runit." + sudo sv status sshd + ;; + *) + echo "Unknown init system, unable to check SSH status." + ;; + esac + ;; 5) - echo -e "sudo nano /etc/ssh/sshd_config \n" - sudo nano /etc/ssh/sshd_config - ;; + if [ -f /etc/ssh/sshd_config ]; then + echo -e "Opening sshd_config in nano." + sudo nano /etc/ssh/sshd_config + else + echo "Failed to find the sshd_config file." + fi + ;; 6) - echo -e "ssh user@ip -p PORT \n digit user:" - read user - echo -e "digit ip: " - read ip - echo -e "digit PORT: " - read port - sudo ssh $user@$ip -p $port - ;; + echo -e "Enter username:" + read user + echo -e "Enter IP address:" + read ip + echo -e "Enter port:" + read port + sudo ssh $user@$ip -p $port + ;; *) - echo "Invalid option" - ;; - esac - + echo "Invalid option" + ;; + esac } # Extracts any archive(s) (if unp isn't installed) From 32e4dbf9f981365923194366bfb05c418284ef75 Mon Sep 17 00:00:00 2001 From: gabriel <89615327+gabriel-scripts@users.noreply.github.com> Date: Sat, 8 Mar 2025 22:25:40 +0000 Subject: [PATCH 5/7] refactor: firewall --- .bashrc | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/.bashrc b/.bashrc index 0451d94..6bd1fc5 100644 --- a/.bashrc +++ b/.bashrc @@ -261,6 +261,28 @@ alias docker-clean=' \ # SPECIAL FUNCTIONS ####################################################### + +system_init(){ + if command -v systemctl &>/dev/null; then + INIT_SYSTEM="systemd" + INIT_SYSTEM_RESTART="sudo systemctl restart" + elif [ -d /etc/init.d/ ] && [ "$(ls -A /etc/init.d/)" ]; then + INIT_SYSTEM="SysVinit" + INIT_SYSTEM_RESTART="sudo service" + elif command -v rc-service &>/dev/null; then + INIT_SYSTEM="OpenRC" + INIT_SYSTEM_RESTART="sudo rc-service" + elif command -v sv &>/dev/null; then + INIT_SYSTEM="runit" + INIT_SYSTEM_RESTART="sudo sv restart" + else + INIT_SYSTEM="Unknown" + fi +} +system_init +export INIT_SYSTEM +export INIT_SYSTEM_RESTART + #firewall simple configuration firewall() { echo -e '(1) firewall status\n(2) reset firewall\n(3) reload firewall\n(4) list apps\n(5) allow (PORT)\n (6)deny (PORT)' @@ -289,11 +311,11 @@ firewall() { fi ;; 2) - echo -e "Reseting firewall:\n" + echo -e "Resetting firewall:\n" if [ "$FIREWALL" = "ufw" ]; then sudo ufw reset elif [ "$FIREWALL" = "firewalld" ]; then - sudo firewall-cmd --reload + sudo firewall-cmd --complete-reload else sudo iptables -F fi @@ -305,7 +327,11 @@ firewall() { elif [ "$FIREWALL" = "firewalld" ]; then sudo firewall-cmd --reload else - echo "" + if [ "$INIT_SYSTEM" = "SysVinit" ] || [ "$INIT_SYSTEM" = "OpenRC" ]; then + $INIT_SYSTEM_RESTART $FIREWALL restart + else + $INIT_SYSTEM_RESTART $FIREWALL + fi fi ;; 4) @@ -319,7 +345,7 @@ firewall() { fi ;; 5) - read -p "Digit a port to allow:\n" allow_port + read -p "Digit a port to allow: " allow_port if [ "$FIREWALL" = "ufw" ]; then sudo ufw allow "$allow_port" elif [ "$FIREWALL" = "firewalld" ]; then @@ -351,21 +377,6 @@ configssh() { echo -e 'SSH MANAGER:\n(1) start\n(2) stop\n(3) restart\n(4) status\n(5) config\n(6) connect to SSH\n' read option - if command -v systemctl &>/dev/null; then - INIT_SYSTEM="systemd" - - elif [ -f /etc/init.d/ ] && [ "$(ls -A /etc/init.d/)" ]; then - INIT_SYSTEM="SysVinit" - - elif command -v rc-service &>/dev/null; then - INIT_SYSTEM="OpenRC" - - elif command -v sv &>/dev/null; then - INIT_SYSTEM="runit" - else - INIT_SYSTEM="Unknown" - fi - echo "System init: $INIT_SYSTEM\n" case $option in @@ -377,6 +388,8 @@ configssh() { ;; SysVinit) echo -e "Starting SSH with SysVinit." + sudo service sshd start + sudo service ssh start ;; OpenRC) echo -e "Starting SSH with OpenRC." @@ -400,6 +413,7 @@ configssh() { SysVinit) echo -e "Stopping SSH with SysVinit." sudo service ssh stop + sudo service sshd stop ;; OpenRC) echo -e "Stopping SSH with OpenRC." From a57b8fe1d245829466e93ec5c142cf320e4b6925 Mon Sep 17 00:00:00 2001 From: gabriel <89615327+gabriel-scripts@users.noreply.github.com> Date: Sun, 9 Mar 2025 21:29:52 +0000 Subject: [PATCH 6/7] feat: system and refactor of .bashrc --- .bashrc | 227 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 147 insertions(+), 80 deletions(-) diff --git a/.bashrc b/.bashrc index 6bd1fc5..de27670 100644 --- a/.bashrc +++ b/.bashrc @@ -262,119 +262,186 @@ alias docker-clean=' \ ####################################################### +#sytemd, Sysvinit, Openrc or runit identifier system_init(){ if command -v systemctl &>/dev/null; then INIT_SYSTEM="systemd" INIT_SYSTEM_RESTART="sudo systemctl restart" + INIT_SYSTEM_STOP="sudo systemctl stop" + INIT_SYSTEM_START="sudo systemctl start" + INIT_SYSTEM_STATUS="sudo systemctl status" elif [ -d /etc/init.d/ ] && [ "$(ls -A /etc/init.d/)" ]; then INIT_SYSTEM="SysVinit" - INIT_SYSTEM_RESTART="sudo service" + INIT_SYSTEM_DEFAULT="sudo service" elif command -v rc-service &>/dev/null; then INIT_SYSTEM="OpenRC" - INIT_SYSTEM_RESTART="sudo rc-service" + INIT_SYSTEM_DEFAULT="sudo rc-service" elif command -v sv &>/dev/null; then INIT_SYSTEM="runit" INIT_SYSTEM_RESTART="sudo sv restart" + INIT_SYSTEM_START="sudo sv start" + INIT_SYSTEM_STOP="sudo sv stop" + INIT_SYSTEM_STATUS="sudo sv status" else INIT_SYSTEM="Unknown" + echo -e "[error] system init not found" fi } -system_init + +if [ -z "$INIT_SYSTEM" ] || [ INIT_SYSTEM == "Unknown" ]; then + system_init +fi + export INIT_SYSTEM +export INIT_SYSTEM_START +export INIT_SYSTEM_STOP +export INIT_SYSTEM_STATUS export INIT_SYSTEM_RESTART -#firewall simple configuration -firewall() { - echo -e '(1) firewall status\n(2) reset firewall\n(3) reload firewall\n(4) list apps\n(5) allow (PORT)\n (6)deny (PORT)' - read option - - if command -v ufw &>/dev/null; then - FIREWALL="ufw" - elif command -v firewall-cmd &>/dev/null; then - FIREWALL="firewalld" - elif command -v iptables &>/dev/null; then - FIREWALL="iptables" - else - echo "Fail, firewall not found." - return 1 - fi +export INIT_SYSTEM_DEFAULT - case $option in +# simple manager to start, stop, restart and see the status of aplications +system(){ + echo -e '(1) start\n(2) stop\n(3) restart\n(4) status' + read option + case $option in 1) - echo -e "Firewall status:\n" - if [ "$FIREWALL" = "ufw" ]; then - sudo ufw status - elif [ "$FIREWALL" = "firewalld" ]; then - sudo firewall-cmd --state - else - sudo iptables -L - fi + echo -e 'name of the app (ex: docker, ssh, Mysql, MongoDb...):\n' + read app + if [ "$INIT_SYSTEM" = "SysVinit" ] || [ "$INIT_SYSTEM" = "OpenRC" ]; then + $INIT_SYSTEM_DEFAULT $FIREWALL start + else + $INIT_SYSTEM_START $app + fi ;; + 2) - echo -e "Resetting firewall:\n" - if [ "$FIREWALL" = "ufw" ]; then - sudo ufw reset - elif [ "$FIREWALL" = "firewalld" ]; then - sudo firewall-cmd --complete-reload - else - sudo iptables -F - fi + echo -e 'name of the app (ex: docker, ssh, Mysql, MongoDb...):\n' + read app + if [ "$INIT_SYSTEM" = "SysVinit" ] || [ "$INIT_SYSTEM" = "OpenRC" ]; then + $INIT_SYSTEM_DEFAULT $FIREWALL stop + else + $INIT_SYSTEM_STOP $app + fi ;; + 3) - echo -e "Reloading firewall:\n" - if [ "$FIREWALL" = "ufw" ]; then - sudo ufw reload - elif [ "$FIREWALL" = "firewalld" ]; then - sudo firewall-cmd --reload - else + echo -e 'name of the app (ex: docker, ssh, Mysql, MongoDb..):\n' + read app if [ "$INIT_SYSTEM" = "SysVinit" ] || [ "$INIT_SYSTEM" = "OpenRC" ]; then - $INIT_SYSTEM_RESTART $FIREWALL restart + $INIT_SYSTEM_DEFAULT $FIREWALL restart else - $INIT_SYSTEM_RESTART $FIREWALL + $INIT_SYSTEM_RESTART $app fi - fi ;; + 4) - echo -e "App list:\n" - if [ "$FIREWALL" = "ufw" ]; then - sudo ufw app list - elif [ "$FIREWALL" = "firewalld" ]; then - sudo firewall-cmd --get-services - else - sudo iptables --list - fi + echo -e 'name of the app (ex: docker, ssh, Mysql, MongoDb..):\n' + read app + if [ "$INIT_SYSTEM" = "SysVinit" ] || [ "$INIT_SYSTEM" = "OpenRC" ]; then + $INIT_SYSTEM_DEFAULT $FIREWALL restart + else + $INIT_SYSTEM_STATUS $app + fi + ;; - 5) - read -p "Digit a port to allow: " allow_port - if [ "$FIREWALL" = "ufw" ]; then - sudo ufw allow "$allow_port" - elif [ "$FIREWALL" = "firewalld" ]; then - sudo firewall-cmd --permanent --add-port="$allow_port/tcp" - sudo firewall-cmd --reload - else - sudo iptables -A INPUT -p tcp --dport "$allow_port" -j ACCEPT - fi - ;; - 6) - read -p "Digit the port to deny:\n" deny_port - if [ "$FIREWALL" = "ufw" ]; then - sudo ufw deny "$deny_port" - elif [ "$FIREWALL" = "firewalld" ]; then - sudo firewall-cmd --permanent --remove-port="$deny_port/tcp" - sudo firewall-cmd --reload + + esac +} + + +#firewall simple configuration +firewall() { + echo -e '(1) firewall status\n(2) reset firewall\n(3) reload firewall\n(4) list apps\n(5) allow (PORT)\n(6) deny (PORT)' + read option + + if command -v ufw &>/dev/null; then + FIREWALL="ufw" + elif command -v firewall-cmd &>/dev/null; then + FIREWALL="firewalld" + elif command -v iptables &>/dev/null; then + FIREWALL="iptables" else - sudo iptables -A INPUT -p tcp --dport "$deny_port" -j DROP + echo "Fail, firewall not found." + return 1 fi - ;; - *) - echo "Invalid option" - ;; - esac -} + + case $option in + 1) + echo -e "Firewall status:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw status + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --state + else + sudo iptables -L + fi + ;; + 2) + echo -e "Resetting firewall:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw reset + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --complete-reload + else + sudo iptables -F + fi + ;; + 3) + echo -e "Reloading firewall:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw reload + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --reload + else + if [ "$INIT_SYSTEM" = "SysVinit" ] || [ "$INIT_SYSTEM" = "OpenRC" ]; then + $INIT_SYSTEM_DEFAULT $FIREWALL restart + else + $INIT_SYSTEM_RESTART $FIREWALL + fi + fi + ;; + 4) + echo -e "App list:\n" + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw app list + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --get-services + else + sudo iptables --list + fi + ;; + 5) + read -p "Digit a port to allow: " allow_port + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw allow "$allow_port" + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --permanent --add-port="$allow_port/tcp" + sudo firewall-cmd --reload + else + sudo iptables -A INPUT -p tcp --dport "$allow_port" -j ACCEPT + fi + ;; + 6) + read -p "Digit the port to deny:\n" deny_port + if [ "$FIREWALL" = "ufw" ]; then + sudo ufw deny "$deny_port" + elif [ "$FIREWALL" = "firewalld" ]; then + sudo firewall-cmd --permanent --remove-port="$deny_port/tcp" + sudo firewall-cmd --reload + else + sudo iptables -A INPUT -p tcp --dport "$deny_port" -j DROP + fi + ;; + *) + echo "Invalid option" + ;; + esac + } # SSH simple manager configssh() { - echo -e 'SSH MANAGER:\n(1) start\n(2) stop\n(3) restart\n(4) status\n(5) config\n(6) connect to SSH\n' + echo -e 'SSH MANAGER:\n(1) start\n(2) stop\n(3) restart\n(4) status\n(5) config SSH\n(6) connect to a SSH\n' read option echo "System init: $INIT_SYSTEM\n" @@ -476,8 +543,8 @@ configssh() { ;; 5) if [ -f /etc/ssh/sshd_config ]; then - echo -e "Opening sshd_config in nano." - sudo nano /etc/ssh/sshd_config + echo -e "Opening sshd_config in vi." + sudo vi /etc/ssh/sshd_config else echo "Failed to find the sshd_config file." fi From 543e9c37621f5b1bb50d037196706a8e76b7b80b Mon Sep 17 00:00:00 2001 From: gabriel cardoso <89615327+gabriel-scripts@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:12:34 +0000 Subject: [PATCH 7/7] feat(listen ports): start, kill, show listening ports --- .bashrc | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index de27670..cba1afd 100644 --- a/.bashrc +++ b/.bashrc @@ -301,7 +301,8 @@ export INIT_SYSTEM_RESTART export INIT_SYSTEM_DEFAULT # simple manager to start, stop, restart and see the status of aplications -system(){ +system(){ + echo -e 'APPS MANAGER\n' echo -e '(1) start\n(2) stop\n(3) restart\n(4) status' read option case $option in @@ -564,6 +565,54 @@ configssh() { esac } +# show listening ports +listenports(){ + echo -e '(1) list all listening ::ports \n(2) show a listening ::port \n(3) kill a process' + read option + case $option in + 1) + if command -v lsof &> /dev/null; then + lsof -i + elif command -v netstat &> /dev/null; then + netstat -tuln + elif command -v ss &> /dev/null; then + ss -tuln + else + echo "Error: No suitable command found to list listening ports." + fi + ;; + + 2) + echo -e 'digit the port' + read port + if command -v lsof &> /dev/null; then + lsof -i :$port + elif command -v netstat &> /dev/null; then + netstat -tuln | grep ":$port" + elif command -v ss &> /dev/null; then + ss -tuln | grep ":$port" + else + echo "Error: No suitable command found to show the port." + fi + ;; + + 3) + echo -e 'digit the pid' + read pid + if kill -0 $pid &> /dev/null; then + kill -9 $pid + echo "Process $pid killed." + else + echo "Error: Process $pid not found." + fi + ;; + + *) + echo "Invalid option." + ;; + esac +} + # Extracts any archive(s) (if unp isn't installed) extract() { for archive in "$@"; do @@ -935,10 +984,23 @@ function hb { fi } + ####################################################### # Set the ultimate amazing command prompt ####################################################### + +alias bashconfig="code ~/.bashrc" +alias bashrestart="source ~/.bashrc" +alias fullupdate="sudo apt update && sudo apt upgrade" + +mycommands(){ + echo -e '1- firewall\n2- bashconfig\n3- bashrestart\n4- fullupdate\n5- configssh\n6- system\n7- configssh\n8- listenports \n9- morecommands(to see more)' +} +morecommands(){ + echo -e '9- distribution\n10- ver\n11- apachelog\n12- apacheconfig\n13- phpconfig\n14- mysqlconfig\n15- whatismyip\n16- trim\n17- ftext\n18- extract\n19- cpg\n20- mvg\n21- mkdirg\n22- up\n23- pwdtail' +} + alias hug="hugo server -F --bind=10.0.0.97 --baseURL=http://10.0.0.97" # Check if the shell is interactive