http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Core/Application.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Core/Application.class.php b/balance/lib/pear/Core/Application.class.php deleted file mode 100644 index 9a1f087..0000000 --- a/balance/lib/pear/Core/Application.class.php +++ /dev/null @@ -1,427 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * Main class for OODT Balance web applications. Contains utility - * methods and definitions that provide standard functionality across - * the site. - * - * @author ahart - * - */ -class Org_Apache_Oodt_Balance_Core_Application { - - public $request; - - public $subrequest; - - public $authenticationProviderInstance = null; - - public $authorizationProviderInstance = null; - - public $response; - - public $settings; - - public $modulesLoaded; - - public function __construct($settings) { - - // Save the application settings - $this->settings = $settings; - - // Update the PHP include path to include the locations specified in - // the application configuration .ini file - if (isset($this->settings['classes_dir']) && is_array($this->settings['classes_dir'])) { - $customClassPath = implode(';',$this->settings['classes_dirs']); - set_include_path(get_include_path() . ';' . $customClassPath); - } - - // Initialize a session - session_start(); - - // Define the application base url - define ("SITE_ROOT", ($settings['site_root'] == '/') - ? '' - : $settings['site_root']); - - } - - - public function getResponse() { - - $this->setAuthenticationProviderInstance(); - $this->setAuthorizationProviderInstance(); - - // Interpret the request uri of the current request - $uri = App::Get()->settings['site_root'] != '/' - ? substr($_SERVER['REQUEST_URI'],strlen(App::Get()->settings['site_root'])) - : $_SERVER['REQUEST_URI']; - $this->request = new Org_Apache_Oodt_Balance_Core_ApplicationRequest( - $this->settings,$uri); - - // Initialize a response object for the request - $this->response = new Org_Apache_Oodt_Balance_Core_ApplicationResponse( - $this->settings,$this->request); - - // Process the response - $this->response->process(); - - // Return the processed response object - return $this->response; - } - - public function cleanup() { - - } - - /** - * Determine whether the current request maps to resources associated - * with an application module. - * - * If a view, script, or static asset is part of an application module, - * the path to the file will differ than those for regular application - * resources. This function provides a way to determine whether a given - * request should be considered part of a module or of the general - * application. - * - * @param $requestURI - The request uri to test - * @return boolean - true indicates the request uri belongs to a module - */ - public function isModule($requestURI) { - // Determine whether a module is being requested - $filteredURI = $requestURI; - $filteredURI = ltrim($filteredURI,'/'); - $parts = explode('/',$filteredURI); - - if (is_dir(HOME . "/modules")) { - $handle = opendir(HOME . "/modules"); - while (false !== ($dir = readdir($handle))) { - if ( $dir == $parts[0] && $module = $this->loadModule($dir) ) { - return $module; - } - } - } - return false; - } - - public function getAuthenticationProvider() { - return $this->authenticationProviderInstance; - } - - public function setAuthenticationProviderInstance() { - - // Check if the user wants authentication for application - if ( $this->settings['authentication_class_path'] != null && - $this->settings['authentication_class'] != null ) { - - require_once $this->settings['authentication_class_path']; - $authProvider = $this->settings['authentication_class']; - $this->authenticationProviderInstance = new $authProvider(); - } - } - - public function getAuthorizationProvider() { - return $this->authorizationProviderInstance; - } - - public function setAuthorizationProviderInstance() { - - // Check if the user wants authorization for application - if ( $this->settings['authorization_class_path'] != null && - $this->settings['authorization_class'] != null ) { - - require_once $this->settings['authorization_class_path']; - $authProvider = $this->settings['authorization_class']; - $this->authorizationProviderInstance = new $authProvider(); - } - } - - public function loadModule($modName = null) { - // If the module name is null, a module is requesting that - // its own context be loaded - if ($modName === null) { - return $this->getModuleContext(); - } - - // If the module has been previously loaded, return its context - if (isset($this->modulesLoaded[$modName])) { - return $this->modulesLoaded[$modName]; - } - - // check if module path exists before loading module context - $modulePath = HOME . "/modules/{$modName}"; - if ( is_dir($modulePath) ) { - - // create stdClass - $modClass = new stdClass(); - $modClass->modulePath = $modulePath; - $modClass->moduleRoot = SITE_ROOT . "/{$modName}"; - $modClass->moduleStatic = SITE_ROOT . "/modules/{$modName}/static"; - - $this->modulesLoaded[$modName] = $modClass; - - // Read in the module config file and append to application config - if (file_exists($modulePath . '/config.ini')) { - // Get the raw contents of the config file - $ini = file_get_contents($modulePath . '/config.ini'); - // Perform environment replacement - $ini = str_replace('[MODULE_PATH]', $modClass->modulePath, $ini); - $ini = str_replace('[MODULE_ROOT]', $modClass->moduleRoot, $ini); - $ini = str_replace('[MODULE_STATIC]',$modClass->moduleStatic, $ini); - - $ini = str_replace('[HOME]', HOME, $ini); - $ini = str_replace('[SITE_ROOT]', SITE_ROOT, $ini); - - // Parse the env-replaced content - $moduleSettings = parse_ini_string($ini); - // Append (union) with global settings. += ensures that - // application settings always override module settings. - $this->settings += $moduleSettings; - } - - // Return the configuration object - return $modClass; - } else { - return false; - } - } - - public function getModuleContext($which = null) { - - // If a module is requesting its own context... - if ( $which === null ) { - $req = ($this->subrequest != null) - ? $this->subrequest - : $this->request; - $uri = ltrim($req->uri,'/'); - $moduleName = substr($uri,0,strpos($uri,'/')); - - return (!empty($moduleName)) - ? $this->loadModule($moduleName) - : false; - } - - // otherwise, return the result of an attempt to load the module - return $this->loadModule($which); - } - - public static function SetMessage($content,$level = CAS_MSG_INFO) { - - switch ($level) { - case CAS_MSG_WARN: - $_SESSION['_messages'][] = '<div class="cas_msg warn">' . $content . '</div>'; - break; - case CAS_MSG_ERROR: - $_SESSION['_messages'][] = '<div class="cas_msg error">' . $content . '</div>'; - break; - default: - $_SESSION['_messages'][] = '<div class="cas_msg info">' . $content . '</div>'; - break; - } - } - - public static function GetMessages() { - $response = isset($_SESSION['_messages']) - ? implode('', $_SESSION['_messages']) - : false; - unset($_SESSION['_messages']); - return $response; - } - - public function fatal($message) { - ApplicationResponse::sendFatal($message); - exit(); - } - - public static function EndUserSession() { - // Unset all of the session variables. - $_SESSION = array(); - - // Finally, destroy the session. - session_destroy(); - } - - public static function Redirect($newLocation) { - header("Location: {$newLocation}"); - exit(); - } - - /** - * Returns an instance of the requested DataProvider class, ensuring - * that all necessary prerequisites are correctly loaded. To load a - * custom DataProvider. The framework looks for a matching data - * provider according to the following heirarchy, stopping when - * it first finds a matching class: If the request involves a module, - * that module's /classes/dataProviders directory is checked, - * otherwise/then the application's classes/dataProviders directory - * is checked, and finally (if no match found yet) the webapp-base - * /classes/dataProviders directory is checked. - * Data providers must be named <ProviderName>.class.php, and must - * implement the IApplicationDataProvider interface. - * - * @param $class string The name of the DataProvider class - * @param $options array optional array of constructor options. - * These are flowed down to the DataProvider's - * constructor function. - * @return the data provider (must implement IApplicationDataProvider) - * - * Example: to get an instance of a data provider: - * $p = $app->GetDataProvider('<ProviderName>'); - * - * Example 2: to get an instance and pass options to the constructor - * $p = $app->GetDataProvider('<ProviderName>',array('opt1'=>'val1')); - * - * Note that this will not attempt to connect to your data provider. - * All implementations of IApplicationDataProvider offer a ::connect() - * function, which should be invoked on the returned class to initiate - * a connection. - * - */ - public function getDataProvider($class,$options = array()) { - require_once( "Org/Apache/Oodt/Balance/Interfaces/IApplicationDataProvider.php"); - $dataProviderPath = "/classes/dataProviders/{$class}.class.php"; - - // Check for the requested data provider in one of 3 locations. It could be: - // 1) Part of a module - if ($this->request->isModule && - is_file($this->request->moduleBase . $dataProviderPath)) { - require_once($this->request->moduleBase . $dataProviderPath); - - return new $class($options); - } - - // 2) Part of the application's widget collection - if (is_file(HOME . $dataProviderPath)) { - require_once(HOME . $dataProviderPath); - return new $class($options); - } - - // 3) Part of the webapp-base widget collection - if (is_file(LIB . $dataProviderPath)) { - require_once(LIB . $dataProviderPath); - return new $class($options); - } - return false; - } - - public function getErrorProvider( - $class = 'Org_Apache_Oodt_Balance_Providers_Error_DefaultErrorProvider', - $options = array()) { - - return new $class; - } - - - /** - * Create an instance of the requested widget class. - * @deprecated - * @param unknown_type $class - * @param unknown_type $options - */ - public function createWidget($class,$options = array()) { - - require_once( "Org/Apache/Oodt/Balance/Interfaces/IApplicationWidget.php"); - - $classPath = "/scripts/widgets/{$class}.php"; - - // Check for the requested widget in one of 2 locations. It could be: - // 1) Part of a module - if ($this->request->isModule && - is_file($this->request->moduleBase . $classPath)) { - require_once($this->request->moduleBase . $classPath); - return new $class($options); - } - - // 2) Part of the application's widget collection - if (is_file(HOME . $classPath)) { - require_once(HOME . $classPath); - return new $class($options); - } - - // No widget matching $class found... - return false; - } - - /** - * Take any application view and 'widgetize' it. This allows developers to nest - * application views, allowing for greater modularity and reuse. - * - * As an example: given an application with URIs /foo/bar and foo/baz (corresponding - * to HOME/views/foo/bar.php and HOME/views/foo/baz.php), the content of /foo/baz can - * be 'widgetized' (nested) within /foo/bar simply by calling this function from somewhere - * within the host view (/foo/bar): - * - * <div> - * <?php App::Get()->widgetizeView('/foo/baz'); - * </div> - * - * will produce: - * - * <div> - * <div class="bal_widget">...contents of HOME/views/foo/baz.php...</div> - * </div> - * - * The `cssClasses` parameter allows for specifying any css class definitions that should - * be applied to the widget container. For example: - * - * App::Get()->widgetizeView('/foo/baz','someClass someOtherClass'); - * - * will produce: - * - * <div> - * <div class="bal_widget someClass someOtherClass">...contents...</div> - * </div> - * - * @param string $contentPath The URI to the view to widgetize - * @param string $cssClasses Any css classes to append to the widget's `classes` attribute - * @param mixed $options An array of options (for the future... none defined yet) - */ - public function widgetizeView($contentPath,$cssClasses = '',$options = array()) { - - // Create a request object for the content to be widgetized - $request = $this->subrequest = new Org_Apache_Oodt_Balance_Core_ApplicationRequest( - $this->settings,$contentPath); - - // Store the application request object prior to processing this nested request - $parentRequest = $this->request; - - // Store the nested request in the application so that it can be accessed as - // expected via App::Get()->request (for accurate segment processing, for example) - $this->request = $request; - - // Generate a response for the nested request - $response = new Org_Apache_Oodt_Balance_Core_ApplicationResponse( - $this->settings,$request); - $response->process(array('skipHeader' => true,'skipFooter' => true,'skipHooks' => true)); - - //TODO: Process any options (still need to define the options available) - - // send the wigitized content - echo '<div class="bal_widget ' . $cssClasses . '">' - . $response->getViewContent() - . '</div>'; - - // Restore the application request - $this->request = $parentRequest; - $this->subrequest = null; - } -}
http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Core/ApplicationDataResponse.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Core/ApplicationDataResponse.class.php b/balance/lib/pear/Core/ApplicationDataResponse.class.php deleted file mode 100644 index f68d12b..0000000 --- a/balance/lib/pear/Core/ApplicationDataResponse.class.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * ApplicationDataResponse provides a standard response object for use by application - * data providers. - * - * The ApplicationDataResponse works off of the idea that the KEY=>VALUE paradigm - * is more or less universal and suits (or is at least compatible with) a broad array - * of data sources. By guaranteeing that all data providers will return objects of this type - * in response to data requests, it is possible to simplify the process of integrating - * and assimilating data from multiple heterogeneous sources - * - * @author ahart - * - */ -class Org_Apache_Oodt_Balance_Core_ApplicationDataResponse { - - public $requestString; - public $data; - public $errorOccurred; - public $errorMessage; - - public function __construct($seed = array()) { - $this->data = $seed; - $this->errorOccurred = false; - } - - public function size() { - return count($this->data); - } - - public function count() { - return count($this->data); - } - - public function add($key,$value) { - $this->data[$key] = $value; - } - - public function bulkAdd($data) { - $this->data = array_merge($this->data,$data); - } - - public function get($key) { - return (isset($this->data['key'])) - ? $this->data['key'] - : false; - } - - public function setRequestString($request) { - $this->requestString = $request; - } - - public function error() { - return ($this->errorOccurred); - } - - public function setError($message) { - $this->errorOccurred = true; - $this->errorMessage = true; - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Core/ApplicationRequest.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Core/ApplicationRequest.class.php b/balance/lib/pear/Core/ApplicationRequest.class.php deleted file mode 100644 index a46d62b..0000000 --- a/balance/lib/pear/Core/ApplicationRequest.class.php +++ /dev/null @@ -1,171 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * ApplicationRequest: Provides methods for interpreting and processing - * a resource request. - * - * @author ahart - * - */ -class Org_Apache_Oodt_Balance_Core_ApplicationRequest { - - public $isScript; - - public $config; - - public $uri; - - public $segments; - - public $data; - - public $viewPath; - - public $scriptPath; - - public $isModule; - - public $modulePath; // Filesystem path for module - - public $moduleRoot; // URL base for module - - public $moduleStatic; // URL base for static module assests (images,css,js,etc) - - public function __construct($config,$requestURI) { - - // Determine if this request is a script or a view - $this->isScript = $this->isScript($requestURI); - - // Store the config as provided - $this->config = $config; - - // Store the uri as provided - $this->uri = htmlentities($requestURI); - - // Initialize the segments and view path - $this->segments = array(); - $this->viewPath = false; - - // Store data associated with the request - $this->data = $_GET; - $this->data = array_merge($this->data,$_POST); - - if ($this->isScript) { - $this->processAsScript(); - } else { - $this->processAsView(); - } - } - - protected function processAsView() { - // Determine the view to use - list($thePage) = explode('index.php', parse_url($this->uri, PHP_URL_PATH)); // we only care about URL path info - $thePage = ltrim($thePage,'/'); - - if ($thePage == '') { $thePage = 'index'; } - $parts = explode('/',$thePage); - - // Determine whether a module is being requested - $module = App::Get()->isModule($thePage); - - if ($module) { - $this->isModule = true; - $this->modulePath = $module->modulePath; - $this->moduleRoot = $module->moduleRoot; - $this->moduleStatic = $module->moduleStatic; - array_shift($parts); - } - - // Starting with the full request string, test for the existance of - // a corresponding view. If none is found in the HOME - // directory, chop off the last segment and try again. Add the chopped - // segment to the "segments" array since it is likely a parameter. - $partCount = count($parts); - - // check for view at least once - do { - $testPath = implode('/',$parts); - $homeTest = (($this->isModule) ? "{$this->modulePath}/views" : $this->config['views_dir']) . '/' . $testPath . '.php'; - $homeIdxTest = (($this->isModule) ? "{$this->modulePath}/views" : $this->config['views_dir']) . '/' . $testPath . '/index.php'; - - - if (is_file($homeTest)) { - $this->viewPath = $homeTest; - break; - } - if (is_file($homeIdxTest)) { - $this->viewPath = $homeIdxTest; - break; - } - - // If here, neither is a valid view, so chop the last segment - $this->segments[] = $parts[$partCount - 1]; - array_pop($parts); - $partCount--; - } while ($partCount > 0); - - // If no view has been found by this point, display a 404 message - if (!$this->viewPath) { - $this->viewPath = dirname(dirname(__FILE__)) . "/views/error/404.php"; - } - - // Reverse the segments array so that params appear in the proper order - $this->segments = array_reverse($this->segments); - } - - protected function processAsScript() { - - // Determine the desired script - list($theScript) = explode("_init.php",$this->uri); - if ($GLOBALS['app']->settings['site_root'] != '/') { - $theScript = str_replace($GLOBALS['app']->settings['site_root'],'',$theScript); - } - $theScript = str_replace(".do",".php",$theScript); - $theScript = strpos($theScript,'?') - ? substr($theScript,0,strpos($theScript,'?')) - : $theScript; - $theScript = ltrim($theScript,'/'); - $module = $GLOBALS['app']->isModule($theScript); - if ($module) { - $this->isModule = true; - $this->modulePath = $module->modulePath; - $this->moduleRoot = $module->moduleRoot; - $this->moduleStatic = $module->moduleStatic; - $theScript = substr($theScript,strpos($theScript,'/')+1); - $path = $module->modulePath . "/scripts/{$theScript}"; - } else { - $path = HOME . "/scripts/{$theScript}"; - } - - $this->scriptPath = $path; - } - - - protected function isScript($requestURI) { - // Is this a script? (does the script filename end in .do?) - $test = $requestURI; - if (strpos($test,'?')) { - $test = substr($test,0,strpos($test,'?')); - } - return (substr($test,-3,3) == '.do'); - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Core/ApplicationResponse.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Core/ApplicationResponse.class.php b/balance/lib/pear/Core/ApplicationResponse.class.php deleted file mode 100644 index e2e9b8d..0000000 --- a/balance/lib/pear/Core/ApplicationResponse.class.php +++ /dev/null @@ -1,311 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * ApplicationResponse: Provides functions for dynamically constructing - * and delivering a response to a resource request. - * - * @author ahart - * - */ -class Org_Apache_Oodt_Balance_Core_ApplicationResponse { - - protected $config; - protected $request; - - protected $headers; - - protected $header; - protected $view; - protected $footer; - - protected $stylesheets = array(); - protected $javascripts = array(); - - protected $data; - - const DYN_JS_TAG = '<!-- JAVASCRIPTS -->'; - const DYN_CSS_TAG = '<!-- STYLESHEETS -->'; - - /** - * Constructor - * - * @param array $config - * @param Org_Apache_Oodt_Balance_Core_ApplicationRequest $request - */ - public function __construct($config, - Org_Apache_Oodt_Balance_Core_ApplicationRequest $request) { - - $this->config = $config; - - $this->request = $request; - - $this->headers = array(); - - $this->header = HOME . "/{$config['header_file_path']}"; - $this->footer = HOME . "/{$config['footer_file_path']}"; - } - - /** - * Generates a response by processing the requested view, - * including any header and footer views (if needed) as specified - * by the application config file. - * - * Available options: - * skipHeader: boolean (default = false) If present, omits header processing - * skipFooter: boolean (default = false) If present, omits footer processing - * skipHooks: boolean (default = false) If present, omits hook processing - * - * @param array $options - */ - public function process($options = array()) { - - // Merge defaults with provided options - $defaults = array( - 'skipHeader' => false, - 'skipFooter' => false, - 'skipHooks' => false, - ); - $options += $defaults; - - if (!$options['skipHooks']) { - // Include the appropriate hooks.php file - include ((App::Get()->request->isModule - ? App::Get()->request->modulePath - : HOME ) . '/hooks.php'); - - // Run 'before_all' hook for all requests - if (function_exists('hook_before_all')) { - hook_before_all(); - } - } - - // Preprocessing for a view - if (!$this->request->isScript) { - ob_start(); // Start buffering the output - - // Check that the requested view exists - if (file_exists($this->request->viewPath)) { - - // Run the beforeView hook - if (!$options['skipHooks'] && function_exists('hook_before_view')) { - hook_before_view(); - } - // Process the view - include($this->request->viewPath); - } else { - include(HOME . "/views/errors/404.php"); // 404 error page - } - - $this->view = ob_get_contents(); - ob_clean(); - - // Determine the header view (if any) to include - if (!$options['skipHeader'] && $this->header && is_file($this->header)) { - // Run the beforeHeader hook - if (!$options['skipHooks'] && function_exists('hook_before_header')) { - hook_before_header(); - } - - // Process the header - if (!empty($this->header)) {include($this->header);} - - $this->header = ob_get_contents(); - ob_clean(); - } - - // Determine the footer view (if any) to include - if (!$options['skipFooter'] && $this->footer && is_file($this->footer)) { - // Run the beforeFooter hook - if (!$options['skipHooks'] && function_exists('hook_before_footer')) { - hook_before_footer(); - } - - // Process the footer - if (!empty($this->footer)) {include($this->footer);} - - $this->footer = ob_get_contents(); - ob_clean(); - } - - ob_end_clean(); // Stop buffering the output - } else { - require_once( $this->request->scriptPath ); - exit(); - } - } - - /** - * Actually sends the response (using 'echo') out to the - * client's browser. - */ - public function send() { - - if ($this->request->isScript) { - if (is_file($this->request->scriptPath)) { - require_once($this->request->scriptPath); - } else { - header("Location: " . SITE_ROOT . "/errors/404"); - } - } else { - // Process any dynamically added content - $this->processDynamicContent(); - - // Run the beforeSend hook - if (function_exists('hook_before_send')) { - hook_before_send(); - } - foreach ($this->headers as $header) { - header($header); - } - if ($this->header) { - echo $this->header; - } - echo $this->view; - if ($this->footer) { - echo $this->footer; - } - // Run the afterSend hook - if (function_exists('hook_after_send')) { - hook_after_send(); - } - } - } - - public static function sendFatal($message) { - // Store the message in the session - $_SESSION['fail_message'] = $message; - - // Clear any old output and restart buffering the output - ob_clean(); - ob_start(); - - // Build the 404 error page - include(LIB . "/views/errors/fail.php"); - - // Get the contents as a string and flush the buffer - $content = ob_get_contents(); - - // Stop buffering output - ob_end_clean(); - - // Send the response - echo $content; - - exit(); - } - - /** - * Replace special tags with their dynamically assigned content. Currently, the only - * special tags are for defining an area for CSS and JavaScript imports. - * - */ - protected function processDynamicContent() { - - // Dynamically insert CSS - $this->header = str_replace(self::DYN_CSS_TAG,implode("\r\n",$this->stylesheets),$this->header); - $this->view = str_replace(self::DYN_CSS_TAG,implode("\r\n",$this->stylesheets),$this->view); - $this->footer = str_replace(self::DYN_CSS_TAG,implode("\r\n",$this->stylesheets),$this->footer); - - // Dynamically insert JS - $this->header = str_replace(self::DYN_JS_TAG,implode("\r\n",$this->javascripts),$this->header); - $this->view = str_replace(self::DYN_JS_TAG,implode("\r\n",$this->javascripts),$this->view); - $this->footer = str_replace(self::DYN_JS_TAG,implode("\r\n",$this->javascripts),$this->footer); - - } - - public function useHeaderFile($path) { - $this->header = $path; - } - - public function useFooterFile($path) { - $this->footer = $path; - } - - public function sendHeader($headerContent) { - $this->headers[] = $headerContent; - } - - public function getHeaderContent() { - return $this->header; - } - public function getViewContent() { - return $this->view; - } - public function getFooterContent() { - return $this->footer; - } - - public function data($key = null, $value = null) { - - // Return the data store associated with this request - if ($key == null && $value == null) { - return $this->data; - } - - // Return the stored value for the provided key - if ($value == null) { - return isset($this->data[$key]) - ? $this->data[$key] - : null; - } - - // Set the stored value for the key to the provided value - $this->data[$key] = $value; - } - - public function addStylesheet($href,$condition='') { - // Build the string for the css import - $str = "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$href}\"/>"; - if (!empty($condition)) { - $str = "<!--[if {$condition}]>{$str}<![endif]-->"; - } - $this->stylesheets[] = $str; - } - - /** - * Add javascript resources to the response - * - * This function provides a clean way to programmatically include arbitrary - * Javascript resources in the response. Depending upon the value - * provided for 'isRaw', the contents of 'src' will either be interpreted - * as the 'src' attribute or the body content of the generated <script> block. - * - * @param string src - Either the url to the resource to include (if - * 'isRaw' = false) or a string representing the - * raw Javascript to include (if 'isRaw' = true) - * @param boolean isRaw - Controls how 'src' is interpreted. If set to false - * (default), 'src' will be interpreted as a URL to the - * Javascript resource to include. If set to true, 'src' - * will be interpreted as a string of raw Javascript. - */ - public function addJavascript($src, $isRaw = false) { - if ($isRaw === true) { - // Build a script container for the raw javascript - $str = "<script type=\"text/javascript\">{$src}</script>"; - $this->javascripts[] = $str; - } else { - // Build the string for the javascript file import - $str = "<script type=\"text/javascript\" src=\"{$src}\"></script>"; - $this->javascripts[] = $str; - } - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php b/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php deleted file mode 100644 index 23e3975..0000000 --- a/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php +++ /dev/null @@ -1,162 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * IApplicationAuthenticationProvider defines an interface that should be - * implemented by all authentication providers to simplify the process of - * accessing and retrieving information about the underlying system. - * - * The interface defines five mandatory functions: - * - __construct: Provide any necessary configuration information but do - * not actually establish a connection to the underlying system. - * - connect: This function does the work of actually connecting to the - * underlying system. Options can be provided either here or in - * the constructor arguments (or both), but the connection to the - * underlying system should not be initiated until this function - * is invoked. - * - disconnect: Disconnect from the underlying system, performing any - * necessary clean up operations in the process. - * - checkLogin: Check if a valid user has logged in. - * - login: Determine the ability to gain access to the underlying system - * as a legitimate user. The requirements are a valid username - * (or user ID) and password. - * - logout: Ending the user's session to the underlying system. - * - * - * Framework implementations of common authentication providers can be found in: - * {LIB}/classes/authenticationProviders and should be named FooAuthenticationProvider.class.php. - * Framework authentication providers can be invoked by doing: - * $app->GetAuthenticationProvider('FooAuthenticationProvider'); - * - * Custom authentication providers should be placed in: - * {HOME}/classes/authenticationProviders and should be named FooAuthenticationProvider.class.php. - * Custom authentication providers can be invoked by doing: - * $app->GetAuthenticationProvider('foo',true); // true --> custom - * - * @author s.khudikyan - * - */ -interface Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthenticationProvider { - - /** - * Constructor - Instantiate the provider but do not yet connect - * to the underlying system. - * - */ - public function __construct(); - - /** - * Initiate a connection to the underlying system. - * - * @return boolean True or false depending on the result - */ - public function connect(); - - /** - * Disconnect from the underlying system and perform any cleanup - * operations necessary. - * - * @return boolean True or false depending on the result - */ - public function disconnect(); - - /** - * Check if a valid user has logged in. - * - * @return boolean True or false depending on the result - */ - public function isLoggedIn(); - - /** - * Determine whether privileges will be granted to a particular user - * using credentials provided. - * - * @param $username mixed The username is usually a string. - * @param $password mixed The password is usually a string. - * @return mixed True or false depending on the success of login - */ - public function login( $username, $password ); - - /** - * Ending the user's session to the underlying system. - * - */ - public function logout(); - - /** - * Get current user's username. - * - */ - public function getCurrentUsername(); - - /** - * Change current user's password. - * - * @param $newPassword string - * @return boolean True or false depending on the success of password change - */ - public function changePassword( $newPassword ); - - /** - * Checks if user is logged in. If true, validates rules from config file and uses - * {@link changePassword} to change password. - * - * @param $newPass string The new password - * @param $encryptionMethod string The encryption method used - */ - public function validateChangePassword( $newPass, $encryptionMethod = "SHA" ); - - /** - * Retrieves the set of attributes from the user's entry - * - * @param $username string The user for which attributes will be returned - * @param $attributes array Attributes to retrieve - * @return array An empty array or requested attributes - */ - public function retrieveUserAttributes( $username, $attributes ); - - /** - * Creates a new account with the user information provided - * - * @param $userInfo array Can include different values depending on provider - * i.e. username, firstname, lastname, email - */ - public function addUser( $userInfo ); - - /** - * Uses {@link retrieveUserAttributes} to retrieve information about the provided - * user. If count of array returned is > 0 then the username is not available. - * - * @param $username string The username for which a user is checking the - * availability of - */ - public function usernameAvailability( $username ); - - /** - * Updates user information with the values of provided attributes - * - * @param $newInfo array (key, value) based array, where keys are the user's - * entry attribute ids and the values will replace - * the values of those attributes - */ - public function updateProfile( $newInfo ); - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php b/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php deleted file mode 100644 index b5bdf48..0000000 --- a/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * LDAPAuthorizationProvider defines an interface that will determine what level - * of access a particular user should have to secured resources. - * - * The interface defines five mandatory functions: - * - __construct: Provide any necessary configuration information - * - * - * Framework implementations of common authorization providers can be found in: - * Balance/Providers/Authorization - * Framework authorization providers can be invoked by doing: - * App:Get()->getAuthorizationProvider(); - * - * @author s.khudikyan - * - */ - -interface Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthorizationProvider { - - /** - * Constructor - Instantiate the provider - * - */ - public function __construct(); - - /** - * Initiate a connection to the underlying system. - * - * @return boolean True or false depending on the result - */ - public function connect(); - - /** - * Retrieves the set of groups for specified user - * - * @param $username string The user for which groups will be returned - * @return array An empty array or groups the user belongs to - */ - public function retrieveGroupsForUser( $username ); - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Interfaces/IApplicationDataProvider.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Interfaces/IApplicationDataProvider.php b/balance/lib/pear/Interfaces/IApplicationDataProvider.php deleted file mode 100644 index b78d7a7..0000000 --- a/balance/lib/pear/Interfaces/IApplicationDataProvider.php +++ /dev/null @@ -1,125 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * IApplicationDataProvider defines an interface that should be implemented - * by all data providers to simplify the process of integrating and accessing - * multiple heterogeneous data sources. A data source could be a relational - * SQL-like database, a CAS File Manager, an LDAP server, anything that can - * be queried for data. - * - * The interface defines five mandatory functions: - * - __construct: Provide any necessary configuration information but do - * not actually establish a connection to the underlying data - * source. - * - connect: This function does the work of actually connecting to the - * underlying data source. Options can be provided either here - * or in the constructor arguments (or both), but the connection - * to the underlying data source should not be initiated until - * this function is invoked. - * - disconnect: Disconnect from the underlying data source, performing any - * necessary clean up operations in the process. - * - request: Satisfy a request for data. The format that this request takes - * will likely differ across implementations. An array of further - * options may be provided as an optional second argument. As a - * concrete example, an SQL-like data source may support string - * requests like "SELECT * FROM foo WHERE bar='baz'". The - * response from this call must be an ApplicationDataResponse object - * containing the (possibly multidimensional) array of response info. - * - command: Send a command to the underlying data source. As with request, - * the format that this command takes will likely differ across - * implementations. As a concrete example, an SQL-like data source - * may support string commands like "UPDATE foo set bar='baz'". - * Command should not be expected to return a value, other than - * possibly true/false to indicate the success of the call. - * - * - * Framework implementations of common data providers can be found in: - * {LIB}/classes/dataProviders and should be named FooDataProvider.class.php. - * Framework data providers can be invoked by doing: - * $app->GetDataProvider('FooDataProvider'); - * - * Custom data providers should be placed in: - * {HOME}/classes/dataProviders and should be named FooDataProvider.class.php. - * Custom data providers can be invoked by doing: - * $app->GetDataProvider('foo',true); // true --> custom - * - * @author ahart - * - */ -interface Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider { - - /** - * Constructor - Instantiate the provider but do not yet connect - * to the underlying data source. - * - * @param $options array An optional set of configuration values - */ - public function __construct($options = array()); - - /** - * Initiate a connection to the underlying data source - * - * @param $options array An optional set of configuration values - * @return boolean True or false depending on the result - */ - public function connect($options = array()); - - /** - * Disconnect from the underlying data source and perform any - * cleanup operations necessary. - * - * @param $options array An optional set of configuration values - * @return unknown_type True or false depending on the result - */ - public function disconnect($options = array()); - - /** - * Request data from the underlying data source. - * - * @param $request mixed The request itself, usually a string. The nature - * of the request is necessarily implementation - * specific and will vary across providers. For a - * SQL-like relational provider, this will likely be - * a "SELECT ..." string. - * @param $options array An array of options to configure the request. - * These will be implementation-specific and - * therefore will likely differ across providers. - * @return ApplicationDataResponse The resulting data retrieved - */ - public function request($request,$options = array()); - - /** - * Send a command to the underlying data source. - * - * @param $command mixed The command itself, usually a string. The nature - * of the command is necessarily implementation - * specific and will vary across providers. For a - * SQL-like relational provider, this will likely be - * a "UPDATE ...", or "CREATE ..." string. - * @param $options array An array of options to configure the command. - * These will be implementation-specific and - * therefore will likely differ across providers. - * @return boolean True or false depending on the success of the command - */ - public function command($command,$options = array()); - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Interfaces/IApplicationErrorProvider.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Interfaces/IApplicationErrorProvider.php b/balance/lib/pear/Interfaces/IApplicationErrorProvider.php deleted file mode 100644 index 63262a1..0000000 --- a/balance/lib/pear/Interfaces/IApplicationErrorProvider.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * IApplicationErrorProvider defines an interface that should be implemented - * by all error providers to simplify the process of formatting and displaying - * application errors. - * - * - * @author ahart - */ -interface Org_Apache_Oodt_Balance_Interfaces_IApplicationErrorProvider { - - /** - * Causes an error response to be sent to the sender - * - * @param integer $httpResponseCode The HTTP response code to send - * @param string $message A contextual message to include or log - */ - public function error($httpResponseCode,$message = '',$options=array()); -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Interfaces/IApplicationWidget.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Interfaces/IApplicationWidget.php b/balance/lib/pear/Interfaces/IApplicationWidget.php deleted file mode 100644 index b1e4831..0000000 --- a/balance/lib/pear/Interfaces/IApplicationWidget.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * Interface for developing widgets (reusable bits of view code) that can - * be placed on different application pages. - * - * This interface defines two mandatory functions: - * - construct : Intialize the widget and provide any necessary - * configuration information - * - render : Build the HTML output that constitutes the widget. This - * function does not accept arguments (any config should - * be provided either in the controller or via other "set" - * functions. This function should return a string composed - * of the final HTML output of the widget. - * - * Framework widgets can be found inside the {LIB}/scripts/widgets directory. - * - * Framework Widgets can be invoked from view code as follows: - * // Create an instance of the widget (will transparently call __construct) - * $myFooWidget = $app->createWidget('FooWidget',array(..config..)) - * - * Custom widgets should be placed inside the {HOME}/scripts/widgets directory and - * can be named FooWidget.php. All widgets must implement this interface. - * - * Custom Widgets can be invoked from view code as follows: - * // Create an instance of the widget (will transparently call __construct) - * $myFooWidget = $app->createWidget('FooWidget',array(..config..),true) // true --> custom - * - * <!-- (all widgets, framework or custom): display widget contents --> - * <span><?php echo $myFooWidget->render()?></span> - * - * @author ahart - * - */ -interface Org_Apache_Oodt_Balance_Interfaces_IApplicationWidget { - - public function __construct($options = array()); - - /** - * Build the HTML output that constitutes the widget. - * - * @param boolean $bEcho (default = true) If true, the function should - * echo the contents directly. If false, the contents should be - * returned as a string. - */ - public function render($bEcho = true); - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Providers/Authentication/LDAPAuthenticationProvider.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Providers/Authentication/LDAPAuthenticationProvider.class.php b/balance/lib/pear/Providers/Authentication/LDAPAuthenticationProvider.class.php deleted file mode 100644 index 9e4c6f9..0000000 --- a/balance/lib/pear/Providers/Authentication/LDAPAuthenticationProvider.class.php +++ /dev/null @@ -1,170 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * Implementation of iApplicationAuthenticationProvider, which extends SingleSignOn. - * - * Note: This class has a dependency on the OODT CAS-SSO package. - * The necessary files can be found at http://pear.apache.org/oodt/ - * along with installation instructions. - * - * @author s.khudikyan - * @author ahart - * - */ -require("Org/Apache/Oodt/Security/SingleSignOn.php"); - -class Org_Apache_Oodt_Balance_Providers_Authentication_LDAPAuthenticationProvider - extends Org_Apache_Oodt_Security_SingleSignOn - implements Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthenticationProvider { - - /** - * If authentication config file exists, require(file_name) file - */ - public function __construct() { - - // set LDAP constants - define("CAS_SECURITY",true); - define("SSO_LDAP_HOST", App::Get()->settings['ldap_host']); - define("SSO_LDAP_PORT", App::Get()->settings['ldap_port']); - define("SSO_BASE_DN", App::Get()->settings['ldap_base_dn']); - define("SSO_GROUPS_DN", App::Get()->settings['ldap_group_dn']); - define("SSO_COOKIE_KEY", App::Get()->settings['cookie_key']); - - } - - public function connect() { - return parent::connect(func_get_arg(0),func_get_arg(1)); - } - - public function disconnect() { - - } - - public function isLoggedIn() { - return parent::isLoggedIn(); - } - - public function login( $username, $password ) { - return parent::login( $username, $password ); - } - - public function logout() { - parent::logout(); - } - - public function getCurrentUsername() { - return parent::getCurrentUsername(); - } - - public function changePassword( $newPassword ) { - if ( App::Get()->settings['authentication_encryption_method'] ) { - return parent::changePassword( $newPassword, App::Get()->settings['authentication_encryption_method'] ); - } - return parent::changePassword( $newPassword ); - } - - public function validateChangePassword( $newPass, $encryptionMethod = "SHA" ) { - $isValid = true; - $messages = array(); - // validate rules from config file - $rules = App::Get()->settings['security_password_rules']; - - if ( isset($rules) ) { - foreach( $rules as $rule ){ - - // Separate the rule from the error message - list($regularExpression,$errorMessage) = explode('|',$rule,2); - - // Test the rule - $rulePassed = preg_match($regularExpression, $newPass); - - // If the rule failed, append the error message - if (!$rulePassed) { - $messages[] = $errorMessage; - $isValid = false; - } - } - } - - if ($isValid && $this->connect(SSO_LDAP_HOST,SSO_LDAP_PORT)) { - $result = $this->changePassword($newPass,$encryptionMethod); - return true; - } else - return $messages; - } - - public function retrieveUserAttributes( $username, $attributes ) { - $rawArray = parent::retrieveUserAttributes( $username, $attributes ); - $userAttributes = array(); - - if ( count($rawArray) > 1 ) { - $rawArray = $rawArray[0]; - // Get only necessary attributes to return - foreach ( $rawArray as $key=>$keyValue ) { - foreach ( $attributes as $value ) { - if ( $key === $value ) { - $userAttributes[$key] = $keyValue[0]; - } - } - } - } - return $userAttributes; - } - - public function addUser($userInfo) { - $ldapconn = $this->connect(SSO_LDAP_HOST,SSO_LDAP_PORT); - if ($ldapconn) { - $user = "uid={$userInfo[ "uid" ]}," . SSO_BASE_DN; - return ldap_add($ldapconn,$user,$userInfo); - } - // connection failed - return false; - } - - public function usernameAvailability( $username ) { - $justthese = array( App::Get()->settings['username_attr'] ); - $profile = $this->retrieveUserAttributes($username, $justthese); - if (count($profile) > 0) { - return false; - } else { - // available - return true; - } - } - - public function updateProfile($newInfo) { - - if ($this->isLoggedIn()) { - $user = "uid={$this->getCurrentUsername()}," . SSO_BASE_DN ; - $ldapconn = $this->connect(SSO_LDAP_HOST,SSO_LDAP_PORT); - - if (ldap_mod_replace($ldapconn,$user,$newInfo)) { - return true; - } else { - return false; - } - } else { - return false; - } - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php b/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php deleted file mode 100644 index 764dfc8..0000000 --- a/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * IApplicationAuthenticationProvider defines an interface that should be - * implemented by all authentication providers to simplify the process of - * accessing and retrieving information about the underlying system. - * - * The interface defines five mandatory functions: - * - __construct: Provide any necessary configuration information but do - * not actually establish a connection to the underlying system. - * - connect: This function does the work of actually connecting to the - * underlying system. Options can be provided either here or in - * the constructor arguments (or both), but the connection to the - * underlying system should not be initiated until this function - * is invoked. - * - disconnect: Disconnect from the underlying system, performing any - * necessary clean up operations in the process. - * - checkLogin: Check if a valid user has logged in. - * - login: Determine the ability to gain access to the underlying system - * as a legitimate user. The requirements are a valid username - * (or user ID) and password. - * - logout: Ending the user's session to the underlying system. - * - * - * Framework implementations of common authentication providers can be found in: - * {LIB}/classes/authenticationProviders and should be named FooAuthenticationProvider.class.php. - * Framework authentication providers can be invoked by doing: - * $app->GetAuthenticationProvider('FooAuthenticationProvider'); - * - * Custom authentication providers should be placed in: - * {HOME}/classes/authenticationProviders and should be named FooAuthenticationProvider.class.php. - * Custom authentication providers can be invoked by doing: - * $app->GetAuthenticationProvider('foo',true); // true --> custom - * - * @author s.khudikyan - * - */ - -class Org_Apache_Oodt_Balance_Providers_Authorization_LDAPAuthorizationProvider - implements Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthorizationProvider { - - /** - * If authorization config file exists, require(file_name) file - */ - public function __construct() { - // Set LDAP constants - define("AUTH_BASE_DN", App::Get()->settings['authorization_ldap_base_dn']); - define("AUTH_GROUPS_DN", App::Get()->settings['authorization_ldap_group_dn']); - define("AUTH_LDAP_HOST", App::Get()->settings['authorization_ldap_host']); - define("AUTH_LDAP_PORT", App::Get()->settings['authorization_ldap_port']); - } - - public function retrieveGroupsForUser($username,$searchDirectory = AUTH_GROUPS_DN) { - - // attempt to connect to ldap server - $ldapconn = $this->connect(AUTH_LDAP_HOST,AUTH_LDAP_PORT); - $groups = array(); - if ($ldapconn) { - $filter = "(&(objectClass=groupOfUniqueNames)" - ."(uniqueMember=uid={$username}," . AUTH_BASE_DN . "))"; - $result = ldap_search($ldapconn,$searchDirectory,$filter,array('cn')); - - if ($result) { - $entries = ldap_get_entries($ldapconn,$result); - foreach ($entries as $rawGroup) { - if (isset($rawGroup['cn'][0]) - && $rawGroup['cn'][0] != '') { - $groups[] = $rawGroup['cn'][0]; - } - } - } - } - return $groups; - } - - public function connect() { - if ($conn = ldap_connect(func_get_arg(0),func_get_arg(1))) { - // Connection established - $this->connectionStatus = 1; - ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3); - ldap_set_option($conn, LDAP_OPT_DEBUG_LEVEL, 7); - ldap_set_option($conn, LDAP_OPT_REFERRALS, 0); - $this->conn = $conn; - return $conn; - } else { - // Connection failed - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php b/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php deleted file mode 100644 index 839c02d..0000000 --- a/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php +++ /dev/null @@ -1,137 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * Implementation of IApplicationDataProvider for PEAR MDB2. - * - * @author s.khudikyan - * @author ahart - * - */ -require_once( 'MDB2.php' ); - -class Org_Apache_Oodt_Balance_Providers_Data_MDB2DataProvider - implements Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider { - - public $link; - - public function __construct($options = array()) { - - } - - public function connect($options = array()) { - $dsn = 'mysql://'.$options['username'].':'.$options['password'].'@'.$options['server'].'/'.$options['database']; - $this->link = MDB2::singleton( $dsn ); - - if ( PEAR::isError($this->link) ) { - - die("There was an error connecting to the database: " . $this->link->getMessage()); - } - } - - public function disconnect($options = array()) { - if ($this->link) { - $this->link->disconnect(); - } - } - - public function request($request,$options = array() ) { - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - - if ($this->link) { - - // Handle associative array - if (isset($options['format']) && - strtolower($options['format']) == 'assoc') { - - // Execute the request and build a response object - $result = $this->link->queryAll($request,null,MDB2_FETCHMODE_ASSOC); - } - - // Handle numeric array - else { - - // Execute the request and build a response object - $result = $this->link->queryAll($request,null,MDB2_FETCHMODE_ORDERED); - } - - if ( PEAR::isError($result) ) { - - $data->setError($result->getMessage()); - return $data; - } else { - - // Store the request used to generate the data - $data->bulkAdd($result); - - // Free the request - $this->link->free(); - - // Return the requested data - return $data; - } - } else { - $data->setError("Unable to establish connection to data source"); - return $data; - } - } - - public function command($command,$options = array()) { - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - - if ($this->link) { - - $result = $this->link->exec($command); - - if ( PEAR::isError($result) ) { - - $data->setError($result->getMessage()); - return $data; - } - } else { - $data->setError("Unable to establish connection to data source"); - return $data; - } - } - - public function lastInsertedId($options = array()){ - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - - if ($this->link) { - - $result = $this->link->lastInsertId(); - - if ( PEAR::isError($result) ) { - - $data->setError($result->getMessage()); - return $data; - } else { - - return $result; - - } - } else { - $data->setError("Unable to establish connection to data source"); - return $data; - } - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php b/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php deleted file mode 100644 index fac93c4..0000000 --- a/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php +++ /dev/null @@ -1,128 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * Implementation of IApplicationDataProvider for a MySql database. - * - * @author ahart - * - */ -class Org_Apache_Oodt_Balance_Providers_Data_MySqlDataProvider - implements Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider { - - public $link; - - public function __construct($options = array()) { - - } - - public function connect($options = array()) { - $this->link = mysql_connect($options['server'], - $options['username'], - $options['password']) or - die("Could not connect: " . mysql_error()); - mysql_select_db($options['database'],$this->link) or - die("Could not select database: " . mysql_error()); - } - - public function disconnect($options = array()) { - if ($this->link) { - mysql_close($this->link); - } - } - - public function request($request,$options = array()) { - if ($this->link) { - - // Execute the request and build a response object - $raw = mysql_query($request,$this->link); - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - - if ('' != ($errMessage = mysql_error($this->link))) { - $data->setError($errMessage); - return $data; - } else { - - // Handle associative array - if (isset($options['format']) && - strtolower($options['format']) == 'assoc') { - $idx = 0; - while (false !== $row = mysql_fetch_assoc($raw)) { - if (isset($options['indexKey'])) { - $data->add($raw[$options['indexKey']],$row); - } else { - $data->add($idx++,$row); - } - } - } - - // Handle numeric array - else { - $idx = 0; - while (false !== $row = mysql_fetch_row($raw)) { - if (isset($options['indexKey'])) { - $data->add($raw[$options['indexKey']],$row); - } else { - $data->add($idx++,$row); - } - } - } - - // Store the request used to generate the data - $data->setRequestString($request); - - // Free the request - mysql_free_result($raw); - - // Return the requested data - return $data; - } - } else { - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - $data->setError("Unable to establish connection to data source"); - return $data; - } - } - - public function command($command,$options = array()) { - if ($this->link) { - - mysql_query($command); - - } else { - $data = Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - $data->setError("Unable to establish connection to data source"); - return $data; - } - } - - public function lastInsertedId($options = array()){ - if ($this->link) { - - return mysql_insert_id(); - - } else { - $data = Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - $data->setError("Unable to establish connection to data source"); - return $data; - } - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Providers/Data/PDODataProvider.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Providers/Data/PDODataProvider.class.php b/balance/lib/pear/Providers/Data/PDODataProvider.class.php deleted file mode 100644 index d32530c..0000000 --- a/balance/lib/pear/Providers/Data/PDODataProvider.class.php +++ /dev/null @@ -1,142 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * Implementation of IApplicationDataProvider for PHP PDO. - * - * @author s.khudikyan - * @author ahart - * - */ -class Org_Apache_Oodt_Balance_Providers_Data_PDODataProvider - implements Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider { - - public $link; - - public function __construct($options = array()) { - - } - - public function connect($options = array()) { - try { - $dsn = 'mysql:host='.$options['server'].';dbname='.$options['database']; - $this->link = new PDO( $dsn, $options['username'], $options['password'] ); - } catch (PDOException $e) { - die("There was an error connecting to the database: " . $e->getMessage()); - } - } - - public function disconnect($options = array()) { - if ($this->link) { - /*** close the database connection ***/ - $this->link = null; - } - } - - public function request($request,$options = array() ) { - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - - if ($this->link) { - - // Handle associative array - if (isset($options['format']) && - strtolower($options['format']) == 'assoc') { - - try { - // fetch into an PDOStatement object - $stmt = $this->link->queryAll($request); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - } catch (PDOException $e) { - - $data->setError( $e->getMessage() ); - return $data; - } - } - - // Handle numeric array - else { - try { - // fetch into an PDOStatement object - $stmt = $this->link->queryAll($request); - $result = $stmt->fetch(PDO::FETCH_NUM); - } catch (PDOException $e) { - - $data->setError( $e->getMessage() ); - return $data; - } - } - - // Store the request used to generate the data - $data->bulkAdd($result); - - // Free the request - $this->link->free(); - - // Return the requested data - return $data; - - } else { - $data->setError("Unable to establish connection to data source"); - return $data; - } - } - - public function command($command,$options = array()) { - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - - if ($this->link) { - - try { - - $result = $this->link->exec( $command ); - } catch (PDOException $e) { - - $data->setError( $e->getMessage() ); - return $data; - } - - } else { - $data->setError( "Unable to establish connection to data source" ); - return $data; - } - } - - public function lastInsertedId($options = array()){ - $data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse(); - - if ($this->link) { - - try { - $lastId = $this->link->lastInsertId(); - } catch (PDOException $e) { - - $data->setError( $e->getMessage() ); - return $data; - } - return $lastId; - - } else { - $data->setError("Unable to establish connection to data source"); - return $data; - } - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php ---------------------------------------------------------------------- diff --git a/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php b/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php deleted file mode 100644 index 6c929f2..0000000 --- a/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * OODT Balance - * Web Application Base Framework - * - * A very simple default implementation of the IApplicationErrorProvider - * interface that simply looks for a view in HOME/views/common/###.php where - * ### matches the provided http code. - * - * @author ahart - */ -class Org_Apache_Oodt_Balance_Providers_Error_DefaultErrorProvider - implements Org_Apache_Oodt_Balance_Interfaces_IApplicationErrorProvider { - - - public function error($httpResponseCode,$message = '',$options = array()) { - require(HOME . '/views/error/' . $httpResponseCode . '.php'); - exit(); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/README ---------------------------------------------------------------------- diff --git a/balance/lib/pear/README b/balance/lib/pear/README deleted file mode 100644 index 5254dd1..0000000 --- a/balance/lib/pear/README +++ /dev/null @@ -1,34 +0,0 @@ -OODT Balance - Framework Library - -OVERVIEW -==================== - -This is the OODT Balance Framework library. It provides a common codebase -upon which to build PHP web applications utilizing the OODT framework. - -More information about the project is available at http://oodt.apache.org/ - -INSTALLATION -==================== - -The library is provided as a PHP Extension and Application Repository (PEAR) -package. More information on how to install the PEAR package manager on your -system can be found at: http://pear.php.net/manual/en/installation.php - -Assuming you have the PEAR package manager installed correctly: - -1) "cd" into the src/pear directory (you should see a package.xml file) -2) Build the pear package: - $ pear package -3) Install the resulting tarball: - $ (sudo) pear install --force Org_Apache_Oodt_Balance_...tgz - - -USAGE -===================== - -This library forms a codebase upon which applications can be developed. It is a -prerequisite for Balance application development, but can do nothing on its own. -For information on creating and developing applications that target this library, -visit http://oodt.apache.org/ - http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/balance/lib/pear/package.xml ---------------------------------------------------------------------- diff --git a/balance/lib/pear/package.xml b/balance/lib/pear/package.xml deleted file mode 100644 index dc5c5a3..0000000 --- a/balance/lib/pear/package.xml +++ /dev/null @@ -1,136 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ ---> -<!-- - @package Org_Apache_Oodt_Balance - @author Andrew F. Hart - @version $Id$ ---> -<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" - xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0.xsd - http://pear.php.net/dtd/package-2.0 - http://pear.php.net/dtd/package-2.0.xsd"> - <name>Apache_OODT_Balance</name> - <channel>pear.apache.org/oodt</channel> - <summary>OODT Balance Webapp Base Package</summary> - <description> - This package provides the OODT Balance webapp-base package required - by all Balance-based web applications. - </description> - <lead> - <name>Andrew Hart</name> - <user>ahart</user> - <email>[email protected]</email> - <active>yes</active> - </lead> - <date>2013-06-29</date> - <version> - <release>0.6.0</release> - <api>0.6.0</api> - </version> - <stability> - <release>stable</release> - <api>stable</api> - </stability> - <license uri="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0 License</license> - <notes> - This package provides the OODT Balance webapp-base package required - by all Balance-based web applications. - </notes> - <contents> - <dir name="/" baseinstalldir="Org/Apache/Oodt/Balance"> - <dir name="Boot"> - <file name="bootstrap.php" role="php"/> - </dir> - <dir name="Core"> - <file name="Application.class.php" role="php"/> - <file name="ApplicationDataResponse.class.php" role="php"/> - <file name="ApplicationRequest.class.php" role="php"/> - <file name="ApplicationResponse.class.php" role="php"/> - </dir> - <dir name="Interfaces"> - <file name="IApplicationAuthenticationProvider.php" role="php"/> - <file name="IApplicationAuthorizationProvider.php" role="php"/> - <file name="IApplicationDataProvider.php" role="php"/> - <file name="IApplicationErrorProvider.php" role="php"/> - <file name="IApplicationWidget.php" role="php"/> - </dir> - <dir name="Providers"> - <dir name="Authentication"> - <file name="LDAPAuthenticationProvider.class.php" role="php"/> - </dir> - <dir name="Authorization"> - <file name="LDAPAuthorizationProvider.class.php" role="php"/> - </dir> - <dir name="Data"> - <file name="MySqlDataProvider.class.php" role="php"/> - </dir> - <dir name="Error"> - <file name="DefaultErrorProvider.class.php" role="php"/> - </dir> - </dir> - </dir><!-- / --> - </contents> - <dependencies> - <required> - <php> - <min>5.1.6</min> - </php> - <pearinstaller> - <min>1.6.1</min> - </pearinstaller> - </required> - </dependencies> - <phprelease /> - <changelog> - <release> - <version> - <release>0.2.0</release> - <api>0.2.0</api> - </version> - <stability> - <release>stable</release> - <api>stable</api> - </stability> - <date>2011-02-03</date> - <license uri="http://oodt.jpl.nasa.gov">OODT License</license> - <notes> - Improvements to the core library to support more flexible use - of modules and greater reusability. - </notes> - </release> - <release> - <version> - <release>0.1.0</release> - <api>0.1.0</api> - </version> - <stability> - <release>stable</release> - <api>stable</api> - </stability> - <date>2010-11-01</date> - <license uri="http://oodt.jpl.nasa.gov">OODT License</license> - <notes> - This release marks the first release of the OODT Balance webapp-base package. - </notes> - </release> - </changelog> -</package>
