public function buildNativeWebTemplatesForPlatform($platform)
 {
     $pages = array_keys($this->getModuleSections('pages'));
     if ($pages) {
         $pages = array_diff($pages, array('pane'));
     }
     if (!$pages) {
         throw new KurogoConfigurationException("module does not have any pages defined in pages.ini");
     }
     $additionalAssets = $this->nativeWebTemplateAssets();
     $nativeConfig = $this->getOptionalModuleSection('native_template');
     if ($nativeConfig && $nativeConfig['additional_assets']) {
         $additionalAssets = array_unique(array_merge($additionalAssets, $nativeConfig['additional_assets']));
     }
     // Phone version
     $rewriter = new KurogoWebBridge($this->configModule, KurogoWebBridge::PAGETYPE_PHONE, $platform, KurogoWebBridge::BROWSER);
     $rewriter->saveTemplates($pages, $additionalAssets);
     if (Kurogo::getOptionalSiteVar('NATIVE_TABLET_ENABLED', 1)) {
         // Tablet version
         $rewriter = new KurogoWebBridge($this->configModule, KurogoWebBridge::PAGETYPE_TABLET, $platform, KurogoWebBridge::BROWSER);
         $rewriter->saveTemplates($pages, $additionalAssets);
     }
 }
Exemple #2
0
 /**
  * Factory method. Used to instantiate a subclass
  * @param string $id, the module id to load
  * @param string $type, the type of module to load (web/api)
  */
 public static function factory($id, $type = null)
 {
     if ($id == 'kurogo') {
         set_exception_handler("exceptionHandlerForError");
     }
     if (!self::isValidModuleName($id)) {
         throw new KurogoException(Kurogo::getLocalizedString('ERROR_INVALID_MODULE'));
     }
     Kurogo::log(LOG_INFO, "Initializing {$type} module {$id}", 'module');
     $configModule = $id;
     $configStore = Kurogo::configStore();
     //attempt to load config/$id/module.ini
     if ($moduleData = $configStore->getOptionalSection('module', 'module', $configModule)) {
         $id = Kurogo::arrayVal($moduleData, 'id', $configModule);
     } else {
         throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
     }
     // see if the class location has been cached
     if ($moduleFile = Kurogo::getCache(self::cacheKey($id, $type))) {
         $className = basename($moduleFile, '.php');
         include_once $moduleFile;
         $module = new $className();
         if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
             $module->setID($id);
         }
         $module->setConfigModule($configModule);
         Kurogo::addModuleLib($id);
         return $module;
     }
     // when run without a type it will find either
     $classNames = array('web' => ucfirst($id) . 'WebModule', 'api' => ucfirst($id) . 'APIModule', 'shell' => ucfirst($id) . 'ShellModule');
     // if we specified a type, include only that type in the array
     if ($type) {
         if (isset($classNames[$type])) {
             $classNames = array($classNames[$type]);
         } else {
             throw new KurogoException("Invalid module type {$type}");
         }
     }
     // possible module paths.
     // 1. Site Folder SiteMODULEIDXXXModule
     // 2. Site Folder MODULEIDXXXModule
     // 3. Project folder MODULEIDXXXModule
     // Note: The PHP class name MUST be the basename of the file path.
     $modulePaths = array(SITE_MODULES_DIR . "/{$id}/Site%s.php", SITE_MODULES_DIR . "/{$id}/%s.php", SHARED_MODULES_DIR . "/{$id}/Site%s.php", SHARED_MODULES_DIR . "/{$id}/%s.php", MODULES_DIR . "/{$id}/%s.php");
     if ($type == 'api' && KurogoWebBridge::moduleHasMediaAssets($configModule)) {
         $modulePaths[] = LIB_DIR . '/' . KurogoWebBridge::STUB_API_CLASS . ".php";
     }
     //cycle module paths
     foreach ($modulePaths as $path) {
         $className = basename($path, '.php');
         //cycle class names to find a valid module
         foreach ($classNames as $class) {
             $className = sprintf($className, $class);
             $path = sprintf($path, $class);
             Kurogo::log(LOG_DEBUG, "Looking for {$path} for {$id}", 'module');
             // see if it exists
             $moduleFile = realpath_exists($path);
             if ($moduleFile && (include_once $moduleFile)) {
                 //found it
                 $info = new ReflectionClass($className);
                 if (!$info->isAbstract()) {
                     Kurogo::log(LOG_INFO, "Found {$moduleFile} for {$id}", 'module');
                     $module = new $className();
                     if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
                         $module->setID($id);
                     }
                     $module->setConfigModule($configModule);
                     // cache the location of the class (which also includes the classname)
                     Kurogo::setCache(self::cacheKey($id, $type), $moduleFile);
                     Kurogo::addModuleLib($id);
                     return $module;
                 }
                 Kurogo::log(LOG_NOTICE, "{$class} found at {$moduleFile} is abstract and cannot be used for {$id}", 'module');
                 return false;
             }
         }
     }
     Kurogo::log(LOG_NOTICE, "No valid {$type} class found for module {$id}", 'module');
     throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
 }
 protected function logoutSuccessful()
 {
     $authorityIndex = $this->getArg('authority');
     //if they are still logged in return to the login page, otherwise go home.
     if ($this->isLoggedIn()) {
         $this->redirectTo('index', array('logout' => $authorityIndex));
     } elseif ($this->nativeApp) {
         $this->assign('message', $this->getLocalizedString("LOGOUT_SUCCESSFUL"));
         $this->assign('redirectURL', KurogoWebBridge::getInternalLink($this->configModule, 'logoutComplete', array()));
     } else {
         $this->redirectToModule($this->getHomeModuleID(), '', array('logout' => $authorityIndex));
     }
 }
Exemple #4
0
 function __construct($device = null)
 {
     $this->version = intval(Kurogo::getSiteVar('MOBI_SERVICE_VERSION'));
     $this->userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     if (KurogoWebBridge::forceNativePlatform($pagetype, $platform, $browser)) {
         $this->setDevice("{$pagetype}-{$platform}-{$browser}");
     } else {
         if ($device && strlen($device)) {
             Kurogo::log(LOG_DEBUG, "Setting device to {$device} (override)", "deviceDetection");
             $this->setDevice($device);
             // user override of device detection
         } else {
             if (isset($_COOKIE[$this->cookieKey()])) {
                 $cookie = $_COOKIE[$this->cookieKey()];
                 if (get_magic_quotes_gpc()) {
                     $cookie = stripslashes($cookie);
                 }
                 $this->setDeviceFromCookieString($cookie);
                 Kurogo::log(LOG_DEBUG, "Setting device to " . $this->getDevice() . " (cookie)", "deviceDetection");
             } else {
                 if (isset($_SERVER['HTTP_USER_AGENT'])) {
                     $this->classification = $this->detectDevice($this->userAgent);
                     $this->setDeviceCookie();
                 }
             }
         }
     }
     // Do this after caching and setting cookies or the value of TABLET_ENABLED would be effectively cached
     if ($this->classification['pagetype'] == 'tablet' && !Kurogo::getOptionalSiteVar('TABLET_ENABLED', 1)) {
         $this->classification['pagetype'] = 'compliant';
         if ($this->classification['platform'] == 'ipad') {
             $this->classification['platform'] = 'iphone';
             // currently not used but just in case
         }
     }
     // Do this after caching and setting cookies or the value of TOUCH_ENABLED would be effectively cached
     if ($this->classification['pagetype'] == 'touch' && !Kurogo::getOptionalSiteVar('TOUCH_ENABLED', 1)) {
         $this->classification['pagetype'] = 'basic';
     }
 }
 public function smartyOutputfilterAddURLPrefixAndStripWhitespace($source, $smarty)
 {
     // rewrite urls for the device classifier in case  our root is not /
     // also handles debugging mode for paths without hostnames
     $source = preg_replace(';(<[^>]+)(url\\("?\'?|href\\s*=\\s*"|src\\s*=\\s*"|action\\s*=\\s*")(' . URL_PREFIX . '|' . URL_DEVICE_DEBUG_PREFIX . '|/);', '\\1\\2' . URL_PREFIX, $source);
     if (Kurogo::getSiteVar('DEVICE_DEBUG')) {
         // if we are in debugging mode we need to also rewrite full paths with hostnames
         $source = preg_replace(';(<[^>]+)(url\\("?\'?|href\\s*=\\s*"|src\\s*=\\s*")(' . FULL_URL_PREFIX . '|' . FULL_URL_BASE . ');', '\\1\\2' . FULL_URL_PREFIX, $source);
     }
     // Most of the following code comes from the trimwhitespace filter:
     // Pull out the script blocks
     preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match);
     $scriptBlocks = $match[0];
     $source = preg_replace("!<script[^>]*?>.*?</script>!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source);
     // Pull out the pre blocks
     preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match);
     $preBlocks = $match[0];
     $source = preg_replace("!<pre[^>]*?>.*?</pre>!is", '@@@SMARTY:TRIM:PRE@@@', $source);
     // Pull out the textarea blocks
     preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match);
     $textareaBlocks = $match[0];
     $source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
     // remove all leading spaces, tabs and carriage returns NOT
     // preceeded by a php close tag.
     $source = trim(preg_replace('/((?<!\\?>)\\n)[\\s]+/m', '\\1', $source));
     // remove all newlines before and after tags.
     $source = preg_replace('/[\\r\\n]*(<[^>]+>)[\\r\\n]*/m', '\\1', $source);
     // collapse whitespace before and after tags.
     $source = preg_replace(array('/\\s+(<)/m', '/(>)\\s+/s'), array(' \\1', '\\1 '), $source);
     // strip spaces around non-breaking spaces
     $source = preg_replace('/\\s*&nbsp;\\s*/m', '&nbsp;', $source);
     // restore textarea, pre, script and style blocks
     $this->stripWhitespaceReplace("@@@SMARTY:TRIM:TEXTAREA@@@", $textareaBlocks, $source);
     $this->stripWhitespaceReplace("@@@SMARTY:TRIM:PRE@@@", $preBlocks, $source);
     $this->stripWhitespaceReplace("@@@SMARTY:TRIM:SCRIPT@@@", $scriptBlocks, $source);
     if (KurogoWebBridge::shouldRewriteAssetPaths()) {
         // Need to rewrite Kurogo assets to use filenames used in native templates
         $rewriter = new KurogoWebBridge($smarty->getTemplateVars('configModule'));
         $source = $rewriter->rewriteURLsToFilePaths($source);
     }
     return $source;
 }
Exemple #6
0
 /**
  * Factory method. Used to instantiate a subclass
  * @param string $id, the module id to load
  * @param string $type, the type of module to load (web/api)
  */
 public static function factory($id, $type = null)
 {
     if ($id == 'error') {
         set_exception_handler("exceptionHandlerForError");
     }
     Kurogo::log(LOG_INFO, "Initializing {$type} module {$id}", 'module');
     $configModule = $id;
     //attempt to load config/$id/module.ini
     if ($config = ModuleConfigFile::factory($id, 'module', ModuleConfigFile::OPTION_DO_NOT_CREATE)) {
         //use the ID parameter if it's present, otherwise use the included id
         $id = $config->getOptionalVar('id', $id);
     } elseif (!Kurogo::getOptionalSiteVar('CREATE_DEFAULT_CONFIG', false, 'modules')) {
         Kurogo::log(LOG_ERR, "Module config file not found for module {$id}", 'module');
         throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
     }
     // see if the class location has been cached
     if ($moduleFile = Kurogo::getCache(self::cacheKey($id, $type))) {
         $className = basename($moduleFile, '.php');
         include_once $moduleFile;
         $module = new $className();
         if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
             $module->setID($id);
         }
         $module->setConfigModule($configModule);
         if ($config) {
             $module->setConfig('module', $config);
         }
         Kurogo::addModuleLib($id);
         return $module;
     }
     // when run without a type it will find either
     $classNames = array('web' => ucfirst($id) . 'WebModule', 'api' => ucfirst($id) . 'APIModule', 'shell' => ucfirst($id) . 'ShellModule');
     // if we specified a type, include only that type in the array
     if ($type) {
         if (isset($classNames[$type])) {
             $classNames = array($classNames[$type]);
         } else {
             throw new KurogoException("Invalid module type {$type}");
         }
     }
     // possible module paths.
     // 1. Site Folder SiteMODULEIDXXXModule
     // 2. Site Folder MODULEIDXXXModule
     // 3. Project folder MODULEIDXXXModule
     $modulePaths = array(SITE_MODULES_DIR . "/{$id}/Site%s.php" => "Site%s", SITE_MODULES_DIR . "/{$id}/%s.php" => "%s", MODULES_DIR . "/{$id}/%s.php" => "%s");
     if ($type == 'api' && KurogoWebBridge::moduleHasMediaAssets($configModule)) {
         $modulePaths[KurogoWebBridge::STUB_API_CLASS_FILE] = KurogoWebBridge::STUB_API_CLASS;
     }
     //cycle module paths
     foreach ($modulePaths as $path => $className) {
         //cycle class names to find a valid module
         foreach ($classNames as $class) {
             $className = sprintf($className, $class);
             $path = sprintf($path, $class);
             Kurogo::log(LOG_DEBUG, "Looking for {$path} for {$id}", 'module');
             // see if it exists
             $moduleFile = realpath_exists($path);
             if ($moduleFile && (include_once $moduleFile)) {
                 //found it
                 $info = new ReflectionClass($className);
                 if (!$info->isAbstract()) {
                     Kurogo::log(LOG_INFO, "Found {$moduleFile} for {$id}", 'module');
                     $module = new $className();
                     if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) {
                         $module->setID($id);
                     }
                     $module->setConfigModule($configModule);
                     if ($config) {
                         $module->setConfig('module', $config);
                     }
                     // cache the location of the class (which also includes the classname)
                     Kurogo::setCache(self::cacheKey($id, $type), $moduleFile);
                     Kurogo::addModuleLib($id);
                     return $module;
                 }
                 Kurogo::log(LOG_NOTICE, "{$class} found at {$moduleFile} is abstract and cannot be used for {$id}", 'module');
                 return false;
             }
         }
     }
     Kurogo::log(LOG_ERR, "No valid class found for module {$id}", 'module');
     throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id));
 }
 public static function getHelloMessageForModule($id, $platform = null)
 {
     $bridgeConfig = array();
     $mediaInfo = KurogoWebBridge::getAvailableMediaInfoForModule($id);
     foreach ($mediaInfo as $key => $mediaItem) {
         $bridgeConfig[$key] = array('md5' => $mediaItem['md5'], 'url' => $mediaItem['url']);
     }
     if ($bridgeConfig && $platform) {
         $bridgeConfig = isset($bridgeConfig[$platform]) ? array($platform => $bridgeConfig[$platform]) : null;
     }
     return $bridgeConfig ? $bridgeConfig : null;
 }
 function __construct($device = null, $deviceCacheTimeout = null, $override = null)
 {
     $this->version = intval(Kurogo::getSiteVar('MOBI_SERVICE_VERSION'));
     if (isset($override)) {
         $this->override = $override;
         $this->setOverrideCookie($override);
     } elseif (isset($_COOKIE['deviceClassificationOverride'])) {
         $this->override = $_COOKIE['deviceClassificationOverride'];
     }
     $this->userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     if (KurogoWebBridge::forceNativePlatform($pagetype, $platform, $browser)) {
         $this->setDevice("{$pagetype}-{$platform}-{$browser}");
     } else {
         if ($device && strlen($device)) {
             Kurogo::log(LOG_DEBUG, "Setting device to {$device} (override)", "deviceDetection");
             $this->setDevice($device);
             // user override of device detection
             $this->setDeviceCookie($deviceCacheTimeout);
         } else {
             if (isset($_COOKIE[self::cookieKey()])) {
                 $cookie = $_COOKIE[self::cookieKey()];
                 if (get_magic_quotes_gpc()) {
                     $cookie = stripslashes($cookie);
                 }
                 $this->setDeviceFromCookieString($cookie, $deviceCacheTimeout);
                 Kurogo::log(LOG_DEBUG, "Setting device to " . $this->getDevice() . " (cookie)", "deviceDetection");
             } else {
                 if (isset($_SERVER['HTTP_USER_AGENT'])) {
                     $this->classification = $this->detectDevice($this->userAgent);
                     $this->setDeviceCookie($deviceCacheTimeout);
                 }
             }
         }
     }
     // Do this after caching and setting cookies or the values
     // of TABLET_ENABLED and COMPUTER_TABLET_ENABLED would be effectively cached
     if (Kurogo::getOptionalSiteVar('TABLET_ENABLED', 1)) {
         if ($this->classification['platform'] == 'computer') {
             if (Kurogo::getOptionalSiteVar('COMPUTER_TABLET_ENABLED', 1)) {
                 $this->classification['pagetype'] = 'tablet';
             } else {
                 $this->classification['pagetype'] = 'compliant';
             }
         }
     } else {
         if ($this->classification['pagetype'] == 'tablet') {
             $this->classification['pagetype'] = 'compliant';
             // platform ipad is currently not used but just in case:
             if ($this->classification['platform'] == 'ipad') {
                 $this->classification['platform'] = 'iphone';
             }
         }
     }
     // Touch pagetype is no longer supported.  Remap to basic:
     if ($this->classification['pagetype'] == 'touch') {
         $this->classification['pagetype'] = 'basic';
     }
 }
Exemple #9
0
 protected function initializeForPage()
 {
     $this->assign('nativeApp', $this->nativeApp);
     // If this is a native app, use the native app GA id
     if ($this->nativeApp) {
         $this->assign('GOOGLE_ANALYTICS_ID', Kurogo::getOptionalSiteVar('GOOGLE_ANALYTICS_NATIVE_ID'));
     }
     if (!Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) {
         throw new KurogoConfigurationException($this->getLocalizedString("ERROR_AUTHENTICATION_DISABLED"));
     }
     $session = $this->getSession();
     //return URL
     $urlArray = $this->extractModuleArray($this->args);
     //see if remain logged in is enabled by the administrator, then if the value has been passed (i.e. the user checked the "remember me" box)
     $allowRemainLoggedIn = Kurogo::getOptionalSiteVar('AUTHENTICATION_REMAIN_LOGGED_IN_TIME');
     if ($allowRemainLoggedIn) {
         $remainLoggedIn = $this->getArg('remainLoggedIn', 0);
     } else {
         $remainLoggedIn = 0;
     }
     // initialize
     $authenticationAuthorities = array('total' => 0, 'direct' => array(), 'indirect' => array(), 'auto' => array());
     $invalidAuthorities = array();
     // cycle through the defined authorities in the config
     foreach (AuthenticationAuthority::getDefinedAuthenticationAuthorities() as $authorityIndex => $authorityData) {
         // USER_LOGIN property determines whether the authority is used for logins (or just groups or oauth)
         $USER_LOGIN = $this->argVal($authorityData, 'USER_LOGIN', 'NONE');
         // trap the exception if the authority is invalid (usually due to misconfiguration)
         try {
             $authority = AuthenticationAuthority::getAuthenticationAuthority($authorityIndex);
             $authorityData['listclass'] = $authority->getAuthorityClass();
             $authorityData['title'] = $authorityData['TITLE'];
             $authorityData['url'] = $this->buildURL('login', array_merge($urlArray, array('authority' => $authorityIndex, 'remainLoggedIn' => $remainLoggedIn, 'startOver' => 1)));
             if ($USER_LOGIN == 'FORM') {
                 $authenticationAuthorities['direct'][$authorityIndex] = $authorityData;
                 $authenticationAuthorities['total']++;
             } elseif ($USER_LOGIN == 'LINK') {
                 $authenticationAuthorities['indirect'][$authorityIndex] = $authorityData;
                 $authenticationAuthorities['total']++;
             } elseif ($USER_LOGIN == 'AUTO') {
                 $authenticationAuthorities['auto'][$authorityIndex] = $authorityData;
                 $authenticationAuthorities['total']++;
             }
         } catch (KurogoConfigurationException $e) {
             Kurogo::log(LOG_WARNING, sprintf("Invalid authority data for %s: %s", $authorityIndex, $e->getMessage()), 'auth');
             $invalidAuthorities[$authorityIndex] = $e->getMessage();
         }
     }
     //see if we have any valid authorities
     if ($authenticationAuthorities['total'] == 0) {
         $message = $this->getLocalizedString("ERROR_NO_AUTHORITIES");
         if (count($invalidAuthorities) > 0) {
             $message .= sprintf(" %s invalid authorit%s found:\n", count($invalidAuthorities), count($invalidAuthorities) > 1 ? 'ies' : 'y');
             foreach ($invalidAuthorities as $authorityIndex => $invalidAuthority) {
                 $message .= sprintf("%s: %s\n", $authorityIndex, $invalidAuthority);
             }
         }
         //we don't
         throw new KurogoConfigurationException($message);
     }
     //assign template variables
     $this->assign('authenticationAuthorities', $authenticationAuthorities);
     $this->assign('allowRemainLoggedIn', $allowRemainLoggedIn);
     if ($forgetPasswordURL = $this->getOptionalModuleVar('FORGET_PASSWORD_URL')) {
         $this->assign('FORGET_PASSWORD_URL', $this->buildBreadcrumbURL('forgotpassword', array()));
         $this->assign('FORGET_PASSWORD_TEXT', $this->getOptionalModuleVar('FORGET_PASSWORD_TEXT', $this->getLocalizedString('FORGET_PASSWORD_TEXT')));
     }
     $multipleAuthorities = count($authenticationAuthorities['direct']) + count($authenticationAuthorities['indirect']) > 1;
     switch ($this->page) {
         case 'logoutConfirm':
             //this page is presented when a specific authority is chosen and the user is presented the option to actually log out.
             $authorityIndex = $this->getArg('authority');
             if (!$this->isLoggedIn($authorityIndex)) {
                 // they aren't logged in
                 $this->redirectTo('index');
             } elseif ($user = $this->getUser($authorityIndex)) {
                 $authority = $user->getAuthenticationAuthority();
                 $this->assign('message', $this->getLocalizedString('LOGIN_SIGNED_IN_SINGLE', Kurogo::getSiteString('SITE_NAME'), $authority->getAuthorityTitle(), $user->getFullName()));
                 $this->assign('url', $this->buildURL('logout', array('authority' => $authorityIndex)));
                 $this->assign('linkText', $this->getLocalizedString('SIGN_OUT'));
             } else {
                 //This honestly should never happen
                 $this->redirectTo('index');
             }
             break;
         case 'logout':
             $authorityIndex = $this->getArg('authority');
             //hard logouts attempt to logout of the indirect service provider (must be implemented by the authority)
             $hard = $this->getArg('hard', false);
             if (!$this->isLoggedIn($authorityIndex)) {
                 //not logged in
                 $this->redirectTo('index');
             } elseif ($authority = AuthenticationAuthority::getAuthenticationAuthority($authorityIndex)) {
                 $user = $this->getUser($authority);
                 //log them out
                 $result = $session->logout($authority, $hard);
             } else {
                 //This honestly should never happen
                 $this->redirectTo('index');
             }
             if ($result) {
                 $this->setLogData($user, $user->getFullName());
                 $this->logView();
                 //if they are still logged in return to the login page, otherwise go home.
                 if ($this->isLoggedIn()) {
                     $this->redirectTo('index', array('logout' => $authorityIndex));
                 } elseif ($this->nativeApp) {
                     $this->assign('message', $this->getLocalizedString("LOGOUT_SUCCESSFUL"));
                     //					$this->assign('buttonURL', $this->buildURL('logoutComplete'));
                     //					$this->assign('buttonTitle', $this->getLocalizedString('LOGOUT_DISMISS'));
                     $this->assign('redirectURL', KurogoWebBridge::getInternalLink($this->configModule, 'logoutComplete', array()));
                 } else {
                     $this->redirectToModule($this->getHomeModuleID(), '', array('logout' => $authorityIndex));
                 }
             } else {
                 //there was an error logging out
                 $this->assign('message', $this->getLocalizedString("ERROR_SIGN_OUT"));
             }
             break;
         case 'forgotpassword':
             //redirect to forgot password url
             if ($forgetPasswordURL = $this->getOptionalModuleVar('FORGET_PASSWORD_URL')) {
                 Kurogo::redirectToURL($forgetPasswordURL);
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'login':
             //get arguments
             $login = $this->argVal($_POST, 'loginUser', '');
             $password = $this->argVal($_POST, 'loginPassword', '');
             $options = array_merge($urlArray, array('remainLoggedIn' => $remainLoggedIn));
             $session = $this->getSession();
             $session->setRemainLoggedIn($remainLoggedIn);
             $authorityIndex = $this->getArg('authority', '');
             if (!($authorityData = AuthenticationAuthority::getAuthenticationAuthorityData($authorityIndex))) {
                 //invalid authority
                 $this->redirectTo('index', $options);
             }
             if ($this->isLoggedIn($authorityIndex)) {
                 //we're already logged in
                 $this->redirectTo('index', $options);
             }
             $this->assign('authority', $authorityIndex);
             $this->assign('remainLoggedIn', $remainLoggedIn);
             $this->assign('authorityTitle', $authorityData['TITLE']);
             //if they haven't submitted the form and it's a direct login show the form
             if ($authorityData['USER_LOGIN'] == 'FORM' && empty($login)) {
                 if (!($loginMessage = $this->getOptionalModuleVar('LOGIN_DIRECT_MESSAGE'))) {
                     $loginMessage = $this->getLocalizedString('LOGIN_DIRECT_MESSAGE', Kurogo::getSiteString('SITE_NAME'));
                 }
                 $this->assign('LOGIN_DIRECT_MESSAGE', $loginMessage);
                 $this->assign('urlArray', $urlArray);
                 break;
             } elseif ($authority = AuthenticationAuthority::getAuthenticationAuthority($authorityIndex)) {
                 //indirect logins handling the login process themselves. Send a return url so the indirect authority can come back here
                 if ($authorityData['USER_LOGIN'] == 'LINK') {
                     $options['return_url'] = FULL_URL_BASE . $this->configModule . '/login?' . http_build_query(array_merge($options, array('authority' => $authorityIndex)));
                 }
                 $options['startOver'] = $this->getArg('startOver', 0);
                 $result = $authority->login($login, $password, $session, $options);
             } else {
                 $this->redirectTo('index', $options);
             }
             switch ($result) {
                 case AUTH_OK:
                     $user = $this->getUser($authority);
                     $this->setLogData($user, $user->getFullName());
                     $this->logView();
                     if ($this->nativeApp) {
                         $this->assign('showMessage', true);
                         $this->assign('message', $this->getLocalizedString("LOGIN_SUCCESSFUL"));
                         $this->assign('redirectURL', KurogoWebBridge::getInternalLink($this->configModule, 'loginComplete', array()));
                         break 2;
                     } elseif ($urlArray) {
                         $this->redirectToArray($urlArray, Kurogo::REDIRECT_SEE_OTHER);
                     } else {
                         $this->redirectToModule($this->getHomeModuleID(), '', array('login' => $authorityIndex), Kurogo::REDIRECT_SEE_OTHER);
                     }
                     break;
                 case AUTH_OAUTH_VERIFY:
                     // authorities that require a manual oauth verification key
                     $this->assign('verifierKey', $authority->getVerifierKey());
                     $this->setTemplatePage('oauth_verify.tpl');
                     break 2;
                 default:
                     //there was a problem.
                     if ($authorityData['USER_LOGIN'] == 'FORM') {
                         $this->assign('message', $this->getLocalizedString('ERROR_LOGIN_DIRECT'));
                         break 2;
                     } else {
                         $this->redirectTo('index', array_merge(array('messagekey' => 'ERROR_LOGIN_INDIRECT'), $options));
                     }
             }
         case 'index':
             //sometimes messages are passed. This probably has some
             if ($messagekey = $this->getArg('messagekey')) {
                 $this->assign('messagekey', $this->getLocalizedString($messagekey));
                 try {
                     $message = $this->getLocalizedString($messagekey);
                     $this->assign('message', $message);
                 } catch (KurogoException $e) {
                 }
             }
             if ($this->isLoggedIn()) {
                 //if the url is set then redirect
                 if ($urlArray) {
                     $this->redirectToArray($urlArray);
                 }
                 //if there is only 1 authority then redirect to logout confirm
                 if (!$multipleAuthorities) {
                     $user = $this->getUser();
                     $this->redirectTo('logoutConfirm', array('authority' => $user->getAuthenticationAuthorityIndex()));
                 }
                 //more than 1 authority. There could be 1 or more actual logged in users
                 $sessionUsers = $session->getUsers();
                 $users = array();
                 //cycle through the logged in users to build a list
                 foreach ($sessionUsers as $authorityIndex => $user) {
                     $authority = $user->getAuthenticationAuthority();
                     $users[] = array('class' => $authority->getAuthorityClass(), 'title' => count($sessionUsers) > 1 ? $this->getLocalizedString("SIGN_OUT_AUTHORITY", $authority->getAuthorityTitle(), $user->getFullName()) : $this->getLocalizedString('SIGN_OUT'), 'subtitle' => count($sessionUsers) > 1 ? $this->getLocalizedString('SIGN_OUT') : '', 'url' => $this->buildBreadcrumbURL('logout', array('authority' => $authorityIndex), false));
                     //remove the authority from the list of available authorities (since they are logged in)
                     if (isset($authenticationAuthorities['direct'][$authorityIndex])) {
                         unset($authenticationAuthorities['direct'][$authorityIndex]);
                     }
                     if (isset($authenticationAuthorities['indirect'][$authorityIndex])) {
                         unset($authenticationAuthorities['indirect'][$authorityIndex]);
                     }
                 }
                 $this->assign('users', $users);
                 // navlist of users
                 $this->assign('authenticationAuthorities', $authenticationAuthorities);
                 //list of authorities not logged in
                 $this->assign('moreAuthorities', count($authenticationAuthorities['direct']) + count($authenticationAuthorities['indirect']));
                 //see if there are any left
                 if (count($sessionUsers) == 1) {
                     //there's only on logged in user
                     $user = current($sessionUsers);
                     $authority = $user->getAuthenticationAuthority();
                     $this->assign('LOGIN_SIGNED_IN_MESSAGE', $this->getLocalizedString('LOGIN_SIGNED_IN_SINGLE', Kurogo::getSiteString('SITE_NAME'), $authority->getAuthorityTitle(), $user->getFullName()));
                 } else {
                     //there are multiple logged in users
                     $this->assign('LOGIN_SIGNED_IN_MESSAGE', $this->getLocalizedString('LOGIN_SIGNED_IN_MULTIPLE', Kurogo::getSiteString('SITE_NAME')));
                 }
                 //use loggedin.tpl
                 $this->setTemplatePage('loggedin');
             } else {
                 // not logged in
                 // if there is only 1 direct authority then redirect to the login page for that authority
                 if (!$multipleAuthorities && count($authenticationAuthorities['direct'])) {
                     $this->redirectTo('login', array_merge($urlArray, array('authority' => key($authenticationAuthorities['direct']))));
                 }
                 // if there is only 1 auto authority then redirect to the login page for that authority
                 if (!$multipleAuthorities && count($authenticationAuthorities['auto']) && !$messagekey) {
                     $this->redirectTo('login', array_merge($urlArray, array('authority' => key($authenticationAuthorities['auto']))));
                 }
                 // do we have any indirect authorities?
                 if (count($authenticationAuthorities['indirect'])) {
                     if (!($indirectMessage = $this->getOptionalModuleVar('LOGIN_INDIRECT_MESSAGE'))) {
                         $indirectMessage = $this->getLocalizedString('LOGIN_INDIRECT_MESSAGE', Kurogo::getSiteString('SITE_NAME'));
                     }
                     $this->assign('LOGIN_INDIRECT_MESSAGE', $indirectMessage);
                 }
                 // the site can create their own message at the top, or it will use the default message
                 if (!($loginMessage = $this->getOptionalModuleVar('LOGIN_INDEX_MESSAGE'))) {
                     if ($multipleAuthorities) {
                         $loginMessage = $this->getLocalizedString('LOGIN_INDEX_MESSAGE_MULTIPLE', Kurogo::getSiteString('SITE_NAME'));
                     } else {
                         $loginMessage = $this->getLocalizedString('LOGIN_INDEX_MESSAGE_SINGLE', Kurogo::getSiteString('SITE_NAME'));
                     }
                 }
                 $this->assign('LOGIN_INDEX_MESSAGE', $loginMessage);
             }
             break;
     }
 }
Exemple #10
0
 private function initSite(&$path)
 {
     includePackage('Cache');
     includePackage('Config');
     $siteConfig = new ConfigGroup();
     $saveCache = true;
     // Load main configuration file
     $kurogoConfig = ConfigFile::factory('kurogo', 'project', ConfigFile::OPTION_IGNORE_MODE | ConfigFile::OPTION_IGNORE_LOCAL | ConfigFile::OPTION_IGNORE_SHARED);
     $siteConfig->addConfig($kurogoConfig);
     define('CONFIG_MODE', $siteConfig->getVar('CONFIG_MODE', 'kurogo'));
     Kurogo::log(LOG_DEBUG, "Setting config mode to " . (CONFIG_MODE ? CONFIG_MODE : '<empty>'), 'config');
     define('CONFIG_IGNORE_LOCAL', $siteConfig->getVar('CONFIG_IGNORE_LOCAL', 'kurogo'));
     define('CONFIG_IGNORE_SHARED', $siteConfig->getOptionalVar('CONFIG_IGNORE_SHARED', false, 'kurogo'));
     if ($cacheClass = $siteConfig->getOptionalVar('CACHE_CLASS', '', 'cache')) {
         $this->cacher = KurogoMemoryCache::factory($cacheClass, $siteConfig->getOptionalSection('cache'));
     }
     //multi site currently only works with a url base of root "/"
     if ($siteConfig->getOptionalVar('MULTI_SITE', false, 'kurogo')) {
         // in scripts you can pass the site name to Kurogo::initialize()
         if (PHP_SAPI == 'cli') {
             $site = strlen($path) > 0 ? $path : $siteConfig->getVar('DEFAULT_SITE');
             $siteDir = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
             if (!file_exists(realpath($siteDir))) {
                 die("FATAL ERROR: Site Directory {$siteDir} not found for site {$path}");
             }
         } else {
             $paths = explode("/", $path);
             // this is url
             $sites = array();
             $siteDir = '';
             if (count($paths) > 1) {
                 $site = $paths[1];
                 if ($sites = $siteConfig->getOptionalVar('ACTIVE_SITES', array(), 'kurogo')) {
                     //see if the site is in the list of available sites
                     if (in_array($site, $sites)) {
                         $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
                         if (($siteDir = realpath($testPath)) && file_exists($siteDir)) {
                             $urlBase = '/' . $site . '/';
                             // this is a url
                         }
                     }
                 } elseif (self::isValidSiteName($site)) {
                     $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
                     if (($siteDir = realpath($testPath)) && file_exists($siteDir)) {
                         $urlBase = '/' . $site . '/';
                         // this is a url
                     }
                 }
             }
             if (!$siteDir) {
                 $site = $siteConfig->getVar('DEFAULT_SITE');
                 array_splice($paths, 1, 1, array($site, $paths[1]));
                 $url = implode("/", $paths);
                 Kurogo::redirectToURL($url, Kurogo::REDIRECT_PERMANENT);
             }
         }
         define('SITE_NAME', $site);
     } else {
         $site = '';
         //if sites section is set attempt to load a site based on the domain name
         if ($sites = $siteConfig->getOptionalSection('sites')) {
             $host = self::arrayVal($_SERVER, 'SERVER_NAME', null);
             $port = self::arrayVal($_SERVER, 'SERVER_PORT', null);
             //try a direct match
             if (isset($sites[$host])) {
                 $site = $sites[$host];
             } elseif (isset($sites[$host . ':' . $port])) {
                 $site = $sites[$host . ':' . $port];
             } elseif (isset($sites['*'])) {
                 //* is the default site
                 $site = $sites['*'];
             } else {
                 throw new KurogoConfigurationException("Unable to locate a site for this host");
             }
             $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
             if (!($siteDir = realpath($testPath)) || !file_exists($siteDir)) {
                 throw new KurogoConfigurationException("FATAL ERROR: Site Directory " . $testPath . " not found for site " . $site);
             }
         } else {
             //make sure active site is set
             if (!($site = $siteConfig->getVar('ACTIVE_SITE'))) {
                 throw new KurogoConfigurationException("ACTIVE_SITE not set");
             }
             // make sure site_dir is set and is a valid path
             // Do not call realpath_exists here because until SITE_DIR define is set
             // it will not allow files and directories outside ROOT_DIR
             if (!($siteDir = $siteConfig->getVar('SITE_DIR')) || !(($siteDir = realpath($siteDir)) && file_exists($siteDir))) {
                 die("FATAL ERROR: Site Directory " . $siteConfig->getVar('SITE_DIR') . " not found for site " . $site);
             }
         }
         define('SITE_NAME', $site);
         if (PHP_SAPI != 'cli') {
             //
             // Get URL base
             //
             if ($urlBase = $siteConfig->getOptionalVar('URL_BASE', '', 'kurogo')) {
                 $urlBase = rtrim($urlBase, '/') . '/';
             } elseif ($urlBase = Kurogo::getCache('URL_BASE')) {
                 //@TODO this won't work yet because the cache hasn't initialized
                 $urlBase = rtrim($urlBase, '/') . '/';
                 $saveCache = false;
             } else {
                 //extract the path parts from the url
                 $pathParts = array_values(array_filter(explode("/", $_SERVER['REQUEST_URI'])));
                 $testPath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR;
                 $urlBase = '/';
                 //once the path equals the WEBROOT_DIR we've found the base. This only works with symlinks
                 if (realpath($testPath) != WEBROOT_DIR) {
                     foreach ($pathParts as $dir) {
                         $test = $testPath . $dir . DIRECTORY_SEPARATOR;
                         if (file_exists(realpath($test))) {
                             $testPath = $test;
                             $urlBase .= $dir . '/';
                             if (realpath($test) == WEBROOT_DIR) {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (PHP_SAPI == 'cli') {
         define('URL_BASE', null);
     } else {
         if (!isset($urlBase)) {
             throw new KurogoConfigurationException("URL base not set. Please report the configuration to see why this happened");
         }
         define('URL_BASE', $urlBase);
         if ($saveCache) {
             Kurogo::setCache('URL_BASE', $urlBase);
         }
         Kurogo::log(LOG_DEBUG, "Setting site to {$site} with a base of {$urlBase}", 'kurogo');
         // Strips out the leading part of the url for sites where
         // the base is not located at the document root, ie.. /mobile or /m
         // Also strips off the leading slash (needed by device debug below)
         if (isset($path)) {
             // Strip the URL_BASE off the path
             $baseLen = strlen(URL_BASE);
             if ($baseLen && strpos($path, URL_BASE) === 0) {
                 $path = substr($path, $baseLen);
             }
         }
     }
     // Set up defines relative to SITE_DIR
     define('SITE_DIR', $siteDir);
     //already been realpath'd
     define('SITE_LIB_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'lib');
     define('SITE_APP_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app');
     define('SITE_MODULES_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'modules');
     define('DATA_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'data');
     define('WEB_BRIDGE_DIR', SITE_DIR . DIRECTORY_SEPARATOR . KurogoWebBridge::getAssetsDir());
     define('CACHE_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'cache');
     define('LOG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'logs');
     define('SITE_CONFIG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'config');
     define('SITE_DISABLED_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'config_disabled');
     define('SITE_SCRIPTS_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'scripts');
     //load in the site config file (required);
     $config = ConfigFile::factory('site', 'site');
     $siteConfig->addConfig($config);
     // attempt to load site key
     $siteKey = $siteConfig->getOptionalVar('SITE_KEY', md5($siteDir));
     define('SITE_KEY', $siteKey);
     if ($siteConfig->getOptionalVar('SITE_DISABLED')) {
         die("FATAL ERROR: Site disabled");
     }
     // Set up theme define
     if (!($theme = $siteConfig->getVar('ACTIVE_THEME'))) {
         die("FATAL ERROR: ACTIVE_THEME not set");
     }
     Kurogo::log(LOG_DEBUG, "Setting theme to {$theme}", 'kurogo');
     define('THEME_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme);
     define('SHARED_THEME_DIR', SHARED_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme);
     $this->siteConfig = $siteConfig;
 }
 public function getWebBridgeConfig($platform = null)
 {
     return KurogoWebBridge::getHelloMessageForModule($this->configModule, $platform);
 }
Exemple #12
0
 public function getWebBridgeConfig()
 {
     return KurogoWebBridge::getHelloMessageForModule($this->configModule);
 }
Exemple #13
0
 public function getWebBridgeDir()
 {
     return $this->siteDir . DIRECTORY_SEPARATOR . KurogoWebBridge::getAssetsDir();
 }