Skip to Content.
Sympa Menu

devel - [sympa-developpers] Dividing sympa.pl was Re: [sympa-commits] sympa[10632] trunk/src: [dev] extract all admin duties of sympa. pl into another dedicated

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: IKEDA Soji <address@concealed>
  • To: address@concealed
  • Subject: [sympa-developpers] Dividing sympa.pl was Re: [sympa-commits] sympa[10632] trunk/src: [dev] extract all admin duties of sympa. pl into another dedicated
  • Date: Tue, 7 Oct 2014 10:08:15 +0900

For my memorandom:

sympa.pl would be divided into daemons to process each spool
(sympa_msg.pl, sympa_automatic.pl, sympa_digest.pl) and one or more
command line utilities (sympa.pl or so).

This change would be made in 6.2b.X to 7.0.

--- Soji

On Mon, 19 May 2014 16:49:35 +0200 (CEST)
address@concealed wrote:

> sympa[10632] trunk/src: [dev] extract all admin duties of sympa.pl into
> another dedicated
> Revision 10632 Author rousse Date 2014-05-19 16:49:35 +0200 (lun. 19 mai
> 2014)
> Log Message[dev] extract all admin duties of sympa.pl into another dedicated
> sympa_manager.pl executable, to reduce dependencies and command-line
> complexity. sympa.pl is now a daemon only executable.
>
> TODO: restore configuration loading and privileges dropping in
> sympa_manager.pl
> Modified Paths
> trunk/src/bin/Makefile.am
> trunk/src/sbin/sympa.pl.in
> Added Paths
> trunk/src/bin/sympa_manager.pl.in
> Diff
> Modified: trunk/src/bin/Makefile.am (10631 => 10632)
> --- trunk/src/bin/Makefile.am 2014-05-19 12:31:58 UTC (rev 10631)
> +++ trunk/src/bin/Makefile.am 2014-05-19 14:49:35 UTC (rev 10632)
> @@ -1,6 +1,6 @@
> -bin_SCRIPTS = sympa_wizard.pl sympa_soap_client.pl
> +bin_SCRIPTS = sympa_wizard.pl sympa_manager.pl sympa_soap_client.pl
>
> -man1_MANS = sympa_wizard.pl.1
> +man1_MANS = sympa_wizard.pl.1 sympa_manager.pl.1
>
> dbscripts = create_db.Pg create_db.mysql create_db.Oracle \
> create_db.Sybase create_db.SQLite
> @@ -26,11 +26,12 @@
> testlogs.pl.in \
> tpl2tt2.pl.in \
> sympa_wizard.pl.in \
> + sympa_manager.pl.in \
> sympa_soap_client.pl.in
>
> CLEANFILES = $(perlscripts) $(bin_SCRIPTS) $(man1_MANS)
>
> -arc2webarc.pl crypt_passwd.pl init_comment.pl mod2html.pl p12topem.pl
> testldap.pl testlogs.pl tpl2tt2.pl sympa_wizard.pl sympa_soap_client.pl:
> Makefile
> +arc2webarc.pl crypt_passwd.pl init_comment.pl mod2html.pl p12topem.pl
> testldap.pl testlogs.pl tpl2tt2.pl sympa_wizard.pl sympa_manager.pl
> sympa_soap_client.pl: Makefile
> rm -f $@
> $(AM_V_GEN)$(SED) \
> -e 's|--PERL--|$(PERL)|' \
> @@ -56,6 +57,7 @@
> testlogs.pl: testlogs.pl.in
> tpl2tt2.pl: tpl2tt2.pl.in
> sympa_wizard.pl: $(srcdir)/sympa_wizard.pl.in
> +sympa_manager.pl: $(srcdir)/sympa_manager.pl.in
> sympa_soap_client.pl: $(srcdir)/sympa_soap_client.pl.in
>
> .pl.1:
> @@ -66,3 +68,10 @@
> --lax --release="$(VERSION)" $* $@
>
> sympa_wizard.pl.1: sympa_wizard.pl
> +
> +sympa_manager.pl.1: Makefile
> + rm -f $@
> + $(AM_V_GEN)$(POD2MAN) --section=1 --center="sympa $(VERSION)" \
> + --lax --release="$(VERSION)" $* $@
> +
> +sympa_manager.pl.1: sympa_manager.pl
> Copied: trunk/src/bin/sympa_manager.pl.in (from rev 10631,
> trunk/src/sbin/sympa.pl.in) (0 => 10632)
> --- trunk/src/bin/sympa_manager.pl.in (rev 0)
> +++ trunk/src/bin/sympa_manager.pl.in 2014-05-19 14:49:35 UTC (rev 10632)
> @@ -0,0 +1,1118 @@
> +#!--PERL--
> +# -*- indent-tabs-mode: nil; -*-
> +# vim:ft=perl:et:sw=4
> +# $Id$
> +
> +# Sympa - SYsteme de Multi-Postage Automatique
> +#
> +# Copyright (c) 1997-1999 Institut Pasteur & Christophe Wolfhugel
> +# Copyright (c) 1997-2011 Comite Reseau des Universites
> +# Copyright (c) 2011-2014 GIP RENATER
> +#
> +# 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, see <http://www.gnu.org/licenses/>.
> +
> +=encoding utf-8
> +
> +=head1 NAME
> +
> +sympa_manager.pl
> +
> +=head1 SYNOPSIS
> +
> +B<sympa_manager.pl> B<--add_list>=I<family>
> + B<--robot>=I<robot> B<--input_file>=I<file.xml>
> +
> +B<sympa_manager.pl> B<--change_user_email>
> + B<--current_email>=I<xx> B<--new_email>=I<xx>
> +
> +B<sympa_manager.pl> B<--close_family>=I<family>
> + B<--robot>=I<robot>
> +
> +B<sympa_manager.pl> B<--close_list>=I<list[@robot]>
> +
> +B<sympa_manager.pl> B<--conf_2_db>
> +
> +B<sympa_manager.pl> B<--create_list>
> + B<--robot>=I<robot> B<--input_file>=I<file.xml>
> +
> +B<sympa_manager.pl> B<--dump>=I<listname>|ALL
> +
> +B<sympa_manager.pl> B<--export_list>
> + [B<--robot>=I<robot_name>]
> +
> +B<sympa_manager.pl> B<--health_check>
> +
> +B<sympa_manager.pl> B<--import>=I<list[@robot]>
> +
> +B<sympa_manager.pl> B<--instantiate_family>=I<family>
> + B<--robot>=I<robot> B<--input_file>=I<file.xml>
> + [B<--close_unknown>] [B<--quiet>]
> +
> +B<sympa_manager.pl> B<--lowercase>
> +
> +B<sympa_manager.pl> B<--make_alias_file>
> +
> +B<sympa_manager.pl> B<--md5_encode_password>
> +
> +B<sympa_manager.pl> B<--modify_list>=I<family>
> + B<--robot>=I<robot> B<--input_file>=I<file.xml>
> +
> +B<sympa_manager.pl> B<--purge_list>=I<list[@robot]>
> +
> +B<sympa_manager.pl> B<--reload_list_config>
> + [B<--list>=I<list[@robot]>] [B<--robot>=I<robot>]
> +
> +B<sympa_manager.pl> B<--rename_list>=I<list[@robot]>
> + B<--new_listname>=I<newname> B<--new_listrobot>=I<newrobot>
> +
> +B<sympa_manager.pl> B<--sync_include=>I<list[@robot]>
> +
> +B<sympa_manager.pl> B<--sync_list_db>
> +
> +B<sympa_manager.pl> B<--test_database_message_buffer>
> +
> +B<sympa_manager.pl> B<--upgrade> [B<--from>=I<X>] [B<--to>=I<Y>]
> +
> +B<sympa_manager.pl> B<--upgrade_shared> [B<--list>=I<X>] [B<--robot>=I<Y>]
> +
> +B<sympa_manager.pl> B<--md5_digest>=I<password>
> +
> +B<sympa_manager.pl> B<-h, --help>
> +
> +=head1 DESCRIPTION
> +
> +FIXME
> +
> +=head1 OPTIONS
> +
> +F<sympa_manager.pl> may run with following options:
> +
> +=over 4
> +
> +=item B<-d>, B<--debug>
> +
> +Enable debug mode.
> +
> +=item B<--log_level>=<level>
> +
> +Sets Sympa log level.
> +
> +=item B<--add_list>=I<family> B<--robot>=I<robot>
> + B<--input_file>=I<file.xml>
> +
> +Add the list described by the file.xml under robot_name, to the family
> +family_name.
> +
> +=item B<--change_user_email> B<--current_email>=I<xx> B<--new_email>=I<xx>
> +
> +Changes a user email address in all Sympa databases (subscriber_table,
> +list config, etc) for all virtual robots.
> +
> +=item B<--close_family>=I<family> B<--robot>=I<robot>
> +
> +Close lists of family_name family under robot_name.
> +
> +=item B<--close_list>=I<list[@robot]>
> +
> +Close the list (changing its status to closed), remove aliases and remove
> +subscribers from DB (a dump is created in the list directory to allow
> +restoring the list)
> +
> +=item B<--conf_2_db>
> +
> +Load sympa.conf and each robot.conf into database.
> +
> +=item B<--create_list> B<--robot>=<robot>
> + B<--input_file>=I<file.xml>
> +
> +Create a list with the XML file under robot robot_name.
> +
> +=item B<--dump>=I<list[@robot]>|C<ALL>
> +
> +Dumps subscribers of for `listname' list or all lists. Subscribers are
> +dumped in subscribers.db.dump.
> +
> +=item B<--export_list> [B<--robot>=I<robot>]
> +
> +B<Not fully implemented>.
> +
> +=item B<--health_check>
> +
> +Check if F<sympa.conf>, F<robot.conf> of virtual robots and database
> structure
> +are correct. If any errors occur, exits with non-zero status.
> +
> +=item B<--import>=I<list[@robot]>
> +
> +Import subscribers in the list. Data are read from standard input.
> +The imported data should contain one entry per line : the first field
> +is an email address, the second (optional) field is the free form name.
> +Fields are spaces-separated.
> +
> +Sample:
> +
> + ## Data to be imported
> + ## email gecos
> + address@concealed John - accountant
> + address@concealed Mary - secretary
> +
> +=item B<--instantiate_family>=I<family> B<--robot>=I<robot>
> + B<--input_file>=I<file.xml> [B<--close_unknown>] [B<--quiet>]
> +
> +Instantiate family_name lists described in the file.xml under robot_name.
> +The family directory must exist; automatically close undefined lists in a
> +new instantiation if --close_unknown is specified; do not print report if
> +C<--quiet> is specified.
> +
> +=item B<--lowercase>
> +
> +Lowercases email addresses in database.
> +
> +=item B<--make_alias_file>
> +
> +Create an aliases file in /tmp/ with all list aliases. It uses the
> +F<list_aliases.tt2> template (useful when list_aliases.tt2 was changed).
> +
> +=item B<--md5_encode_password>
> +
> +Rewrite password in C<user_table> of database using MD5 fingerprint.
> +YOU CAN'T UNDO unless you save this table first.
> +
> +=item B<--modify_list>=I<family> B<--robot>=I<robot>
> + B<--input_file>=I<file.xml>
> +
> +Modify the existing list installed under the robot robot_name and that
> +belongs to the family family_name. The new description is in the
> C<file.xml>.
> +
> +=item B<--purge_list>=I<list[@robot]>
> +
> +Remove the list (remove archive, configuration files, users and owners in
> admin table. Restore is not possible after this operation.
> +
> +=item B<--reload_list_config>
> + [B<--list>=I<list[@robot]>] [B<--robot>=I<robot>]
> +
> +Recreates all F<config.bin> files or cache in C<list_table>.
> +You should run this command if you edit authorization scenarios.
> +The list and robot parameters are optional.
> +
> +=item B<--rename_list>=I<list[@robot]>
> + B<--new_listname>=I<newname> B<--new_listrobot>=I<newrobot>
> +
> +Renames a list or move it to another virtual robot.
> +
> +=item B<--sync_include>=I<list[@robot]>
> +
> +Trigger the list members update.
> +
> +=item B<--sync_list_db>
> +
> +B<Deprecated>. Use B<--reload_list_config>.
> +
> +=item B<--test_database_message_buffer>
> +
> +Test the database message buffer size.
> +
> +=item B<--upgrade> [B<--from>=I<X>] [B<--to>=I<Y>]
> +
> +Runs Sympa maintenance script to upgrade from version I<X> to version I<Y>.
> +
> +=item B<--upgrade_shared> [B<--list>=I<X>] [B<--robot>=I<Y>]>
> +
> +Rename files in shared.
> +
> +=item B<-h>, B<--help>
> +
> +Print this help message.
> +
> +=item B<--md5_digest>=I<password>
> +
> +Output a MD5 digest of a password (useful for SOAP client trusted
> +application).
> +
> +=back
> +
> +=head1 FILES
> +
> +F<--CONFIG--> main configuration file.
> +
> +=cut
> +
> +use strict;
> +use warnings;
> +use lib '--modulesdir--';
> +
> +use Digest::MD5;
> +use English qw(-no_match_vars);
> +use Getopt::Long;
> +use Pod::Usage;
> +
> +use Sympa::Admin;
> +use Sympa::Conf;
> +use Sympa::Config_XML;
> +use Sympa::Constants;
> +use Sympa::DatabaseManager;
> +use Sympa::Family;
> +use Sympa::Language;
> +use Sympa::List;
> +use Sympa::Log::Syslog;
> +use Sympa::Robot;
> +use Sympa::Site;
> +use Sympa::Spool::SQL;
> +use Sympa::Tools;
> +use Sympa::Upgrade;
> +
> +## Init random engine
> +srand(time());
> +
> +my %options;
> +unless (
> + GetOptions(
> + \%options,
> + 'add_list=s',
> + 'change_user_email',
> + 'close_family=s',
> + 'close_list=s',
> + 'close_unknown',
> + 'conf_2_db',
> + 'create_list',
> + 'current_email=s',
> + 'debug|d',
> + 'dump=s',
> + 'export_list',
> + 'health_check',
> + 'help|h',
> + 'import=s',
> + 'input_file=s',
> + 'instantiate_family=s',
> + 'log_level=s',
> + 'lowercase',
> + 'make_alias_file',
> + 'md5_digest=s',
> + 'md5_encode_password',
> + 'modify_list=s',
> + 'new_email=s',
> + 'new_listname=s',
> + 'new_listrobot=s',
> + 'purge_list=s',
> + 'reload_list_config',
> + 'rename_list=s',
> + 'robot=s',
> + 'sync_include=s',
> + 'sync_list_db',
> + 'test_database_message_buffer',
> + 'upgrade',
> + 'upgrade_shared',
> + )
> + ) {
> + pod2usage(-exitval => 1, -output => \*STDERR);
> +}
> +
> +if ($options{'debug'}) {
> + $options{'log_level'} = 2 unless ($options{'log_level'});
> +}
> +
> +$options{'log_to_stderr'} = 1;
> +
> +if ($options{'help'}) {
> + pod2usage(0);
> +} elsif ($options{'health_check'}) {
> + healt_check();
> +} elsif ($options{'dump'}) {
> + dump_list();
> +} elsif ($options{'make_alias_file'}) {
> + make_alias_file();
> +} elsif ($options{'md5_digest'}) {
> + md5_digest();
> +} elsif ($options{'import'}) {
> + import();
> +} elsif ($options{'md5_encode_password'}) {
> + md5_encode_password();
> +} elsif ($options{'lowercase'}) {
> + lowercase();
> +} elsif ($options{'close_list'}) {
> + close_list();
> +} elsif ($options{'change_user_email'}) {
> + change_user_email();
> +} elsif ($options{'purge_list'}) {
> + purge_list();
> +} elsif ($options{'rename_list'}) {
> + rename_list();
> +} elsif ($options{'test_database_message_buffer'}) {
> + test_database_message_buffer();
> +} elsif ($options{'conf_2_db'}) {
> + conf_2_db();
> +} elsif ($options{'create_list'}) {
> + create_list();
> +} elsif ($options{'instantiate_family'}) {
> + instantiate_family();
> +} elsif ($options{'add_list'}) {
> + add_list();
> +} elsif ($options{'sync_include'}) {
> + sync_include();
> +} elsif ($options{'upgrade'}) {
> + upgrade();
> +} elsif ($options{'upgrade_shared'}) {
> + upgrade_shared();
> +} elsif ($options{'reload_list_config'}) {
> + reload_list_config();
> +} elsif ($options{'modify_list'}) {
> + modify_list();
> +} elsif ($options{'close_family'}) {
> + close_family();
> +} elsif ($options{'sync_list_db'}) {
> + sync_list_db();
> +} elsif ($options{'export_list'}) {
> + export_list();
> +}
> +
> +exit 0;
> +
> +sub health_check {
> + ## Health check
> +
> + ## Load configuration file. Ignoring database config for now: it avoids
> + ## trying to load a database that could not exist yet.
> + unless (Sympa::Site->load('no_db' => 1, 'force_reload' => 1)) {
> + printf STDERR
> + "Configuration file %s has errors.\n",
> + Sympa::Conf::get_sympa_conf();
> + exit 1;
> + }
> +
> + ## Open the syslog and say we're read out stuff.
> + Sympa::Log::Syslog::do_openlog(Sympa::Site->syslog,
> Sympa::Site->log_socket_type,
> + 'health_check');
> +
> + ## Setting log_level using conf unless it is set by calling option
> + if ($options{'log_level'}) {
> + Sympa::Log::Syslog::set_log_level($options{'log_level'});
> + Sympa::Log::Syslog::do_log(
> + 'info',
> + 'Configuration file read, log level set using options : %s',
> + $options{'log_level'}
> + );
> + } else {
> + Sympa::Log::Syslog::set_log_level(Sympa::Site->log_level);
> + Sympa::Log::Syslog::do_log('info',
> + 'Configuration file read, default log level %s',
> + Sympa::Site->log_level);
> + }
> +
> + ## Check database connectivity and probe database
> + unless (Sympa::DatabaseManager::check_db_connect('just_try') and
> Sympa::DatabaseManager::probe_db()) {
> + printf STDERR
> + "Database %s defined in sympa.conf has not the right structure
> or is unreachable. verify db_xxx parameters in sympa.conf\n",
> + Sympa::Site->db_name;
> + exit 1;
> + }
> +
> + ## Now trying to load full config (including database)
> + unless (Sympa::Site->load() and Sympa::Robot::get_robots()) {
> + printf STDERR
> + "Unable to load Sympa configuration, file %s or any of the
> virtual host robot.conf files contain errors. Exiting.\n",
> + Sympa::Conf::get_sympa_conf();
> + exit 1;
> + }
> +
> + ## Change working directory.
> + if (!chdir(Sympa::Site->home)) {
> + printf STDERR "Can't chdir to %s: %s\n", Sympa::Site->home, $ERRNO;
> + exit 1;
> + }
> +
> + ## Check for several files.
> + unless (Sympa::Conf::checkfiles_as_root()) {
> + printf STDERR "Missing files.\n";
> + exit 1;
> + }
> +
> + ## Check that the data structure is uptodate
> + unless (Sympa::DatabaseManager::data_structure_uptodate()) {
> + printf STDERR
> + "Data structure was not updated; you should run sympa.pl
> --upgrade to run the upgrade process.\n";
> + exit 1;
> + }
> +}
> +
> +sub dump_list {
> + my ($all_lists, $list);
> + if ($options{'dump'} eq 'ALL') {
> + $all_lists = Sympa::List::get_lists();
> + } else {
> +
> + ## The parameter can be a list address
> + unless ($options{'dump'} =~ /\@/) {
> + Sympa::Log::Syslog::do_log('err', 'Incorrect list address %s',
> + $options{'dump'});
> +
> + exit;
> + }
> +
> + my $list = Sympa::List->new($options{'dump'});
> + unless (defined $list) {
> + Sympa::Log::Syslog::do_log('err', 'Unknown list %s',
> + $options{'dump'});
> +
> + exit;
> + }
> + push @$all_lists, $list;
> + }
> +
> + foreach my $list (@$all_lists) {
> + unless ($list->dump()) {
> + print STDERR "Could not dump list(s)\n";
> + }
> + }
> +}
> +
> +sub make_alias_file {
> + my $all_lists = Sympa::List::get_lists();
> +
> + my $aliases_file = Sympa::Site->tmpdir . '/sympa_aliases' . $PID;
> + unless (open TMP, '>', $aliases_file) {
> + printf STDERR "Unable to create %s, exiting\n", $aliases_file;
> + exit;
> + }
> + printf TMP "#\n#\tAliases for all Sympa lists open\n#\n";
> + close TMP;
> +
> + foreach my $list (@$all_lists) {
> + my $cmd = sprintf '%s add %s %s %s',
> + Sympa::Site->alias_manager, $list->name, $list->domain,
> + $aliases_file;
> + system($cmd) if $list->status eq 'open';
> + }
> + printf
> + "Sympa aliases file %s was made. You probably need to install it
> in your SMTP engine\n",
> + $aliases_file;
> +}
> +
> +sub md5_digest {
> + my $md5 = Digest::MD5::md5_hex($options{'md5_digest'});
> + printf "MD5 digest : %s \n", $md5;
> +}
> +
> +sub import {
> + my ($list, $total);
> +
> + ## The parameter should be a list address
> + unless ($options{'import'} =~ /\@/) {
> + Sympa::Log::Syslog::do_log(
> + 'err',
> + 'Incorrect list address %s',
> + $options{'import'}
> + );
> + exit;
> + }
> +
> + unless ($list = Sympa::List->new($options{'import'})) {
> + Sympa::Log::Syslog::fatal_err('Unknown list name %s',
> + $options{'import'});
> + }
> +
> + ## Read imported data from STDIN
> + while (<STDIN>) {
> + next if /^\s*$/;
> + next if /^\s*\#/;
> +
> + unless (/^\s*((\S+|\".*\")@\S+)(\s*(\S.*))?\s*$/) {
> + printf STDERR "Not an email address: %s\n", $_;
> + }
> +
> + my $email = lc($1);
> + my $gecos = $4;
> + my $u;
> + my $defaults = $list->default_user_options;
> + %{$u} = %{$defaults};
> + $u->{'email'} = $email;
> + $u->{'gecos'} = $gecos;
> +
> + $list->add_list_member($u);
> + if (defined $list->{'add_outcome'}{'errors'}) {
> + printf STDERR "\nCould not add %s. %s\n", $email,
> + $list->{'add_outcome'}{'errors'}{'error_message'};
> + next;
> + }
> + print STDERR '+';
> +
> + $total++;
> + }
> +
> + printf STDERR "Total imported subscribers: %d\n", $total;
> +}
> +
> +sub md5_encore_password {
> +
> + unless ($Sympa::Site::use_db) {
> + Sympa::Log::Syslog::fatal_err(
> + "You don't have a database setup, can't lowercase email
> addresses"
> + );
> + }
> +
> + my $total = Sympa::Upgrade::md5_encode_password();
> + printf STDERR "Total password re-encoded using MD5: %d\n", $total;
> +}
> +
> +sub lowercase {
> + unless ($Sympa::Site::use_db) {
> + Sympa::Log::Syslog::fatal_err(
> + "You don't have a database setup, can't lowercase email
> addresses"
> + );
> + }
> +
> + print STDERR "Working on user_table...\n";
> + my $total = Sympa::List::lowercase_field('user_table', 'email_user');
> +
> + print STDERR "Working on subscriber_table...\n";
> + $total +=
> + Sympa::List::lowercase_field('subscriber_table',
> 'user_subscriber');
> +
> + unless (defined $total) {
> + Sympa::Log::Syslog::fatal_err("Could not work on database");
> + }
> +
> + printf STDERR "Total lowercased rows: %d\n", $total;
> +}
> +
> +sub close_list {
> +
> + my ($listname, $robotname) = split /\@/, $options{'close_list'};
> + my $list = Sympa::List->new($listname, $robotname);
> +
> + unless (defined $list) {
> + print STDERR "Incorrect list name $options{'close_list'}\n";
> + exit 1;
> + }
> +
> + if ($list->family_name) {
> + unless (
> + $list->set_status_family_closed('close_list', $list->name)) {
> + print STDERR
> + "Could not close list $options{'close_list'}\n";
> + exit 1;
> + }
> + } else {
> + unless ($list->close_list()) {
> + print STDERR
> + "Could not close list $options{'close_list'}\n";
> + exit 1;
> + }
> + }
> +
> + printf STDOUT "List %s has been closed, aliases have been removed\n",
> + $list->get_id;
> +}
> +
> +sub change_user_email {
> + unless ($options{'current_email'}
> + && $options{'new_email'}) {
> + print STDERR "Missing current_email or new_email parameter\n";
> + exit 1;
> + }
> +
> + foreach my $robot (@{Sympa::Robot::get_robots()}) {
> + printf STDOUT "Doing processing for virtual robot %s...\n",
> + $robot->name;
> + my ($status, $failed_for) = Sympa::Admin::change_user_email(
> + 'current_email' => $options{'current_email'},
> + 'new_email' => $options{'new_email'},
> + 'robot' => $robot
> + );
> + unless (defined $status) {
> + printf STDERR
> + "Failed to change user email address in virtual robot
> %s'}\n",
> + $robot->name;
> + exit 1;
> + }
> +
> + foreach my $failed_list (@$failed_for) {
> + printf STDERR
> + "Failed to change user email address for list %s\n",
> + $failed_list->{'name'};
> + }
> + }
> +
> + printf STDOUT "Email address %s has been changed to %s\n",
> + $options{'current_email'}, $options{'new_email'};
> +
> +}
> +
> +sub purge_list {
> + my ($listname, $robotname) = split /\@/, $options{'purge_list'};
> + my $list = Sympa::List->new($listname, $robotname);
> +
> + unless (defined $list) {
> + print STDERR "Incorrect list name $options{'purge_list'}\n";
> + exit 1;
> + }
> +
> + if ($list->family_name) {
> + unless (
> + $list->set_status_family_closed('purge_list', $list->name)) {
> + print STDERR
> + "Could not purge list $options{'purge_list'}\n";
> + exit 1;
> + }
> + } else {
> + unless ($list->purge()) {
> + print STDERR
> + "Could not purge list $options{'close_list'}\n";
> + exit 1;
> + }
> + }
> +
> + printf STDOUT "List %s has been closed, aliases have been removed\n",
> + $list->get_id;
> +
> +}
> +
> +sub rename_list {
> + my ($listname, $robotname) = split /\@/,
> + $options{'rename_list'};
> + my $list = Sympa::List->new($listname, $robotname);
> +
> + unless (defined $list) {
> + print STDERR
> + "Incorrect list name $options{'rename_list'}\n";
> + exit 1;
> + }
> +
> + unless ($options{'new_listname'}) {
> + print STDERR "Missing parameter new_listname\n";
> + exit 1;
> + }
> +
> + unless ($options{'new_listrobot'}) {
> + print STDERR "Missing parameter new_listrobot\n";
> + exit 1;
> + }
> +
> + my ($new_listname, $new_robotname) =
> + ($options{'new_listname'}, $options{'new_listrobot'});
> +
> + my $result = Sympa::Admin::rename_list(
> + list => $list,
> + new_listname => $new_listname,
> + new_robot => $new_robotname,
> + options => {'skip_authz' => 1},
> + user_email => 'listmaster@' . $robotname,
> + );
> +
> + unless ($result == 1) {
> + printf STDERR "Could not rename list %s to %s\@%s: %s\n",
> + $options{'rename_list'}, $options{'new_listname'},
> + $options{'new_listrobot'}, $result;
> + exit 1;
> + }
> +
> + printf STDOUT "List %s has been renamed to %s\@%s\n",
> + $options{'rename_list'}, $options{'new_listname'},
> + $options{'new_listrobot'};
> +}
> +
> +sub test_database_message_buffer {
> + my $size = 0;
> + print
> + "Sympa is going to store messages bigger and bigger to test the
> limit with its database. This may be very long \n";
> + ## will test message until a 21 Mo message.
> + $size = Sympa::Spool::SQL::store_test(21000);
> + if ($size == 21000) {
> + printf
> + "The maximum message size (%d Ko) testing was successful \n",
> + $size;
> + } else {
> + printf
> + "maximum message size that can be stored in database : %d
> Ko\n",
> + $size;
> + }
> +}
> +
> +sub conf_2_db {
> + printf
> + "Sympa is going to store %s in database conf_table. This operation
> do NOT remove original files\n",
> + Sympa::Conf::get_sympa_conf();
> + if (Sympa::Conf::conf_2_db()) {
> + printf "Done";
> + } else {
> + printf "an error occur";
> + }
> + exit 1;
> +}
> +
> +sub create_list {
> + my $robot_id = $options{'robot'}
> + || Sympa::Site->host; #FIXME: is domain better?
> +
> + unless ($options{'input_file'}) {
> + print STDERR "Error : missing 'input_file' parameter\n";
> + exit 1;
> + }
> +
> + unless (open INFILE, $options{'input_file'}) {
> + print STDERR "Unable to open $options{'input_file'}) file";
> + exit 1;
> + }
> +
> + my $config = Sympa::Config_XML->new(\*INFILE);
> + unless (defined $config->createHash()) {
> + print STDERR "Error in representation data with these XML data\n";
> + exit 1;
> + }
> +
> + my $hash = $config->getHash();
> +
> + close INFILE;
> +
> + my $resul =
> + Sympa::Admin::create_list_old($hash->{'config'}, $hash->{'type'},
> + $robot_id, "command_line");
> + unless (defined $resul) {
> + print STDERR "Could not create list with these XML data\n";
> + exit 1;
> + }
> +
> + if (!defined($resul->{'aliases'}) || $resul->{'aliases'} == 1) {
> + print STDOUT "List has been created \n";
> + } else {
> + printf STDOUT "List has been created, required aliases :\n %s \n",
> + $resul->{'aliases'};
> + }
> +}
> +
> +sub instantiate_family {
> + my $robot_id = $options{'robot'} || Sympa::Site->host;
> +
> + my $family_name;
> + unless ($family_name = $options{'instantiate_family'}) {
> + print STDERR "Error : missing family parameter\n";
> + exit 1;
> + }
> + my $family;
> + unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> + print STDERR
> + "The family $family_name does not exist, impossible
> instantiation\n";
> + exit 1;
> + }
> +
> + unless ($options{'input_file'}) {
> + print STDERR "Error : missing input_file parameter\n";
> + exit 1;
> + }
> +
> + unless (-r $options{'input_file'}) {
> + print STDERR "Unable to read $options{'input_file'} file";
> + exit 1;
> + }
> +
> + unless (
> + $family->instantiate(
> + $options{'input_file'},
> + $options{'close_unknown'}
> + )
> + ) {
> + print STDERR
> + "\nImpossible family instantiation : action stopped \n";
> + exit 1;
> + }
> +
> + my %result;
> + my $err = $family->get_instantiation_results(\%result);
> + close INFILE;
> +
> + unless ($options{'quiet'}) {
> + print STDOUT "@{$result{'info'}}";
> + print STDOUT "@{$result{'warn'}}";
> + }
> + if ($err) {
> + print STDERR "@{$result{'errors'}}";
> + }
> +}
> +
> +sub add_list {
> + my $robot_id = $options{'robot'} || Sympa::Site->host;
> +
> + my $family_name;
> + unless ($family_name = $options{'add_list'}) {
> + print STDERR "Error : missing family parameter\n";
> + exit 1;
> + }
> +
> + print STDOUT
> + "\n************************************************************\n";
> +
> + my $family;
> + unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> + print STDERR
> + "The family $family_name does not exist, impossible to add a
> list\n";
> + exit 1;
> + }
> +
> + unless ($options{'input_file'}) {
> + print STDERR "Error : missing 'input_file' parameter\n";
> + exit 1;
> + }
> +
> + unless (open INFILE, $options{'input_file'}) {
> + print STDERR "\n Impossible to open input file : $ERRNO \n";
> + exit 1;
> + }
> +
> + my $result;
> + unless ($result = $family->add_list(\*INFILE)) {
> + print STDERR
> + "\nImpossible to add a list to the family : action stopped \n";
> + exit 1;
> + }
> +
> + print STDOUT
> + "\n************************************************************\n";
> +
> + unless (defined $result->{'ok'}) {
> + printf STDERR "\n%s\n", join("\n", @{$result->{'string_info'}});
> + print STDERR
> + "\n The action has been stopped because of error :\n";
> + printf STDERR "\n%s\n", join("\n", @{$result->{'string_error'}});
> + exit 1;
> + }
> +
> + close INFILE;
> +
> + print STDOUT "\n%s\n", join("\n", @{$result->{'string_info'}});
> +}
> +
> +sub sync_include {
> + my $list = Sympa::List->new($options{'sync_include'});
> +
> + unless (defined $list) {
> + print STDERR
> + "Incorrect list name $options{'sync_include'}\n";
> + exit 1;
> + }
> +
> + unless (defined $list->sync_include()) {
> + print STDERR "Failed to synchronize list members\n";
> + exit 1;
> + }
> +
> + printf "Members of list %s have been successfully updated.\n",
> + $list->get_id;
> +}
> +
> +## Migration from one version to another
> +sub upgrade {
> + Sympa::Log::Syslog::do_log('notice', "Upgrade process...");
> +
> + $options{'from'} ||= Sympa::Upgrade::get_previous_version();
> + $options{'to'} ||= Sympa::Constants::VERSION;
> +
> + if ($options{'from'} eq $options{'to'}) {
> + Sympa::Log::Syslog::do_log('err',
> + "Current version : %s ; no upgrade is required.",
> + $options{'to'});
> + exit 0;
> + } else {
> + Sympa::Log::Syslog::do_log('notice', "Upgrading from %s to %s...",
> + $options{'from'}, $options{'to'});
> + }
> +
> + Sympa::DatabaseManager::probe_db;
> + unless (
> + Sympa::Upgrade::upgrade($options{'from'}, $options{'to'})) {
> + Sympa::Log::Syslog::do_log('err',
> + "Migration from %s to %s failed",
> + $options{'from'}, $options{'to'});
> + exit 1;
> + }
> + Sympa::Log::Syslog::do_log('notice', "Upgrade process finished.");
> + Sympa::Upgrade::update_version();
> +}
> +
> +## rename file names that may be incorrectly encoded because of
> +## previous Sympa versions
> +sub upgrade_shared {
> + Sympa::Log::Syslog::do_log('notice', "Upgrade shared process...");
> +
> + my $listname;
> + my $robot_id;
> +
> + unless (($options{'list'}) || ($options{'robot'})) {
> + Sympa::Log::Syslog::do_log('err',
> + "listname and domain are required, use --list= --robot=
> options"
> + );
> + exit 0;
> + }
> + $listname = $options{'list'};
> + $robot_id = $options{'robot'};
> +
> + Sympa::Log::Syslog::do_log('notice',
> + "Upgrading share for list=%s robot=%s",
> + $listname, $robot_id);
> +
> + my $list = Sympa::List->new($listname, $robot_id);
> +
> + unless (defined $list) {
> + printf STDERR "Incorrect list or domain name : %s %s\n",
> + $listname, $robot_id;
> + exit 1;
> + }
> +
> + if (-d $list->dir . '/shared') {
> + Sympa::Log::Syslog::do_log('notice', ' Processing list %s...',
> + $list);
> +
> + ## Determine default lang for this list
> + ## It should tell us what character encoding was used for
> + ## filenames
> + Sympa::Language::SetLang($list->lang);
> + my $list_encoding = Sympa::Language::GetCharset();
> +
> + my $count = Sympa::Tools::qencode_hierarchy($list->dir . '/shared',
> + $list_encoding);
> +
> + if ($count) {
> + Sympa::Log::Syslog::do_log('notice',
> + 'List %s : %d filenames has been changed',
> + $list, $count);
> + }
> + }
> + Sympa::Log::Syslog::do_log('notice',
> + "Upgrade_shared process finished.");
> +}
> +
> +sub reload_list_config {
> + my $listname = $options{'list'};
> + my $robot_id = $options{'robot'} || '';
> + $listname = '' unless defined $listname;
> + if ($listname =~ s/\@(.+)$//) {
> + $robot_id = $1;
> + }
> +
> + if (length $listname) {
> + Sympa::Log::Syslog::do_log('notice', 'Loading list %s...',
> + $listname);
> + my $robot = Sympa::Robot->new($robot_id || Sympa::Site->domain);
> + unless (defined $robot) {
> + print STDERR "Error : incorrect robot name '$robot_id'\n";
> + exit 1;
> + }
> + unless (Sympa::List->new($listname, $robot, {'reload_config' =>
> 1})) {
> + print STDERR "Error : incorrect list name '$listname'\n";
> + exit 1;
> + }
> + } else {
> + my $that;
> + if ($robot_id) {
> + Sympa::Log::Syslog::do_log('notice',
> + 'Loading all lists in %s...', $robot_id);
> + $that = Sympa::Robot->new($robot_id);
> + unless (defined $that) {
> + print STDERR "Error : incorrect robot name '$robot_id'\n";
> + exit 1;
> + }
> + } else {
> + Sympa::Log::Syslog::do_log('notice', 'Loading ALL lists...');
> + $that = 'Site';
> + }
> + Sympa::List::get_lists($that, {'reload_config' => 1});
> + }
> + Sympa::Log::Syslog::do_log('notice', '...Done.');
> +}
> +
> +sub modify_list {
> + my $robot_id = $options{'robot'} || Sympa::Site->host;
> +
> + my $family_name;
> + unless ($family_name = $options{'modify_list'}) {
> + print STDERR "Error : missing family parameter\n";
> + exit 1;
> + }
> +
> + print STDOUT
> + "\n************************************************************\n";
> +
> + my $family;
> + unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> + print STDERR
> + "The family $family_name does not exist, impossible to modify
> the list.\n";
> + exit 1;
> + }
> +
> + unless ($options{'input_file'}) {
> + print STDERR "Error : missing input_file parameter\n";
> + exit 1;
> + }
> +
> + unless (open INFILE, $options{'input_file'}) {
> + print STDERR "Unable to open $options{'input_file'}) file";
> + exit 1;
> + }
> +
> + my $result;
> + unless ($result = $family->modify_list(\*INFILE)) {
> + print STDERR
> + "\nImpossible to modify the family list : action stopped. \n";
> + exit 1;
> + }
> +
> + print STDOUT
> + "\n************************************************************\n";
> +
> + unless (defined $result->{'ok'}) {
> + printf STDERR "\n%s\n", join("\n", @{$result->{'string_info'}});
> + print STDERR "\nThe action has been stopped because of error :\n";
> + printf STDERR "\n%s\n", join("\n", @{$result->{'string_error'}});
> + exit 1;
> + }
> +
> + close INFILE;
> +
> + printf STDOUT "\n%s\n", join("\n", @{$result->{'string_info'}});
> +}
> +
> +sub close_family {
> + my $robot_id = $options{'robot'} || Sympa::Site->host;
> +
> + my $family_name;
> + unless ($family_name = $options{'close_family'}) {
> + pod2usage(-exitval => 1, -output => \*STDERR);
> + }
> + my $family;
> + unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> + print STDERR
> + "The family $family_name does not exist, impossible family
> closure\n";
> + exit 1;
> + }
> +
> + my $string;
> + unless ($string = $family->close_family()) {
> + print STDERR "\nImpossible family closure : action stopped \n";
> + exit 1;
> + }
> +
> + print STDOUT $string;
> +}
> +
> +sub sync_list_db {
> + print STDERR
> + "--sync_list_db was deprecated. Use --reload_list_config.\n";
> + exit 1;
> +}
> +
> +sub export_list {
> + my $robot_id = $options{'robot'} || '*';
> + my $all_lists = Sympa::List::get_lists($robot_id);
> + exit 1 unless defined $all_lists;
> + foreach my $list (@$all_lists) {
> + printf "%s\n", $list->name;
> + }
> +}
> Modified: trunk/src/sbin/sympa.pl.in (10631 => 10632)
> --- trunk/src/sbin/sympa.pl.in 2014-05-19 12:31:58 UTC (rev 10631)
> +++ trunk/src/sbin/sympa.pl.in 2014-05-19 14:49:35 UTC (rev 10632)
> @@ -30,17 +30,19 @@
>
> =head1 SYNOPSIS
>
> -S<B<sympa.pl> [ B<-d, --debug> ] [ B<-f, --file>=I<another.sympa.conf> ]>
> - S<[ B<-k, --keepcopy>=I<directory> ]>
> - S<[ B<-l, --lang>=I<lang> ]> [ B<-m, --mail> ]
> - S<[ B<-h, --help> ]> [ B<-v, --version> ]
> - S<>
> - S<[ B<--import>=I<listname> ]>
> - S<[ B<--close_list>=I<list[@robot]> ]>
> - S<[ B<--purge_list>=I<list[@robot]> ]>
> - S<[ B<--lowercase> ] [ B<--make_alias_file> ]>
> - S<[ B<--dump>=I<listname> | ALL ]>
> +B<sympa.pl>
> + S<[ B<-d, --debug> ]>
> + S<[ B<-f, --config>=I<another.sympa.conf> ]>
> + S<[ B<-l, --lang>=I<lang> ]>
> + S<[ B<--log-level>=I<level> ]>
> + S<[ B<--foreground> ]>
> + S<[ B<-k, --keepcopy>=I<directory> ]>
> + S<[ B<-m, --mail> ]>
>
> +B<sympa.pl> B<-h, --help>
> +
> +B<sympa.pl> B<-v, --version>
> +
> =head1 DESCRIPTION
>
> B<Sympa> is scalable and highly customizable mailing list manager.
> @@ -56,7 +58,7 @@
>
> =head1 OPTIONS
>
> -F<sympa.pl> may run with following options in general.
> +F<sympa.pl> may run with following options:
>
> =over 4
>
> @@ -64,32 +66,26 @@
>
> Enable debug mode.
>
> -=item B<-f>, B<--config=>I<file>
> +=item B<-f>, B<--config>=I<file>
>
> Force Sympa to use an alternative configuration file instead
> of F<--CONFIG-->.
>
> -=item B<-l>, B<--lang=>I<lang>
> +=item B<-l>, B<--lang>=I<lang>
>
> Set this option to use a language for Sympa. The corresponding
> gettext catalog file must be located in F<--localedir-->
> directory.
>
> -=item B<--log_level=>I<level>
> +=item B<--log_level>=I<level>
>
> Sets Sympa log level.
>
> -=back
> -
> -F<sympa.pl> may run in daemon mode with following options.
> -
> -=over 4
> -
> =item B<--foreground>
>
> The process remains attached to the TTY.
>
> -=item B<-k>, B<--keepcopy=>F<directory>
> +=item B<-k>, B<--keepcopy>=F<directory>
>
> This option tells Sympa to keep a copy of every incoming message,
> instead of deleting them. `directory' is the directory to
> @@ -101,155 +97,8 @@
> useful for keeping track of each mail sent (log files may grow faster
> though).
>
> -=begin comment
> -
> -=item B<--service=process_command>|B<process_message>|B<process_creation>
> -
> -Process is dedicated to messages distribution, commands or to automatic
> lists
> -creation (default three of them).
> -
> -B<Not implemented>.
> -
> -=end comment
> -
> =back
>
> -With the following options F<sympa.pl> will run in batch mode:
> -
> -=over 4
> -
> -=item B<--add_list=>I<family_name> B<--robot=>I<robot_name>
> - B<--input_file=>I</path/to/file.xml>
> -
> -Add the list described by the file.xml under robot_name, to the family
> -family_name.
> -
> -=item B<--change_user_email> B<--current_email=>I<xx> B<--new_email=>I<xx>
> -
> -Changes a user email address in all Sympa databases (subscriber_table,
> -list config, etc) for all virtual robots.
> -
> -=item B<--close_family=>I<family_name> B<--robot=>I<robot_name>
> -
> -Close lists of family_name family under robot_name.
> -
> -=item B<--close_list=>I<list[@robot]>
> -
> -Close the list (changing its status to closed), remove aliases and remove
> -subscribers from DB (a dump is created in the list directory to allow
> -restoring the list)
> -
> -=item B<--conf_2_db>
> -
> -Load sympa.conf and each robot.conf into database.
> -
> -=item B<--create_list> B<--robot=>I<robot_name>
> - B<--input_file=>I</path/to/file.xml >
> -
> -Create a list with the XML file under robot robot_name.
> -
> -=item B<--dump=>I<list>@I<dom>|C<ALL>
> -
> -Dumps subscribers of for `listname' list or all lists. Subscribers are
> -dumped in subscribers.db.dump.
> -
> -=begin comment
> -
> -=item B<--export_list> [B<--robot=>I<robot_name>]
> -
> -B<Not fully implemented>.
> -
> -=end comment
> -
> -=item B<--health_check>
> -
> -Check if F<sympa.conf>, F<robot.conf> of virtual robots and database
> structure
> -are correct. If any errors occur, exits with non-zero status.
> -
> -=item B<--import=>I<list>@I<dom>
> -
> -Import subscribers in the list. Data are read from standard input.
> -The imported data should contain one entry per line : the first field
> -is an email address, the second (optional) field is the free form name.
> -Fields are spaces-separated.
> -
> -Sample:
> -
> - ## Data to be imported
> - ## email gecos
> - address@concealed John - accountant
> - address@concealed Mary - secretary
> -
> -=item B<--instantiate_family=>I<family_name> B<--robot=>I<robot_name>
> - B<--input_file=>I</path/to/file.xml> [B<--close_unknown>] [B<--quiet>]
> -
> -Instantiate family_name lists described in the file.xml under robot_name.
> -The family directory must exist; automatically close undefined lists in a
> -new instantiation if --close_unknown is specified; do not print report if
> -C<--quiet> is specified.
> -
> -=item B<--lowercase>
> -
> -Lowercases email addresses in database.
> -
> -=item B<--make_alias_file>
> -
> -Create an aliases file in /tmp/ with all list aliases. It uses the
> -F<list_aliases.tt2> template (useful when list_aliases.tt2 was changed).
> -
> -=item B<--md5_encode_password>
> -
> -Rewrite password in C<user_table> of database using MD5 fingerprint.
> -YOU CAN'T UNDO unless you save this table first.
> -
> -=item B<--modify_list=>I<family_name> B<--robot=>I<robot_name>
> - B<--input_file=>I</path/to/file.xml>
> -
> -Modify the existing list installed under the robot robot_name and that
> -belongs to the family family_name. The new description is in the
> C<file.xml>.
> -
> -=item B<--purge_list>=I<list>[@I<robot>]
> -
> -Remove the list (remove archive, configuration files, users and owners in
> admin table. Restore is not possible after this operation.
> -
> -=item B<--reload_list_config>
> - [B<--list=>I<mylist>@I<mydom>] [B<--robot=>I<mydom>]
> -
> -Recreates all F<config.bin> files or cache in C<list_table>.
> -You should run this command if you edit authorization scenarios.
> -The list and robot parameters are optional.
> -
> -=item B<--rename_list=>I<listname>@I<robot>
> - B<--new_listname=>I<newlistname> B<--new_listrobot=>I<newrobot>
> -
> -Renames a list or move it to another virtual robot.
> -
> -=item B<--sync_include=>I<listname>@I<robot>
> -
> -Trigger the list members update.
> -
> -=begin comment
> -
> -=item B<--sync_list_db>
> -
> -B<Deprecated>. Use B<--reload_list_config>.
> -
> -=end comment
> -
> -=item B<--test_database_message_buffer>
> -
> -Test the database message buffer size.
> -
> -=item B<--upgrade> [B<--from=>I<X>] [B<--to=>I<Y>]
> -
> -Runs Sympa maintenance script to upgrade from version I<X> to version I<Y>.
> -
> -=item B<--upgrade_shared> [B<--list=>I<X>] [B<--robot=>I<Y>]>
> -
> -Rename files in shared.
> -
> -=back
> -
> With following options F<sympa.pl> will print some information and exit.
>
> =over 4
> @@ -258,11 +107,6 @@
>
> Print this help message.
>
> -=item B<--md5_digest=>I<password>
> -
> -Output a MD5 digest of a password (useful for SOAP client trusted
> -application).
> -
> =item B<-v>, B<--version>
>
> Print the version number.
> @@ -335,17 +179,14 @@
> use lib '--modulesdir--';
>
> use Carp qw(croak);
> -use Digest::MD5;
> use English qw(-no_match_vars);
> use Getopt::Long;
> use MIME::Charset;
> use Pod::Usage;
> use POSIX qw();
>
> -use Sympa::Admin;
> use Sympa::Commands;
> use Sympa::Conf;
> -use Sympa::Config_XML;
> use Sympa::Constants;
> use Sympa::DatabaseManager;
> use Sympa::Family;
> @@ -357,16 +198,15 @@
> use Sympa::Message;
> use Sympa::Report;
> use Sympa::Robot;
> +use Sympa::Site;
> use Sympa::Spool::File;
> use Sympa::Spool::File::Message;
> -use Sympa::Spool::SQL;
> use Sympa::Tools;
> use Sympa::Tools::Data;
> use Sympa::Tools::Daemon;
> use Sympa::Tools::File;
> use Sympa::Tools::Message;
> use Sympa::Tools::Password;
> -use Sympa::Upgrade;
>
> # dirty global variables
> my $is_signed = {};
> @@ -386,33 +226,19 @@
> $ip = $ENV{'REMOTE_HOST'};
> $ip = $ENV{'REMOTE_ADDR'} unless ($ip);
>
> -## Check --dump option
> my %options;
> unless (
> GetOptions(
> - \%options, 'dump=s',
> - 'debug|d',,
> - 'log_level=s', 'foreground',
> - 'config|f=s', 'lang|l=s',
> - 'mail|m', 'keepcopy|k=s',
> - 'help|h', 'version|v',
> - 'import=s', 'make_alias_file',
> - 'lowercase', 'sync_list_db',
> - 'md5_encode_password', 'close_list=s',
> - 'rename_list=s', 'new_listname=s',
> - 'new_listrobot=s', 'purge_list=s',
> - 'create_list', 'instantiate_family=s',
> - 'robot=s', 'add_list=s',
> - 'modify_list=s', 'close_family=s',
> - 'md5_digest=s', 'change_user_email',
> - 'current_email=s', 'new_email=s',
> - 'input_file=s', 'sync_include=s',
> - 'upgrade', 'upgrade_shared',
> - 'from=s', 'to=s',
> - 'reload_list_config', 'list=s',
> - 'quiet', 'close_unknown',
> - 'test_database_message_buffer', 'conf_2_db',
> - 'export_list', 'health_check'
> + \%options,
> + 'config|f=s',
> + 'debug|d',
> + 'foreground',
> + 'help|h',
> + 'keepcopy|k=s',
> + 'lang|l=s',
> + 'log_level=s',
> + 'mail|m',
> + 'version|v',
> )
> ) {
> pod2usage(-exitval => 1, -output => \*STDERR);
> @@ -421,116 +247,18 @@
> if ($options{'debug'}) {
> $options{'log_level'} = 2 unless ($options{'log_level'});
> }
> -## Batch mode, ie NOT daemon
> -$options{'batch'} = 1
> - if ($options{'dump'}
> - || $options{'help'}
> - || $options{'version'}
> - || $options{'import'}
> - || $options{'make_alias_file'}
> - || $options{'lowercase'}
> - || $options{'md5_encode_password'}
> - || $options{'change_user_email'}
> - || $options{'close_list'}
> - || $options{'purge_list'}
> - || $options{'create_list'}
> - || $options{'rename_list'}
> - || $options{'instantiate_family'}
> - || $options{'add_list'}
> - || $options{'modify_list'}
> - || $options{'close_family'}
> - || $options{'md5_digest'}
> - || $options{'sync_include'}
> - || $options{'upgrade'}
> - || $options{'upgrade_shared'}
> - || $options{'test_database_message_buffer'}
> - || $options{'conf_2_db'}
> - || $options{'reload_list_config'}
> - || $options{'sync_list_db'});
>
> # Some option force foreground mode
> $options{'foreground'} = 1
> - if ($options{'debug'} || $options{'batch'});
> + if ($options{'debug'});
>
> -$options{'log_to_stderr'} = 1 unless ($options{'batch'});
> -$options{'log_to_stderr'} = 1
> - if ($options{'upgrade'}
> - || $options{'reload_list_config'}
> - || $options{'test_database_message_buffer'}
> - || $options{'conf_2_db'});
> +$options{'log_to_stderr'} = 1;
>
> if ($options{'help'}) {
> pod2usage(0);
> } elsif ($options{'version'}) {
> print $version_string;
> exit 0;
> -} elsif ($options{'health_check'}) {
> - ## Health check
> -
> - ## Load configuration file. Ignoring database config for now: it avoids
> - ## trying to load a database that could not exist yet.
> - unless (Sympa::Site->load('no_db' => 1, 'force_reload' => 1)) {
> - printf STDERR
> - "Configuration file %s has errors.\n",
> - Sympa::Conf::get_sympa_conf();
> - exit 1;
> - }
> -
> - ## Open the syslog and say we're read out stuff.
> - Sympa::Log::Syslog::do_openlog(Sympa::Site->syslog,
> Sympa::Site->log_socket_type,
> - 'health_check');
> -
> - ## Setting log_level using conf unless it is set by calling option
> - if ($options{'log_level'}) {
> - Sympa::Log::Syslog::set_log_level($options{'log_level'});
> - Sympa::Log::Syslog::do_log(
> - 'info',
> - 'Configuration file read, log level set using options : %s',
> - $options{'log_level'}
> - );
> - } else {
> - Sympa::Log::Syslog::set_log_level(Sympa::Site->log_level);
> - Sympa::Log::Syslog::do_log('info',
> - 'Configuration file read, default log level %s',
> - Sympa::Site->log_level);
> - }
> -
> - ## Check database connectivity and probe database
> - unless (Sympa::DatabaseManager::check_db_connect('just_try') and
> Sympa::DatabaseManager::probe_db()) {
> - printf STDERR
> - "Database %s defined in sympa.conf has not the right structure
> or is unreachable. verify db_xxx parameters in sympa.conf\n",
> - Sympa::Site->db_name;
> - exit 1;
> - }
> -
> - ## Now trying to load full config (including database)
> - unless (Sympa::Site->load() and Sympa::Robot::get_robots()) {
> - printf STDERR
> - "Unable to load Sympa configuration, file %s or any of the
> virtual host robot.conf files contain errors. Exiting.\n",
> - Sympa::Conf::get_sympa_conf();
> - exit 1;
> - }
> -
> - ## Change working directory.
> - if (!chdir(Sympa::Site->home)) {
> - printf STDERR "Can't chdir to %s: %s\n", Sympa::Site->home, $ERRNO;
> - exit 1;
> - }
> -
> - ## Check for several files.
> - unless (Sympa::Conf::checkfiles_as_root()) {
> - printf STDERR "Missing files.\n";
> - exit 1;
> - }
> -
> - ## Check that the data structure is uptodate
> - unless (Sympa::DatabaseManager::data_structure_uptodate()) {
> - printf STDERR
> - "Data structure was not updated; you should run sympa.pl
> --upgrade to run the upgrade process.\n";
> - exit 1;
> - }
> -
> - exit 0;
> }
>
> ## Main loop
> @@ -642,32 +370,30 @@
> 'sympa');
>
> Sympa::Log::Syslog::do_log('debug', 'Running server %d', $PID);
> - unless ($options{'batch'}) {
>
> - # check presence of a PID file from a previous execution
> - Sympa::Tools::Daemon::check_old_pid_file(
> - name => 'sympa',
> - piddir => Sympa::Constants::PIDDIR,
> - tmpdir => Sympa::Site->tmpdir(),
> - );
> + # check presence of a PID file from a previous execution
> + Sympa::Tools::Daemon::check_old_pid_file(
> + name => 'sympa',
> + piddir => Sympa::Constants::PIDDIR,
> + tmpdir => Sympa::Site->tmpdir(),
> + );
>
> - # Create the PID file
> - Sympa::Tools::Daemon::write_pid(
> - name => 'sympa',
> + # Create the PID file
> + Sympa::Tools::Daemon::write_pid(
> + name => 'sympa',
> + pid => $PID,
> + piddir => Sympa::Constants::PIDDIR,
> + user => Sympa::Constants::USER,
> + group => Sympa::Constants::GROUP,
> + );
> + # redirect STDERR to a file, unless the process is running in
> foreground
> + unless ($options{'foreground'}) {
> + Sympa::Tools::Daemon::direct_stderr_to_file(
> pid => $PID,
> - piddir => Sympa::Constants::PIDDIR,
> + tmpdir => Sympa::Site->tmpdir(),
> user => Sympa::Constants::USER,
> group => Sympa::Constants::GROUP,
> );
> - # redirect STDERR to a file, unless the process is running in
> foreground
> - unless ($options{'foreground'}) {
> - Sympa::Tools::Daemon::direct_stderr_to_file(
> - pid => $PID,
> - tmpdir => Sympa::Site->tmpdir(),
> - user => Sympa::Constants::USER,
> - group => Sympa::Constants::GROUP,
> - );
> - }
> }
>
> # Set the User ID & Group ID for the process
> @@ -703,700 +429,6 @@
> Sympa::Log::Syslog::fatal_err("Missing files. Aborting.");
> }
>
> - ## Daemon called for dumping subscribers list
> - if ($options{'dump'}) {
> -
> - my ($all_lists, $list);
> - if ($options{'dump'} eq 'ALL') {
> - $all_lists = Sympa::List::get_lists();
> - } else {
> -
> - ## The parameter can be a list address
> - unless ($options{'dump'} =~ /\@/) {
> - Sympa::Log::Syslog::do_log('err', 'Incorrect list address
> %s',
> - $options{'dump'});
> -
> - exit;
> - }
> -
> - my $list = Sympa::List->new($options{'dump'});
> - unless (defined $list) {
> - Sympa::Log::Syslog::do_log('err', 'Unknown list %s',
> - $options{'dump'});
> -
> - exit;
> - }
> - push @$all_lists, $list;
> - }
> -
> - foreach my $list (@$all_lists) {
> - unless ($list->dump()) {
> - print STDERR "Could not dump list(s)\n";
> - }
> - }
> -
> - exit 0;
> - } elsif ($options{'make_alias_file'}) {
> - my $all_lists = Sympa::List::get_lists();
> -
> - my $aliases_file = Sympa::Site->tmpdir . '/sympa_aliases' . $PID;
> - unless (open TMP, '>', $aliases_file) {
> - printf STDERR "Unable to create %s, exiting\n", $aliases_file;
> - exit;
> - }
> - printf TMP "#\n#\tAliases for all Sympa lists open\n#\n";
> - close TMP;
> -
> - foreach my $list (@$all_lists) {
> - my $cmd = sprintf '%s add %s %s %s',
> - Sympa::Site->alias_manager, $list->name, $list->domain,
> - $aliases_file;
> - system($cmd) if $list->status eq 'open';
> - }
> - printf
> - "Sympa aliases file %s was made. You probably need to install
> it in your SMTP engine\n",
> - $aliases_file;
> -
> - exit 0;
> - } elsif ($options{'md5_digest'}) {
> - my $md5 = Digest::MD5::md5_hex($options{'md5_digest'});
> - printf "MD5 digest : %s \n", $md5;
> -
> - exit 0;
> - } elsif ($options{'import'}) {
> - my ($list, $total);
> -
> - ## The parameter should be a list address
> - unless ($options{'import'} =~ /\@/) {
> - Sympa::Log::Syslog::do_log(
> - 'err',
> - 'Incorrect list address %s',
> - $options{'import'}
> - );
> - exit;
> - }
> -
> - unless ($list = Sympa::List->new($options{'import'})) {
> - Sympa::Log::Syslog::fatal_err('Unknown list name %s',
> - $options{'import'});
> - }
> -
> - ## Read imported data from STDIN
> - while (<STDIN>) {
> - next if /^\s*$/;
> - next if /^\s*\#/;
> -
> - unless (/^\s*((\S+|\".*\")@\S+)(\s*(\S.*))?\s*$/) {
> - printf STDERR "Not an email address: %s\n", $_;
> - }
> -
> - my $email = lc($1);
> - my $gecos = $4;
> - my $u;
> - my $defaults = $list->default_user_options;
> - %{$u} = %{$defaults};
> - $u->{'email'} = $email;
> - $u->{'gecos'} = $gecos;
> -
> - $list->add_list_member($u);
> - if (defined $list->{'add_outcome'}{'errors'}) {
> - printf STDERR "\nCould not add %s. %s\n", $email,
> - $list->{'add_outcome'}{'errors'}{'error_message'};
> - next;
> - }
> - print STDERR '+';
> -
> - $total++;
> - }
> -
> - printf STDERR "Total imported subscribers: %d\n", $total;
> -
> - exit 0;
> - } elsif ($options{'md5_encode_password'}) {
> -
> - unless ($Sympa::Site::use_db) {
> - Sympa::Log::Syslog::fatal_err(
> - "You don't have a database setup, can't lowercase email
> addresses"
> - );
> - }
> -
> - my $total = Sympa::Upgrade::md5_encode_password();
> - printf STDERR "Total password re-encoded using MD5: %d\n", $total;
> -
> - exit 0;
> -
> - } elsif ($options{'lowercase'}) {
> -
> - unless ($Sympa::Site::use_db) {
> - Sympa::Log::Syslog::fatal_err(
> - "You don't have a database setup, can't lowercase email
> addresses"
> - );
> - }
> -
> - print STDERR "Working on user_table...\n";
> - my $total = Sympa::List::lowercase_field('user_table',
> 'email_user');
> -
> - print STDERR "Working on subscriber_table...\n";
> - $total +=
> - Sympa::List::lowercase_field('subscriber_table',
> 'user_subscriber');
> -
> - unless (defined $total) {
> - Sympa::Log::Syslog::fatal_err("Could not work on database");
> - }
> -
> - printf STDERR "Total lowercased rows: %d\n", $total;
> -
> - exit 0;
> - } elsif ($options{'close_list'}) {
> -
> - my ($listname, $robotname) = split /\@/, $options{'close_list'};
> - my $list = Sympa::List->new($listname, $robotname);
> -
> - unless (defined $list) {
> - print STDERR "Incorrect list name $options{'close_list'}\n";
> - exit 1;
> - }
> -
> - if ($list->family_name) {
> - unless (
> - $list->set_status_family_closed('close_list',
> $list->name)) {
> - print STDERR
> - "Could not close list $options{'close_list'}\n";
> - exit 1;
> - }
> - } else {
> - unless ($list->close_list()) {
> - print STDERR
> - "Could not close list $options{'close_list'}\n";
> - exit 1;
> - }
> - }
> -
> - printf STDOUT "List %s has been closed, aliases have been
> removed\n",
> - $list->get_id;
> -
> - exit 0;
> - } elsif ($options{'change_user_email'}) {
> -
> - unless ($options{'current_email'}
> - && $options{'new_email'}) {
> - print STDERR "Missing current_email or new_email parameter\n";
> - exit 1;
> - }
> -
> - foreach my $robot (@{Sympa::Robot::get_robots()}) {
> - printf STDOUT "Doing processing for virtual robot %s...\n",
> - $robot->name;
> - my ($status, $failed_for) = Sympa::Admin::change_user_email(
> - 'current_email' => $options{'current_email'},
> - 'new_email' => $options{'new_email'},
> - 'robot' => $robot
> - );
> - unless (defined $status) {
> - printf STDERR
> - "Failed to change user email address in virtual robot
> %s'}\n",
> - $robot->name;
> - exit 1;
> - }
> -
> - foreach my $failed_list (@$failed_for) {
> - printf STDERR
> - "Failed to change user email address for list %s\n",
> - $failed_list->{'name'};
> - }
> - }
> -
> - printf STDOUT "Email address %s has been changed to %s\n",
> - $options{'current_email'}, $options{'new_email'};
> -
> - exit 0;
> - } elsif ($options{'purge_list'}) {
> -
> - my ($listname, $robotname) = split /\@/, $options{'purge_list'};
> - my $list = Sympa::List->new($listname, $robotname);
> -
> - unless (defined $list) {
> - print STDERR "Incorrect list name $options{'purge_list'}\n";
> - exit 1;
> - }
> -
> - if ($list->family_name) {
> - unless (
> - $list->set_status_family_closed('purge_list',
> $list->name)) {
> - print STDERR
> - "Could not purge list $options{'purge_list'}\n";
> - exit 1;
> - }
> - } else {
> - unless ($list->purge()) {
> - print STDERR
> - "Could not purge list $options{'close_list'}\n";
> - exit 1;
> - }
> - }
> -
> - printf STDOUT "List %s has been closed, aliases have been
> removed\n",
> - $list->get_id;
> -
> - exit 0;
> - } elsif ($options{'rename_list'}) {
> -
> - ## TODO A completer
> -
> - my ($listname, $robotname) = split /\@/,
> - $options{'rename_list'};
> - my $list = Sympa::List->new($listname, $robotname);
> -
> - unless (defined $list) {
> - print STDERR
> - "Incorrect list name $options{'rename_list'}\n";
> - exit 1;
> - }
> -
> - unless ($options{'new_listname'}) {
> - print STDERR "Missing parameter new_listname\n";
> - exit 1;
> - }
> -
> - unless ($options{'new_listrobot'}) {
> - print STDERR "Missing parameter new_listrobot\n";
> - exit 1;
> - }
> -
> - my ($new_listname, $new_robotname) =
> - ($options{'new_listname'}, $options{'new_listrobot'});
> -
> - my $result = Sympa::Admin::rename_list(
> - list => $list,
> - new_listname => $new_listname,
> - new_robot => $new_robotname,
> - options => {'skip_authz' => 1},
> - user_email => 'listmaster@' . $robotname,
> - );
> -
> - unless ($result == 1) {
> - printf STDERR "Could not rename list %s to %s\@%s: %s\n",
> - $options{'rename_list'}, $options{'new_listname'},
> - $options{'new_listrobot'}, $result;
> - exit 1;
> - }
> -
> - printf STDOUT "List %s has been renamed to %s\@%s\n",
> - $options{'rename_list'}, $options{'new_listname'},
> - $options{'new_listrobot'};
> -
> - exit 0;
> -
> - } elsif ($options{'test_database_message_buffer'}) {
> - my $size = 0;
> - print
> - "Sympa is going to store messages bigger and bigger to test
> the limit with its database. This may be very long \n";
> - ## will test message until a 21 Mo message.
> - $size = Sympa::Spool::store_test(21000);
> - if ($size == 21000) {
> - printf
> - "The maximum message size (%d Ko) testing was successful
> \n",
> - $size;
> - } else {
> - printf
> - "maximum message size that can be stored in database : %d
> Ko\n",
> - $size;
> - }
> - exit 1;
> -
> - } elsif ($options{'conf_2_db'}) {
> - printf
> - "Sympa is going to store %s in database conf_table. This
> operation do NOT remove original files\n",
> - Sympa::Conf::get_sympa_conf();
> - if (Sympa::Conf::conf_2_db()) {
> - printf "Done";
> - } else {
> - printf "an error occur";
> - }
> - exit 1;
> -
> - } elsif ($options{'create_list'}) {
> - my $robot_id = $options{'robot'}
> - || Sympa::Site->host; #FIXME: is domain better?
> -
> - unless ($options{'input_file'}) {
> - print STDERR "Error : missing 'input_file' parameter\n";
> - exit 1;
> - }
> -
> - unless (open INFILE, $options{'input_file'}) {
> - print STDERR "Unable to open $options{'input_file'}) file";
> - exit 1;
> - }
> -
> - my $config = Sympa::Config_XML->new(\*INFILE);
> - unless (defined $config->createHash()) {
> - print STDERR "Error in representation data with these XML
> data\n";
> - exit 1;
> - }
> -
> - my $hash = $config->getHash();
> -
> - close INFILE;
> -
> - my $resul =
> - Sympa::Admin::create_list_old($hash->{'config'},
> $hash->{'type'},
> - $robot_id, "command_line");
> - unless (defined $resul) {
> - print STDERR "Could not create list with these XML data\n";
> - exit 1;
> - }
> -
> - if (!defined($resul->{'aliases'}) || $resul->{'aliases'} == 1) {
> - print STDOUT "List has been created \n";
> - exit 0;
> - } else {
> - printf STDOUT "List has been created, required aliases :\n %s
> \n",
> - $resul->{'aliases'};
> - exit 0;
> - }
> - } elsif ($options{'instantiate_family'}) {
> -
> - my $robot_id = $options{'robot'} || Sympa::Site->host;
> -
> - my $family_name;
> - unless ($family_name = $options{'instantiate_family'}) {
> - print STDERR "Error : missing family parameter\n";
> - exit 1;
> - }
> - my $family;
> - unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> - print STDERR
> - "The family $family_name does not exist, impossible
> instantiation\n";
> - exit 1;
> - }
> -
> - unless ($options{'input_file'}) {
> - print STDERR "Error : missing input_file parameter\n";
> - exit 1;
> - }
> -
> - unless (-r $options{'input_file'}) {
> - print STDERR "Unable to read $options{'input_file'} file";
> - exit 1;
> - }
> -
> - unless (
> - $family->instantiate(
> - $options{'input_file'},
> - $options{'close_unknown'}
> - )
> - ) {
> - print STDERR
> - "\nImpossible family instantiation : action stopped \n";
> - exit 1;
> - }
> -
> - my %result;
> - my $err = $family->get_instantiation_results(\%result);
> - close INFILE;
> -
> - unless ($options{'quiet'}) {
> - print STDOUT "@{$result{'info'}}";
> - print STDOUT "@{$result{'warn'}}";
> - }
> - if ($err) {
> - print STDERR "@{$result{'errors'}}";
> - }
> -
> - exit 0;
> - } elsif ($options{'add_list'}) {
> -
> - my $robot_id = $options{'robot'} || Sympa::Site->host;
> -
> - my $family_name;
> - unless ($family_name = $options{'add_list'}) {
> - print STDERR "Error : missing family parameter\n";
> - exit 1;
> - }
> -
> - print STDOUT
> -
> "\n************************************************************\n";
> -
> - my $family;
> - unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> - print STDERR
> - "The family $family_name does not exist, impossible to add
> a list\n";
> - exit 1;
> - }
> -
> - unless ($options{'input_file'}) {
> - print STDERR "Error : missing 'input_file' parameter\n";
> - exit 1;
> - }
> -
> - unless (open INFILE, $options{'input_file'}) {
> - print STDERR "\n Impossible to open input file : $ERRNO \n";
> - exit 1;
> - }
> -
> - my $result;
> - unless ($result = $family->add_list(\*INFILE)) {
> - print STDERR
> - "\nImpossible to add a list to the family : action stopped
> \n";
> - exit 1;
> - }
> -
> - print STDOUT
> -
> "\n************************************************************\n";
> -
> - unless (defined $result->{'ok'}) {
> - printf STDERR "\n%s\n", join("\n",
> @{$result->{'string_info'}});
> - print STDERR
> - "\n The action has been stopped because of error :\n";
> - printf STDERR "\n%s\n", join("\n",
> @{$result->{'string_error'}});
> - exit 1;
> - }
> -
> - close INFILE;
> -
> - print STDOUT "\n%s\n", join("\n", @{$result->{'string_info'}});
> - exit 0;
> - } elsif ($options{'sync_include'}) {
> -
> - my $list = Sympa::List->new($options{'sync_include'});
> -
> - unless (defined $list) {
> - print STDERR
> - "Incorrect list name $options{'sync_include'}\n";
> - exit 1;
> - }
> -
> - unless (defined $list->sync_include()) {
> - print STDERR "Failed to synchronize list members\n";
> - exit 1;
> - }
> -
> - printf "Members of list %s have been successfully updated.\n",
> - $list->get_id;
> - exit 0;
> - } elsif ($options{'upgrade'}) {
> -
> - ## Migration from one version to another
> - Sympa::Log::Syslog::do_log('notice', "Upgrade process...");
> -
> - $options{'from'} ||= Sympa::Upgrade::get_previous_version();
> - $options{'to'} ||= Sympa::Constants::VERSION;
> -
> - if ($options{'from'} eq $options{'to'}) {
> - Sympa::Log::Syslog::do_log('err',
> - "Current version : %s ; no upgrade is required.",
> - $options{'to'});
> - exit 0;
> - } else {
> - Sympa::Log::Syslog::do_log('notice', "Upgrading from %s to
> %s...",
> - $options{'from'}, $options{'to'});
> - }
> -
> - Sympa::DatabaseManager::probe_db;
> - unless (
> - Sympa::Upgrade::upgrade($options{'from'}, $options{'to'})) {
> - Sympa::Log::Syslog::do_log('err',
> - "Migration from %s to %s failed",
> - $options{'from'}, $options{'to'});
> - exit 1;
> - }
> - Sympa::Log::Syslog::do_log('notice', "Upgrade process finished.");
> - Sympa::Upgrade::update_version();
> -
> - exit 0;
> -
> - } elsif ($options{'upgrade_shared'}) {
> -
> - ## rename file names that may be incorrectly encoded because of
> - ## previous Sympa versions
> - Sympa::Log::Syslog::do_log('notice', "Upgrade shared process...");
> -
> - my $listname;
> - my $robot_id;
> -
> - unless (($options{'list'}) || ($options{'robot'})) {
> - Sympa::Log::Syslog::do_log('err',
> - "listname and domain are required, use --list= --robot=
> options"
> - );
> - exit 0;
> - }
> - $listname = $options{'list'};
> - $robot_id = $options{'robot'};
> -
> - Sympa::Log::Syslog::do_log('notice',
> - "Upgrading share for list=%s robot=%s",
> - $listname, $robot_id);
> -
> - my $list = Sympa::List->new($listname, $robot_id);
> -
> - unless (defined $list) {
> - printf STDERR "Incorrect list or domain name : %s %s\n",
> - $listname, $robot_id;
> - exit 1;
> - }
> -
> - if (-d $list->dir . '/shared') {
> - Sympa::Log::Syslog::do_log('notice', ' Processing list %s...',
> - $list);
> -
> - ## Determine default lang for this list
> - ## It should tell us what character encoding was used for
> - ## filenames
> - Sympa::Language::SetLang($list->lang);
> - my $list_encoding = Sympa::Language::GetCharset();
> -
> - my $count = Sympa::Tools::qencode_hierarchy($list->dir .
> '/shared',
> - $list_encoding);
> -
> - if ($count) {
> - Sympa::Log::Syslog::do_log('notice',
> - 'List %s : %d filenames has been changed',
> - $list, $count);
> - }
> - }
> - Sympa::Log::Syslog::do_log('notice',
> - "Upgrade_shared process finished.");
> -
> - exit 0;
> -
> - } elsif ($options{'reload_list_config'}) {
> - my $listname = $options{'list'};
> - my $robot_id = $options{'robot'} || '';
> - $listname = '' unless defined $listname;
> - if ($listname =~ s/\@(.+)$//) {
> - $robot_id = $1;
> - }
> -
> - if (length $listname) {
> - Sympa::Log::Syslog::do_log('notice', 'Loading list %s...',
> - $listname);
> - my $robot = Sympa::Robot->new($robot_id ||
> Sympa::Site->domain);
> - unless (defined $robot) {
> - print STDERR "Error : incorrect robot name '$robot_id'\n";
> - exit 1;
> - }
> - unless (Sympa::List->new($listname, $robot, {'reload_config'
> => 1})) {
> - print STDERR "Error : incorrect list name '$listname'\n";
> - exit 1;
> - }
> - } else {
> - my $that;
> - if ($robot_id) {
> - Sympa::Log::Syslog::do_log('notice',
> - 'Loading all lists in %s...', $robot_id);
> - $that = Sympa::Robot->new($robot_id);
> - unless (defined $that) {
> - print STDERR "Error : incorrect robot name
> '$robot_id'\n";
> - exit 1;
> - }
> - } else {
> - Sympa::Log::Syslog::do_log('notice', 'Loading ALL
> lists...');
> - $that = 'Site';
> - }
> - Sympa::List::get_lists($that, {'reload_config' => 1});
> - }
> - Sympa::Log::Syslog::do_log('notice', '...Done.');
> -
> - exit 0;
> - }
> -
> - ##########################################
> - elsif ($options{'modify_list'}) {
> -
> - my $robot_id = $options{'robot'} || Sympa::Site->host;
> -
> - my $family_name;
> - unless ($family_name = $options{'modify_list'}) {
> - print STDERR "Error : missing family parameter\n";
> - exit 1;
> - }
> -
> - print STDOUT
> -
> "\n************************************************************\n";
> -
> - my $family;
> - unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> - print STDERR
> - "The family $family_name does not exist, impossible to
> modify the list.\n";
> - exit 1;
> - }
> -
> - unless ($options{'input_file'}) {
> - print STDERR "Error : missing input_file parameter\n";
> - exit 1;
> - }
> -
> - unless (open INFILE, $options{'input_file'}) {
> - print STDERR "Unable to open $options{'input_file'}) file";
> - exit 1;
> - }
> -
> - my $result;
> - unless ($result = $family->modify_list(\*INFILE)) {
> - print STDERR
> - "\nImpossible to modify the family list : action stopped.
> \n";
> - exit 1;
> - }
> -
> - print STDOUT
> -
> "\n************************************************************\n";
> -
> - unless (defined $result->{'ok'}) {
> - printf STDERR "\n%s\n", join("\n",
> @{$result->{'string_info'}});
> - print STDERR "\nThe action has been stopped because of error
> :\n";
> - printf STDERR "\n%s\n", join("\n",
> @{$result->{'string_error'}});
> - exit 1;
> - }
> -
> - close INFILE;
> -
> - printf STDOUT "\n%s\n", join("\n", @{$result->{'string_info'}});
> - exit 0;
> - }
> -
> - ##########################################
> - elsif ($options{'close_family'}) {
> -
> - my $robot_id = $options{'robot'} || Sympa::Site->host;
> -
> - my $family_name;
> - unless ($family_name = $options{'close_family'}) {
> - pod2usage(-exitval => 1, -output => \*STDERR);
> - }
> - my $family;
> - unless ($family = Sympa::Family->new($family_name, $robot_id)) {
> - print STDERR
> - "The family $family_name does not exist, impossible family
> closure\n";
> - exit 1;
> - }
> -
> - my $string;
> - unless ($string = $family->close_family()) {
> - print STDERR "\nImpossible family closure : action stopped \n";
> - exit 1;
> - }
> -
> - print STDOUT $string;
> - exit 0;
> - }
> - ##########################################
> - elsif ($options{'sync_list_db'}) {
> - print STDERR
> - "--sync_list_db was deprecated. Use --reload_list_config.\n";
> - exit 1;
> - }
> - ##########################################
> - elsif ($options{'export_list'}) {
> - my $robot_id = $options{'robot'} || '*';
> - my $all_lists = Sympa::List::get_lists($robot_id);
> - exit 1 unless defined $all_lists;
> - foreach my $list (@$all_lists) {
> - printf "%s\n", $list->name;
> - }
> - exit 0;
> - }
> -
> ## Do we have right access in the directory
> if ($options{'keepcopy'}) {
> if (!-d $options{'keepcopy'}) {


--
IKEDA Soji <address@concealed>


  • [sympa-developpers] Dividing sympa.pl was Re: [sympa-commits] sympa[10632] trunk/src: [dev] extract all admin duties of sympa. pl into another dedicated, IKEDA Soji, 10/07/2014

Archive powered by MHonArc 2.6.19+.

Top of Page