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@30: chdir("/home/devi/cvs/lilalo"); devi@30: require l3config; devi@48: l3config::init_config(); 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@48: $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@48: devi@48: $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@30: for my $student (@{$XMLTraining->{"student"}}) { devi@30: $XMLTraining->{host}->{$student->{"host"}}=$student; devi@30: } devi@30: return $XMLTraining; devi@30: } devi@30: devi@29: devi@29: devi@30: if ($ENV{PATH_INFO} eq "/index") { devi@30: # Показываем индекс курсов devi@61: my @training_files = glob($l3config::Config{"path_classes"}."/2*".$l3config::Config{"class_suffix"}); devi@30: if (@training_files) { devi@30: for my $training_file (@training_files) { devi@48: $training_file =~ s@.*/@@; devi@48: $training_file =~ s@$l3config::Config{"class_suffix"}$@@; 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@71: 				$print .= " ".$h->{company}." ";
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@31: elsif ($ENV{PATH_INFO} eq "/current") { devi@48: open (FRONTEND, "./l3-frontend --output - --show_comments no --frontend_css $l3config::Config{frontend_css}|"); devi@48: binmode FRONTEND, ":utf8"; devi@31: while () { devi@43: $print .= $_; devi@31: } devi@31: close(FRONTEND); devi@31: } devi@30: else { devi@30: # Вызов производится по URL devi@48: $ENV{PATH_INFO} = "/".$ENV{PATH_INFO} unless $ENV{PATH_INFO} =~ m@^/@; devi@48: my ($skip, $training, $host, $user) = split /\//,$ENV{PATH_INFO},4; devi@29: devi@48: if (!$host || $host eq "index") { devi@48: # Нам неизвестен курс или явно указан просмотр индекса devi@48: # Просматриваем его devi@30: devi@48: my $t = load_training($training); devi@48: $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@48: $print .= "\n"; devi@48: $print .= "\n"; devi@48: $print .= "Журналы лабораторных работ\n"; devi@57: $print .= ""; devi@48: $print .= "\n"; devi@48: $print .= "\n"; devi@48: $print .= "\n"; devi@48: $print .= "

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

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