Merge branch 'jokob-sk:main' into nginx

This commit is contained in:
((void*)0)
2022-08-05 13:37:07 +00:00
committed by GitHub
13 changed files with 224 additions and 19 deletions

View File

@@ -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] |

View File

@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /index.php');
header('Location: index.php');
exit;
}

View File

@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /index.php');
header('Location: index.php');
exit;
}

View File

@@ -1,6 +1,6 @@
<!-- ---------------------------------------------------------------------------
# Pi.Alert
# Open Source Network Guard / WIFI & LAN intrusion detector
# Open Source Network Guard / WIFI & LAN intrusion detector
#
# events.php - Front module. Events page
#-------------------------------------------------------------------------------
@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /index.php');
header('Location: index.php');
exit;
}

View File

@@ -3,7 +3,7 @@ session_start();
if ($_REQUEST['action'] == 'logout') {
session_destroy();
header('Location: /index.php');
header('Location: index.php');
}
// ###################################
// ## Login settings locale start
@@ -40,7 +40,7 @@ $Pia_WebProtection = strtolower(trim($protection_line[1]));
if ($Pia_WebProtection == 'false')
{
header('Location: /devices.php');
header('Location: devices.php');
$_SESSION["login"] = 1;
exit;
}
@@ -55,13 +55,13 @@ $Pia_Password = $password_line[1];
if ($Pia_Password == hash('sha256',$_POST["loginpassword"]))
{
header('Location: /devices.php');
header('Location: devices.php');
$_SESSION["login"] = 1;
}
if ($_SESSION["login"] == 1)
{
header('Location: /devices.php');
header('Location: devices.php');
}
if ($_SESSION["login"] != 1)
@@ -123,7 +123,7 @@ if ($ENABLED_DARKMODE === True) {
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg"><?php echo $pia_lang['Login_Box'];?></p>
<form action="/index.php" method="post">
<form action="index.php" method="post">
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="<?php echo $pia_lang['Login_Psw-box'];?>" name="loginpassword">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>

View File

@@ -197,3 +197,10 @@ function debugTimer () {
}
// -----------------------------------------------------------------------------
function openInNewTab (url) {
window.open(url, "_blank");
}

View File

@@ -3,7 +3,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /index.php');
header('Location: index.php');
exit;
}
@@ -344,6 +344,18 @@ if (submit && isset($_POST['langselector_set'])) {
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_purgebackup_text'];?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" style="">
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="btnExportCSV" onclick="askExportCSV()"><?php echo $pia_lang['Maintenance_Tool_ExportCSV'];?></button>
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_ExportCSV_text'];?></div>
</div>
<div class="db_info_table_row">
<div class="db_tools_table_cell_a" style="">
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnImportCSV" onclick="askImportCSV()"><?php echo $pia_lang['Maintenance_Tool_ImportCSV'];?></button>
</div>
<div class="db_tools_table_cell_b"><?php echo $pia_lang['Maintenance_Tool_ImportCSV_text'];?></div>
</div>
</div>
</div>
</div>
@@ -491,6 +503,32 @@ function PiaPurgeDBBackups()
});
}
// Export CSV
function askExportCSV() {
// Ask
showModalWarning('<?php echo $pia_lang['Maintenance_Tool_ExportCSV_noti'];?>', '<?php echo $pia_lang['Maintenance_Tool_ExportCSV_noti_text'];?>',
'<?php echo $pia_lang['Gen_Cancel'];?>', '<?php echo $pia_lang['Gen_Okay'];?>', 'ExportCSV');
}
function ExportCSV()
{
// Execute
openInNewTab(window.location.origin + "/php/server/devices.php?action=ExportCSV")
}
// Import CSV
function askImportCSV() {
// Ask
showModalWarning('<?php echo $pia_lang['Maintenance_Tool_ImportCSV_noti'];?>', '<?php echo $pia_lang['Maintenance_Tool_ImportCSV_noti_text'];?>',
'<?php echo $pia_lang['Gen_Cancel'];?>', '<?php echo $pia_lang['Gen_Okay'];?>', 'ImportCSV');
}
function ImportCSV()
{
// Execute
$.get('/php/server/devices.php?action=ImportCSV', function(msg) {
showMessage (msg);
});
}
// Switch Darkmode
function askPiaEnableDarkmode() {
// Ask

View File

@@ -2,7 +2,7 @@
session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /index.php');
header('Location: index.php');
exit;
}
@@ -151,7 +151,7 @@
FROM Devices WHERE dev_Network_Node_MAC_ADDR = "'.$node_mac.'" order by port asc';
global $db;
$func_result = $db->query($func_sql);
$func_result = $db->query($func_sql);
// array
$tableData = array();
@@ -226,7 +226,7 @@
</h4>
<div>
This network device (node) doesn't have any assigned devices (leaf nodes).
Go to <a href='./devices.php'><b>".$pia_lang['Device_Title']."</b></a>, select a device you want to attach to this node and assign it in the <b>Details</b> tab by selecting it in the <b>".$pia_lang['DevDetail_MainInfo_Network'] ."</b> dropdown.
Go to <a href='devices.php'><b>".$pia_lang['Device_Title']."</b></a>, select a device you want to attach to this node and assign it in the <b>Details</b> tab by selecting it in the <b>".$pia_lang['DevDetail_MainInfo_Network'] ."</b> dropdown.
</div>
</div>";
$str_table_close = "";

View File

@@ -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
//------------------------------------------------------------------------------

View File

@@ -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
//------------------------------------------------------------------------------

View File

@@ -133,7 +133,7 @@ function show_pia_servertime() {
<!-- ----------------------------------------------------------------------- -->
<!-- Logo -->
<a href="." class="logo">
<a href="devices.php" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini">P<b>a</b></span>
<!-- logo for regular state and mobile devices -->
@@ -177,7 +177,7 @@ function show_pia_servertime() {
<li class="user-footer">
<div class="pull-right">
<a href="/index.php?action=logout" class="btn btn-danger">Sign out</a>
<a href="index.php?action=logout" class="btn btn-danger">Sign out</a>
</div>
</li>
</ul>

View File

@@ -235,11 +235,11 @@ $pia_lang['Maintenance_Tool_del_allevents30_noti_text'] = 'Are you sure you want
$pia_lang['Maintenance_Tool_backup'] = 'DB Backup';
$pia_lang['Maintenance_Tool_backup_text'] = 'The database backups are located in the database directory as a zip-archive, named with the creation date. There is no maximum number of backups.';
$pia_lang['Maintenance_Tool_backup_noti'] = 'DB Backup';
$pia_lang['Maintenance_Tool_backup_noti_text'] = 'Are you sure you want to exectute the the DB Backup? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_backup_noti_text'] = 'Are you sure you want to execute the the DB Backup? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_restore'] = 'DB Restore';
$pia_lang['Maintenance_Tool_restore_text'] = 'The latest backup can be restored via the button, but older backups can only be restored manually. After the restore, make an integrity check on the database for safety, in case the db was currently in write access when the backup was created.';
$pia_lang['Maintenance_Tool_restore_noti'] = 'DB Restore';
$pia_lang['Maintenance_Tool_restore_noti_text'] = 'Are you sure you want to exectute the the DB Restore? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_restore_noti_text'] = 'Are you sure you want to execute the the DB Restore? Be sure that no scan is currently running.';
$pia_lang['Maintenance_Tool_purgebackup'] = 'Purge Backups';
$pia_lang['Maintenance_Tool_purgebackup_text'] = 'All other backups will be deleted except for the last 3 backups.';
$pia_lang['Maintenance_Tool_purgebackup_noti'] = 'Purge Backups';
@@ -248,6 +248,14 @@ $pia_lang['Maintenance_Tool_del_ActHistory'] = 'Deleting the network activity';
$pia_lang['Maintenance_Tool_del_ActHistory_text'] = 'The network activity graph is reset. This does not affect the events.';
$pia_lang['Maintenance_Tool_del_ActHistory_noti'] = 'Delete network activity';
$pia_lang['Maintenance_Tool_del_ActHistory_noti_text'] = 'Are you sure you want to reset the network activity?';
$pia_lang['Maintenance_Tool_ExportCSV'] = 'CSV Export';
$pia_lang['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.';
$pia_lang['Maintenance_Tool_ExportCSV_noti'] = 'CSV Export';
$pia_lang['Maintenance_Tool_ExportCSV_noti_text'] = 'Are you sure you want to generate a CSV file?';
$pia_lang['Maintenance_Tool_ImportCSV'] = 'CSV Import';
$pia_lang['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.';
$pia_lang['Maintenance_Tool_ImportCSV_noti'] = 'CSV Import';
$pia_lang['Maintenance_Tool_ImportCSV_noti_text'] = 'Are you sure you want to import the CSV file? This will completely overwrite the devices in your database.';
//////////////////////////////////////////////////////////////////
// Maintenance Page
@@ -274,6 +282,10 @@ $pia_lang['BackDevices_DBTools_UpdDevError'] = 'Error updating device';
$pia_lang['BackDevices_DBTools_Upgrade'] = 'Database upgraded successfully';
$pia_lang['BackDevices_DBTools_UpgradeError'] = 'Database upgrade failed';
$pia_lang['BackDevices_DBTools_Purge'] = 'The oldest backups were deleted';
$pia_lang['BackDevices_DBTools_ImportCSV'] = 'The devices from the CSV file were imported successfully.';
$pia_lang['BackDevices_DBTools_ImportCSVError'] = 'The CSV file couldn\'t be imported. Make sure the format is correct.';
$pia_lang['BackDevices_DBTools_ImportCSVMissing'] = 'The CSV file couldn\'t be found under <b>/config/devices.csv.</b>';
//////////////////////////////////////////////////////////////////
// Network Page

View File

@@ -12,7 +12,7 @@ session_start();
if ($_SESSION["login"] != 1)
{
header('Location: /index.php');
header('Location: index.php');
exit;
}