Project

General

Profile

Download (4.43 KB) Statistics
| Branch: | Tag: | Revision:
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;
63
}
64

    
65
function get_notices($category = "all") {
66
	global $notice_path;
67
	if(file_exists($notice_path)) {
68
		$queue = unserialize(file_get_contents($notice_path));
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
	if(!$notices = get_notices()) return;
87
	if($id == "all") {
88
		unlink_if_exists($notice_path);
89
		return;
90
	}
91
	foreach(array_keys($notices) as $time) {
92
		if($id == $time) {
93
			unset($notices[$id]);
94
			break;
95
		}
96
	}
97
	foreach($notices as $key => $notice) {
98
		$ids[$key] = $notice['id'];
99
	}
100
	foreach($ids as $time => $tocheck) {
101
		if($id == $tocheck) {
102
			unset($notices[$time]);
103
			break;
104
		}
105
	}
106
	$queueout = fopen($notice_path, "w");
107
        fwrite($queueout, serialize($queue));
108
        fclose($queueout);
109
        return;
110
}
111

    
112
function dump_xml_notices() {
113
	require_once("xmlparse.inc");
114
	global $notice_path, $listtags;
115
	$listtags[] = 'notice';
116
	if(!$notices = get_notices()) return;
117
	foreach($notices as $time => $notice) {
118
		$notice['time'] = $time;
119
		$toput['notice'][] = $notice;
120
	}
121
	$xml = dump_xml_config($toput, 'notices');
122
	return $xml;
123
}
124

    
125
function print_notices($notices, $category = "all") {
126
	foreach($notices as $notice) {
127
		if($category != "all") {
128
			if(in_array($notice['category'], $category)) $categories[] = $notice['category'];
129
		} else {
130
			$categories[] = $notice['category'];
131
		}
132
	}
133
	$categories = array_unique($categories);
134
	sort($categories);
135
	foreach($categories as $category) {
136
		$toreturn .= "<ul><li>{$category}<ul>";
137
		foreach($notices as $notice) {
138
			if(strtolower($notice['category']) == strtolower($category)) {
139
				if($notice['id'] != "") {
140
					if($notice['url'] != "") {
141
						$toreturn .= "<li><a href={$notice['url']}>{$notice['id']}</a> - {$notice['notice']}</li>";
142
					} else {
143
						$toreturn .= "<li>{$notice['id']} - {$notice['notice']}</li>";
144
					}
145
				}
146
			}
147
		}
148
		$toreturn .= "</ul></li></ul>";
149
	}
150
	return $toreturn;
151
}
152

    
153
?>
(9-9/21)