rev |
line source |
devi@101
|
1 #!/usr/bin/perl
|
devi@101
|
2
|
devi@101
|
3 use strict;
|
devi@101
|
4 use CGI qw(:standard);
|
devi@101
|
5 use utf8;
|
devi@101
|
6
|
devi@101
|
7 BEGIN {
|
igor@115
|
8 chdir("/etc/lilalo/");
|
devi@101
|
9 require l3config;
|
devi@101
|
10 l3config::init_config();
|
devi@101
|
11 };
|
devi@101
|
12
|
devi@101
|
13 sub path_is_correct($);
|
devi@101
|
14 sub error($);
|
devi@101
|
15 sub remove_extra_slashes_from($);
|
devi@101
|
16 sub print_header($);
|
devi@101
|
17 sub print_footer;
|
devi@101
|
18 sub nav_bar;
|
devi@101
|
19
|
igor@109
|
20 sub count_command_lines($);
|
igor@109
|
21
|
devi@101
|
22 my $print="";
|
devi@101
|
23 my $path = $ENV{PATH_INFO};
|
devi@101
|
24 remove_extra_slashes_from($path);
|
devi@101
|
25
|
igor@109
|
26
|
igor@109
|
27 my $commands_to_show_at_a_go = $l3config::Config{"commands_to_show_at_a_go"};
|
igor@110
|
28 my $start_from_command = "0";
|
igor@109
|
29 my $this_page_number=0;
|
igor@109
|
30 if ($path =~ s/:(.*)//) {
|
igor@109
|
31 $this_page_number = $1;
|
igor@109
|
32 $start_from_command = $this_page_number*$commands_to_show_at_a_go;
|
igor@109
|
33 }
|
igor@109
|
34
|
devi@101
|
35 my $real_path = $l3config::Config{"backend_datadir"} ;
|
devi@101
|
36 my $cgi_path = $l3config::Config{"cgi_path"} ;
|
devi@101
|
37 my $style_files = $l3config::Config{"frontend_files"} ;
|
devi@101
|
38 my $frontend_css = $l3config::Config{"frontend_css"} ;
|
igor@109
|
39
|
igor@141
|
40 my $filter=$ENV{QUERY_STRING};
|
igor@141
|
41 if ($filter !~ /filter=/) {
|
igor@141
|
42 # $filter="";
|
igor@141
|
43 }
|
igor@141
|
44 else {
|
igor@141
|
45 $filter =~ s@.*filter=@@;
|
igor@141
|
46 $filter =~ s@\&.*@@;
|
igor@141
|
47 }
|
igor@141
|
48
|
devi@101
|
49 my $data_file = "data.xml";
|
devi@101
|
50
|
devi@101
|
51 path_is_correct($path)
|
devi@101
|
52 or error ("Путь $path содержит недопустимые символы или комбинации символов.");
|
devi@101
|
53
|
devi@101
|
54 $real_path .= $path;
|
devi@101
|
55 remove_extra_slashes_from($real_path);
|
devi@101
|
56
|
devi@101
|
57 # Чувак, ты хотел бы посмотреть на журнал $path
|
devi@101
|
58 # Он должен находиться в каталоге $real_path файловой системы\n";
|
devi@101
|
59
|
devi@101
|
60 (-d $real_path)
|
devi@101
|
61 or error("Каталог <b>$real_path</b> не существует. Проверьте, пожалуйста, URL\n");
|
devi@101
|
62
|
devi@101
|
63 if (-e $real_path."/$data_file") {
|
devi@101
|
64
|
devi@101
|
65 # В каталоге есть файл $data_file
|
devi@101
|
66 # Отлично! Сейчас будем показывать журнал
|
devi@101
|
67
|
devi@101
|
68 # Если существуют html и xml файлы,
|
devi@101
|
69 # html файл новее чем xml,
|
devi@101
|
70 # и CGI-скрипту не передано дополнительных параметров,
|
devi@101
|
71 # используем html файл, иначе перегенируем его
|
devi@101
|
72
|
devi@101
|
73 unless ( -e "$real_path/$data_file"
|
devi@101
|
74 && -e "$real_path/index.html"
|
igor@109
|
75 && (stat("$real_path/index.html"))[9] > (stat("$real_path/$data_file"))[9] && 0!=0 ) {
|
devi@101
|
76
|
igor@141
|
77 my $l3_frontend = "l3-frontend --backend_datafile $real_path/$data_file".
|
igor@141
|
78 " --output $real_path/index.html".
|
igor@141
|
79 " --start_from_command $start_from_command ".
|
igor@141
|
80 " --filter '$filter'";
|
devi@101
|
81 system($l3_frontend) == 0
|
devi@101
|
82 or error("Файл журнала найден, но возникла ошибка при его обработке:<br/> $!");
|
devi@101
|
83 }
|
devi@101
|
84
|
devi@101
|
85 {
|
devi@101
|
86 local $/;
|
devi@101
|
87 open(HTML, "<:utf8", "$real_path/index.html");
|
devi@101
|
88 my $html = <HTML>;
|
devi@101
|
89
|
devi@101
|
90 # Добавим в начало документа навигационную строку
|
devi@101
|
91 my $nav_bar = nav_bar;
|
devi@101
|
92 $html =~ s/(<body[^>]*>)/$1$nav_bar/;
|
devi@101
|
93
|
devi@101
|
94 $print .= $html;
|
devi@101
|
95 close(HTML);
|
devi@101
|
96 }
|
devi@101
|
97
|
devi@101
|
98 }
|
devi@101
|
99 else {
|
devi@101
|
100
|
devi@101
|
101 # В этом каталоге нет файла data.xml
|
devi@101
|
102 # Но в нём должны быть подкаталоги!
|
devi@101
|
103 # Если и их тут нет, то тут вообще делать нечего
|
devi@101
|
104
|
devi@101
|
105 $print .= nav_bar;
|
devi@101
|
106
|
devi@101
|
107 my @dirs = glob("$real_path/*");
|
devi@101
|
108 my $folder_link = "$cgi_path/$path";
|
devi@101
|
109 remove_extra_slashes_from($folder_link);
|
devi@101
|
110
|
devi@101
|
111 $folder_link =~ s@/[^\/]*/?$@@;
|
devi@101
|
112 if ($folder_link) {
|
devi@101
|
113 $print .= "<img src='$style_files/folder.up.gif'/><a href='$folder_link'>..</a><br/>";
|
devi@101
|
114 }
|
devi@101
|
115
|
devi@101
|
116 for my $dir (@dirs) {
|
devi@101
|
117 next unless (-d $dir);
|
devi@101
|
118 my ($folder_name) = $dir =~ m@.*/(.*)@;
|
devi@101
|
119 $folder_link = "$cgi_path/$path/$folder_name";
|
devi@101
|
120 $folder_link =~ s@//@/@g;
|
devi@101
|
121 $print .= "<img src='$style_files/folder.gif'/><a href='$folder_link'>$folder_name</a><br/>";
|
devi@101
|
122 }
|
devi@101
|
123
|
devi@101
|
124 $print = print_header("LiLaLo -- ".remove_extra_slashes_from("$cgi_path/$path"))
|
devi@101
|
125 .$print
|
devi@101
|
126 .print_footer;
|
devi@101
|
127 };
|
devi@101
|
128
|
devi@101
|
129 binmode STDOUT, ":utf8";
|
devi@101
|
130 print header(-charset => "utf-8");
|
devi@101
|
131 print $print;
|
devi@101
|
132 exit(0);
|
devi@101
|
133
|
devi@101
|
134 #----------------------------------------------
|
devi@101
|
135
|
devi@101
|
136
|
devi@101
|
137 sub error($)
|
devi@101
|
138 {
|
devi@101
|
139 my $message = $_[0];
|
devi@101
|
140
|
devi@101
|
141 binmode STDOUT, ":utf8";
|
devi@101
|
142 print header(-charset => "utf-8");
|
devi@101
|
143
|
devi@101
|
144 my $print = "<h2>Извините, произошла ошибка</h2>";
|
devi@101
|
145 $print .= $message;
|
devi@101
|
146
|
devi@101
|
147 print $print;
|
devi@101
|
148 exit(0);
|
devi@101
|
149 }
|
devi@101
|
150
|
devi@101
|
151
|
devi@101
|
152 sub path_is_correct($)
|
devi@101
|
153 {
|
devi@101
|
154 my $path = $_[0];
|
devi@106
|
155 # return 0 if $path =~ m@/../@;
|
devi@101
|
156 return 0 unless $path =~ m@^[a-zA-Z0-9./\@\-]*$@;
|
devi@101
|
157 return 1;
|
devi@101
|
158 }
|
devi@101
|
159
|
devi@101
|
160 sub remove_extra_slashes_from($)
|
devi@101
|
161 {
|
devi@101
|
162 while ($_[0] =~ s@//@/@g) {1;};
|
devi@101
|
163 return $_[0];
|
devi@101
|
164 }
|
devi@101
|
165
|
devi@101
|
166 sub print_header($)
|
devi@101
|
167 {
|
devi@101
|
168 my $title = $_[0];
|
devi@101
|
169 "<html>"
|
devi@101
|
170 ."<head>"
|
devi@101
|
171 ."<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />"
|
devi@101
|
172 ."<link rel='stylesheet' href='$frontend_css' type='text/css'/>"
|
devi@101
|
173 ."<title>$title</title>"
|
devi@101
|
174 ."</head>"
|
devi@101
|
175 }
|
devi@101
|
176
|
devi@101
|
177 sub print_footer()
|
devi@101
|
178 {
|
devi@101
|
179 "</html>";
|
devi@101
|
180 }
|
devi@101
|
181
|
devi@101
|
182 sub nav_bar()
|
devi@101
|
183 {
|
devi@101
|
184 my $nav_bar="";
|
devi@101
|
185 my $skip_first=1;
|
devi@101
|
186 my $current_path="";
|
devi@101
|
187 for my $path_part (split("/", remove_extra_slashes_from("$cgi_path/$path"))) {
|
devi@101
|
188 if ($skip_first) {
|
devi@101
|
189 $skip_first--;
|
devi@101
|
190 next;
|
devi@101
|
191 }
|
devi@101
|
192 $current_path .= "/$path_part";
|
devi@101
|
193 $nav_bar .= "/<a href='$current_path'>$path_part</a>";
|
devi@101
|
194 }
|
igor@109
|
195 my $pages=int(count_command_lines("$real_path/$data_file")/$commands_to_show_at_a_go)+1;
|
igor@109
|
196 my $i=1;
|
igor@109
|
197 while ($i<$pages) {
|
igor@109
|
198 if ($i==$this_page_number) {
|
igor@109
|
199 $nav_bar .= " <b>:$i</b>";
|
igor@109
|
200 }
|
igor@109
|
201 else {
|
igor@109
|
202 $nav_bar .= " <a href='$current_path:$i'>:$i</a>";
|
igor@109
|
203 }
|
igor@109
|
204 $i++;
|
igor@109
|
205 }
|
igor@141
|
206 $filter = "($filter)" if $filter;
|
igor@141
|
207 return "<table class='nav_bar' cellpadding='0' cellspacing='0' width='100%'><tr><td>$nav_bar $filter</td></tr></table>";
|
devi@101
|
208 }
|
devi@101
|
209
|
igor@109
|
210 sub count_command_lines($)
|
igor@109
|
211 #
|
igor@109
|
212 # Считает количество строк в файле с данными
|
igor@109
|
213 # Грязный временный хак
|
igor@109
|
214 #
|
igor@109
|
215 {
|
igor@109
|
216 my $filename= $_[0];
|
igor@109
|
217 return int(`grep '<command>' $filename |wc -l`);
|
igor@109
|
218 # return $filename;
|
igor@109
|
219 }
|
igor@109
|
220
|