package cPanel::Bulletin_Boards::YaBB;

use strict;
use warnings;

our $VERSION = 0.7;
my $pkg = __PACKAGE__;

require Digest::MD5;

my $new = <<'END_UPGRADE';
<p>We regret to inform you that we cannot provide an update of YaBB. However, you can manually update your YaBB installation. To learn more, please visit <a target="_blank" href="http://www.yabbforum.com/">YaBB's documentation</a>.</p>

END_UPGRADE

our $meta_info = {
    disable => {
        install => $new,
    },
    require_suexec      => 1,
    admin_email         => 1,
    installdir          => 'yabb',
    description         => 'Fast and efficient forum/BB system written in Perl. It is feature rich and does not have the security issues inherent to PHP based scripts. For information on Yet another Bulletin Board (YaBB) or support, please visit their website above.',
    version             => '2.3.1',
    security_rank       => 8,
    website             => 'http://yabbforum.com/',
    config_files        => [qw(Paths.pl Members/admin.vars Members/memberinfo.txt Members/memberlist.txt Variables/secsettings.txt Variables/Settings.pl)],
    install_fields_hook => sub {
        my ( $input_hr, $error_ref, $cpo ) = @_;
        ${$error_ref} = 'Invalid password. Minimum 7 letters, numbers, or underscores'
          if $input_hr->{'password'} !~ m/^\w+$/ || length $input_hr->{'password'} < 7;

        $cpo->{'password_md5_base64'} = Digest::MD5::md5_base64( $input_hr->{'password'} );

        require Cpanel::cPanelFunctions;    # not necessary but for good measure :)
        $cpo->{'input_webmaster_email'} = $cpo->{'email'} if !$input_hr->{'webmaster_email'};
        ${$error_ref} .= '<br />Invalid webmaster email'
          if !Cpanel::cPanelFunctions::validemail( $cpo->{'input_webmaster_email'} );

    },
    install_fields => {
        password => {
            label => 'Password for "admin"',
            value => '',
            attr  => '',
            type  => 'text'
        },
        'webmaster_email' => {
            label => 'Webmaster email (leave blank to be the same as above)',
            value => '',
            attr  => '',
            type  => 'text'
        },
    },
    '2.1' => {
        'public_html_install_note'    => 'All files installed are removed upon uninstallation so take care you don\'t lose anything on uninstalls for installs that are installed directly in a DocumentRoot',
        'public_html_install_files'   => [qw( fader.js post.js ubbc.js yabbc.js YaBB.pl Paths.pl index.html FixFile.pl AdminIndex.pl )],
        'public_html_install_unknown' => [
            qw(
              Admin/   Attachments/ Boards/  Help/    Languages/ Messages/ Modules/   Sources/
              avatars/ Buttons/     Convert/ Members/ ModImages/ Smilies/  Templates/ Variables/
              )
        ],
    },
};

%{ $meta_info->{'2.2'} }   = %{ $meta_info->{'2.1'} };
%{ $meta_info->{'2.2.2'} } = %{ $meta_info->{'2.1'} };
%{ $meta_info->{'2.2.3'} } = %{ $meta_info->{'2.1'} };
%{ $meta_info->{'2.3'} }   = %{ $meta_info->{'2.1'} };

# 2.3.1 and on we'll be using manifest files
if ( defined &Cpanel::cPAddons::proc_keys_named_after_version ) {
    Cpanel::cPAddons::proc_keys_named_after_version( $meta_info, __PACKAGE__ );
}

#### action functions ##
sub install {
    print $meta_info->{'disable'}{'install'};
    return;
}
sub upgrade   { shift->stdupgrade(@_) }
sub uninstall { shift->stduninstall(@_) }

#### non action functions ##
sub installform   { print $meta_info->{'disable'}{'install'} }
sub upgradeform   { print shift->{upgradeform} }
sub uninstallform { print shift->{uninstallform} }

1;
