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() { function psm_get_lang() {
$args = func_get_args(); $args = func_get_args();
if(empty($args)) return $GLOBALS['sm_lang']; if (empty($args)) return $GLOBALS['sm_lang'];
$result = null; $result = null;
$resultDefault = null;
$node = null; $node = null;
$nodeDefault = null;
if($args) { if ($args) {
$node = '$GLOBALS[\'sm_lang\'][\'' . implode('\'][\'', $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() * @see psm_get_lang()
*/ */
function psm_load_lang($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'; $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 // If the file has been removed, we use the english one
$en_file = PSM_PATH_LANG . 'en_US.lang.php'; $en_file = PSM_PATH_LANG . 'en_US.lang.php';
if(!file_exists($en_file)) { if (!file_exists($en_file)) {
// OK, nothing we can do // OK, nothing we can do
die('unable to load language file: ' . $lang_file); die('unable to load language file: ' . $lang_file);
} }
@ -73,7 +95,7 @@ function psm_load_lang($lang) {
} }
require $lang_file; require $lang_file;
if(isset($sm_lang['locale'])) { if (isset($sm_lang['locale'])) {
setlocale(LC_TIME, $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 * @param string $latency
*/ */
function psm_log_uptime($server_id, $status, $latency) { function psm_log_uptime($server_id, $status, $latency) {
global $db; global $db;
$db->save( $db->save(
PSM_DB_PREFIX.'servers_uptime', PSM_DB_PREFIX.'servers_uptime',
array( array(
'server_id' => $server_id, 'server_id' => $server_id,
'date' => date('Y-m-d H:i:s'), 'date' => date('Y-m-d H:i:s'),
'status' => $status, 'status' => $status,
'latency' => $latency, 'latency' => $latency,
) )
); );
} }
/** /**
@ -608,6 +630,9 @@ function psm_no_cache() {
*/ */
function psm_password_encrypt($password) function psm_password_encrypt($password)
{ {
if(empty($password))
return '';
$key = psm_get_conf('password_encrypt_key'); $key = psm_get_conf('password_encrypt_key');
$iv = mcrypt_create_iv( $iv = mcrypt_create_iv(
@ -619,7 +644,7 @@ function psm_password_encrypt($password)
$iv . $iv .
mcrypt_encrypt( mcrypt_encrypt(
MCRYPT_RIJNDAEL_128, MCRYPT_RIJNDAEL_128,
hash('sha256', $key, true), hash('sha256', $key, true),
$password, $password,
MCRYPT_MODE_CBC, MCRYPT_MODE_CBC,
$iv $iv
@ -638,6 +663,9 @@ function psm_password_encrypt($password)
*/ */
function psm_password_decrypt($encryptedString) function psm_password_decrypt($encryptedString)
{ {
if(empty($encryptedString))
return '';
$key = psm_get_conf('password_encrypt_key'); $key = psm_get_conf('password_encrypt_key');
$data = base64_decode($encryptedString); $data = base64_decode($encryptedString);
@ -646,7 +674,7 @@ function psm_password_decrypt($encryptedString)
$decrypted = rtrim( $decrypted = rtrim(
mcrypt_decrypt( mcrypt_decrypt(
MCRYPT_RIJNDAEL_128, MCRYPT_RIJNDAEL_128,
hash('sha256', $key, true), hash('sha256', $key, true),
substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)), substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)),
MCRYPT_MODE_CBC, MCRYPT_MODE_CBC,
$iv $iv

View File

@ -125,7 +125,7 @@ $sm_lang = array(
'website_username' => 'Username', 'website_username' => 'Username',
'website_username_description' => 'Username to access the site. (Only Apache authentication is supported.)', 'website_username_description' => 'Username to access the site. (Only Apache authentication is supported.)',
'website_password' => 'Password', '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_monitoring' => 'Monitoring',
'fieldset_permissions' => 'Permissions', 'fieldset_permissions' => 'Permissions',
'port' => 'Port', 'port' => 'Port',

View File

@ -200,7 +200,7 @@ class ServerController extends AbstractServerController {
'edit_value_pattern' => $edit_server['pattern'], 'edit_value_pattern' => $edit_server['pattern'],
'edit_value_warning_threshold' => $edit_server['warning_threshold'], 'edit_value_warning_threshold' => $edit_server['warning_threshold'],
'edit_website_username' => $edit_server['website_username'], '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_type_selected_' . $edit_server['type'] => 'selected="selected"',
'edit_active_selected_' . $edit_server['active'] => 'selected="selected"', 'edit_active_selected_' . $edit_server['active'] => 'selected="selected"',
'edit_email_selected_' . $edit_server['email'] => '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 // dont process anything if no data has been posted
return $this->executeIndex(); 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( $clean = array(
'label' => trim(strip_tags(psm_POST('label', ''))), 'label' => trim(strip_tags(psm_POST('label', ''))),
'ip' => trim(strip_tags(psm_POST('ip', ''))), 'ip' => trim(strip_tags(psm_POST('ip', ''))),
'timeout' => (isset($_POST['timeout']) && intval($_POST['timeout']) > 0) ? intval($_POST['timeout']) : null, 'timeout' => (isset($_POST['timeout']) && intval($_POST['timeout']) > 0) ? intval($_POST['timeout']) : null,
'website_username' => psm_POST('website_username', 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)), 'port' => intval(psm_POST('port', 0)),
'type' => psm_POST('type', ''), 'type' => psm_POST('type', ''),
'pattern' => psm_POST('pattern', ''), 'pattern' => psm_POST('pattern', ''),

View File

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

View File

@ -88,7 +88,7 @@
<div class="control-group types typeWebsite"> <div class="control-group types typeWebsite">
<label class="control-label" for="website_password">{{ label_website_password }}</label> <label class="control-label" for="website_password">{{ label_website_password }}</label>
<div class="controls"> <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>
</div> </div>
</fieldset> </fieldset>

View File

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

View File

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