/
find_free_section_subnets.php
164 lines (139 loc) · 5.01 KB
/
find_free_section_subnets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/*
* Print edit subnet
*********************/
/* functions */
require_once( dirname(__FILE__) . '/../../../functions/functions.php' );
# initialize user object
$Database = new Database_PDO;
$User = new User ($Database);
$Admin = new Admin ($Database, false);
$Sections = new Sections ($Database);
$Subnets = new Subnets ($Database);
$Tools = new Tools ($Database);
$Result = new Result ();
# verify that user is logged in
$User->check_user_session();
# verify that user has permissions to add subnet
if($Sections->check_permission ($User->user, $_POST['sectionid']) != 3) { $Result->show("danger", _('You do not have permissions to add new subnet in this section')."!", true, true); }
// fetch all section subnets
$section_subnets = $Subnets->fetch_multiple_objects ("subnets", "sectionId", $_POST['sectionid'], "subnet", true, false, ["id","subnet","mask","isFolder", "masterSubnetId"]);
// result array
$all_subnets = []; // all existing subnets
// loop and filter relevant sections
if ($section_subnets!==false) {
foreach ($section_subnets as $s) {
if ($s->isFolder!="1") {
// only master subnets
if(!$Subnets->has_slaves ($s->id)) {
$all_subnets[] = $s;
}
}
}
}
?>
<script>
$(document).ready(function() {
// select dropdown value
$('.dropdown-subnet_search li a').click(function () {
var maska = $(this).html();
$('input.mask').val(maska);
$('.input-group-btn').removeClass('open');
return false;
});
});
</script>
<!-- header -->
<div class="pHeader"><?php print ucwords(_("Search")); ?> <?php print _('for'); ?> <?php print _('subnet'); ?></div>
<!-- content -->
<div class="pContent">
<form id="search_section_free_subnet">
<table class="editSubnetDetails table table-noborder table-condensed">
<!-- name -->
<tr>
<td class="middle"><?php print _('Subnet mask'); ?></td>
<td>
<div class="input-group">
<input type="text" class="form-control input-sm mask" name="mask" placeholder="<?php print _('Subnet bitmask'); ?>" value='24'>
<div class="input-group-btn">
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Select <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right dropdown-subnet_search">
<?php
for($m=31; $m>7; $m--) {
print "<li><a href='#'>$m</a></li>";
}
?>
</ul>
</div>
</div>
</td>
<td class="info2">
<?php print _('Enter or select required subnet bitmask e.g. (/24)'); ?>
</td>
</tr>
<tr>
<td class="middle"><?php print _('Maximum results'); ?></td>
<td>
<div class="input-group">
<input type="text" class="form-control input-sm input-w-auto" name="results" value='50'>
<input type="hidden" name="sectionid" value='<?php print $_POST['sectionid']; ?>'>
</div>
</td>
<td class="info2">
<?php print _('Enter maximum number of results returned'); ?>
</td>
</tr>
<tr>
<td class="middle"><?php print _('Start subnet'); ?></td>
<td>
<select class="form-control input-sm input-w-auto" name="subnet_start">
<?php
foreach ($all_subnets as $s) {
print "<option value='$s->subnet'>".$Subnets->transform_to_dotted ($s->subnet)."/".$s->mask."</option>";
}
?>
</select>
</td>
<td class="info2">
<?php print _('Search start'); ?>
</td>
</tr>
<tr>
<td class="middle"><?php print _('End subnet'); ?></td>
<td>
<select class="form-control input-sm input-w-auto" name="subnet_end">
<?php
foreach ($all_subnets as $s) {
print "<option value='$s->subnet' selected>".$Subnets->transform_to_dotted ($s->subnet)."/".$s->mask."</option>";
}
?>
</select>
</td>
<td class="info2">
<?php print _('Search end'); ?>
</td>
</tr>
<tr>
<td class="middle"></td>
<td class="text-right">
<button class='btn btn-sm btn-default submit_popup' data-script="app/admin/subnets/find_free_section_subnets_result.php" data-result_div="search_section_free_subnet_result" data-form='search_section_free_subnet'><?php print _("Search"); ?></button>
</td>
<td class="info2"></td>
</tr>
<tr>
<td colspan="3" class="hr"><hr></td>
</tr>
<tr>
<td colspan="3">
<div id="search_section_free_subnet_result"></div>
</td>
</tr>
</table>
</form>
</div>
<!-- footer -->
<div class="pFooter">
<div class="btn-group">
<button class="btn btn-sm btn-default hidePopups"><?php print _('Close'); ?></button>
</div>
</div>