Project

General

Profile

Download (2.61 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * itemid.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2009-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2009 Janne Enberg <janne.enberg@lietu.net>
8
 * All rights reserved.
9
 *
10
 * 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
 *
14
 * http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 * 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
 */
22

    
23
/****f* itemid/delete_id
24
 * NAME
25
 *   delete_id - delete an item with ['id'] = $id from $array
26
 * INPUTS
27
 *   $id       - int: The ID to delete
28
 *   $array    - array to delete the item from
29
 * RESULT
30
 *   boolean   - true if item was found and deleted
31
 ******/
32
function delete_id($id, &$array) {
33
	global $config;
34

    
35
	// Index to delete
36
	$delete_index = NULL;
37

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

    
42
	// Search for the item in the array
43
	foreach ($array as $key => $item) {
44
		// If this item is the one we want to delete
45
		if (isset($item['associated-rule-id']) && $item['associated-rule-id'] == $id) {
46
			$delete_index = $key;
47
			$if = $item['interface'];
48
			break;
49
		}
50
	}
51

    
52
	// If we found the item, unset it
53
	if ($delete_index !== NULL) {
54
		unset($array[$delete_index]);
55

    
56
		// Update the separators
57
		$a_separators = &$config['filter']['separator'][strtolower($if)];
58
		$ridx = ifridx($if, $delete_index);	// get rule index within interface
59
		$mvnrows = -1;
60
		move_separators($a_separators, $ridx, $mvnrows);
61

    
62
		return true;
63
	} else {
64
		return false;
65
	}
66

    
67
}
68

    
69
/****f* itemid/get_id
70
 * NAME
71
 *   get_id - Get an item id with ['associated-rule-id'] = $id from $array
72
 * INPUTS
73
 *   $id       - string: The ID to get
74
 *   $array    - array to get the item from
75
 * RESULT
76
 *   mixed   - The id, NULL if not found
77
 ******/
78
function get_id($id, &$array) {
79
	// Use $foo = &get_id('id', array('id'=>'value'));
80

    
81
	if (!is_array($array)) {
82
		return false;
83
	}
84

    
85
	// Search for the item in the array
86
	foreach ($array as $key => $item) {
87
		// If this item is the one we want to delete
88
		if (isset($item['associated-rule-id']) && $item['associated-rule-id'] == $id) {
89
			return $key;
90
		}
91
	}
92

    
93
	return false;
94
}
95

    
96
/****f* itemid/get_unique_id
97
 * NAME
98
 *   get_unique_id - get a unique identifier
99
 * RESULT
100
 *   string     - unique id
101
 ******/
102
function get_unique_id() {
103

    
104
	return uniqid("nat_", true);
105
}
106

    
107
?>
(22-22/51)