]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/misc-progs/monitorTraff.c
IPSec-Downgrade auf 2.4.8-STABLE
[people/pmueller/ipfire-2.x.git] / src / misc-progs / monitorTraff.c
CommitLineData
d81292e0
CS
1/* Addon helper program - monitorTraff
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * Copyright (c) Achim Weber 2 November 2006
7 *
8 * Wrapper for Perl Monitoring script
9 *
10 * $Id: monitorTraff.c,v 1.4 2006/11/15 17:53:43 dotzball Exp $
11 *
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17#include "setuid.h"
18
19/* define parameters */
20#define PARA_TEST "--testEmail"
21#define PARA_WARN "--warnEmail"
22#define PARA_FORCE "--force"
23
24struct keyvalue *kv = NULL;
25
26void usage()
27{
28 fprintf (stderr, "Usage:\n");
29 fprintf (stderr, "\tmonitorTraff [PARAMETER]\n");
30 fprintf (stderr, "\t\tWhen called without parameter, monitorTraff calculates the traffic.\n");
31 fprintf (stderr, "\t\tPARAMETER:\n");
32 fprintf (stderr, "\t\t\t--testEmail : Send a test email\n");
33 fprintf (stderr, "\t\t\t--warnEmail : Send a warn email\n");
34 fprintf (stderr, "\t\t\t--force : Force re-calculation\n");
35}
36
37int main(int argc, char *argv[])
38{
39 char buffer[STRING_SIZE];
40
41 if (!(initsetuid()))
42 return 1;
43
44 // What should we do?
45 if (argc==1)
46 {
47 // calc traffic
48 safe_system("/usr/local/bin/monitorTraffic.pl");
49 }
50 else if (argc==2
51 && (strcmp(argv[1], PARA_TEST)==0
52 || strcmp(argv[1], PARA_WARN)==0
53 || strcmp(argv[1], PARA_FORCE)==0) )
54 {
55 // send (test|warn) Email or force re-calc
56 memset(buffer, 0, STRING_SIZE);
57 if ( snprintf(buffer, STRING_SIZE - 1, "/usr/local/bin/monitorTraffic.pl %s", argv[1]) >= STRING_SIZE )
58 {
59 fprintf(stderr, "Command too long\n");
60 exit(1);
61 }
62 safe_system(buffer);
63 }
64 else
65 {
66 usage();
67 }
68
69 return 0;
70}