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