index.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // Check user
  9. if ($_SESSION['user'] != 'admin') {
  10. header("Location: /list/user");
  11. exit;
  12. }
  13. // Check POST request
  14. if (!empty($_POST['ok'])) {
  15. // Check empty fields
  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. if (!empty($errors[0])) {
  21. foreach ($errors as $i => $error) {
  22. if ( $i == 0 ) {
  23. $error_msg = $error;
  24. } else {
  25. $error_msg = $error_msg.", ".$error;
  26. }
  27. }
  28. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  29. }
  30. // Protect input
  31. $v_ip = escapeshellarg($_POST['v_ip']);
  32. $v_netmask = escapeshellarg($_POST['v_netmask']);
  33. $v_name = escapeshellarg($_POST['v_name']);
  34. $v_nat = escapeshellarg($_POST['v_nat']);
  35. $v_interface = escapeshellarg($_POST['v_interface']);
  36. $v_owner = escapeshellarg($_POST['v_owner']);
  37. $v_shared = $_POST['v_shared'];
  38. // Check shared checkmark
  39. if ($v_shared == 'on') {
  40. $ip_status = 'shared';
  41. } else {
  42. $ip_status = 'dedicated';
  43. $v_dedicated = 'yes';
  44. }
  45. // Add IP
  46. if (empty($_SESSION['error_msg'])) {
  47. exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name." ".$v_nat, $output, $return_var);
  48. check_return_code($return_var,$output);
  49. unset($output);
  50. $v_owner = $_POST['v_owner'];
  51. $v_interface = $_POST['v_interface'];
  52. }
  53. // Flush field values on success
  54. if (empty($_SESSION['error_msg'])) {
  55. $_SESSION['ok_msg'] = __('IP_CREATED_OK',$_POST['v_ip'],$_POST['v_ip']);
  56. unset($v_ip);
  57. unset($v_netmask);
  58. unset($v_name);
  59. unset($v_nat);
  60. }
  61. }
  62. // Header
  63. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  64. // Panel
  65. top_panel($user,$TAB);
  66. // List network interfaces
  67. exec (VESTA_CMD."v-list-sys-interfaces 'json'", $output, $return_var);
  68. $interfaces = json_decode(implode('', $output), true);
  69. unset($output);
  70. // List users
  71. exec (VESTA_CMD."v-list-sys-users 'json'", $output, $return_var);
  72. $users = json_decode(implode('', $output), true);
  73. unset($output);
  74. // Display body
  75. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html');
  76. // Flush session messages
  77. unset($_SESSION['error_msg']);
  78. unset($_SESSION['ok_msg']);
  79. // Footer
  80. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');