|
|
@@ -18,6 +18,79 @@
|
|
|
# description: Activates/Deactivates the firewall at boot time
|
|
|
#
|
|
|
|
|
|
+
|
|
|
+has_parent_process(){
|
|
|
+ echo "${1} ${2}"
|
|
|
+ local parent_to_search
|
|
|
+ parent_to_search="${1:-}"
|
|
|
+ if [[ -z "${parent_to_search:-}" ]]
|
|
|
+ then
|
|
|
+ echo "ERROR: need parent process pid as first arg"
|
|
|
+ return 5
|
|
|
+ fi
|
|
|
+ local pid
|
|
|
+ if [[ -z "${2:-}" ]]
|
|
|
+ then
|
|
|
+ pid=$$
|
|
|
+ #pid=$(ps --pid $$ -o ppid= | xargs)
|
|
|
+ fi
|
|
|
+ if [[ $parent_to_search -eq $pid ]]
|
|
|
+ then
|
|
|
+ echo $parent_to_search
|
|
|
+ else if [[ $pid -gt 0 ]]
|
|
|
+ then
|
|
|
+ parent_process_terminal ${parent_to_search} $(ps --pid ${pid} -o ppid= | xargs)
|
|
|
+ else
|
|
|
+ echo 0
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+find_pid_user_of(){
|
|
|
+ local used_file=$1
|
|
|
+ local regex="$2"
|
|
|
+ lsof ${used_file} | awk 'NR>1 && $1 ~ /'${regex}'/ && !($2 in a){a[$2]++; print $2}'
|
|
|
+}
|
|
|
+
|
|
|
+echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
|
|
+declare -g shell_pid=""
|
|
|
+declare -g systemctl_pid=""
|
|
|
+
|
|
|
+#ps -elf | grep 'systemctl' | grep -v grep | awk '{print $13}' | sort -u | while read term ; do echo "$term"; lsof /dev/$term ; echo "TEST:$term" > /dev/$term ; done
|
|
|
+ps -elf | grep 'systemctl' | grep -v grep | awk '{print $13}' | sort -u | while read term
|
|
|
+do
|
|
|
+ echo "$term ---"
|
|
|
+ lsof /dev/$term
|
|
|
+ lsof -F 'cp' /dev/$term
|
|
|
+ echo "$term >>>"
|
|
|
+ #lsof /dev/$term | awk 'NR>1 && $1 ~ /.*sh$/ && !($2 in a){a[$2]++; print $2}'
|
|
|
+ if [[ -z "${shell_pid:-}" ]]
|
|
|
+ then
|
|
|
+ shell_pid=$(find_pid_user_of /dev/$term '.*sh$')
|
|
|
+ fi
|
|
|
+ if [[ -z "${systemctl_pid:-}" ]]
|
|
|
+ then
|
|
|
+ systemctl_pid=$(find_pid_user_of /dev/$term 'systemctl')
|
|
|
+ fi
|
|
|
+ echo "shell_pid=$shell_pid"
|
|
|
+ echo "systemctl_pid=$systemctl_pid"
|
|
|
+ echo "TEST:$term" > /dev/$term
|
|
|
+done
|
|
|
+echo "shell_pid=$shell_pid"
|
|
|
+echo "systemctl_pid=$systemctl_pid"
|
|
|
+if [[ -z "${shell_pid:-}" ]]
|
|
|
+then
|
|
|
+ echo has_parent_process ${shell_pid} ${systemctl_pid}
|
|
|
+ has_parent_process ${shell_pid} ${systemctl_pid}
|
|
|
+else
|
|
|
+ echo "SHELL PID NOT FOUND"
|
|
|
+fi
|
|
|
+echo "Parent terminal:"
|
|
|
+parent_process_terminal
|
|
|
+echo "SSH_TTY: $SSH_TTY"
|
|
|
+echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
|
|
+
|
|
|
+
|
|
|
set -euo pipefail
|
|
|
|
|
|
help_message_lfirewall(){
|