Project

General

Profile

Download (3.29 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * itemid.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2009-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2009 Janne Enberg <janne.enberg@lietu.net>
10
 * All rights reserved.
11
 *
12
 * 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
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * 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
 */
24

    
25
/****f* itemid/delete_id
26
 * NAME
27
 *   delete_id - delete an item with ['associated-rule-id'] = $id from $array
28
 * 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
function delete_id($id, &$array) {
35
	global $config;
36

    
37
	if (!is_array($array)) {
38
		return false;
39
	}
40

    
41
	// Search for the item in the array
42
	$delete_index = get_id($id, $array);
43

    
44
	// If we found the item, unset it
45
	if ($delete_index === false) {
46
		return false;
47
	}
48

    
49
	$if = $array[$delete_index]['interface'];
50
	unset($array[$delete_index]);
51

    
52
	// Update the separators
53
	init_config_arr(array('filter', 'separator', strtolower($if)));
54
	$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
}
62

    
63
/****f* itemid/toggle_id
64
 * NAME
65
 *   toggle_id - enable/disable item with ['associated-rule-id'] = $id from $array
66
 * 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
/****f* itemid/get_id
98
 * NAME
99
 *   get_id - Get an item id with ['associated-rule-id'] = $id from $array
100
 * INPUTS
101
 *   $id     - string: The ID to get
102
 *   $array  - array to get the item from
103
 * RESULT
104
 *   mixed   - The id, false if not found
105
 ******/
106
function get_id($id, $array) {
107
	// Use $foo = get_id('id', array('id'=>'value'));
108

    
109
	if (!is_array($array)) {
110
		return false;
111
	}
112

    
113
	// Search for the item in the array
114
	foreach ($array as $key => $item) {
115
		// If this item is the one we want to delete
116
		if (isset($item['associated-rule-id']) &&
117
		    $item['associated-rule-id'] == $id) {
118
			return $key;
119
		}
120
	}
121

    
122
	return false;
123
}
124

    
125
/****f* itemid/get_unique_id
126
 * NAME
127
 *   get_unique_id - get a unique identifier
128
 * RESULT
129
 *   string     - unique id
130
 ******/
131
function get_unique_id() {
132

    
133
	return uniqid("nat_", true);
134
}
135

    
136
?>
(27-27/60)