lilalo

annotate l3-cgi @ 41:6452bfe549d1

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