index.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. ob_start();
  3. $TAB = 'FIREWALL';
  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_ipname'])) {
  17. $errors[] = _('Name');
  18. }
  19. if (empty($_POST['v_datasource'])) {
  20. $errors[] = _('Data Source');
  21. }
  22. if (empty($_POST['v_ipver'])) {
  23. $errors[] = _('Ip Version');
  24. }
  25. if (empty($_POST['v_autoupdate'])) {
  26. $errors[] = _('Autoupdate');
  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. $v_ipname = $_POST['v_ipname'];
  39. $v_datasource = $_POST['v_datasource'];
  40. $v_ipver = $_POST['v_ipver'];
  41. $v_autoupdate = $_POST['v_autoupdate'];
  42. // Add firewall ipset list
  43. if (empty($_SESSION['error_msg'])) {
  44. exec(HESTIA_CMD."v-add-firewall-ipset ".escapeshellarg($v_ipname)." ".escapeshellarg($v_datasource)." ".escapeshellarg($v_ipver)." ".escapeshellarg($v_autoupdate), $output, $return_var);
  45. check_return_code($return_var, $output);
  46. unset($output);
  47. }
  48. // Flush field values on success
  49. if (empty($_SESSION['error_msg'])) {
  50. $_SESSION['ok_msg'] = _('IPSET_CREATED_OK');
  51. }
  52. }
  53. // Render
  54. render_page($user, $TAB, 'add_firewall_ipset');
  55. // Flush session messages
  56. unset($_SESSION['error_msg']);
  57. unset($_SESSION['ok_msg']);