diff --git a/bin/v-add-user b/bin/v-add-user index bc3cde653..b8696c55e 100755 --- a/bin/v-add-user +++ b/bin/v-add-user @@ -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 diff --git a/bin/v-change-sys-language b/bin/v-change-sys-language new file mode 100755 index 000000000..5512a6a2f --- /dev/null +++ b/bin/v-change-sys-language @@ -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 diff --git a/bin/v-change-user-language b/bin/v-change-user-language new file mode 100755 index 000000000..36891419c --- /dev/null +++ b/bin/v-change-user-language @@ -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 diff --git a/bin/v-change-user-package b/bin/v-change-user-package index 40761ba80..1849abfa5 100755 --- a/bin/v-change-user-package +++ b/bin/v-change-user-package @@ -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 } diff --git a/bin/v-list-sys-languages b/bin/v-list-sys-languages new file mode 100755 index 000000000..685bafc3f --- /dev/null +++ b/bin/v-list-sys-languages @@ -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 diff --git a/bin/v-list-user b/bin/v-list-user index d4d798d6c..b8decbc65 100755 --- a/bin/v-list-user +++ b/bin/v-list-user @@ -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 diff --git a/bin/v-list-users b/bin/v-list-users index a2d276911..7944f9fe1 100755 --- a/bin/v-list-users +++ b/bin/v-list-users @@ -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 diff --git a/func/main.sh b/func/main.sh index c5222d1b0..b7335418a 100644 --- a/func/main.sh +++ b/func/main.sh @@ -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 ;; diff --git a/web/add/user/index.php b/web/add/user/index.php index 34e5e7670..48d8f9e91 100644 --- a/web/add/user/index.php +++ b/web/add/user/index.php @@ -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']); diff --git a/web/edit/user/index.php b/web/edit/user/index.php index c0f696761..5efacdad2 100644 --- a/web/edit/user/index.php +++ b/web/edit/user/index.php @@ -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('
', $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('
', $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']); diff --git a/web/error/index.html b/web/error/index.html index 710a5fce8..522b81967 100644 --- a/web/error/index.html +++ b/web/error/index.html @@ -1,8 +1,8 @@ - <?php print _('505');?> + 505 — internal error - +