Explorar o código

Merge branch 'master' of ssh://gitgreen/david/failUser

david %!s(int64=3) %!d(string=hai) anos
pai
achega
7694cd672e
Modificáronse 1 ficheiros con 9 adicións e 5 borrados
  1. 9 5
      failUser.py

+ 9 - 5
failUser.py

@@ -2,7 +2,7 @@
 from json import loads, dumps
 from json import loads, dumps
 from json.decoder import JSONDecodeError
 from json.decoder import JSONDecodeError
 import pendulum
 import pendulum
-from subprocess import run, PIPE
+from subprocess import run, PIPE, CalledProcessError
 from os.path import exists, join
 from os.path import exists, join
 from pyinotify import WatchManager, Notifier, ProcessEvent
 from pyinotify import WatchManager, Notifier, ProcessEvent
 from pyinotify import IN_MODIFY, IN_DELETE, IN_MOVE_SELF, IN_CREATE
 from pyinotify import IN_MODIFY, IN_DELETE, IN_MOVE_SELF, IN_CREATE
@@ -27,13 +27,16 @@ dirmask = IN_MODIFY | IN_DELETE | IN_MOVE_SELF | IN_CREATE
 
 
 def blocker(ip):
 def blocker(ip):
     # Utility function to block given ip as string
     # Utility function to block given ip as string
-    #run(["iptables", "-I", "DOCKER-USER", "-i", "eth0", "-s", ip, "-j", "DROP"], stdout=PIPE, check=True)
-    print("iptables -I DOCKER-USER -i eth0 -s {0} -j DROP".format(ip))
+    run(["iptables", "-I", "DOCKER-USER", "-i", "eth0", "-s", ip, "-j", "DROP"], stdout=PIPE, check=True)
+    #print("iptables -I DOCKER-USER -i eth0 -s {0} -j DROP".format(ip))
 
 
 def unblocker(ip):
 def unblocker(ip):
     # Utility function to unblock given ip as string
     # Utility function to unblock given ip as string
-    #run(["iptables", "-D", "DOCKER-USER", "-i", "eth0", "-s", ip, "-j", "DROP"], stdout=PIPE, check=True)
-    print("iptables -D DOCKER-USER -i eth0 -s {0} -j DROP".format(ip))
+    try:
+        run(["iptables", "-D", "DOCKER-USER", "-i", "eth0", "-s", ip, "-j", "DROP"], stdout=PIPE, check=True)
+    except CalledProcessError:
+        pass
+    #print("iptables -D DOCKER-USER -i eth0 -s {0} -j DROP".format(ip))
 
 
 # def is_bad(line):
 # def is_bad(line):
 #     # Given line, attempt to parse... then is there a issue with it
 #     # Given line, attempt to parse... then is there a issue with it
@@ -134,6 +137,7 @@ target.close()
 
 
 # Update config
 # Update config
 myConfig["last_unblock"] = last.to_atom_string()
 myConfig["last_unblock"] = last.to_atom_string()
+myConfig["bad_users"] = bad_users
 save_config(myConfig)
 save_config(myConfig)
 
 
 exit(0)
 exit(0)