dns/bind: check&preview primary zone, log to syslog with desired severity (#3708)

* dns/bind: check&preview primary zone, log to syslog with desired severity

and make grids responsive also

* ver bump

and remove foreign part from template

* Update dns/bind/src/etc/inc/plugins.inc.d/bind.inc

* Update dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/General.xml

* cleanup

-prettify js, actions naming, phalcon post payload handling.
-Error message if Check&Preview button clicked for disabled Zone
-dont show Copy button if not supported

---------

Co-authored-by: Franco Fichtner <franco@lastsummer.de>
This commit is contained in:
kulikov-a
2024-01-09 17:33:44 +01:00
committed by GitHub
co-authored by Franco Fichtner
parent d92bb27d87
commit cfac344e4a
13 changed files with 438 additions and 175 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
PLUGIN_NAME= bind
PLUGIN_VERSION= 1.28
PLUGIN_REVISION= 1
PLUGIN_VERSION= 1.29
PLUGIN_COMMENT= BIND domain name service
PLUGIN_DEPENDS= bind918
PLUGIN_MAINTAINER= m.muenz@gmail.com
+5
View File
@@ -10,6 +10,11 @@ WWW: https://www.isc.org
Plugin Changelog
================
1.29
* Migrate General Log to Syslog
* Add Check & Preview button to Primary Zones grid
1.28
* Add break-dnssec toggle when using filter-aaaa on IPv4/IPv6 clients (contributed by doktornotor)
@@ -99,3 +99,16 @@ function bind_configure_do($verbose)
service_log("done.\n", $verbose);
}
/**
* register syslog facilities
* @return array
*/
function bind_syslog()
{
$syslogconf = [];
$syslogconf['bind'] = ['facility' => ['named']];
return $syslogconf;
}
@@ -31,9 +31,32 @@
namespace OPNsense\Bind\Api;
use OPNsense\Base\ApiMutableModelControllerBase;
use OPNsense\Core\Backend;
class GeneralController extends ApiMutableModelControllerBase
{
protected static $internalModelClass = '\OPNsense\Bind\General';
protected static $internalModelName = 'general';
public function zonetestAction($zonename = null)
{
$response = "request error";
if ($this->request->hasPost("zone")) {
$zonename = $this->request->getPost("zone");
$backend = new Backend();
$response = trim($backend->configdpRun("bind zone check", [$zonename]));
}
return array("response" => $response);
}
public function zoneshowAction($zonename = null)
{
$response = "request error";
if ($this->request->hasPost("zone")) {
$zonename = $this->request->getPost("zone");
$backend = new Backend();
$response = json_decode($backend->configdpRun("bind zone show", [$zonename]), true);
}
return $response;
}
}
@@ -93,7 +93,14 @@
<id>general.logsize</id>
<label>Logsize in MB</label>
<type>text</type>
<help>Set the amount how big a logfile can growth.</help>
<help>Set the amount how big a logfile can growth. For Query and Blocked logs.</help>
</field>
<field>
<id>general.general_log_level</id>
<label>General Log level</label>
<style>selectpicker</style>
<type>dropdown</type>
<help>Select General Log level. Log levels are listed in the order of increasing verbosity. Setting a certain log level will cause all messages of the specified and more severe log levels to be logged.</help>
</field>
<field>
<id>general.maxcachesize</id>
@@ -1,7 +1,7 @@
<model>
<mount>//OPNsense/bind/general</mount>
<description>BIND configuration</description>
<version>1.0.10</version>
<version>1.0.11</version>
<items>
<enabled type="BooleanField">
<default>0</default>
@@ -76,6 +76,20 @@
<MaximumValue>1000</MaximumValue>
<ValidationMessage>Choose a value between 1 and 1000.</ValidationMessage>
</logsize>
<general_log_level type="OptionField">
<OptionValues>
<emerg value="emerg">Emergency</emerg>
<alert value="alert">Alert</alert>
<crit value="crit">Critical</crit>
<error value="error">Error</error>
<warn value="warn">Warning</warn>
<notice value="notice">Notice</notice>
<info value="info">Informational</info>
<debug value="debug">Debug</debug>
</OptionValues>
<Required>Y</Required>
<default>info</default>
</general_log_level>
<maxcachesize type="IntegerField">
<default>80</default>
<Required>Y</Required>
File diff suppressed because it is too large Load Diff
@@ -27,16 +27,6 @@
<script>
$( document ).ready(function() {
// get entries from named/named.log
let grid_generallog = $("#grid-generallog").UIBootgrid({
options:{
sorting:false,
rowSelect: false,
selection: false,
rowCount:[20,50,100,200,500,1000,-1],
},
search:'/api/diagnostics/log/named/named'
});
// get entries from named/query.log
let grid_querylog = $("#grid-querylog").UIBootgrid({
@@ -60,19 +50,6 @@
search:'/api/diagnostics/log/named/rpz'
});
grid_generallog.on("loaded.rs.jquery.bootgrid", function(){
$(".action-page").click(function(event){
event.preventDefault();
$("#grid-generallog").bootgrid("search", "");
let new_page = parseInt((parseInt($(this).data('row-id')) / $("#grid-log").bootgrid("getRowCount")))+1;
$("input.search-field").val("");
// XXX: a bit ugly, but clearing the filter triggers a load event.
setTimeout(function(){
$("ul.pagination > li:last > a").data('page', new_page).click();
}, 100);
});
});
grid_querylog.on("loaded.rs.jquery.bootgrid", function(){
$(".action-page").click(function(event){
event.preventDefault();
@@ -112,22 +89,7 @@
<div class="content-box tab-content">
<div id="generallog" class="tab-pane fade in active">
<div class="content-box" style="padding-bottom: 1.5em;">
<div class="col-sm-12">
<table id="grid-generallog" class="table table-condensed table-hover table-striped table-responsive" data-store-selection="true">
<thead>
<tr>
<th data-column-id="timestamp" data-width="15em" data-type="string">{{ lang._('Date') }}</th>
<th data-column-id="process_name" data-width="9em" data-type="string">{{ lang._('Type') }}</th>
<th data-column-id="severity" data-width="11em" data-type="string">{{ lang._('Level')}}</th>
<th data-column-id="line" data-type="string">{{ lang._('Line') }}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
{{ partial("OPNsense/Diagnostics/log",['module':'core','scope':'named'])}}
</div>
<div id="querylog" class="tab-pane fade">
@@ -169,5 +131,4 @@
</div>
</div>
</div>
</div>
@@ -0,0 +1,14 @@
#!/bin/sh
# check the primary zone file validity
ZONENAME=${1}
ZONEPATH="/usr/local/etc/namedb/primary/${ZONENAME}.db"
if checkzone_errors=$(named-checkzone ${ZONENAME} ${ZONEPATH} 2>&1); then
echo "Zone check completed successfully"
echo "$checkzone_errors"
else
echo "$checkzone_errors"
fi
exit 0
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
# send primary zone file content to stdout
import sys
import os.path
import glob
import ujson
zone_name = sys.argv[1]
result = dict()
zone_config = []
zone_files_root = '/usr/local/etc/namedb/primary/'
zone_file = zone_files_root + zone_name + '.db'
def load_db_file(zone_file):
""" load db-file
"""
for line in open(zone_file, 'r').read().split('\n'):
zone_config.append(line.rstrip())
if os.path.isfile(zone_file):
result['path'] = zone_file
result['time'] = os.path.getmtime(zone_file)
load_db_file(zone_file)
result['zone_content'] = zone_config
print(ujson.dumps(result))
@@ -40,3 +40,13 @@ parameters:
type:script
message:fetching DNSBLs and restart
description: Download BIND DNSBLs and restart
[zone.check]
command:/usr/local/opnsense/scripts/OPNsense/Bind/zoneCheck.sh
parameters: %s
type:script_output
[zone.show]
command:/usr/local/opnsense/scripts/OPNsense/Bind/zoneShow.py
parameters: %s
type:script_output
@@ -201,6 +201,14 @@ logging {
print-category yes;
};
channel default_syslog {
print-time yes;
print-category yes;
print-severity yes;
syslog daemon;
severity {% if helpers.exists('OPNsense.bind.general.general_log_level') %}{{ OPNsense.bind.general.general_log_level }}{% else %}info{% endif %};
};
channel query_log {
file "/var/log/named/query.log" versions 3 size {{ OPNsense.bind.general.logsize }}m;
print-time yes;
@@ -211,8 +219,11 @@ logging {
print-time yes;
};
category default { default_log; };
category general { default_log; };
category default { default_syslog; };
category general { default_syslog; };
category config { default_syslog; };
category dispatch { default_syslog; };
category network { default_syslog; };
category queries { query_log; };
category rpz { rpz_log; };
category lame-servers { null; };
@@ -0,0 +1,6 @@
###################################################################
# Local syslog-ng configuration filter definition [named].
###################################################################
filter f_local_named {
program("named");
};