lilalo

diff l3-frontend @ 32:4d252e7dd478

l3-frontend:
Добавлена поддержка фильтрации по пользователю (user) и хосту (hostname).
Пока только прототип - нужно оптимизировать.
И нужно стандартизировать имена для полей

l3-cgi:
В current теперь могут быть подразделы
author devi
date Mon Nov 14 07:42:57 2005 +0200 (2005-11-14)
parents 196c82b6e538
children 5f60fe514d49
line diff
     1.1 --- a/l3-frontend	Fri Nov 11 21:29:49 2005 +0200
     1.2 +++ b/l3-frontend	Mon Nov 14 07:42:57 2005 +0200
     1.3 @@ -10,6 +10,7 @@
     1.4  our %Commands_Description;
     1.5  our %Args_Description;
     1.6  our $Mywi_Socket;
     1.7 +our %Sessions;
     1.8  
     1.9  # vvv Инициализация переменных выполняется процедурой init_variables
    1.10  our @Day_Name;
    1.11 @@ -25,6 +26,7 @@
    1.12  sub search_buy;
    1.13  sub make_comment;
    1.14  sub load_command_lines_from_xml;
    1.15 +sub load_sessions_from_xml;
    1.16  sub print_command_lines;
    1.17  sub sort_command_lines;
    1.18  sub process_command_lines;
    1.19 @@ -41,8 +43,9 @@
    1.20  	init_variables();
    1.21  	init_config();
    1.22  
    1.23 -	open_mywi_socket;
    1.24 +	open_mywi_socket();
    1.25  	load_command_lines_from_xml($Config{"backend_datafile"});
    1.26 +	load_sessions_from_xml($Config{"backend_datafile"});
    1.27  	sort_command_lines;
    1.28  	process_command_lines;
    1.29  	print_command_lines($Config{"output"});
    1.30 @@ -223,6 +226,27 @@
    1.31  	}
    1.32  }
    1.33  
    1.34 +sub load_sessions_from_xml
    1.35 +{
    1.36 +	my $datafile = $_[0];
    1.37 +
    1.38 +	open (CLASS, $datafile)
    1.39 +		or die "Can't open file of the class ",$datafile,"\n";
    1.40 +	local $/;
    1.41 +	my $data = <CLASS>;
    1.42 +	close(CLASS);
    1.43 +
    1.44 +	for my $session ($data =~ m@<session>(.*?)</session>@sg) {
    1.45 +		my %session;
    1.46 +		while ($session =~ m@<([^>]*?)>(.*?)</\1>@sg) {
    1.47 +			$session{$1} = $2;
    1.48 +		}
    1.49 +		$Sessions{$session{local_session_id}} = \%session;
    1.50 +	}
    1.51 +}
    1.52 +
    1.53 +
    1.54 +
    1.55  sub sort_command_lines
    1.56  {
    1.57  	# Sort Command_Lines
    1.58 @@ -305,11 +329,11 @@
    1.59  				my $j = $i;
    1.60  				if ($1 eq "^") {
    1.61  					$j--;
    1.62 -					$j-- while ($j >=0  && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]);
    1.63 +					$j-- while ($j >=0  && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
    1.64  				}
    1.65  				elsif ($1 eq "v") {
    1.66  					$j++;
    1.67 -					$j++ while ($j <= @Command_Lines  && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]);
    1.68 +					$j++ while ($j <= @Command_Lines  && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty}));
    1.69  				}
    1.70  				$Command_Lines[$j]->{note_title}="$2";
    1.71  				$Command_Lines[$j]->{note}=$$cl->{output};
    1.72 @@ -373,12 +397,32 @@
    1.73  	my $in_range=0;
    1.74  
    1.75  	my $i=0;
    1.76 +
    1.77 +COMMAND_LINE:
    1.78  	for my $k (@Command_Lines_Index) {
    1.79  
    1.80  		my $cl=$Command_Lines[$Command_Lines_Index[$i++]];
    1.81  		
    1.82  		next unless $cl;
    1.83  
    1.84 +
    1.85 +		if ($Config{filter}) {
    1.86 +			# Инициализация фильтра
    1.87 +			my %filter;
    1.88 +			for (split /&/,$Config{filter}) {
    1.89 +				my ($var, $val) = split /=/;
    1.90 +				$filter{$var} = $val;
    1.91 +			}
    1.92 +
    1.93 +			if ($filter{hostname}) {
    1.94 +				next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{hostname} eq $filter{hostname};
    1.95 +			}
    1.96 +
    1.97 +			#for my $filter_field (keys %filter) {
    1.98 +			#	next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{$filter_field} eq $filter{$filter_field};
    1.99 +			#}
   1.100 +		}
   1.101 +
   1.102  		if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) {
   1.103  			$in_range=1;
   1.104  			next;
   1.105 @@ -495,7 +539,9 @@
   1.106  
   1.107  		# CONSOLE CHANGE
   1.108  		if ( $last_tty ne $cl->{"tty"}) {
   1.109 -			$Result{"body"} .= "<td colspan='6'><table><tr><td class='ttychange' width='140' align='center'>".$cl->{"tty"}."</td><td/></tr></table></td></tr><tr>";
   1.110 +			my $host;
   1.111 +			#$host = $Sessions{$cl->{local_session_id}}->{user}."@".$Sessions{$cl->{local_session_id}}->{hostname};
   1.112 +			$Result{"body"} .= "<td colspan='6'><table><tr><td class='ttychange' width='140' align='center'>".$cl->{"tty"}."</td><td>$host</td></tr></table></td></tr><tr>";
   1.113  			$last_tty=$cl->{"tty"};
   1.114  		}
   1.115  
   1.116 @@ -513,8 +559,10 @@
   1.117  		$Result{"body"} .= "<pre class='${class}cline'>\n";
   1.118  		my $cline = $cl->{"prompt"}.$cl->{"cline"};
   1.119  		$cline =~ s/\n//;
   1.120 +
   1.121 +		#$cline .= "(".$Sessions{$cl->{local_session_id}}.")";
   1.122 +		
   1.123  		my $hint = make_comment($cl->{"cline"});
   1.124 -	#	join(" ",@new_commands), join (" ",@new_files));
   1.125  		$cline = "<div title='$hint'>$cline</div>" if $hint;
   1.126  		$Result{"body"} .= $cline;
   1.127  		$Result{"body"} .= "</pre>\n";
   1.128 @@ -576,7 +624,7 @@
   1.129  		FirstCommand => "Время первой команды журнала",
   1.130  		LastCommand => "Время последней команды журнала",
   1.131  		TotalCommands => "Количество командных строк в журнале",
   1.132 -		ErrorsPercentage => "Процент команд с кодом ненулевым кодом завершения, %",
   1.133 +		ErrorsPercentage => "Процент команд с ненулевым кодом завершения, %",
   1.134  		TotalTime => "Суммарное время работы с терминалом <sup><font size='-2'>*</font></sup>, час",
   1.135  		CommandsPerTime => "Количество командных строк в единицу времени, команда/мин",
   1.136  		CommandsFDistribution => "Частота использования команд",
   1.137 @@ -606,7 +654,7 @@
   1.138  		if $Stat{TotalCommands};
   1.139  	$Stat{CommandsPerTime} = sprintf "%5.2f", $Stat{TotalCommands}*60/$Stat{TotalTime}
   1.140  		if $Stat{TotalTime};
   1.141 -	$Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/24;
   1.142 +	$Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/60;
   1.143  
   1.144  	my $total_commands=0;
   1.145  	for $command (keys %CommandsFDistribution){
   1.146 @@ -614,17 +662,18 @@
   1.147  	}
   1.148  	if ($total_commands) {
   1.149  		for $command (reverse sort {$CommandsFDistribution{$a} <=> $CommandsFDistribution{$b}} keys %CommandsFDistribution){
   1.150 +			my $command_html;
   1.151  			my $percentage = sprintf "%5.2f",$CommandsFDistribution{$command}*100/$total_commands;
   1.152  			if ($percentage < 0.5) {
   1.153  				my $hint = make_comment($command);
   1.154 -				my $command_html = "$command";
   1.155 +				$command_html = "$command";
   1.156  				$command_html = "<span title='$hint' class='hint'>$command_html</span>" if $hint;
   1.157  				my $command_html = "<tt>$command_html</tt>";
   1.158  				$Stat{RareCommands} .= $command_html."<sub><font size='-2'>".$CommandsFDistribution{$command}."</font></sub> , ";
   1.159  			}
   1.160  			else {
   1.161  				my $hint = make_comment($command);
   1.162 -				my $command_html = "$command";
   1.163 +				$command_html = "$command";
   1.164  				$command_html = "<span title='$hint' class='hint'>$command_html</span>" if $hint;
   1.165  				my $command_html = "<tt>$command_html</tt>";
   1.166  				$percentage = sprintf "%5.2f",$percentage;
   1.167 @@ -633,13 +682,14 @@
   1.168  			}
   1.169  		}
   1.170  		$Stat{CommandsFDistribution} = "<table>".$Stat{CommandsFDistribution}."</table>";
   1.171 -		$Stat{RareCommands} =~ s/, $//;
   1.172 +		$Stat{RareCommands} =~ s/, $// if $Stat{RareCommands};
   1.173  	}
   1.174  
   1.175  	$Result{"stat"} .= "<h2 id='stat'>Статистика</h2>";
   1.176  	$Result{"stat"} .= "<table>";
   1.177  	for my $stat (@StatOrder) {
   1.178 -	$Result{"stat"} .= "<tr valign='top'><td width='300'>".$StatNames{"$stat"}."</td><td>".$Stat{"$stat"}."</td></tr>";
   1.179 +	$Result{"stat"} .= "<tr valign='top'><td width='300'>".$StatNames{"$stat"}."</td><td>".$Stat{"$stat"}."</td></tr>"
   1.180 +		if $Stat{"$stat"};
   1.181  	}
   1.182  	
   1.183  	$Result{"stat"} .= "</table>";