mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
🔐PWD work #634
This commit is contained in:
@@ -147,7 +147,6 @@ if ($ENABLED_DARKMODE === True) {
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true"><3E></button>
|
||||
<h4><i class="icon fa <?php echo $login_icon;?>"></i><?php echo $login_headline;?></h4>
|
||||
<p><?php echo $login_info;?></p>
|
||||
<p><?= lang('Login_Psw_run');?><br><span style="border: solid 1px yellow; padding: 2px;"> /app/back/pialert-cli set_password <?= lang('Login_Psw_new');?></span><br><?= lang('Login_Psw_folder');?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -165,6 +165,18 @@
|
||||
return true; // Return true if no schedules are found
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Checks if value is already encoded
|
||||
function isSHA256(value) {
|
||||
// Check if the value is a string and has a length of 64 characters
|
||||
if (typeof value === "string" && value.length === 64) {
|
||||
// Check if the value contains only hexadecimal characters
|
||||
return /^[0-9a-fA-F]+$/.test(value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1
front/lib/crypto/crypto-js.min.js
vendored
Executable file
1
front/lib/crypto/crypto-js.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
@@ -328,7 +328,7 @@ function saveSettings()
|
||||
$settingValue = $setting[3];
|
||||
|
||||
if ($group == $settingGroup) {
|
||||
if ($settingType == 'text' || $settingType == 'password' || $settingType == 'readonly' || $settingType == 'text.select') {
|
||||
if ($settingType == 'text' || $settingType == 'password' || $settingType == 'password.SHA256' || $settingType == 'readonly' || $settingType == 'text.select') {
|
||||
$val = encode_single_quotes($settingValue);
|
||||
$txt .= $settingKey . "='" . $val . "'\n";
|
||||
} elseif ($settingType == 'integer' || $settingType == 'integer.select') {
|
||||
|
||||
@@ -29,18 +29,18 @@ $config_file_lines = file($config_file);
|
||||
$CookieSaveLoginName = "NetAlertX_SaveLogin";
|
||||
|
||||
// ###################################
|
||||
// ## PIALERT_WEB_PROTECTION FALSE
|
||||
// ## SETPWD_enable_password FALSE
|
||||
// ###################################
|
||||
|
||||
$config_file_lines_bypass = array_values(preg_grep('/^PIALERT_WEB_PROTECTION.*=/', $config_file_lines));
|
||||
$config_file_lines_bypass = array_values(preg_grep('/^SETPWD_enable_password.*=/', $config_file_lines));
|
||||
$protection_line = explode("=", $config_file_lines_bypass[0]);
|
||||
$Pia_WebProtection = strtolower(trim($protection_line[1]));
|
||||
|
||||
// ###################################
|
||||
// ## PIALERT_WEB_PROTECTION TRUE
|
||||
// ## SETPWD_enable_password TRUE
|
||||
// ###################################
|
||||
|
||||
$config_file_lines = array_values(preg_grep('/^PIALERT_WEB_PASSWORD.*=/', $config_file_lines));
|
||||
$config_file_lines = array_values(preg_grep('/^SETPWD_password.*=/', $config_file_lines));
|
||||
$password_line = explode("'", $config_file_lines[0]);
|
||||
$Pia_Password = $password_line[1];
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
| | Yes | PIHOLE | External SQLite DB | 🔍dev scanner | 📚[pihole_scan](/front/plugins/pihole_scan/) |
|
||||
| | | PUSHSAFER | Script | 💬 publisher | 📚[_publisher_pushsafer](/front/plugins/_publisher_pushsafer/) |
|
||||
| | | PUSHOVER | Script | 💬 publisher | 📚[_pushover_pushsafer](/front/plugins/_publisher_pushover/) |
|
||||
| | | SETPWD | Script | ⚙ system | 📚[set_password](/front/plugins/set_password/) |
|
||||
| Yes | | SETPWD | Template | ⚙ system | 📚[set_password](/front/plugins/set_password/) |
|
||||
| | | SMTP | Script | 💬 publisher | 📚[_publisher_email](/front/plugins/_publisher_email/) |
|
||||
| | Yes | SNMPDSC | Script | 🔍dev scanner | 📚[snmp_discovery](/front/plugins/snmp_discovery/) |
|
||||
| | Yes** | UNDIS | Script | ♻ other | 📚[undiscoverables](/front/plugins/undiscoverables/) |
|
||||
|
||||
@@ -1,48 +1,13 @@
|
||||
## Overview
|
||||
|
||||
A simple script-based plugin for setting the password.
|
||||
A simple setting-based plugin for setting the password.
|
||||
|
||||
### Usage
|
||||
|
||||
- Head to **Settings** > **UI password** to adjust the default values.
|
||||
- Head to **Settings** > **Set Password** to adjust the default values.
|
||||
|
||||
### Notes
|
||||
|
||||
- The plugin is executed on the `RUN` type `before_config_save` so it's possible to update the `app.conf` file before the data is loaded into the app.
|
||||
- The executed command is stored in the `CMD` setting: `/app/back/pialert-cli set_password {password}`
|
||||
- The `{password}` parameter is replaced via the parameter and setting below:
|
||||
|
||||
```json
|
||||
...
|
||||
"params" : [
|
||||
{
|
||||
"name" : "password",
|
||||
"type" : "setting",
|
||||
"value" : "SETPWD_password"
|
||||
}
|
||||
],
|
||||
|
||||
...
|
||||
{
|
||||
"function": "password",
|
||||
"type": "password",
|
||||
"maxLength": 50,
|
||||
"default_value": "123456",
|
||||
"options": [],
|
||||
"localized": ["name", "description"],
|
||||
"name": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "Password"
|
||||
}
|
||||
],
|
||||
"description": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "The default password is <code>123456</code>. To change the password run <code>/app/back/pialert-cli set_password {password}</code> in the container"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
- The default password is <code>123456</code>.
|
||||
- When enabled a login dialog is displayed. If facing issues, you can always disable the login by setting <code>SETPWD_enable_password=False</code> in your <code>app.conf</code> file.
|
||||
- SHA256 hash is used
|
||||
@@ -4,7 +4,7 @@
|
||||
"unique_prefix": "SETPWD",
|
||||
"plugin_type": "system",
|
||||
"enabled": true,
|
||||
"data_source": "script",
|
||||
"data_source": "template",
|
||||
"show_ui": false,
|
||||
"localized": ["display_name", "description", "icon"],
|
||||
"display_name": [{
|
||||
@@ -40,57 +40,29 @@
|
||||
"value" : "SETPWD_password"
|
||||
}
|
||||
],
|
||||
"settings":[
|
||||
{
|
||||
"function": "RUN",
|
||||
"events": [],
|
||||
"type": "text.select",
|
||||
"default_value":"disabled",
|
||||
"options": ["disabled", "before_config_save"],
|
||||
"localized": ["name", "description"],
|
||||
"name" :[{
|
||||
"language_code":"en_us",
|
||||
"string" : "When to run"
|
||||
},
|
||||
{
|
||||
"language_code":"es_es",
|
||||
"string" : "Cuándo ejecuta"
|
||||
}],
|
||||
"description": [{
|
||||
"language_code":"en_us",
|
||||
"string" : "Set to <code>before_config_save</code> and specify password to reset your pasword in <code>SETPWD_password</code>."
|
||||
},
|
||||
{
|
||||
"language_code":"es_es",
|
||||
"string" : "Configure en <code>before_config_save</code> y especifique la contraseña para restablecer su contraseña en <code>SETPWD_password</code>. Puede establecer <code>deshabilitado</code> una vez que se cambia la contraseña."
|
||||
}]
|
||||
},
|
||||
"settings":[
|
||||
{
|
||||
"function": "CMD",
|
||||
"type": "readonly",
|
||||
"default_value":"/app/back/pialert-cli set_password {password}",
|
||||
"options": [],
|
||||
"localized": ["name", "description"],
|
||||
"name" : [{
|
||||
"language_code":"en_us",
|
||||
"string" : "Command"
|
||||
},
|
||||
{
|
||||
"language_code":"es_es",
|
||||
"string" : "Comando"
|
||||
}],
|
||||
"description": [{
|
||||
"language_code":"en_us",
|
||||
"string" : "Command to run"
|
||||
},
|
||||
{
|
||||
"language_code":"es_es",
|
||||
"string" : "Comando a ejecutar"
|
||||
}]
|
||||
"function": "enable_password",
|
||||
"type": "boolean",
|
||||
"default_value": false,
|
||||
"options": [],
|
||||
"localized": ["name", "description"],
|
||||
"name": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "Enable login"
|
||||
}
|
||||
],
|
||||
"description": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "When enabled a login dialog is displayed. If facing issues, you can always disable the login by setting <code>SETPWD_enable_password=False</code> in your <code>app.conf</code> file."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"function": "password",
|
||||
"type": "password",
|
||||
"type": "password.SHA256",
|
||||
"maxLength": 50,
|
||||
"default_value": "123456",
|
||||
"options": [],
|
||||
@@ -108,12 +80,8 @@
|
||||
"description": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "The default password is <code>123456</code>. To change it, you can either use this plugin (follow the instructions in the <code>SETPWD_RUN</code> setting) or run <code>/app/back/pialert-cli set_password {password}</code> in the container."
|
||||
},
|
||||
{
|
||||
"language_code": "es_es",
|
||||
"string": "La contraseña predeterminada es <code>123456</code>. Para cambiar la contraseña, ejecute <code>/app/back/pialert-cli set_password {password}</code> en el contenedor"
|
||||
}
|
||||
"string": "The default password is <code>123456</code>."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
<script src="js/settings_utils.js"></script>
|
||||
<script src="js/db_methods.js"></script>
|
||||
<script src="js/ui_components.js"></script>
|
||||
<script src="lib/crypto/crypto-js.min.js"></script>
|
||||
|
||||
|
||||
<div id="settingsPage" class="content-wrapper">
|
||||
@@ -412,7 +413,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
}
|
||||
} else if (setType === 'integer') {
|
||||
inputHtml = `<input onChange="settingsChanged()" my-data-type="${setType}" class="form-control" id="${codeName}" type="number" value="${val}"/>`;
|
||||
} else if (setType === 'password') {
|
||||
} else if (setType.startsWith('password')) {
|
||||
inputHtml = `<input onChange="settingsChanged()" my-data-type="${setType}" class="form-control input" id="${codeName}" type="password" value="${val}"/>`;
|
||||
} else if (setType === 'readonly') {
|
||||
inputHtml = `<input class="form-control input" my-data-type="${setType}" id="${codeName}" value="${val}" readonly/>`;
|
||||
@@ -645,7 +646,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
$('#SCAN_SUBNETS').empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------
|
||||
function saveSettings() {
|
||||
if(<?php echo count($settings)?> != settingsNumber)
|
||||
@@ -686,6 +687,15 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
settingsArray.push([set["Group"], set["Code_Name"], set["Type"], JSON.stringify(temps)]);
|
||||
} else if (set['Type'] === 'json') {
|
||||
const temps = $('#'+set["Code_Name"]).val();
|
||||
settingsArray.push([set["Group"], set["Code_Name"], set["Type"], temps]);
|
||||
} else if (set['Type'] === 'password.SHA256') {
|
||||
// save value as SHA256 if value isn't SHA256 already
|
||||
var temps = $('#'+set["Code_Name"]).val();
|
||||
|
||||
if(temps != "" && !isSHA256(temps))
|
||||
{
|
||||
temps = CryptoJS.SHA256(temps).toString(CryptoJS.enc.Hex);
|
||||
}
|
||||
settingsArray.push([set["Group"], set["Code_Name"], set["Type"], temps]);
|
||||
}
|
||||
});
|
||||
@@ -705,11 +715,11 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
window.onbeforeunload = null;
|
||||
|
||||
// Reloads the current page
|
||||
setTimeout("window.location.reload()", 3000);
|
||||
|
||||
setTimeout("window.location.reload()", 3000);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user