index.php 2.8 KB

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