diff --git a/bin/v_add_sys_ip b/bin/v_add_sys_ip index 2c327f2c..d2a2aeb4 100755 --- a/bin/v_add_sys_ip +++ b/bin/v_add_sys_ip @@ -19,7 +19,7 @@ ip=$1 mask=$2 interface="${3-eth0}" user="${4-admin}" -ip_status="${5-shared}" +ip_status="${5-shared}" # can be dedicated as well ip_name=$6 # Includes diff --git a/bin/v_list_sys_interfaces b/bin/v_list_sys_interfaces index 7d6baf7f..3ed672f2 100755 --- a/bin/v_list_sys_interfaces +++ b/bin/v_list_sys_interfaces @@ -17,11 +17,11 @@ source $VESTA/func/main.sh # Json function json_list_iface() { - interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ') + dev=$(cat /proc/net/dev |grep : |cut -f 1 -d : |tr -d ' ' |grep -v lo) int_counter=$(echo "$interfaces" | wc -l) i=1 echo '[' - for interface in $interfaces; do + for interface in $dev; do if [ "$i" -lt "$int_counter" ]; then echo -e "\t\"$interface\"," else @@ -34,12 +34,12 @@ json_list_iface() { # Shell function shell_list_iface() { - interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ') + dev=$(cat /proc/net/dev |grep : |cut -f 1 -d : |tr -d ' ' |grep -v lo) if [ -z "$nohead" ]; then echo "INTERFACES" echo "----------" fi - for interface in $interfaces; do + for interface in $dev; do echo "$interface" done } diff --git a/bin/v_list_sys_ip b/bin/v_list_sys_ip index 24401cef..d6552186 100755 --- a/bin/v_list_sys_ip +++ b/bin/v_list_sys_ip @@ -74,7 +74,7 @@ conf=$VESTA/data/ips/$IP # Defining fileds to select fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE - $NETMASK $DATE' + $NETMASK $TIME $DATE' # Listing ip case $format in diff --git a/bin/v_list_sys_users b/bin/v_list_sys_users new file mode 100755 index 00000000..a5f523c9 --- /dev/null +++ b/bin/v_list_sys_users @@ -0,0 +1,64 @@ +#!/bin/bash +# info: list system users +# options: [format] +# +# The function for obtaining the list of system users. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +format=${1-shell} + +# Includes +source $VESTA/func/main.sh + +# Json function +json_list_users() { + users=$(grep @ /etc/passwd|cut -f 1 -d :) + int_counter=$(echo "$users" | wc -l) + i=1 + echo '[' + for user in $users; do + if [ "$i" -lt "$int_counter" ]; then + echo -e "\t\"$user\"," + else + echo -e "\t\"$user\"" + fi + (( ++i)) + done + echo "]" +} + +# Shell function +shell_list_users() { + if [ -z "$nohead" ]; then + echo "USERS" + echo "----------" + fi + for user in $(grep @ /etc/passwd|cut -f 1 -d :); do + echo "$user" + done +} + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Listing domains +case $format in + json) json_list_users ;; + plain) nohead=1; shell_list_users ;; + shell) shell_list_users ;; + *) check_args '1' '0' '[format]' ;; +esac + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/func/ip.sh b/func/ip.sh index 3ea3f9ad..bee45555 100644 --- a/func/ip.sh +++ b/func/ip.sh @@ -1,7 +1,8 @@ # Validationg ip address is_ip_valid() { - check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip") - if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then + #check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip") + #if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then + if [ ! -e "$VESTA/data/ips/$ip" ] ; then echo "Error: IP $ip not exist" log_event "$E_NOTEXIST" "$EVENT" exit $E_NOTEXIST diff --git a/web/add/ip/index.php b/web/add/ip/index.php new file mode 100644 index 00000000..a4659ed8 --- /dev/null +++ b/web/add/ip/index.php @@ -0,0 +1,88 @@ + $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 { + // Add IP + $v_interface = escapeshellarg($_POST['v_interface']); + $v_owner = $_POST['v_owner']; + exec (VESTA_CMD."v_add_sys_ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name, $output, $return_var); + $v_owner = $_POST['v_owner']; + $v_interface = $_POST['v_interface']; + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + unset($v_password); + unset($output); + } else { + $_SESSION['ok_msg'] = "OK: ip ".$_POST['v_ip']." has been created successfully."; + unset($v_ip); + unset($v_netmask); + unset($v_name); + unset($output); + } + } + } + exec (VESTA_CMD."v_list_sys_interfaces 'json'", $output, $return_var); + $interfaces = json_decode(implode('', $output), true); + unset($output); + + exec (VESTA_CMD."v_list_sys_users 'json'", $output, $return_var); + $users = json_decode(implode('', $output), true); + unset($output); + + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_ip.html'); + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html'); + unset($_SESSION['error_msg']); + unset($_SESSION['ok_msg']); +} + +// Footer +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); diff --git a/web/delete/ip/index.php b/web/delete/ip/index.php new file mode 100644 index 00000000..c2115f04 --- /dev/null +++ b/web/delete/ip/index.php @@ -0,0 +1,16 @@ +', $output); + if (empty($error)) $error = 'Error: vesta did not return any output.'; + $_SESSION['error_msg'] = $error; + } else { + $data = json_decode(implode('', $output), true); + unset($output); + $v_username = $user; + $v_ip = $_GET['ip']; + $v_netmask = $data[$v_ip]['NETMASK']; + $v_interace = $data[$v_ip]['INTERFACE']; + $v_name = $data[$v_ip]['NAME']; + $v_ipstatus = $data[$v_ip]['STATUS']; + if ($v_ipstatus == 'dedicated') $v_dedicated = 'yes'; + $v_owner = $data[$v_ip]['OWNER']; + $v_date = $data[$v_ip]['DATE']; + $v_time = $data[$v_ip]['TIME']; + $v_suspended = $data[$v_ip]['SUSPENDED']; + if ( $v_suspended == 'yes' ) { + $v_status = 'suspended'; + } else { + $v_status = 'active'; + } + + exec (VESTA_CMD."v_list_sys_users 'json'", $output, $return_var); + $users = json_decode(implode('', $output), true); + unset($output); + + // Action + if (!empty($_POST['save'])) { + $v_username = $user; + $v_ip = escapeshellarg($_POST['v_ip']); + + // Change Status + if (($v_ipstatus == 'shared') && (empty($_POST['v_shared'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_change_sys_ip_status ".$v_ip." 'dedicated'", $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); + $v_dedicated = 'yes'; + } + if (($v_ipstatus == 'dedicated') && (!empty($_POST['v_shared'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v_change_sys_ip_status ".$v_ip." 'shared'", $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); + unset($v_dedicated); + } + + // Change owner + if (($v_owner != $_POST['v_owner']) && (empty($_SESSION['error_msg']))) { + $v_owner = escapeshellarg($_POST['v_owner']); + exec (VESTA_CMD."v_change_sys_ip_owner ".$v_ip." ".$v_owner, $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; + } + $v_owner = $_POST['v_owner']; + unset($output); + } + + // Change Name + if (($v_name != $_POST['v_name']) && (empty($_SESSION['error_msg']))) { + $v_name = escapeshellarg($_POST['v_name']); + exec (VESTA_CMD."v_change_sys_ip_name ".$v_ip." ".$v_name, $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'])) { + $_SESSION['ok_msg'] = "OK: changes has been saved."; + } + } + } + + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_ip.html'); + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_ip.html'); + unset($_SESSION['error_msg']); + unset($_SESSION['ok_msg']); +} + +// Footer +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); diff --git a/web/templates/admin/add_ip.html b/web/templates/admin/add_ip.html new file mode 100644 index 00000000..287ab895 --- /dev/null +++ b/web/templates/admin/add_ip.html @@ -0,0 +1,74 @@ + + + + + + + +
+ + +
+
+ + +
+ + + + + + + + + + + +
IP
Netmask
Interface
Shared
onclick="javascript:elementHideShow('usrtable');">
+ + +
Assigned User
Associated Domain (optional)
+ + +
+
diff --git a/web/templates/admin/edit_ip.html b/web/templates/admin/edit_ip.html new file mode 100644 index 00000000..dba815de --- /dev/null +++ b/web/templates/admin/edit_ip.html @@ -0,0 +1,66 @@ + + + + + + + +
+ + + + +
+
+ + +
+ + + + + + + + + + + +
IP
Netmask
Interface
Shared
Assigned User
Associated Domain (optional)
+ + +
+
diff --git a/web/templates/admin/list_ip.html b/web/templates/admin/list_ip.html index 2c5bf7d5..965f33fb 100644 --- a/web/templates/admin/list_ip.html +++ b/web/templates/admin/list_ip.html @@ -4,6 +4,28 @@ foreach ($data as $key => $value) { ++$i; ?> + @@ -16,7 +38,14 @@ foreach ($data as $key => $value) { - + +
delete"> edit + + delete +
+

Are you sure you want to delete ip?

+
+
diff --git a/web/templates/admin/menu_add_ip.html b/web/templates/admin/menu_add_ip.html new file mode 100644 index 00000000..95d83d1e --- /dev/null +++ b/web/templates/admin/menu_add_ip.html @@ -0,0 +1,15 @@ +
+ + + + diff --git a/web/templates/admin/menu_edit_ip.html b/web/templates/admin/menu_edit_ip.html new file mode 100644 index 00000000..f9ecbcd8 --- /dev/null +++ b/web/templates/admin/menu_edit_ip.html @@ -0,0 +1,15 @@ + + + + +