function setSwitchVLANs($object_id = 0, $setcmd) { global $remote_username; $objectInfo = spotEntity('object', $object_id); $endpoints = findAllEndpoints($object_id, $objectInfo['name']); if (count($endpoints) == 0) { throw new RTGatewayError('no management address set'); } if (count($endpoints) > 1) { throw new RTGatewayError('cannot pick management address'); } $hwtype = $swtype = 'unknown'; foreach (getAttrValues($object_id) as $record) { if ($record['name'] == 'SW type' && strlen($record['o_value'])) { $swtype = strtr(execGMarker($record['o_value']), ' ', '+'); } if ($record['name'] == 'HW type' && strlen($record['o_value'])) { $hwtype = strtr(execGMarker($record['o_value']), ' ', '+'); } } $endpoint = str_replace(' ', '+', $endpoints[0]); $data = queryGateway('switchvlans', array("connect {$endpoint} {$hwtype} {$swtype} {$remote_username}", $setcmd)); // Finally we can parse the response into message array. foreach (explode(';', substr($data[1], strlen('OK!'))) as $text) { $message = 'gw: ' . substr($text, 2); if (strpos($text, 'I!') === 0) { showSuccess($message); } elseif (strpos($text, 'W!') === 0) { showWarning($message); } elseif (strpos($text, 'E!') === 0) { showError($message); } else { // All improperly formatted messages must be treated as error conditions. showError('unexpected line from gw: ' . $text); } } }
function parseWikiLink(&$record) { if (!preg_match('/^\\[\\[(.+)\\]\\]$/', $record['value'], $matches)) { $record['o_value'] = $record['value']; } else { $s = explode('|', $matches[1]); if (isset($s[1])) { $record['href'] = trim($s[1]); } $record['o_value'] = trim($s[0]); } $record['a_value'] = execGMarker($record['o_value']); }