1 |
a4698195
|
unknown
|
<?php
|
2 |
523855b0
|
Scott Ullrich
|
|
3 |
|
|
/*
|
4 |
b6aed0e1
|
Scott Ullrich
|
pfSense_MODULE: utils
|
5 |
523855b0
|
Scott Ullrich
|
*/
|
6 |
|
|
|
7 |
b9e28d57
|
unknown
|
/*
|
8 |
|
|
Copyright (C) 2009 Janne Enberg <janne.enberg@lietu.net>
|
9 |
|
|
All rights reserved.
|
10 |
a4698195
|
unknown
|
|
11 |
b9e28d57
|
unknown
|
Redistribution and use in source and binary forms, with or without
|
12 |
|
|
modification, are permitted provided that the following conditions are met:
|
13 |
|
|
|
14 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
this list of conditions and the following disclaimer.
|
16 |
|
|
|
17 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
notice, this list of conditions and the following disclaimer in the
|
19 |
|
|
documentation and/or other materials provided with the distribution.
|
20 |
|
|
|
21 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
|
32 |
|
|
DISABLE_PHP_LINT_CHECKING
|
33 |
a4698195
|
unknown
|
*/
|
34 |
b9e28d57
|
unknown
|
|
35 |
|
|
/****f* itemid/delete_id
|
36 |
|
|
* NAME
|
37 |
|
|
* delete_id - delete an item with ['id'] = $id from $array
|
38 |
|
|
* INPUTS
|
39 |
|
|
* $id - int: The ID to delete
|
40 |
|
|
* $array - array to delete the item from
|
41 |
|
|
* RESULT
|
42 |
|
|
* boolean - true if item was found and deleted
|
43 |
|
|
******/
|
44 |
a4698195
|
unknown
|
function delete_id($id, &$array){
|
45 |
|
|
// Index to delete
|
46 |
|
|
$delete_index = NULL;
|
47 |
|
|
|
48 |
9b16b834
|
Ermal Lu?i
|
if (!is_array($array))
|
49 |
|
|
return false;
|
50 |
|
|
|
51 |
a4698195
|
unknown
|
// Search for the item in the array
|
52 |
|
|
foreach ($array as $key => $item){
|
53 |
|
|
// If this item is the one we want to delete
|
54 |
9b16b834
|
Ermal Lu?i
|
if(isset($item['associated-rule-id']) && $item['associated-rule-id']==$id ){
|
55 |
a4698195
|
unknown
|
$delete_index = $key;
|
56 |
|
|
break;
|
57 |
|
|
}
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
// If we found the item, unset it
|
61 |
|
|
if( $delete_index!==NULL ){
|
62 |
|
|
unset($array[$delete_index]);
|
63 |
|
|
return true;
|
64 |
|
|
} else {
|
65 |
|
|
return false;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
}
|
69 |
|
|
|
70 |
473d0ff0
|
pierrepomes
|
/****f* itemid/get_id
|
71 |
|
|
* NAME
|
72 |
9b16b834
|
Ermal Lu?i
|
* get_id - Get an item id with ['associated-rule-id'] = $id from $array
|
73 |
473d0ff0
|
pierrepomes
|
* INPUTS
|
74 |
9b16b834
|
Ermal Lu?i
|
* $id - string: The ID to get
|
75 |
473d0ff0
|
pierrepomes
|
* $array - array to get the item from
|
76 |
|
|
* RESULT
|
77 |
9b16b834
|
Ermal Lu?i
|
* mixed - The id, NULL if not found
|
78 |
473d0ff0
|
pierrepomes
|
******/
|
79 |
9b16b834
|
Ermal Lu?i
|
function get_id($id, &$array) {
|
80 |
473d0ff0
|
pierrepomes
|
// Use $foo = &get_id('id', array('id'=>'value'));
|
81 |
9b16b834
|
Ermal Lu?i
|
|
82 |
|
|
if (!is_array($array))
|
83 |
|
|
return false;
|
84 |
473d0ff0
|
pierrepomes
|
|
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 |
9b16b834
|
Ermal Lu?i
|
if (isset($item['associated-rule-id']) && $item['associated-rule-id']==$id)
|
89 |
|
|
return $key;
|
90 |
473d0ff0
|
pierrepomes
|
}
|
91 |
|
|
|
92 |
9b16b834
|
Ermal Lu?i
|
return false;
|
93 |
473d0ff0
|
pierrepomes
|
}
|
94 |
|
|
|
95 |
9b16b834
|
Ermal Lu?i
|
/****f* itemid/get_unique_id
|
96 |
b9e28d57
|
unknown
|
* NAME
|
97 |
9b16b834
|
Ermal Lu?i
|
* get_unique_id - get a unique identifier
|
98 |
b9e28d57
|
unknown
|
* RESULT
|
99 |
9b16b834
|
Ermal Lu?i
|
* string - unique id
|
100 |
b9e28d57
|
unknown
|
******/
|
101 |
9b16b834
|
Ermal Lu?i
|
function get_unique_id(){
|
102 |
|
|
|
103 |
|
|
return uniqid("nat_", true);
|
104 |
a4698195
|
unknown
|
}
|
105 |
|
|
|
106 |
9734b054
|
Scott Ullrich
|
?>
|