lilalo

view l3-cgi @ 43:a717ea245c90

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