File: logoff

package info (click to toggle)
nufw 2.4.3-2.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 5,728 kB
  • sloc: ansic: 32,174; sh: 10,146; python: 4,176; makefile: 965; perl: 630; lex: 176; php: 168; yacc: 117; xml: 34
file content (16 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
# $Id$

user="nufw-user"
passwd="nufw-passwd"
db="nufw-db"
LOGOUT_TIME="30 MINUTE"

UNLOG=`mysql -u ${user} -p${passwd} ${db} -s -N -e "select HEX(ip_saddr) from ipauth_sessions where no_logout='n' and ip_saddr not in (select distinct ip_saddr from conntrack_ulog where state=1 or state=2) and ip_saddr not in (select distinct ip_saddr from ulog where timestamp > NOW() - INTERVAL ${LOGOUT_TIME})"`

[ -z "${UNLOG}" ] && exit 0

UNLOG=x\'`echo ${UNLOG} | sed -e "s/ /\',x\'/g"`\'

mysql -u ${user} -p${passwd} ${db} -s -N -e "delete from ipauth_sessions where ip_saddr in ($UNLOG)"
mysql -u ${user} -p${passwd} ${db} -s -N -e "UPDATE users set end_time=NOW() where (end_time is null) and ip_saddr in ($UNLOG)"