iup-nft 0.6__py3-none-any.whl → 0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iup/main.py +48 -4
- iup/main_iupd.py +46 -4
- {iup_nft-0.6.dist-info → iup_nft-0.7.dist-info}/METADATA +1 -1
- iup_nft-0.7.dist-info/RECORD +9 -0
- {iup_nft-0.6.dist-info → iup_nft-0.7.dist-info}/WHEEL +1 -1
- iup_nft-0.6.dist-info/RECORD +0 -9
- {iup_nft-0.6.dist-info → iup_nft-0.7.dist-info}/entry_points.txt +0 -0
- {iup_nft-0.6.dist-info → iup_nft-0.7.dist-info}/top_level.txt +0 -0
iup/main.py
CHANGED
|
@@ -42,6 +42,47 @@ def parse_port(port: str):
|
|
|
42
42
|
return None
|
|
43
43
|
|
|
44
44
|
|
|
45
|
+
def parse_host_name(hostname_str: str):
|
|
46
|
+
"""Normalize input and return domain name only (no scheme, no port).
|
|
47
|
+
|
|
48
|
+
Accepts inputs like:
|
|
49
|
+
- a.com:443
|
|
50
|
+
- https://a.com
|
|
51
|
+
- http//:a.com:443
|
|
52
|
+
|
|
53
|
+
Returns domain (e.g. 'a.com') or None. IP addresses are rejected.
|
|
54
|
+
"""
|
|
55
|
+
if not hostname_str:
|
|
56
|
+
return None
|
|
57
|
+
s = hostname_str.strip()
|
|
58
|
+
# detect and strip scheme (require '://', e.g. http:// or https://)
|
|
59
|
+
# this prevents malformed inputs like 'http:a.com:443' being treated as scheme
|
|
60
|
+
m = re.match(r'^([a-zA-Z][a-zA-Z0-9+\-]*)://', s)
|
|
61
|
+
has_scheme = bool(m)
|
|
62
|
+
if m:
|
|
63
|
+
s = s[m.end():]
|
|
64
|
+
# remove credentials if present (user:pass@host)
|
|
65
|
+
if '@' in s:
|
|
66
|
+
s = s.split('@')[-1]
|
|
67
|
+
# if there was a scheme, remove path part
|
|
68
|
+
if has_scheme and '/' in s:
|
|
69
|
+
s = s.split('/')[0]
|
|
70
|
+
# now s should be host[:port]
|
|
71
|
+
host_port = s.strip()
|
|
72
|
+
# strip port if present (last :digits)
|
|
73
|
+
if ':' in host_port:
|
|
74
|
+
parts = host_port.rsplit(':', 1)
|
|
75
|
+
if parts[1].isdigit():
|
|
76
|
+
host_port = parts[0]
|
|
77
|
+
host = host_port.strip().lower()
|
|
78
|
+
# reject pure IPs
|
|
79
|
+
if is_ip_address(host):
|
|
80
|
+
return None
|
|
81
|
+
if is_domain_name(host):
|
|
82
|
+
return host
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
45
86
|
def parse_yes_or_no(msg: str):
|
|
46
87
|
msg = msg.upper()
|
|
47
88
|
if msg in ['Y', 'YES', 'T', 'TRUE']:
|
|
@@ -56,8 +97,9 @@ def read_hostname_from_file(path: str):
|
|
|
56
97
|
with open(path, 'r') as f:
|
|
57
98
|
for line in f:
|
|
58
99
|
host_name_str = line.strip()
|
|
59
|
-
|
|
60
|
-
|
|
100
|
+
parsed = parse_host_name(host_name_str)
|
|
101
|
+
if parsed:
|
|
102
|
+
hostnames.append(parsed)
|
|
61
103
|
hostnames = list(dict.fromkeys(hostnames))
|
|
62
104
|
return hostnames
|
|
63
105
|
|
|
@@ -119,8 +161,9 @@ def gen_hostnames_by_sources(sources):
|
|
|
119
161
|
hostnames = []
|
|
120
162
|
for source in sources:
|
|
121
163
|
if not path.exists(source):
|
|
122
|
-
|
|
123
|
-
|
|
164
|
+
parsed = parse_host_name(source)
|
|
165
|
+
if parsed:
|
|
166
|
+
hostnames.append(parsed)
|
|
124
167
|
elif path.isfile(source):
|
|
125
168
|
hostnames += read_hostname_from_file(source)
|
|
126
169
|
return list(dict.fromkeys(hostnames))
|
|
@@ -130,6 +173,7 @@ def main():
|
|
|
130
173
|
print('sources:', sources)
|
|
131
174
|
hostnames = gen_hostnames_by_sources(sources)
|
|
132
175
|
if hostnames:
|
|
176
|
+
print('hostnames to update:', hostnames)
|
|
133
177
|
update_rule_by_ssh(hostnames, config)
|
|
134
178
|
else:
|
|
135
179
|
print('没有读取到有效域名,请检查!!!')
|
iup/main_iupd.py
CHANGED
|
@@ -51,14 +51,54 @@ def parse_yes_or_no(msg: str):
|
|
|
51
51
|
return False
|
|
52
52
|
return None
|
|
53
53
|
|
|
54
|
+
def parse_host_name(hostname_str: str):
|
|
55
|
+
"""Normalize input and return domain name only (no scheme, no port).
|
|
56
|
+
|
|
57
|
+
Accepts inputs like:
|
|
58
|
+
- a.com:443
|
|
59
|
+
- https://a.com
|
|
60
|
+
- http//:a.com:443
|
|
61
|
+
|
|
62
|
+
Returns domain (e.g. 'a.com') or None. IP addresses are rejected.
|
|
63
|
+
"""
|
|
64
|
+
if not hostname_str:
|
|
65
|
+
return None
|
|
66
|
+
s = hostname_str.strip()
|
|
67
|
+
# detect and strip scheme (require '://', e.g. http:// or https://)
|
|
68
|
+
# this prevents malformed inputs like 'http:a.com:443' being treated as scheme
|
|
69
|
+
m = re.match(r'^([a-zA-Z][a-zA-Z0-9+\-]*)://', s)
|
|
70
|
+
has_scheme = bool(m)
|
|
71
|
+
if m:
|
|
72
|
+
s = s[m.end():]
|
|
73
|
+
# remove credentials if present (user:pass@host)
|
|
74
|
+
if '@' in s:
|
|
75
|
+
s = s.split('@')[-1]
|
|
76
|
+
# if there was a scheme, remove path part
|
|
77
|
+
if has_scheme and '/' in s:
|
|
78
|
+
s = s.split('/')[0]
|
|
79
|
+
# now s should be host[:port]
|
|
80
|
+
host_port = s.strip()
|
|
81
|
+
# strip port if present (last :digits)
|
|
82
|
+
if ':' in host_port:
|
|
83
|
+
parts = host_port.rsplit(':', 1)
|
|
84
|
+
if parts[1].isdigit():
|
|
85
|
+
host_port = parts[0]
|
|
86
|
+
host = host_port.strip().lower()
|
|
87
|
+
# reject pure IPs
|
|
88
|
+
if is_ip_address(host):
|
|
89
|
+
return None
|
|
90
|
+
if is_domain_name(host):
|
|
91
|
+
return host
|
|
92
|
+
return None
|
|
54
93
|
|
|
55
94
|
def read_hostname_from_file(path: str):
|
|
56
95
|
hostnames = []
|
|
57
96
|
with open(path, 'r') as f:
|
|
58
97
|
for line in f:
|
|
59
98
|
host_name_str = line.strip()
|
|
60
|
-
|
|
61
|
-
|
|
99
|
+
parsed = parse_host_name(host_name_str)
|
|
100
|
+
if parsed:
|
|
101
|
+
hostnames.append(parsed)
|
|
62
102
|
hostnames = list(dict.fromkeys(hostnames))
|
|
63
103
|
return hostnames
|
|
64
104
|
|
|
@@ -120,8 +160,9 @@ def gen_hostnames_by_sources(sources):
|
|
|
120
160
|
hostnames = []
|
|
121
161
|
for source in sources:
|
|
122
162
|
if not path.exists(source):
|
|
123
|
-
|
|
124
|
-
|
|
163
|
+
parsed = parse_host_name(source)
|
|
164
|
+
if parsed:
|
|
165
|
+
hostnames.append(parsed)
|
|
125
166
|
elif path.isfile(source):
|
|
126
167
|
hostnames += read_hostname_from_file(source)
|
|
127
168
|
return list(dict.fromkeys(hostnames))
|
|
@@ -131,6 +172,7 @@ def main():
|
|
|
131
172
|
print('sources:', sources)
|
|
132
173
|
hostnames = gen_hostnames_by_sources(sources)
|
|
133
174
|
if hostnames:
|
|
175
|
+
print('hostnames to delete:', hostnames)
|
|
134
176
|
update_rule_by_ssh(hostnames, config)
|
|
135
177
|
else:
|
|
136
178
|
print('没有读取到有效域名,请检查!!!')
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
iup/__init__.py,sha256=CJiAR6OdV8OFR6zNHs9vvRnJV8UgZ_c7dcvaVHeSHkY,112
|
|
2
|
+
iup/config.py,sha256=Ecg9m83D_Cp_inYrltt--oPcupVvCw9oo8m5ukKyWLA,2862
|
|
3
|
+
iup/main.py,sha256=46zeTzjdpYlwpiaU1wJdfhyKRmYxhWE2tR57xniVE4M,6839
|
|
4
|
+
iup/main_iupd.py,sha256=HeW4eHp0P0E5cjmEJyJrSuU7So0LTyCA-orsYatzaZQ,6729
|
|
5
|
+
iup_nft-0.7.dist-info/METADATA,sha256=-ShoFLrteDbDgvR-q7PhtuuI58iI1BMEDb3rd4FQHAE,209
|
|
6
|
+
iup_nft-0.7.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
|
|
7
|
+
iup_nft-0.7.dist-info/entry_points.txt,sha256=__DnLePT02PMCliwlVR7zwdJVJXmIWIwa5jeAb-U9rM,94
|
|
8
|
+
iup_nft-0.7.dist-info/top_level.txt,sha256=abec3YOzJRti4IxzOLIn-uDOPTtYUE-Uv65cAv1v8JY,4
|
|
9
|
+
iup_nft-0.7.dist-info/RECORD,,
|
iup_nft-0.6.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
iup/__init__.py,sha256=CJiAR6OdV8OFR6zNHs9vvRnJV8UgZ_c7dcvaVHeSHkY,112
|
|
2
|
-
iup/config.py,sha256=Ecg9m83D_Cp_inYrltt--oPcupVvCw9oo8m5ukKyWLA,2862
|
|
3
|
-
iup/main.py,sha256=cO20fqi4so3tW_qT_zRUsbdgWAWt7FQl7_6C8Knc0tI,5508
|
|
4
|
-
iup/main_iupd.py,sha256=bbTA3H_VPVyyz5g46ZMiSE7Yt0YLweD9LLVbtosjir8,5400
|
|
5
|
-
iup_nft-0.6.dist-info/METADATA,sha256=19bv18biH47C3NjIeTEb8HbYJwaat9oD2t34TizNTNw,209
|
|
6
|
-
iup_nft-0.6.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
7
|
-
iup_nft-0.6.dist-info/entry_points.txt,sha256=__DnLePT02PMCliwlVR7zwdJVJXmIWIwa5jeAb-U9rM,94
|
|
8
|
-
iup_nft-0.6.dist-info/top_level.txt,sha256=abec3YOzJRti4IxzOLIn-uDOPTtYUE-Uv65cAv1v8JY,4
|
|
9
|
-
iup_nft-0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|