unetmsgd 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env ucode
  2. // SPDX-License-Identifier: GPL-2.0+
  3. /*
  4. * Copyright (C) 2025 Felix Fietkau <[email protected]>
  5. */
  6. 'use strict';
  7. import * as libubus from "ubus";
  8. import * as uloop from "uloop";
  9. import * as unetmsg_core from "unetmsg.unetmsgd";
  10. uloop.init();
  11. let ubus = libubus.connect();
  12. if (!ubus) {
  13. warn(`Failed to connect to ubus\n`);
  14. exit(1);
  15. }
  16. let core = unetmsg_core.init(ubus, true);
  17. function update_acl() {
  18. let data = ubus.call(libubus.SYSTEM_OBJECT_ACL, "query");
  19. core.acl_set(data.acl);
  20. }
  21. let obj = ubus.publish("unetmsg", {
  22. channel: {
  23. args: {},
  24. call: function(req) {
  25. if (!core.client.new(req))
  26. return libubus.STATUS_INVALID_ARGUMENT;
  27. return 0;
  28. }
  29. },
  30. list: {
  31. args: {
  32. name: "",
  33. },
  34. call: function(req) {
  35. let ret = [];
  36. for (let name in { ...core.publish, ...core.remote_publish })
  37. if (req.args.name == null || wildcard(name, req.args.name))
  38. push(ret, name);
  39. return {
  40. id: sort(ret),
  41. };
  42. },
  43. },
  44. request: {
  45. args: {
  46. name: "",
  47. type: "",
  48. host: "",
  49. data: {},
  50. },
  51. call: function(req) {
  52. try {
  53. let host = req.args.host;
  54. delete req.args.host;
  55. core.handle_request(null, req, req.args, true, host);
  56. } catch (e) {
  57. core.exception(e);
  58. }
  59. }
  60. }
  61. });
  62. ubus.subscriber("ubus.acl.sequence", () => update_acl());
  63. update_acl();
  64. uloop.run();