It's a simple script that clocks the user in/out of the Moodle platform. Using Web Scraping. Moodle doesn't provide an API.
You are NOT going to learn how to setup or create your our server. You will learn how to setup the docker container and your mobile phone so it can automatically connect to the docker container.
- Moodle Account
- Bot Gmail / Your own Email (NO needed but recommended)
- Docker
- mobile phone (Android OR Iphone)
First let's install Docker and configure it.
sudo apt update && sudo apt install docker.io
Now, lets start and enable docker automatically everytime when we reboot the server.
sudo systemctl start docker && sudo systemctl enable docker
Once you are done just clone this repository.
git clone https://github.com/U-L-M-S/moodle-auto-clock.git
Next change the credentials.json wiht your credentials
{
"username": "[email protected]",
"password": "moodle_pswd_for_login",
"bot_mail": "[email protected]",
"bot_pswd": "bot_gmail_pswd_to_send_email",
"user_mail": "[email protected]"
}
You can use your credentials of your own email and send the email (in case of errors) to youself or create a bot and send the errors via the bot to your email. In each case you will need a gmail app password.
Now you need to configure the docker compose.
just go to the project folder cd moodle-auto-clock
and run this command:
docker compose build
In this way a docker image will be created with the name moodle-auto-clock_image.
you can simple run
ssh user@server "docker run --rm -e ACTION=starten moodle-auto-clock_image"
you can use starten
(it will clock you in) or beenden
(it will clock you out) as variable valuer on ACTION
. But our goal here is to make it happen automatically.
On your Shortcuts go to automation and select the trigger. It can be the time or place.
Then select the action run ssh command, input your informations (hostname, username, password) and in the area of scripting insert this command docker run --rm -e ACTION=starten moodle-auto-clock_image
.
Unfortunately, there is no built-in feature for Android, so we need to use an app. If I am mistaken, please correct me (Coffmann).
There are many apps available. Example apps:
- Tasker Google Play
- MacroDroid Google Play
- Termux GitHub
But for these instructions, we will use the free app "MacroDroid"
- Download and install MacroDroid from an app store of your choice:
- Launch MacroDroid and navigate through the introductory screens.
- On the Tile Screen or Main Menu, locate and tap the "Create Macro" tab.
- Name the macro as you prefer.
- Tap the small plus (+) icon in the upper right corner of the red tile labeled "Trigger".
- Configure the trigger parameters according to your preferences (e.g., Time, Geofence, Shaking).
- Once you've set the trigger, return to the Macro Creation Screen and tap the plus (+) symbol on the blue tile labeled "Actions".
- In the Actions menu, select "Applications", then choose "Shell Script" from the dropdown menu.
- Enable the "Helper App" feature and switch the access type to "No Root Access".
- Now, insert the command
docker run --rm -e ACTION=starten moodle-auto-clock_image
, then press "OK". - OPTIONAL: Customize constraints using the plus (+) symbol within the green tile labeled "Constraints".
- Press the "Back" arrow in the top-left corner, then click "Save" in the pop-up message. You're done!
To view all your saved macros, navigate to the "Macros" tab at the bottom of the Main Menu.