]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/misc-progs/addonctrl.c
tor: added daemon stats and little changes on styling
[people/teissler/ipfire-2.x.git] / src / misc-progs / addonctrl.c
CommitLineData
33cb80ed
AF
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#define BUFFER_SIZE 1024
17
18char command[BUFFER_SIZE];
19
20int main(int argc, char *argv[]) {
21
22 if (!(initsetuid()))
23 exit(1);
24
25 if (argc < 3) {
26 fprintf(stderr, "\nMissing arguments.\n\naddonctrl addon (start|stop|restart|reload|enable|disable)\n\n");
27 exit(1);
28 }
29
30 if ( strlen(argv[1])>32 ) {
31 fprintf(stderr, "\nString to large.\n\naddonctrl addon (start|stop|restart|reload|enable|disable)\n\n");
32 exit(1);
33 }
34
35 if ( strchr(argv[1],'/') || strchr(argv[1],'$') || strchr(argv[1],'[') || strchr(argv[1],'{') ) {
36 fprintf(stderr, "\nIllegal Char found.\n\naddonctrl addon (start|stop|restart|reload|enable|disable)\n\n");
37 exit(1);
38 }
39
40 sprintf(command, "/opt/pakfire/db/installed/meta-%s", argv[1]);
41 FILE *fp = fopen(command,"r");
42 if ( fp ) {
43 fclose(fp);
44 } else {
45 fprintf(stderr, "\nAddon '%s' not found.\n\naddonctrl addon (start|stop|restart|reload|status|enable|disable)\n\n", argv[1]);
46 exit(1);
47 }
48
49 if (strcmp(argv[2], "start") == 0) {
50 sprintf(command,"/etc/rc.d/init.d/%s start", argv[1]);
51 safe_system(command);
52 } else if (strcmp(argv[2], "stop") == 0) {
53 sprintf(command,"/etc/rc.d/init.d/%s stop", argv[1]);
54 safe_system(command);
55 } else if (strcmp(argv[2], "restart") == 0) {
56 sprintf(command,"/etc/rc.d/init.d/%s restart", argv[1]);
57 safe_system(command);
58 } else if (strcmp(argv[2], "reload") == 0) {
59 sprintf(command,"/etc/rc.d/init.d/%s reload", argv[1]);
60 safe_system(command);
61 } else if (strcmp(argv[2], "status") == 0) {
62 sprintf(command,"/etc/rc.d/init.d/%s status", argv[1]);
63 safe_system(command);
64 } else if (strcmp(argv[2], "enable") == 0) {
65 sprintf(command,"mv -f /etc/rc.d/rc3.d/off/S??%s /etc/rc.d/rc3.d" , argv[1]);
66 safe_system(command);
67 } else if (strcmp(argv[2], "disable") == 0) {
68 sprintf(command,"mkdir -p /etc/rc.d/rc3.d/off");
69 safe_system(command);
70 sprintf(command,"mv -f /etc/rc.d/rc3.d/S??%s /etc/rc.d/rc3.d/off" , argv[1]);
71 safe_system(command);
72 } else {
73 fprintf(stderr, "\nBad argument given.\n\naddonctrl addon (start|stop|restart|reload|enable|disable)\n\n");
74 exit(1);
75 }
76
77 return 0;
78}