Example #1
0
		<option value="mac"><?php 
print _('MAC address');
?>
</option>
		<option value="switch"><?php 
print _('Switch');
?>
</option>
		<option value="port"><?php 
print _('Port');
?>
</option>
		
		<?php 
#get all custom fields!
$myFields = getCustomIPaddrFields();
if (sizeof($myFields) > 0) {
    foreach ($myFields as $myField) {
        print '<option value="' . $myField['name'] . '"> ' . $myField['name'] . '</option>';
    }
}
?>
		
	</select>
	</td>
</tr>

<tr>
	<td><?php 
print _('Select search string');
?>
Example #2
0
/**
 * accept IP request
 */
function acceptIPrequest($request)
{
    global $db;
    # get variables from config file
    $database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
    /* first update request */
    $query = 'update requests set `processed` = "1", `accepted` = "1", `adminComment` = "' . $request['adminComment'] . '" where `id` = "' . $request['requestId'] . '";' . "\n";
    /* We need to get custom fields! */
    $myFields = getCustomIPaddrFields();
    $myFieldsInsert['query'] = '';
    $myFieldsInsert['values'] = '';
    if (sizeof($myFields) > 0) {
        /* set inserts for custom */
        foreach ($myFields as $myField) {
            $myFieldsInsert['query'] .= ', `' . $myField['name'] . '`';
            $myFieldsInsert['values'] .= ", '" . $request[$myField['name']] . "'";
        }
    }
    /* insert */
    $query .= "insert into `ipaddresses` ";
    $query .= "(`subnetId`,`description`,`ip_addr`, `dns_name`,`mac`, `owner`, `state`, `switch`, `port`, `note` " . $myFieldsInsert['query'] . ") ";
    $query .= "values ";
    $query .= "('" . $request['subnetId'] . "', '" . $request['description'] . "', '" . $request['ip_addr'] . "', " . "\n";
    $query .= " '" . $request['dns_name'] . "', '" . $request['mac'] . "', '" . $request['owner'] . "', '" . $request['state'] . "', " . "\n";
    $query .= " '" . $request['switch'] . "', '" . $request['port'] . "', '" . $request['note'] . "'" . $myFieldsInsert['values'] . ");";
    /* set log file */
    foreach ($request as $key => $req) {
        $log .= " " . $key . ": " . $req . "<br>";
    }
    /* execute */
    try {
        $database->executeMultipleQuerries($query);
    } catch (Exception $e) {
        $error = $e->getMessage();
        print "<div class='alert alert-error'>" . _('Error') . ": {$error}</div>";
        updateLogTable('Failed to accept IP request', $log . "\n" . $error, 2);
        return false;
    }
    /* return success */
    updateLogTable('IP request accepted', $log, 1);
    return true;
}
Example #3
0
/**
 * set insert / update / delete query for adding IP address
 * based on provided array
 */
function SetInsertQuery($ip)
{
    /* First we need to get custom fields! */
    $myFields = getCustomIPaddrFields();
    $myFieldsInsert['query'] = '';
    $myFieldsInsert['values'] = '';
    // <eNovance>
    // Finds the GLPI id of a new ip address.
    if ($ip['action'] == "add" and $ip['glpiId'] == '') {
        global $db;
        /* Find the glpiId of the newly added ip addresse */
        $database = new database($db['glpi_host'], $db['glpi_user'], $db['glpi_pass'], $db['glpi_name']);
        $query = "SELECT DISTINCT glpi_networkports.items_id ";
        $query .= "FROM glpi_networkports ";
        $query .= "INNER JOIN glpi_computers ON glpi_networkports.ip = '" . $ip['ip_addr'] . "' ";
        $query .= "AND glpi_computers.is_deleted = 0 ";
        $query .= "AND glpi_networkports.items_id = glpi_computers.id;";
        $glpiId = $database->getRow($query);
        if (count($glpiId > 0)) {
            $ip['glpiId'] = $glpiId[0];
        }
    }
    // </eNovance>
    if (sizeof($myFields) > 0) {
        /* set inserts for custom */
        foreach ($myFields as $myField) {
            $myFieldsInsert['query'] .= ', `' . $myField['name'] . '`';
            $myFieldsInsert['values'] .= ", '" . $ip[$myField['name']] . "'";
        }
    }
    /* insert */
    if ($ip['action'] == "add") {
        $query = "insert into `ipaddresses` ";
        $query .= "(`subnetId`,`description`,`ip_addr`, `dns_name`,`mac`, `owner`, `state`, `switch`, `port`, `note`, `excludePing` " . $myFieldsInsert['query'] . ") ";
        $query .= "values ";
        $query .= "('" . $ip['subnetId'] . "', '" . $ip['description'] . "', '" . Transform2decimal($ip['ip_addr']) . "', " . "\n";
        $query .= " '" . $ip['dns_name'] . "', '" . $ip['mac'] . "', '" . $ip['owner'] . "', '" . $ip['state'] . "', " . "\n";
        $query .= " '" . $ip['switch'] . "', '" . $ip['port'] . "', '" . $ip['note'] . "', '" . @$ip['excludePing'] . "' " . $myFieldsInsert['values'] . ");";
    } else {
        if ($ip['action'] == "edit" && $ip['type'] == "series") {
            $query = "update `ipaddresses` ";
            $query .= "set `ip_addr` = '" . Transform2decimal($ip['ip_addr']) . "', ";
            $query .= "`description` = '" . $ip['description'] . "', ";
            $query .= "`dns_name` = '" . $ip['dns_name'] . "' ,";
            $query .= "`mac` = '" . $ip['mac'] . "' ,";
            $query .= "`owner` = '" . $ip['owner'] . "' ,";
            $query .= "`state` = '" . $ip['state'] . "',";
            $query .= "`switch` = '" . $ip['switch'] . "',";
            $query .= "`port` = '" . $ip['port'] . "',";
            $query .= "`excludePing` = '" . @$ip['excludePing'] . "',";
            # custom!
            foreach ($myFields as $myField) {
                $query .= "`" . $myField['name'] . "` = '" . $ip[$myField['name']] . "',";
            }
            $query .= "`note` = '" . $ip['note'] . "' ";
            $query .= "where `subnetId` = '" . $ip['subnetId'] . "' and `ip_addr` = '" . Transform2decimal($ip['ip_addr']) . "';";
        } else {
            if ($ip['action'] == "edit") {
                $query = "update ipaddresses ";
                $query .= "set `ip_addr` = '" . Transform2decimal($ip['ip_addr']) . "', `description` = '" . $ip['description'] . "', `dns_name` = '" . $ip['dns_name'] . "' , `mac` = '" . $ip['mac'] . "', " . "\n";
                #custom!
                foreach ($myFields as $myField) {
                    $query .= "`" . $myField['name'] . "` = '" . $ip[$myField['name']] . "',";
                }
                $query .= "`owner` = '" . $ip['owner'] . "' , `state` = '" . $ip['state'] . "', `switch` = '" . $ip['switch'] . "', " . "\n";
                $query .= "`port` = '" . $ip['port'] . "', `note` = '" . $ip['note'] . "', `excludePing` = '" . @$ip['excludePing'] . "' ";
                $query .= "where `id` = '" . $ip['id'] . "';";
            } else {
                if ($ip['action'] == "delete" && $ip['type'] == "series") {
                    $query = "delete from ipaddresses where `subnetId` = '" . $ip['subnetId'] . "' and `ip_addr` = '" . Transform2decimal($ip['ip_addr']) . "';";
                } else {
                    if ($ip['action'] == "delete") {
                        $query = "delete from ipaddresses where `id` = '" . $ip['id'] . "';";
                    } else {
                        if ($ip['action'] == "move") {
                            $query = "update `ipaddresses` set `subnetId` = '{$ip['newSubnet']}' where `id` = '{$ip['id']}';";
                        }
                    }
                }
            }
        }
    }
    /* return query */
    return $query;
}
Example #4
0
/**
 * CSV import IP address
 *
 *		provided input is CSV line!
 */
function importCSVline($line, $subnetId)
{
    /* array */
    $line = explode(",", $line);
    global $db;
    # get variables from config file
    $database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
    /* get subnet details by Id */
    $subnetDetails = getSubnetDetailsById($subnetId);
    $subnet = Transform2long($subnetDetails['subnet']) . "/" . $subnetDetails['mask'];
    /* verify! */
    if (VerifyIpAddress($line[0], $subnet)) {
        return _('Wrong IP address') . ' - ' . $line[0];
    }
    /* check for duplicates */
    if (checkDuplicate($line[0], $subnetId)) {
        return _('IP address already exists') . ' - ' . $line[0];
    }
    /* reformat state */
    switch ($line[5]) {
        case "Active":
            $line[5] = "1";
            break;
        case "active":
            $line[5] = "1";
            break;
        case "Reserved":
            $line[5] = "2";
            break;
        case "reserved":
            $line[5] = "2";
            break;
        case "Offline":
            $line[5] = "0";
            break;
        case "offline":
            $line[5] = "0";
            break;
    }
    /* reformat switch! */
    $switch = getSwitchDetailsByHostname($line[7]);
    /* get custom fields */
    $myFields = getCustomIPaddrFields();
    if (sizeof($myFields) > 0) {
        $import['fieldName'] = "";
        $import['fieldValue'] = "";
        $m = 9;
        foreach ($myFields as $field) {
            $import['fieldName'] .= ",`{$field['name']}`";
            $import['fieldValue'] .= ",'{$line[$m]}'";
            $m++;
        }
    }
    /* all ok, set query */
    $query = "insert into ipaddresses ";
    $query .= "(`subnetId`, `ip_addr`, `state`, `description`, `dns_name`, `mac`, `owner`, `switch`, `port`, `note` {$import['fieldName']} ) ";
    $query .= "values ";
    $query .= "('{$subnetId}','" . Transform2decimal($line[0]) . "', '{$line['1']}','{$line['2']}','{$line['3']}','{$line['4']}','{$line['5']}','{$line['6']}','{$switch['id']}','{$line['8']}' {$import['fieldValue']});";
    /* set log details */
    $log = prepareLogFromArray($line);
    /* execute */
    try {
        $database->executeQuery($query);
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
    if (!isset($e)) {
        updateLogTable('CSV import of IP address ' . $line[1] . ' succeeded', $log, 0);
        return true;
    } else {
        updateLogTable('CSV import of IP address ' . $line[1] . ' failed', $log, 2);
        return $error;
    }
}
Example #5
0
/**
 * Script to get all active IP requests
 ****************************************/
/* verify that user is admin */
checkAdmin();
/* get all fields in IP table */
$fields = getIPaddrFields();
/* get all selected fields */
$setFieldsTemp = getSelectedIPaddrFields();
/* format them to array! */
$setFields = explode(";", $setFieldsTemp);
/* unset mandatory fields -> id,subnetid,ip_addr */
unset($fields['id'], $fields['subnetId'], $fields['ip_addr'], $fields['description'], $fields['dns_name'], $fields['lastSeen'], $fields['excludePing']);
/* unset custom! */
$custom = getCustomIPaddrFields();
if (sizeof($custom) > 0) {
    foreach ($custom as $key => $cust) {
        unset($fields[$key]);
    }
}
?>


<h4><?php 
print _('Filter which fields to display in IP list');
?>
</h4>
<hr>

<div class="alert alert-info alert-absolute"><?php