commit 754accf27dbc8d1b9595279fd860ddf325bce8c3 Author: Daniel Berteaud Date: Thu Nov 22 09:48:02 2012 +0100 Initial commit diff --git a/createlinks b/createlinks new file mode 100644 index 0000000..aef4fb1 --- /dev/null +++ b/createlinks @@ -0,0 +1,10 @@ +#!/usr/bin/perl -w + +use esmith::Build::CreateLinks qw(:all); + +panel_link('minilist','manager'); + +event_link("qmail-update-list", "list-create", "20"); +event_link("qmail-update-list", "list-modify", "20"); +event_link("qmail-delete-list", "list-delete", "20"); +templates2events("/var/service/qpsmtpd/config/goodrcptto", qw(list-create list-modify list-delete)); diff --git a/root/etc/e-smith/events/actions/qmail-delete-list b/root/etc/e-smith/events/actions/qmail-delete-list new file mode 100644 index 0000000..0ff69b4 --- /dev/null +++ b/root/etc/e-smith/events/actions/qmail-delete-list @@ -0,0 +1,18 @@ +#!/usr/bin/perl -w + +package esmith; + +use strict; +use Errno; + +my $event = $ARGV [0]; +my $list = $ARGV [1]; + +die "list name argument missing." unless defined ($list); + +$list =~ s/\./:/g; +unlink "/var/qmail/alias/.qmail-$list"; +unlink "/var/qmail/alias/.qmail-$list-default"; + +exit (0); + diff --git a/root/etc/e-smith/events/actions/qmail-update-list b/root/etc/e-smith/events/actions/qmail-update-list new file mode 100644 index 0000000..0fb2118 --- /dev/null +++ b/root/etc/e-smith/events/actions/qmail-update-list @@ -0,0 +1,53 @@ +#!/usr/bin/perl -w + +package esmith; + +use strict; +use Errno; +use esmith::ConfigDB; +use esmith::AccountsDB; +use esmith::util; + +my $c = esmith::ConfigDB->open_ro || die "Couldn't open config db\n"; +my $a = esmith::AccountsDB->open_ro || die "Couldn't open accounts db\n"; + +my $event = $ARGV [0] || die "Event name arg missing\n";; +my @lists; + +if ($ARGV[1]){ + @lists = $a->get($ARGV[1]); +} + +@lists = $a->get_all_by_prop(type=>'minilist') + if (scalar @lists lt 1); + + +foreach my $list (@lists){ + my $name = $list->key; + unless ($list->prop('type') eq 'minilist'){ + warn "Account $name is not a mailinglist account.\n"; + next; + } + my $members = $list->prop('Members') || ''; + + esmith::util::processTemplate( + { + CONFREF => + { + Members => $members, + }, + + TEMPLATE_PATH => + "/var/qmail/alias/.qmail-group", + + OUTPUT_FILENAME => "/var/qmail/alias/.qmail-$name", + } + ); + + unless (-f "/var/qmail/alias/.qmail-$name-default"){ + symlink "/var/qmail/alias/.qmail-$name", + "/var/qmail/alias/.qmail-$name-default"; + } +} +exit (0); + diff --git a/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/minilist b/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/minilist new file mode 100644 index 0000000..8f2933b --- /dev/null +++ b/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/minilist @@ -0,0 +1,118 @@ + + + MINILIST + Mailing lists + + + FORM_TITLE + Create, modify, or remove mailing lists + + + CREATE_LIST + Create a new list + + + DESC_NAME + + The list name will be used as mail address for the list. + It needs to contains only lowercases letters, numbers, periods (.), hyphens (-) and undescores (_). + It must start with a letter or a number. + + + + LABEL_NAME + Name + + + LABEL_DESC + Description + + + DESC_DESC + You can enter a description for this list + + + LABEL_MEMBERS + Members + + + DESC_MEMBERS + Enter here the mail addresses which will be part of this list. One address per line. You can also enter user login. + + + VALIDATE + Validate + + + REMOVE_LIST + Remove a list + + + DESC_REMOVE + You are about to remove the following list. Are you sure you want to continue ? + + + REMOVE + Remove + + + MODIFY_LIST + Modify a list + + + LIST_ADD + Add a new list + + + NO_LIST_CREATED + Ther's no list configured + + + LIST + List + + + DESCRIPTION + Description + + + ACTION + Action + + + MODIFY + Modify + + + CREATE_ERROR + An error occured during list creation + + + CREATE_SUCCESS + List successfully created + + + MODIFY_ERROR + An error occured during list modification + + + MODIFY_SUCCESS + List successfully modified + + + DELETE_ERROR + An error occured during list removal + + + DELETE_SUCCESS + List successfully deleted + + + INVALID_CHARS + {$string} contains invalid characters + + + ACCOUNT_CLASH + Another account named {$string} allready exists on this system + + diff --git a/root/etc/e-smith/locale/fr/etc/e-smith/web/functions/minilist b/root/etc/e-smith/locale/fr/etc/e-smith/web/functions/minilist new file mode 100644 index 0000000..1871c53 --- /dev/null +++ b/root/etc/e-smith/locale/fr/etc/e-smith/web/functions/minilist @@ -0,0 +1,118 @@ + + + MINILIST + Mailing lists + + + FORM_TITLE + Création, modification ou suppression des listes + + + CREATE_LIST + Création d'une nouvelle liste + + + DESC_NAME + + Le nom de la liste sera utilisé comme adresse mail. + Il ne doit contenir que des lettres minuscules, des nombres, des points (.), des traits d'union (-) et des underscores (_). + Il doit commencer par une lettre ou un nombre. + + + + LABEL_NAME + Nom + + + LABEL_DESC + Description + + + DESC_DESC + Vous pouvez entrer une description pour cette liste + + + LABEL_MEMBERS + Membres + + + DESC_MEMBERS + Entrez ici les adresses mail membres de la liste. Une adresse par ligne. Vous pouvez aussi entrer des identifiants d'utilisateurs. + + + VALIDATE + Valider + + + REMOVE_LIST + Suppression d'une liste + + + DESC_REMOVE + Vous êtes sur le point de supprimer la liste suivante. Êtes-vous sûre de vouloir continuer ? + + + REMOVE + Supprimer + + + MODIFY_LIST + Modification d'une liste + + + LIST_ADD + Ajouter une liste + + + NO_LIST_CREATED + Aucune liste n'est configurée + + + LIST + Liste + + + DESCRIPTION + Description + + + ACTION + Action + + + MODIFY + Modifier + + + CREATE_ERROR + Une erreur est sruvenue pendant la création de la liste + + + CREATE_SUCCESS + La liste a été créée + + + MODIFY_ERROR + Une erreur est survenue durant la modification de la liste + + + MODIFY_SUCCESS + La liste a été modifiée + + + DELETE_ERROR + Une erreur est survenue durant la suppression de la liste + + + DELETE_SUCCESS + La liste a été supprimée + + + INVALID_CHARS + {$string} contient des caractères invalides + + + ACCOUNT_CLASH + Un autre compte nommé {$string} existe sur ce système + + diff --git a/root/etc/e-smith/templates/var/service/qpsmtpd/config/goodrcptto/45minilist b/root/etc/e-smith/templates/var/service/qpsmtpd/config/goodrcptto/45minilist new file mode 100644 index 0000000..e021862 --- /dev/null +++ b/root/etc/e-smith/templates/var/service/qpsmtpd/config/goodrcptto/45minilist @@ -0,0 +1,17 @@ +{ + use esmith::AccountsDB; + + $OUT = ""; + + my $a = esmith::AccountsDB->open_ro(); + + foreach my $list ($a->get_all_by_prop(type=>'minilist')){ + my $key = $list->key; + if ($key =~ /\@/){ + $OUT .= "$key\n"; + } + else{ + $OUT .= "$key\@$_\n" for (@domains); + } + } +} diff --git a/root/etc/e-smith/web/functions/minilist b/root/etc/e-smith/web/functions/minilist new file mode 100644 index 0000000..a048553 --- /dev/null +++ b/root/etc/e-smith/web/functions/minilist @@ -0,0 +1,93 @@ +#!/usr/bin/perl -wT + +# vim: ft=xml ts=4 sw=4 et: +#---------------------------------------------------------------------- +# heading : Collaboration +# description : MINILIST +# navigation : 2200 2400 +#---------------------------------------------------------------------- +#---------------------------------------------------------------------- +# copyright (C) 2012 Firewall Services +# daniel@firewall-services.com +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +#---------------------------------------------------------------------- + + +use strict; +use esmith::FormMagick::Panel::minilist; +my $f = esmith::FormMagick::Panel::minilist->new(); +$f->display(); + + +__DATA__ +
+ + + + + CREATE_LIST + DESC_NAME + + + + + + DESC_DESC + + + + DESC_MEMBERS + + + + + REMOVE_LIST + + + DESC_REMOVE + + + + + + + + + + + MODIFY_LIST + + + + + + + + + DESC_MEMBERS + + + +
+ diff --git a/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/minilist.pm b/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/minilist.pm new file mode 100644 index 0000000..6dd8234 --- /dev/null +++ b/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/minilist.pm @@ -0,0 +1,210 @@ +#!/usr/bin/perl -w + +package esmith::FormMagick::Panel::minilist; + +use strict; + +use esmith::FormMagick; +use esmith::ConfigDB; +use esmith::AccountsDB; +use File::Basename; +use Exporter; +use Carp; + +our @ISA = qw(esmith::FormMagick Exporter); + +our @EXPORT = qw( + new + get_accounts_prop + get_members + get_html_members + get_description + show_initial + create_list + modify_list + delete_list + validate_list_name + validate_list_description + validate_list_members +); + +our $a = esmith::AccountsDB->open() || die "Couldn't open accounts"; +our $db = esmith::ConfigDB->open || die "Couldn't open config db"; + +sub new { + shift; + my $self = esmith::FormMagick->new(); + $self->{calling_package} = (caller)[0]; + bless $self; + return $self; +} + +# return the value of a prop from an account object +sub get_accounts_prop { + my $fm = shift; + my $item = shift; + my $prop = shift; + + my $record = $a->get($item); + + if ($record) { + return $record->prop($prop); + } + else { + return ''; + } +} + +# Return the members of a list +sub get_members { + my $fm = shift; + my $q = $fm->{cgi}; + my $list = $q->param('listName') || ''; + my @members = split /[;,]/, get_accounts_prop($fm,$list,'Members'); + my $members = join "\n", @members; + return $members; +} + +# return the members of a list +# to display in HTML +sub get_html_members { + my $fm = shift; + my $q = $fm->{cgi}; + my $list = $q->param('listName') || ''; + my $members = get_members($fm,$list); + $members =~ s/\n/
/g; + return $members; +} + +# return the description of a list +sub get_description { + my $fm = shift; + my $q = $fm->{cgi}; + my $list = $q->param('listName') || ''; + return get_accounts_prop($fm,$list,'Description'); +} + +# Print a table with the actual list and a button to create new ones +sub show_initial () { + my $fm = shift; + my $q = $fm->{cgi}; + + my @lists = $a->get_all_by_prop(type=>'minilist'); + + print $q->Tr($q->td( + "

" + . $fm->localise("LIST_ADD") + . "

")); + + if ( scalar @lists == 0 ) { + print $q->Tr($q->td( + '

' . $fm->localise("NO_LIST_CREATED") . '

')); + } + else { + print $q->start_table({-CLASS => "sme-border"}),"\n"; + print "" + . $fm->localise("LIST") + . " " + . $fm->localise('DESCRIPTION') + . "" + . $fm->localise('ACTION') + . ""; + foreach my $list ( @lists ) { + my $name = $list->key; + print "" . "" + . $name . "" . "" + . $list->prop('Description') . "" + . "" + . $fm->localise("MODIFY") . "" + . "" + . $fm->localise("REMOVE") . "" . ""; + + } + print $q->end_table,"\n"; + } + return; +} + +# Create a new list +sub create_list { + my $fm =shift; + my $q = $fm->{cgi}; + my $name =$q->param('listName') || ''; + my @members = split /\r?\n/, ($q->param('members') || ''); + my $members = join ",", @members; + + my %props = ( + 'type', 'minilist', 'Description', + $q->param('listDesc'), 'Members', $members + ); + + $a->new_record( $name, \%props ); + ($name) = ($name =~ /^([a-z0-9][\-\_\.a-z0-9]*)$/); + return system("/sbin/e-smith/signal-event", "list-create", "$name") ? + $fm->error('CREATE_ERROR') : $fm->success('CREATE_SUCCESS'); +} + +# modify an existinbg list +sub modify_list { + my $fm =shift; + my $q = $fm->{cgi}; + my $name =$q->param('listName') || ''; + my @members = split /\r?\n/, ($q->param('members') || ''); + my $members = join ",", @members; + $a->set_prop($name,'Description',$q->param('listDesc')); + $a->set_prop($name,'Members',$members); + ($name) = ($name =~ /^([a-z0-9][\-\_\.a-z0-9]*)$/); + return system("/sbin/e-smith/signal-event", "list-modify", "$name") ? + $fm->error('MODIFY_ERROR') : $fm->success('MODIFY_SUCCESS'); +} + +# delete a list (after confirmation) +sub delete_list { + my $fm =shift; + my $q = $fm->{cgi}; + my $name =$q->param('listName') || ''; + return $fm->error('DELETE_ERROR') unless $a->get($name)->delete; + ($name) = ($name =~ /^([a-z0-9][\-\_\.a-z0-9]*)$/); + return system("/sbin/e-smith/signal-event", "list-delete", "$name") ? + $fm->error('DELETE_ERROR') : $fm->success('DELETE_SUCCESS'); +} + +# Validate list name +sub validate_list_name { + my $fm = shift; + my $name = shift; + unless ($name =~ /^([a-zA-Z0-9][\_\.\-a-zA-Z0-9]*)$/){ + return $fm->localise('INVALID_CHARS',{string => $name}); + } + if ($a->get($name)){ + return $fm->localise('ACCOUNT_CLASH',{string => $name}); + } + return "OK"; +} + +# Validate list description +sub validate_list_description { + my $fm = shift; + my $desc = shift; + unless ($desc =~ /^([a-zA-Z0-9][\s\w\.\-]*)$/){ + return $fm->localise('INVALID_CHARS',{string => $desc}); + } + return "OK"; +} + +# Validate memebrs of a list +sub validate_list_members { + my $fm = shift; + my $members = shift; + foreach my $member (split /\r?\n/, $members) { + my $acc = $a->get($member); + if ($acc){ + my $type = $acc->prop('type') || 'none'; + next if ($type eq 'user'); + } + unless ($member =~ /^[a-zA-Z0-9][\w\.\-]*\@([a-zA-Z0-9\._\-]+\.[a-zA-Z0-9\._\-]+)$/){ + return $fm->localise('INVALID_CHARS',{string => $member}); + } + } + return "OK"; +} diff --git a/smeserver-minilist.spec b/smeserver-minilist.spec new file mode 100644 index 0000000..c2447a4 --- /dev/null +++ b/smeserver-minilist.spec @@ -0,0 +1,52 @@ +%define version 0.1.1 +%define release 1 +%define name smeserver-minilist + + +Summary: minilist provide a panel to manage simple mailing lists +Name: %{name} +Version: %{version} +Release: %{release}%{?dist} +License: GPL +Group: Networking/Daemons +Source: %{name}-%{version}.tar.gz + +BuildRoot: /var/tmp/%{name}-%{version}-%{release}-buildroot +BuildArchitectures: noarch +BuildRequires: e-smith-devtools + +Requires: e-smith-base >= 5.2.0 + +%description +Provides group like mail fonctionnality, but lets you enter arbitrary email addresses + +%changelog +* Thu Nov 22 2012 Daniel Berteaud - 0.1.1-1 +- Add template for qpsmtpd goodrcptto + +* Thu Nov 22 2012 Daniel Berteaud - 0.1.0-1 +- initial release + +%prep +%setup -q -n %{name}-%{version} + +%build +perl createlinks + +%install +/bin/rm -rf $RPM_BUILD_ROOT +(cd root ; /usr/bin/find . -depth -print | /bin/cpio -dump $RPM_BUILD_ROOT) +/bin/rm -f %{name}-%{version}-filelist +/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \ + > %{name}-%{version}-filelist + +%files -f %{name}-%{version}-filelist +%defattr(-,root,root) + +%clean +rm -rf $RPM_BUILD_ROOT + +%pre + +%post +