index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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::linkTo('files','webdav.php'));
  43. exit();
  44. }
  45. // Someone is logged in :
  46. elseif(OC_User::isLoggedIn()) {
  47. if(isset($_GET["logout"]) and ($_GET["logout"])) {
  48. OC_User::logout();
  49. header("Location: ".OC::$WEBROOT.'/');
  50. exit();
  51. }
  52. else {
  53. OC_Util::redirectToDefaultPage();
  54. }
  55. }
  56. // For all others cases, we display the guest page :
  57. else {
  58. OC_App::loadApps();
  59. $error = false;
  60. // remember was checked after last login
  61. if(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && isset($_COOKIE["oc_username"]) && $_COOKIE["oc_remember_login"]) {
  62. if(defined("DEBUG") && DEBUG) {
  63. OC_Log::write('core','Trying to login from cookie',OC_Log::DEBUG);
  64. }
  65. // confirm credentials in cookie
  66. if(isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) &&
  67. OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) {
  68. OC_User::setUserId($_COOKIE['oc_username']);
  69. OC_Util::redirectToDefaultPage();
  70. }
  71. else {
  72. OC_User::unsetMagicInCookie();
  73. }
  74. }
  75. // Someone wants to log in :
  76. elseif(isset($_POST["user"]) && isset($_POST['password'])) {
  77. if(OC_User::login($_POST["user"], $_POST["password"])) {
  78. if(!empty($_POST["remember_login"])){
  79. if(defined("DEBUG") && DEBUG) {
  80. OC_Log::write('core','Setting remember login to cookie',OC_Log::DEBUG);
  81. }
  82. $token = md5($_POST["user"].time());
  83. OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
  84. OC_User::setMagicInCookie($_POST["user"], $token);
  85. }
  86. else {
  87. OC_User::unsetMagicInCookie();
  88. }
  89. OC_Util::redirectToDefaultPage();
  90. } else {
  91. $error = true;
  92. }
  93. }
  94. // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP
  95. elseif(isset($_SERVER["PHP_AUTH_USER"]) && isset($_SERVER["PHP_AUTH_PW"])){
  96. if (OC_User::login($_SERVER["PHP_AUTH_USER"],$_SERVER["PHP_AUTH_PW"])) {
  97. OC_User::unsetMagicInCookie();
  98. OC_Util::redirectToDefaultPage();
  99. }else{
  100. $error = true;
  101. }
  102. }
  103. OC_Template::printGuestPage('', 'login', array('error' => $error, 'redirect' => isset($_REQUEST['redirect_url'])?$_REQUEST['redirect_url']:'' ));
  104. }