PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/www/src/prepend.inc.php

http://scalr.googlecode.com/
PHP | 116 lines | 88 code | 21 blank | 7 comment | 27 complexity | dc51b59b5c08d73cba50482793c3e0f9 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, GPL-3.0
  1. <?
  2. $ADM = true;
  3. session_start();
  4. require_once (dirname(__FILE__)."/../../src/prepend.inc.php");
  5. // Define current context
  6. if (!$context)
  7. CONTEXTS::$APPCONTEXT = !stristr($_SERVER['PHP_SELF'], "event_handler.php") ? APPCONTEXT::CONTROL_PANEL : APPCONTEXT::EVENT_HANDLER;
  8. else
  9. CONTEXTS::$APPCONTEXT = $context;
  10. if (!defined("NO_AUTH"))
  11. {
  12. Core::load("Data/JSON/JSON.php");
  13. Core::load("XMLNavigation", dirname(__FILE__));
  14. define("NOW", str_replace("..","", substr(basename($_SERVER['PHP_SELF']),0, -4)));
  15. if ($_COOKIE['scalr_uid'])
  16. {
  17. $Client = Client::Load($_COOKIE['scalr_uid']);
  18. $cpwd = $Crypto->Decrypt(@file_get_contents(dirname(__FILE__)."/../../etc/.passwd"));
  19. $signature = $Crypto->Hash("{$_COOKIE["scalr_sault"]}:{$_COOKIE["scalr_hash"]}:{$_COOKIE["scalr_uid"]}:{$_SERVER['REMOTE_ADDR']}:{$cpwd}");
  20. if ($signature == $_COOKIE['scalr_signature'])
  21. {
  22. $_SESSION["sault"] = $_COOKIE['scalr_sault'];
  23. $_SESSION["hash"] = $_COOKIE['scalr_hash'];
  24. $_SESSION["uid"] = $_COOKIE['scalr_uid'];
  25. $_SESSION["cpwd"] = $cpwd;
  26. $_SESSION["aws_accesskey"] = $Client->AWSAccessKey;
  27. $_SESSION["aws_accesskeyid"] = $Client->AWSAccessKeyID;
  28. $_SESSION["aws_accountid"] = $Client->AWSAccountID;
  29. $_SESSION["aws_private_key"] = $Client->AWSPrivateKey;
  30. $_SESSION["aws_certificate"] = $Client->AWSCertificate;
  31. }
  32. }
  33. // Auth
  34. if ($_SESSION["uid"] == 0)
  35. $newhash = $Crypto->Hash(CONFIG::$ADMIN_LOGIN.":".CONFIG::$ADMIN_PASSWORD.":".$_SESSION["sault"]);
  36. else
  37. {
  38. $user = $db->GetRow("SELECT * FROM clients WHERE id=?", $_SESSION['uid']);
  39. $newhash = $Crypto->Hash("{$user['email']}:{$user['password']}:".$_SESSION["sault"]);
  40. }
  41. $valid = ($newhash == $_SESSION["hash"] && !empty($_SESSION["hash"]));
  42. if (!$valid && !stristr($_SERVER['PHP_SELF'], "login.php"))
  43. {
  44. if (CONTEXTS::$APPCONTEXT != APPCONTEXT::AJAX_REQUEST)
  45. {
  46. $_SESSION["REQUEST_URI"] = $_SERVER['REQUEST_URI'];
  47. $mess = "Please login";
  48. UI::Redirect("/login.php");
  49. }
  50. else
  51. {
  52. throw new Exception(_("Session expired. Please <a href='/login.php'>login</a> again."));
  53. exit();
  54. }
  55. }
  56. //
  57. // Load menu
  58. //
  59. require_once (dirname(__FILE__)."/navigation.inc.php");
  60. if ($get_search)
  61. {
  62. $display["grid_query_string"] = "&query=".addslashes($get_search);
  63. $display["search"] = htmlspecialchars($get_search);
  64. }
  65. // title
  66. $display["title"] = "Scalr CP";
  67. if ($_SESSION['uid'] != 0)
  68. {
  69. if (!$_SESSION["aws_accesskey"] ||
  70. !$_SESSION["aws_private_key"] ||
  71. !$_SESSION["aws_certificate"]
  72. ) {
  73. if (!stristr($_SERVER['PHP_SELF'], 'aws_settings.php') &&
  74. !stristr($_SERVER['PHP_SELF'], 'login.php') &&
  75. !stristr($_SERVER['PHP_SELF'], 'profile.php')
  76. )
  77. UI::Redirect("/aws_settings.php");
  78. $errmsg = "Welcome to Scalr - in order to get started, we need some additional information. Please enter the requested information below.";
  79. }
  80. }
  81. if ($_SESSION['uid'] != 0)
  82. {
  83. define("SCALR_SERVER_TZ", date("T"));
  84. $Client = Client::Load($_SESSION['uid']);
  85. $tz = $Client->GetSettingValue(CLIENT_SETTINGS::TIMEZONE);
  86. if ($tz)
  87. date_default_timezone_set($tz);
  88. }
  89. }
  90. if ($req_region)
  91. $_SESSION['aws_region'] = $req_region;
  92. //TODO: Move default region to config
  93. if (!$_SESSION['aws_region'])
  94. $_SESSION['aws_region'] = 'us-east-1';
  95. ?>