Project

General

Profile

Download (3.29 KB) Statistics
| Branch: | Tag: | Revision:
1 a4698195 unknown
<?php
2 b9e28d57 unknown
/*
3 ac24dc24 Renato Botelho
 * itemid.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2009-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2009 Janne Enberg <janne.enberg@lietu.net>
10 ac24dc24 Renato Botelho
 * All rights reserved.
11
 *
12 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15 ac24dc24 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
17 ac24dc24 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23 ac24dc24 Renato Botelho
 */
24 b9e28d57 unknown
25
/****f* itemid/delete_id
26
 * NAME
27 632a238f Phil Davis
 *   delete_id - delete an item with ['associated-rule-id'] = $id from $array
28 b9e28d57 unknown
 * INPUTS
29
 *   $id       - int: The ID to delete
30
 *   $array    - array to delete the item from
31
 * RESULT
32
 *   boolean   - true if item was found and deleted
33
 ******/
34 b37a2e8c Phil Davis
function delete_id($id, &$array) {
35 7475d7b3 NOYB
	global $config;
36
37 b37a2e8c Phil Davis
	if (!is_array($array)) {
38 9b16b834 Ermal Lu?i
		return false;
39 b37a2e8c Phil Davis
	}
40 9b16b834 Ermal Lu?i
41 a4698195 unknown
	// Search for the item in the array
42 75bb5037 Renato Botelho
	$delete_index = get_id($id, $array);
43 a4698195 unknown
44
	// If we found the item, unset it
45 75bb5037 Renato Botelho
	if ($delete_index === false) {
46 a4698195 unknown
		return false;
47
	}
48
49 75bb5037 Renato Botelho
	$if = $array[$delete_index]['interface'];
50
	unset($array[$delete_index]);
51
52
	// Update the separators
53 c6c398c6 jim-p
	init_config_arr(array('filter', 'separator', strtolower($if)));
54 75bb5037 Renato Botelho
	$a_separators = &$config['filter']['separator'][strtolower($if)];
55
	// get rule index within interface
56
	$ridx = ifridx($if, $delete_index);
57
	$mvnrows = -1;
58
	move_separators($a_separators, $ridx, $mvnrows);
59
60
	return true;
61 a4698195 unknown
}
62
63 8aa2dd26 Renato Botelho
/****f* itemid/toggle_id
64
 * NAME
65 632a238f Phil Davis
 *   toggle_id - enable/disable item with ['associated-rule-id'] = $id from $array
66 8aa2dd26 Renato Botelho
 * INPUTS
67
 *   $id       - int: The ID to delete
68
 *   $array    - array to delete the item from
69
 *   $status   - true to enable item and false to disable
70
 * RESULT
71
 *   boolean   - true if item was found and set
72
 ******/
73
function toggle_id($id, &$array, $status) {
74
	global $config;
75
76
	if (!is_array($array)) {
77
		return false;
78
	}
79
80
	// Search for the item in the array
81
	$toggle_index = get_id($id, $array);
82
83
	// If we found the item, unset it
84
	if ($toggle_index === false) {
85
		return false;
86
	}
87
88
	if ($status) {
89
		unset($array[$toggle_index]['disabled']);
90
	} else {
91
		$array[$toggle_index]['disabled'] = true;
92
	}
93
94
	return true;
95
}
96
97 473d0ff0 pierrepomes
/****f* itemid/get_id
98
 * NAME
99 9b16b834 Ermal Lu?i
 *   get_id - Get an item id with ['associated-rule-id'] = $id from $array
100 473d0ff0 pierrepomes
 * INPUTS
101 21408bb4 Renato Botelho
 *   $id     - string: The ID to get
102
 *   $array  - array to get the item from
103 473d0ff0 pierrepomes
 * RESULT
104 21408bb4 Renato Botelho
 *   mixed   - The id, false if not found
105 473d0ff0 pierrepomes
 ******/
106 9f61bcc9 Renato Botelho
function get_id($id, $array) {
107 21408bb4 Renato Botelho
	// Use $foo = get_id('id', array('id'=>'value'));
108 9b16b834 Ermal Lu?i
109 b37a2e8c Phil Davis
	if (!is_array($array)) {
110 9b16b834 Ermal Lu?i
		return false;
111 b37a2e8c Phil Davis
	}
112 473d0ff0 pierrepomes
113
	// Search for the item in the array
114 b37a2e8c Phil Davis
	foreach ($array as $key => $item) {
115 473d0ff0 pierrepomes
		// If this item is the one we want to delete
116 75bb5037 Renato Botelho
		if (isset($item['associated-rule-id']) &&
117
		    $item['associated-rule-id'] == $id) {
118 9b16b834 Ermal Lu?i
			return $key;
119 b37a2e8c Phil Davis
		}
120 473d0ff0 pierrepomes
	}
121
122 9b16b834 Ermal Lu?i
	return false;
123 473d0ff0 pierrepomes
}
124
125 9b16b834 Ermal Lu?i
/****f* itemid/get_unique_id
126 b9e28d57 unknown
 * NAME
127 9b16b834 Ermal Lu?i
 *   get_unique_id - get a unique identifier
128 b9e28d57 unknown
 * RESULT
129 9b16b834 Ermal Lu?i
 *   string     - unique id
130 b9e28d57 unknown
 ******/
131 b37a2e8c Phil Davis
function get_unique_id() {
132 9b16b834 Ermal Lu?i
133
	return uniqid("nat_", true);
134 a4698195 unknown
}
135
136 6aa3723a Renato Botelho
?>