From cc78a698a2e6c9f7a9bb744b46157f184f040cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Wed, 15 Apr 2015 14:16:19 +0200 Subject: [PATCH] Use rpc call directly --- luci2/luci2/htdocs/luci2/view/status.dsl.js | 13 +++----- luci2/luci2/share/acl.d/luci2.json | 6 ++-- luci2/luci2/src/rpcd/luci2.c | 37 --------------------- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/luci2/luci2/htdocs/luci2/view/status.dsl.js b/luci2/luci2/htdocs/luci2/view/status.dsl.js index 3bd6fed6c..60d821973 100644 --- a/luci2/luci2/htdocs/luci2/view/status.dsl.js +++ b/luci2/luci2/htdocs/luci2/view/status.dsl.js @@ -3,18 +3,15 @@ L.ui.view.extend({ description: L.tr('Router ADSL status.'), getDSLStatus: L.rpc.declare({ - object: 'luci2.network', + object: 'router', method: 'dslstats', - expect: { data: '' } + expect: { dslstats: {} } }), execute: function() { - return this.getDSLStatus().then(function(data){ - var dslstats = {}; - try { dslstats = JSON.parse(data); } catch(e){} - + return this.getDSLStatus().then(function(dslstats){ // todo fields - with({dslstats: dslstats.dslstats}){ + with({dslstats: dslstats}){ dslstats.ip = "TODO"; dslstats.ipstate = "TODO"; dslstats.mode_details = "TODO"; @@ -54,7 +51,7 @@ L.ui.view.extend({ var model = $(this).attr("ng-model"); try { if(model) { - with({dslstats: dslstats.dslstats}) { + with({dslstats: dslstats}) { $(this).html(eval(model)); } } diff --git a/luci2/luci2/share/acl.d/luci2.json b/luci2/luci2/share/acl.d/luci2.json index f0fbfeace..a33113f9a 100644 --- a/luci2/luci2/share/acl.d/luci2.json +++ b/luci2/luci2/share/acl.d/luci2.json @@ -38,6 +38,9 @@ "assoclist", "phyname" ], + "router": [ + "dslstats" + ], "system": [ "info", "board" @@ -51,8 +54,7 @@ "dhcp6_leases", "arp_table", "routes", - "routes6", - "dslstats" + "routes6" ], "luci2.system": [ "diskfree", diff --git a/luci2/luci2/src/rpcd/luci2.c b/luci2/luci2/src/rpcd/luci2.c index d585972d9..427992868 100644 --- a/luci2/luci2/src/rpcd/luci2.c +++ b/luci2/luci2/src/rpcd/luci2.c @@ -1119,33 +1119,6 @@ backup_finish_list(struct blob_buf *blob, int status, void *priv) } -static int rpc_run_command(struct ubus_context *ctx, struct ubus_request_data *req, const char *cmd){ - FILE *fd; - int buffer_size = 4096; - char *data = malloc(buffer_size); - char *pdata = data; - int c; - - blob_buf_init(&buf, 0); - if ((fd = popen("ubus call router dslstats", "r"))) { - while((c = fgetc(fd)) != EOF){ - *pdata = c; - pdata++; - if(pdata == (data + buffer_size)){ - size_t size = buffer_size; - buffer_size += 4096; - data = realloc(data, buffer_size); - pdata = data + size; - } - } - pclose(fd); - } - blobmsg_add_string(&buf, "data", data); - free(data); - ubus_send_reply(ctx, req, buf.head); - return 0; -} - static int rpc_luci2_backup_list(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -1842,15 +1815,6 @@ rpc_luci2_network_sw_list(struct ubus_context *ctx, struct ubus_object *obj, state, ctx, req); } -static int -rpc_luci2_network_dslstats(struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, const char *method, - struct blob_attr *msg) -{ - return rpc_run_command(ctx, req, "ubus call router dslstats"); -} - - static int swconfig_parse_help(struct blob_buf *blob, char *buf, int len, void *priv) { @@ -2844,7 +2808,6 @@ rpc_luci2_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx) UBUS_METHOD_NOARG("routes", rpc_luci2_network_routes), UBUS_METHOD_NOARG("routes6", rpc_luci2_network_routes6), UBUS_METHOD_NOARG("switch_list", rpc_luci2_network_sw_list), - UBUS_METHOD_NOARG("dslstats", rpc_luci2_network_dslstats), UBUS_METHOD("switch_info", rpc_luci2_network_sw_info, rpc_switch_policy), UBUS_METHOD("switch_status", rpc_luci2_network_sw_status,