PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/scalr-2/tags/scalr-2.2.0/app/www/src/prepend.inc.php

http://scalr.googlecode.com/
PHP | 135 lines | 87 code | 33 blank | 15 comment | 23 complexity | 1cb070e469656eb8c5206304f007f5e6 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, GPL-3.0
  1. <?
  2. @session_start();
  3. require_once (dirname(__FILE__)."/../../src/prepend.inc.php");
  4. Scalr_Session::restore();
  5. if (/*isset($_SERVER['HTTP_X_AJAX_SCALR']) && 0 || 0 ||*/ !Scalr_Session::getInstance()->isAuthenticated()) {
  6. // @TODO: must be "!Scalr_Session::getInstance()->isAuthenticated()", this is for testing purpose
  7. Scalr_Session::destroy();
  8. if (isset($_SERVER['HTTP_X_AJAX_SCALR']))
  9. header("HTTP/1.0 403 Forbidden");
  10. else
  11. header('Location: /login.html');
  12. exit();
  13. }
  14. if ( !defined("NO_TEMPLATES")) { // @TODO: remove after clearing old ajax handlers
  15. if (Scalr_Session::getInstance()->getEnvironment()) {
  16. $env = array('list' => array(), 'current' => Scalr_Session::getInstance()->getEnvironment()->name);
  17. $current = Scalr_Session::getInstance()->getEnvironment()->id;
  18. foreach (Scalr_Session::getInstance()->getEnvironment()->loadByFilter(array('clientId' => Scalr_Session::getInstance()->getClientId())) as $value) {
  19. $env['list'][] = array('text' => $value['name'], 'envId' => $value['id'], 'checked' => ($value['id'] == $current) ? true : false, 'group' => 'env', 'style' => 'width: 124px');
  20. }
  21. $Smarty->assign('session_environments', json_encode($env));
  22. }
  23. }
  24. // All uncaught exceptions will raise ApplicationException
  25. function exception_handler($exception)
  26. {
  27. UI::DisplayException($exception);
  28. }
  29. set_exception_handler("exception_handler");
  30. Core::load("XMLNavigation", dirname(__FILE__)); // @TODO: delete xml menu, replace with new one
  31. define("NOW", str_replace("..","", substr(basename($_SERVER['PHP_SELF']),0, -4))); // @TODO: remove with old templates
  32. // Auth
  33. if (Scalr_Session::getInstance()->isAuthenticated())
  34. {
  35. if (Scalr_Session::getInstance()->getClientId() != 0) {
  36. $user = $db->GetRow("SELECT * FROM clients WHERE id=?", Scalr_Session::getInstance()->getClientId());
  37. }
  38. if (Scalr_Session::getInstance()->getClientId() != 0 && $user["isactive"] == 0 && !stristr($_SERVER['PHP_SELF'], "billing.php") && !stristr($_SERVER['REQUEST_URI'], 'logout'))
  39. UI::Redirect("/billing.php");
  40. //if (CONTEXTS::$APPCONTEXT != APPCONTEXT::AJAX_REQUEST)
  41. //{
  42. //
  43. // Load menu
  44. //
  45. require_once (dirname(__FILE__)."/navigation.inc.php");
  46. //}
  47. }
  48. if ($get_search)
  49. {
  50. $display["grid_query_string"] = "&query=".addslashes($get_search);
  51. $display["search"] = htmlspecialchars($get_search);
  52. }
  53. // title
  54. $display["title"] = "Scalr CP";
  55. if (Scalr_Session::getInstance()->getClientId() != 0)
  56. {
  57. define("SCALR_SERVER_TZ", date_default_timezone_get());
  58. $tz = Scalr_Session::getInstance()->getEnvironment()->getPlatformConfigValue(ENVIRONMENT_SETTINGS::TIMEZONE);
  59. if ($tz)
  60. date_default_timezone_set($tz);
  61. $display['logged_as'] = Client::Load(Scalr_Session::getInstance()->getClientId())->Email;
  62. }
  63. if (Scalr_Session::getInstance()->getEnvironment())
  64. {
  65. $locations = Scalr_Session::getInstance()->getEnvironment()->getLocations();
  66. $display['locations'] = $locations;
  67. }
  68. if ($req_redirect_to == 'support')
  69. {
  70. $farms_rs = $db->GetAll("SELECT id FROM farms WHERE clientid=?", array(Scalr_Session::getInstance()->getClientId()));
  71. $farms = array();
  72. foreach ($farms_rs as $frm)
  73. $farms[] = $frm['id'];
  74. $farms = implode(', ', array_values($farms));
  75. $Client = Client::Load(Scalr_Session::getInstance()->getClientId());
  76. $args = array(
  77. "name" => $Client->Fullname,
  78. "Farms" => $farms,
  79. "ClientID" => $Client->ID,
  80. "email" => $Client->Email,
  81. "expires" => date("D M d H:i:s O Y", time()+120)
  82. );
  83. $token = GenerateTenderMultipassToken(json_encode($args));
  84. //////////////////////////////
  85. UI::Redirect("http://support.scalr.net/?sso={$token}");
  86. }
  87. define("CHARGIFY_SITE_SHARED_KEY", "jHw77cfhB3ZJiVpTdJex");
  88. //TODO: MOVE TO SESSION
  89. //
  90. // Select AWS regions (Temp, for old ugly code)
  91. //
  92. $regions = array();
  93. foreach (AWSRegions::GetList() as $region)
  94. {
  95. $regions[$region] = AWSRegions::GetName($region);
  96. }
  97. $display['regions'] = $regions;
  98. if ($req_region)
  99. $_SESSION['aws_region'] = $req_region;
  100. if (!$_SESSION['aws_region'])
  101. $_SESSION['aws_region'] = 'us-east-1';
  102. ?>