31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from flask import Blueprint, request, redirect, flash
|
|
from auth import require_level
|
|
from config_utils import load_core, save_core, verify_core_hash
|
|
|
|
bp = Blueprint('action_apply_ddns_ip_check', __name__)
|
|
|
|
VIEW = '/view/view_ddns'
|
|
|
|
|
|
@bp.route('/action/ddns_ip_check_save', methods=['POST'])
|
|
@require_level('administrator')
|
|
def ddns_ip_check_save():
|
|
if not verify_core_hash(request.form.get('config_hash', '')):
|
|
flash('Configuration was modified by another session. Please refresh and try again.', 'error')
|
|
return redirect(VIEW)
|
|
|
|
http_services = [u.strip() for u in request.form.getlist('http_services') if u.strip()]
|
|
dig_services = [u.strip() for u in request.form.getlist('dig_services') if u.strip()]
|
|
|
|
if not http_services and not dig_services:
|
|
flash('At least one IP check service is required.', 'error')
|
|
return redirect(VIEW)
|
|
|
|
services = [{'type': 'http', 'url': u} for u in http_services]
|
|
services += [{'type': 'dig', 'url': u} for u in dig_services]
|
|
|
|
core = load_core()
|
|
core.setdefault('ddns', {})['ip_check_services'] = services
|
|
save_core(core)
|
|
flash('IP check services saved.', 'success')
|
|
return redirect(VIEW)
|