devi@27: #!/usr/bin/perl devi@27: devi@27: use strict; devi@27: use CGI qw(:standard); devi@30: use XML::Simple; devi@30: devi@30: BEGIN { devi@30: chdir("/home/devi/cvs/lilalo"); devi@30: require l3config; devi@30: }; devi@27: devi@37: my %filter; devi@32: devi@37: for my $key (qw(login_from)) { devi@37: $filter{$key} = param($key) if param($key); devi@42: $filter{$key} = $ENV{$key} if defined $ENV{$key}; devi@32: } devi@27: devi@30: my %Trainings; devi@30: my $XMLTraining; devi@30: my %Machines; devi@42: my $print = ""; devi@30: devi@30: sub load_training devi@30: { devi@30: my $classfile = devi@30: $_[0]|| devi@30: $l3config::Config{"classfile"} || devi@30: $l3config::Config{"path_classes"}."/".$l3config::Config{"class"}.$l3config::Config{"class_suffix"}; devi@30: devi@30: my $XMLTraining = XMLin($classfile , ForceArray => [ 'student' ] ) devi@32: or die "Can't open file of the training ",$classfile,"\n"; devi@30: devi@30: for my $student (@{$XMLTraining->{"student"}}) { devi@30: $XMLTraining->{host}->{$student->{"host"}}=$student; devi@30: } devi@30: return $XMLTraining; devi@30: } devi@30: devi@44: print header( devi@27: -charset => "utf-8", devi@27: ); devi@29: devi@29: devi@30: if ($ENV{PATH_INFO} eq "/index") { devi@30: # Показываем индекс курсов devi@30: my @training_files = glob($l3config::Config{"path_classes"}."/*".$l3config::Config{"class_suffix"}); devi@30: if (@training_files) { devi@30: for my $training_file (@training_files) { devi@30: my $training = load_training($training_file); devi@30: $Trainings{$training->{"date"}}=$training; devi@30: } devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@42: $print .= "Журналы лабораторных работ\n"; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@30: for my $tdate (reverse sort keys %Trainings) { devi@30: my $t = $Trainings{$tdate}; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= "\n"; devi@42: $print .= ""; devi@42: $print .= "\n"; devi@30: } devi@42: $print .= "
".$t->{date}."".$t->{course}."
"; devi@42: $print .= "
";
devi@30: 			for my $host (sort keys %{$t->{host}}) {
devi@30: 				my $h = $t->{host}->{$host};
devi@42: 				$print .= "$host";
devi@42: 				$print .= " ".$h->{firstname}." ".$h->{surname}." ";
devi@42: 				$print .= "root ";
devi@42: 				$print .= "".$h->{user}." ";
devi@42: 				$print .= "\n";
devi@30: 			}
devi@42: 			$print .= "
"; devi@42: $print .= "
\n"; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@30: } devi@30: else { devi@42: $print .= "No training-files found
\n"; devi@42: $print .= "Template to load files: ".$l3config::Config{"path_classes"}."*".$l3config::Config{"class_suffix"}."\n" devi@30: } devi@30: } devi@33: elsif ($ENV{PATH_INFO} eq "/current/index" || $ENV{PATH_INFO} eq "") { devi@33: my $t = load_training(); devi@39: devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@42: $print .= "Журналы лабораторных работ\n"; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@42: $print .= "

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

\n"; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= "\n"; devi@33: for my $host (sort keys %{$t->{host}}) { devi@41: devi@41: my $prefix = "/cgi-bin/l3/current/"; devi@41: my $suffix = ""; devi@41: devi@42: $print .= "\n"; devi@33: my $h = $t->{host}->{$host}; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@33: } devi@42: $print .= "\n"; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= ""; devi@42: $print .= "\n"; devi@42: $print .= "
"."Имя"."ХостПользователь
".$h->{firstname}." ".$h->{surname}."$hostroot".$h->{user}."все
"."Инструктор"."from linux.nt"; devi@42: $print .= ""; devi@42: $print .= "все
\n"; devi@42: $print .= "\n"; devi@42: $print .= "\n"; devi@33: } devi@31: elsif ($ENV{PATH_INFO} eq "/current") { devi@31: open (FRONTEND, "./l3-frontend --output - --show_comments no |"); devi@31: while () { devi@43: $print .= $_; devi@31: } devi@31: close(FRONTEND); devi@31: } devi@30: else { devi@30: # Вызов производится по URL devi@30: my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4; devi@29: devi@32: $l3config::Config{"class"}=$course if $course ne 'current'; devi@30: $XMLTraining = load_training; devi@30: devi@30: my @args=( devi@30: "--output" => "-", devi@30: "--show_comments" => "no", devi@30: "--course-center" => $XMLTraining->{center}, devi@30: "--course-trainer" => $XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname}, devi@30: "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname}, devi@30: "--course-code" => $XMLTraining->{course}, devi@30: "--course-date" => $XMLTraining->{date}, devi@31: "--encoding" => $XMLTraining->{host}->{$host}->{charset}, devi@30: ); devi@32: if ($course ne 'current') { devi@32: push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml"); devi@32: } else { devi@37: $filter{hostname} = $host if $host; devi@37: $filter{user} = $user if $user; devi@37: push @args, ("--filter" => join ("&", (map("$_=$filter{$_}", keys %filter)))); devi@37: #push @args, ("--filter" => "hostname=".$host."&user=".$user); devi@32: } devi@30: devi@30: open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |"); devi@30: while () { devi@42: $print .= $_; devi@30: } devi@30: close(FRONTEND); devi@27: } devi@27: devi@42: print $print;