index.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // Header
  9. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  10. // Panel
  11. top_panel($user,$TAB);
  12. // Are you admin?
  13. if ($_SESSION['user'] == 'admin') {
  14. if (!empty($_POST['ok'])) {
  15. // Check input
  16. if (empty($_POST['v_ip'])) $errors[] = _('ip address');
  17. if (empty($_POST['v_netmask'])) $errors[] = _('netmask');
  18. if (empty($_POST['v_interface'])) $errors[] = _('interface');
  19. if (empty($_POST['v_owner'])) $errors[] = _('assigned user');
  20. // Protect input
  21. $v_ip = escapeshellarg($_POST['v_ip']);
  22. $v_netmask = escapeshellarg($_POST['v_netmask']);
  23. $v_name = escapeshellarg($_POST['v_name']);
  24. $v_interface = $_POST['v_interface'];
  25. $v_shared = $_POST['v_shared'];
  26. if ($v_shared == 'on') {
  27. $ip_status = 'shared';
  28. } else {
  29. $ip_status = 'dedicated';
  30. $v_dedicated = 'yes';
  31. }
  32. $v_owner = $_POST['v_owner'];
  33. // Check for errors
  34. if (!empty($errors[0])) {
  35. foreach ($errors as $i => $error) {
  36. if ( $i == 0 ) {
  37. $error_msg = $error;
  38. } else {
  39. $error_msg = $error_msg.", ".$error;
  40. }
  41. }
  42. $_SESSION['error_msg'] = _('Error: field "%s" can not be blank.',$error_msg);
  43. } else {
  44. // Add IP
  45. $v_interface = escapeshellarg($_POST['v_interface']);
  46. $v_owner = $_POST['v_owner'];
  47. exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name, $output, $return_var);
  48. $v_owner = $_POST['v_owner'];
  49. $v_interface = $_POST['v_interface'];
  50. if ($return_var != 0) {
  51. $error = implode('<br>', $output);
  52. if (empty($error)) $error = _('Error: vesta did not return any output.');
  53. $_SESSION['error_msg'] = $error;
  54. unset($v_password);
  55. unset($output);
  56. } else {
  57. $_SESSION['ok_msg'] = _('IP_CREATED_OK',$_POST['v_ip'],$_POST['v_ip']);
  58. unset($v_ip);
  59. unset($v_netmask);
  60. unset($v_name);
  61. unset($output);
  62. }
  63. }
  64. }
  65. exec (VESTA_CMD."v-list-sys-interfaces 'json'", $output, $return_var);
  66. $interfaces = json_decode(implode('', $output), true);
  67. unset($output);
  68. exec (VESTA_CMD."v-list-sys-users 'json'", $output, $return_var);
  69. $users = json_decode(implode('', $output), true);
  70. unset($output);
  71. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html');
  72. unset($_SESSION['error_msg']);
  73. unset($_SESSION['ok_msg']);
  74. }
  75. // Footer
  76. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');