index.php 2.6 KB

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