settings prep 2

This commit is contained in:
Jokob-sk
2022-12-23 20:36:07 +11:00
parent ffd8f870f3
commit eb96791223
9 changed files with 417 additions and 133 deletions

View File

@@ -583,9 +583,18 @@ height: 50px;
width:30%;
}
.setting_input input
.center
{
width:300px;
margin: 0;
position: relative;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.top-margin
{
margin-top: 50px;
}
.settings_content {

View File

@@ -381,7 +381,7 @@ if ($_REQUEST['tab'] == '1') {
pialert.log
</div>
<div class="db_tools_table_cell_b">
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert.log" ); ?>
<textarea id="pialert_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert.log" ); ?>
</textarea>
</div>
</div>
@@ -390,7 +390,7 @@ if ($_REQUEST['tab'] == '1') {
IP_changes.log
</div>
<div class="db_tools_table_cell_b">
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
<textarea id="IP_changes_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
</textarea>
</div>
</div>
@@ -399,7 +399,7 @@ if ($_REQUEST['tab'] == '1') {
stdout.log
</div>
<div class="db_tools_table_cell_b">
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stdout.log" ); ?>
<textarea id="stdout_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stdout.log" ); ?>
</textarea>
</div>
</div>
@@ -408,7 +408,7 @@ if ($_REQUEST['tab'] == '1') {
stderr.log
</div>
<div class="db_tools_table_cell_b">
<textarea class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stderr.log" ); ?>
<textarea id="stderr_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stderr.log" ); ?>
</textarea>
</div>
</div>
@@ -450,6 +450,21 @@ if ($_REQUEST['tab'] == '1') {
<script>
function scrollDown()
{
temp = $('#pialert_log');
$temp.scrollTop($text[0].scrollHeight);
temp = $('#IP_changes_log');
$temp.scrollTop($text[0].scrollHeight);
temp = $('#stdout_log');
$temp.scrollTop($text[0].scrollHeight);
temp = $('#stderr_log');
$temp.scrollTop($text[0].scrollHeight);
}
// delete devices with emty macs
function askDeleteDevicesWithEmptyMACs () {
// Ask
@@ -630,9 +645,12 @@ function PiaToggleArpScan()
});
}
// laod footer asynchronously not to block the page load/other sections
// load footer asynchronously not to block the page load/other sections
window.onload = function asyncFooter()
{
// scrollDown();
$("#lastCommit").append('<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github">');
$("#lastDockerUpdate").append(

View File

@@ -8,32 +8,56 @@
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
## TimeZone processing
$basePath = "../../../config/";
$config_file = "pialert.conf";
$fullConfPath = $basePath.$config_file;
chmod($fullConfPath, 0777);
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
$FUNCTION = $_REQUEST['function'];
$SETTINGS = $_REQUEST['settings'];
if ($FUNCTION == 'savesettings') {
saveSettings();
} elseif ($PIA_SCAN_MODE == 'test') {
// other function
}
//------------------------------------------------------------------------------
// Formatting data functions
//------------------------------------------------------------------------------
// Creates a PHP array from a string representing a python array (input format ['...','...'])
function createArray($input){
$pattern = '/(^\s*\[)|(\]\s*$)/';
// regex patterns
$patternBrackets = '/(^\s*\[)|(\]\s*$)/';
$patternQuotes = '/(^\s*\')|(\'\s*$)/';
$replacement = '';
$noBrackets = preg_replace($pattern, $replacement, $input);
// remove brackets
$noBrackets = preg_replace($patternBrackets, $replacement, $input);
return $options = explode(",", $noBrackets);
$options = array();
// create array
$optionsTmp = explode(",", $noBrackets);
// remove quotes
foreach ($optionsTmp as $item)
{
array_push($options, preg_replace($patternQuotes, $replacement, $item) );
}
return $options;
}
function formatDate ($date1) {
@@ -75,7 +99,8 @@ function checkPermissions($files)
// check access to database
if(file_exists($file) != 1)
{
displayMessage("File ".$file." not found or inaccessible. Grant read & write permissions to the file to the correct user.");
$message = "File ".$file." not found or inaccessible. Grant read & write permissions to the file to the correct user.";
displayMessage($message);
}
}
@@ -90,25 +115,118 @@ function displayMessage($message)
function saveSettings()
{
$config_file = "../../../config/pialert.conf";
// save in the file
$new_location = $config_file.'_'.strtotime("now").'.backup';
global $SETTINGS, $FUNCTION, $fullConfPath, $basePath, $config_file_lines_timezone, $config_file_lines;
if(file_exists( $config_file) == 1)
{
// create a backup copy
if (!copy($config_file, $new_location))
{
echo "Failed to copy file ".$config_file." to ".$new_location." <br/> Check your permissions to allow read/write access to the /config folder.";
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
{
echo "Backup of pialert.conf created: <code>".$new_location."</code>";
}
} else {
echo 'File "'.$config_file.'" not found or missing read permissions.';
}
// save in the DB
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
// save in the file
$new_name = "pialert.conf".'_'.$timestamp.'.backup';
$new_location = $basePath.$new_name;
// chmod($fullConfPath, 0755);
if(file_exists( $fullConfPath) == 1)
{
// create a backup copy
if (!copy($fullConfPath, $new_location))
{
echo "Failed to copy file ".$fullConfPath." to ".$new_location." <br/> Check your permissions to allow read/write access to the /config folder.";
}
{
echo "Backup of original pialert.conf created: <code>".$new_name."</code><br/>";
// generate a clean pialert.conf file
$groups = [];
$txt = $txt."#-----------------AUTOGENERATED FILE-----------------#\n";
$txt = $txt."# #\n";
$txt = $txt."# Generated: ".$timestamp." #\n";
$txt = $txt."# #\n";
$txt = $txt."# Config file for the LAN intruder detection app: #\n";
$txt = $txt."# https://github.com/jokob-sk/Pi.Alert #\n";
$txt = $txt."# #\n";
$txt = $txt."#-----------------AUTOGENERATED FILE-----------------#\n";
// collect all groups
foreach ($SETTINGS as $setting) {
if( in_array($setting[0] , $groups) == false) {
array_push($groups ,$setting[0]);
}
}
// go thru the groups and prepare settings to write to file
foreach($groups as $group)
{
$txt = $txt."\n\n# ".$group;
$txt = $txt."\n#---------------------------\n" ;
foreach($SETTINGS as $setting)
{
if($group == $setting[0])
{
if($setting[3] == 'text' or $setting[3] == 'password' or $setting[3] == 'readonly' or $setting[3] == 'selecttext')
{
$txt = $txt.$setting[1]."='".$setting[2]."'\n" ;
} elseif($setting[3] == 'integer' or $setting[3] == 'selectinteger')
{
$txt = $txt.$setting[1]."=".$setting[2]."\n" ;
} elseif($setting[3] == 'boolean')
{
$val = "False";
if($setting[2] == 'true')
{
$val = "True";
}
$txt = $txt.$setting[1]."=".$val."\n" ;
}elseif($setting[3] == 'multiselect' or $setting[3] == 'subnets')
{
$temp = '[';
foreach($setting[2] as $val)
{
$temp = $temp."'". $val."',";
}
$temp = substr_replace($temp, "", -1).']'; // close brackets and remove last comma ','
$txt = $txt.$setting[1]."=".$temp."\n" ;
}
}
}
}
$txt = $txt."\n\n";
$txt = $txt."#-------------------IMPORTANT INFO-------------------#\n";
$txt = $txt."# This file is ingested by a python script, so if #\n";
$txt = $txt."# modified it needs to use python syntax #\n";
$txt = $txt."#-------------------IMPORTANT INFO-------------------#\n";
// open new file and write the new configuration
$newConfig = fopen($basePath."pialert.conf", "w") or die("Unable to open file!");
fwrite($newConfig, $txt);
fclose($newConfig);
}
} else {
echo 'File "'.$fullConfPath.'" not found or missing read permissions.';
}
}
function getString ($codeName, $default, $pia_lang) {
@@ -195,4 +313,6 @@ function setCache($key, $value) {
?>

View File

@@ -408,15 +408,17 @@ $pia_lang['HelpFAQ_Cat_Network_600_text'] = 'Diese Seite soll dir die Möglichke
//General
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
$pia_lang['SCAN_SUBNETS_description'] = '
The scan time itself depends on the number of IP addresses to check.
The number of Ips to check depends on the <a target="_blank" href="https://www.calculator.net/ip-subnet-calculator.html">network mask</a> you set here.
For example, a <code>/24</code> mask results in 256 IPs to check, where as a <code>/16</code>
mask checks around 65,536. Every IP takes a couple seconds to scan. This means that with an incorrect configuration
the scan will take hours to complete instead of seconds.
<ol>
<li>Specify the network mask. For example, the filter <code>192.168.1.0/24</code> covers IP ranges 192.168.1.0 to 192.168.1.255.</li>
<li>Run <code>iwconfig</code> to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
<li>Examples (<g-emoji class="g-emoji" alias="exclamation" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2757.png">❗</g-emoji> Note the <code>[\'...\', \'...\']</code> format for two and more subnets):
<li>Run <code>iwconfig</code> in your ocntainer to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
</ol>
<ul dir="auto">
<li>One subnet: <code>\'192.168.1.0/24 --interface=eth0\'</code></li>
<li>Two subnets: <code>[\'192.168.1.0/24 --interface=eth0\', \'192.168.1.0/24 --interface=eth1\']</code></li>
</ul>';
';
$pia_lang['PRINT_LOG_name'] = 'Print additional logging';
$pia_lang['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
$pia_lang['TIMEZONE_name'] = 'Time zone';
@@ -424,7 +426,7 @@ $pia_lang['TIMEZONE_description'] = 'Time zone to display stats correctly. Find
$pia_lang['PIALERT_WEB_PROTECTION_name'] = 'Enable login';
$pia_lang['PIALERT_WEB_PROTECTION_description'] = 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.';
$pia_lang['PIALERT_WEB_PASSWORD_name'] = 'Login password';
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code>';
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code> in the container';
$pia_lang['INCLUDED_SECTIONS_name'] = 'Notify on';
$pia_lang['INCLUDED_SECTIONS_description'] = 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select / deselect).';
$pia_lang['SCAN_CYCLE_MINUTES_name'] = 'Scan cycle delay';

View File

@@ -373,9 +373,9 @@ $pia_lang['HelpFAQ_Cat_General_102_text'] = 'Check in the Pi.Alert directory if
</span><br>
If the database is still read-only, try reinstalling or restoring a database backup from the maintenance page.';
$pia_lang['HelpFAQ_Cat_General_102docker_head'] = '(🐳 Docker only) Database issues (AJAX errors, read-only, not found)';
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
<li data-sourcepos="49:4-49:106">Download the <a href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
<li data-sourcepos="49:4-49:106">Download the <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/front/log</code>.</li>
<li data-sourcepos="52:4-52:146">To solve permission issues you can also try to create a DB backup and then run a DB Restore via the <strong>Maintenance &gt; Backup/Restore</strong> section.</li>
<li data-sourcepos="53:4-53:228">If the database is in read-only mode you can solve this by setting the owner and group by executing the following command on the host system: <code>docker exec pialert chown -R www-data:www-data /home/pi/pialert/db/pialert.db</code>.</li>
@@ -420,15 +420,17 @@ $pia_lang['HelpFAQ_Cat_Network_600_text'] = 'This page should offer you the poss
//General
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
$pia_lang['SCAN_SUBNETS_description'] = '
The scan time itself depends on the number of IP addresses to check.
The number of Ips to check depends on the <a target="_blank" href="https://www.calculator.net/ip-subnet-calculator.html">network mask</a> you set here.
For example, a <code>/24</code> mask results in 256 IPs to check, where as a <code>/16</code>
mask checks around 65,536. Every IP takes a couple seconds to scan. This means that with an incorrect configuration
the scan will take hours to complete instead of seconds.
<ol>
<li>Specify the network mask. For example, the filter <code>192.168.1.0/24</code> covers IP ranges 192.168.1.0 to 192.168.1.255.</li>
<li>Run <code>iwconfig</code> to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
<li>Examples (<g-emoji class="g-emoji" alias="exclamation" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2757.png">❗</g-emoji> Note the <code>[\'...\', \'...\']</code> format for two and more subnets):
<li>Run <code>iwconfig</code> in your container to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
</ol>
<ul dir="auto">
<li>One subnet: <code>\'192.168.1.0/24 --interface=eth0\'</code></li>
<li>Two subnets: <code>[\'192.168.1.0/24 --interface=eth0\', \'192.168.1.0/24 --interface=eth1\']</code></li>
</ul>';
';
$pia_lang['PRINT_LOG_name'] = 'Print additional logging';
$pia_lang['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
$pia_lang['TIMEZONE_name'] = 'Time zone';
@@ -436,7 +438,7 @@ $pia_lang['TIMEZONE_description'] = 'Time zone to display stats correctly. Find
$pia_lang['PIALERT_WEB_PROTECTION_name'] = 'Enable login';
$pia_lang['PIALERT_WEB_PROTECTION_description'] = 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.';
$pia_lang['PIALERT_WEB_PASSWORD_name'] = 'Login password';
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code>';
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code> in the container';
$pia_lang['INCLUDED_SECTIONS_name'] = 'Notify on';
$pia_lang['INCLUDED_SECTIONS_description'] = 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select / deselect).';
$pia_lang['SCAN_CYCLE_MINUTES_name'] = 'Scan cycle delay';

View File

@@ -414,15 +414,17 @@ $pia_lang['HelpFAQ_Cat_Network_600_text'] = 'Esta sección debería ofrecerle la
//General
$pia_lang['SCAN_SUBNETS_name'] = 'Subnets to scan';
$pia_lang['SCAN_SUBNETS_description'] = '
The scan time itself depends on the number of IP addresses to check.
The number of Ips to check depends on the <a target="_blank" href="https://www.calculator.net/ip-subnet-calculator.html">network mask</a> you set here.
For example, a <code>/24</code> mask results in 256 IPs to check, where as a <code>/16</code>
mask checks around 65,536. Every IP takes a couple seconds to scan. This means that with an incorrect configuration
the scan will take hours to complete instead of seconds.
<ol>
<li>Specify the network mask. For example, the filter <code>192.168.1.0/24</code> covers IP ranges 192.168.1.0 to 192.168.1.255.</li>
<li>Run <code>iwconfig</code> to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
<li>Examples (<g-emoji class="g-emoji" alias="exclamation" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2757.png">❗</g-emoji> Note the <code>[\'...\', \'...\']</code> format for two and more subnets):
<li>Run <code>iwconfig</code> in your container to find your interface name(s) (e.g.: <code>eth0</code>, <code>eth1</code>)</li>
</ol>
<ul dir="auto">
<li>One subnet: <code>\'192.168.1.0/24 --interface=eth0\'</code></li>
<li>Two subnets: <code>[\'192.168.1.0/24 --interface=eth0\', \'192.168.1.0/24 --interface=eth1\']</code></li>
</ul>';
';
$pia_lang['PRINT_LOG_name'] = 'Print additional logging';
$pia_lang['PRINT_LOG_description'] = 'This setting will enable more verbose logging. Useful for debugging events writing into the database.';
$pia_lang['TIMEZONE_name'] = 'Time zone';
@@ -430,7 +432,7 @@ $pia_lang['TIMEZONE_description'] = 'Time zone to display stats correctly. Find
$pia_lang['PIALERT_WEB_PROTECTION_name'] = 'Enable login';
$pia_lang['PIALERT_WEB_PROTECTION_description'] = 'When enabled a login dialog is displayed. Read below carefully if you get locked out of your instance.';
$pia_lang['PIALERT_WEB_PASSWORD_name'] = 'Login password';
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code>';
$pia_lang['PIALERT_WEB_PASSWORD_description'] = 'The default password is <code>123456</code>. To change password run <code>/home/pi/pialert/back/pialert-cli</code> in the container';
$pia_lang['INCLUDED_SECTIONS_name'] = 'Notify on';
$pia_lang['INCLUDED_SECTIONS_description'] = 'Specifies which events trigger notifications. Remove the event type(s) you don\'t want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select / deselect).';
$pia_lang['SCAN_CYCLE_MINUTES_name'] = 'Scan cycle delay';
@@ -531,5 +533,4 @@ $pia_lang['PIHOLE_ACTIVE_description'] = 'If enabled you need to map <code>:/etc
$pia_lang['DHCP_ACTIVE_name'] = 'Enable PiHole DHCP';
$pia_lang['DHCP_ACTIVE_description'] = 'If enabled you need to map <code>:/etc/pihole/dhcp.leases</code> in your <code>docker-compose.yml</code> file.';
?>

View File

@@ -13,7 +13,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color: #d0d0d0;">
<div class="modal-header" >
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 id="modal-default-title" class="modal-title"> Modal Default Title </h4>
</div>

View File

@@ -75,7 +75,7 @@ $db->close();
<?php
$resultHTML = "";
$html = "";
$groups = [];
// collect all groups
@@ -87,70 +87,85 @@ $db->close();
// create settings groups
foreach ($groups as $group) {
$resultHTML = $resultHTML.'<section class="settings_content">
$html = $html.'<section class="settings_content">
<h4>'.$group.'</h4>';
// populate settings for each group
foreach ($settings as $setting) {
if($setting["Group"] == $group)
foreach ($settings as $set) {
if($set["Group"] == $group)
{
$resultHTML = $resultHTML.
$html = $html.
'<div class="table_row" >
<div class="table_cell setting_name" >';
$resultHTML = $resultHTML.getString ($setting['Code_Name'].'_name', $setting['Display_Name'], $pia_lang);
$html = $html.getString ($set['Code_Name'].'_name', $set['Display_Name'], $pia_lang);
$resultHTML = $resultHTML.
$html = $html.
'</div>
<div class="table_cell setting_description" >';
$resultHTML = $resultHTML.getString ($setting['Code_Name'].'_description', $setting['Description'], $pia_lang);
$html = $html.getString ($set['Code_Name'].'_description', $set['Description'], $pia_lang);
$resultHTML = $resultHTML.
$html = $html.
'</div>
<div class="table_cell setting_input" >';
// render different input types based on the setting type
$inputType = "";
// render different input types based on the set type
$input = "";
// text - textbox
if($setting['Type'] == 'text')
if($set['Type'] == 'text' )
{
$inputType = '<input value="'.$setting['Value'].'"/>';
$input = '<input class="form-control input" id="'.$set['Code_Name'].'" value="'.$set['Value'].'"/>';
}
// password - hidden text
elseif ($setting['Type'] == 'password')
elseif ($set['Type'] == 'password')
{
$inputType = '<input type="password" value="'.$setting['Value'].'"/>';
$input = '<input class="form-control input" id="'.$set['Code_Name'].'" type="password" value="'.$set['Value'].'"/>';
}
// readonly
elseif ($set['Type'] == 'readonly')
{
$input = '<input class="form-control input" id="'.$set['Code_Name'].'" value="'.$set['Value'].'" readonly/>';
}
// boolean - checkbox
elseif ($setting['Type'] == 'boolean')
elseif ($set['Type'] == 'boolean')
{
$checked = "";
if ($setting['Value'] == "True") { $checked = "checked";};
$inputType = '<input type="checkbox" value="'.$setting['Value'].'" '.$checked.' />';
if ($set['Value'] == "True") { $checked = "checked";};
$input = '<input class="checkbox" id="'.$set['Code_Name'].'" type="checkbox" value="'.$set['Value'].'" '.$checked.' />';
}
// integer - number input
elseif ($setting['Type'] == 'integer')
elseif ($set['Type'] == 'integer')
{
$inputType = '<input type="number" value="'.$setting['Value'].'"/>';
$input = '<input class="form-control" id="'.$set['Code_Name'].'" type="number" value="'.$set['Value'].'"/>';
}
// select - dropdown
elseif ($setting['Type'] == 'select')
// selecttext - dropdown
elseif ($set['Type'] == 'selecttext')
{
$inputType = '<select name="'.$setting['Code_Name'].'" id="'.$setting['Code_Name'].'">';
$options = createArray($setting['Options']);
$input = '<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">';
$options = createArray($set['Options']);
foreach ($options as $option) {
$inputType = $inputType.'<option value="'.$option.'">'.$option.'</option>';
$input = $input.'<option value="'.$option.'">'.$option.'</option>';
}
$inputType = $inputType.'</select>';
$input = $input.'</select>';
}
// selectinteger - dropdown
elseif ($set['Type'] == 'selectinteger')
{
$input = '<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'">';
$options = createArray($set['Options']);
foreach ($options as $option) {
$input = $input.'<option value="'.$option.'">'.$option.'</option>';
}
$input = $input.'</select>';
}
// multiselect
elseif ($setting['Type'] == 'multiselect')
elseif ($set['Type'] == 'multiselect')
{
$inputType = '<select name="'.$setting['Code_Name'].'" id="'.$setting['Code_Name'].'" multiple>';
$values = createArray($setting['Value']);
$options = createArray($setting['Options']);
$input = '<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple>';
$values = createArray($set['Value']);
$options = createArray($set['Options']);
foreach ($options as $option) {
$selected = "";
@@ -159,27 +174,57 @@ $db->close();
$selected = "selected";
}
$inputType = $inputType.'<option value="'.$option.'" '.$selected.'>'.$option.'</option>';
$input = $input.'<option value="'.$option.'" '.$selected.'>'.$option.'</option>';
}
$inputType = $inputType.'</select>';
}
$input = $input.'</select>';
}
// multiselect
elseif ($set['Type'] == 'subnets')
{
$input = $input.
'<div class="row form-group">
<div class="col-xs-6">
<input class="form-control " id="ipMask" type="text" placeholder="192.168.1.0/24"/>
</div>';
$input = $input.
'<div class="col-xs-3">
<input class="form-control " id="ipInterface" type="text" placeholder="eth0" />
</div>
<div class="col-xs-3"><button class="btn btn-primary" onclick="addInterface()" >Add</button></div>
</div>';
$input = $input.'<div class="form-group">
<select class="form-control" name="'.$set['Code_Name'].'" id="'.$set['Code_Name'].'" multiple readonly>';
$options = createArray($set['Value']);
$resultHTML = $resultHTML.$inputType;
foreach ($options as $option) {
$resultHTML = $resultHTML.'</div>
$input = $input.'<option value="'.$option.'" disabled>'.$option.'</option>';
}
$input = $input.'</select></div>';
$input = $input.'<div><button class="btn btn-primary" onclick="removeInterfaces()">Remove all</button></div>';
}
$html = $html.$input;
$html = $html.'</div>
</div>';
}
}
$resultHTML = $resultHTML.'</section>';
$html = $html.'</section>';
}
echo $resultHTML;
echo $html;
?>
<!-- /.content -->
<div class="table_row" >
<button type="button" class="btn btn-default pa-btn bg-green dbtools-button" id="save" onclick="saveSettings()"><?php echo $pia_lang['DevDetail_button_Save'];?></button>
<div class="row" >
<div class="row">
<button type="button" class="center top-margin btn btn-primary btn-default pa-btn bg-green dbtools-button" id="save" onclick="saveSettings()"><?php echo $pia_lang['DevDetail_button_Save'];?></button>
</div>
<div id="result"></div>
</div>
</div>
@@ -193,13 +238,77 @@ $db->close();
?>
<script>
function addInterface()
{
ipMask = $('#ipMask').val();
ipInterface = $('#ipInterface').val();
full = ipMask + " --interface=" + ipInterface;
if(ipMask == "" || ipInterface == "")
{
showModalDefault ('Validation error', 'Specify both, the network mask and the interface');
} else {
$('#SCAN_SUBNETS').append($('<option disabled></option>').attr('value', full).text(full));
$('#ipMask').val('');
$('#ipInterface').val('');
}
}
function removeInterfaces()
{
$('#SCAN_SUBNETS').empty();
}
function collectSettings()
{
var settingsArray = [];
// generate javascript to collect values
// multiselect, select, password
<?php
$noConversion = array('text', 'integer', 'password', 'readonly', 'selecttext', 'selectinteger', "multiselect");
foreach ($settings as $set) {
if(in_array($set['Type'] , $noConversion))
{
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", $("#'.$set["Code_Name"].'").val(), "'.$set["Type"].'" ]);';
}
elseif ($set['Type'] == "boolean")
{
echo 'temp = $("#'.$set["Code_Name"].'").is(":checked") ;';
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", temp, "'.$set["Type"].'" ]);';
}
elseif ($set["Code_Name"] == "SCAN_SUBNETS")
{
echo "var temps = [];
$( '#SCAN_SUBNETS option' ).each( function( i, selected ) {
temps.push($( selected ).val());
});
";
echo 'settingsArray.push(["'.$set["Group"].'", "'.$set["Code_Name"].'", temps, "'.$set["Type"].'" ]);';
}
}
?>
console.log(settingsArray);
return settingsArray;
}
function saveSettings() {
$.ajax({
method: "POST",
url: "../php/server/util.php",
data: { function: 'savesettings' },
data: { function: 'savesettings', settings: collectSettings() },
success: function(data, textStatus) {
$("#result").html(data);
// $("#result").html(data);
console.log(data);
showModalDefault ('Result', data + "<br/><b>Restart the container for the chanegs to take effect.</b>");
}
})
}