#!/usr/local/bin/perl
# run.cgi
# Run a command, and maybe display it's output

require './proc-lib.pl';
&ReadParse();
$access{'run'} || &error($text{'run_ecannot'});
&switch_acl_uid();

$in{'input'} =~ s/\r//g;
if ($in{'mode'}) {
	# fork and run..
	if (!($pid = fork())) {
		close(STDIN); close(STDOUT); close(STDERR);
		open(PROC, "| ($in{'cmd'})");
		print PROC $in{'input'};
		close(PROC);
		exit;
		}
	&redirect("index_tree.cgi");
	}
else {
	# run and display output..
	$| = 1;
	$theme_no_table = 1;
	&header($text{'run_title'}, "");
	print "<hr><p>\n";
	print &text('run_output', "<tt>$in{'cmd'}</tt>"),"<p>\n";
	print "<pre>";
	$got = &safe_process_exec_logged($in{'cmd'}, 0, 0,
					 STDOUT, $in{'input'}, 1);
	if (!$got) { print "<i>$text{'run_none'}</i>\n"; }
	print "</pre>\n";
	print "<hr>\n";
	&footer("", $text{'index'});
	}
&webmin_log("run", undef, undef, \%in);

