lilalo
changeset 32:4d252e7dd478
l3-frontend:
Добавлена поддержка фильтрации по пользователю (user) и хосту (hostname).
Пока только прототип - нужно оптимизировать.
И нужно стандартизировать имена для полей
l3-cgi:
В current теперь могут быть подразделы
Добавлена поддержка фильтрации по пользователю (user) и хосту (hostname).
Пока только прототип - нужно оптимизировать.
И нужно стандартизировать имена для полей
l3-cgi:
В current теперь могут быть подразделы
author | devi |
---|---|
date | Mon Nov 14 07:42:57 2005 +0200 (2005-11-14) |
parents | 196c82b6e538 |
children | e22df843b512 |
files | l3-agent l3-cgi l3-frontend l3config.pm lm lm-install |
line diff
1.1 --- a/l3-agent Fri Nov 11 21:29:49 2005 +0200 1.2 +++ b/l3-agent Mon Nov 14 07:42:57 2005 +0200 1.3 @@ -8,11 +8,10 @@ 1.4 use POSIX; 1.5 use Term::VT102; 1.6 use Text::Iconv; 1.7 -use Data::Dumper; 1.8 use Time::Local 'timelocal_nocheck'; 1.9 use IO::Socket; 1.10 1.11 -use lib "."; 1.12 +use lib "/usr/local/bin"; 1.13 use l3config; 1.14 1.15 1.16 @@ -296,6 +295,8 @@ 1.17 $commandlines_processed++; 1.18 # time 1.19 1.20 + next if s/^Script started on.*?\n//s; 1.21 + 1.22 if (/[0-9][0-9]:[0-9][0-9]:[0-9][0-9].\[[0-9][0-9]D.\[K/ && m/$cline_re/) { 1.23 s/.*\x0d(?!\x0a)//; 1.24 # print "!!!",$_,"!!!\n";
2.1 --- a/l3-cgi Fri Nov 11 21:29:49 2005 +0200 2.2 +++ b/l3-cgi Mon Nov 14 07:42:57 2005 +0200 2.3 @@ -9,7 +9,14 @@ 2.4 require l3config; 2.5 }; 2.6 2.7 -my $value = param('PARAM'); 2.8 +my @filter; 2.9 + 2.10 +for my $i (qw(host)) { 2.11 + my $value = param("$i"); 2.12 + if ($value) { 2.13 + push @filter, "$i=$value"; 2.14 + } 2.15 +} 2.16 2.17 my %Trainings; 2.18 my $XMLTraining; 2.19 @@ -23,7 +30,7 @@ 2.20 $l3config::Config{"path_classes"}."/".$l3config::Config{"class"}.$l3config::Config{"class_suffix"}; 2.21 2.22 my $XMLTraining = XMLin($classfile , ForceArray => [ 'student' ] ) 2.23 - or die "Can't open file of the class ",$classfile,"\n"; 2.24 + or die "Can't open file of the training ",$classfile,"\n"; 2.25 2.26 for my $student (@{$XMLTraining->{"student"}}) { 2.27 $XMLTraining->{host}->{$student->{"host"}}=$student; 2.28 @@ -83,7 +90,7 @@ 2.29 # Вызов производится по URL 2.30 my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4; 2.31 2.32 - $l3config::Config{"class"}=$course; 2.33 + $l3config::Config{"class"}=$course if $course ne 'current'; 2.34 $XMLTraining = load_training; 2.35 2.36 my @args=( 2.37 @@ -94,9 +101,13 @@ 2.38 "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname}, 2.39 "--course-code" => $XMLTraining->{course}, 2.40 "--course-date" => $XMLTraining->{date}, 2.41 - "--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml", 2.42 "--encoding" => $XMLTraining->{host}->{$host}->{charset}, 2.43 ); 2.44 + if ($course ne 'current') { 2.45 + push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml"); 2.46 + } else { 2.47 + push @args, ("--filter" => "hostname=".$host."&user=".$user); 2.48 + } 2.49 2.50 open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |"); 2.51 while (<FRONTEND>) {
3.1 --- a/l3-frontend Fri Nov 11 21:29:49 2005 +0200 3.2 +++ b/l3-frontend Mon Nov 14 07:42:57 2005 +0200 3.3 @@ -10,6 +10,7 @@ 3.4 our %Commands_Description; 3.5 our %Args_Description; 3.6 our $Mywi_Socket; 3.7 +our %Sessions; 3.8 3.9 # vvv Инициализация переменных выполняется процедурой init_variables 3.10 our @Day_Name; 3.11 @@ -25,6 +26,7 @@ 3.12 sub search_buy; 3.13 sub make_comment; 3.14 sub load_command_lines_from_xml; 3.15 +sub load_sessions_from_xml; 3.16 sub print_command_lines; 3.17 sub sort_command_lines; 3.18 sub process_command_lines; 3.19 @@ -41,8 +43,9 @@ 3.20 init_variables(); 3.21 init_config(); 3.22 3.23 - open_mywi_socket; 3.24 + open_mywi_socket(); 3.25 load_command_lines_from_xml($Config{"backend_datafile"}); 3.26 + load_sessions_from_xml($Config{"backend_datafile"}); 3.27 sort_command_lines; 3.28 process_command_lines; 3.29 print_command_lines($Config{"output"}); 3.30 @@ -223,6 +226,27 @@ 3.31 } 3.32 } 3.33 3.34 +sub load_sessions_from_xml 3.35 +{ 3.36 + my $datafile = $_[0]; 3.37 + 3.38 + open (CLASS, $datafile) 3.39 + or die "Can't open file of the class ",$datafile,"\n"; 3.40 + local $/; 3.41 + my $data = <CLASS>; 3.42 + close(CLASS); 3.43 + 3.44 + for my $session ($data =~ m@<session>(.*?)</session>@sg) { 3.45 + my %session; 3.46 + while ($session =~ m@<([^>]*?)>(.*?)</\1>@sg) { 3.47 + $session{$1} = $2; 3.48 + } 3.49 + $Sessions{$session{local_session_id}} = \%session; 3.50 + } 3.51 +} 3.52 + 3.53 + 3.54 + 3.55 sub sort_command_lines 3.56 { 3.57 # Sort Command_Lines 3.58 @@ -305,11 +329,11 @@ 3.59 my $j = $i; 3.60 if ($1 eq "^") { 3.61 $j--; 3.62 - $j-- while ($j >=0 && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]); 3.63 + $j-- while ($j >=0 && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty})); 3.64 } 3.65 elsif ($1 eq "v") { 3.66 $j++; 3.67 - $j++ while ($j <= @Command_Lines && $Command_Lines[$j]->{tty} ne $$cl->{tty} || !$Command_Lines[$j]); 3.68 + $j++ while ($j <= @Command_Lines && (!$Command_Lines[$j] || $Command_Lines[$j]->{tty} ne $$cl->{tty})); 3.69 } 3.70 $Command_Lines[$j]->{note_title}="$2"; 3.71 $Command_Lines[$j]->{note}=$$cl->{output}; 3.72 @@ -373,12 +397,32 @@ 3.73 my $in_range=0; 3.74 3.75 my $i=0; 3.76 + 3.77 +COMMAND_LINE: 3.78 for my $k (@Command_Lines_Index) { 3.79 3.80 my $cl=$Command_Lines[$Command_Lines_Index[$i++]]; 3.81 3.82 next unless $cl; 3.83 3.84 + 3.85 + if ($Config{filter}) { 3.86 + # Инициализация фильтра 3.87 + my %filter; 3.88 + for (split /&/,$Config{filter}) { 3.89 + my ($var, $val) = split /=/; 3.90 + $filter{$var} = $val; 3.91 + } 3.92 + 3.93 + if ($filter{hostname}) { 3.94 + next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{hostname} eq $filter{hostname}; 3.95 + } 3.96 + 3.97 + #for my $filter_field (keys %filter) { 3.98 + # next COMMAND_LINE unless $Sessions{$cl->{local_session_id}}->{$filter_field} eq $filter{$filter_field}; 3.99 + #} 3.100 + } 3.101 + 3.102 if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) { 3.103 $in_range=1; 3.104 next; 3.105 @@ -495,7 +539,9 @@ 3.106 3.107 # CONSOLE CHANGE 3.108 if ( $last_tty ne $cl->{"tty"}) { 3.109 - $Result{"body"} .= "<td colspan='6'><table><tr><td class='ttychange' width='140' align='center'>".$cl->{"tty"}."</td><td/></tr></table></td></tr><tr>"; 3.110 + my $host; 3.111 + #$host = $Sessions{$cl->{local_session_id}}->{user}."@".$Sessions{$cl->{local_session_id}}->{hostname}; 3.112 + $Result{"body"} .= "<td colspan='6'><table><tr><td class='ttychange' width='140' align='center'>".$cl->{"tty"}."</td><td>$host</td></tr></table></td></tr><tr>"; 3.113 $last_tty=$cl->{"tty"}; 3.114 } 3.115 3.116 @@ -513,8 +559,10 @@ 3.117 $Result{"body"} .= "<pre class='${class}cline'>\n"; 3.118 my $cline = $cl->{"prompt"}.$cl->{"cline"}; 3.119 $cline =~ s/\n//; 3.120 + 3.121 + #$cline .= "(".$Sessions{$cl->{local_session_id}}.")"; 3.122 + 3.123 my $hint = make_comment($cl->{"cline"}); 3.124 - # join(" ",@new_commands), join (" ",@new_files)); 3.125 $cline = "<div title='$hint'>$cline</div>" if $hint; 3.126 $Result{"body"} .= $cline; 3.127 $Result{"body"} .= "</pre>\n"; 3.128 @@ -576,7 +624,7 @@ 3.129 FirstCommand => "Время первой команды журнала", 3.130 LastCommand => "Время последней команды журнала", 3.131 TotalCommands => "Количество командных строк в журнале", 3.132 - ErrorsPercentage => "Процент команд с кодом ненулевым кодом завершения, %", 3.133 + ErrorsPercentage => "Процент команд с ненулевым кодом завершения, %", 3.134 TotalTime => "Суммарное время работы с терминалом <sup><font size='-2'>*</font></sup>, час", 3.135 CommandsPerTime => "Количество командных строк в единицу времени, команда/мин", 3.136 CommandsFDistribution => "Частота использования команд", 3.137 @@ -606,7 +654,7 @@ 3.138 if $Stat{TotalCommands}; 3.139 $Stat{CommandsPerTime} = sprintf "%5.2f", $Stat{TotalCommands}*60/$Stat{TotalTime} 3.140 if $Stat{TotalTime}; 3.141 - $Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/24; 3.142 + $Stat{TotalTime} = sprintf "%5.2f", $Stat{TotalTime}/60/60; 3.143 3.144 my $total_commands=0; 3.145 for $command (keys %CommandsFDistribution){ 3.146 @@ -614,17 +662,18 @@ 3.147 } 3.148 if ($total_commands) { 3.149 for $command (reverse sort {$CommandsFDistribution{$a} <=> $CommandsFDistribution{$b}} keys %CommandsFDistribution){ 3.150 + my $command_html; 3.151 my $percentage = sprintf "%5.2f",$CommandsFDistribution{$command}*100/$total_commands; 3.152 if ($percentage < 0.5) { 3.153 my $hint = make_comment($command); 3.154 - my $command_html = "$command"; 3.155 + $command_html = "$command"; 3.156 $command_html = "<span title='$hint' class='hint'>$command_html</span>" if $hint; 3.157 my $command_html = "<tt>$command_html</tt>"; 3.158 $Stat{RareCommands} .= $command_html."<sub><font size='-2'>".$CommandsFDistribution{$command}."</font></sub> , "; 3.159 } 3.160 else { 3.161 my $hint = make_comment($command); 3.162 - my $command_html = "$command"; 3.163 + $command_html = "$command"; 3.164 $command_html = "<span title='$hint' class='hint'>$command_html</span>" if $hint; 3.165 my $command_html = "<tt>$command_html</tt>"; 3.166 $percentage = sprintf "%5.2f",$percentage; 3.167 @@ -633,13 +682,14 @@ 3.168 } 3.169 } 3.170 $Stat{CommandsFDistribution} = "<table>".$Stat{CommandsFDistribution}."</table>"; 3.171 - $Stat{RareCommands} =~ s/, $//; 3.172 + $Stat{RareCommands} =~ s/, $// if $Stat{RareCommands}; 3.173 } 3.174 3.175 $Result{"stat"} .= "<h2 id='stat'>Статистика</h2>"; 3.176 $Result{"stat"} .= "<table>"; 3.177 for my $stat (@StatOrder) { 3.178 - $Result{"stat"} .= "<tr valign='top'><td width='300'>".$StatNames{"$stat"}."</td><td>".$Stat{"$stat"}."</td></tr>"; 3.179 + $Result{"stat"} .= "<tr valign='top'><td width='300'>".$StatNames{"$stat"}."</td><td>".$Stat{"$stat"}."</td></tr>" 3.180 + if $Stat{"$stat"}; 3.181 } 3.182 3.183 $Result{"stat"} .= "</table>";
4.1 --- a/l3config.pm Fri Nov 11 21:29:49 2005 +0200 4.2 +++ b/l3config.pm Mon Nov 14 07:42:57 2005 +0200 4.3 @@ -1,3 +1,4 @@ 4.4 + 4.5 package l3config; 4.6 4.7 use Exporter; 4.8 @@ -7,7 +8,11 @@ 4.9 @ISA = ('Exporter'); 4.10 @EXPORT = qw(%Config &init_config); 4.11 4.12 -our $Config_File = "labmaker.conf"; 4.13 +our $System_Config_File = "/etc/lilalo.conf"; 4.14 +our $User_Config_File = "$ENV{HOME}/.lilalo.conf"; 4.15 +$ENV{HOME} ||= "/tmp"; 4.16 + 4.17 + 4.18 our %Config = ( 4.19 "skip_empty" => "yes", 4.20 "skip_interrupted" => "no", 4.21 @@ -28,24 +33,23 @@ 4.22 4.23 "head_lines" => 5, 4.24 "tail_lines" => 5, 4.25 - "cache_head_lines" => 50, 4.26 - "cache_tail_lines" => 50, 4.27 + "cache_head_lines" => 50, 4.28 + "cache_tail_lines" => 50, 4.29 "skip_text" => "...", 4.30 "show_time" => "yes", 4.31 "show_diffs" => "yes", 4.32 "show_comments" => "yes", 4.33 "show_notes" => "yes", 4.34 4.35 - "input" => "/root/.labmaker", 4.36 + "input" => "$ENV{HOME}/.lilalo", 4.37 "diffs" => "", 4.38 "input_mask" => "*.script", 4.39 "encoding" => "utf-8", 4.40 4.41 - "cache" => "/tmp/report.xml", 4.42 - "cache_stat" => "/tmp/.report.dat", 4.43 + "cache" => "$ENV{HOME}/.lilalo/report.xml", 4.44 + "cache_stat" => "$ENV{HOME}/.lilalo/.report.dat", 4.45 4.46 "output" => "/tmp/report.html", 4.47 - #"output" => "report.xml", 4.48 "output_mask" => "INDEX", 4.49 "output_format" => "html", 4.50 "frontend_css" => "/l3/l3.css", 4.51 @@ -74,12 +78,12 @@ 4.52 "mode" => "daemon", # daemon | normal 4.53 "daemon_sleep_interval" => "1", 4.54 "detach" => "yes", 4.55 - "agent_pidfile" => "$ENV{HOME}/.labmaker/l3-agent.pid", 4.56 + "agent_pidfile" => "$ENV{HOME}/.lilalo/l3-agent.pid", 4.57 4.58 "backend_address" => "127.0.0.1", 4.59 "backend_port" => "18030", 4.60 "backend_pidfile" => "/tmp/l3-backend.pid", 4.61 - "backend_datafile" => "/tmp/backend.xml", 4.62 + "backend_datafile" => "/var/lilalo/lablogs-xml/backend.xml", 4.63 4.64 "l3-agent" => "l3-agent", 4.65 "l3-backend" => "l3-backend", 4.66 @@ -91,7 +95,7 @@ 4.67 "course-trainer" => "", 4.68 "course-student" => "", 4.69 4.70 - 4.71 + "filter" => "", 4.72 #lm 4.73 "show_host" => "no", 4.74 4.75 @@ -144,7 +148,8 @@ 4.76 { 4.77 my %argv_config; 4.78 my %file_config; 4.79 - read_config_file(\%file_config, $Config_File); 4.80 + read_config_file(\%file_config, $System_Config_File); 4.81 + read_config_file(\%file_config, $User_Config_File); 4.82 GetOptions(\%argv_config, map "$_=s", keys %Config); 4.83 %Config = (%Config, %file_config, %argv_config); 4.84 }
5.1 --- a/lm Fri Nov 11 21:29:49 2005 +0200 5.2 +++ b/lm Mon Nov 14 07:42:57 2005 +0200 5.3 @@ -494,6 +494,11 @@ 5.4 ###install-lm 5.5 cat $lminstall | ssh $ssh_user@$host /bin/sh -s $dirs 5.6 5.7 +###install-pm 5.8 +scp PM/* $ssh_user@$host:/tmp 5.9 +ssh $ssh_user@$host 'cd /tmp; tar xfz Term-VT102*; cd Term-VT102*; perl Makefile.PL; make ; make install' 5.10 +ssh $ssh_user@$host 'cd /tmp; tar xfz Text-Iconv*; cd Text-Iconv*; perl Makefile.PL; make ; make install' 5.11 + 5.12 ###copy-lablogs 5.13 for i in $dirs 5.14 do 5.15 @@ -522,6 +527,7 @@ 5.16 export UG_DATE="$date" 5.17 export UG_STUDENT="$name" 5.18 export UG_COMPANY="$company" 5.19 +export UG_MAIL="$email" 5.20 cd $coursepath; make personal; cd ~- 5.21 5.22 ###watch
6.1 --- a/lm-install Fri Nov 11 21:29:49 2005 +0200 6.2 +++ b/lm-install Mon Nov 14 07:42:57 2005 +0200 6.3 @@ -39,13 +39,9 @@ 6.4 | sed '/LabMaker:START/,/LabMaker:END/ d' \ 6.5 > $temp_file 6.6 cat <<'LM_bash_profile' >> $temp_file 6.7 - # LabMaker:START 6.8 - #LMHOME=~/.labmaker 6.9 - #mkdir -p ${LMHOME} 6.10 - #TTY=`tty` 6.11 - #flush="-f" 6.12 - #exec script $flush -q $LMHOME/${TTY##*/}-$$.script 6.13 - # LabMaker:END 6.14 +# LabMaker:START 6.15 +/usr/local/bin/l3-agent 6.16 +# LabMaker:END 6.17 LM_bash_profile 6.18 cat $temp_file > $profile 6.19 rm $temp_file 6.20 @@ -69,7 +65,7 @@ 6.21 > $temp_file 6.22 cat <<'LM_bash_profile' >> $temp_file 6.23 # LabMaker:START 6.24 -LMHOME=~/.labmaker 6.25 +LMHOME=~/.lilalo 6.26 mkdir -p ${LMHOME} 6.27 6.28 uname -a | grep -qi bsd && bsd=yes 6.29 @@ -100,7 +96,7 @@ 6.30 6.31 cat <<INFO > $LMHOME/${session_id}.info 6.32 <session> 6.33 -<session_id>$session_id</session_id> 6.34 +<local_session_id>$session_id</local_session_id> 6.35 <hostname>$hostname</hostname> 6.36 <user>$USER</user> 6.37 <login_from>$login_from</login_from> 6.38 @@ -139,7 +135,7 @@ 6.39 cat <<'editor_wrapper' | sed "s@EDITOR@$editor@" > $editor 6.40 #!/bin/sh 6.41 6.42 -LMHOME=~/.labmaker 6.43 +LMHOME=~/.lilalo 6.44 if [ "${1#-}" = "$1" -a -d "$LMHOME" ] 6.45 then 6.46 LAB=`cat $LMHOME/lab` 6.47 @@ -192,9 +188,9 @@ 6.48 # fix this! 6.49 user=${home%/} 6.50 user=${user##*/} 6.51 - mkdir -p $home/.labmaker 6.52 - echo $first_lab > $home/.labmaker/lab 6.53 - chown -R $user $home/.labmaker 6.54 + mkdir -p $home/.lilalo 6.55 + echo $first_lab > $home/.lilalo/lab 6.56 + chown -R $user $home/.lilalo 6.57 6.58 #if [ ! -e $home/.bash_profile ] 6.59 #then 6.60 @@ -229,9 +225,9 @@ 6.61 for user in $users_to_install 6.62 do 6.63 home=$user 6.64 - mkdir -p $home/.labmaker 6.65 - echo $first_lab > $home/.labmaker/lab 6.66 - chown -R ${user##*/} $home/.labmaker 6.67 + mkdir -p $home/.lilalo 6.68 + echo $first_lab > $home/.lilalo/lab 6.69 + chown -R ${user##*/} $home/.lilalo 6.70 6.71 #if [ ! -e $home/.bash_profile ] 6.72 #then