JamoDevNich / SuperHub3-CLI

A command-line interface for managing the VM SuperHub 3/ARRIS TG2492S/CE router. Allows listing current/past connected devices, toggle private/guest WLAN, rebooting and viewing router status

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when Admin user already logged in.

richard-scott opened this issue · comments

I have been using your script for a while, and when I am logged in via the Web UI in a browser on my desktop, I get this error on the command line:

Searching for 192.168.0.1...
Logging in...
Checking firmware compatibility...
--! HTTP/1.1 Response Code 401 Received
Traceback (most recent call last):
  File "/root/bin/tools/superhubclientsapi.py", line 850, in <module>
    Main.app();
  File "/root/bin/tools/superhubclientsapi.py", line 834, in app
    raise Exception(Hub.ErrorMessages.firmware_warn);
Exception: Couldn't check firmware version, something must have went wrong with the login.

This happens as only one Admin can be logged in at a time.

commented

Could you try version 2.0.a1 on the dev-2.0.0 branch and see if that works, or if that throws a similar error message?

The verbose level is temporarily set high though, to make things more readable comment out line 33

VERBOSE_MODE = 4; # TODO: FOR DEBUG

There will be a detection mechanism for existing logins in the next commit to the dev branch - although not too sure how this scenario will be handled in the CLI yet...

When I log in via the Browser, and then use the CLI I get this:
I get this:

<<< WARNING >>> Instance of 'Output' not found. To avoid unintentional behavior, remove the '@Utilities.debug' decorator from 'CommandLineInterface.main'.
<<< Entering method >>> type.main(Namespace(clients=False, diagnostic=False, format=None, oids=None, password='REDACTED', reboot=False, silent=False, verbose=False, wlan=None))
<<< Entering method >>> Session.__init__(auto_recover_session=False,output_handler=<class Output {'self._verbose_level': 4}>)
<<< Entering method >>> Session._set_credential('admin',username=True)
<<< Entering method >>> Session._set_credential('00000000')
SuperHub 3 Client API by JamoDevNich <github@nich.dev>
Version 2.0.a1
Searching for 192.168.0.1...
<<< Entering method >>> Session.router_reachable()
<<< Entering method >>> Session.get_oids_walk(['1.3.6.1.4.1.4115.1.3.4.1.9.2'])
<<< Entering method >>> Session._http_request('walk',{'oids': '1.3.6.1.4.1.4115.1.3.4.1.9.2'})
Sending request to: http://192.168.0.1/walk?oids=1.3.6.1.4.1.4115.1.3.4.1.9.2&_n=60982
<<< WARNING >>> Instance of 'Output' not found. To avoid unintentional behavior, remove the '@Utilities.debug' decorator from 'HTTPResponse.__init__'.
<<< Entering method >>> HTTPResponse.__init__(200,{'Cache-Control': 'no-cache, must-revalidate',
 'Connection': 'close',
 'Date': 'Mon, 06 Jul 2020 11:37:27 GMT',
 'Server': 'lighttpd',
 'X-Frame-Options': 'SAMEORIGIN'},('{\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.1.4":"2",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.1.82":"4",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.1.83":"1",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.1.84":"3",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.2.4":"5120",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.2.82":"5120",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.2.83":"5120",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.2.84":"5120",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.3.4":"5",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.3.82":"5",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.3.83":"5",\n'
 '"1.3.6.1.4.1.4115.1.3.4.1.9.2.1.3.84":"5",\n'
 '"1":"Finish"\n'
 '}\n'))
--i Password set in CLI
<<< Entering method >>> Session._set_credential('REDACTED')
Signing in...
<<< Entering method >>> Session.sign_in()
<<< Entering method >>> Session._sign_in('admin','REDACTED')
<<< Entering method >>> Session._http_request('login',{'arg': 'YWRtaW46MzIyOTU3MDI='})
Sending request to: http://192.168.0.1/login?arg=YWRtaW46MzIyOTU3MDI=&_n=60982
<<< WARNING >>> Instance of 'Output' not found. To avoid unintentional behavior, remove the '@Utilities.debug' decorator from 'HTTPResponse.__init__'.
<<< Entering method >>> HTTPResponse.__init__(200,{'Cache-Control': 'no-cache, must-revalidate',
 'Connection': 'close',
 'Content-Length': '256',
 'Date': 'Mon, 06 Jul 2020 11:37:29 GMT',
 'Server': 'lighttpd',
 'X-Frame-Options': 'SAMEORIGIN'},'eyAidW5pcXVlIjoiTG5tNXFMSFgzalR6SEwiLCAiZmFtaWx5IjoiODUyIiwgIm1vZGVsbmFtZSI6IlRHMjQ5MkxHLTg1IiwgIm5hbWUiOiJhZG1pbiIsICJ0ZWNoIjpmYWxzZSwgIm1vY2EiOjAsICJ3aWZpIjo1LCAiY29uVHlwZSI6IkxBTiIsICJtdXRpIjoiTEFOIiwgImd3V2FuIjoiZiIsICJEZWZQYXNzd2RDaGFuZ2VkIjoiTk8iIH0=')
Checking firmware compatibility...
<<< Entering method >>> Session.get_firmware_info()
<<< Entering method >>> Session.get_oid('1.3.6.1.4.1.4115.1.20.1.1.5.11.0')
<<< Entering method >>> Session.get_oids(['1.3.6.1.4.1.4115.1.20.1.1.5.11.0'])
<<< Entering method >>> Session._http_request('snmpGet',{'oids': '1.3.6.1.4.1.4115.1.20.1.1.5.11.0'})
Sending request to: http://192.168.0.1/snmpGet?oids=1.3.6.1.4.1.4115.1.20.1.1.5.11.0&_n=60982
Error sending request - <HTTPError 401: 'Unauthorized'>
<<< WARNING >>> Instance of 'Output' not found. To avoid unintentional behavior, remove the '@Utilities.debug' decorator from 'HTTPResponse.__init__'.
<<< Entering method >>> HTTPResponse.__init__(401,{},None)
Traceback (most recent call last):
  File "./superhubclientsapi.py", line 1406, in <module>
    CommandLineInterface.main(args);
  File "./superhubclientsapi.py", line 234, in inner
    return func(*args, **kwargs);
  File "./superhubclientsapi.py", line 1284, in main
    firmware_info = cls._session.get_firmware_info();
  File "./superhubclientsapi.py", line 234, in inner
    return func(*args, **kwargs);
  File "./superhubclientsapi.py", line 661, in get_firmware_info
    firmware_version = self.get_oid(self.Oids.firmware_version);
  File "./superhubclientsapi.py", line 234, in inner
    return func(*args, **kwargs);
  File "./superhubclientsapi.py", line 592, in get_oid
    return self.get_oids([oid])[oid];
  File "./superhubclientsapi.py", line 234, in inner
    return func(*args, **kwargs);
  File "./superhubclientsapi.py", line 611, in get_oids
    raise NotImplementedError("HTTP response was %s, no handling implemented yet for this response type" % response.status_code);
NotImplementedError: HTTP response was 401, no handling implemented yet for this response type
<<< Entering method >>> Session.sign_out(invoked=1)
<<< Entering method >>> Session._http_request('logout')
Sending request to: http://192.168.0.1/logout?_n=60982
Error sending request - <HTTPError 401: 'Unauthorized'>
<<< WARNING >>> Instance of 'Output' not found. To avoid unintentional behavior, remove the '@Utilities.debug' decorator from 'HTTPResponse.__init__'.
<<< Entering method >>> HTTPResponse.__init__(401,{},None)

commented

Looks like the newer firmware is blocking more than one login being active.

A potential fix for this could be to warn that an existing user is already logged in, might also add in a CLI arg to wait until the existing user logs out. Unless you had any other ideas in mind?

The wait arg is a good idea. Maybe some extra args like this would be good too.

Both of these would wait 60 seconds for a valid login.
The 2nd one would be controlled by the '--timeout' default of 60 seconds.

--retry --timeout 60
--retry

In this next one, we want to be able to try 10 login attempts, and wait 20 seconds between each attempt.
There would be no need for a timeout as after 9x20s the app will exit anyway. You may also want to set a default
For wait if one is not provided by the user.

--retry 10 --wait 20
commented

I think hardcoding the timeout to 60 seconds might be better than having it as an extra arg, since the arg probably might not be used that often.

When I'm free next week I'll add the --retry and --wait args into the dev branch. Considering renaming the --retry arg to --limit though, since -r is already assigned for reboot?

A quick draft of what these would do...

CLI argument Description
--limit [n] Retry a failed request up to [n] times, Default 3
--wait [n] Waits for an existing user to log out, delaying the login attempts by [n] seconds, Default 10. Note: This runs indefinitely unless --limit is set