devi@27: #!/usr/bin/perl devi@27: devi@27: use strict; devi@27: use CGI qw(:standard); devi@30: use XML::Simple; devi@46: use utf8; devi@30: devi@30: BEGIN { devi@84: chdir("/home/devi/cvs/lilalo"); devi@84: require l3config; devi@84: l3config::init_config(); devi@30: }; devi@27: devi@37: my %filter; devi@32: devi@80: for my $key (qw(login_from local_session_id)) { devi@84: $filter{$key} = param($key) if param($key); devi@84: $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@84: $l3config::Config{cgi2file} = $ENV{cgi2file} if defined($ENV{cgi2file}); devi@48: $ENV{PATH_INFO} = $l3config::Config{cgi_path_info} if $l3config::Config{cgi_path_info}; devi@48: devi@47: my $is_not_cgi=""; devi@48: $is_not_cgi = "1" if $l3config::Config{cgi2file}; devi@47: # Пока что мы считаем, что вызов выполняется через CGI, devi@48: # если не установлена переменная cgi2file devi@48: # и не передан такой аргумент командной строки. devi@47: # Это неверно, но как временное решение - пойдёт devi@48: my $to_file = $l3config::Config{cgi2file}; devi@47: devi@47: $l3config::Config{frontend_css} =~ s@^/@@ if $is_not_cgi; devi@47: devi@30: sub load_training devi@30: { devi@48: my $training_file; devi@84: devi@84: $training_file = $l3config::Config{"path_classes"}.$_[0].$l3config::Config{"class_suffix"} if $_[0]; devi@48: $training_file ||= $l3config::Config{"classfile"} || devi@48: $l3config::Config{"path_classes"}.$l3config::Config{"class"}.$l3config::Config{"class_suffix"}; devi@30: devi@48: my $XMLTraining = XMLin($training_file , ForceArray => [ 'student' ] ) devi@48: or die "Can't open file of the training ",$training_file,"\n"; devi@30: devi@84: my $course_file = $l3config::Config{"courses_path"}.$XMLTraining->{"course"}.".xml"; devi@84: my $XMLCourse; devi@84: if (eval{$XMLCourse = XMLin($course_file)}) { devi@84: $XMLTraining->{"course-name"} = $XMLCourse->{"fullname"}; devi@84: } devi@84: devi@30: for my $student (@{$XMLTraining->{"student"}}) { devi@84: $XMLTraining->{host}->{$student->{"host"}}=$student; devi@30: } devi@84: return $XMLTraining; devi@30: } devi@30: devi@29: devi@29: devi@30: if ($ENV{PATH_INFO} eq "/index") { devi@84: # Показываем индекс курсов devi@84: my @training_files = glob($l3config::Config{"path_classes"}."/2*".$l3config::Config{"class_suffix"}); devi@84: if (@training_files) { devi@84: for my $training_file (@training_files) { devi@84: $training_file =~ s@.*/@@; devi@84: $training_file =~ s@$l3config::Config{"class_suffix"}$@@; devi@84: my $training = load_training($training_file); devi@84: $Trainings{$training->{"date"}}=$training; devi@84: } devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: $print .= "Журналы лабораторных работ\n"; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: for my $tdate (reverse sort keys %Trainings) { devi@84: my $t = $Trainings{$tdate}; devi@84: $print .= ""; devi@84: $print .= ""; devi@88: $print .= ""; devi@84: $print .= "\n"; devi@84: for my $host (sort keys %{$t->{host}}) { devi@88: my %row; devi@88: my @row_keys = qw{ devi@88: name email company host root user devi@88: }; devi@84: my $h = $t->{host}->{$host}; devi@88: $row{name}= $h->{firstname}." ".$h->{surname}; devi@88: $row{email}= $h->{email}; devi@88: $row{company} = $h->{company}; devi@88: $row{host} = "$host"; devi@88: $row{root} = "root "; devi@88: $row{user} = "".$h->{user}." "; devi@88: $print .= "".join("", map("", @row_keys)).""; devi@84: } devi@84: } devi@84: $print .= "
".$t->{date}."".$t->{course}."
$row{$_}
\n"; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: } devi@84: else { devi@84: $print .= "No training-files found
\n"; devi@84: $print .= "Template to load files: ".$l3config::Config{"path_classes"}."*".$l3config::Config{"class_suffix"}."\n" devi@84: } devi@30: } devi@31: elsif ($ENV{PATH_INFO} eq "/current") { devi@84: open (FRONTEND, "./l3-frontend --output - --show_comments no --frontend_css $l3config::Config{frontend_css}|"); devi@84: binmode FRONTEND, ":utf8"; devi@84: while () { devi@84: $print .= $_; devi@84: } devi@84: close(FRONTEND); devi@31: } devi@30: else { devi@84: # Вызов производится по URL devi@84: $ENV{PATH_INFO} = "/".$ENV{PATH_INFO} unless $ENV{PATH_INFO} =~ m@^/@; devi@84: my ($skip, $training, $host, $user) = split /\//,$ENV{PATH_INFO},4; devi@29: devi@84: if (!$host || $host eq "index") { devi@84: # Нам неизвестен курс или явно указан просмотр индекса devi@84: # Просматриваем его devi@30: devi@84: my $t = load_training($training); devi@84: $training ||= "current"; devi@48: devi@57: my $prefix = "/cgi-bin/l3/$training/"; devi@57: my $suffix = ""; devi@57: if ($is_not_cgi) { devi@57: $prefix = ""; devi@57: $suffix = ".html"; devi@57: } devi@57: my $path = $to_file; devi@57: $path = "" unless $path =~ s@/[^/]*$@@; devi@57: devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: $print .= "Журналы лабораторных работ\n"; devi@57: $print .= ""; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: $print .= "

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

\n"; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: $print .= ""; devi@84: $print .= ""; devi@84: $print .= ""; devi@84: $print .= "\n"; devi@84: for my $host (sort keys %{$t->{host}}) { devi@84: $print .= "\n"; devi@84: my $h = $t->{host}->{$host}; devi@84: $print .= ""; devi@84: $print .= ""; devi@84: $print .= ""; devi@84: $print .= ""; devi@84: $print .= "" if not $is_not_cgi; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@48: devi@84: if ($is_not_cgi) { devi@84: # Это грязный хак devi@84: # Если мы чувствуем, что нас вызывают для генерения индексного файла, devi@84: # нам нужно создать и файлы, на которые он указывает devi@84: # Лучше было бы это сделать хотя бы через вызов функций devi@57: # Такой же хак чуть ниже devi@84: mkdir("$path/$host"); devi@84: system("$0 --cgi2file $path/$prefix$host/root$suffix ". devi@84: "--cgi_path_info ".$training."/".$host."/root ". devi@84: "--frontend_css ../$l3config::Config{frontend_css}"); devi@84: system("$0 --cgi2file $path/$prefix$host/".$h->{user}."$suffix ". devi@84: "--cgi_path_info ".$training."/".$host."/".$h->{user}." ". devi@84: "--frontend_css ../$l3config::Config{frontend_css}"); devi@84: # system("$0 --cgi2file $path/$prefix$host$suffix ". devi@84: # "--cgi_path_info ".$training."/".$host." ". devi@84: # "--frontend_css ../$l3config::Config{frontend_css}"); devi@84: } devi@84: devi@84: } devi@57: # Такой же хак был чуть выше devi@57: if ($is_not_cgi) { devi@57: # $print .= ""; devi@57: # system("$0 --cgi2file $path/$prefix$host$suffix" devi@57: # . " --cgi_path_info ".$training."?login_from=192.168.15.254".$host devi@57: # . " --frontend_css ../$l3config::Config{frontend_css}"); devi@57: } devi@57: else { devi@57: $print .= "\n"; devi@57: $print .= ""; devi@57: $print .= ""; devi@57: $print .= ""; devi@57: } devi@84: $print .= "\n"; devi@84: $print .= "
"."Имя"."ХостПользователь
".$h->{firstname}." ".$h->{surname}."$hostroot".$h->{user}."все
все
"."Инструктор"."from linux.nt"; devi@57: $print .= ""; devi@57: $print .= "все
\n"; devi@84: $print .= "\n"; devi@84: $print .= "\n"; devi@84: } devi@84: else { devi@30: devi@84: $l3config::Config{"class"}=$training if $training ne 'current'; devi@84: $XMLTraining = load_training; devi@48: devi@84: my @args=( devi@84: "--output" => "-", devi@84: "--show_comments" => "no", devi@84: "--course-center" => $XMLTraining->{center}, devi@84: "--course-trainer" => $XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname}, devi@84: "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname}, devi@84: "--course-code" => $XMLTraining->{course}, devi@84: "--course-date" => $XMLTraining->{date}, devi@84: "--encoding" => $XMLTraining->{host}->{$host}->{charset}, devi@84: ); devi@84: if ($XMLTraining->{"course-name"}) { devi@84: push @args, ("--course-name" => $XMLTraining->{"course-name"}); devi@84: }; devi@84: if ($training ne 'current') { devi@84: push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$training/$host/$user.xml"); devi@84: } else { devi@84: $filter{hostname} = $host if $host; devi@84: $filter{user} = $user if $user; devi@84: } devi@84: push @args, ("--filter" => join ("&", (map("$_=$filter{$_}", keys %filter)))); devi@48: devi@84: #$print .= "./l3-frontend --frontend_css $l3config::Config{frontend_css} ".join(" ",map("\"$_\"",@args))." |
"; devi@84: open (FRONTEND, "./l3-frontend --frontend_css $l3config::Config{frontend_css} ".join(" ",map("\"$_\"",@args))." |"); devi@84: binmode FRONTEND, ":utf8"; devi@84: while () { devi@84: $print .= $_; devi@84: } devi@84: close(FRONTEND); devi@84: } devi@27: } devi@27: devi@47: # Если задана переменная окружения l3_to_file, devi@47: # печатаем в файл с соответствующим именем, devi@47: # в противном случае -- выводим на стандартный поток вывода devi@48: if (not $to_file) { devi@47: binmode STDOUT, ":utf8"; devi@47: print header(-charset => "utf-8"); devi@47: print $print; devi@47: } devi@47: else { devi@48: open(FILE, ">:utf8", $to_file) devi@48: or die "Can't open $to_file for writing"; devi@47: print FILE $print; devi@47: close(FILE); devi@47: } devi@47: devi@47: