SetClientIp(GetClientIp()); $user->SetClientAgent(GetClientAgent()); $siteConnection = new MgSiteConnection(); $siteConnection->Open($user); } else { /* If a session has previously been established, we can connect using the * credentials that the user logged in with previously ... these are stored * in the MapGuide session. * It is possible for the user to re-authenticate using a different set of * credentials. Handle this here, but keep the session the same. */ $sessionID = $_REQUEST['session']; session_id(str_replace('_', '-', $sessionID)); session_start(); /* current user is re-authenticating or not? */ if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) { $user = new MgUserInformation($_REQUEST['username'], $_REQUEST['password']); $user->SetClientIp(GetClientIp()); $user->SetClientAgent(GetClientAgent()); $user->SetMgSessionId($sessionID); } else { $user = new MgUserInformation($sessionID); $user->SetClientIp(GetClientIp()); $user->SetClientAgent(GetClientAgent()); } /* open a connection to the site. This will generate exceptions if the user * is set up properly - not found, invalid password etc */ $siteConnection = new MgSiteConnection(); $siteConnection->Open($user); /* MgUserInformation doesn't tell us who is logged in so we store it * in the php session for convenience */ if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) { $_SESSION['username'] = $_REQUEST['username']; } //echo "".$_SESSION['username']. ''; } } catch (MgAuthenticationFailedException $afe) { header('Content-type: text/xml'); echo ""; echo "Authentication Failed"; echo "" . $afe->GetMessage() . ""; echo "
" . $afe->GetDetails() . "
"; echo "
"; exit; } catch (MgUserNotFoundException $unfe) { header('Content-type: text/xml'); echo ""; echo "User Not Found"; echo "" . $unfe->GetMessage() . ""; echo "
" . $unfe->GetDetails() . "
"; echo "
"; exit; } catch (MgSessionExpiredException $see) { header('Content-type: text/xml'); echo ""; echo "Session Expired"; echo "" . $see->GetMessage() . ""; echo "
" . $see->GetDetails() . "
"; echo "
"; exit; } catch (MgException $e) { header('Content-type: text/xml'); echo ""; echo "Exception"; echo "" . $e->GetMessage() . ""; echo "
" . $e->GetDetails() . "
"; echo "
"; exit; } //common resource service to be used by all scripts $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService); if (isset($_REQUEST['mapname'])) { $mapName = $_REQUEST['mapname']; $mapResourceID = new MgResourceIdentifier( 'Session:'.$sessionID.'//'.$mapName.'.MapDefinition'); $mapStateID = new MgResourceIdentifier('Session:'.$sessionID.'//'.$mapName.'.'.MgResourceType::Map); } function GetDefaultLocale() { return "en"; // localizable string } function GetLocalizationPath() { $thisFile = __FILE__; $pos = strrpos($thisFile, '\\'); if ($pos == false) $pos = strrpos($thisFile, '/'); return substr($thisFile, 0, $pos+1) . "../../../localized/"; } function FormatMessage($id, $locale, $params) { $text = GetString($id, $locale); for($i = 0; $i < count($params); $i++) { $tag = "{" . $i . "}"; $pos1 = strpos($text, $tag); if($pos1 == false) break; if($pos1 > 0) $begin = substr($text, 0, $pos1); else $begin = ""; $end = substr($text, $pos1 + strlen($tag)); $text = $begin . $params[$i] . $end; } return $text; } function GetSurroundVirtualPath() { if (isset($_SERVER["REQUEST_URI"])) { $path = $_SERVER["REQUEST_URI"]; $baseuri = substr($path, 0, strrpos($path, '?') + 1); } else { $baseuri = $_SERVER["PHP_SELF"]; } return substr($baseuri, 0, strrpos($baseuri, '/') + 1); } function GetRootVirtualFolder() { if (isset($_SERVER["REQUEST_URI"])) { $path = $_SERVER["REQUEST_URI"]; $baseuri = substr($path, 0, strrpos($path, '?') + 1); } else { $baseuri = $_SERVER["PHP_SELF"]; } return substr($baseuri, 0, strpos($baseuri, '/', 1)); } function GetClientOS() { if(!isset($_SERVER['HTTP_USER_AGENT'])) return 0; $agent = $_SERVER['HTTP_USER_AGENT']; if(strpos($agent, "Windows") != FALSE) return 0; else if(strpos($agent, "Macintosh") != FALSE) return 1; return 2; } function EscapeForHtml($str) { $org = array("'", "\"", "\n", "<", ">"); $repl = array("'", """, " ", "<", ">" ); return str_replace($org, $repl, $str); } function GetDecimalFromLocalizedString($numberString, $locale) { if($locale != null && $numberString != null) { // Remove thousand separators $thousandSeparator = GetLocalizedString("THOUSANDSEPARATOR", $locale); if($thousandSeparator != null && strlen($thousandSeparator) > 0) { $numberString = str_replace($thousandSeparator, "", $numberString); } // Replace localized decimal separators with "." $decimalSeparator = GetLocalizedString("DECIMALSEPARATOR", $locale); if($decimalSeparator != null && strlen($decimalSeparator) > 0 && $decimalSeparator != ".") { $numberString = str_replace($decimalSeparator, ".", $numberString); } } return $numberString; } function GetClientIp() { $clientIp = ''; if (array_key_exists('HTTP_CLIENT_IP', $_SERVER) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknown') != 0) { $clientIp = $_SERVER['HTTP_CLIENT_IP']; } else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknown') != 0) { $clientIp = $_SERVER['HTTP_X_FORWARDED_FOR']; } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) { $clientIp = $_SERVER['REMOTE_ADDR']; } return $clientIp; } function GetClientAgent() { return "Fusion Viewer"; } ?>