Skip to content

Commit def0f35

Browse files
committed
i18n backend support
1 parent 0030364 commit def0f35

File tree

19 files changed

+347
-23
lines changed

19 files changed

+347
-23
lines changed

bin/v-add-user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ U_MAIL_ACCOUNTS='0'
202202
U_DATABASES='0'
203203
U_CRON_JOBS='0'
204204
U_BACKUPS='0'
205+
LANGUAGE=''
205206
TIME='$TIME'
206207
DATE='$DATE'" > $USER_DATA/user.conf
207208
chmod 660 $USER_DATA/user.conf

bin/v-change-sys-language

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# info: change sys language
3+
# options: LANGUAGE
4+
#
5+
# The function for changing system language.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
language=$1
14+
15+
# Includes
16+
source $VESTA/conf/vesta.conf
17+
source $VESTA/func/main.sh
18+
19+
20+
is_language_valid() {
21+
if [ ! -e "$VESTA/web/inc/i18n/$language.php" ]; then
22+
echo "Error: language $language not exist"
23+
log_event "$E_NOTEXIST $EVENT"
24+
exit $E_NOTEXIST
25+
fi
26+
}
27+
28+
29+
#----------------------------------------------------------#
30+
# Verifications #
31+
#----------------------------------------------------------#
32+
33+
check_args '1' "$#" 'LANGUAGE'
34+
validate_format 'language'
35+
is_language_valid $language
36+
37+
38+
#----------------------------------------------------------#
39+
# Action #
40+
#----------------------------------------------------------#
41+
42+
# Change language
43+
if [ -z "$(grep LANGUAGE $VESTA/conf/vesta.conf)" ]; then
44+
echo "LANGUAGE='$language'" >> $VESTA/conf/vesta.conf
45+
else
46+
sed -i "s/LANGUAGE=.*/LANGUAGE='$language'/g" $VESTA/conf/vesta.conf
47+
fi
48+
49+
50+
#----------------------------------------------------------#
51+
# Vesta #
52+
#----------------------------------------------------------#
53+
54+
# Logging
55+
log_event "$OK" "$EVENT"
56+
57+
exit

bin/v-change-user-language

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# info: change user language
3+
# options: USER LANGUAGE
4+
#
5+
# The function for changing language.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
language=$2
15+
16+
# Includes
17+
source $VESTA/conf/vesta.conf
18+
source $VESTA/func/main.sh
19+
20+
21+
is_language_valid() {
22+
if [ ! -e "$VESTA/web/inc/i18n/$language.php" ]; then
23+
echo "Error: language $language not exist"
24+
log_event "$E_NOTEXIST $EVENT"
25+
exit $E_NOTEXIST
26+
fi
27+
}
28+
29+
30+
#----------------------------------------------------------#
31+
# Verifications #
32+
#----------------------------------------------------------#
33+
34+
check_args '2' "$#" 'USER LANGUAGE'
35+
validate_format 'user' 'language'
36+
is_object_valid 'user' 'USER' "$user"
37+
is_object_unsuspended 'user' 'USER' "$user"
38+
is_language_valid $language
39+
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
45+
# Change language
46+
if [ -z "$(grep LANGUAGE $USER_DATA/user.conf)" ]; then
47+
echo "adding LANG"
48+
sed -i "s/^TIME/LANGUAGE='$language'\nTIME/g" $USER_DATA/user.conf
49+
else
50+
update_user_value "$user" '$LANGUAGE' "$language"
51+
echo "changinx LANG"
52+
fi
53+
54+
exit
55+
# Changing user contact email
56+
old_email=$(get_user_value '$CONTACT')
57+
update_user_value "$user" '$CONTACT' "$email"
58+
pw_str=$(grep -n "^$user:" /etc/passwd)
59+
str=$(echo "$pw_str" | cut -f 1 -d :)
60+
sed -i "$str s/$old_email/$email/g" /etc/passwd
61+
62+
63+
#----------------------------------------------------------#
64+
# Vesta #
65+
#----------------------------------------------------------#
66+
67+
# Logging
68+
log_history "changed contact email to $email"
69+
log_event "$OK" "$EVENT"
70+
71+
exit

bin/v-change-user-package

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ U_MAIL_ACCOUNTS='$U_MAIL_ACCOUNTS'
107107
U_DATABASES='$U_DATABASES'
108108
U_CRON_JOBS='$U_CRON_JOBS'
109109
U_BACKUPS='$U_BACKUPS'
110+
LANGUAGE='$LANGUAGE'
110111
TIME='$TIME'
111112
DATE='$DATE'" > $USER_DATA/user.conf
112113
}

bin/v-list-sys-languages

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
# info: list system users
3+
# options: [FORMAT]
4+
#
5+
# The function for obtaining the list of system users without
6+
# detailed information.
7+
8+
9+
#----------------------------------------------------------#
10+
# Variable&Function #
11+
#----------------------------------------------------------#
12+
13+
# Argument defenition
14+
format=${1-shell}
15+
16+
# Includes
17+
source $VESTA/func/main.sh
18+
19+
# Json function
20+
json_list_lang() {
21+
int_counter=$(echo "$languages" | wc -l)
22+
i=1
23+
echo '['
24+
for lang in $languages; do
25+
if [ "$i" -lt "$int_counter" ]; then
26+
echo -e "\t\"$lang\","
27+
else
28+
echo -e "\t\"$lang\""
29+
fi
30+
(( ++i))
31+
done
32+
echo "]"
33+
}
34+
35+
# Shell function
36+
shell_list_lang() {
37+
if [ -z "$nohead" ]; then
38+
echo "LANGUAGES"
39+
echo "----------"
40+
fi
41+
for lang in $languages; do
42+
echo "$lang"
43+
done
44+
}
45+
46+
47+
#----------------------------------------------------------#
48+
# Action #
49+
#----------------------------------------------------------#
50+
51+
# Check languages
52+
languages=$(ls $VESTA/web/inc/i18n/|cut -f 1 -d .)
53+
54+
# Listing domains
55+
case $format in
56+
json) json_list_lang ;;
57+
plain) nohead=1; shell_list_lang ;;
58+
shell) shell_list_lang ;;
59+
*) check_args '1' '0' '[FORMAT]' ;;
60+
esac
61+
62+
63+
#----------------------------------------------------------#
64+
# Vesta #
65+
#----------------------------------------------------------#
66+
67+
exit

bin/v-list-user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fields='$USER $FNAME $LNAME $PACKAGE $TEMPLATE $WEB_DOMAINS $WEB_ALIASES
8080
$IP_OWNED $U_USERS $U_DISK $U_DISK_DIRS $U_DISK_WEB $U_DISK_MAIL $U_DISK_DB
8181
$U_BANDWIDTH $U_WEB_DOMAINS $U_WEB_SSL $U_WEB_ALIASES $U_DNS_DOMAINS
8282
$U_DNS_RECORDS $U_MAIL_DOMAINS $U_MAIL_DKIM $U_MAIL_ACCOUNTS $U_DATABASES
83-
$U_CRON_JOBS $U_BACKUPS $TIME $DATE'
83+
$U_CRON_JOBS $U_BACKUPS $LANGUAGE $TIME $DATE'
8484

8585
# Listing user
8686
case $format in

bin/v-list-users

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ fields="$fields \$U_USERS \$U_DISK \$U_DISK_DIRS \$U_DISK_WEB \$U_DISK_MAIL"
8484
fields="$fields \$U_DISK_DB \$U_BANDWIDTH \$U_WEB_DOMAINS \$U_WEB_SSL"
8585
fields="$fields \$U_WEB_ALIASES \$U_DNS_DOMAINS \$U_DNS_RECORDS"
8686
fields="$fields \$U_MAIL_DOMAINS \$U_MAIL_DKIM \$U_MAIL_ACCOUNTS"
87-
fields="$fields \$U_DATABASES \$U_CRON_JOBS \$U_BACKUPS \$TIME \$DATE"
87+
fields="$fields \$U_DATABASES \$U_CRON_JOBS \$U_BACKUPS \$LANGUAGE"
88+
fields="$fields \$TIME \$DATE"
8889

8990
# Listing domains
9091
case $format in

func/main.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,18 @@ validate_format_email() {
554554
fi
555555
}
556556

557+
# Name
558+
validate_format_name() {
559+
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
560+
echo "Error: $2 $1 is not valid"
561+
log_event "$E_INVALID" "$EVENT"
562+
exit $E_INVALID
563+
fi
564+
}
565+
557566
# Username
558567
validate_format_username() {
559-
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
568+
if ! [[ "$1" =~ ^[a-zA-Z0-9]+([\.|_|-][a-zA-Z0-9]+)?$ ]]; then
560569
echo "Error: $2 $1 is not valid"
561570
log_event "$E_INVALID" "$EVENT"
562571
exit $E_INVALID
@@ -710,7 +719,7 @@ validate_format(){
710719
antivirus) validate_format_boolean "$arg" 'antivirus' ;;
711720
autoreply) validate_format_autoreply "$arg" ;;
712721
backup) validate_format_date "$arg" ;;
713-
charset) validate_format_username "$arg" "$arg_name" ;;
722+
charset) validate_format_name "$arg" "$arg_name" ;;
714723
charsets) validate_format_common "$arg" 'charsets' ;;
715724
database) validate_format_database "$arg" 'database';;
716725
day) validate_format_mhdmw "$arg" $arg_name ;;
@@ -724,7 +733,7 @@ validate_format(){
724733
email) validate_format_email "$arg" ;;
725734
exp) validate_format_date "$arg" ;;
726735
extentions) validate_format_common "$arg" 'extentions' ;;
727-
fname) validate_format_username "$arg" "$arg_name" ;;
736+
fname) validate_format_name "$arg" "$arg_name" ;;
728737
forward) validate_format_email "$arg" ;;
729738
ftp_password) validate_format_password "$arg" ;;
730739
ftp_user) validate_format_username "$arg" "$arg_name" ;;
@@ -737,7 +746,7 @@ validate_format(){
737746
ip_status) validate_format_ip_status "$arg" ;;
738747
job) validate_format_int "$arg" ;;
739748
key) validate_format_username "$arg" "$arg_name" ;;
740-
lname) validate_format_username "$arg" "$arg_name" ;;
749+
lname) validate_format_name "$arg" "$arg_name" ;;
741750
malias) validate_format_username "$arg" "$arg_name" ;;
742751
mask) validate_format_ip "$arg" ;;
743752
max_db) validate_format_int "$arg" ;;
@@ -747,7 +756,7 @@ validate_format(){
747756
ns2) validate_format_domain "$arg" ;;
748757
ns3) validate_format_domain "$arg" ;;
749758
ns4) validate_format_domain "$arg" ;;
750-
package) validate_format_username "$arg" "$arg_name" ;;
759+
package) validate_format_name "$arg" "$arg_name" ;;
751760
password) validate_format_password "$arg" ;;
752761
port) validate_format_int "$arg" ;;
753762
quota) validate_format_int "$arg" ;;
@@ -758,7 +767,7 @@ validate_format(){
758767
soa) validate_format_domain "$arg" ;;
759768
stats_pass) validate_format_password "$arg" ;;
760769
stats_user) validate_format_username "$arg" "$arg_name" ;;
761-
template) validate_format_username "$arg" "$arg_name" ;;
770+
template) validate_format_name "$arg" "$arg_name" ;;
762771
ttl) validate_format_int "$arg" ;;
763772
user) validate_format_username "$arg" "$arg_name" ;;
764773
wday) validate_format_mhdmw "$arg" $arg_name ;;

web/add/user/index.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
// Protect input
3131
$v_username = escapeshellarg($_POST['v_username']);
3232
$v_password = escapeshellarg($_POST['v_password']);
33-
$v_package = escapeshellarg($_POST['v_package']);
3433
$v_email = escapeshellarg($_POST['v_email']);
34+
$v_package = escapeshellarg($_POST['v_package']);
35+
$v_language = escapeshellarg($_POST['v_language']);
3536
$v_fname = escapeshellarg($_POST['v_fname']);
3637
$v_lname = escapeshellarg($_POST['v_lname']);
3738
$v_notify = $_POST['v_notify'];
@@ -60,6 +61,7 @@
6061
if (empty($error)) $error = _('Error: vesta did not return any output.');
6162
$_SESSION['error_msg'] = $error;
6263
} else {
64+
exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
6365
if (!empty($v_notify)) {
6466
$to = $_POST['v_notify'];
6567
$subject = _("Welcome to Vesta Control Panel");
@@ -91,6 +93,10 @@
9193
$data = json_decode(implode('', $output), true);
9294
unset($output);
9395

96+
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
97+
$languages = json_decode(implode('', $output), true);
98+
unset($output);
99+
94100
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_user.html');
95101
unset($_SESSION['error_msg']);
96102
unset($_SESSION['ok_msg']);

0 commit comments

Comments
 (0)