mirror of
https://github.com/HuFlungDu/pylibmeshctrl.git
synced 2026-02-20 13:42:11 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04c8f622de | ||
|
|
ccb5f1eb40 | ||
|
|
ce2cf2bfe1 | ||
|
|
a3b4962e7f | ||
|
|
5947e48c5b | ||
|
|
31a8f00cd0 | ||
|
|
871d36b334 | ||
|
|
59fb1f104e | ||
|
|
9bd3e10ed7 | ||
|
|
28e1d94ab9 | ||
|
|
51325a89d3 | ||
|
|
97dff80222 | ||
|
|
8da445348b | ||
|
|
ab1fba5cc1 | ||
|
|
34a80cdda7 | ||
|
|
fcf523dd62 | ||
|
|
9a1311167d | ||
|
|
c2319fcf29 | ||
|
|
4d1c25a35c | ||
|
|
e226fff8dd | ||
|
|
a07b0f129a | ||
|
|
64dc5eccdf | ||
|
|
1a7714663a | ||
|
|
0a59edd19a | ||
|
|
f8600b09fe | ||
|
|
351f425ce5 | ||
|
|
77e76aeb7c | ||
|
|
5393321f7b | ||
|
|
79554ebad6 | ||
|
|
1dbcd012ec | ||
|
|
61eebf1532 |
@@ -2,6 +2,36 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
version 1.2.1
|
||||||
|
=============
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
* Fixed handling of meshcentral's list_devices return with details=True
|
||||||
|
|
||||||
|
version 1.2.0
|
||||||
|
=============
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
* Fixed agent sometimes being None causing an oxception
|
||||||
|
* Fixed bad code in device_open_url
|
||||||
|
|
||||||
|
Features:
|
||||||
|
* Changed websockets version to 15. This now uses the proxy implemention from that library, instead of the previous hack.
|
||||||
|
* Added lastaddr and lastconnect to list_devices API
|
||||||
|
|
||||||
|
version 1.1.2
|
||||||
|
=============
|
||||||
|
Bugs:
|
||||||
|
* Fixed semver for requirements. New version of websockets broke this library.
|
||||||
|
|
||||||
|
Security:
|
||||||
|
* Updated cryptogaphy to ~44.0.1 to fix ssl vulnerability.
|
||||||
|
|
||||||
|
Version 1.1.1
|
||||||
|
=============
|
||||||
|
Bugs:
|
||||||
|
* Fixed bug when running device_info when user has access to multiple meshes
|
||||||
|
|
||||||
Version 1.1.0
|
Version 1.1.0
|
||||||
=============
|
=============
|
||||||
Features:
|
Features:
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ sphinx>=3.2.1
|
|||||||
sphinx-jinja2-compat>=0.1.1
|
sphinx-jinja2-compat>=0.1.1
|
||||||
sphinx-toolbox>=2.16.0
|
sphinx-toolbox>=2.16.0
|
||||||
# sphinx_rtd_theme
|
# sphinx_rtd_theme
|
||||||
cffi==1.17.1
|
cffi~=1.17.1
|
||||||
cryptography==43.0.3
|
cryptography~=44.0.1
|
||||||
pycparser==2.22
|
pycparser~=2.22
|
||||||
websockets==13.1
|
websockets~=15.0.0
|
||||||
enum_tools
|
enum_tools
|
||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@@ -44,9 +44,9 @@ python_requires = >=3.8
|
|||||||
# For more information, check out https://semver.org/.
|
# For more information, check out https://semver.org/.
|
||||||
install_requires =
|
install_requires =
|
||||||
importlib-metadata
|
importlib-metadata
|
||||||
cryptography>=43.0.3
|
cryptography~=44.0.1
|
||||||
websockets>=13.1
|
websockets~=15.0.0
|
||||||
python-socks[asyncio]
|
python-socks[asyncio]~=2.5.3
|
||||||
|
|
||||||
|
|
||||||
[options.packages.find]
|
[options.packages.find]
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class Device(object):
|
|||||||
def __init__(self, nodeid, session, agent=None,
|
def __init__(self, nodeid, session, agent=None,
|
||||||
name=None, desc=None, description=None,
|
name=None, desc=None, description=None,
|
||||||
tags=None, users=None,
|
tags=None, users=None,
|
||||||
agct=None, created_at=None,
|
agct=None, created_at=None,
|
||||||
rname=None, computer_name=None, icon=constants.Icon.desktop,
|
rname=None, computer_name=None, icon=constants.Icon.desktop,
|
||||||
mesh=None, mtype=None, meshtype=None, groupname=None, meshname=None,
|
mesh=None, mtype=None, meshtype=None, groupname=None, meshname=None,
|
||||||
domain=None, host=None, ip=None, conn=None, connected=None,
|
domain=None, host=None, ip=None, conn=None, connected=None,
|
||||||
@@ -71,7 +71,7 @@ class Device(object):
|
|||||||
if links is None:
|
if links is None:
|
||||||
links = {}
|
links = {}
|
||||||
self.links = links
|
self.links = links
|
||||||
if ("ver" in agent):
|
if agent and "ver" in agent:
|
||||||
agent = {
|
agent = {
|
||||||
"version": agent["ver"],
|
"version": agent["ver"],
|
||||||
"id": agent["id"],
|
"id": agent["id"],
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ class Session(object):
|
|||||||
|
|
||||||
|
|
||||||
options["additional_headers"] = headers
|
options["additional_headers"] = headers
|
||||||
async for websocket in util.proxy_connect(self.url, proxy_url=self._proxy, process_exception=util._process_websocket_exception, **options):
|
async for websocket in websockets.asyncio.client.connect(self.url, proxy=self._proxy, process_exception=util._process_websocket_exception, **options):
|
||||||
self.alive = True
|
self.alive = True
|
||||||
self._socket_open.set()
|
self._socket_open.set()
|
||||||
try:
|
try:
|
||||||
@@ -478,10 +478,21 @@ class Session(object):
|
|||||||
if "result" in res0:
|
if "result" in res0:
|
||||||
raise exceptions.ServerError(res0["result"])
|
raise exceptions.ServerError(res0["result"])
|
||||||
if details:
|
if details:
|
||||||
nodes = json.loads(res0["data"])
|
nodes = res0["data"]
|
||||||
|
# Accept any number of nested strings, meshcentral is odd
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
nodes = json.loads(nodes)
|
||||||
|
except TypeError:
|
||||||
|
break
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
if node["node"].get("meshid", None):
|
if node["node"].get("meshid", None):
|
||||||
node["node"]["mesh"] = mesh.Mesh(node["node"].get("meshid"), self)
|
node["node"]["mesh"] = mesh.Mesh(node["node"].get("meshid"), self)
|
||||||
|
if "lastConnect" in node and isinstance(node["lastConnect"], dict):
|
||||||
|
node["node"]["lastconnect"] = node["lastConnect"].get("time")
|
||||||
|
node["node"]["lastaddr"] = node["lastConnect"].get("addr")
|
||||||
|
del node["lastConnect"]
|
||||||
details = {}
|
details = {}
|
||||||
for key, val in node.items():
|
for key, val in node.items():
|
||||||
if key != "node":
|
if key != "node":
|
||||||
@@ -1363,10 +1374,10 @@ class Session(object):
|
|||||||
node["meshid"] = meshid
|
node["meshid"] = meshid
|
||||||
if _mesh is not None:
|
if _mesh is not None:
|
||||||
node["mesh"] = _mesh
|
node["mesh"] = _mesh
|
||||||
sysinfo["node"] = node
|
break
|
||||||
sysinfo["nodeid"] = nodeid
|
else:
|
||||||
del sysinfo["result"]
|
continue
|
||||||
del sysinfo["noinfo"]
|
break
|
||||||
if node is None:
|
if node is None:
|
||||||
raise ValueError("Invalid device id")
|
raise ValueError("Invalid device id")
|
||||||
if lastconnect is not None:
|
if lastconnect is not None:
|
||||||
@@ -1737,10 +1748,11 @@ class Session(object):
|
|||||||
tasks.append(tg.create_task(asyncio.wait_for(_(), timeout=timeout)))
|
tasks.append(tg.create_task(asyncio.wait_for(_(), timeout=timeout)))
|
||||||
tasks.append({ "action": 'msg', "type": 'openUrl', "nodeid": nodeid, "url": url }, "device_open_url", timeout=timeout)
|
tasks.append({ "action": 'msg', "type": 'openUrl', "nodeid": nodeid, "url": url }, "device_open_url", timeout=timeout)
|
||||||
|
|
||||||
|
|
||||||
|
success = tasks[0].result()
|
||||||
res = tasks[1].result()
|
res = tasks[1].result()
|
||||||
success = tasks[2].result()
|
|
||||||
|
|
||||||
if data.get("result", "ok").lower() != "ok":
|
if res.get("result", "ok").lower() != "ok":
|
||||||
raise exceptions.ServerError(data["result"])
|
raise exceptions.ServerError(data["result"])
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
@@ -1964,4 +1976,4 @@ class _FileExplorerWrapper:
|
|||||||
return await self._files.__aenter__()
|
return await self._files.__aenter__()
|
||||||
|
|
||||||
async def __aexit__(self, exc_t, exc_v, exc_tb):
|
async def __aexit__(self, exc_t, exc_v, exc_tb):
|
||||||
return await self._files.__aexit__(exc_t, exc_v, exc_tb)
|
return await self._files.__aexit__(exc_t, exc_v, exc_tb)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class Tunnel(object):
|
|||||||
self.url = self._session.url.replace('/control.ashx', '/meshrelay.ashx?browser=1&p=' + str(self._protocol) + '&nodeid=' + self.node_id + '&id=' + self._tunnel_id + '&auth=' + self._authcookie["cookie"])
|
self.url = self._session.url.replace('/control.ashx', '/meshrelay.ashx?browser=1&p=' + str(self._protocol) + '&nodeid=' + self.node_id + '&id=' + self._tunnel_id + '&auth=' + self._authcookie["cookie"])
|
||||||
|
|
||||||
|
|
||||||
async for websocket in util.proxy_connect(self.url, proxy_url=self._session._proxy, process_exception=util._process_websocket_exception, **options):
|
async for websocket in websockets.asyncio.client.connect(self.url, proxy=self._session._proxy, process_exception=util._process_websocket_exception, **options):
|
||||||
self.alive = True
|
self.alive = True
|
||||||
self._socket_open.set()
|
self._socket_open.set()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import ssl
|
|||||||
import functools
|
import functools
|
||||||
import urllib
|
import urllib
|
||||||
import python_socks
|
import python_socks
|
||||||
from python_socks.async_.asyncio import Proxy
|
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
|
|
||||||
def _encode_cookie(o, key):
|
def _encode_cookie(o, key):
|
||||||
@@ -164,17 +163,7 @@ def _process_websocket_exception(exc):
|
|||||||
return exc
|
return exc
|
||||||
if isinstance(exc, python_socks._errors.ProxyError):
|
if isinstance(exc, python_socks._errors.ProxyError):
|
||||||
return None
|
return None
|
||||||
return tmp
|
# Proxy errors show up like this now, and it's default to error out. Handle explicitly.
|
||||||
|
if isinstance(exc, websockets.exceptions.InvalidProxyMessage):
|
||||||
class proxy_connect(websockets.asyncio.client.connect):
|
return None
|
||||||
def __init__(self,*args, proxy_url=None, **kwargs):
|
return tmp
|
||||||
self.proxy = None
|
|
||||||
if proxy_url is not None:
|
|
||||||
self.proxy = Proxy.from_url(proxy_url)
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
async def create_connection(self, *args, **kwargs):
|
|
||||||
if self.proxy is not None:
|
|
||||||
parsed = urllib.parse.urlparse(self.uri)
|
|
||||||
self.connection_kwargs["sock"] = await self.proxy.connect(dest_host=parsed.hostname, dest_port=parsed.port)
|
|
||||||
return await super().create_connection(*args, **kwargs)
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
requests
|
requests
|
||||||
pytest-asyncio
|
pytest-asyncio
|
||||||
cffi==1.17.1
|
cffi==1.17.1
|
||||||
cryptography==43.0.3
|
cryptography~=44.0.1
|
||||||
pycparser==2.22
|
pycparser==2.22
|
||||||
websockets==13.1
|
websockets~=15.0.0
|
||||||
@@ -120,7 +120,7 @@ async def test_upload_download(env):
|
|||||||
downfilestream.seek(0)
|
downfilestream.seek(0)
|
||||||
|
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
r = await files.download(f"{pwd}/test", downfilestream, skip_http_attempt=True, timeout=5)
|
r = await files.download(f"{pwd}/test", downfilestream, skip_http_attempt=True, timeout=20)
|
||||||
print("\ninfo files_download: {}\n".format(r))
|
print("\ninfo files_download: {}\n".format(r))
|
||||||
assert r["result"] == True, "Download failed"
|
assert r["result"] == True, "Download failed"
|
||||||
assert r["size"] == len(randdata), "Downloaded wrong number of bytes"
|
assert r["size"] == len(randdata), "Downloaded wrong number of bytes"
|
||||||
|
|||||||
@@ -46,9 +46,11 @@ async def test_auto_reconnect(env):
|
|||||||
for i in range(3):
|
for i in range(3):
|
||||||
try:
|
try:
|
||||||
await admin_session.ping(timeout=10)
|
await admin_session.ping(timeout=10)
|
||||||
except:
|
except* Exception as e:
|
||||||
continue
|
print("".join(traceback.format_exception(e)))
|
||||||
break
|
pass
|
||||||
|
else:
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
raise Exception("Failed to reconnect")
|
raise Exception("Failed to reconnect")
|
||||||
|
|
||||||
@@ -57,6 +59,7 @@ async def test_auto_reconnect(env):
|
|||||||
try:
|
try:
|
||||||
await admin_session.ping(timeout=10)
|
await admin_session.ping(timeout=10)
|
||||||
except* Exception as e:
|
except* Exception as e:
|
||||||
|
print("".join(traceback.format_exception(e)))
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
@@ -200,15 +203,17 @@ async def test_mesh_device(env):
|
|||||||
|
|
||||||
assert r[0].description == "New description", "Description either failed to change, or was changed by a user without permission to do so"
|
assert r[0].description == "New description", "Description either failed to change, or was changed by a user without permission to do so"
|
||||||
|
|
||||||
|
# There once was a bug that occured whenever running run_commands with multiple meshes. We need to add devices to both meshes to be sure that bug is squashed.
|
||||||
with env.create_agent(mesh.short_meshid) as agent,\
|
with env.create_agent(mesh.short_meshid) as agent,\
|
||||||
env.create_agent(mesh.short_meshid) as agent2:
|
env.create_agent(mesh.short_meshid) as agent2,\
|
||||||
|
env.create_agent(mesh2.short_meshid) as agent3:
|
||||||
# Test agent added to device group being propagated correctly
|
# Test agent added to device group being propagated correctly
|
||||||
# Create agent isn't so good at waiting for the agent to show in the sessions. Give it a couple seconds to appear.
|
# Create agent isn't so good at waiting for the agent to show in the sessions. Give it a couple seconds to appear.
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
try:
|
try:
|
||||||
r = await admin_session.list_devices(timeout=10)
|
r = await admin_session.list_devices(timeout=10)
|
||||||
print("\ninfo list_devices: {}\n".format(r))
|
print("\ninfo list_devices: {}\n".format(r))
|
||||||
assert len(r) == 2, "Incorrect number of agents connected"
|
assert len(r) == 3, "Incorrect number of agents connected"
|
||||||
except:
|
except:
|
||||||
if i == 2:
|
if i == 2:
|
||||||
raise
|
raise
|
||||||
@@ -227,6 +232,9 @@ async def test_mesh_device(env):
|
|||||||
r = await admin_session.list_devices(meshid=mesh.meshid, timeout=10)
|
r = await admin_session.list_devices(meshid=mesh.meshid, timeout=10)
|
||||||
print("\ninfo list_devices_meshid: {}\n".format(r))
|
print("\ninfo list_devices_meshid: {}\n".format(r))
|
||||||
|
|
||||||
|
r = await admin_session.device_info(agent.nodeid, timeout=10)
|
||||||
|
print("\ninfo admin_device_info: {}\n".format(r))
|
||||||
|
|
||||||
# Test editing device info propagating correctly
|
# Test editing device info propagating correctly
|
||||||
assert await admin_session.edit_device(agent.nodeid, name="new_name", description="New Description", tags="device", consent=meshctrl.constants.ConsentFlags.all, timeout=10), "Failed to edit device info"
|
assert await admin_session.edit_device(agent.nodeid, name="new_name", description="New Description", tags="device", consent=meshctrl.constants.ConsentFlags.all, timeout=10), "Failed to edit device info"
|
||||||
|
|
||||||
@@ -269,7 +277,7 @@ async def test_mesh_device(env):
|
|||||||
|
|
||||||
# Test getting individual device info
|
# Test getting individual device info
|
||||||
r = await unprivileged_session.device_info(agent.nodeid, timeout=10)
|
r = await unprivileged_session.device_info(agent.nodeid, timeout=10)
|
||||||
print("\ninfo device_info: {}\n".format(r))
|
print("\ninfo unprivileged_device_info: {}\n".format(r))
|
||||||
|
|
||||||
# This device info includes the mesh ID of the device, even though the user doesn't have acces to that mesh. That's odd.
|
# This device info includes the mesh ID of the device, even though the user doesn't have acces to that mesh. That's odd.
|
||||||
# assert r.meshid is None, "Individual device is exposing its meshid"
|
# assert r.meshid is None, "Individual device is exposing its meshid"
|
||||||
|
|||||||
Reference in New Issue
Block a user