L33TSig 2 Logo
Personal tools



Writing Linux Plugins

From L33TSig Wiki

Jump to: navigation, search

Since version 0.8.4, L33TSig Linux supports plugins. These plugins can be written using any language, including scripting languages such as Perl and PHP. Please note that if you write a plugin using a scripting language the end user will require that particular interpreter to use your plugin.

Important: Plugins must be set executable (chmod a+x filename) for L33TSig to be able to execute them.

Creating a plugin

When a plugin is loaded into L33TSig, it executes the plugin twice, with 2 command line options:

./plugin --desc
This returns a description which will appear in the Plugins page on the user interface.

./plugin --shortdesc
This is a short description which will appear as the Line Type in the Edit Line dialog.

Linux plugins don't have a "GetLine" method, instead, they use the following:

./plugin
When the plugin is executed with no command line options it is expected to return the results of the plugin in a single line of text.

All 3 functions must end with a linefeed character (ASCII code 10 or "\n" in various scripting languages).

Example plugins

Perl

#!/usr/bin/perl
$desc = "My Perl test plugin 0.0.1 (c)2006 Matthew Hipkin\n";
$shortdesc = "Test Perl plugin\n";
if($#ARGV > -1) {
  if($ARGV[0] eq "--desc") { print $desc; }
  elsif($ARGV[0] eq "--shortdesc") { print $shortdesc; }
}
else {
  print "This is a Perl plugin!\n";
}

C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
  // Check for a required command line option
  if(argc > 1) {
    // Write description
    if(strstr(argv[1],"--desc")) {
      puts("My test C plugin 0.0.1 (c)2006 Matthew Hipkin");
    }
    // Write short description
    if(strstr(argv[1],"--shortdesc")) {
      puts("Test C plugin");
    }
  }
  else {
    // This is the text L33TSig Linux will pick up
    puts("This is a C plugin!");
  }
  return EXIT_SUCCESS;
}

PHP

#!/usr/bin/php -q
<?php
  // Set the description and short description variables
  $desc = "My test PHP plugin 0.0.1 (c)2006 Matthew Hipkin\n";
  $shortdesc = "Test PHP plugin\n";
  // Check for a required command line option
  if(count($argv) > 1) {
    if($argv[1] == "--desc") die($desc);
    elseif($argv[1] == "--shortdesc") die($shortdesc);
  }
  // No command line option was given so we are free to continue
  echo "This is a PHP plugin!\n"; // This is the text L33TSig Linux will pick up
?>