C0D3D3V / Moodle-DL

Moodle-DL downloads course content fast from Moodle (eg. lecture pdfs)
GNU General Public License v3.0
428 stars 63 forks source link

sudo: moodle-dl: command not found #111

Closed fulcus closed 3 years ago

fulcus commented 3 years ago

Running moodle-dl with sudo (to automatically retrieve token for example) returns sudo: moodle-dl: command not found

Ubuntu 20.04

It seems to be because sudo doesn't check /home/fulco/.local/bin where moodle-dl is installed, so I tried to run it with the full path of the bin as follows: sudo /home/fulco/.local/bin/moodle-dl and the error is:

Traceback (most recent call last):
  File "/home/fulco/.local/bin/moodle-dl", line 5, in <module>
    from moodle_dl.main import main
ModuleNotFoundError: No module named 'moodle_dl'

Same as above happens copying /home/fulco/.local/bin/moodle-dl to /usr/bin (where commands are usually located) and then running moodle-dl.

C0D3D3V commented 3 years ago

You can install moodle-dl for all users by running sudo pip install moodle-dl. This will also install moodle-dl for root. Be sure to uninstall the user installation, otherwise you will have two versions to manage (run pip uninstall moodle-dl as the user you installed it on).

(( You can also just download the whole project git clone https://github.com/C0D3D3V/Moodle-Downloader-2.git. (Update with git pull). And then you can run ./moodle-dl directly from that directory. ))

fulcus commented 3 years ago

That works. However it won't retrieve the token automatically, after I login and go to the link it doesn't go on.

The token shows up in the console but not in the terminal, where it stays stuck at this point:

fulco@fido:~/projects/webeep-downloader/moodle-dl-test$ sudo moodle-dl --init --sso
Do you want to activate Notifications via mail? (y/N) 
Do you want to activate Notifications via Telegram? (y/N) 
Do you want to activate Notifications via XMPP? (y/N) 
Do you want to configure Error Reporting via Sentry? (y/N) 
URL of Moodle:   https://webeep.polimi.it
 If you want to copy the login-token manual, you will be guided through the manual copy process.
Do you want to try to receive the SSO token automatically? (y/N) Yes
Please log into Moodle on this computer and then visit the following address in your web browser: 
https://webeep.polimi.it/admin/tool/mobile/launch.php?service=moodle_mobile_app&passport=12345&urlscheme=http%3A%2F%2Flocalhost

Sorry to bother you again but I'd like to create a GUI for your app and need to get it to work as automatically as possible first.

C0D3D3V commented 3 years ago

Were you logged into moodle in the web browser?

If you want to build a GUI, then the issue is related to #89 :)

The automatic process works by starting a web server (thats why you need root). And once you click the link (and are logged in to Moodle) you will be redirected to the domain specified in urlscheme, and that is localhost so your own computer and in that case the moodle downloader.

This causes two problems. Normally urlscheme=moodlemobile which on mobile devices and the desktop app will redirect to the app. We could also implement that moodlemobile is a valid URL in the browser by using some browser driver like selenium and redirect to moodle downloader, but it was too much work for me .

1st problem: Since Moodle version 3.8.1 urlscheme can't be customized arbitrarily, so there the webserver doesn't work anymore, because it can't redirect to localhost. See https://github.com/moodle/moodle/blob/214adb798498741f9ddfe3533efcb106db8ad6ec/admin/tool/mobile/launch.php#L38

2nd problem: This probably happened to you. You can force a urlscheme in Moodle, then you can't redirect to localhost either. See https://github.com/moodle/moodle/blob/master/admin/tool/mobile/launch.php#L100 . Then the automatic token thing doesn`t work either,

The best thing would be if we manage to register moodlemobile on the system so that it can be opened with moodle-dl. But you could also just write an electron app, so everything would work (like in the Moodle app).

The easiest way for your Moodle is to copy the token from the settings under "Security Keys".

C0D3D3V commented 3 years ago

Please create a new issue (with sreenshots and everything that can be useful) if you have further questions about getting tokens automatically with SSO login.

C0D3D3V commented 3 years ago

The Moodle version of your Moodle is 3.11.2 anyway so the server does not work anymore because http://localhost is filtered. Actually this warning should come when you try this: https://github.com/C0D3D3V/Moodle-Downloader-2/blob/66592fe997727e05e5de7fc5b710cab9fe80adca/moodle_dl/moodle_connector/moodle_service.py#L133-L140 . I'll check why it didn't come up.

C0D3D3V commented 3 years ago

Ah my version check is wrong :D I check basically if 3.112 > 3.8 xD which is not mathematically larger, but the version itself is newer. I will fix that soon.

C0D3D3V commented 3 years ago

I now know the solution to get a sso token as easy as possible :D I knew it was possible for a long time but I didn't know it was so easy. We just have to set as urlscheme moodle-dl and then register the URI scheme in the system. On linux it is super easy with a desktop entry https://archive.is/8C3zb on windows you have to play with the registry. if you are still interested to implement this :) then very welcome.