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