i18n backend support

This commit is contained in:
Serghey Rodin 2013-01-24 12:49:22 +02:00
parent 003036434c
commit def0f35141
19 changed files with 347 additions and 23 deletions

View file

@ -202,6 +202,7 @@ U_MAIL_ACCOUNTS='0'
U_DATABASES='0'
U_CRON_JOBS='0'
U_BACKUPS='0'
LANGUAGE=''
TIME='$TIME'
DATE='$DATE'" > $USER_DATA/user.conf
chmod 660 $USER_DATA/user.conf

57
bin/v-change-sys-language Executable file
View file

@ -0,0 +1,57 @@
#!/bin/bash
# info: change sys language
# options: LANGUAGE
#
# The function for changing system language.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
language=$1
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
is_language_valid() {
if [ ! -e "$VESTA/web/inc/i18n/$language.php" ]; then
echo "Error: language $language not exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'LANGUAGE'
validate_format 'language'
is_language_valid $language
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Change language
if [ -z "$(grep LANGUAGE $VESTA/conf/vesta.conf)" ]; then
echo "LANGUAGE='$language'" >> $VESTA/conf/vesta.conf
else
sed -i "s/LANGUAGE=.*/LANGUAGE='$language'/g" $VESTA/conf/vesta.conf
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

71
bin/v-change-user-language Executable file
View file

@ -0,0 +1,71 @@
#!/bin/bash
# info: change user language
# options: USER LANGUAGE
#
# The function for changing language.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
language=$2
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
is_language_valid() {
if [ ! -e "$VESTA/web/inc/i18n/$language.php" ]; then
echo "Error: language $language not exist"
log_event "$E_NOTEXIST $EVENT"
exit $E_NOTEXIST
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER LANGUAGE'
validate_format 'user' 'language'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_language_valid $language
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Change language
if [ -z "$(grep LANGUAGE $USER_DATA/user.conf)" ]; then
echo "adding LANG"
sed -i "s/^TIME/LANGUAGE='$language'\nTIME/g" $USER_DATA/user.conf
else
update_user_value "$user" '$LANGUAGE' "$language"
echo "changinx LANG"
fi
exit
# Changing user contact email
old_email=$(get_user_value '$CONTACT')
update_user_value "$user" '$CONTACT' "$email"
pw_str=$(grep -n "^$user:" /etc/passwd)
str=$(echo "$pw_str" | cut -f 1 -d :)
sed -i "$str s/$old_email/$email/g" /etc/passwd
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "changed contact email to $email"
log_event "$OK" "$EVENT"
exit

View file

@ -107,6 +107,7 @@ U_MAIL_ACCOUNTS='$U_MAIL_ACCOUNTS'
U_DATABASES='$U_DATABASES'
U_CRON_JOBS='$U_CRON_JOBS'
U_BACKUPS='$U_BACKUPS'
LANGUAGE='$LANGUAGE'
TIME='$TIME'
DATE='$DATE'" > $USER_DATA/user.conf
}

67
bin/v-list-sys-languages Executable file
View file

@ -0,0 +1,67 @@
#!/bin/bash
# info: list system users
# options: [FORMAT]
#
# The function for obtaining the list of system users without
# detailed information.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
format=${1-shell}
# Includes
source $VESTA/func/main.sh
# Json function
json_list_lang() {
int_counter=$(echo "$languages" | wc -l)
i=1
echo '['
for lang in $languages; do
if [ "$i" -lt "$int_counter" ]; then
echo -e "\t\"$lang\","
else
echo -e "\t\"$lang\""
fi
(( ++i))
done
echo "]"
}
# Shell function
shell_list_lang() {
if [ -z "$nohead" ]; then
echo "LANGUAGES"
echo "----------"
fi
for lang in $languages; do
echo "$lang"
done
}
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Check languages
languages=$(ls $VESTA/web/inc/i18n/|cut -f 1 -d .)
# Listing domains
case $format in
json) json_list_lang ;;
plain) nohead=1; shell_list_lang ;;
shell) shell_list_lang ;;
*) check_args '1' '0' '[FORMAT]' ;;
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -80,7 +80,7 @@ fields='$USER $FNAME $LNAME $PACKAGE $TEMPLATE $WEB_DOMAINS $WEB_ALIASES
$IP_OWNED $U_USERS $U_DISK $U_DISK_DIRS $U_DISK_WEB $U_DISK_MAIL $U_DISK_DB
$U_BANDWIDTH $U_WEB_DOMAINS $U_WEB_SSL $U_WEB_ALIASES $U_DNS_DOMAINS
$U_DNS_RECORDS $U_MAIL_DOMAINS $U_MAIL_DKIM $U_MAIL_ACCOUNTS $U_DATABASES
$U_CRON_JOBS $U_BACKUPS $TIME $DATE'
$U_CRON_JOBS $U_BACKUPS $LANGUAGE $TIME $DATE'
# Listing user
case $format in

View file

@ -84,7 +84,8 @@ fields="$fields \$U_USERS \$U_DISK \$U_DISK_DIRS \$U_DISK_WEB \$U_DISK_MAIL"
fields="$fields \$U_DISK_DB \$U_BANDWIDTH \$U_WEB_DOMAINS \$U_WEB_SSL"
fields="$fields \$U_WEB_ALIASES \$U_DNS_DOMAINS \$U_DNS_RECORDS"
fields="$fields \$U_MAIL_DOMAINS \$U_MAIL_DKIM \$U_MAIL_ACCOUNTS"
fields="$fields \$U_DATABASES \$U_CRON_JOBS \$U_BACKUPS \$TIME \$DATE"
fields="$fields \$U_DATABASES \$U_CRON_JOBS \$U_BACKUPS \$LANGUAGE"
fields="$fields \$TIME \$DATE"
# Listing domains
case $format in

View file

@ -554,9 +554,18 @@ validate_format_email() {
fi
}
# Name
validate_format_name() {
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
echo "Error: $2 $1 is not valid"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi
}
# Username
validate_format_username() {
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
if ! [[ "$1" =~ ^[a-zA-Z0-9]+([\.|_|-][a-zA-Z0-9]+)?$ ]]; then
echo "Error: $2 $1 is not valid"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
@ -710,7 +719,7 @@ validate_format(){
antivirus) validate_format_boolean "$arg" 'antivirus' ;;
autoreply) validate_format_autoreply "$arg" ;;
backup) validate_format_date "$arg" ;;
charset) validate_format_username "$arg" "$arg_name" ;;
charset) validate_format_name "$arg" "$arg_name" ;;
charsets) validate_format_common "$arg" 'charsets' ;;
database) validate_format_database "$arg" 'database';;
day) validate_format_mhdmw "$arg" $arg_name ;;
@ -724,7 +733,7 @@ validate_format(){
email) validate_format_email "$arg" ;;
exp) validate_format_date "$arg" ;;
extentions) validate_format_common "$arg" 'extentions' ;;
fname) validate_format_username "$arg" "$arg_name" ;;
fname) validate_format_name "$arg" "$arg_name" ;;
forward) validate_format_email "$arg" ;;
ftp_password) validate_format_password "$arg" ;;
ftp_user) validate_format_username "$arg" "$arg_name" ;;
@ -737,7 +746,7 @@ validate_format(){
ip_status) validate_format_ip_status "$arg" ;;
job) validate_format_int "$arg" ;;
key) validate_format_username "$arg" "$arg_name" ;;
lname) validate_format_username "$arg" "$arg_name" ;;
lname) validate_format_name "$arg" "$arg_name" ;;
malias) validate_format_username "$arg" "$arg_name" ;;
mask) validate_format_ip "$arg" ;;
max_db) validate_format_int "$arg" ;;
@ -747,7 +756,7 @@ validate_format(){
ns2) validate_format_domain "$arg" ;;
ns3) validate_format_domain "$arg" ;;
ns4) validate_format_domain "$arg" ;;
package) validate_format_username "$arg" "$arg_name" ;;
package) validate_format_name "$arg" "$arg_name" ;;
password) validate_format_password "$arg" ;;
port) validate_format_int "$arg" ;;
quota) validate_format_int "$arg" ;;
@ -758,7 +767,7 @@ validate_format(){
soa) validate_format_domain "$arg" ;;
stats_pass) validate_format_password "$arg" ;;
stats_user) validate_format_username "$arg" "$arg_name" ;;
template) validate_format_username "$arg" "$arg_name" ;;
template) validate_format_name "$arg" "$arg_name" ;;
ttl) validate_format_int "$arg" ;;
user) validate_format_username "$arg" "$arg_name" ;;
wday) validate_format_mhdmw "$arg" $arg_name ;;

View file

@ -30,8 +30,9 @@ if ($_SESSION['user'] == 'admin') {
// Protect input
$v_username = escapeshellarg($_POST['v_username']);
$v_password = escapeshellarg($_POST['v_password']);
$v_package = escapeshellarg($_POST['v_package']);
$v_email = escapeshellarg($_POST['v_email']);
$v_package = escapeshellarg($_POST['v_package']);
$v_language = escapeshellarg($_POST['v_language']);
$v_fname = escapeshellarg($_POST['v_fname']);
$v_lname = escapeshellarg($_POST['v_lname']);
$v_notify = $_POST['v_notify'];
@ -60,6 +61,7 @@ if ($_SESSION['user'] == 'admin') {
if (empty($error)) $error = _('Error: vesta did not return any output.');
$_SESSION['error_msg'] = $error;
} else {
exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
if (!empty($v_notify)) {
$to = $_POST['v_notify'];
$subject = _("Welcome to Vesta Control Panel");
@ -91,6 +93,10 @@ if ($_SESSION['user'] == 'admin') {
$data = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
$languages = json_decode(implode('', $output), true);
unset($output);
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_user.html');
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);

View file

@ -40,6 +40,7 @@ if ($_SESSION['user'] == 'admin') {
$v_email = $data[$v_username]['CONTACT'];
$v_template = $data[$v_username]['TEMPLATE'];
$v_package = $data[$v_username]['PACKAGE'];
$v_language = $data[$v_username]['LANGUAGE'];
$v_fname = $data[$v_username]['FNAME'];
$v_lname = $data[$v_username]['LNAME'];
$v_shell = $data[$v_username]['SHELL'];
@ -62,6 +63,10 @@ if ($_SESSION['user'] == 'admin') {
$packages = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
$languages = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-web-templates json", $output, $return_var);
$templates = json_decode(implode('', $output), true);
unset($output);
@ -100,6 +105,18 @@ if ($_SESSION['user'] == 'admin') {
unset($output);
}
// Change language
if (($v_language != $_POST['v_language']) && (empty($_SESSION['error_msg']))) {
$v_language = escapeshellarg($_POST['v_language']);
exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
if ($return_var != 0) {
$error = implode('<br>', $output);
if (empty($error)) $error = _('Error: vesta did not return any output.');
$_SESSION['error_msg'] = $error;
}
unset($output);
}
// Change template
if (($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
$v_template = escapeshellarg($_POST['v_template']);
@ -201,6 +218,7 @@ if ($_SESSION['user'] == 'admin') {
$v_email = $data[$v_username]['CONTACT'];
$v_fname = $data[$v_username]['FNAME'];
$v_lname = $data[$v_username]['LNAME'];
$v_language = $data[$v_username]['LANGUAGE'];
$v_ns = $data[$v_username]['NS'];
$nameservers = explode(", ", $v_ns);
$v_ns1 = $nameservers[0];
@ -216,6 +234,10 @@ if ($_SESSION['user'] == 'admin') {
$v_time = $data[$v_username]['TIME'];
$v_date = $data[$v_username]['DATE'];
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
$languages = json_decode(implode('', $output), true);
unset($output);
}
// Action
@ -235,6 +257,18 @@ if ($_SESSION['user'] == 'admin') {
unset($output);
}
// Change language
if (($v_language != $_POST['v_language']) && (empty($_SESSION['error_msg']))) {
$v_language = escapeshellarg($_POST['v_language']);
exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
if ($return_var != 0) {
$error = implode('<br>', $output);
if (empty($error)) $error = _('Error: vesta did not return any output.');
$_SESSION['error_msg'] = $error;
}
unset($output);
}
// Change contact email
if (($v_email != $_POST['v_email']) && (empty($_SESSION['error_msg']))) {
$v_email = escapeshellarg($_POST['v_email']);

View file

@ -1,8 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<title><?php print _('505');?></title>
<title>505 &mdash; internal error</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="description" content="<?php print _('505');?>"/>
<meta name="description" content="internal error"/>
<style type="text/css">
body {font-size:14px; color:#777777; font-family:arial; text-align:center; background: black;}
h1 {font-size:180px; color:#99A7AF; margin: 70px 0 0 0;}
@ -17,10 +17,10 @@
</head>
<body>
<h2><?php print _('An internal error occurred');?></h2>
<h2>Internal vesta error</h2>
<img src="/error/vesta.jpg">
<div>
<?php print _('GO_BACK_LINK');?>
Try start again from <a href="/">home page</a> or go back to <a href="javascript:%20history.go(-1)">previous page</a>
</div>
</body>
</html>

View file

@ -219,7 +219,7 @@ $LANG = array(
'First Name' => 'First Name',
'Last Name' => 'Last Name',
'SEND_CREDENTIALS_NOTICE' => 'Send login credentials to',
'SEND_FTP_CREDENTIALS' => 'Send FTP credentials to'
'SEND_FTP_CREDENTIALS' => 'Send FTP credentials to',
'Adding Web Domain' => 'Adding Web Domain',
'Apache template' => 'Apache template',
'Nginx Support' => 'Nginx Support',

View file

@ -361,7 +361,9 @@ $LANG = array(
'shared' => 'общий',
'dedicated' => 'выделенный',
'Domains' => 'Домены',
'IP address' => 'IP адрес'
'IP address' => 'IP адрес',
'Welcome' => 'Добро пожаловать',
'Language' => 'Язык'
);
/*error_reporting(E_ALL);

View file

@ -5,7 +5,6 @@ define('LANGUAGE','ru');
require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.LANGUAGE.'.php');
// works like sprintf if more than one arguments called
function _() {
global $LANG;

View file

@ -1,8 +1,8 @@
<?php
session_start();
define('NO_AUTH_REQUIRED',true);
define('NO_LANG', true);
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
@ -12,6 +12,15 @@ if (isset($_GET['logout'])) {
$TAB = 'LOGIN';
exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
if ($return_var != 0) {
header("Location: /error/");
exit;
}
$data = json_decode(implode('', $output), true);
unset($output);
//$LANGUAGE = $data['config']['LANGUAGE'];
if (isset($_SESSION['user'])) {
if ($_SESSION['user'] == 'admin' && !empty($_GET['loginas'])) {
if ($_GET['loginas'] == 'admin') {

View file

@ -112,6 +112,27 @@
</select>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;" >
<?php print _('Language');?>
</td>
</tr>
<tr>
<td>
<select class="vst-list" name="v_language">
<?php
foreach ($languages as $key => $value) {
echo "\n\t\t\t\t\t\t\t\t\t<option value=\"".$value."\"";
$svalue = "'".$value."'";
if (( $value == $v_language ) || ( $svalue == $v_language)){
echo 'selected' ;
}
echo ">".$value."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;">
<?php print _('First Name');?>

View file

@ -107,6 +107,27 @@
</select>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;" >
<?php print _('Language');?>
</td>
</tr>
<tr>
<td>
<select class="vst-list" name="v_language">
<?php
foreach ($languages as $key => $value) {
echo "\n\t\t\t\t\t\t\t\t\t<option value=\"".$value."\"";
$svalue = "'".$value."'";
if (( $value == $v_language ) || ( $svalue == $v_language)){
echo 'selected' ;
}
echo ">".$value."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;">
<?php print _('First Name');?>

View file

@ -112,12 +112,12 @@
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
},
}
});
});
</script>
<div id="dialog-message" title="Wellcome">
<div id="dialog-message" title="<?php print _('Welcome') ?>">
<p><?php print _('LOGGED_IN_AS',$key);?></p>
</div>
<?php

View file

@ -45,7 +45,7 @@
<table class="data-col1">
<tr><td style="padding: 24px 0 2px 4px;"><a class="data-date" ?><?php echo strftime("%d %b %Y", strtotime($v_date))?></a></td></tr>
<tr><td style="padding: 0 0 6px 4px;"><a class="data-date" ?><?php echo $v_time?></a></td></tr>
<tr><td style="padding: 0 0 0 21px;" class="data-<?php echo $v_status ?>"><b><?php echo $v_status ?></b></td></tr>
<tr><td style="padding: 0 0 0 21px;" class="data-<?php echo $v_status ?>"><b><?php echo _($v_status) ?></b></td></tr>
</table>
</td>
<td class="data-dotted" width="830px" style="vertical-align:top;">
@ -85,6 +85,27 @@
<input type="text" size="20" class="vst-input" name="v_email" <?php if (!empty($v_email)) echo "value=".$v_email; ?>>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;" >
<?php print _('Language');?>
</td>
</tr>
<tr>
<td>
<select class="vst-list" name="v_language">
<?php
foreach ($languages as $key => $value) {
echo "\n\t\t\t\t\t\t\t\t\t<option value=\"".$value."\"";
$svalue = "'".$value."'";
if (( $value == $v_language ) || ( $svalue == $v_language)){
echo 'selected' ;
}
echo ">".$value."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td class="vst-text" style="padding: 10px 0 0 2px;">
<?php print _('Default Name Servers');?>
@ -110,9 +131,13 @@
<input type="text" size="20" class="vst-input" name="v_ns4" <?php if (!empty($v_ns4)) echo "value=".$v_ns4; ?>>
</td>
</tr>
</table>
<table class="data-col2">
<tr>
<td style="padding: 24px 0 0 0;">
<td style="padding: 24px 0 0 0;" width="116px">
<input type="submit" class="button" name="save" value="<?php print _('Save');?>">
</td>
<td style="padding: 24px 0 0 0;">
<input type="button" class="button" value="<?php print _('Back');?>" onclick="<?php echo $back ?>">
</td>
</tr>