p3lib 1.1.66__py3-none-any.whl → 1.1.68__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/bokeh_auth.py CHANGED
@@ -15,18 +15,22 @@ from argon2 import PasswordHasher
15
15
  from argon2.exceptions import VerificationError
16
16
  from datetime import datetime
17
17
 
18
+ # could also define get_login_url function (but must give up LoginHandler)
19
+ login_url = "/login"
20
+
18
21
  CRED_FILE_KEY = "CRED_FILE"
19
22
  LOGIN_HTML_FILE_KEY = "LOGIN_HTML_FILE"
20
23
  ACCESS_LOG_FILE = "ACCESS_LOG_FILE"
21
24
 
22
25
  # could define get_user_async instead
23
26
  def get_user(request_handler):
27
+ # Record the get request
28
+ LoginHandler.RecordGet(request_handler.request.remote_ip)
24
29
  user = request_handler.get_cookie("user")
30
+ # Record the user making the request
31
+ LoginHandler.SaveInfoAccessLogMessage(f"USER={user}")
25
32
  return user
26
33
 
27
- # could also define get_login_url function (but must give up LoginHandler)
28
- login_url = "/login"
29
-
30
34
  def GetAuthAttrFile():
31
35
  """@brief Get the file that is used to pass parameters (credentials file and login.html file) to the tornado server.
32
36
  There must be a better way of passing the credentials file to the tornado login handler than this..."""
@@ -73,19 +77,22 @@ def GetAccessLogFile():
73
77
  # optional login page for login_url
74
78
  class LoginHandler(RequestHandler):
75
79
 
76
- def _recordGet(self):
77
- """@brief Record an HHTP get on the login page."""
78
- self._saveInfoAccessLogMessage(f"HTTP GET from {self.request.remote_ip}")
80
+ @staticmethod
81
+ def RecordGet(remoteIP):
82
+ """@brief Record an HHTP get on the login page.
83
+ @param remoteIP The IP address of the client."""
84
+ msg = f"HTTP GET from {remoteIP}"
85
+ LoginHandler.SaveInfoAccessLogMessage(msg)
79
86
  try:
80
87
  # We import here so that the p3lib module will import even if ip2geotools
81
- # is not available as pip install ip2geotools adds in 73 python modules !!!
88
+ # is not available as pip install ip2geotools adds in ~ 70 python modules !!!
82
89
  from ip2geotools.databases.noncommercial import DbIpCity
83
- response = DbIpCity.get(self.request.remote_ip, api_key='free')
84
- self._saveInfoAccessLogMessage(f"HTTP GET country = {response.country}")
85
- self._saveInfoAccessLogMessage(f"HTTP GET region = {response.region}")
86
- self._saveInfoAccessLogMessage(f"HTTP GET city = {response.city}")
87
- self._saveInfoAccessLogMessage(f"HTTP GET latitude = {response.latitude}")
88
- self._saveInfoAccessLogMessage(f"HTTP GET longitude = {response.longitude}")
90
+ response = DbIpCity.get(remoteIP, api_key='free')
91
+ LoginHandler.SaveInfoAccessLogMessage(f"HTTP GET country = {response.country}")
92
+ LoginHandler.SaveInfoAccessLogMessage(f"HTTP GET region = {response.region}")
93
+ LoginHandler.SaveInfoAccessLogMessage(f"HTTP GET city = {response.city}")
94
+ LoginHandler.SaveInfoAccessLogMessage(f"HTTP GET latitude = {response.latitude}")
95
+ LoginHandler.SaveInfoAccessLogMessage(f"HTTP GET longitude = {response.longitude}")
89
96
  except:
90
97
  pass
91
98
 
@@ -94,26 +101,23 @@ class LoginHandler(RequestHandler):
94
101
  @param username The username entered.
95
102
  @param password The password entered."""
96
103
  pw = "*"*len(password)
97
- self._saveInfoAccessLogMessage(f"Login attempt from {self.request.remote_ip}: username = {username}, password={pw}")
104
+ LoginHandler.SaveInfoAccessLogMessage(f"Login attempt from {self.request.remote_ip}: username = {username}, password={pw}")
98
105
 
99
106
  def _recordLoginSuccess(self, username, password):
100
107
  """@brief Record a successful login to the server.
101
108
  @param username The username entered.
102
109
  @param password The password entered."""
103
110
  pw = "*"*len(password)
104
- self._saveInfoAccessLogMessage(f"Login success from {self.request.remote_ip}: username = {username}, password={pw}")
105
-
106
- def _saveInfoAccessLogMessage(self, msg):
107
- """@brief Save an info level access log message.
108
- @param msg The message to save to the access log."""
109
- self._saveAccessLogMessage("INFO: "+str(msg))
111
+ LoginHandler.SaveInfoAccessLogMessage(f"Login success from {self.request.remote_ip}: username = {username}, password={pw}")
110
112
 
111
- def _saveErrorAccessLogMessage(self, msg):
113
+ @staticmethod
114
+ def SaveInfoAccessLogMessage(msg):
112
115
  """@brief Save an info level access log message.
113
116
  @param msg The message to save to the access log."""
114
- self._saveAccessLogMessage("ERROR: "+str(msg))
117
+ LoginHandler.SaveAccessLogMessage("INFO: "+str(msg))
115
118
 
116
- def _saveAccessLogMessage(self, msg):
119
+ @staticmethod
120
+ def SaveAccessLogMessage(msg):
117
121
  """@brief Save an access log message.
118
122
  @param msg The message to save to the access log."""
119
123
  now = datetime.now()
@@ -132,7 +136,6 @@ class LoginHandler(RequestHandler):
132
136
  pass
133
137
 
134
138
  def get(self):
135
- self._recordGet()
136
139
  try:
137
140
  errormessage = self.get_argument("error")
138
141
  except Exception:
@@ -166,10 +169,10 @@ class LoginHandler(RequestHandler):
166
169
  def set_current_user(self, user):
167
170
  if user:
168
171
  self.set_cookie("user", tornado.escape.json_encode(user))
169
- self._saveInfoAccessLogMessage(f"Set user cookie: user={user}")
172
+ LoginHandler.SaveInfoAccessLogMessage(f"Set user cookie: user={user}")
170
173
  else:
171
174
  self.clear_cookie("user")
172
- self._saveInfoAccessLogMessage("Cleared user cookie")
175
+ LoginHandler.SaveInfoAccessLogMessage("Cleared user cookie")
173
176
 
174
177
  # optional logout_url, available as curdoc().session_context.logout_url
175
178
  logout_url = "/logout"
p3lib/ssh.py CHANGED
@@ -331,8 +331,10 @@ class SSH(object):
331
331
  'timeout': timeout,
332
332
  'username': self._username,
333
333
  'key_filename': privateKeyFile,
334
- # This is required of else loging in without the password fails.
335
- 'disabled_algorithms': dict(pubkeys=['rsa-sha2-256', 'rsa-sha2-512'])
334
+ # This used to be required or else loging in without the password would fail.
335
+ # This is no longer true for the latest paramiko as of 8 Mar 2024.
336
+ # Therefore this workaround has been removed but shown in place in case of future issues.
337
+ #'disabled_algorithms': dict(pubkeys=['rsa-sha2-256', 'rsa-sha2-512'])
336
338
  }
337
339
  # If we have a password then add this to the config
338
340
  if self._password and len(self._password) > 0:
@@ -340,6 +342,12 @@ class SSH(object):
340
342
  self._ssh.connect(**cfg)
341
343
  connected = True
342
344
  break
345
+
346
+ # Ensure we throw an exception in the event of authencication failure as this ensures
347
+ # that the code to triggers the code to allow the user to copy thier public ssh key to
348
+ # the server in order that future logins are passwordless.
349
+ except AuthenticationException:
350
+ raise
343
351
 
344
352
  except:
345
353
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: p3lib
3
- Version: 1.1.66
3
+ Version: 1.1.68
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
@@ -1,6 +1,6 @@
1
1
  p3lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  p3lib/ate.py,sha256=_BiqMUYNAlp4O8MkP_PAUe62Bzd8dzV4Ipv62OFS6Ok,4759
3
- p3lib/bokeh_auth.py,sha256=oyDGoJ4h1D2aMpzB36es-p5YjMLWuy8-yDCcts3-oOU,14660
3
+ p3lib/bokeh_auth.py,sha256=XqdCLOalHL3dkyrMPqQoVQBSziVnqlfjB9YAWhZUd_U,14769
4
4
  p3lib/bokeh_gui.py,sha256=MNapLctSncZ9YyKGzNcUICMwpI5_h7a7bH3QdMd2UxI,40393
5
5
  p3lib/boot_manager.py,sha256=-kbfYbFpO-ktKv_heUgYdvvIQrntfCQ7pBcPWqS3C0s,12551
6
6
  p3lib/conduit.py,sha256=jPkjdtyCx2I6SFqcEo8y2g7rgnZ-jNY7oCuYIETzT5Q,6046
@@ -11,10 +11,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/pconfig.py,sha256=_ri9w3aauHXZp8u2YLYHBVroFR_iCqaTCwj_MRa3rHo,30153
14
- p3lib/ssh.py,sha256=YE1ddgiEt9EeBM8evuxCV8Gnj4jz1Sv52vEKidvjrJA,38369
14
+ p3lib/ssh.py,sha256=-w_2oQWZaIABanF1lk8fRyMLkJK231Bvy11StgdYqJg,38951
15
15
  p3lib/uio.py,sha256=hMarPnYXnqVF23HUIeDfzREo7TMdBjrupXMY_ffuCbI,23133
16
- p3lib-1.1.66.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
17
- p3lib-1.1.66.dist-info/METADATA,sha256=OrQlH17mOVpX1q-9EBGq0__yRQfbFG8h__wDe4rBup4,920
18
- p3lib-1.1.66.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
- p3lib-1.1.66.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
20
- p3lib-1.1.66.dist-info/RECORD,,
16
+ p3lib-1.1.68.dist-info/LICENSE,sha256=igqTy5u0kVWM1n-NUZMvAlinY6lVjAXKoag0okkS8V8,1067
17
+ p3lib-1.1.68.dist-info/METADATA,sha256=zIeiIZdLh23VBFQxyIgt8L08nmOhaHJP0Bl2_rtW-AQ,920
18
+ p3lib-1.1.68.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
+ p3lib-1.1.68.dist-info/top_level.txt,sha256=SDCpXYh-19yCFp4Z8ZK4B-3J4NvTCJElZ42NPgcR6-U,6
20
+ p3lib-1.1.68.dist-info/RECORD,,
File without changes