| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/usr/bin/env ucode
- // SPDX-License-Identifier: GPL-2.0+
- /*
- * Copyright (C) 2025 Felix Fietkau <[email protected]>
- */
- 'use strict';
- import * as libubus from "ubus";
- import * as uloop from "uloop";
- import * as unetmsg_core from "unetmsg.unetmsgd";
- uloop.init();
- let ubus = libubus.connect();
- if (!ubus) {
- warn(`Failed to connect to ubus\n`);
- exit(1);
- }
- let core = unetmsg_core.init(ubus, true);
- function update_acl() {
- let data = ubus.call(libubus.SYSTEM_OBJECT_ACL, "query");
- core.acl_set(data.acl);
- }
- let obj = ubus.publish("unetmsg", {
- channel: {
- args: {},
- call: function(req) {
- if (!core.client.new(req))
- return libubus.STATUS_INVALID_ARGUMENT;
- return 0;
- }
- },
- list: {
- args: {
- name: "",
- },
- call: function(req) {
- let ret = [];
- for (let name in { ...core.publish, ...core.remote_publish })
- if (req.args.name == null || wildcard(name, req.args.name))
- push(ret, name);
- return {
- id: sort(ret),
- };
- },
- },
- request: {
- args: {
- name: "",
- type: "",
- host: "",
- data: {},
- },
- call: function(req) {
- try {
- let host = req.args.host;
- delete req.args.host;
- core.handle_request(null, req, req.args, true, host);
- } catch (e) {
- core.exception(e);
- }
- }
- }
- });
- ubus.subscriber("ubus.acl.sequence", () => update_acl());
- update_acl();
- uloop.run();
|