+
+ if ((f = fopen("/proc/cpuinfo", "r")) != NULL)
+ {
+ while(fgets(line, sizeof(line), f))
+ {
+ key = strtok(line, "\t:");
+ val = strtok(NULL, "\t\n");
+
+ if (!key || !val)
+ continue;
+
+ if (!strcasecmp(key, "system type") ||
+ !strcasecmp(key, "processor") ||
+ !strcasecmp(key, "model name"))
+ {
+ blobmsg_add_string(&b, "system", val + 2);
+ break;
+ }
+ }
+
+ fclose(f);
+ }
+
+ if ((f = fopen("/tmp/sysinfo/model", "r")) != NULL)
+ {
+ if (fgets(line, sizeof(line), f))
+ {
+ val = strtok(line, "\t\n");
+
+ if (val)
+ blobmsg_add_string(&b, "model", val);
+ }
+
+ fclose(f);
+ }
+ else if ((f = fopen("/proc/cpuinfo", "r")) != NULL)
+ {
+ while(fgets(line, sizeof(line), f))
+ {
+ key = strtok(line, "\t:");
+ val = strtok(NULL, "\t\n");
+
+ if (!key || !val)
+ continue;
+
+ if (!strcasecmp(key, "machine") ||
+ !strcasecmp(key, "hardware"))
+ {
+ blobmsg_add_string(&b, "model", val + 2);
+ break;
+ }
+ }
+
+ fclose(f);
+ }
+
+ if ((f = fopen("/etc/openwrt_release", "r")) != NULL)
+ {
+ c = blobmsg_open_table(&b, "release");
+
+ while (fgets(line, sizeof(line), f))
+ {
+ char *dest;
+ char ch;
+
+ key = line;
+ val = strchr(line, '=');
+ if (!val)
+ continue;
+
+ *(val++) = 0;
+
+ if (!strcasecmp(key, "DISTRIB_ID"))
+ key = "distribution";
+ else if (!strcasecmp(key, "DISTRIB_RELEASE"))
+ key = "version";
+ else if (!strcasecmp(key, "DISTRIB_REVISION"))
+ key = "revision";
+ else if (!strcasecmp(key, "DISTRIB_CODENAME"))
+ key = "codename";
+ else if (!strcasecmp(key, "DISTRIB_TARGET"))
+ key = "target";
+ else if (!strcasecmp(key, "DISTRIB_DESCRIPTION"))
+ key = "description";
+ else
+ continue;
+
+ dest = blobmsg_alloc_string_buffer(&b, key, strlen(val));
+ while (val && (ch = *(val++)) != 0) {
+ switch (ch) {
+ case '\'':
+ case '"':
+ next = strchr(val, ch);
+ if (next)
+ *next = 0;
+
+ strcpy(dest, val);
+
+ if (next)
+ val = next + 1;
+
+ dest += strlen(dest);
+ break;
+ case '\\':
+ *(dest++) = *(val++);
+ break;
+ }
+ }
+ blobmsg_add_string_buffer(&b);
+ }
+
+ blobmsg_close_array(&b, c);
+
+ fclose(f);