Bug 6874: (QA followup) Warnings in about page
[koha-equinox.git] / about.pl
1 #!/usr/bin/perl
2
3 # Copyright Pat Eyler 2003
4 # Copyright Biblibre 2006
5 # Parts Copyright Liblime 2008
6 # Parts Copyright Chris Nighswonger 2010
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 use strict;
24 use warnings;
25
26 use CGI qw ( -utf8 );
27 use LWP::Simple;
28 use XML::Simple;
29 use Config;
30
31 use C4::Output;
32 use C4::Auth;
33 use C4::Context;
34 use C4::Installer;
35
36 use Koha;
37 use Koha::Config::SysPrefs;
38
39 #use Smart::Comments '####';
40
41 my $query = new CGI;
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43     {
44         template_name   => "about.tt",
45         query           => $query,
46         type            => "intranet",
47         authnotrequired => 0,
48         flagsrequired   => { catalogue => 1 },
49         debug           => 1,
50     }
51 );
52
53 my $kohaVersion   = Koha::version();
54 my $osVersion     = `uname -a`;
55 my $perl_path = $^X;
56 if ($^O ne 'VMS') {
57     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
58 }
59 my $perlVersion   = $];
60 my $mysqlVersion  = `mysql -V`;
61 # Get Apache version
62 my $apacheVersion = (`apache2ctl -v`)[0];
63 $apacheVersion    = `httpd2 -v 2> /dev/null` unless $apacheVersion;
64 $apacheVersion    = `httpd -v 2> /dev/null` unless $apacheVersion;
65 my $zebraVersion = `zebraidx -V`;
66
67 # Additional system information for warnings
68 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
69 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
70 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
71
72 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
73 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
74 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
75 my $warnPrefAnonymousPatron = (
76     C4::Context->preference('OPACPrivacy')
77         and not C4::Context->preference('AnonymousPatron')
78 );
79
80 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
81
82 my $warnIsRootUser   = (! $loggedinuser);
83
84 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
85 my @xml_config_warnings;
86
87 my $context = new C4::Context;
88
89 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
90     push @xml_config_warnings, {
91         error => 'zebra_bib_index_mode_warn'
92     };
93     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
94         push @xml_config_warnings, {
95             error => 'zebra_bib_mode_seems_grs1'
96         };
97     }
98     else {
99         push @xml_config_warnings, {
100             error => 'zebra_bib_mode_seems_dom'
101         };
102     }
103 } else {
104     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
105         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
106 }
107
108 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
109      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
110
111     push @xml_config_warnings, {
112         error => 'zebra_bib_index_mode_mismatch_warn'
113     };
114 }
115
116 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
117      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
118
119     push @xml_config_warnings, {
120         error => 'zebra_bib_index_mode_mismatch_warn'
121     };
122 }
123
124 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
125     push @xml_config_warnings, {
126         error => 'zebra_auth_index_mode_warn'
127     };
128     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
129         push @xml_config_warnings, {
130             error => 'zebra_auth_mode_seems_grs1'
131         };
132     }
133     else {
134         push @xml_config_warnings, {
135             error => 'zebra_auth_mode_seems_dom'
136         };
137     }
138 } else {
139     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
140         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
141 }
142
143 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
144     push @xml_config_warnings, {
145         error => 'zebra_auth_index_mode_mismatch_warn'
146     };
147 }
148
149 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
150     push @xml_config_warnings, {
151         error => 'zebra_auth_index_mode_mismatch_warn'
152     };
153 }
154
155 if ( ! defined C4::Context->config('log4perl_conf') ) {
156     push @xml_config_warnings, {
157         error => 'log4perl_entry_missing'
158     }
159 }
160
161 if ( ! defined C4::Context->config('upload_path') ) {
162     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
163         # OPACBaseURL seems to be set
164         push @xml_config_warnings, {
165             error => 'uploadpath_entry_missing'
166         }
167     } else {
168         push @xml_config_warnings, {
169             error => 'uploadpath_and_opacbaseurl_entry_missing'
170         }
171     }
172 }
173
174 # Test QueryParser configuration sanity
175 if ( C4::Context->preference( 'UseQueryParser' ) ) {
176     # Get the QueryParser configuration file name
177     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
178     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
179     # Check QueryParser is functional
180     my $QParser = C4::Context->queryparser();
181     my $queryparser_error = {};
182     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
183         # Error initializing the QueryParser object
184         # Get the used queryparser.yaml file path to report the user
185         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
186         $queryparser_error->{ file }     = ( defined $queryparser_file )
187                                                 ? $queryparser_file
188                                                 : $queryparser_fallback_file;
189         # Report error data to the template
190         $template->param( QueryParserError => $queryparser_error );
191     } else {
192         # Check for an absent queryparser_config entry in koha-conf.xml
193         if ( ! defined $queryparser_file ) {
194             # Not an error but a warning for the missing entry in koha-conf-xml
195             push @xml_config_warnings, {
196                     error => 'queryparser_entry_missing',
197                     file  => $queryparser_fallback_file
198             };
199         }
200     }
201 }
202
203 # Test Zebra facets configuration
204 if ( !defined C4::Context->config('use_zebra_facets') ) {
205     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
206 } else {
207     if ( C4::Context->config('use_zebra_facets') &&
208          C4::Context->config('zebra_bib_index_mode') ) {
209         # use_zebra_facets works with DOM
210         push @xml_config_warnings, {
211             error => 'use_zebra_facets_needs_dom'
212         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
213     }
214 }
215
216 $template->param(
217     kohaVersion   => $kohaVersion,
218     osVersion     => $osVersion,
219     perlPath      => $perl_path,
220     perlVersion   => $perlVersion,
221     perlIncPath   => [ map { perlinc => $_ }, @INC ],
222     mysqlVersion  => $mysqlVersion,
223     apacheVersion => $apacheVersion,
224     zebraVersion  => $zebraVersion,
225     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
226     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
227     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
228     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
229     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
230     errZebraConnection => $errZebraConnection,
231     warnIsRootUser => $warnIsRootUser,
232     warnNoActiveCurrency => $warnNoActiveCurrency,
233     xml_config_warnings => \@xml_config_warnings,
234 );
235
236 my @components = ();
237
238 my $perl_modules = C4::Installer::PerlModules->new;
239 $perl_modules->version_info;
240
241 my @pm_types = qw(missing_pm upgrade_pm current_pm);
242
243 foreach my $pm_type(@pm_types) {
244     my $modules = $perl_modules->get_attr($pm_type);
245     foreach (@$modules) {
246         my ($module, $stats) = each %$_;
247         push(
248             @components,
249             {
250                 name    => $module,
251                 version => $stats->{'cur_ver'},
252                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
253                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
254                 current => ($pm_type eq 'current_pm' ? 1 : 0),
255                 require => $stats->{'required'},
256                 reqversion => $stats->{'min_ver'},
257             }
258         );
259     }
260 }
261
262 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
263
264 my $counter=0;
265 my $row = [];
266 my $table = [];
267 foreach (@components) {
268     push (@$row, $_);
269     unless (++$counter % 4) {
270         push (@$table, {row => $row});
271         $row = [];
272     }
273 }
274 # Processing the last line (if there are any modules left)
275 if (scalar(@$row) > 0) {
276     # Extending $row to the table size
277     $$row[3] = '';
278     # Pushing the last line
279     push (@$table, {row => $row});
280 }
281 ## ## $table
282
283 $template->param( table => $table );
284
285
286 ## ------------------------------------------
287 ## Koha time line code
288
289 #get file location
290 my $docdir;
291 if ( defined C4::Context->config('docdir') ) {
292     $docdir = C4::Context->config('docdir');
293 } else {
294     # if no <docdir> is defined in koha-conf.xml, use the default location
295     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
296     $docdir = C4::Context->config('intranetdir') . '/docs';
297 }
298
299 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
300
301     my $i = 0;
302
303     my @rows2 = ();
304     my $row2  = [];
305
306     my @lines = <$file>;
307     close($file);
308
309     shift @lines; #remove header row
310
311     foreach (@lines) {
312         my ( $date, $desc, $tag ) = split(/\t/);
313         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
314             ($date, $desc)= ($`, $');
315         }
316         push(
317             @rows2,
318             {
319                 date => $date,
320                 desc => $desc,
321             }
322         );
323     }
324
325     my $table2 = [];
326     #foreach my $row2 (@rows2) {
327     foreach  (@rows2) {
328         push (@$row2, $_);
329         push( @$table2, { row2 => $row2 } );
330         $row2 = [];
331     }
332
333     $template->param( table2 => $table2 );
334 } else {
335     $template->param( timeline_read_error => 1 );
336 }
337
338 output_html_with_http_headers $query, $cookie, $template->output;