index.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. error_reporting(NULL);
  3. ob_start();
  4. $TAB = 'IP';
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Check user
  8. if ($_SESSION['user'] != 'admin') {
  9. header("Location: /list/user");
  10. exit;
  11. }
  12. // Check POST request
  13. if (!empty($_POST['ok'])) {
  14. // Check token
  15. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  16. header('location: /login/');
  17. exit();
  18. }
  19. // Check empty fields
  20. if (empty($_POST['v_ip'])) $errors[] = __('ip address');
  21. if (empty($_POST['v_netmask'])) $errors[] = __('netmask');
  22. if (empty($_POST['v_interface'])) $errors[] = __('interface');
  23. if (empty($_POST['v_owner'])) $errors[] = __('assigned user');
  24. if (!empty($errors[0])) {
  25. foreach ($errors as $i => $error) {
  26. if ( $i == 0 ) {
  27. $error_msg = $error;
  28. } else {
  29. $error_msg = $error_msg.", ".$error;
  30. }
  31. }
  32. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  33. }
  34. // Protect input
  35. $v_ip = escapeshellarg($_POST['v_ip']);
  36. $v_netmask = escapeshellarg($_POST['v_netmask']);
  37. $v_name = escapeshellarg($_POST['v_name']);
  38. $v_nat = escapeshellarg($_POST['v_nat']);
  39. $v_interface = escapeshellarg($_POST['v_interface']);
  40. $v_owner = escapeshellarg($_POST['v_owner']);
  41. $v_shared = $_POST['v_shared'];
  42. // Check shared checkmark
  43. if ($v_shared == 'on') {
  44. $ip_status = 'shared';
  45. } else {
  46. $ip_status = 'dedicated';
  47. $v_dedicated = 'yes';
  48. }
  49. // Add IP
  50. if (empty($_SESSION['error_msg'])) {
  51. exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." ".$ip_status." ".$v_name." ".$v_nat, $output, $return_var);
  52. check_return_code($return_var,$output);
  53. unset($output);
  54. $v_owner = $_POST['v_owner'];
  55. $v_interface = $_POST['v_interface'];
  56. }
  57. // Flush field values on success
  58. if (empty($_SESSION['error_msg'])) {
  59. $_SESSION['ok_msg'] = __('IP_CREATED_OK',htmlentities($_POST['v_ip']),htmlentities($_POST['v_ip']));
  60. unset($v_ip);
  61. unset($v_netmask);
  62. unset($v_name);
  63. unset($v_nat);
  64. }
  65. }
  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. // Render
  75. render_page($user, $TAB, 'add_ip');
  76. // Flush session messages
  77. unset($_SESSION['error_msg']);
  78. unset($_SESSION['ok_msg']);