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
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
close)
|
||||
echo close > $PIPE_PATH
|
||||
action="$1"
|
||||
isTriggerActivated="0"
|
||||
|
||||
if [ -z "$action" ]
|
||||
then
|
||||
action="$SSH_ORIGINAL_COMMAND"
|
||||
isTriggerActivated="1"
|
||||
fi
|
||||
|
||||
case $action in
|
||||
close|open)
|
||||
echo $action | tee $PIPE_PATH > /tmp/state
|
||||
;;
|
||||
open)
|
||||
echo open > $PIPE_PATH
|
||||
status)
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $(basename $0) { close, open}"
|
||||
echo "Usage: $(basename $0) { close, open, status }"
|
||||
exit 1
|
||||
;;
|
||||
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"
|
||||
|
||||
dest=/var/run/foodoor-keys
|
||||
temp_outfile="$dest.tmp"
|
||||
|
||||
|
||||
if [ ! -e "${dest}/.git/config" ]
|
||||
then
|
||||
@ -14,10 +16,7 @@ else
|
||||
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
|
||||
fi
|
||||
|
||||
for action in open close
|
||||
do
|
||||
outfile="${dest}/authorized_keys.${action}"
|
||||
rm -f ${outfile}
|
||||
rm -f ${temp_outfile}
|
||||
find "${dest}/keys" -name '*.pub' | sort | \
|
||||
while read keyfile
|
||||
do
|
||||
@ -42,15 +41,26 @@ do
|
||||
fi
|
||||
|
||||
if [ "$valid" = true ]; then
|
||||
printf "command=\"/usr/sbin/foodoor ${action}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding " >> ${outfile}
|
||||
cat "${keyfile}" >> ${outfile}
|
||||
echo >> ${outfile}
|
||||
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding ${keyfile}" >> ${temp_outfile}
|
||||
fi
|
||||
fi
|
||||
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
|
||||
install -d -o ${action} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
|
||||
install -b -S .last -o ${action} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
|
||||
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
|
||||
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
|
||||
|
||||
|
||||
# Unten
|
||||
|
Loading…
Reference in New Issue
Block a user