diff --git a/README.md b/README.md
index 61c4e505..892a54cc 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,8 @@ A web frontend that allows:
- IP's
- Manual Nmap scans
- Optional speedtest for Device "Internet"
+ - Simple Network relationship display
+ - CSV Export / Import (Experimental)
- ...
| ![Screen 1][screen1] | ![Screen 2][screen2] |
diff --git a/front/deviceDetails.php b/front/deviceDetails.php
index aec5aa3c..ff96dcf6 100644
--- a/front/deviceDetails.php
+++ b/front/deviceDetails.php
@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
- header('Location: /index.php');
+ header('Location: index.php');
exit;
}
diff --git a/front/devices.php b/front/devices.php
index 79d5effe..1e8a5682 100644
--- a/front/devices.php
+++ b/front/devices.php
@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
- header('Location: /index.php');
+ header('Location: index.php');
exit;
}
diff --git a/front/events.php b/front/events.php
index e7acb376..677b9f0a 100644
--- a/front/events.php
+++ b/front/events.php
@@ -1,6 +1,6 @@
+
This network device (node) doesn't have any assigned devices (leaf nodes).
- Go to
".$pia_lang['Device_Title'].", select a device you want to attach to this node and assign it in the
Details tab by selecting it in the
".$pia_lang['DevDetail_MainInfo_Network'] ." dropdown.
+ Go to
".$pia_lang['Device_Title'].", select a device you want to attach to this node and assign it in the
Details tab by selecting it in the
".$pia_lang['DevDetail_MainInfo_Network'] ." dropdown.
";
$str_table_close = "";
diff --git a/front/php/server/devices.php b/front/php/server/devices.php
index 4a790e82..6c7fb92b 100644
--- a/front/php/server/devices.php
+++ b/front/php/server/devices.php
@@ -58,7 +58,9 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
case 'PiaRestoreDBfromArchive': PiaRestoreDBfromArchive(); break;
case 'PiaPurgeDBBackups': PiaPurgeDBBackups(); break;
case 'PiaEnableDarkmode': PiaEnableDarkmode(); break;
- case 'PiaToggleArpScan': PiaToggleArpScan(); break;
+ case 'PiaToggleArpScan': PiaToggleArpScan(); break;
+ case 'ExportCSV': ExportCSV(); break;
+ case 'ImportCSV': ImportCSV(); break;
case 'getDevicesTotals': getDevicesTotals(); break;
case 'getDevicesList': getDevicesList(); break;
@@ -437,6 +439,120 @@ function PiaPurgeDBBackups() {
}
+//------------------------------------------------------------------------------
+// Export CSV of devices
+//------------------------------------------------------------------------------
+function ExportCSV() {
+
+ header("Content-Type: application/octet-stream");
+ header("Content-Transfer-Encoding: Binary");
+ header("Content-disposition: attachment; filename=\"devices.csv\"");
+
+ global $db;
+ $func_result = $db->query("SELECT * FROM Devices");
+
+ // prepare CSV header row
+ // header array with column names
+ $columns = getDevicesColumns();
+
+ // wrap the headers with " (quotes)
+ $resultCSV = '"'.implode('","', $columns).'"';
+
+ //and append a new line
+ $resultCSV = $resultCSV."\n";
+
+ // retrieve the devices from the DB
+ while ($row = $func_result -> fetchArray (SQLITE3_ASSOC)) {
+
+ // loop through columns and add values to the string
+ $index = 0;
+ foreach ($columns as $columnName) {
+
+ // add quotes around the value to prevent issues with commas in fields
+ $resultCSV = $resultCSV.'"'.$row[$columnName].'"';
+
+ // detect last loop - skip as no comma needed
+ if ($index != count($columns) - 1 )
+ {
+ $resultCSV = $resultCSV.',';
+ }
+ $index++;
+ }
+
+ //$resultCSV = $resultCSV.implode(",", [$row["dev_MAC"], $row["dev_Name"]]);
+ $resultCSV = $resultCSV."\n";
+ }
+
+ //write the built CSV string
+ echo $resultCSV;
+}
+
+//------------------------------------------------------------------------------
+// Import CSV of devices
+//------------------------------------------------------------------------------
+function ImportCSV() {
+
+
+ $file = '../../../config/devices.csv';
+
+ if (file_exists($file)) {
+
+ global $db;
+ global $pia_lang;
+
+ $error = "";
+
+ // sql
+ $sql = 'DELETE FROM Devices';
+ // execute sql
+ $result = $db->query($sql);
+
+ // Open the CSV file with read-only mode
+ $csvFile = fopen($file, 'r');
+
+ // Skip the first line
+ fgetcsv($csvFile);
+
+ $columns = getDevicesColumns();
+
+ // Parse data from CSV file line by line (max 10000 lines)
+ while (($row = fgetcsv($csvFile, 10000, ",")) !== FALSE)
+ {
+ $sql = 'INSERT INTO Devices ('.implode(',', $columns).') VALUES ("' .implode('","', $row).'")';
+
+ $result = $db->query($sql);
+
+ // check result
+ if ($result != TRUE) {
+ $error = $db->lastErrorMsg();
+ // break the while loop on error
+ break;
+ }
+ }
+
+ // Close opened CSV file
+ fclose($csvFile);
+
+ if($error == "")
+ {
+ // import succesful
+ echo $pia_lang['BackDevices_DBTools_ImportCSV'];
+
+ }
+ else{
+ // an error occurred while writing to the DB, display the last error message
+ echo $pia_lang['BackDevices_DBTools_ImportCSVError']."\n\n$sql \n\n".$error;
+ }
+
+ } else {
+ echo $pia_lang['BackDevices_DBTools_ImportCSVMissing'];
+ }
+
+
+ $db->close();
+
+}
+
//------------------------------------------------------------------------------
// Toggle Dark/Light Themes
//------------------------------------------------------------------------------
diff --git a/front/php/server/util.php b/front/php/server/util.php
index 925f86e4..58e75f4f 100644
--- a/front/php/server/util.php
+++ b/front/php/server/util.php
@@ -74,6 +74,36 @@ function getNetworkTypes(){
return $array;
}
+function getDevicesColumns(){
+
+ $columns = ["dev_MAC",
+ "dev_Name",
+ "dev_Owner",
+ "dev_DeviceType",
+ "dev_Vendor",
+ "dev_Favorite",
+ "dev_Group",
+ "dev_Comments",
+ "dev_FirstConnection",
+ "dev_LastConnection",
+ "dev_LastIP",
+ "dev_StaticIP",
+ "dev_ScanCycle",
+ "dev_LogEvents",
+ "dev_AlertEvents",
+ "dev_AlertDeviceDown",
+ "dev_SkipRepeated",
+ "dev_LastNotification",
+ "dev_PresentLastScan",
+ "dev_NewDevice",
+ "dev_Location",
+ "dev_Archived",
+ "dev_Network_Node_port",
+ "dev_Network_Node_MAC_ADDR"];
+
+ return $columns;
+}
+
//------------------------------------------------------------------------------
// Simple cookie cache
//------------------------------------------------------------------------------
diff --git a/front/php/templates/header.php b/front/php/templates/header.php
index 2a339335..d224aff5 100644
--- a/front/php/templates/header.php
+++ b/front/php/templates/header.php
@@ -133,7 +133,7 @@ function show_pia_servertime() {
-