#!/usr/bin/perl
use strict;
use CGI qw(:standard);
use utf8;
BEGIN {
    chdir("/home/devi/cvs/lilalo");
    require l3config;
    l3config::init_config();
};
sub path_is_correct($);
sub error($);
sub remove_extra_slashes_from($);
sub print_header($);
sub print_footer;
sub nav_bar;
sub count_command_lines($);
my $print="";
my $path = $ENV{PATH_INFO};
remove_extra_slashes_from($path);
my $commands_to_show_at_a_go = $l3config::Config{"commands_to_show_at_a_go"};
my $start_from_command = "0";
my $this_page_number=0;
if ($path =~ s/:(.*)//) {
    $this_page_number = $1;
    $start_from_command = $this_page_number*$commands_to_show_at_a_go;
}
my $real_path = $l3config::Config{"backend_datadir"} ;
my $cgi_path = $l3config::Config{"cgi_path"} ;
my $style_files = $l3config::Config{"frontend_files"} ;
my $frontend_css = $l3config::Config{"frontend_css"} ;
my $data_file = "data.xml";
path_is_correct($path)
    or error ("Путь $path содержит недопустимые символы или комбинации символов.");
$real_path .= $path;
remove_extra_slashes_from($real_path);
# Чувак, ты хотел бы посмотреть на журнал $path
# Он должен находиться в каталоге $real_path файловой системы\n";
(-d $real_path)
    or error("Каталог $real_path не существует. Проверьте, пожалуйста, URL\n");
if (-e $real_path."/$data_file") {
# В каталоге есть файл $data_file
# Отлично! Сейчас будем показывать журнал
# Если существуют html и xml файлы,
# html файл новее чем xml,
# и CGI-скрипту не передано дополнительных параметров, 
# используем html файл, иначе перегенируем его
    unless ( -e "$real_path/$data_file"
             && -e "$real_path/index.html" 
             && (stat("$real_path/index.html"))[9] > (stat("$real_path/$data_file"))[9] && 0!=0 ) {
        my $l3_frontend = "/home/devi/cvs/lilalo/l3-frontend --backend_datafile $real_path/$data_file --output $real_path/index.html --start_from_command $start_from_command ";
        system($l3_frontend) == 0
            or error("Файл журнала найден, но возникла ошибка при его обработке:
 $!");
        #$print .= "(перегенирован)
";
    }
    {
        local $/;
        open(HTML, "<:utf8", "$real_path/index.html");
        my $html = ;
# Добавим в начало документа навигационную строку
        my $nav_bar = nav_bar;
        $html =~ s/(
 ..
.. $folder_name
$folder_name| $nav_bar |