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