index.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2010 Frank Karlitschek karlitschek@kde.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. $RUNTIME_NOAPPS = TRUE; //no apps, yet
  23. require_once('lib/base.php');
  24. // Setup required :
  25. $not_installed = !OC_Config::getValue('installed', false);
  26. if($not_installed) {
  27. // Check for autosetup:
  28. $autosetup_file = OC::$SERVERROOT."/config/autoconfig.php";
  29. if( file_exists( $autosetup_file )){
  30. OC_Log::write('core','Autoconfig file found, setting up owncloud...',OC_Log::INFO);
  31. include( $autosetup_file );
  32. $_POST['install'] = 'true';
  33. $_POST = array_merge ($_POST, $AUTOCONFIG);
  34. unlink($autosetup_file);
  35. }
  36. OC_Util::addScript('setup');
  37. require_once('setup.php');
  38. exit();
  39. }
  40. // Handle WebDAV
  41. if($_SERVER['REQUEST_METHOD']=='PROPFIND'){
  42. header('location: '.OC_Helper::linkToRemote('webdav'));
  43. exit();
  44. }
  45. // Someone is logged in :
  46. elseif(OC_User::isLoggedIn()) {
  47. OC_App::loadApps();
  48. if(isset($_GET["logout"]) and ($_GET["logout"])) {
  49. OC_User::logout();
  50. header("Location: ".OC::$WEBROOT.'/');
  51. exit();
  52. }else{
  53. if(is_null(OC::$REQUESTEDFILE)){
  54. OC::loadapp();
  55. }else{
  56. OC::loadfile();
  57. }
  58. }
  59. // For all others cases, we display the guest page :
  60. } else {
  61. OC_App::loadApps();
  62. $error = false;
  63. // remember was checked after last login
  64. if(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && isset($_COOKIE["oc_username"]) && $_COOKIE["oc_remember_login"]) {
  65. if(defined("DEBUG") && DEBUG) {
  66. OC_Log::write('core','Trying to login from cookie',OC_Log::DEBUG);
  67. }
  68. // confirm credentials in cookie
  69. if(isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) &&
  70. OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) {
  71. OC_User::setUserId($_COOKIE['oc_username']);
  72. OC_Util::redirectToDefaultPage();
  73. }
  74. else {
  75. OC_User::unsetMagicInCookie();
  76. }
  77. // Someone wants to log in :
  78. } elseif(isset($_POST["user"]) and isset($_POST['password']) and isset($_SESSION['sectoken']) and isset($_POST['sectoken']) and ($_SESSION['sectoken']==$_POST['sectoken']) ) {
  79. if(OC_User::login($_POST["user"], $_POST["password"])) {
  80. if(!empty($_POST["remember_login"])){
  81. if(defined("DEBUG") && DEBUG) {
  82. OC_Log::write('core','Setting remember login to cookie',OC_Log::DEBUG);
  83. }
  84. $token = md5($_POST["user"].time().$_POST['password']);
  85. OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
  86. OC_User::setMagicInCookie($_POST["user"], $token);
  87. }
  88. else {
  89. OC_User::unsetMagicInCookie();
  90. }
  91. OC_Util::redirectToDefaultPage();
  92. } else {
  93. $error = true;
  94. }
  95. // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP
  96. } elseif(isset($_SERVER["PHP_AUTH_USER"]) && isset($_SERVER["PHP_AUTH_PW"])){
  97. if (OC_User::login($_SERVER["PHP_AUTH_USER"],$_SERVER["PHP_AUTH_PW"])) {
  98. //OC_Log::write('core',"Logged in with HTTP Authentication",OC_Log::DEBUG);
  99. OC_User::unsetMagicInCookie();
  100. OC_Util::redirectToDefaultPage();
  101. }else{
  102. $error = true;
  103. }
  104. }
  105. if(is_null(OC::$REQUESTEDFILE)){
  106. $sectoken=rand(1000000,9999999);
  107. $_SESSION['sectoken']=$sectoken;
  108. OC_Template::printGuestPage('', 'login', array('error' => $error, 'sectoken' => $sectoken, 'redirect' => isset($_REQUEST['redirect_url'])?htmlentities($_REQUEST['redirect_url']):'' ));
  109. }
  110. }