diff --git a/bin/v_add_user b/bin/v_add_user index c2eb6af18..1a2ed3ad1 100755 --- a/bin/v_add_user +++ b/bin/v_add_user @@ -1,5 +1,9 @@ #!/bin/bash -# info: adding system user +# info: add system user +# options: user password email [package] [fname] [lname] +# +# The function creates new user account. + #----------------------------------------------------------# # Variable&Function # @@ -56,10 +60,11 @@ is_package_valid "$package" package_data=$(cat $V_PKG/$package.pkg) # Checking shell -shell_conf=$(echo "$package_data"|grep 'SHELL'|cut -f 2 -d \') +shell_conf=$(echo "$package_data" | grep 'SHELL' | cut -f 2 -d \') case $shell_conf in nologin) shell='/sbin/nologin' ;; bash) shell='/bin/bash' ;; + sh) shell='/bin/bash' ;; *) shell='/sbin/nologin' ;; esac @@ -95,8 +100,8 @@ chmod -R a+x $V_HOME/$user # Checking quota if [ ! -z "$DISK_QUOTA" ] && [ "$DISK_QUOTA" != 'no' ]; then - DISK_QUOTA=$(echo "$package_data"|grep 'DISK_QUOTA' | cut -f 2 -d \') - set_quota "$user" "$DISK_QUOTA" + DISK_QUOTA=$(echo "$package_data" | grep 'DISK_QUOTA' | cut -f 2 -d \') + #$V_BIN/v_add_user_quota "$user" "$DISK_QUOTA" fi diff --git a/bin/v_add_user_backup b/bin/v_add_user_backup index 177dd4e98..470c847d7 100755 --- a/bin/v_add_user_backup +++ b/bin/v_add_user_backup @@ -1,5 +1,9 @@ #!/bin/bash -# info: schedule user backup +# info: schedule user backup creation +# options: user +# +# The function for scheduling user backup creation. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_add_user_reports b/bin/v_add_user_reports index a65925f93..a480abf84 100755 --- a/bin/v_add_user_reports +++ b/bin/v_add_user_reports @@ -1,5 +1,10 @@ #!/bin/bash -# info: adding user reports +# info: add user reports +# opions: user +# +# The script for enabling reports on cron tasks and administrative +# notifications. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_add_web_domain_nginx b/bin/v_add_web_domain_nginx index 0d6329f57..4a0439e36 100755 --- a/bin/v_add_web_domain_nginx +++ b/bin/v_add_web_domain_nginx @@ -79,8 +79,6 @@ fi #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# -echo "NGINX=$NGINX" -echo "NGINX_EXT=$NGINX_EXT" # Adding nginx params to config update_web_domain_value '$NGINX' "$NGINX" diff --git a/bin/v_backup_user b/bin/v_backup_user index 495024c7a..a8beb299e 100755 --- a/bin/v_backup_user +++ b/bin/v_backup_user @@ -1,5 +1,9 @@ #!/bin/bash # info: backup system user with all its objects +# options: user +# +# The call is used for backing up user with all its domains and databases. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_backup_users b/bin/v_backup_users index 7ed0ff395..1a1ac0037 100755 --- a/bin/v_backup_users +++ b/bin/v_backup_users @@ -1,13 +1,16 @@ #!/bin/bash -# info: updating montly billing user report +# info: backup all users +# options: none +# +# The function backups all system users. + #----------------------------------------------------------# # Variable&Function # #----------------------------------------------------------# - # Importing system enviroment as we run this script -# mostly by cron wich not read it by itself +# mostly by cron wich not read it by itself source /etc/profile.d/vesta.sh # Importing variables diff --git a/bin/v_change_user_contact b/bin/v_change_user_contact index 185434b0e..e8162c9dc 100755 --- a/bin/v_change_user_contact +++ b/bin/v_change_user_contact @@ -1,5 +1,9 @@ #!/bin/bash -# info: changing user contact email +# info: change user contact email +# options: user email +# +# The function for changing of e-mail associated with a certain user. + #----------------------------------------------------------# # Variable&Function # @@ -14,6 +18,7 @@ source $VESTA/conf/vars.conf source $V_CONF/vesta.conf source $V_FUNC/shared.func + #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# diff --git a/bin/v_change_user_name b/bin/v_change_user_name index 86653f037..9f88eab6a 100755 --- a/bin/v_change_user_name +++ b/bin/v_change_user_name @@ -1,5 +1,9 @@ #!/bin/bash -# info: changing user nameservers +# info: change user full name +# options: user fname lname +# +# The function allow to change user's full name. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_change_user_ns b/bin/v_change_user_ns index 198a35ebd..32f364166 100755 --- a/bin/v_change_user_ns +++ b/bin/v_change_user_ns @@ -1,5 +1,9 @@ #!/bin/bash -# info: changing user nameservers +# info: change user nameservers +# options: user ns1 ns2 [ns3] [ns4] [ns5] [ns6] [ns7] [ns8] +# +# The function for changing default nameservers for speciefic user. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_change_user_package b/bin/v_change_user_package index 794cbdcfb..bed06755b 100755 --- a/bin/v_change_user_package +++ b/bin/v_change_user_package @@ -1,5 +1,9 @@ #!/bin/bash -# info: changing user package +# info: change user package +# options: user package +# +# The function changes user's hosting package. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_change_user_password b/bin/v_change_user_password index 49124c929..85ef6066c 100755 --- a/bin/v_change_user_password +++ b/bin/v_change_user_password @@ -1,5 +1,9 @@ #!/bin/bash -# info: changing user password +# info: change user password +# options: user password +# +# The function changes user's password and updates RKEY value. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_change_user_shell b/bin/v_change_user_shell index d7ee2cea4..41cfb3b0d 100755 --- a/bin/v_change_user_shell +++ b/bin/v_change_user_shell @@ -1,5 +1,9 @@ #!/bin/bash -# info: changing user shell +# info: change user shell +# options: user shell +# +# The function changes system shell of a user. Shell gives abilty to use ssh. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_delete_user b/bin/v_delete_user index b9f72d4b2..cc17cf76b 100755 --- a/bin/v_delete_user +++ b/bin/v_delete_user @@ -1,5 +1,10 @@ #!/bin/bash -# info: deliting system user +# info: delete user +# options: user +# +# This function deletes a certain user and all his resourses such as domains, +# databases, cron jobs, etc. + #----------------------------------------------------------# # Variable&Function # @@ -113,7 +118,7 @@ if [ ! -z "$statp" ]; then fi # Removing system user -userdel -f $user +/usr/sbin/userdel -f $user rm -rf $V_HOME/$user rm -f /var/spool/mail/$user rm -f /var/spool/cron/$user diff --git a/bin/v_delete_user_ips b/bin/v_delete_user_ips index a70fab422..9edfca041 100755 --- a/bin/v_delete_user_ips +++ b/bin/v_delete_user_ips @@ -1,5 +1,9 @@ #!/bin/bash -# info: deliting system user ips +# info: delete user ips +# options: user +# +# The function deletes all user's ip addresses. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_delete_user_reports b/bin/v_delete_user_reports index e681cd370..f01c4ffab 100755 --- a/bin/v_delete_user_reports +++ b/bin/v_delete_user_reports @@ -1,5 +1,10 @@ #!/bin/bash -# info: adding user reports +# info: delete user reports +# options: user +# +# The script for disabling reports on cron tasks and administrative +# notifications. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_get_user_value b/bin/v_get_user_value index 5b5062a8f..8bc3e5925 100755 --- a/bin/v_get_user_value +++ b/bin/v_get_user_value @@ -1,5 +1,9 @@ #!/bin/bash -# info: Getting system user value +# info: get user value +# options: user key +# +# The function for obtaining certain user's parameters. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_list_user b/bin/v_list_user index 9a1ea0296..89567e3c9 100755 --- a/bin/v_list_user +++ b/bin/v_list_user @@ -1,5 +1,9 @@ #!/bin/bash -# info: listing system user +# info: list system user +# options: user [format] +# +# The function for obtainig the list of all user's parameters. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_list_user_backups b/bin/v_list_user_backups index 2d5c091d4..79e703d08 100755 --- a/bin/v_list_user_backups +++ b/bin/v_list_user_backups @@ -1,5 +1,9 @@ #!/bin/bash -# info: listing system bakups +# info: list user backups +# options: user [format] +# +# The function for obtainig the list of available user backups. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_list_user_ips b/bin/v_list_user_ips index c4428effc..f93949332 100755 --- a/bin/v_list_user_ips +++ b/bin/v_list_user_ips @@ -1,5 +1,9 @@ #!/bin/bash -# info: listing user ips +# info: list user ips +# options user [format] +# +# The function for obtainig the list of available ip addresses. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_list_user_ns b/bin/v_list_user_ns index a313d91d2..a567ff7fc 100755 --- a/bin/v_list_user_ns +++ b/bin/v_list_user_ns @@ -1,5 +1,9 @@ #!/bin/bash -# info: listing user nameservers +# info: list user nameservers +# options: user [format] +# +# Function for obtainig the list of user's DNS servers. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_list_user_packages b/bin/v_list_user_packages index 2941a3839..af7b2f675 100755 --- a/bin/v_list_user_packages +++ b/bin/v_list_user_packages @@ -1,5 +1,9 @@ #!/bin/bash -# info: listing sys user packages +# info: list user packages +# options: [format] +# +# The function for obtaining the list of available hosting packages. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_list_users b/bin/v_list_users index 56b46bb74..d990b2ddb 100755 --- a/bin/v_list_users +++ b/bin/v_list_users @@ -1,5 +1,9 @@ #!/bin/bash -# info: listing system users +# info: list system users +# options: [format] +# +# The function for obtainig the list of all server's users. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_suspend_user b/bin/v_suspend_user index 841f37d2b..475de314f 100755 --- a/bin/v_suspend_user +++ b/bin/v_suspend_user @@ -1,5 +1,9 @@ #!/bin/bash -# info: Suspending sys user +# info: suspend user +# options: user +# +# The function suspends a certain user and all his objects. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_unsuspend_user b/bin/v_unsuspend_user index 8ee936bb0..a37aee177 100755 --- a/bin/v_unsuspend_user +++ b/bin/v_unsuspend_user @@ -1,5 +1,9 @@ #!/bin/bash -# info: Unsuspending sys user +# info: unsuspend user +# options: user +# +# The function unsuspends user and all his objects. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_update_user_backups b/bin/v_update_user_backups index 6b2da7b93..b725947bc 100755 --- a/bin/v_update_user_backups +++ b/bin/v_update_user_backups @@ -1,5 +1,9 @@ #!/bin/bash -# info: updating current backups for +# info: update user backups +# options: user +# +# The function rescan backup directory and updates backup database. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_update_user_bill b/bin/v_update_user_bill index 55d468e65..1f3978099 100755 --- a/bin/v_update_user_bill +++ b/bin/v_update_user_bill @@ -1,5 +1,9 @@ #!/bin/bash -# info: updating montly billing user report +# info: update billing user billing +# options: user +# +# Function logs user parameters into billing database. + #----------------------------------------------------------# # Variable&Function # diff --git a/bin/v_update_user_disk b/bin/v_update_user_disk index 2c9c64581..b3e612879 100755 --- a/bin/v_update_user_disk +++ b/bin/v_update_user_disk @@ -1,5 +1,9 @@ #!/bin/bash -# info: updating disk usage for user directories +# info: update user disk usage +# options: user +# +# The functions recalculates disk usage and updates database. + #----------------------------------------------------------# # Variable&Function # diff --git a/src/c_coding_style.txt b/src/c_coding_style.txt new file mode 100644 index 000000000..813594433 --- /dev/null +++ b/src/c_coding_style.txt @@ -0,0 +1,5 @@ +BASH CODING STYLE + +Please see GNU Coding Standards +******************** +http://www.gnu.org/prep/standards/standards.txt diff --git a/src/v_check_user_password.c b/src/v_check_user_password.c index b93c9d915..7e1ee0b2b 100755 --- a/src/v_check_user_password.c +++ b/src/v_check_user_password.c @@ -9,7 +9,6 @@ /* */ /***************************************************************************/ -#define _XOPEN_SOURCE #include #include #include @@ -21,60 +20,60 @@ int main (int argc, char** argv) { - // defining ip + /* define ip */ char *ip = "127.0.0.1"; - // checking argument list + /* check argument list */ if (3 > argc) { printf("Error: bad args\n",argv[0]); printf("Usage: %s user password [ip]\n",argv[0]); exit(1); }; - // checking ip + /* check ip */ if (4 <= argc) { ip = (char*)malloc(strlen(argv[3])); strcpy(ip, argv[3]); } - // formating current time + /* format current time */ time_t lt = time(NULL); struct tm* ptr = localtime(<); char str[280]; strftime(str, 100, "%Y-%m-%d %H:%M:%S ", ptr); - // openning log file + /* open log file */ FILE* pFile = fopen ("/usr/local/vesta/log/auth.log","a+"); if (NULL == pFile) { printf("Error: can not open file %s \n", argv[0]); exit(12); } - // parsing user argument + /* parse user argument */ struct passwd* userinfo = getpwnam(argv[1]); if (NULL != userinfo) { struct spwd* passw = getspnam(userinfo->pw_name); if (NULL != passw) { char* cryptedPasswrd = (char*)crypt(argv[2], passw->sp_pwdp); if (strcmp(passw->sp_pwdp,crypt(argv[2],passw->sp_pwdp))==0) { - // concatinating time with user and ip + /* concatinate time with user and ip */ strcat(str, userinfo->pw_name); strcat(str, " "); strcat(str, ip); strcat(str, " successfully logged in \n"); - fputs (str,pFile); // writing - fclose (pFile); // closing - exit(EXIT_SUCCESS); // exiting + fputs (str,pFile); /* write */ + fclose (pFile); /* close */ + exit(EXIT_SUCCESS); /* exit */ } else { - // concatinating time with user string + /* concatinate time with user string */ printf ("Error: password missmatch\n"); strcat(str, userinfo->pw_name); strcat(str, " "); strcat(str, ip); strcat(str, " failed to login \n"); - fputs (str,pFile); // writing - fclose (pFile); // closing - exit(9); // exiting + fputs (str,pFile); /* write */ + fclose (pFile); /* close */ + exit(9); /* exit */ }; } } else { diff --git a/test/json.sh b/test/json.sh new file mode 100755 index 000000000..8cc4665e4 --- /dev/null +++ b/test/json.sh @@ -0,0 +1,105 @@ +# https://github.com/dominictarr/JSON.sh +# Code is licensed under the MIT license +# Copyright (c) 2011 Dominic Tarr + +throw () { + echo "$*" >&2 + exit 1 +} + +tokenize () { + local ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})' + local CHAR='[^[:cntrl:]"\\]' + local STRING="\"$CHAR*($ESCAPE$CHAR*)*\"" + local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?' + local KEYWORD='null|false|true' + local SPACE='[[:space:]]+' + egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." --color=never | + egrep -v "^$SPACE$" # eat whitespace +} + +parse_array () { + local index=0 + local ary='' + read -r token + case "$token" in + ']') ;; + *) + while : + do + parse_value "$1" "$index" + let index=$index+1 + ary="$ary""$value" + read -r token + case "$token" in + ']') break ;; + ',') ary="$ary," ;; + *) throw "EXPECTED , or ] GOT ${token:-EOF}" ;; + esac + read -r token + done + ;; + esac + value=`printf '[%s]' $ary` +} + +parse_object () { + local key + local obj='' + read -r token + case "$token" in + '}') ;; + *) + while : + do + case "$token" in + '"'*'"') key=$token ;; + *) throw "EXPECTED string GOT ${token:-EOF}" ;; + esac + read -r token + case "$token" in + ':') ;; + *) throw "EXPECTED : GOT ${token:-EOF}" ;; + esac + read -r token + parse_value "$1" "$key" + obj="$obj$key:$value" + read -r token + case "$token" in + '}') break ;; + ',') obj="$obj," ;; + *) throw "EXPECTED , or } GOT ${token:-EOF}" ;; + esac + read -r token + done + ;; + esac + value=`printf '{%s}' "$obj"` +} + +parse_value () { + local jpath="${1:+$1,}$2" + case "$token" in + '{') parse_object "$jpath" ;; + '[') parse_array "$jpath" ;; + # At this point, the only valid single-character tokens are digits. + ''|[^0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;; + *) value=$token ;; + esac + printf "[%s]\t%s\n" "$jpath" "$value" +} + +parse () { + read -r token + parse_value + read -r token + case "$token" in + '') ;; + *) throw "EXPECTED EOF GOT $token" ;; + esac +} + +if [ $0 = $BASH_SOURCE ]; +then + tokenize | parse +fi diff --git a/test/test_actions.sh b/test/test_actions.sh new file mode 100755 index 000000000..1e4396bdc --- /dev/null +++ b/test/test_actions.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +# Define some variables +source /etc/profile.d/vesta.sh +V_BIN="$VESTA/bin" +V_TEST="$VESTA/test" + +# Define functions +tmp_user() { + MATRIX='0123456789' + LENGTH=4 + while [ ${n:=1} -le $LENGTH ]; do + rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}" + let n+=1 + done + echo "tmp_$rand" +} + +echo_result() { + echo -en "$1" + echo -en '\033[60G' + echo -n '[' + + if [ "$2" -ne 0 ]; then + echo -n 'FAILED' + echo -n ']' + echo -ne '\r\n' + echo "$4" + echo "RETURN VALUE $2" + cat $3 + else + echo -n ' OK ' + echo -n ']' + fi + echo -ne '\r\n' +} + +# Create random username +user=$(tmp_user) +while [ ! -z "$(grep "^$user:" /etc/passwd)" ]; do + user=$(tmp_user) +done + +# Create random tmpfile +tmpfile=$(mktemp -p /tmp ) + +# Add new user +cmd="v_add_user $user $user $user@vestacp.com default Super Test" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Adding new user $user" "$?" "$tmpfile" "$cmd" + +# Change system shell +cmd="v_change_user_shell $user bash" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Changing system shell to /bin/bash" "$?" "$tmpfile" "$cmd" + +# Change name servers +cmd="v_change_user_ns $user ns0.com ns1.com ns2.com ns3.com" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Changing nameservers" "$?" "$tmpfile" "$cmd" + +# Add cron job +cmd="v_add_cron_job $user 1 1 1 1 1 echo" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Adding cron job" "$?" "$tmpfile" "$cmd" + +# Suspend cron job +cmd="v_suspend_cron_job $user 1" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Suspending cron job" "$?" "$tmpfile" "$cmd" + +# Unsuspend cron job +cmd="v_unsuspend_cron_job $user 1" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Unsuspending cron job" "$?" "$tmpfile" "$cmd" + +# Delete cron job +cmd="v_delete_cron_job $user 1" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Deleting cron job" "$?" "$tmpfile" "$cmd" + +# Add cron job +cmd="v_add_cron_job $user 1 1 1 1 1 echo 1" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Adding cron job" "$?" "$tmpfile" "$cmd" + +# Add cron job +cmd="v_add_cron_job $user 1 1 1 1 1 echo 1" +$cmd > $tmpfile 2>> $tmpfile +if [ "$?" -eq 4 ]; then + retval=0 +else + retval=1 +fi +echo_result "Dublicate cron job check" "$retval" "$tmpfile" "$cmd" + +# Check ip +#cat /proc/net/dev|cut -f 1 -d :|tail -n1 +#v_add_sys_ip 192.168.11.11 255.255.255.255 venet0 ekho + +# Delete new user +cmd="v_delete_user $user" +$cmd > $tmpfile 2>> $tmpfile +echo_result "Deleting user $user" "$?" "$tmpfile" "$cmd" + diff --git a/test/test_json_listing.sh b/test/test_json_listing.sh new file mode 100755 index 000000000..e8a35d67b --- /dev/null +++ b/test/test_json_listing.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +source /etc/profile.d/vesta.sh + +V_BIN="$VESTA/bin" +V_TEST="$VESTA/test" + +commands='v_list_cron_jobs vesta json +v_list_db_bases vesta json +v_list_db_base vesta vesta_read json +v_list_db_host mysql localhost json +v_list_db_hosts mysql json +v_list_dns_domains vesta json +v_list_dns_templates json +v_list_sys_config json +v_list_sys_interfaces json +v_list_sys_ips json +v_list_sys_rrd json +v_list_user vesta json +v_list_user_backups vesta json +v_list_user_ips vesta json +v_list_user_ns vesta json +v_list_user_packages json +v_list_users json +v_list_web_domains vesta json +v_list_web_domain vesta default.vesta.domain json +v_list_web_templates vesta json' + +IFS=$'\n' +for cmd in $commands; do + script=$(echo $cmd |cut -f 1 -d ' ') + arg1=$(echo $cmd |cut -f 2 -d ' ') + arg2=$(echo $cmd |cut -f 3 -d ' ') + arg3=$(echo $cmd |cut -f 4 -d ' ') + $V_BIN/$script $arg1 $arg2 $arg3 | $V_TEST/json.sh >/dev/null 2>/dev/null + retval="$?" + echo -en "$cmd" + echo -en '\033[60G' + echo -n '[' + + if [ "$retval" -ne 0 ]; then + echo -n 'FAILED' + echo -n ']' + echo -ne '\r\n' + $V_BIN/$script $arg1 $arg2 $arg3 | $V_TEST/json.sh + else + echo -n ' OK ' + echo -n ']' + fi + echo -ne '\r\n' + +done + +exit diff --git a/web/index.html b/web/index.html index 8bcb52b02..febb71277 100644 --- a/web/index.html +++ b/web/index.html @@ -217,7 +217,7 @@
- All + None
@@ -226,6 +226,10 @@