Plush behind apache mod_proxy with authentication (ajax acts funny)

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
User avatar
mantis006
Release Testers
Release Testers
Posts: 17
Joined: January 28th, 2008, 5:06 am
Contact:

Plush behind apache mod_proxy with authentication (ajax acts funny)

Post by mantis006 »

So i have sabnzbd (with plush interface) running on the same box as my web server running Apache2 (with some extra modules like mod_proxy and pretty cool cookie+MySQL authentication system).  The system works great and offers authenticated only access to SABnzbd from afar that works with my existing single sign-on solution.

The "problem" arises when my current session expires and I'm no longer authorized to grab the data that is retrieved on queue and history javascript calls.  The existing code like this for updating the queue (interfaces/Plush/templates/static/javascripts/plush.js):

Code: Select all

function RefreshTheQueue() {
	if (skipRefresh) return $('#skipped_refresh').fadeIn("slow").fadeOut("slow"); // set within queue <table>
	var limit = queue_view_preference;
	if ($('#queue_view_preference').val() != "")
		var limit = $('#queue_view_preference').val()
	$.ajax({
		type: "GET",
		url: 'queue/?dummy2='+limit+'&dummy='+Math.random(),
		success: function(result){
			return $('#queue').html(result);
		}
	});
}
will grab the contents of what should go in that div in html.  my authentication system throws a 301 found header upon failed authentication (defined here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) in order to redirect someone to the proper login screen.  This results in my login page displaying where the queue and history go!

Now I'm not all that familiar with jQuery (a Prototype man myself); but, I think there should be a manner to programmatically distinguish between http status codes when using jQuery's ajax.  It's probably something like on401, 301, etc much like the success or onsuccess depending on your library.

If this is possible in jQuery and Plush+SABnzbd don't find itself throwing out 301 or 401 status codes often (shouldn't be):  I suggest adding the additional anonymous functions to handle 301 and 401 status codes and handle them more appropriately.  For 301 codes, Plush could redirect the client to that location (window.location.href i think?) and for 401 codes a friendly error msg should probably be displayed (otherwise i bet the standard "authentication required" message will appear in the queue and history's place).  Another solution could be to provide an additional variable that can be set in SABnzbd (or Plush) for a redirection url if such codes occur, or even a URL to request regularly in order to keep sessions active.

I'll check into the feasibility of this in jQuery later, and maybe I'll check into this other post as well while I'm at it ?topic=677
Last edited by mantis006 on July 31st, 2008, 4:21 am, edited 1 time in total.
~Chris
Post Reply