colinodell / python-qnapstats

Python API for obtaining QNAP NAS system stats
Other
73 stars 30 forks source link

TS-251+ KeyError: 'authPassed' #25

Closed jsinkers closed 4 years ago

jsinkers commented 5 years ago

The authPassed key does not exist in the xml returned

Device Model Number: <TS-251+>

QTS Version: <4.3.6>

XML/Debug Output:

>>> pprint(qnap.get_volumes())
DEBUG: Creating new session
DEBUG: POST to URL: http://192.168.20.3:8080/cgi-bin/authLogin.cgi
C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
DEBUG: Request executed: 200
DEBUG: Response Text: <?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><model><modelName><![CDATA[TS-X51]]></modelName><internalModelName><![CDATA[TS-X51]]></internalModelName><platform><![CDATA[TS-NASX86]]></platform><platform_ex><![CDATA[X86_BAYTRAIL]]></platform_ex><customModelName><![CDATA[]]></customModelName><displayModelName><![CDATA[TS-251+]]></displayModelName><sas_model><![CDATA[0]]></sas_model><storage_v2>1</storage_v2>
<encryptfsSupported><![CDATA[1]]></encryptfsSupported></model>
<firmware><version><![CDATA[4.3.6]]></version><number><![CDATA[0959]]></number><build><![CDATA[20190531]]></build><patch><![CDATA[0]]></patch><buildTime><![CDATA[2019/05/31]]></buildTime></firmware>
<rfs_bits><![CDATA[64]]></rfs_bits><specVersion><![CDATA[1.0]]></specVersion><hostname><![CDATA[nasty]]></hostname><DemoSiteSuppurt><![CDATA[no]]></DemoSiteSuppurt><customLogo><customFrontLogo><![CDATA[]]></customFrontLogo><customLoginLogo><![CDATA[]]></customLoginLogo></customLogo>
<HTTPHost><![CDATA[192.168.20.3]]></HTTPHost><webAccessPort><![CDATA[8080]]></webAccessPort><QWebPort><![CDATA[80]]></QWebPort><webFSEnabled><![CDATA[1]]></webFSEnabled><QMultimediaEnabled><![CDATA[0]]></QMultimediaEnabled><MSV2Supported><![CDATA[0]]></MSV2Supported><MSV2WebEnabled><![CDATA[1]]></MSV2WebEnabled><MSV2URL><![CDATA[/MSV2/]]></MSV2URL><QDownloadEnabled><![CDATA[1]]></QDownloadEnabled><DSV2Supported><![CDATA[0]]></DSV2Supported><DSV3Supported><![CDATA[1]]></DSV3Supported><DSV2URL><![CDATA[/downloadstation/?ssid=]]></DSV2URL><QWebEnabled><![CDATA[1]]></QWebEnabled><QWebSSLEnabled><![CDATA[1]]></QWebSSLEnabled><QWebSSLPort><![CDATA[8081]]></QWebSSLPort><NVREnabled><![CDATA[0]]></NVREnabled><NVRURL><![CDATA[/surveillance/]]></NVRURL><NVRVER><![CDATA[1]]></NVRVER><WFM2><![CDATA[1]]></WFM2><wfmPortEnabled><![CDATA[0]]></wfmPortEnabled><wfmPort><![CDATA[8080]]></wfmPort><wfmSSLEnabled><![CDATA[0]]></wfmSSLEnabled><wfmSSLPort><![CDATA[443]]></wfmSSLPort><wfmURL><![CDATA[/filestation/]]></wfmURL><QMusicsEnabled><![CDATA[0]]></QMusicsEnabled><QMusicsURL><![CDATA[/musicstation/]]></QMusicsURL><QVideosEnabled><![CDATA[0]]></QVideosEnabled><QVideosURL><![CDATA[/videostation/]]></QVideosURL><QPhotosEnabled><![CDATA[0]]></QPhotosEnabled><QPhotosURL><![CDATA[/photo/]]></QPhotosURL><stunnelEnabled><![CDATA[1]]></stunnelEnabled><stunnelPort><![CDATA[443]]></stunnelPort><forceSSL><![CDATA[1]]></forceSSL><HDAROOT_ALMOST_FULL><![CDATA[0]]></HDAROOT_ALMOST_FULL><passwdConstraints><passwdConstraint01><![CDATA[0]]></passwdConstraint01><passwdConstraint02><![CDATA[0]]></passwdConstraint02><passwdConstraint03><![CDATA[0]]></passwdConstraint03><passwdConstraint04><![CDATA[0]]></passwdConstraint04></passwdConstraints>
<ts><![CDATA[96177256]]></ts><fwNotice><![CDATA[0]]></fwNotice><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[4dec1e319e179d9ab67638e81a12669d]]></cuid></QDocRoot>

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\qnapstats\qnap_stats.py", line 135, in get_volumes
    force_list=("volume", "volumeUse", "folder_element")
  File "C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\qnapstats\qnap_stats.py", line 67, in _get_url
    self._init_session()
  File "C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\qnapstats\qnap_stats.py", line 49, in _init_session
    if self._login() is False:
  File "C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\qnapstats\qnap_stats.py", line 57, in _login
    result = self._execute_post_url("authLogin.cgi", data, False)
  File "C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\qnapstats\qnap_stats.py", line 98, in _execute_post_url
    return self._handle_response(resp, **kwargs)
  File "C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\qnapstats\qnap_stats.py", line 112, in _handle_response
    auth_passed = data['authPassed']
KeyError: 'authPassed'
colinodell commented 5 years ago

Interesting... I'm not seeing an authSid either. Perhaps instead of returning the session ID via XML it's using a session cookie?

I can't replicate this on QTS 4.3.5 (TS-451+) but let me upgrade and see if I can replicate it then.

colinodell commented 5 years ago

Still can't replicate this on 4.3.6, so this might be a device-specific issue.

I've added some new code to debug.py to output the response headers and any cookies. Would you mind pulling down the latest version of this repo and re-running that script? That should (hopefully) give me the info I'd need to make this compatible with your device.

jsinkers commented 5 years ago

I've pulled the latest version and ran debug.py:

PS C:\Users\James\Documents\python-qnapstats> python .\debug.py
Host (prefix with 'https://' if needed): 192.168.20.3
Port: 8080
Username: admin
Password:
DEBUG: Creating new session
DEBUG: POST to URL: http://192.168.20.3:8080/cgi-bin/authLogin.cgi
C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
DEBUG: Request executed: 200
DEBUG: Headers: {"Date": "Mon, 17 Jun 2019 06:59:48 GMT", "Server": "Apache", "X-Frame-Options": "SAMEORIGIN", "Content-type": "text/xml", "Keep-Alive": "timeout=15, max=100", "Connection": "Keep-Alive", "Transfer-Encoding": "chunked"}
DEBUG: Cookies: {}
DEBUG: Response Text: <?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><model><modelName><![CDATA[TS-X51]]></modelName><internalModelName><![CDATA[TS-X51]]></internalModelName><platform><![CDATA[TS-NASX86]]></platform><platform_ex><![CDATA[X86_BAYTRAIL]]></platform_ex><customModelName><![CDATA[]]></customModelName><displayModelName><![CDATA[TS-251+]]></displayModelName><sas_model><![CDATA[0]]></sas_model><storage_v2>1</storage_v2>
<encryptfsSupported><![CDATA[1]]></encryptfsSupported></model>
<firmware><version><![CDATA[4.3.6]]></version><number><![CDATA[0959]]></number><build><![CDATA[20190531]]></build><patch><![CDATA[0]]></patch><buildTime><![CDATA[2019/05/31]]></buildTime></firmware>
<rfs_bits><![CDATA[64]]></rfs_bits><specVersion><![CDATA[1.0]]></specVersion><hostname><![CDATA[nasty]]></hostname><DemoSiteSuppurt><![CDATA[no]]></DemoSiteSuppurt><customLogo><customFrontLogo><![CDATA[]]></customFrontLogo><customLoginLogo><![CDATA[]]></customLoginLogo></customLogo>
<HTTPHost><![CDATA[192.168.20.3]]></HTTPHost><webAccessPort><![CDATA[8080]]></webAccessPort><QWebPort><![CDATA[80]]></QWebPort><webFSEnabled><![CDATA[1]]></webFSEnabled><QMultimediaEnabled><![CDATA[0]]></QMultimediaEnabled><MSV2Supported><![CDATA[0]]></MSV2Supported><MSV2WebEnabled><![CDATA[1]]></MSV2WebEnabled><MSV2URL><![CDATA[/MSV2/]]></MSV2URL><QDownloadEnabled><![CDATA[1]]></QDownloadEnabled><DSV2Supported><![CDATA[0]]></DSV2Supported><DSV3Supported><![CDATA[1]]></DSV3Supported><DSV2URL><![CDATA[/downloadstation/?ssid=]]></DSV2URL><QWebEnabled><![CDATA[1]]></QWebEnabled><QWebSSLEnabled><![CDATA[1]]></QWebSSLEnabled><QWebSSLPort><![CDATA[8081]]></QWebSSLPort><NVREnabled><![CDATA[0]]></NVREnabled><NVRURL><![CDATA[/surveillance/]]></NVRURL><NVRVER><![CDATA[1]]></NVRVER><WFM2><![CDATA[1]]></WFM2><wfmPortEnabled><![CDATA[0]]></wfmPortEnabled><wfmPort><![CDATA[8080]]></wfmPort><wfmSSLEnabled><![CDATA[0]]></wfmSSLEnabled><wfmSSLPort><![CDATA[443]]></wfmSSLPort><wfmURL><![CDATA[/filestation/]]></wfmURL><QMusicsEnabled><![CDATA[0]]></QMusicsEnabled><QMusicsURL><![CDATA[/musicstation/]]></QMusicsURL><QVideosEnabled><![CDATA[0]]></QVideosEnabled><QVideosURL><![CDATA[/videostation/]]></QVideosURL><QPhotosEnabled><![CDATA[0]]></QPhotosEnabled><QPhotosURL><![CDATA[/photo/]]></QPhotosURL><stunnelEnabled><![CDATA[1]]></stunnelEnabled><stunnelPort><![CDATA[443]]></stunnelPort><forceSSL><![CDATA[1]]></forceSSL><HDAROOT_ALMOST_FULL><![CDATA[0]]></HDAROOT_ALMOST_FULL><passwdConstraints><passwdConstraint01><![CDATA[0]]></passwdConstraint01><passwdConstraint02><![CDATA[0]]></passwdConstraint02><passwdConstraint03><![CDATA[0]]></passwdConstraint03><passwdConstraint04><![CDATA[0]]></passwdConstraint04></passwdConstraints>
<ts><![CDATA[96177256]]></ts><fwNotice><![CDATA[0]]></fwNotice><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[4dec1e319e179d9ab67638e81a12669d]]></cuid></QDocRoot>

('authPassed',)
Traceback (most recent call last):
  File ".\debug.py", line 14, in <module>
    qnap.get_system_stats()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 210, in get_system_stats
    force_list=("DNS_LIST")
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 68, in _get_url
    self._init_session()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 50, in _init_session
    if self._login() is False:
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 58, in _login
    result = self._execute_post_url("authLogin.cgi", data, False)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 99, in _execute_post_url
    return self._handle_response(resp, **kwargs)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 115, in _handle_response
    auth_passed = data['authPassed']
KeyError: 'authPassed'
DEBUG: Creating new session
DEBUG: POST to URL: http://192.168.20.3:8080/cgi-bin/authLogin.cgi
C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
DEBUG: Request executed: 200
DEBUG: Headers: {"Date": "Mon, 17 Jun 2019 06:59:48 GMT", "Server": "Apache", "X-Frame-Options": "SAMEORIGIN", "Content-type": "text/xml", "Keep-Alive": "timeout=15, max=100", "Connection": "Keep-Alive", "Transfer-Encoding": "chunked"}
DEBUG: Cookies: {}
DEBUG: Response Text: <?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><model><modelName><![CDATA[TS-X51]]></modelName><internalModelName><![CDATA[TS-X51]]></internalModelName><platform><![CDATA[TS-NASX86]]></platform><platform_ex><![CDATA[X86_BAYTRAIL]]></platform_ex><customModelName><![CDATA[]]></customModelName><displayModelName><![CDATA[TS-251+]]></displayModelName><sas_model><![CDATA[0]]></sas_model><storage_v2>1</storage_v2>
<encryptfsSupported><![CDATA[1]]></encryptfsSupported></model>
<firmware><version><![CDATA[4.3.6]]></version><number><![CDATA[0959]]></number><build><![CDATA[20190531]]></build><patch><![CDATA[0]]></patch><buildTime><![CDATA[2019/05/31]]></buildTime></firmware>
<rfs_bits><![CDATA[64]]></rfs_bits><specVersion><![CDATA[1.0]]></specVersion><hostname><![CDATA[nasty]]></hostname><DemoSiteSuppurt><![CDATA[no]]></DemoSiteSuppurt><customLogo><customFrontLogo><![CDATA[]]></customFrontLogo><customLoginLogo><![CDATA[]]></customLoginLogo></customLogo>
<HTTPHost><![CDATA[192.168.20.3]]></HTTPHost><webAccessPort><![CDATA[8080]]></webAccessPort><QWebPort><![CDATA[80]]></QWebPort><webFSEnabled><![CDATA[1]]></webFSEnabled><QMultimediaEnabled><![CDATA[0]]></QMultimediaEnabled><MSV2Supported><![CDATA[0]]></MSV2Supported><MSV2WebEnabled><![CDATA[1]]></MSV2WebEnabled><MSV2URL><![CDATA[/MSV2/]]></MSV2URL><QDownloadEnabled><![CDATA[1]]></QDownloadEnabled><DSV2Supported><![CDATA[0]]></DSV2Supported><DSV3Supported><![CDATA[1]]></DSV3Supported><DSV2URL><![CDATA[/downloadstation/?ssid=]]></DSV2URL><QWebEnabled><![CDATA[1]]></QWebEnabled><QWebSSLEnabled><![CDATA[1]]></QWebSSLEnabled><QWebSSLPort><![CDATA[8081]]></QWebSSLPort><NVREnabled><![CDATA[0]]></NVREnabled><NVRURL><![CDATA[/surveillance/]]></NVRURL><NVRVER><![CDATA[1]]></NVRVER><WFM2><![CDATA[1]]></WFM2><wfmPortEnabled><![CDATA[0]]></wfmPortEnabled><wfmPort><![CDATA[8080]]></wfmPort><wfmSSLEnabled><![CDATA[0]]></wfmSSLEnabled><wfmSSLPort><![CDATA[443]]></wfmSSLPort><wfmURL><![CDATA[/filestation/]]></wfmURL><QMusicsEnabled><![CDATA[0]]></QMusicsEnabled><QMusicsURL><![CDATA[/musicstation/]]></QMusicsURL><QVideosEnabled><![CDATA[0]]></QVideosEnabled><QVideosURL><![CDATA[/videostation/]]></QVideosURL><QPhotosEnabled><![CDATA[0]]></QPhotosEnabled><QPhotosURL><![CDATA[/photo/]]></QPhotosURL><stunnelEnabled><![CDATA[1]]></stunnelEnabled><stunnelPort><![CDATA[443]]></stunnelPort><forceSSL><![CDATA[1]]></forceSSL><HDAROOT_ALMOST_FULL><![CDATA[0]]></HDAROOT_ALMOST_FULL><passwdConstraints><passwdConstraint01><![CDATA[0]]></passwdConstraint01><passwdConstraint02><![CDATA[0]]></passwdConstraint02><passwdConstraint03><![CDATA[0]]></passwdConstraint03><passwdConstraint04><![CDATA[0]]></passwdConstraint04></passwdConstraints>
<ts><![CDATA[96177256]]></ts><fwNotice><![CDATA[0]]></fwNotice><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[4dec1e319e179d9ab67638e81a12669d]]></cuid></QDocRoot>

('authPassed',)
Traceback (most recent call last):
  File ".\debug.py", line 20, in <module>
    qnap.get_system_health()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 124, in get_system_health
    resp = self._get_url("management/manaRequest.cgi?subfunc=sysinfo&sysHealth=1")
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 68, in _get_url
    self._init_session()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 50, in _init_session
    if self._login() is False:
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 58, in _login
    result = self._execute_post_url("authLogin.cgi", data, False)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 99, in _execute_post_url
    return self._handle_response(resp, **kwargs)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 115, in _handle_response
    auth_passed = data['authPassed']
KeyError: 'authPassed'
DEBUG: Creating new session
DEBUG: POST to URL: http://192.168.20.3:8080/cgi-bin/authLogin.cgi
C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
DEBUG: Request executed: 200
DEBUG: Headers: {"Date": "Mon, 17 Jun 2019 06:59:48 GMT", "Server": "Apache", "X-Frame-Options": "SAMEORIGIN", "Content-type": "text/xml", "Keep-Alive": "timeout=15, max=100", "Connection": "Keep-Alive", "Transfer-Encoding": "chunked"}
DEBUG: Cookies: {}
DEBUG: Response Text: <?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><model><modelName><![CDATA[TS-X51]]></modelName><internalModelName><![CDATA[TS-X51]]></internalModelName><platform><![CDATA[TS-NASX86]]></platform><platform_ex><![CDATA[X86_BAYTRAIL]]></platform_ex><customModelName><![CDATA[]]></customModelName><displayModelName><![CDATA[TS-251+]]></displayModelName><sas_model><![CDATA[0]]></sas_model><storage_v2>1</storage_v2>
<encryptfsSupported><![CDATA[1]]></encryptfsSupported></model>
<firmware><version><![CDATA[4.3.6]]></version><number><![CDATA[0959]]></number><build><![CDATA[20190531]]></build><patch><![CDATA[0]]></patch><buildTime><![CDATA[2019/05/31]]></buildTime></firmware>
<rfs_bits><![CDATA[64]]></rfs_bits><specVersion><![CDATA[1.0]]></specVersion><hostname><![CDATA[nasty]]></hostname><DemoSiteSuppurt><![CDATA[no]]></DemoSiteSuppurt><customLogo><customFrontLogo><![CDATA[]]></customFrontLogo><customLoginLogo><![CDATA[]]></customLoginLogo></customLogo>
<HTTPHost><![CDATA[192.168.20.3]]></HTTPHost><webAccessPort><![CDATA[8080]]></webAccessPort><QWebPort><![CDATA[80]]></QWebPort><webFSEnabled><![CDATA[1]]></webFSEnabled><QMultimediaEnabled><![CDATA[0]]></QMultimediaEnabled><MSV2Supported><![CDATA[0]]></MSV2Supported><MSV2WebEnabled><![CDATA[1]]></MSV2WebEnabled><MSV2URL><![CDATA[/MSV2/]]></MSV2URL><QDownloadEnabled><![CDATA[1]]></QDownloadEnabled><DSV2Supported><![CDATA[0]]></DSV2Supported><DSV3Supported><![CDATA[1]]></DSV3Supported><DSV2URL><![CDATA[/downloadstation/?ssid=]]></DSV2URL><QWebEnabled><![CDATA[1]]></QWebEnabled><QWebSSLEnabled><![CDATA[1]]></QWebSSLEnabled><QWebSSLPort><![CDATA[8081]]></QWebSSLPort><NVREnabled><![CDATA[0]]></NVREnabled><NVRURL><![CDATA[/surveillance/]]></NVRURL><NVRVER><![CDATA[1]]></NVRVER><WFM2><![CDATA[1]]></WFM2><wfmPortEnabled><![CDATA[0]]></wfmPortEnabled><wfmPort><![CDATA[8080]]></wfmPort><wfmSSLEnabled><![CDATA[0]]></wfmSSLEnabled><wfmSSLPort><![CDATA[443]]></wfmSSLPort><wfmURL><![CDATA[/filestation/]]></wfmURL><QMusicsEnabled><![CDATA[0]]></QMusicsEnabled><QMusicsURL><![CDATA[/musicstation/]]></QMusicsURL><QVideosEnabled><![CDATA[0]]></QVideosEnabled><QVideosURL><![CDATA[/videostation/]]></QVideosURL><QPhotosEnabled><![CDATA[0]]></QPhotosEnabled><QPhotosURL><![CDATA[/photo/]]></QPhotosURL><stunnelEnabled><![CDATA[1]]></stunnelEnabled><stunnelPort><![CDATA[443]]></stunnelPort><forceSSL><![CDATA[1]]></forceSSL><HDAROOT_ALMOST_FULL><![CDATA[0]]></HDAROOT_ALMOST_FULL><passwdConstraints><passwdConstraint01><![CDATA[0]]></passwdConstraint01><passwdConstraint02><![CDATA[0]]></passwdConstraint02><passwdConstraint03><![CDATA[0]]></passwdConstraint03><passwdConstraint04><![CDATA[0]]></passwdConstraint04></passwdConstraints>
<ts><![CDATA[96177256]]></ts><fwNotice><![CDATA[0]]></fwNotice><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[4dec1e319e179d9ab67638e81a12669d]]></cuid></QDocRoot>

('authPassed',)
Traceback (most recent call last):
  File ".\debug.py", line 26, in <module>
    qnap.get_smart_disk_health()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 185, in get_smart_disk_health
    resp = self._get_url("disk/qsmart.cgi?func=all_hd_data", force_list=("entry"))
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 68, in _get_url
    self._init_session()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 50, in _init_session
    if self._login() is False:
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 58, in _login
    result = self._execute_post_url("authLogin.cgi", data, False)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 99, in _execute_post_url
    return self._handle_response(resp, **kwargs)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 115, in _handle_response
    auth_passed = data['authPassed']
KeyError: 'authPassed'
DEBUG: Creating new session
DEBUG: POST to URL: http://192.168.20.3:8080/cgi-bin/authLogin.cgi
C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
DEBUG: Request executed: 200
DEBUG: Headers: {"Date": "Mon, 17 Jun 2019 06:59:49 GMT", "Server": "Apache", "X-Frame-Options": "SAMEORIGIN", "Content-type": "text/xml", "Keep-Alive": "timeout=15, max=100", "Connection": "Keep-Alive", "Transfer-Encoding": "chunked"}
DEBUG: Cookies: {}
DEBUG: Response Text: <?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><model><modelName><![CDATA[TS-X51]]></modelName><internalModelName><![CDATA[TS-X51]]></internalModelName><platform><![CDATA[TS-NASX86]]></platform><platform_ex><![CDATA[X86_BAYTRAIL]]></platform_ex><customModelName><![CDATA[]]></customModelName><displayModelName><![CDATA[TS-251+]]></displayModelName><sas_model><![CDATA[0]]></sas_model><storage_v2>1</storage_v2>
<encryptfsSupported><![CDATA[1]]></encryptfsSupported></model>
<firmware><version><![CDATA[4.3.6]]></version><number><![CDATA[0959]]></number><build><![CDATA[20190531]]></build><patch><![CDATA[0]]></patch><buildTime><![CDATA[2019/05/31]]></buildTime></firmware>
<rfs_bits><![CDATA[64]]></rfs_bits><specVersion><![CDATA[1.0]]></specVersion><hostname><![CDATA[nasty]]></hostname><DemoSiteSuppurt><![CDATA[no]]></DemoSiteSuppurt><customLogo><customFrontLogo><![CDATA[]]></customFrontLogo><customLoginLogo><![CDATA[]]></customLoginLogo></customLogo>
<HTTPHost><![CDATA[192.168.20.3]]></HTTPHost><webAccessPort><![CDATA[8080]]></webAccessPort><QWebPort><![CDATA[80]]></QWebPort><webFSEnabled><![CDATA[1]]></webFSEnabled><QMultimediaEnabled><![CDATA[0]]></QMultimediaEnabled><MSV2Supported><![CDATA[0]]></MSV2Supported><MSV2WebEnabled><![CDATA[1]]></MSV2WebEnabled><MSV2URL><![CDATA[/MSV2/]]></MSV2URL><QDownloadEnabled><![CDATA[1]]></QDownloadEnabled><DSV2Supported><![CDATA[0]]></DSV2Supported><DSV3Supported><![CDATA[1]]></DSV3Supported><DSV2URL><![CDATA[/downloadstation/?ssid=]]></DSV2URL><QWebEnabled><![CDATA[1]]></QWebEnabled><QWebSSLEnabled><![CDATA[1]]></QWebSSLEnabled><QWebSSLPort><![CDATA[8081]]></QWebSSLPort><NVREnabled><![CDATA[0]]></NVREnabled><NVRURL><![CDATA[/surveillance/]]></NVRURL><NVRVER><![CDATA[1]]></NVRVER><WFM2><![CDATA[1]]></WFM2><wfmPortEnabled><![CDATA[0]]></wfmPortEnabled><wfmPort><![CDATA[8080]]></wfmPort><wfmSSLEnabled><![CDATA[0]]></wfmSSLEnabled><wfmSSLPort><![CDATA[443]]></wfmSSLPort><wfmURL><![CDATA[/filestation/]]></wfmURL><QMusicsEnabled><![CDATA[0]]></QMusicsEnabled><QMusicsURL><![CDATA[/musicstation/]]></QMusicsURL><QVideosEnabled><![CDATA[0]]></QVideosEnabled><QVideosURL><![CDATA[/videostation/]]></QVideosURL><QPhotosEnabled><![CDATA[0]]></QPhotosEnabled><QPhotosURL><![CDATA[/photo/]]></QPhotosURL><stunnelEnabled><![CDATA[1]]></stunnelEnabled><stunnelPort><![CDATA[443]]></stunnelPort><forceSSL><![CDATA[1]]></forceSSL><HDAROOT_ALMOST_FULL><![CDATA[0]]></HDAROOT_ALMOST_FULL><passwdConstraints><passwdConstraint01><![CDATA[0]]></passwdConstraint01><passwdConstraint02><![CDATA[0]]></passwdConstraint02><passwdConstraint03><![CDATA[0]]></passwdConstraint03><passwdConstraint04><![CDATA[0]]></passwdConstraint04></passwdConstraints>
<ts><![CDATA[96177256]]></ts><fwNotice><![CDATA[0]]></fwNotice><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[4dec1e319e179d9ab67638e81a12669d]]></cuid></QDocRoot>

('authPassed',)
Traceback (most recent call last):
  File ".\debug.py", line 32, in <module>
    qnap.get_volumes()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 138, in get_volumes
    force_list=("volume", "volumeUse", "folder_element")
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 68, in _get_url
    self._init_session()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 50, in _init_session
    if self._login() is False:
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 58, in _login
    result = self._execute_post_url("authLogin.cgi", data, False)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 99, in _execute_post_url
    return self._handle_response(resp, **kwargs)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 115, in _handle_response
    auth_passed = data['authPassed']
KeyError: 'authPassed'
DEBUG: Creating new session
DEBUG: POST to URL: http://192.168.20.3:8080/cgi-bin/authLogin.cgi
C:\Users\James\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
DEBUG: Request executed: 200
DEBUG: Headers: {"Date": "Mon, 17 Jun 2019 06:59:49 GMT", "Server": "Apache", "X-Frame-Options": "SAMEORIGIN", "Content-type": "text/xml", "Keep-Alive": "timeout=15, max=100", "Connection": "Keep-Alive", "Transfer-Encoding": "chunked"}
DEBUG: Cookies: {}
DEBUG: Response Text: <?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><model><modelName><![CDATA[TS-X51]]></modelName><internalModelName><![CDATA[TS-X51]]></internalModelName><platform><![CDATA[TS-NASX86]]></platform><platform_ex><![CDATA[X86_BAYTRAIL]]></platform_ex><customModelName><![CDATA[]]></customModelName><displayModelName><![CDATA[TS-251+]]></displayModelName><sas_model><![CDATA[0]]></sas_model><storage_v2>1</storage_v2>
<encryptfsSupported><![CDATA[1]]></encryptfsSupported></model>
<firmware><version><![CDATA[4.3.6]]></version><number><![CDATA[0959]]></number><build><![CDATA[20190531]]></build><patch><![CDATA[0]]></patch><buildTime><![CDATA[2019/05/31]]></buildTime></firmware>
<rfs_bits><![CDATA[64]]></rfs_bits><specVersion><![CDATA[1.0]]></specVersion><hostname><![CDATA[nasty]]></hostname><DemoSiteSuppurt><![CDATA[no]]></DemoSiteSuppurt><customLogo><customFrontLogo><![CDATA[]]></customFrontLogo><customLoginLogo><![CDATA[]]></customLoginLogo></customLogo>
<HTTPHost><![CDATA[192.168.20.3]]></HTTPHost><webAccessPort><![CDATA[8080]]></webAccessPort><QWebPort><![CDATA[80]]></QWebPort><webFSEnabled><![CDATA[1]]></webFSEnabled><QMultimediaEnabled><![CDATA[0]]></QMultimediaEnabled><MSV2Supported><![CDATA[0]]></MSV2Supported><MSV2WebEnabled><![CDATA[1]]></MSV2WebEnabled><MSV2URL><![CDATA[/MSV2/]]></MSV2URL><QDownloadEnabled><![CDATA[1]]></QDownloadEnabled><DSV2Supported><![CDATA[0]]></DSV2Supported><DSV3Supported><![CDATA[1]]></DSV3Supported><DSV2URL><![CDATA[/downloadstation/?ssid=]]></DSV2URL><QWebEnabled><![CDATA[1]]></QWebEnabled><QWebSSLEnabled><![CDATA[1]]></QWebSSLEnabled><QWebSSLPort><![CDATA[8081]]></QWebSSLPort><NVREnabled><![CDATA[0]]></NVREnabled><NVRURL><![CDATA[/surveillance/]]></NVRURL><NVRVER><![CDATA[1]]></NVRVER><WFM2><![CDATA[1]]></WFM2><wfmPortEnabled><![CDATA[0]]></wfmPortEnabled><wfmPort><![CDATA[8080]]></wfmPort><wfmSSLEnabled><![CDATA[0]]></wfmSSLEnabled><wfmSSLPort><![CDATA[443]]></wfmSSLPort><wfmURL><![CDATA[/filestation/]]></wfmURL><QMusicsEnabled><![CDATA[0]]></QMusicsEnabled><QMusicsURL><![CDATA[/musicstation/]]></QMusicsURL><QVideosEnabled><![CDATA[0]]></QVideosEnabled><QVideosURL><![CDATA[/videostation/]]></QVideosURL><QPhotosEnabled><![CDATA[0]]></QPhotosEnabled><QPhotosURL><![CDATA[/photo/]]></QPhotosURL><stunnelEnabled><![CDATA[1]]></stunnelEnabled><stunnelPort><![CDATA[443]]></stunnelPort><forceSSL><![CDATA[1]]></forceSSL><HDAROOT_ALMOST_FULL><![CDATA[0]]></HDAROOT_ALMOST_FULL><passwdConstraints><passwdConstraint01><![CDATA[0]]></passwdConstraint01><passwdConstraint02><![CDATA[0]]></passwdConstraint02><passwdConstraint03><![CDATA[0]]></passwdConstraint03><passwdConstraint04><![CDATA[0]]></passwdConstraint04></passwdConstraints>
<ts><![CDATA[96177256]]></ts><fwNotice><![CDATA[0]]></fwNotice><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[4dec1e319e179d9ab67638e81a12669d]]></cuid></QDocRoot>

('authPassed',)
Traceback (most recent call last):
  File ".\debug.py", line 38, in <module>
    qnap.get_bandwidth()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 279, in get_bandwidth
    force_list=("item")
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 68, in _get_url
    self._init_session()
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 50, in _init_session
    if self._login() is False:
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 58, in _login
    result = self._execute_post_url("authLogin.cgi", data, False)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 99, in _execute_post_url
    return self._handle_response(resp, **kwargs)
  File "C:\Users\James\Documents\python-qnapstats\qnapstats\qnap_stats.py", line 115, in _handle_response
    auth_passed = data['authPassed']
KeyError: 'authPassed'
jrot commented 5 years ago

Any update on this issue?

Getting the samen error on TS-469 Pro OS 4.3.4

colinodell commented 5 years ago

<cuid><![CDATA[4dec1e319e179d9ab67638e81a12669d]]></cuid> looks like it might be a session id, but unfortunately I have no idea how it's used :-/

In order to resolve this, we're going to need somebody to use Chrome Dev Tools to inspect the HTTP requests and see how these devices are a) authenticating, and b) passing that authentication token to the various API endpoints to pull the device data.

cerebrate commented 4 years ago

Well, I can get some of this from my TS-251+ , but you may have to talk me through some of the details of getting it, as web development isn't even close to my main gig. I couldn't get the response data to the actual login request using dev tools ("Failed to load response data"), but using them to perform the identical request with curl, I get this:

❯ curl 'https://mnemosyne.arkane-systems.lan/cgi-bin/authLogin.cgi' -H 'authority: mnemosyne.arkane-systems.lan' -H 'sec-ch-ua: "Microsoft Edge 80"' -H 'origin: https://mnemosyne.arkane-systems.lan' -H 'sec-fetch-dest: empty' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36 Edg/80.0.361.57' -H 'content-type: application/x-www-form-urlencoded' -H 'accept: */*' -H 'sec-fetch-site: same-origin' -H 'sec-fetch-mode: cors' -H 'referer: https://mnemosyne.arkane-systems.lan/cgi-bin/' -H 'accept-language: en-US,en;q=0.9' -H 'cookie: WINDOW_MODE=1; DESKTOP=1; remeber=1; nas_1_u=YWRtaW4=; qtoken_account=YWRtaW4=; QT=1582664404665; NAS_PW_STATUS=0' --data 'user=admin&serviceKey=1&remme=1&pwd=RnNuN1dzZmh2aDJvUUE%3D&r=0.08100709450634147' --compressed --insecure

<?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><qtoken><![CDATA[cdd2d0a9f92a8ecb2a7690d555d1310f]]></qtoken><authPassed><![CDATA[1]]></authPassed><authSid><![CDATA[3lkyu0kl]]></authSid><pw_status><![CDATA[0]]></pw_status><isAdmin><![CDATA[1]]></isAdmin><username><![CDATA[admin]]></username><groupname><![CDATA[administrators]]></groupname><ts><![CDATA[10867949]]></ts><fwNotice><![CDATA[0]]></fwNotice><SUID><![CDATA[4b773bc50ea43391067edce45e68a877]]></SUID><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[WARNING: This is a secure system. Do not login without proper authorization. Unauthorized use will be prosecuted.]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[c459ad9a8e414b891aefacf275853183]]></cuid></QDocRoot>

initiated by https://mnemosyne.arkane-systems.lan/cgi-bin/js/qos-core-login.js?1562189408.

I think the relevant part of this is the "authSid" value, since on inspecting calls to userConfig.cgi, sysinfoReq.cgi, et. al. downstream, it is supplied in the querystring, i.e.:

https://mnemosyne.arkane-systems.lan/cgi-bin/userConfig.cgi?sid=slvl2wgu

and is also present in the request cookies:

cookie: WINDOW_MODE=1; DESKTOP=1; remeber=1; nas_1_u=YWRtaW4=; qtoken_account=YWRtaW4=; QT=1582664404665; NAS_PW_STATUS=0; NAS_USER=admin; NAS_SID=slvl2wgu; home=1; nas_1_a=MC42MjY5NTM1NDk2MDI1MzYyLXgteC14LTAuNzY5MzczNDY5NDIwNDU5OQ==; qtoken=cdd2d0a9f92a8ecb2a7690d555d1310f; showQuickStart=1

While the qtoken value also appears in the cookies, it is identical across multiple login sessions, unlike the sid (NAS_SID) which differs.

cerebrate commented 4 years ago

Further experimentation with curl and a call to userConfig.cgi:

curl 'https://mnemosyne.arkane-systems.lan/cgi-bin/userConfig.cgi?sid=slvl2wgu' -H 'authority: mnemosyne.arkane-systems.lan' -H 'sec-ch-ua: "Microsoft Edge 80"' -H 'origin: https://mnemosyne.arkane-systems.lan' -H 'x-requested-with: XMLHttpRequest' -H 'sec-fetch-dest: empty' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36 Edg/80.0.361.57' -H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' -H 'accept: */*' -H 'sec-fetch-site: same-origin' -H 'sec-fetch-mode: cors' -H 'referer: https://mnemosyne.arkane-systems.lan/cgi-bin/' -H 'accept-language: en-US,en;q=0.9' -H 'cookie: WINDOW_MODE=1; DESKTOP=1; remeber=1; nas_1_u=YWRtaW4=; qtoken_account=YWRtaW4=; QT=1582664404665; NAS_PW_STATUS=0; NAS_USER=admin; NAS_SID=slvl2wgu; home=1; nas_1_a=MC42MjY5NTM1NDk2MDI1MzYyLXgteC14LTAuNzY5MzczNDY5NDIwNDU5OQ==; qtoken=cdd2d0a9f92a8ecb2a7690d555d1310f; showQuickStart=1' --data 'func=getUserProfile' --compressed --insecure

shows that if I can lose the cookies altogether and chop it down to:

curl 'https://mnemosyne.arkane-systems.lan/cgi-bin/userConfig.cgi?sid=slvl2wgu' -H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' --data 'func=getUserProfile' --compressed --insecure

And still have the request succeed.

colinodell commented 4 years ago

Thanks for that information! That does help a bit, but it also makes me a little confused. Over in https://github.com/home-assistant/home-assistant/issues/30980, the stack trace you posted suggested that authPassed was missing, but it's definitely showing in the XML output you shared here... :thinking:

Would you mind sharing the XML output of that /cgi-bin/userConfig.cgi call? I'm curious if it shows up in there or not.

cerebrate commented 4 years ago

Hm. Well, that call doesn't have XML output, just JSON output:

{ "success": "true", "dateformatindex": 1, "timeformat": 24, "current": "2020-02-25T15:25:45", "profile": { "name": "admin", "fullname": "administrator", "address": "", "tel": "", "email": "avatar@arkane-systems.net", "IM": "", "description": "administrator", "misc": "" } }

On the other hand, after seeing that, I also tried calling the /cgi-bin/management/manaRequest.cgi call, thus:

curl 'https://mnemosyne.arkane-systems.lan/cgi-bin/management/manaRequest.cgi?sid=yshqulgr' --compressed --insecure

which does include authPassed:

<?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<authPassed><![CDATA[1]]></authPassed><model><modelName><![CDATA[TS-X51]]></modelName><internalModelName><![CDATA[TS-X51]]></internalModelName><platform><![CDATA[TS-NASX86]]></platform><platform_ex><![CDATA[X86_BAYTRAIL]]></platform_ex><customModelName><![CDATA[]]></customModelName><displayModelName><![CDATA[TS-251+]]></displayModelName><sas_model><![CDATA[0]]></sas_model><storage_v2>1</storage_v2>
<encryptfsSupported><![CDATA[1]]></encryptfsSupported></model>
<firmware><version><![CDATA[4.3.6]]></version><number><![CDATA[0993]]></number><build><![CDATA[20190704]]></build><patch><![CDATA[0]]></patch><buildTime><![CDATA[2019/07/04]]></buildTime></firmware>
<rfs_bits><![CDATA[64]]></rfs_bits><specVersion><![CDATA[1.0]]></specVersion><hostname><![CDATA[mnemosyne]]></hostname><DemoSiteSuppurt><![CDATA[no]]></DemoSiteSuppurt><customLogo><customFrontLogo><![CDATA[]]></customFrontLogo><customLoginLogo><![CDATA[]]></customLoginLogo></customLogo>
</QDocRoot>
cerebrate commented 4 years ago

(Looking through that stack trace, it seems to be missing the authPassed in the response to calling authLogin.cgi from _login ( https://github.com/colinodell/python-qnapstats/blob/8fbb87b99580629c0e0e81358ea888d84301b317/qnapstats/qnap_stats.py#L55 ), but even performing a minimal request to that passing the same data

curl 'https://mnemosyne.arkane-systems.lan/cgi-bin/authLogin.cgi' -H 'content-type: application/x-www-form-urlencoded' --data 'user=admin&pwd=RnNuN1dzZmh2aDJvUUE%3D' --compressed --insecure

gives me back XML which includes authPassed, so I'll confess to being a mite puzzled my own self:

<?xml version="1.0" encoding="UTF-8" ?>
<QDocRoot version="1.0">
<doQuick><![CDATA[]]></doQuick><is_booting><![CDATA[0]]></is_booting><mediaReady><![CDATA[1]]></mediaReady><shutdown_info><type><![CDATA[-1]]></type><timestamp><![CDATA[0]]></timestamp><duration><![CDATA[0]]></duration></shutdown_info>
<SMBFW><![CDATA[0]]></SMBFW><authPassed><![CDATA[1]]></authPassed><authSid><![CDATA[7i02ih00]]></authSid><pw_status><![CDATA[0]]></pw_status><isAdmin><![CDATA[1]]></isAdmin><username><![CDATA[admin]]></username><groupname><![CDATA[administrators]]></groupname><ts><![CDATA[10867949]]></ts><fwNotice><![CDATA[0]]></fwNotice><SUID><![CDATA[4b773bc50ea43391067edce45e68a877]]></SUID><title><![CDATA[]]></title><content><![CDATA[]]></content><psType><![CDATA[1]]></psType><standard_massage><![CDATA[WARNING: This is a secure system. Do not login without proper authorization. Unauthorized use will be prosecuted.]]></standard_massage><standard_color><![CDATA[#FFFFFF]]></standard_color><standard_size><![CDATA[12 px]]></standard_size><standard_bg_style><![CDATA[fill]]></standard_bg_style><showVersion><![CDATA[1]]></showVersion><show_link><![CDATA[1]]></show_link><cuid><![CDATA[c459ad9a8e414b891aefacf275853183]]></cuid></QDocRoot>
cerebrate commented 4 years ago

Okay, even stranger. When I fire up Python and manually create and call a QNAPStats object - per the example section of the README - it works just fine.

>>> from qnapstats import QNAPStats
>>> from pprint import pprint
>>> qnap = QNAPStats('https://mnemosyne.arkane-systems.lan','443','admin','OBVIOUSLY_FAKE_PWD', False, False)
>>> pprint(qnap.get_system_stats())
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1006: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mnemosyne.arkane-systems.lan'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1006: InsecureRequestWarning: Unverified HTTPS request is being made to host 'mnemosyne.arkane-systems.lan'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
{'cpu': {'model': 'Intel(R) Celeron(R) CPU  J1900  @ 2.00GHz',
         'temp_c': 40,
         'temp_f': 104,
         'usage_percent': 27.7},
 'dns': ['172.16.0.128', '172.16.0.130', '172.16.0.128'],
 'firmware': {'build': '20190704',
              'build_time': '2019/07/04',
              'patch': '0',
              'version': '4.3.6'},
 'memory': {'free': 1368.9, 'total': 1885.0},
 'nics': {'eth0': {'err_packets': 0,
                   'ip': '172.16.0.24',
                   'link_status': 'Up',
                   'mac': '24:5e:be:14:aa:33',
                   'mask': '255.255.0.0',
                   'max_speed': 1000,
                   'rx_packets': 1459749180,
                   'tx_packets': 1437501974,
                   'usage': 'DHCP'},
          'eth1': {'err_packets': 0,
                   'ip': '0.0.0.0',
                   'link_status': 'Down',
                   'mac': '24:5e:be:14:aa:34',
                   'mask': '0.0.0.0',
                   'max_speed': 1000,
                   'rx_packets': 0,
                   'tx_packets': 0,
                   'usage': 'DHCP'}},
 'system': {'model': 'TS-251+',
            'name': 'mnemosyne',
            'serial_number': 'Q17BB11057',
            'temp_c': 34,
            'temp_f': 93,
            'timezone': '(GMT-06:00) Central Time(US &amp; Canada)'},
 'uptime': {'days': 185, 'hours': 3, 'minutes': 13, 'seconds': 29}}

It's only the QNAP integration that appears to generate the issue; the above works even when I docker exec into the Home Assistant core container to ensure I'm using its version of python-qnapstats, etc.

nickm324 commented 4 years ago

Has anything changed with this issue for the TS-251+, I am trying to get the sensor working also but am getting a flat out connection refused.

2020-05-14 08:27:59 ERROR (SyncWorker_7) [homeassistant.components.qnap.sensor] Failed to fetch QNAP stats from the NAS Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection raise err File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

colinodell commented 4 years ago

Connection refused indicates a network connectivity issue outside of the scope of this code. Double-check that your IP address is correct, both devices are connected to the same network, the ports are open, no firewall is in the way, etc.

jsinkers commented 4 years ago

Just found some time to come back to this finally. Looks like I had two misconfigurations:

  1. The user wasn't in the admin group
  2. I was forcing HTTPS only (I saw that "http://" gets prepended to the host in qnapstats) - should this actually be an issue? It breaks if I enable HTTPS only.

But now I am able to fetch stats!

cerebrate commented 4 years ago

I have tried disabling https only (my user was already in the admin group), and am still getting the error listed above with the QNAP integration. Can we reopen?

colinodell commented 4 years ago

I saw that "http://" gets prepended to the host in qnapstats

Yes, but that only happens if you don't provide https:// in your host:

https://github.com/colinodell/python-qnapstats/blob/9362161bd06fb0aa0bd874783a01a93f79fb643d/qnapstats/qnap_stats.py#L25-L26

I have tried disabling https only (my user was already in the admin group), and am still getting the error listed above with the QNAP integration. Can we reopen?

Are you still experiencing the same behavior you reported on Feb 25? If so, that would seem to suggest the issue is likely on the HASS side, so I'd recommend creating or updating a ticket in that project. Otherwise, if you can replicate the issue with just the qnapstats library, we can absolutely re-open this :)

cerebrate commented 4 years ago

Will do, thanks.