#!/usr/local/bin/perl
# view.cgi
# Show details of the action, including changed files

require './webminlog-lib.pl';
&ReadParse();
&header($text{'view_title'}, "");
print "<hr>\n";

# find the log record to view
open(LOG, $webmin_logfile);
while(<LOG>) {
	if (($act = &parse_logline($_)) && $act->{'id'} eq $in{'id'}) {
		last;
		}
	}
close(LOG);
if (-r "../$act->{'module'}/log_parser.pl") {
	&foreign_require($act->{'module'}, "log_parser.pl");
	$parser++;
	}

# display info about the action
print "<table border width=100%>\n";
print "<tr $tb> <td><b>",&text('view_header', $act->{'id'}),"</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";

$d = &foreign_call($act->{'module'}, "parse_webmin_log",
		   $act->{'user'}, $act->{'script'},
		   $act->{'action'}, $act->{'type'},
		   $act->{'object'}, $act->{'param'}, 1) if ($parser);
print "<tr> <td valign=top><b>$text{'view_action'}</b></td>\n";
if ($d) {
	print "<td colspan=3>$d</td> </tr>\n";
	}
elsif ($act->{'action'} eq '_config_') {
	print "<td colspan=3>$text{'search_config'}</td> </tr>";
	}
else {
	printf "<td colspan=3>%s %s %s</td> </tr>\n",
		$act->{'action'}, $act->{'type'} ? $act->{'type'} : '',
		$act->{'object'};
	}

print "<tr> <td><b>$text{'view_module'}</b></td>\n";
%minfo = &get_module_info($act->{'module'});
print "<td>$minfo{'desc'}</td>\n";
print "<td><b>$text{'view_script'}</b></td>\n";
print "<td><tt>$act->{'module'}/$act->{'script'}</tt></td> </tr>\n";

print "<tr> <td><b>$text{'view_user'}</b></td>\n";
print "<td>$act->{'user'}</td>\n";
print "<td><b>$text{'view_ip'}</b></td>\n";
print "<td>$act->{'ip'}</td> </tr>\n";

print "<tr>\n";
if ($act->{'sid'} ne '-') {
	print "<td><b>$text{'view_sid'}</b></td>\n";
	print "<td><a href='search.cgi?sid=$act->{'sid'}&uall=1&mall=1&tall=1'>$act->{'sid'}</a></td>\n";
	}
@tm = localtime($act->{'time'});
print "<td><b>$text{'view_time'}</b></td>\n";
printf "<td>%2.2d/%s/%4.4d %2.2d:%2.2d:%2.2d</td> </tr>\n",
	$tm[3], $text{"smonth_".($tm[4]+1)}, $tm[5]+1900,
	$tm[2], $tm[1], $tm[0];

print "</table></td></tr></table><p>\n";

# display modified files
$i = 0;
while(open(DIFF, "$ENV{'WEBMIN_VAR'}/diffs/$act->{'id'}.$i")) {
	local ($type, $object, $diff);
	local $line = <DIFF>;
	while(<DIFF>) { $diff .= $_; }
	close(DIFF);
	if ($line =~ /^(\/.*)/) {
		$type = 'modify'; $object = $1;
		}
	elsif ($line =~ /^(\S+)\s+(.*)/) {
		$type = $1; $object = $2;
		}
	local $t = $text{"view_type_$type"};
	if ($t =~ /\$2/ || !$diff) {
		print "<table border width=100%>\n";
		print "<tr $tb> <td><b>",
		      &text("view_type_$type", "<tt>$object</tt>",
			    "<tt>".&html_escape($diff)."</tt>"),"</b></td> </tr>\n";
		print "</table><p>\n";
		}
	else {
		print "<table border width=100%>\n";
		print "<tr $tb> <td><b>",&text("view_type_$type",
		      "<tt>$object</tt>"),"</b></td> </tr>\n";
		print "<tr $cb> <td><pre>";
		print &html_escape($diff);
		print "</pre></td> </tr></table><p>\n";
		}
	$i++;
	}

print "<b>$text{'view_nofiles'}</b><p>\n" if (!$i);

print "<hr>\n";
&footer($ENV{'HTTP_REFERER'}, $text{'search_return'},
	"", $text{'index_return'});


