Skip to content

Commit c05fb35

Browse files
committed
ip pages
1 parent 36ab122 commit c05fb35

File tree

13 files changed

+497
-9
lines changed

13 files changed

+497
-9
lines changed

bin/v_add_sys_ip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ip=$1
1919
mask=$2
2020
interface="${3-eth0}"
2121
user="${4-admin}"
22-
ip_status="${5-shared}"
22+
ip_status="${5-shared}" # can be dedicated as well
2323
ip_name=$6
2424

2525
# Includes

bin/v_list_sys_interfaces

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ source $VESTA/func/main.sh
1717

1818
# Json function
1919
json_list_iface() {
20-
interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
20+
dev=$(cat /proc/net/dev |grep : |cut -f 1 -d : |tr -d ' ' |grep -v lo)
2121
int_counter=$(echo "$interfaces" | wc -l)
2222
i=1
2323
echo '['
24-
for interface in $interfaces; do
24+
for interface in $dev; do
2525
if [ "$i" -lt "$int_counter" ]; then
2626
echo -e "\t\"$interface\","
2727
else
@@ -34,12 +34,12 @@ json_list_iface() {
3434

3535
# Shell function
3636
shell_list_iface() {
37-
interfaces=$(cat /proc/net/dev | grep : | cut -f 1 -d : | tr -d ' ')
37+
dev=$(cat /proc/net/dev |grep : |cut -f 1 -d : |tr -d ' ' |grep -v lo)
3838
if [ -z "$nohead" ]; then
3939
echo "INTERFACES"
4040
echo "----------"
4141
fi
42-
for interface in $interfaces; do
42+
for interface in $dev; do
4343
echo "$interface"
4444
done
4545
}

bin/v_list_sys_ip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ conf=$VESTA/data/ips/$IP
7474

7575
# Defining fileds to select
7676
fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE
77-
$NETMASK $DATE'
77+
$NETMASK $TIME $DATE'
7878

7979
# Listing ip
8080
case $format in

bin/v_list_sys_users

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# info: list system users
3+
# options: [format]
4+
#
5+
# The function for obtaining the list of system users.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
18+
# Json function
19+
json_list_users() {
20+
users=$(grep @ /etc/passwd|cut -f 1 -d :)
21+
int_counter=$(echo "$users" | wc -l)
22+
i=1
23+
echo '['
24+
for user in $users; do
25+
if [ "$i" -lt "$int_counter" ]; then
26+
echo -e "\t\"$user\","
27+
else
28+
echo -e "\t\"$user\""
29+
fi
30+
(( ++i))
31+
done
32+
echo "]"
33+
}
34+
35+
# Shell function
36+
shell_list_users() {
37+
if [ -z "$nohead" ]; then
38+
echo "USERS"
39+
echo "----------"
40+
fi
41+
for user in $(grep @ /etc/passwd|cut -f 1 -d :); do
42+
echo "$user"
43+
done
44+
}
45+
46+
47+
#----------------------------------------------------------#
48+
# Action #
49+
#----------------------------------------------------------#
50+
51+
# Listing domains
52+
case $format in
53+
json) json_list_users ;;
54+
plain) nohead=1; shell_list_users ;;
55+
shell) shell_list_users ;;
56+
*) check_args '1' '0' '[format]' ;;
57+
esac
58+
59+
60+
#----------------------------------------------------------#
61+
# Vesta #
62+
#----------------------------------------------------------#
63+
64+
exit

func/ip.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Validationg ip address
22
is_ip_valid() {
3-
check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip")
4-
if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then
3+
#check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip")
4+
#if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then
5+
if [ ! -e "$VESTA/data/ips/$ip" ] ; then
56
echo "Error: IP $ip not exist"
67
log_event "$E_NOTEXIST" "$EVENT"
78
exit $E_NOTEXIST

web/add/ip/index.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
$TAB = 'IP';
7+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
8+
9+
// Header
10+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
11+
12+
// Panel
13+
top_panel($user,$TAB);
14+
15+
// Are you admin?
16+
if ($_SESSION['user'] == 'admin') {
17+
if (!empty($_POST['ok'])) {
18+
// Check input
19+
if (empty($_POST['v_ip'])) $errors[] = 'ip address';
20+
if (empty($_POST['v_netmask'])) $errors[] = 'netmask';
21+
if (empty($_POST['v_interface'])) $errors[] = 'interface';
22+
if (empty($_POST['v_owner'])) $errors[] = 'assigned used';
23+
if (empty($_POST['v_interface'])) $errors[] = 'interface';
24+
25+
// Protect input
26+
$v_ip = escapeshellarg($_POST['v_ip']);
27+
$v_netmask = escapeshellarg($_POST['v_netmask']);
28+
$v_name = escapeshellarg($_POST['v_name']);
29+
30+
$v_interface = $_POST['v_interface'];
31+
$v_shared = $_POST['v_shared'];
32+
if ($v_shared == 'on') {
33+
$ip_status = 'shared';
34+
} else {
35+
$ip_status = 'dedicated';
36+
$v_dedicated = 'yes';
37+
}
38+
39+
$v_owner = $_POST['v_owner'];
40+
41+
// Check for errors
42+
if (!empty($errors[0])) {
43+
foreach ($errors as $i => $error) {
44+
if ( $i == 0 ) {
45+
$error_msg = $error;
46+
} else {
47+
$error_msg = $error_msg.", ".$error;
48+
}
49+
}
50+
$_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
51+
} else {
52+
// Add IP
53+
$v_interface = escapeshellarg($_POST['v_interface']);
54+
$v_owner = $_POST['v_owner'];
55+
exec (VESTA_CMD."v_add_sys_ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name, $output, $return_var);
56+
$v_owner = $_POST['v_owner'];
57+
$v_interface = $_POST['v_interface'];
58+
if ($return_var != 0) {
59+
$error = implode('<br>', $output);
60+
if (empty($error)) $error = 'Error: vesta did not return any output.';
61+
$_SESSION['error_msg'] = $error;
62+
unset($v_password);
63+
unset($output);
64+
} else {
65+
$_SESSION['ok_msg'] = "OK: ip <b>".$_POST['v_ip']."</b> has been created successfully.";
66+
unset($v_ip);
67+
unset($v_netmask);
68+
unset($v_name);
69+
unset($output);
70+
}
71+
}
72+
}
73+
exec (VESTA_CMD."v_list_sys_interfaces 'json'", $output, $return_var);
74+
$interfaces = json_decode(implode('', $output), true);
75+
unset($output);
76+
77+
exec (VESTA_CMD."v_list_sys_users 'json'", $output, $return_var);
78+
$users = json_decode(implode('', $output), true);
79+
unset($output);
80+
81+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_add_ip.html');
82+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html');
83+
unset($_SESSION['error_msg']);
84+
unset($_SESSION['ok_msg']);
85+
}
86+
87+
// Footer
88+
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

web/delete/ip/index.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
7+
8+
if ($_SESSION['user'] == 'admin') {
9+
if (!empty($_GET['ip'])) {
10+
$v_ip = escapeshellarg($_GET['ip']);
11+
exec (VESTA_CMD."v_delete_sys_ip ".$v_ip, $output, $return_var);
12+
unset($output);
13+
}
14+
}
15+
16+
header("Location: /list/ip/");

web/edit/ip/index.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
7+
$TAB = 'IP';
8+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
9+
10+
// Header
11+
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
12+
13+
// Panel
14+
top_panel($user,$TAB);
15+
16+
// Are you admin?
17+
if ($_SESSION['user'] == 'admin') {
18+
19+
// Check user argument?
20+
if (empty($_GET['ip'])) {
21+
header("Location: /list/ip/");
22+
exit;
23+
}
24+
25+
$v_ip = escapeshellarg($_GET['ip']);
26+
exec (VESTA_CMD."v_list_sys_ip ".$v_ip." 'json'", $output, $return_var);
27+
if ($return_var != 0) {
28+
$error = implode('<br>', $output);
29+
if (empty($error)) $error = 'Error: vesta did not return any output.';
30+
$_SESSION['error_msg'] = $error;
31+
} else {
32+
$data = json_decode(implode('', $output), true);
33+
unset($output);
34+
$v_username = $user;
35+
$v_ip = $_GET['ip'];
36+
$v_netmask = $data[$v_ip]['NETMASK'];
37+
$v_interace = $data[$v_ip]['INTERFACE'];
38+
$v_name = $data[$v_ip]['NAME'];
39+
$v_ipstatus = $data[$v_ip]['STATUS'];
40+
if ($v_ipstatus == 'dedicated') $v_dedicated = 'yes';
41+
$v_owner = $data[$v_ip]['OWNER'];
42+
$v_date = $data[$v_ip]['DATE'];
43+
$v_time = $data[$v_ip]['TIME'];
44+
$v_suspended = $data[$v_ip]['SUSPENDED'];
45+
if ( $v_suspended == 'yes' ) {
46+
$v_status = 'suspended';
47+
} else {
48+
$v_status = 'active';
49+
}
50+
51+
exec (VESTA_CMD."v_list_sys_users 'json'", $output, $return_var);
52+
$users = json_decode(implode('', $output), true);
53+
unset($output);
54+
55+
// Action
56+
if (!empty($_POST['save'])) {
57+
$v_username = $user;
58+
$v_ip = escapeshellarg($_POST['v_ip']);
59+
60+
// Change Status
61+
if (($v_ipstatus == 'shared') && (empty($_POST['v_shared'])) && (empty($_SESSION['error_msg']))) {
62+
exec (VESTA_CMD."v_change_sys_ip_status ".$v_ip." 'dedicated'", $output, $return_var);
63+
if ($return_var != 0) {
64+
$error = implode('<br>', $output);
65+
if (empty($error)) $error = 'Error: vesta did not return any output.';
66+
$_SESSION['error_msg'] = $error;
67+
}
68+
unset($output);
69+
$v_dedicated = 'yes';
70+
}
71+
if (($v_ipstatus == 'dedicated') && (!empty($_POST['v_shared'])) && (empty($_SESSION['error_msg']))) {
72+
exec (VESTA_CMD."v_change_sys_ip_status ".$v_ip." 'shared'", $output, $return_var);
73+
if ($return_var != 0) {
74+
$error = implode('<br>', $output);
75+
if (empty($error)) $error = 'Error: vesta did not return any output.';
76+
$_SESSION['error_msg'] = $error;
77+
}
78+
unset($output);
79+
unset($v_dedicated);
80+
}
81+
82+
// Change owner
83+
if (($v_owner != $_POST['v_owner']) && (empty($_SESSION['error_msg']))) {
84+
$v_owner = escapeshellarg($_POST['v_owner']);
85+
exec (VESTA_CMD."v_change_sys_ip_owner ".$v_ip." ".$v_owner, $output, $return_var);
86+
if ($return_var != 0) {
87+
$error = implode('<br>', $output);
88+
if (empty($error)) $error = 'Error: vesta did not return any output.';
89+
$_SESSION['error_msg'] = $error;
90+
}
91+
$v_owner = $_POST['v_owner'];
92+
unset($output);
93+
}
94+
95+
// Change Name
96+
if (($v_name != $_POST['v_name']) && (empty($_SESSION['error_msg']))) {
97+
$v_name = escapeshellarg($_POST['v_name']);
98+
exec (VESTA_CMD."v_change_sys_ip_name ".$v_ip." ".$v_name, $output, $return_var);
99+
if ($return_var != 0) {
100+
$error = implode('<br>', $output);
101+
if (empty($error)) $error = 'Error: vesta did not return any output.';
102+
$_SESSION['error_msg'] = $error;
103+
}
104+
unset($output);
105+
}
106+
107+
if (empty($_SESSION['error_msg'])) {
108+
$_SESSION['ok_msg'] = "OK: changes has been saved.";
109+
}
110+
}
111+
}
112+
113+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/menu_edit_ip.html');
114+
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_ip.html');
115+
unset($_SESSION['error_msg']);
116+
unset($_SESSION['ok_msg']);
117+
}
118+
119+
// Footer
120+
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

0 commit comments

Comments
 (0)