Merge remote-tracking branch 'upstream/develop' into develop

# Conflicts:
#	src/includes/functions.inc.php
#	src/lang/en_US.lang.php
#	src/psm/Module/Server/Controller/ServerController.php
#	src/psm/Util/Install/Installer.php
#	src/templates/default/module/server/server/update.tpl.html
#	src/templates/default/module/server/server/view.tpl.html
pull/298/head
Pavel Dvořák 2016-05-21 23:57:03 +02:00
commit 84a21d613d
7 changed files with 94 additions and 25 deletions

View File

@ -40,17 +40,26 @@
function psm_get_lang() {
$args = func_get_args();
if(empty($args)) return $GLOBALS['sm_lang'];
if (empty($args)) return $GLOBALS['sm_lang'];
$result = null;
$resultDefault = null;
$node = null;
$nodeDefault = null;
if($args) {
if ($args) {
$node = '$GLOBALS[\'sm_lang\'][\'' . implode('\'][\'', $args) . '\']';
$nodeDefault = '$GLOBALS[\'sm_lang_default\'][\'' . implode('\'][\'', $args) . '\']';
}
eval('if (isset('.$node.')) $result = '.$node.';');
return $result;
eval('if (isset(' . $node . ')) $result = ' . $node . ';');
eval('if (isset(' . $nodeDefault . ')) $resultDefault = ' . $nodeDefault . ';');
if (empty($result)) {
return $resultDefault;
} else {
return $result;
}
}
/**
@ -60,12 +69,25 @@ function psm_get_lang() {
* @see psm_get_lang()
*/
function psm_load_lang($lang) {
// if not in the language translation must always be available starting translation - English
$default_lang_file = PSM_PATH_LANG . 'en_US.lang.php';
if (file_exists($default_lang_file)) {
require $default_lang_file;
if (isset($sm_lang)) {
$GLOBALS['sm_lang_default'] = $sm_lang;
unset($sm_lang);
}
}
// translated language
$lang_file = PSM_PATH_LANG . $lang . '.lang.php';
if(!file_exists($lang_file)) {
if (!file_exists($lang_file)) {
// If the file has been removed, we use the english one
$en_file = PSM_PATH_LANG . 'en_US.lang.php';
if(!file_exists($en_file)) {
if (!file_exists($en_file)) {
// OK, nothing we can do
die('unable to load language file: ' . $lang_file);
}
@ -73,7 +95,7 @@ function psm_load_lang($lang) {
}
require $lang_file;
if(isset($sm_lang['locale'])) {
if (isset($sm_lang['locale'])) {
setlocale(LC_TIME, $sm_lang['locale']);
}
@ -223,17 +245,17 @@ function psm_add_log($server_id, $type, $message, $user_id = null) {
* @param string $latency
*/
function psm_log_uptime($server_id, $status, $latency) {
global $db;
global $db;
$db->save(
PSM_DB_PREFIX.'servers_uptime',
array(
'server_id' => $server_id,
'date' => date('Y-m-d H:i:s'),
'status' => $status,
'latency' => $latency,
)
);
$db->save(
PSM_DB_PREFIX.'servers_uptime',
array(
'server_id' => $server_id,
'date' => date('Y-m-d H:i:s'),
'status' => $status,
'latency' => $latency,
)
);
}
/**
@ -608,6 +630,9 @@ function psm_no_cache() {
*/
function psm_password_encrypt($password)
{
if(empty($password))
return '';
$key = psm_get_conf('password_encrypt_key');
$iv = mcrypt_create_iv(
@ -619,7 +644,7 @@ function psm_password_encrypt($password)
$iv .
mcrypt_encrypt(
MCRYPT_RIJNDAEL_128,
hash('sha256', $key, true),
hash('sha256', $key, true),
$password,
MCRYPT_MODE_CBC,
$iv
@ -638,6 +663,9 @@ function psm_password_encrypt($password)
*/
function psm_password_decrypt($encryptedString)
{
if(empty($encryptedString))
return '';
$key = psm_get_conf('password_encrypt_key');
$data = base64_decode($encryptedString);
@ -646,7 +674,7 @@ function psm_password_decrypt($encryptedString)
$decrypted = rtrim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
hash('sha256', $key, true),
hash('sha256', $key, true),
substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)),
MCRYPT_MODE_CBC,
$iv

View File

@ -125,7 +125,7 @@ $sm_lang = array(
'website_username' => 'Username',
'website_username_description' => 'Username to access the site. (Only Apache authentication is supported.)',
'website_password' => 'Password',
'website_password_description' => 'Password to access the site. The password is encrypted in the database and is not stored in plain text.',
'website_password_description' => 'Password to access the site. The password is encrypted in the database.',
'fieldset_monitoring' => 'Monitoring',
'fieldset_permissions' => 'Permissions',
'port' => 'Port',

View File

@ -200,7 +200,7 @@ class ServerController extends AbstractServerController {
'edit_value_pattern' => $edit_server['pattern'],
'edit_value_warning_threshold' => $edit_server['warning_threshold'],
'edit_website_username' => $edit_server['website_username'],
'edit_website_password' => psm_password_decrypt($edit_server['website_password']),
'edit_website_password' => empty($edit_server['website_password']) ? '' : sha1($edit_server['website_password']),
'edit_type_selected_' . $edit_server['type'] => 'selected="selected"',
'edit_active_selected_' . $edit_server['active'] => 'selected="selected"',
'edit_email_selected_' . $edit_server['email'] => 'selected="selected"',
@ -233,12 +233,38 @@ class ServerController extends AbstractServerController {
// dont process anything if no data has been posted
return $this->executeIndex();
}
$encrypted_password = '';
if(!empty($_POST['website_password']))
{
$new_password = psm_POST('website_password');
if($this->server_id > 0)
{
$edit_server = $this->getServers($this->server_id);
$hash = sha1($edit_server['website_password']);
if($new_password == $hash)
{
$encrypted_password = $edit_server['website_password'];
}
else
{
$encrypted_password = psm_password_encrypt( $new_password);
}
}
else
{
$encrypted_password = psm_password_encrypt($new_password);
}
}
$clean = array(
'label' => trim(strip_tags(psm_POST('label', ''))),
'ip' => trim(strip_tags(psm_POST('ip', ''))),
'timeout' => (isset($_POST['timeout']) && intval($_POST['timeout']) > 0) ? intval($_POST['timeout']) : null,
'website_username' => psm_POST('website_username', null),
'website_password' => (isset($_POST['website_password'])) ? psm_password_encrypt(psm_POST('website_password')) : '',
'website_password' => $encrypted_password,
'port' => intval(psm_POST('port', 0)),
'type' => psm_POST('type', ''),
'pattern' => psm_POST('pattern', ''),

View File

@ -146,7 +146,7 @@ class Installer {
('sms_from', '1234567890'),
('pushover_status', '0'),
('pushover_api_token', ''),
('password_encrypt_key', " . sha1(microtime()) . "),
('password_encrypt_key', '" . sha1(microtime()) . "'),
('alert_type', 'status'),
('log_status', '1'),
('log_email', '1'),

View File

@ -88,7 +88,7 @@
<div class="control-group types typeWebsite">
<label class="control-label" for="website_password">{{ label_website_password }}</label>
<div class="controls">
<input type="text" id="website_password" name="website_password" value="{{ edit_website_password }}" data-toggle="tooltip" title="{{ label_website_password_description }}" />
<input type="password" id="website_password" name="website_password" value="{{ edit_website_password }}" data-toggle="tooltip" title="{{ label_website_password_description }}" />
</div>
</div>
</fieldset>

View File

@ -79,7 +79,11 @@
</tr>
<tr>
<td>{{ label_website_password }}:</td>
<td>******</td>
<td>
{% if (website_password is not empty) %}
******
{% endif %}
</td>
</tr>
{% if has_admin_actions %}
<tr>

View File

@ -285,6 +285,17 @@ legend {
}
/* Status page */
h2 {
font-size: 16px;
line-height: 12px;
}
h2 small {
font-size: 18px;
}
.offline, .online {
display: inline-block;
width: 100%;