index.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_nat = escapeshellarg($_POST['v_nat']);
  25. $v_interface = $_POST['v_interface'];
  26. $v_shared = $_POST['v_shared'];
  27. if ($v_shared == 'on') {
  28. $ip_status = 'shared';
  29. } else {
  30. $ip_status = 'dedicated';
  31. $v_dedicated = 'yes';
  32. }
  33. $v_owner = $_POST['v_owner'];
  34. // Check for errors
  35. if (!empty($errors[0])) {
  36. foreach ($errors as $i => $error) {
  37. if ( $i == 0 ) {
  38. $error_msg = $error;
  39. } else {
  40. $error_msg = $error_msg.", ".$error;
  41. }
  42. }
  43. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  44. } else {
  45. // Add IP
  46. $v_interface = escapeshellarg($_POST['v_interface']);
  47. $v_owner = $_POST['v_owner'];
  48. exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name." ".$v_nat, $output, $return_var);
  49. $v_owner = $_POST['v_owner'];
  50. $v_interface = $_POST['v_interface'];
  51. check_return_code($return_var,$output);
  52. unset($output);
  53. if (empty($_SESSION['error_msg'])) {
  54. $_SESSION['ok_msg'] = __('IP_CREATED_OK',$_POST['v_ip'],$_POST['v_ip']);
  55. unset($v_ip);
  56. unset($v_netmask);
  57. unset($v_name);
  58. unset($v_nat);
  59. }
  60. }
  61. }
  62. exec (VESTA_CMD."v-list-sys-interfaces 'json'", $output, $return_var);
  63. $interfaces = json_decode(implode('', $output), true);
  64. unset($output);
  65. exec (VESTA_CMD."v-list-sys-users 'json'", $output, $return_var);
  66. $users = json_decode(implode('', $output), true);
  67. unset($output);
  68. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html');
  69. unset($_SESSION['error_msg']);
  70. unset($_SESSION['ok_msg']);
  71. }
  72. // Footer
  73. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');