lilalo
view l3-cgi @ 39:aa788e638a9d
l3: Добавил небольшое оформление и строчку "Инструтор" в индекс
lm-install: Убрал ошибочно закомментированный login_from для FreeBSD
lm-install: Убрал ошибочно закомментированный login_from для FreeBSD
author | devi |
---|---|
date | Tue Nov 22 22:45:45 2005 +0200 (2005-11-22) |
parents | 219389279acb |
children | 6452bfe549d1 |
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 "<html>\n";
52 print "<head>\n";
53 print "<title>Журналы лабораторных работ</title>\n";
54 print "</head>\n";
55 print "<body>\n";
56 print "<table>\n";
57 for my $tdate (reverse sort keys %Trainings) {
58 my $t = $Trainings{$tdate};
59 print "<tr>";
60 print "<td>".$t->{date}."</td>";
61 print "<td>".$t->{course}."</td>";
62 print "</tr>\n";
63 print "<tr>";
64 print "<td/>";
65 print "<td><pre>";
66 for my $host (sort keys %{$t->{host}}) {
67 my $h = $t->{host}->{$host};
68 print "$host";
69 print " ".$h->{firstname}." ".$h->{surname}." ";
70 print "<a href='/cgi-bin/l3/".$tdate."/".$host."/root'>root</a> ";
71 print "<a href='/cgi-bin/l3/".$tdate."/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
72 print "\n";
73 }
74 print "</pre><td>";
75 print "</tr>\n";
76 }
77 print "</table>\n";
78 print "</body>\n";
79 print "</html>\n";
80 }
81 else {
82 print "No training-files found<br/>\n";
83 print "Template to load files: ".$l3config::Config{"path_classes"}."*".$l3config::Config{"class_suffix"}."\n"
84 }
85 }
86 elsif ($ENV{PATH_INFO} eq "/current/index" || $ENV{PATH_INFO} eq "") {
87 my $t = load_training();
89 print "<html>\n";
90 print "<head>\n";
91 print "<title>Журналы лабораторных работ</title>\n";
92 print "<link rel='stylesheet' href='".$l3config::Config{frontend_css}."' type='text/css'/>\n";
93 print "</head>\n";
94 print "<body>\n";
95 print "<h1>Журналы лабораторных работ</h1>\n";
96 print "<table>\n";
97 print "<tr class='table_header'>\n";
98 print "<td>"."Имя"."</td>";
99 print "<td>Хост</td>";
100 print "<td colspan='3'>Пользователь</td>";
101 print "</tr>\n";
102 for my $host (sort keys %{$t->{host}}) {
103 print "<tr>\n";
104 my $h = $t->{host}->{$host};
105 print "<td>".$h->{firstname}." ".$h->{surname}."</td>";
106 print "<td>$host</td>";
107 print "<td><a href='/cgi-bin/l3/current/".$host."/root'>root</a></td>";
108 print "<td><a href='/cgi-bin/l3/current/".$host."/".$h->{user}."'>".$h->{user}."</a></td>";
109 print "<td><a href='/cgi-bin/l3/current/".$host."'>все</a></td>";
110 print "</td>\n";
111 print "</tr>\n";
112 }
113 print "<tr>\n";
114 print "<td>"."Инструктор"."</td>";
115 print "<td>from linux.nt</td>";
116 print "<td/>";
117 print "<td/>";
118 print "<td><a href='/cgi-bin/l3/current"."?login_from=192.168.15.254'>все</a></td>";
119 print "</tr>\n";
120 print "</table>\n";
121 print "</body>\n";
122 print "</html>\n";
123 }
124 elsif ($ENV{PATH_INFO} eq "/current") {
125 open (FRONTEND, "./l3-frontend --output - --show_comments no |");
126 while (<FRONTEND>) {
127 print;
128 }
129 close(FRONTEND);
130 }
131 else {
132 # Вызов производится по URL
133 my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4;
135 $l3config::Config{"class"}=$course if $course ne 'current';
136 $XMLTraining = load_training;
138 my @args=(
139 "--output" => "-",
140 "--show_comments" => "no",
141 "--course-center" => $XMLTraining->{center},
142 "--course-trainer" => $XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname},
143 "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname},
144 "--course-code" => $XMLTraining->{course},
145 "--course-date" => $XMLTraining->{date},
146 "--encoding" => $XMLTraining->{host}->{$host}->{charset},
147 );
148 if ($course ne 'current') {
149 push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml");
150 } else {
151 $filter{hostname} = $host if $host;
152 $filter{user} = $user if $user;
153 push @args, ("--filter" => join ("&", (map("$_=$filter{$_}", keys %filter))));
154 #push @args, ("--filter" => "hostname=".$host."&user=".$user);
155 }
157 open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |");
158 while (<FRONTEND>) {
159 print;
160 }
161 close(FRONTEND);
162 }