2018-06-12 07:42:26 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2019-12-06 03:46:54 +00:00
|
|
|
# A CLI Script to update list of domains instead from the UI. Can be useful for people who want to execute updates from a cronjob
|
|
|
|
#
|
2018-06-12 07:42:26 +00:00
|
|
|
# Tip:
|
|
|
|
# When running from a cron, use flock (you might need to install it) to be sure only one process is running a time. eg:
|
|
|
|
# */5 * * * * flock -xn "/tmp/pdns-update-zones.lock" python /var/www/html/apps/poweradmin/update_zones.py >/dev/null 2>&1
|
|
|
|
#
|
|
|
|
##############################################################
|
|
|
|
|
|
|
|
### Imports
|
2019-12-06 03:46:54 +00:00
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from powerdnsadmin import create_app
|
2019-12-04 04:50:46 +00:00
|
|
|
from powerdnsadmin.models.domain import Domain
|
2019-12-06 03:46:54 +00:00
|
|
|
from powerdnsadmin.models.setting import Setting
|
2018-06-12 07:42:26 +00:00
|
|
|
|
2019-12-06 03:46:54 +00:00
|
|
|
app = create_app()
|
|
|
|
app.logger.setLevel(logging.INFO)
|
2018-06-12 07:42:26 +00:00
|
|
|
|
2019-12-06 03:46:54 +00:00
|
|
|
with app.app_context():
|
|
|
|
status = Setting().get('bg_domain_updates')
|
2018-06-12 07:42:26 +00:00
|
|
|
|
2019-12-06 03:46:54 +00:00
|
|
|
### Check if bg_domain_updates is set to true
|
|
|
|
if not status:
|
|
|
|
app.logger.error('Please turn on "bg_domain_updates" setting to run this job.')
|
|
|
|
sys.exit(1)
|
2018-06-12 07:42:26 +00:00
|
|
|
|
2019-12-06 03:46:54 +00:00
|
|
|
### Start the update process
|
2020-08-06 13:16:18 +00:00
|
|
|
app.logger.info('Update domains from nameserver API')
|
2018-06-12 07:42:26 +00:00
|
|
|
|
2020-08-06 13:16:18 +00:00
|
|
|
Domain().update()
|