IP Reg is a IPAM tool to keep track of assets, nodes (IP addresses, MAC addresses, DNS aliases) within different subnets, over different locations or even VLAN's. Written in PHP, used with a MySQL-database to have a unique insight in your local network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
ipreg/nodeadd.php

191 lines
4.0 KiB

<?php
include("header.php");
// display only if admin
if($_SESSION['suser_level'] >= 2) {
// check for submit
if ($_SERVER['REQUEST_METHOD']=="POST" ) {
$ip = str_replace(' ', '', $_POST['ip']);
// IP in use?
$result = mysql_query("SELECT * FROM node WHERE ip='$ip'");
if (mysql_num_rows($result)!=0) {
echo 'IP in use!';
exit;
} else {
$asset_name = $_POST['asset_name'];
$hostname = $_POST['hostname'];
$assetclass_id = $_POST['assetclass_id'];
mysql_query("INSERT INTO asset (asset_name, hostname, assetclass_id) VALUE ('$asset_name', '$hostname', '$assetclass_id')") or die(mysql_error());
// get asset_id for new node
$asset_id = mysql_insert_id();
$mac = strip_mac($_POST['mac']);
// DNS1
if (!empty($_POST['dns1']) && isset($_POST['dns1suffix'])) {
$dns1 = $_POST['dns1'] . $config_dns1suffix;
} else {
$dns1 = $_POST['dns1'];
}
// DNS2
if (!empty($_POST['dns2']) && isset($_POST['dns2suffix'])) {
$dns2 = $_POST['dns2'] . $config_dns2suffix;
} else {
$dns2 = $_POST['dns2'];
}
$subnet_id = $_POST['subnet_id'];
mysql_query("INSERT INTO node (ip, mac, dns1, dns2, subnet_id, asset_id) VALUE ('$ip', '$mac', '$dns1', '$dns2', '$subnet_id', '$asset_id')") or die(mysql_error());
$node_id = mysql_insert_id();
header_location("assetview.php?asset_id=" . $asset_id);
}
}
// check for ip
if (isset($_GET['ip'])) {
$ip = $_GET['ip'];
} else {
$ip = "";
}
// check for subnet_id
if (isset($_GET['subnet_id'])) {
$subnet_id = $_GET['subnet_id'];
} else {
$subnet_id = '';
}
?>
<form method="POST" action="nodeadd.php">
<table border="0">
<tr>
<td colspan="2">
<b>Add new node:</b><br>
</td>
</tr>
<tr>
<td>
Asset name:
</td>
<td>
<input type="text" name="asset_name">
</td>
<td>
*
</td>
</tr>
<tr>
<td>
Hostname:
</td>
<td>
<input type="text" name="hostname">
</td>
<td>
&nbsp;
</td>
</tr>
<tr>
<td>
IP Address:
</td>
<td>
<input type="text" name="ip" value="<?php echo $ip; ?>">
</td>
<td>
*
</td>
</tr>
<tr>
<td>
Subnet:<br>
</td>
<td>
<select name="subnet_id">
<?php
$result = mysql_query("SELECT subnet_id, subnet_address, subnet_mask FROM subnet ORDER BY INET_ATON(subnet_address)");
while ($row = mysql_fetch_object($result)) {
if ($row->subnet_id==$subnet_id) {
$selected = ' selected';
} else {
$selected = '';
}
echo '<option value="' . $row->subnet_id . '" ' . $selected . '>' . $row->subnet_address . '/' . $row->subnet_mask . '</option>';
}
?>
</select>
</td>
<td>
*
</td>
</tr>
<tr>
<td>
Asset class:
</td>
<td>
<select name="assetclass_id">
<?php
$result = mysql_query("SELECT assetclass_id, assetclass_name FROM assetclass ORDER BY assetclass_name");
while ($row = mysql_fetch_object($result)) {
echo '<option value="' . $row->assetclass_id . '" ' . $selected . '>' . $row->assetclass_name . '</option>';
}
?>
</select>
</td>
<td>
*
</td>
</tr>
<tr>
<td>
MAC Address:
</td>
<td>
<input type="text" name="mac">
</td>
<td>
&nbsp;
</td>
</tr>
<tr>
<td>
DNS name:
</td>
<td>
<input type="text" name="dns1">
</td>
<td>
<input type="checkbox" name="dns1suffix" checked><?php echo $config_dns1suffix; ?>
</td>
</tr>
<tr>
<td>
DNS alias:
</td>
<td>
<input type="text" name="dns2">
</td>
<td>
<input type="checkbox" name="dns2suffix" checked><?php echo $config_dns2suffix; ?>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="Submit"><input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
<?php
// end display only if admin
}
include("footer.php");
?>