public function initialize(AgaviContext $context, array $parameters = array()) { parent::initialize($context, $parameters); $this->__type = $this->getParameter('type'); $this->__oids = AppKitArrayUtil::trimSplit($this->getParameter('oids')); if (!in_array($this->__type, array(self::TYPE_HOST, self::TYPE_SERVICE))) { throw new AppKitModelException('Parameter type not valid!'); } if (!is_array($this->__oids)) { throw new AppKitModelException('oids must be an array'); } $model = $this->getContext()->getModel("ApiDataRequest", "Api"); $this->__request = $model->createRequestDescriptor($parameters["connection"]); }
public function dispatchCommands() { $dispatcher = $this->getContext()->getModel("Commands.CommandDispatcher", "Api"); $this->context->getLoggerManager()->log(print_r($this->selection, 1)); $this->selection = AppKitArrayUtil::uniqueMultidimensional($this->selection); $this->context->getLoggerManager()->log(print_r($this->selection, 1)); AppKitLogger::debug("Trying to send commands, targets: %s , data: %s ", json_encode($this->selection), json_encode($this->data)); foreach ($this->selection as $target) { $console = $this->getConsoleInstance($target['instance']); $dispatcher->setConsoleContext($console); AppKitLogger::debug("Submitting command %s to %s", $this->command, json_encode($target)); $dispatcher->submitCommand($this->command, array_merge($target, $this->data)); AppKitLogger::debug("Finished submitting command"); } }
public function executeJson(AgaviRequestDataHolder $rd) { // init $jsonData = array('result' => array('count' => 0, 'data' => array())); $model = $this->getContext()->getModel('Icinga.ApiSimpleDataProvider', 'Web'); $srcId = $rd->getParameter('src_id'); $filter = $rd->getParameter('filter'); $result = $model->setSourceId($srcId)->setFilter($filter)->fetch(); $jsonData['result']['data'] = $result; // store final count and convert $jsonData['result']['count'] = count($jsonData['result']['data']); if (($template = $model->getTemplateCode()) !== false) { $jsonData['result']['template'] = $template; } AppKitArrayUtil::toUTF8_recursive($jsonData); $jsonDataEnc = json_encode($jsonData); return $jsonDataEnc; }
/** * Converts an array containing ISO-8859-1 string to utf-8 * * @param array $obj */ public static function toISO_recursive(array &$obj) { foreach ($obj as $field => &$value) { if (is_string($value)) { $value = utf8_decode($value); } else { if (is_array($value)) { AppKitArrayUtil::toISO_recursive($value); } } } }
/** * Tries to detect username * * Sets appropriate data from header * * @return null|string */ public function determineUsername() { $source = $this->getVarSource(); foreach (self::$source_map as $class_target => $config_target) { $search_keys = AppKitArrayUtil::trimSplit($this->getParameter($config_target, self::$source_map_defaults[$class_target])); $search_value = null; // Looking for multiple keys and use the first match foreach ($search_keys as $search_key) { if ($source->getParameter($search_key) !== null) { $search_value = $source->getParameter($search_key); $this->log('Auth.Provider.HTTPBasicAuthentification: Got header data: %s=%s', $search_key, $search_value, AgaviILogger::DEBUG); break; } } if ($search_value !== null) { if ($class_target == 'auth_name') { // Fixes mixed auth models (case-sensitive and case-insensitive) // see #3714 (Thanks dirk) if ($this->getParameter('auth_lowercase_username', false) == true) { $search_value = strtolower($search_value); } if ($strip = strtolower($this->getParameter('auth_strip_domain', ''))) { $m = '~@' . preg_quote($strip, '~') . '~'; $this->{$class_target} = preg_replace($m, '', $search_value); } else { $this->{$class_target} = $search_value; } } else { $this->{$class_target} = $search_value; } } else { $this->log('Auth.Provider.HTTPBasicAuthentification: No value found for %s/%s', $class_target, $config_target, AgaviILogger::DEBUG); } } if ($this->auth_type) { $this->auth_type = strtolower($this->auth_type); } $this->log('Auth.Provider.HTTPBasicAuthentification: Got data (auth_name=%s, auth_type=%s)', $this->auth_name, $this->auth_type, AgaviLogger::DEBUG); return $this->auth_name; }
/** * Adding order parts from main query to subquery which delivers * the recordset * https://dev.icinga.org/issues/2215 * @param string $query * @return string */ private function fixOrdersInSubqueries(&$query) { list($mainTable, $mainAlias) = $this->getTableParts($query); $m = array(); if (preg_match('/ORDER\\s+BY\\s+(.+)(;|$)/i', $query, $m)) { $fields = AppKitArrayUtil::trimSplit($m[1]); $pparse = new AppKitStringParanthesesParser($query, AppKitStringParanthesesParser::STRIP_PARANTHESES); if ($pparse->count()) { foreach ($pparse as $part) { $m = array(); if (preg_match('/^\\s*(SELECT\\s+[\\w\\.\\,\\s]+\\s+FROM\\s+' . preg_quote($mainTable, '/') . '[^$]+)/', $part, $m)) { $subQuery = $m[0]; list($subTable, $subAlias) = $this->getTableParts($subQuery); if ($subTable == $mainTable && !preg_match('/ORDER BY/i', $subQuery)) { $orderParts = array(); $newSub = $subQuery; foreach ($fields as $field) { $newOrder = preg_replace('/^\\w+\\./', $subAlias . '.', $field); $newField = preg_replace('/\\s+.+$/', '', $newOrder); $orderParts[] = $newOrder; $newSub = preg_replace('/^\\s*(SELECT\\s+(DISTINCT)?\\s*)' . $subAlias . '/i', '\\1 ' . $newField . ', ' . $subAlias, $subQuery); } $newSub = $newSub . ' ORDER BY ' . implode(', ', $orderParts); $query = preg_replace('/' . preg_quote($subQuery, '/') . '/', $newSub, $query); } break; } } } } return $query; }
/** * @group AppKit */ public function testEncodingProcessor1() { $test = array('test1' => 'ÜÜöö%%123', 'test2' => array('ÖÖÖ', 'ÄÄÄ', 'ßßß')); $work = $test; AppKitArrayUtil::toISO_recursive($work); $this->assertNotEquals($test, $work); AppKitArrayUtil::toUTF8_recursive($work); $this->assertEquals($test, $work); }
/** * Default groups used by this provider * @return array List of groups */ public function getDefaultGroups() { $string = $this->getParameter('auth_groups'); if ($string) { return AppKitArrayUtil::trimSplit($string); } }
public function combinedData() { $cat_out = array(); $cronks_out = array(); $categories = $this->getCategoryModel()->getCategories(); $cronks = $this->getCronks(); foreach ($categories as $category_name => $category) { $tmp = array(); foreach ($cronks as $cronk) { // skipping hidden cronks for the output if ($cronk['hide'] == true) { continue; } if (AppKitArrayUtil::matchAgainstStringList($cronk['categories'], $category_name)) { $tmp[] = $cronk; } } if ($count = count($tmp)) { $cronks_out[$category_name] = array('rows' => $tmp, 'success' => true, 'total' => $count); $cat_out[] = $category; } } $data = array('categories' => $cat_out, 'cronks' => $cronks_out); return $data; }
/** * Append customvariables to query */ private function parseCustomVariables() { if (!empty($this->view['customvariables'])) { foreach ($this->view['customvariables'] as $customvariable) { $params = $customvariable['params']; $variables = AppKitArrayUtil::trimSplit($params['list']); if (!isset($params['leftJoin'])) { continue; } $leftJoin = $params['leftJoin']; $prefix = 'cv_'; if (isset($params['prefix'])) { $prefix = $params['prefix']; } foreach ($variables as $variable) { $canonicalName = strtolower($variable); $safeName = $prefix . $canonicalName; $this->currentQuery->leftJoin($leftJoin . ' AS ' . $safeName . ' WITH ' . $safeName . '.varname=?', $variable); $this->currentQuery->addSelect($safeName . '.varvalue AS value'); $filterName = $canonicalName . '_value'; $this->view['filter'][$filterName] = array('name' => $filterName, 'type' => 'dql', 'calls' => array(array('type' => 'resolve', 'arg' => $safeName . '.varvalue'))); $this->resolvedCustomVariables[$filterName] = $safeName . '.varvalue'; } } } }
/** * Create of update a category * @param array $cat * @return Ambigous <NULL, CronkCategory> */ public function createCategory(array $cat) { AppKitArrayUtil::swapKeys($cat, self::$cat_map, true); $category = null; if ($this->agaviUser->hasCredential('icinga.cronk.category.admin') && isset($cat['cc_uid'])) { $category = AppKitDoctrineUtil::createQuery()->from('CronkCategory cc')->andWhere('cc.cc_uid=?', $cat['cc_uid'])->execute()->getFirst(); } if (!$category instanceof CronkCategory || !$category->cc_id > 0) { $category = new CronkCategory(); } $category->fromArray($cat); $category->save(); return $category; }
private function fetchDQLViews(DOMXPath $xpath) { $dqlRoot = $xpath->query('//ae:configuration/node()'); foreach ($dqlRoot as $node) { if ($node->nodeType != XML_ELEMENT_NODE) { continue; } $this->parseDQLPart($node); } foreach ($this->views as $name => &$vals) { if (!$vals["base"]) { continue; } if (!isset($this->views[$vals["base"]])) { AppKitLogger::warn("View %s references to unknown base query %s", $name, $vals["base"]); continue; } $base = $this->views[$vals["base"]]; $vals = AppKitArrayUtil::replaceRecursive($base, $vals); } }