###
###  Copyright 2000-2007 University of Illinois Board of Trustees
###  All rights reserved. 
###
###  qpopper.pm - qpopper configuration module for psgconf
###
###  Campus Information Technologies and Educational Services
###  University of Illinois at Urbana-Champaign
###


package PSGConf::Control::qpopper;

use strict;

use PSGConf::Action::GenerateFile::qpopper_conf;
use PSGConf::Data::Boolean;
use PSGConf::Data::Hash;
use PSGConf::Data::List;
use PSGConf::Data::String;
use PSGConf::Control::Packages qw(_add_pkgs);
use PSGConf::Control::syslog qw(_add_syslog);


###############################################################################
###  decide() method
###############################################################################

sub decide
{
	my ($self, $psgconf) = @_;

	$psgconf->register_actions(
		PSGConf::Action::GenerateFile::qpopper_conf->new(
			name		=> '/etc/qpopper.conf',
			description	=> 'qpopper configuration file (pop3)',
			options		=> $psgconf->data_obj('qpopper_options')->get()
		)
	) if ($psgconf->data_obj('qpopper_enable')->equals('true'));

	$psgconf->register_actions(
		PSGConf::Action::GenerateFile::qpopper_conf->new(
			name		=> '/etc/qpopper_ssl.conf',
			description	=> 'qpopper configuration file (pop3s)',
			options		=> $psgconf->data_obj('qpopper_ssl_options')->get()
		)
	) if ($psgconf->data_obj('qpopper_ssl_enable')->equals('true'));
}


###############################################################################
###  policy methods
###############################################################################

sub _policy_add_packages
{
	my ($self, $psgconf) = @_;

	$self->_add_pkgs($psgconf);

	### Add if we are just using SSL also.
	$self->{enable} = 'qpopper_ssl_enable';
	$self->_add_pkgs($psgconf);
}

sub _policy_add_syslog
{
	my ($self, $psgconf) = @_;

	$self->{facility} = $psgconf->data_obj('qpopper_syslog')->get();

	return $self->_add_syslog($psgconf);
}

sub _add_inetd
{
	my ($self, $psgconf) = @_;
	my ($inetd);

	$inetd = $psgconf->data_obj('inetd')->get();

	if ($psgconf->data_obj('qpopper_enable')->equals('true')
	    && !exists($inetd->{'pop3/tcp'}))
	{
		$inetd->{'pop3/tcp'} = {
			server		=> $psgconf->data_obj('qpopper_path')->get(),
			server_args	=> '-f /etc/qpopper.conf '
					   . $psgconf->data_obj('qpopper_args')->get()
		};
	}

	if ($psgconf->data_obj('qpopper_ssl_enable')->equals('true')
	    && !exists($inetd->{'pop3s/tcp'}))
	{
		$inetd->{'pop3s/tcp'} = {
			server		=> $psgconf->data_obj('qpopper_path')->get(),
			server_args	=> '-f /etc/qpopper_ssl.conf '
					   . $psgconf->data_obj('qpopper_ssl_args')->get()
		};
	}
}


sub _add_tcp_wrappers
{
	my ($self, $psgconf) = @_;

	return
		if ( $psgconf->data_obj('qpopper_enable')->equals('false')
			|| $psgconf->data_obj('qpopper_ssl_enable')->equals('false'));

	$psgconf->data_obj('tcp_wrappers')->insert_row(
		{ 1 => 'all' },
		[ 'popper', 'all', 'allow' ]
	) if (! $psgconf->data_obj('tcp_wrappers')->find_row(
				{ 0 => qr/\bpopper\b/ }
		));
}


###############################################################################
###  constructor
###############################################################################

sub new
{
	my ($class, $psgconf) = @_;
	my ($self);

	$self = {};
	bless($self, $class);

	$self->{name} = 'qpopper';
	$self->{enable} = $self->{name} . '_enable';
	$self->{packages} = $self->{name} . '_packages';
	$self->{syslog} = $self->{name};

	$psgconf->register_data(
		qpopper_path		=> PSGConf::Data::String->new(
						'value_abspath' => 1,
						value => '/usr/local/sbin/popper'
					   ),
		qpopper_enable		=> PSGConf::Data::Boolean->new(
							'value' => 'false'
						),
		qpopper_packages        => PSGConf::Data::List->new(),
		qpopper_args		=> PSGConf::Data::String->new(),
		qpopper_syslog		=> PSGConf::Data::String->new(
							'value' => 'local0.info'
						),
		qpopper_options		=> PSGConf::Data::Hash->new(),
		qpopper_ssl_enable	=> PSGConf::Data::Boolean->new(
							'value' => 'false'
						),
		qpopper_ssl_args	=> PSGConf::Data::String->new(),
		qpopper_ssl_options	=> PSGConf::Data::Hash->new()
	);

	$psgconf->register_policy($self,
		qpopper_add_packages	=> '_policy_add_packages',
		qpopper_add_inetd	=> '_add_inetd',
		qpopper_add_syslog	=> '_policy_add_syslog',
		qpopper_add_tcpwrapper_entry
					=> '_add_tcp_wrappers'
	);

	return $self;
}


###############################################################################
###  documentation
###############################################################################

1;

__END__

=head1 NAME

PSGConf::Control::qpopper - psgconf control class for qpopper configuration

=head1 SYNOPSIS

In F<psgconf_modules>:

  Control PSGConf::Control::qpopper

=head1 DESCRIPTION

The B<PSGConf::Control::qpopper> module provides a B<psgconf> control
object for configuring B<qpopper>, the Qualcomm POP server.  It supports
the following methods:

=over 4

=item new()

The constructor.  Its parameter is a reference to the B<PSGConf>
object.  It registers the following data objects:

=over 4

=item I<qpopper_path>

A B<PSGConf::Data::String> object containing the absolute path of the
B<qpopper> binary.  The default is F</usr/local/sbin/popper>.

=item I<qpopper_enable>

A B<PSGConf::Data::Boolean> object indicating whether B<qpopper> should
be configured on the standard I<pop3> service port.

=item I<qpopper_packages>

A B<PSGConf::Data::List> object listing all packages that need to be installed.

=item I<qpopper_args>

A B<PSGConf::Data::String> object containing additional arguments to be
passed to B<qpopper> when it is invoked by B<inetd> on the I<pop3>
port.

=item I<qpopper_syslog>

A B<PSGConf::Data::String> object containing the default syslog facility
the application logs to.  Default is C<local0.info>.

=item I<qpopper_options>

A B<PSGConf::Data::Hash> object containing configuration options to be
set in the configuration file used by B<qpopper> when it is invoked on
the I<pop3> port.

=item I<qpopper_ssl_enable>

A B<PSGConf::Data::Boolean> object indicating whether B<qpopper> should
be configured on the I<pop3s> service port (i.e., for SSL-encrypted POP).

=item I<qpopper_ssl_args>

A B<PSGConf::Data::String> object containing additional arguments to be
passed to B<qpopper> when it is invoked by B<inetd> on the I<pop3s>
port.

=item I<qpopper_ssl_options>

A B<PSGConf::Data::Hash> object containing configuration options to be
set in the configuration file used by B<qpopper> when it is invoked on
the I<pop3s> port.

=back

The constructor also registers the following policy methods:

=over 4

=item I<qpopper_add_packages>

Adds an entry for I<qpopper> to the I<pkg_install_list> object (provided
by B<PSGConf::Control::Packages>), if not already present.

=item I<qpopper_add_syslog>

Adds C<qpopper_syslog> to the I<syslog> data object (which is
supplied by the B<PSGConf::Control::syslog> module).

=item I<qpopper_add_inetd>

Adds entries for I<qpopper> to the I<inetd> object (provided
by B<PSGConf::Control::inetd>).

=item I<qpopper_add_tcpwrapper_entry>

Adds an entry for I<qpopper> to the I<tcp_wrappers> object (provided
by B<PSGConf::Control::TCPWrappers>).

=back

=item decide()

If I<qpopper_enable> is set, registers a
B<PSGConf::Action::GenerateFile::qpopper_conf> object to create
the F</etc/qpopper.conf> file.

If I<qpopper_ssl_enable> is set, registers a
B<PSGConf::Action::GenerateFile::qpopper_conf> object to create
the F</etc/qpopper_ssl.conf> file.

=back

=head1 SEE ALSO

L<perl>

popper(8)

L<PSGConf>

L<PSGConf::Action::GenerateFile::qpopper_conf>

L<PSGConf::Control::inetd>

L<PSGConf::Control::Packages>

L<PSGConf::Control::syslog>

L<PSGConf::Control::TCPWrappers>

L<PSGConf::Data::Boolean>

L<PSGConf::Data::Hash>

L<PSGConf::Data::List>

L<PSGConf::Data::String>

L<PSGConf::Util>

L<psgconf-intro>

=cut



syntax highlighted by Code2HTML, v. 0.9.1