Browse Source

added child list function

Serghey Rodin 14 years ago
parent
commit
7fede99297
4 changed files with 99 additions and 7 deletions
  1. 1 2
      bin/v_add_sys_user
  2. 8 0
      bin/v_del_sys_user
  3. 55 0
      bin/v_list_sys_user_childs
  4. 35 5
      func/shared_func.sh

+ 1 - 2
bin/v_add_sys_user

@@ -166,9 +166,8 @@ U_MAIL_DOMAINS='0'
 DATE='$V_DATE'" > $V_USERS/$user/user.conf
 
 # Filling owner config
-ROLE=$(echo "$role" | tr "[:lower:]" "[:upper:]")
 if [ "$user" != 'vesta' ]; then
-    echo "$ROLE='$user'" >> $V_USERS/$owner/child.conf
+    echo "USER='$user'" >> $V_USERS/$owner/child.conf
     increase_user_value "$owner" 'U_CHILDS'
 fi
 

+ 8 - 0
bin/v_del_sys_user

@@ -111,6 +111,14 @@ if [ ! -z "$statp" ]; then
     done
 fi
 
+# Deleteing user from parent
+childc=$(grep -n "USER='$user'" $V_USERS/child.conf |cut -d : -f 1|sort -n -r)
+if [ ! -z "$childc" ]; then
+    for str in $childc; do
+        sed -i "$str d" $V_USERS/child.conf
+    done
+fi
+
 # Removing system user
 userdel -f $user
 rm -rf $V_HOME/$user

+ 55 - 0
bin/v_list_sys_user_childs

@@ -0,0 +1,55 @@
+#!/bin/bash
+# info: listing user childs
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument defenition
+user="$1"
+format="${2-shell}"
+limit="${3-1000}"
+offset="${4-1}"
+
+# Importing variables
+source $VESTA/conf/vars.conf
+source $V_FUNC/shared_func.sh
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Checking arg number
+check_args '1' "$#" 'user [format] [limit] [offset]'
+
+# Checking argument format
+format_validation 'user' 'limit' 'offset'
+
+# Checking user
+is_user_valid
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Defining fileds to select
+fields='$USER'
+
+# Listing domains
+case $format in 
+    json) childs_json_list ;;
+    shell) childs_shell_list ;;
+    *) check_args '1' '0' 'user [format] [limit] [offset]'
+esac
+
+
+#----------------------------------------------------------#
+#                       Vesta                              #
+#----------------------------------------------------------#
+
+# Logging
+log_event 'system' "$V_EVENT"
+
+exit $OK

+ 35 - 5
func/shared_func.sh

@@ -1235,13 +1235,14 @@ usr_shell_list() {
 }
 
 usrns_json_list() {
-    ns=$(grep "NS[1|2]=" $V_USERS/$user/user.conf |cut -f 2 -d \')
+    ns=$(grep "^NS='" $V_USERS/$user/user.conf |cut -f 2 -d \')
     # Print top bracket
     echo '['
     i=1
+    nslistc=$(echo -e "${ns//,/\n}"|wc -l)
     # Listing servers
-    for nameserver in $ns;do
-        if [ "$i" -eq 1 ]; then
+    for nameserver in ${ns//,/ };do
+        if [ "$i" -ne "$nslistc" ]; then
             echo -e  "\t\"$nameserver\","
         else
             echo -e  "\t\"$nameserver\""
@@ -1253,15 +1254,44 @@ usrns_json_list() {
 }
 
 usrns_shell_list() {
-    ns=$(grep "NS[1|2]=" $V_USERS/$user/user.conf |cut -f 2 -d \')
+    ns=$(grep "^NS='" $V_USERS/$user/user.conf |cut -f 2 -d \')
     # Print result
     echo "NAMESERVER"
     echo "----------"
-    for nameserver in $ns;do
+    for nameserver in ${ns//,/ };do
         echo "$nameserver"
     done
 }
 
+childs_json_list() {
+    # Print result
+    echo '['
+    if [ -e "$V_USERS/$user/child.conf" ]; then
+        i=1
+        childlistc=$(wc -l $V_USERS/$user/child.conf |cut -f -1 -d ' ')
+        for child in $(cat $V_USERS/$user/child.conf|cut -f 2 -d \');do
+            if [ "$i" -ne "$childlistc" ]; then
+                echo -e "\t\"$child\","
+            else
+                echo -e "\t\"$child\""
+            fi
+            i=$((i + 1))
+        done
+    fi
+    echo ']'
+}
+
+childs_shell_list() {
+    # Print result
+    echo "CHILDS"
+    echo "----------"
+    if [ -e "$V_USERS/$user/child.conf" ]; then
+        for child in $(cat $V_USERS/$user/child.conf|cut -f 2 -d \');do
+            echo "$child"
+        done
+    fi
+}
+
 get_usr_disk() {
     size='0'