1# See bottom of file for license and copyright information
2package Foswiki::Plugins::MailerContribPlugin;
3
4use strict;
5use warnings;
6
7# Also change Version/Release in Contrib/MailerContrib.pm
8our $VERSION           = '2.84';
9our $RELEASE           = '2.84';
10our $SHORTDESCRIPTION  = 'Supports e-mail notification of changes';
11our $NO_PREFS_IN_TOPIC = 1;
12
13# Plugin init method, used to initialise handlers
14sub initPlugin {
15    Foswiki::Func::registerRESTHandler(
16        'notify', \&_restNotify,
17        authenticate => 1,
18        validate     => 1,
19        http_allow   => 'POST',
20        description =>
21          'Allow administrators to run the mailNotify process from the web.',
22    );
23    return 1;
24}
25
26# Run mailnotify using a rest handler
27sub _restNotify {
28    my ( $session, $plugin, $verb, $response ) = @_;
29
30    if ( !Foswiki::Func::isAnAdmin() ) {
31        $response->header( -status => 403, -type => 'text/plain' );
32        $response->print("Only administrators can do that");
33    }
34    else {
35
36        # Don't use the $response; we want to see things happening
37        local $| = 1;    # autoflush on
38        require CGI;
39        print CGI::header(
40            -status  => 200,
41            -type    => 'text/plain',
42            -charset => $Foswiki::cfg{Site}{CharSet},
43        );
44
45        my $query   = Foswiki::Func::getCgiQuery();
46        my %options = (
47            verbose => 1,
48            news    => 1,
49            changes => 1,
50            reset   => 1,
51            mail    => 1
52        );
53
54        if ( $query->param('q') ) {
55            $options{verbose} = 0;
56        }
57        if ( $query->param('nonews') ) {
58            $options{news} = 0;
59        }
60        if ( $query->param('nochanges') ) {
61            $options{changes} = 0;
62        }
63        if ( $query->param('noreset') ) {
64            $options{reset} = 0;
65        }
66        if ( $query->param('nomail') ) {
67            $options{mail} = 0;
68        }
69
70        my @exwebs = split( ',', $query->param('excludewebs') || '' );
71        my @webs   = split( ',', $query->param('webs')        || '' );
72
73        require Foswiki::Contrib::MailerContrib;
74        Foswiki::Contrib::MailerContrib::mailNotify( \@webs, \@exwebs,
75            %options );
76    }
77    return undef;
78}
79
801;
81__END__
82Foswiki - The Free and Open Source Wiki, http://foswiki.org/
83
84Copyright (C) 2008-2017 Foswiki Contributors. Foswiki Contributors
85are listed in the AUTHORS file in the root of this distribution.
86NOTE: Please extend that file, not this notice.
87
88This program is free software; you can redistribute it and/or
89modify it under the terms of the GNU General Public License
90as published by the Free Software Foundation; either version 2
91of the License, or (at your option) any later version. For
92more details read LICENSE in the root of this distribution.
93
94This program is distributed in the hope that it will be useful,
95but WITHOUT ANY WARRANTY; without even the implied warranty of
96MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
97
98As per the GPL, removal of this notice is prohibited.
99