lilalo
annotate lm-report @ 3:6c1d2b9f45e7
Добавил команду lm report.
Строит html-представление журналов
для заданного класса.
Нужно сделать поддержку опций GetOpt::Long
и тогда эту же команду можно будет использовать
для построения всех журналов в репозитории.
Строит html-представление журналов
для заданного класса.
Нужно сделать поддержку опций GetOpt::Long
и тогда эту же команду можно будет использовать
для построения всех журналов в репозитории.
author | devi |
---|---|
date | Tue May 24 13:00:28 2005 +0300 (2005-05-24) |
parents | |
children | a0f30dd46d1a |
rev | line source |
---|---|
devi@0 | 1 #!/usr/bin/perl -w |
devi@0 | 2 |
devi@0 | 3 # |
devi@0 | 4 # (c) Igor Chubin, imchubin@mail.ru, 2004 |
devi@0 | 5 # |
devi@0 | 6 |
devi@0 | 7 use strict; |
devi@0 | 8 use Getopt::Long; |
devi@0 | 9 use Term::VT102; |
devi@0 | 10 use Text::Iconv; |
devi@0 | 11 use Data::Dumper; |
devi@0 | 12 |
devi@0 | 13 our $Config_File = "labmaker.conf"; |
devi@0 | 14 our %Config = ( |
devi@0 | 15 "skip_empty" => "yes", |
devi@0 | 16 "skip_interrupted" => "no", |
devi@0 | 17 "skip_wrong" => "no", |
devi@0 | 18 "editors" => ["vi", "pico", "ee", "vim"], |
devi@0 | 19 "pagers" => ["more", "less", "zmore", "zless", "info", |
devi@0 | 20 "man", "mc", "trafshow", "screen", "cfdisk", |
devi@0 | 21 "trafshow-bsd", "yes", "lynx", "links", "centericq" |
devi@0 | 22 ], |
devi@0 | 23 "terminal" => ["mc"], |
devi@0 | 24 "suppress_editors" => "yes", |
devi@0 | 25 "suppress_pagers" => "yes", |
devi@0 | 26 "suppress_terminal" => "yes", |
devi@0 | 27 |
devi@0 | 28 "terminal_width" => 100, |
devi@0 | 29 "terminal_height" => 100, |
devi@0 | 30 "verbose" => "yes", |
devi@0 | 31 |
devi@0 | 32 "head_lines" => 5, |
devi@0 | 33 "tail_lines" => 5, |
devi@0 | 34 "skip_text" => "...", |
devi@0 | 35 "show_time" => "yes", |
devi@0 | 36 "show_diffs" => "yes", |
devi@0 | 37 "show_comments" => "yes", |
devi@0 | 38 |
devi@0 | 39 "input" => "/root/.labmaker", |
devi@0 | 40 "diffs" => "", |
devi@0 | 41 "input_mask" => "*.script", |
devi@0 | 42 "encoding" => "utf-8", |
devi@0 | 43 |
devi@0 | 44 "output" => "/var/www/lm/reportINDEX.html", |
devi@0 | 45 #"output" => "report.xml", |
devi@0 | 46 "output_mask" => "INDEX", |
devi@0 | 47 "output_format" => "html", |
devi@0 | 48 |
devi@0 | 49 "signature" => "#lm:", |
devi@0 | 50 "from" => "", |
devi@0 | 51 "to" => "", |
devi@0 | 52 "lab" => "", |
devi@0 | 53 "keywords" => "linux command", |
devi@0 | 54 "files_keywords" => "linux file", |
devi@0 | 55 |
devi@0 | 56 comment_width => "300", |
devi@0 | 57 time_width => "60", |
devi@0 | 58 |
devi@0 | 59 ); |
devi@0 | 60 |
devi@0 | 61 our @Command_Lines; |
devi@0 | 62 our @Command_Lines_Index; |
devi@0 | 63 our @Diffs; |
devi@0 | 64 |
devi@0 | 65 our %Commands_Stat; # Statistics about commands usage |
devi@0 | 66 our %Files_Stat; # Statistics about commands usage |
devi@0 | 67 |
devi@0 | 68 our %Search_Machines = ( |
devi@0 | 69 "google" => { "query" => "http://www.google.com/search?q=" , |
devi@0 | 70 "icon" => "google.ico" }, |
devi@0 | 71 "freebsd" => { "query" => "http://www.freebsd.org/cgi/man.cgi?query=", |
devi@0 | 72 "icon" => "freebsd.ico" }, |
devi@0 | 73 "linux" => { "query" => "http://man.he.net/?topic=", |
devi@0 | 74 "icon" => "linux.ico"}, |
devi@0 | 75 "opennet" => { "query" => "http://www.opennet.ru/search.shtml?words=", |
devi@0 | 76 "icon" => "opennet.ico"}, |
devi@0 | 77 "local" => { "query" => "http://www.freebsd.org/cgi/man.cgi?query=", |
devi@0 | 78 "icon" => "freebsd.ico" }, |
devi@0 | 79 |
devi@0 | 80 ); |
devi@0 | 81 |
devi@0 | 82 our %Elements_Visibility = ( |
devi@0 | 83 "note" => "замечания", |
devi@0 | 84 "diff" => "редактор", |
devi@0 | 85 "time" => "время", |
devi@0 | 86 "ttychange" => "терминал", |
devi@0 | 87 "wrong_output wrong_cline wrong_root_output wrong_root_cline" |
devi@0 | 88 => "команды с ошибками", |
devi@0 | 89 "interrupted_output interrupted_cline interrupted_root_output interrupted_root_cline" |
devi@0 | 90 => "прерванные команды", |
devi@0 | 91 "tab_completion_output tab_completion_cline" |
devi@0 | 92 => "продолжение с помощью tab" |
devi@0 | 93 ); |
devi@0 | 94 |
devi@0 | 95 |
devi@0 | 96 sub load_diff_files |
devi@0 | 97 { |
devi@0 | 98 my @pathes = @_; |
devi@0 | 99 |
devi@0 | 100 for my $path (@pathes) { |
devi@0 | 101 my $template = "*.diff"; |
devi@0 | 102 my @files = <$path/$template>; |
devi@0 | 103 my $i=0; |
devi@0 | 104 for my $file (@files) { |
devi@0 | 105 my %diff; |
devi@0 | 106 |
devi@0 | 107 $diff{"path"}=$path; |
devi@0 | 108 $diff{"uid"}="SET THIS"; |
devi@0 | 109 |
devi@0 | 110 # Сейчас UID определяется из названия каталога |
devi@0 | 111 # откуда берутся diff-файлы |
devi@0 | 112 # Это неправильно |
devi@0 | 113 # |
devi@0 | 114 # ВАРИАНТ: |
devi@0 | 115 # К файлам жураналам должны прилагаться ситемны файлы, |
devi@0 | 116 # мз которых и будет определяться соответствие |
devi@0 | 117 # имён пользователей их uid'ам |
devi@0 | 118 # |
devi@0 | 119 $diff{"uid"} = 0 if $path =~ m@/root/@; |
devi@0 | 120 |
devi@0 | 121 $diff{"bind_to"}=""; |
devi@0 | 122 $diff{"time_range"}=-1; |
devi@0 | 123 |
devi@0 | 124 next if not $file=~m@/(D?[0-9][0-9]?[0-9]?)[^/]*?([0-9]*):([0-9]*):?([0-9]*)@; |
devi@0 | 125 $diff{"day"}=$1 || ""; |
devi@0 | 126 $diff{"hour"}=$2; |
devi@0 | 127 $diff{"min"}=$3; |
devi@0 | 128 $diff{"sec"}=$4 || 0; |
devi@0 | 129 |
devi@0 | 130 $diff{"index"}=$i; |
devi@0 | 131 |
devi@0 | 132 print "diff loaded: $diff{day} $diff{hour}:$diff{min}:$diff{sec}\n"; |
devi@0 | 133 |
devi@0 | 134 local $/; |
devi@0 | 135 open (F, "$file") |
devi@0 | 136 or return "Can't open file $file ($_[0]) for reading"; |
devi@0 | 137 my $text = <F>; |
devi@0 | 138 if ($Config{"encoding"} && $Config{"encoding"} !~ /^utf-8$/i) { |
devi@0 | 139 my $converter = Text::Iconv->new($Config{"encoding"}, "utf-8"); |
devi@0 | 140 $text = $converter->convert($text); |
devi@0 | 141 } |
devi@0 | 142 close(F); |
devi@0 | 143 $diff{"text"}=$text; |
devi@0 | 144 #print "$file loaded ($diff{day})\n"; |
devi@0 | 145 |
devi@0 | 146 push @Diffs, \%diff; |
devi@0 | 147 $i++; |
devi@0 | 148 } |
devi@0 | 149 } |
devi@0 | 150 } |
devi@0 | 151 |
devi@0 | 152 |
devi@0 | 153 sub bind_diff |
devi@0 | 154 { |
devi@0 | 155 # my $path = shift; |
devi@0 | 156 # my $pid = shift; |
devi@0 | 157 # my $day = shift; |
devi@0 | 158 # my $lab = shift; |
devi@0 | 159 |
devi@0 | 160 print "Trying to bind diff...\n"; |
devi@0 | 161 |
devi@0 | 162 my $cl = shift; |
devi@0 | 163 my $hour = $cl->{"hour"}; |
devi@0 | 164 my $min = $cl->{"min"}; |
devi@0 | 165 my $sec = $cl->{"sec"}; |
devi@0 | 166 |
devi@0 | 167 my $min_dt = 10000; |
devi@0 | 168 |
devi@0 | 169 for my $diff (@Diffs) { |
devi@0 | 170 # Check here date, time and user |
devi@0 | 171 next if ($diff->{"day"} && $cl->{"day"} && ($cl->{"day"} ne $diff->{"day"})); |
devi@0 | 172 #next if (!$diff->{"uid"} && $cl->{"euid"} != $diff->{"uid"}); |
devi@0 | 173 |
devi@0 | 174 my $dt=($diff->{"hour"}-$hour)*3600 +($diff->{"min"}-$min)*60 + ($diff->{"sec"}-$sec); |
devi@0 | 175 if ($dt >0 && $dt < $min_dt && ($diff->{"time_range"} <0 || $dt < $diff->{"time_range"})) { |
devi@0 | 176 print "Approppriate diff found: dt=$dt\n"; |
devi@0 | 177 if ($diff->{"bind_to"}) { |
devi@0 | 178 undef $diff->{"bind_to"}->{"diff"}; |
devi@0 | 179 }; |
devi@0 | 180 $diff->{"time_range"}=$dt; |
devi@0 | 181 $diff->{"bind_to"}=$cl; |
devi@0 | 182 |
devi@0 | 183 $cl->{"diff"} = $diff->{"index"}; |
devi@0 | 184 $min_dt = $dt; |
devi@0 | 185 } |
devi@0 | 186 |
devi@0 | 187 } |
devi@0 | 188 } |
devi@0 | 189 |
devi@0 | 190 |
devi@0 | 191 sub extract_from_cline |
devi@0 | 192 # Разобрать командную строку $_[1] и возвратить хэш, содержащий |
devi@0 | 193 # номер первого появление команды в строке: |
devi@0 | 194 # команда => первая позиция |
devi@0 | 195 { |
devi@0 | 196 my $what = $_[0]; |
devi@0 | 197 my $cline = $_[1]; |
devi@0 | 198 my @lists = split /\;/, $cline; |
devi@0 | 199 |
devi@0 | 200 |
devi@0 | 201 my @commands = (); |
devi@0 | 202 for my $list (@lists) { |
devi@0 | 203 push @commands, split /\|/, $list; |
devi@0 | 204 } |
devi@0 | 205 |
devi@0 | 206 my %commands; |
devi@0 | 207 my %files; |
devi@0 | 208 my $i=0; |
devi@0 | 209 for my $command (@commands) { |
devi@0 | 210 $command =~ /\s*(\S+)\s*(.*)/; |
devi@0 | 211 if ($1 && $1 eq "sudo" ) { |
devi@0 | 212 $commands{"$1"}=$i++; |
devi@0 | 213 $command =~ s/\s*sudo\s+//; |
devi@0 | 214 } |
devi@0 | 215 $command =~ /\s*(\S+)\s*(.*)/; |
devi@0 | 216 if ($1 && !defined $commands{"$1"}) { |
devi@0 | 217 $commands{"$1"}=$i++; |
devi@0 | 218 }; |
devi@0 | 219 if ($2) { |
devi@0 | 220 my $args = $2; |
devi@0 | 221 my @args = split (/\s+/, $args); |
devi@0 | 222 for my $a (@args) { |
devi@0 | 223 $files{"$a"}=$i++ |
devi@0 | 224 if !defined $files{"$a"}; |
devi@0 | 225 }; |
devi@0 | 226 |
devi@0 | 227 |
devi@0 | 228 } |
devi@0 | 229 } |
devi@0 | 230 |
devi@0 | 231 if ($what eq "commands") { |
devi@0 | 232 return %commands; |
devi@0 | 233 } else { |
devi@0 | 234 return %files; |
devi@0 | 235 } |
devi@0 | 236 |
devi@0 | 237 } |
devi@0 | 238 |
devi@0 | 239 sub load_command_lines |
devi@0 | 240 { |
devi@0 | 241 my $lab_scripts_path = $_[0]; |
devi@0 | 242 my $lab_scripts_mask = $_[1]; |
devi@0 | 243 |
devi@0 | 244 my $cline_re_base = qq' |
devi@0 | 245 (?:\\^?([0-9]*C?)) # exitcode |
devi@0 | 246 (?:_([0-9]+)_)? # uid |
devi@0 | 247 (?:_([0-9]+)_) # pid |
devi@0 | 248 (...?) # day |
devi@0 | 249 (..) # lab |
devi@0 | 250 \\s # space separator |
devi@0 | 251 ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]) # time |
devi@0 | 252 .\\[50D.\\[K # killing symbols |
devi@0 | 253 (.*?([\$\#]\\s?)) # prompt |
devi@0 | 254 (.*) # command line |
devi@0 | 255 '; |
devi@0 | 256 #my $cline_re = qr/$cline_re_base(?:$cline_re_base|$)/x; |
devi@0 | 257 #my $cline_re = qr/(?:$cline_re_base)*$cline_re_base$/x; |
devi@0 | 258 my $cline_re = qr/$cline_re_base/sx; |
devi@0 | 259 my $cline_re1 = qr/$cline_re_base\x0D/sx; |
devi@0 | 260 my $cline_re2 = qr/$cline_re_base$/sx; |
devi@0 | 261 |
devi@0 | 262 my $vt = Term::VT102->new ( 'cols' => $Config{"terminal_width"}, |
devi@0 | 263 'rows' => $Config{"terminal_height"}); |
devi@0 | 264 my $cline_vt = Term::VT102->new ('cols' => $Config{"terminal_width"}, |
devi@0 | 265 'rows' => $Config{"terminal_height"}); |
devi@0 | 266 |
devi@0 | 267 my $converter = Text::Iconv->new($Config{"encoding"}, "utf-8") |
devi@0 | 268 if ($Config{"encoding"} && $Config{"encoding"} !~ /^utf-8$/i); |
devi@0 | 269 |
devi@0 | 270 print "Loading lm-scripts...\n" if $Config{"verbose"} =~ /y/; |
devi@0 | 271 |
devi@0 | 272 my @lab_scripts = <$lab_scripts_path/$lab_scripts_mask>; |
devi@0 | 273 my $file; |
devi@0 | 274 my $files_number = $#lab_scripts; |
devi@0 | 275 my $ii = 0; |
devi@0 | 276 my $skip_info; |
devi@0 | 277 |
devi@0 | 278 my $commandlines_loaded =0; |
devi@0 | 279 my $commandlines_processed =0; |
devi@0 | 280 |
devi@0 | 281 for $file (@lab_scripts){ |
devi@0 | 282 #printf "\t%i %3.2f\n", $ii, (100*$ii++/$files_number) if $Config{"verbose"} =~ /y/; |
devi@0 | 283 |
devi@0 | 284 open (FILE, "$file"); |
devi@0 | 285 binmode FILE; |
devi@0 | 286 $file =~ m@.*/(.*?)-.*@; |
devi@0 | 287 |
devi@0 | 288 my $tty = $1; |
devi@0 | 289 my $first_pass = 1; |
devi@0 | 290 my %cl; |
devi@0 | 291 my $last_output_length=0; |
devi@0 | 292 while (<FILE>) { |
devi@0 | 293 $commandlines_processed++; |
devi@0 | 294 # time |
devi@0 | 295 |
devi@0 | 296 if (/[0-9][0-9]:[0-9][0-9]:[0-9][0-9].\[[0-9][0-9]D.\[K/ && m/$cline_re/) { |
devi@0 | 297 s/.*\x0d(?!\x0a)//; |
devi@0 | 298 # print "!!!",$_,"!!!\n"; |
devi@0 | 299 # next; |
devi@0 | 300 # while (m/$cline_re1/gs) { |
devi@0 | 301 # } |
devi@0 | 302 m/$cline_re2/gs; |
devi@0 | 303 |
devi@0 | 304 $commandlines_loaded++; |
devi@0 | 305 $last_output_length=0; |
devi@0 | 306 |
devi@0 | 307 # Previous command |
devi@0 | 308 my %last_cl = %cl; |
devi@0 | 309 my $err = $1 || ""; |
devi@0 | 310 |
devi@0 | 311 # Parse new command |
devi@0 | 312 $cl{"uid"} = $2; |
devi@0 | 313 $cl{"euid"} = $cl{"uid"}; # Если в команде обнаружится sudo, euid поменяем на 0 |
devi@0 | 314 $cl{"pid"} = $3; |
devi@0 | 315 $cl{"day"} = $4; |
devi@0 | 316 $cl{"lab"} = $5; |
devi@0 | 317 $cl{"hour"} = $6; |
devi@0 | 318 $cl{"min"} = $7; |
devi@0 | 319 $cl{"sec"} = $8; |
devi@0 | 320 $cl{"fullprompt"} = $9; |
devi@0 | 321 $cl{"prompt"} = $10; |
devi@0 | 322 $cl{"raw_cline"} = $11; |
devi@0 | 323 |
devi@0 | 324 $cl{"err"} = 0; |
devi@0 | 325 $cl{"output"} = ""; |
devi@0 | 326 $cl{"tty"} = $tty; |
devi@0 | 327 |
devi@0 | 328 $cline_vt->process($cl{"raw_cline"}."\n"); |
devi@0 | 329 $cl{"cline"} = $cline_vt->row_plaintext (1); |
devi@0 | 330 $cl{"cline"} =~ s/\s*$//; |
devi@0 | 331 $cline_vt->reset(); |
devi@0 | 332 |
devi@0 | 333 my %commands = extract_from_cline("commands", $cl{"cline"}); |
devi@0 | 334 $cl{"euid"}=0 if defined $commands{"sudo"}; |
devi@0 | 335 my @comms = sort { $commands{$a} cmp $commands{$b} } keys %commands; |
devi@0 | 336 $cl{"last_command"} = $comms[$#comms] || ""; |
devi@0 | 337 |
devi@0 | 338 if ( |
devi@0 | 339 $Config{"suppress_editors"} =~ /^y/i |
devi@0 | 340 && grep ($_ eq $cl{"last_command"}, @{$Config{"editors"}}) || |
devi@0 | 341 $Config{"suppress_pagers"} =~ /^y/i |
devi@0 | 342 && grep ($_ eq $cl{"last_command"}, @{$Config{"pagers"}}) || |
devi@0 | 343 $Config{"suppress_terminal"}=~ /^y/i |
devi@0 | 344 && grep ($_ eq $cl{"last_command"}, @{$Config{"terminal"}}) |
devi@0 | 345 ) { |
devi@0 | 346 $cl{"suppress_output"} = "1"; |
devi@0 | 347 } |
devi@0 | 348 else { |
devi@0 | 349 $cl{"suppress_output"} = "0"; |
devi@0 | 350 |
devi@0 | 351 } |
devi@0 | 352 $skip_info = 0; |
devi@0 | 353 |
devi@0 | 354 |
devi@0 | 355 print " ",$cl{"last_command"}; |
devi@0 | 356 |
devi@0 | 357 # Processing previous command line |
devi@0 | 358 if ($first_pass) { |
devi@0 | 359 $first_pass = 0; |
devi@0 | 360 next; |
devi@0 | 361 } |
devi@0 | 362 |
devi@0 | 363 # Error code |
devi@0 | 364 $last_cl{"err"}=$err; |
devi@0 | 365 $last_cl{"err"}=130 if $err eq "^C"; |
devi@0 | 366 |
devi@0 | 367 if (grep ($_ eq $last_cl{"last_command"}, @{$Config{"editors"}})) { |
devi@0 | 368 bind_diff(\%last_cl); |
devi@0 | 369 } |
devi@0 | 370 |
devi@0 | 371 # Output |
devi@0 | 372 if (!$last_cl{"suppress_output"} || $last_cl{"err"}) { |
devi@0 | 373 for (my $i=0; $i<$Config{"terminal_height"}; $i++) { |
devi@0 | 374 my $line= $vt->row_plaintext($i); |
devi@0 | 375 next if !defined ($line) || $line =~ /^\s*$/; |
devi@0 | 376 $line =~ s/\s*$//; |
devi@0 | 377 $last_cl{"output"} .= $line."\n"; |
devi@0 | 378 } |
devi@0 | 379 } |
devi@0 | 380 else { |
devi@0 | 381 $last_cl{"output"}= ""; |
devi@0 | 382 } |
devi@0 | 383 |
devi@0 | 384 $vt->reset(); |
devi@0 | 385 |
devi@0 | 386 |
devi@0 | 387 # Classifying the command line |
devi@0 | 388 |
devi@0 | 389 |
devi@0 | 390 # Save |
devi@0 | 391 if (!$Config{"lab"} || $cl{"lab"} eq $Config{"lab"}) { |
devi@0 | 392 # Changing encoding |
devi@0 | 393 for (keys %last_cl) { |
devi@0 | 394 $last_cl{$_} = $converter->convert($last_cl{$_}) |
devi@0 | 395 if ($Config{"encoding"} && |
devi@0 | 396 $Config{"encoding"} !~ /^utf-8$/i); |
devi@0 | 397 } |
devi@0 | 398 push @Command_Lines, \%last_cl; |
devi@0 | 399 } |
devi@0 | 400 next; |
devi@0 | 401 } |
devi@0 | 402 $last_output_length+=length($_); |
devi@0 | 403 #if (!$cl{"suppress_output"} || $last_output_length < 5000) { |
devi@0 | 404 if ($last_output_length < 5000) { |
devi@0 | 405 #print "(",length($_),")" if (length($_) > 2000) ; |
devi@0 | 406 $vt->process("$_"."\n") |
devi@0 | 407 } |
devi@0 | 408 else |
devi@0 | 409 { |
devi@0 | 410 if (!$skip_info) { |
devi@0 | 411 print "($cl{last_command})"; |
devi@0 | 412 $skip_info = 1; |
devi@0 | 413 } |
devi@0 | 414 } |
devi@0 | 415 } |
devi@0 | 416 close(FILE); |
devi@0 | 417 |
devi@0 | 418 } |
devi@0 | 419 if ($Config{"verbose"} =~ /y/) { |
devi@0 | 420 print "...finished." ; |
devi@0 | 421 print "Lines loaded: $commandlines_processed\n"; |
devi@0 | 422 print "Command lines: $commandlines_loaded\n"; |
devi@0 | 423 } |
devi@0 | 424 } |
devi@0 | 425 |
devi@0 | 426 sub search_by |
devi@0 | 427 { |
devi@0 | 428 my $sm = shift; |
devi@0 | 429 my $topic = shift; |
devi@0 | 430 $topic =~ s/ /+/; |
devi@0 | 431 |
devi@0 | 432 return "<a href='". $Search_Machines{$sm}->{"query"}."$topic'><img width='16' height='16' src='". |
devi@0 | 433 $Search_Machines{$sm}->{"icon"}."' border='0'/></a>"; |
devi@0 | 434 } |
devi@0 | 435 |
devi@0 | 436 sub make_comment |
devi@0 | 437 { |
devi@0 | 438 my $commands = $_[0]; |
devi@0 | 439 my $files = $_[1]; |
devi@0 | 440 chomp $commands; |
devi@0 | 441 chomp $files; |
devi@0 | 442 return if (!$commands && !$files); |
devi@0 | 443 |
devi@0 | 444 my $comment=""; |
devi@0 | 445 |
devi@0 | 446 # Commands |
devi@0 | 447 for my $command (split /\s+/,$commands) { |
devi@0 | 448 $command =~ s/'//g; |
devi@0 | 449 my $description=""; |
devi@0 | 450 eval { $description=`mywi-client '$command'`; } ; |
devi@0 | 451 $description = join ("<br>\n", grep(/\([18]\)/, split(/\n/, $description))); |
devi@0 | 452 $description =~ s/.*?-//; |
devi@0 | 453 next if $description =~ /^\s*$/; |
devi@0 | 454 |
devi@0 | 455 my $query=$command." ".$Config{"keywords"}; |
devi@0 | 456 $query =~ s/\ /+/g; |
devi@0 | 457 my $search= search_by("opennet",$query). |
devi@0 | 458 search_by("local",$command). |
devi@0 | 459 search_by("google",$query); |
devi@0 | 460 |
devi@0 | 461 $comment .= "<tr><td class='note_title'>$command</td>". |
devi@0 | 462 "<td class='note_search'>$search</td>". |
devi@0 | 463 "</tr><tr><td width='100%' colspan='2' class='note_text'>". |
devi@0 | 464 "$description</td></tr><tr/>"; |
devi@0 | 465 } |
devi@0 | 466 |
devi@0 | 467 # Files |
devi@0 | 468 for my $file (split /\s+/,$files) { |
devi@0 | 469 $file =~ s@.*/@@; |
devi@0 | 470 $file =~ s/'//g; |
devi@0 | 471 next if $file =~ /^\s*$/; |
devi@0 | 472 next if $file =~ /^-/; |
devi@0 | 473 |
devi@0 | 474 my $description=`mywi '$file'`; |
devi@0 | 475 $description = join ("<br>\n", grep(/\(5\)/, split(/\n/, $description))); |
devi@0 | 476 next if $description =~ /^\s*$/; |
devi@0 | 477 |
devi@0 | 478 my $query=$file." ".$Config{"files_keywords"}; |
devi@0 | 479 $query =~ s/\ /+/g; |
devi@0 | 480 my $search= search_by("opennet",$query). |
devi@0 | 481 search_by("local",$file). |
devi@0 | 482 search_by("google",$query); |
devi@0 | 483 |
devi@0 | 484 $comment .= "<tr><td class='note_title'>$file</td>". |
devi@0 | 485 "<td class='note_search'>$search</td>". |
devi@0 | 486 "</tr><tr><td width='100%' colspan='2' class='note_text'>". |
devi@0 | 487 "$description</td></tr><tr/>"; |
devi@0 | 488 } |
devi@0 | 489 |
devi@0 | 490 |
devi@0 | 491 return $comment; |
devi@0 | 492 } |
devi@0 | 493 |
devi@0 | 494 sub printq |
devi@0 | 495 { |
devi@0 | 496 my $TO = shift; |
devi@0 | 497 my $text = join "", @_; |
devi@0 | 498 $text =~ s/&/&/g; |
devi@0 | 499 $text =~ s/</</g; |
devi@0 | 500 $text =~ s/>/>/g; |
devi@0 | 501 print $TO $text; |
devi@0 | 502 } |
devi@0 | 503 |
devi@0 | 504 |
devi@0 | 505 sub sort_command_lines |
devi@0 | 506 { |
devi@0 | 507 print "Sorting command lines...\n" if $Config{"verbose"} =~ /y/; |
devi@0 | 508 |
devi@0 | 509 # Sort Command_Lines |
devi@0 | 510 # Write Command_Lines to Command_Lines_Index |
devi@0 | 511 |
devi@0 | 512 my @index; |
devi@0 | 513 for (my $i=0;$i<=$#Command_Lines;$i++) { |
devi@0 | 514 $index[$i]=$i; |
devi@0 | 515 } |
devi@0 | 516 |
devi@0 | 517 @Command_Lines_Index = sort { |
devi@0 | 518 $Command_Lines[$index[$a]]->{"day"} cmp $Command_Lines[$index[$b]]->{"day"} || |
devi@0 | 519 $Command_Lines[$index[$a]]->{"hour"} <=> $Command_Lines[$index[$b]]->{"hour"} || |
devi@0 | 520 $Command_Lines[$index[$a]]->{"min"} <=> $Command_Lines[$index[$b]]->{"min"} || |
devi@0 | 521 $Command_Lines[$index[$a]]->{"sec"} <=> $Command_Lines[$index[$b]]->{"sec"} |
devi@0 | 522 } @index; |
devi@0 | 523 |
devi@0 | 524 print "...finished\n" if $Config{"verbose"} =~ /y/; |
devi@0 | 525 |
devi@0 | 526 } |
devi@0 | 527 |
devi@0 | 528 sub process_command_lines |
devi@0 | 529 { |
devi@0 | 530 my $lab_scripts_path = $_[0]; |
devi@0 | 531 |
devi@0 | 532 for my $i (@Command_Lines_Index) { |
devi@0 | 533 |
devi@0 | 534 my $cl = \$Command_Lines[$i]; |
devi@0 | 535 @{${$cl}->{"new_commands"}} =(); |
devi@0 | 536 @{${$cl}->{"new_files"}} =(); |
devi@0 | 537 $$cl->{"class"} = ""; |
devi@0 | 538 |
devi@0 | 539 if ($$cl->{"err"}) { |
devi@0 | 540 $$cl->{"class"}="wrong"; |
devi@0 | 541 $$cl->{"class"}="interrupted" |
devi@0 | 542 if ($$cl->{"err"} eq 130); |
devi@0 | 543 } |
devi@0 | 544 if (!$$cl->{"euid"}) { |
devi@0 | 545 $$cl->{"class"}.="_root"; |
devi@0 | 546 } |
devi@0 | 547 |
devi@0 | 548 #tab# my @tab_words=split /\s+/, $$cl->{"output"}; |
devi@0 | 549 #tab# my $last_word= $$cl->{"cline"} =~ /(\S*)$/; |
devi@0 | 550 #tab# $last_word =~ s@.*/@@; |
devi@0 | 551 #tab# my $this_is_tab=1; |
devi@0 | 552 #tab# |
devi@0 | 553 #tab# if ($last_word && @tab_words >2) { |
devi@0 | 554 #tab# for my $tab_words (@tab_words) { |
devi@0 | 555 #tab# if ($tab_words !~ /^$last_word/) { |
devi@0 | 556 #tab# $this_is_tab=0; |
devi@0 | 557 #tab# last; |
devi@0 | 558 #tab# } |
devi@0 | 559 #tab# } |
devi@0 | 560 #tab# } |
devi@0 | 561 #tab# $$cl->{"class"}="tab" if $this_is_tab; |
devi@0 | 562 |
devi@0 | 563 |
devi@0 | 564 if ( !$$cl->{"err"}) { |
devi@0 | 565 # Command does not contain mistakes |
devi@0 | 566 |
devi@0 | 567 my %commands = extract_from_cline("commands", ${$cl}->{"cline"}); |
devi@0 | 568 my %files = extract_from_cline("files", ${$cl}->{"cline"}); |
devi@0 | 569 |
devi@0 | 570 # Searching for new commands only |
devi@0 | 571 for my $command (keys %commands) { |
devi@0 | 572 if (!defined $Commands_Stat{$command}) { |
devi@0 | 573 push @{$$cl->{new_commands}}, $command; |
devi@0 | 574 } |
devi@0 | 575 $Commands_Stat{$command}++; |
devi@0 | 576 } |
devi@0 | 577 |
devi@0 | 578 for my $file (keys %files) { |
devi@0 | 579 if (!defined $Files_Stat{$file}) { |
devi@0 | 580 push @{$$cl->{new_files}}, $file; |
devi@0 | 581 } |
devi@0 | 582 $Files_Stat{$file}++; |
devi@0 | 583 } |
devi@0 | 584 } |
devi@0 | 585 } |
devi@0 | 586 |
devi@0 | 587 } |
devi@0 | 588 |
devi@0 | 589 sub print_command_lines |
devi@0 | 590 { |
devi@0 | 591 my $output_filename=$_[0]; |
devi@0 | 592 my $format = $Config{"output_format"}; |
devi@0 | 593 |
devi@0 | 594 open(OUT, ">", $output_filename) |
devi@0 | 595 or die "Can't open $output_filename for writing\n"; |
devi@0 | 596 |
devi@0 | 597 |
devi@0 | 598 |
devi@0 | 599 if ($format eq "html") { |
devi@0 | 600 # vvvv HTML Header |
devi@0 | 601 print OUT <<HEADER; |
devi@0 | 602 <html> |
devi@0 | 603 <head> |
devi@0 | 604 <meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> |
devi@0 | 605 <link rel='stylesheet' href='labmaker.css' type='text/css'/> |
devi@0 | 606 </head> |
devi@0 | 607 <body> |
devi@0 | 608 <script> |
devi@0 | 609 function getElementsByClassName(Class_Name) |
devi@0 | 610 { |
devi@0 | 611 var Result=new Array(); |
devi@0 | 612 var All_Elements=document.all || document.getElementsByTagName('*'); |
devi@0 | 613 for (i=0; i<All_Elements.length; i++) |
devi@0 | 614 if (All_Elements[i].className==Class_Name) |
devi@0 | 615 Result.push(All_Elements[i]); |
devi@0 | 616 return Result; |
devi@0 | 617 } |
devi@0 | 618 function ShowHide (name) |
devi@0 | 619 { |
devi@0 | 620 elements=getElementsByClassName(name); |
devi@0 | 621 for(i=0; i<elements.length; i++) |
devi@0 | 622 if (elements[i].style.display == "none") |
devi@0 | 623 elements[i].style.display = ""; |
devi@0 | 624 else |
devi@0 | 625 elements[i].style.display = "none"; |
devi@0 | 626 //if (elements[i].style.visibility == "hidden") |
devi@0 | 627 // elements[i].style.visibility = "visible"; |
devi@0 | 628 //else |
devi@0 | 629 // elements[i].style.visibility = "hidden"; |
devi@0 | 630 } |
devi@0 | 631 function filter_by_output(text) |
devi@0 | 632 { |
devi@0 | 633 |
devi@0 | 634 var jjj=0; |
devi@0 | 635 |
devi@0 | 636 elements=getElementsByClassName('command'); |
devi@0 | 637 for(i=0; i<elements.length; i++) { |
devi@0 | 638 subelems = elements[i].getElementsByTagName('pre'); |
devi@0 | 639 for(j=0; j<subelems.length; j++) { |
devi@0 | 640 if (subelems[j].className = 'output') { |
devi@0 | 641 var str = new String(subelems[j].nodeValue); |
devi@0 | 642 if (jjj != 1) { |
devi@0 | 643 alert(str); |
devi@0 | 644 jjj=1; |
devi@0 | 645 } |
devi@0 | 646 if (str.indexOf(text) >0) |
devi@0 | 647 subelems[j].style.display = "none"; |
devi@0 | 648 else |
devi@0 | 649 subelems[j].style.display = ""; |
devi@0 | 650 |
devi@0 | 651 } |
devi@0 | 652 |
devi@0 | 653 } |
devi@0 | 654 } |
devi@0 | 655 |
devi@0 | 656 } |
devi@0 | 657 </script> |
devi@0 | 658 HEADER |
devi@0 | 659 print OUT "<table class='visibility_form'><tr><td><form>\n"; |
devi@0 | 660 for my $element (keys %Elements_Visibility) |
devi@0 | 661 { |
devi@0 | 662 my @e = split /\s+/, $element; |
devi@0 | 663 my $showhide = join "", map { "ShowHide('$_');" } @e ; |
devi@0 | 664 print OUT "<input type='checkbox' name='$e[0]' onclick=\"$showhide\" checked>", |
devi@0 | 665 $Elements_Visibility{$element}, |
devi@0 | 666 "</input><br>\n"; |
devi@0 | 667 } |
devi@0 | 668 #print OUT "<input type='text' size='10' name=\"by_command\"/>". |
devi@0 | 669 #"<input type='button' value='фильтр по командам' onclick=\"filter_by_command()\"/> <br>\n"; |
devi@0 | 670 #print OUT "<input type='text' size='10' name=\"by_output\"/>". |
devi@0 | 671 #"<input type='button' value='фильтр по результату' ". |
devi@0 | 672 #"onclick=\"filter_by_output(this.form.by_output.value)\"/> <br>\n"; |
devi@0 | 673 |
devi@0 | 674 print OUT "</form></td></tr></table>\n"; |
devi@0 | 675 print OUT "<table width='100%'>\n"; |
devi@0 | 676 # ^^^^ HTML Header |
devi@0 | 677 } |
devi@0 | 678 else { |
devi@0 | 679 # XML Header |
devi@0 | 680 print OUT "<script>\n" |
devi@0 | 681 } |
devi@0 | 682 |
devi@0 | 683 my $cl; |
devi@0 | 684 my $last_tty=""; |
devi@0 | 685 my $in_range=0; |
devi@0 | 686 for my $i (@Command_Lines_Index) { |
devi@0 | 687 |
devi@0 | 688 $cl = $Command_Lines[$i]; |
devi@0 | 689 |
devi@0 | 690 if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) { |
devi@0 | 691 $in_range=1; |
devi@0 | 692 next; |
devi@0 | 693 } |
devi@0 | 694 if ($Config{"to"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"to"}/) { |
devi@0 | 695 $in_range=0; |
devi@0 | 696 next; |
devi@0 | 697 } |
devi@0 | 698 next if ($Config{"from"} && $Config{"to"} && !$in_range) |
devi@0 | 699 || |
devi@0 | 700 ($Config{"skip_empty"} =~ /^y/i && $cl->{"cline"} =~ /^\s*$/ ) |
devi@0 | 701 || |
devi@0 | 702 ($Config{"skip_wrong"} =~ /^y/i && $cl->{"err"} != 0) |
devi@0 | 703 || |
devi@0 | 704 ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130); |
devi@0 | 705 |
devi@0 | 706 my @new_commands=@{$cl->{"new_commands"}}; |
devi@0 | 707 my @new_files=@{$cl->{"new_files"}}; |
devi@0 | 708 |
devi@0 | 709 my $cl_class="cline"; |
devi@0 | 710 my $out_class="output"; |
devi@0 | 711 if ($cl->{"class"}) { |
devi@0 | 712 $cl_class = $cl->{"class"}."_".$cl_class; |
devi@0 | 713 $out_class = $cl->{"class"}."_".$out_class; |
devi@0 | 714 } |
devi@0 | 715 |
devi@0 | 716 my $output=""; |
devi@0 | 717 if ($Config{"head_lines"} || $Config{"tail_lines"}) { |
devi@0 | 718 # Partialy output |
devi@0 | 719 my @lines = split '\n', $cl->{"output"}; |
devi@0 | 720 # head |
devi@0 | 721 my $mark=1; |
devi@0 | 722 for (my $i=0; $i<= $#lines && $i < $Config{"head_lines"}; $i++) { |
devi@0 | 723 $output .= $lines[$i]."\n"; |
devi@0 | 724 } |
devi@0 | 725 # tail |
devi@0 | 726 my $start=$#lines-$Config{"tail_lines"}+1; |
devi@0 | 727 if ($start < 0) { |
devi@0 | 728 $start=0; |
devi@0 | 729 $mark=0; |
devi@0 | 730 } |
devi@0 | 731 if ($start < $Config{"head_lines"}) { |
devi@0 | 732 $start=$Config{"head_lines"}; |
devi@0 | 733 $mark=0; |
devi@0 | 734 } |
devi@0 | 735 $output .= $Config{"skip_text"}."\n" if $mark; |
devi@0 | 736 for (my $i=$start; $i<= $#lines; $i++) { |
devi@0 | 737 $output .= $lines[$i]."\n"; |
devi@0 | 738 } |
devi@0 | 739 } |
devi@0 | 740 else { |
devi@0 | 741 # Full output |
devi@0 | 742 $output .= $cl->{"output"}; |
devi@0 | 743 } |
devi@0 | 744 $output .= "^C\n" if ($cl->{"err"} eq "130"); |
devi@0 | 745 |
devi@0 | 746 |
devi@0 | 747 # Printing out |
devi@0 | 748 |
devi@0 | 749 # <command> |
devi@0 | 750 print OUT $format eq "html" |
devi@0 | 751 ? "<tr class='command'>\n" |
devi@0 | 752 : "\n<action time='$cl->{hour}:$cl->{min}:$cl->{sec}' tty='$cl->{tty}'>\n"; |
devi@0 | 753 |
devi@0 | 754 |
devi@0 | 755 if ($format eq "html") { |
devi@0 | 756 # CONSOLE CHANGE |
devi@0 | 757 if ( $last_tty ne $cl->{"tty"}) { |
devi@0 | 758 print OUT "<td colspan='6'><table><tr><td class='ttychange' width='140' align='center'>",$cl->{"tty"},"</td><td/></tr></table></td></tr><tr>"; |
devi@0 | 759 $last_tty=$cl->{"tty"}; |
devi@0 | 760 } |
devi@0 | 761 |
devi@0 | 762 # TIME |
devi@0 | 763 if ($Config{"show_time"} =~ /^y/i) { |
devi@0 | 764 print OUT "<td valign='top' class='time' width='$Config{time_width}'><pre>", |
devi@0 | 765 $cl->{"hour"}, ":", $cl->{"min"}, ":", $cl->{"sec"}, |
devi@0 | 766 "</td>"; |
devi@0 | 767 } else { |
devi@0 | 768 print OUT "<td width='0'/>" |
devi@0 | 769 } |
devi@0 | 770 } |
devi@0 | 771 |
devi@0 | 772 # COMMAND |
devi@0 | 773 |
devi@0 | 774 |
devi@0 | 775 if ($format eq "html") { |
devi@0 | 776 print OUT "<td class='script'>\n"; |
devi@0 | 777 print OUT "<pre class='$cl_class'>\n"; |
devi@0 | 778 my $cline = $cl->{"cline"}; |
devi@0 | 779 $cline =~ s/\n//; |
devi@0 | 780 printq(\*OUT,$cl->{"prompt"},$cl->{"cline"}); |
devi@0 | 781 # printq(\*OUT,"(sudo ".$cl->{"last_command"}.")\n") if !$cl->{"euid"}; |
devi@0 | 782 print OUT "</pre>\n"; |
devi@0 | 783 } |
devi@0 | 784 else { |
devi@0 | 785 print OUT "<line class='$cl_class'>\n"; |
devi@0 | 786 print OUT "<prompt>"; |
devi@0 | 787 printq(\*OUT,$cl->{"prompt"}); |
devi@0 | 788 print OUT "</prompt>"; |
devi@0 | 789 print OUT "<command>"; |
devi@0 | 790 printq(\*OUT,$cl->{"cline"}); |
devi@0 | 791 print OUT "</command>"; |
devi@0 | 792 print OUT "\n</line>\n"; |
devi@0 | 793 } |
devi@0 | 794 |
devi@0 | 795 my $last_command = $cl->{"last_command"}; |
devi@0 | 796 if (!( |
devi@0 | 797 $Config{"suppress_editors"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"editors"}}) || |
devi@0 | 798 $Config{"suppress_pagers"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"pagers"}}) || |
devi@0 | 799 $Config{"suppress_terminal"}=~ /^y/i && grep ($_ eq $last_command, @{$Config{"terminal"}}) |
devi@0 | 800 )) { |
devi@0 | 801 |
devi@0 | 802 if ($format eq "html") { |
devi@0 | 803 print OUT "<pre class='$out_class'>"; |
devi@0 | 804 printq(\*OUT,$output); |
devi@0 | 805 print OUT "</pre>\n"; |
devi@0 | 806 } |
devi@0 | 807 else { |
devi@0 | 808 print OUT "<output class='$out_class'>\n"; |
devi@0 | 809 printq(\*OUT,$output); |
devi@0 | 810 print OUT "</output>\n"; |
devi@0 | 811 } |
devi@0 | 812 } |
devi@0 | 813 |
devi@0 | 814 # DIFF |
devi@0 | 815 if ( $Config{"show_diffs"} =~ /^y/i && $cl->{"diff"}) { |
devi@0 | 816 if ($format eq "html") { |
devi@0 | 817 #print Dumper(%{$cl->{"diff"}}); |
devi@0 | 818 print OUT "<table><tr><td width='5'/><td class='diff'><pre>"; |
devi@0 | 819 printq(\*OUT,${$Diffs[$cl->{"diff"}]}{"text"}); |
devi@0 | 820 print OUT "</pre></td></tr></table>"; |
devi@0 | 821 } |
devi@0 | 822 else { |
devi@0 | 823 print OUT "<diff>\n"; |
devi@0 | 824 printq(\*OUT,${$Diffs[$cl->{"diff"}]}{"text"}); |
devi@0 | 825 print OUT "</diff>\n"; |
devi@0 | 826 } |
devi@0 | 827 } |
devi@0 | 828 |
devi@0 | 829 # COMMENT |
devi@0 | 830 if ( $Config{"show_comments"} =~ /^y/i) { |
devi@0 | 831 my $comment = make_comment(join(" ",@new_commands), join (" ",@new_files)); |
devi@0 | 832 if ($comment) { |
devi@0 | 833 if ($format eq "html") { |
devi@0 | 834 print OUT "<table width='$Config{comment_width}'>". |
devi@0 | 835 "<tr><td width='5'/><td>"; |
devi@0 | 836 print OUT "<table class='note' width='100%'>"; |
devi@0 | 837 print OUT $comment; |
devi@0 | 838 print OUT "</table>\n"; |
devi@0 | 839 print OUT "</td></tr></table>"; |
devi@0 | 840 } |
devi@0 | 841 # else { |
devi@0 | 842 # print OUT "<comment>"; |
devi@0 | 843 # printq(\*OUT,$comment); |
devi@0 | 844 # print OUT "</comment>"; |
devi@0 | 845 # } |
devi@0 | 846 } |
devi@0 | 847 } |
devi@0 | 848 |
devi@0 | 849 if ($format eq "html") { |
devi@0 | 850 print OUT "</td>\n"; |
devi@0 | 851 print OUT "</tr>\n"; |
devi@0 | 852 } |
devi@0 | 853 else { |
devi@0 | 854 print OUT "</action>\n"; |
devi@0 | 855 } |
devi@0 | 856 |
devi@0 | 857 } |
devi@0 | 858 if ($format eq "html") { |
devi@0 | 859 print OUT "</table>\n"; |
devi@0 | 860 print OUT "</body>\n"; |
devi@0 | 861 print OUT "</html>\n"; |
devi@0 | 862 } |
devi@0 | 863 else { |
devi@0 | 864 print OUT "</script>\n"; |
devi@0 | 865 } |
devi@0 | 866 close(OUT); |
devi@0 | 867 } |
devi@0 | 868 |
devi@0 | 869 sub read_config_file |
devi@0 | 870 { |
devi@0 | 871 my $config = $_[0]; |
devi@0 | 872 my $filename = $_[1]; |
devi@0 | 873 open(CONFIG, "$filename") |
devi@0 | 874 or return; |
devi@0 | 875 while (<CONFIG>) { |
devi@0 | 876 s/#.*//; |
devi@0 | 877 next if /^\s*$/; |
devi@0 | 878 my ($var, $val) = split /\s*=\s*/, $_, 2; |
devi@0 | 879 $var =~ s/\s*//; |
devi@0 | 880 $config->{$var} = $val; |
devi@0 | 881 } |
devi@0 | 882 close(CONFIG); |
devi@0 | 883 } |
devi@0 | 884 |
devi@0 | 885 $| = 1; |
devi@0 | 886 |
devi@0 | 887 my %file_config; |
devi@0 | 888 my %argv_config; |
devi@0 | 889 read_config_file(\%file_config, $Config_File); |
devi@0 | 890 GetOptions(\%argv_config, map "$_=s", keys %Config); |
devi@0 | 891 %Config = (%Config, %file_config, %argv_config); |
devi@0 | 892 |
devi@0 | 893 |
devi@0 | 894 my $i=0; |
devi@0 | 895 |
devi@0 | 896 for my $lab_log (split (/\s+/, $Config{"diffs"} || $Config{"input"})) |
devi@0 | 897 { |
devi@0 | 898 load_diff_files($lab_log); |
devi@0 | 899 } |
devi@0 | 900 |
devi@0 | 901 for my $lab_log (split /\s+/, $Config{"input"}) |
devi@0 | 902 { |
devi@0 | 903 my $tofile=$Config{"output"}; |
devi@0 | 904 $tofile =~ s/$Config{"output_mask"}/$i/; |
devi@0 | 905 #load_diff_files($lab_log); |
devi@0 | 906 load_command_lines($lab_log, $Config{"input_mask"}); |
devi@0 | 907 sort_command_lines; |
devi@0 | 908 process_command_lines($lab_log); |
devi@0 | 909 print_command_lines($tofile); |
devi@0 | 910 $i++; |
devi@0 | 911 } |
devi@0 | 912 |