lilalo

view l3-cgi @ 32:4d252e7dd478

l3-frontend:
Добавлена поддержка фильтрации по пользователю (user) и хосту (hostname).
Пока только прототип - нужно оптимизировать.
И нужно стандартизировать имена для полей

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