- Author: Mark Dehmlow
- Additional author(s):
- Institution: University of Notre Dame
- Year: 2010
- License: GNU GPL version 3, Copyright 2010 University of Notre Dame/Hesburgh Libraries
- Link to terms: http://www.gnu.org/licenses/gpl-3.0.html
- Skill required for using this code:
TRUNC uses a technique called URL redirection - it essentially creates small URLs that are aliases, these aliases redirect to the longer URLs. If used properly, these can be an effective means to provide succinct URLs to systems like SFX and Aleph that have very long URL structures. If used improperly, this technique can mask a URL that your users should not go to, exposing them potentially to malicious computer attacks, viruses, etc.
The benefit to installing TRUNC locally is that you give your small URLs your local branding instead of using a service like tinyurl, and if implemented properly, you can establish trust with this service for your users. The key to making sure TRUNC is used properly is to limit who can create truncated URLs. It is highly recommended that you lock down the trunc/admin directory to be accessible by only specific servers that you designate or password protect it to create an audit trail - the database is able to track IP address and username if sent to it via the api. Here is a sample directive to place in an .htaccess file in the trunc/admin directory:
This will allow access to the index.php (manual creation script) and api.php (api script) only from machines that have a hostname ending in .library.nd.edu or with the IP address 184.108.40.206. You can add other directives that will force login as well or use some combination of IP or username and password.
perl (available on request)
php 5 or greater with mysql, dom, and SimpleXML modules loaded
Initial release of TRUNC. I will create a linked article for how to integrate into SFX.
After downloading the application package, you will need to create a database schema in mysql. You will also have to create a mysql user account that has DROP, CREATE, INSERT, and SELECT permissions. Once installation is complete, you can remove DROP and CREATE from the account, they are only for installing the database.
You can unzip and untar the package and drag and drop it to a web space if you have that ability. Otherwise, place it on your web server and run the following from the command line:
Next go into the trunc/admin directory and edit the config.xml file.
|baseUrl is the URL base that your truncated URLs will use, e.g. http://link.library.nd.edu/|
|apiUrl is the URL that the system will use to send URLs to and get back truncated URLs, they system has a web entry form that uses the api to create truncated URLs|
|the database section holds all of your mysql connection details|
|urlCodeLength is the length of the truncated code, e.g. l3nfo in http://link.library.nd.edu/l3nfo|
note: the system by default will not allow codes shorter than 5 characters
Next, navigate a web browser to the ../trunc/admin/install.php
This script will walk you through the installation, let you know what isn't in place, and once you have all of the php modules installed and database configuration details, it will install the database for you.
Once installation is completed properly, you will be redirected to the small url creation form ../trunc/admin/index.php
If you would like your truncated URLs to look like http://link.library.nd.edu/l3nfo instead of http://link.library.nd.edu/index.cgi?id=l3nfo, you will need to configure your Apache environment to do this for you.
First you will need to allow directives to be placed in .htaccess files - these are files that can apply directives at the directory level.
For security, make sure you have this directive which prohibits people from looking at your .htaccess files
To have pretty truncated URLs without the script name in them, e.g. http://link.library.nd.edu/l3nfo
You must have these two lines in the .htaccess file in the trunc directory
You may also wish to set index.php or index.cgi to be a valid index page (that is one you can see by only typing in the URL to the directory - e.g. http://demo.library.nd.edu/trunc/admin
If you are using the CGI version, you will need to allow CGI for the directory you put it in, if you aren't using the cgi-bin directory
If you are using the CGI version, you may also need to add a line to your config that specifies how to handle cgi files