#!/usr/bin/env python import sqlite3 import logging import logging.handlers import time import sys import socket import os from xmlrpclib import * def main(): sysloger = logging.getLogger('sysloger') # logging levels = CRITICAL << ERROR << WARNING << INFO << DEBUG << NOTSET sysloger.setLevel(logging.WARNING) sysloger.addHandler(logging.handlers.SysLogHandler(address='/dev/log')) accesslog = "/var/lib/lliurex-sync-server/userlogged" maxtimedelay = 180 #In seconds if os.path.exists(accesslog) : sysloger.info('[lliurex-watchdog] : Database /var/lib/lliurex-listener/userlogged exist') s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(("server",4242)) except: sysloger.error('[lliurex-watchdog] : not connect with server on port 80') sys.exit(1) serverip = s.getpeername()[0] conn = sqlite3.connect(accesslog) mintime = time.time() mintime -= maxtimedelay print (str(mintime)) c = conn.cursor() t = (mintime,) sysloger.debug('[lliurex-watchdog] : sql "select machine, user, mac from users where lasttime <= '+ str(mintime) +'"') c.execute('select machine, user, mac from users where lasttime <= ?',t) server = ServerProxy ("http://"+serverip+":4242") for row in c: sysloger.debug("[lliurex-watchdog] : force logout for user " + row[1] + " in " +row[0]) server.userlogout(row[1],row[0],row[2]) c.close() else: sysloger.warning('[lliurex-watchdog] : Database /var/lib/lliurex-listener/userlogged not exist') if __name__ == '__main__': main()