mirror of https://github.com/itsmrval/accessGate
fail..
parent
bbfbc03813
commit
edd010865d
79
agent.sh
79
agent.sh
|
|
@ -1,44 +1,67 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
url=$1
|
||||||
|
server=$2
|
||||||
|
secret=$3
|
||||||
|
user=$4
|
||||||
|
rootpath="/opt/accessgate"
|
||||||
|
updateScriptUrl=https://raw.githubusercontent.com/itsmrval/accessgate/scripts/update.sh
|
||||||
|
|
||||||
. config.txt
|
|
||||||
|
|
||||||
if [ $user == "accessgatemultiuser"]
|
i=0
|
||||||
then
|
while [ $i -ne 100 ]
|
||||||
tmp_file=tmp_user.txt
|
|
||||||
old_file=old_user.txt
|
|
||||||
isDifferent=false
|
|
||||||
curl -o $tmp_file -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/users
|
|
||||||
[[ -f filename ]] || touch $old_file
|
|
||||||
cmp --silent $old_file $tmp_file || isDifferent=true
|
|
||||||
|
|
||||||
for x in $(head $tmp_file)
|
|
||||||
do
|
do
|
||||||
|
i=$(($i+1))
|
||||||
userPath=$x
|
echo ""
|
||||||
echo $x
|
|
||||||
if [ $x != "root" ]
|
|
||||||
then
|
|
||||||
userPath=home/$x
|
|
||||||
fi
|
|
||||||
mkdir -p $userPath/.ssh
|
|
||||||
curl -o $userPath/.ssh -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/key/$x
|
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
printf " ___ ______ __ \n"
|
||||||
if [ $user != "root" ]
|
printf " / | _____________ __________/ ____/___ _/ /____ \n"
|
||||||
|
printf " / /| |/ ___/ ___/ _ \/ ___/ ___/ / __/ __ \`/ __/ _ \ \n"
|
||||||
|
printf " / ___ / /__/ /__/ __(__ |__ ) /_/ / /_/ / /_/ __/ \n"
|
||||||
|
printf "/_/ |_\___/\___/\___/____/____/\____/\__,_/\__/\___/ \n\n\n\n"
|
||||||
|
|
||||||
|
echo -ne "[INFO] Checking agent directory.. "
|
||||||
|
|
||||||
|
if [ -d "$rootpath" ]
|
||||||
then
|
then
|
||||||
userPath=home/$x
|
rm -rf $rootpath
|
||||||
fi
|
fi
|
||||||
mkdir -p $userPath/.ssh
|
mkdir -p $rootpath
|
||||||
curl -o $userPath/.ssh -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/allKeys
|
echo -ne "✓\n"
|
||||||
|
|
||||||
|
echo -ne "[INFO] Testing parameters.. "
|
||||||
|
|
||||||
|
secretRequest=$(curl -s -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server)
|
||||||
|
|
||||||
|
if [ "$secretRequest" = "invalid request" ]
|
||||||
|
then
|
||||||
|
echo -ne "✗\n"
|
||||||
|
echo '[ERROR] Please verify your configuration'
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo -ne "✓\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -ne "[INFO] Creating agent directory.. "
|
||||||
|
touch $rootpath/config.txt
|
||||||
|
truncate -s 0 $rootpath/config.txt
|
||||||
|
tee -a $rootpath/config.txt > /dev/null <<EOT
|
||||||
|
server=$server
|
||||||
|
url=$url
|
||||||
|
secret=$secret
|
||||||
|
user=$user
|
||||||
|
EOT
|
||||||
|
echo -ne "✓\n"
|
||||||
|
|
||||||
|
echo -ne "[INFO] Downloading update script.. "
|
||||||
|
curl -s $updateScriptUrl --output $rootpath/update.sh
|
||||||
|
echo -ne "✓\n"
|
||||||
|
|
||||||
|
echo -n "[INFO] Creating crontab entry.. "
|
||||||
|
|
||||||
# mkdir -p /$user/.ssh/
|
(crontab -u root -l; echo "* * * * * /bin/sh /opt/accessgate/update.sh" ) | crontab -u root -
|
||||||
# curl -o /$user/.ssh/authorized_keys -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/key/$1
|
sleep 0.5
|
||||||
|
echo -ne "✓\n"
|
||||||
|
|
||||||
mv $tmp_file $old_file
|
echo -ne "[SUCCESS] Script ended \n\n"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue