Use rpc call directly

This commit is contained in:
Martin Schröder 2015-04-15 14:16:19 +02:00 committed by Martin Schröder
parent d6dd3bec0c
commit cc78a698a2
3 changed files with 9 additions and 47 deletions

View file

@ -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));
}
}

View file

@ -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",

View file

@ -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,