source: src/router/httpd/modules/stats.c @ 31689

Last change on this file since 31689 was 31689, checked in by brainslayer, 2 months ago

increase nvram size for wdr4900

File size: 2.3 KB
Line 
1/*
2 * Support for router statistics gathering
3 *
4 * Copyright 2001-2003, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
11 *
12 * $Id: stats.c,v 1.2 2005/11/11 09:26:18 seg Exp $
13 */
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <limits.h>
18#include <ctype.h>
19#include <string.h>
20#include <signal.h>
21#include <time.h>
22#include <unistd.h>
23#include <errno.h>
24
25#include <bcmnvram.h>
26#include <shutils.h>
27
28extern int http_post(const char *server, char *buf, size_t count);
29
30#define BUFSPACE 50000
31
32#ifdef NVRAM_SPACE_256
33#define NVRAMSPACE NVRAM_SPACE_256
34#elif HAVE_NVRAM_128
35#define NVRAMSPACE 0x20000
36#elif HAVE_MVEBU
37#define NVRAMSPACE 0x10000
38#elif HAVE_WDR4900
39#define NVRAMSPACE 0x20000
40#elif HAVE_ALPINE
41#define NVRAMSPACE 0x20000
42#elif HAVE_IPQ806X
43#define NVRAMSPACE 0x10000
44#else
45#define NVRAMSPACE NVRAM_SPACE
46#endif
47
48int http_stats(const char *url)
49{
50        char *buf, *s;
51        char **cur;
52        char *secrets[] = { "os_server", "stats_server", "http_passwd", NULL };
53        char *files[] = { "/proc/version", "/proc/meminfo", "/proc/cpuinfo",
54                "/proc/interrupts",
55                "/proc/net/dev", "/proc/net/pppoe", "/proc/net/snmp", NULL
56        };
57        char *contents;
58
59        if (!(buf = safe_malloc(NVRAMSPACE)))
60                return errno;
61
62        /*
63         * Get NVRAM variables
64         */
65        nvram_getall(buf, NVRAMSPACE);
66        for (s = buf; *s; s++) {
67                for (cur = secrets; *cur; cur++) {
68                        if (!strncmp(s, *cur, strlen(*cur))) {
69                                s += strlen(*cur) + 1;
70                                while (*s)
71                                        *s++ = '*';
72                                break;
73                        }
74                }
75                *(s += strlen(s)) = '&';
76        }
77
78        /*
79         * Dump interesting /proc entries
80         */
81        for (cur = files; *cur; cur++) {
82                if ((contents = file2str(*cur))) {
83                        s += snprintf(s, buf + BUFSPACE - s, "%s=%s&", *cur, contents);
84                        free(contents);
85                }
86        }
87
88        /*
89         * Report uptime
90         */
91        s += snprintf(s, buf + BUFSPACE - s, "uptime=%lu&", (unsigned long)time(NULL));
92
93        /*
94         * Save
95         */
96        s += snprintf(s, buf + BUFSPACE - s, "action=save");
97        buf[BUFSPACE - 1] = '\0';
98
99        /*
100         * Post to server
101         */
102        http_post(url ? : nvram_safe_get("stats_server"), buf, BUFSPACE);
103
104        free(buf);
105        return 0;
106}
Note: See TracBrowser for help on using the repository browser.