]>
Commit | Line | Data |
---|---|---|
b684b13b MT |
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" | |
b0a014b7 | 15 | #include "libsmooth.h" |
b684b13b | 16 | |
9a09d94e MT |
17 | #define QOS_SH "/var/ipfire/qos/bin/qos.sh" |
18 | ||
b684b13b | 19 | int main(int argc, char *argv[]) { |
b0a014b7 | 20 | struct keyvalue* kv = NULL; |
af95dec5 | 21 | int fd = -1; |
b0a014b7 | 22 | int r = 0; |
af95dec5 CS |
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) { | |
b0a014b7 MT |
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); | |
af95dec5 CS |
48 | } |
49 | ||
9a09d94e | 50 | if ((fd = open(QOS_SH, O_RDONLY)) != -1) { |
af95dec5 CS |
51 | close(fd); |
52 | } else { | |
53 | // If there is no qos.sh do nothing. | |
b0a014b7 | 54 | goto END; |
af95dec5 CS |
55 | } |
56 | ||
9a09d94e | 57 | safe_system("chmod 755 " QOS_SH " &>/dev/null"); |
af95dec5 | 58 | if (strcmp(argv[1], "start") == 0) { |
9a09d94e | 59 | safe_system(QOS_SH " start"); |
af95dec5 | 60 | } else if (strcmp(argv[1], "stop") == 0) { |
9a09d94e | 61 | safe_system(QOS_SH " clear"); |
af95dec5 | 62 | } else if (strcmp(argv[1], "status") == 0) { |
9a09d94e | 63 | safe_system(QOS_SH " status"); |
af95dec5 | 64 | } else if (strcmp(argv[1], "restart") == 0) { |
9a09d94e | 65 | safe_system(QOS_SH " restart"); |
af95dec5 CS |
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 | ||
b0a014b7 MT |
72 | END: |
73 | if (kv) | |
74 | freekeyvalues(kv); | |
75 | ||
76 | return r; | |
b684b13b | 77 | } |