diff --git a/bin/v_add_dns_on_web_alias b/bin/v_add_dns_on_web_alias new file mode 100755 index 000000000..b7eff6de5 --- /dev/null +++ b/bin/v_add_dns_on_web_alias @@ -0,0 +1,76 @@ +#!/bin/bash +# info: add dns domain or dns record based on web domain alias +# options: user domain +# +# The function adds dns domain or dns record based on web domain alias. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) +domain_idn=$(idn -t --quiet -a "$domain") + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh +source $VESTA/func/domain.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '2' "$#" 'user domain' +validate_format 'user' 'domain' +is_system_enabled "$WEB_SYSTEM" +is_system_enabled "$DNS_SYSTEM" +is_object_valid 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'web' 'DOMAIN' "$domain" +is_object_unsuspended 'web' 'DOMAIN' "$domain" + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Parsing domain values +get_domain_values 'web' + +OLD_IFS=$IFS +IFS=',' +for web_alias in $ALIAS; do + # Check if parent dns domain exist + sub_domain=$(echo $web_alias | cut -f1 -d .) + pr_domain=$(echo $web_alias | sed -e "s/^$sub_domain.//" ) + check_parent=$(grep "DOMAIN='$pr_domain'" $USER_DATA/dns.conf) + if [ -z "$check_parent" ]; then + check_dom=$(grep "DOMAIN='$web_alias'" $USER_DATA/dns.conf) + if [ -z "$check_dom" ]; then + $BIN/v_add_dns_domain $user $web_alias $IP + fi + else + check_rec=$(grep "RECORD='$sub_domain'" $USER_DATA/dns/$pr_domain.conf) + if [ -z "$check_rec" ]; then + $BIN/v_add_dns_domain_record $user $pr_domain $sub_domain A $IP + fi + fi +done + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Restart web server +$BIN/v_restart_dns "$EVENT" + +# Logging +log_history "$EVENT" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v_add_web_domain b/bin/v_add_web_domain index a80391db4..8cebcce5a 100755 --- a/bin/v_add_web_domain +++ b/bin/v_add_web_domain @@ -1,6 +1,6 @@ #!/bin/bash # info: add web domain -# options: user domain ip [template] +# options: user domain ip [template] [restart] # # The function adds virtual host to a server. In cases when a template is # undefined in the script, the template "default" will be used. The alias of @@ -21,6 +21,7 @@ domain=$(echo $domain | tr '[:upper:]' '[:lower:]') domain_idn=$(idn -t --quiet -a "$domain") ip=$3 template=${4-default} +restart=$5 # Includes source $VESTA/conf/vesta.conf @@ -33,7 +34,7 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'user domain ip [template]' +check_args '3' "$#" 'user domain ip [template] [restart]' validate_format 'user' 'domain' 'ip' 'template' is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -190,7 +191,9 @@ echo "$str" >> $USER_DATA/web.conf chmod 660 $USER_DATA/web.conf # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_add_web_domain_alias b/bin/v_add_web_domain_alias index 9bd5aafe3..9cebb33fd 100755 --- a/bin/v_add_web_domain_alias +++ b/bin/v_add_web_domain_alias @@ -1,6 +1,6 @@ #!/bin/bash # info: add web domain alias -# options: user domain alias +# options: user domain alias [restart] # # The call is intended for adding aliases to a domain (it is also called # "domain parking"). The function supports wildcards *.domain.tpl. @@ -18,6 +18,7 @@ domain_idn=$(idn -t --quiet -a "$domain") dom_alias=$(idn -t --quiet -u "$3" ) dom_alias=$(echo $dom_alias | tr '[:upper:]' '[:lower:]') dom_alias_idn=$(idn -t --quiet -a "$dom_alias" ) +restart="$4" # Includes source $VESTA/conf/vesta.conf @@ -29,7 +30,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'user domain dom_alias' +check_args '3' "$#" 'user domain dom_alias [restart]' validate_format 'user' 'domain' 'dom_alias' is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -98,7 +99,9 @@ update_object_value 'web' 'DOMAIN' "$domain" '$ALIAS' "$ALIAS" increase_user_value "$user" '$U_WEB_ALIASES' # Adding task to the vesta pipe -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi log_history "$EVENT" log_event "$OK" "$EVENT" diff --git a/bin/v_add_web_domain_elog b/bin/v_add_web_domain_elog index bf7858a2b..91d1c1898 100755 --- a/bin/v_add_web_domain_elog +++ b/bin/v_add_web_domain_elog @@ -1,6 +1,6 @@ #!/bin/bash # info: add error logging for domain -# options: user domain +# options: user domain [restart] # # The function enables a separate ErrorLog file for a domain, accessible for # reading by users. @@ -14,6 +14,7 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") +restart="$3" # Includes source $VESTA/conf/vesta.conf @@ -25,14 +26,13 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '2' "$#" 'user domain' +check_args '2' "$#" 'user domain [restart]' validate_format 'user' 'domain' is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" is_object_valid 'web' 'DOMAIN' "$domain" is_object_unsuspended 'web' 'DOMAIN' "$domain" -is_object_value_empty 'web' 'DOMAIN' "$domain" '$ELOG' #----------------------------------------------------------# @@ -41,6 +41,10 @@ is_object_value_empty 'web' 'DOMAIN' "$domain" '$ELOG' # Parsing domain values get_domain_values 'web' +if [ $ELOG == 'yes' ]; then + exit 0 +fi + tpl_file="$WEBTPL/apache_$TPL.tpl" conf="$HOMEDIR/$user/conf/web/httpd.conf" ELOG='yes' @@ -85,7 +89,9 @@ fi update_object_value 'web' 'DOMAIN' "$domain" '$ELOG' 'yes' # Adding task to the vesta pipe -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_add_web_domain_nginx b/bin/v_add_web_domain_nginx index 0f6a85545..296b03b33 100755 --- a/bin/v_add_web_domain_nginx +++ b/bin/v_add_web_domain_nginx @@ -1,6 +1,6 @@ #!/bin/bash # info: add webdomain nginx support -# options: user domain +# options: user domain [template] [extentions] [restart] # # The function enables nginx support for a domain. It can significantly improve # website speed. @@ -18,6 +18,7 @@ template=${3-default} default_extentions="jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,\ pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm" extentions=${4-$default_extentions} +restart="$5" # Includes source $VESTA/conf/vesta.conf @@ -29,7 +30,7 @@ source $VESTA/func/domain.sh # Verifications # #----------------------------------------------------------# -check_args '2' "$#" 'user domain [template] [extentions]' +check_args '2' "$#" 'user domain [template] [extentions] [restart]' validate_format 'user' 'domain' 'template' 'extentions' is_system_enabled "$PROXY_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -94,7 +95,9 @@ update_object_value 'web' 'DOMAIN' "$domain" '$NGINX' "$NGINX" update_object_value 'web' 'DOMAIN' "$domain" '$NGINX_EXT' "$extentions" # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi log_history "$EVENT" log_event "$OK" "$EVENT" diff --git a/bin/v_add_web_domain_ssl b/bin/v_add_web_domain_ssl index c1c3fe976..def7ffc0f 100755 --- a/bin/v_add_web_domain_ssl +++ b/bin/v_add_web_domain_ssl @@ -1,6 +1,6 @@ #!/bin/bash # info: adding ssl for domain -# options: user domain ssl_dir [ssl_home] +# options: user domain ssl_dir [ssl_home] [restart] # # The function turns on SSL support for a domain. Parameter ssl_dir is a path # to directory where 2 or 3 ssl files can be found. Certificate file @@ -19,7 +19,8 @@ user=$1 domain=$(idn -t --quiet -u "$2" ) domain_idn=$(idn -t --quiet -a "$domain") ssl_dir=$3 -ssl_home=${4-single} +ssl_home=${4-same} +restart="$5" # Includes source $VESTA/conf/vesta.conf @@ -32,7 +33,7 @@ source $VESTA/func/ip.sh # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'user domain ssl_dir [ssl_home]' +check_args '3' "$#" 'user domain ssl_dir [ssl_home] [restart]' validate_format 'user' 'domain' 'ssl_dir' is_system_enabled "$WEB_SYSTEM" is_object_valid 'user' 'USER' "$user" @@ -124,7 +125,9 @@ update_object_value 'web' 'DOMAIN' "$domain" '$SSL_HOME' "$SSL_HOME" update_object_value 'web' 'DOMAIN' "$domain" '$SSL' "yes" # Restart web server -$BIN/v_restart_web "$EVENT" +if [ "$restart" != 'no' ]; then + $BIN/v_restart_web "$EVENT" +fi # Logging log_history "$EVENT" diff --git a/bin/v_list_web_stats b/bin/v_list_web_stats new file mode 100755 index 000000000..1e716366e --- /dev/null +++ b/bin/v_list_web_stats @@ -0,0 +1,66 @@ +#!/bin/bash +# info: list web statistics +# options: [format] +# +# The function for obtaining the list of system shells. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +format=${1-shell} + +# Includes +source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + +# Json function +json_list_st() { + stats=$(echo "${STATS_SYSTEM//,/ } none") + st_counter=$(echo "$stats" | wc -w) + i=1 + echo '[' + for st in $stats; do + if [ "$i" -lt "$st_counter" ]; then + echo -e "\t\"$st\"," + else + echo -e "\t\"$st\"" + fi + (( ++i)) + done + echo "]" +} + +# Shell function +shell_list_st() { + stats=$(echo "none ${STATS_SYSTEM//,/ }") + if [ -z "$nohead" ]; then + echo "STATS" + echo "----------" + fi + for st in $stats; do + echo "$st" + done +} + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Listing domains +case $format in + json) json_list_st ;; + plain) nohead=1; shell_list_st ;; + shell) shell_list_st ;; + *) check_args '1' '0' '[format]' ;; +esac + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/web/add/user/index.php b/web/add/user/index.php index ea9a49642..615b199f4 100644 --- a/web/add/user/index.php +++ b/web/add/user/index.php @@ -6,6 +6,10 @@ session_start(); $TAB = 'USER'; include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); +if (empty($_SESSION['user'])) { + header("Location: /login/"); +} + // Header include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); diff --git a/web/add/web/index.php b/web/add/web/index.php new file mode 100644 index 000000000..61c23451a --- /dev/null +++ b/web/add/web/index.php @@ -0,0 +1,228 @@ + $error) { + if ( $i == 0 ) { + $error_msg = $error; + } else { + $error_msg = $error_msg.", ".$error; + } + } + $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank."; + } else { + exec (VESTA_CMD."v_add_web_domain ".$user." ".$v_domain." ".$v_ip." ".$v_template." 'no'", $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); + + // Add DNS + if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_add_dns_domain ".$user." ".$v_domain." ".$v_ip, $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); + } + + // Add Mail + if (($_POST['v_mail'] == 'on') && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_add_mail_domain ".$user." ".$v_domain, $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); + } + + // Add Aliases + if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) { + $valiases = preg_replace("/\n/", " ", $_POST['v_aliases']); + $valiases = preg_replace("/,/", " ", $valiases); + $valiases = preg_replace('/\s+/', ' ',$valiases); + + $aliases = explode(" ", $valiases); + foreach ($aliases as $alias) { + $alias = escapeshellarg($alias); + if (empty($_SESSION['error_msg'])) { + exec (VESTA_CMD."v_add_web_domain_alias ".$user." ".$v_domain." ".$alias." 'no'", $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); + } + if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_add_dns_on_web_alias ".$user." ".$v_domain." 'no'", $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); + } + } + + // Add ErrorLog + if ((!empty($_POST['v_elog'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_add_web_domain_elog ".$user." ".$v_domain." 'no'", $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); + } + + // Add Nginx + if ((!empty($_POST['v_nginx'])) && (empty($_SESSION['error_msg']))) { + $nginx_ext = "'jpg,jpeg,gif,png,ico,css,zip,tgz,gz,rar,bz2,doc,xls,exe,pdf,ppt,txt,tar,wav,bmp,rtf,js,mp3,avi,mpeg,html,htm'"; + exec (VESTA_CMD."v_add_web_domain_nginx ".$user." ".$v_domain." 'default' ".$nginx_ext." 'no'", $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); + } + + // Add SSL + if (!empty($_POST['v_ssl'])) { + exec ('mktemp -d', $output, $return_var); + $tmpdir = $output[0]; + + // Certificate + if (!empty($_POST['v_ssl_cert'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); + fwrite($fp, $_POST['v_ssl_cert']."\n"); + fclose($fp); + } + + // Key + if (!empty($_POST['v_ssl_key'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); + fwrite($fp, $_POST['v_ssl_key']."\n"); + fclose($fp); + } + + // Pem + if (!empty($_POST['v_ssl_pem'])) { + $fp = fopen($tmpdir."/".$_POST['v_domain'].".pem", 'w'); + fwrite($fp, $_POST['v_ssl_pem']."\n"); + fclose($fp); + } + + exec (VESTA_CMD."v_add_web_domain_ssl ".$user." ".$v_domain." ".$tmpdir." 'same' 'no'", $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); + } + + // Add WebStats + if ((!empty($_POST['v_stats'])) && ($_POST['v_stats'] != 'none' ) && (empty($_SESSION['error_msg']))) { + $v_stats = escapeshellarg($_POST['v_stats']); + exec (VESTA_CMD."v_add_web_domain_stats ".$user." ".$v_domain." ".$v_stats, $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); + } + + if (empty($_SESSION['error_msg'])) { + exec (VESTA_CMD."v_restart_web", $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); + $_SESSION['ok_msg'] = "OK: domain ".$_POST[v_domain]." has been created successfully."; + unset($v_domain); + unset($v_aliases); + unset($v_ssl); + unset($v_ssl_cert); + unset($v_ssl_key); + unset($v_ssl_pem); + } + } + } + + exec (VESTA_CMD."v_list_user_ips ".$user." json", $output, $return_var); + $ips = json_decode(implode('', $output), true); + unset($output); + + exec (VESTA_CMD."v_list_web_templates ".$user." json", $output, $return_var); + $templates = json_decode(implode('', $output), true); + unset($output); + + exec (VESTA_CMD."v_list_web_stats json", $output, $return_var); + $stats = json_decode(implode('', $output), true); + unset($output); + + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_web.html'); + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_web.html'); + unset($_SESSION['error_msg']); + unset($_SESSION['ok_msg']); +} + +// Footer +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); diff --git a/web/edit/user/index.php b/web/edit/user/index.php index 0b5e069cf..b101c00b3 100644 --- a/web/edit/user/index.php +++ b/web/edit/user/index.php @@ -3,6 +3,7 @@ //error_reporting(NULL); ob_start(); session_start(); + $TAB = 'USER'; include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); diff --git a/web/inc/main.php b/web/inc/main.php index 0d2b30147..87da175ed 100644 --- a/web/inc/main.php +++ b/web/inc/main.php @@ -2,18 +2,19 @@ // Set timezone date_default_timezone_set('UTC'); -// Check user +// Check user session if (!isset($_SESSION['user'])) { + $_SESSION['request_uri'] = $_SERVER['REQUEST_URI']; header("Location: /login/"); + exit; } -if (!empty($_SESSION['look'])&& $_SESSION['look'] != 'admin') { +if (isset($_SESSION['look']) && ( $_SESSION['look'] != 'admin' )) { $user = $_SESSION['look']; } else { $user = $_SESSION['user']; } - define('VESTA_CMD', '/usr/bin/sudo /usr/local/vesta/bin/'); $i = 0; @@ -22,6 +23,7 @@ $i = 0; function check_error($return_var){ if ( $return_var > 0 ) { header("Location: /error/"); + exit; } } diff --git a/web/login/index.php b/web/login/index.php index 82f52f776..023113e96 100644 --- a/web/login/index.php +++ b/web/login/index.php @@ -14,8 +14,8 @@ if (isset($_SESSION['user'])) { $_SESSION['look_alert'] = $_GET['loginas']; } } - header("Location: /"); + exit; } else { if (isset($_POST['user']) && isset($_POST['password'])) { $cmd="/usr/bin/sudo /usr/local/vesta/bin/"; @@ -25,7 +25,14 @@ if (isset($_SESSION['user'])) { $ERROR = "ERROR: Invalid username or password"; } else { $_SESSION['user'] = $_POST['user']; - header("Location: /"); + if (!empty($_SESSION['request_uri'])) { + header("Location: ".$_SESSION['request_uri']); + unset($_SESSION['request_uri']); + exit; + } else { + header("Location: /"); + exit; + } } } require_once '../templates/login.html'; diff --git a/web/logout/index.php b/web/logout/index.php index 28ee3c703..5cbfd2099 100644 --- a/web/logout/index.php +++ b/web/logout/index.php @@ -8,5 +8,5 @@ if (!empty($_SESSION['look'])) { } header("Location: /"); - +exit; ?> diff --git a/web/templates/admin/add_web.html b/web/templates/admin/add_web.html new file mode 100644 index 000000000..c57019e05 --- /dev/null +++ b/web/templates/admin/add_web.html @@ -0,0 +1,100 @@ + + + + + + + + +
+ + +
+
+ + +
+ + + + + + + + + + + + + + + + + +
Domain
IP address
Template
DNS support
>
Mail support
>
Advanced Options ⇢
+ + + + + + + + + + + + + + + + + +
Aliases
Error Logging
>
Nginx Support
>
SSL Support
>
SSL Certificate
SSL Key
SSL PEM
Web Statistics
+
+ + +
+
diff --git a/web/templates/admin/menu_add_web.html b/web/templates/admin/menu_add_web.html new file mode 100644 index 000000000..e15e758d3 --- /dev/null +++ b/web/templates/admin/menu_add_web.html @@ -0,0 +1,15 @@ + + + + + diff --git a/web/templates/admin/menu_web.html b/web/templates/admin/menu_web.html index 35725729d..8e0fe6401 100644 --- a/web/templates/admin/menu_web.html +++ b/web/templates/admin/menu_web.html @@ -1,6 +1,6 @@ - +