1 # Copyright (C) 2011 Alex Schroeder <alex@gnu.org>
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the GNU General Public License as published by the Free Software
5 # Foundation, either version 3 of the License, or (at your option) any later
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along with
13 # this program. If not, see <http://www.gnu.org/licenses/>.
17 use vars
qw($MonitorUser $MonitorPassword $MonitorHost
18 $MonitorFrom $MonitorTo $MonitorRegexp);
21 # $MonitorUser = 'oddmuse.wiki';
22 # $MonitorPassword = '***secret***';
23 # $MonitorHost = 'smpt.google.com';
24 # $MonitorFrom = 'oddmuse.wiki@gmail.com';
25 # $MonitorTo = 'kensanata@gmail.com';
26 # $MonitorRegexp = '.';
28 push(@MyInitVariables, \&MonitorInit);
31 $Message .= $q->p(shift);
35 $MonitorTo = $MonitorFrom unless $MonitorTo;
36 if (!$MonitorUser or !$MonitorPassword
37 or !$MonitorHost or !$MonitorFrom) {
38 $Message .= $q->p('Monitor extension has been installed but not configured.');
40 if ($q->request_method() eq 'POST'
41 && !$q->param('Preview')
42 && $q->url =~ /$MonitorRegexp/) {
47 MonitorLog("monitor error: $@");
53 # MonitorLog("monitor send");
56 # MonitorLog("monitor require");
57 my $fh = File::Temp->new(SUFFIX => '.html');
58 my $home = ScriptLink(UrlEncode($HomePage), "$SiteName: $HomePage");
59 print $fh qq(<p>Monitor mail from $home.</p><hr />)
62 # MonitorLog("monitor file");
63 my $mail = new MIME::Entity->build(To => $MonitorTo,
65 Subject => "Oddmuse Monitor",
68 # MonitorLog("monitor mail");
70 require Net::SMTP::TLS;
71 my $smtp = Net::SMTP::TLS->new($MonitorHost,
73 Password => $MonitorPassword);
74 $smtp->mail($MonitorFrom);
75 $smtp->to($MonitorTo);
77 $smtp->datasend($mail->stringify);
81 MonitorLog("monitor TSL error: $@") if $@;
83 require Net::SMTP::SSL;
84 my $smtp = Net::SMTP::SSL->new($MonitorHost, Port => 465);
85 $smtp->auth($MonitorUser, $MonitorPassword);
86 $smtp->mail($MonitorFrom);
87 $smtp->to($MonitorTo);
89 $smtp->datasend($mail->stringify);
93 MonitorLog("monitor SSL error: $@") if $@;