. XigmaNAS® is a registered trademark of Michael Zoon (zoon01@xigmanas.com). 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_once 'auth.inc'; require_once 'guiconfig.inc'; require_once 'bastille_manager-lib.inc'; $img_path = [ 'add' => 'images/add.png', 'mod' => 'images/edit.png', 'del' => 'images/delete.png', 'loc' => 'images/locked.png', 'unl' => 'images/unlocked.png', 'mai' => 'images/maintain.png', 'inf' => 'images/info.png', 'ena' => 'images/status_enabled.png', 'dis' => 'images/status_disabled.png', 'mup' => 'images/up.png', 'mdn' => 'images/down.png' ]; // --- START AUTO-REFRESH LOGIC --- if (isset($_GET['action']) && $_GET['action'] === 'refresh_table') { error_reporting(0); ini_set('display_errors', 0); ob_start(); // Fetch fresh data $jls_list = []; if (function_exists('get_jail_infos')) { $jls_list = get_jail_infos(); } // Return JSON ob_clean(); header('Content-Type: application/json'); header('Cache-Control: no-cache'); echo json_encode(['success' => true, 'jails' => $jls_list ?: []]); exit; } // --- END AUTO-REFRESH LOGIC --- function mwexec_parallel($commands) { $processes = []; $results = []; foreach ($commands as $key => $command) { $descriptors = [ 0 => ['pipe', 'r'], // stdin 1 => ['pipe', 'w'], // stdout 2 => ['pipe', 'w'] // stderr ]; $process = proc_open($command, $descriptors, $pipes); if (is_resource($process)) { stream_set_blocking($pipes[1], false); stream_set_blocking($pipes[2], false); $processes[$key] = [ 'process' => $process, 'pipes' => $pipes, 'command' => $command ]; } } $timeout = 30; $start_time = time(); foreach ($processes as $key => $proc) { $elapsed = time() - $start_time; if ($elapsed < $timeout) { $stdout = stream_get_contents($proc['pipes'][1]); $stderr = stream_get_contents($proc['pipes'][2]); fclose($proc['pipes'][0]); fclose($proc['pipes'][1]); fclose($proc['pipes'][2]); $return_code = proc_close($proc['process']); $results[$key] = [ 'return_code' => $return_code, 'stdout' => $stdout, 'stderr' => $stderr ]; } else { proc_terminate($proc['process']); proc_close($proc['process']); $results[$key] = [ 'return_code' => -1, 'stdout' => '', 'stderr' => 'Command timeout' ]; } } return $results; } function mwexec_background($command) { $command = $command . ' > /dev/null 2>&1 &'; exec($command); } $sphere_scriptname = basename(__FILE__); $sphere_scriptname_child = 'bastille_manager_util.php'; $sphere_header = 'Location: '.$sphere_scriptname; $sphere_header_parent = $sphere_header; $sphere_array = []; $sphere_record = []; $checkbox_member_name = 'checkbox_member_array'; $checkbox_member_array = []; $checkbox_member_record = []; $gt_record_add = gtext('Create new jail'); $gt_record_mod = gtext('Utilities'); $gt_selection_start = gtext('Start Selected'); $gt_selection_stop = gtext('Stop Selected'); $gt_selection_restart = gtext('Restart Selected'); $gt_selection_autoboot = gtext('Auto-boot 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)?'); $gt_selection_restart_confirm = gtext('Do you want to restart the selected jail(s)?'); $gt_selection_autoboot_confirm = gtext('Do you want to set auto-boot on selected jail(s)?'); $jls_list = get_jail_infos(); $sphere_array = $jls_list; if(!initial_install_banner()): $errormsg = gtext('Bastille Initial Configuration:') . ' ' . '' . gtext('Please check and configure ZFS support option first.') . '' . '
' . gtext('Alternatively to skip this step:') . ' ' . '' . gtext('Please click here then push "Save" button.') . ''; $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; if($_POST): if(isset($_POST['apply']) && $_POST['apply']): $ret = array('output' => [], 'retval' => 0); if(!file_exists($d_sysrebootreqd_path)): // Process notifications endif; $savemsg = get_std_save_message($ret['retval']); if($ret['retval'] == 0): updatenotify_delete($sphere_notifier); header($sphere_header); exit; endif; updatenotify_delete($sphere_notifier); $errormsg = implode("\n", $ret['output']); endif; if(isset($_POST['start_selected_jail']) && $_POST['start_selected_jail']): $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; $commands = []; foreach($checkbox_member_array as $checkbox_member_record): if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): if(!isset($sphere_array[$index]['protected'])): $commands[] = "/usr/local/bin/bastille start {$checkbox_member_record}"; endif; endif; endforeach; if (!empty($commands)): $results = mwexec_parallel($commands); $success_count = 0; $fail_count = 0; foreach ($results as $result): if ($result['return_code'] == 0): $success_count++; else: $fail_count++; endif; endforeach; if (function_exists('invalidate_jail_cache')) { invalidate_jail_cache(); } if ($fail_count > 0): $errormsg = sprintf(gtext("Started %d jail(s), failed %d jail(s)."), $success_count, $fail_count); else: $savemsg = sprintf(gtext("%d jail(s) started successfully."), $success_count); endif; header($sphere_header); endif; endif; if(isset($_POST['stop_selected_jail']) && $_POST['stop_selected_jail']): $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; $commands = []; foreach($checkbox_member_array as $checkbox_member_record): if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): if(!isset($sphere_array[$index]['protected'])): $commands[] = "/usr/local/bin/bastille stop {$checkbox_member_record}"; endif; endif; endforeach; if (!empty($commands)): $results = mwexec_parallel($commands); $success_count = 0; $fail_count = 0; foreach ($results as $result): if ($result['return_code'] == 0): $success_count++; else: $fail_count++; endif; endforeach; if (function_exists('invalidate_jail_cache')) { invalidate_jail_cache(); } if ($fail_count > 0): $errormsg = sprintf(gtext("Stopped %d jail(s), failed %d jail(s)."), $success_count, $fail_count); else: $savemsg = sprintf(gtext("%d jail(s) stopped successfully."), $success_count); endif; header($sphere_header); endif; endif; if(isset($_POST['restart_selected_jail']) && $_POST['restart_selected_jail']): $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; $commands = []; foreach($checkbox_member_array as $checkbox_member_record): if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): if(!isset($sphere_array[$index]['protected'])): $commands[] = "/usr/local/bin/bastille restart {$checkbox_member_record}"; endif; endif; endforeach; if (!empty($commands)): $results = mwexec_parallel($commands); $success_count = 0; $fail_count = 0; foreach ($results as $result): if ($result['return_code'] == 0): $success_count++; else: $fail_count++; endif; endforeach; if (function_exists('invalidate_jail_cache')) { invalidate_jail_cache(); } if ($fail_count > 0): $errormsg = sprintf(gtext("Restarted %d jail(s), failed %d jail(s)."), $success_count, $fail_count); else: $savemsg = sprintf(gtext("%d jail(s) restarted successfully."), $success_count); endif; header($sphere_header); endif; endif; if(isset($_POST['autoboot_selected_jail']) && $_POST['autoboot_selected_jail']): $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; $commands = []; foreach($checkbox_member_array as $checkbox_member_record): if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): if(!isset($sphere_array[$index]['protected'])): $commands[] = "/usr/local/bin/bastille config {$checkbox_member_record} set boot on"; endif; endif; endforeach; if (!empty($commands)): $results = mwexec_parallel($commands); $success_count = 0; $fail_count = 0; foreach ($results as $result): if ($result['return_code'] == 0): $success_count++; else: $fail_count++; endif; endforeach; if (function_exists('invalidate_jail_cache')) { invalidate_jail_cache(); } if ($fail_count > 0): $errormsg = sprintf(gtext("Set autoboot on %d jail(s), failed %d jail(s)."), $success_count, $fail_count); else: $savemsg = sprintf(gtext("Autoboot set on %d jail(s) successfully."), $success_count); endif; header($sphere_header); endif; endif; endif; $pgtitle = [gtext("Extensions"), gtext('Bastille'), gtext('Manager')]; include 'fbegin.inc'; ?> add_area_tabnav()-> push()-> add_tabnav_upper()-> ins_tabnav_record('bastille_manager_gui.php',gettext('Containers'))-> ins_tabnav_record('bastille_manager_info.php',gettext('Information'))-> ins_tabnav_record('bastille_manager_maintenance.php',gettext('Maintenance')); $document->render(); ?>
                   
<?=$gt_record_mod;?> <?=$gt_record_del;?> <?=$gt_record_loc;?> <?=$gt_record_conf?> <?=$gt_record_inf?>
<?=$gt_record_add;?>