Bugzilla: Code on start - perl

I tried to install Bugzilla on my Raspberry. Everything is greater than the minimum system requirements and I installed perl lib to apache too, but I got this when I wanted to "run" it.
#!/usr/bin/perl -T
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
use 5.10.1;
use strict;
use warnings;
use lib qw(. lib);
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Update;
# Check whether or not the user is logged in
my $user = Bugzilla->login(LOGIN_OPTIONAL);
my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template;
my $vars = {};
# And log out the user if requested. We do this first so that nothing
# else accidentally relies on the current login.
if ($cgi->param('logout')) {
Bugzilla->logout();
$user = Bugzilla->user;
$vars->{'message'} = "logged_out";
# Make sure that templates or other code doesn't get confused about this.
$cgi->delete('logout');
}
# Return the appropriate HTTP response headers.
print $cgi->header();
if ($user->in_group('admin')) {
# If 'urlbase' is not set, display the Welcome page.
unless (Bugzilla->params->{'urlbase'}) {
$template->process('welcome-admin.html.tmpl')
|| ThrowTemplateError($template->error());
exit;
}
# Inform the administrator about new releases, if any.
$vars->{'release'} = Bugzilla::Update::get_notifications();
}
if ($user->id) {
my $dbh = Bugzilla->dbh;
$vars->{assignee_count} =
$dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE assigned_to = ?
AND resolution = ''", undef, $user->id);
$vars->{reporter_count} =
$dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE reporter = ?
AND resolution = ''", undef, $user->id);
$vars->{requestee_count} =
$dbh->selectrow_array('SELECT COUNT(DISTINCT bug_id) FROM flags
WHERE requestee_id = ?', undef, $user->id);
}
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("index.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
What I missed? Or should I use an another issue tracker? (MantisBT)

Assuming that by "run it" you mean "Visited an HTTP URL pointing to your Raspbery Pi on the network in a web browser" and that by "this" you mean "The source code of the CGI program was rendered in the browser" then:
You haven't configured Apache to support CGI for whereever you installed Bugzilla.
The Apache manual page covers how to do this in detail.
You'll need to start by loading the module:
LoadModule cgid_module modules/mod_cgid.so
and enabling CGI for the location you put Bugzilla:
<Directory "/path/to/bugzilla/">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

This is helped me
nano /etc/apache2/sites-available/bugzilla.conf
Paste in the following and save:
ServerName localhost
<Directory /var/www/html/bugzilla>
AddHandler cgi-script .cgi
Options +ExecCGI
DirectoryIndex index.cgi index.html
AllowOverride All
</Directory>
$ a2ensite bugzilla
$ a2enmod cgi headers expires
$ service apache2 restart
Referral URL:
https://bugzilla.readthedocs.io/en/latest/installing/quick-start.html#configure-apache

Related

Catalyst application under Apache2 mod_perl won't render Mason templates

my application root is /home/user/apps/learningcatalyst/CGAddressBook
in that folder I have a /mason folder where mason components are stored
my View is located in /lib/CGAddressBook/View where I have a few files called login_form and addressbook.
Couldn't render component "login_form" - error was "could not find component for initial path '/login_form' (component roots are: '/home/user/apps/learningcatalyst/CGAddressBook/lib/CGAddressBook/View')
is the error I get when trying to reach the site through Apache. My apache conf file is
PerlSwitches -I/home/user/apps/learningcatalyst/CGAddressBook/lib
PerlModule CGAddressBook
<Location /user_catalyst/>
SetHandler modperl
PerlResponseHandler CGAddressBook
</Location>
DocumentRoot /home/user/apps/learningcatalyst/CGAddressBook/root
<Location /user_catalyst/static>
SetHandler default-handler
</Location>
All folders are readable by user, its group, and other. The mason folder, where Mason is set to write its cache, is set to read, write, and execute by user, group, and other. Its owner is user.
I have restarted Apache to no avail, I have changed folder owners (and recursively) of both the /View and /mason.
The application works just fine when running script/cgaddressbook_server.pl -r -p3001 and I go to my site on port 3001.
The path to comp_root is meant to be the path to your template "components". You appear to be pointing it at the same directory as the "View" package. You "might" actually have the components there but that is not really a good practice.
The default location without specifying this should be the "root/comps" folder ( or something like that ) in your Catalyst project structure. One of my own samples is like this:
package SnakierTen::Web::View::HTML;
use Modern::Perl;
use Moose;
use MooseX::NonMoose;
extends 'Catalyst::View::Mason2';
around BUILDARGS => sub {
my ( $orig, $class, $c, #args ) = #_;
$class->config(
comp_root => $c->path_to( 'root' ),
data_dir => $c->path_to( 'data' ),
plugins => [
'TidyObjectFiles',
'HTMLFilters',
],
);
$class->$orig( $c, #args );
};
__PACKAGE__->meta->make_immutable;
no Moose;
1;
Aside from that, direct support of Mod Perl handlers is being deprecated in Catalyst core.
The favored method is to start the application under it's own PSGI compliant server and use a "front end" web server to "proxy" the requests to this application server.
Where you must run the application under a mod_perl environment, it is still recommended to run under a PSGI handler. There are some notes here that are a part of the documentation yet to be built on this. You can use the methods there to guide you in doing this.

Apache rewriteRule to check login and redirect to page

This is a follow up for this question Apache directory directive authentication based on Perl CGI::Session
Alias /files /myData/all
<Directory /myData/all >
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ cgi-bin/checklogin.pl?url=/files/$1 [L,R]
Options +Indexes
</Directory>
/files is a directory listing.
I edited the directive so that if a user goes to webserver/files/ they are redirected to checklogin.pl which checks for the existance of a session. If there is one it should redirect to the ?url if not it takes them to the loginpage.
The first part works. The redirect to $url causes a loop.
my $url = $cgi->param("url");
my $cookie = $cgi->cookie('mysession');
if(!$cookie){
$session = new CGI::Session();
print $session->redirect('/loginpage.html');
}else{
# HOW DO I display folder or files now?
$session = new CGI::Session(undef, $cookie, {Directory=>'/tmp/'});
print $session->redirect($url);
}
I am, obviously, getting a redirect loop error in Apache
This webpage has a redirect loop
If you redirect every request to checklogin.pl, any requests made inside checklogin.pl will redirect to checklogin.pl, which will redirect to checklogin.pl, which will redirect to checklogin.pl...
Instead, why don't you make a master script with a logged_in function that you call with each request:
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI;
sub logged_in {
# Check session
}
my $q = CGI->new;
if (not logged_in()) {
print $q->redirect('http://url/to/login.html'); # Need to use a full URL
}
else {
# Do stuff
}

How to pass environment variable to an AutoLoaded mod_perl handler, to be used at module load time?

I have a HTTP Request Handler for mod_perl which needs to read an environment variable, from %ENV, at module load time. The environment variable is passed from the Apache config into mod_perl using the PerlSetEnv directive.
This worked fine, until we changed the Apache configuration to AutoLoad the handler at startup time, for performance reasons. When the module is AutoLoaded like this, thePerlSetEnv does not take effect at module load time, and the variable we need is only available from %ENV at request time inside the handler method.
Is there a way to continue using AutoLoad, but still set an environment variable in the Apache config which is available in Perl's %ENV at module load time?
Minimal example:
Here's a stripped down test-case to illustrate the problem.
The Apache config without autoload enabled:
PerlSwitches -I/home/day/modperl
<Location /perl>
SetHandler modperl
PerlSetEnv TEST_PERLSETENV 'Does it work?'
PerlResponseHandler ModPerl::Test
Allow from all
</Location>
Contents of /home/day/modperl/ModPerl/Test.pm:
package ModPerl::Test;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const qw(OK);
my %ENV_AT_MODULE_LOAD = %ENV; # Take a copy
sub handler {
my $r = shift;
$r->content_type('text/plain');
$r->print("ENV:\n");
foreach my $key (sort keys %ENV) {
$r->print(" $key: $ENV{$key}\n");
}
$r->print("ENV_AT_MODULE_LOAD:\n");
foreach my $key (sort keys %ENV_AT_MODULE_LOAD) {
$r->print(" $key: $ENV_AT_MODULE_LOAD{$key}\n");
}
return OK;
}
1;
When localhost/perl is viewed in the browser, I see this:
ENV:
MOD_PERL: mod_perl/2.0.5
MOD_PERL_API_VERSION: 2
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
TEST_PERLSETENV: Does it work?
ENV_AT_MODULE_LOAD:
MOD_PERL: mod_perl/2.0.5
MOD_PERL_API_VERSION: 2
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
TEST_PERLSETENV: Does it work?
Hooray! TEST_PERLSETENV is available at module load time, as we want.
But when we change the Apache config to enable Autoload (by using + in the PerlResponseHandler like so):
PerlResponseHandler +ModPerl::Test
I get the following output instead:
ENV:
MOD_PERL: mod_perl/2.0.5
MOD_PERL_API_VERSION: 2
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
TEST_PERLSETENV: Does it work?
ENV_AT_MODULE_LOAD:
MOD_PERL: mod_perl/2.0.5
MOD_PERL_API_VERSION: 2
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Boo! TEST_PERLSETENV is no longer available at module load time :( How can I get it back while keeping the AutoLoad behaviour?
Argh, 30 seconds after posting this question, I found the answer. Thank you rubber duck.
Move the PerlSetEnv to before the <Location> block which contains the PerlResponseHandler directive, and it works again!
i.e. like this:
PerlSwitches -I/home/dbarr/modperl
PerlSetEnv TEST_PERLSETENV 'Does it work?'
<Location /perl>
SetHandler modperl
PerlResponseHandler +ModPerl::Test
Allow from all
</Location>

ModPerl::RegistryPrefork should make my old cgi work but

I developped a web app under CGI.pm.I'd like to switch to mod_perl2.
My webapp worked under CGI but when i tried to change the mod, it's not working anymore while I didn't change anything in the webapp ,except the apache conf files to run under mod_perl.
I have installed mod-perl2 and configure my VirualHost like this :
Alias /project1/ /var/www/v6/cgi-bin/
PerlModule Apache::DBI
PerlModule ModPerl::RegistryPrefork
<Directory /var/www/v6/cgi-bin/ >
PerlOptions -SetupEnv
SetHandler perl-script
PerlResponseHandler ModPerl::RegistryPrefork
PerlOptions +ParseHeaders
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
My script looks like . he uses some modules in /v6/cgi-bin/lib/
#!/usr/bin/perl
use lib qw(lib);
use strict;
use DBI;
use CGI;
use Template;
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;
use Connexion;
use Search;
my $cgi = new CGI;
our $fastdb = Connexion::database('1','1');
my $get_description__id_sth = Search->get_description_id_sth();
Apache2 write the error in the log :
[Thu Feb 3 17:35:13 2011] -e: DBI
connect(':','',...) failed: Access
denied for user 'www-data'#'localhost'
(using password: NO) at
lib/Connexion.pm line 134
In the browser i have :
Can't call method "prepare" on an
undefined value at lib/Search.pm line
51.
So i understand that the script can't connect to the database.But why?
It was working on mod_cgi.
If someone has an idea :'(
Thanks.
What is Connexion and what is it doing in the DBI connect call?
You very likely need to not be disabling SetupEnv.
Connexion is a module i made for connecting my database.It's in /cgi-bin/lib whereas my previous script call him from /cgi-bin/ directory.
package Connexion;
use strict;
use DBI;
sub database{
my ($var,$var) = #_;
my ($host1 ,$user1,$dbname1 ,$pass1)= '';
if (($var== 1) and ($var ==1)){
$host1 = 'localhost';
$user1 = 'root';
$dbname1 = 'BASE';
$pass1 = '**';
}
return my $fastdb = DBI -> connect ('DBI:mysql:' . $dbname1 . ':' . $host1, $user1, $pass1);
}
1;

Why does my simple fastCGI Perl script fail?

I'm not of the Perl world, so some of this is new to me. I'm running Ubuntu Hardy LTS with apache2 and mod_fcgid packages installed. I'd like to get MT4 running under fcgid rather than mod-cgi (it seems to run OK with plain-old CGI).
I can't seem to get even a simple Perl script to run under fcgid. I created a simple "Hello World" app and included the code from this previous question to test if FCGI is running.
I named my script HelloWorld.fcgi (currently fcgid is set to handle .fcgi files only). Code:
#!/usr/bin/perl
use FCGI;
print "Content-type: text/html\n\n";
print "Hello world.\n\n";
my $request = FCGI::Request();
if ( $request->IsFastCGI ) {
print "we're running under FastCGI!\n";
} else {
print "plain old boring CGI\n";
}
When run from the command line, it prints "plain old boring..." When invoked via an http request to apache, I get a 500 Internal Server error and the output of the script is printed to the Apache error log:
Content-type: text/html
Hello world.
we're running under FastCGI!
[Wed Dec 03 22:26:19 2008] [warn] (104)Connection reset by peer: mod_fcgid: read data from fastcgi server error.
[Wed Dec 03 22:26:19 2008] [error] [client 70.23.221.171] Premature end of script headers: HelloWorld.fcgi
[Wed Dec 03 22:26:25 2008] [notice] mod_fcgid: process /www/mt/HelloWorld.fcgi(14189) exit(communication error), terminated by calling exit(), return code: 0
When I run the .cgi version of the same code, it works fine. Any idea why the output of the script is going to the error log? Apache config is the default mod_fcgid config plus, in a VirtualHost directive:
ServerName test1.example.com
DocumentRoot /www/example
<Directory /www/example>
AllowOverride None
AddHandler cgi-script .cgi
AddHandler fcgid-script .fcgi
Options +ExecCGI +Includes +FollowSymLinks
</Directory>
The problem is that the "Content-Type" header is sent outside of the request loop. You must print the "Content-Type" header for every request. If you move
print "Content-type: text/html\n\n";
to the top of the request loop it should fix the problem.
Also, you need to loop over the requests or you'll get no benefit, so following the first poster's example:
my $request = FCGI::Request();
while($request->Accept() >= 0) {
print("Content-type: text/html\n\n");
}
I use CGI::Fast more than FCGI, but the idea is the same, I think. The goal of fast cgi is to load the program once, and iterate in a loop for every request.
FCGI's man page says :
use FCGI;
my $count = 0;
my $request = FCGI::Request();
while($request->Accept() >= 0) {
print("Content-type: text/html\r\n\r\n", ++$count);
}
Which means, you have to Accept the request before being able to print anything back to the browser.
Movable Type uses CGI::Fast for FastCGI. The typical FastCGI script runs in a loop, as mat described. A loop that uses CGI::Fast would look like this:
#!/usr/bin/perl
use strict;
use CGI::Fast;
my $count = 0;
while (my $q = CGI::Fast->new) {
print("Content-Type: text/plain\n\n");
print("Process ID: $$; Count is: " . ++$count);
}
I tested this script on a server with the FCGI and CGI::Fast modules installed and count increments as you'd expect. If the process id changes, count will go back to 1 and then increment within that process. Each process has it's own variable space of course.
For MT, enabling FastCGI a matter of renaming (or symlinking) the cgi scripts to 'fcgi' (or making the handler for 'cgi' scripts fcgid, but that won't work for mt-xmlrpc.cgi which isn't FastCGI friendly yet). You'll also need to add some directives to your mt-config.cgi file so that it knows the new script names. Like this:
AdminScript mt.fcgi
CommentsScript mt-comments.fcgi
And so forth. More documentation specific to FastCGI and Movable Type is available on movabletype.org.
Anyway, based on your server's error logs, it looks like FCGI is working, and being invoked properly, but your script just isn't running in a loop, waiting for the next request to come along. So your test script did accomplish the task -- reporting whether FastCGI is configured or not. So now you should be able to reconfigure MT to use FastCGI.