2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * @package phpMyAdmin-Transformation
7 function PMA_transformation_text_plain__external_info() {
9 'info' => __('LINUX ONLY: Launches an external application and feeds it the column data via standard input. Returns the standard output of the application. The default is Tidy, to pretty-print HTML code. For security reasons, you have to manually edit the file libraries/transformations/text_plain__external.inc.php and list the tools you want to make available. The first option is then the number of the program you want to use and the second option is the parameters for the program. The third option, if set to 1, will convert the output using htmlspecialchars() (Default 1). The fourth option, if set to 1, will prevent wrapping and ensure that the output appears all on one line (Default 1).'),
16 function PMA_transformation_text_plain__external_nowrap($options = array()) {
17 if (!isset($options[3]) ||
$options[3] == '') {
19 } elseif ($options[3] == '1' ||
$options[3] == 1) {
28 function PMA_transformation_text_plain__external($buffer, $options = array(), $meta = '') {
29 // possibly use a global transform and feed it with special options:
30 // include './libraries/transformations/global.inc.php';
32 // further operations on $buffer using the $options[] array.
34 $allowed_programs = array();
39 // It's up to administrator to allow anything here. Note that users may
40 // specify any parameters, so when programs allow output redirection or
41 // any other possibly dangerous operations, you should write wrapper
42 // script that will publish only functions you really want.
44 // Add here program definitions like (note that these are NOT safe
47 //$allowed_programs[0] = '/usr/local/bin/tidy';
48 //$allowed_programs[1] = '/usr/local/bin/validate';
50 // no-op when no allowed programs
51 if (count($allowed_programs) == 0) {
55 if (!isset($options[0]) ||
$options[0] == '' ||
!isset($allowed_programs[$options[0]])) {
56 $program = $allowed_programs[0];
58 $program = $allowed_programs[$options[0]];
61 if (!isset($options[1]) ||
$options[1] == '') {
62 $poptions = '-f /dev/null -i -wrap -q';
64 $poptions = $options[1];
67 if (!isset($options[2]) ||
$options[2] == '') {
71 if (!isset($options[3]) ||
$options[3] == '') {
77 $descriptorspec = array(
78 0 => array("pipe", "r"),
79 1 => array("pipe", "w")
81 $process = proc_open($program . ' ' . $poptions, $descriptorspec, $pipes);
82 if (is_resource($process)) {
83 fwrite($pipes[0], $buffer);
86 while (!feof($pipes[1])) {
87 $newstring .= fgets($pipes[1], 1024);
90 // we don't currently use the return value
91 $return_value = proc_close($process);
94 if ($options[2] == 1 ||
$options[2] == '2') {
95 $retstring = htmlspecialchars($newstring);
97 $retstring = $newstring;