p3lib 1.1.91__py3-none-any.whl → 1.1.92__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.
- p3lib/helper.py +7 -2
- p3lib/ssh.py +47 -6
- {p3lib-1.1.91.dist-info → p3lib-1.1.92.dist-info}/METADATA +1 -1
- {p3lib-1.1.91.dist-info → p3lib-1.1.92.dist-info}/RECORD +7 -7
- {p3lib-1.1.91.dist-info → p3lib-1.1.92.dist-info}/WHEEL +1 -1
- {p3lib-1.1.91.dist-info → p3lib-1.1.92.dist-info}/LICENSE +0 -0
- {p3lib-1.1.91.dist-info → p3lib-1.1.92.dist-info}/top_level.txt +0 -0
p3lib/helper.py
CHANGED
@@ -8,7 +8,8 @@ import os
|
|
8
8
|
import platform
|
9
9
|
import json
|
10
10
|
import traceback
|
11
|
-
import
|
11
|
+
import socket
|
12
|
+
import platform
|
12
13
|
|
13
14
|
def initArgs(parser, lastCmdLineArg=None, checkHostArg=True):
|
14
15
|
"""This method is responsible for
|
@@ -270,7 +271,11 @@ def getIntListUserResponse(uio, prompt, minValue=None, maxValue=None, allowQuit=
|
|
270
271
|
|
271
272
|
def getHomePath():
|
272
273
|
"""Get the user home path as this will be used to store config files"""
|
273
|
-
if
|
274
|
+
if platform.system() == 'Linux' and os.geteuid() == 0:
|
275
|
+
# Fix for os.environ["HOME"] returning /home/root sometimes.
|
276
|
+
return '/root/'
|
277
|
+
|
278
|
+
elif "HOME" in os.environ:
|
274
279
|
return os.environ["HOME"]
|
275
280
|
|
276
281
|
elif "HOMEDRIVE" in os.environ and "HOMEPATH" in os.environ:
|
p3lib/ssh.py
CHANGED
@@ -310,6 +310,14 @@ class SSH(object):
|
|
310
310
|
if self._uio:
|
311
311
|
self._uio.debug(text)
|
312
312
|
|
313
|
+
def isConnected(self):
|
314
|
+
"""@brief Check if a connection is active.
|
315
|
+
@return True if connected."""
|
316
|
+
connected = False
|
317
|
+
if self._ssh and self._ssh.get_transport() is not None:
|
318
|
+
connected = self._ssh.get_transport().is_active()
|
319
|
+
return connected
|
320
|
+
|
313
321
|
def _connect(self, connectSFTPSession=False, timeout=DEFAULT_SSH_CONNECTION_TIMEOUT):
|
314
322
|
"""@brief Connect the ssh connection
|
315
323
|
@param connectSFTPSession If True then just after the ssh connection
|
@@ -675,7 +683,7 @@ class SSHTunnelManager(object):
|
|
675
683
|
if self._uio:
|
676
684
|
self._uio.error(text)
|
677
685
|
|
678
|
-
def startFwdSSHTunnel(self, serverPort, destHost, destPort):
|
686
|
+
def startFwdSSHTunnel(self, serverPort, destHost, destPort, serverBindAddress=''):
|
679
687
|
"""@brief Start an ssh port forwarding tunnel. This is a non blocking method.
|
680
688
|
A separate thread will be started to handle data transfer over the
|
681
689
|
ssh forwarding connection.
|
@@ -685,7 +693,8 @@ class SSHTunnelManager(object):
|
|
685
693
|
@param destHost The host address of the tunnel destination at the remote
|
686
694
|
end of the ssh connection.
|
687
695
|
@param destPort The host TCP port of the tunnel destination at the remote
|
688
|
-
end of the ssh connection.
|
696
|
+
end of the ssh connection.
|
697
|
+
@param serverBindAddress The server address to bind to."""
|
689
698
|
self._info("Forwarding local TCP server port (%d) to %s:%d on the remote end of the ssh connection." % (
|
690
699
|
serverPort, destHost, destPort))
|
691
700
|
transport = self._ssh.getTransport()
|
@@ -697,12 +706,26 @@ class SSHTunnelManager(object):
|
|
697
706
|
ssh_transport.use_compression(self._useCompression)
|
698
707
|
uo = self._uio
|
699
708
|
|
700
|
-
forwardingServer = ForwardingServer((
|
709
|
+
forwardingServer = ForwardingServer((serverBindAddress, serverPort), SubHander)
|
701
710
|
self._forwardingServerList.append(forwardingServer)
|
702
711
|
newThread = threading.Thread(target=forwardingServer.serve_forever)
|
703
712
|
newThread.daemon = True
|
704
713
|
newThread.start()
|
705
714
|
|
715
|
+
def startFwdTunnel(self, serverBindAddress, serverPort, destHost, destPort):
|
716
|
+
"""@brief Another method to start a forward SSH tunnel. startFwdSSHTunnel() was the original method.
|
717
|
+
We needed to keep this interface. However I wanted an interface to force the user to enter a bind
|
718
|
+
address on the server.
|
719
|
+
@param serverBindAddress The server address to bind to.
|
720
|
+
@param serverPort The TCP server port. On a port forwarding connection
|
721
|
+
the TCP server runs on the src end of the ssh connection.
|
722
|
+
This is the machine that this python code is executing on.
|
723
|
+
@param destHost The host address of the tunnel destination at the remote
|
724
|
+
end of the ssh connection.
|
725
|
+
@param destPort The host TCP port of the tunnel destination at the remote
|
726
|
+
end of the ssh connection."""
|
727
|
+
self.startFwdSSHTunnel(serverPort, destHost, destPort, serverBindAddress=serverBindAddress)
|
728
|
+
|
706
729
|
def stopFwdSSHTunnel(self, serverPort):
|
707
730
|
"""@brief stop a previously started ssh port forwarding server
|
708
731
|
@param serverPort The TCP server port which is currently accepting
|
@@ -721,7 +744,7 @@ class SSHTunnelManager(object):
|
|
721
744
|
forwardingServer.server_close()
|
722
745
|
self._info("Shutdown ssh port forwarding on %s." % (str(forwardingServer.server_address)))
|
723
746
|
|
724
|
-
def startRevSSHTunnel(self, serverPort, destHost, destPort):
|
747
|
+
def startRevSSHTunnel(self, serverPort, destHost, destPort, serverBindAddress=''):
|
725
748
|
"""@brief Start an ssh reverse port forwarding tunnel
|
726
749
|
@param serverPort The TCP server port. On a reverse port forwarding connection
|
727
750
|
the TCP server runs on the dest end of the ssh connection.
|
@@ -729,7 +752,8 @@ class SSHTunnelManager(object):
|
|
729
752
|
@param destHost The host address of the tunnel destination at the local
|
730
753
|
end of the ssh connection.
|
731
754
|
@param destPort The host TCP port of the tunnel destination at the local
|
732
|
-
end of the ssh connection.
|
755
|
+
end of the ssh connection.
|
756
|
+
@param serverBindAddress The server address to bind to."""
|
733
757
|
self._info("Forwarding (reverse) Remote TCP server port (%d) to %s:%d on this end of the ssh connection." % (
|
734
758
|
serverPort, destHost, destPort))
|
735
759
|
# We add the None refs as the placeholders will be used later
|
@@ -738,7 +762,24 @@ class SSHTunnelManager(object):
|
|
738
762
|
self._reverseSShDict[serverPort] = (destHost, destPort, chan, sock)
|
739
763
|
|
740
764
|
self._ssh.getTransport().use_compression(self._useCompression)
|
741
|
-
|
765
|
+
#serverBindAddress = "0.0.0.0"
|
766
|
+
print(f"PJA: BIND ADDR: {serverBindAddress}")
|
767
|
+
self._ssh.getTransport().request_port_forward(serverBindAddress, serverPort, handler=self._startReverseForwardingHandler)
|
768
|
+
|
769
|
+
def startRevTunnel(self, serverBindAddress, serverPort, destHost, destPort):
|
770
|
+
"""@brief Another method to start a reverse SSH tunnerl. startRevSSHTunnel() was the original method.
|
771
|
+
We needed to keep this interface. However I wanted an interface to force the user to enter a bind
|
772
|
+
address on the server.
|
773
|
+
@param serverBindAddress The server address to bind to.
|
774
|
+
@param serverPort The TCP server port. On a reverse port forwarding connection
|
775
|
+
the TCP server runs on the dest end of the ssh connection.
|
776
|
+
This is the machine at the remote end of the ssh connection.
|
777
|
+
@param destHost The host address of the tunnel destination at the local
|
778
|
+
end of the ssh connection.
|
779
|
+
@param destPort The host TCP port of the tunnel destination at the local
|
780
|
+
end of the ssh connection."""
|
781
|
+
|
782
|
+
self.startRevSSHTunnel(serverPort, destHost, destPort, serverBindAddress=serverBindAddress)
|
742
783
|
|
743
784
|
def stopRevSSHTunnel(self, serverPort):
|
744
785
|
"""@brief stop a previously started reverse ssh port forwarding server
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: p3lib
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.92
|
4
4
|
Summary: A group of python modules for networking, plotting data, config storage, automating boot scripts, ssh access and user input output.
|
5
5
|
Home-page: https://github.com/pjaos/p3lib
|
6
6
|
Author: Paul Austen
|
@@ -5,18 +5,18 @@ p3lib/bokeh_gui.py,sha256=55sajP_x9O1lE0uP3w3-T5f2oMzk7jSolLqxlEdLeLg,40245
|
|
5
5
|
p3lib/boot_manager.py,sha256=h5In_QoRDH8oHivcu4gyTzGXWg3joKBiVCz2B8Ttn8E,16941
|
6
6
|
p3lib/conduit.py,sha256=jPkjdtyCx2I6SFqcEo8y2g7rgnZ-jNY7oCuYIETzT5Q,6046
|
7
7
|
p3lib/database_if.py,sha256=XKu1w3zftGbj4Rh54wrWJnoCtqHkhCzJUPN2S70XIKg,11915
|
8
|
-
p3lib/helper.py,sha256
|
8
|
+
p3lib/helper.py,sha256=LVLz-CxXyolX6Ys3coxQyU77SFFEtd5jHb9CDGrd8u0,12036
|
9
9
|
p3lib/json_networking.py,sha256=6u4s1SmypjTYPnSxHP712OgQ3ZJaxOqIkgHQ1J7Qews,9738
|
10
10
|
p3lib/mqtt_rpc.py,sha256=6LmFA1kR4HSJs9eWbOJORRHNY01L_lHWjvtE2fmY8P8,10511
|
11
11
|
p3lib/netif.py,sha256=3QV5OGdHhELIf4MBj6mx5MNCtVeZ7JXoNEkeu4KzCaE,9796
|
12
12
|
p3lib/netplotly.py,sha256=PMDx-w1jtRVW6Od5u_kuKbBxNpTS_Y88mMF60puMxLM,9363
|
13
13
|
p3lib/ngt.py,sha256=rXA-6zQkfeOupZ-3Q-k3-1DvbKYIi2TCtLKgUb0waWY,37726
|
14
14
|
p3lib/pconfig.py,sha256=82rX7zvJVbSFtYYHvhj9I6GTdpjf9v73fNs9WQE-5ik,35388
|
15
|
-
p3lib/ssh.py,sha256=
|
15
|
+
p3lib/ssh.py,sha256=j08l94U0m8PDAtRi3b_iKs1flUHzEbW57lbk5CeLfCg,42218
|
16
16
|
p3lib/table_plot.py,sha256=RPncwVlGUkkx5Fw0dHQedXo0TSPlTi__VrJBDzaMsuI,32116
|
17
17
|
p3lib/uio.py,sha256=Aaxc99XiE3d2f9vLjaN-bZsckoNxay5t0ujdK6PXGrw,23265
|
18
|
-
p3lib-1.1.
|
19
|
-
p3lib-1.1.
|
20
|
-
p3lib-1.1.
|
21
|
-
p3lib-1.1.
|
22
|
-
p3lib-1.1.
|
18
|
+
p3lib-1.1.92.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
|
19
|
+
p3lib-1.1.92.dist-info/METADATA,sha256=VqQPrSElb7irOKEodRxjVMRAYFTMnEaRomKrAWi1mjE,918
|
20
|
+
p3lib-1.1.92.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
21
|
+
p3lib-1.1.92.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
|
22
|
+
p3lib-1.1.92.dist-info/RECORD,,
|
File without changes
|
File without changes
|