proxy working

left: print
send files
This commit is contained in:
ofilter 2022-03-25 06:40:38 +01:00
parent e5c862378b
commit 974a7d3f38
3 changed files with 112 additions and 47 deletions

View File

@ -50,6 +50,7 @@ Place the files on the working structure (aka. script folder)
./distribute.sh
./send_files.sh
./files_to_send
./proxy_route
./users
#### files to send

View File

@ -10,64 +10,125 @@
export _USERS="$(cat ./users)"
export _PROXY_ROUTES="$(cat ./proxy_routes)"
### COLORS
_RED="\033[1;31m"
_GREEN="\033[1;32m"
_RESET="\033[0m"
_YELLOW="\033[0;33m"
### Main
sed '/^$/d' h | tee ./curr_h >/dev/null # remove empty lines
sed '/^$/d' h | tee ./.curr_h >/dev/null # remove empty lines
printf "Attempting to SSH\n"
for username in $_USERS
do
printf "\033[0;33m ${username}\n\033[0m"
cat > "./${username}/h"
for hostname in $(cat ./curr_h)
do
printf "${hostname}: -->"
sshpass -f "./${username}/p" ssh -q -o StrictHostKeyChecking=no -T "${username}@${hostname}" 'echo true' &> /dev/null &&
printf "${hostname}: \033[1;32mYES \033[0m\n" &&
printf "${hostname}\n" | tee -a "./${username}/h" > /dev/null ||
printf "${hostname}: \033[1;31mNo \033[0m\n"
done
diff --new-line-format="" --unchanged-line-format="" ./curr_h "${username}/h" > left_h
mv ./left_h ./curr_h
done
mv curr_h discards_h
#for username in $_USERS
#do
# printf "${_YELLOW} ${username}\n${_RESET}"
# printf "" > "./${username}/h"
# for hostname in $(cat ./.curr_h)
# do
# printf "${hostname}: -->"
# result=""
# sshpass -f "./${username}/p" ssh -q -o StrictHostKeyChecking=no -T "${username}@${hostname}" 'echo true' &> /dev/null && result="true";
#
# if [[ "$result" ]]
# then
# printf "${hostname}\n" | tee -a "./${username}/h" > /dev/null
# printf "${hostname}: ${_GREEN}YES${_RESET}\n"
# else
# printf "${hostname}: ${_RED}No${_RESET}\n";
# fi
# done
# diff --new-line-format="" --unchanged-line-format="" ./.curr_h "${username}/h" > .left_h
# mv ./.left_h ./.curr_h
#done
# Proxy / Triangulate
#printf "Proxy routes"
# Check if hosts left
printf "" >.proxy_results
for proxy in $_PROXY_ROUTES
do
printf "\033[0;33m ${username}\n\033[0m"
for username in $_USERS
do
false
# printf "\033[0;33m ${username}\n\033[0m"
# rm ./${username}/h
# touch ./${username}/h
# for hostname in $(cat ./curr_h)
# do
# printf "${hostname}: -->"
# sshpass -f "./${username}/p" ssh -q -o StrictHostKeyChecking=no -T "${username}@${hostname}" 'echo true' &> /dev/null &&
# printf "${hostname}: \033[1;32mYES \033[0m\n" &&
# printf "${hostname}\n" | tee -a "./${username}/h" > /dev/null ||
# printf "${hostname}: \033[1;31mNo \033[0m\n" < "./${username}/p"
# done
# diff --new-line-format="" --unchanged-line-format="" ./curr_h "${username}/h" > left_h
# mv ./left_h ./curr_h
done
done
mv curr_h discards_h
printf "${_YELLOW}>> Status proxy ${proxy}:${_RESET} "
printf "" > "./_${proxy}/result"
proxy_username="$(cat ./_${proxy}/u)"
printf "Distributed hosts\n"
result=""
sshpass -f "./${proxy_username}/p" ssh -q -o StrictHostKeyChecking=no -T "${proxy_username}@${proxy}" 'echo true' &> /dev/null && result="true";
if [[ ! "$result" ]]
then
printf "${_RED}Cannot establish connection with the proxy, skipping ...${_RESET}\n";
else
printf "${_GREEN}OK${_RESET}\n"
for username in $_USERS
do
for hostname in $(cat ./.curr_h)
do
printf ">> ($proxy) --> ${username}@${hostname}: ${_RESET}"
result=""
sshpass -f "./${_proxy}/p" ssh -q -o StrictHostKeyChecking=no -T "${proxy_username}@${proxy}" "sshpass -f /dev/stdin ssh -q -o StrictHostKeyChecking=no -T \"${username}@${hostname}\" \"echo true\" && echo true " < "./${username}/p" &> /dev/null && result="true";
if [[ "$result" ]]
then
printf "${_GREEN}YES${_RESET}\n"
# hostname;proxy;username
printf "${hostname};${proxy};${username}\n" | tee -a ./.proxy_results > /dev/null
diff --new-line-format="" --unchanged-line-format="" ./.curr_h <(echo $hostname) > .left_h
mv ./.left_h ./.curr_h
# awk -F ";" '{print $1}' .proxy_results
else
printf "${_RED}No${_RESET}\n";
fi
done
done
fi
# for username in $_USERS
# do
# printf "${_YELLOW} ${username}\n${_RESET}"
# rm ./${username}/h
# touch ./${username}/h
# for hostname in $(cat ./.curr_h)
# do
# printf "${hostname}: -->"
# sshpass -f "./${username}/p" ssh -q -o StrictHostKeyChecking=no -T "${username}@${hostname}" 'echo true' &> /dev/null &&
# printf "${hostname}: ${_GREEN}YES${_RESET}\n" &&
# printf "${hostname}\n" | tee -a "./${username}/h" > /dev/null ||
# printf "${hostname}: ${_RED}No${_RESET}\n" < "./${username}/p"
# done
# diff --new-line-format="" --unchanged-line-format="" ./.curr_h "${username}/h" > .left_h
# mv ./.left_h ./.curr_h
# done
for username in $_USERS
do
printf "\033[0;32m ${username}\n\033[0m"
awk '{ printf" %s\n",$0 }' < "./${username}/h"
done
printf "\033[0;31mDISCARDS:\033[0m\n"
awk '{ printf" %s\n",$0 }' < ./discards_h
printf "Discards are stored in './discards_h'\n"
bash ./send_files.sh
#printf "Distributed hosts\n"
#mv .curr_h .discards_h
#for username in $_USERS
#do
# printf "\033[0;32m ${username}\n${_RESET}"
# awk '{ printf" %s\n",$0 }' < "./${username}/h"
#done
#
#printf "\033[0;31mDISCARDS:${_RESET}\n"
#awk '{ printf" %s\n",$0 }' < ./.discards_h
#
#printf "Discards are stored in './discards_h'\n"
#
#bash ./send_files.sh

View File

@ -35,4 +35,7 @@ do
done
done
# Proxy
printf "\033[1;32mDONE \033[0m\n"