Handbuch zur MoodleBox (auch offline)

4. MoodleBox erweitern

4.7. URL-Verkürzer

Kurze URLs

https://github.com/moodlebox/moodlebox/issues/90

--- 

2018-09-28

Hi Nicolas,
what do you think about an url shortener for the MoodleBox?

I had a teachers workshop for teachers with a very interesting setting. The teachers should find a hidden MoodleBox in the wood. They used the smartphone app OsmAnd with an OpenStreetMap to find a MoodleBox by its gps coordinates. The MoodleBox had no wifi passwords everybody could connect without knowing a password.

To open a Moodle course firstly I thought about using a qr code. But I should use something digital .... a digital idea .... something like an iBeacon. Okay ... I tested the calliope mini as a beacon ... please look at https://ckblog2016.wordpress.com/2017/08/11/calliope-mini-als-ble-beacon/

The problem was that the beacon allows only 17 characters for the url. Every url expect the start page of the MoodleBox has more than 17 characters. https://makecode.microbit.org/reference/bluetooth/advertise-url

In our offline setting I could not use a normal url shortener from the Internet. There was no connection to the internet. So I added some hard coded short links http://moodlebox/x/t1 for the team 1 and http://moodlebox/x/t2 for the team 2. I did this with a folder x and two subfolders t1 and t2. Inside t1 i loaded an index.php with an http location reload to http://moodlebox.home/course/view.php?id=7&section=1

I am thinking about a local url shortener because no teacher will get an idea how to do this. If there would be an url shortener we would get very easy links like http://mb/x/t1. The url shortener should have a web gui to create and to edit the short links.

Best regards, Ralf

---

2018-10-07

Hi Nicolas,
I got it! The url shortener YOURLS is running on my MoodleBox.

First I should tell why I could not use an url shortener bit.ly or goo.gl or tiny url.com ... my project runs offline on the MoodleBox and I couldn't use an online url shortener. I needed to get very short urls on my MoodleBox because iBeacons should be used for linking to some Moodlebox content ... and iBeacons only allow urls with 16 chars.

So to get a very short base url I edited the file /etc/hosts on my Moodlebox and added mb to the last line. This shows the start page with the short url http://mb/ and a course with http://mb/course/view.php?id=2 ... but the url to any course is still too long for the iBeacon.

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

10.0.0.1        moodlebox.home  moodlebox  mb

I installed the files from http://yourls.org into the folder /var/www/yourls/ and added a new database yourls with the collation utf8_general_ci via phpMyAdmin. I copied the file user/config-sample.php to user/config.php and edited the database settings.

/** MySQL database settings */
define( 'YOURLS_DB_USER', 'moodlebox' );

/** MySQL database password */
define( 'YOURLS_DB_PASS', 'Moodlebox4$' );

/** The name of the database for YOURLS */
define( 'YOURLS_DB_NAME', 'yourls' );

/** MySQL hostname.
 ** If using a non standard port, specify it like 'hostname:port', 
 ** eg. 'localhost:9999' or '127.0.0.1:666' */
define( 'YOURLS_DB_HOST', 'localhost' );

/** MySQL tables prefix */
define( 'YOURLS_DB_PREFIX', 'yourls_' );

/** MySQL database engine */
define( 'YOURLS_DB_DRIVER', 'mysqli' );

/** YOURLS installation URL -- all lowercase and with no trailing slash.
 ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
define( 'YOURLS_SITE', 'http://mb/x' );

In the Moodle folder I added a link to the url shortener ... the url will be http://mb/x ... it's very short :-)

cd /var/www/moodle
sudo ln -s /var/www/yourls x

To rewrite the short urls in the web server nginx I had edit the file /etc/nginx/sites-available/default ... I added some lines at the bottom of the file and rebooted the MoodleBox.

        ### url shortener
        location /x/ {
                try_files $uri $uri/ /x/yourls-loader.php$is_args$args;
        }

This was all ... the database installed automatically on the first start of the admin page http://mb/x/admin.

You will see three predefined short urls in the admin interface and you can add your own urls. I started with http://moodlebox.home/course/view.php?id=2 and the short url http://mb/x/c2/ ... very short ... very nice! The next thing I tested was http://moodlebox.home/course/view.php?id=7&section=2 and the short url http://mb/u/c7s2/.

Some links from my project

moodlebox-yourls