Checking URLS before connecting with EZproxy
Much like many other institutions Brock uses EZproxy to connect users to off-campus resources. In theory everything works perfectly however not always. I wanted to create a web-app that would form an EZproxy request to a particular website and return yes if the URL was in the ezproxy.cfg file. My first attempt at this was using a straight PHP based command line approach. The bad news is that security settings in EZproxy wouldn't allow this to happen, which makes perfect sense looking back at it now. So I tried to see if EZproxy had built in support for this. Much to my happiness EZproxy recently implemented an XML based service that does what I need.
Basically you format an XML object and send it to your Ezproxy software. It returns back an XML object with some great diagnostic information about the request. In particular if it connected. Like many great features of EZproxy this is not documented well. In fact the only real mention of it that I found was on the update page that gets created everytime a new version of the software is out. Look for something called:
You basically set the line:
somepassword in ezproxy.cfg and restart the server. At that point it is ready to go.
Using PHP's simple XML object, here is the specific chunk of code that creates the request, sends it off and evaluates the results from the EZproxy server:
$site_xml_lu = 'http://ezproxy.edu/proxy_url?xml=%3C?xml%20version=%221.0%22?%3E%3Cproxy_url_request%20password= %22somepassword%22%3E%3Curls%3E%3Curl%3E'.$url_in.'%3C/url%3E%3C/urls%3E%3C/proxy_url_request%3E';
$sxe = new SimpleXMLElement($site_xml_lu, NULL, TRUE);
$string = $sxe->asXML();
if (strstr($string, "url proxy=\"true\""))
echo "Yah look up worked!";
echo "Look up failed. Please contact the library";
- Here is the what is right after "$site_xml_lu=" after it has been URL decoded: "http://ezproxy.edu/proxy_url?xml=<?xml version="1.0"?><proxy_url_request password="somepassword"><urls><url>$url_in</url></urls></proxy_url_request>"
- "http://ezproxy.edu/proxy_url?" is the domain name of your proxy instance with /proxy_url? appended
somepasswordis the same one in your ezproxy.cfg file. and
$url_inis the name of the variable I gave the incoming URL you want to look up.
substrchecks to see if "true" is in the returned XML object, indicating that the lookup worked.
You can try this directly in web-based environment by going directly to http://ezproxy.edu/proxy_url (where of course you use the domain name of your ezproxy install). Trying it on the web really makes it clear as to how your XML request needs to look. In fact it gives you a text box with a built example that you can crib from.
After wrapping it up with some AJAX and some other reporting functions the end result is here: