72_pbr.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "require ui";
  2. "require rpc";
  3. "require form";
  4. "require baseclass";
  5. "require pbr.status as pbr";
  6. var pkg = pbr.pkg;
  7. return baseclass.extend({
  8. title: _("Policy Based Routing"),
  9. load: function () {
  10. return Promise.all([pbr.getInitStatus(pkg.Name)]);
  11. },
  12. render: function (data) {
  13. var reply;
  14. if (data[0] && data[0][pkg.Name]) {
  15. reply = data[0][pkg.Name];
  16. } else {
  17. reply = {
  18. enabled: null,
  19. running: null,
  20. running_iptables: null,
  21. running_nft: null,
  22. running_nft_file: null,
  23. version: null,
  24. gateways: null,
  25. errors: [],
  26. warnings: [],
  27. };
  28. }
  29. var versionText,
  30. statusText = "",
  31. modeText = "";
  32. if (reply.version) {
  33. versionText = reply.version;
  34. if (reply.running) {
  35. statusText = _("Active");
  36. if (reply.running_iptables) {
  37. modeText = _("iptables mode");
  38. } else if (reply.running_nft_file) {
  39. modeText = _("fw4 nft file mode");
  40. } else if (reply.running_nft) {
  41. modeText = _("nft mode");
  42. } else {
  43. modeText = _("unknown");
  44. }
  45. } else {
  46. if (reply.enabled) {
  47. statusText = _("Inactive");
  48. } else {
  49. statusText = _("Inactive (Disabled)");
  50. }
  51. }
  52. } else {
  53. versionText = _("Not installed or not found");
  54. }
  55. var table = E("table", { class: "table", id: "pbr_status_table" }, [
  56. E("tr", { class: "tr table-titles" }, [
  57. E("th", { class: "th" }, _("Status")),
  58. E("th", { class: "th" }, _("Version")),
  59. E("th", { class: "th" }, _("Mode")),
  60. ]),
  61. E("tr", { class: "tr" }, [
  62. E("td", { class: "td" }, statusText),
  63. E("td", { class: "td" }, versionText),
  64. E("td", { class: "td" }, modeText),
  65. ]),
  66. ]);
  67. return table;
  68. },
  69. });