feat: structured upstream DNS / allow-recursion editor in Web UI
新增配置管理页面 '上游 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:表单输入 -> 写文件 -> 再解析 -> 一致
This commit is contained in:
@@ -23,6 +23,41 @@
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user