1 |
a4698195
|
unknown
|
<?php
|
2 |
b9e28d57
|
unknown
|
/*
|
3 |
ac24dc24
|
Renato Botelho
|
* itemid.inc
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
81299b5c
|
Renato Botelho
|
* Copyright (c) 2009-2016 Rubicon Communications, LLC (Netgate)
|
7 |
c5d81585
|
Renato Botelho
|
* Copyright (c) 2009 Janne Enberg <janne.enberg@lietu.net>
|
8 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
9 |
|
|
*
|
10 |
b12ea3fb
|
Renato Botelho
|
* 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 |
ac24dc24
|
Renato Botelho
|
*
|
14 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15 |
ac24dc24
|
Renato Botelho
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* 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 |
ac24dc24
|
Renato Botelho
|
*/
|
22 |
b9e28d57
|
unknown
|
|
23 |
|
|
/****f* itemid/delete_id
|
24 |
|
|
* NAME
|
25 |
21408bb4
|
Renato Botelho
|
* delete_id - delete an item with ['assiciated-rule-id'] = $id from $array
|
26 |
b9e28d57
|
unknown
|
* 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 |
b37a2e8c
|
Phil Davis
|
function delete_id($id, &$array) {
|
33 |
7475d7b3
|
NOYB
|
global $config;
|
34 |
|
|
|
35 |
b37a2e8c
|
Phil Davis
|
if (!is_array($array)) {
|
36 |
9b16b834
|
Ermal Lu?i
|
return false;
|
37 |
b37a2e8c
|
Phil Davis
|
}
|
38 |
9b16b834
|
Ermal Lu?i
|
|
39 |
a4698195
|
unknown
|
// Search for the item in the array
|
40 |
75bb5037
|
Renato Botelho
|
$delete_index = get_id($id, $array);
|
41 |
a4698195
|
unknown
|
|
42 |
|
|
// If we found the item, unset it
|
43 |
75bb5037
|
Renato Botelho
|
if ($delete_index === false) {
|
44 |
a4698195
|
unknown
|
return false;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
75bb5037
|
Renato Botelho
|
$if = $array[$delete_index]['interface'];
|
48 |
|
|
unset($array[$delete_index]);
|
49 |
|
|
|
50 |
|
|
// Update the separators
|
51 |
|
|
$a_separators = &$config['filter']['separator'][strtolower($if)];
|
52 |
|
|
// get rule index within interface
|
53 |
|
|
$ridx = ifridx($if, $delete_index);
|
54 |
|
|
$mvnrows = -1;
|
55 |
|
|
move_separators($a_separators, $ridx, $mvnrows);
|
56 |
|
|
|
57 |
|
|
return true;
|
58 |
a4698195
|
unknown
|
}
|
59 |
|
|
|
60 |
473d0ff0
|
pierrepomes
|
/****f* itemid/get_id
|
61 |
|
|
* NAME
|
62 |
9b16b834
|
Ermal Lu?i
|
* get_id - Get an item id with ['associated-rule-id'] = $id from $array
|
63 |
473d0ff0
|
pierrepomes
|
* INPUTS
|
64 |
21408bb4
|
Renato Botelho
|
* $id - string: The ID to get
|
65 |
|
|
* $array - array to get the item from
|
66 |
473d0ff0
|
pierrepomes
|
* RESULT
|
67 |
21408bb4
|
Renato Botelho
|
* mixed - The id, false if not found
|
68 |
473d0ff0
|
pierrepomes
|
******/
|
69 |
9f61bcc9
|
Renato Botelho
|
function get_id($id, $array) {
|
70 |
21408bb4
|
Renato Botelho
|
// Use $foo = get_id('id', array('id'=>'value'));
|
71 |
9b16b834
|
Ermal Lu?i
|
|
72 |
b37a2e8c
|
Phil Davis
|
if (!is_array($array)) {
|
73 |
9b16b834
|
Ermal Lu?i
|
return false;
|
74 |
b37a2e8c
|
Phil Davis
|
}
|
75 |
473d0ff0
|
pierrepomes
|
|
76 |
|
|
// Search for the item in the array
|
77 |
b37a2e8c
|
Phil Davis
|
foreach ($array as $key => $item) {
|
78 |
473d0ff0
|
pierrepomes
|
// If this item is the one we want to delete
|
79 |
75bb5037
|
Renato Botelho
|
if (isset($item['associated-rule-id']) &&
|
80 |
|
|
$item['associated-rule-id'] == $id) {
|
81 |
9b16b834
|
Ermal Lu?i
|
return $key;
|
82 |
b37a2e8c
|
Phil Davis
|
}
|
83 |
473d0ff0
|
pierrepomes
|
}
|
84 |
|
|
|
85 |
9b16b834
|
Ermal Lu?i
|
return false;
|
86 |
473d0ff0
|
pierrepomes
|
}
|
87 |
|
|
|
88 |
9b16b834
|
Ermal Lu?i
|
/****f* itemid/get_unique_id
|
89 |
b9e28d57
|
unknown
|
* NAME
|
90 |
9b16b834
|
Ermal Lu?i
|
* get_unique_id - get a unique identifier
|
91 |
b9e28d57
|
unknown
|
* RESULT
|
92 |
9b16b834
|
Ermal Lu?i
|
* string - unique id
|
93 |
b9e28d57
|
unknown
|
******/
|
94 |
b37a2e8c
|
Phil Davis
|
function get_unique_id() {
|
95 |
9b16b834
|
Ermal Lu?i
|
|
96 |
|
|
return uniqid("nat_", true);
|
97 |
a4698195
|
unknown
|
}
|
98 |
|
|
|
99 |
6aa3723a
|
Renato Botelho
|
?>
|