struct stat s;
void *c, *t;
bool wireless, bridge, tuntap;
- int type;
+ int type, flags;
DIR *d;
FILE *f;
fclose(f);
+ snprintf(path, sizeof(path) - 1, "/sys/class/net/%s/flags", e->d_name);
+
+ if (stat(path, &s) || !S_ISREG(s.st_mode) || !(f = fopen(path, "r")))
+ continue;
+
+ flags = 0;
+ memset(path, 0, sizeof(path));
+
+ if (fread(path, 1, sizeof(path) - 1, f) > 0)
+ flags = strtoul(path, NULL, 16);
+
+ fclose(f);
snprintf(path, sizeof(path) - 1,
"/sys/class/net/%s/wireless", e->d_name);
blobmsg_add_string(&buf, "device", e->d_name);
blobmsg_add_u32(&buf, "type", type);
+ blobmsg_add_u8(&buf, "is_up", flags & 1);
blobmsg_add_u8(&buf, "is_bridge", bridge);
blobmsg_add_u8(&buf, "is_tuntap", tuntap);
blobmsg_add_u8(&buf, "is_wireless", wireless);
return rv;
}
+static bool
+menu_files(struct blob_attr *files)
+{
+ int rem;
+ bool empty = true;
+ struct stat s;
+ struct blob_attr *file;
+
+ blobmsg_for_each_attr(file, files, rem)
+ {
+ empty = false;
+
+ if (blobmsg_type(file) != BLOBMSG_TYPE_STRING)
+ continue;
+
+ if (stat(blobmsg_get_string(file), &s) || !S_ISREG(s.st_mode))
+ continue;
+
+ return true;
+ }
+
+ return empty;
+}
+
static int
rpc_luci2_ui_menu(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_buf item = { 0 };
struct blob_attr *entry, *attr;
struct blob_attr *tb[__RPC_MENU_MAX];
- bool access;
+ bool access, files;
void *c, *d;
blobmsg_parse(rpc_menu_policy, __RPC_MENU_MAX, tb,
blob_for_each_attr(entry, menu.head, rem)
{
- access = true;
+ access = files = true;
blob_buf_init(&item, 0);
d = blobmsg_open_table(&item, blobmsg_name(entry));
if (blob_id(attr) == BLOBMSG_TYPE_ARRAY &&
!strcmp(blobmsg_name(attr), "acls"))
access = menu_access(tb[RPC_MENU_SESSION], attr, &item);
+ else if (blob_id(attr) == BLOBMSG_TYPE_ARRAY &&
+ !strcmp(blobmsg_name(attr), "files"))
+ files = menu_files(attr);
else
blobmsg_add_blob(&item, attr);
}
blobmsg_close_table(&item, d);
- if (access)
+ if (access && files)
blob_for_each_attr(attr, item.head, rem2)
blobmsg_add_blob(&buf, attr);