How do implement this plugin in Joomla?

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

badwolfffAuthor Commented:
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?
Steve BinkCommented:
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`
'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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.