mobileraker icon indicating copy to clipboard operation
mobileraker copied to clipboard

Config files access denied

Open robonxt opened this issue 2 years ago • 7 comments

Describe the bug When opening a '.cfg' file from the config files tab, files show a 401 error instead of actual data, cannot be edited in the app.

To Reproduce

  1. Go to 'Files' tab
  2. Tap on 'Configs'
  3. Tap on any '.cfg' file
  4. Editor shows the following content:
{"error": {"code": 401, "message": "Unauthorized", "traceback": "Traceback (most recent call last):\n\n  File \"/home/pi/moonraker-env/lib/python3.9/site-packages/tornado/web.py\", line 1681, in _execute\n    result = self.prepare()\n\n  File \"/home/pi/moonraker/moonraker/app.py\", line 494, in prepare\n    self.current_user = auth.check_authorized(self.request)\n\n  File \"/home/pi/moonraker/moonraker/components/authorization.py\", line 741, in check_authorized\n    raise HTTPError(401, \"Unauthorized\")\n\ntornado.web.HTTPError: HTTP 401: Unauthorized (Unauthorized)\n"}}
  1. Tap save button
  2. Error banner pops up with 'cannot save file'

Expected behavior Editor should load the file and be able to make changes to them. Saving should work without errors.

Screenshots File content Screenshot_20220616-222459__01

Saving error Screenshot_20220616-222509__01

Smartphone (please complete the following information):

  • Device: OnePlus 8T
  • OS: Android 11

**Mobileraker-Version

  • 1.6.2-16 (latest beta from Google Play Store)

robonxt avatar Jun 17 '22 05:06 robonxt

Sorry for my late response. It seems like moonraker does not have the permission to access the config files. Ensure the file manager is configured correctly.

See https://moonraker.readthedocs.io/en/latest/configuration/#file_manager

Clon1998 avatar Jul 03 '22 11:07 Clon1998

Alternatively the authorization might be configured wrongly.

See

https://moonraker.readthedocs.io/en/latest/configuration/#authorization

Clon1998 avatar Jul 03 '22 11:07 Clon1998

Weird. I've followed (or at least copied) many of the config setups, so it should work. Here's my condensed moonraker.conf file:

# moonraker.conf
[server]
host: 0.0.0.0
port: 7125

[file_manager]
config_path: ~/klipper_config
log_path: ~/klipper_logs
enable_object_processing: True

[data_store]
temperature_store_size: 6000
gcode_store_size: 1000

[authorization]
force_logins: True
cors_domains:
  *.local
  *.lan
  *://app.fluidd.xyz

trusted_clients:
  10.0.0.0/8
  127.0.0.0/8
  169.254.0.0/16
  172.16.0.0/12
  192.168.0.0/16
  192.168.2.59
  FE80::/10
  ::1/128

# enables partial support of Octoprint API
[octoprint_compat]

# enables moonraker to track and store print history.
[history]

# Timelapse features here
...

# this enables moonraker's update manager
[update_manager]
enable_auto_refresh: True
channel: beta

# this enables fluidd updates
[update_manager client fluidd]
type: web
repo: fluidd-core/fluidd
path: ~/fluidd

# Timelapse update stuff here
...

[update_manager mobileraker]
type: git_repo
path: ~/mobileraker_companion
origin: https://github.com/Clon1998/mobileraker_companion.git
primary_branch:main
managed_services: mobileraker
env: ~/mobileraker-env/bin/python
requirements: scripts/mobileraker-requirements.txt
install_script: scripts/install-mobileraker-companion.sh

# KlipperScreen update stuff here
...

EDIT: I also have these set up as well:

# add virtual sd card
[virtual_sdcard]
path: ~/sdcard

[force_move]
enable_force_move: True

[pause_resume]
[gcode_arcs]
[exclude_object]
[endstop_phase]

What did I missed or misconfigured?

robonxt avatar Jul 03 '22 19:07 robonxt

Sadly I am not an expert with moonraker and its config. However, does opening the config file work on any webinterface?

Clon1998 avatar Jul 05 '22 09:07 Clon1998

Yes it does. I use fluidd, and the web file manager works normally.

robonxt avatar Jul 05 '22 16:07 robonxt

Hey due to other issues related to printer-url parsing. Can you verify that the Printer-Address in the Printer-Settings is correct? For example, my printer runs on 192.168.178.135 therefore, the correct address should be http://192.168.178.135.

Clon1998 avatar Aug 08 '22 13:08 Clon1998

Sorry for the late response. Yes, the printer address is set properly in the app, if that is what you meant by Printer-Address

robonxt avatar Sep 06 '22 02:09 robonxt

Have the exact same issue. Really frustrating since everything else in the app works as expected.

EricThunder avatar Aug 05 '23 23:08 EricThunder

Have the exact same issue. Really frustrating since everything else in the app works as expected.

Could you please post a screenshot of the printer configuration in mobileraker? Is most cases this is caused by a faulty configured http printer address.

Clon1998 avatar Aug 06 '23 00:08 Clon1998

I set-up my printer behind a reverse proxy (nginx proxy manager) so that I can remote anywhere and have a ssl certificat. image

EricThunder avatar Aug 06 '23 00:08 EricThunder

I set-up my printer behind a reverse proxy (nginx proxy manager) so that I can remote anywhere and have a ssl certificat. image

I don't think the reverse proxy is the issue. After checking the relevant code section again I seem to have found the reason for the error. I simply forgot to correctly setup the HTTP call that is responsible for downloading any config file from moonraker. Therefore, Can you confirm that the app is showing a 400 status code instead of a 404?

Clon1998 avatar Aug 06 '23 00:08 Clon1998

Nope, error code is 401, unauthorized. Maybe I just missed some configuration? But again, everything else works as expected. image

EricThunder avatar Aug 06 '23 00:08 EricThunder

Nope, error code is 401, unauthorized. Maybe I just missed some configuration? But again, everything else works as expected. image

No that's perfect! Its quite late and I confused 400 - Bad Request with 401 - Unauthorized.

This confirms my assumption that I simply forgot to include the header / ApiKey in the request that downloads the file. I will fix that in the next release. Sadly, there is no temporary workaround for this :(

Clon1998 avatar Aug 06 '23 00:08 Clon1998

Well at least now I know its just a bug and don't have to worry about it. I'll just wait until the next update.

EricThunder avatar Aug 06 '23 00:08 EricThunder

Added in 2.5.0

Clon1998 avatar Aug 11 '23 19:08 Clon1998

Finally got the update on the app store (2.5.1) but still got the same exact issue.

EricThunder avatar Aug 14 '23 14:08 EricThunder

Finally got the update on the app store (2.5.1) but still got the same exact issue.

Still 401?

Clon1998 avatar Aug 14 '23 15:08 Clon1998

Yup

EricThunder avatar Aug 14 '23 15:08 EricThunder

Could you send me the logs of the app after you once more tried to open the file. The logs can be found at the bottom of the apps settings

Clon1998 avatar Aug 14 '23 15:08 Clon1998