lilalo

changeset 92:db51b62442ac

Написан прототип lm get
author devi
date Sat Apr 22 17:08:05 2006 +0300 (2006-04-22)
parents d3182b751893
children 45196265d30e
files lm
line diff
     1.1 --- a/lm	Mon Mar 06 10:22:13 2006 +0200
     1.2 +++ b/lm	Sat Apr 22 17:08:05 2006 +0300
     1.3 @@ -15,42 +15,42 @@
     1.4  our $XMLCourse;
     1.5  our @Labs;
     1.6  
     1.7 -our %Machines;			# Machines list from class.xml
     1.8 -our @SelectedMachines;		# Machines list given as the command line argument
     1.9 +our %Machines;          # Machines list from class.xml
    1.10 +our @SelectedMachines;      # Machines list given as the command line argument
    1.11  
    1.12  our $Config_File = "labmaker.conf";
    1.13  our %Config_ = (
    1.14 -	"show_host" 	=> "no",
    1.15 +    "show_host"     => "no",
    1.16  
    1.17 -	# Вспомогательные программы
    1.18 -	#"l3-report"	=> "./lm-report",
    1.19 -	"l3-report"	=> "./l3-report",
    1.20 +    # Вспомогательные программы
    1.21 +    #"l3-report"    => "./lm-report",
    1.22 +    "l3-report" => "./l3-report",
    1.23  
    1.24 -	# Каталоги
    1.25 -	"path_lilalo" => "/var/lilalo/",
    1.26 -	"path_classes"	=> "/var/lilalo/classes/",
    1.27 -	"path_lablogs"	=> "/var/lilalo/lablogs/",
    1.28 -	"courses_path"	=> "/var/lilalo/courses/",
    1.29 -	"outpath"	=> "/var/lilalo/out/",
    1.30 -	"path_web"	=> "/var/www/l3",		# Путь к web-отчётам
    1.31 -	"path_share"	=> "./share/",		# Путь к web-отчётам
    1.32 +    # Каталоги
    1.33 +    "path_lilalo" => "/var/lilalo/",
    1.34 +    "path_classes"  => "/var/lilalo/classes/",
    1.35 +    "path_lablogs"  => "/var/lilalo/lablogs/",
    1.36 +    "courses_path"  => "/var/lilalo/courses/",
    1.37 +    "outpath"   => "/var/lilalo/out/",
    1.38 +    "path_web"  => "/var/www/l3",       # Путь к web-отчётам
    1.39 +    "path_share"    => "./share/",      # Путь к web-отчётам
    1.40  
    1.41 -	# Файлы
    1.42 -	"runfile"	=> "lm.run", 
    1.43 -	"logfile"	=> "lm.log", 
    1.44 +    # Файлы
    1.45 +    "runfile"   => "lm.run", 
    1.46 +    "logfile"   => "lm.log", 
    1.47  
    1.48 -	"class" 	=> "class", 				# Имя файла класса
    1.49 -	"class_suffix" 	=> ".xml", 				# Cуффикс файла класса
    1.50 -	"classfile"	=> "",
    1.51 +    "class"     => "class",                 # Имя файла класса
    1.52 +    "class_suffix"  => ".xml",              # Cуффикс файла класса
    1.53 +    "classfile" => "",
    1.54  
    1.55 -	"sshkey"	=> "$ENV{HOME}/.ssh/id_dsa.pub",
    1.56 -	"lmssh"		=> "./lm-ssh",
    1.57 -	"lminstall"	=> "./lm-install",
    1.58 -	"ssh_user"	=> "root",
    1.59 +    "sshkey"    => "$ENV{HOME}/.ssh/id_dsa.pub",
    1.60 +    "lmssh"     => "./lm-ssh",
    1.61 +    "lminstall" => "./lm-install",
    1.62 +    "ssh_user"  => "root",
    1.63  );
    1.64  
    1.65  our %Run = (
    1.66 -	"lab" => ""
    1.67 +    "lab" => ""
    1.68  );
    1.69  
    1.70  our %Scripts;
    1.71 @@ -60,6 +60,7 @@
    1.72  sub load_course;
    1.73  sub load_scripts;
    1.74  
    1.75 +sub lm_get;
    1.76  sub lm_next;
    1.77  sub lm_prev;
    1.78  sub lm_start;
    1.79 @@ -81,282 +82,300 @@
    1.80  
    1.81  sub main()
    1.82  {
    1.83 -	binmode STDOUT, ":utf8";
    1.84 +    binmode STDOUT, ":utf8";
    1.85  
    1.86 -	if (! @ARGV) {
    1.87 -		print_usage_info();
    1.88 -		exit(0);
    1.89 -	}
    1.90 +    if (! @ARGV) {
    1.91 +        print_usage_info();
    1.92 +        exit(0);
    1.93 +    }
    1.94  
    1.95 -	init_config();
    1.96 -	#load_config;
    1.97 -	load_run;
    1.98 -	load_scripts;
    1.99 -	load_class;
   1.100 -	load_course;
   1.101 -	
   1.102 -	my $arg = join " ", @ARGV;
   1.103 +    if ($ARGV[0] eq "get") {
   1.104 +         print "argv= ".$ARGV[0]."ZLO\n";
   1.105 +         lm_get;
   1.106 +         exit(0);
   1.107 +    }
   1.108  
   1.109 -	# Getting @SelectedMachines if any
   1.110 -	if ($arg =~ s/@(.*?)\s//) {
   1.111 -		my $machines = $1;
   1.112 -		my @list = split /,/, $machines;
   1.113 -		for my $interval (@list) {
   1.114 -			my ($first, $last) = split /-/, $interval;
   1.115 +    init_config();
   1.116 +    #load_config;
   1.117 +    load_run;
   1.118 +    load_scripts;
   1.119 +    load_class;
   1.120 +    load_course;
   1.121 +    
   1.122 +    my $arg = join " ", @ARGV;
   1.123  
   1.124 -			push @SelectedMachines, $first;
   1.125 -			while ($first < $last) {
   1.126 -				push @SelectedMachines, ++$first;
   1.127 -			}	
   1.128 -		}
   1.129 -	}
   1.130 +    # Getting @SelectedMachines if any
   1.131 +    if ($arg =~ s/@(.*?)\s//) {
   1.132 +        my $machines = $1;
   1.133 +        my @list = split /,/, $machines;
   1.134 +        for my $interval (@list) {
   1.135 +            my ($first, $last) = split /-/, $interval;
   1.136  
   1.137 -	# Choose command to do
   1.138 -	switch ($arg) {
   1.139 -		case "next"	{ lm_next }
   1.140 -		case "prev"	{ lm_prev }
   1.141 -		case /set /	{ $arg =~ /set (.*)/; lm_set $1 }
   1.142 -		case "report"	{ lm_report }
   1.143 -		case "start"	{ lm_start }
   1.144 -		case "stop"	{ lm_stop }
   1.145 -		case "show hosts" { lm_show_hosts }
   1.146 -		case "show email" { lm_show_email }
   1.147 -		case "show labs" { lm_show_labs }
   1.148 -		case /do /  { $arg =~ /do (.*)/;  lm_do "$1" }
   1.149 -		else 		{ print_usage_info() }
   1.150 -	}
   1.151 -	save_run;
   1.152 -	exit(0);
   1.153 +            push @SelectedMachines, $first;
   1.154 +            while ($first < $last) {
   1.155 +                push @SelectedMachines, ++$first;
   1.156 +            }   
   1.157 +        }
   1.158 +    }
   1.159 +
   1.160 +    # Choose command to do
   1.161 +    switch ($arg) {
   1.162 +        case "next" { lm_next }
   1.163 +        case "prev" { lm_prev }
   1.164 +        case /set / { $arg =~ /set (.*)/; lm_set $1 }
   1.165 +        case "report"   { lm_report }
   1.166 +        case "start"    { lm_start }
   1.167 +        case "stop" { lm_stop }
   1.168 +        case "show hosts" { lm_show_hosts }
   1.169 +        case "show email" { lm_show_email }
   1.170 +        case "show labs" { lm_show_labs }
   1.171 +        case /do /  { $arg =~ /do (.*)/;  lm_do "$1" }
   1.172 +        else        { print_usage_info() }
   1.173 +    }
   1.174 +    save_run;
   1.175 +    exit(0);
   1.176  }
   1.177  
   1.178  sub load_scripts
   1.179  {
   1.180 -	open (SCRIPTS, "$Config{l3scripts}")
   1.181 -		or die "Cant open l3scripts file: ".$Config{l3scripts}.": $!\n";
   1.182 -	binmode SCRIPTS, ":utf8";
   1.183 -	local $/;
   1.184 -	$_=<SCRIPTS>;
   1.185 -	close(SCRIPTS);
   1.186 +    open (SCRIPTS, "$Config{l3scripts}")
   1.187 +        or die "Cant open l3scripts file: ".$Config{l3scripts}.": $!\n";
   1.188 +    binmode SCRIPTS, ":utf8";
   1.189 +    local $/;
   1.190 +    $_=<SCRIPTS>;
   1.191 +    close(SCRIPTS);
   1.192  
   1.193 -	%Scripts = ("empty-element", split (/###(.*)\n/));
   1.194 -	delete($Scripts{"empty-element"});
   1.195 +    %Scripts = ("empty-element", split (/###(.*)\n/));
   1.196 +    delete($Scripts{"empty-element"});
   1.197  
   1.198  }
   1.199  
   1.200  sub load_config
   1.201  {
   1.202 -	my %file_config;
   1.203 -	my %argv_config;
   1.204 -	#read_config_file(\%file_config, $Config_File);
   1.205 -	GetOptions(\%argv_config, map "$_=s", keys %Config);
   1.206 -	%Config = (%Config, %file_config, %argv_config);
   1.207 +    my %file_config;
   1.208 +    my %argv_config;
   1.209 +    #read_config_file(\%file_config, $Config_File);
   1.210 +    GetOptions(\%argv_config, map "$_=s", keys %Config);
   1.211 +    %Config = (%Config, %file_config, %argv_config);
   1.212  }
   1.213  
   1.214  sub load_course
   1.215  {
   1.216 -	$XMLCourse = XMLin($Config{"courses_path"}.$XMLClass->{"course"}.".xml", ForceArray => 1 )  
   1.217 -		or die "Can't open file of the course ",$XMLClass->{"course"}," [with .xml extension]\n";
   1.218 -#	print Dumper($XMLCourse);
   1.219 -	for my $lab (@{$XMLCourse->{"module"}}) {
   1.220 -		push @Labs, $lab->{"code"};
   1.221 -	}
   1.222 +    $XMLCourse = XMLin($Config{"courses_path"}.$XMLClass->{"course"}.".xml", ForceArray => 1 )  
   1.223 +        or die "Can't open file of the course ",$XMLClass->{"course"}," [with .xml extension]\n";
   1.224 +#   print Dumper($XMLCourse);
   1.225 +    for my $lab (@{$XMLCourse->{"module"}}) {
   1.226 +        push @Labs, $lab->{"code"};
   1.227 +    }
   1.228  }
   1.229  
   1.230  sub load_class
   1.231  {
   1.232 -	my $classfile =
   1.233 -	$Config{"classfile"} || 
   1.234 -	$Config{"path_classes"}."/".$Config{"class"}.$Config{"class_suffix"};
   1.235 -	$XMLClass = XMLin($classfile , ForceArray => [ 'student' ] )  
   1.236 -		or die "Can't open file of the class ",$classfile,"\n";
   1.237 +    my $classfile =
   1.238 +    $Config{"classfile"} || 
   1.239 +    $Config{"path_classes"}."/".$Config{"class"}.$Config{"class_suffix"};
   1.240 +    $XMLClass = XMLin($classfile , ForceArray => [ 'student' ] )  
   1.241 +        or die "Can't open file of the class ",$classfile,"\n";
   1.242  
   1.243 -	for my $student (@{$XMLClass->{"student"}}) {
   1.244 -		$Machines{$student->{"host"}} = {
   1.245 -			"name"	=> "$student->{firstname} $student->{surname}",
   1.246 -			"firstname"	=> "$student->{firstname}",
   1.247 -			"user"	=> "$student->{user}",
   1.248 -			"email"	=> "$student->{email}",
   1.249 -			"student" => $student,
   1.250 -		}	
   1.251 -	}
   1.252 -#	print Dumper($XMLClass);
   1.253 -#	print Dumper(\%Machines);
   1.254 +    for my $student (@{$XMLClass->{"student"}}) {
   1.255 +        $Machines{$student->{"host"}} = {
   1.256 +            "name"  => "$student->{firstname} $student->{surname}",
   1.257 +            "firstname" => "$student->{firstname}",
   1.258 +            "user"  => "$student->{user}",
   1.259 +            "email" => "$student->{email}",
   1.260 +            "student" => $student,
   1.261 +        }   
   1.262 +    }
   1.263 +#   print Dumper($XMLClass);
   1.264 +#   print Dumper(\%Machines);
   1.265 +}
   1.266 +
   1.267 +sub lm_get
   1.268 +{
   1.269 +    print "Getting class description file...";
   1.270 +    if (system("cd $Config{path_classes}; wget -r xgu.ru/l3/classes/class.xml") ==0 )
   1.271 +    {
   1.272 +        print "Ok\n";
   1.273 +    } 
   1.274 +    else {
   1.275 +        die "Can't load class file\n"
   1.276 +    }
   1.277  }
   1.278  
   1.279  
   1.280  sub lm_next
   1.281  {
   1.282 -	for(my $i=0; $i<=$#Labs; $i++){
   1.283 -		if ( $Labs[$i] eq $Run{"lab"} ) {
   1.284 -			if ($i < $#Labs) {
   1.285 -				lm_set($Labs[$i+1]);
   1.286 -				return ;
   1.287 -			} else {
   1.288 -				die "Lab ", $Run{"lab"}, " is the last. Switch to next lab is impossible"
   1.289 -			}
   1.290 -		}
   1.291 -		
   1.292 -	}
   1.293 -	die "Lab ", $Run{"lab"}, " not found. Don't know which is next"
   1.294 +    for(my $i=0; $i<=$#Labs; $i++){
   1.295 +        if ( $Labs[$i] eq $Run{"lab"} ) {
   1.296 +            if ($i < $#Labs) {
   1.297 +                lm_set($Labs[$i+1]);
   1.298 +                return ;
   1.299 +            } else {
   1.300 +                die "Lab ", $Run{"lab"}, " is the last. Switch to next lab is impossible"
   1.301 +            }
   1.302 +        }
   1.303 +        
   1.304 +    }
   1.305 +    die "Lab ", $Run{"lab"}, " not found. Don't know which is next"
   1.306  }
   1.307  
   1.308  sub lm_prev
   1.309  # Switch to previous lab
   1.310  {
   1.311 -	for(my $i=0; $i<=$#Labs; $i++){
   1.312 -		if ( $Labs[$i] eq $Run{"lab"} ) {
   1.313 -			if ($i > 0) {
   1.314 -				lm_set($Labs[$i-1]);
   1.315 -				return ;
   1.316 -			} else {
   1.317 -				die "Lab ", $Run{"lab"}, " is the first. Switch to previous lab is impossible"
   1.318 -			}
   1.319 -		}
   1.320 -		
   1.321 -	}
   1.322 -	die "Lab ", $Run{"lab"}, " not found. Don't know which is previous"
   1.323 +    for(my $i=0; $i<=$#Labs; $i++){
   1.324 +        if ( $Labs[$i] eq $Run{"lab"} ) {
   1.325 +            if ($i > 0) {
   1.326 +                lm_set($Labs[$i-1]);
   1.327 +                return ;
   1.328 +            } else {
   1.329 +                die "Lab ", $Run{"lab"}, " is the first. Switch to previous lab is impossible"
   1.330 +            }
   1.331 +        }
   1.332 +        
   1.333 +    }
   1.334 +    die "Lab ", $Run{"lab"}, " not found. Don't know which is previous"
   1.335  }
   1.336  
   1.337  sub lm_set
   1.338  # Switch to $_[0] lab
   1.339  # FIXME
   1.340  {
   1.341 -	my $lab = shift;
   1.342 -	print "Current lab is $lab\n";
   1.343 -	$Run{"lab"} = "$lab";
   1.344 -	lm_do "setlab", $lab;
   1.345 +    my $lab = shift;
   1.346 +    print "Current lab is $lab\n";
   1.347 +    $Run{"lab"} = "$lab";
   1.348 +    lm_do "setlab", $lab;
   1.349  }
   1.350  
   1.351  
   1.352  sub lm_start
   1.353  # Start new training day
   1.354  {
   1.355 -	print_log(`date`." STARTED\n");
   1.356 -	if ($Run{"lab"}) {
   1.357 -		lm_next;
   1.358 -	}
   1.359 -	else
   1.360 -	{
   1.361 -		# First lab in the course
   1.362 -		lm_set($Labs[0]);
   1.363 -	}
   1.364 +    print_log(`date`." STARTED\n");
   1.365 +    if ($Run{"lab"}) {
   1.366 +        lm_next;
   1.367 +    }
   1.368 +    else
   1.369 +    {
   1.370 +        # First lab in the course
   1.371 +        lm_set($Labs[0]);
   1.372 +    }
   1.373  }
   1.374  
   1.375  sub lm_stop
   1.376  # Stop this training day
   1.377  {
   1.378 -	print_log(`date`." STOPPED\n");
   1.379 +    print_log(`date`." STOPPED\n");
   1.380  }
   1.381  
   1.382  
   1.383  sub lm_show_hosts
   1.384  # Show hosts used to run a commands
   1.385  {
   1.386 -	my $i=1;
   1.387 -	for my $m (sort keys %Machines) {
   1.388 -		if (!@SelectedMachines || grep /^$i$/, @SelectedMachines) {
   1.389 -			print "($i)","\t",$m,"\t",$Machines{$m}->{"name"},"\n";
   1.390 -		}	
   1.391 -		$i++;
   1.392 -	}
   1.393 +    my $i=1;
   1.394 +    for my $m (sort keys %Machines) {
   1.395 +        if (!@SelectedMachines || grep /^$i$/, @SelectedMachines) {
   1.396 +            print "($i)","\t",$m,"\t",$Machines{$m}->{"name"},"\n";
   1.397 +        }   
   1.398 +        $i++;
   1.399 +    }
   1.400  }
   1.401  
   1.402  sub lm_show_email
   1.403  # Show hosts used to run a commands
   1.404  {
   1.405 -	my $i=1;
   1.406 -	for my $m (sort keys %Machines) {
   1.407 -		if (!@SelectedMachines || grep /^$i$/, @SelectedMachines) {
   1.408 -			print $Machines{$m}->{"email"},"\t",$Machines{$m}->{"name"},"\n";
   1.409 -		}	
   1.410 -		$i++;
   1.411 -	}
   1.412 +    my $i=1;
   1.413 +    for my $m (sort keys %Machines) {
   1.414 +        if (!@SelectedMachines || grep /^$i$/, @SelectedMachines) {
   1.415 +            print $Machines{$m}->{"email"},"\t",$Machines{$m}->{"name"},"\n";
   1.416 +        }   
   1.417 +        $i++;
   1.418 +    }
   1.419  }
   1.420  
   1.421  sub lm_show_labs
   1.422  # Show hosts used to run a commands
   1.423  {
   1.424 -	my $i=1;
   1.425 -	for my $lab (@Labs) {
   1.426 -		print $lab;
   1.427 -		print "*" if $lab eq $Run{"lab"};
   1.428 -		print "\n";
   1.429 -	}
   1.430 +    my $i=1;
   1.431 +    for my $lab (@Labs) {
   1.432 +        print $lab;
   1.433 +        print "*" if $lab eq $Run{"lab"};
   1.434 +        print "\n";
   1.435 +    }
   1.436  }
   1.437  
   1.438  sub lm_do
   1.439  # Do the $_[0] command on all of the hosts 
   1.440  {
   1.441 -	my $command = shift;
   1.442 -	my $arg = join " ", @_;
   1.443 -	my $i=1;
   1.444 +    my $command = shift;
   1.445 +    my $arg = join " ", @_;
   1.446 +    my $i=1;
   1.447  
   1.448 -	my %myenv = ( %Config, 
   1.449 -				lab	=> 	$arg,			
   1.450 -				center 	=>	$XMLClass->{"center"},
   1.451 -				course 	=>	$XMLClass->{"course"},
   1.452 -				date 	=>	$XMLClass->{"date"},
   1.453 -				stopdate 	=>	$XMLClass->{"stop-date"},
   1.454 -				instructor 	=>	$XMLClass->{"instructor"}->{"firstname"}." ".$XMLClass->{"instructor"}->{"surname"},
   1.455 -				manager 	=>	$XMLClass->{"manager"}->{"firstname"}." ".$XMLClass->{"manager"}->{"surname"},
   1.456 -				coursepath =>	$XMLCourse->{"path"},
   1.457 -			);
   1.458 +    my %myenv = ( %Config, 
   1.459 +                lab =>  $arg,           
   1.460 +                center  =>  $XMLClass->{"center"},
   1.461 +                course  =>  $XMLClass->{"course"},
   1.462 +                date    =>  $XMLClass->{"date"},
   1.463 +                stopdate    =>  $XMLClass->{"stop-date"},
   1.464 +                instructor  =>  $XMLClass->{"instructor"}->{"firstname"}." ".$XMLClass->{"instructor"}->{"surname"},
   1.465 +                manager     =>  $XMLClass->{"manager"}->{"firstname"}." ".$XMLClass->{"manager"}->{"surname"},
   1.466 +                coursepath =>   $XMLCourse->{"path"},
   1.467 +            );
   1.468  
   1.469 -	if (grep { $_ eq "PRE-$command"} keys %Scripts) {
   1.470 -		$_=$Scripts{"PRE-$command"};
   1.471 -		s/\$(\w+)/$myenv{$1}/ge;
   1.472 -		open(SHELL, "|/bin/sh -s");
   1.473 -		binmode SHELL, ":utf8";
   1.474 -		print SHELL $_;
   1.475 -		close (SHELL);
   1.476 -	}
   1.477 +    if (grep { $_ eq "PRE-$command"} keys %Scripts) {
   1.478 +        $_=$Scripts{"PRE-$command"};
   1.479 +        s/\$(\w+)/$myenv{$1}/ge;
   1.480 +        open(SHELL, "|/bin/sh -s");
   1.481 +        binmode SHELL, ":utf8";
   1.482 +        print SHELL $_;
   1.483 +        close (SHELL);
   1.484 +    }
   1.485  
   1.486  
   1.487 -	for my $m (sort keys %Machines) {
   1.488 -		if (!@SelectedMachines || grep $_ eq $i, @SelectedMachines) {
   1.489 -			print "$m:\n" if $Config{"show_host"} =~ /y/i;
   1.490 +    for my $m (sort keys %Machines) {
   1.491 +        if (!@SelectedMachines || grep $_ eq $i, @SelectedMachines) {
   1.492 +            print "$m:\n" if $Config{"show_host"} =~ /y/i;
   1.493  
   1.494 -			%myenv = ( %myenv,
   1.495 -				host 	=>	$m,
   1.496 -				ipaddress	=> 	$Machines{$m}->{"ipaddress"},
   1.497 -				dirs	=>	"/root /home/".$Machines{$m}->{"user"},
   1.498 -				lablogs =>	$Config{"path_lablogs"}."/".
   1.499 -						$XMLClass->{"course"}."/".
   1.500 -						$XMLClass->{"date"}."/".
   1.501 -						"$m",
   1.502 -				email	=>	$Machines{$m}->{"student"}->{"email"},
   1.503 -				company	=>	$Machines{$m}->{"student"}->{"company"},
   1.504 -				name	=> 	$Machines{$m}->{"name"},
   1.505 -				firstname	=> 	$Machines{$m}->{"firstname"},
   1.506 -			);
   1.507 -			if (grep { $_ eq $command} keys %Scripts) {
   1.508 -				$_=$Scripts{"$command"};
   1.509 -				s/\$(\w+)/$myenv{$1}/ge;
   1.510 -				open(SHELL, "|/bin/sh -s");
   1.511 -				binmode SHELL, ":utf8";
   1.512 -				print SHELL $_;
   1.513 -				close (SHELL);
   1.514 -			}
   1.515 -			else {
   1.516 -				my $res = `ssh $Config{"ssh_user"}\@$m $command`;
   1.517 -				if ($res) {
   1.518 -					my $count = ($res =~ s/(^)/$m: /mg);
   1.519 -					print $res;
   1.520 -					print "\n" if ($count > 1);
   1.521 -				}
   1.522 -			}	
   1.523 -		}	
   1.524 -		$i++;
   1.525 -	}
   1.526 +            %myenv = ( %myenv,
   1.527 +                host    =>  $m,
   1.528 +                ipaddress   =>  $Machines{$m}->{"ipaddress"},
   1.529 +                dirs    =>  "/root /home/".$Machines{$m}->{"user"},
   1.530 +                lablogs =>  $Config{"path_lablogs"}."/".
   1.531 +                        $XMLClass->{"course"}."/".
   1.532 +                        $XMLClass->{"date"}."/".
   1.533 +                        "$m",
   1.534 +                email   =>  $Machines{$m}->{"student"}->{"email"},
   1.535 +                company =>  $Machines{$m}->{"student"}->{"company"},
   1.536 +                name    =>  $Machines{$m}->{"name"},
   1.537 +                firstname   =>  $Machines{$m}->{"firstname"},
   1.538 +            );
   1.539 +            if (grep { $_ eq $command} keys %Scripts) {
   1.540 +                $_=$Scripts{"$command"};
   1.541 +                s/\$(\w+)/$myenv{$1}/ge;
   1.542 +                open(SHELL, "|/bin/sh -s");
   1.543 +                binmode SHELL, ":utf8";
   1.544 +                print SHELL $_;
   1.545 +                close (SHELL);
   1.546 +            }
   1.547 +            else {
   1.548 +                my $res = `ssh $Config{"ssh_user"}\@$m $command`;
   1.549 +                if ($res) {
   1.550 +                    my $count = ($res =~ s/(^)/$m: /mg);
   1.551 +                    print $res;
   1.552 +                    print "\n" if ($count > 1);
   1.553 +                }
   1.554 +            }   
   1.555 +        }   
   1.556 +        $i++;
   1.557 +    }
   1.558  
   1.559 -	if (grep { $_ eq "POST-$command"} keys %Scripts) {
   1.560 -		$_=$Scripts{"POST-$command"};
   1.561 -		s/\$(\w+)/$myenv{$1}/ge;
   1.562 -		open(SHELL, "|/bin/sh -s");
   1.563 -		binmode SHELL, ":utf8";
   1.564 -		print SHELL $_;
   1.565 -		close (SHELL);
   1.566 -	}
   1.567 +    if (grep { $_ eq "POST-$command"} keys %Scripts) {
   1.568 +        $_=$Scripts{"POST-$command"};
   1.569 +        s/\$(\w+)/$myenv{$1}/ge;
   1.570 +        open(SHELL, "|/bin/sh -s");
   1.571 +        binmode SHELL, ":utf8";
   1.572 +        print SHELL $_;
   1.573 +        close (SHELL);
   1.574 +    }
   1.575  }
   1.576  
   1.577  
   1.578 @@ -373,163 +392,163 @@
   1.579  sub lm_report
   1.580  {
   1.581  
   1.582 -	my $webdir = $Config{"path_web"};
   1.583 -	my $course=$XMLClass->{"course"};
   1.584 -	my $date=$XMLClass->{"date"};
   1.585 -	my $encoding=$XMLClass->{"charset"};
   1.586 +    my $webdir = $Config{"path_web"};
   1.587 +    my $course=$XMLClass->{"course"};
   1.588 +    my $date=$XMLClass->{"date"};
   1.589 +    my $encoding=$XMLClass->{"charset"};
   1.590  
   1.591 -	my $center = $XMLClass->{"center"};
   1.592 -	my $instructor = $XMLClass->{"instructor"}->{"firstname"}." ".$XMLClass->{"instructor"}->{"surname"};
   1.593 -	my $course_name = $XMLCourse->{"fullname"}[0];
   1.594 +    my $center = $XMLClass->{"center"};
   1.595 +    my $instructor = $XMLClass->{"instructor"}->{"firstname"}." ".$XMLClass->{"instructor"}->{"surname"};
   1.596 +    my $course_name = $XMLCourse->{"fullname"}[0];
   1.597  
   1.598  
   1.599 -	# Собственно журналы
   1.600 +    # Собственно журналы
   1.601  
   1.602 -	for my $student (@{$XMLClass->{"student"}}) {
   1.603 -		my $user = $student->{"user"};
   1.604 -		my $hostname = $student->{"host"};
   1.605 -		my $encoding = $student->{"charset"};
   1.606 -		my $student_name = $student->{"firstname"}." ".$student->{"surname"};
   1.607 +    for my $student (@{$XMLClass->{"student"}}) {
   1.608 +        my $user = $student->{"user"};
   1.609 +        my $hostname = $student->{"host"};
   1.610 +        my $encoding = $student->{"charset"};
   1.611 +        my $student_name = $student->{"firstname"}." ".$student->{"surname"};
   1.612  
   1.613 -		system("mkdir -p $webdir/$date/$hostname");
   1.614 -		system("cp ".$Config{"path_share"}."/*.{ico,css} $webdir/$date/$hostname");
   1.615 -		system($Config{"l3-report"}.
   1.616 -			" --input ".$Config{"path_lablogs"}."/$course/$date/$hostname/$user".
   1.617 -			" --diffs ".$Config{"path_lablogs"}."/$course/$date/$hostname/$user ".
   1.618 -				   $Config{"path_lablogs"}."/$course/$date/$hostname/root".
   1.619 -			" --output $webdir/$date/$hostname/$user.html".
   1.620 -			" --course-name '$course_name'".
   1.621 -			" --course-code '$course'".
   1.622 -			" --course-date '$date'".
   1.623 -			" --course-center '$center'".
   1.624 -			" --course-student '$student_name'".
   1.625 -			" --course-trainer '$instructor'".
   1.626 -			" --encoding $encoding"
   1.627 -		);
   1.628 -		system($Config{"l3-report"}.
   1.629 -			" --input ".$Config{"path_lablogs"}."/$course/$date/$hostname/root".
   1.630 -			" --diffs ".$Config{"path_lablogs"}."/$course/$date/$hostname/root ".
   1.631 -			" --output $webdir/$date/$hostname/root.html".
   1.632 -			" --course-name '$course_name'".
   1.633 -			" --course-code '$course'".
   1.634 -			" --course-date '$date'".
   1.635 -			" --course-center '$center'".
   1.636 -			" --course-student '$student_name'".
   1.637 -			" --course-trainer '$instructor'".
   1.638 -			" --encoding $encoding"
   1.639 -		);
   1.640 -	}
   1.641 +        system("mkdir -p $webdir/$date/$hostname");
   1.642 +        system("cp ".$Config{"path_share"}."/*.{ico,css} $webdir/$date/$hostname");
   1.643 +        system($Config{"l3-report"}.
   1.644 +            " --input ".$Config{"path_lablogs"}."/$course/$date/$hostname/$user".
   1.645 +            " --diffs ".$Config{"path_lablogs"}."/$course/$date/$hostname/$user ".
   1.646 +                   $Config{"path_lablogs"}."/$course/$date/$hostname/root".
   1.647 +            " --output $webdir/$date/$hostname/$user.html".
   1.648 +            " --course-name '$course_name'".
   1.649 +            " --course-code '$course'".
   1.650 +            " --course-date '$date'".
   1.651 +            " --course-center '$center'".
   1.652 +            " --course-student '$student_name'".
   1.653 +            " --course-trainer '$instructor'".
   1.654 +            " --encoding $encoding"
   1.655 +        );
   1.656 +        system($Config{"l3-report"}.
   1.657 +            " --input ".$Config{"path_lablogs"}."/$course/$date/$hostname/root".
   1.658 +            " --diffs ".$Config{"path_lablogs"}."/$course/$date/$hostname/root ".
   1.659 +            " --output $webdir/$date/$hostname/root.html".
   1.660 +            " --course-name '$course_name'".
   1.661 +            " --course-code '$course'".
   1.662 +            " --course-date '$date'".
   1.663 +            " --course-center '$center'".
   1.664 +            " --course-student '$student_name'".
   1.665 +            " --course-trainer '$instructor'".
   1.666 +            " --encoding $encoding"
   1.667 +        );
   1.668 +    }
   1.669  
   1.670 -	# Индекс для данного класса
   1.671 +    # Индекс для данного класса
   1.672  
   1.673 -	my $head;
   1.674 +    my $head;
   1.675  
   1.676 -	$head="Журналы лабораторных работ";
   1.677 -	open(HTML, ">$webdir/$date/index.html")
   1.678 -		or die "Can't open $webdir/$date/index.html for writing";
   1.679 -	binmode HTML, ":utf8";
   1.680 -	print HTML <<HEAD;
   1.681 -	<html>
   1.682 -	<head>
   1.683 -	<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
   1.684 -	<title>$head</title>
   1.685 -	</head>
   1.686 -	<body>
   1.687 -	<h1>$head</h1>
   1.688 -	<p>
   1.689 -	Курс: $course_name ($course)<br/>
   1.690 -	Начало: $date<br/>
   1.691 -	Учебный центр: $center <br/>
   1.692 -	Инструктор: $instructor <br/>
   1.693 -	</p>
   1.694 -	<table>
   1.695 +    $head="Журналы лабораторных работ";
   1.696 +    open(HTML, ">$webdir/$date/index.html")
   1.697 +        or die "Can't open $webdir/$date/index.html for writing";
   1.698 +    binmode HTML, ":utf8";
   1.699 +    print HTML <<HEAD;
   1.700 +    <html>
   1.701 +    <head>
   1.702 +    <meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
   1.703 +    <title>$head</title>
   1.704 +    </head>
   1.705 +    <body>
   1.706 +    <h1>$head</h1>
   1.707 +    <p>
   1.708 +    Курс: $course_name ($course)<br/>
   1.709 +    Начало: $date<br/>
   1.710 +    Учебный центр: $center <br/>
   1.711 +    Инструктор: $instructor <br/>
   1.712 +    </p>
   1.713 +    <table>
   1.714  HEAD
   1.715 -	for my $student (@{$XMLClass->{"student"}}) {
   1.716 -		my $user = $student->{"user"};
   1.717 -		my $hostname = $student->{"host"};
   1.718 -		print HTML "<tr>\n";
   1.719 -		print HTML "<td>",$student->{"firstname"}," ",$student->{"surname"},"</td>\n";
   1.720 -		print HTML "<td>",$hostname,"</td>\n";
   1.721 -		print HTML "<td><a href=\"$hostname/$user.html\">",$user,"</td>\n";
   1.722 -		print HTML "<td><a href=\"$hostname/root.html\">","root","</td>\n";
   1.723 -		print HTML "</tr>\n";
   1.724 -	}
   1.725 -	print HTML <<TAIL;
   1.726 -	</table>
   1.727 -	</html>
   1.728 +    for my $student (@{$XMLClass->{"student"}}) {
   1.729 +        my $user = $student->{"user"};
   1.730 +        my $hostname = $student->{"host"};
   1.731 +        print HTML "<tr>\n";
   1.732 +        print HTML "<td>",$student->{"firstname"}," ",$student->{"surname"},"</td>\n";
   1.733 +        print HTML "<td>",$hostname,"</td>\n";
   1.734 +        print HTML "<td><a href=\"$hostname/$user.html\">",$user,"</td>\n";
   1.735 +        print HTML "<td><a href=\"$hostname/root.html\">","root","</td>\n";
   1.736 +        print HTML "</tr>\n";
   1.737 +    }
   1.738 +    print HTML <<TAIL;
   1.739 +    </table>
   1.740 +    </html>
   1.741  TAIL
   1.742 -	close (HTML);
   1.743 +    close (HTML);
   1.744  
   1.745 -	
   1.746 -	
   1.747 +    
   1.748 +    
   1.749  }
   1.750  
   1.751  sub load_run
   1.752  {
   1.753 -	my $runfile = $Config{"path_labmaker"}."/".$Config{"path_runfile"};
   1.754 -	open (RUN, $runfile)
   1.755 -		or return;
   1.756 -	while (<RUN>) {
   1.757 -		chomp;
   1.758 -		my ($var, $val) = split /\s+/,$_,2;
   1.759 -		$Run{$var}=$val;
   1.760 -	}
   1.761 -	close (RUN);	
   1.762 +    my $runfile = $Config{"path_labmaker"}."/".$Config{"path_runfile"};
   1.763 +    open (RUN, $runfile)
   1.764 +        or return;
   1.765 +    while (<RUN>) {
   1.766 +        chomp;
   1.767 +        my ($var, $val) = split /\s+/,$_,2;
   1.768 +        $Run{$var}=$val;
   1.769 +    }
   1.770 +    close (RUN);    
   1.771  }
   1.772  
   1.773  sub save_run
   1.774  {
   1.775 -	my $runfile = $Config{"path_labmaker"}."/".$Config{"path_runfile"};
   1.776 -	open (RN, "$runfile")
   1.777 -		or die "Can't save running state to $runfile";
   1.778 -	for my $var (keys %Run) {
   1.779 -		print RN $var,"\t",$Run{$var},"\n";
   1.780 -	}
   1.781 -	close (RN);	
   1.782 +    my $runfile = $Config{"path_labmaker"}."/".$Config{"path_runfile"};
   1.783 +    open (RN, "$runfile")
   1.784 +        or die "Can't save running state to $runfile";
   1.785 +    for my $var (keys %Run) {
   1.786 +        print RN $var,"\t",$Run{$var},"\n";
   1.787 +    }
   1.788 +    close (RN); 
   1.789  }
   1.790  
   1.791  sub print_log
   1.792  {
   1.793 -	my $logfile = $Config{"path_labmaker"}."/".$Config{"path_logfile"};
   1.794 -	open (LOG, ">>$logfile")
   1.795 -		or die "Can't open logfile $logfile for writing";
   1.796 -	print LOG  @_;
   1.797 -	close (LOG);	
   1.798 +    my $logfile = $Config{"path_labmaker"}."/".$Config{"path_logfile"};
   1.799 +    open (LOG, ">>$logfile")
   1.800 +        or die "Can't open logfile $logfile for writing";
   1.801 +    print LOG  @_;
   1.802 +    close (LOG);    
   1.803  }
   1.804  
   1.805  
   1.806  sub print_usage_info
   1.807  {
   1.808 -	print "Usage:\n\n\t$0 [host-list] command\n";
   1.809 -	print <<'USAGE';
   1.810 +    print "Usage:\n\n\t$0 [host-list] command\n";
   1.811 +    print <<'USAGE';
   1.812  
   1.813  Commands:
   1.814  
   1.815 -	next		-- next lab
   1.816 -	prev		-- prev lab
   1.817 -	set LAB		-- set current lab to LAB
   1.818 -	start		-- start this day training
   1.819 -	stop		-- stop this day training
   1.820 -	show hosts	-- show available hosts in the class
   1.821 -	show labs	-- show available labs in the course
   1.822 -	do COMMAND	-- do specified command on the hosts of hostlist
   1.823 -	report		-- generate XML/HTML reports
   1.824 +    next        -- next lab
   1.825 +    prev        -- prev lab
   1.826 +    set LAB     -- set current lab to LAB
   1.827 +    start       -- start this day training
   1.828 +    stop        -- stop this day training
   1.829 +    show hosts  -- show available hosts in the class
   1.830 +    show labs   -- show available labs in the course
   1.831 +    do COMMAND  -- do specified command on the hosts of hostlist
   1.832 +    report      -- generate XML/HTML reports
   1.833  
   1.834 -	
   1.835 +    
   1.836  do commands:
   1.837 -	
   1.838 -	install [PROFILE] -- install profile 
   1.839 -	
   1.840 -Host list:	
   1.841 +    
   1.842 +    install [PROFILE] -- install profile 
   1.843 +    
   1.844 +Host list:  
   1.845  
   1.846 -	@N		-- machine N
   1.847 -	@N1-N2		-- all of the machines from N1 to N2
   1.848 -	@N1,N2,N3	-- machine N1, N2 and N3
   1.849 +    @N      -- machine N
   1.850 +    @N1-N2      -- all of the machines from N1 to N2
   1.851 +    @N1,N2,N3   -- machine N1, N2 and N3
   1.852  
   1.853 -	N* is numbers or domain names of the machines.
   1.854 -	
   1.855 -	If host list is not specified, 
   1.856 -	command is executed on all of the machines
   1.857 +    N* is numbers or domain names of the machines.
   1.858 +    
   1.859 +    If host list is not specified, 
   1.860 +    command is executed on all of the machines
   1.861  
   1.862  USAGE
   1.863  }