1 |
9774f564
|
Colin Smith
|
<?php
|
2 |
09221bc3
|
Renato Botelho
|
/*
|
3 |
ac24dc24
|
Renato Botelho
|
* notices.inc
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
c5d81585
|
Renato Botelho
|
* Copyright (c) 2005 Colin Smith (ethethlay@gmail.com)
|
7 |
880ed461
|
jim-p
|
* Copyright (c) 2005-2020 Rubicon Communications, LLC (Netgate)
|
8 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
9 |
|
|
*
|
10 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11 |
|
|
* you may not use this file except in compliance with the License.
|
12 |
|
|
* You may obtain a copy of the License at
|
13 |
ac24dc24
|
Renato Botelho
|
*
|
14 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15 |
ac24dc24
|
Renato Botelho
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
17 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19 |
|
|
* See the License for the specific language governing permissions and
|
20 |
|
|
* limitations under the License.
|
21 |
9774f564
|
Colin Smith
|
*/
|
22 |
|
|
|
23 |
|
|
require_once("globals.inc");
|
24 |
419af712
|
Denny Page
|
require_once("functions.inc");
|
25 |
0c884086
|
jim-p
|
require_once("led.inc");
|
26 |
9774f564
|
Colin Smith
|
|
27 |
|
|
$notice_path = $g['tmp_path'] . '/notices';
|
28 |
c4249322
|
Phil Davis
|
$smtp_authentication_mechanisms = array(
|
29 |
|
|
'PLAIN' => 'PLAIN',
|
30 |
|
|
'LOGIN' => 'LOGIN');
|
31 |
|
|
/* Other SMTP Authentication Mechanisms that could be supported.
|
32 |
|
|
* Note that MD5 is no longer considered secure.
|
33 |
|
|
* 'GSSAPI' => 'GSSAPI ' . gettext("Generic Security Services Application Program Interface")
|
34 |
|
|
* 'DIGEST-MD5' => 'DIGEST-MD5 ' . gettext("Digest access authentication")
|
35 |
|
|
* 'MD5' => 'MD5'
|
36 |
|
|
* 'CRAM-MD5' => 'CRAM-MD5'
|
37 |
|
|
*/
|
38 |
9774f564
|
Colin Smith
|
|
39 |
91cae49d
|
Scott Ullrich
|
/****f* notices/file_notice
|
40 |
|
|
* NAME
|
41 |
|
|
* file_notice
|
42 |
|
|
* INPUTS
|
43 |
642c6023
|
Phil Davis
|
* $id, $notice, $category, $url, $priority, $local_only
|
44 |
91cae49d
|
Scott Ullrich
|
* RESULT
|
45 |
|
|
* Files a notice and kicks off the various alerts, smtp, growl, system log, LED's, etc.
|
46 |
642c6023
|
Phil Davis
|
* If $local_only is true then the notice is not sent to external places (smtp, growl)
|
47 |
91cae49d
|
Scott Ullrich
|
******/
|
48 |
642c6023
|
Phil Davis
|
function file_notice($id, $notice, $category = "General", $url = "", $priority = 1, $local_only = false) {
|
49 |
91cae49d
|
Scott Ullrich
|
/*
|
50 |
|
|
* $category - Category that this notice should be displayed under. This can be arbitrary,
|
51 |
|
|
* but a page must be set to receive this messages for it to be displayed.
|
52 |
|
|
*
|
53 |
|
|
* $priority - A notice's priority. Higher numbers indicate greater severity.
|
54 |
|
|
* 0 = informational, 1 = warning, 2 = error, etc. This may also be arbitrary,
|
55 |
|
|
*/
|
56 |
9774f564
|
Colin Smith
|
global $notice_path;
|
57 |
b37a2e8c
|
Phil Davis
|
if (!$queue = get_notices()) {
|
58 |
|
|
$queue = array();
|
59 |
|
|
}
|
60 |
9774f564
|
Colin Smith
|
$queuekey = time();
|
61 |
|
|
$toqueue = array(
|
62 |
e392cc2b
|
Chris Buechler
|
'id' => htmlentities($id),
|
63 |
|
|
'notice' => htmlentities($notice),
|
64 |
|
|
'url' => htmlentities($url),
|
65 |
|
|
'category' => htmlentities($category),
|
66 |
|
|
'priority' => htmlentities($priority),
|
67 |
9774f564
|
Colin Smith
|
);
|
68 |
80b53805
|
Phil Davis
|
while (isset($queue[$queuekey])) {
|
69 |
|
|
$queuekey++;
|
70 |
|
|
}
|
71 |
9774f564
|
Colin Smith
|
$queue[$queuekey] = $toqueue;
|
72 |
|
|
$queueout = fopen($notice_path, "w");
|
73 |
b37a2e8c
|
Phil Davis
|
if (!$queueout) {
|
74 |
6d44231f
|
Phil Davis
|
log_error(sprintf(gettext("Could not open %s for writing"), $notice_path));
|
75 |
34e1ff97
|
Scott Ullrich
|
return;
|
76 |
|
|
}
|
77 |
9774f564
|
Colin Smith
|
fwrite($queueout, serialize($queue));
|
78 |
|
|
fclose($queueout);
|
79 |
e8c516a0
|
Phil Davis
|
log_error(sprintf(gettext("New alert found: %s"), $notice));
|
80 |
a0a125b9
|
Scott Ullrich
|
/* soekris */
|
81 |
b37a2e8c
|
Phil Davis
|
if (file_exists("/dev/led/error")) {
|
82 |
5f9bcd7a
|
Scott Ullrich
|
exec("/bin/echo 1 > /dev/led/error");
|
83 |
b37a2e8c
|
Phil Davis
|
}
|
84 |
0c884086
|
jim-p
|
/* wrap & alix */
|
85 |
1c9512f2
|
jim-p
|
led_normalize();
|
86 |
0c884086
|
jim-p
|
led_morse(1, 'sos');
|
87 |
642c6023
|
Phil Davis
|
if (!$local_only) {
|
88 |
a2e35163
|
Phil Davis
|
notify_all_remote($notice);
|
89 |
642c6023
|
Phil Davis
|
}
|
90 |
e2c48999
|
Colin Smith
|
return $queuekey;
|
91 |
9774f564
|
Colin Smith
|
}
|
92 |
|
|
|
93 |
91cae49d
|
Scott Ullrich
|
/****f* notices/get_notices
|
94 |
|
|
* NAME
|
95 |
|
|
* get_notices
|
96 |
|
|
* INPUTS
|
97 |
|
|
* $category
|
98 |
|
|
* RESULT
|
99 |
|
|
* Returns a specific notices text
|
100 |
|
|
******/
|
101 |
9774f564
|
Colin Smith
|
function get_notices($category = "all") {
|
102 |
6955830f
|
Ermal Lu?i
|
global $g;
|
103 |
|
|
|
104 |
b37a2e8c
|
Phil Davis
|
if (file_exists("{$g['tmp_path']}/notices")) {
|
105 |
6955830f
|
Ermal Lu?i
|
$queue = unserialize(file_get_contents("{$g['tmp_path']}/notices"));
|
106 |
b37a2e8c
|
Phil Davis
|
if (!$queue) {
|
107 |
|
|
return false;
|
108 |
|
|
}
|
109 |
|
|
if ($category != 'all') {
|
110 |
|
|
foreach ($queue as $time => $notice) {
|
111 |
|
|
if (strtolower($notice['category']) == strtolower($category)) {
|
112 |
9774f564
|
Colin Smith
|
$toreturn[$time] = $notice;
|
113 |
b37a2e8c
|
Phil Davis
|
}
|
114 |
9774f564
|
Colin Smith
|
}
|
115 |
|
|
return $toreturn;
|
116 |
|
|
} else {
|
117 |
|
|
return $queue;
|
118 |
|
|
}
|
119 |
|
|
} else {
|
120 |
|
|
return false;
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
|
124 |
91cae49d
|
Scott Ullrich
|
/****f* notices/close_notice
|
125 |
|
|
* NAME
|
126 |
|
|
* close_notice
|
127 |
|
|
* INPUTS
|
128 |
|
|
* $id
|
129 |
|
|
* RESULT
|
130 |
|
|
* Removes a notice from the list
|
131 |
|
|
******/
|
132 |
9774f564
|
Colin Smith
|
function close_notice($id) {
|
133 |
|
|
global $notice_path;
|
134 |
|
|
require_once("util.inc");
|
135 |
5f9bcd7a
|
Scott Ullrich
|
/* soekris */
|
136 |
b37a2e8c
|
Phil Davis
|
if (file_exists("/dev/led/error")) {
|
137 |
5f9bcd7a
|
Scott Ullrich
|
exec("/bin/echo 0 > /dev/led/error");
|
138 |
b37a2e8c
|
Phil Davis
|
}
|
139 |
0c884086
|
jim-p
|
/* wrap & alix */
|
140 |
|
|
led_normalize();
|
141 |
fab14377
|
Colin Smith
|
$ids = array();
|
142 |
b37a2e8c
|
Phil Davis
|
if (!$notices = get_notices()) {
|
143 |
|
|
return;
|
144 |
|
|
}
|
145 |
|
|
if ($id == "all") {
|
146 |
9774f564
|
Colin Smith
|
unlink_if_exists($notice_path);
|
147 |
|
|
return;
|
148 |
|
|
}
|
149 |
b37a2e8c
|
Phil Davis
|
foreach (array_keys($notices) as $time) {
|
150 |
|
|
if ($id == $time) {
|
151 |
9774f564
|
Colin Smith
|
unset($notices[$id]);
|
152 |
|
|
break;
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
b37a2e8c
|
Phil Davis
|
foreach ($notices as $key => $notice) {
|
156 |
9774f564
|
Colin Smith
|
$ids[$key] = $notice['id'];
|
157 |
|
|
}
|
158 |
b37a2e8c
|
Phil Davis
|
foreach ($ids as $time => $tocheck) {
|
159 |
|
|
if ($id == $tocheck) {
|
160 |
9774f564
|
Colin Smith
|
unset($notices[$time]);
|
161 |
|
|
break;
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
b37a2e8c
|
Phil Davis
|
if (count($notices) != 0) {
|
165 |
cebc42e6
|
Colin Smith
|
$queueout = fopen($notice_path, "w");
|
166 |
b37a2e8c
|
Phil Davis
|
fwrite($queueout, serialize($notices));
|
167 |
|
|
fclose($queueout);
|
168 |
cebc42e6
|
Colin Smith
|
} else {
|
169 |
|
|
unlink_if_exists($notice_path);
|
170 |
|
|
}
|
171 |
a0a125b9
|
Scott Ullrich
|
|
172 |
669e1adb
|
Bill Marquette
|
return;
|
173 |
9774f564
|
Colin Smith
|
}
|
174 |
|
|
|
175 |
91cae49d
|
Scott Ullrich
|
/****f* notices/dump_xml_notices
|
176 |
|
|
* NAME
|
177 |
|
|
* dump_xml_notices
|
178 |
|
|
* INPUTS
|
179 |
|
|
* NONE
|
180 |
|
|
* RESULT
|
181 |
|
|
* Outputs notices in XML formatted text
|
182 |
|
|
******/
|
183 |
9774f564
|
Colin Smith
|
function dump_xml_notices() {
|
184 |
b37a2e8c
|
Phil Davis
|
if (file_exists("/cf/conf/use_xmlreader")) {
|
185 |
093bcebc
|
Scott Ullrich
|
require_once("xmlreader.inc");
|
186 |
b37a2e8c
|
Phil Davis
|
} else {
|
187 |
093bcebc
|
Scott Ullrich
|
require_once("xmlparse.inc");
|
188 |
b37a2e8c
|
Phil Davis
|
}
|
189 |
9774f564
|
Colin Smith
|
global $notice_path, $listtags;
|
190 |
|
|
$listtags[] = 'notice';
|
191 |
b37a2e8c
|
Phil Davis
|
if (!$notices = get_notices()) {
|
192 |
|
|
return;
|
193 |
|
|
}
|
194 |
|
|
foreach ($notices as $time => $notice) {
|
195 |
9774f564
|
Colin Smith
|
$notice['time'] = $time;
|
196 |
|
|
$toput['notice'][] = $notice;
|
197 |
|
|
}
|
198 |
|
|
$xml = dump_xml_config($toput, 'notices');
|
199 |
|
|
return $xml;
|
200 |
|
|
}
|
201 |
|
|
|
202 |
91cae49d
|
Scott Ullrich
|
/****f* notices/are_notices_pending
|
203 |
|
|
* NAME
|
204 |
|
|
* are_notices_pending
|
205 |
|
|
* INPUTS
|
206 |
|
|
* $category to check
|
207 |
|
|
* RESULT
|
208 |
|
|
* returns true if notices are pending, false if they are not
|
209 |
|
|
******/
|
210 |
34e1ff97
|
Scott Ullrich
|
function are_notices_pending($category = "all") {
|
211 |
|
|
global $notice_path;
|
212 |
b37a2e8c
|
Phil Davis
|
if (file_exists($notice_path)) {
|
213 |
34e1ff97
|
Scott Ullrich
|
return true;
|
214 |
|
|
}
|
215 |
|
|
return false;
|
216 |
6e2ec568
|
Scott Ullrich
|
}
|
217 |
|
|
|
218 |
dc5fdeea
|
PiBa-NL
|
function notices_sendqueue() {
|
219 |
|
|
global $g;
|
220 |
|
|
$nothing_done_count = 0;
|
221 |
|
|
$messagequeue = array();
|
222 |
|
|
$growlerrorcount = 0;
|
223 |
|
|
$growlskipped = 0;
|
224 |
179377b0
|
robjarsen
|
|
225 |
dc5fdeea
|
PiBa-NL
|
while(true) {
|
226 |
|
|
$notifyqueue_lck = lock("notifyqueue", LOCK_EX);
|
227 |
|
|
$nothing_done_count++;
|
228 |
|
|
$smptcount = 0;
|
229 |
|
|
$messages = array();
|
230 |
|
|
if (file_exists("{$g['vardb_path']}/notifyqueue.messages")) {
|
231 |
|
|
$messages = unserialize(file_get_contents("{$g['vardb_path']}/notifyqueue.messages"));
|
232 |
|
|
$messagequeue = $messages;
|
233 |
|
|
$messages['mails']['item'] = array(); // clear all items to be send
|
234 |
|
|
file_put_contents("{$g['vardb_path']}/notifyqueue.messages", serialize($messages));
|
235 |
|
|
unset($messages);
|
236 |
|
|
}
|
237 |
|
|
// clear lock before trying to send messages, so new one's can be added
|
238 |
|
|
unlock($notifyqueue_lck);
|
239 |
179377b0
|
robjarsen
|
|
240 |
dc5fdeea
|
PiBa-NL
|
if (is_array($messagequeue['mails']['item'])) {
|
241 |
|
|
$smtpmessage = "";
|
242 |
|
|
$growlqueue = array();
|
243 |
|
|
foreach($messagequeue['mails']['item'] as $mail) {
|
244 |
|
|
switch ($mail['type']) {
|
245 |
179377b0
|
robjarsen
|
case 'mail':
|
246 |
dc5fdeea
|
PiBa-NL
|
$smptcount++;
|
247 |
|
|
$smtpmessage .= "\r\n" . date("G:i:s",$mail['time']) . " " . $mail['msg'];
|
248 |
|
|
break;
|
249 |
|
|
case 'growl':
|
250 |
|
|
$message = date("G:i:s",$mail['time']) . " " . $mail['msg'];
|
251 |
|
|
$nothing_done_count = 0;
|
252 |
|
|
$growlqueue[] = $message;
|
253 |
|
|
break;
|
254 |
|
|
default:
|
255 |
|
|
break;
|
256 |
|
|
}
|
257 |
|
|
}
|
258 |
|
|
if (!empty($smtpmessage)) {
|
259 |
d0d6d27f
|
jim-p
|
$smtpmessageheader = sprintf(gettext("Notifications in this message: %s"), $smptcount);
|
260 |
|
|
$smtpmessageheader .= "\n" . str_repeat('=', strlen($smtpmessageheader)) . "\n";
|
261 |
dc5fdeea
|
PiBa-NL
|
$nothing_done_count = 0;
|
262 |
d0d6d27f
|
jim-p
|
notify_via_smtp($smtpmessageheader . $smtpmessage, true);
|
263 |
dc5fdeea
|
PiBa-NL
|
}
|
264 |
|
|
if (count($growlqueue) > 0) {
|
265 |
|
|
$nothing_done_count = 0;
|
266 |
|
|
foreach($growlqueue as $message) {
|
267 |
|
|
if ($growlerrorcount < 3) {
|
268 |
|
|
$ret = notify_via_growl($message, true);
|
269 |
|
|
if (!empty($ret)) {
|
270 |
|
|
$growlerrorcount++;
|
271 |
|
|
}
|
272 |
|
|
} else {
|
273 |
|
|
$growlskipped++;
|
274 |
|
|
}
|
275 |
|
|
}
|
276 |
|
|
}
|
277 |
|
|
}
|
278 |
|
|
if ($nothing_done_count > 6) {
|
279 |
|
|
break;
|
280 |
|
|
} else {
|
281 |
|
|
sleep(10);
|
282 |
|
|
}
|
283 |
|
|
}
|
284 |
|
|
if ($growlskipped > 0) {
|
285 |
|
|
log_error("{$growlskipped} growl notifications were skipped due to to many errors: {$growlerrorcount}.");
|
286 |
|
|
}
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
function notify_via_queue_add($message, $type='mail') {
|
290 |
|
|
global $g;
|
291 |
|
|
$mail = array();
|
292 |
|
|
$mail['time'] = time();
|
293 |
|
|
$mail['type'] = $type;
|
294 |
|
|
$mail['msg'] = $message;
|
295 |
|
|
$notifyqueue_lck = lock("notifyqueue", LOCK_EX);
|
296 |
|
|
$messages = array();
|
297 |
|
|
if (file_exists("{$g['vardb_path']}/notifyqueue.messages")) {
|
298 |
|
|
$messages = unserialize(file_get_contents("{$g['vardb_path']}/notifyqueue.messages"));
|
299 |
|
|
}
|
300 |
|
|
if(is_array($messages)) {
|
301 |
|
|
$messages['mails']['item'][] = $mail;
|
302 |
|
|
file_put_contents("{$g['vardb_path']}/notifyqueue.messages", serialize($messages));
|
303 |
|
|
}
|
304 |
|
|
unset($messages);
|
305 |
179377b0
|
robjarsen
|
|
306 |
dc5fdeea
|
PiBa-NL
|
mwexec_bg('/usr/local/bin/notify_monitor.php');
|
307 |
|
|
unlock($notifyqueue_lck);
|
308 |
|
|
}
|
309 |
|
|
|
310 |
91cae49d
|
Scott Ullrich
|
/****f* notices/notify_via_smtp
|
311 |
b19369b7
|
Scott Ullrich
|
* NAME
|
312 |
|
|
* notify_via_smtp
|
313 |
|
|
* INPUTS
|
314 |
|
|
* notification string to send as an email
|
315 |
|
|
* RESULT
|
316 |
|
|
* returns true if message was sent
|
317 |
|
|
******/
|
318 |
48b86f62
|
jim-p
|
function notify_via_smtp($message, $force = false) {
|
319 |
8273ea35
|
Scott Ullrich
|
global $config, $g;
|
320 |
b37a2e8c
|
Phil Davis
|
if (platform_booting()) {
|
321 |
8273ea35
|
Scott Ullrich
|
return;
|
322 |
b37a2e8c
|
Phil Davis
|
}
|
323 |
b19369b7
|
Scott Ullrich
|
|
324 |
b37a2e8c
|
Phil Davis
|
if (isset($config['notifications']['smtp']['disable']) && !$force) {
|
325 |
48b86f62
|
jim-p
|
return;
|
326 |
b37a2e8c
|
Phil Davis
|
}
|
327 |
48b86f62
|
jim-p
|
|
328 |
acc9c73e
|
Renato Botelho
|
/* Do NOT send the same message twice, except if $force is true */
|
329 |
|
|
if (!$force && file_exists("/var/db/notices_lastmsg.txt")) {
|
330 |
2c7ac8dc
|
Scott Ullrich
|
$lastmsg = trim(file_get_contents("/var/db/notices_lastmsg.txt"));
|
331 |
b37a2e8c
|
Phil Davis
|
if ($lastmsg == $message) {
|
332 |
2c7ac8dc
|
Scott Ullrich
|
return;
|
333 |
b37a2e8c
|
Phil Davis
|
}
|
334 |
2c7ac8dc
|
Scott Ullrich
|
}
|
335 |
743c30df
|
Scott Ullrich
|
|
336 |
7c845149
|
jim-p
|
/* Store last message sent to avoid spamming */
|
337 |
dc5fdeea
|
PiBa-NL
|
@file_put_contents("/var/db/notices_lastmsg.txt", $message);
|
338 |
|
|
if (!$force) {
|
339 |
|
|
notify_via_queue_add($message, 'mail');
|
340 |
|
|
$ret = true;
|
341 |
|
|
} else {
|
342 |
|
|
$ret = send_smtp_message($message, "{$config['system']['hostname']}.{$config['system']['domain']} - Notification", $force);
|
343 |
|
|
}
|
344 |
7c845149
|
jim-p
|
|
345 |
dc5fdeea
|
PiBa-NL
|
return $ret;
|
346 |
7c845149
|
jim-p
|
}
|
347 |
|
|
|
348 |
02376f6f
|
Phil Davis
|
function send_smtp_message($message, $subject = "(no subject)", $force = false) {
|
349 |
7c845149
|
jim-p
|
global $config, $g;
|
350 |
d4c5ada9
|
Renato Botelho
|
require_once("Mail.php");
|
351 |
4bbb3155
|
Scott Ullrich
|
|
352 |
b37a2e8c
|
Phil Davis
|
if (isset($config['notifications']['smtp']['disable']) && !$force) {
|
353 |
02376f6f
|
Phil Davis
|
return;
|
354 |
b37a2e8c
|
Phil Davis
|
}
|
355 |
02376f6f
|
Phil Davis
|
|
356 |
b37a2e8c
|
Phil Davis
|
if (!$config['notifications']['smtp']['ipaddress']) {
|
357 |
7c845149
|
jim-p
|
return;
|
358 |
b37a2e8c
|
Phil Davis
|
}
|
359 |
7c845149
|
jim-p
|
|
360 |
b37a2e8c
|
Phil Davis
|
if (!$config['notifications']['smtp']['notifyemailaddress']) {
|
361 |
7c845149
|
jim-p
|
return;
|
362 |
b37a2e8c
|
Phil Davis
|
}
|
363 |
7c845149
|
jim-p
|
|
364 |
b19369b7
|
Scott Ullrich
|
$to = $config['notifications']['smtp']['notifyemailaddress'];
|
365 |
|
|
|
366 |
d4c5ada9
|
Renato Botelho
|
if (empty($config['notifications']['smtp']['username']) ||
|
367 |
|
|
empty($config['notifications']['smtp']['password'])) {
|
368 |
|
|
$auth = false;
|
369 |
|
|
$username = '';
|
370 |
|
|
$password = '';
|
371 |
|
|
} else {
|
372 |
|
|
$auth = isset($config['notifications']['smtp']['authentication_mechanism'])
|
373 |
|
|
? $config['notifications']['smtp']['authentication_mechanism']
|
374 |
|
|
: 'PLAIN';
|
375 |
|
|
$username = $config['notifications']['smtp']['username'];
|
376 |
|
|
$password = $config['notifications']['smtp']['password'];
|
377 |
|
|
}
|
378 |
|
|
|
379 |
|
|
$params = array(
|
380 |
|
|
'host' => (isset($config['notifications']['smtp']['ssl'])
|
381 |
|
|
? 'ssl://'
|
382 |
|
|
: '')
|
383 |
|
|
. $config['notifications']['smtp']['ipaddress'],
|
384 |
|
|
'port' => empty($config['notifications']['smtp']['port'])
|
385 |
|
|
? 25
|
386 |
|
|
: $config['notifications']['smtp']['port'],
|
387 |
|
|
'auth' => $auth,
|
388 |
|
|
'username' => $username,
|
389 |
|
|
'password' => $password,
|
390 |
|
|
'localhost' => $config['system']['hostname'] . "." .
|
391 |
|
|
$config['system']['domain'],
|
392 |
c8c46e5a
|
Renato Botelho
|
'timeout' => !empty($config['notifications']['smtp']['timeout'])
|
393 |
|
|
? $config['notifications']['smtp']['timeout']
|
394 |
|
|
: 20,
|
395 |
d4c5ada9
|
Renato Botelho
|
'debug' => false,
|
396 |
|
|
'persist' => false
|
397 |
|
|
);
|
398 |
|
|
|
399 |
0b76ff3b
|
jim-p
|
if ($config['notifications']['smtp']['sslvalidate'] == "disabled") {
|
400 |
|
|
$params['socket_options'] = array('ssl' => array('verify_peer_name' => false));
|
401 |
|
|
}
|
402 |
|
|
|
403 |
b37a2e8c
|
Phil Davis
|
if ($config['notifications']['smtp']['fromaddress']) {
|
404 |
72306d5a
|
Scott Ullrich
|
$from = $config['notifications']['smtp']['fromaddress'];
|
405 |
d4c5ada9
|
Renato Botelho
|
} else {
|
406 |
|
|
$from = "pfsense@{$config['system']['hostname']}.{$config['system']['domain']}";
|
407 |
72306d5a
|
Scott Ullrich
|
}
|
408 |
b19369b7
|
Scott Ullrich
|
|
409 |
|
|
$headers = array(
|
410 |
d4c5ada9
|
Renato Botelho
|
"From" => $from,
|
411 |
|
|
"To" => $to,
|
412 |
|
|
"Subject" => $subject,
|
413 |
|
|
"Date" => date("r")
|
414 |
b19369b7
|
Scott Ullrich
|
);
|
415 |
|
|
|
416 |
d4c5ada9
|
Renato Botelho
|
$smtp =& Mail::factory('smtp', $params);
|
417 |
|
|
$mail = $smtp->send($to, $headers, $message);
|
418 |
|
|
|
419 |
|
|
if (PEAR::isError($mail)) {
|
420 |
|
|
$err_msg = sprintf(gettext(
|
421 |
|
|
'Could not send the message to %1$s -- Error: %2$s'),
|
422 |
|
|
$to, $mail->getMessage());
|
423 |
|
|
log_error($err_msg);
|
424 |
|
|
return($err_msg);
|
425 |
f9fb2569
|
Scott Ullrich
|
}
|
426 |
d4c5ada9
|
Renato Botelho
|
|
427 |
|
|
log_error(sprintf(gettext("Message sent to %s OK"), $to));
|
428 |
|
|
return;
|
429 |
b19369b7
|
Scott Ullrich
|
}
|
430 |
|
|
|
431 |
91cae49d
|
Scott Ullrich
|
/****f* notices/notify_via_growl
|
432 |
b21fc797
|
Scott Ullrich
|
* NAME
|
433 |
|
|
* notify_via_growl
|
434 |
|
|
* INPUTS
|
435 |
|
|
* notification string to send
|
436 |
|
|
* RESULT
|
437 |
|
|
* returns true if message was sent
|
438 |
|
|
******/
|
439 |
48b86f62
|
jim-p
|
function notify_via_growl($message, $force=false) {
|
440 |
e7cf30eb
|
Renato Botelho
|
require_once("Net/Growl/Autoload.php");
|
441 |
|
|
|
442 |
086cf944
|
Phil Davis
|
global $config, $g;
|
443 |
a93020d5
|
Scott Ullrich
|
|
444 |
b37a2e8c
|
Phil Davis
|
if (isset($config['notifications']['growl']['disable']) && !$force) {
|
445 |
48b86f62
|
jim-p
|
return;
|
446 |
b37a2e8c
|
Phil Davis
|
}
|
447 |
48b86f62
|
jim-p
|
|
448 |
e7cf30eb
|
Renato Botelho
|
if (empty($config['notifications']['growl']['ipaddress'])) {
|
449 |
|
|
return;
|
450 |
|
|
}
|
451 |
179377b0
|
robjarsen
|
|
452 |
a93020d5
|
Scott Ullrich
|
/* Do NOT send the same message twice */
|
453 |
b37a2e8c
|
Phil Davis
|
if (file_exists("/var/db/growlnotices_lastmsg.txt")) {
|
454 |
a93020d5
|
Scott Ullrich
|
$lastmsg = trim(file_get_contents("/var/db/growlnotices_lastmsg.txt"));
|
455 |
b37a2e8c
|
Phil Davis
|
if ($lastmsg == $message) {
|
456 |
a93020d5
|
Scott Ullrich
|
return;
|
457 |
b37a2e8c
|
Phil Davis
|
}
|
458 |
a93020d5
|
Scott Ullrich
|
}
|
459 |
dc5fdeea
|
PiBa-NL
|
/* Store last message sent to avoid spamming */
|
460 |
|
|
@file_put_contents("/var/db/growlnotices_lastmsg.txt", $message);
|
461 |
179377b0
|
robjarsen
|
|
462 |
dc5fdeea
|
PiBa-NL
|
if (!$force) {
|
463 |
|
|
notify_via_queue_add($message, 'growl');
|
464 |
|
|
return;
|
465 |
|
|
}
|
466 |
a93020d5
|
Scott Ullrich
|
|
467 |
e7cf30eb
|
Renato Botelho
|
$ip = $config['notifications']['growl']['ipaddress'];
|
468 |
|
|
|
469 |
|
|
if (!is_ipaddr($ip) && !(dns_check_record($ip, A) || dns_check_record($ip, AAAA))) {
|
470 |
|
|
$err_msg = gettext(
|
471 |
|
|
"Growl IP Address is invalid. Check the setting in System Advanced Notifications.");
|
472 |
|
|
log_error($err_msg);
|
473 |
|
|
return($err_msg);
|
474 |
|
|
}
|
475 |
|
|
|
476 |
9a132756
|
Scott Ullrich
|
$hostname = $config['system']['hostname'] . "." . $config['system']['domain'];
|
477 |
e7cf30eb
|
Renato Botelho
|
$password = $config['notifications']['growl']['password'];
|
478 |
|
|
$name = $config['notifications']['growl']['name'];
|
479 |
|
|
$notification = $config['notifications']['growl']['notification_name'];
|
480 |
|
|
|
481 |
|
|
$options = array(
|
482 |
|
|
'host' => $ip,
|
483 |
|
|
'protocol' => 'gntp',
|
484 |
|
|
'timeout' => 20
|
485 |
|
|
);
|
486 |
|
|
|
487 |
|
|
try {
|
488 |
|
|
$growl = Net_Growl::singleton($name, null, $password, $options);
|
489 |
|
|
//$name = 'GROWL_NOTIFY_STATUS';
|
490 |
1579e70f
|
Phil Davis
|
$title = sprintf(gettext('%1$s (%2$s) - Notification'), $g['product_name'], $hostname);
|
491 |
e7cf30eb
|
Renato Botelho
|
$growl->publish($name, $title, $message);
|
492 |
|
|
} catch (Net_Growl_Exception $e) {
|
493 |
|
|
$err_msg = sprintf(gettext(
|
494 |
|
|
'Could not send Growl notification to %1$s -- Error: %2$s'),
|
495 |
|
|
$ip, $e->getMessage());
|
496 |
|
|
log_error($err_msg);
|
497 |
|
|
return($err_msg);
|
498 |
b21fc797
|
Scott Ullrich
|
}
|
499 |
a93020d5
|
Scott Ullrich
|
|
500 |
e7cf30eb
|
Renato Botelho
|
return;
|
501 |
b21fc797
|
Scott Ullrich
|
}
|
502 |
|
|
|
503 |
91cae49d
|
Scott Ullrich
|
/****f* notices/register_via_growl
|
504 |
b21fc797
|
Scott Ullrich
|
* NAME
|
505 |
|
|
* register_via_growl
|
506 |
|
|
* INPUTS
|
507 |
|
|
* none
|
508 |
|
|
* RESULT
|
509 |
|
|
* none
|
510 |
|
|
******/
|
511 |
|
|
function register_via_growl() {
|
512 |
e7cf30eb
|
Renato Botelho
|
require_once("Net/Growl/Autoload.php");
|
513 |
|
|
|
514 |
b21fc797
|
Scott Ullrich
|
global $config;
|
515 |
e7cf30eb
|
Renato Botelho
|
|
516 |
|
|
if (empty($config['notifications']['growl']['ipaddress'])) {
|
517 |
|
|
return;
|
518 |
b21fc797
|
Scott Ullrich
|
}
|
519 |
e7cf30eb
|
Renato Botelho
|
|
520 |
|
|
$ip = $config['notifications']['growl']['ipaddress'];
|
521 |
|
|
|
522 |
|
|
if (!is_ipaddr($ip) && !(dns_check_record($ip, A) || dns_check_record($ip, AAAA))) {
|
523 |
|
|
$err_msg = gettext(
|
524 |
|
|
"Growl IP Address is invalid. Check the setting in System Advanced Notifications.");
|
525 |
|
|
log_error($err_msg);
|
526 |
|
|
return($err_msg);
|
527 |
|
|
}
|
528 |
|
|
|
529 |
|
|
$name = $config['notifications']['growl']['name'];
|
530 |
|
|
$password = $config['notifications']['growl']['password'];
|
531 |
|
|
|
532 |
|
|
$app = new Net_Growl_Application(
|
533 |
|
|
$name,
|
534 |
|
|
null,
|
535 |
|
|
$password
|
536 |
|
|
);
|
537 |
|
|
|
538 |
|
|
$options = array(
|
539 |
|
|
'host' => $ip,
|
540 |
|
|
'protocol' => 'gntp',
|
541 |
f97cd756
|
NewEraCracker
|
'timeout' => 20
|
542 |
e7cf30eb
|
Renato Botelho
|
);
|
543 |
|
|
|
544 |
|
|
try {
|
545 |
|
|
$growl = Net_Growl::singleton($app, null, null, $options);
|
546 |
|
|
$growl->register();
|
547 |
|
|
} catch (Net_Growl_Exception $e) {
|
548 |
|
|
$err_msg = sprintf(gettext(
|
549 |
|
|
'Could not send register Growl on %1$s -- Error: %2$s'),
|
550 |
|
|
$ip, $e->getMessage());
|
551 |
|
|
log_error($err_msg);
|
552 |
|
|
return($err_msg);
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
return;
|
556 |
b21fc797
|
Scott Ullrich
|
}
|
557 |
|
|
|
558 |
53842a6c
|
jim-p
|
/* Notify via remote methods only - not via GUI. */
|
559 |
|
|
function notify_all_remote($msg) {
|
560 |
|
|
notify_via_smtp($msg);
|
561 |
|
|
notify_via_growl($msg);
|
562 |
|
|
}
|
563 |
|
|
|
564 |
6955830f
|
Ermal Lu?i
|
?>
|