devi@23: #!/usr/bin/perl -w devi@23: devi@31: use IO::Socket; devi@23: use lib '.'; devi@23: use l3config; devi@31: use locale; devi@23: devi@23: our @Command_Lines; devi@31: our @Command_Lines_Index; devi@31: our %Commands_Description; devi@31: our %Args_Description; devi@31: our $Mywi_Socket; devi@32: our %Sessions; devi@23: devi@23: # vvv Инициализация переменных выполняется процедурой init_variables devi@23: our @Day_Name; devi@23: our @Month_Name; devi@23: our @Of_Month_Name; devi@23: our %Search_Machines; devi@23: our %Elements_Visibility; devi@23: # ^^^ devi@23: devi@31: our %Stat; devi@31: our %CommandsFDistribution; # Сколько раз в журнале встречается какая команда devi@31: devi@23: sub search_buy; devi@23: sub make_comment; devi@23: sub load_command_lines_from_xml; devi@32: sub load_sessions_from_xml; devi@23: sub print_command_lines; devi@31: sub sort_command_lines; devi@31: sub process_command_lines; devi@23: sub init_variables; devi@23: sub main; devi@31: sub collapse_list($); devi@23: devi@23: main(); devi@23: devi@23: sub main devi@23: { devi@23: $| = 1; devi@23: devi@23: init_variables(); devi@23: init_config(); devi@23: devi@32: open_mywi_socket(); devi@27: load_command_lines_from_xml($Config{"backend_datafile"}); devi@32: load_sessions_from_xml($Config{"backend_datafile"}); devi@31: sort_command_lines; devi@31: process_command_lines; devi@23: print_command_lines($Config{"output"}); devi@31: close_mywi_socket; devi@23: } devi@23: devi@23: devi@23: sub search_by devi@23: { devi@23: my $sm = shift; devi@23: my $topic = shift; devi@23: $topic =~ s/ /+/; devi@23: devi@23: return ""; devi@23: } devi@23: devi@31: sub extract_from_cline devi@31: # Разобрать командную строку $_[1] и возвратить хэш, содержащий devi@31: # номер первого появление команды в строке: devi@31: # команда => первая позиция devi@31: { devi@31: my $what = $_[0]; devi@31: my $cline = $_[1]; devi@31: my @lists = split /\;/, $cline; devi@31: devi@31: devi@31: my @commands = (); devi@31: for my $list (@lists) { devi@31: push @commands, split /\|/, $list; devi@31: } devi@31: devi@31: my %commands; devi@31: my %args; devi@31: my $i=0; devi@31: for my $command (@commands) { devi@31: $command =~ s@^\s*\S+/@@; devi@31: $command =~ /\s*(\S+)\s*(.*)/; devi@31: if ($1 && $1 eq "sudo" ) { devi@31: $commands{"$1"}=$i++; devi@31: $command =~ s/\s*sudo\s+//; devi@31: } devi@31: $command =~ s@^\s*\S+/@@; devi@31: $command =~ /\s*(\S+)\s*(.*)/; devi@31: if ($1 && !defined $commands{"$1"}) { devi@31: $commands{"$1"}=$i++; devi@31: }; devi@31: if ($2) { devi@31: my $args = $2; devi@31: my @args = split (/\s+/, $args); devi@31: for my $a (@args) { devi@31: $args{"$a"}=$i++ devi@31: if !defined $args{"$a"}; devi@31: }; devi@31: devi@31: devi@31: } devi@31: } devi@31: devi@31: if ($what eq "commands") { devi@31: return \%commands; devi@31: } else { devi@31: return \%args; devi@31: } devi@31: devi@31: } devi@31: devi@31: sub open_mywi_socket devi@31: { devi@31: $Mywi_Socket = IO::Socket::INET->new( devi@31: PeerAddr => $Config{mywi_server}, devi@31: PeerPort => $Config{mywi_port}, devi@31: Proto => "tcp", devi@31: Type => SOCK_STREAM); devi@31: } devi@31: devi@31: sub close_mywi_socket devi@31: { devi@31: close ($Mywi_Socket); devi@31: } devi@31: devi@31: devi@31: sub mywi_client devi@31: { devi@31: my $query = $_[0]; devi@31: my $mywi; devi@31: devi@31: open_mywi_socket; devi@31: if ($Mywi_Socket) { devi@31: local $| = 1; devi@31: local $/ = ""; devi@31: print $Mywi_Socket $query."\n"; devi@31: $mywi = <$Mywi_Socket>; devi@31: $mywi = "" if $mywi =~ /nothing app/; devi@31: } devi@31: close_mywi_socket; devi@31: return $mywi; devi@31: } devi@31: devi@23: sub make_comment devi@23: { devi@31: my $cline = $_[0]; devi@31: #my $files = $_[1]; devi@23: devi@31: my @comments=(); devi@31: my @commands = keys %{extract_from_cline("commands", $cline)}; devi@31: my @args = keys %{extract_from_cline("args", $cline)}; devi@31: return if (!@commands && !@args); devi@31: #return "commands=".join(" ",@commands)."; files=".join(" ",@files); devi@23: devi@23: # Commands devi@31: for my $command (@commands) { devi@23: $command =~ s/'//g; devi@31: $CommandsFDistribution{$command}++; devi@31: if (!$Commands_Description{$command}) { devi@35: my $mywi=""; devi@31: $mywi = mywi_client ($command); devi@31: $mywi = join ("\n", grep(/\([18]\)/, split(/\n/, $mywi))); devi@31: $mywi =~ s/\s+/ /; devi@31: if ($mywi !~ /^\s*$/) { devi@31: $Commands_Description{$command} = $mywi; devi@31: } devi@31: else { devi@31: next; devi@31: } devi@31: } devi@23: devi@31: push @comments, $Commands_Description{$command}; devi@23: } devi@31: return join(" \n", @comments); devi@23: devi@23: # Files devi@31: for my $arg (@args) { devi@31: $arg =~ s/'//g; devi@31: if (!$Args_Description{$arg}) { devi@31: my $mywi; devi@31: $mywi = mywi_client ($arg); devi@31: $mywi = join ("\n", grep(/\([5]\)/, split(/\n/, $mywi))); devi@31: $mywi =~ s/\s+/ /; devi@31: if ($mywi !~ /^\s*$/) { devi@31: $Args_Description{$arg} = $mywi; devi@31: } devi@31: else { devi@31: next; devi@31: } devi@31: } devi@23: devi@31: push @comments, $Args_Description{$arg}; devi@23: } devi@23: devi@23: } devi@23: devi@23: =cut devi@23: Процедура load_command_lines_from_xml выполняет загрузку разобранного lab-скрипта devi@23: из XML-документа в переменную @Command_Lines devi@23: devi@23: Предупреждение! devi@23: Процедура не в состоянии обрабатывать XML-документ любой структуры. devi@23: В действительности файл cache из которого загружаются данные devi@23: просто напоминает XML с виду. devi@23: =cut devi@23: sub load_command_lines_from_xml devi@23: { devi@23: my $datafile = $_[0]; devi@23: devi@23: open (CLASS, $datafile) devi@23: or die "Can't open file of the class ",$datafile,"\n"; devi@23: local $/; devi@23: $data = ; devi@23: close(CLASS); devi@23: devi@23: for $command ($data =~ m@(.*?)@sg) { devi@23: my %cl; devi@23: while ($command =~ m@<([^>]*?)>(.*?)@sg) { devi@23: $cl{$1} = $2; devi@23: } devi@23: push @Command_Lines, \%cl; devi@23: } devi@23: } devi@23: devi@32: sub load_sessions_from_xml devi@32: { devi@32: my $datafile = $_[0]; devi@32: devi@32: open (CLASS, $datafile) devi@32: or die "Can't open file of the class ",$datafile,"\n"; devi@32: local $/; devi@32: my $data = ; devi@32: close(CLASS); devi@32: devi@32: for my $session ($data =~ m@(.*?)@sg) { devi@32: my %session; devi@32: while ($session =~ m@<([^>]*?)>(.*?)@sg) { devi@32: $session{$1} = $2; devi@32: } devi@32: $Sessions{$session{local_session_id}} = \%session; devi@32: } devi@32: } devi@32: devi@32: devi@32: devi@31: sub sort_command_lines devi@31: { devi@31: # Sort Command_Lines devi@31: # Write Command_Lines to Command_Lines_Index devi@31: devi@31: my @index; devi@31: for (my $i=0;$i<=$#Command_Lines;$i++) { devi@31: $index[$i]=$i; devi@31: } devi@31: devi@31: @Command_Lines_Index = sort { devi@31: $Command_Lines[$index[$a]]->{"time"} <=> $Command_Lines[$index[$b]]->{"time"} devi@31: } @index; devi@31: devi@31: } devi@31: devi@31: sub process_command_lines devi@31: { devi@31: for my $i (@Command_Lines_Index) { devi@31: devi@31: my $cl = \$Command_Lines[$i]; devi@35: #@{${$cl}->{"new_commands"}} =(); devi@35: #@{${$cl}->{"new_files"}} =(); devi@31: $$cl->{"class"} = ""; devi@31: devi@31: if ($$cl->{"err"}) { devi@31: $$cl->{"class"}="wrong"; devi@31: $$cl->{"class"}="interrupted" devi@31: if ($$cl->{"err"} eq 130); devi@31: } devi@31: if (!$$cl->{"euid"}) { devi@31: $$cl->{"class"}.="_root"; devi@31: } devi@31: devi@31: #tab# my @tab_words=split /\s+/, $$cl->{"output"}; devi@31: #tab# my $last_word= $$cl->{"cline"} =~ /(\S*)$/; devi@31: #tab# $last_word =~ s@.*/@@; devi@31: #tab# my $this_is_tab=1; devi@31: #tab# devi@31: #tab# if ($last_word && @tab_words >2) { devi@31: #tab# for my $tab_words (@tab_words) { devi@31: #tab# if ($tab_words !~ /^$last_word/) { devi@31: #tab# $this_is_tab=0; devi@31: #tab# last; devi@31: #tab# } devi@31: #tab# } devi@31: #tab# } devi@31: #tab# $$cl->{"class"}="tab" if $this_is_tab; devi@31: devi@31: devi@31: # if ( !$$cl->{"err"}) { devi@31: # # Command does not contain mistakes devi@31: # devi@31: # my %commands = extract_from_cline("commands", ${$cl}->{"cline"}); devi@31: # my %files = extract_from_cline("files", ${$cl}->{"cline"}); devi@31: # devi@31: # # Searching for new commands only devi@31: # for my $command (keys %commands) { devi@31: # if (!defined $Commands_Stat{$command}) { devi@31: # push @{$$cl->{new_commands}}, $command; devi@31: # } devi@31: # $Commands_Stat{$command}++; devi@31: # } devi@31: # devi@31: # for my $file (keys %files) { devi@31: # if (!defined $Files_Stat{$file}) { devi@31: # push @{$$cl->{new_files}}, $file; devi@31: # } devi@31: # $Files_Stat{$file}++; devi@31: # } devi@31: # } devi@31: devi@31: if ($$cl->{cline}=~ m@cat[^#]*#([\^=v])\s*(.*)@) { devi@31: if ($1 eq "=") { devi@31: $$cl->{"class"} = "note"; devi@31: $$cl->{"note"} = $$cl->{"output"}; devi@31: $$cl->{"note_title"} = $2; devi@31: } devi@31: else { devi@31: my $j = $i; devi@31: if ($1 eq "^") { devi@31: $j--; devi@32: $j-- while ($j >=0 && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty})); devi@31: } devi@31: elsif ($1 eq "v") { devi@31: $j++; devi@32: $j++ while ($j <= @Command_Lines && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty})); devi@31: } devi@31: $Command_Lines[$j]->{note_title}="$2"; devi@31: $Command_Lines[$j]->{note}=$$cl->{output}; devi@31: $$cl=0; devi@31: } devi@31: } devi@31: elsif ($$cl->{cline}=~ /#([\^=v])(.*)/) { devi@31: if ($1 eq "=") { devi@31: $$cl->{"class"} = "note"; devi@31: $$cl->{"note"} = $2; devi@31: } devi@31: else { devi@31: my $j=$i; devi@31: if ($1 eq "^") { devi@31: $j--; devi@31: $j-- while ($j >=0 && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty})); devi@31: } devi@31: elsif ($1 eq "v") { devi@31: $j++; devi@31: $j++ while ($j <= @Command_Lines && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]); devi@31: } devi@37: $Command_Lines[$j]->{note}.="$2\n"; devi@31: $$cl=0; devi@31: } devi@31: } devi@31: } devi@31: devi@31: } devi@31: devi@31: devi@23: =cut devi@23: Процедура print_command_lines выводит HTML-представление devi@23: разобранного lab-скрипта. devi@23: devi@23: Разобранный lab-скрипт должен находиться в массиве @Command_Lines devi@23: =cut devi@23: devi@23: sub print_command_lines devi@23: { devi@23: my $output_filename=$_[0]; devi@23: devi@23: my $course_name = $Config{"course-name"}; devi@23: my $course_code = $Config{"course-code"}; devi@23: my $course_date = $Config{"course-date"}; devi@23: my $course_center = $Config{"course-center"}; devi@23: my $course_trainer = $Config{"course-trainer"}; devi@23: my $course_student = $Config{"course-student"}; devi@23: devi@23: devi@23: # Результат выполнения процедуры равен devi@23: # join("", @Result{header,body,stat,help,about,footer}) devi@23: my %Result; devi@31: my @toc; # Хранит оглавление devi@31: my $note_number=0; devi@23: devi@23: $Result{"body"} = "\n"; devi@23: devi@23: my $cl; devi@23: my $last_tty=""; devi@23: my $last_day=""; devi@23: my $in_range=0; devi@23: devi@31: my $i=0; devi@32: devi@32: COMMAND_LINE: devi@31: for my $k (@Command_Lines_Index) { devi@31: devi@31: my $cl=$Command_Lines[$Command_Lines_Index[$i++]]; devi@31: devi@31: next unless $cl; devi@23: devi@32: devi@32: if ($Config{filter}) { devi@32: # Инициализация фильтра devi@32: my %filter; devi@32: for (split /&/,$Config{filter}) { devi@32: my ($var, $val) = split /=/; devi@32: $filter{$var} = $val; devi@32: } devi@32: devi@37: for my $filter_key (keys %filter) { devi@37: next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{$filter_key} eq $filter{$filter_key}; devi@32: } devi@32: devi@37: #if ($filter{user}) { devi@37: # next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{user} eq $filter{user}; devi@37: #} devi@35: devi@32: #for my $filter_field (keys %filter) { devi@32: # next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{$filter_field} eq $filter{$filter_field}; devi@32: #} devi@32: } devi@32: devi@23: if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) { devi@23: $in_range=1; devi@23: next; devi@23: } devi@23: if ($Config{"to"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"to"}/) { devi@23: $in_range=0; devi@23: next; devi@23: } devi@23: next if ($Config{"from"} && $Config{"to"} && !$in_range) devi@23: || devi@23: ($Config{"skip_empty"} =~ /^y/i && $cl->{"cline"} =~ /^\s*$/ ) devi@23: || devi@23: ($Config{"skip_wrong"} =~ /^y/i && $cl->{"err"} != 0) devi@23: || devi@23: ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130); devi@23: devi@23: #my @new_commands=@{$cl->{"new_commands"}}; devi@23: #my @new_files=@{$cl->{"new_files"}}; devi@23: devi@31: if ($cl->{class} eq "note") { devi@31: my $note = $cl->{note}; devi@31: $note = join ("\n", map ("

$_

", split (/-\n/, $note))); devi@35: $note =~ s@(http:[a-zA-Z.0-9/?%-]*)@$1@g; devi@35: $note =~ s@(www\.[a-zA-Z.0-9/?%-]*)@$1@g; devi@31: $Result{"body"} .= ""; devi@31: devi@31: if ($cl->{note_title}) { devi@31: push @{$toc[@toc]},"".$cl->{note_title}.""; devi@31: $note_number++; devi@31: } devi@31: next; devi@31: } devi@31: devi@23: my $cl_class="cline"; devi@23: my $out_class="output"; devi@23: if ($cl->{"class"}) { devi@23: $cl_class = $cl->{"class"}."_".$cl_class; devi@23: $out_class = $cl->{"class"}."_".$out_class; devi@23: } devi@23: devi@23: my @new_commands; devi@23: my @new_files; devi@23: @new_commands = split (/\s+/, $cl->{"new_commands"}) if defined $cl->{"new_commands"}; devi@23: @new_files = split (/\s+/, $cl->{"new_files"}) if defined $cl->{"new_files"}; devi@23: devi@23: my $output=""; devi@23: if ($Config{"head_lines"} || $Config{"tail_lines"}) { devi@23: # Partialy output devi@23: my @lines = split '\n', $cl->{"output"}; devi@23: # head devi@23: my $mark=1; devi@23: for (my $i=0; $i<= $#lines && $i < $Config{"head_lines"}; $i++) { devi@23: $output .= $lines[$i]."\n"; devi@23: } devi@23: # tail devi@23: my $start=$#lines-$Config{"tail_lines"}+1; devi@23: if ($start < 0) { devi@23: $start=0; devi@23: $mark=0; devi@23: } devi@23: if ($start < $Config{"head_lines"}) { devi@23: $start=$Config{"head_lines"}; devi@23: $mark=0; devi@23: } devi@23: $output .= $Config{"skip_text"}."\n" if $mark; devi@23: for (my $i=$start; $i<= $#lines; $i++) { devi@23: $output .= $lines[$i]."\n"; devi@23: } devi@23: } devi@23: else { devi@23: # Full output devi@23: $output .= $cl->{"output"}; devi@23: } devi@23: #$output .= "^C\n" if ($cl->{"err"} eq "130"); devi@23: devi@23: # devi@23: ## devi@23: ## Начинается собственно вывод devi@23: ## devi@23: # devi@23: devi@23: # devi@23: devi@23: my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime($cl->{time}); devi@31: $Stat{FirstCommand} = $cl->{time} unless $Stat{FirstCommand}; devi@31: $Stat{LastCommand} = 0 unless defined $Stat{LastCommand}; devi@31: $Stat{TotalTime} += $cl->{time} - $Stat{LastCommand} devi@31: if $cl->{time} - $Stat{LastCommand} < $Config{stat_inactivity_interval}; devi@31: $Stat{LastCommand} = $cl->{time}; devi@31: $Stat{TotalCommands} = 0 unless $Stat{TotalCommands}; devi@31: $Stat{TotalCommands}++; devi@31: devi@23: # Добавляем спереди 0 для удобочитаемости devi@23: $min = "0".$min if $min =~ /^.$/; devi@23: $hour = "0".$hour if $hour =~ /^.$/; devi@23: $sec = "0".$sec if $sec =~ /^.$/; devi@23: devi@23: $class=$cl->{"out_class"}; devi@23: $class =~ s/output$//; devi@23: devi@31: $Stat{ErrorCommands}++ devi@31: if $class =~ /wrong/; devi@23: devi@23: $Result{"body"} .= "\n"; devi@23: devi@23: devi@23: # DAY CHANGE devi@23: if ( $last_day ne $day) { devi@23: #$Result{"body"} .= ""; devi@23: $Result{"body"} .= ""; devi@31: push @toc, "".$Day_Name[$wday]."\n"; devi@23: $last_day=$day; devi@23: } devi@23: devi@23: # CONSOLE CHANGE devi@23: if ( $last_tty ne $cl->{"tty"}) { devi@32: my $host; devi@32: #$host = $Sessions{$cl->{local_session_id}}->{user}."@".$Sessions{$cl->{local_session_id}}->{hostname}; devi@32: $Result{"body"} .= ""; devi@23: $last_tty=$cl->{"tty"}; devi@23: } devi@23: devi@23: # TIME devi@23: if ($Config{"show_time"} =~ /^y/i) { devi@23: $Result{"body"} .= ""; devi@23: } else { devi@23: $Result{"body"} .= "\n"; devi@23: $Result{"body"} .= "\n"; devi@23: } devi@23: devi@23: $Result{"body"} .= "
"; devi@31: $Result{"body"} .= "

".$cl->{note_title}."

" if $cl->{note_title}; devi@31: $Result{"body"} .= "".$note."

День ",$day,"

".$Day_Name[$wday]."

".$cl->{"tty"}."$host
".
devi@23: 				$hour. ":". $min. ":". $sec.
devi@23: 				"
" devi@23: } devi@23: devi@23: # COMMAND devi@23: $Result{"body"} .= "\n"; devi@23: $Result{"body"} .= "
\n";
devi@31: 		my $cline = $cl->{"prompt"}.$cl->{"cline"};
devi@23: 		$cline =~ s/\n//;
devi@32: 
devi@32: 		#$cline .= "(".$Sessions{$cl->{local_session_id}}.")";
devi@32: 		
devi@31: 		my $hint = make_comment($cl->{"cline"});
devi@31: 		$cline = "
$cline
" if $hint; devi@31: $Result{"body"} .= $cline; devi@23: $Result{"body"} .= "
\n"; devi@23: devi@23: my $last_command = $cl->{"last_command"}; devi@23: if (!( devi@23: $Config{"suppress_editors"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"editors"}}) || devi@23: $Config{"suppress_pagers"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"pagers"}}) || devi@23: $Config{"suppress_terminal"}=~ /^y/i && grep ($_ eq $last_command, @{$Config{"terminal"}}) devi@23: )) { devi@23: devi@23: $Result{"body"} .= "
";
devi@23: 			$Result{"body"} .= $output;
devi@23: 			$Result{"body"} .= "
\n"; devi@23: } devi@23: devi@23: # DIFF devi@23: if ( $Config{"show_diffs"} =~ /^y/i && $cl->{"diff"}) { devi@23: $Result{"body"} .= "
";
devi@23: 			$Result{"body"} .= $cl->{"diff"};
devi@23: 			$Result{"body"} .= "
"; devi@23: } devi@31: devi@31: #NOTES devi@31: if ( $Config{"show_notes"} =~ /^y/i && $cl->{"note"}) { devi@31: my $note=$cl->{"note"}; devi@31: $note =~ s/\n/\n/msg; devi@35: $note =~ s@(http:[a-zA-Z.0-9/?%-]*)@$1@g; devi@35: $note =~ s@(www\.[a-zA-Z.0-9/?%-]*)@$1@g; devi@31: # Ширину пока не используем devi@31: # $Result{"body"} .= ""; devi@31: $Result{"body"} .= "
"; devi@31: $Result{"body"} .= "" if $cl->{note_title}; devi@31: $Result{"body"} .= ""; devi@31: $Result{"body"} .= "
".$cl->{note_title}."
".$note."
\n"; devi@31: } devi@23: devi@23: # COMMENT devi@23: if ( $Config{"show_comments"} =~ /^y/i) { devi@31: my $comment = make_comment($cl->{"cline"}); devi@23: if ($comment) { devi@23: $Result{"body"} .= "". devi@23: "
"; devi@23: $Result{"body"} .= ""; devi@23: $Result{"body"} .= $comment; devi@23: $Result{"body"} .= "
\n"; devi@23: $Result{"body"} .= "
"; devi@23: } devi@23: } devi@23: devi@23: # Вывод очередной команды окончен devi@23: $Result{"body"} .= "
\n"; devi@23: devi@31: #$Result{"stat"} = "
"; devi@31: devi@31: %StatNames = ( devi@31: FirstCommand => "Время первой команды журнала", devi@31: LastCommand => "Время последней команды журнала", devi@31: TotalCommands => "Количество командных строк в журнале", devi@32: ErrorsPercentage => "Процент команд с ненулевым кодом завершения, %", devi@31: TotalTime => "Суммарное время работы с терминалом *, час", devi@31: CommandsPerTime => "Количество командных строк в единицу времени, команда/мин", devi@37: CommandsFrequency => "Частота использования команд", devi@31: RareCommands => "Частота использования этих команд < 0.5%", devi@31: ); devi@31: @StatOrder = ( devi@31: FirstCommand, devi@31: LastCommand, devi@31: TotalCommands, devi@31: ErrorsPercentage, devi@31: TotalTime, devi@31: CommandsPerTime, devi@37: CommandsFrequency, devi@31: RareCommands, devi@31: ); devi@31: devi@31: # Подготовка статистики к выводу devi@31: # Некоторые значения пересчитываются! devi@31: # Дальше их лучше уже не использовать!!! devi@31: devi@37: my %CommandsFrequency = %CommandsFDistribution; devi@37: devi@31: my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($Stat{FirstCommand}); devi@31: $Stat{FirstCommand} = sprintf "%02i:%02i:%02i %04i-%2i-%2i", $hour, $min, $sec, $year+1900, $mon+1, $mday; devi@31: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($Stat{LastCommand}); devi@31: $Stat{LastCommand} = sprintf "%02i:%02i:%02i %04i-%2i-%2i", $hour, $min, $sec, $year+1900, $mon+1, $mday; devi@31: $Stat{ErrorsPercentage} = sprintf "%5.2f", $Stat{ErrorCommands}*100/$Stat{TotalCommands} devi@31: if $Stat{TotalCommands}; devi@31: $Stat{CommandsPerTime} = sprintf "%5.2f", $Stat{TotalCommands}*60/$Stat{TotalTime} devi@31: if $Stat{TotalTime}; devi@32: $Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/60; devi@31: devi@31: my $total_commands=0; devi@37: for $command (keys %CommandsFrequency){ devi@37: $total_commands += $CommandsFrequency{$command}; devi@31: } devi@31: if ($total_commands) { devi@37: for $command (reverse sort {$CommandsFrequency{$a} <=> $CommandsFrequency{$b}} keys %CommandsFrequency){ devi@32: my $command_html; devi@37: my $percentage = sprintf "%5.2f",$CommandsFrequency{$command}*100/$total_commands; devi@31: if ($percentage < 0.5) { devi@31: my $hint = make_comment($command); devi@32: $command_html = "$command"; devi@31: $command_html = "$command_html" if $hint; devi@31: my $command_html = "$command_html"; devi@37: $Stat{RareCommands} .= $command_html."".$CommandsFrequency{$command}." , "; devi@31: } devi@31: else { devi@31: my $hint = make_comment($command); devi@32: $command_html = "$command"; devi@31: $command_html = "$command_html" if $hint; devi@31: my $command_html = "$command_html"; devi@31: $percentage = sprintf "%5.2f",$percentage; devi@37: $Stat{CommandsFrequency} .= "".$command_html."".$CommandsFrequency{$command}."". devi@37: "|".("="x int($CommandsFrequency{$command}*100/$total_commands))."| $percentage%"; devi@31: } devi@31: } devi@37: $Stat{CommandsFrequency} = "".$Stat{CommandsFrequency}."
"; devi@32: $Stat{RareCommands} =~ s/, $// if $Stat{RareCommands}; devi@31: } devi@31: devi@23: $Result{"stat"} .= "

Статистика

"; devi@31: $Result{"stat"} .= ""; devi@31: for my $stat (@StatOrder) { devi@32: $Result{"stat"} .= "" devi@32: if $Stat{"$stat"}; devi@31: } devi@31: devi@31: $Result{"stat"} .= "
".$StatNames{"$stat"}."".$Stat{"$stat"}."
"; devi@31: $Result{"stat"} .= "____
*) Интервалы неактивности длительностью ".($Config{stat_inactivity_interval}/60)." минут и более не учитываются

"; devi@31: devi@31: #$Result{"help"} .= "
"; devi@23: $Result{"help"} .= "

Справка

"; devi@23: $Result{"help"} .= "$Html_Help
"; devi@31: #$Result{"about"} .= "
"; devi@23: $Result{"about"} .= "

О программе

"; devi@23: $Result{"about"} .= "$Html_About"; devi@23: $Result{"footer"} .= "\n"; devi@23: $Result{"footer"} .= "\n"; devi@23: devi@31: $Result{"title"} = "Журнал лабораторных работ"; devi@31: $Result{"title"}.= " -- ".$course_student if $course_student; devi@31: if ($course_date) { devi@31: $Result{"title"}.= " -- ".$course_date; devi@31: $Result{"title"}.= "/".$course_code if $course_code; devi@31: } devi@31: else { devi@31: $Result{"title"}.= " -- ".$course_code if $course_code; devi@31: } devi@31: devi@23: # Заголовок генерируется позже всего devi@23: # Тогда, когда известно уже, что должно быть написано в devi@23: # оглавлении devi@23: $Result{"header"} = < devi@23: devi@23: devi@27: devi@31: $Result{title} devi@23: devi@23: devi@23: devi@31:

Журнал лабораторных работ

devi@23: devi@31: HEADER devi@31: $Result{"header"} .= "

" if $course_student || $course_trainer || $course_name || $course_code || $course_date || $course_center; devi@31: $Result{"header"} .= "Выполнил $course_student
" if $course_student; devi@31: $Result{"header"} .= "Проверил $course_trainer
" if $course_trainer; devi@31: $Result{"header"} .= "Курс " if $course_name || $course_code || $course_date; devi@31: $Result{"header"} .= "$course_name " if $course_name; devi@31: $Result{"header"} .= "($course_code)" if $course_code; devi@31: $Result{"header"} .= ", $course_date
" if $course_date; devi@31: $Result{"header"} .= "Учебный центр $course_center
" if $course_center; devi@31: $Result{"header"} .= "

" if $course_student || $course_trainer || $course_name || $course_code || $course_date || $course_center; devi@23: devi@31: my $toc = collapse_list (\@toc); devi@31: $Result{"header"} .= < devi@23:
  • Журнал
  • devi@23:
      $toc
    devi@23:
  • Статистика
  • devi@23:
  • Справка
  • devi@23:
  • О программе
  • devi@23: devi@23: devi@23:

    Журнал

    devi@23: HEADER devi@31: $Result{"header"} .= "
    \n"; devi@23: for my $element (keys %Elements_Visibility) devi@23: { devi@23: my @e = split /\s+/, $element; devi@23: my $showhide = join "", map { "ShowHide('$_');" } @e ; devi@23: $Result{"header"} .= "". devi@23: $Elements_Visibility{$element}. devi@23: "
    \n"; devi@23: } devi@23: devi@23: $Result{"header"} .= "
    \n"; devi@23: devi@27: if ($output_filename eq "-") { devi@27: print $Result{"header"}, $Result{"body"}, $Result{"stat"}, $Result{"help"}, $Result{"about"}, $Result{"footer"}; devi@27: } devi@27: else { devi@27: open(OUT, ">", $output_filename) devi@27: or die "Can't open $output_filename for writing\n"; devi@27: print OUT $Result{"header"}, $Result{"body"}, $Result{"stat"}, $Result{"help"}, $Result{"about"}, $Result{"footer"}; devi@27: close(OUT); devi@27: } devi@23: } devi@23: devi@23: devi@23: devi@31: sub collapse_list($) devi@31: { devi@31: my $res = ""; devi@31: for my $elem (@{$_[0]}) { devi@31: if (ref $elem eq "ARRAY") { devi@31: $res .= "
      ".collapse_list($elem)."
    "; devi@31: } devi@31: else devi@31: { devi@31: $res .= "
  • ".$elem."
  • "; devi@31: } devi@31: } devi@31: return $res; devi@31: } devi@31: devi@23: devi@23: devi@23: devi@23: sub init_variables devi@23: { devi@23: $Html_Help = < devi@31:
  • devi@31: В журнал автоматически попадают все команды, данные в любом терминале системы. devi@31:

  • devi@31:
  • devi@31: Для того чтобы убедиться, что журнал на текущем терминале ведётся, devi@31: и команды записываются, дайте команду w. devi@31: В поле WHAT, соответствующем текущему терминалу, devi@31: должна быть указана программа script. devi@31:

  • devi@31:
  • devi@31: Если код завершения команды равен нулю, devi@31: команда была выполнена без ошибок. devi@36: Команды, код завершения которых отличен от нуля, выделяются цветом. devi@31: devi@31: devi@31: devi@31: devi@31:
    devi@31:
    devi@31: \$ l s-l
    devi@31:
    bash: l: command not found
    devi@31: 
    devi@31:
    devi@31:
    devi@31:

  • devi@31:
  • devi@31: Команды, ход выполнения которых был прерван пользователем, выделяются цветом. devi@31: devi@31: devi@31: devi@31: devi@31:
    devi@31:
    devi@31: \$ find / -name abc
    devi@31:
    find: /home/devi-orig/.gnome2: Keine Berechtigung
    devi@31: find: /home/devi-orig/.gnome2_private: Keine Berechtigung
    devi@31: find: /home/devi-orig/.nautilus/metafiles: Keine Berechtigung
    devi@31: find: /home/devi-orig/.metacity: Keine Berechtigung
    devi@31: find: /home/devi-orig/.inkscape: Keine Berechtigung
    devi@31: ^C
    devi@31: 
    devi@31:
    devi@31:
    devi@31:

  • devi@31:
  • devi@31: Команды, выполненные с привилегиями суперпользователя, devi@31: выделяются слева красной чертой. devi@31: devi@31: devi@31: devi@31: devi@31:
    devi@31:
    devi@31: # id
    devi@31:
    devi@31: uid=0(root) gid=0(root) Gruppen=0(root)
    devi@31: 
    devi@31:
    devi@31:
    devi@31:

  • devi@31:
  • devi@31: Изменения, внесённые в текстовый файл с помощью редактора, devi@31: запоминаются и показываются в журнале в формате ed. devi@31: Строки, начинающиеся символом "<", удалены, а строки, devi@31: начинающиеся символом ">" -- добавлены. devi@31: devi@31: devi@31: devi@31: devi@31:
    devi@31:
    devi@31: \$ vi ~/.bashrc
    devi@31:
    2a3,5
    devi@31: > 	if [ -f /usr/local/etc/bash_completion ]; then
    devi@31: >         . /usr/local/etc/bash_completion
    devi@31: >     	fi
    devi@31: 
    devi@31:
    devi@31:

  • devi@31:
  • devi@31: Для того чтобы получить краткую справочную информацию о команде, devi@31: нужно подвести к ней мышь. Во всплывающей подсказке появится краткое devi@31: описание команды. devi@31:

  • devi@31:
  • devi@31: Время ввода команды, показанное в журнале, соответствует времени devi@31: начала ввода командной строки, которое равно тому моменту, devi@31: когда на терминале появилось приглашение интерпретатора devi@31:

  • devi@31:
  • devi@31: Имя терминала, на котором была введена команда, показано в специальном блоке. devi@31: Этот блок показывается только в том случае, если терминал devi@31: текущей команды отличается от терминала предыдущей. devi@31:

  • devi@31:
  • devi@31: Вывод не интересующих вас в настоящий момент элементов журнала, devi@31: таких как время, имя терминала и других, можно отключить. devi@31: Для этого нужно воспользоваться формой управления журналом devi@31: вверху страницы. devi@31:

  • devi@31:
  • devi@31: Небольшие комментарии к командам можно вставлять прямо из командной строки. devi@31: Комментарий вводится прямо в командную строку, после символов #^ или #v. devi@31: Символы ^ и v показывают направление выбора команды, к которой относится комментарий: devi@31: ^ - к предыдущей, v - к следующей. devi@31: Например, если в командной строке было введено: devi@31:

    devi@31: \$ whoami
    devi@31: 
    devi@31:
    devi@31: user
    devi@31: 
    devi@31:
    devi@31: \$ #^ Интересно, кто я?
    devi@31: 
    devi@31: в журнале это будет выглядеть так: devi@31: devi@31:
    devi@31: \$ whoami
    devi@31: 
    devi@31:
    devi@31: user
    devi@31: 
    devi@31:
    devi@31:
    Интересно, кто я?
    devi@31:

  • devi@31:
  • devi@31: Если комментарий содержит несколько строк, devi@31: его можно вставить в журнал следующим образом: devi@31:

    devi@31: \$ whoami
    devi@31: 
    devi@31:
    devi@31: user
    devi@31: 
    devi@31:
    devi@31: \$ cat > /dev/null #^ Интересно, кто я?
    devi@31: 
    devi@31:
    devi@31: Программа whoami выводит имя пользователя, под которым 
    devi@31: мы зарегистрировались в системе.
    devi@31: -
    devi@31: Она не может ответить на вопрос о нашем назначении 
    devi@31: в этом мире.
    devi@31: 
    devi@31: В журнале это будет выглядеть так: devi@31: devi@31: devi@31: devi@31: devi@31:
    devi@31:
    devi@31: \$ whoami
    devi@31:
    user
    devi@31: 
    devi@31:
    Интересно, кто я?
    devi@31: Программа whoami выводит имя пользователя, под которым
    devi@31: мы зарегистрировались в системе.
    devi@31:
    devi@31: Она не может ответить на вопрос о нашем назначении
    devi@31: в этом мире.
    devi@31:
    devi@31:
    devi@31: Для разделения нескольких абзацев между собой devi@31: используйте символ "-", один в строке. devi@31:
    devi@31:

  • devi@31:
  • devi@31: Комментарии, не относящиеся непосредственно ни к какой из команд, devi@31: добавляются точно таким же способом, только вместо симолов #^ или #v devi@31: нужно использовать символы #= devi@31:

  • devi@31: devi@23: HELP devi@23: devi@23: $Html_About = < devi@23: LiLaLo (L3) расшифровывается как Live Lab Log.
    devi@29: Программа разработана для повышения эффективности обучения Unix/Linux-системам.
    devi@23: (c) Игорь Чубин, 2004-2005
    devi@23:

    devi@23: ABOUT devi@23: $Html_About.='$Id$

    '; devi@23: devi@23: $Html_JavaScript = <0) devi@23: subelems[j].style.display = "none"; devi@23: else devi@23: subelems[j].style.display = ""; devi@23: devi@23: } devi@23: devi@23: } devi@23: } devi@23: devi@23: } devi@23: JS devi@23: devi@23: %Search_Machines = ( devi@23: "google" => { "query" => "http://www.google.com/search?q=" , devi@28: "icon" => "$Config{frontend_google_ico}" }, devi@23: "freebsd" => { "query" => "http://www.freebsd.org/cgi/man.cgi?query=", devi@28: "icon" => "$Config{frontend_freebsd_ico}" }, devi@23: "linux" => { "query" => "http://man.he.net/?topic=", devi@28: "icon" => "$Config{frontend_linux_ico}"}, devi@23: "opennet" => { "query" => "http://www.opennet.ru/search.shtml?words=", devi@28: "icon" => "$Config{frontend_opennet_ico}"}, devi@23: "local" => { "query" => "http://www.freebsd.org/cgi/man.cgi?query=", devi@28: "icon" => "$Config{frontend_local_ico}" }, devi@23: devi@23: ); devi@23: devi@23: %Elements_Visibility = ( devi@23: "note" => "замечания", devi@23: "diff" => "редактор", devi@23: "time" => "время", devi@23: "ttychange" => "терминал", devi@23: "wrong_output wrong_cline wrong_root_output wrong_root_cline" devi@23: => "команды с ошибками", devi@23: "interrupted_output interrupted_cline interrupted_root_output interrupted_root_cline" devi@23: => "прерванные команды", devi@23: "tab_completion_output tab_completion_cline" devi@23: => "продолжение с помощью tab" devi@23: ); devi@23: devi@23: @Day_Name = qw/ Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота /; devi@23: @Month_Name = qw/ Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь /; devi@23: @Of_Month_Name = qw/ Января Февраля Марта Апреля Мая Июня Июля Августа Сентября Октября Ноября Декабря /; devi@23: } devi@23: