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