]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
misc-progs: New binary guardianctrl.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 1 Jun 2014 13:40:40 +0000 (15:40 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 22 Jun 2014 09:18:29 +0000 (11:18 +0200)
This is a helper binary which is used to perform several tasks around guardian
when using guardians page in the webinterface.

config/rootfiles/common/misc-progs
src/misc-progs/Makefile
src/misc-progs/guardianctrl.c [new file with mode: 0644]

index 1ab4dec5f1aa5053d5a8a96d798f08cf7c95e870..bcf53fd8ffc3bd1523b06d4fcebab418d70fadac 100644 (file)
@@ -8,6 +8,7 @@ usr/local/bin/extrahdctrl
 usr/local/bin/fireinfoctrl
 usr/local/bin/getconntracktable
 usr/local/bin/getipstat
+#usr/local/bin/guardianctrl
 #usr/local/bin/iowrap
 usr/local/bin/ipfirereboot
 usr/local/bin/ipsecctrl
index b4474355ad53797c46608dda2cfd09a2d6aae549..08ea0c00bf79b4bf3c4695c9ebce5450472d9f66 100644 (file)
@@ -32,7 +32,7 @@ SUID_PROGS = squidctrl sshctrl ipfirereboot \
        redctrl syslogdctrl extrahdctrl sambactrl upnpctrl tripwirectrl \
        smartctrl clamavctrl addonctrl pakfire mpfirectrl wlanapctrl \
        setaliases urlfilterctrl updxlratorctrl fireinfoctrl rebuildroutes \
-       getconntracktable wirelessclient dnsmasqctrl torctrl
+       getconntracktable wirelessclient dnsmasqctrl torctrl guardianctrl
 SUID_UPDX = updxsetperms
 
 install : all
@@ -160,3 +160,6 @@ dnsmasqctrl: dnsmasqctrl.c setuid.o ../install+setup/libsmooth/varval.o
 
 torctrl: torctrl.c setuid.o ../install+setup/libsmooth/varval.o
        $(COMPILE) -I../install+setup/libsmooth/ torctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
+
+guardianctrl: guardianctrl.c setuid.o ../install+setup/libsmooth/varval.o
+       $(COMPILE) -I../install+setup/libsmooth/ guardianctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
diff --git a/src/misc-progs/guardianctrl.c b/src/misc-progs/guardianctrl.c
new file mode 100644 (file)
index 0000000..e94d233
--- /dev/null
@@ -0,0 +1,81 @@
+/* This file is part of the IPFire Firewall.
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence.  See the file COPYING for details.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "setuid.h"
+#include "netutil.h"
+
+const char *chain = "GUARDIAN";
+
+int main(int argc, char *argv[]) {
+       char cmd[STRING_SIZE];
+
+        if (!(initsetuid()))
+                exit(1);
+
+        if (argc < 2) {
+                fprintf(stderr, "\nNo argument given.\n\nguardianctrl (start|stop|restart|get-chain|flush-chain|block|unblock)\n\n");
+                exit(1);
+        }
+       if (strcmp(argv[1], "start") == 0) {
+               safe_system("/etc/rc.d/init.d/guardian start");
+
+       } else if (strcmp(argv[1], "stop") == 0) {
+               safe_system("/etc/rc.d/init.d/guardian stop");
+
+       } else if (strcmp(argv[1], "restart") == 0) {
+               safe_system("/etc/rc.d/init.d/guardian restart");
+
+       } else if (strcmp(argv[1], "get-chain") == 0) {
+               snprintf(cmd, sizeof(cmd), "/sbin/iptables -n -v -L %s", chain);
+                safe_system(cmd);
+
+        } else if (strcmp(argv[1], "flush-chain") == 0) {
+               snprintf(cmd, sizeof(cmd), "/sbin/iptables -F %s", chain);
+                safe_system(cmd);
+
+        } else if (strcmp(argv[1], "block") == 0) {
+               if (argc == 3) {
+                       char* ipaddress = argv[2];
+                       if (!VALID_IP(ipaddress)) {
+                               fprintf(stderr, "A valid IP address is required.\n");
+                               exit(1);
+                       }
+
+                       snprintf(cmd, sizeof(cmd), "/sbin/iptables -I %s -s %s -j DROP", chain, ipaddress);
+                       safe_system(cmd);
+               } else {
+                       fprintf(stderr, "\nTo few arguments. \n\nUSAGE: guardianctrl block <address>\n\n");
+                       exit(1);
+               }
+        } else if (strcmp(argv[1], "unblock") == 0) {
+               if (argc == 3) {
+                       char* ipaddress = argv[2];
+                       if (!VALID_IP(ipaddress)) {
+                               fprintf(stderr, "A valid IP address is required.\n");
+                               exit(1);
+                       }
+
+                       snprintf(cmd, sizeof(cmd), "/sbin/iptables -D %s -s %s -j DROP", chain, ipaddress);
+                       safe_system(cmd);
+               } else {
+                       fprintf(stderr, "\nTo few arguments. \n\nUSAGE: guardianctrl unblock <address>\n\n");
+                       exit(1);
+               }
+        } else {
+                fprintf(stderr, "\nBad argument given.\n\nguardianctrl (start|stop|restart|get-chain|flush-chain|block|unblock)\n\n");
+                exit(1);
+        }
+
+        return 0;
+}