@@ -19,6 +19,16 @@ def initChainIPv4(self):
19
19
rule .target = target
20
20
if rule not in chain .rules :
21
21
chain .insert_rule (rule )
22
+
23
+ # always allow TCP connections to 80 and 443 ports to show 403 page in case of ban
24
+ chain = iptc .Chain (iptc .Table (iptc .Table .FILTER ), self .chain_name )
25
+ rule = iptc .Rule ()
26
+ rule .create_target ("ACCEPT" )
27
+ match = rule .create_match ('multiport' )
28
+ rule .protocol = 'tcp'
29
+ match .dports = '80,443'
30
+ if rule not in chain .rules :
31
+ chain .insert_rule (rule )
22
32
23
33
def initChainIPv6 (self ):
24
34
if not iptc .Chain (iptc .Table6 (iptc .Table6 .FILTER ), self .chain_name ) in iptc .Table6 (iptc .Table6 .FILTER ).chains :
@@ -32,6 +42,16 @@ def initChainIPv6(self):
32
42
rule .target = target
33
43
if rule not in chain .rules :
34
44
chain .insert_rule (rule )
45
+
46
+ # always allow TCP connections to 80 and 443 ports to show 403 page in case of ban
47
+ chain = iptc .Chain (iptc .Table6 (iptc .Table6 .FILTER ), self .chain_name )
48
+ rule = iptc .Rule6 ()
49
+ rule .create_target ("ACCEPT" )
50
+ match = rule .create_match ('multiport' )
51
+ rule .protocol = 'tcp'
52
+ match .dports = '80,443'
53
+ if rule not in chain .rules :
54
+ chain .insert_rule (rule )
35
55
36
56
def checkIPv4ChainOrder (self ):
37
57
filter_table = iptc .Table (iptc .Table .FILTER )
@@ -98,7 +118,7 @@ def banIPv4(self, source):
98
118
rule .target = target
99
119
if rule in chain .rules :
100
120
return False
101
- chain .insert_rule (rule )
121
+ chain .append_rule (rule )
102
122
return True
103
123
104
124
def banIPv6 (self , source ):
@@ -109,7 +129,7 @@ def banIPv6(self, source):
109
129
rule .target = target
110
130
if rule in chain .rules :
111
131
return False
112
- chain .insert_rule (rule )
132
+ chain .append_rule (rule )
113
133
return True
114
134
115
135
def unbanIPv4 (self , source ):
0 commit comments