Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postfix package for pfSense 2.3 #23

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions mail/pfSense-pkg-postfix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-postfix
PORTVERSION= 2.5
CATEGORIES= mail
MASTER_SITES= # empty
DISTFILES= # empty
EXTRACT_ONLY= # empty

MAINTAINER= marcellocoutinho@gmail.com
COMMENT= pfSense package Postfix Forwarder.

RUN_DEPENDS= ${LOCALBASE}/sbin/postfix:${PORTSDIR}/mail/postfix \
p5-perl-ldap>0:${PORTSDIR}/net/p5-perl-ldap

USE_PERL5= run
USES= perl5

NO_BUILD= yes
NO_MTREE= yes

SUB_FILES= pkg-install pkg-deinstall
SUB_LIST= PORTNAME=${PORTNAME}

do-extract:
${MKDIR} ${WRKSRC}

do-install:
${MKDIR} ${STAGEDIR}${PREFIX}/pkg
${MKDIR} ${STAGEDIR}${PREFIX}/www/shortcuts
${MKDIR} ${STAGEDIR}/etc/inc/priv
${MKDIR} ${STAGEDIR}${PREFIX}/www/widgets/widgets
${MKDIR} ${STAGEDIR}${PREFIX}/www
${MKDIR} ${STAGEDIR}${PREFIX}/bin
${MKDIR} ${STAGEDIR}${DATADIR}
${INSTALL_DATA} -m 0644 ${FILESDIR}${PREFIX}/pkg/postfix.xml \
${STAGEDIR}${PREFIX}/pkg
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/postfix.inc \
${STAGEDIR}${PREFIX}/pkg
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/postfix_acl.xml \
${STAGEDIR}${PREFIX}/pkg
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/postfix_domains.xml \
${STAGEDIR}${PREFIX}/pkg
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/postfix_recipients.xml \
${STAGEDIR}${PREFIX}/pkg
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/postfix_antispam.xml \
${STAGEDIR}${PREFIX}/pkg
${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/postfix_sync.xml \
${STAGEDIR}${PREFIX}/pkg
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/postfix_view_config.php \
${STAGEDIR}${PREFIX}/www
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/postfix_recipients.php \
${STAGEDIR}${PREFIX}/www
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/postfix_search.php \
${STAGEDIR}${PREFIX}/www
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/postfix.php \
${STAGEDIR}${PREFIX}/www
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/postfix_about.php \
${STAGEDIR}${PREFIX}/www
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/widgets/widgets/postfix.widget.php \
${STAGEDIR}${PREFIX}/www/widgets/widgets
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/postfix_queue.php \
${STAGEDIR}${PREFIX}/www
${INSTALL_DATA} ${FILESDIR}/etc/inc/priv/postfix.priv.inc \
${STAGEDIR}/etc/inc/priv
${INSTALL_DATA} ${FILESDIR}${PREFIX}/bin/adexport.pl \
${STAGEDIR}${PREFIX}/bin
${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/shortcuts/pkg_postfix.inc \
${STAGEDIR}${PREFIX}/www/shortcuts
${INSTALL_DATA} ${FILESDIR}${DATADIR}/info.xml \
${STAGEDIR}${DATADIR}

.include <bsd.port.mk>
24 changes: 24 additions & 0 deletions mail/pfSense-pkg-postfix/files/etc/inc/priv/postfix.priv.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

global $priv_list;

$priv_list['page-diagnostics-search-email'] = array();
$priv_list['page-diagnostics-search-email']['name'] = "WebCfg - Diagnostics: Postfix search email";
$priv_list['page-diagnostics-search-email']['descr'] = "Allow access to postfix search page.";
$priv_list['page-diagnostics-search-email']['match'] = array();
$priv_list['page-diagnostics-search-email']['match'][] = "postfix_search.php*";

$priv_list['page-status-postfix-queue'] = array();
$priv_list['page-status-postfix-queue']['name'] = "WebCfg - Status: Postfix queue";
$priv_list['page-status-postfix-queue']['descr'] = "Allow access to postfix queue page.";
$priv_list['page-status-postfix-queue']['match'] = array();
$priv_list['page-status-postfix-queue']['match'][] = "postfix_queue.php*";

$priv_list['page-services-postfix-forwarder'] = array();
$priv_list['page-services-postfix-forwarder']['name'] = "WebCfg - Services: All xml pages (config).";
$priv_list['page-services-postfix-forwarder']['descr'] = "Allow access to any xml package page.";
$priv_list['page-services-postfix-forwarder']['match'] = array();
$priv_list['page-services-postfix-forwarder']['match'][] = "pkg_edit.php*";
$priv_list['page-services-postfix-forwarder']['match'][] = "postfix*.php*";

?>
3 changes: 3 additions & 0 deletions mail/pfSense-pkg-postfix/files/pkg-deinstall.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

/usr/local/bin/php -f /etc/rc.packages %%PORTNAME%% ${2}
7 changes: 7 additions & 0 deletions mail/pfSense-pkg-postfix/files/pkg-install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if [ "${2}" != "POST-INSTALL" ]; then
exit 0
fi

/usr/local/bin/php -f /etc/rc.packages %%PORTNAME%% ${2}
189 changes: 189 additions & 0 deletions mail/pfSense-pkg-postfix/files/usr/local/bin/adexport.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/usr/local/bin/perl -w
##############################################################################
#
# Script to export a list of all email addresses from Active Directory
# Brian Landers <brian@packetslave.com>
#
# This code is in the public domain. Your use of this code is at your own
# risk, and no warranty is implied. The author accepts no liability for any
# damages or risks incurred by its use.
#
##############################################################################
# This script would be most useful for generating an access.db file on a
# sendmail gateway server. You would run it to generate a list of all
# valid email addresses, then insert those addresses into access.db as
# follows:
#
# To:bob@example.com RELAY
# To:jim@example.com RELAY
# To:joe@example.com RELAY
#
# Then, you'd create a default entry for the domain that rejects all other
# recipients (since if they're not in the list, they're by definition invalid).
#
# To:example.com ERROR:"User unknown"
#
# For this to work, you need to have "example.com" in your relay-domains
# file (normally /etc/mail/relay-domains), and you need to enable the
# "blacklist_recipients" FEATURE in your sendmail.mc file.
#
# FEATURE(`blacklist_recipients')
#
# See also my genaccessdb script at packetslave.com for ideas on how to
# generate the access.db file from this list of addresses
#
##############################################################################
# $Id: adexport,v 1.2 2011/08/20 23:30:52 blanders Exp $

use strict;
$|++;

use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED );

#our ($cn,$passwd,$base);
#($cn,$passwd,$base)=@_ARGV;
#print "$cn \n $passwd \n $base";
#exit;

# ---- Constants ----
our $bind = $ARGV[2].','.$ARGV[1]; # AD account
our $passwd = $ARGV[3]; # AD password
our $base = $ARGV[1]; # Start from root
our @servers;
push (@servers,$ARGV[0]);
our $filter = '(|(objectClass=publicFolder)(&(sAMAccountName=*)(mail=*)))';
# -------------------


# We use this to keep track of addresses we've seen
my %gSeen;

# Connect to the server, try each one until we succeed
my $ldap = undef;
foreach( @servers ) {
$ldap = Net::LDAP->new( $_ );
last if $ldap;

# If we get here, we didn't connect
die "Unable to connect to any LDAP servers!\n";
}

# Create our paging control. Exchange has a maximum recordset size of
# 1000 records by default. We have to use paging to get the full list.

my $page = Net::LDAP::Control::Paged->new( size => 100 );

# Try to bind (login) to the server now that we're connected
my $msg = $ldap->bind( dn => $bind,
password => $passwd
);

# If we can't bind, we can't continue
if( $msg->code() ) {
die( "error while binding:", $msg->error_text(), "\n" );
}

# Build the args for the search
my @args = ( base => $base,
scope => "subtree",
filter => $filter,
attrs => [ "proxyAddresses" ],
callback => \&handle_object,
control => [ $page ],
);

# Now run the search in a loop until we run out of results. This code
# is taken pretty much directly from the example code in the perldoc
# page for Net::LDAP::Control::Paged

my $cookie;
while(1) {
# Perform search
my $mesg = $ldap->search( @args );

# Only continue on LDAP_SUCCESS
$mesg->code and last;

# Get cookie from paged control
my($resp) = $mesg->control( LDAP_CONTROL_PAGED ) or last;
$cookie = $resp->cookie or last;

# Set cookie in paged control
$page->cookie($cookie);
}

if( $cookie ) {
# We had an abnormal exit, so let the server know we do not want any more
$page->cookie($cookie);
$page->size(0);
$ldap->search( @args );
}

# Finally, unbind from the server
$ldap->unbind;

# ------------------------------------------------------------------------
# Callback function that gets called for each record we get from the server
# as we get it. We look at the type of object and call the appropriate
# handler function
#

sub handle_object {

my $msg = shift; # Net::LDAP::Message object
my $data = shift; # May be Net::LDAP::Entry or Net::LDAP::Reference

# Only process if we actually got data
return unless $data;

return handle_entry( $msg, $data ) if $data->isa("Net::LDAP::Entry");
return handle_reference( $msg, $data ) if $data->isa("Net::LDAP::Reference");

# If we get here, it was something we're not prepared to handle,
# so just return silently.

return;
}

# ------------------------------------------------------------------------
# Handler for a Net::LDAP::Entry object. This is an actual record. We
# extract all email addresses from the record and output only the SMTP
# ones we haven't seen before.

sub handle_entry {

my $msg = shift;
my $data = shift;

# Extract the email addressess, selecting only the SMTP ones, and
# filter them so that we only get unique addresses

my @mails = grep { /^smtp:/i && !$gSeen{$_}++ }
$data->get_value( "proxyAddresses" );

# If we found any, strip off the SMTP: identifier and print them out
if( @mails ) {
print map { s/^smtp:(.+)$/\L$1\n/i; $_ } @mails;
}
}

# ------------------------------------------------------------------------
# Handler for a Net::LDAP::Reference object. This is a 'redirect' to
# another portion of the directory. We simply extract the references
# from the object and resubmit them to the handle_object function for
# processing.

sub handle_reference {

my $msg = shift;
my $data = shift;

foreach my $obj( $data->references() ) {

# Oooh, recursion! Might be a reference to another reference, after all
return handle_object( $msg, $obj );
}
}

Loading