lilalo

annotate l3-cgi @ 46:f13cd5b4f2d0

Исправления
author devi
date Tue Nov 22 23:54:49 2005 +0200 (2005-11-22)
parents 5a7cc5c87f82
children fcd63bc2bfa0
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@46 6 use utf8;
devi@30 7
devi@30 8 BEGIN {
devi@30 9 chdir("/home/devi/cvs/lilalo");
devi@30 10 require l3config;
devi@30 11 };
devi@27 12
devi@37 13 my %filter;
devi@32 14
devi@37 15 for my $key (qw(login_from)) {
devi@37 16 $filter{$key} = param($key) if param($key);
devi@42 17 $filter{$key} = $ENV{$key} if defined $ENV{$key};
devi@32 18 }
devi@27 19
devi@30 20 my %Trainings;
devi@30 21 my $XMLTraining;
devi@30 22 my %Machines;
devi@42 23 my $print = "";
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@45 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@42 54 $print .= "<html>\n";
devi@42 55 $print .= "<head>\n";
devi@42 56 $print .= "<title>Журналы лабораторных работ</title>\n";
devi@42 57 $print .= "</head>\n";
devi@42 58 $print .= "<body>\n";
devi@42 59 $print .= "<table>\n";
devi@30 60 for my $tdate (reverse sort keys %Trainings) {
devi@30 61 my $t = $Trainings{$tdate};
devi@42 62 $print .= "<tr>";
devi@42 63 $print .= "<td>".$t->{date}."</td>";
devi@42 64 $print .= "<td>".$t->{course}."</td>";
devi@42 65 $print .= "</tr>\n";
devi@42 66 $print .= "<tr>";
devi@42 67 $print .= "<td/>";
devi@42 68 $print .= "<td><pre>";
devi@30 69 for my $host (sort keys %{$t->{host}}) {
devi@30 70 my $h = $t->{host}->{$host};
devi@42 71 $print .= "$host";
devi@42 72 $print .= " ".$h->{firstname}." ".$h->{surname}." ";
devi@42 73 $print .= "<a href='/cgi-bin/l3/".$tdate."/".$host."/root'>root</a> ";
devi@42 74 $print .= "<a href='/cgi-bin/l3/".$tdate."/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
devi@42 75 $print .= "\n";
devi@30 76 }
devi@42 77 $print .= "</pre><td>";
devi@42 78 $print .= "</tr>\n";
devi@30 79 }
devi@42 80 $print .= "</table>\n";
devi@42 81 $print .= "</body>\n";
devi@42 82 $print .= "</html>\n";
devi@30 83 }
devi@30 84 else {
devi@42 85 $print .= "No training-files found<br/>\n";
devi@42 86 $print .= "Template to load files: ".$l3config::Config{"path_classes"}."*".$l3config::Config{"class_suffix"}."\n"
devi@30 87 }
devi@30 88 }
devi@33 89 elsif ($ENV{PATH_INFO} eq "/current/index" || $ENV{PATH_INFO} eq "") {
devi@33 90 my $t = load_training();
devi@39 91
devi@42 92 $print .= "<html>\n";
devi@42 93 $print .= "<head>\n";
devi@42 94 $print .= "<title>Журналы лабораторных работ</title>\n";
devi@42 95 $print .= "<link rel='stylesheet' href='".$l3config::Config{frontend_css}."' type='text/css'/>\n";
devi@42 96 $print .= "</head>\n";
devi@42 97 $print .= "<body>\n";
devi@42 98 $print .= "<h1>Журналы лабораторных работ</h1>\n";
devi@42 99 $print .= "<table>\n";
devi@42 100 $print .= "<tr class='table_header'>\n";
devi@42 101 $print .= "<td>"."Имя"."</td>";
devi@42 102 $print .= "<td>Хост</td>";
devi@42 103 $print .= "<td colspan='3'>Пользователь</td>";
devi@42 104 $print .= "</tr>\n";
devi@33 105 for my $host (sort keys %{$t->{host}}) {
devi@41 106
devi@41 107 my $prefix = "/cgi-bin/l3/current/";
devi@41 108 my $suffix = "";
devi@41 109
devi@42 110 $print .= "<tr>\n";
devi@33 111 my $h = $t->{host}->{$host};
devi@42 112 $print .= "<td>".$h->{firstname}." ".$h->{surname}."</td>";
devi@42 113 $print .= "<td>$host</td>";
devi@42 114 $print .= "<td><a href='".$prefix.$host."/root$suffix'>root</a></td>";
devi@42 115 $print .= "<td><a href='".$prefix.$host."/".$h->{user}."$suffix'>".$h->{user}."</a></td>";
devi@42 116 $print .= "<td><a href='".$prefix.$host."$suffix'>все</a></td>";
devi@42 117 $print .= "</td>\n";
devi@42 118 $print .= "</tr>\n";
devi@33 119 }
devi@42 120 $print .= "<tr>\n";
devi@42 121 $print .= "<td>"."Инструктор"."</td>";
devi@42 122 $print .= "<td>from linux.nt</td>";
devi@42 123 $print .= "<td/>";
devi@42 124 $print .= "<td/>";
devi@42 125 $print .= "<td><a href='/cgi-bin/l3/current"."?login_from=192.168.15.254'>все</a></td>";
devi@42 126 $print .= "</tr>\n";
devi@42 127 $print .= "</table>\n";
devi@42 128 $print .= "</body>\n";
devi@42 129 $print .= "</html>\n";
devi@33 130 }
devi@31 131 elsif ($ENV{PATH_INFO} eq "/current") {
devi@31 132 open (FRONTEND, "./l3-frontend --output - --show_comments no |");
devi@31 133 while (<FRONTEND>) {
devi@43 134 $print .= $_;
devi@31 135 }
devi@31 136 close(FRONTEND);
devi@31 137 }
devi@30 138 else {
devi@30 139 # Вызов производится по URL
devi@30 140 my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4;
devi@29 141
devi@32 142 $l3config::Config{"class"}=$course if $course ne 'current';
devi@30 143 $XMLTraining = load_training;
devi@30 144
devi@30 145 my @args=(
devi@30 146 "--output" => "-",
devi@30 147 "--show_comments" => "no",
devi@30 148 "--course-center" => $XMLTraining->{center},
devi@30 149 "--course-trainer" => $XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname},
devi@30 150 "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname},
devi@30 151 "--course-code" => $XMLTraining->{course},
devi@30 152 "--course-date" => $XMLTraining->{date},
devi@31 153 "--encoding" => $XMLTraining->{host}->{$host}->{charset},
devi@30 154 );
devi@32 155 if ($course ne 'current') {
devi@32 156 push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml");
devi@32 157 } else {
devi@37 158 $filter{hostname} = $host if $host;
devi@37 159 $filter{user} = $user if $user;
devi@37 160 push @args, ("--filter" => join ("&", (map("$_=$filter{$_}", keys %filter))));
devi@37 161 #push @args, ("--filter" => "hostname=".$host."&user=".$user);
devi@32 162 }
devi@30 163
devi@30 164 open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |");
devi@30 165 while (<FRONTEND>) {
devi@42 166 $print .= $_;
devi@30 167 }
devi@30 168 close(FRONTEND);
devi@27 169 }
devi@27 170
devi@45 171 binmode STDOUT, ":utf8";
devi@42 172 print $print;