Skip to content

Commit

Permalink
Extending Maintenance w/ app.conf (im/ex)port
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Jan 11, 2025
1 parent 711e001 commit b4e7415
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 42 deletions.
90 changes: 70 additions & 20 deletions front/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,38 @@
</div>
</div>
<div class="tab-pane" id="tab_BackupRestore">
<div class="db_info_table">
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="btnExportCSV" onclick="ExportCSV()"><?= lang('Maintenance_Tool_ExportCSV');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ExportCSV_text');?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnImportCSV" onclick="askImportCSV()"><?= lang('Maintenance_Tool_ImportCSV');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ImportCSV_text');?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnImportPastedCSV" onclick="askImportPastedCSV()"><?= lang('Maintenance_Tool_ImportPastedCSV');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ImportPastedCSV_text');?></div>
</div>
</div>
<div class="db_info_table">
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="btnExportCSV" onclick="ExportCSV()"><?= lang('Maintenance_Tool_ExportCSV');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ExportCSV_text');?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnImportCSV" onclick="askImportCSV()"><?= lang('Maintenance_Tool_ImportCSV');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ImportCSV_text');?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnImportPastedCSV" onclick="askImportPastedCSV()"><?= lang('Maintenance_Tool_ImportPastedCSV');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ImportPastedCSV_text');?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="btnDownloadConfig" onclick="DownloadConfig()"><?= lang('Maintenance_Tool_DownloadConfig');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_DownloadConfig_text');?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" >
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnImportPastedConfig" onclick="askImportPastedConfig()"><?= lang('Maintenance_Tool_ImportPastedConfig');?></button>
</div>
<div class="db_tools_table_cell_b"><?= lang('Maintenance_Tool_ImportPastedConfig_text');?></div>
</div>
</div>
</div>
<!-- ---------------------------Logging-------------------------------------------- -->
<div class="tab-pane" id="tab_Logging">
Expand Down Expand Up @@ -445,6 +457,44 @@ function restartBackend() {
})
}

// -----------------------------------------------------------
// Import pasted Config ASK
function askImportPastedConfig() {

// Add new icon as base64 string
showModalInput ('<i class="fa fa-square-plus pointer"></i> <?= lang('Maintenance_Tool_ImportConfig_noti');?>', '<?= lang('Maintenance_Tool_ImportPastedConfig_noti_text');?>',
'<?= lang('Gen_Cancel');?>', '<?= lang('Gen_Okay');?>', 'UploadConfig');
}

// -----------------------------------------------------------
// Upload Settings Config
function UploadConfig()
{
// alert("aaa")

appConf = $('#modal-input-textarea').val()
// encode for import
appConfBase64 = btoa(appConf)

// import
$.post('php/server/query_replace_config.php', { config: appConfBase64 }, function(msg) {
console.log(msg);
// showMessage(msg);
write_notification(`[Maintenance] Settings imported from backup: ${msg}`, 'interrupt');
});

}

// -----------------------------------------------------------
// Download Settings Config
function DownloadConfig()
{
// Execute
openInNewTab("php/server/query_config.php?file=app.conf&download=true")
}



// -----------------------------------------------------------
// Export CSV
function ExportCSV()
Expand Down
23 changes: 19 additions & 4 deletions front/php/server/query_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
//------------------------------------------------------------------------------
// Handle incoming requests
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// Get query string parameter ?file=settings_table.json
// Get query string parameters ?file=settings_table.json&download=true
$file = isset($_GET['file']) ? $_GET['file'] : null;
$download = isset($_GET['download']) ? $_GET['download'] === 'true' : false;

// Check if file parameter is provided
if ($file) {
Expand All @@ -21,9 +22,23 @@

// Check if the file exists
if (file_exists($filePath)) {
// Send the response back to the client
header('Content-Type: text/plain');
echo file_get_contents($filePath);
// Handle download behavior
if ($download) {
// Force file download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
exit;
} else {
// Display file content
header('Content-Type: text/plain');
echo file_get_contents($filePath);
}
} else {
// File not found response
http_response_code(404);
Expand Down
6 changes: 6 additions & 0 deletions front/php/templates/language/ar_ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@
"Maintenance_Running_Version": "",
"Maintenance_Status": "",
"Maintenance_Title": "",
"Maintenance_Tool_DownloadConfig": "",
"Maintenance_Tool_DownloadConfig_text": "",
"Maintenance_Tool_ExportCSV": "",
"Maintenance_Tool_ExportCSV_noti": "",
"Maintenance_Tool_ExportCSV_noti_text": "",
Expand All @@ -406,9 +408,13 @@
"Maintenance_Tool_ImportCSV_noti": "",
"Maintenance_Tool_ImportCSV_noti_text": "",
"Maintenance_Tool_ImportCSV_text": "",
"Maintenance_Tool_ImportConfig_noti": "",
"Maintenance_Tool_ImportPastedCSV": "",
"Maintenance_Tool_ImportPastedCSV_noti_text": "",
"Maintenance_Tool_ImportPastedCSV_text": "",
"Maintenance_Tool_ImportPastedConfig": "",
"Maintenance_Tool_ImportPastedConfig_noti_text": "",
"Maintenance_Tool_ImportPastedConfig_text": "",
"Maintenance_Tool_arpscansw": "",
"Maintenance_Tool_arpscansw_noti": "",
"Maintenance_Tool_arpscansw_noti_text": "",
Expand Down
8 changes: 7 additions & 1 deletion front/php/templates/language/ca_ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@
"Maintenance_Running_Version": "Versió instal·lada",
"Maintenance_Status": "Estat",
"Maintenance_Title": "Eines de manteniment",
"Maintenance_Tool_DownloadConfig": "",
"Maintenance_Tool_DownloadConfig_text": "",
"Maintenance_Tool_ExportCSV": "CSV Exportació",
"Maintenance_Tool_ExportCSV_noti": "CSV Exportació",
"Maintenance_Tool_ExportCSV_noti_text": "Estàs segur que vols generar un fitxer CSV?",
Expand All @@ -406,9 +408,13 @@
"Maintenance_Tool_ImportCSV_noti": "CSV Importació",
"Maintenance_Tool_ImportCSV_noti_text": "Estàs segur que vols importar el fitxer CSV? Això <b> sobreescriurà</b> completament els dispositius de la seva base de dades.",
"Maintenance_Tool_ImportCSV_text": "Abans d'utilitzar aquesta funció, fes una còpia de seguretat, si us plau. Importa un CSV (comma separated value) el fitxer que conté la llista dels dispositius que inclouen les relacions de Xarxa entre Nodes i dispositius connectats. Per fer-ho col·loca el CSV el fitxer anomenat <b>devices.csv</b> a la vostra <b>/config</b> carpeta.",
"Maintenance_Tool_ImportConfig_noti": "",
"Maintenance_Tool_ImportPastedCSV": "Importació CSV (Paste)",
"Maintenance_Tool_ImportPastedCSV_noti_text": "Estàs segur que vols importar el CSV copiat? Això <b> sobreescriurà</b> completament els dispositius de la base de dades.",
"Maintenance_Tool_ImportPastedCSV_text": "Abans d'utilitzar aquesta funció, feu una còpia de seguretat. Importar un fitxer CSV (comma separated value) que contingui la llista de dispositius, incloent les relacions de xarxa entre els nodes i els dispositius connectats.",
"Maintenance_Tool_ImportPastedConfig": "",
"Maintenance_Tool_ImportPastedConfig_noti_text": "",
"Maintenance_Tool_ImportPastedConfig_text": "",
"Maintenance_Tool_arpscansw": "Conmuta arp-Scan (on/off)",
"Maintenance_Tool_arpscansw_noti": "Conmuta arp-Scan on or off",
"Maintenance_Tool_arpscansw_noti_text": "Quan l'escàner ha estat canviat a off es queda off fins que és activat de bell nou.",
Expand Down Expand Up @@ -744,4 +750,4 @@
"settings_update_item_warning": "Actualitza el valor sota. Sigues curós de seguir el format anterior. <b>No hi ha validació.</b>",
"test_event_icon": "fa-vial-circle-check",
"test_event_tooltip": "Deseu els canvis primer abans de comprovar la configuració."
}
}
6 changes: 6 additions & 0 deletions front/php/templates/language/cs_cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@
"Maintenance_Running_Version": "",
"Maintenance_Status": "",
"Maintenance_Title": "",
"Maintenance_Tool_DownloadConfig": "",
"Maintenance_Tool_DownloadConfig_text": "",
"Maintenance_Tool_ExportCSV": "",
"Maintenance_Tool_ExportCSV_noti": "",
"Maintenance_Tool_ExportCSV_noti_text": "",
Expand All @@ -406,9 +408,13 @@
"Maintenance_Tool_ImportCSV_noti": "",
"Maintenance_Tool_ImportCSV_noti_text": "",
"Maintenance_Tool_ImportCSV_text": "",
"Maintenance_Tool_ImportConfig_noti": "",
"Maintenance_Tool_ImportPastedCSV": "",
"Maintenance_Tool_ImportPastedCSV_noti_text": "",
"Maintenance_Tool_ImportPastedCSV_text": "",
"Maintenance_Tool_ImportPastedConfig": "",
"Maintenance_Tool_ImportPastedConfig_noti_text": "",
"Maintenance_Tool_ImportPastedConfig_text": "",
"Maintenance_Tool_arpscansw": "",
"Maintenance_Tool_arpscansw_noti": "",
"Maintenance_Tool_arpscansw_noti_text": "",
Expand Down
8 changes: 7 additions & 1 deletion front/php/templates/language/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@
"Maintenance_Running_Version": "Installierte Version",
"Maintenance_Status": "Status",
"Maintenance_Title": "Wartungswerkzeuge",
"Maintenance_Tool_DownloadConfig": "",
"Maintenance_Tool_DownloadConfig_text": "",
"Maintenance_Tool_ExportCSV": "CSV Export",
"Maintenance_Tool_ExportCSV_noti": "CSV Export",
"Maintenance_Tool_ExportCSV_noti_text": "Sind Sie sich sicher, dass Sie die CSV-Datei erstellen wollen?",
Expand All @@ -432,9 +434,13 @@
"Maintenance_Tool_ImportCSV_noti": "CSV Import",
"Maintenance_Tool_ImportCSV_noti_text": "Sind Sie sich sicher, dass Sie die CSV-Datei importieren wollen? Dies wird <b>alle Geräte in der Datenbank überschreiben</b>.",
"Maintenance_Tool_ImportCSV_text": "Machen Sie ein Backup, bevor Sie diese Funk­tion nutzen. Importiere eine CSV-Datei (comma separated values) mit einer Liste aller Geräte und deren Beziehungen zwischen Netzwerkknoten und verbundenen Geräten. Um dies zu tun platziere die <b>devices.csv</b> benannte CSV-Datei in deinen <b>/config</b> Ordner.",
"Maintenance_Tool_ImportConfig_noti": "",
"Maintenance_Tool_ImportPastedCSV": "CSV-Import (Einfügen)",
"Maintenance_Tool_ImportPastedCSV_noti_text": "",
"Maintenance_Tool_ImportPastedCSV_text": "",
"Maintenance_Tool_ImportPastedConfig": "",
"Maintenance_Tool_ImportPastedConfig_noti_text": "",
"Maintenance_Tool_ImportPastedConfig_text": "",
"Maintenance_Tool_arpscansw": "ARP-Scan umschalten (ein/aus)",
"Maintenance_Tool_arpscansw_noti": "ARP-Scan ein- oder ausschalten",
"Maintenance_Tool_arpscansw_noti_text": "Wenn der Scan aus ist, bleibt er so lange aus bis er wieder aktiviert wird.",
Expand Down Expand Up @@ -825,4 +831,4 @@
"settings_update_item_warning": "",
"test_event_icon": "",
"test_event_tooltip": "Speichere die Änderungen, bevor Sie die Einstellungen testen."
}
}
20 changes: 13 additions & 7 deletions front/php/templates/language/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,23 @@
"Maintenance_Running_Version": "Installed version",
"Maintenance_Status": "Status",
"Maintenance_Title": "Maintenance tools",
"Maintenance_Tool_ExportCSV": "CSV Export",
"Maintenance_Tool_ExportCSV_noti": "CSV Export",
"Maintenance_Tool_DownloadConfig": "Settings Export",
"Maintenance_Tool_DownloadConfig_text": "Download a full backup of your Settings configuration stored in the <code>app.conf</code> file.",
"Maintenance_Tool_ExportCSV": "Devices Export (csv)",
"Maintenance_Tool_ExportCSV_noti": "Devices Export (csv)",
"Maintenance_Tool_ExportCSV_noti_text": "Are you sure you want to generate a CSV file?",
"Maintenance_Tool_ExportCSV_text": "Generate a CSV (comma separated value) file containing the list of Devices including the Network relationships between Network Nodes and connected devices. You can also trigger this by accessing this URL <code>your NetAlertX url/php/server/devices.php?action=ExportCSV</code> or by enabling the <a href=\"settings.php#CSVBCKP_header\">CSV Backup</a> plugin.",
"Maintenance_Tool_ImportCSV": "CSV Import",
"Maintenance_Tool_ImportCSV_noti": "CSV Import",
"Maintenance_Tool_ExportCSV_text": "Generate a CSV (comma separated value) file containing the list of Devices including the Network relationships between Network Nodes and connected devices. You can also trigger this by accessing this URL <code>your_NetAlertX_url/php/server/devices.php?action=ExportCSV</code> or by enabling the <a href=\"settings.php#CSVBCKP_header\">CSV Backup</a> plugin.",
"Maintenance_Tool_ImportCSV": "Devices Import (csv)",
"Maintenance_Tool_ImportCSV_noti": "Devices Import (csv)",
"Maintenance_Tool_ImportCSV_noti_text": "Are you sure you want to import the CSV file? This will completely <b>overwrite</b> the devices in your database.",
"Maintenance_Tool_ImportCSV_text": "Before using this function, please make a backup. Import a CSV (comma separated value) file containing the list of Devices including the Network relationships between Network Nodes and connected devices. To do that place the CSV file named <b>devices.csv</b> into your <b>/config</b> folder.",
"Maintenance_Tool_ImportPastedCSV": "CSV Import (Paste)",
"Maintenance_Tool_ImportConfig_noti": "Settings Import (app.conf)",
"Maintenance_Tool_ImportPastedCSV": "Devices Import (csv) (paste)",
"Maintenance_Tool_ImportPastedCSV_noti_text": "Are you sure you want to import the pasted CSV? This will completely <b>overwrite</b> the devices in your database.",
"Maintenance_Tool_ImportPastedCSV_text": "Before using this function, please make a backup. Import a CSV (comma separated value) file containing the list of Devices including the Network relationships between Network Nodes and connected devices.",
"Maintenance_Tool_ImportPastedConfig": "Settings Import (paste)",
"Maintenance_Tool_ImportPastedConfig_noti_text": "Are you sure you want to import the pasted config settings? This will completely <b>overwrite</b> the <code>app.conf</code> file.",
"Maintenance_Tool_ImportPastedConfig_text": "Imports the <code>app.conf</code> file containing all the application Settings. You might want to download the current <code>app.conf</code> file first with the <b>Settings Export</b>.",
"Maintenance_Tool_arpscansw": "Toggle arp-Scan (on/off)",
"Maintenance_Tool_arpscansw_noti": "Toggle arp-Scan on or off",
"Maintenance_Tool_arpscansw_noti_text": "When the scan has been switched off it remains off until it is activated again.",
Expand Down Expand Up @@ -489,7 +495,7 @@
"Maintenance_themeselector_lable": "Select Skin",
"Maintenance_themeselector_text": "The change takes place on the server side, so it affects all devices in use.",
"Maintenance_version": "App updates",
"NETWORK_DEVICE_TYPES_description": "Which device types are allowed to be used as network devices in the Network view. The device type has to match exactly the <code>Type</code> setting on a specific device in Device details. Add it on teh Device via the <code>+</code> button. Do not remove existing types, only add new ones.",
"NETWORK_DEVICE_TYPES_description": "Which device types are allowed to be used as network devices in the Network view. The device type has to match exactly the <code>Type</code> setting on a specific device in Device details. Add it on the Device via the <code>+</code> button. Do not remove existing types, only add new ones.",
"NETWORK_DEVICE_TYPES_name": "Network device types",
"Navigation_About": "About",
"Navigation_Devices": "Devices",
Expand Down
Loading

0 comments on commit b4e7415

Please sign in to comment.