Django app to handle HTTP redirections.
A registered user can redirect an URL under their domain (identified by an alias) in the form http://<path to redirections>/<user>/<alias> to the desired target URL.
https://github.com/samuelmh/django-smh_redirections
The simplest way to use the service is as a mean to shorten URLs like https://goo.gl/ or https://bit.ly//. The user asigns the target URL to an alias (this binding won't be modified).
For example: http://redirections/my_user/school_function could redirect to some youtube video. And the former link is easier to remember.
This is a case where the destination URL can vary over the time while the alias is inmutable. It is useful as a locator for dynamic IP devices (i.e. locate a home web server).
These are the properties of a redirection:
Redirections are fully manageable through the web interface.
The Add/modify redirection widget allows the user to create or modify a redirection. The alias and URL fields are mandatory. It is possible to go from the modify mode to the add one by pressing the 'Cancel' button.
The List section shows the user's redirections.
Actions:
This actions can be performed by any user, even if they are not registered in the system.
When a user visits http://<path to redirections>/<user>/<alias>, if the redirection is public, they will be sent to the URL the user <user> has given to the alias <alias>. The 'Visits' field will be increased by 1.
If a redirection has a password, it is possible to modify the 'URL' field with a POST call to http://<path to redirections>/<user>/<alias> sending the params password=<configured password> and url=<new url>.
The redirection fields 'Visits' will be set to 0 and 'Last refresh' to the time the redirection was modified.
If no POST param url is provided, the 'URL' field will be set to the IP address of the request.
Where can I find the code?
This is free software and the original code can be found at https://github.com/samuelmh/django-smh_redirections
How can I made a machine to update a redirection easily?
The easiest way is to force the machine to send a HTTP POST call to http://<path to redirections>/<user>/<alias>. With the password as a param.
In GNU/Linux this can be automated with the curl command (for the HTTP call) and the cron daemon (calls curl over the time).
EXAMPLE:
Let say your username is 'john', you have a web server installed in your Raspberry Pi at your home but you can't access from outside your home network because you never remember (or even know) the router IP address. Let say you also want to update the redirection every 10 minutes so in case the router resets and change its IP you can access your Raspberry Pi in no more than 10 minutes.
Here the goal is to access your machine just by visiting http://<path to redirections>/john/raspberry
These are the steps to follow:
In this example, the POST param 'url' is not provided because the raspberry doesn't know which is the public IP of the network, so it is better to delegate the guess to the redirections platform. If we wanted to know our public IP whe should ask some external service like http://www.whatsmyip.org/
I have completed the previous tutorial successfully but I cannot access my machine.
Do you have any HTTP service running in your machine? Did you open the needed ports in your router? Are you behind a proxy? Do you even have an idea of what you are doing?
The base URL for the REST API is http://<path to redirections>/api/v1/
Path: /<user>
Method: GET
Auth: YES
IN: NO params
OUT: JSON {redirecions: [{alias:str, url:str, password:str, prints:int, public:bool, last_refresh: int(UTC millis) }] }
Description:
List all the <user> redirections with all the fields.
Path: /<user>
Method: GET
Auth: NO
IN: NO params
OUT: JSON {redirecions: [{alias:str, url:str}] }
Description:
List only the public <user> redirections with the user and alias fields.
Path: /<user>/<alias>
Method: DELETE
Auth: YES
IN: NO params
OUT: JSON {msg: str}
Description:
Delete a redirection. The output is a message with the result of the operation.
Path: /<user>/<alias>
Method: PUT
Auth: YES
IN:JSON
{url:str, public:bool, password:str}
OUT: JSON {msg: str}
Description:
Add or modify (if exists) a redirection. The output is a message with the result of the operation.
The authentication functionality is provided by the django-smh_jwt app. Which decorates the required views (REST API) and expects a JWT token in the Authentication header.
This Django app provides a sample template with a rich web application written in Angular. This webapp uses the REST API to perform the actions.