iup-nft 0.5__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 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
- if is_domain_name(host_name_str):
60
- hostnames.append(host_name_str)
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
 
@@ -99,16 +141,16 @@ def update_rule_by_ssh(hostnames: list, config: Config):
99
141
  print('msg', msg) if msg else print()
100
142
  print('err', err) if err else print()
101
143
  if config.refresh:
102
- if need_restart_dns:
103
- print('reboot dnsmasq')
104
- _, stdout, stderr = ssh.exec_command(CMD_DNSMASQ)
144
+ if need_restart_cdns:
145
+ print('reboot chinadns')
146
+ _, stdout, stderr = ssh.exec_command(CMD_CHNDNS)
105
147
  msg = stdout.readlines()
106
148
  err = stderr.readlines()
107
149
  print('msg', msg) if msg else print()
108
150
  print('err', err) if err else print()
109
- if need_restart_cdns:
110
- print('reboot chinadns')
111
- _, stdout, stderr = ssh.exec_command(CMD_CHNDNS)
151
+ if need_restart_dns:
152
+ print('reboot dnsmasq')
153
+ _, stdout, stderr = ssh.exec_command(CMD_DNSMASQ)
112
154
  msg = stdout.readlines()
113
155
  err = stderr.readlines()
114
156
  print('msg', msg) if msg else print()
@@ -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
- if is_domain_name(source):
123
- hostnames.append(source)
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
- if is_domain_name(host_name_str):
61
- hostnames.append(host_name_str)
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
 
@@ -100,16 +140,16 @@ def update_rule_by_ssh(hostnames: list, config: Config):
100
140
  print('msg', msg) if msg else print()
101
141
  print('err', err) if err else print()
102
142
  if config.refresh:
103
- if need_restart_dns:
104
- print('reboot dnsmasq')
105
- _, stdout, stderr = ssh.exec_command(CMD_DNSMASQ)
143
+ if need_restart_cdns:
144
+ print('reboot chinadns')
145
+ _, stdout, stderr = ssh.exec_command(CMD_CHNDNS)
106
146
  msg = stdout.readlines()
107
147
  err = stderr.readlines()
108
148
  print('msg', msg) if msg else print()
109
149
  print('err', err) if err else print()
110
- if need_restart_cdns:
111
- print('reboot chinadns')
112
- _, stdout, stderr = ssh.exec_command(CMD_CHNDNS)
150
+ if need_restart_dns:
151
+ print('reboot dnsmasq')
152
+ _, stdout, stderr = ssh.exec_command(CMD_DNSMASQ)
113
153
  msg = stdout.readlines()
114
154
  err = stderr.readlines()
115
155
  print('msg', msg) if msg else print()
@@ -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
- if is_domain_name(source):
124
- hostnames.append(source)
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('没有读取到有效域名,请检查!!!')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iup-nft
3
- Version: 0.5
3
+ Version: 0.7
4
4
  Summary: nftset updater for openwrt
5
5
  Author: nobitaqaq
6
6
  Author-email: xiaoleigs@gmail.com
@@ -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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.1)
2
+ Generator: setuptools (75.3.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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=j7-6cFrI6_RFkWR-Y4_LChs3fBVb1JGKQ8aW_w_9kMk,5508
4
- iup/main_iupd.py,sha256=Jq0JioHvsRhQhAM0Rroro3tgvyh-obaSniINzq8wqm8,5400
5
- iup_nft-0.5.dist-info/METADATA,sha256=9zDVl_0O8SqEDl64F2th2tH-0nU4iTaOL3N679Fy9QI,209
6
- iup_nft-0.5.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
7
- iup_nft-0.5.dist-info/entry_points.txt,sha256=__DnLePT02PMCliwlVR7zwdJVJXmIWIwa5jeAb-U9rM,94
8
- iup_nft-0.5.dist-info/top_level.txt,sha256=abec3YOzJRti4IxzOLIn-uDOPTtYUE-Uv65cAv1v8JY,4
9
- iup_nft-0.5.dist-info/RECORD,,