added support for operation via command instead of user
This commit is contained in:
parent
8bb7f10d84
commit
30b027014e
26
foodoor
26
foodoor
@ -9,15 +9,29 @@ if [ ! -e $PIPE_PATH ]
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $1 in
|
action="$1"
|
||||||
close)
|
isTriggerActivated="0"
|
||||||
echo close > $PIPE_PATH
|
|
||||||
|
if [ -z "$action" ]
|
||||||
|
then
|
||||||
|
action="$SSH_ORIGINAL_COMMAND"
|
||||||
|
isTriggerActivated="1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $action in
|
||||||
|
close|open)
|
||||||
|
echo $action | tee $PIPE_PATH > /tmp/state
|
||||||
;;
|
;;
|
||||||
open)
|
status)
|
||||||
echo open > $PIPE_PATH
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: $(basename $0) { close, open}"
|
echo "Usage: $(basename $0) { close, open, status }"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if [ $isTriggerActivated -eq 1 ]
|
||||||
|
then
|
||||||
|
cat /tmp/state
|
||||||
|
sleep 2
|
||||||
|
fi
|
||||||
|
@ -4,6 +4,8 @@ set -e
|
|||||||
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
||||||
|
|
||||||
dest=/var/run/foodoor-keys
|
dest=/var/run/foodoor-keys
|
||||||
|
temp_outfile="$dest.tmp"
|
||||||
|
|
||||||
|
|
||||||
if [ ! -e "${dest}/.git/config" ]
|
if [ ! -e "${dest}/.git/config" ]
|
||||||
then
|
then
|
||||||
@ -14,10 +16,7 @@ else
|
|||||||
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
|
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for action in open close
|
rm -f ${temp_outfile}
|
||||||
do
|
|
||||||
outfile="${dest}/authorized_keys.${action}"
|
|
||||||
rm -f ${outfile}
|
|
||||||
find "${dest}/keys" -name '*.pub' | sort | \
|
find "${dest}/keys" -name '*.pub' | sort | \
|
||||||
while read keyfile
|
while read keyfile
|
||||||
do
|
do
|
||||||
@ -42,15 +41,26 @@ do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$valid" = true ]; then
|
if [ "$valid" = true ]; then
|
||||||
printf "command=\"/usr/sbin/foodoor ${action}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding " >> ${outfile}
|
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding ${keyfile}" >> ${temp_outfile}
|
||||||
cat "${keyfile}" >> ${outfile}
|
|
||||||
echo >> ${outfile}
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
for appendix in open close door
|
||||||
|
do
|
||||||
|
action="$appendix"
|
||||||
|
if [ "$action" -eq "door" ]
|
||||||
|
then
|
||||||
|
action=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
export action
|
||||||
|
outfile="${dest}/authorized_keys.${appendix}"
|
||||||
|
cat ${tmp_outfile} |envsubst > ${outfile}
|
||||||
|
|
||||||
# Oben
|
# Oben
|
||||||
install -d -o ${action} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
|
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
|
||||||
install -b -S .last -o ${action} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
|
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
|
||||||
|
|
||||||
|
|
||||||
# Unten
|
# Unten
|
||||||
|
Loading…
Reference in New Issue
Block a user