Skip to Content.
Sympa Menu

devel - [sympa-dev] new data source

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: LAVAUD Laurent<address@concealed>
  • To: address@concealed
  • Subject: [sympa-dev] new data source
  • Date: Wed, 23 Mar 2005 09:53:43 +0100

I've extended sympa to work with another data source type: include_shell

In this mode, all the subscribers returned by a launched script become
subscribers of the current list.

The script only have to flow out emails to stdout.

I don't know if it has an interest for sympa team (my problem might be
resolved by using the include_remote_file directive), but I send you my work.


For example, a trivial script could be:

-- BEGIN OF SCRIPT trivial.sh --
#! /bin/sh

echo "address@concealed"
echo "address@concealed"
-- END OF SCRIPT trivial.sh --


And a part of the list config file looks like:

-- BEGIN PART OF CONFIG FILE --
user_data_source include
include_shell /var/sympa/scripts/trivial.sh
-- END PART OF CONFIG FILE --


Here is the patch code to apply to List.pm:

-- BEGIN OF patch code --
--- List.pm 2005-03-23 09:33:52.920062248 +0100
+++ List.pm.orig 2005-03-23 09:25:06.758251478 +0100
@@ -226,7 +226,7 @@
account topics
host lang web_archive archive digest
available_user_options
default_user_options reply_to_header reply_to
forced_reply_to *
- welcome_return_path remind_return_path user_data_source
include_file include_shell
+ welcome_return_path remind_return_path user_data_source
include_file
include_list include_remote_sympa_list
include_ldap_query
include_ldap_2level_query include_sql_query
include_admin ttl creation update
status serial);
@@ -504,12 +504,6 @@
'title_id' => 34,
'group' => 'data_source'
},
- 'include_shell' => {'format' => '\S+',
- 'length' => 20,
- 'occurrence' => '0-n',
- 'title_id' => 34,
- 'group' => 'data_source'
- },

'include_admin' => {'format' => {'list' => {'format' => '\S+',
'occurrence' => '1',
@@ -1487,7 +1481,6 @@
}elsif ($self->{'admin'}{'user_data_source'} eq 'include2') {
## include other subscribers as defined in include directives
(list|ldap|sql|file|owners|editors)
unless ( defined $self->{'admin'}{'include_file'}
- || defined $self->{'admin'}{'include_shell'}
|| defined $self->{'admin'}{'include_list'}
|| defined $self->{'admin'}{'include_remote_sympa_list'}
|| defined $self->{'admin'}{'include_sql_query'}
@@ -1504,7 +1497,6 @@

## include other subscribers as defined in include directives
(list|ldap|sql|file|owners|editors)
unless ( defined $self->{'admin'}{'include_file'}
- || defined $self->{'admin'}{'include_shell'}
|| defined $self->{'admin'}{'include_list'}
|| defined $self->{'admin'}{'include_remote_sympa_list'}
|| defined $self->{'admin'}{'include_sql_query'}
@@ -5558,62 +5550,6 @@
}


-sub _include_users_shell {
- my ($users, $filename, $default_user_options,$tied) = @_;
- do_log('debug2', 'List::_include_users_shell');
-
- my $total = 0;
-
- unless (open(INCLUDE, "$filename|")) {
- do_log('err', 'Unable to open shell file "%s"' , $filename);
- return undef;
- }
- do_log('debug2','including shell file %s' , $filename);
-
- my $id = _get_datasource_id($filename);
-
- while (<INCLUDE>) {
- next if /^\s*$/;
- next if /^\s*\#/;
-
- unless (/^\s*($tools::regexp{'email'})(\s*(\S.*))?\s*$/) {
- &do_log('notice', 'Not an email address: %s', $_);
- }
-
- my $email = &tools::clean_email($1);
- my $gecos = $5;
-
- next unless $email;
-
- my %u;
- ## Check if user has already been included
- if ($users->{$email}) {
- if ($tied) {
- %u = split "\n",$users->{$email};
- }else {
- %u = %{$users->{$email}};
- }
- }else {
- %u = %{$default_user_options};
- $total++;
- }
- $u{'email'} = $email;
- $u{'gecos'} = $gecos;
- $u{'id'} = join (',', split(',', $u{'id'}), $id);
-
- if ($tied) {
- $users->{$email} = join("\n", %u);
- }else {
- $users->{$email} = \%u;
- }
- }
- close INCLUDE ;
-
- do_log('info',"include %d new subscribers from shell
%s",$total,$filename);
- return $total ;
-}
-
-
## Returns a list of subscribers extracted from a remote LDAP Directory
sub _include_users_ldap {
my ($users, $param, $default_user_options, $tied) = @_;
@@ -6061,7 +5997,7 @@
}
&do_log('debug3', 'Got lock for writing on %s', $db_file);

- foreach my $type
('include_list','include_remote_sympa_list','include_file','include_shell','include_ldap_query','include_ldap_2level_query','include_sql_query')
{
+ foreach my $type
('include_list','include_remote_sympa_list','include_file','include_ldap_query','include_ldap_2level_query','include_sql_query')
{
last unless (defined $total);

foreach my $incl (@{$admin->{$type}}) {
@@ -6087,8 +6023,6 @@
$included = _include_users_remote_sympa_list(\%users,
$incl, $dir,$admin->{'domain'},$admin->{'default_user_options'}, 'tied');
}elsif ($type eq 'include_file') {
$included = _include_users_file (\%users, $incl,
$admin->{'default_user_options'}, 'tied');
- }elsif ($type eq 'include_shell') {
- $included = _include_users_shell (\%users, $incl,
$admin->{'default_user_options'}, 'tied');
}
unless (defined $included) {
&do_log('err', 'Inclusion %s failed in list %s', $type,
$name);
@@ -6172,7 +6106,7 @@
my (%users, $depend_on, $ref);
my $total = 0;

- foreach my $type
('include_list','include_remote_sympa_list','include_file','include_shell','include_ldap_query','include_ldap_2level_query','include_sql_query')
{
+ foreach my $type
('include_list','include_remote_sympa_list','include_file','include_ldap_query','include_ldap_2level_query','include_sql_query')
{
last unless (defined $total);

foreach my $incl (@{$admin->{$type}}) {
@@ -6197,8 +6131,6 @@
}
}elsif ($type eq 'include_file') {
$included = _include_users_file (\%users, $incl,
$admin->{'default_user_options'});
- }elsif ($type eq 'include_shell') {
- $included = _include_users_shell (\%users, $incl,
$admin->{'default_user_options'});
# }elsif ($type eq 'include_admin') {
# $included = _include_users_admin (\\%users, $incl,
$admin->{'default_user_options'});
}
-- END OF patch code --


Best regards,

--
Laurent LAVAUD
Centre de Ressources Informatiques
Universite Bordeaux2
143 rue Leo Saignat
33076 Bordeaux cedex
Tel: 05 57 57 15 03
Fax: 05 57 57 45 42


  • [sympa-dev] new data source, LAVAUD Laurent, 03/23/2005

Archive powered by MHonArc 2.6.19+.

Top of Page