]>
Commit | Line | Data |
---|---|---|
1 | /* This file is part of the IPFire Firewall. | |
2 | * | |
3 | * This program is distributed under the terms of the GNU General Public | |
4 | * Licence. See the file COPYING for details. | |
5 | * | |
6 | */ | |
7 | ||
8 | #include <stdlib.h> | |
9 | #include <stdio.h> | |
10 | #include <string.h> | |
11 | #include <unistd.h> | |
12 | #include <sys/types.h> | |
13 | #include <fcntl.h> | |
14 | #include "setuid.h" | |
15 | #include "libsmooth.h" | |
16 | ||
17 | #define QOS_SH "/var/ipfire/qos/bin/qos.sh" | |
18 | ||
19 | int main(int argc, char *argv[]) { | |
20 | struct keyvalue* kv = NULL; | |
21 | int fd = -1; | |
22 | int r = 0; | |
23 | ||
24 | if (!(initsetuid())) | |
25 | exit(1); | |
26 | ||
27 | if (argc < 2) { | |
28 | fprintf(stderr, "\nNo argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n"); | |
29 | exit(1); | |
30 | } | |
31 | ||
32 | if (strcmp(argv[1], "generate") == 0) { | |
33 | kv = initkeyvalues(); | |
34 | if (!readkeyvalues(kv, CONFIG_ROOT "/qos/settings")) { | |
35 | fprintf(stderr, "Cannot read QoS settings\n"); | |
36 | r = 1; | |
37 | goto END; | |
38 | } | |
39 | ||
40 | char enabled[STRING_SIZE]; | |
41 | if (!findkey(kv, "ENABLED", enabled)) | |
42 | strcpy(enabled, "off"); | |
43 | ||
44 | if (strcmp(enabled, "on") == 0) | |
45 | safe_system("/usr/bin/perl /var/ipfire/qos/bin/makeqosscripts.pl > " QOS_SH); | |
46 | else | |
47 | unlink(QOS_SH); | |
48 | } | |
49 | ||
50 | if ((fd = open(QOS_SH, O_RDONLY)) != -1) { | |
51 | close(fd); | |
52 | } else { | |
53 | // If there is no qos.sh do nothing. | |
54 | goto END; | |
55 | } | |
56 | ||
57 | safe_system("chmod 755 " QOS_SH " &>/dev/null"); | |
58 | if (strcmp(argv[1], "start") == 0) { | |
59 | safe_system(QOS_SH " start"); | |
60 | } else if (strcmp(argv[1], "stop") == 0) { | |
61 | safe_system(QOS_SH " clear"); | |
62 | } else if (strcmp(argv[1], "status") == 0) { | |
63 | safe_system(QOS_SH " status"); | |
64 | } else if (strcmp(argv[1], "restart") == 0) { | |
65 | safe_system(QOS_SH " restart"); | |
66 | } else { | |
67 | if (strcmp(argv[1], "generate") == 0) {exit(0);} | |
68 | fprintf(stderr, "\nBad argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n"); | |
69 | exit(1); | |
70 | } | |
71 | ||
72 | END: | |
73 | if (kv) | |
74 | freekeyvalues(kv); | |
75 | ||
76 | return r; | |
77 | } |