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

Last change on this file since 31463 was 31463, checked in by kong, 2 months ago

fix reported nvram size for alpine

File size: 2.2 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_ALPINE
39#define NVRAMSPACE 0x20000
40#elif HAVE_IPQ806X
41#define NVRAMSPACE 0x10000
42#else
43#define NVRAMSPACE NVRAM_SPACE
44#endif
45
46int http_stats(const char *url)
47{
48        char *buf, *s;
49        char **cur;
50        char *secrets[] = { "os_server", "stats_server", "http_passwd", NULL };
51        char *files[] = { "/proc/version", "/proc/meminfo", "/proc/cpuinfo",
52                "/proc/interrupts",
53                "/proc/net/dev", "/proc/net/pppoe", "/proc/net/snmp", NULL
54        };
55        char *contents;
56
57        if (!(buf = safe_malloc(NVRAMSPACE)))
58                return errno;
59
60        /*
61         * Get NVRAM variables
62         */
63        nvram_getall(buf, NVRAMSPACE);
64        for (s = buf; *s; s++) {
65                for (cur = secrets; *cur; cur++) {
66                        if (!strncmp(s, *cur, strlen(*cur))) {
67                                s += strlen(*cur) + 1;
68                                while (*s)
69                                        *s++ = '*';
70                                break;
71                        }
72                }
73                *(s += strlen(s)) = '&';
74        }
75
76        /*
77         * Dump interesting /proc entries
78         */
79        for (cur = files; *cur; cur++) {
80                if ((contents = file2str(*cur))) {
81                        s += snprintf(s, buf + BUFSPACE - s, "%s=%s&", *cur, contents);
82                        free(contents);
83                }
84        }
85
86        /*
87         * Report uptime
88         */
89        s += snprintf(s, buf + BUFSPACE - s, "uptime=%lu&", (unsigned long)time(NULL));
90
91        /*
92         * Save
93         */
94        s += snprintf(s, buf + BUFSPACE - s, "action=save");
95        buf[BUFSPACE - 1] = '\0';
96
97        /*
98         * Post to server
99         */
100        http_post(url ? : nvram_safe_get("stats_server"), buf, BUFSPACE);
101
102        free(buf);
103        return 0;
104}
Note: See TracBrowser for help on using the repository browser.