Update for recent bastille boot settings changes

This commit is contained in:
JRGTH
2025-09-04 23:51:29 -04:00
parent 74428e54e1
commit afa76f6a9c
7 changed files with 74 additions and 51 deletions
+5 -3
View File
@@ -67,6 +67,7 @@ $tarballversion = "/usr/local/bin/bastille";
$bastille_version_min = exec("grep 'BASTILLE_VERSION=' $tarballversion | cut -d '\"' -f2 | tr -d '.'");
$host_version = exec("/bin/cat /etc/prd.version | tr -d '.'");
$linux_compat_support = exec("/usr/bin/grep 'LINUX_COMPAT_SUPPORT=' $configfile | /usr/bin/cut -d'\"' -f2");
$jail_settings = "settings.conf";
// Ensure the root directory is configured.
if ($rootfolder == "")
@@ -253,10 +254,11 @@ function get_jail_infos() {
$r['path'] = "-";
endif;
// Display auto-start settings.
$jail_autostart = exec("/usr/bin/grep -w {$item}_AUTO_START $configfile | cut -d'=' -f2 | tr -d '\"'");
if ($jail_autostart == 'YES') {
//$jail_autostart = exec("/usr/bin/grep -w {$item}_AUTO_START $configfile | cut -d'=' -f2 | tr -d '\"'");
$jail_autostart = exec("/usr/bin/grep -w boot {$jail_dir}/{$item}/settings.conf | cut -d'=' -f2 | tr -d '\"'");
if ($jail_autostart == 'on') {
$r['boot'] = $img_path['ena'];
} elseif ($jail_autostart == 'NO') {
} elseif ($jail_autostart == 'off') {
$r['boot'] = $img_path['dis'];
} else {
$r['boot'] = $img_path['dis'];
+15 -16
View File
@@ -113,10 +113,10 @@ if($_POST):
// Just create an empty container with minimal jail.conf.
$cmd = ("/usr/local/bin/bastille create -E {$jname}");
else:
if (isset($_POST['nowstart'])):
$cmd = ("/usr/local/bin/bastille create {$options} {$jname} {$release} {$ipaddr} {$interface} && /usr/local/bin/bastille start {$jname}");
else:
if (isset($_POST['autostart'])):
$cmd = ("/usr/local/bin/bastille create {$options} {$jname} {$release} {$ipaddr} {$interface}");
else:
$cmd = ("/usr/local/bin/bastille create --no-boot {$options} {$jname} {$release} {$ipaddr} {$interface}");
endif;
endif;
@@ -124,16 +124,15 @@ if($_POST):
if(get_all_release_list()):
unset($output,$retval);mwexec2($cmd,$output,$retval);
if($retval == 0):
if (isset($_POST['autostart'])):
exec("/usr/sbin/sysrc -f {$configfile} {$jname}_AUTO_START=\"YES\"");
endif;
//if (isset($_POST['autostart'])):
// exec("/usr/sbin/sysrc -f {$configfile} {$jname}_AUTO_START=\"YES\"");
//endif;
if(is_link($resolv_conf)):
if(unlink($resolv_conf)):
//exec("/usr/local/bin/bastille cp $jname $resolv_host etc");
copy($resolv_host, $resolv_conf);
endif;
endif;
//$savemsg .= gtext("Boot Environment created and activated successfully.");
header('Location: bastille_manager_gui.php');
exit;
else:
@@ -163,7 +162,7 @@ function emptyjail_change() {
showElementById('thickjail_tr', 'show');
showElementById('vnetjail_tr', 'show');
showElementById('bridgejail_tr', 'show');
showElementById('nowstart_tr', 'show');
//showElementById('nowstart_tr', 'show');
showElementById('autostart_tr', 'show');
showElementById('linuxjail_tr', 'show');
break;
@@ -174,7 +173,7 @@ function emptyjail_change() {
showElementById('thickjail_tr', 'hide');
showElementById('vnetjail_tr', 'hide');
showElementById('bridgejail_tr', 'hide');
showElementById('nowstart_tr', 'hide');
//showElementById('nowstart_tr', 'hide');
showElementById('autostart_tr', 'hide');
showElementById('linuxjail_tr', 'hide');
break;
@@ -190,7 +189,7 @@ function linuxjail_change() {
showElementById('thickjail_tr', 'show');
showElementById('vnetjail_tr', 'show');
showElementById('bridgejail_tr', 'show');
showElementById('nowstart_tr', 'show');
//showElementById('nowstart_tr', 'show');
showElementById('autostart_tr', 'show');
showElementById('linuxjail_tr', 'show');
showElementById('emptyjail_tr', 'show');
@@ -202,7 +201,7 @@ function linuxjail_change() {
showElementById('thickjail_tr', 'hide');
showElementById('vnetjail_tr', 'hide');
showElementById('bridgejail_tr', 'hide');
showElementById('nowstart_tr', 'show');
//showElementById('nowstart_tr', 'show');
showElementById('autostart_tr', 'show');
showElementById('emptyjail_tr', 'hide');
break;
@@ -218,7 +217,7 @@ function vnetjail_change() {
showElementById('thickjail_tr', 'show');
showElementById('vnetjail_tr', 'show');
showElementById('bridgejail_tr', 'show');
showElementById('nowstart_tr', 'show');
//showElementById('nowstart_tr', 'show');
showElementById('autostart_tr', 'show');
showElementById('linuxjail_tr', 'show');
break;
@@ -229,7 +228,7 @@ function vnetjail_change() {
showElementById('thickjail_tr', 'show');
showElementById('vnetjail_tr', 'show');
showElementById('bridgejail_tr', 'hide');
showElementById('nowstart_tr', 'show');
//showElementById('nowstart_tr', 'show');
showElementById('autostart_tr', 'show');
showElementById('linuxjail_tr', 'show');
break;
@@ -245,7 +244,7 @@ function bridgejail_change() {
showElementById('thickjail_tr', 'show');
showElementById('vnetjail_tr', 'show');
showElementById('bridgejail_tr', 'show');
showElementById('nowstart_tr', 'show');
//showElementById('nowstart_tr', 'show');
showElementById('autostart_tr', 'show');
showElementById('linuxjail_tr', 'show');
break;
@@ -256,7 +255,7 @@ function bridgejail_change() {
showElementById('thickjail_tr', 'show');
showElementById('vnetjail_tr', 'hide');
showElementById('bridgejail_tr', 'show');
showElementById('nowstart_tr', 'show');
//showElementById('nowstart_tr', 'show');
showElementById('autostart_tr', 'show');
showElementById('linuxjail_tr', 'show');
break;
@@ -320,7 +319,7 @@ $document->render();
html_checkbox2('linuxjail',gettext('Create a Linux container'),!empty($pconfig['linuxjail']) ? true : false,gettext('This will create a Linux container, this is highly experimental and for testing purposes.'),'',false,false,'linuxjail_change()');
endif;
endif;
html_checkbox2('nowstart',gettext('Start after creation'),!empty($pconfig['nowstart']) ? true : false,gettext('Start the container after creation(May be overridden by later bastille releases).'),'',false);
//html_checkbox2('nowstart',gettext('Start after creation'),!empty($pconfig['nowstart']) ? true : false,gettext('Start the container after creation(May be overridden by later bastille releases).'),'',false);
html_checkbox2('autostart',gettext('Auto start on boot'),!empty($pconfig['autostart']) ? true : false,gettext('Automatically start the container at boot time.'),'',false);
?>
</tbody>
+30 -24
View File
@@ -62,10 +62,11 @@ endif;
$pgtitle = [gtext('Extensions'),gtext('Bastille'),gtext('Configuration'), $container];
$jail_config = "$jail_dir/$container/jail.conf";
$item = $pconfig['jailname'];
// Get some jail system settings.
$is_vnet = exec("/usr/bin/grep '.*vnet;' $jail_config");
$pconfig['autostart'] = exec("/usr/bin/grep -w '{$container}_AUTO_START=\"YES\"' $bastille_config");
$pconfig['autostart'] = exec("/usr/bin/grep -w 'boot=\"on\"' {$jail_dir}/{$item}/{$jail_settings}");
// Get some jail config parameters.
// This could be done with a nice php preg loop in the future.
@@ -124,17 +125,19 @@ if ($_POST):
$input_errors[] = gtext("A valid hostname must be specified, it can't be left blank.");
endif;
if(isset($_POST['ipv4'])):
if(!preg_match('/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$/', $pconfig['ipv4'])):
$input_errors[] = gtext("A valid IPv4 address must be specified.");
endif;
endif;
// Disable this IP validation check since bastille jail.conf syntax has changed recently.
//if(isset($_POST['ipv4'])):
// if(!preg_match('/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$/', $pconfig['ipv4'])):
// $input_errors[] = gtext("A valid IPv4 address must be specified.");
// endif;
//endif;
if(isset($_POST['ipv6'])):
if(!preg_match('/^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))/', $pconfig['ipv6'])):
$input_errors[] = gtext("A valid IPv6 address must be specified.");
endif;
endif;
// Disable this IP validation check since bastille jail.conf syntax has changed recently.
//if(isset($_POST['ipv6'])):
// if(!preg_match('/^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))/', $pconfig['ipv6'])):
// $input_errors[] = gtext("A valid IPv6 address must be specified.");
// endif;
//endif;
if(isset($_POST['securelevel'])):
if(!preg_match('/^[0-3]$/', $pconfig['securelevel'])):
@@ -249,7 +252,7 @@ if ($_POST):
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";
$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.");
@@ -261,7 +264,7 @@ if ($_POST):
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";
$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.");
@@ -336,11 +339,12 @@ if ($_POST):
endif;
if (isset($_POST['autostart']) && $_POST['autostart']):
if($jail_name_def !== $jail_name):
// Remove obsolete variable.
exec("/usr/sbin/sysrc -f $configfile -x {$jail_name_def}_AUTO_START");
endif;
$cmd = ("/usr/sbin/sysrc -f $configfile {$jail_name}_AUTO_START=\"YES\"");
//if($jail_name_def !== $jail_name):
// // Remove obsolete variable.
// exec("/usr/sbin/sysrc -f $configfile -x {$jail_name_def}_AUTO_START");
//endif;
//$cmd = ("/usr/sbin/sysrc -f $configfile {$jail_name}_AUTO_START=\"YES\"");
$cmd = ("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} boot=\"on\"");
unset($output,$retval);mwexec2($cmd,$output,$retval);
if($retval == 0):
//$savemsg .= gtext("Autostart changed successfully.");
@@ -348,12 +352,13 @@ if ($_POST):
$input_errors[] = gtext("Failed to enable autostart.");
endif;
else:
if($jail_name_def !== $jail_name):
// Remove obsolete variable.
exec("/usr/sbin/sysrc -f $configfile -x {$jail_name_def}_AUTO_START");
endif;
if(exec("/usr/sbin/sysrc -f $configfile -qn {$jail_name}_AUTO_START")):
$cmd = ("/usr/sbin/sysrc -f $configfile -x {$jail_name}_AUTO_START");
//if($jail_name_def !== $jail_name):
// // Remove obsolete variable.
// exec("/usr/sbin/sysrc -f $configfile -x {$jail_name_def}_AUTO_START");
//endif;
if(exec("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} -qn boot")):
//$cmd = ("/usr/sbin/sysrc -f $configfile -x {$jail_name}_AUTO_START");
$cmd = ("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} boot=\"off\"");
unset($output,$retval);mwexec2($cmd,$output,$retval);
if($retval == 0):
//$savemsg .= gtext("Autostart changed successfully.");
@@ -442,6 +447,7 @@ endif;
. gtext('For additional information about the jail configuration file, check the FreeBSD documentation')
. '</a>.';
html_remark("note", gtext('Note'), $helpinghand);
html_remark("note", gtext("Warning"), sprintf(gtext("Please be careful here as no input validation will be performed.")));
?>
</div>
<?php include 'formend.inc';?>
+5 -3
View File
@@ -284,7 +284,8 @@ if($_POST):
$container['jailname'] = $_POST['jailname'];
$confirm_name = $pconfig['confirmname'];
$item = $container['jailname'];
$cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"YES\"");
//$cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"YES\"");
$cmd = ("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} boot=\"on\"");
unset($output,$retval);mwexec2($cmd,$output,$retval);
if($retval == 0):
header('Location: bastille_manager_gui.php');
@@ -303,8 +304,9 @@ if($_POST):
$container['jailname'] = $_POST['jailname'];
$confirm_name = $pconfig['confirmname'];
$item = $container['jailname'];
if(exec("/usr/sbin/sysrc -f $configfile -qn {$item}_AUTO_START")):
$cmd = ("/usr/sbin/sysrc -f $configfile -x {$item}_AUTO_START");
if(exec("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} -qn boot")):
//$cmd = ("/usr/sbin/sysrc -f $configfile -x {$item}_AUTO_START");
$cmd = ("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} boot=\"off\"");
unset($output,$retval);mwexec2($cmd,$output,$retval);
if($retval == 0):
header('Location: bastille_manager_gui.php');