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