iup-nft 0.4__py3-none-any.whl → 0.6__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 +6 -6
- iup/main_iupd.py +29 -0
- {iup_nft-0.4.dist-info → iup_nft-0.6.dist-info}/METADATA +2 -2
- iup_nft-0.6.dist-info/RECORD +9 -0
- {iup_nft-0.4.dist-info → iup_nft-0.6.dist-info}/WHEEL +1 -1
- iup_nft-0.4.dist-info/RECORD +0 -9
- {iup_nft-0.4.dist-info → iup_nft-0.6.dist-info}/entry_points.txt +0 -0
- {iup_nft-0.4.dist-info → iup_nft-0.6.dist-info}/top_level.txt +0 -0
iup/main.py
CHANGED
|
@@ -99,16 +99,16 @@ def update_rule_by_ssh(hostnames: list, config: Config):
|
|
|
99
99
|
print('msg', msg) if msg else print()
|
|
100
100
|
print('err', err) if err else print()
|
|
101
101
|
if config.refresh:
|
|
102
|
-
if
|
|
103
|
-
print('reboot
|
|
104
|
-
_, stdout, stderr = ssh.exec_command(
|
|
102
|
+
if need_restart_cdns:
|
|
103
|
+
print('reboot chinadns')
|
|
104
|
+
_, stdout, stderr = ssh.exec_command(CMD_CHNDNS)
|
|
105
105
|
msg = stdout.readlines()
|
|
106
106
|
err = stderr.readlines()
|
|
107
107
|
print('msg', msg) if msg else print()
|
|
108
108
|
print('err', err) if err else print()
|
|
109
|
-
if
|
|
110
|
-
print('reboot
|
|
111
|
-
_, stdout, stderr = ssh.exec_command(
|
|
109
|
+
if need_restart_dns:
|
|
110
|
+
print('reboot dnsmasq')
|
|
111
|
+
_, stdout, stderr = ssh.exec_command(CMD_DNSMASQ)
|
|
112
112
|
msg = stdout.readlines()
|
|
113
113
|
err = stderr.readlines()
|
|
114
114
|
print('msg', msg) if msg else print()
|
iup/main_iupd.py
CHANGED
|
@@ -12,6 +12,10 @@ import ipaddress
|
|
|
12
12
|
HOSTNAME_PATTERN = r'^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$'
|
|
13
13
|
CMD_TEMPLATE = 'iupd {}'
|
|
14
14
|
CFG_FILE = 'config.ini'
|
|
15
|
+
CMD_DNSMASQ = '/etc/init.d/dnsmasq restart'
|
|
16
|
+
CMD_CHNDNS = '/etc/init.d/chinadns-ng restart'
|
|
17
|
+
MAGIC_STR = "del dnsmasq rule"
|
|
18
|
+
MAGIC_STR2 = "del chinadns rule"
|
|
15
19
|
|
|
16
20
|
def is_domain_name(string: str):
|
|
17
21
|
if re.match(HOSTNAME_PATTERN, string):
|
|
@@ -61,6 +65,7 @@ def read_hostname_from_file(path: str):
|
|
|
61
65
|
def load_and_overlay_config() -> Config:
|
|
62
66
|
parser = argparse.ArgumentParser(description='iupd参数说明')
|
|
63
67
|
parser.add_argument("sources", nargs='+', help='域名或者域名文件路径')
|
|
68
|
+
parser.add_argument("-nr", "--no_refresh", action='store_true', default=False, help="是否刷新")
|
|
64
69
|
parser.add_argument(
|
|
65
70
|
"--version",
|
|
66
71
|
action="version",
|
|
@@ -72,9 +77,14 @@ def load_and_overlay_config() -> Config:
|
|
|
72
77
|
gen_config()
|
|
73
78
|
print('当前配置文件路径为:', config_path)
|
|
74
79
|
config = Config(config_path)
|
|
80
|
+
if args.no_refresh:
|
|
81
|
+
config.refresh = False
|
|
82
|
+
print('是否重启相关服务:', config.refresh)
|
|
75
83
|
return args.sources, config
|
|
76
84
|
|
|
77
85
|
def update_rule_by_ssh(hostnames: list, config: Config):
|
|
86
|
+
need_restart_dns = False
|
|
87
|
+
need_restart_cdns = False
|
|
78
88
|
ssh = paramiko.SSHClient()
|
|
79
89
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
80
90
|
ssh.connect(config.host, port=config.port, username=config.username, password=config.password)
|
|
@@ -83,8 +93,27 @@ def update_rule_by_ssh(hostnames: list, config: Config):
|
|
|
83
93
|
_, stdout, stderr = ssh.exec_command(cmd)
|
|
84
94
|
msg = stdout.readlines()
|
|
85
95
|
err = stderr.readlines()
|
|
96
|
+
if MAGIC_STR in str(msg):
|
|
97
|
+
need_restart_dns = True
|
|
98
|
+
if MAGIC_STR2 in str(msg):
|
|
99
|
+
need_restart_cdns = True
|
|
86
100
|
print('msg', msg) if msg else print()
|
|
87
101
|
print('err', err) if err else print()
|
|
102
|
+
if config.refresh:
|
|
103
|
+
if need_restart_cdns:
|
|
104
|
+
print('reboot chinadns')
|
|
105
|
+
_, stdout, stderr = ssh.exec_command(CMD_CHNDNS)
|
|
106
|
+
msg = stdout.readlines()
|
|
107
|
+
err = stderr.readlines()
|
|
108
|
+
print('msg', msg) if msg else print()
|
|
109
|
+
print('err', err) if err else print()
|
|
110
|
+
if need_restart_dns:
|
|
111
|
+
print('reboot dnsmasq')
|
|
112
|
+
_, stdout, stderr = ssh.exec_command(CMD_DNSMASQ)
|
|
113
|
+
msg = stdout.readlines()
|
|
114
|
+
err = stderr.readlines()
|
|
115
|
+
print('msg', msg) if msg else print()
|
|
116
|
+
print('err', err) if err else print()
|
|
88
117
|
ssh.close()
|
|
89
118
|
|
|
90
119
|
def gen_hostnames_by_sources(sources):
|
|
@@ -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=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,,
|
iup_nft-0.4.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=j7-6cFrI6_RFkWR-Y4_LChs3fBVb1JGKQ8aW_w_9kMk,5508
|
|
4
|
-
iup/main_iupd.py,sha256=JA4ZQRZV5q-DO3hig-vWe6HMxKXKKmdtZFwL9XhrHl0,4204
|
|
5
|
-
iup_nft-0.4.dist-info/METADATA,sha256=7lPKohW7t9jXhEiZpW_msi42Au7NnNRwf4WDN9w43EY,208
|
|
6
|
-
iup_nft-0.4.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
|
|
7
|
-
iup_nft-0.4.dist-info/entry_points.txt,sha256=__DnLePT02PMCliwlVR7zwdJVJXmIWIwa5jeAb-U9rM,94
|
|
8
|
-
iup_nft-0.4.dist-info/top_level.txt,sha256=abec3YOzJRti4IxzOLIn-uDOPTtYUE-Uv65cAv1v8JY,4
|
|
9
|
-
iup_nft-0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|