diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 45786561..67381113 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -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 diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 54440b82..23a3f4ac 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -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', diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index a22838f3..20d82fbd 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -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', ''), diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 82ace432..41683aef 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -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'), diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index 9b416694..7af848a4 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -88,7 +88,7 @@
- +
diff --git a/src/templates/default/module/server/server/view.tpl.html b/src/templates/default/module/server/server/view.tpl.html index a2a4e27b..17dad262 100644 --- a/src/templates/default/module/server/server/view.tpl.html +++ b/src/templates/default/module/server/server/view.tpl.html @@ -79,7 +79,11 @@ {{ label_website_password }}: - ****** + + {% if (website_password is not empty) %} + ****** + {% endif %} + {% if has_admin_actions %} diff --git a/static/css/style.css b/static/css/style.css index 37ebf4bc..c306cb96 100755 --- a/static/css/style.css +++ b/static/css/style.css @@ -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%;