1614e37386
新增配置管理页面 '上游 DNS 转发' 卡片,让管理员通过两个 textarea
分别维护 forwarders 和 allow-recursion,不需要手写 BIND 语法:
- 每行一个 IP / CIDR
- 支持 # 和 // 注释
- 留空 = 清空该字段(forwarders 留空表示走根提示;
allow-recursion 留空表示只有 localhost/localnets 能递归)
实现要点:
1. _parse_options_lists() 从 options 文件文本里抽出 forwarders /
allow-recursion 列表(用大括号平衡匹配,不依赖单行格式)。
2. _replace_or_append_option() 在 options block 里精准替换已有 directive,
自动跟随原缩进;找不到则按 4 空格缩进追加到 'options {' 之后;
options block 本身不存在则新建一个。
3. _ensure_options_file() 自动创建缺失的 options 文件(带合理的最小
默认值),避免 'No such file' 错误。
4. config_upstream_save() 写文件前用 named-checkconf 验证语法,
失败则不写入;成功则备份 .bak + 写文件 + rndc reload。
附带的修复:config_view 进入页面时也调用 _ensure_options_file(),
解决了 'Web 端第一次配置 options 文件不存在' 的问题。
模板 templates/config.html 新增 '上游 DNS 转发' 卡片,放在 named.conf
主配置卡片和 named.conf.options 卡片之间,placeholder 给出常用示例
(223.5.5.5 / 114.114.114.114 / RFC1918 三段)。
回归测试(dev 环境):
- _parse_options_lists: 正确从样例 options 抽出 3 forwarders + 2 recursion
- _replace_or_append_option: 替换后缩进正确,保留其它 directives
- round-trip:表单输入 -> 写文件 -> 再解析 -> 一致
126 lines
5.0 KiB
HTML
126 lines
5.0 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}配置管理 - DNS{% endblock %}
|
|
{% block content %}
|
|
<div class="page-header">
|
|
<h1>BIND 配置管理</h1>
|
|
</div>
|
|
|
|
<div class="config-status {% if config_ok %}config-ok{% else %}config-err{% endif %}">
|
|
<span class="config-icon">{% if config_ok %}✅{% else %}❌{% endif %}</span>
|
|
<span>配置检查: {% if config_ok %}通过{% else %}有错误{% endif %}</span>
|
|
{% if not config_ok %}
|
|
<pre class="config-error">{{ config_msg }}</pre>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2>named.conf (主配置)</h2>
|
|
<span class="text-muted text-sm">只读</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<pre class="config-viewer">{{ main_content }}</pre>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2>上游 DNS 转发</h2>
|
|
<span class="text-muted text-sm">结构化字段 — 不需要手写 BIND 语法</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="POST" action="{{ url_for('config_upstream_save') }}">
|
|
<div class="form-group">
|
|
<label for="forwarders">
|
|
<strong>Forwarders</strong>
|
|
<span class="text-muted text-sm">每行一个上游 DNS IP(v4 / v6 都可)。留空表示使用根提示。</span>
|
|
</label>
|
|
<textarea name="forwarders" class="code-editor" rows="5" spellcheck="false"
|
|
placeholder="223.5.5.5 114.114.114.114 8.8.8.8">{% for ip in forwarders %}{{ ip }}
|
|
{% endfor %}</textarea>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="recursion">
|
|
<strong>Allow-recursion 网段</strong>
|
|
<span class="text-muted text-sm">允许递归查询外网的客户端 CIDR。留空表示只允许本机。</span>
|
|
</label>
|
|
<textarea name="recursion" class="code-editor" rows="5" spellcheck="false"
|
|
placeholder="127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16">{% for net in recursion %}{{ net }}
|
|
{% endfor %}</textarea>
|
|
</div>
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary">💾 保存并重载</button>
|
|
<span class="text-muted text-sm" style="margin-left: 12px;">
|
|
此处只改 forwarders 和 allow-recursion;其它 options 字段请用下方文本编辑器。
|
|
</span>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2>named.conf.options (选项配置)</h2>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="POST" action="{{ url_for('config_options_save') }}">
|
|
<div class="form-group">
|
|
<textarea name="content" class="code-editor" rows="20" spellcheck="false">{{ options_content }}</textarea>
|
|
</div>
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary">💾 保存并重载</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2>named.conf.local (本地区域配置)</h2>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="POST" action="{{ url_for('config_local_save') }}">
|
|
<div class="form-group">
|
|
<textarea name="content" class="code-editor" rows="20" spellcheck="false">{{ local_content }}</textarea>
|
|
</div>
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary">💾 保存并重载</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header"><h2>配置说明</h2></div>
|
|
<div class="card-body">
|
|
<table class="table">
|
|
<thead>
|
|
<tr><th>配置文件</th><th>用途</th><th>路径</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><strong>named.conf</strong></td>
|
|
<td>主配置,包含其他配置文件</td>
|
|
<td class="text-mono text-sm">/etc/bind/named.conf</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>named.conf.options</strong></td>
|
|
<td>全局选项: 监听端口/地址、转发器、查询权限等</td>
|
|
<td class="text-mono text-sm">/etc/bind/named.conf.options</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>named.conf.local</strong></td>
|
|
<td>区域(zone)声明 - 由 Web UI 自动管理</td>
|
|
<td class="text-mono text-sm">/etc/bind/named.conf.local</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>zone files</strong></td>
|
|
<td>DNS 记录文件</td>
|
|
<td class="text-mono text-sm">/etc/bind/zones/db.*</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|