/** * Mark the last started query as stopped. This can be used for timing of queries. * * @return void */ public function stopQuery() { $result = microtime() - $this->startTime; if ($this->logger->isDebugEnabled()) { $this->logger->debug("query done for {$result}"); } }
/** * This will resolve the given ModelAndView to a view in the filesystem * (an absolute path to a file). * * @param ModelAndView $modelAndView What to render. * * @see Ding\Mvc.IViewResolver::resolve() * @return HttpView */ public function resolve(ModelAndView $modelAndView) { $name = $modelAndView->getName(); $path = $this->_path . DIRECTORY_SEPARATOR . $this->_prefix . $name . $this->_suffix; if ($this->_logger->isDebugEnabled()) { $this->_logger->debug('Using viewpath: ' . $path); } return new HttpView($modelAndView, $path); }
/** * Closes the connection to ami. * * @return void */ public function close() { if ($this->_logger->isDebugEnabled()) { $this->_logger->debug('Closing connection to asterisk.'); } @stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR); }
public function updateCollaboratorPermission(IShareable $object, AbstractEyeosPrincipal $collaborator, IPermission $permission) { try { if ($object->getId() === null) { throw new EyeNullPointerException('$object ID cannot be null.'); } $handlerClassName = null; foreach (self::getAllShareableObjectsHandlers() as $handler) { if ($handler->checkType($object)) { $handlerClassName = get_class($handler); break; } } if ($handlerClassName === null) { throw new EyeHandlerNotFoundException('Unable to find a ShareableObjectHandler for object of class ' . get_class($object) . '.'); } $owner = $object->getShareOwner(); SecurityManager::getInstance()->checkPermission($object, new SharePermission(array('updatecollaborator'), $collaborator)); //prepare query array $shareInfoQuery = array(self::SHAREINFO_KEY_OWNERID => $owner->getId(), self::SHAREINFO_KEY_SHAREABLEID => $object->getId(), self::SHAREINFO_KEY_COLLABORATORID => $collaborator->getId(), self::SHAREINFO_KEY_PERMISSIONACTIONS => $permission->getActionsAsString(), self::SHAREINFO_KEY_HANDLERCLASSNAME => $handlerClassName); $this->getProvider()->updateShareInfo($owner, $shareInfoQuery); // TODO: we could also add the ShareInfo object containing the old permission as a // "related source" of the event $event = new SharingEvent(new BasicShareInfo($owner, $object, $collaborator, $permission, $handlerClassName)); foreach ($this->listeners as $listener) { $listener->collaboratorPermissionUpdated($event); } } catch (Exception $e) { self::$Logger->warn('Unable to update collaborator ' . $collaborator->getName() . ' permissions for object of class ' . get_class($object) . '.'); if (self::$Logger->isDebugEnabled()) { self::$Logger->debug(ExceptionStackUtil::getStackTrace($e, false)); } throw $e; } }
public function checkPermission($object, IPermission $perm, LoginContext $context = null) { try { if ($object === null) { throw new EyeNullPointerException('$object cannot be null.'); } if ($perm === null) { throw new EyeNullPointerException('$perm cannot be null.'); } if ($context === null) { $currentProcess = ProcManager::getInstance()->getCurrentProcess(); if ($currentProcess === null) { self::$Logger->warn('Cannot check permission on object of class ' . get_class($object) . ': No current process.'); throw new EyeAccessControlException('Access denied: No current process.'); } $context = $currentProcess->getLoginContext(); if ($context === null) { //self::$Logger->warn('Cannot check permission on object of class ' . get_class($object) . ': No LoginContext found in current process.'); //throw new EyeAccessControlException('Access denied: No LoginContext found in current process.'); self::$Logger->info('Initializing blank login context for permission check on object of class ' . get_class($object) . '.'); $context = new LoginContext('eyeos-login', new Subject()); } } $checker = new SecurityChecker(); $checker->doCheck($object, $perm, $context); } catch (Exception $e) { self::$Logger->error('Cannot perform permission check: ' . $e->getMessage()); if (self::$Logger->isDebugEnabled()) { self::$Logger->debug(ExceptionStackUtil::getStackTrace($e, false)); } throw $e; } }
public function updateTag(ITag $tag, ITag $newTag) { SecurityManager::getInstance()->checkPermission($tag, new SimplePermission(null, array('update'))); try { $this->getProvider()->updateTag($tag, $newTag); } catch (Exception $e) { self::$Logger->error('Unable to update tag "' . $tag . '": ' . $e->getMessage()); if (self::$Logger->isDebugEnabled()) { self::$Logger->debug(ExceptionStackUtil::getStackTrace($e, false)); } throw $e; } }
/** * Make an HTTP request * * @return string API results * @ignore */ function http($url, $method, $postfields = NULL, $headers = array()) { list($usec, $sec) = explode(" ", microtime()); $begin = (double) $usec + (double) $sec; $this->http_info = array(); $ci = curl_init(); /* Curl settings */ curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent); curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout); curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ci, CURLOPT_ENCODING, ""); curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer); curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader')); curl_setopt($ci, CURLOPT_HEADER, FALSE); curl_setopt($ci, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); $config = HaloEnv::get('config'); $debug = $config['app']['debug']; if (!isEmptyString($this->http_proxy)) { curl_setopt($ci, CURLOPT_PROXY, $this->http_proxy); if (Logger::isDebugEnabled()) { Logger::DEBUG('URL:[' . $url . '][PROXY:' . $this->http_proxy . ']', __FILE__, __LINE__, 'sina_api'); } } if ($this->cookie) { if (isset($this->cookie['SUW'])) { $this->cookie['SUW'] = urldecode($this->cookie['SUW']); curl_setopt($ci, CURLOPT_REFERER, "http://weibo.cn"); } else { curl_setopt($ci, CURLOPT_REFERER, "http://weibo.com"); } $cookie = http_build_query($this->cookie, null, '; '); curl_setopt($ci, CURLOPT_COOKIE, $cookie); } switch ($method) { case 'POST': curl_setopt($ci, CURLOPT_POST, TRUE); if (!empty($postfields)) { curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); $this->postdata = $postfields; } break; case 'DELETE': curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE'); if (!empty($postfields)) { $url = "{$url}?{$postfields}"; } } if (isset($this->access_token) && $this->access_token) { $headers[] = "Authorization: OAuth2 " . $this->access_token; } $headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR']; curl_setopt($ci, CURLOPT_URL, $url); curl_setopt($ci, CURLOPT_HTTPHEADER, $headers); curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE); $response = curl_exec($ci); $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); $this->http_info = array_merge($this->http_info, curl_getinfo($ci)); $this->url = $url; if ($this->http_code != 200) { if (curl_errno($ci) == CURLE_OPERATION_TIMEOUTED) { Logger::ERROR("sina api timeout url is " . $url . ", sever ip is " . $_SERVER['REMOTE_ADDR'], "", "", "sina_api_timeout"); // $msg = urlencode("Fatal error sina api is timeout on ip ".$_SERVER['REMOTE_ADDR']); // system('wget "http://223.202.17.147/insert_information.php?email=junqiang.liu@yolu-inc.com&info='.$msg.'&pass=fuck18324hfbdhfkgmxc" -O /dev/null -o /dev/null'); } $e = new Exception(); Logger::ERROR("&&&&&& Curl error is: " . print_r(curl_error($ci), true), "", "", "sina_api_error"); Logger::ERROR(sprintf("====\ncode: %d\nurl:%s\nresponse:%s====\nstack:%s\ninfo:%s\n", $this->http_code, $url, $response, $e->getTraceAsString(), print_r(curl_getinfo($ci), true)), __FILE__, __LINE__, 'sina_api_error'); } if ($this->debug) { echo "<hr/>=====post data======\r\n<pre>"; // var_dump($postfields); echo '</pre><hr/>=====info=====' . "\r\n<pre>"; // var_dump( curl_getinfo($ci) ); echo '</pre><hr/>=====$response=====' . "\r\n"; // var_dump( $response ); } curl_close($ci); return $response; }
/** * Constructor. * * @param array $options options. * * @return void */ protected function __construct(array $options) { // Setup logger. $this->_logger = \Logger::getLogger(get_class($this)); $this->_logDebugEnabled = $this->_logger->isDebugEnabled(); $soullessArray = array(); $this->_beanAliases = $soullessArray; $this->_beanDefs = $soullessArray; $this->_beans = $soullessArray; $this->_shutdowners = $soullessArray; $this->_resources = $soullessArray; $this->_eventListeners = $soullessArray; $this->_properties = $soullessArray; // Merge options with our defaults. self::$_options = array_replace_recursive(self::$_options, $options); $this->registerProperties(self::$_options['properties']); $sapi = php_sapi_name(); if (function_exists('pcntl_signal')) { if ($sapi == 'cgi' || $sapi == 'cli') { $signals = array(SIGQUIT, SIGHUP, SIGINT, SIGCHLD, SIGTERM, SIGUSR1, SIGUSR2); $handler = array($this, 'signalHandler'); foreach ($signals as $signal) { pcntl_signal($signal, $handler); } pcntl_sigprocmask(SIG_UNBLOCK, $signals); } } set_error_handler(array($this, 'errorHandler')); register_shutdown_function(array($this, 'shutdownHandler')); $this->_lifecycleManager = new BeanLifecycleManager(); $this->_dispatcherTemplate = new DispatcherImpl(); $this->_aspectManager = new AspectManager(); $this->_aspectManager->setCache(DummyCacheImpl::getInstance()); $this->_beanDefCache = DummyCacheImpl::getInstance(); $this->_beanCache = DummyCacheImpl::getInstance(); $this->registerBeanDefinitionProvider(new Core(self::$_options)); $this->_reflectionFactory = $this; $this->_reflectionFactory = $this->getBean('dingReflectionFactory'); $this->_proxyFactory = $this->getBean('dingProxyFactory'); $this->_beanDefCache = $this->getBean('dingDefinitionsCache'); $this->_beanCache = $this->getBean('dingBeanCache'); $this->_lifecycleManager = $this->getBean('dingLifecycleManager'); $this->_aspectManager = $this->getBean('dingAspectManager'); $this->_dispatcherTemplate = $this->getBean('dingAspectCallDispatcher'); // Set drivers if (isset(self::$_options['bdef']['xml'])) { $xmlDriver = $this->getBean('dingXmlBeanDefinitionProvider'); } if (isset(self::$_options['bdef']['yaml'])) { $yamlDriver = $this->getBean('dingYamlBeanDefinitionProvider'); } $this->getBean('dingPropertiesDriver'); $this->getBean('dingMessageSourceDriver'); $this->getBean('dingMethodInjectionDriver'); // All set, continue. if (isset(self::$_options['bdef']['annotation'])) { $this->getBean('dingAnnotationDiscovererDriver'); $this->getBean('dingAnnotationBeanDefinitionProvider'); $this->getBean('dingAnnotationValueDriver'); $this->getBean('dingAnnotationResourceDriver'); $this->getBean('dingAnnotationInjectDriver'); $this->getBean('dingAnnotationInitDestroyMethodDriver'); $this->getBean('dingAnnotationRequiredDriver'); $this->getBean('dingMvcAnnotationDriver'); } $this->_lifecycleManager->afterConfig(); }
/** * @abstract Methode pour un message d'erreur * @param string $message */ public static function Error($message) { $date = date(Logger::DATEFORMAT); if (Logger::isDebugEnabled()) { return sprintf(Logger::HTMLERRORFORMAT, $date, $message); } }