public function dispatch() { global $debug_mode; if ($debug_mode) { printGenericException($this); return; } showError($this->message); redirectUser(buildRedirectURL('index', 'default')); }
public function testVcrAfterSave() { $return_id = '1bb73165-dcd7-21b2-b648-4ded8dce0bf8'; $_REQUEST['return_action'] = 'DetailView'; $_REQUEST['return_module'] = 'Accounts'; $_REQUEST['return_id'] = $return_id; $_REQUEST['offset'] = 4; require_once 'include/formbase.php'; $url = buildRedirectURL($return_id, 'Accounts'); unset($_REQUEST['return_action']); unset($_REQUEST['return_module']); unset($_REQUEST['return_id']); unset($_REQUEST['offset']); $this->assertContains('offset=4', $url, "Offset was not included in the redirect url"); }
function doVSMigrate() { global $dbxlink; $vs_id = assertUIntArg('vs_id'); $vs_cell = spotEntity('ipvs', $vs_id); amplifyCell($vs_cell); $tag_ids = genericAssertion('taglist', 'array0'); $old_vs_list = genericAssertion('vs_list', 'array'); $plan = callHook('buildVSMigratePlan', $vs_id, $old_vs_list); $dbxlink->beginTransaction(); // remove all triplets usePreparedDeleteBlade('VSEnabledIPs', array('vs_id' => $vs_id)); usePreparedDeleteBlade('VSEnabledPorts', array('vs_id' => $vs_id)); // remove all VIPs and ports that are in $plan and create new ones foreach ($plan['vips'] as $vip) { usePreparedDeleteBlade('VSIPs', array('vs_id' => $vs_id, 'vip' => $vip['vip'])); usePreparedInsertBlade('VSIPs', array('vs_id' => $vs_id) + $vip); } foreach ($plan['ports'] as $port) { usePreparedDeleteBlade('VSPorts', array('vs_id' => $vs_id, 'proto' => $port['proto'], 'vport' => $port['vport'])); usePreparedInsertBlade('VSPorts', array('vs_id' => $vs_id) + $port); } // create triplets foreach ($plan['triplets'] as $triplet) { $tr_key = array('vs_id' => $triplet['vs_id'], 'object_id' => $triplet['object_id'], 'rspool_id' => $triplet['rspool_id']); foreach ($triplet['ports'] as $port) { addSLBPortLink($tr_key + $port); } foreach ($triplet['vips'] as $vip) { addSLBIPLink($tr_key + $vip); } } // update configs usePreparedUpdateBlade('VS', $plan['properties'], array('id' => $vs_id)); // replace tags global $taglist; $chain = array(); foreach ($tag_ids as $tid) { if (!isset($taglist[$tid])) { $dbxlink->rollback(); showError("Unknown tag id {$tid}"); } else { $chain[] = $taglist[$tid]; } } rebuildTagChainForEntity('ipvs', $vs_id, $chain, TRUE); $dbxlink->commit(); showSuccess("old VS configs were copied to VS group"); return buildRedirectURL(NULL, 'default'); }
function doPDUSNMPmining($switch) { global $objectInfo, $known_APC_SKUs; if (FALSE !== ($dict_key = array_search($switch->getHWModel(), $known_APC_SKUs))) { updateStickerForCell($objectInfo, 2, $dict_key); } updateStickerForCell($objectInfo, 1, $switch->getHWSerial()); updateStickerForCell($objectInfo, 3, $switch->getName()); updateStickerForCell($objectInfo, 5, $switch->getFWRev()); checkPIC('1-16'); commitAddPort($objectInfo['id'], 'input', '1-16', 'input', ''); $portno = 1; foreach ($switch->getPorts() as $name => $port) { $label = mb_strlen($port[0]) ? $port[0] : $portno; checkPIC('1-1322'); commitAddPort($objectInfo['id'], $portno, '1-1322', $port[0], ''); $portno++; } showSuccess("Added {$portno} port(s)"); return buildRedirectURL(NULL, 'ports'); }
/** * Handles a redirect from a Form SugarCRM based or return_url information. * * This function redirect automatically if $_REQUEST['return_url'] isn't empty. * It also exits the app always. * * @see buildRedirectUrl() * @see SugarApplication::redirect() * * @deprecated since 7.0.0. Use buildRedirectUrl() and SugarApplication::redirect(). * * @param string $return_id (optional) The record id to redirect to. * @param string $return_module (optional) The module to redirect to. * @param array $additionalFlags (optional) Additional flags to sent to the URL. */ function handleRedirect($return_id = '', $return_module = '', array $additionalFlags = array()) { if (!empty($_REQUEST['return_url'])) { $url = $_REQUEST['return_url']; } else { $url = buildRedirectURL($return_id, $return_module, $additionalFlags); } SugarApplication::redirect($url); }
/** * handles save functionality for meetings * @param string prefix * @param bool redirect default True * @param bool useRequired default True */ function handleSave($prefix, $redirect = true, $useRequired = false) { require_once 'include/formbase.php'; global $current_user; global $timedate; $focus = BeanFactory::getBean('Meetings'); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } if (!isset($_POST['reminder_checked']) or isset($_POST['reminder_checked']) && $_POST['reminder_checked'] == '0') { $_POST['reminder_time'] = -1; } if (!isset($_POST['reminder_time'])) { $_POST['reminder_time'] = $current_user->getPreference('reminder_time'); $_POST['reminder_checked'] = 1; } if (!isset($_POST['email_reminder_checked']) || isset($_POST['email_reminder_checked']) && $_POST['email_reminder_checked'] == '0') { $_POST['email_reminder_time'] = -1; } if (!isset($_POST['email_reminder_time'])) { $_POST['email_reminder_time'] = $current_user->getPreference('email_reminder_time'); $_POST['email_reminder_checked'] = 1; } if (isset($_POST['repeat_parent_id']) && trim($_POST['repeat_parent_id']) == '') { unset($_POST['repeat_parent_id']); } // don't allow to set recurring_source from a form unset($_POST['recurring_source']); $time_format = $timedate->get_user_time_format(); $time_separator = ":"; if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) { $time_separator = $match[1]; } if (!empty($_POST[$prefix . 'time_hour_start']) && empty($_POST['time_start'])) { $_POST[$prefix . 'time_start'] = $_POST[$prefix . 'time_hour_start'] . $time_separator . $_POST[$prefix . 'time_minute_start']; } if (isset($_POST[$prefix . 'meridiem']) && !empty($_POST[$prefix . 'meridiem'])) { $_POST[$prefix . 'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix . 'time_start'], $timedate->get_time_format(), $_POST[$prefix . 'meridiem']); } if (isset($_POST[$prefix . 'time_start']) && strlen($_POST[$prefix . 'date_start']) == 10) { $_POST[$prefix . 'date_start'] = $_POST[$prefix . 'date_start'] . ' ' . $_POST[$prefix . 'time_start']; } // retrieve happens here $focus = populateFromPost($prefix, $focus); if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } // if dates changed if (!empty($focus->id)) { $oldBean = new Meeting(); $oldBean->retrieve($focus->id); if ($focus->date_start != $oldBean->date_start || $focus->date_end != $oldBean->date_end) { $focus->date_changed = true; } else { $focus->date_changed = false; } } $newBean = true; if (!empty($focus->id)) { $newBean = false; } //add assigned user and current user if this is the first time bean is saved if (empty($focus->id) && !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Meetings' && !empty($_REQUEST['return_action']) && $_REQUEST['return_action'] == 'DetailView') { //if return action is set to detail view and return module to meeting, then this is from the long form, do not add the assigned user (only the current user) //The current user is already added to UI and we want to give the current user the option of opting out of meeting. //add current user if the assigned to user is different than current user. if ($current_user->id != $_POST['assigned_user_id']) { $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', '; $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']); } } elseif (empty($focus->id)) { //this is not from long form so add assigned and current user automatically as there is no invitee list UI. //This call could be through an ajax call from subpanels or shortcut bar if (!isset($_POST['user_invitees'])) { $_POST['user_invitees'] = ''; } $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', '; //add current user if the assigned to user is different than current user. if ($current_user->id != $_POST['assigned_user_id'] && $_REQUEST['module'] != "Calendar") { $_POST['user_invitees'] .= ',' . $current_user->id . ', '; } //remove any double comma's introduced during appending $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']); } if (isset($_POST['isSaveFromDetailView']) && $_POST['isSaveFromDetailView'] == 'true' || (isset($_POST['is_ajax_call']) && !empty($_POST['is_ajax_call']) && !empty($focus->id) || isset($_POST['return_action']) && $_POST['return_action'] == 'SubPanelViewer' && !empty($focus->id)) || !isset($_POST['user_invitees'])) { $focus->save(true); $return_id = $focus->id; } else { if ($focus->status == 'Held' && $this->isEmptyReturnModuleAndAction() && !$this->isSaveFromDCMenu()) { //if we are closing the meeting, and the request does not have a return module AND return action set and it is not a save //being triggered by the DCMenu (shortcut bar) then the request is coming from a dashlet or subpanel close icon and there is no //need to process user invitees, just save the current values. $focus->save(true); } else { $relate_to = $this->getRelatedModuleName($focus); $userInvitees = array(); $contactInvitees = array(); $leadInvitees = array(); $existingUsers = array(); $existingContacts = array(); $existingLeads = array(); if (!empty($_POST['user_invitees'])) { $userInvitees = explode(',', trim($_POST['user_invitees'], ',')); } if (!empty($_POST['existing_invitees'])) { $existingUsers = explode(",", trim($_POST['existing_invitees'], ',')); } if (!empty($_POST['contact_invitees'])) { $contactInvitees = explode(',', trim($_POST['contact_invitees'], ',')); } if (!empty($_POST['existing_contact_invitees'])) { $existingContacts = explode(",", trim($_POST['existing_contact_invitees'], ',')); } if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') { $contactInvitees[] = $_POST['parent_id']; } if ($relate_to == 'Contacts') { if (!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_id'], $contactInvitees)) { $contactInvitees[] = $_REQUEST['relate_id']; } } if (!empty($_POST['lead_invitees'])) { $leadInvitees = explode(',', trim($_POST['lead_invitees'], ',')); } if (!empty($_POST['existing_lead_invitees'])) { $existingLeads = explode(",", trim($_POST['existing_lead_invitees'], ',')); } if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Leads') { $leadInvitees[] = $_POST['parent_id']; } if ($relate_to == 'Leads') { if (!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_id'], $leadInvitees)) { $leadInvitees[] = $_REQUEST['relate_id']; } } // Call the Meeting module's save function to handle saving other fields besides // the users and contacts relationships $focus->update_vcal = false; // Bug #49195 : don't update vcal b/s related users aren't saved yet, create vcal cache below $focus->users_arr = $userInvitees; $focus->contacts_arr = $contactInvitees; $focus->leads_arr = $leadInvitees; $focus->save(true); $return_id = $focus->id; if (empty($return_id)) { //this is to handle the situation where the save fails, most likely because of a failure //in the external api. bug: 42200 $_REQUEST['action'] = 'EditView'; $_REQUEST['return_action'] = 'EditView'; handleRedirect('', 'Meetings'); } $focus->setUserInvitees($userInvitees, $existingUsers); $focus->setContactInvitees($contactInvitees, $existingContacts); $focus->setLeadInvitees($focus->leads_arr, $existingLeads); // Bug #49195 : update vcal vCal::cache_sugar_vcal($current_user); $this->processRecurring($focus); } } if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] === 'Home') { SugarApplication::redirect(buildRedirectURL('', 'Home')); } else { if ($redirect) { handleRedirect($return_id, 'Meetings'); } else { return $focus; } } }
function handleRedirect($return_id = '', $return_module = '', $additionalFlags = false) { if (isset($_REQUEST['return_url']) && $_REQUEST['return_url'] != "") { header("Location: " . $_REQUEST['return_url']); exit; } $url = buildRedirectURL($return_id, $return_module); header($url); exit; }
function execute_PortLinker() { global $localSplit, $remoteSplit; $errorText = determine_PortLinker(); $object = spotEntity('object', $_REQUEST['object_id']); if (strlen($errorText) == 0) { $count = 0; // loop through all remote objects as defined foreach ($localSplit as $aKey => $aValue) { $numAdd = $remoteSplit[$aKey][$object['name']]['start'] - $aValue['start']; foreach ($aValue['ports'] as $aPortNum => $aPort) { linkPorts($aPort['id'], $aValue['remote_ports'][$aPortNum + $numAdd]['id']); $count++; } } } if (strlen($errorText) == 0) { return buildRedirectURL(__FUNCTION__, 'OK', array("{$count} ports successfully linked")); } else { return buildRedirectURL(__FUNCTION__, 'ERR', array($errorText)); } }
$params = array(); $params[] = "<a href='index.php?module={$focus->module_dir}&action=index'>{$focus->module_dir}</a>"; $params[] = "<a href='index.php?module={$focus->module_dir}&action=DetailView&record={$focus->id}'>{$focus->name}</a>"; $params[] = $mod_strings['LBL_MANAGE_SUBSCRIPTIONS_TITLE']; $title = getClassicModuleTitle($focus->module_dir, $params, true); $orig_vals_str = printOriginalValues($focus); $orig_vals_array = constructDDSubscriptionList($focus); $this->ss->assign('title', $title); $this->ss->assign('enabled_subs', $orig_vals_array[0]); $this->ss->assign('disabled_subs', $orig_vals_array[1]); $this->ss->assign('enabled_subs_string', $orig_vals_str[0]); $this->ss->assign('disabled_subs_string', $orig_vals_str[1]); // FIXME we are doing this way since this view is going to be removed later // this should be with proper buttons from smarty tpls. require_once 'include/formbase.php'; $url = buildRedirectURL(); $cancelButtonClick = "SUGAR.ajaxUI.loadContent('{$url}'); return false;"; /* * Parse the module from the URL first using regular expression. * This is faster than parse_url + parse_str in first place and most of * our redirects won't go to sidecar (at least for now). */ if (preg_match('/module=([^&]+)/', $url, $matches) && !isModuleBWC($matches[1])) { parse_str(parse_url($url, PHP_URL_QUERY), $params); $script = navigateToSidecar(buildSidecarRoute($params['module'], $params['record'], translateToSidecarAction($params['action']))); $cancelButtonClick = "{$script} return false;"; } $buttons = array('<input id="save_button" title="' . $app_strings['LBL_SAVE_BUTTON_TITLE'] . '" accessKey="' . $app_strings['LBL_SAVE_BUTTON_KEY'] . '" class="button" onclick="save();this.form.action.value=\'Subscriptions\'; " type="submit" name="button" value="' . $app_strings['LBL_SAVE_BUTTON_LABEL'] . '">', '<input id="cancel_button" title="' . $app_strings['LBL_CANCEL_BUTTON_TITLE'] . '" accessKey="' . $app_strings['LBL_CANCEL_BUTTON_KEY'] . '" class="button" onclick="' . $cancelButtonClick . '" type="submit" name="button" value="' . $app_strings['LBL_CANCEL_BUTTON_LABEL'] . '">'); $this->ss->assign('BUTTONS', $buttons); $this->ss->display('modules/Campaigns/Subscriptions.tpl'); /*
echo "NAK\nRuntime exception: " . $e->getMessage(); } break; case 'redirect' == $_REQUEST['module']: // Include init after ophandlers/snmp, not before, so local.php can redefine things. require_once 'inc/ophandlers.php'; // snmp.php is an exception, it is treated by a special hack if (isset($_REQUEST['op']) and $_REQUEST['op'] == 'querySNMPData') { require_once 'inc/snmp.php'; } require_once 'inc/init.php'; try { genericAssertion('op', 'string'); $op = $_REQUEST['op']; prepareNavigation(); $location = buildRedirectURL(); // FIXME: find a better way to handle this error if ($op == 'addFile' && !isset($_FILES['file']['error'])) { throw new RackTablesError('File upload error, check upload_max_filesize in php.ini', RackTablesError::MISCONFIGURED); } fixContext(); if (!isset($ophandler[$pageno][$tabno][$op]) or !is_callable($ophandler[$pageno][$tabno][$op])) { throw new RackTablesError("Invalid navigation data for '{$pageno}-{$tabno}-{$op}'", RackTablesError::INTERNAL); } // We have a chance to handle an error before starting HTTP header. if (!isset($delayauth["{$pageno}-{$tabno}-{$op}"])) { assertPermission(); } # Call below does the job of bypass argument assertion, if such is required, # so the ophandler function doesn't have to re-assert this portion of its # arguments. And it would be even better to pass returned value to ophandler,
function updateObjectAllocation() { global $remote_username, $sic; if (!isset($_REQUEST['got_atoms'])) { unset($_GET['page']); unset($_GET['tab']); unset($_GET['op']); unset($_POST['page']); unset($_POST['tab']); unset($_POST['op']); return buildRedirectURL(NULL, NULL, $_REQUEST); } $object_id = getBypassValue(); $rf1 = $_REQUEST['rfid']; if (isset($_REQUEST['rfid'])) { // $rf1 = 1000000;//$_REQUEST['rfid']; $result = usePreparedSelectBlade("SELECT object_id FROM objecttorf WHERE rf_id = ?", array($rf1)); $row = $result->fetch(PDO::FETCH_ASSOC); if (isset($row)) { $object_id = $row['object_id']; } //получить значение из базы где rf1=njvenj //showError ('Permission deniedddddddd, "' . $object_id . '" left unchanged'); } $changecnt = 0; // Get a list of all of this object's parents, // then trim the list to only include parents that are racks $objectParents = getEntityRelatives('parents', 'object', $object_id); $parentRacks = array(); foreach ($objectParents as $parentData) { if ($parentData['entity_type'] == 'rack') { $parentRacks[] = $parentData['entity_id']; } } $workingRacksData = array(); foreach ($_REQUEST['rackmulti'] as $cand_id) { if (!isset($workingRacksData[$cand_id])) { $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); $workingRacksData[$cand_id] = $rackData; } // It's zero-U mounted to this rack on the form, but not in the DB. Mount it. if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) { $changecnt++; commitLinkEntities('rack', $cand_id, 'object', $object_id); } // It's not zero-U mounted to this rack on the form, but it is in the DB. Unmount it. if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) { $changecnt++; commitUnlinkEntities('rack', $cand_id, 'object', $object_id); } } foreach ($workingRacksData as &$rd) { applyObjectMountMask($rd, $object_id); } $oldMolecule = getMoleculeForObject($object_id); foreach ($workingRacksData as $rack_id => $rackData) { if (!processGridForm($rackData, 'F', 'T', $object_id)) { continue; } $changecnt++; // Reload our working copy after form processing. $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); applyObjectMountMask($rackData, $object_id); $workingRacksData[$rack_id] = $rackData; } if ($changecnt) { // Log a record. $newMolecule = getMoleculeForObject($object_id); usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment'])); } showFuncMessage(__FUNCTION__, 'OK', array($changecnt)); }
function cloneRSPool() { assertUIntArg('pool_id'); $pool = spotEntity('ipv4rspool', $_REQUEST['pool_id']); $rs_list = getRSListInPool($pool['id']); $tagidlist = array(); foreach ($pool['etags'] as $taginfo) { $tagidlist[] = $taginfo['id']; } $new_id = commitCreateRSPool($pool['name'] . ' (copy)', $pool['vsconfig'], $pool['rsconfig'], $tagidlist); foreach ($rs_list as $rs) { addRStoRSPool($new_id, $rs['rsip_bin'], $rs['rsport'], $rs['inservice'], $rs['rsconfig'], $rs['comment']); } showSuccess("Created a copy of pool <a href='" . makeHref(array('page' => 'ipv4rspool', 'tab' => 'default', 'pool_id' => $pool['id'])) . "'>{$pool['name']}</a>"); return buildRedirectURL('ipv4rspool', 'default', array('pool_id' => $new_id)); }
* Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'include/formbase.php'; $focus = BeanFactory::getBean('ContractTypes', $_POST['record']); if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } $check_notify = FALSE; foreach ($focus->column_fields as $field) { if (isset($_POST[$field])) { $value = $_POST[$field]; $focus->{$field} = $value; } } foreach ($focus->additional_column_fields as $field) { if (isset($_POST[$field])) { $value = $_POST[$field]; $focus->{$field} = $value; } } $return_id = $focus->save($check_notify); $GLOBALS['log']->debug("Saved record with id of " . $return_id); $url = buildRedirectURL($return_id, 'ContractTypes'); if (isset($_REQUEST['edit'])) { $url .= "&edit=" . $_REQUEST['edit']; } if (isset($_REQUEST['isDuplicate'])) { $url .= "&isDuplicate=" . $_REQUEST['isDuplicate']; } SugarApplication::redirect($url);
function redirectIfNecessary() { global $trigger, $pageno, $tabno; @session_start(); if (!isset($_REQUEST['tab']) and isset($_SESSION['RTLT'][$pageno]) and getConfigVar('SHOW_LAST_TAB') == 'yes' and permitted($pageno, $_SESSION['RTLT'][$pageno]['tabname']) and time() - $_SESSION['RTLT'][$pageno]['time'] <= TAB_REMEMBER_TIMEOUT) { redirectUser(buildRedirectURL($pageno, $_SESSION['RTLT'][$pageno]['tabname'])); } // check if we accidentaly got on a dynamic tab that shouldn't be shown for this object if (isset($trigger[$pageno][$tabno]) and !strlen(call_user_func($trigger[$pageno][$tabno]))) { $_SESSION['RTLT'][$pageno]['dont_remember'] = 1; redirectUser(buildRedirectURL($pageno, 'default')); } if (is_array(@$_SESSION['RTLT'][$pageno]) && isset($_SESSION['RTLT'][$pageno]['dont_remember'])) { unset($_SESSION['RTLT'][$pageno]['dont_remember']); } // store the last visited tab name if (isset($_REQUEST['tab'])) { $_SESSION['RTLT'][$pageno] = array('tabname' => $tabno, 'time' => time()); } session_commit(); // if we are continuing to run, unlock session data }
function Update() { // Read uploaded file $lines = file($_FILES['userfile']['tmp_name']); // add file contents to facter array foreach ($lines as $line_num => $line) { $tmpfacter = explode("=>", $line, 2); $facter[trim($tmpfacter[0])] = str_replace('"', '', trim($tmpfacter[1])); } // Fix fqdn since all fields have \n inn them $facter['fqdn'] = str_replace("\n", "", $facter['fqdn']); // Check if it's an existing machine // 2011-08-31 <*****@*****.**> // * expanded query to try to match via facter Serialnumber to be able to // match unnamed HW assets. Serial is more precise and less likely to be changed. if (array_key_exists('serialnumber', $facter) && strlen($facter['serialnumber']) > 0 && $facter['serialnumber'] != 'Not Specified') { $query = "select id from RackObject where name = \"{$facter['fqdn']}\" OR asset_no = \"{$facter['serialnumber']}\" LIMIT 1"; } else { $query = "select id from RackObject where name = \"{$facter['fqdn']}\" LIMIT 1"; } unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; } // If it's a new machine if (!isset($id)) { // Check to see if it's a physical machine and get the correct id for Server if ($facter['is_virtual'] == "false") { // Find server id $query = "select dict_key from Dictionary where dict_value='Server' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(); if ($resultarray) { $virtual = $resultarray[0]['dict_key']; } } else { // Find virtual id $query = "select dict_key from Dictionary where dict_value='VM' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $virtual = $resultarray[0]['dict_key']; } } // Add the new machine $newmachine = commitAddObject($facter['fqdn'], "", $virtual, $value = ""); $type_id = getObjectTypeID($newmachine); } else { // Just set some fields I use later down for updating $newmachine = $id; $machineupdate = 1; $type_id = getObjectTypeID($newmachine); } // 2011-08-31 <*****@*****.**> // * Update (unique) name of object. if (array_key_exists('serialnumber', $facter) && strlen($facter['serialnumber']) > 0 && $facter['serialnumber'] != 'Not Specified') { unset($result); $query = "select * from RackObject where asset_no = \"{$facter['serialnumber']}\" LIMIT 1"; $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; $label = $resultarray[0]['label']; // Update FQDN commitUpdateObject($id, $facter['fqdn'], $label, 'no', $facter['serialnumber'], 'Facter Import::Update Common Name'); } } // Find HW type id // 2011-08-31 <*****@*****.**> // * adjust format to match default Dictionary Sets if ($facter['is_virtual'] == "false") { $iHWTemp = preg_match('([a-zA-Z]{1,})', $facter['manufacturer'], $matches); $sManufacturer = $matches[0]; $sHW = preg_replace('(\\ )', '\\1%GPASS%', $facter['productname']); $sHWType = $sManufacturer . ' ' . $sHW; $query = "select id from Attribute where name='HW type' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update HW type $hw_dict_key = getdict($sHWType, $chapter = 11); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $hw_dict_key); } //Also Check if HYPERVISOR if (isset($facter['is_hypervisor'])) { $query = "select id from Attribute where name REGEXP '^ *Hypervisor Type\$' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update Hypervisor type $hypervisor_type = $facter['is_hypervisor']; $hypervisor_type_dict_key = getdict($hw = $hypervisor_type, $chapter = 10005); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $hypervisor_type_dict_key); } //Set Value to Yes $query = "select id from Attribute where name REGEXP '^ *Hypervisor' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update Hypervisor type $hypervisor = "Yes"; $hypervisor_dict_key = getdict($hypervisor, $chapter = 29); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $hypervisor_dict_key); } //Find Running VMs $vms = explode(',', $facter['vms']); $vm_count = count($vms); for ($i = 0; $i < $vm_count; $i++) { //addToParent addVmToParent($vms[$i], $newmachine); } } else { $query = "select id from Attribute where name REGEXP '^ *Hypervisor' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update Hypervisor type $hypervisor = "No"; $hypervisor_dict_key = getdict($hypervisor, $chapter = 29); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = ""); } } } // Find SW type id (OS) $query = "select id from Attribute where name REGEXP '^ *SW type\$' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update SW type (OS) $osrelease = $facter['operatingsystem'] . '%GSKIP%' . $facter['operatingsystem'] . ' V' . $facter['operatingsystemrelease']; $os_dict_key = getdict($hw = $osrelease, $chapter = 13); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $os_dict_key); } //Generic to read in from file $manifest_file = fopen("../plugins/manifest", "r") or die("Could not open manifest, make sure it is in the websrv root and called manifest \n"); while (!feof($manifest_file)) { $tmp_line = fgets($manifest_file); if (!empty($tmp_line) && !preg_match("/\\/\\//", $tmp_line)) { @(list($Fact, $Attr, $Chapter) = array_map('trim', explode(',', $tmp_line, 3))); //check for multi-facter names if (strstr($Fact, '.')) { @(list($Fact1, $Fact2) = array_map('trim', explode('.', $Fact))); $value = $facter[$Fact1] . ' ' . $facter[$Fact2]; if (!isset($facter[$Fact1]) || !isset($facter[$Fact2])) { echo "WARNING: {$Fact1} or {$Fact2} does not exist in Facter for this object \n"; continue; } } else { if (!isset($facter[$Fact])) { echo "WARNING: {$Fact} does not exist in Facter for this object \n"; continue; } else { $value = $facter[$Fact]; } } $query = "select id from Attribute where name REGEXP '^ *{$Attr}' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); $id = $resultarray[0]['id']; if (!valid($type_id, $id)) { echo "WARNING: Not a valid Mapping for {$Fact} to {$Attr} for objectType {$type_id} \n"; } else { if ($resultarray) { if (!empty($Chapter)) { $name = $value; $name_dict_key = getdict($hw = $name, $chapter = $Chapter); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $name_dict_key); } else { if (preg_match("/[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4}/", $value) || preg_match("/[0-9]{1,2}\\-[0-9]{1,2}\\-[0-9]{4}/", $value) || preg_match("/[0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2}/", $value)) { //handle dates commitUpdateAttrValue($newmachine, $id, strtotime($value)); } else { commitUpdateAttrValue($newmachine, $id, $value); } } } } } } fclose($manifest_file); // Add network interfaces // Create an array with interfaces $nics = explode(',', $facter['interfaces']); // Go through all interfaces and add IP and MAC $count = count($nics); for ($i = 0; $i < $count; $i++) { // Remove newline from the field $nics[$i] = str_replace("\n", "", $nics[$i]); // We generally don't monitor sit interfaces. // We don't do this for lo interfaces, too // 2011-08-31 <*****@*****.**> // * Only Document real interfaces, dont do bridges, bonds, vlan-interfaces // when they have no IP defined. if (preg_match('(_|^(bond|lo|sit|vnet|virbr|veth|peth))', $nics[$i]) != 0) { // do nothing } else { // Get IP if (isset($facter['ipaddress_' . $nics[$i]])) { $ip = $facter['ipaddress_' . $nics[$i]]; } // Get MAC if (isset($facter['macaddress_' . $nics[$i]])) { $mac = $facter['macaddress_' . $nics[$i]]; } //check if VM or not if ($facter['is_virtual'] == "false") { // Find 1000Base-T id $query = "select id from PortOuterInterface where oif_name REGEXP '^ *1000Base-T\$' LIMIT 1"; } else { // Find virtual port id $query = "select id from PortOuterInterface where oif_name REGEXP '^ *virtual port\$' LIMIT 1"; } unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $nictypeid = $resultarray[0]['id']; } // Remove newline from ip $ip = str_replace("\n", "", $ip); // Check to se if the interface has an ip assigned $query = "SELECT object_id FROM IPv4Allocation where object_id={$newmachine} and name=\"{$nics[$i]}\""; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { unset($id); $ipcheck = $resultarray; } // Check if it's been configured a port already $query = "SELECT id,iif_id FROM Port where object_id={$newmachine} and name=\"{$nics[$i]}\""; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $portid = $resultarray[0]['id']; unset($id); $portcheck = $resultarray; } // Add/update port // 2011-08-31 <*****@*****.**> // * Don't touch already existing complex ports if ($resultarray[0]['type'] != 9) { if (count($portcheck) == 1) { commitUpdatePort($newmachine, $portid, $nics[$i], $nictypeid, "Ethernet port", "{$mac}", NULL); } else { commitAddPort($object_id = $newmachine, $nics[$i], $nictypeid, 'Ethernet port', "{$mac}"); } } else { //We've got a complex port, don't touch it, it raises an error with 'Database error: foreign key violation' } if (count($ipcheck) == 1) { if ($ip) { updateAddress(ip_parse($ip), $newmachine, $nics[$i], 'regular'); } } else { if ($ip) { bindIpToObject(ip_parse($ip), $newmachine, $nics[$i], 'regular'); } } unset($portcheck); unset($ipcheck); unset($ip); unset($mac); } } //uncomment to start using auto tags //addTagToObject($facter, $newmachine); return buildRedirectURL(); }