lilalo
view l3-cgi @ 34:34f3ce44c365
lm-install:
Инсталляция запуска l3-agent в .bash_profile
Инсталляция запуска l3-agent в .bash_profile
| author | devi | 
|---|---|
| date | Mon Nov 14 09:17:49 2005 +0200 (2005-11-14) | 
| parents | 4d252e7dd478 | 
| children | 219389279acb | 
 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 $i (qw(host)) {
    15 	my $value = param("$i");
    16 	if ($value) {
    17 		push @filter, "$i=$value";
    18 	}
    19 }
    21 my %Trainings;
    22 my $XMLTraining;
    23 my %Machines;
    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 "<table>\n";
    55 		for my $tdate (reverse sort keys %Trainings) {
    56 			my $t = $Trainings{$tdate};
    57 			print "<tr>";
    58 			print "<td>".$t->{date}."</td>";
    59 			print "<td>".$t->{course}."</td>";
    60 			print "</tr>\n";
    61 			print "<tr>";
    62 			print "<td/>";
    63 			print "<td><pre>";
    64 			for my $host (sort keys %{$t->{host}}) {
    65 				my $h = $t->{host}->{$host};
    66 				print "$host";
    67 				print " ".$h->{firstname}." ".$h->{surname}." ";
    68 				print "<a href='/cgi-bin/l3/".$tdate."/".$host."/root'>root</a> ";
    69 				print "<a href='/cgi-bin/l3/".$tdate."/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
    70 				print "\n";
    71 			}
    72 			print "</pre><td>";
    73 			print "</tr>\n";
    74 		}
    75 		print "</table>\n";
    76 	}
    77 	else {
    78 		print "No training-files found<br/>\n";
    79 		print "Template to load files: ".$l3config::Config{"path_classes"}."*".$l3config::Config{"class_suffix"}."\n"
    80 	}
    81 }
    82 elsif ($ENV{PATH_INFO} eq "/current/index" || $ENV{PATH_INFO} eq "") {
    83 	my $t = load_training();
    84 	for my $host (sort keys %{$t->{host}}) {
    85 		my $h = $t->{host}->{$host};
    86 		print "$host";
    87 		print " ".$h->{firstname}." ".$h->{surname}." ";
    88 		print "<a href='/cgi-bin/l3/current/".$host."/root'>root</a> ";
    89 		print "<a href='/cgi-bin/l3/current/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
    90 		print "<br/>\n";
    91 	}
    92 }
    93 elsif ($ENV{PATH_INFO} eq "/current") {
    94 	open (FRONTEND, "./l3-frontend --output - --show_comments no |");
    95 	while (<FRONTEND>) {
    96 		print;
    97 	}
    98 	close(FRONTEND);
    99 }
   100 else {
   101 	# Вызов производится по URL
   102 	my ($skip, $course, $host, $user) = split /\//,$ENV{PATH_INFO},4;
   104 	$l3config::Config{"class"}=$course if $course ne 'current';
   105 	$XMLTraining = load_training;
   107 	my @args=(
   108 		"--output" 		=>	"-",
   109 		"--show_comments" 	=>	"no",
   110 		"--course-center"	=>	$XMLTraining->{center},
   111 		"--course-trainer"	=>	$XMLTraining->{instructor}->{firstname}." ".$XMLTraining->{instructor}->{surname},
   112 		"--course-student"	=>	$XMLTraining->{host}->{$host}->{firstname}." ".$XMLTraining->{host}->{$host}->{surname},
   113 		"--course-code"		=>	$XMLTraining->{course},
   114 		"--course-date"		=>	$XMLTraining->{date},
   115 		"--encoding"		=>	$XMLTraining->{host}->{$host}->{charset},
   116 	);
   117 	if ($course ne 'current') {
   118 		push @args, 	("--backend_datafile"	=>	"/var/lilalo/lablogs-xml/$course/$host/$user.xml");
   119 	} else {
   120 		push @args, ("--filter" => "hostname=".$host."&user=".$user);
   121 	}
   123 	open (FRONTEND, "./l3-frontend ".join(" ",map("\"$_\"",@args))." |");
   124 	while (<FRONTEND>) {
   125 		print;
   126 	}
   127 	close(FRONTEND);
   128 }
