Chain Plugin

description: Execute a sys command and create output file in a current directory for a next chain command.
author     : Riccardo Pisanu
email      : rkpisanu@yahoo.it
type       : syntax
lastupdate : 2010-01-23
compatible : 
depends    : 
conflicts  : 
similar    : format
tags       : 

Download

Download chain_latest.zip Latest Current Release: Insert <end> tag for better table parse if it is present, to mark end of line correctly

History:

Download chain_201102180930.zip Current Release: Insert <end> tag for better table parse if it is present, to mark end of line correctly
Download chain_201002011030.zip Current Release: Insert @Path@ Variable
Download chain_201001251500.zip Improved permit delimitator for csv output
Download chain_201001241700.zip Improved csv output
Download chain_201001231840.zip Fixed cache browser problem
Download chain_201001211800.zip Add Wintel Command Line and fixed media access files
Download chain_201001172000.zip First Release: Unix Command Line

Description

This plugin allows you to send text to an external program and display the resulting media (image, text, etc.) in the current wiki page. It create output file in a current wiki directory useful for a next chain command.

DISCLAIMER

This plugin can be very dangerous, because it allows anyone to edit a page on your wiki and potentially execute arbitrary code on the web server (hard to avoid). Using the plugin will be at your own risk. You can use the plugin with the understanding that the author will not be responsible for everything that you could do with it.

All user input is loaded in a file, wrapped in the 'pre' and 'post' text specified in the configuration file or in current wiki text. The resulting file is then made available through the replacement of @InputFile@, @OutputFile@ variable before to run the command line.

Syntax

After setting up the external programs in the conf/default.php file, you can call an external program like:

  <chain alias=program_alias output=file_ouput render=[yes/no] delim=[string|tab|mtab] > 
  text to feed into the program
  </chain>

Where:

alias The alias item is the program present in the conf/default.php files
output The output item is the output filename created without extension. Extension is manage by oext tag ( see below )
render The render item is a flag to set htlm rendering. File rendering is always on.
delim The delim item is a delimitator string for csv to htlm rendering. The tag mtab is special tag to render multitab and multispace separator in sqlplus standard output with no explicit delimitator (Esperimental Only). This is the permit values:
 1) tab  --> \t
 2) mtab --> multiples tabs and spaces
 3) pipe --> |
 4) scol --> ;
 5) default --> ,

Configuration settings

All of the interesting setup happens in the conf/default.php file. For each program to be called, add a block to the conf/default.php file that is similar to:

$conf['<program_alias>']=array('name'   => "<user name>",
            '<mode>' => array('iext'    => "<input  extension>",
                              'oext'    => "<output extension>",
                              'pre'     => "<pre>",
                              'post'    => "<post>",
                              'command_wintel' => '<wintel command line>', 
                              'command' => "<non wintel command line>" ));

The various fields are:

<program_alias> The alias of the program, as it will be used in the alias=program_alias syntax
<user name> The user-friendly name of the program similar to comments
<mode> The mode these particular commands apply to. You can run different programs based on the rendering pass of the page. For example, you can return some text in the 'metadata' mode, but render an image in XHTML mode.
<iext> The extension of the input file that will be generated. Examples: tmp,plt,dot,sql,etc..
<oext> The extension of the output file that will be generated. Examples: out,png,csv,etc..
<pre> Text to go before the text the user wrote in the wiki page. You can use this to set parameters in the program or otherwise set up the environment of the program.
<post> Text to go after the text the user wrote in the wiki page. You can use this to clean up variables, generate pictures, etc.
<wintel command> The command to run via the PHP system call for wintel platform. There are two variables that can be substituted in the command line. @InputFile@ refers to the file containing, in order, the <pre> text, the text the user wrote in the wiki, and the <post> text. @OutputFile@ contains the path and name of the file you should put your result into.
<non wintel command> The command to run via the PHP system call for unix platform. There are two variables that can be substituted in the command line. @InputFile@ refers to the file containing, in order, the <pre> text, the text the user wrote in the wiki, and the <post> text. @OutputFile@ contains the path and name of the file you should put your result into.

Here is an example conf/default.php file:

<?php 				   
 
$conf['pwd']=  array('name'    => 'PWD Command',
    'xhtml' => array('iext'    => 'tmp',
                     'oext'    => 'out',
                     'pre'     => "",
                     'post'    => "",
                     'command_wintel' => 'dir', 
                     'command' => 'ls'));
 
/*
~~NOCACHE~~
<chain alias=pwd output=pwdfile render=yes> 
text to feed into the program
</chain>  
*/
 
$conf['gnuplot']=array('name'    => 'GnuPlot Command',
      'xhtml' => array('iext'    => 'plt',
					   'oext'    => 'png',
                       'pre'     => "set terminal png transparent nocrop enhanced size 640,400\nset output '@OutputFile@'",
                       'post'    => "\nexit\n",
                       'command_wintel' => 'D:\Program Files\xampp\htdocs\crmas\files\gnuplot\bin\gnuplot.exe @InputFile@',
                       'command' => '/usr/bin/gnuplot @InputFile@'));
 
/*
~~NOCACHE~~
<chain alias=gnuplot output=gnuplotfile render=yes>
plot [-20:20] sin(x)/2*x
</chain>
*/
 
$conf['dot']=array('name'   => 'Linux Graphviz Dot Command',
      'xhtml' => array('iext'    => 'dot',
                       'oext'    => 'png',
                       'pre'     => "",
                       'post'    => "",
					   'command_wintel' => 'D:\Program Files\xampp\htdocs\crmas\files\Graphviz2.26\bin\dot.exe -Tpng -o@OutputFile@ @InputFile@',
                       'command' => 'dot -Tpng -o@OutputFile@ @InputFile@'));
 
/*
~~NOCACHE~~
<chain alias=dot output=dotfile render=yes>
digraph G {
 
	subgraph cluster_0 {
		style=filled;
		color=lightgrey;
		node [style=filled,color=white];
		a0 -> a1 -> a2 -> a3;
		label = "process #1";
	}
 
	subgraph cluster_1 {
		node [style=filled];
		b0 -> b1 -> b2 -> b3;
		label = "process #2";
		color=blue
	}
	start -> a0;
	start -> b0;
	a1 -> b3;
	b2 -> a3;
	a3 -> a0;
	a3 -> end;
	b3 -> end;
 
	start [shape=Mdiamond];
	end [shape=Msquare];
}
</chain>
*/
 
$conf['neato']=array('name'   => 'Linux Graphviz Neato Command',
      'xhtml' => array('iext'    => 'dot',
                       'oext'    => 'png',
                       'pre'     => "",
                       'post'    => "",
					   'command_wintel' => 'D:\Program Files\xampp\htdocs\crmas\files\Graphviz2.26\bin\neato.exe -Tpng -o@OutputFile@ @InputFile@',
                       'command' => 'neato -Tpng -o@OutputFile@ @InputFile@'));
 
/*
~~NOCACHE~~
<chain alias=neato output=neatofile render=yes>
digraph DokuWikiParser { 
        node [style=rounded, fontname=Arial, fontsize=13];
        edge [fontname=Arial, fontsize=11];
        P [label=Parser,         shape=box, pin=true, pos="1,3.5", color=red];
        H [label=Handler,        shape=box, pin=true, pos="3,2", color=blue, style="rounded,filled", fontcolor=black, fillcolor=blue];
        CC [label="Client Code", shape=box, pin=true, pos="3,3.5", color=green];
        L [label=Lexer,          shape=box, pin=true, pos="1,2", color=darkviolet];
        M [label=Modes,          shape=box, pin=true, pos="1,1", color=gold1];
        CC -> P [label="Input String"];
        H -> CC [label="Render\nInstructions"];
        P -> L  [label="Modes\n+\nInput String"];
        L -> H  [label=Tokens];
        L -> M  [arrowhead=none];  
 
</chain>
*/
 
$conf['sqlplus_out']=array('name'   => 'Linux Oracle Sqlplus Command',
      'xhtml' => array('iext'    => 'sql',
                       'oext'    => 'out',
                       'pre'     => "set lines 5000;\nset pages 5000;\nset feed off;\nalter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';\n",
                       'post'    => "\nexit\n",
					   'command_wintel' => 'D:\Program Files\xampp\htdocs\crmas\files\shell\sqlplus.bat @InputFile@',
                       'command' => '/usr/bin/sqlplus.ksh @InputFile@'));
 
/*
Create the following shell sqlplus.ksh in the following directory /usr/bin:
 
sudo vi /usr/bin/sqlplus.ksh
 
#..............................................................
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_HOME
export ORACLE_SID=XE
 
export PATH
 
sqlplus -s hr/password@XE @$1
#................................................................
 
Assign the permission to execute:
sudo chmod +x /usr/bin/sqlplus.ksh
 
<chain alias=sqlplus output=dates render=yes> 
select sysdate from dual;
</chain>  
 
*/

File storage

The generated media files are stored in the data/media/temp/chain/<program-name>/namespace/page folder. The folder /temp/chain/* is a temporary folder, so files and directory can be deleted.

Thanks

This plugin is a enhancement and generalization of the existing csv, format, graphviz and gnuplot plugins. Special thanks goes to the authors of those plugins.

dokuwiki/devel/plugins/chain.txt · Last modified: 2013/01/16 14:43 by rkpisanu
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0





Mail