File: //usr/syno/lib/systemd/scripts/clean-session.sh
#!/bin/bash
## remove login session
CLEAN_SESSION=`/bin/get_key_value /etc/synoinfo.conf restart_clean_session`
if [ "$SUPPORT_DUAL_HEAD" == "yes" ]; then
SWITCHOVER=`/usr/syno/synoaha/bin/synoaha --should-keep-session-for-switch-over`
if [ "$SWITCHOVER" == "yes" ]; then
CLEAN_SESSION="no"
fi
fi
# avoid clean session when SHA is upgrading, no matter keep login is true or false
if [ "yes" = "$(/usr/syno/sbin/synohacore --is_ha_running)" ]; then
if [ "yes" = "$(/var/packages/HighAvailability/target/sbin/synohaupgrade --is-node-upgrading -N=local)" ]; then
exit 0
fi
fi
if [ ! -f /etc.defaults/rc.clean_session_after_upgrade ]; then
CLEAN_SESSION="yes"
find /usr/syno/etc/preference/ -name activities -exec sed -i -E 's/(\pkey":\")[a-zA-Z0-9_-]{43}(","pkeyClient":"browser")/\1\2/g' {} \;
/bin/touch /etc.defaults/rc.clean_session_after_upgrade
/bin/cp -a /usr/syno/etc.defaults/webapi/scope /usr/syno/etc/webapi/scope
fi
if [ x$CLEAN_SESSION != "xno" ]; then
/bin/sqlite3 /usr/syno/etc/private/session/syno-pam-key.db "UPDATE key SET enabled=0 WHERE scope='SynoCgiKnownDevice' and attribute2='browser';"
fi
if [ -s /usr/syno/etc/private/session/current.users ]; then
if [ x$CLEAN_SESSION == "xno" ]; then
if [ `/bin/grep -c -a -v '"duration"\s*:\s*"0"' /usr/syno/etc/private/session/current.users` -ne 0 ]; then
/bin/grep -a -v '"duration"\s*:\s*"0"' /usr/syno/etc/private/session/current.users > /usr/syno/etc/private/session/current.users.tmp
/bin/mv -f /usr/syno/etc/private/session/current.users.tmp /usr/syno/etc/private/session/current.users
fi
else
if [ `/bin/grep -c -a '"duration"\s*:\s*"-1"' /usr/syno/etc/private/session/current.users` -ne 0 ]; then
/bin/grep -a '"duration"\s*:\s*"-1"' /usr/syno/etc/private/session/current.users > /usr/syno/etc/private/session/current.users.tmp
/bin/mv -f /usr/syno/etc/private/session/current.users.tmp /usr/syno/etc/private/session/current.users
else
/bin/cp /dev/null /usr/syno/etc/private/session/current.users
fi
fi
fi
if [ -d /usr/syno/etc/private/session/current.users.access.time/ ]; then
for i in `find /usr/syno/etc/private/session/current.users.access.time/ -type f`; do
id=`basename $i`;
if ! /bin/grep -- $id /usr/syno/etc/private/session/current.users ; then
/bin/rm -f $i;
fi
done
fi