diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/apop.c | 84 | ||||
-rw-r--r-- | src/graph.c | 17 | ||||
-rw-r--r-- | src/main.c | 19 | ||||
-rw-r--r-- | src/output.c | 11 | ||||
-rw-r--r-- | src/readconfig.c | 23 | ||||
-rw-r--r-- | src/report.c | 37 | ||||
-rw-r--r-- | src/server.c | 193 | ||||
-rw-r--r-- | src/tagr.h | 41 | ||||
-rw-r--r-- | src/udb.c | 90 | ||||
-rw-r--r-- | src/xhostname.c | 56 |
11 files changed, 487 insertions, 89 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 0db1eb6..996c541 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -17,6 +17,7 @@ | |||
17 | sbin_PROGRAMS=tagr | 17 | sbin_PROGRAMS=tagr |
18 | 18 | ||
19 | tagr_SOURCES=\ | 19 | tagr_SOURCES=\ |
20 | apop.c\ | ||
20 | graph.c\ | 21 | graph.c\ |
21 | grid.c\ | 22 | grid.c\ |
22 | html.gram.y\ | 23 | html.gram.y\ |
@@ -30,7 +31,9 @@ tagr_SOURCES=\ | |||
30 | report.h\ | 31 | report.h\ |
31 | server.c\ | 32 | server.c\ |
32 | stat.c\ | 33 | stat.c\ |
33 | tagr.h | 34 | tagr.h\ |
35 | udb.c\ | ||
36 | xhostname.c | ||
34 | 37 | ||
35 | noinst_HEADERS=html.gram.h | 38 | noinst_HEADERS=html.gram.h |
36 | 39 | ||
diff --git a/src/apop.c b/src/apop.c new file mode 100644 index 0000000..ce423a5 --- /dev/null +++ b/src/apop.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* This file is part of tagr. | ||
2 | Copyright (C) 2009 Sergey Poznyakoff | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #ifdef HAVE_CONFIG_H | ||
18 | # include <config.h> | ||
19 | #endif | ||
20 | |||
21 | #include <unistd.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | #include <tagr.h> | ||
27 | |||
28 | #include <md5.h> | ||
29 | |||
30 | static char *msg_id; | ||
31 | |||
32 | const char * | ||
33 | tagr_auth_init () | ||
34 | { | ||
35 | asprintf (&msg_id, "<%lu.%lu@%s>", | ||
36 | (unsigned long) getpid (), | ||
37 | (unsigned long) time (NULL), | ||
38 | hostname); | ||
39 | return msg_id; | ||
40 | } | ||
41 | |||
42 | static int | ||
43 | verify_apop (const char *password, const char *user_digest) | ||
44 | { | ||
45 | int i; | ||
46 | struct md5_ctx md5context; | ||
47 | unsigned char md5digest[16]; | ||
48 | char buf[sizeof (md5digest) * 2 + 1]; | ||
49 | char *p; | ||
50 | |||
51 | md5_init_ctx (&md5context); | ||
52 | md5_process_bytes (msg_id, strlen (msg_id), &md5context); | ||
53 | md5_process_bytes (password, strlen (password), &md5context); | ||
54 | md5_finish_ctx (&md5context, md5digest); | ||
55 | |||
56 | for (i = 0, p = buf; i < 16; i++, p += 2) | ||
57 | sprintf (p, "%02x", md5digest[i]); | ||
58 | return strcmp (user_digest, buf); | ||
59 | } | ||
60 | |||
61 | int | ||
62 | tagr_auth (const char *username, const char *authstr) | ||
63 | { | ||
64 | int rc = 1; | ||
65 | char *password; | ||
66 | |||
67 | rc = udb_get_password (username, &password); | ||
68 | if (rc == 1) | ||
69 | { | ||
70 | logmsg (L_ERR, _("no such user `%s'"), username); | ||
71 | } | ||
72 | else if (rc == 0) | ||
73 | { | ||
74 | rc = verify_apop (password, authstr); | ||
75 | if (rc) | ||
76 | logmsg (L_ERR, _("authentication failed for `%s'"), | ||
77 | username); | ||
78 | else | ||
79 | verbose (1, _("%s authenticated"), username); | ||
80 | udb_free_password (password); | ||
81 | } | ||
82 | return rc; | ||
83 | } | ||
84 | |||
diff --git a/src/graph.c b/src/graph.c index 1197a7d..02e0586 100644 --- a/src/graph.c +++ b/src/graph.c | |||
@@ -73,7 +73,7 @@ draw_vtext (gdImagePtr graph, int color, const char *text) | |||
73 | int | 73 | int |
74 | draw_graph (FILE *fp, | 74 | draw_graph (FILE *fp, |
75 | struct monitor *mon, | 75 | struct monitor *mon, |
76 | queue_t *dataq, const struct avg_acc *avg, time_t now, | 76 | queue_t *dataq, const struct avg_acc *avg, time_t start, |
77 | int xstep, unsigned long xmax, | 77 | int xstep, unsigned long xmax, |
78 | int growright, | 78 | int growright, |
79 | struct grid_class *xgrid, struct grid_class *ygrid) | 79 | struct grid_class *xgrid, struct grid_class *ygrid) |
@@ -90,7 +90,6 @@ draw_graph (FILE *fp, | |||
90 | int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; | 90 | int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; |
91 | grid_t grid; | 91 | grid_t grid; |
92 | unsigned long ymax = mon->max_rate; | 92 | unsigned long ymax = mon->max_rate; |
93 | time_t start; | ||
94 | 93 | ||
95 | yscale = (double) graph_ysize / ymax; | 94 | yscale = (double) graph_ysize / ymax; |
96 | xscale = (double) graph_xsize / xmax; | 95 | xscale = (double) graph_xsize / xmax; |
@@ -143,13 +142,13 @@ draw_graph (FILE *fp, | |||
143 | n = queue_count (dataq); | 142 | n = queue_count (dataq); |
144 | 143 | ||
145 | /* Incoming traffic */ | 144 | /* Incoming traffic */ |
146 | for (i = n - 1, start = 0; i > 0; i--) | 145 | for (i = n - 1; i > 0; i--) |
147 | { | 146 | { |
148 | struct traffic_history th, tnext; | 147 | struct traffic_history th, tnext; |
149 | 148 | ||
150 | scale_sample (mon, queue_get_ptr (dataq, i), &th); | 149 | scale_sample (mon, queue_get_ptr (dataq, i), &th); |
151 | if (start == 0) | 150 | if (th.time > start) |
152 | start = th.time; | 151 | continue; |
153 | scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); | 152 | scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); |
154 | if (start - tnext.time > xmax) | 153 | if (start - tnext.time > xmax) |
155 | break; | 154 | break; |
@@ -172,13 +171,13 @@ draw_graph (FILE *fp, | |||
172 | 171 | ||
173 | /* Outgoing traffic */ | 172 | /* Outgoing traffic */ |
174 | gdImageSetBrush (graph, brush_out); | 173 | gdImageSetBrush (graph, brush_out); |
175 | for (i = n - 1, start = 0; i > 0; i--) | 174 | for (i = n - 1; i > 0; i--) |
176 | { | 175 | { |
177 | struct traffic_history th, tnext; | 176 | struct traffic_history th, tnext; |
178 | 177 | ||
179 | scale_sample (mon, queue_get_ptr (dataq, i), &th); | 178 | scale_sample (mon, queue_get_ptr (dataq, i), &th); |
180 | if (start == 0) | 179 | if (th.time > start) |
181 | start = th.time; | 180 | continue; |
182 | scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); | 181 | scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); |
183 | if (start - tnext.time > xmax) | 182 | if (start - tnext.time > xmax) |
184 | break; | 183 | break; |
@@ -245,7 +244,7 @@ draw_graph (FILE *fp, | |||
245 | grid_destroy (grid); | 244 | grid_destroy (grid); |
246 | } | 245 | } |
247 | 246 | ||
248 | grid = grid_create (xgrid, dataq, 0, xmax, &now); | 247 | grid = grid_create (xgrid, dataq, 0, xmax, &start); |
249 | if (grid) | 248 | if (grid) |
250 | { | 249 | { |
251 | unsigned long i; | 250 | unsigned long i; |
@@ -57,12 +57,12 @@ char *configfile = TAGR_CONFIGFILE; | |||
57 | char *html_template = TAGR_TEMPLATE; | 57 | char *html_template = TAGR_TEMPLATE; |
58 | char *user; | 58 | char *user; |
59 | char *basedir; | 59 | char *basedir; |
60 | int port; | 60 | char *hostname; |
61 | int sockfd; | ||
62 | int foreground = 0; | 61 | int foreground = 0; |
63 | int single_process_option = 0; | 62 | int single_process_option = 0; |
64 | int verbose_level; | 63 | int verbose_level; |
65 | static int rebuild_option; | 64 | static int rebuild_option; |
65 | static int rebuild_last_option; | ||
66 | 66 | ||
67 | static int import_option; | 67 | static int import_option; |
68 | static int read_option; | 68 | static int read_option; |
@@ -88,6 +88,7 @@ enum { | |||
88 | OPT_DUMP_LEX_TRACE, | 88 | OPT_DUMP_LEX_TRACE, |
89 | OPT_CONFIG_HELP, | 89 | OPT_CONFIG_HELP, |
90 | OPT_READ, | 90 | OPT_READ, |
91 | OPT_REBUILD_LAST | ||
91 | }; | 92 | }; |
92 | 93 | ||
93 | static struct argp_option options[] = { | 94 | static struct argp_option options[] = { |
@@ -108,6 +109,8 @@ static struct argp_option options[] = { | |||
108 | N_("read statistics from given FILEs or standard input") }, | 109 | N_("read statistics from given FILEs or standard input") }, |
109 | {"rebuild", 'b', NULL, 0, | 110 | {"rebuild", 'b', NULL, 0, |
110 | N_("rebuild graphs using existing statistics"), GRID+1}, | 111 | N_("rebuild graphs using existing statistics"), GRID+1}, |
112 | {"rebuild-last", OPT_REBUILD_LAST, NULL, 0, | ||
113 | N_("same as --rebuild, but refer to the last stored sample"), GRID+1}, | ||
111 | {"list", 'l', NULL, 0, N_("list contents of the rate database"), GRID+1}, | 114 | {"list", 'l', NULL, 0, N_("list contents of the rate database"), GRID+1}, |
112 | {"show-defaults", OPT_SHOW_DEFAULTS, NULL, 0, | 115 | {"show-defaults", OPT_SHOW_DEFAULTS, NULL, 0, |
113 | N_("Show configuration default values"), GRID+1}, | 116 | N_("Show configuration default values"), GRID+1}, |
@@ -276,6 +279,11 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
276 | case OPT_READ: | 279 | case OPT_READ: |
277 | read_option = 1; | 280 | read_option = 1; |
278 | break; | 281 | break; |
282 | |||
283 | case OPT_REBUILD_LAST: | ||
284 | rebuild_option = 1; | ||
285 | rebuild_last_option = 1; | ||
286 | break; | ||
279 | 287 | ||
280 | case OPT_NO_PREPROCESSOR: | 288 | case OPT_NO_PREPROCESSOR: |
281 |