index.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_interface = escapeshellarg($_POST['v_interface']);
  45. $v_owner = escapeshellarg($_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." ".escapeshellarg($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. // Render
  80. render_page($user, $TAB, 'add_ip');
  81. // Flush session messages
  82. unset($_SESSION['error_msg']);
  83. unset($_SESSION['ok_msg']);