common.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. $path_extra = dirname(dirname(dirname(__FILE__)));
  3. $path = ini_get('include_path');
  4. $path = $path_extra . PATH_SEPARATOR . $path;
  5. ini_set('include_path', $path);
  6. function displayError($message) {
  7. $error = $message;
  8. include 'index.php';
  9. exit(0);
  10. }
  11. function doIncludes() {
  12. /**
  13. * Require the OpenID consumer code.
  14. */
  15. require_once "Auth/OpenID/Consumer.php";
  16. /**
  17. * Require the "file store" module, which we'll need to store
  18. * OpenID information.
  19. */
  20. require_once "Auth/OpenID/FileStore.php";
  21. /**
  22. * Require the Simple Registration extension API.
  23. */
  24. require_once "Auth/OpenID/SReg.php";
  25. /**
  26. * Require the PAPE extension module.
  27. */
  28. require_once "Auth/OpenID/PAPE.php";
  29. }
  30. doIncludes();
  31. global $pape_policy_uris;
  32. $pape_policy_uris = array(
  33. PAPE_AUTH_MULTI_FACTOR_PHYSICAL,
  34. PAPE_AUTH_MULTI_FACTOR,
  35. PAPE_AUTH_PHISHING_RESISTANT
  36. );
  37. function &getStore() {
  38. /**
  39. * This is where the example will store its OpenID information.
  40. * You should change this path if you want the example store to be
  41. * created elsewhere. After you're done playing with the example
  42. * script, you'll have to remove this directory manually.
  43. */
  44. $store_path = null;
  45. if (function_exists('sys_get_temp_dir')) {
  46. $store_path = sys_get_temp_dir();
  47. }
  48. else {
  49. if (strpos(PHP_OS, 'WIN') === 0) {
  50. $store_path = $_ENV['TMP'];
  51. if (!isset($store_path)) {
  52. $dir = 'C:\Windows\Temp';
  53. }
  54. }
  55. else {
  56. $store_path = @$_ENV['TMPDIR'];
  57. if (!isset($store_path)) {
  58. $store_path = '/tmp';
  59. }
  60. }
  61. }
  62. $store_path .= DIRECTORY_SEPARATOR . '_php_consumer_test';
  63. if (!file_exists($store_path) &&
  64. !mkdir($store_path)) {
  65. print "Could not create the FileStore directory '$store_path'. ".
  66. " Please check the effective permissions.";
  67. exit(0);
  68. }
  69. $r = new Auth_OpenID_FileStore($store_path);
  70. return $r;
  71. }
  72. function &getConsumer() {
  73. /**
  74. * Create a consumer object using the store object created
  75. * earlier.
  76. */
  77. $store = getStore();
  78. $r = new Auth_OpenID_Consumer($store);
  79. return $r;
  80. }
  81. function getScheme() {
  82. $scheme = 'http';
  83. if (isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') {
  84. $scheme .= 's';
  85. }
  86. return $scheme;
  87. }
  88. function getReturnTo() {
  89. return sprintf("%s://%s:%s%s/finish_auth.php",
  90. getScheme(), $_SERVER['SERVER_NAME'],
  91. $_SERVER['SERVER_PORT'],
  92. dirname($_SERVER['PHP_SELF']));
  93. }
  94. function getTrustRoot() {
  95. return sprintf("%s://%s:%s%s/",
  96. getScheme(), $_SERVER['SERVER_NAME'],
  97. $_SERVER['SERVER_PORT'],
  98. dirname($_SERVER['PHP_SELF']));
  99. }
  100. ?>