Skip to content

Commit

Permalink
feature: support output log to syslog.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Dec 29, 2023
1 parent 60b5e2b commit 339dfa3
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 180 deletions.
3 changes: 2 additions & 1 deletion etc/smartdns/smartdns.conf
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ force-qtype-SOA 65
# max-query-limit 65535

# response mode
# Experimental feature
# response-mode [first-ping|fastest-ip|fastest-response]

# set log level
# log-level: [level], level=off, fatal, error, warn, notice, info, debug
# log-file: file path of log file.
# log-console [yes|no]: output log to console.
# log-syslog [yes|no]: output log to syslog.
# log-size: size of each log file, support k,m,g
# log-num: number of logs, 0 means disable log
log-level info
Expand All @@ -179,6 +179,7 @@ log-level info
# audit-size size of each audit file, support k,m,g
# audit-file /var/log/smartdns-audit.log
# audit-console [yes|no]: output audit log to console.
# audit-syslog [yes|no]: output audit log to syslog.
# audit-file-mode [mode]: file mode of audit file.
# audit-size 128k
# audit-num 2
Expand Down
27 changes: 27 additions & 0 deletions package/luci-compat/files/luci/i18n/smartdns.zh-cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ msgstr "额外的服务器参数,参考bind选项的帮助说明。"
msgid "Advanced Settings"
msgstr "高级设置"

msgid "Audit Log Output Mode"
msgstr "审计日志输出模式"

msgid "Audit Log Size"
msgstr "审计日志大小"

msgid "Audit Log Number"
msgstr "审计日志数量"

msgid "Audit Log File"
msgstr "审计日志文件路径"

msgid ""
"Attempts to serve old responses from cache with a TTL of 0 in the response "
"without waiting for the actual resolution to finish."
Expand Down Expand Up @@ -235,6 +247,9 @@ msgstr "每周日"
msgid "Update Time (Every Day)"
msgstr "更新时间(每天)"

msgid "Enable Audit Log"
msgstr "启用审计日志"

msgid "Enable domain prefetch, accelerate domain response speed."
msgstr "启用域名预加载,加速域名响应速度。"

Expand All @@ -250,6 +265,9 @@ msgstr "从default默认服务器组中排除。"
msgid "Exclude Default Group"
msgstr "从默认组中排除"

msgid "file"
msgstr "文件"

msgid "Fastest IP"
msgstr "最快IP"

Expand Down Expand Up @@ -338,6 +356,9 @@ msgstr "监听在指定的设备上,避免非本地网络的DNS查询请求。
msgid "Local Port"
msgstr "本地端口"

msgid "Log Output Mode"
msgstr "日志输出模式"

msgid "Log Size"
msgstr "日志大小"

Expand Down Expand Up @@ -449,6 +470,9 @@ msgstr "重启"
msgid "Restart Service"
msgstr "重启服务"

msgid "syslog"
msgstr "系统日志"

msgid "Second Server Settings"
msgstr "第二DNS服务器"

Expand Down Expand Up @@ -523,6 +547,9 @@ msgstr "跳过双栈优选"
msgid "Skip Dualstack Selection."
msgstr "跳过双栈优选。"

msgid "Skip IP Alias"
msgstr "跳过IP别名"

msgid "Skip Ipset Rule"
msgstr "跳过ipset规则"

Expand Down
57 changes: 50 additions & 7 deletions package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

o = s:taboption("seconddns", Flag, "seconddns_no_ip_alias", translate("Skip IP Alias"))
o.rmempty = true
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

o = s:taboption("seconddns", Value, "seconddns_ipset_name", translate("IPset Name"), translate("IPset name."))
o.rmempty = true
o.datatype = "hostname"
Expand Down Expand Up @@ -494,10 +501,6 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

o = s:taboption("custom", Value, "log_size", translate("Log Size"))
o.rmempty = true
o.placeholder = "default"

o = s:taboption("custom", ListValue, "log_level", translate("Log Level"))
o.rmempty = true
o.placeholder = "default"
Expand All @@ -510,13 +513,53 @@ o:value("error")
o:value("fatal")
o:value("off")

o = s:taboption("custom", Value, "log_num", translate("Log Number"))
o.rmempty = true
o.placeholder = "default"
o = s:taboption("custom", ListValue, "log_output_mode", translate("Log Output Mode"));
o.rmempty = true;
o.placeholder = translate("file");
o:value("file", translate("file"));
o:value("syslog", translate("syslog"));

o = s:taboption("custom", Value, "log_size", translate("Log Size"));
o.rmempty = true;
o.placeholder = "default";
o:depends("log_output_mode", "file");

o = s:taboption("custom", Value, "log_num", translate("Log Number"));
o.rmempty = true;
o.placeholder = "default";
o:depends("log_output_mode", "file");

o = s:taboption("custom", Value, "log_file", translate("Log File"))
o.rmempty = true
o.placeholder = "/var/log/smartdns/smartdns.log"
o:depends("log_output_mode", "file");

o = s:taboption("custom", Flag, "enable_audit_log", translate("Enable Audit Log"));
o.rmempty = true;
o.default = o.disabled;
o.rempty = true;

o = s:taboption("custom", ListValue, "audit_log_output_mode", translate("Audit Log Output Mode"));
o.rmempty = true;
o.placeholder = translate("file");
o:value("file", translate("file"));
o:value("syslog", translate("syslog"));
o:depends("enable_audit_log", "1");

o = s:taboption("custom", Value, "audit_log_size", translate("Audit Log Size"));
o.rmempty = true;
o.placeholder = "default";
o:depends({enable_audit_log = "1", audit_log_output_mode = "file"});

o = s:taboption("custom", Value, "audit_log_num", translate("Audit Log Number"));
o.rmempty = true;
o.placeholder = "default";
o:depends({enable_audit_log = "1", audit_log_output_mode = "file"});

o = s:taboption("custom", Value, "audit_log_file", translate("Audit Log File"))
o.rmempty = true
o.placeholder = "/var/log/smartdns/smartdns-audit.log"
o:depends({enable_audit_log = "1", audit_log_output_mode = "file"});

-- Upstream servers
s = m:section(TypedSection, "server", translate("Upstream Servers"), translate("Upstream Servers, support UDP, TCP protocol. " ..
Expand Down
27 changes: 27 additions & 0 deletions package/luci/files/luci/i18n/smartdns.zh-cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ msgstr "额外的服务器参数,参考bind选项的帮助说明。"
msgid "Advanced Settings"
msgstr "高级设置"

msgid "Audit Log Output Mode"
msgstr "审计日志输出模式"

msgid "Audit Log Size"
msgstr "审计日志大小"

msgid "Audit Log Number"
msgstr "审计日志数量"

msgid "Audit Log File"
msgstr "审计日志文件路径"

msgid ""
"Attempts to serve old responses from cache with a TTL of 0 in the response "
"without waiting for the actual resolution to finish."
Expand Down Expand Up @@ -230,6 +242,9 @@ msgstr "更新时间(每天)"
msgid "Update Time (Every Week)"
msgstr "更新时间(每周)"

msgid "Enable Audit Log"
msgstr "启用审计日志"

msgid "Every Day"
msgstr "每天"

Expand Down Expand Up @@ -269,6 +284,9 @@ msgstr "从default默认服务器组中排除。"
msgid "Exclude Default Group"
msgstr "从默认组中排除"

msgid "file"
msgstr "文件"

msgid "Fastest IP"
msgstr "最快IP"

Expand Down Expand Up @@ -381,6 +399,9 @@ msgstr "监听在指定的设备上,避免非本地网络的DNS查询请求。
msgid "Local Port"
msgstr "本地端口"

msgid "Log Output Mode"
msgstr "日志输出模式"

msgid "Log Size"
msgstr "日志大小"

Expand Down Expand Up @@ -498,6 +519,9 @@ msgstr "重启"
msgid "Restart Service"
msgstr "重启服务"

msgid "syslog"
msgstr "系统日志"

msgid "Second Server Settings"
msgstr "第二DNS服务器"

Expand Down Expand Up @@ -575,6 +599,9 @@ msgstr "跳过双栈优选"
msgid "Skip Dualstack Selection."
msgstr "跳过双栈优选。"

msgid "Skip IP Alias"
msgstr "跳过IP别名"

msgid "Skip Ipset Rule"
msgstr "跳过ipset规则"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ return view.extend({
o.rmempty = true;
o.default = o.disabled;

o = s.taboption("seconddns", form.Flag, "seconddns_no_ip_alias", _("Skip IP Alias"));
o.rmempty = true;
o.default = o.disabled;

o = s.taboption("seconddns", form.Value, "seconddns_ipset_name", _("IPset Name"), _("IPset name."));
o.rmempty = true;
o.datatype = "string";
Expand Down Expand Up @@ -672,10 +676,6 @@ return view.extend({
o.rmempty = true;
o.default = o.disabled;

o = s.taboption("custom", form.Value, "log_size", _("Log Size"));
o.rmempty = true;
o.placeholder = "default";

o = s.taboption("custom", form.ListValue, "log_level", _("Log Level"));
o.rmempty = true;
o.placeholder = "default";
Expand All @@ -688,13 +688,53 @@ return view.extend({
o.value("fatal");
o.value("off");

o = s.taboption("custom", form.ListValue, "log_output_mode", _("Log Output Mode"));
o.rmempty = true;
o.placeholder = _("file");
o.value("file", _("file"));
o.value("syslog", _("syslog"));

o = s.taboption("custom", form.Value, "log_size", _("Log Size"));
o.rmempty = true;
o.placeholder = "default";
o.depends("log_output_mode", "file");

o = s.taboption("custom", form.Value, "log_num", _("Log Number"));
o.rmempty = true;
o.placeholder = "default";
o.depends("log_output_mode", "file");

o = s.taboption("custom", form.Value, "log_file", _("Log File"))
o.rmempty = true
o.placeholder = "/var/log/smartdns/smartdns.log"
o.depends("log_output_mode", "file");

o = s.taboption("custom", form.Flag, "enable_audit_log", _("Enable Audit Log"));
o.rmempty = true;
o.default = o.disabled;
o.rempty = true;

o = s.taboption("custom", form.ListValue, "audit_log_output_mode", _("Audit Log Output Mode"));
o.rmempty = true;
o.placeholder = _("file");
o.value("file", _("file"));
o.value("syslog", _("syslog"));
o.depends("enable_audit_log", "1");

o = s.taboption("custom", form.Value, "audit_log_size", _("Audit Log Size"));
o.rmempty = true;
o.placeholder = "default";
o.depends({"enable_audit_log":"1", "audit_log_output_mode":"file"});

o = s.taboption("custom", form.Value, "audit_log_num", _("Audit Log Number"));
o.rmempty = true;
o.placeholder = "default";
o.depends({"enable_audit_log":"1", "audit_log_output_mode":"file"});

o = s.taboption("custom", form.Value, "audit_log_file", _("Audit Log File"))
o.rmempty = true
o.placeholder = "/var/log/smartdns/smartdns-audit.log"
o.depends({"enable_audit_log":"1", "audit_log_output_mode":"file"});

////////////////
// Upstream servers;
Expand Down
21 changes: 21 additions & 0 deletions package/openwrt/files/etc/init.d/smartdns
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ load_second_server()
config_get_bool seconddns_force_aaaa_soa "$section" "seconddns_force_aaaa_soa" "0"
[ "$seconddns_force_aaaa_soa" = "1" ] && ARGS="$ARGS -force-aaaa-soa"

config_get_bool seconddns_no_ip_alias "$section" "seconddns_no_ip_alias" "0"
[ "$seconddns_no_ip_alias" = "1" ] && ARGS="$ARGS -no-ip-alias"

config_get seconddns_ipset_name "$section" "seconddns_ipset_name" ""
[ -z "$seconddns_ipset_name" ] || ARGS="$ARGS -ipset $seconddns_ipset_name"

Expand Down Expand Up @@ -615,6 +618,24 @@ load_service()
config_get log_file "$section" "log_file" ""
[ -z "$log_file" ] || conf_append "log-file" "$log_file"

config_get log_output_mode "$section" "log_output_mode" ""
[ "$log_output_mode" = "syslog" ] && conf_append "log-syslog" "yes"

config_get_bool enable_audit_log "$section" "enable_audit_log" "0"
[ "$enable_audit_log" = "1" ] && conf_append "audit-enable" "yes"

config_get audit_log_size "$section" "audit_log_size" "64K"
[ -z "$audit_log_size" ] || conf_append "audit-size" "$audit_log_size"

config_get audit_log_num "$section" "audit_log_num" "1"
[ -z "$audit_log_num" ] || conf_append "audit-num" "$audit_log_num"

config_get audit_log_file "$section" "audit_log_file" ""
[ -z "$audit_log_file" ] || conf_append "audit-file" "$audit_log_file"

config_get audit_log_output_mode "$section" "audit_log_output_mode" ""
[ "$audit_log_output_mode" = "syslog" ] && conf_append "audit-syslog" "yes"

config_get response_mode "$section" "response_mode" ""
[ -z "$response_mode" ] || conf_append "response-mode" "$response_mode"

Expand Down
Loading

0 comments on commit 339dfa3

Please sign in to comment.