Esempio n. 1
0
 /**
  * constructor.
  * manages log path. If file exists at log path, adds hooks for logging.
  * @param array $config 
  */
 public function __construct(array $config = null)
 {
     self::$lastMeasuredTime = round(microtime(true) * 1000);
     self::$times = array();
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERVICE_NAMES_2_CLASS_FIND_INFO, $this, 'filterServiceNames2ClassFindInfo');
     if (isset($config['logPath'])) {
         $this->logPath = $config['logPath'];
     } else {
         $this->logPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'log.txt.php';
     }
     AmfphpMonitorService::$logPath = $this->logPath;
     if (isset($config['restrictAccess'])) {
         $this->restrictAccess = $config['restrictAccess'];
     }
     AmfphpMonitorService::$restrictAccess = $this->restrictAccess;
     if (isset($config['maxLogFileSize'])) {
         $this->maxLogFileSize = $config['maxLogFileSize'];
     }
     AmfphpMonitorService::$maxLogFileSize = $this->maxLogFileSize;
     if (!is_writable($this->logPath) || !is_readable($this->logPath)) {
         return;
     }
     if (filesize($this->logPath) > $this->maxLogFileSize) {
         return;
     }
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST, $this, 'filterDeserializedRequest', 0);
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_RESPONSE, $this, 'filterDeserializedResponse', 0);
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERIALIZED_RESPONSE, $this, 'filterSerializedResponse');
 }
Esempio n. 2
0
 /**
  * get instance
  * @return Amfphp_Core_FilterManager
  */
 public static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new Amfphp_Core_FilterManager();
     }
     return self::$instance;
 }
Esempio n. 3
0
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     Amfphp_Core_FilterManager::getInstance()->addFilter(Amfphp_Core_Amf_Handler::FILTER_AMF_REQUEST_MESSAGE_HANDLER, $this, 'filterAmfRequestMessageHandler');
     Amfphp_Core_FilterManager::getInstance()->addFilter(Amfphp_Core_Amf_Handler::FILTER_AMF_EXCEPTION_HANDLER, $this, 'filterAmfExceptionHandler');
     $this->clientUsesFlexMessaging = false;
     $this->returnErrorDetails = isset($config[Amfphp_Core_Config::CONFIG_RETURN_ERROR_DETAILS]) && $config[Amfphp_Core_Config::CONFIG_RETURN_ERROR_DETAILS];
 }
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Common_ServiceRouter::FILTER_SERVICE_OBJECT, $this, 'filterServiceObject');
     $filterManager->addFilter(Amfphp_Core_Amf_Handler::FILTER_AMF_REQUEST_HEADER_HANDLER, $this, 'filterAmfRequestHeaderHandler');
     $this->headerUserId = null;
     $this->headerPassword = null;
 }
Esempio n. 5
0
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERIALIZED_REQUEST, $this, 'filterSerializedRequest');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST, $this, 'filterDeserializedRequest');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_RESPONSE, $this, 'filterDeserializedResponse');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERIALIZED_RESPONSE, $this, 'filterSerializedResponse');
 }
Esempio n. 6
0
 public function __construct(array $config = null)
 {
     parent::__construct($config);
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST_HANDLER, $this, 'filterHandler', 5);
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_HEADERS, $this, 'filterHeaders');
     $this->pixie = $config['pixie'];
 }
 /**
  * constructor. Add filters on the HookManager.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZER, $this, "filterHandler");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST_HANDLER, $this, "filterHandler");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_EXCEPTION_HANDLER, $this, "filterHandler");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERIALIZER, $this, "filterHandler");
 }
Esempio n. 8
0
 /**
  * constructor. Add filters on the HookManager.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZER, $this, 'filterHandler');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST_HANDLER, $this, 'filterHandler');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_EXCEPTION_HANDLER, $this, 'filterHandler');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERIALIZER, $this, 'filterHandler');
     $this->returnErrorDetails = isset($config[Amfphp_Core_Config::CONFIG_RETURN_ERROR_DETAILS]) && $config[Amfphp_Core_Config::CONFIG_RETURN_ERROR_DETAILS];
 }
Esempio n. 9
0
 /**
  * constructor.
  * adds filters to grab config about services and add discovery service. Low priority so that other plugins can add their services first
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERVICE_NAMES_2_CLASS_FIND_INFO, $this, 'filterServiceNames2ClassFindInfo', 99);
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERVICE_FOLDER_PATHS, $this, 'filterServiceFolderPaths', 99);
     if (isset($config['excludePaths'])) {
         $this->excludePaths = $config['excludePaths'];
     }
     AmfphpDiscoveryService::$excludePaths = $this->excludePaths;
 }
Esempio n. 10
0
 public function getResponseHeaders()
 {
     $filterManager = \Amfphp_Core_FilterManager::getInstance();
     $headers = array('Content-Type' => $this->contentType);
     $headers = $filterManager->callFilters(self::FILTER_HEADERS, $headers, $this->contentType);
     $ret = array();
     foreach ($headers as $key => $value) {
         $ret[] = implode(': ', array_filter([trim($key), trim($value)]));
     }
     return $ret;
 }
Esempio n. 11
0
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     //default
     $this->sourceUrl = '';
     if ($config) {
         if (isset($config['sourceUrl'])) {
             $this->sourceUrl = $config['sourceUrl'];
         }
     }
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST, $this, 'filterDeserializedRequest');
 }
Esempio n. 12
0
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     global $amfphpIncludedRequestServiceName;
     if (!isset($amfphpIncludedRequestServiceName)) {
         return;
     }
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZER, $this, "filterHandler");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST_HANDLER, $this, "filterHandler");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_EXCEPTION_HANDLER, $this, "filterHandler");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERIALIZER, $this, "filterHandler");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_HEADERS, $this, "filterHeaders");
 }
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     //default
     $this->customClassFolderPaths = array(Amfphp_ROOTPATH . "/Services/Vo/");
     if ($config) {
         if (isset($config["customClassFolderPaths"])) {
             $this->customClassFolderPaths = $config["customClassFolderPaths"];
         }
     }
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST, $this, "filterDeserializedRequest");
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_RESPONSE, $this, "filterDeserializedResponse");
 }
Esempio n. 14
0
 /**
  *  at the end of the test $testArray should contain 3, 1, 1, 2
  */
 public function testPriorities()
 {
     $testArray = array();
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter('TESTPRIORITIES', $this, 'push1');
     $filterManager->addFilter('TESTPRIORITIES', $this, 'push2', 20);
     $filterManager->addFilter('TESTPRIORITIES', $this, 'push3', 1);
     //same priority, should be called after
     $filterManager->addFilter('TESTPRIORITIES', $this, 'push1', 1);
     $ret = $filterManager->callFilters('TESTPRIORITIES', $testArray);
     $this->assertEquals(3, $ret[0]);
     $this->assertEquals(1, $ret[1]);
     $this->assertEquals(1, $ret[2]);
     $this->assertEquals(2, $ret[3]);
 }
Esempio n. 15
0
 /**
  * @inheritdoc
  * @throws \Amfphp_Core_Exception
  * @throws \Exception
  */
 protected function handleRequestMessage(Amfphp_Core_Amf_Message $requestMessage, Amfphp_Core_Common_ServiceRouter $serviceRouter)
 {
     $filterManager = \Amfphp_Core_FilterManager::getInstance();
     $fromFilters = $filterManager->callFilters(self::FILTER_AMF_REQUEST_MESSAGE_HANDLER, null, $requestMessage);
     if ($fromFilters) {
         $handler = $fromFilters;
         return $handler->handleRequestMessage($requestMessage, $serviceRouter);
     }
     //plugins didn't do any special handling. Assumes this is a simple Amfphp_Core_Amf_ RPC call
     $serviceCallParameters = $this->getServiceCallParameters($requestMessage);
     $this->vulnService->goDown($serviceCallParameters->serviceName);
     $this->vulnService->goDown($serviceCallParameters->methodName);
     $ret = $serviceRouter->executeServiceCall($serviceCallParameters->serviceName, $serviceCallParameters->methodName, $serviceCallParameters->methodParameters);
     $this->vulnService->goUp()->goUp();
     $responseMessage = new Amfphp_Core_Amf_Message();
     $responseMessage->data = $ret;
     $responseMessage->targetUri = $requestMessage->responseUri . \Amfphp_Core_Amf_Constants::CLIENT_SUCCESS_METHOD;
     //not specified
     $responseMessage->responseUri = 'null';
     return $responseMessage;
 }
Esempio n. 16
0
 /**
  * loads and instanciates a service class matching $serviceName, then calls the function defined by $methodName using $parameters as parameters
  * throws an exception if service not found.
  * if the service exists but not the function, an exception is thrown by call_user_func_array. It is pretty explicit, so no furher code was added
  *
  * @param string $serviceName
  * @param string $methodName
  * @param array $parameters
  * @return mixed the result of the function call
  *
  */
 public function executeServiceCall($serviceName, $methodName, array $parameters)
 {
     $serviceObject = $this->getServiceObject($serviceName);
     $serviceObject = Amfphp_Core_FilterManager::getInstance()->callFilters(self::FILTER_SERVICE_OBJECT, $serviceObject, $serviceName, $methodName, $parameters);
     if (!method_exists($serviceObject, $methodName)) {
         throw new Amfphp_Core_Exception("method {$methodName} not found on {$serviceName} object ");
     }
     return call_user_func_array(array($serviceObject, $methodName), $parameters);
 }
Esempio n. 17
0
 /**
  * get the response headers. Creates an associative array of headers, then filters them, then returns an array of strings
  * @return array
  */
 public function getResponseHeaders()
 {
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $headers = array('Content-Type' => $this->contentType);
     $headers = $filterManager->callFilters(self::FILTER_HEADERS, $headers, $this->contentType);
     $ret = array();
     foreach ($headers as $key => $value) {
         $ret[] = $key . ': ' . $value;
     }
     return $ret;
 }
Esempio n. 18
0
 /**
  * @see Amfphp_Core_Common_IExceptionHandler
  */
 public function handleException(Exception $exception)
 {
     $errorPacket = new Amfphp_Core_Amf_Packet();
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $fromFilters = $filterManager->callFilters(self::FILTER_AMF_EXCEPTION_HANDLER, null);
     if ($fromFilters) {
         $handler = $fromFilters;
         return $handler->generateErrorResponse($exception);
     }
     //no special handling by plugins. generate a simple error response with information about the exception
     $errorResponseMessage = null;
     $errorResponseMessage = new Amfphp_Core_Amf_Message();
     $errorResponseMessage->targetUri = $this->lastRequestMessageResponseUri . Amfphp_Core_Amf_Constants::CLIENT_FAILURE_METHOD;
     //not specified
     $errorResponseMessage->responseUri = "null";
     $errorResponseMessage->data = new stdClass();
     $errorResponseMessage->data->faultCode = $exception->getCode();
     $errorResponseMessage->data->faultString = $exception->getMessage();
     $errorResponseMessage->data->faultDetail = $exception->getTraceAsString();
     $errorPacket->messages[] = $errorResponseMessage;
     return $errorPacket;
 }
Esempio n. 19
0
 /**
  * loads and instanciates a service class matching $serviceName, then calls the function defined by $methodName using $parameters as parameters
  * throws an exception if service not found.
  * if the service exists but not the function, an exception is thrown by call_user_func_array. It is pretty explicit, so no further code was added
  *
  * @param string $serviceName
  * @param string $methodName
  * @param array $parameters
  * @return mixed the result of the function call
  *
  */
 public function executeServiceCall($serviceName, $methodName, array $parameters)
 {
     $unfilteredServiceObject = $this->getServiceObject($serviceName);
     $serviceObject = Amfphp_Core_FilterManager::getInstance()->callFilters(self::FILTER_SERVICE_OBJECT, $unfilteredServiceObject, $serviceName, $methodName, $parameters);
     $isStaticMethod = false;
     if (method_exists($serviceObject, $methodName)) {
         //method exists, but isn't static
     } else {
         if (method_exists($serviceName, $methodName)) {
             $isStaticMethod = true;
         } else {
             throw new Amfphp_Core_Exception("method {$methodName} not found on {$serviceName} object ");
         }
     }
     if (substr($methodName, 0, 1) == '_') {
         throw new Amfphp_Core_Exception("The method {$methodName} starts with a '_', and is therefore not accessible");
     }
     if ($this->checkArgumentCount) {
         $method = new ReflectionMethod($serviceObject, $methodName);
         $numberOfRequiredParameters = $method->getNumberOfRequiredParameters();
         $numberOfParameters = $method->getNumberOfParameters();
         $numberOfProvidedParameters = count($parameters);
         if ($numberOfProvidedParameters < $numberOfRequiredParameters || $numberOfProvidedParameters > $numberOfParameters) {
             throw new Amfphp_Core_Exception("Invalid number of parameters for method {$methodName} in service {$serviceName} : {$numberOfRequiredParameters}  required, {$numberOfParameters} total, {$numberOfProvidedParameters} provided");
         }
     }
     if ($isStaticMethod) {
         return call_user_func_array(array($serviceName, $methodName), $parameters);
     } else {
         return call_user_func_array(array($serviceObject, $methodName), $parameters);
     }
 }
Esempio n. 20
0
 /**
  * loads and instanciates a service class matching $serviceName, then calls the function defined by $methodName using $parameters as parameters
  * throws an exception if service not found.
  * if the service exists but not the function, an exception is thrown by call_user_func_array. It is pretty explicit, so no further code was added
  *
  * @param string $serviceName
  * @param string $methodName
  * @param array $parameters
  * @return mixed the result of the function call
  *
  */
 public function executeServiceCall($serviceName, $methodName, array $parameters)
 {
     $serviceObject = $this->getServiceObject($serviceName);
     $serviceObject = Amfphp_Core_FilterManager::getInstance()->callFilters(self::FILTER_SERVICE_OBJECT, $serviceObject, $serviceName, $methodName, $parameters);
     if (!method_exists($serviceObject, $methodName)) {
         throw new Amfphp_Core_Exception("method {$methodName} not found on {$serviceName} object ");
     }
     if (substr($methodName, 0, 1) == '_') {
         throw new Exception("The method {$methodName} starts with a '_', and is therefore not accessible");
     }
     if ($this->checkArgumentCount) {
         $this->checkNumberOfArguments($serviceObject, $serviceName, $methodName, $parameters);
     }
     return call_user_func_array(array($serviceObject, $methodName), $parameters);
 }
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     //defaults
     $this->clientCharset = 'utf-8';
     $this->phpCharset = 'utf-8';
     $this->method = self::METHOD_NONE;
     if ($config) {
         if (isset($config['clientCharset'])) {
             $this->clientCharset = $config['clientCharset'];
         }
         if (isset($config['phpCharset'])) {
             $this->phpCharset = $config['phpCharset'];
         }
         if (isset($config['method'])) {
             $this->method = $config['method'];
         }
     }
     //only add filters if conversion is necessary
     if ($this->method == self::METHOD_NONE) {
         return;
     }
     if ($this->clientCharset == $this->phpCharset) {
         return;
     }
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST, $this, 'filterDeserializedRequest');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_RESPONSE, $this, 'filterDeserializedResponse');
 }
Esempio n. 22
0
 public function __construct(array $config = null)
 {
     $filterManager = \Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(\Amfphp_Core_Common_ServiceRouter::FILTER_SERVICE_OBJECT, $this, 'filterServiceObject');
     $this->pixie = $config['pixie'];
 }
Esempio n. 23
0
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     Amfphp_Core_FilterManager::getInstance()->addFilter(Amfphp_Core_Amf_Handler::FILTER_AMF_REQUEST_MESSAGE_HANDLER, $this, "filterAmfRequestMessageHandler");
     Amfphp_Core_FilterManager::getInstance()->addFilter(Amfphp_Core_Amf_Handler::FILTER_AMF_EXCEPTION_HANDLER, $this, "filterAmfExceptionHandler");
     $this->clientUsesFlexMessaging = false;
 }
 /**
  * test with filters grant access
  */
 public function testWithFiltersGrantAccess()
 {
     $credentialsAssoc = new stdClass();
     $userIdField = Amfphp_Core_Amf_Constants::CREDENTIALS_FIELD_USERID;
     $passwordField = Amfphp_Core_Amf_Constants::CREDENTIALS_FIELD_PASSWORD;
     $credentialsAssoc->{$userIdField} = 'admin';
     $credentialsAssoc->{$passwordField} = 'adminPassword';
     $credentialsHeader = new Amfphp_Core_Amf_Header(Amfphp_Core_Amf_Constants::CREDENTIALS_HEADER_NAME, true, $credentialsAssoc);
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $ret = $filterManager->callFilters(Amfphp_Core_Amf_Handler::FILTER_AMF_REQUEST_HEADER_HANDLER, null, $credentialsHeader);
     $ret->handleRequestHeader($credentialsHeader);
     $ret->filterServiceObject($this->serviceObj, 'AnyService', 'adminMethod');
 }
Esempio n. 25
0
 /**
  * constructor.
  * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  */
 public function __construct(array $config = null)
 {
     //default
     $this->voFolders = array(AMFPHP_ROOTPATH . '/Services/Vo/');
     if ($config) {
         if (isset($config['voFolders'])) {
             $this->voFolders = $config['voFolders'];
         }
         if (isset($config['enforceConversion'])) {
             $this->enforceConversion = $config['enforceConversion'];
         }
     }
     $filterManager = Amfphp_Core_FilterManager::getInstance();
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_VO_CONVERTER, $this, 'filterVoConverter');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST, $this, 'filterDeserializedRequest');
     $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_RESPONSE, $this, 'filterDeserializedResponse');
 }