Explorar o código

Changes due to dependency of old system.

Minor bug in /web/add/user/index.php as we can't translate emaill in "user" language instead of admin
Jaap Marcus %!s(int64=5) %!d(string=hai) anos
pai
achega
b401c4ca43

+ 1 - 1
bin/v-change-sys-language

@@ -19,7 +19,7 @@ source $HESTIA/conf/hestia.conf
 
 
 
 
 is_language_valid() {
 is_language_valid() {
-    if [ ! -e "$HESTIA/web/inc/i18n/$language.php" ]; then
+    if [ ! -d "$HESTIA/web/locale/$language" ]; then
         echo "Error: language file $language doesn't exist"
         echo "Error: language file $language doesn't exist"
         log_event "$E_NOTEXIST $ARGUMENTS"
         log_event "$E_NOTEXIST $ARGUMENTS"
         exit $E_NOTEXIST
         exit $E_NOTEXIST

+ 5 - 5
web/add/user/index.php

@@ -81,17 +81,17 @@ if (!empty($_POST['ok'])) {
     // Send email to the new user
     // Send email to the new user
     if ((empty($_SESSION['error_msg'])) && (!empty($v_notify))) {
     if ((empty($_SESSION['error_msg'])) && (!empty($v_notify))) {
         $to = $_POST['v_notify'];
         $to = $_POST['v_notify'];
-        $subject = _translate($_POST['v_language'],"Welcome to Hestia Control Panel");
+        $subject = _("Welcome to Hestia Control Panel"); //currently not supported to use the account language
         $hostname = exec('hostname');
         $hostname = exec('hostname');
         unset($output);
         unset($output);
-        $from = _translate($_POST['v_language'],'MAIL_FROM',$hostname);
+        $from = _('MAIL_FROM',$hostname); //currently not supported to use the account language
         
         
         if (!empty($_POST['v_name'])) {
         if (!empty($_POST['v_name'])) {
-            $mailtext = _translate($_POST['v_language'],'GREETINGS_GORDON',$_POST['v_name']);
+            $mailtext = _('GREETINGS_GORDON',$_POST['v_name']);
         } else {
         } else {
-            $mailtext = _translate($_POST['v_language'],'GREETINGS');
+            $mailtext = _('GREETINGS');
         }
         }
-        $mailtext .= _translate($_POST['v_language'],'ACCOUNT_READY',$_SERVER['HTTP_HOST'],$_POST['v_username'],$_POST['v_password']);
+        $mailtext .= _($_POST['v_language'],'ACCOUNT_READY',$_SERVER['HTTP_HOST'],$_POST['v_username'],$_POST['v_password']);
         send_email($to, $subject, $mailtext, $from);
         send_email($to, $subject, $mailtext, $from);
     }
     }
 
 

+ 4 - 23
web/inc/i18n.php

@@ -1,42 +1,23 @@
 <?php
 <?php
 // Functions for internationalization
 // Functions for internationalization
 // I18N support information here
 // I18N support information here
-$language = 'nl_NL';
 
 
-putenv("LANGUAGE=$language");
+putenv("LANGUAGE=".$_SESSION['language']);
 setlocale( LC_ALL, 'C.UTF-8' );
 setlocale( LC_ALL, 'C.UTF-8' );
 
 
-$domain = 'messages';
+$domain = 'hestiacp';
 $localedir = '/usr/local/hestia/web/locale';
 $localedir = '/usr/local/hestia/web/locale';
 bindtextdomain($domain, $localedir);
 bindtextdomain($domain, $localedir);
 textdomain($domain);
 textdomain($domain);
 
 
 
 
-
-/**
- * Translates string to given language in first parameter, key given in second parameter (dynamically loads required language). Works like spritf from second parameter
- * @global array $LANG Associative array of language pharses
- * @return string Translated string
- */
-function _translate() {
-
-}
-
-/**
- * Translates string by a given key in first parameter to current session language. Works like sprintf
- * @global array $LANG Associative array of language pharses
- * @return string Translated string
- * @see _translate()
- */
-
-
 /**
 /**
  * Detects user language from Accept-Language HTTP header.
  * Detects user language from Accept-Language HTTP header.
  * @param string Fallback language (default: 'en')
  * @param string Fallback language (default: 'en')
  * @return string Language code (such as 'en' and 'ja')
  * @return string Language code (such as 'en' and 'ja')
  */
  */
-function detect_user_language($fallback='en') {
-
+function detect_user_language($fallback='en_US') {
+    
 }
 }
 
 
 /**
 /**

+ 1 - 2
web/inc/mail-wrapper.php

@@ -23,9 +23,8 @@ $data = json_decode(implode('', $output), true);
 if (!empty( $data['config']['LANGUAGE'])) {
 if (!empty( $data['config']['LANGUAGE'])) {
     $_SESSION['language'] = $data['config']['LANGUAGE'];
     $_SESSION['language'] = $data['config']['LANGUAGE'];
 } else {
 } else {
-    $_SESSION['language'] = 'en';
+    $_SESSION['language'] = 'en_US';
 }
 }
-require_once('/usr/local/hestia/web/inc/i18n/'.$_SESSION['language'].'.php');
 
 
 // Define vars
 // Define vars
 $from = 'Hestia Control Panel <hestia@'.gethostname().'>';
 $from = 'Hestia Control Panel <hestia@'.gethostname().'>';

+ 3 - 26
web/inc/main.php

@@ -8,9 +8,6 @@ define('DEFAULT_PHP_VERSION', "php-" . exec('php -r "echo (float)phpversion();"'
 
 
 $i = 0;
 $i = 0;
 
 
-require_once(dirname(__FILE__).'/i18n.php');
-
-
 // Saving user IPs to the session for preventing session hijacking
 // Saving user IPs to the session for preventing session hijacking
 $user_combined_ip = $_SERVER['REMOTE_ADDR'];
 $user_combined_ip = $_SERVER['REMOTE_ADDR'];
 
 
@@ -47,6 +44,8 @@ if($_SESSION['user_combined_ip'] != $user_combined_ip && $_SERVER['REMOTE_ADDR']
     header("Location: /login/");
     header("Location: /login/");
     exit;
     exit;
 }
 }
+// Load Hestia Config directly
+    load_hestia_config();
 
 
 // Check system settings
 // Check system settings
 if ((!isset($_SESSION['VERSION'])) && (!defined('NO_AUTH_REQUIRED'))) {
 if ((!isset($_SESSION['VERSION'])) && (!defined('NO_AUTH_REQUIRED'))) {
@@ -72,37 +71,15 @@ if (isset($_SESSION['user'])) {
     }
     }
 }
 }
 
 
-if (isset($_SESSION['language'])) {
-    switch ($_SESSION['language']) {
-        case 'ro':
-            setlocale(LC_ALL, 'ro_RO.utf8');
-            break;
-        case 'ru':
-            setlocale(LC_ALL, 'ru_RU.utf8');
-            break;
-        case 'ua':
-            setlocale(LC_ALL, 'uk_UA.utf8');
-            break;
-        case 'es':
-            setlocale(LC_ALL, 'es_ES.utf8');
-            break;
-        case 'ja':
-            setlocale(LC_ALL, 'ja_JP.utf8');
-            break;
-        default:
-            setlocale(LC_ALL, 'en_US.utf8');
-    }
-}
-
 if (isset($_SESSION['user'])) {
 if (isset($_SESSION['user'])) {
     $user = $_SESSION['user'];
     $user = $_SESSION['user'];
-    load_hestia_config();
 }
 }
 
 
 if (isset($_SESSION['look']) && ( $_SESSION['look'] != 'admin' )) {
 if (isset($_SESSION['look']) && ( $_SESSION['look'] != 'admin' )) {
     $user = $_SESSION['look'];
     $user = $_SESSION['look'];
 }
 }
 
 
+require_once(dirname(__FILE__).'/i18n.php');
 
 
 function check_error($return_var) {
 function check_error($return_var) {
     if ( $return_var > 0 ) {
     if ( $return_var > 0 ) {

+ 0 - 4
web/js/i18n.js.php

@@ -3,10 +3,6 @@ header("Content-Type: text/javascript");
 session_start();
 session_start();
 
 
 require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n.php');
 require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n.php');
-
-if (empty($_SESSION['language'])) {
-    //$_SESSION['language'] = detect_user_language();
-}
 ?>
 ?>
 
 
 App.i18n.ARE_YOU_SURE                           = '<?=_('Are you sure?')?>';
 App.i18n.ARE_YOU_SURE                           = '<?=_('Are you sure?')?>';

+ 2 - 2
web/login/index.php

@@ -170,13 +170,13 @@ if (empty($_SESSION['language'])) {
         $_SESSION['language'] = $lang;
         $_SESSION['language'] = $lang;
     }
     }
     else {
     else {
-        $_SESSION['language'] = 'en';
+        $_SESSION['language'] = 'en_US';
     }
     }
 }
 }
 
 
 // Generate CSRF token
 // Generate CSRF token
 $_SESSION['token'] = md5(uniqid(mt_rand(), true));
 $_SESSION['token'] = md5(uniqid(mt_rand(), true));
-require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$_SESSION['language'].'.php');
+
 require_once('../templates/header.html');
 require_once('../templates/header.html');
 if (empty($_POST['user'])) {
 if (empty($_POST['user'])) {
     require_once('../templates/login.html');
     require_once('../templates/login.html');

+ 0 - 3
web/reset/index.php

@@ -94,9 +94,6 @@ if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['pass
     }
     }
 }
 }
 
 
-// Detect language
-if (empty($_SESSION['language'])) $_SESSION['language'] = detect_user_language();
-
 if (empty($_GET['action'])) {
 if (empty($_GET['action'])) {
     require_once '../templates/header.html';
     require_once '../templates/header.html';
     require_once '../templates/reset_1.html';
     require_once '../templates/reset_1.html';

+ 0 - 4
web/reset2fa/index.php

@@ -10,10 +10,6 @@ if (isset($_SESSION['user'])) {
 // Main include
 // Main include
 include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
 include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
 
 
-// Detect language
-if (empty($_SESSION['language'])){ 
-    $_SESSION['language'] = detect_user_language();
-}
 //Check values
 //Check values
 if(!empty($_POST['user']) && !empty($_POST['twofa'])){
 if(!empty($_POST['user']) && !empty($_POST['twofa'])){
     $error = true;
     $error = true;