lilalo

annotate l3-cgi @ 33:e22df843b512

Поддержка /l3/current/index
author devi
date Mon Nov 14 09:16:28 2005 +0200 (2005-11-14)
parents 4d252e7dd478
children 219389279acb
rev   line source
devi@27 1 #!/usr/bin/perl
devi@27 2
devi@27 3 use strict;
devi@27 4 use CGI qw(:standard);
devi@30 5 use XML::Simple;
devi@30 6
devi@30 7 BEGIN {
devi@30 8 chdir("/home/devi/cvs/lilalo");
devi@30 9 require l3config;
devi@30 10 };
devi@27 11
devi@32 12 my @filter;
devi@32 13
devi@32 14 for my $i (qw(host)) {
devi@32 15 my $value = param("$i");
devi@32 16 if ($value) {
devi@32 17 push @filter, "$i=$value";
devi@32 18 }
devi@32 19 }
devi@27 20
devi@30 21 my %Trainings;
devi@30 22 my $XMLTraining;
devi@30 23 my %Machines;
devi@30 24
devi@30 25 sub load_training
devi@30 26 {
devi@30 27 my $classfile =
devi@30 28 $_[0]||
devi@30 29 $l3config::Config{"classfile"} ||
devi@30 30 $l3config::Config{"path_classes"}."/".$l3config::Config{"class"}.$l3config::Config{"class_suffix"};
devi@30 31
devi@30 32 my $XMLTraining = XMLin($classfile , ForceArray => [ 'student' ] )
devi@32 33 or die "Can't open file of the training ",$classfile,"\n";
devi@30 34
devi@30 35 for my $student (@{$XMLTraining->{"student"}}) {
devi@30 36 $XMLTraining->{host}->{$student->{"host"}}=$student;
devi@30 37 }
devi@30 38 return $XMLTraining;
devi@30 39 }
devi@30 40
devi@27 41 print header(
devi@27 42 -charset => "utf-8",
devi@27 43 );
devi@29 44
devi@29 45
devi@30 46 if ($ENV{PATH_INFO} eq "/index") {
devi@30 47 # Показываем индекс курсов
devi@30 48 my @training_files = glob($l3config::Config{"path_classes"}."/*".$l3config::Config{"class_suffix"});
devi@30 49 if (@training_files) {
devi@30 50 for my $training_file (@training_files) {
devi@30 51 my $training = load_training($training_file);
devi@30 52 $Trainings{$training->{"date"}}=$training;
devi@30 53 }
devi@30 54 print "<table>\n";
devi@30 55 for my $tdate (reverse sort keys %Trainings) {
devi@30 56 my $t = $Trainings{$tdate};
devi@30 57 print "<tr>";
devi@30 58 print "<td>".$t->{date}."</td>";
devi@30 59 print "<td>".$t->{course}."</td>";
devi@30 60 print "</tr>\n";
devi@30 61 print "<tr>";
devi@30 62 print "<td/>";
devi@30 63 print "<td><pre>";
devi@30 64 for my $host (sort keys %{$t->{host}}) {
devi@30 65 my $h = $t->{host}->{$host};
devi@30 66 print "$host";
devi@30 67 print " ".$h->{firstname}." ".$h->{surname}." ";
devi@30 68 print "<a href='/cgi-bin/l3/".$tdate."/".$host."/root'>root</a> ";
devi@30 69 print "<a href='/cgi-bin/l3/".$tdate."/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
devi@30 70 print "\n";
devi@30 71 }
devi@30 72 print "</pre><td>";
devi@30 73 print "</tr>\n";
devi@30 74 }
devi@30 75 print "</table>\n";
devi@30 76 }
devi@30 77 else {
devi@30 78 print "No training-files found<br/>\n";
devi@30 79 print "Template to load files: ".$l3config::Config{"path_classes"}."*".$l3config::Config{"class_suffix"}."\n"
devi@30 80 }
devi@30 81 }
devi@33 82 elsif ($ENV{PATH_INFO} eq "/current/index" || $ENV{PATH_INFO} eq "") {
devi@33 83 my $t = load_training();
devi@33 84 for my $host (sort keys %{$t->{host}}) {
devi@33 85 my $h = $t->{host}->{$host};
devi@33 86 print "$host";
devi@33 87 print " ".$h->{firstname}." ".$h->{surname}." ";
devi@33 88 print "<a href='/cgi-bin/l3/current/".$host."/root'>root</a> ";
devi@33 89 print "<a href='/cgi-bin/l3/current/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
devi@33 90 print "<br/>\n";
devi@33 91 }
devi@33 92 }
devi@31 93 elsif ($ENV{PATH_INFO} eq "/current") {
devi@31 94 open (FRONTEND, "./l3-frontend --output - --show_comments no |");
devi@31 95 while (<FRONTEND>) {
devi@31 96 print;
devi@31 97 }
devi@31 98 close(FRONTEND);
devi@31 99 }
devi@30 100 else {
devi@30 101 # Вызов производится по URL
devi@30 102 my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4;
devi@29 103
devi@32 104 $l3config::Config{"class"}=$course if $course ne 'current';
devi@30 105 $XMLTraining = load_training;
devi@30 106
devi@30 107 my @args=(
devi@30 108 "--output" => "-",
devi@30 109 "--show_comments" => "no",
devi@30 110 "--course-center" => $XMLTraining->{center},
devi@30 111 "--course-trainer" => $XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname},
devi@30 112 "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname},
devi@30 113 "--course-code" => $XMLTraining->{course},
devi@30 114 "--course-date" => $XMLTraining->{date},
devi@31 115 "--encoding" => $XMLTraining->{host}->{$host}->{charset},
devi@30 116 );
devi@32 117 if ($course ne 'current') {
devi@32 118 push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml");
devi@32 119 } else {
devi@32 120 push @args, ("--filter" => "hostname=".$host."&user=".$user);
devi@32 121 }
devi@30 122
devi@30 123 open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |");
devi@30 124 while (<FRONTEND>) {
devi@30 125 print;
devi@30 126 }
devi@30 127 close(FRONTEND);
devi@27 128 }
devi@27 129