528 |
528 |
$currentlyResolvedLink = str_replace('[DOMAIN]', '', $currentlyResolvedLink); // Clean [DOMAIN] tag
|
529 |
529 |
}
|
530 |
530 |
if (strstr($commandLink, '[IP]') || strstr($commandLink, '[MAC]')) { // Handle "IP" and "MAC" tags
|
531 |
|
/* Fetches network ports */
|
|
531 |
$handledTags = array(
|
|
532 |
// TAG => rowset key
|
|
533 |
'[IP]' => 'ip',
|
|
534 |
'[MAC]' => 'mac',
|
|
535 |
);
|
|
536 |
|
|
537 |
// Fetches every IP (glpi_ipaddresses) and MAC of any network ports (glpi_networkports) of given item:
|
|
538 |
//Note: As of GLPI 0.84 it returns both IPv4 and IPv6 under the same "ip" key. Usually convenient but can bother some commands
|
|
539 |
//Internet Protocol version could be filtered using `glpi_ipaddresses`.`version`
|
532 |
540 |
$networkportsRowset = $DB->query(
|
533 |
|
'SELECT
|
534 |
|
`id`,
|
535 |
|
`name`,
|
536 |
|
`ip`,
|
537 |
|
`mac`
|
538 |
|
FROM `glpi_networkports`
|
539 |
|
WHERE
|
540 |
|
`items_id` = ' . $item->getID() . '
|
541 |
|
AND `itemtype` = \'' . mysql_real_escape_string(get_class($item)) . '\'
|
542 |
|
ORDER BY `logical_number`');
|
543 |
|
$networkportsResolvedLinks = array();
|
544 |
|
while ($networkportRow = $DB->fetch_array($networkportsRowset)) { // For each network port found
|
|
541 |
'SELECT DISTINCT
|
|
542 |
`glpi_networkports`.`name` AS "name",
|
|
543 |
`glpi_networkports`.`mac` AS "mac",
|
|
544 |
`glpi_ipaddresses`.`name` AS "ip"
|
|
545 |
FROM
|
|
546 |
`glpi_networkports`
|
|
547 |
JOIN `glpi_networknames`
|
|
548 |
ON (`glpi_networknames`.`itemtype` = \'NetworkPort\' AND `glpi_networknames`.`items_id` = `glpi_networkports`.`id`)
|
|
549 |
JOIN `glpi_ipaddresses`
|
|
550 |
ON (`glpi_ipaddresses`.`itemtype` = \'NetworkName\' AND `glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`)
|
|
551 |
WHERE
|
|
552 |
`glpi_networkports`.`items_id` = ' . $item->getID() . '
|
|
553 |
AND `glpi_networkports`.`itemtype` = \'' . $DB->escape(get_class($item)) . '\'
|
|
554 |
AND `glpi_networkports`.`is_deleted` = 0
|
|
555 |
AND `glpi_networknames`.`is_deleted` = 0
|
|
556 |
AND `glpi_ipaddresses`.`is_deleted` = 0
|
|
557 |
ORDER
|
|
558 |
BY `glpi_networkports`.`logical_number` ASC');
|
|
559 |
|
|
560 |
while ($networkportRow = $DB->fetch_assoc($networkportsRowset)) { // For each found network port
|
545 |
561 |
$currentlyResolvedNetworkport = $currentlyResolvedLink;
|
546 |
|
if (strstr($commandLink, '[IP]') && array_key_exists('ip', $networkportRow) && !empty($networkportRow['ip'])) { // If "IP" tag and networkport has IP
|
547 |
|
$currentlyResolvedNetworkport = str_replace('[IP]', $networkportRow['ip'], $currentlyResolvedNetworkport);
|
548 |
|
}
|
549 |
|
|
550 |
|
if (strstr($commandLink, '[MAC]') && array_key_exists('mac', $networkportRow) && !empty($networkportRow['mac'])) { // If "MAC" tag and networkport has MAC
|
551 |
|
$currentlyResolvedNetworkport = str_replace('[MAC]', $networkportRow['mac'], $currentlyResolvedNetworkport);
|
|
562 |
foreach ($handledTags as $currentHandledTag => $currentHandledRowsetKey) { // For each handled tags
|
|
563 |
if (strstr($commandLink, $currentHandledTag)) { // Tag in $commandLink?
|
|
564 |
if (array_key_exists($currentHandledRowsetKey, $networkportRow) && !empty($networkportRow[$currentHandledRowsetKey])) { // Matching key found in row
|
|
565 |
$currentlyResolvedValue = $networkportRow[$currentHandledRowsetKey];
|
|
566 |
} else {
|
|
567 |
$currentlyResolvedValue = ''; // To clean this unmatched tag
|
|
568 |
}
|
|
569 |
$currentlyResolvedNetworkport = str_replace($currentHandledTag, $currentlyResolvedValue, $currentlyResolvedNetworkport);
|
|
570 |
}
|
552 |
571 |
}
|
553 |
|
$currentlyResolvedNetworkport = str_replace('[IP]', '', $currentlyResolvedNetworkport); // Clean [IP] tag
|
554 |
|
$currentlyResolvedNetworkport = str_replace('[MAC]', '', $currentlyResolvedNetworkport); // Clean [MAC] tag
|
555 |
|
if (!empty($currentlyResolvedNetworkport)) {
|
|
572 |
|
|
573 |
if (!empty($currentlyResolvedNetworkport)) { // If something was resolved
|
556 |
574 |
if ($fetchItemName) {
|
557 |
575 |
$resolvedLinks[] = array($networkportRow['name'] => $currentlyResolvedNetworkport);
|
558 |
576 |
} else {
|
... | ... | |
560 |
578 |
}
|
561 |
579 |
}
|
562 |
580 |
}
|
563 |
|
/* /Fetches network ports */
|
564 |
|
|
565 |
|
if (strstr($commandLink, '[IP]')) { // Handle "IP" tag
|
566 |
|
if ($item instanceof NetworkEquipment) { // Add internal IP of this network equipment
|
567 |
|
$currentlyResolvedLink = str_replace('[IP]', $item->getField('ip'), $currentlyResolvedLink);
|
568 |
|
}
|
569 |
|
$currentlyResolvedLink = str_replace('[IP]', '', $currentlyResolvedLink); // Clean [IP] tag
|
570 |
|
}
|
571 |
|
|
572 |
|
if (strstr($commandLink, '[MAC]')) { // Handle "MAC" tag
|
573 |
|
if ($item instanceof NetworkEquipment) { // Add internal MAC of this network equipment
|
574 |
|
$currentlyResolvedLink = str_replace('[MAC]', $item->getField('mac'), $currentlyResolvedLink);
|
|
581 |
|
|
582 |
/* Remove/clean tags */
|
|
583 |
foreach (array_keys($handledTags) as $currentHandledTag) { // For each handled tags
|
|
584 |
if (strstr($commandLink, $currentHandledTag)) { // Tag in $commandLink?
|
|
585 |
$currentlyResolvedLink = str_replace($currentHandledTag, '', $currentlyResolvedLink); // Clean
|
575 |
586 |
}
|
576 |
|
$currentlyResolvedLink = str_replace('[MAC]', '', $currentlyResolvedLink); // Clean [MAC] tag
|
577 |
587 |
}
|
|
588 |
/* /Remove/clean tags */
|
578 |
589 |
}
|
579 |
590 |
if (!empty($currentlyResolvedLink)) {
|
580 |
591 |
if ($fetchItemName) {
|
581 |
|
-- shellcommands/inc/webservice.class.php Fri May 23 02:39:53 2014
|
|
592 |
++ shellcommands/inc/webservice.class.php Fri May 23 18:34:33 2014
|
... | ... | |
153 |
153 |
$target_names = (array) $params['target_name'];
|
154 |
154 |
foreach ($target_names as $currentTargetName) {
|
155 |
155 |
$target = new $params['target_type']();
|
156 |
|
if ($found = $target->find('`name` LIKE \'%' . mysql_real_escape_string($currentTargetName) . '%\'')) {
|
|
156 |
if ($found = $target->find('`name` LIKE \'%' . $DB->escape($currentTargetName) . '%\'')) {
|
157 |
157 |
$targetIds = array_merge($targetIds, array_keys($found));
|
158 |
158 |
} else {
|
159 |
159 |
$invalidTargets[] = $currentTargetName;
|