lilalo
view l3-cgi @ 41:6452bfe549d1
Наброски для отправки письма после курса
author | devi |
---|---|
date | Tue Nov 22 23:27:51 2005 +0200 (2005-11-22) |
parents | aa788e638a9d |
children | 5499496e2462 |
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}}) {
104 my $prefix = "/cgi-bin/l3/current/";
105 my $suffix = "";
107 print "<tr>\n";
108 my $h = $t->{host}->{$host};
109 print "<td>".$h->{firstname}." ".$h->{surname}."</td>";
110 print "<td>$host</td>";
111 print "<td><a href='".$prefix.$host."/root$suffix'>root</a></td>";
112 print "<td><a href='".$prefix.$host."/".$h->{user}."$suffix'>".$h->{user}."</a></td>";
113 print "<td><a href='".$prefix.$host."$suffix'>все</a></td>";
114 print "</td>\n";
115 print "</tr>\n";
116 }
117 print "<tr>\n";
118 print "<td>"."Инструктор"."</td>";
119 print "<td>from linux.nt</td>";
120 print "<td/>";
121 print "<td/>";
122 print "<td><a href='/cgi-bin/l3/current"."?login_from=192.168.15.254'>все</a></td>";
123 print "</tr>\n";
124 print "</table>\n";
125 print "</body>\n";
126 print "</html>\n";
127 }
128 elsif ($ENV{PATH_INFO} eq "/current") {
129 open (FRONTEND, "./l3-frontend --output - --show_comments no |");
130 while (<FRONTEND>) {
131 print;
132 }
133 close(FRONTEND);
134 }
135 else {
136 # Вызов производится по URL
137 my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4;
139 $l3config::Config{"class"}=$course if $course ne 'current';
140 $XMLTraining = load_training;
142 my @args=(
143 "--output" => "-",
144 "--show_comments" => "no",
145 "--course-center" => $XMLTraining->{center},
146 "--course-trainer" => $XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname},
147 "--course-student" => $XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname},
148 "--course-code" => $XMLTraining->{course},
149 "--course-date" => $XMLTraining->{date},
150 "--encoding" => $XMLTraining->{host}->{$host}->{charset},
151 );
152 if ($course ne 'current') {
153 push @args, ("--backend_datafile" => "/var/lilalo/lablogs-xml/$course/$host/$user.xml");
154 } else {
155 $filter{hostname} = $host if $host;
156 $filter{user} = $user if $user;
157 push @args, ("--filter" => join ("&", (map("$_=$filter{$_}", keys %filter))));
158 #push @args, ("--filter" => "hostname=".$host."&user=".$user);
159 }
161 open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |");
162 while (<FRONTEND>) {
163 print;
164 }
165 close(FRONTEND);
166 }