This commit is contained in:
Serghey Rodin 2012-06-30 00:37:48 +03:00
commit c05fb35800
13 changed files with 497 additions and 9 deletions

View file

@ -19,7 +19,7 @@ ip=$1
mask=$2 mask=$2
interface="${3-eth0}" interface="${3-eth0}"
user="${4-admin}" user="${4-admin}"
ip_status="${5-shared}" ip_status="${5-shared}" # can be dedicated as well
ip_name=$6 ip_name=$6
# Includes # Includes

View file

@ -17,11 +17,11 @@ source $VESTA/func/main.sh
# Json function # Json function
json_list_iface() { 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) int_counter=$(echo "$interfaces" | wc -l)
i=1 i=1
echo '[' echo '['
for interface in $interfaces; do for interface in $dev; do
if [ "$i" -lt "$int_counter" ]; then if [ "$i" -lt "$int_counter" ]; then
echo -e "\t\"$interface\"," echo -e "\t\"$interface\","
else else
@ -34,12 +34,12 @@ json_list_iface() {
# Shell function # Shell function
shell_list_iface() { 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 if [ -z "$nohead" ]; then
echo "INTERFACES" echo "INTERFACES"
echo "----------" echo "----------"
fi fi
for interface in $interfaces; do for interface in $dev; do
echo "$interface" echo "$interface"
done done
} }

View file

@ -74,7 +74,7 @@ conf=$VESTA/data/ips/$IP
# Defining fileds to select # Defining fileds to select
fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE
$NETMASK $DATE' $NETMASK $TIME $DATE'
# Listing ip # Listing ip
case $format in case $format in

64
bin/v_list_sys_users Executable file
View file

@ -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

View file

@ -1,7 +1,8 @@
# Validationg ip address # Validationg ip address
is_ip_valid() { is_ip_valid() {
check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip") #check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip")
if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then #if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then
if [ ! -e "$VESTA/data/ips/$ip" ] ; then
echo "Error: IP $ip not exist" echo "Error: IP $ip not exist"
log_event "$E_NOTEXIST" "$EVENT" log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST exit $E_NOTEXIST

88
web/add/ip/index.php Normal file
View file

@ -0,0 +1,88 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'IP';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
if (!empty($_POST['ok'])) {
// Check input
if (empty($_POST['v_ip'])) $errors[] = 'ip address';
if (empty($_POST['v_netmask'])) $errors[] = 'netmask';
if (empty($_POST['v_interface'])) $errors[] = 'interface';
if (empty($_POST['v_owner'])) $errors[] = 'assigned used';
if (empty($_POST['v_interface'])) $errors[] = 'interface';
// Protect input
$v_ip = escapeshellarg($_POST['v_ip']);
$v_netmask = escapeshellarg($_POST['v_netmask']);
$v_name = escapeshellarg($_POST['v_name']);
$v_interface = $_POST['v_interface'];
$v_shared = $_POST['v_shared'];
if ($v_shared == 'on') {
$ip_status = 'shared';
} else {
$ip_status = 'dedicated';
$v_dedicated = 'yes';
}
$v_owner = $_POST['v_owner'];
// Check for errors
if (!empty($errors[0])) {
foreach ($errors as $i => $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('<br>', $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 <b>".$_POST['v_ip']."</b> 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');

16
web/delete/ip/index.php Normal file
View file

@ -0,0 +1,16 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['ip'])) {
$v_ip = escapeshellarg($_GET['ip']);
exec (VESTA_CMD."v_delete_sys_ip ".$v_ip, $output, $return_var);
unset($output);
}
}
header("Location: /list/ip/");

120
web/edit/ip/index.php Normal file
View file

@ -0,0 +1,120 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
$TAB = 'IP';
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Header
include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
// Panel
top_panel($user,$TAB);
// Are you admin?
if ($_SESSION['user'] == 'admin') {
// Check user argument?
if (empty($_GET['ip'])) {
header("Location: /list/ip/");
exit;
}
$v_ip = escapeshellarg($_GET['ip']);
exec (VESTA_CMD."v_list_sys_ip ".$v_ip." 'json'", $output, $return_var);
if ($return_var != 0) {
$error = implode('<br>', $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('<br>', $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('<br>', $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('<br>', $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('<br>', $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');

View file

@ -0,0 +1,74 @@
<script type="text/javascript">
function elementHideShow(elementToHideOrShow)
{
var el = document.getElementById(elementToHideOrShow);
if (el.style.display == "block") {
el.style.display = "none";
} else {
el.style.display = "block";
}
}
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 10;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
document.getElementById('v_password').value = randomstring;
}
</script>
<table class='data'>
<tr class="data-add">
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
<table class="data-col1">
<tr><td style="padding: 18 0 4 18;"></td></tr>
</table>
</td>
<td class="data-dotted" width="830px" style="vertical-align:top;">
<table width="830px"><tr>
<td></td>
</tr></table>
<table class="data-col2" width="600px">
<form method="post" name="v_add_user">
<tr><td class="add-text" style="padding: 10 0 0 2px;">IP</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_ip" <?php if (!empty($v_ip)) echo "value=".$v_ip; ?>></td></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Netmask</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_netmask" <?php if (!empty($v_netmask)) echo "value=".$v_netmask; ?>></tr>
<tr><td class="add-text" style="padding: 10 0 0 2px;">Interface</td></tr>
<tr><td><select class="add-list" name="v_interface">
<?php
foreach ($interfaces as $key => $value) {
echo "\t\t\t\t<option value=\"".$value."\"";
if ((!empty($v_interface)) && ( $value == $v_interface )) echo ' selected';
echo ">".$value."</option>\n";
}
?>
</select></td></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Shared</td></tr>
<tr><td><input type="checkbox" size="20" class="add-checkbox" name="v_shared" <?php if (empty($v_dedicated)) echo "checked=yes" ?> onclick="javascript:elementHideShow('usrtable');"></tr>
<tr><td><table style="display:<?php if (empty($v_dedicated)) { echo 'none';} else {echo 'block';}?> ;" id="usrtable"><tr>
<tr><td class="add-text" style="padding: 0 0 0 2px;">Assigned User</td></tr>
<tr><td><select class="add-list" name="v_owner">
<?php
foreach ($users as $key => $value) {
echo "\t\t\t\t<option value=\"".$value."\"";
if ((!empty($v_owner)) && ( $value == $v_owner )) echo ' selected';
echo ">".$value."</option>\n";
}
?>
</select></td></tr>
</table></td></tr>
<tr><td class="add-text" style="padding: 10 0 0 2px;">Associated Domain <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(optional)</span></td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_name" <?php if (!empty($v_name)) echo "value=".$v_name; ?>></td></tr>
<tr><td style="padding: 24px 0 0 0;">
<input type="submit" name="ok" value="OK" class="add-button"></form>
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/ip/'">
</td></tr>
</table>
</td>
</tr>
</table>

View file

@ -0,0 +1,66 @@
<script type="text/javascript">
function elementHideShow(elementToHideOrShow)
{
var el = document.getElementById(elementToHideOrShow);
if (el.style.display == "block") {
el.style.display = "none";
} else {
el.style.display = "block";
}
}
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 10;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
document.getElementById('v_password').value = randomstring;
}
</script>
<table class='data'>
<tr class="data-add">
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
<table class="data-col1">
<tr><td style="padding: 24px 0 2px 4px;"><a class="data-date" ?><?php echo date("d M Y", strtotime($v_date))?></a></td></tr>
<tr><td style="padding: 0 0 6px 4px;"><a class="data-date" ?><?php echo $v_time?></a></td></tr>
<tr><td style="padding: 0 0 0 21px;" class="data-<?php echo $v_status ?>"><b><?php echo $v_status ?></b></td></tr>
</table>
</td>
<td class="data-dotted" width="830px" style="vertical-align:top;">
<table width="830px"><tr>
<td></td>
</tr></table>
<table class="data-col2" width="600px">
<form method="post" name="v_add_user">
<tr><td class="add-text" style="padding: 10 0 0 2px;">IP</td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_ip" <?php if (!empty($v_ip)) echo "value=".$v_ip; ?> disabled> <input type="hidden" name="v_ip" <?php if (!empty($v_ip)) echo "value=".$v_ip; ?>></td></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Netmask</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_netmask" <?php if (!empty($v_netmask)) echo "value=".$v_netmask; ?> disabled></tr>
<tr><td class="add-text" style="padding: 10 0 0 2px;">Interface</td></tr>
<tr><td></span><input type="text" size="20" class="add-input" name="v_netmask" <?php if (!empty($v_interace)) echo "value=".$v_interace; ?> disabled></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Shared</td></tr>
<tr><td><input type="checkbox" size="20" class="add-checkbox" name="v_shared" <?php if (empty($v_dedicated)) echo "checked=yes" ?></tr>
<tr><td class="add-text" style="padding: 10px 0 0 2px;">Assigned User</td></tr>
<tr><td><select class="add-list" name="v_owner">
<?php
foreach ($users as $key => $value) {
echo "\t\t\t\t<option value=\"".$value."\"";
if ((!empty($v_owner)) && ( $value == $v_owner )) echo ' selected';
echo ">".$value."</option>\n";
}
?>
</select></td></tr>
<tr><td class="add-text" style="padding: 10 0 0 2px;">Associated Domain <span style="padding:0 0 0 6px; font-size: 10pt; color:#555;">(optional)</span></td></tr>
<tr><td><input type="text" size="20" class="add-input" name="v_name" <?php if (!empty($v_name)) echo "value=".$v_name; ?>></td></tr>
<tr><td style="padding: 24px 0 0 0;">
<input type="submit" name="save" value="Save" class="add-button"></form>
<input type="button" class="add-button" value="Cancel" onClick="location.href='/list/ip/'">
</td></tr>
</table>
</td>
</tr>
</table>

View file

@ -4,6 +4,28 @@
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
++$i; ++$i;
?> ?>
<script type="text/javascript">
$(function(){
$('#delete_dialog_<?php echo "$i" ?>').dialog({
modal: true,
autoOpen: false,
width: 360,
buttons: {
"Ok": function(event, ui) {
location.href = '/delete/ip/?ip=<?php echo "$key" ?>';
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
$('#delete_link_<?php echo "$i" ?>').click(function(){
$('#delete_dialog_<?php echo "$i" ?>').dialog('open');
return false;
});
});
</script>
<tr class="data-row"> <tr class="data-row">
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150"> <td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
@ -16,7 +38,14 @@ foreach ($data as $key => $value) {
<td class="data-dotted" width="830px" style="vertical-align:top;"> <td class="data-dotted" width="830px" style="vertical-align:top;">
<table width="830px"><tr> <table width="830px"><tr>
<td></td> <td></td>
<td class="data-controls" width="70px"><img src="/images/delete.png" width="7px" height="7px"><a href="#"> delete</a></td> <td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="/edit/ip/?ip=<?php echo "$key" ?>"> edit</a></td>
<td class="data-controls" width="70px">
<img src="/images/delete.png" width="7px" height="7px">
<a href="#" id="delete_link_<?php echo $i ?>"> delete</a>
<div id="delete_dialog_<?php echo $i ?>" title="Confirmation">
<p class="counter-value">Are you sure you want to delete <b><?php echo "$key" ?></b> ip?</p>
</div>
</td>
</tr></table> </tr></table>
<table class="data-col2" width="830px"> <table class="data-col2" width="830px">

View file

@ -0,0 +1,15 @@
<table class="sub-menu">
<tr>
<td style="padding: 14px 0 24px 0;" ><a class="add-name"><b>Adding IP Address</b></a>
<?php
if (!empty($_SESSION['error_msg'])) {
echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
} else {
if (!empty($_SESSION['ok_msg'])) {
echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
}
}
?>
</td>
</tr>
</table>

View file

@ -0,0 +1,15 @@
<table class="sub-menu">
<tr>
<td style="padding: 14px 0 24px 0;" ><a class="add-name"><b>Editing IP Address</b></a>
<?php
if (!empty($_SESSION['error_msg'])) {
echo "<a class=\"add-error\"> → ".$_SESSION['error_msg']."</a>";
} else {
if (!empty($_SESSION['ok_msg'])) {
echo "<a class=\"add-ok\"> → ".$_SESSION['ok_msg']."</a>";
}
}
?>
</td>
</tr>
</table>