. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the developer nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require("auth.inc"); require("guiconfig.inc"); require_once("bastille_manager-lib.inc"); $pgtitle = array(gtext("Extensions"), "Bastille", "Maintenance"); if(!initial_install_banner()): $errormsg = gtext('Bastille Initial Configuration.') . ' ' . '' . gtext('Please check and configure ZFS support option first.') . '' . '
' . gtext('Or click the "Save" button to store the default configuration.'); $prerequisites_ok = false; endif; $zfs_status = get_state_zfs(); if($zfs_status == "Invalid ZFS configuration"): // Warning if invalid ZFS configuration. $input_errors[] = gtext("WARNING: Invalid ZFS configuration detected."); endif; // For legacy product versions. $legacy_check = mwexec("/bin/cat /etc/prd.version | cut -d'.' -f1 | /usr/bin/grep '10'", true); if ($legacy_check == 0) { if (is_array($config['rc']['postinit'] ) && is_array( $config['rc']['postinit']['cmd'] ) ) { for ($i = 0; $i < count($config['rc']['postinit']['cmd']);) { if (preg_match('/bastille-init/', $config['rc']['postinit']['cmd'][$i])) break; ++$i; } } } // Set default backup directory. if (1 == mwexec("/bin/cat {$configfile} | /usr/bin/grep 'BACKUP_DIR='")) { if (is_file("{$configfile}")) exec("/usr/sbin/sysrc -f {$configfile} BACKUP_DIR={$rootfolder}/backups"); } $backup_path = exec("/bin/cat {$configfile} | /usr/bin/grep 'BACKUP_DIR=' | cut -d'\"' -f2"); if ($_POST) { global $retval; global $zfs_activated; global $backup_path_bastille; global $configfile_bastille; if(isset($_POST['upgrade']) && $_POST['upgrade']): $cmd = sprintf('%1$s/bastille-init -u > %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", "
", $ausgabe)."
"; else: $input_errors[] = gtext('An error has occurred during upgrade process.'); $cmd = sprintf('echo %s: %s An error has occurred during upgrade process. >> %s',$date,$application,$logfile); exec($cmd); endif; endif; if(isset($_POST['update']) && $_POST['update']): $cmd = sprintf('%1$s/bastille-init bastillebsd_update > %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", "
", $ausgabe)."
"; else: $input_errors[] = gtext('An error has occurred during core update process.'); $cmd = sprintf('echo %s: %s An error has occurred during core update process. >> %s',$date,$application,$logfile); exec($cmd); endif; endif; // Remove only extension related files during cleanup. if (isset($_POST['uninstall']) && $_POST['uninstall']) { if(isset($_POST['delete_confirm']) && $_POST['delete_confirm']): bindtextdomain("xigmanas", $textdomain); if (is_link($textdomain_bastille)) mwexec("rm -f {$textdomain_bastille}", true); if (is_dir($confdir)) mwexec("rm -Rf {$confdir}", true); mwexec("rm /usr/local/www/bastille_manager_gui.php && rm -R /usr/local/www/ext/bastille", true); mwexec("{$rootfolder}/usr/local/sbin/bastille-init -t", true); $uninstall_cmd = "echo 'y' | /usr/local/sbin/bastille-init -U"; mwexec($uninstall_cmd, true); if (is_link("/usr/local/share/{$prdname}")) mwexec("rm /usr/local/share/{$prdname}", true); //if (is_link("/var/cache/pkg")) mwexec("rm /var/cache/pkg", true); //if (is_link("/var/db/pkg")) mwexec("rm /var/db/pkg && mkdir /var/db/pkg", true); // Remove start postinit cmd in later product versions. if (is_array($config['rc']) && is_array($config['rc']['param'])) { $postinit_cmd = "{$rootfolder}/bastille-init"; $value = $postinit_cmd; $sphere_array = &$config['rc']['param']; $updateconfigfile = false; if (false !== ($index = array_search_ex($value, $sphere_array, 'value'))) { unset($sphere_array[$index]); $updateconfigfile = true; } if ($updateconfigfile) { write_config(); $updateconfigfile = false; } } // Remove stop postinit cmd in later product versions. if (is_array($config['rc']) && is_array($config['rc']['param'])) { $shutdown_cmd = "{$rootfolder}/bastille-init -p"; $value = $shutdown_cmd; $sphere_array = &$config['rc']['param']; $updateconfigfile = false; if (false !== ($index = array_search_ex($value, $sphere_array, 'value'))) { unset($sphere_array[$index]); $updateconfigfile = true; } if ($updateconfigfile) { write_config(); $updateconfigfile = false; } } header("Location:index.php"); else: $input_errors[] = gtext('Confirmation is required for extension removal.'); endif; } if (isset($_POST['save']) && $_POST['save']) { // Ensure to have NO whitespace & trailing slash. $backup_path = rtrim(trim($_POST['backup_path']),'/'); if ("{$backup_path}" == "") { $backup_path = "{$rootfolder}/backups"; } if (!is_file($backup_path)) { if($backup_path_bastille !== $backup_path): // Update bastille config if required. $cmd = "/usr/sbin/sysrc -f {$configfile_bastille} bastille_backupsdir={$backup_path}"; //unset($retval); mwexec($cmd,$retval); if ($retval == 0) { $savemsg .= gtext("Bastille config updated successfully."); exec("echo '{$date}: {$application}: Bastille config updated successfully' >> {$logfile}"); } else { $input_errors[] = gtext("Failed to update Bastille config."); exec("echo '{$date}: {$application}: Failed to update Bastille config' >> {$logfile}"); } endif; // Update extension config. $cmd = "/usr/sbin/sysrc -f {$configfile} BACKUP_DIR={$backup_path}"; //unset($retval); mwexec($cmd,$retval); if ($retval == 0) { $savemsg .= gtext("Extension settings saved successfully."); exec("echo '{$date}: {$application}: Extension settings saved successfully' >> {$logfile}"); } else { $input_errors[] = gtext("Failed to save extension settings."); exec("echo '{$date}: {$application}: Failed to save extension settings' >> {$logfile}"); } } else { $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): unset ($errormsg); ob_start(); include("{$logevent}"); $ausgabe = ob_get_contents(); ob_end_clean(); $savemsg .= str_replace("\n", "
", $ausgabe)."
"; 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 == "Available but not enabled"): $input_errors[] = gtext("Cannot skip ZFS activation with current config, either disable ZFS option in the config or just Activate ZFS support."); elseif($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): unset ($errormsg); 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']) { // Ensure to have NO whitespace & trailing slash. $backup_file = rtrim(trim($_POST['backup_path']),'/'); $filename_trim = exec("echo {$backup_file} | awk '{print $1}' | grep -o '[^/]*$'"); $jailname_trim = exec("echo {$backup_file} | awk '{print $1}' | grep -o '[^/]*$' | cut -d '_' -f1"); if ("{$backup_file}" == "") { $input_errors[] = gtext("Error: backup file undefined."); } if (is_dir("{$jail_dir}/{$jailname_trim}")): $input_errors[] = gtext("Container directory/dataset already exist."); else: if (is_file($backup_file)) { $cmd = ("/usr/local/bin/bastille import '{$filename_trim}'"); //unset($output,$retval); mwexec2($cmd,$output,$retval); if ($retval == 0) { $savemsg .= gtext("Container restored successfully."); exec("echo '{$date}: {$application}: Container restored successfully from {$filename_trim}' >> {$logfile}"); } else { $input_errors[] = gtext("Failed to restore container."); exec("echo '{$date}: {$application}: Failed to restore container from {$filename_trim}' >> {$logfile}"); } } else { $input_errors[] = gtext("Failed to restore container, file not found."); exec("echo '{$date}: {$application}: Failed to restore container, file {$filename_trim} not found' >> {$logfile}"); } endif; } } function get_version_ext() { global $versionfile; exec("/bin/cat {$versionfile}", $result); return ($result[0] ?? ''); } if (is_ajax()) { $getinfo['bastille'] = get_version_bastille(); $getinfo['ext'] = get_version_ext(); render_ajax($getinfo); } bindtextdomain("xigmanas", $textdomain); include("fbegin.inc"); bindtextdomain("xigmanas", $textdomain_bastille); ?>
" value=""/> " value="" /> " value="" /> " value="" />
" value="" onclick="return confirm('')" />