8a8f07ebc099eb5c17613bf4c89f1bfc5a8a1a06
[people/pmueller/ipfire-2.x.git] / src / misc-progs / qosctrl.c
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
16 int main(int argc, char *argv[]) {
17
18 int fd = -1;
19
20 if (!(initsetuid()))
21 exit(1);
22
23 if (argc < 2) {
24 fprintf(stderr, "\nNo argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n");
25 exit(1);
26 }
27
28 if ((fd = open("/var/ipfire/qos/bin/qos.sh", O_RDONLY)) != -1) {
29 close(fd);
30 } else {
31 // If there is no qos.sh do nothing.
32 exit(0);
33 }
34
35 safe_system("chmod 755 /var/ipfire/qos/bin/qos.sh &>/dev/null");
36 if (strcmp(argv[1], "start") == 0) {
37 safe_system("/var/ipfire/qos/bin/qos.sh start");
38 } else if (strcmp(argv[1], "stop") == 0) {
39 safe_system("/var/ipfire/qos/bin/qos.sh clear");
40 } else if (strcmp(argv[1], "status") == 0) {
41 safe_system("/var/ipfire/qos/bin/qos.sh status");
42 } else if (strcmp(argv[1], "restart") == 0) {
43 safe_system("/var/ipfire/qos/bin/qos.sh restart");
44 } else if (strcmp(argv[1], "generate") == 0) {
45 safe_system("/usr/bin/perl /var/ipfire/qos/bin/makeqosscripts.pl > /var/ipfire/qos/bin/qos.sh");
46 } else {
47 fprintf(stderr, "\nBad argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n");
48 exit(1);
49 }
50
51 return 0;
52 }