コード例 #1
0
ファイル: devices.php プロジェクト: krys1976/phpipam-1
$switches = getAllUniqueSwitches();
/* add unspecified */
$switches[] = array("id" => "", "hostname" => "");
/* switch count for collapse / extend */
$m = 0;
# title
print "<h4>" . _('List of network devices') . "</h4>";
print "<hr>";
# main table frame
print "<table id='switchMainTable' class='switches table table-striped table-top table-condensed'>";
/* print */
foreach ($switches as $switch) {
    /* Get all IP addresses belonging to switch */
    $ipaddresses = getIPaddressesBySwitchName($switch['id']);
    /* Get switch details */
    $switchDetails = getSwitchDetailsByHostname($switch['hostname']);
    if (empty($switchDetails['hostname'])) {
        $switchDetails['hostname'] = _('Device not specified');
        $switchDetails['ip_addr'] = "";
    } else {
        $switchDetails['ip_addr'] = "({$switchDetails['ip_addr']})";
    }
    /* reformat if empty */
    if (empty($switch['hostname'])) {
        $switch['hostname'] = "Unspecified";
    }
    # count size
    $size = sizeof($ipaddresses);
    # print name
    print "<tbody id='switch-{$m}'>";
    print "<tr class='switch-title'>";
コード例 #2
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;
    }
}