Skip to content
ibettinger edited this page Jul 18, 2011 · 19 revisions

Pogo plugins allow administrators to easily change Pogo's default behavior to meet the needs of their particular organization or installation. Where no custom behavior is required, default plugins provide standard functionality out-of-the-box.

In places where Pogo uses a plugin (currently: HTML encoding, root transform definitions, and the constraints engine), an administrator can install a custom perl module which defines alternate functionality with the same interface. Assuming that the module:

  1. provides the methods required by that plugin type
  2. provides a new() method that returns an instance of the plugin
  3. provides a priority() method that returns a higher value than the other plugins of its type

it will be picked up at startup time and used in place of the default plugin.

Example plugin for HTMLEncode

The first and probably simplest use of Pogo's plugin architecture is Pogo::Plugin::HTMLEncode::*, which allows administrators to change the way input (commands, host ranges, etc) is modified for display on the Pogo UI. By default, the plugin module Pogo::Plugin::HTMLEncode::Default will be used: it does basic HTML encoding using HTML::Entities, to prevent XSS attacks, etc.

There is only one required method for an HTMLEncode plugin, html_encode(), which takes a data structure containing inputs to be treated, and returns the same data structure with the scalar values encoded as needed. So, if an administrator wanted to have all output capitalized, she could provide the following plugin and install it in the same directory as Pogo::Plugin::HTMLEncode::Default.

Capitalize.pm

package Pogo::Plugin::HTMLEncode::Capitalize;

sub new { return bless( {}, $_[0] ); }

sub html_encode
{
  my $self = shift;
  my $value = shift;

  if ( ref $value eq 'HASH' )
  {
    foreach my $key ( keys %{$value} )
    {
      $value->{$key} = $self->html_encode( $value->{$key} );
    }
    return $value;

  }
  elsif ( ref $value eq 'ARRAY' )
  {
    return [ map { $self->html_encode($_) } @$value ];
  }

  return uc $value;
}

sub priority { return 100; }

1;

Multiple Plugins

In some cases, (currently only for Root transforms) multiple plugins can be loaded. Any eligible plugins found of that type will be loaded and used as appropriate. For specific details on providing and specifying Root transforms, see the POD documentation for Plugin::Root::Example.

Clone this wiki locally