Add initial ZFS activation guided support

This commit is contained in:
Jose
2020-05-11 15:22:05 -04:00
parent 2493da2df2
commit 4cc63f2f08
7 changed files with 211 additions and 94 deletions
+39 -11
View File
@@ -2,7 +2,7 @@
/*
bastille_manager-lib.inc
Copyright (c) 2019 José Rivera (joserprg@gmail.com).
Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com).
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -43,22 +43,24 @@ require_once 'system.inc';
$application = "Bastille Manager";
$restore_name = "restore";
$confdir = "/var/etc/bastille_conf";
$cwdir = exec("/usr/bin/grep 'INSTALL_DIR=' {$confdir}/conf/bastille_config | /usr/bin/cut -d'\"' -f2");
$cwdir = exec("/usr/bin/grep 'INSTALL_DIR=' $confdir/conf/bastille_config | /usr/bin/cut -d'\"' -f2");
$rootfolder = $cwdir;
$configfile = "{$rootfolder}/conf/bastille_config";
$versionfile = "{$rootfolder}/version";
$configfile = "$rootfolder/conf/bastille_config";
$versionfile = "$rootfolder/version";
$date = strftime('%c');
$logfile = "{$rootfolder}/log/bastille_ext.log";
$logevent = "{$rootfolder}/log/bastille_last_event.log";
$backup_path = exec("/bin/cat {$configfile} | /usr/bin/grep 'BACKUP_DIR=' | /usr/bin/cut -d'\"' -f2");
$bastille_config = "{$rootfolder}/conf/bastille_config";
$config_path = exec("/bin/cat {$configfile} | /usr/bin/grep 'BASTILLE_CONFIG=' | /usr/bin/cut -d'\"' -f2");
$default_distfiles = exec("/bin/cat {$config_path} | /usr/bin/grep 'bastille_bootstrap_archives=' | /usr/bin/cut -d'\"' -f2");
$logfile = "$rootfolder/log/bastille_ext.log";
$logevent = "$rootfolder/log/bastille_last_event.log";
$backup_path = exec("/usr/bin/grep 'BACKUP_DIR=' $configfile | /usr/bin/cut -d'\"' -f2");
$bastille_config = "$rootfolder/conf/bastille_config";
$config_path = exec("/usr/bin/grep 'BASTILLE_CONFIG=' $configfile | /usr/bin/cut -d'\"' -f2");
$default_distfiles = exec("/usr/bin/grep 'bastille_bootstrap_archives=' $config_path | /usr/bin/cut -d'\"' -f2");
$jail_dir = "{$rootfolder}/jails";
$image_dir = "ext/bastille/images";
$options_support = exec("/usr/local/bin/bastille create | grep -wo '\[option\]'");
$reldir = "{$rootfolder}/releases";
$zfs_support = exec("/bin/cat {$configfile} | /usr/bin/grep 'ZFS_SUPPORT=' | /usr/bin/cut -d'\"' -f2");
//$zfs_already = exec("/sbin/zfs list | /usr/bin/grep -w $rootfolder/bastille");
$zfs_support = exec("/usr/bin/grep 'ZFS_SUPPORT=' $configfile | /usr/bin/cut -d'\"' -f2");
$zfs_activated = exec("/usr/bin/grep 'ZFS_ACTIVATED=' $configfile | /usr/bin/cut -d'\"' -f2");
// Ensure the root directory is configured.
if ($rootfolder == "")
@@ -78,6 +80,32 @@ function is_dir_empty($reldir) {
return (count(scandir($reldir)) == 2);
}
// Initial install banner
function initial_install_banner() {
// Never display this if bastille is already bootstraped/activated.
global $rootfolder;
global $zfs_activated;
$is_activated = "";
$is_bootstrapped = "";
// Check activation
if ($zfs_activated == "YES"):
return $is_activated = "YES";
elseif ($zfs_activated == "NO"):
return $is_activated = "NO";
else:
// Check for bootstrap directories.
exec("/bin/echo ' cache jails logs releases templates ' | /usr/bin/tr -s ' ' '\n'", $bastille_dirs);
array_shift($bastille_dirs);
foreach($bastille_dirs as $dir):
if(is_dir("$rootfolder/$dir")):
return $is_bootstrapped = "YES";
break;
endif;
endforeach;
endif;
}
// Check for sane ZFS settings.
function get_state_zfs() {
global $zfs_support;
+16 -1
View File
@@ -48,7 +48,21 @@ $pgtitle = array(gtext("Extensions"), gtext("Bastille"), gtext("Configuration"))
$wSpace = "  ";
$wSpaceEqual = "  =  ";
$paramNameSize = 30; //length of parameter name input field, default for parameter value input field is '80'
$paramNameSize = 30; //length of parameter name input field, default for parameter value input field is '80'
if(!initial_install_banner()):
$errormsg = gtext('Bastille Initial Configuration.')
. ' '
. '</br>'
. gtext('Please check and configure the following ZFS options: BASTILLE_ZFS_ENABLE and BASTILLE_ZFS_ZPOOL.')
.'</br>'
. gtext('Where BASTILLE_ZFS_ENABLE can be set to "YES", and BASTILLE_ZFS_ZPOOL can be set to "tank" or even "tank/dataset1/dataset2" accordingly.')
.'</br>'
. '<a href="' . 'bastille_manager_maintenance.php' . '">'
. gtext('After either configuring or skip this ZFS option, please visit this link to Enable/Disable ZFS Support on Bastille.')
. '</a>';
$prerequisites_ok = false;
endif;
function htmlInput($name, $title, $value="", $size=80) {
$result = "<input name='{$name}' size='{$size}' title='{$title}' placeholder='{$title}' value='{$value}' />";
@@ -145,6 +159,7 @@ bindtextdomain("xigmanas", $textdomain_bastille);
</td></tr>
<tr><td class="tabcont">
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<?php if(!empty($errormsg)): print_error_box($errormsg); endif; ?>
<?php // create table from configuration
echo "<tr><td colspan='2' style='padding-left:0px; padding-right:0px;'>";
if (!empty($input_errors)) print_input_errors($input_errors);
+10 -1
View File
@@ -2,7 +2,7 @@
/*
bastille_manager_gui.php
Copyright (c) 2019 José Rivera (joserprg@gmail.com).
Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com).
All rights reserved.
Portions of XigmaNAS® (https://www.xigmanas.com).
@@ -75,6 +75,15 @@ $img_path = [
$jls_list = get_jail_infos();
$sphere_array = $jls_list;
if(!initial_install_banner()):
$errormsg = gtext('Bastille Initial Configuration.')
. ' '
. '<a href="' . 'bastille_manager_config.php' . '">'
. gtext('Please check and configure ZFS support option first.')
. '</a>';
$prerequisites_ok = false;
endif;
if($_POST):
if(isset($_POST['apply']) && $_POST['apply']):
$ret = array('output' => [], 'retval' => 0);
+63 -16
View File
@@ -2,7 +2,7 @@
/*
bastille_manager_maintenance.php
Copyright (c) 2019 José Rivera (joserprg@gmail.com).
Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com).
All rights reserved.
Copyright (c) 2016 Andreas Schmidhuber
@@ -43,6 +43,17 @@ require_once("bastille_manager-lib.inc");
$pgtitle = array(gtext("Extensions"), "Bastille", "Maintenance");
if(!initial_install_banner()):
$errormsg = gtext('Bastille Initial Configuration.')
. ' '
. '<a href="' . 'bastille_manager_config.php' . '">'
. gtext('Please check and configure ZFS support option first.')
. '</a>'
. '</br>'
. gtext('Or click Activate to save current configuration regardless.');
$prerequisites_ok = false;
endif;
// For legacy product versions.
$return_val = mwexec("/bin/cat /etc/prd.version | cut -d'.' -f1 | /usr/bin/grep '10'", true);
if ($return_val == 0) {
@@ -61,6 +72,7 @@ $prdname = "bastille";
$tarballversion = "/usr/local/bin/bastille";
if ($_POST) {
global $zfs_activated;
if(isset($_POST['upgrade']) && $_POST['upgrade']):
$cmd = sprintf('%1$s/bastille-init -u > %2$s',$rootfolder,$logevent);
$return_val = 0;
@@ -147,6 +159,44 @@ if ($_POST) {
$input_errors[] = gtext("Failed to save extension settings.");
exec("echo '{$date}: {$application}: Failed to save extension settings' >> {$logfile}");
}
// ZFS activation support.
if ($_POST['zfs_activate']):
$zfs_status = get_state_zfs();
if($zfs_status == "Available but not enabled" || $zfs_status == "Enabled"):
if(!$zfs_activated):
$cmd = sprintf('/bin/echo Y | %1$s/bastille-init -Z > %2$s',$rootfolder,$logevent);
$return_val = 0;
$output = [];
exec($cmd,$output,$return_val);
if($return_val == 0):
ob_start();
include("{$logevent}");
$ausgabe = ob_get_contents();
ob_end_clean();
$savemsg .= str_replace("\n", "<br />", $ausgabe)."<br />";
exec("/usr/sbin/sysrc -f {$configfile} ZFS_ACTIVATED=\"YES\"");
else:
$input_errors[] = gtext('An error has occurred during ZFS activation process.');
$cmd = sprintf('echo %s: %s An error has occurred during ZFS activation process. >> %s',$date,$application,$logfile);
exec($cmd);
endif;
endif;
else:
$input_errors[] = gtext("Cannot activate ZFS with either invalid or disabled configurations.");
endif;
else:
$zfs_status = get_state_zfs();
if($zfs_status == "Invalid ZFS configuration"):
$input_errors[] = gtext("Cannot skip ZFS activation with an invalid configuration.");
elseif($zfs_status == "Enabled"):
exec("/usr/sbin/sysrc -f {$configfile} ZFS_ACTIVATED=\"YES\"");
elseif(!$zfs_activated):
exec("/usr/sbin/sysrc -f {$configfile} ZFS_ACTIVATED=\"NO\"");
$savemsg .= gtext("ZFS activation option has been skipped.");
endif;
endif;
# Run bastille-init to update config.
exec("bastille-init");
}
if (isset($_POST['restore']) && $_POST['restore']) {
@@ -231,20 +281,6 @@ $(document).ready(function(){
//-->
</script>
<form action="bastille_manager_maintenance.php" method="post" name="iform" id="iform" onsubmit="spinner()">
<?php
if(!empty($errormsg)):
print_error_box($errormsg);
endif;
if(!empty($savemsg)):
print_info_box($savemsg);
endif;
if(!empty($input_errors)):
print_input_errors($input_errors);
endif;
if(file_exists($d_sysrebootreqd_path)):
print_info_box(get_std_save_message(0));
endif;
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td class="tabnavtbl">
<ul id="tabnav">
@@ -261,6 +297,12 @@ $(document).ready(function(){
</td></tr>
<tr><td class="tabcont">
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<?php
if(!empty($errormsg)): print_error_box($errormsg); endif;
if(!empty($savemsg)): print_info_box($savemsg); endif;
if(!empty($input_errors)): print_input_errors($input_errors); endif;
if(file_exists($d_sysrebootreqd_path)): print_info_box(get_std_save_message(0)); endif;
?>
<?php html_titleline(gtext("Bastille"));?>
<?php html_text("installation_directory", gtext("Installation directory"), sprintf(gtext("The extension is installed in %s"), $rootfolder));?>
<tr>
@@ -275,6 +317,11 @@ $(document).ready(function(){
<td class="vncellt"><?=gtext("ZFS support");?></td>
<td class="vtable"><span name="getinfo_zfs" id="getinfo_zfs"><?=get_state_zfs()?></span></td>
</tr>
<?php
if(!initial_install_banner()):
html_checkbox2('zfs_activate',gtext('ZFS support activation'),'' ? true : false,gtext('Check this to activate ZFS support or leave unchecked to dismiss, this is a one time option and this row will disappear after clicking Save button.'),'',false);
endif;
?>
<?php html_filechooser("backup_path", gtext("Backup directory"), $backup_path, gtext("Directory to store containers backup archives, use as file chooser for restoring from file."), $backup_path, true, 60);?>
</table>
<div id="submit">
@@ -284,7 +331,7 @@ $(document).ready(function(){
</div>
<div id="remarks">
<?php html_remark("note", gtext("Info"), sprintf(gtext("For general information visit the following link(s):")));?>
<div id="enumeration"><ul><li><a href="http://bastillebsd.org/" target="_blank" > Bastille helps you quickly create and manage FreeBSD Jails.</a></li></ul></div>
<div id="enumeration"><ul><li><a href="http://bastillebsd.org/" target="_blank" ><?=gtext("Bastille helps you quickly create and manage FreeBSD Jails.")?></a></li></ul></div>
</div>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<?php html_separator();?>