Unbound python mod - services.inc

* Include any additional functions as defined by python script include file
* Add missing escapeshellarg()'s
* Make grep mount validation cmd more specific to include "(nullfs"
This commit is contained in:
BBcan177 2019-04-23 20:29:24 -04:00 committed by GitHub
parent 14b1c98d82
commit 6a4635fc80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2204,19 +2204,35 @@ function services_unbound_configure($restart_dhcp = true) {
}
}
$python_mode = false;
if (isset($config['unbound']['python']) && !empty($config['unbound']['python_script'])) {
$python_mode = true;
}
/* Include any additional functions as defined by python script include file */
if (file_exists("{$g['unbound_chroot_path']}/{$config['unbound']['python_script']}_include.inc")) {
exec("/usr/local/bin/php -l " . escapeshellarg("{$g['unbound_chroot_path']}/{$config['unbound']['python_script']}_include.inc")
. " 2>&1", $py_output, $py_retval);
if ($py_retval == 0) {
require_once("{$g['unbound_chroot_path']}/{$config['unbound']['python_script']}_include.inc");
}
}
/* DNS Resolver python integration */
$base_folder = '/usr/local';
foreach (array('/bin', '/lib') as $dir) {
$validate = exec("/sbin/mount | /usr/bin/grep '{$g['unbound_chroot_path']}{$base_folder}{$dir}' 2>&1");
if (isset($config['unbound']['python']) && !empty($config['unbound']['python_script'])) {
$validate = exec("/sbin/mount | /usr/bin/grep " . escapeshellarg("{$g['unbound_chroot_path']}{$base_folder}{$dir} (nullfs") . " 2>&1");
if ($python_mode) {
// Add DNS Resolver python integration
if (empty($validate)) {
if (!is_dir("{$g['unbound_chroot_path']}{$base_folder}{$dir}")) {
safe_mkdir("{$g['unbound_chroot_path']}{$base_folder}{$dir}");
}
exec("/sbin/mount_nullfs -o ro " . escapeshellarg("/usr/local{$dir}") . " " . escapeshellarg("{$g['unbound_chroot_path']}{$base_folder}{$dir}") . " 2>&1", $output, $retval);
$output = $retval = '';
exec("/sbin/mount_nullfs -o ro " . escapeshellarg("/usr/local{$dir}") . ' '
. escapeshellarg("{$g['unbound_chroot_path']}{$base_folder}{$dir}") . " 2>&1", $output, $retval);
// Disable Unbound python on mount failure
if ($retval != 0) {
$config['unbound']['python'] = '';
@ -2233,7 +2249,7 @@ function services_unbound_configure($restart_dhcp = true) {
if ($retval == 0) {
foreach (array( "/usr/local{$dir}", '/usr/local', '/usr') as $folder) {
if (!empty($g['unbound_chroot_path']) && $g['unbound_chroot_path'] != '/' && is_dir("{$g['unbound_chroot_path']}{$folder}")) {
rmdir("{$g['unbound_chroot_path']}{$folder}");
@rmdir(escapeshellarg("{$g['unbound_chroot_path']}{$folder}"));
}
// Delete remaining subfolders on next loop