index.php 2.9 KB

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