How do implement this plugin in Joomla?

Posted on 2014-08-18
Last Modified: 2014-08-20
Hi all,

I have a Ubuntu 14.04 server with Varnish 4 installed and I have finally managed to get Wordpress working on it, with the especially tricky part being the backend logging in. Instead with my joomla sites I am still having some difficulty logging in the back end. The front end is working fine so no problems there but the back end, even with the right combination of login/password just does not work. I found an article on the net that might solve my problem but I don't really know how to implement it:

This is an excerpt:
So, firstly there is a Joomla plug-in to set/unset the cookie, as follows...

class  plgSystemVarnish extends JPlugin
  function onAfterRoute( )
    $user = JFactory::getUser( );
    $option = JRequest::getVar( 'option' );
    if( !$user->guest || $option == 'com_users' )
      setcookie( 'varnishbypass', 'True', time( ) + 604800, '/' );
      setcookie( 'varnishbypass', '', time( ) - 604800, '/' );
  // setting the cookie in the afterRoute event is probably adequate,
  // but in an outburst of belt and braces I decided to set/unset the
  // cookie on the log in and out events too. Probably unnecessary,
  // but apparently harmless.
  function onUserLogin( $response )
    setcookie( 'varnishbypass', 'True', time( ) + 604800, '/' );
  function onUserLogout( $response )
    setcookie( 'varnishbypass', '', time( ) - 604800, '/' );
...then an adaptation to the VCL configuration from the snipt site as follows...

  if( req.url ~ "^/administrator" || req.request == "POST" ||
        req.http.cookie ~ "varnishbypass" )
    return( pass );
...and even more Ta Da! this works and respects the users logging in an out.

Open in new window

Now the bottom part about editing the VCL configuration I understand but the top part I have no idea where to put that code in. It seems to be a plugin but how do I install it? Do I just save that code in a .php file inside the joomla "plugins/extension" and try to get Joomla installation to discover it? Or do I have to save it in an installable format for joomla installer? Or is there another way?

Any help will be greatly appreciated
Question by:badwolfff

    Author Comment

    Ah by the way I forgot! On the online version I can't get into the admin backed so I can't install anything... am I in the shit?
    LVL 50

    Accepted Solution

    Please see here:

    For Joomla plugins, you're normally looking for an XML file to handle the installation and parameters.  It does not look like you have that option with this, so you'll need to install it manually.  This is not difficult.

    Take the class code and paste it into a new file.  Name the file Varnish.php.  The capitalization is important.  This plugin is associated with system functionality (the "System" in "class plgSystemVarnish") so that's where we'll install it.  In your website's root directory, find the directory "plugins", then the directory "system" under that.  Create a subdirectory of "system" named "varnish", and copy your new PHP file there.  Don't forget to include an empty index.html for safety (you can copy one from another directory).

    Now you should be able to install the plugin.  This is much better if you can get into the administrative back-end and use the "Discover" functionality.  Otherwise, time to do it the hard way - SQL:
    INSERT INTO `##_extensions` (
    `name`, `type`, `element`, `folder`, 
    `client_id`, `enabled`, `access`, `protected`, 
    `custom_data`, `system_data`
    ) VALUES (
    'plg_varnish', 'plugin', 'varnish', 'system', 
    0, 1, 1, 0, 
    '{"name":"plg_varnish","type":"plugin","creationDate":"August 2014","author":"Give Dude Some Credit","copyright":"Copyright (C) 2014 Where Credit is Due","authorEmail":"","authorUrl":"","version":"3.0.0","description":"Varnish Plugin","group":""}', 
    '', '');

    Open in new window

    A few notes:
    These instructions are J3+.  The process is similar in J2.5, but you might have to tweak the SQL.
    Consider making/obtaining the XML for this plugin.  It's always better to do it right.
    The "manifest_cache" field is a serialized version of the standard manifest file's attributes.  See Joomla's docs on manifest files to learn more.
    In the query, the table name should be corrected to use your proper table prefix.
    If anything goes wrong, you can always disable/remove the plugin with the appropriate UPDATE/DELETE query:/* to disable */ UPDATE ##_extensions SET enabled=0 WHERE name='plg_varnish'; /* to remove */ DELETE FROM ##_extensions WHERE name='plg_varnish';  Don't forget to remove the directory/files if you remove the extension.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Since I am currently running into this issue right now as I type this, I though I would share my experiences with moving a ModX Revolution site from one server to another.  It is not an easy task, but can be accomplished rather easily. The first …
    In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now