index.php 2.7 KB

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