home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / index.php < prev    next >
PHP Script  |  2004-03-08  |  4KB  |  138 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. if(!file_exists("Group-Office.php"))
  14. {
  15.     header("Location: install.php");
  16.     exit();
  17. }elseif(is_writable("Group-Office.php"))
  18. {
  19.     echo '<font color="red"><b>Group-Office.php is writable please chmod 755 Group-Office.php and change the ownership to any other user then the webserver user.</b></font>';
  20.     exit();
  21. }
  22.  
  23. require("Group-Office.php");
  24.  
  25. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  26. $lang = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : $GO_LANGUAGE->default_language;
  27.  
  28. require($GO_LANGUAGE->get_language_file('login'));
  29.  
  30. if ($task == "logout")
  31. {
  32.     SetCookie("GO_UN","",time()-3600,"/","",0);
  33.     SetCookie("GO_PW","",time()-3600,"/","",0);
  34.     unset($_SESSION);
  35.     unset($_COOKIE);
  36.     $GO_SECURITY->logout();
  37. }
  38.  
  39. //when the user is logged in redirect him.
  40. if ($GO_SECURITY->logged_in == true)
  41. {
  42.     $start_module = $GO_MODULES->get_module($_SESSION['GO_SESSION']['start_module']);
  43.  
  44.     if (isset($_REQUEST['return_to']))
  45.     {
  46.         $link = $_REQUEST['return_to'];
  47.     }elseif ($start_module && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $start_module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $start_module['acl_write'])))
  48.     {
  49.         $link = $GO_CONFIG->host.$start_module['path'];
  50.     }else
  51.     {
  52.         //todo make nice startpage
  53.         $link = $GO_CONFIG->host.'about.php';
  54.     }
  55.     //header('Location: '.$link);
  56.     require($GO_THEME->theme_path."frames.inc");
  57.     exit();
  58. }
  59.  
  60. //if form was posted user wants to login
  61. //set cookies to remember login before headers are sent
  62. if ($_SERVER['REQUEST_METHOD'] == "POST" || (isset($_COOKIE['GO_UN']) && isset($_COOKIE['GO_PW'])))
  63. {
  64.     if ($_SERVER['REQUEST_METHOD'] != "POST")
  65.     {
  66.         $remind = true;
  67.         $password = $_COOKIE['GO_PW'];
  68.         $username = $_COOKIE['GO_UN'];
  69.         echo $auth_mail_server_key = isset($_COOKIE['GO_AUTH_MAIL_SERVER_KEY']) ? $_COOKIE['GO_AUTH_MAIL_SERVER_KEY'] : '';
  70.     }else
  71.     {
  72.         $remind = isset($_POST['remind']) ? true : false;
  73.         $username = $_POST['username'];
  74.         $password = $_POST['password'];
  75.     }
  76.  
  77.     //check if both fields were filled
  78.     if (!$username || !$password)
  79.     {
  80.             $feedback = "<p class=\"Error\">".$login_missing_field."</p>";
  81.     }else
  82.     {
  83.         $auth_mail_server_key = isset($_POST['auth_mail_server_key']) ? $_POST['auth_mail_server_key'] : -1;
  84.         SetCookie("GO_AUTH_MAIL_SERVER_KEY",$auth_mail_server_key,time()+3600*24*30,"/",'',0);
  85.         $_COOKIE['auth_mail_server_key'] = $auth_mail_server_key;
  86.  
  87.         //attempt login using security class inherited from index.php
  88.  
  89.         if ($GO_SECURITY->login($username,$password, $auth_mail_server_key))
  90.         {
  91.             //login is correct final check if login registration was ok
  92.             if ($GO_SECURITY->logged_in == true)
  93.             {
  94.                 if ($remind)
  95.                 {
  96.                     SetCookie("GO_UN",$username,time()+3600*24*30,"/",'',0);
  97.                     SetCookie("GO_PW",$password,time()+3600*24*30,"/",'',0);
  98.                 }
  99.  
  100.                 if ($_SESSION['GO_SESSION']['first_name'] == '' || $_SESSION['GO_SESSION']['last_name'] == '' || $_SESSION['GO_SESSION']['email'] == '')
  101.                 {
  102.                     header("Location: ".$GO_CONFIG->host."configuration/account/index.php");
  103.                     exit();
  104.                 }else
  105.                 {
  106.                     $start_module = $GO_MODULES->get_module($_SESSION['GO_SESSION']['start_module']);
  107.  
  108.                     if (isset($_REQUEST['return_to']))
  109.                     {
  110.                         $link = $_REQUEST['return_to'];
  111.                     }elseif ($start_module && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $start_module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $start_module['acl_write'])))
  112.                     {
  113.                         $link = $GO_CONFIG->host.$start_module['path'];
  114.                     }else
  115.                     {
  116.                         //todo make nice startpage
  117.                         $link = $GO_CONFIG->host.'about.php';
  118.                     }
  119.                     //redefine theme
  120.                     $GO_THEME = new GO_THEME();
  121.  
  122.                     require($GO_THEME->theme_path."frames.inc");
  123.                     exit();
  124.                 }
  125.  
  126.             }else
  127.             {
  128.                 $feedback = "<p class=\"Error\">".$login_registration_fail."</p>";
  129.             }
  130.         }else
  131.         {
  132.             $feedback = "<p class=\"Error\">".$login_bad_login."</p>";
  133.         }
  134.     }
  135. }
  136. require('login.inc');
  137. ?>
  138.