Firewalls.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import axios from 'axios';
  2. import { getAuthToken } from 'src/utils/token';
  3. const BASE_URL = window.location.origin;
  4. const usersUri = '/api/v1/list/firewall/index.php';
  5. const addFirewallUri = '/api/v1/add/firewall/index.php';
  6. const firewallInfoUri = '/api/v1/edit/firewall/index.php';
  7. const updateFirewallUri = '/api/v1/edit/firewall/index.php';
  8. const addBanIpsUri = '/api/v1/add/firewall/banlist/index.php';
  9. const banListUri = '/api/v1/list/firewall/banlist/index.php';
  10. export const getFirewallList = () => {
  11. return axios.get(BASE_URL + usersUri);
  12. }
  13. export const getBanList = () => {
  14. return axios.get(BASE_URL + banListUri);
  15. }
  16. export const bulkAction = (action, firewalls) => {
  17. const formData = new FormData();
  18. formData.append("action", action);
  19. formData.append("token", getAuthToken());
  20. firewalls.forEach(firewall => {
  21. formData.append("rule[]", firewall);
  22. });
  23. return axios.post(BASE_URL + '/api/v1/bulk/firewall/', formData);
  24. };
  25. export const handleAction = uri => {
  26. return axios.get(BASE_URL + uri, {
  27. params: {
  28. token: getAuthToken()
  29. }
  30. });
  31. }
  32. export const getBanIps = data => {
  33. let formDataObject = new FormData();
  34. for (let key in data) {
  35. formDataObject.append(key, data[key]);
  36. }
  37. return axios.get(BASE_URL + addBanIpsUri, {
  38. params: {
  39. token: getAuthToken()
  40. }
  41. });
  42. }
  43. export const addBanIp = (data) => {
  44. let formDataObject = new FormData();
  45. for (let key in data) {
  46. formDataObject.append(key, data[key]);
  47. }
  48. return axios.get(BASE_URL + addBanIpsUri, {
  49. params: {
  50. token: getAuthToken()
  51. }
  52. });
  53. }
  54. export const addFirewall = data => {
  55. let formDataObject = new FormData();
  56. for (let key in data) {
  57. formDataObject.append(key, data[key]);
  58. }
  59. return axios.post(BASE_URL + addFirewallUri, formDataObject);
  60. }
  61. export const getFirewallInfo = rule => {
  62. return axios.get(BASE_URL + firewallInfoUri, {
  63. params: {
  64. rule,
  65. token: getAuthToken()
  66. }
  67. });
  68. }
  69. export const updateFirewall = (data, rule) => {
  70. let formDataObject = new FormData();
  71. for (let key in data) {
  72. formDataObject.append(key, data[key]);
  73. }
  74. return axios.post(BASE_URL + updateFirewallUri, formDataObject, {
  75. params: {
  76. rule,
  77. token: getAuthToken()
  78. }
  79. });
  80. }