# HG changeset patch # User devi # Date 1131946977 -7200 # Node ID 4d252e7dd478dc0b8f0d90723c98e0e188bd1830 # Parent 196c82b6e53807855f1249ede095b444a6513891 l3-frontend: Добавлена поддержка фильтрации по пользователю (user) и хосту (hostname). Пока только прототип - нужно оптимизировать. И нужно стандартизировать имена для полей l3-cgi: В current теперь могут быть подразделы diff -r 196c82b6e538 -r 4d252e7dd478 l3-agent --- a/l3-agent Fri Nov 11 21:29:49 2005 +0200 +++ b/l3-agent Mon Nov 14 07:42:57 2005 +0200 @@ -8,11 +8,10 @@ use POSIX; use Term::VT102; use Text::Iconv; -use Data::Dumper; use Time::Local 'timelocal_nocheck'; use IO::Socket; -use lib "."; +use lib "/usr/local/bin"; use l3config; @@ -296,6 +295,8 @@ $commandlines_processed++; # time + next if s/^Script started on.*?\n//s; + if (/[0-9][0-9]:[0-9][0-9]:[0-9][0-9].\[[0-9][0-9]D.\[K/ && m/$cline_re/) { s/.*\x0d(?!\x0a)//; # print "!!!",$_,"!!!\n"; diff -r 196c82b6e538 -r 4d252e7dd478 l3-cgi --- a/l3-cgi Fri Nov 11 21:29:49 2005 +0200 +++ b/l3-cgi Mon Nov 14 07:42:57 2005 +0200 @@ -9,7 +9,14 @@ require l3config; }; -my $value = param('PARAM'); +my @filter; + +for my $i (qw(host)) { + my $value = param("$i"); + if ($value) { + push @filter, "$i=$value"; + } +} my %Trainings; my $XMLTraining; @@ -23,7 +30,7 @@ $l3config::Config{"path_classes"}."/".$l3config::Config{"class"}.$l3config::Config{"class_suffix"}; my $XMLTraining = XMLin($classfile , ForceArray => [ 'student' ] ) - or die "Can't open file of the class ",$classfile,"\n"; + or die "Can't open file of the training ",$classfile,"\n"; for my $student (@{$XMLTraining->{"student"}}) { $XMLTraining->{host}->{$student->{"host"}}=$student; @@ -83,7 +90,7 @@ # Вызов производится по URL my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4; - $l3config::Config{"class"}=$course; + $l3config::Config{"class"}=$course if $course ne 'current'; $XMLTraining = load_training; my @args=( @@ -94,9 +101,13 @@ "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname}, "--course-code" => $XMLTraining->{course}, "--course-date" => $XMLTraining->{date}, - "--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml", "--encoding" => $XMLTraining->{host}->{$host}->{charset}, ); + if ($course ne 'current') { + push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml"); + } else { + push @args, ("--filter" => "hostname=".$host."&user=".$user); + } open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |"); while () { diff -r 196c82b6e538 -r 4d252e7dd478 l3-frontend --- a/l3-frontend Fri Nov 11 21:29:49 2005 +0200 +++ b/l3-frontend Mon Nov 14 07:42:57 2005 +0200 @@ -10,6 +10,7 @@ our %Commands_Description; our %Args_Description; our $Mywi_Socket; +our %Sessions; # vvv Инициализация переменных выполняется процедурой init_variables our @Day_Name; @@ -25,6 +26,7 @@ sub search_buy; sub make_comment; sub load_command_lines_from_xml; +sub load_sessions_from_xml; sub print_command_lines; sub sort_command_lines; sub process_command_lines; @@ -41,8 +43,9 @@ init_variables(); init_config(); - open_mywi_socket; + open_mywi_socket(); load_command_lines_from_xml($Config{"backend_datafile"}); + load_sessions_from_xml($Config{"backend_datafile"}); sort_command_lines; process_command_lines; print_command_lines($Config{"output"}); @@ -223,6 +226,27 @@ } } +sub load_sessions_from_xml +{ + my $datafile = $_[0]; + + open (CLASS, $datafile) + or die "Can't open file of the class ",$datafile,"\n"; + local $/; + my $data = ; + close(CLASS); + + for my $session ($data =~ m@(.*?)@sg) { + my %session; + while ($session =~ m@<([^>]*?)>(.*?)@sg) { + $session{$1} = $2; + } + $Sessions{$session{local_session_id}} = \%session; + } +} + + + sub sort_command_lines { # Sort Command_Lines @@ -305,11 +329,11 @@ my $j = $i; if ($1 eq "^") { $j--; - $j-- while ($j >=0 && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]); + $j-- while ($j >=0 && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty})); } elsif ($1 eq "v") { $j++; - $j++ while ($j <= @Command_Lines && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]); + $j++ while ($j <= @Command_Lines && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty})); } $Command_Lines[$j]->{note_title}="$2"; $Command_Lines[$j]->{note}=$$cl->{output}; @@ -373,12 +397,32 @@ my $in_range=0; my $i=0; + +COMMAND_LINE: for my $k (@Command_Lines_Index) { my $cl=$Command_Lines[$Command_Lines_Index[$i++]]; next unless $cl; + + if ($Config{filter}) { + # Инициализация фильтра + my %filter; + for (split /&/,$Config{filter}) { + my ($var, $val) = split /=/; + $filter{$var} = $val; + } + + if ($filter{hostname}) { + next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{hostname} eq $filter{hostname}; + } + + #for my $filter_field (keys %filter) { + # next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{$filter_field} eq $filter{$filter_field}; + #} + } + if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) { $in_range=1; next; @@ -495,7 +539,9 @@ # CONSOLE CHANGE if ( $last_tty ne $cl->{"tty"}) { - $Result{"body"} .= "
".$cl->{"tty"}."
"; + my $host; + #$host = $Sessions{$cl->{local_session_id}}->{user}."@".$Sessions{$cl->{local_session_id}}->{hostname}; + $Result{"body"} .= "
".$cl->{"tty"}."$host
"; $last_tty=$cl->{"tty"}; } @@ -513,8 +559,10 @@ $Result{"body"} .= "
\n";
 		my $cline = $cl->{"prompt"}.$cl->{"cline"};
 		$cline =~ s/\n//;
+
+		#$cline .= "(".$Sessions{$cl->{local_session_id}}.")";
+		
 		my $hint = make_comment($cl->{"cline"});
-	#	join(" ",@new_commands), join (" ",@new_files));
 		$cline = "
$cline
" if $hint; $Result{"body"} .= $cline; $Result{"body"} .= "
\n"; @@ -576,7 +624,7 @@ FirstCommand => "Время первой команды журнала", LastCommand => "Время последней команды журнала", TotalCommands => "Количество командных строк в журнале", - ErrorsPercentage => "Процент команд с кодом ненулевым кодом завершения, %", + ErrorsPercentage => "Процент команд с ненулевым кодом завершения, %", TotalTime => "Суммарное время работы с терминалом *, час", CommandsPerTime => "Количество командных строк в единицу времени, команда/мин", CommandsFDistribution => "Частота использования команд", @@ -606,7 +654,7 @@ if $Stat{TotalCommands}; $Stat{CommandsPerTime} = sprintf "%5.2f", $Stat{TotalCommands}*60/$Stat{TotalTime} if $Stat{TotalTime}; - $Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/24; + $Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/60; my $total_commands=0; for $command (keys %CommandsFDistribution){ @@ -614,17 +662,18 @@ } if ($total_commands) { for $command (reverse sort {$CommandsFDistribution{$a} <=> $CommandsFDistribution{$b}} keys %CommandsFDistribution){ + my $command_html; my $percentage = sprintf "%5.2f",$CommandsFDistribution{$command}*100/$total_commands; if ($percentage < 0.5) { my $hint = make_comment($command); - my $command_html = "$command"; + $command_html = "$command"; $command_html = "$command_html" if $hint; my $command_html = "$command_html"; $Stat{RareCommands} .= $command_html."".$CommandsFDistribution{$command}." , "; } else { my $hint = make_comment($command); - my $command_html = "$command"; + $command_html = "$command"; $command_html = "$command_html" if $hint; my $command_html = "$command_html"; $percentage = sprintf "%5.2f",$percentage; @@ -633,13 +682,14 @@ } } $Stat{CommandsFDistribution} = "".$Stat{CommandsFDistribution}."
"; - $Stat{RareCommands} =~ s/, $//; + $Stat{RareCommands} =~ s/, $// if $Stat{RareCommands}; } $Result{"stat"} .= "

Статистика

"; $Result{"stat"} .= ""; for my $stat (@StatOrder) { - $Result{"stat"} .= ""; + $Result{"stat"} .= "" + if $Stat{"$stat"}; } $Result{"stat"} .= "
".$StatNames{"$stat"}."".$Stat{"$stat"}."
".$StatNames{"$stat"}."".$Stat{"$stat"}."
"; diff -r 196c82b6e538 -r 4d252e7dd478 l3config.pm --- a/l3config.pm Fri Nov 11 21:29:49 2005 +0200 +++ b/l3config.pm Mon Nov 14 07:42:57 2005 +0200 @@ -1,3 +1,4 @@ + package l3config; use Exporter; @@ -7,7 +8,11 @@ @ISA = ('Exporter'); @EXPORT = qw(%Config &init_config); -our $Config_File = "labmaker.conf"; +our $System_Config_File = "/etc/lilalo.conf"; +our $User_Config_File = "$ENV{HOME}/.lilalo.conf"; +$ENV{HOME} ||= "/tmp"; + + our %Config = ( "skip_empty" => "yes", "skip_interrupted" => "no", @@ -28,24 +33,23 @@ "head_lines" => 5, "tail_lines" => 5, - "cache_head_lines" => 50, - "cache_tail_lines" => 50, + "cache_head_lines" => 50, + "cache_tail_lines" => 50, "skip_text" => "...", "show_time" => "yes", "show_diffs" => "yes", "show_comments" => "yes", "show_notes" => "yes", - "input" => "/root/.labmaker", + "input" => "$ENV{HOME}/.lilalo", "diffs" => "", "input_mask" => "*.script", "encoding" => "utf-8", - "cache" => "/tmp/report.xml", - "cache_stat" => "/tmp/.report.dat", + "cache" => "$ENV{HOME}/.lilalo/report.xml", + "cache_stat" => "$ENV{HOME}/.lilalo/.report.dat", "output" => "/tmp/report.html", - #"output" => "report.xml", "output_mask" => "INDEX", "output_format" => "html", "frontend_css" => "/l3/l3.css", @@ -74,12 +78,12 @@ "mode" => "daemon", # daemon | normal "daemon_sleep_interval" => "1", "detach" => "yes", - "agent_pidfile" => "$ENV{HOME}/.labmaker/l3-agent.pid", + "agent_pidfile" => "$ENV{HOME}/.lilalo/l3-agent.pid", "backend_address" => "127.0.0.1", "backend_port" => "18030", "backend_pidfile" => "/tmp/l3-backend.pid", - "backend_datafile" => "/tmp/backend.xml", + "backend_datafile" => "/var/lilalo/lablogs-xml/backend.xml", "l3-agent" => "l3-agent", "l3-backend" => "l3-backend", @@ -91,7 +95,7 @@ "course-trainer" => "", "course-student" => "", - + "filter" => "", #lm "show_host" => "no", @@ -144,7 +148,8 @@ { my %argv_config; my %file_config; - read_config_file(\%file_config, $Config_File); + read_config_file(\%file_config, $System_Config_File); + read_config_file(\%file_config, $User_Config_File); GetOptions(\%argv_config, map "$_=s", keys %Config); %Config = (%Config, %file_config, %argv_config); } diff -r 196c82b6e538 -r 4d252e7dd478 lm --- a/lm Fri Nov 11 21:29:49 2005 +0200 +++ b/lm Mon Nov 14 07:42:57 2005 +0200 @@ -494,6 +494,11 @@ ###install-lm cat $lminstall | ssh $ssh_user@$host /bin/sh -s $dirs +###install-pm +scp PM/* $ssh_user@$host:/tmp +ssh $ssh_user@$host 'cd /tmp; tar xfz Term-VT102*; cd Term-VT102*; perl Makefile.PL; make ; make install' +ssh $ssh_user@$host 'cd /tmp; tar xfz Text-Iconv*; cd Text-Iconv*; perl Makefile.PL; make ; make install' + ###copy-lablogs for i in $dirs do @@ -522,6 +527,7 @@ export UG_DATE="$date" export UG_STUDENT="$name" export UG_COMPANY="$company" +export UG_MAIL="$email" cd $coursepath; make personal; cd ~- ###watch diff -r 196c82b6e538 -r 4d252e7dd478 lm-install --- a/lm-install Fri Nov 11 21:29:49 2005 +0200 +++ b/lm-install Mon Nov 14 07:42:57 2005 +0200 @@ -39,13 +39,9 @@ | sed '/LabMaker:START/,/LabMaker:END/ d' \ > $temp_file cat <<'LM_bash_profile' >> $temp_file - # LabMaker:START - #LMHOME=~/.labmaker - #mkdir -p ${LMHOME} - #TTY=`tty` - #flush="-f" - #exec script $flush -q $LMHOME/${TTY##*/}-$$.script - # LabMaker:END +# LabMaker:START +/usr/local/bin/l3-agent +# LabMaker:END LM_bash_profile cat $temp_file > $profile rm $temp_file @@ -69,7 +65,7 @@ > $temp_file cat <<'LM_bash_profile' >> $temp_file # LabMaker:START -LMHOME=~/.labmaker +LMHOME=~/.lilalo mkdir -p ${LMHOME} uname -a | grep -qi bsd && bsd=yes @@ -100,7 +96,7 @@ cat < $LMHOME/${session_id}.info -$session_id +$session_id $hostname $USER $login_from @@ -139,7 +135,7 @@ cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor #!/bin/sh -LMHOME=~/.labmaker +LMHOME=~/.lilalo if [ "${1#-}" = "$1" -a -d "$LMHOME" ] then LAB=`cat $LMHOME/lab` @@ -192,9 +188,9 @@ # fix this! user=${home%/} user=${user##*/} - mkdir -p $home/.labmaker - echo $first_lab > $home/.labmaker/lab - chown -R $user $home/.labmaker + mkdir -p $home/.lilalo + echo $first_lab > $home/.lilalo/lab + chown -R $user $home/.lilalo #if [ ! -e $home/.bash_profile ] #then @@ -229,9 +225,9 @@ for user in $users_to_install do home=$user - mkdir -p $home/.labmaker - echo $first_lab > $home/.labmaker/lab - chown -R ${user##*/} $home/.labmaker + mkdir -p $home/.lilalo + echo $first_lab > $home/.lilalo/lab + chown -R ${user##*/} $home/.lilalo #if [ ! -e $home/.bash_profile ] #then