1
|
<?php
|
2
|
/****h* pfSense/notices
|
3
|
* NAME
|
4
|
* notices.inc - pfSense notice utilities
|
5
|
* DESCRIPTION
|
6
|
* This include contains the pfSense notice facilities.
|
7
|
* HISTORY
|
8
|
* $Id$
|
9
|
******
|
10
|
*
|
11
|
* Copyright (C) 2005 Colin Smith (ethethlay@gmail.com)
|
12
|
* All rights reserved.
|
13
|
* Redistribution and use in source and binary forms, with or without
|
14
|
* modification, are permitted provided that the following conditions are met:
|
15
|
*
|
16
|
* 1. Redistributions of source code must retain the above copyright notice,
|
17
|
* this list of conditions and the following disclaimer.
|
18
|
*
|
19
|
* 2. Redistributions in binary form must reproduce the above copyright
|
20
|
* notice, this list of conditions and the following disclaimer in the
|
21
|
* documentation and/or other materials provided with the distribution.
|
22
|
*
|
23
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
* RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
* POSSIBILITY OF SUCH DAMAGE.
|
33
|
*
|
34
|
*/
|
35
|
|
36
|
require_once("globals.inc");
|
37
|
|
38
|
$notice_path = $g['tmp_path'] . '/notices';
|
39
|
|
40
|
/*
|
41
|
* $category - Category that this notice should be displayed under. This can be arbitrary,
|
42
|
* but a page must be set to receive this messages for it to be displayed.
|
43
|
*
|
44
|
* $priority - A notice's priority. Higher numbers indicate greater severity.
|
45
|
* 0 = informational, 1 = warning, 2 = error, etc. This may also be arbitrary,
|
46
|
*/
|
47
|
function file_notice($id, $notice, $category = "General", $url = "", $priority = 1) {
|
48
|
global $notice_path;
|
49
|
if(!$queue = get_notices()) $queue = array();
|
50
|
$queuekey = time();
|
51
|
$toqueue = array(
|
52
|
'id' => $id,
|
53
|
'notice' => $notice,
|
54
|
'url' => $url,
|
55
|
'category' => $category,
|
56
|
'priority' => $priority,
|
57
|
);
|
58
|
$queue[$queuekey] = $toqueue;
|
59
|
$queueout = fopen($notice_path, "w");
|
60
|
fwrite($queueout, serialize($queue));
|
61
|
fclose($queueout);
|
62
|
return $queuekey;
|
63
|
}
|
64
|
|
65
|
function get_notices($category = "all") {
|
66
|
if(file_exists('/tmp/notices')) {
|
67
|
$queue = unserialize(file_get_contents('/tmp/notices'));
|
68
|
if(!$queue) return false;
|
69
|
if($category != 'all') {
|
70
|
foreach($queue as $time => $notice) {
|
71
|
if(strtolower($notice['category']) == strtolower($category))
|
72
|
$toreturn[$time] = $notice;
|
73
|
}
|
74
|
return $toreturn;
|
75
|
} else {
|
76
|
return $queue;
|
77
|
}
|
78
|
} else {
|
79
|
return false;
|
80
|
}
|
81
|
}
|
82
|
|
83
|
function close_notice($id) {
|
84
|
global $notice_path;
|
85
|
require_once("util.inc");
|
86
|
$ids = array();
|
87
|
if(!$notices = get_notices()) return;
|
88
|
if($id == "all") {
|
89
|
unlink_if_exists($notice_path);
|
90
|
return;
|
91
|
}
|
92
|
foreach(array_keys($notices) as $time) {
|
93
|
if($id == $time) {
|
94
|
unset($notices[$id]);
|
95
|
break;
|
96
|
}
|
97
|
}
|
98
|
foreach($notices as $key => $notice) {
|
99
|
$ids[$key] = $notice['id'];
|
100
|
}
|
101
|
foreach($ids as $time => $tocheck) {
|
102
|
if($id == $tocheck) {
|
103
|
unset($notices[$time]);
|
104
|
break;
|
105
|
}
|
106
|
}
|
107
|
if(count($notices) != 0) {
|
108
|
$queueout = fopen($notice_path, "w");
|
109
|
fwrite($queueout, serialize($notices));
|
110
|
fclose($queueout);
|
111
|
} else {
|
112
|
unlink_if_exists($notice_path);
|
113
|
}
|
114
|
return;
|
115
|
}
|
116
|
|
117
|
function dump_xml_notices() {
|
118
|
require_once("xmlparse.inc");
|
119
|
global $notice_path, $listtags;
|
120
|
$listtags[] = 'notice';
|
121
|
if(!$notices = get_notices()) return;
|
122
|
foreach($notices as $time => $notice) {
|
123
|
$notice['time'] = $time;
|
124
|
$toput['notice'][] = $notice;
|
125
|
}
|
126
|
$xml = dump_xml_config($toput, 'notices');
|
127
|
return $xml;
|
128
|
}
|
129
|
|
130
|
function print_notices($notices, $category = "all") {
|
131
|
foreach($notices as $notice) {
|
132
|
if($category != "all") {
|
133
|
if(in_array($notice['category'], $category)) $categories[] = $notice['category'];
|
134
|
} else {
|
135
|
$categories[] = $notice['category'];
|
136
|
}
|
137
|
}
|
138
|
$categories = array_unique($categories);
|
139
|
sort($categories);
|
140
|
foreach($categories as $category) {
|
141
|
$toreturn .= "<ul><li>{$category}<ul>";
|
142
|
foreach($notices as $notice) {
|
143
|
if(strtolower($notice['category']) == strtolower($category)) {
|
144
|
if($notice['id'] != "") {
|
145
|
if($notice['url'] != "") {
|
146
|
$toreturn .= "<li><a href={$notice['url']}>{$notice['id']}</a> - {$notice['notice']}</li>";
|
147
|
} else {
|
148
|
$toreturn .= "<li>{$notice['id']} - {$notice['notice']}</li>";
|
149
|
}
|
150
|
}
|
151
|
}
|
152
|
}
|
153
|
$toreturn .= "</ul></li></ul>";
|
154
|
}
|
155
|
return $toreturn;
|
156
|
}
|
157
|
|
158
|
function print_notice_box($category = "all") {
|
159
|
$notices = get_notices();
|
160
|
if(!$notices) return;
|
161
|
print_info_box_np(print_notices($notices, $category));
|
162
|
return;
|
163
|
}
|
164
|
|
165
|
|
166
|
function are_notices_pending($category = "all") {
|
167
|
global $notice_path;
|
168
|
if(file_exists($notice_path)) {
|
169
|
return true;
|
170
|
}
|
171
|
return false;
|
172
|
}
|
173
|
|
174
|
?>
|