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

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

\n"; $print .= "\n"; $print .= "\n"; $print .= ""; $print .= ""; $print .= ""; $print .= "\n"; for my $host (sort keys %{$t->{host}}) { my $prefix = "/cgi-bin/l3/current/"; my $suffix = ""; if ($is_not_cgi) { $prefix = ""; $suffix = ".html"; } $print .= "\n"; my $h = $t->{host}->{$host}; $print .= ""; $print .= ""; $print .= ""; $print .= ""; $print .= ""; $print .= "\n"; $print .= "\n"; } $print .= "\n"; $print .= ""; $print .= ""; $print .= ""; $print .= "\n"; $print .= "
"."Имя"."ХостПользователь
".$h->{firstname}." ".$h->{surname}."$hostroot".$h->{user}."все
"."Инструктор"."from linux.nt"; $print .= ""; $print .= "все
\n"; $print .= "\n"; $print .= "\n"; } elsif ($ENV{PATH_INFO} eq "/current") { open (FRONTEND, "./l3-frontend --output - --show_comments no |"); while () { $print .= $_; } close(FRONTEND); } else { # Вызов производится по URL my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4; $l3config::Config{"class"}=$course if $course ne 'current'; $XMLTraining = load_training; my @args=( "--output" => "-", "--show_comments" => "no", "--course-center" => $XMLTraining->{center}, "--course-trainer" => $XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname}, "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname}, "--course-code" => $XMLTraining->{course}, "--course-date" => $XMLTraining->{date}, "--encoding" => $XMLTraining->{host}->{$host}->{charset}, ); if ($course ne 'current') { push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml"); } else { $filter{hostname} = $host if $host; $filter{user} = $user if $user; push @args, ("--filter" => join ("&", (map("$_=$filter{$_}", keys %filter)))); #push @args, ("--filter" => "hostname=".$host."&user=".$user); } open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |"); while () { $print .= $_; } close(FRONTEND); } # Если задана переменная окружения l3_to_file, # печатаем в файл с соответствующим именем, # в противном случае -- выводим на стандартный поток вывода if (not defined $ENV{l3_to_file}) { binmode STDOUT, ":utf8"; print header(-charset => "utf-8"); print $print; } else { open(FILE, ">:utf8", $ENV{l3_to_file}) or die "Can't open $ENV{l3_to_file} for writing"; print FILE $print; close(FILE); }