index.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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['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 = escapeshellarg($_POST['v_ip']);
  41. $v_netmask = escapeshellarg($_POST['v_netmask']);
  42. $v_name = escapeshellarg($_POST['v_name']);
  43. $v_nat = escapeshellarg($_POST['v_nat']);
  44. $v_helo = escapeshellarg($_POST['v_helo']);
  45. $v_interface = escapeshellarg($_POST['v_interface']);
  46. $v_owner = escapeshellarg($_POST['v_owner']);
  47. $v_shared = $_POST['v_shared'];
  48. // Check shared checkmark
  49. if ($v_shared == 'on') {
  50. $ip_status = 'shared';
  51. } else {
  52. $ip_status = 'dedicated';
  53. $v_dedicated = 'yes';
  54. }
  55. // Add IP
  56. if (empty($_SESSION['error_msg'])) {
  57. exec(HESTIA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." ".escapeshellarg($ip_status)." ".$v_name." ".$v_nat." ".$v_helo, $output, $return_var);
  58. check_return_code($return_var, $output);
  59. unset($output);
  60. $v_owner = $_POST['v_owner'];
  61. $v_interface = $_POST['v_interface'];
  62. }
  63. // Flush field values on success
  64. if (empty($_SESSION['error_msg'])) {
  65. $_SESSION['ok_msg'] = sprintf(_('IP_CREATED_OK'), htmlentities($_POST['v_ip']), htmlentities($_POST['v_ip']));
  66. unset($v_ip);
  67. unset($v_netmask);
  68. unset($v_name);
  69. unset($v_nat);
  70. unset($v_helo);
  71. }
  72. }
  73. // List network interfaces
  74. exec(HESTIA_CMD."v-list-sys-interfaces 'json'", $output, $return_var);
  75. $interfaces = json_decode(implode('', $output), true);
  76. unset($output);
  77. // List users
  78. exec(HESTIA_CMD."v-list-sys-users 'json'", $output, $return_var);
  79. $users = json_decode(implode('', $output), true);
  80. unset($output);
  81. // Render
  82. render_page($user, $TAB, 'add_ip');
  83. // Flush session messages
  84. unset($_SESSION['error_msg']);
  85. unset($_SESSION['ok_msg']);