🚧 added fetch, persist width

This commit is contained in:
rubn
2026-02-16 23:06:03 +01:00
parent 5ed42b2965
commit 9ebfeab85c
3 changed files with 94 additions and 16 deletions

View File

@@ -318,6 +318,10 @@ function get_jail_infos() {
$r['tags'] = '-';
}
// Get description
$r['description'] = exec("/usr/local/bin/bastille config {$item} get description");
if (!$r['description']) $r['description'] = "-";
// Set defaults for empty values
if (!$r['id']) $r['id'] = "-";
if (!$r['boot']) $r['boot'] = "-";

View File

@@ -60,6 +60,8 @@ if (isset($_GET['action']) && $_GET['action'] === 'refresh_table') {
ob_start();
// Fetch fresh data
// Note: We rely on the internal caching of get_jail_infos() (5 seconds)
// to avoid overloading the system with 'bastille list' commands if multiple requests occur.
$jls_list = [];
if (function_exists('get_jail_infos')) {
$jls_list = get_jail_infos();
@@ -383,9 +385,10 @@ include 'fbegin.inc';
filter: brightness(150%);
}
/* --- SIMPLE RESIZE STYLES --- */
/* --- ESTILOS DE RESIZE SIMPLE --- */
table.area_data_selection {
table-layout: fixed;
table-layout: fixed; /* Mantiene la cordura del navegador */
/*width: auto; IMPORTANTE: Auto para empezar */
border-collapse: collapse;
}
@@ -397,7 +400,7 @@ table.area_data_selection th {
text-overflow: ellipsis;
}
/* The visible handle */
/* El tirador visible */
.resizer {
position: absolute;
top: 0;
@@ -448,7 +451,7 @@ $(window).on("load", function() {
autoRefresh.interval = parseInt(savedInterval);
}
// --- REFRESH INIT ---
// Only start if the button is visible (enabled in settings)
// Solo iniciar si el botón está visible (habilitado en configuración)
if (localStorage.getItem('bastille_show_refresh_button') === 'true') {
$("#refresh-controls").show();
startAutoRefresh();
@@ -469,6 +472,7 @@ $(window).on("load", function() {
}
});
// --- INICIALIZAR EL RESIZE MANUAL ---
initSimpleResize();
});
@@ -510,16 +514,15 @@ function updateJailTable() {
autoRefresh.isUpdating = true;
$("#refresh-status").text('Updating...');
// Backup of checked checkboxes for persistence
// Backup de checkboxes marcados para persistencia
autoRefresh.selectedJails = [];
$("input[name='<?=$checkbox_member_name;?>[]']:checked").each(function() {
autoRefresh.selectedJails.push($(this).val());
});
$.ajax({
url: 'bastille_manager_gui.php?action=refresh_table',
dataType: 'json',
success: function(data) {
fetch('bastille_manager_gui.php?action=refresh_table')
.then(response => response.json())
.then(data => {
if (data.success) {
var tbody = $(".area_data_selection tbody");
tbody.empty();
@@ -538,6 +541,10 @@ function updateJailTable() {
// 2. Data Columns
row.append($('<td class="lcell">').text(jail.id || '-'));
row.append($('<td class="lcell">').text(jail.name || '-'));
// Description Column
// row.append($('<td class="lcell">').text(jail.description || '-'));
row.append($('<td class="lcell">').text(jail.boot || '-'));
row.append($('<td class="lcell">').text(jail.prio || '-'));
row.append($('<td class="lcell">').text(jail.state || '-'));
@@ -563,10 +570,18 @@ function updateJailTable() {
autoRefresh.lastUpdate = Date.now();
$("#refresh-status").text('Last update: just now');
controlactionbuttons(null, '<?=$checkbox_member_name;?>[]');
// Re-aplicar anchos de columna guardados después de actualizar la tabla
applySavedColumnWidths();
}
},
complete: function() { autoRefresh.isUpdating = false; }
});
})
.catch(error => {
console.error('Error fetching jail data:', error);
$("#refresh-status").text('Update failed');
})
.finally(() => {
autoRefresh.isUpdating = false;
});
}
function startAutoRefresh() {
@@ -579,18 +594,23 @@ function stopAutoRefresh() {
if (autoRefresh.timerId) clearInterval(autoRefresh.timerId);
}
// --- STABLE REDIMENSIONING FUNCTION (without %) ---
// --- FUNCIÓN DE REDIMENSIONADO ESTABLE (Sin %) ---
function initSimpleResize() {
var $table = $("table.area_data_selection");
var $cols = $table.find('colgroup col');
var $headers = $table.find('thead th');
// 1. Aplicar anchos guardados al inicio
applySavedColumnWidths();
// 2. AÑADIR TIRADORES
$headers.each(function(i) {
if (i >= $headers.length - 1) return; // Ignore the last column
if (i >= $headers.length - 1) return; // Ignorar la última columna
var $resizer = $('<div class="resizer"></div>');
$(this).append($resizer);
});
// 3. LÓGICA DE ARRASTRE
var isResizing = false;
var startX = 0;
var $currentCol = null;
@@ -600,7 +620,7 @@ function initSimpleResize() {
e.preventDefault(); e.stopPropagation();
stopAutoRefresh();
// Convert all columns to fixed pixels when starting to drag
// Convertir todas las columnas a píxeles fijos al iniciar el arrastre
$cols.each(function() {
var w = $(this).width();
$(this).css('width', w + 'px');
@@ -631,12 +651,46 @@ function initSimpleResize() {
isResizing = false;
$('.resizer').removeClass('resizing');
$(document).off('mousemove.rsz mouseup.rsz');
// Guardar anchos al terminar de redimensionar
saveColumnWidths();
setTimeout(function() {
startAutoRefresh();
// Solo reanudar si estaba habilitado
if (localStorage.getItem('bastille_show_refresh_button') === 'true') {
startAutoRefresh();
}
}, 500);
});
});
}
function saveColumnWidths() {
var widths = {};
var $cols = $("table.area_data_selection colgroup col");
$cols.each(function(index) {
// Guardamos el ancho en píxeles
widths[index] = $(this).css('width');
});
localStorage.setItem('bastille_col_widths', JSON.stringify(widths));
}
function applySavedColumnWidths() {
var saved = localStorage.getItem('bastille_col_widths');
if (saved) {
try {
var widths = JSON.parse(saved);
var $cols = $("table.area_data_selection colgroup col");
$cols.each(function(index) {
if (widths[index]) {
$(this).css('width', widths[index]);
}
});
} catch (e) {
console.error("Error parsing saved column widths", e);
}
}
}
//]]>
</script>
<?php
@@ -719,6 +773,7 @@ $document->render();
<th class="lhelc"><?=gtext('Select');?></th>
<th class="lhell"><?=gtext('JID');?></th>
<th class="lhell"><?=gtext('Name');?></th>
<!-- <th class="lhell"><?=gtext('Description');?></th> -->
<th class="lhell"><?=gtext('Boot');?></th>
<th class="lhell"><?=gtext('Prio');?></th>
<th class="lhell"><?=gtext('State');?></th>
@@ -756,6 +811,7 @@ $document->render();
</td>
<td class="lcell"><?=htmlspecialchars($sphere_record['id']);?>&nbsp;</td>
<td class="lcell"><?=htmlspecialchars($sphere_record['name']);?>&nbsp;</td>
<!-- <td class="lcell"><?=htmlspecialchars($sphere_record['description']);?>&nbsp;</td> -->
<td class="lcell"><?=htmlspecialchars($sphere_record['boot']);?>&nbsp;</td>
<td class="lcell"><?=htmlspecialchars($sphere_record['prio']);?>&nbsp;</td>
<td class="lcell"><?=htmlspecialchars($sphere_record['state']);?>&nbsp;</td>

View File

@@ -87,6 +87,7 @@ $pconfig['enforce_statfs'] = exec("/usr/bin/grep '.*enforce_statfs.*=' $jail_con
$pconfig['osrelease'] = exec("/usr/local/bin/bastille config {$item} get osrelease | cut -d '=' -f2 | tr -d ' ;'");
$pconfig['vnet_interface'] = exec("/usr/bin/grep '.*vnet.interface.*=' $jail_config | cut -d '=' -f2 | tr -d ' ;'");
$pconfig['boot_prio'] = exec("/usr/local/bin/bastille config {$item} get priority");
$pconfig['description'] = exec("/usr/local/bin/bastille config {$item} get description");
// Set the jail config default parameters.
$jail_name_def = $pconfig['jname'];
@@ -100,6 +101,7 @@ $jail_enforce_statfs_def = $pconfig['enforce_statfs'];
$jail_osrelease_def = $pconfig['osrelease'];
$jail_vnet_interface_def = $pconfig['vnet_interface'];
$jail_boot_prio_def = $pconfig['boot_prio'];
$jail_description_def = $pconfig['description'];
// Check if is a Linux jail.
$is_linux_jail = exec("/usr/bin/grep linsysfs {$jail_dir}/{$jail_name_def}/fstab");
@@ -233,6 +235,9 @@ if ($_POST):
if(isset($pconfig['boot_prio'])):
$jail_boot_prio = $pconfig['boot_prio'];
endif;
if(isset($pconfig['description'])):
$jail_description = $pconfig['description'];
endif;
// Check if the config has changed for each parameters.
// This jails wide changes requires the jail to be already stopped.
@@ -434,6 +439,18 @@ if ($_POST):
endif;
endif;
if (isset($_POST['description']) || $_POST['description']):
if($jail_description_def !== $jail_description):
$cmd = "/usr/local/bin/bastille config {$item} set description \"$jail_description\"";
unset($output,$retval);mwexec2($cmd,$output,$retval);
if($retval == 0):
//$savemsg .= gtext("Description changed successfully.");
else:
$input_errors[] = gtext("Failed to save description.");
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";
@@ -498,6 +515,7 @@ endif;
html_titleline2(gtext("Misc Configuration"));
html_checkbox2('autostart',gtext('Autoboot'),!empty($pconfig['autostart']) ? true : false,gtext('Autoboot this jail after system reboot.'),'',false);
html_inputbox("boot_prio", gtext("Priority"), $pconfig['boot_prio'], gtext("Set the priority value of the jail. Affects the boot order behaviour."), false, 20);
html_inputbox("description", gtext("Description"), $pconfig['description'], gtext("Set a description for the jail."), false, 40);
//html_checkbox2('force_edit',gtext('Force edit'),!empty($pconfig['force_edit']) ? true : false,gtext('Automatically stop and start this jail if is already running.'),'',false);
?>
</table>