tplinkrouterc6u 5.8.0__py3-none-any.whl → 5.9.0__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.
test/test_client_c1200.py CHANGED
@@ -5,7 +5,6 @@ from tplinkrouterc6u import (
5
5
  Connection,
6
6
  ClientException,
7
7
  )
8
- from tplinkrouterc6u.common.package_enum import VPN
9
8
 
10
9
 
11
10
  class TestTPLinkC1200Client(TestCase):
@@ -201,13 +200,13 @@ class TestTPLinkC1200Client(TestCase):
201
200
  ignore_response: bool = False,
202
201
  ignore_errors: bool = False,
203
202
  ) -> dict | None:
204
- if path == "/admin/openvpn?form=config&operation=read":
203
+ if path == "admin/openvpn?form=config&operation=read":
205
204
  return loads(response_openvpn_read)
206
- if path == "/admin/pptpd?form=config&operation=read":
205
+ if path == "admin/pptpd?form=config&operation=read":
207
206
  return loads(response_pptp_read)
208
- if path == "/admin/vpnconn?form=config&operation=list&vpntype=openvpn":
207
+ if path == "admin/vpnconn?form=config&operation=list&vpntype=openvpn":
209
208
  return loads(respone_vpnconn_openvpn)
210
- if path == "/admin/vpnconn?form=config&operation=list&vpntype=pptp":
209
+ if path == "admin/vpnconn?form=config&operation=list&vpntype=pptp":
211
210
  return loads(respone_vpnconn_pptpvpn)
212
211
  raise ClientException()
213
212
 
@@ -219,41 +218,6 @@ class TestTPLinkC1200Client(TestCase):
219
218
  self.assertEqual(vpn_status.openvpn_clients_total, 2)
220
219
  self.assertEqual(vpn_status.pptpvpn_clients_total, 3)
221
220
 
222
- def test_set_vpn(self) -> None:
223
- response_openvpn_read = """
224
- {
225
- "enabled": "on",
226
- "proto": "udp",
227
- "access": "home",
228
- "cert_exist": true,
229
- "mask": "255.255.255.0",
230
- "port": "1194",
231
- "serverip": "10.8.0.0"
232
- }
233
- """
234
-
235
- class TPLinkRouterTest(TplinkC1200Router):
236
- def request(
237
- self,
238
- path: str,
239
- data: str,
240
- ignore_response: bool = False,
241
- ignore_errors: bool = False,
242
- ) -> dict | None:
243
- if path == "/admin/openvpn?form=config&operation=read":
244
- return loads(response_openvpn_read)
245
- self.captured_path = path
246
-
247
- client = TPLinkRouterTest("", "")
248
- client.set_vpn(VPN.OPEN_VPN, True)
249
-
250
- expected_path = (
251
- "/admin/openvpn?form=config&operation=write&enabled=on"
252
- "&proto=udp&access=home&cert_exist=True"
253
- "&mask=255.255.255.0&port=1194&serverip=10.8.0.0"
254
- )
255
- self.assertEqual(client.captured_path, expected_path)
256
-
257
221
 
258
222
  if __name__ == "__main__":
259
223
  main()
test/test_client_c6u.py CHANGED
@@ -9,6 +9,7 @@ from tplinkrouterc6u import (
9
9
  IPv4Status,
10
10
  Device,
11
11
  ClientException,
12
+ VPN,
12
13
  )
13
14
 
14
15
 
@@ -768,6 +769,107 @@ class TestTPLinkClient(TestCase):
768
769
  self.assertEqual(result.wan_ipv4_gateway, '0.0.0.0')
769
770
  self.assertEqual(result.lan_macaddr, '06-E6-97-9E-23-F5')
770
771
 
772
+ def test_vpn_status(self) -> None:
773
+ response_openvpn_read = """
774
+ {
775
+ "enabled": "on",
776
+ "proto": "udp",
777
+ "access": "home",
778
+ "cert_exist": true,
779
+ "mask": "255.255.255.0",
780
+ "port": "1194",
781
+ "serverip": "10.8.0.0"
782
+ }
783
+ """
784
+
785
+ response_pptp_read = """
786
+ {
787
+ "enabled": "off",
788
+ "unencrypted_access": "on",
789
+ "samba_access": "on",
790
+ "netbios_pass": "on",
791
+ "remoteip": "10.0.0.11-20"
792
+ }
793
+ """
794
+
795
+ respone_vpnconn_openvpn = """[
796
+ {"username": "admin", "remote_ip": "192.168.0.200", "ipaddr": "10.0.0.11",
797
+ "extra": "7450", "vpntype": "openvpn", "key": "7450"},
798
+ {"username": "admin", "remote_ip": "192.168.0.200", "ipaddr": "10.0.0.11",
799
+ "extra": "7450", "vpntype": "openvpn", "key": "7450"}
800
+ ]"""
801
+
802
+ respone_vpnconn_pptpvpn = """[
803
+ {"username": "admin", "remote_ip": "192.168.0.200", "ipaddr": "10.0.0.11",
804
+ "extra": "7450", "vpntype": "pptp", "key": "7450"},
805
+ {"username": "admin", "remote_ip": "192.168.0.200", "ipaddr": "10.0.0.11",
806
+ "extra": "7450", "vpntype": "pptp", "key": "7450"},
807
+ {"username": "admin", "remote_ip": "192.168.0.200", "ipaddr": "10.0.0.11",
808
+ "extra": "7450", "vpntype": "pptp", "key": "7450"}
809
+ ]"""
810
+
811
+ class TPLinkRouterTest(TplinkRouter):
812
+ def request(
813
+ self,
814
+ path: str,
815
+ data: str,
816
+ ignore_response: bool = False,
817
+ ignore_errors: bool = False,
818
+ ) -> dict | None:
819
+ if path == "admin/openvpn?form=config":
820
+ return loads(response_openvpn_read)
821
+ if path == "admin/pptpd?form=config":
822
+ return loads(response_pptp_read)
823
+ if path == "admin/vpnconn?form=config" and data == "operation=list&vpntype=openvpn":
824
+ return loads(respone_vpnconn_openvpn)
825
+ if path == "admin/vpnconn?form=config" and data == "operation=list&vpntype=pptp":
826
+ return loads(respone_vpnconn_pptpvpn)
827
+ raise ClientException()
828
+
829
+ client = TPLinkRouterTest("", "")
830
+
831
+ vpn_status = client.get_vpn_status()
832
+ self.assertTrue(vpn_status.openvpn_enable)
833
+ self.assertFalse(vpn_status.pptpvpn_enable)
834
+ self.assertEqual(vpn_status.openvpn_clients_total, 2)
835
+ self.assertEqual(vpn_status.pptpvpn_clients_total, 3)
836
+
837
+ def test_set_vpn(self) -> None:
838
+ response_openvpn_read = """
839
+ {
840
+ "enabled": "on",
841
+ "proto": "udp",
842
+ "access": "home",
843
+ "cert_exist": true,
844
+ "mask": "255.255.255.0",
845
+ "port": "1194",
846
+ "serverip": "10.8.0.0"
847
+ }
848
+ """
849
+
850
+ class TPLinkRouterTest(TplinkRouter):
851
+ def request(
852
+ self,
853
+ path: str,
854
+ data: str,
855
+ ignore_response: bool = False,
856
+ ignore_errors: bool = False,
857
+ ) -> dict | None:
858
+ if path == "admin/openvpn?form=config" and data == "operation=read":
859
+ return loads(response_openvpn_read)
860
+ self.captured_path = path
861
+ self.captured_data = data
862
+
863
+ client = TPLinkRouterTest("", "")
864
+ client.set_vpn(VPN.OPEN_VPN, True)
865
+
866
+ expected_data = (
867
+ "operation=write&enabled=on"
868
+ "&proto=udp&access=home&cert_exist=True&mask=255.255.255.0&port=1194&serverip=10.8.0.0"
869
+ )
870
+ self.assertEqual(client.captured_path, 'admin/openvpn?form=config')
871
+ self.assertEqual(client.captured_data, expected_data)
872
+
771
873
 
772
874
  if __name__ == '__main__':
773
875
  main()
@@ -1,11 +1,8 @@
1
1
  from re import search
2
2
  from requests import post, Response
3
- from urllib.parse import urlencode
4
3
  from tplinkrouterc6u.common.encryption import EncryptionWrapper
5
4
  from tplinkrouterc6u.common.exception import ClientException, AuthorizeError
6
5
  from tplinkrouterc6u.client.c5400x import TplinkC5400XRouter
7
- from tplinkrouterc6u.common.dataclass import VPNStatus
8
- from tplinkrouterc6u.common.package_enum import VPN
9
6
 
10
7
 
11
8
  class TplinkC1200Router(TplinkC5400XRouter):
@@ -103,36 +100,3 @@ class TplinkC1200Router(TplinkC5400XRouter):
103
100
  @staticmethod
104
101
  def _get_login_data(crypted_pwd: str) -> str:
105
102
  return 'operation=login&password={}'.format(crypted_pwd)
106
-
107
- def get_vpn_status(self) -> VPNStatus:
108
- status = VPNStatus()
109
-
110
- values = [
111
- self.request("/admin/openvpn?form=config&operation=read", "operation=read"),
112
- self.request("/admin/pptpd?form=config&operation=read", "operation=read"),
113
- self.request("/admin/vpnconn?form=config&operation=list&vpntype=openvpn",
114
- "operation=list&operation=list&vpntype=openvpn"),
115
- self.request("/admin/vpnconn?form=config&operation=list&vpntype=pptp",
116
- "operation=list&operation=list&vpntype=pptp"),
117
- ]
118
-
119
- status.openvpn_enable = values[0]['enabled'] == 'on'
120
- status.pptpvpn_enable = values[1]['enabled'] == 'on'
121
-
122
- if isinstance(values[2], list):
123
- status.openvpn_clients_total = len(values[2])
124
- status.pptpvpn_clients_total = len(values[3])
125
- else:
126
- status.openvpn_clients_total = 0
127
- status.pptpvpn_clients_total = 0
128
-
129
- return status
130
-
131
- def set_vpn(self, vpn: VPN, enable: bool) -> None:
132
- path = "/admin/{}?form=config&operation=read".format(vpn.lowercase)
133
- current_config = self.request(path, "operation=read")
134
- current_config['enabled'] = "on" if enable else "off"
135
- data = urlencode(current_config)
136
- data = "&operation=write&{}".format(data)
137
- path = "/admin/{}?form=config{}".format(vpn.lowercase, data)
138
- self.request(path, data)
@@ -1,14 +1,23 @@
1
1
  from hashlib import md5
2
2
  from re import search
3
3
  from json import loads
4
+ from urllib.parse import urlencode
4
5
  from requests import post, Response
5
6
  from macaddress import EUI48
6
7
  from ipaddress import IPv4Address
7
8
  from logging import Logger
8
9
  from tplinkrouterc6u.common.helper import get_ip, get_mac
9
10
  from tplinkrouterc6u.common.encryption import EncryptionWrapper
10
- from tplinkrouterc6u.common.package_enum import Connection
11
- from tplinkrouterc6u.common.dataclass import Firmware, Status, Device, IPv4Reservation, IPv4DHCPLease, IPv4Status
11
+ from tplinkrouterc6u.common.package_enum import Connection, VPN
12
+ from tplinkrouterc6u.common.dataclass import (
13
+ Firmware,
14
+ Status,
15
+ Device,
16
+ IPv4Reservation,
17
+ IPv4DHCPLease,
18
+ IPv4Status,
19
+ VPNStatus,
20
+ )
12
21
  from tplinkrouterc6u.common.exception import ClientException, ClientError
13
22
  from tplinkrouterc6u.client_abstract import AbstractRouter
14
23
  from abc import abstractmethod
@@ -231,6 +240,10 @@ class TplinkBaseRouter(AbstractRouter, TplinkRequest):
231
240
  self._url_firmware = 'admin/firmware?form=upgrade&operation=read'
232
241
  self._url_ipv4_reservations = 'admin/dhcps?form=reservation&operation=load'
233
242
  self._url_ipv4_dhcp_leases = 'admin/dhcps?form=client&operation=load'
243
+ self._url_openvpn = 'admin/openvpn?form=config&operation=read'
244
+ self._url_pptpd = 'admin/pptpd?form=config&operation=read'
245
+ self._url_vpnconn_openvpn = 'admin/vpnconn?form=config&operation=list&vpntype=openvpn'
246
+ self._url_vpnconn_pptpd = 'admin/vpnconn?form=config&operation=list&vpntype=pptp'
234
247
  referer = '{}/webpages/index.html'.format(self.host)
235
248
  self._headers_request = {'Referer': referer}
236
249
  self._headers_login = {'Referer': referer, 'Content-Type': 'application/x-www-form-urlencoded'}
@@ -401,6 +414,36 @@ class TplinkBaseRouter(AbstractRouter, TplinkRequest):
401
414
 
402
415
  return dhcp_leases
403
416
 
417
+ def get_vpn_status(self) -> VPNStatus:
418
+ status = VPNStatus()
419
+
420
+ values = [
421
+ self.request(self._url_openvpn, "operation=read"),
422
+ self.request(self._url_pptpd, "operation=read"),
423
+ self.request(self._url_vpnconn_openvpn, "operation=list&vpntype=openvpn"),
424
+ self.request(self._url_vpnconn_pptpd, "operation=list&vpntype=pptp"),
425
+ ]
426
+
427
+ status.openvpn_enable = values[0]['enabled'] == 'on'
428
+ status.pptpvpn_enable = values[1]['enabled'] == 'on'
429
+
430
+ if isinstance(values[2], list):
431
+ status.openvpn_clients_total = len(values[2])
432
+ status.pptpvpn_clients_total = len(values[3])
433
+ else:
434
+ status.openvpn_clients_total = 0
435
+ status.pptpvpn_clients_total = 0
436
+
437
+ return status
438
+
439
+ def set_vpn(self, vpn: VPN, enable: bool) -> None:
440
+ path = self._url_openvpn if VPN.OPEN_VPN == vpn else self._url_pptpd
441
+ current_config = self.request(path, "operation=read")
442
+ current_config['enabled'] = "on" if enable else "off"
443
+ data = urlencode(current_config)
444
+ data = "operation=write&{}".format(data)
445
+ self.request(path, data)
446
+
404
447
  @staticmethod
405
448
  def _str2bool(v) -> bool | None:
406
449
  return str(v).lower() in ("yes", "true", "on") if v is not None else None
@@ -435,3 +478,7 @@ class TplinkRouter(TplinkEncryption, TplinkBaseRouter):
435
478
  self._url_firmware = 'admin/firmware?form=upgrade'
436
479
  self._url_ipv4_reservations = 'admin/dhcps?form=reservation'
437
480
  self._url_ipv4_dhcp_leases = 'admin/dhcps?form=client'
481
+ self._url_openvpn = 'admin/openvpn?form=config'
482
+ self._url_pptpd = 'admin/pptpd?form=config'
483
+ self._url_vpnconn_openvpn = 'admin/vpnconn?form=config'
484
+ self._url_vpnconn_pptpd = 'admin/vpnconn?form=config'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tplinkrouterc6u
3
- Version: 5.8.0
3
+ Version: 5.9.0
4
4
  Summary: TP-Link Router API (supports also Mercusys Router)
5
5
  Home-page: https://github.com/AlexandrErohin/TP-Link-Archer-C6U
6
6
  Author: Alex Erohin
@@ -59,6 +59,7 @@ from tplinkrouterc6u import (
59
59
  TPLinkXDRClient,
60
60
  TPLinkDecoClient,
61
61
  TplinkC80Router,
62
+ TplinkWDRRouter,
62
63
  Connection
63
64
  )
64
65
  from logging import Logger
@@ -312,6 +313,7 @@ or you have TP-link C5400X or similar router you need to get web encrypted passw
312
313
  - Archer AX3000 V1
313
314
  - Archer AX6000 V1
314
315
  - Archer AX11000 V1
316
+ - Archer BE400 v1.0
315
317
  - Archer BE550 v1.0
316
318
  - Archer BE800 v1.0
317
319
  - Archer BE805 v1.0
@@ -334,6 +336,7 @@ or you have TP-link C5400X or similar router you need to get web encrypted passw
334
336
  - Archer VR1200v v1
335
337
  - Archer VR2100v v1
336
338
  - Archer VX1800v v1.0
339
+ - BE11000 2.0
337
340
  - Deco M4 2.0
338
341
  - Deco M4R 2.0
339
342
  - Deco M5 v3
@@ -359,6 +362,7 @@ or you have TP-link C5400X or similar router you need to get web encrypted passw
359
362
  - TL-WA3001 v1.0
360
363
  - TL-XDR3010 V2
361
364
  - TL-WDR3600 V1
365
+ - VX420-G2h v1.1
362
366
  - XC220-G3v v2.30
363
367
  ### <a id="mercusys">MERCUSYS routers</a>
364
368
  - MR47BE v1.0
@@ -1,6 +1,6 @@
1
1
  test/__init__.py,sha256=McQmUjeN3AwmwdS6QNfwGXXE77OKoPK852I2BM9XsrU,210
2
- test/test_client_c1200.py,sha256=4RdwMEwTGWLOxOVTuPikifXDcUJFQ13DuyWGm2Aevrk,8811
3
- test/test_client_c6u.py,sha256=ulKoOJiwQVaBslY7kxCa7HmLaqTPzKJaNjm-xIBjB6A,33755
2
+ test/test_client_c1200.py,sha256=Sl-85JGqINNg-ckBZCIVqY0CC-V1UOc-yiIUljtePRM,7582
3
+ test/test_client_c6u.py,sha256=VpxF5etPtGYuXX9TfUl78tOj0pjozvPkrVx6FKbZDjQ,37585
4
4
  test/test_client_c80.py,sha256=RY_1SgRVcQQdN9h0_IXA0YW4_0flEB_uel05QvDDfws,42359
5
5
  test/test_client_deco.py,sha256=YPLKRD8GoyDYHfRgdXvCk8iVNw8zdMJW-AHVnNbpdTM,31719
6
6
  test/test_client_ex.py,sha256=0dVvOJqxpR2xNca99vadfdpxmzW-4sk9X_4tAK8x9-c,21710
@@ -11,9 +11,9 @@ tplinkrouterc6u/__init__.py,sha256=DDy6XVFH8Ne5C9JToRWNzRqevUfNutLUTlDhvIMsebo,1
11
11
  tplinkrouterc6u/client_abstract.py,sha256=3UYzmll774S_Gb5E0FTVO_rI3-XFM7PSklg1-V-2jls,1419
12
12
  tplinkrouterc6u/provider.py,sha256=bzH0WW2peC66f8NqfiI3t_niX6MFO8SAdKP9WZL-IV4,2152
13
13
  tplinkrouterc6u/client/__init__.py,sha256=KBy3fmtA9wgyFrb0Urh2x4CkKtWVnESdp-vxmuOvq0k,27
14
- tplinkrouterc6u/client/c1200.py,sha256=_nY_pJ-wPWODAaes9kHPdVcM6YM54f1E54CfdoFHqbE,4771
14
+ tplinkrouterc6u/client/c1200.py,sha256=4XEYidEGmVIJk0YQLvmTnd0Gqa7glH2gUWvjreHpWrk,3178
15
15
  tplinkrouterc6u/client/c5400x.py,sha256=9E0omBSbWY_ljrs5MTCMu5brmrLtzsDB5O62Db8lP8Q,4329
16
- tplinkrouterc6u/client/c6u.py,sha256=zcnMFsP-rn219PLfav-7KtHhOFkfrdtYnCyHWdcdKOw,17661
16
+ tplinkrouterc6u/client/c6u.py,sha256=3Jon6_WZkaCyrbTAp9TckB-SIXLP_JyB5gtRI65IuVI,19485
17
17
  tplinkrouterc6u/client/c80.py,sha256=ArVhza_fnXcEO-_fsQOd1l2QvmSfsswtohKxrZxEnoU,18568
18
18
  tplinkrouterc6u/client/deco.py,sha256=cpKRggKD2RvSmMZuD6tzsZmehAUCU9oLiTTHcZBW81Y,8898
19
19
  tplinkrouterc6u/client/ex.py,sha256=ZK08mlOts3fbBJh9NUrzBADP0N9LHgzOXCKY2tF9gG0,13111
@@ -27,8 +27,8 @@ tplinkrouterc6u/common/encryption.py,sha256=4HelTxzN6esMfDZRBt3m8bwB9Nj_biKijnCn
27
27
  tplinkrouterc6u/common/exception.py,sha256=_0G8ZvW5__CsGifHrsZeULdl8c6EUD071sDCQsQgrHY,140
28
28
  tplinkrouterc6u/common/helper.py,sha256=23b04fk9HuVinrZXMCS5R1rmF8uZ7eM-Cdnp7Br9NR0,572
29
29
  tplinkrouterc6u/common/package_enum.py,sha256=4ykL_2Pw0nDEIH_qR9UJlFF6stTgSfhPz32r8KT-sh8,1624
30
- tplinkrouterc6u-5.8.0.dist-info/licenses/LICENSE,sha256=YF6QR6Vjxcg5b_sYIyqkME7FZYau5TfEUGTG-0JeRK0,35129
31
- tplinkrouterc6u-5.8.0.dist-info/METADATA,sha256=XceOtjPvarwp7C7OvSVjvmFgLTU-nYDwu5K_DSMjbnc,15496
32
- tplinkrouterc6u-5.8.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
33
- tplinkrouterc6u-5.8.0.dist-info/top_level.txt,sha256=1iSCCIueqgEkrTxtQ-jiHe99jAB10zqrVdBcwvNfe_M,21
34
- tplinkrouterc6u-5.8.0.dist-info/RECORD,,
30
+ tplinkrouterc6u-5.9.0.dist-info/licenses/LICENSE,sha256=YF6QR6Vjxcg5b_sYIyqkME7FZYau5TfEUGTG-0JeRK0,35129
31
+ tplinkrouterc6u-5.9.0.dist-info/METADATA,sha256=PCYcU6cFG5lUp73dLZ-0UscRtpXxtWPan6B-J1tudlk,15568
32
+ tplinkrouterc6u-5.9.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
33
+ tplinkrouterc6u-5.9.0.dist-info/top_level.txt,sha256=1iSCCIueqgEkrTxtQ-jiHe99jAB10zqrVdBcwvNfe_M,21
34
+ tplinkrouterc6u-5.9.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.7.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5