lilalo

view l3-cgi @ 38:466bea239d25

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