1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-22 20:44:55 +00:00

py-i2phosts-maint: use config values instead of hardcoded ones

This commit is contained in:
Hidden Z 2010-10-30 20:54:04 +00:00
parent 1d909dc522
commit d0388bc7e2

View File

@ -72,25 +72,26 @@ for host in all_hosts:
# how long host was added # how long host was added
dl = datetime.datetime.now() - host.date_added dl = datetime.datetime.now() - host.date_added
if host.last_seen == None: if host.last_seen == None:
# delete external hosts which we never seen after 365 days of inactivity # delete external hosts which we never seen after X days of inactivity
if host.external == True: if host.external == True:
if dl > datetime.timedelta(days=365): if dl > datetime.timedelta(days=config['external_inactive_max']):
log.info('deleting %s, reason: external host, never seen for 365 days', host.name) log.info('deleting %s, reason: external host, never seen for %s days',
host.name, config['external_inactive_max'])
host.delete() host.delete()
continue continue
# delete hosts added by us and never seen after 14 days of inactivity # delete hosts added by us and never seen after X days of inactivity
else: else:
if dl > datetime.timedelta(days=14): if dl > datetime.timedelta(days=config['internal_inactive_max']):
log.info('deleting %s, reason: internal host, never seen for 14 days', host.name) log.info('deleting %s, reason: internal host, never seen for %s days',
host.name, config['internal_inactive_max'])
host.delete() host.delete()
continue continue
else: else:
# configure registration period for hosts # configure registration period for hosts
# FIXME: make intervals configurable via config or/and commandline
if host.external == True: if host.external == True:
timedelta = datetime.timedelta(days=30) timedelta = datetime.timedelta(days=config['external_expires'])
else: else:
timedelta = datetime.timedelta(days=60) timedelta = datetime.timedelta(days=config['internal_expires'])
# get current host expiration date from database # get current host expiration date from database
if host.expires == None: if host.expires == None:
# workaround for situation when we updating expires first time # workaround for situation when we updating expires first time
@ -105,17 +106,20 @@ for host in all_hosts:
log.debug('updating expires for %s', host.name) log.debug('updating expires for %s', host.name)
host.expires = expires_new host.expires = expires_new
# deactivate if expired # deactivate if expired
min_dl = datetime.timedelta(days=config['activate_min_delay'])
if host.expires < datetime.datetime.now().date(): if host.expires < datetime.datetime.now().date():
log.info('deactivating %s, reason: expired', host.name) log.info('deactivating %s, reason: expired', host.name)
host.activated = False host.activated = False
# if not expired and added more than 3 days ago and approved then activate # if not expired and added more than X days ago and approved then activate
elif dl > datetime.timedelta(days=3) and host.activated == False and host.approved == True: elif dl > min_dl and host.activated == False and host.approved == True:
log.info('activating %s, reason: host up and added more than 3 days ago', host.name) log.info('activating %s, reason: host up and added more than %s days ago',
host.name, config['activate_min_delay'])
host.activated = True host.activated = True
# if expired two years ago then delete # if expired X days ago then delete
dl_e = datetime.datetime.now().date() - host.expires dl_e = datetime.datetime.now().date() - host.expires
if dl_e > datetime.timedelta(days=730): if dl_e > datetime.timedelta(days=config['keep_expired']):
log.info('deleting %s, reason: expired 2 years ago', host.name) log.info('deleting %s, reason: expired % days ago',
host.name, config['keep_expired'])
host.delete() host.delete()
continue continue
host.save() host.save()