-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefix_add.php
198 lines (161 loc) · 6.49 KB
/
prefix_add.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2006 Michael Earls |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| - phpIP - http://www.phpip.net/ |
+-------------------------------------------------------------------------+
*/
ob_start();
// include the layout file
include 'layout.php';
require('Net/IPv4.php');
login_check();
admin_check();
// Use the myheader function from layout.php
myheader("phpIP Management");
switch ($_REQUEST["mode"]) {
case "add":
{
/*
/ mysql insert for prefix
*/
if (isset ($_POST['di'])) { $di = strip_tags($_POST['di']); }
if (isset ($_POST['cidr'])) { $cidr = strip_tags($_POST['cidr']); }
if (isset ($_GET['cidr'])) { $cidr = strip_tags($_GET['cidr']); }
if (isset ($_GET['di'])) { $di = strip_tags($_GET['di']); }
if (isset ($_POST['prefix'])) { $prefix = strip_tags($_POST['prefix']); }
$net = Net_IPv4::parseAddress($cidr);
$n = explode(".", $net->network); // parse for network address
$b = explode(".", $net->broadcast); // parse for broadcast address
$bit = $net->bitmask;
$i = 0;
if (count($_POST[nets]) >0)
{
foreach ($_POST[nets] as $NetAdd) {
if ($bit > '24') {
// Greater then 24
// loop and update view to 1 to display prefix
$PrefixUpdate = mysql_query("UPDATE `net_ips` SET `view` = '1' WHERE `AddressId` = '$NetAdd'");
} else {
// Less then 24
// loop and get netaddress
$PrefixSelect = mysql_query("SELECT `netaddress` FROM `net_ips` WHERE `AddressId` = '$NetAdd'");
while($row = mysql_fetch_array($PrefixSelect))
{
$Prefix = $row[netaddress];
}
// for loop to build third octects
for ($g = 0; $g <= "255"; $g++)
{
$insertIP = mysql_query("INSERT INTO `addresses` (`ip`, `NetID`) VALUES ('$Prefix.$g', '$di')");
} // end for loop
// loop and update view to 1 to display prefix
$PrefixUpdate = mysql_query("UPDATE `net_ips` SET `view` = '1' WHERE `AddressId` = '$NetAdd'");
} // end if else
$i++;
}
// Redirect to add.php after sql insert
?>
<h2><font color="FF0000">Updating Database, Please wait</font></h2>
<meta http-equiv=Refresh content=1;url="prefix_add.php">
<?php
}
else {
echo "<h2><font color=\"FF0000\">No Data Selected, Please use your browser back button to complete the form.</font></h2>";
}
} // end case
break;
case "parse":
{
if (isset ($_POST['di'])) { $di = strip_tags($_POST['di']); }
if (isset ($_POST['cidr'])) { $cidr = strip_tags($_POST['cidr']); }
if (isset ($_GET['cidr'])) { $cidr = strip_tags($_GET['cidr']); }
if (isset ($_GET['di'])) { $di = strip_tags($_GET['di']); }
if (isset ($_POST['prefix'])) { $prefix = strip_tags($_POST['prefix']); }
$net = Net_IPv4::parseAddress($cidr);
$n = explode(".", $net->network); // parse for network address
$b = explode(".", $net->broadcast); // parse for broadcast address
$ShowPrefix = mysql_query("SELECT COUNT(*) AS NetCount FROM `net_ips` WHERE `NetCidr` = '$di' AND `view` = '0'");
?>
<FORM action="<?php $PHPSELF;?>?mode=add" method=post name="update">
<table class="listTable" style="width:100%" cellpadding="0" cellspacing="0">
<tr class="listCell">
<TD class="listCell" colspan="3">PREFIX -- <?php echo $cidr; ?></TD>
</tr>
<tr class="listHeadRow">
<td class="listCell"> </td>
<td class="listCell">IP</td>
<td class="listCell">DESCRIPTION</td>
</tr>
<?php
if ($NetCount < '1') {
$ListPrefix = mysql_query("SELECT * FROM `net_ips` WHERE `NetCidr` = '$di' AND `view` = '0' +0");
while($row = mysql_fetch_array($ListPrefix))
{
if ($RowClass == "listRow2") { $RowClass = "listRow1";
}
else
{ $RowClass = "listRow2";
}
echo "<TR class=\"$RowClass\">";
echo "<TD class=\"listCell\" width=\"20\"><INPUT TYPE=\"checkbox\" NAME=\"nets[]\" VALUE=\"$row[AddressId]\"></td>";
echo "<TD class=\"listCell\"> $row[netaddress]</TD>";
echo "<TD class=\"listCell\"> $row[ip_description]</TD>";
echo "</tr>";
}
echo "</TABLE>";
// echo "<TABLE>";
echo "<a href=\"javascript:document.update.submit()\">[ADD]</a>";
// echo "</TABLE>";
echo "</br>";
echo "<input type=\"hidden\" name=\"cidr\" value=\"$cidr\">";
echo "<input type=\"hidden\" name=\"di\" value=\"$di\">";
echo "</form>";
} // END IF ELSE
}
break;
default:
$sqllist = mysql_query("SELECT * FROM `NetMenu` ORDER BY `NetMenuCidr` + 0");
?>
<FORM action="<?php $PHPSELF;?>?mode=parse" method=post name="prefixadd">
<table class="listTable" style="width:100%" cellpadding="0" cellspacing="0">
<tr class="listCell">
<TD class="listCell" colspan="3">PREFIX UPDATE</TD>
</tr>
<tr class="listHeadRow">
<td class="listCell"> </td>
<td class="listCell">IP</td>
<td class="listCell">DESCRIPTION</td>
</tr>
<?php
while($row = mysql_fetch_array($sqllist))
{
if ($RowClass == "listRow2") { $RowClass = "listRow1";
}
else
{ $RowClass = "listRow2";
}
echo "<TR class=\"$RowClass\">";
echo "<TD class=\"listCell\" width=\"20\"><a href=\"prefix_add.php?mode=parse&cidr=$row[NetMenuCidr]&di=$row[NetMenuId]\">[Add]</a></TD>";
echo "<TD class=\"listCell\">$row[NetMenuCidr] </TD>";
echo "<TD class=\"listCell\">$row[NetCidrDescription] </TD>";
echo "</tr>";
}
echo "</TABLE>";
echo "</form>";
// Use the footer function from layout.php
footer();
} // end switch
//------------------------------------------------------------------------------------------
?>