🚧 added fetch, persist width
This commit is contained in:
@@ -318,6 +318,10 @@ function get_jail_infos() {
|
|||||||
$r['tags'] = '-';
|
$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
|
// Set defaults for empty values
|
||||||
if (!$r['id']) $r['id'] = "-";
|
if (!$r['id']) $r['id'] = "-";
|
||||||
if (!$r['boot']) $r['boot'] = "-";
|
if (!$r['boot']) $r['boot'] = "-";
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ if (isset($_GET['action']) && $_GET['action'] === 'refresh_table') {
|
|||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
// Fetch fresh data
|
// 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 = [];
|
$jls_list = [];
|
||||||
if (function_exists('get_jail_infos')) {
|
if (function_exists('get_jail_infos')) {
|
||||||
$jls_list = get_jail_infos();
|
$jls_list = get_jail_infos();
|
||||||
@@ -383,9 +385,10 @@ include 'fbegin.inc';
|
|||||||
filter: brightness(150%);
|
filter: brightness(150%);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- SIMPLE RESIZE STYLES --- */
|
/* --- ESTILOS DE RESIZE SIMPLE --- */
|
||||||
table.area_data_selection {
|
table.area_data_selection {
|
||||||
table-layout: fixed;
|
table-layout: fixed; /* Mantiene la cordura del navegador */
|
||||||
|
/*width: auto; IMPORTANTE: Auto para empezar */
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,7 +400,7 @@ table.area_data_selection th {
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The visible handle */
|
/* El tirador visible */
|
||||||
.resizer {
|
.resizer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -448,7 +451,7 @@ $(window).on("load", function() {
|
|||||||
autoRefresh.interval = parseInt(savedInterval);
|
autoRefresh.interval = parseInt(savedInterval);
|
||||||
}
|
}
|
||||||
// --- REFRESH INIT ---
|
// --- 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') {
|
if (localStorage.getItem('bastille_show_refresh_button') === 'true') {
|
||||||
$("#refresh-controls").show();
|
$("#refresh-controls").show();
|
||||||
startAutoRefresh();
|
startAutoRefresh();
|
||||||
@@ -469,6 +472,7 @@ $(window).on("load", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --- INICIALIZAR EL RESIZE MANUAL ---
|
||||||
initSimpleResize();
|
initSimpleResize();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -510,16 +514,15 @@ function updateJailTable() {
|
|||||||
autoRefresh.isUpdating = true;
|
autoRefresh.isUpdating = true;
|
||||||
$("#refresh-status").text('Updating...');
|
$("#refresh-status").text('Updating...');
|
||||||
|
|
||||||
// Backup of checked checkboxes for persistence
|
// Backup de checkboxes marcados para persistencia
|
||||||
autoRefresh.selectedJails = [];
|
autoRefresh.selectedJails = [];
|
||||||
$("input[name='<?=$checkbox_member_name;?>[]']:checked").each(function() {
|
$("input[name='<?=$checkbox_member_name;?>[]']:checked").each(function() {
|
||||||
autoRefresh.selectedJails.push($(this).val());
|
autoRefresh.selectedJails.push($(this).val());
|
||||||
});
|
});
|
||||||
|
|
||||||
$.ajax({
|
fetch('bastille_manager_gui.php?action=refresh_table')
|
||||||
url: 'bastille_manager_gui.php?action=refresh_table',
|
.then(response => response.json())
|
||||||
dataType: 'json',
|
.then(data => {
|
||||||
success: function(data) {
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
var tbody = $(".area_data_selection tbody");
|
var tbody = $(".area_data_selection tbody");
|
||||||
tbody.empty();
|
tbody.empty();
|
||||||
@@ -538,6 +541,10 @@ function updateJailTable() {
|
|||||||
// 2. Data Columns
|
// 2. Data Columns
|
||||||
row.append($('<td class="lcell">').text(jail.id || '-'));
|
row.append($('<td class="lcell">').text(jail.id || '-'));
|
||||||
row.append($('<td class="lcell">').text(jail.name || '-'));
|
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.boot || '-'));
|
||||||
row.append($('<td class="lcell">').text(jail.prio || '-'));
|
row.append($('<td class="lcell">').text(jail.prio || '-'));
|
||||||
row.append($('<td class="lcell">').text(jail.state || '-'));
|
row.append($('<td class="lcell">').text(jail.state || '-'));
|
||||||
@@ -563,10 +570,18 @@ function updateJailTable() {
|
|||||||
autoRefresh.lastUpdate = Date.now();
|
autoRefresh.lastUpdate = Date.now();
|
||||||
$("#refresh-status").text('Last update: just now');
|
$("#refresh-status").text('Last update: just now');
|
||||||
controlactionbuttons(null, '<?=$checkbox_member_name;?>[]');
|
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() {
|
function startAutoRefresh() {
|
||||||
@@ -579,18 +594,23 @@ function stopAutoRefresh() {
|
|||||||
if (autoRefresh.timerId) clearInterval(autoRefresh.timerId);
|
if (autoRefresh.timerId) clearInterval(autoRefresh.timerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- STABLE REDIMENSIONING FUNCTION (without %) ---
|
// --- FUNCIÓN DE REDIMENSIONADO ESTABLE (Sin %) ---
|
||||||
function initSimpleResize() {
|
function initSimpleResize() {
|
||||||
var $table = $("table.area_data_selection");
|
var $table = $("table.area_data_selection");
|
||||||
var $cols = $table.find('colgroup col');
|
var $cols = $table.find('colgroup col');
|
||||||
var $headers = $table.find('thead th');
|
var $headers = $table.find('thead th');
|
||||||
|
|
||||||
|
// 1. Aplicar anchos guardados al inicio
|
||||||
|
applySavedColumnWidths();
|
||||||
|
|
||||||
|
// 2. AÑADIR TIRADORES
|
||||||
$headers.each(function(i) {
|
$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>');
|
var $resizer = $('<div class="resizer"></div>');
|
||||||
$(this).append($resizer);
|
$(this).append($resizer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 3. LÓGICA DE ARRASTRE
|
||||||
var isResizing = false;
|
var isResizing = false;
|
||||||
var startX = 0;
|
var startX = 0;
|
||||||
var $currentCol = null;
|
var $currentCol = null;
|
||||||
@@ -600,7 +620,7 @@ function initSimpleResize() {
|
|||||||
e.preventDefault(); e.stopPropagation();
|
e.preventDefault(); e.stopPropagation();
|
||||||
stopAutoRefresh();
|
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() {
|
$cols.each(function() {
|
||||||
var w = $(this).width();
|
var w = $(this).width();
|
||||||
$(this).css('width', w + 'px');
|
$(this).css('width', w + 'px');
|
||||||
@@ -631,12 +651,46 @@ function initSimpleResize() {
|
|||||||
isResizing = false;
|
isResizing = false;
|
||||||
$('.resizer').removeClass('resizing');
|
$('.resizer').removeClass('resizing');
|
||||||
$(document).off('mousemove.rsz mouseup.rsz');
|
$(document).off('mousemove.rsz mouseup.rsz');
|
||||||
|
|
||||||
|
// Guardar anchos al terminar de redimensionar
|
||||||
|
saveColumnWidths();
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
startAutoRefresh();
|
// Solo reanudar si estaba habilitado
|
||||||
|
if (localStorage.getItem('bastille_show_refresh_button') === 'true') {
|
||||||
|
startAutoRefresh();
|
||||||
|
}
|
||||||
}, 500);
|
}, 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>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
@@ -719,6 +773,7 @@ $document->render();
|
|||||||
<th class="lhelc"><?=gtext('Select');?></th>
|
<th class="lhelc"><?=gtext('Select');?></th>
|
||||||
<th class="lhell"><?=gtext('JID');?></th>
|
<th class="lhell"><?=gtext('JID');?></th>
|
||||||
<th class="lhell"><?=gtext('Name');?></th>
|
<th class="lhell"><?=gtext('Name');?></th>
|
||||||
|
<!-- <th class="lhell"><?=gtext('Description');?></th> -->
|
||||||
<th class="lhell"><?=gtext('Boot');?></th>
|
<th class="lhell"><?=gtext('Boot');?></th>
|
||||||
<th class="lhell"><?=gtext('Prio');?></th>
|
<th class="lhell"><?=gtext('Prio');?></th>
|
||||||
<th class="lhell"><?=gtext('State');?></th>
|
<th class="lhell"><?=gtext('State');?></th>
|
||||||
@@ -756,6 +811,7 @@ $document->render();
|
|||||||
</td>
|
</td>
|
||||||
<td class="lcell"><?=htmlspecialchars($sphere_record['id']);?> </td>
|
<td class="lcell"><?=htmlspecialchars($sphere_record['id']);?> </td>
|
||||||
<td class="lcell"><?=htmlspecialchars($sphere_record['name']);?> </td>
|
<td class="lcell"><?=htmlspecialchars($sphere_record['name']);?> </td>
|
||||||
|
<!-- <td class="lcell"><?=htmlspecialchars($sphere_record['description']);?> </td> -->
|
||||||
<td class="lcell"><?=htmlspecialchars($sphere_record['boot']);?> </td>
|
<td class="lcell"><?=htmlspecialchars($sphere_record['boot']);?> </td>
|
||||||
<td class="lcell"><?=htmlspecialchars($sphere_record['prio']);?> </td>
|
<td class="lcell"><?=htmlspecialchars($sphere_record['prio']);?> </td>
|
||||||
<td class="lcell"><?=htmlspecialchars($sphere_record['state']);?> </td>
|
<td class="lcell"><?=htmlspecialchars($sphere_record['state']);?> </td>
|
||||||
|
|||||||
@@ -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['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['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['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.
|
// Set the jail config default parameters.
|
||||||
$jail_name_def = $pconfig['jname'];
|
$jail_name_def = $pconfig['jname'];
|
||||||
@@ -100,6 +101,7 @@ $jail_enforce_statfs_def = $pconfig['enforce_statfs'];
|
|||||||
$jail_osrelease_def = $pconfig['osrelease'];
|
$jail_osrelease_def = $pconfig['osrelease'];
|
||||||
$jail_vnet_interface_def = $pconfig['vnet_interface'];
|
$jail_vnet_interface_def = $pconfig['vnet_interface'];
|
||||||
$jail_boot_prio_def = $pconfig['boot_prio'];
|
$jail_boot_prio_def = $pconfig['boot_prio'];
|
||||||
|
$jail_description_def = $pconfig['description'];
|
||||||
|
|
||||||
// Check if is a Linux jail.
|
// Check if is a Linux jail.
|
||||||
$is_linux_jail = exec("/usr/bin/grep linsysfs {$jail_dir}/{$jail_name_def}/fstab");
|
$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'])):
|
if(isset($pconfig['boot_prio'])):
|
||||||
$jail_boot_prio = $pconfig['boot_prio'];
|
$jail_boot_prio = $pconfig['boot_prio'];
|
||||||
endif;
|
endif;
|
||||||
|
if(isset($pconfig['description'])):
|
||||||
|
$jail_description = $pconfig['description'];
|
||||||
|
endif;
|
||||||
|
|
||||||
// Check if the config has changed for each parameters.
|
// Check if the config has changed for each parameters.
|
||||||
// This jails wide changes requires the jail to be already stopped.
|
// This jails wide changes requires the jail to be already stopped.
|
||||||
@@ -434,6 +439,18 @@ if ($_POST):
|
|||||||
endif;
|
endif;
|
||||||
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 (isset($_POST['jname']) && $_POST['jname']):
|
||||||
if($jail_name_def !== $jail_name):
|
if($jail_name_def !== $jail_name):
|
||||||
$cmd = "/usr/local/bin/bastille rename $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_titleline2(gtext("Misc Configuration"));
|
||||||
html_checkbox2('autostart',gtext('Autoboot'),!empty($pconfig['autostart']) ? true : false,gtext('Autoboot this jail after system reboot.'),'',false);
|
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("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);
|
//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>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user