From 90ad7895fdee1b2075e69277e112c421fb744cc2 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 10 May 2020 03:20:02 -0400 Subject: [PATCH] Cosmetic changes, add misc configuration row to jail quick config --- CHANGELOG | 1 + gui/bastille_manager_jconf.php | 100 +++++++++++++++++++++++++-------- gui/bastille_manager_util.php | 92 +++++++++++++++--------------- version | 2 +- 4 files changed, 125 insertions(+), 70 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f4d3028..285bb76 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ ====================== Version Description +1.0.50......Cosmetic changes, add misc configuration row to jail quick config. 1.0.49......Don't allow for blank fields in the jail config page. 1.0.48......Added jail name validation. 1.0.47......Cosmetic changes, display notify on success. diff --git a/gui/bastille_manager_jconf.php b/gui/bastille_manager_jconf.php index 2467faa..5279301 100644 --- a/gui/bastille_manager_jconf.php +++ b/gui/bastille_manager_jconf.php @@ -63,9 +63,12 @@ endif; $pgtitle = [gtext('Extensions'),gtext('Bastille'),gtext('Configuration'), $container]; $jail_config = "$jail_dir/$container/jail.conf"; +// Get some jail system settings. +$is_vnet = exec("/usr/bin/grep '.*vnet;' $jail_config"); +$pconfig['autostart'] = exec("/usr/bin/grep '{$container}_AUTO_START=\"YES\"' $bastille_config"); + // Get some jail config parameters. // This could be done with a nice php preg loop in the future. -$is_vnet = exec("/usr/bin/grep '.*vnet;' $jail_config"); $pconfig['jname'] = "$container"; $pconfig['hostname'] = exec("/usr/bin/grep '.*host.hostname.*=' $jail_config | /usr/bin/sed 's/.*host.hostname.*= //;s/;//'"); $pconfig['ipv4'] = exec("/usr/bin/grep '.*ip4.addr.*=' $jail_config | /usr/bin/sed 's/.*ip4.addr.*= //;s/;//'"); @@ -88,6 +91,7 @@ $jail_enforce_statfs_def = $pconfig['enforce_statfs']; $jail_vnet_interface_def = $pconfig['vnet_interface']; if ($_POST): + global $configfile; unset($savemsg); unset($input_errors); $pconfig = $_POST; @@ -153,24 +157,50 @@ if ($_POST): else: if(isset($_POST['Submit']) && $_POST['Submit']): - // Check if the jail is running. - $cmd = "/usr/sbin/jls -j $container >/dev/null 2>&1"; - unset($output,$retval);mwexec2($cmd,$output,$retval); - if($retval == 0): - $savemsg .= gtext("This jail is running, please stop it before making config changes."); + // Set current config values. + $jail_name = $pconfig['jname']; + $jail_hostname = $pconfig['hostname']; + $jail_ipv4 = $pconfig['ipv4']; + $jail_ipv6 = $pconfig['ipv6']; + $jail_interface = $pconfig['interface']; + $jail_securelevel = $pconfig['securelevel']; + $jail_devfs_ruleset = $pconfig['devfs_ruleset']; + $jail_enforce_statfs = $pconfig['enforce_statfs']; + $jail_vnet_interface = $pconfig['vnet_interface']; + + // Check if the config has changed. + // This could be done with a nice foreach loop in the future. + if($jail_name_def !== $jail_name): + $is_changed = "1"; + elseif($jail_hostname_def !== $jail_hostname): + $is_changed = "1"; + elseif(isset($_POST['ipv4']) && ($jail_ipv4_def !== $jail_ipv4)): + $is_changed = "1"; + elseif(isset($_POST['ipv6']) && ($jail_ipv6_def !== $jail_ipv6)): + $is_changed = "1"; + elseif(isset($_POST['interface']) && ($jail_interface_def !== $jail_interface)): + $is_changed = "1"; + elseif($jail_securelevel_def !== $jail_securelevel): + $is_changed = "1"; + elseif($jail_devfs_ruleset_def !== $jail_devfs_ruleset): + $is_changed = "1"; + elseif($jail_enforce_statfs_def !== $jail_enforce_statfs): + $is_changed = "1"; + elseif(isset($_POST['vnet_interface']) && ($jail_vnet_interface_def !== $jail_vnet_interface)): + $is_changed = "1"; + endif; + + if($is_changed): + // Check if the jail is running. + $cmd = "/usr/sbin/jls -j $container >/dev/null 2>&1"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + else: + // Skip jail running check. + $retval = "1"; + endif; + if($retval == 0): + $input_errors[] = gtext("This jail is running, please stop it before making jail.conf changes."); else: - - // Set current config values. - $jail_name = $pconfig['jname']; - $jail_hostname = $pconfig['hostname']; - $jail_ipv4 = $pconfig['ipv4']; - $jail_ipv6 = $pconfig['ipv6']; - $jail_interface = $pconfig['interface']; - $jail_securelevel = $pconfig['securelevel']; - $jail_devfs_ruleset = $pconfig['devfs_ruleset']; - $jail_enforce_statfs = $pconfig['enforce_statfs']; - $jail_vnet_interface = $pconfig['vnet_interface']; - if (isset($_POST['hostname']) && $_POST['hostname']): if($jail_hostname_def !== $jail_hostname): $cmd = "/usr/bin/sed -i '' 's/.*host.hostname.*=.*;/ host.hostname = $jail_hostname;/' $jail_config"; @@ -282,6 +312,24 @@ if ($_POST): endif; endif; endif; + + if (isset($_POST['autostart']) && $_POST['autostart']): + $cmd = ("/usr/sbin/sysrc -f $configfile {$container}_AUTO_START=\"YES\""); + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + //$savemsg .= gtext("Autostart changed successfully."); + else: + $input_errors[] = gtext("Failed to enable autostart."); + endif; + else: + $cmd = ("/usr/sbin/sysrc -f $configfile {$container}_AUTO_START=\"NO\""); + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + //$savemsg .= gtext("Autostart changed successfully."); + else: + $input_errors[] = gtext("Failed to disable autostart."); + endif; + endif; //header("Location: bastille_manager_gui.php"); $savemsg .= gtext("Configuration has been saved successfully."); endif; @@ -294,11 +342,11 @@ endif; + +
-
    -
  • -
  • -
-
@@ -326,6 +374,12 @@ endif; html_inputbox("vnet_interface", gtext("VNET Interface"), $pconfig['vnet_interface'], gtext("Set the VNET interface manually, usually should not be changed unless renaming the interface or moving jail from host."), false, 20); endif; ?> +
" /> diff --git a/gui/bastille_manager_util.php b/gui/bastille_manager_util.php index c6bf7d9..b391035 100644 --- a/gui/bastille_manager_util.php +++ b/gui/bastille_manager_util.php @@ -185,43 +185,43 @@ if($_POST): endif; break; - case 'autoboot': - // Input validation not required - if(empty($input_errors)): - $container = []; - $container['uuid'] = $_POST['uuid']; - $container['jailname'] = $_POST['jailname']; - $confirm_name = $pconfig['confirmname']; - $item = $container['jailname']; - $cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"YES\""); - unset($output,$retval);mwexec2($cmd,$output,$retval); - if($retval == 0): - header('Location: bastille_manager_gui.php'); - exit; - else: - $input_errors[] = gtext("Failed to set auto-boot."); - endif; - endif; - break; + //case 'autoboot': + // // Input validation not required + // if(empty($input_errors)): + // $container = []; + // $container['uuid'] = $_POST['uuid']; + // $container['jailname'] = $_POST['jailname']; + // $confirm_name = $pconfig['confirmname']; + // $item = $container['jailname']; + // $cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"YES\""); + // unset($output,$retval);mwexec2($cmd,$output,$retval); + // if($retval == 0): + // header('Location: bastille_manager_gui.php'); + // exit; + // else: + // $input_errors[] = gtext("Failed to set auto-boot."); + // endif; + // endif; + // break; - case 'noauto': - // Input validation not required - if(empty($input_errors)): - $container = []; - $container['uuid'] = $_POST['uuid']; - $container['jailname'] = $_POST['jailname']; - $confirm_name = $pconfig['confirmname']; - $item = $container['jailname']; - $cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"NO\""); - unset($output,$retval);mwexec2($cmd,$output,$retval); - if($retval == 0): - header('Location: bastille_manager_gui.php'); - exit; - else: - $input_errors[] = gtext("Failed to set no-auto."); - endif; - endif; - break; + //case 'noauto': + // // Input validation not required + // if(empty($input_errors)): + // $container = []; + // $container['uuid'] = $_POST['uuid']; + // $container['jailname'] = $_POST['jailname']; + // $confirm_name = $pconfig['confirmname']; + // $item = $container['jailname']; + // $cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"NO\""); + // unset($output,$retval);mwexec2($cmd,$output,$retval); + // if($retval == 0): + // header('Location: bastille_manager_gui.php'); + // exit; + // else: + // $input_errors[] = gtext("Failed to set no-auto."); + // endif; + // endif; + // break; case 'fstab': // Input validation not required @@ -361,14 +361,14 @@ function action_change() { showElementById('jail_release_tr', 'show'); showElementById('release_tr','show'); break; - case "autoboot": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); - break; - case "noauto": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); - break; + //case "autoboot": + // showElementById('confirmname_tr','hide'); + // showElementById('nowstop_tr','hide'); + // break; + //case "noauto": + // showElementById('confirmname_tr','hide'); + // showElementById('nowstop_tr','hide'); + // break; case "fstab": showElementById('confirmname_tr','hide'); showElementById('nowstop_tr','hide'); @@ -451,8 +451,8 @@ $document->render(); 'backup' => gettext('Backup'), 'update' => gettext('Update'), 'base' => gettext('Release'), - 'autoboot' => gettext('Autoboot'), - 'noauto' => gettext('Noauto'), + //'autoboot' => gettext('Autoboot'), + //'noauto' => gettext('Noauto'), 'fstab' => gettext('Fstab'), 'delete' => gettext('Destroy'), 'advanced' => gettext('Advanced'), diff --git a/version b/version index f133985..3e9c4a6 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.0.49 +1.0.50