Bug 17261: (followup) Rebase against 17189 and 11921
[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 Modern::Perl;
24
25 use CGI qw ( -utf8 );
26 use List::MoreUtils qw/ any /;
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::Acquisition::Currencies;
38 use Koha::Patrons;
39 use Koha::Caches;
40 use Koha::Config::SysPrefs;
41 use C4::Members::Statistics;
42
43 #use Smart::Comments '####';
44
45 my $query = new CGI;
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47     {
48         template_name   => "about.tt",
49         query           => $query,
50         type            => "intranet",
51         authnotrequired => 0,
52         flagsrequired   => { catalogue => 1 },
53         debug           => 1,
54     }
55 );
56
57 my $perl_path = $^X;
58 if ($^O ne 'VMS') {
59     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
60 }
61
62 my $zebraVersion = `zebraidx -V`;
63
64 # Check running PSGI env
65 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
66     $template->param(
67         is_psgi => 1,
68         psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
69                        ($ENV{ MOD_PERL })  ? "mod_perl ($ENV{MOD_PERL})" :
70                                              'Unknown'
71     );
72 }
73
74 # Memcached configuration
75 my $memcached_servers   = $ENV{MEMCACHED_SERVERS} // C4::Context->config('memcached_servers');
76 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} // C4::Context->config('memcached_namespace');
77
78 my $effective_caching_method = ref(Koha::Caches->get_instance->cache);
79
80 $template->param(
81     effective_caching_method => $effective_caching_method,
82     memcached_servers   => $memcached_servers,
83     memcached_namespace => $memcached_namespace,
84     memcached_running   => Koha::Caches->get_instance->memcached_cache
85 );
86
87 # Additional system information for warnings
88
89 my $warnStatisticsFieldsError;
90 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
91 if ($prefStatisticsFields) {
92     $warnStatisticsFieldsError = $prefStatisticsFields
93         unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
94 }
95
96 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
97 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
98 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
99
100 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
101 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
102 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
103 my $warnPrefAnonymousPatron = (
104     C4::Context->preference('OPACPrivacy')
105         and not C4::Context->preference('AnonymousPatron')
106 );
107
108 my $anonymous_patron = Koha::Patrons->find( C4::Context->preference('AnonymousPatron') );
109 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
110
111 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
112
113 my $warnIsRootUser   = (! $loggedinuser);
114
115 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
116 my @xml_config_warnings;
117
118 my $context = new C4::Context;
119
120 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
121     push @xml_config_warnings, {
122         error => 'zebra_bib_index_mode_warn'
123     };
124     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
125         push @xml_config_warnings, {
126             error => 'zebra_bib_mode_seems_grs1'
127         };
128     }
129     else {
130         push @xml_config_warnings, {
131             error => 'zebra_bib_mode_seems_dom'
132         };
133     }
134 } else {
135     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
136         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
137 }
138
139 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
140      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
141
142     push @xml_config_warnings, {
143         error => 'zebra_bib_index_mode_mismatch_warn'
144     };
145 }
146
147 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
148      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
149
150     push @xml_config_warnings, {
151         error => 'zebra_bib_index_mode_mismatch_warn'
152     };
153 }
154
155 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
156     push @xml_config_warnings, {
157         error => 'zebra_auth_index_mode_warn'
158     };
159     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
160         push @xml_config_warnings, {
161             error => 'zebra_auth_mode_seems_grs1'
162         };
163     }
164     else {
165         push @xml_config_warnings, {
166             error => 'zebra_auth_mode_seems_dom'
167         };
168     }
169 } else {
170     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
171         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
172 }
173
174 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
175     push @xml_config_warnings, {
176         error => 'zebra_auth_index_mode_mismatch_warn'
177     };
178 }
179
180 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
181     push @xml_config_warnings, {
182         error => 'zebra_auth_index_mode_mismatch_warn'
183     };
184 }
185
186 if ( ! defined C4::Context->config('log4perl_conf') ) {
187     push @xml_config_warnings, {
188         error => 'log4perl_entry_missing'
189     }
190 }
191
192 if ( ! defined C4::Context->config('upload_path') ) {
193     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
194         # OPACBaseURL seems to be set
195         push @xml_config_warnings, {
196             error => 'uploadpath_entry_missing'
197         }
198     } else {
199         push @xml_config_warnings, {
200             error => 'uploadpath_and_opacbaseurl_entry_missing'
201         }
202     }
203 }
204
205 # Test QueryParser configuration sanity
206 if ( C4::Context->preference( 'UseQueryParser' ) ) {
207     # Get the QueryParser configuration file name
208     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
209     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
210     # Check QueryParser is functional
211     my $QParser = C4::Context->queryparser();
212     my $queryparser_error = {};
213     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
214         # Error initializing the QueryParser object
215         # Get the used queryparser.yaml file path to report the user
216         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
217         $queryparser_error->{ file }     = ( defined $queryparser_file )
218                                                 ? $queryparser_file
219                                                 : $queryparser_fallback_file;
220         # Report error data to the template
221         $template->param( QueryParserError => $queryparser_error );
222     } else {
223         # Check for an absent queryparser_config entry in koha-conf.xml
224         if ( ! defined $queryparser_file ) {
225             # Not an error but a warning for the missing entry in koha-conf-xml
226             push @xml_config_warnings, {
227                     error => 'queryparser_entry_missing',
228                     file  => $queryparser_fallback_file
229             };
230         }
231     }
232 }
233
234 # Test Zebra facets configuration
235 if ( !defined C4::Context->config('use_zebra_facets') ) {
236     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
237 } else {
238     if ( C4::Context->config('use_zebra_facets') &&
239          C4::Context->config('zebra_bib_index_mode') ) {
240         # use_zebra_facets works with DOM
241         push @xml_config_warnings, {
242             error => 'use_zebra_facets_needs_dom'
243         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
244     }
245 }
246
247 # Sco Patron should not contain any other perms than circulate => self_checkout
248 if (  C4::Context->preference('WebBasedSelfCheck')
249       and C4::Context->preference('AutoSelfCheckAllowed')
250 ) {
251     my $userid = C4::Context->preference('AutoSelfCheckID');
252     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
253     my ( $has_self_checkout_perm, $has_other_permissions );
254     while ( my ( $module, $permissions ) = each %$all_permissions ) {
255         if ( $module eq 'circulate' ) {
256             while ( my ( $permission, $flag ) = each %$permissions ) {
257                 if ( $permission eq 'self_checkout' ) {
258                     $has_self_checkout_perm = 1;
259                 } else {
260                     $has_other_permissions = 1;
261                 }
262             }
263         } else {
264             $has_other_permissions = 1;
265         }
266     }
267     $template->param(
268         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
269         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
270     );
271
272
273 }
274
275 my %versions = C4::Context::get_versions();
276
277 $template->param(
278     kohaVersion   => $versions{'kohaVersion'},
279     osVersion     => $versions{'osVersion'},
280     perlPath      => $perl_path,
281     perlVersion   => $versions{'perlVersion'},
282     perlIncPath   => [ map { perlinc => $_ }, @INC ],
283     mysqlVersion  => $versions{'mysqlVersion'},
284     apacheVersion => $versions{'apacheVersion'},
285     zebraVersion  => $zebraVersion,
286     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
287     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
288     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
289     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
290     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
291     warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
292     errZebraConnection => $errZebraConnection,
293     warnIsRootUser => $warnIsRootUser,
294     warnNoActiveCurrency => $warnNoActiveCurrency,
295     xml_config_warnings => \@xml_config_warnings,
296     warnStatisticsFieldsError => $warnStatisticsFieldsError,
297 );
298
299 my @components = ();
300
301 my $perl_modules = C4::Installer::PerlModules->new;
302 $perl_modules->version_info;
303
304 my @pm_types = qw(missing_pm upgrade_pm current_pm);
305
306 foreach my $pm_type(@pm_types) {
307     my $modules = $perl_modules->get_attr($pm_type);
308     foreach (@$modules) {
309         my ($module, $stats) = each %$_;
310         push(
311             @components,
312             {
313                 name    => $module,
314                 version => $stats->{'cur_ver'},
315                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
316                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
317                 current => ($pm_type eq 'current_pm' ? 1 : 0),
318                 require => $stats->{'required'},
319                 reqversion => $stats->{'min_ver'},
320             }
321         );
322     }
323 }
324
325 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
326
327 my $counter=0;
328 my $row = [];
329 my $table = [];
330 foreach (@components) {
331     push (@$row, $_);
332     unless (++$counter % 4) {
333         push (@$table, {row => $row});
334         $row = [];
335     }
336 }
337 # Processing the last line (if there are any modules left)
338 if (scalar(@$row) > 0) {
339     # Extending $row to the table size
340     $$row[3] = '';
341     # Pushing the last line
342     push (@$table, {row => $row});
343 }
344 ## ## $table
345
346 $template->param( table => $table );
347
348
349 ## ------------------------------------------
350 ## Koha time line code
351
352 #get file location
353 my $docdir;
354 if ( defined C4::Context->config('docdir') ) {
355     $docdir = C4::Context->config('docdir');
356 } else {
357     # if no <docdir> is defined in koha-conf.xml, use the default location
358     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
359     $docdir = C4::Context->config('intranetdir') . '/docs';
360 }
361
362 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
363
364     my $i = 0;
365
366     my @rows2 = ();
367     my $row2  = [];
368
369     my @lines = <$file>;
370     close($file);
371
372     shift @lines; #remove header row
373
374     foreach (@lines) {
375         my ( $date, $desc, $tag ) = split(/\t/);
376         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
377             ($date, $desc)= ($`, $');
378         }
379         push(
380             @rows2,
381             {
382                 date => $date,
383                 desc => $desc,
384             }
385         );
386     }
387
388     my $table2 = [];
389     #foreach my $row2 (@rows2) {
390     foreach  (@rows2) {
391         push (@$row2, $_);
392         push( @$table2, { row2 => $row2 } );
393         $row2 = [];
394     }
395
396     $template->param( table2 => $table2 );
397 } else {
398     $template->param( timeline_read_error => 1 );
399 }
400
401 output_html_with_http_headers $query, $cookie, $template->output;