From d3cc5faa418fcc3958074f148c4a82f87b103d7b Mon Sep 17 00:00:00 2001 From: Jose Date: Sat, 9 May 2020 06:08:54 -0400 Subject: [PATCH] Added simple page for quick jail config, cosmetic changes --- CHANGELOG | 1 + gui/bastille_manager_gui.php | 6 +- gui/bastille_manager_jconf.php | 341 +++++++++++++++++++++++++++++++++ gui/bastille_manager_util.php | 3 - version | 2 +- 5 files changed, 346 insertions(+), 7 deletions(-) create mode 100644 gui/bastille_manager_jconf.php diff --git a/CHANGELOG b/CHANGELOG index a9ffbc3..9851b2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ ====================== Version Description +1.0.46......Added simple page for quick jail config, cosmetic changes. 1.0.45......Minor cosmetic changes. 1.0.44......Plugin/template icons code changes. 1.0.43......Add Swedish translation, thanks to Anders Malm. diff --git a/gui/bastille_manager_gui.php b/gui/bastille_manager_gui.php index cedee69..995bede 100644 --- a/gui/bastille_manager_gui.php +++ b/gui/bastille_manager_gui.php @@ -53,6 +53,7 @@ $gt_record_mod = gtext('Utilities'); $gt_selection_start = gtext('Start Selected'); $gt_selection_stop = gtext('Stop Selected'); $gt_selection_restart = gtext('Restart Selected'); +$gt_record_conf = gtext('Jail Configuration'); $gt_record_inf = gtext('Information'); $gt_selection_start_confirm = gtext('Do you really want to start selected jail(s)?'); $gt_selection_stop_confirm = gtext('Do you want to stop the selected jail(s)?'); @@ -258,7 +259,7 @@ $document->render(); - + @@ -318,9 +319,8 @@ $document->render(); endif; endif; ?> - - + <?=$gt_record_conf?> <?=$gt_record_inf?> diff --git a/gui/bastille_manager_jconf.php b/gui/bastille_manager_jconf.php new file mode 100644 index 0000000..31375b7 --- /dev/null +++ b/gui/bastille_manager_jconf.php @@ -0,0 +1,341 @@ +/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."); + 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"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("Hostname changed successfully."); + else: + $input_errors[] = gtext("Failed to save hostname."); + endif; + endif; + endif; + + if (isset($_POST['jname']) && $_POST['jname']): + if($jail_name_def !== $jail_name): + $cmd = "/usr/local/bin/bastille rename $jail_name_def $jail_name"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("Jail name changed successfully."); + else: + $input_errors[] = gtext("Failed to save jail name."); + endif; + endif; + endif; + + if (isset($_POST['ipv4']) && $_POST['ipv4']): + if($jail_ipv4_def !== $jail_ipv4): + $cmd = "/usr/bin/sed -i '' 's|.*ip4.addr.*=.*;| ip4.addr = $jail_ipv4;|' $jail_config"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("IPv4 changed successfully."); + else: + $input_errors[] = gtext("Failed to save IPv4."); + endif; + endif; + endif; + + if (isset($_POST['ipv6']) && $_POST['ipv6']): + if($jail_ipv6_def !== $jail_ipv6): + $cmd = "/usr/bin/sed -i '' 's|.*ip6.addr.*=.*;| ip6.addr = $jail_ipv6;|' $jail_config"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("IPv6 changed successfully."); + else: + $input_errors[] = gtext("Failed to save IPv6."); + endif; + endif; + endif; + + if (isset($_POST['interface']) && $_POST['interface']): + if($jail_interface_def !== $jail_interface): + if ($_POST['interface'] !== 'Config'): + $cmd = "/usr/bin/sed -i '' 's|.*interface.*=.*;| interface = $jail_interface;|' $jail_config"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("Interface changed successfully."); + else: + $input_errors[] = gtext("Failed to save interface."); + endif; + endif; + endif; + endif; + + if (isset($_POST['vnet_interface']) && $_POST['vnet_interface']): + if($jail_vnet_interface_def !== $jail_vnet_interface): + if ($_POST['vnet_interface'] !== 'Config'): + $cmd = "/usr/bin/sed -i '' 's|.*vnet.interface.*=.*;| vnet.interface = $jail_vnet_interface;|' $jail_config"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("VNET Interface changed successfully."); + else: + $input_errors[] = gtext("Failed to save VNET Interface."); + endif; + endif; + endif; + endif; + + if (isset($_POST['securelevel']) && $_POST['securelevel']): + if($jail_securelevel_def !== $jail_securelevel): + $cmd = "/usr/bin/sed -i '' 's/.*securelevel.*=.*;/ securelevel = $jail_securelevel;/' $jail_config"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("Securelevel changed successfully."); + else: + $input_errors[] = gtext("Failed to save securelevel."); + endif; + endif; + endif; + + if (isset($_POST['devfs_ruleset']) && $_POST['devfs_ruleset']): + if($jail_devfs_ruleset_def !== $jail_devfs_ruleset): + $cmd = "/usr/bin/sed -i '' 's/.*devfs_ruleset.*=.*;/ devfs_ruleset = $jail_devfs_ruleset;/' $jail_config"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("Devfs_ruleset changed successfully."); + else: + $input_errors[] = gtext("Failed to save devfs_ruleset."); + endif; + endif; + endif; + + if (isset($_POST['enforce_statfs']) && $_POST['enforce_statfs']): + if($jail_enforce_statfs_def !== $jail_enforce_statfs): + $cmd = "/usr/bin/sed -i '' 's/.*enforce_statfs.*=.*;/ enforce_statfs = $jail_enforce_statfs;/' $jail_config"; + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= gtext("Enforce_statfs changed successfully."); + else: + $input_errors[] = gtext("Failed to save enforce_statfs."); + endif; + endif; + endif; + //header("Location: bastille_manager_gui.php"); + //$savemsg .= gtext("successfully."); + endif; + endif; + endif; +endif; + +?> + + + + + + +
+
    +
  • +
  • +
+
+
+ + + + +
+
+ " /> + " /> + + + +
+
+ ' + . gtext('For additional information about the jail configuration file, check the FreeBSD documentation') + . '.'; + html_remark("note", gtext('Note'), $helpinghand); + ?> +
+ +
+
+ diff --git a/gui/bastille_manager_util.php b/gui/bastille_manager_util.php index b16cb62..c6bf7d9 100644 --- a/gui/bastille_manager_util.php +++ b/gui/bastille_manager_util.php @@ -64,9 +64,6 @@ if(isset($container) && !empty($container)): else: $pconfig['name'] = 'unknown'; endif; - $pconfig['newname'] = ''; - $pconfig['recursive'] = false; - $pconfig['action'] = 'activate'; else: // not supported $pconfig = []; diff --git a/version b/version index 2fec751..3c92cd0 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.0.45 +1.0.46