Google+ Followers

2016年1月14日 星期四

[Linux] 建置 Perl 5.10.0 及 BugZilla 3.0.5 測試環境 @ Ubuntu 14.04

最近接收公司的 Mail Server,其中有一台 Server 在跑 Bugzilla 3.0.5 版本以及跑在 Perl 5.10.0 的環境,然而新的 Mail server 限制外寄走 SMTP + AUTH + SSL 的方式,這時就踩到 Bugzilla 3.0.5 不支援 SMTP AUTH 也不支援 STMP SSL。

我先翻了 Bugzilla 4.4.11 來看,其中 bugzilla-4.4.11/Bugzilla/Mailer.pm 有看到埋了以下功能:

    // bugzilla-4.4.11/Bugzilla/Mailer.pm
    if ($method eq "SMTP") {
        push @args, Host  => Bugzilla->params->{"smtpserver"},
                    username => Bugzilla->params->{"smtp_username"},
                    password => Bugzilla->params->{"smtp_password"},
                    Hello => $hostname,
                    ssl => Bugzilla->params->{'smtp_ssl'},
                    Debug => Bugzilla->params->{'smtp_debug'};
    }


而 Bugzilla 3.0.5 來看:

    //original: bugzilla-3.0.5/Bugzilla/Mailer.pm
    if ($method eq "SMTP") {
        push @args, Host  => Bugzilla->params->{"smtpserver"},
                    Hello => $hostname,
                    Debug => Bugzilla->params->{'smtp_debug'};
    }


很清楚沒看到 Auth 跟 SSL 得設置,很可惜的,當我替 Bugzilla 3.0.5 加入 username/password/ssl 後:

    //modified: bugzilla-3.0.5/Bugzilla/Mailer.pm
    if ($method eq "SMTP") {
        push @args, Host  => Bugzilla->params->{"smtpserver"},
                    username => 'MySMTPAccount',
                    password => 'MySMTPPassword',
                    Hello => $hostname,
                    ssl => 1,
                    Debug => Bugzilla->params->{'smtp_debug'};
    }


就蹦出這個錯誤訊息:

undef error - Can't locate object method "new" via package "Net::SMTP::SSL" at /usr/lib/perl5/site_perl/5.10.0/Email/Send/SMTP.pm line 57.

因此翻一下 5.10.0/Email/Send/SMTP.pm 後,就會看到 SSL 的問題 Orz 只好架設完整的 Perl 跟 Bugzilla 環境來試試了!

想要挑個沒有 Perl 環境,以方便架設 Perl 5.10.0 時,發現有點難搞,好險有 perlbrew 這工具:

$ sudo apt-get install perlbrew

$ perl -v

This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
(with 41 registered patches, see perl -V for more detail)

$ perlbrew init
$ perlbrew --notest install 5.10.0
Installing /home/ubuntu/perl5/perlbrew/build/perl-5.10.0 into ~/perl5/perlbrew/perls/perl-5.10.0

This could take a while. You can run the following command on another shell to track the status:

  tail -f ~/perl5/perlbrew/build.perl-5.10.0.log

perl-5.10.0 is successfully installed.

$ perlbrew use 5.10.0

A sub-shell is launched with 5.10.0 as the activated perl. Run 'exit' to finish it.

bash-4.3$


好的,接下來準備架設 Bugzilla 3.0.5 版:

bash-4.3$  wget https://ftp.mozilla.org/pub/webtools/archived/bugzilla-3.0.5.tar.gz
bash-4.3$  cd bugzilla-3.0.5
bash-4.3$  perl checksetup.pl


就會看到一堆模組需要安裝,接著就手動把上述的指令都跑一跑:

$ sudo apt-get install build-essential mysql-server libmysqlclient-dev libgd-dev libssl-dev imagemagick libmagickcore-dev

$ perl -MCPAN -e 'install "Template"'
$ perl -MCPAN -e 'install "Email::MIME::Modifier"'
$ perl -MCPAN -e 'install "Email::Send"'
$ perl -MCPAN -e 'install "Email::MIME"'
$ perl -MCPAN -e 'install "DBI"'
$ perl -MCPAN -e 'install "DBD::mysql"'

$ perl -MCPAN -e 'install "LWP::UserAgent"'
$ perl -MCPAN -e 'install "GD::Graph"'
$ perl -MCPAN -e 'install "GD::Text"'
$ perl -MCPAN -e 'install "Template::Plugin::GD::Image"'
$ perl -MCPAN -e 'install "GD"'
$ perl -MCPAN -e 'install "Email::Reply"'
$ perl -MCPAN -e 'install "Email::MIME::Attachment::Stripper"'
$ perl -MCPAN -e 'install "Net::LDAP"'
$ perl -MCPAN -e 'install "HTML::Parser"'
$ perl -MCPAN -e 'install "HTML::Scrubber"'
$ perl -MCPAN -e 'install "MIME::Parser"'
$ perl -MCPAN -e 'install "XML::Twig"'
$ perl -MCPAN -e 'install "Chart::Base"'
$ perl -MCPAN -e 'install "Image::Magick"'
$ perl -MCPAN -e 'install "PatchReader"'
$ perl -MCPAN -e 'install "SOAP::Lite"'
$ perl -MCPAN -e 'install "mod_perl2"'


結果一堆 make test 都不過 Orz 只好痛苦改成這樣:

$ perl -MCPAN -e "CPAN::Shell->notest('install', 'YAML')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'ExtUtils::MakeMaker')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'CGI')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Template')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Email::MIME::Modifier')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Email::Send')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Email::MIME')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'DBI')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'DBD::mysql')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'LWP::UserAgent')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'GD::Graph')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'GD::Text')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Template::Plugin::GD::Image')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'GD')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Email::Reply')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Net::LDAP')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Email::MIME::Attachment::Stripper')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'HTML::Parser')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'HTML::Scrubber')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'XML::Twig')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Chart::Base')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'Image::Magick')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'PatchReader')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'SOAP::Lite')"
$ perl -MCPAN -e "CPAN::Shell->notest('install', 'mod_perl2')"


若 CGI.pm 還是一直有問題,就硬上:

$ wget http://search.cpan.org/CPAN/authors/id/L/LE/LEEJO/CGI-4.25.tar.gz
$ tar -xvf CGI-4.25.tar.gz
$ cd CGI-4.25
$ make
$ make install


終於:

bash-4.3$ perl checksetup.pl
* This is Bugzilla 3.0.5 on perl 5.10.0
* Running on Linux 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015

Checking perl modules...
Checking for          CGI.pm (v3.33)   ok: found v4.25
Checking for        TimeDate (v2.21)   ok: found v2.24
Checking for             DBI (v1.41)   ok: found v1.634
Checking for       PathTools (v0.84)   ok: found v3.2501
Checking for Template-Toolkit (v2.12)   ok: found v2.26
Checking for      Email-Send (v2.00)   ok: found v2.201
Checking for      Email-MIME (v1.861)  ok: found v1.936
Checking for Email-MIME-Modifier (v1.442)  ok: found v1.936

Checking available perl DBD modules...
Checking for          DBD-Pg (v1.45)    not found
Checking for       DBD-mysql (v2.9003) ok: found v4.033

The following Perl modules are optional:
Checking for              GD (v1.20)   ok: found v2.56
Checking for     Template-GD (any)     ok: found v1.56
Checking for           Chart (v1.0)    ok: found v2.4.10
Checking for         GDGraph (any)     ok: found v1.51
Checking for      GDTextUtil (any)     ok: found v0.86
Checking for        XML-Twig (any)     ok: found v3.49
Checking for      MIME-tools (v5.406)  ok: found v5.507
Checking for     libwww-perl (any)     ok: found v6.15
Checking for     PatchReader (v0.9.4)  ok: found v0.9.6
Checking for      PerlMagick (any)      not found
Checking for       perl-ldap (any)     ok: found v0.65
Checking for       SOAP-Lite (any)     ok: found v1.19
Checking for     HTML-Parser (v3.40)   ok: found v3.71
Checking for   HTML-Scrubber (any)     ok: found v0.15
Checking for Email-MIME-Attachment-Stripper (any)     ok: found v1.317
Checking for     Email-Reply (any)     ok: found v1.204
Checking for        mod_perl (v1.999022)  not found


大概還有兩個沒裝好,但有點懶在處理了,開始設定 Bugzilla 的部分:

bash-4.3$ vim localconfig
$webservergroup = 'www-data';
$db_driver = 'mysql';
$db_host = 'localhost';
$db_name = 'bugs';
$db_user = 'bugs';
$db_pass = 'bugs';


建立 MySQL 資料:

$ mysql -u root -p -e 'CREATE DATABASE bugs';
$ mysql -u root -p -e 'CREATE USER "bugs"@"%" IDENTIFIED BY "bugs"'
$ mysql -u root -p -e 'GRANT ALL ON *.* TO "bugs"@"%"'


正式安裝 Bugzilla 以及設定管理者資訊:

bash-4.3$ perl checksetup.pl
...


設定 Web server ,此例使用 Apache:

$ sudo apt-get install apache2 libapache2-mod-fcgid
$ sudo a2enmod cgi cgid
$ sudo vim /etc/apache2/sites-available/000-default.conf
AddHandler cgi-script .cgi .pl
Alias /bugzilla/ /home/ubuntu/bugzilla-3.0.5/
<Directory "/home/ubuntu/bugzilla-3.0.5">
        Options +ExecCGI
        AllowOverride All
        #SetHandler cgi-script
        #AddHandler cgi-script .cgi
        Order allow,deny
        Allow from all
        Require all granted
</Directory>
$ sudo service apache2 restart
$ sudo chown -R www-data:www-data bugzilla-3.0.5


將系統內建的 Perl 版本更新為 5.10.0 版本:

bash-4.3$ which perl
/home/ubuntu/perl5/perlbrew/perls/perl-5.10.0/bin/perl
bash-4.3$ sudo mv /usr/bin/perl /usr/bin/perl-5.18
bash-4.3$ sudo ln -s /home/ubuntu/perl5/perlbrew/perls/perl-5.10.0/bin/perl /usr/bin/perl


就可以瀏覽 http://ip/bugzilla/ 啦

最後,才真正開始面對最初待解的問題 Orz 仍需安裝更多軟體:

perl -MCPAN -e "CPAN::Shell->notest('install', 'IO::Socket::SSL')"
perl -MCPAN -e "CPAN::Shell->notest('install', 'Net::SMTP::SSL')"
perl -MCPAN -e "CPAN::Shell->notest('install', 'Net::SMTP::TLS')"
perl -MCPAN -e "CPAN::Shell->notest('install', 'Net::SSLeay')"


結論?!其實 SMTP + SSL + AUTH 還是沒有成功 XD 為了專心測試,反而獨立成解決 Perl 5.10.0 的 Email::Send 模組寄信問題,記錄在另一篇:[Perl] 測試及修正 Perl 5.10.0 的 Email:Send 支援 SMTP + TLS + AUTH 寄信方式 @ perlbrew 5.10.0 / Ubuntu 14.04

沒有留言:

張貼留言