home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / index.php < prev    next >
Encoding:
PHP Script  |  2003-09-04  |  13.0 KB  |  410 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    source/index.php
  5. //
  6. //    (C)Copyright 2000-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
  7. //
  8. //        This file is part of IlohaMail.
  9. //        IlohaMail is free software released under the GPL 
  10. //        license.  See enclosed file COPYING for details,
  11. //        or see http://www.fsf.org/copyleft/gpl.html
  12. //
  13. /////////////////////////////////////////////////////////
  14.  
  15. /********************************************************
  16.  
  17.     AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
  18.     FILE: source/index.php
  19.     PURPOSE:
  20.         1. Provides interface for logging in.
  21.         2. Authenticates user/password for given IMAP server
  22.         3. Initiates session
  23.     PRE-CONDITIONS:
  24.         $user - IMAP account name
  25.         $password - IMAP account password
  26.         $host - IMAP server
  27.     COMMENTS:
  28.         Modify form tags for "host" as required.
  29.         For an example, if you only want the program to be used to log into specific 
  30.         servers, you can use "select" lists (if multiple), or "hidden" (if single) tags.
  31.         Alternatively, simply show a text box to have the user specify the server.
  32. ********************************************************/
  33. include("../include/super2global.inc");
  34. include("../include/nocache.inc");
  35.  
  36. $document_head = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  37. <HTML>
  38. <HEAD>
  39. <TITLE>IlohaMail</TITLE>
  40.         <STYLE type="text/css">
  41.             <!--
  42.                 body
  43.                 {
  44.                     font-family: Verdana, Arial, Helvetica, sans-serif;
  45.                 }
  46.             //-->
  47.         </STYLE>
  48.  
  49. </HEAD>';
  50.  
  51. include_once("../include/encryption.inc");
  52. include_once("../include/version.inc");
  53. include_once("../include/langs.inc");
  54. include_once("../conf/conf.inc");
  55. include_once("../conf/login.inc");
  56.  
  57. //set content type header
  58. if (!empty($int_lang)){
  59.     include_once("../lang/".$int_lang."init.inc");
  60. }else{
  61.     include_once("../lang/".$default_lang."init.inc");
  62. }
  63. header("Content-type: text/html; charset=".$lang_charset);
  64.  
  65. $authenticated = false;
  66.  
  67. // session not started yet
  68. if (!isset($session) || (empty($session))){    
  69.     //figure out lang
  70.     if (strlen($int_lang)>2){
  71.         //lang selected from menu (probably)
  72.         $lang = $int_lang;
  73.     }else{
  74.         //default, or non-selection
  75.         $lang = (isset($default_lang)?$default_lang:"eng/");
  76.     }
  77.     include_once("../conf/defaults.inc");
  78.  
  79.     //validate host
  80.     if (isset($host)){
  81.         //validate host
  82.         if (!empty($default_host)){
  83.             if (is_array($default_host)){
  84.                 if (empty($default_host[$host])){
  85.                     $host="";
  86.                     $error .= $loginErrors[0]."<br>\n";
  87.                 }
  88.             }else{
  89.                 if (strcasecmp($host, $default_host)!=0){
  90.                     $host="";
  91.                     $error .= $loginErrors[0]."<br>\n";
  92.                 }
  93.             }
  94.         }
  95.     }
  96.     
  97.     //auto append
  98.     if ((empty($error)) && (is_array($AUTO_APPEND)) && (!empty($AUTO_APPEND[$host]))){
  99.         if (strpos($user, $AUTO_APPEND[$host])===false) $user .= $AUTO_APPEND[$host];
  100.     }
  101.  
  102.     //attempt to initiate session
  103.     if ((isset($user))&&(isset($password))&&(isset($host))){
  104.         include("../include/icl.inc");
  105.         $user_name = $user;
  106.         
  107.         //first, authenticate against server
  108.         $iil_conn=iil_Connect($host, $user, $password, $AUTH_MODE);
  109.         if ($iil_conn){
  110.             //run custom authentication code
  111.             include("../conf/custom_auth.inc");
  112.             
  113.             //if successful, start session
  114.             if (empty($error)){
  115.                 if ((!isset($port))||(empty($port))) $port = 143;
  116.                 include("../include/write_sinc.inc");
  117.                 if ($new_user){
  118.                     include("../conf/new_user.inc");
  119.                     $new_user = 1;
  120.                 }else{
  121.                     $new_user = 0;
  122.                 }
  123.                 $authenticated = true;
  124.             }
  125.             
  126.             iil_Close($iil_conn);
  127.         }else{
  128.             $error = $iil_error."<br>";
  129.         }
  130.         
  131.         //make log entry
  132.         $log_action = "log in";
  133.         include("../include/log.inc");
  134.     }
  135. }
  136.  
  137.  
  138. // valid session
  139. $login_success = false;
  140. if ((isset($session)) && ($session != "")){
  141.     $user=$session;
  142.     
  143.     //load session data
  144.     include("../include/session_auth.inc");
  145.     include("../conf/defaults.inc");
  146.     
  147.     //authenticate
  148.     if (!$authenticated){
  149.         include_once("../include/icl.inc");
  150.         $conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  151.         if ($conn){
  152.             iil_Close($conn);
  153.         }else{
  154.             echo "Authentication failed.";
  155.             echo "</html>\n";
  156.             exit;
  157.         }
  158.     }
  159.  
  160.     //do prefs (posted from "Prefs" pane so that changes apply to all frames)
  161.     if ($do_prefs){
  162.         //check charset (change to default if unsupported)
  163.         include_once("../lang/".$lang."init.inc");
  164.         if (!empty($charset)){ 
  165.             if (!$supported_charsets[$charset]) $charset = $lang_charset;
  166.         }else{
  167.             $charset = $lang_charset;
  168.         }
  169.  
  170.         //apply changes...
  171.         if (isset($apply)) $update=true;
  172.         if ((isset($update))||(isset($revert))){
  173.             //check rootdir
  174.             if ($rootdir=="-") $rootdir = $rootdir_other;
  175.         
  176.             //initialize $my_prefs
  177.             $my_prefs=$init["my_prefs"];
  178.             
  179.             //if updating, over-write values
  180.             if (isset($update)){
  181.                 reset($my_prefs);
  182.                  while (list($key, $value) = each ($my_prefs)) {
  183.                      $my_prefs[$key]=$$key;
  184.                     echo "<!-- $key ".$$key." -->\n";
  185.                 }
  186.             }
  187.         
  188.             //save prefs to backend
  189.             include("../include/save_prefs.inc");
  190.         
  191.             //display prefs page again
  192.             $show_page="prefs";
  193.             
  194.             //show error if any
  195.             if (!empty($error)){
  196.                 echo "<body>ERROR: $error</body></html>";
  197.                 exit;
  198.             }    
  199.         }
  200.     }
  201.     
  202.     //do pref_colors (posted from "Prefs:Colors" pane so that changes apply to all frames)
  203.     if ($do_pref_colors){
  204.         //apply changes...
  205.         if (isset($apply)) $update=true;
  206.         if ((isset($update))||(isset($revert))){
  207.             //check rootdir
  208.             if ($font_family=="other") $font_family = $font_family_other;
  209.         
  210.             //initialize $my_prefs
  211.             $my_colors=$init["my_colors"];
  212.             
  213.             //if updating, over-write values
  214.             if (isset($update)){
  215.                 reset($my_colors);
  216.                  while (list($key, $value) = each ($my_colors)) {
  217.                      $my_colors[$key]=$$key;
  218.                     echo "<!-- $key ".$$key." -->\n";
  219.                 }
  220.             }
  221.         
  222.             //save prefs to backend
  223.             include("../include/save_colors.inc");
  224.         
  225.             //display prefs page again
  226.             $show_page="pref_colors";
  227.             
  228.             //show error...
  229.             if (!empty($error)){
  230.                 echo "<body>ERROR: $error</body></html>";
  231.                 exit;
  232.             }    
  233.         }
  234.     }
  235.  
  236.     //overwrite lang prefs if different
  237.     if ((strlen($int_lang)>2) && (strcmp($int_lang, $my_prefs["lang"])!=0)){
  238.         $my_prefs["lang"] = $int_lang;
  239.         include("../lang/".$lang."init.inc");
  240.         if ($supported_charsets[$my_prefs["charset"]]!=1) $my_prefs["charset"] = $lang_charset;
  241.         include("../include/save_prefs.inc");
  242.     }
  243.     
  244.     //figure out which page to load in main frame
  245.     if (($new_user)||($show_page=="prefs")) $main_page = "prefs.php?user=".$session;
  246.     else if ($show_page == "pref_colors") $main_page = "pref_colors.php?user=".$session;
  247.     else $main_page = "main.php?folder=INBOX&user=".$session;
  248.     
  249.     //show document head
  250.     echo $document_head;
  251.     
  252.     //show frames
  253.     if (($my_prefs["list_folders"]==1) && ($port!=110)){
  254.         //...with folder list
  255.         $login_success = true;
  256.         ?>
  257.         <FRAMESET ROWS="30,*"  frameborder=no border=0 framespacing=0 MARGINWIDTH="0" MARGINHEIGHT="0">
  258.             <FRAMESET COLS="30,*"  frameborder=no border=0 framespacing=0 MARGINWIDTH="0" MARGINHEIGHT="0">
  259.                 <FRAME SRC="radar.php?user=    <?php echo $session?>" NAME="radar" SCROLLING="NO" MARGINWIDTH="0" MARGINHEIGHT="0"  frameborder=no border=0 framespacing=0>
  260.                 <FRAME SRC="tool.php?user=    <?php echo $session?>" NAME="tool" SCROLLING="NO" MARGINWIDTH="0" MARGINHEIGHT="0"  frameborder=no border=0 framespacing=0>
  261.             </FRAMESET>
  262.             <FRAMESET COLS="    <?php echo $my_prefs["folderlistWidth"]?>,*" frameborder=no border=0 framespacing=0 MARGINWIDTH="0" MARGINHEIGHT="0">
  263.                 <FRAME SRC="folders.php?user=    <?php echo $session?>" NAME="list1"  MARGINWIDTH=5 MARGINHEIGHT=5 NORESIZE frameborder=no border=0 framespacing=0>
  264.                 <FRAME SRC="    <?php echo $main_page?>" NAME="list2" MARGINWIDTH=10 MARGINHEIGHT=10 FRAMEBORDER=no border=0 framespacing=0>
  265.             </FRAMESET>
  266.         </FRAMESET>
  267.         <?php
  268.     }else if (empty($error)){
  269.         //...without folder list
  270.         $login_success = true;
  271.         ?>
  272.         <FRAMESET ROWS="30,*"  frameborder=no border=0 framespacing=0 MARGINWIDTH="0" MARGINHEIGHT="0">
  273.             <FRAMESET COLS="30,*"  frameborder=no border=0 framespacing=0 MARGINWIDTH="0" MARGINHEIGHT="0">
  274.                 <FRAME SRC="radar.php?user=    <?php echo $session?>" NAME="radar" SCROLLING="NO" MARGINWIDTH="0" MARGINHEIGHT="0"  frameborder=no border=0 framespacing=0>
  275.                 <FRAME SRC="tool.php?user=    <?php echo $session?>" NAME="tool" SCROLLING="NO" MARGINWIDTH="0" MARGINHEIGHT="0"  frameborder=no border=0 framespacing=0>
  276.             </FRAMESET>
  277.             <FRAME SRC="    <?php echo $main_page?>" NAME="list2" MARGINWIDTH=10 MARGINHEIGHT=10 FRAMEBORDER=no border=0 framespacing=0>
  278.         </FRAMESET>
  279.         <?php
  280.     }
  281. }
  282.  
  283. //couldn't log in, show login form
  284. if (!$login_success){
  285.     //check for cookie...
  286.     if ($_COOKIE["ILOHAMAIL_SESSION"]){
  287.         $user = "";
  288.         setcookie("ILOHAMAIL_SESSION", "");
  289.     }
  290.  
  291.     //put together lang options
  292.     $langOptions="<option value=\"--\">--";
  293.     while (list($key, $val)=each($languages)) 
  294.         $langOptions.="<option value=\"$key\" ".(strcmp($key,$int_lang)==0?"SELECTED":"").">$val\n";
  295.  
  296.     //colors...
  297.     $bgcolor = $default_colors["folder_bg"];
  298.     $textColorOut = $default_colors["folder_link"];
  299.     $bgcolorIn = $default_colors["tool_bg"];
  300.     $textColorIn = $default_colors["tool_link"];
  301.     
  302.     //load lang file
  303.     if (!empty($int_lang)){
  304.         include("../lang/".$int_lang."login.inc");
  305.     }else{
  306.         include("../lang/".$default_lang."login.inc");
  307.     }
  308.     
  309.     //set a test cookie
  310.     if ($USE_COOKIES){
  311.         setcookie ("IMAIL_TEST_COOKIE", "test", time()+$MAX_SESSION_TIME, "/", $_SERVER[SERVER_NAME]);
  312.     }
  313.     
  314.     //print document head
  315.     echo $document_head;
  316.     
  317.     echo "\n<!-- \nSESS_KEY: $IMAIL_SESS_KEY $MAX_SESSION_TIME ".$_SERVER[SERVER_NAME]."\nOLD: $OLD_SESS_KEY\n //-->\n";
  318.     ?>
  319.     <BODY BGCOLOR="<?php echo $bgcolor?>" TEXT="<?php echo $textColorOut?>" LINK="<?php echo $textColorOut?>" ALINK="<?php echo $textColorOut?>" VLINK="<?php echo $textColorOut?>" onLoad="document.forms[0].user.focus();">
  320.     <p><BR><BR>
  321.     <center>
  322.     <form method="POST" action="index.php">
  323.     <input type="hidden" name="logout" value=0>
  324.     <table width="280" border="0" cellspacing="0" cellpadding="0" bgcolor="<?php echo $bgcolorIn?>">
  325.     <tr><td align="center" colspan=2>
  326.     <?php
  327.         include("../conf/login_title.inc");
  328.         if (!empty($error)) echo "<font color=\"#FFAAAA\">".$error."</font><br>";
  329.     ?>
  330.     </td>
  331.     </tr>
  332.     <tr><td align=right><?php echo $loginStrings[0] ?>:</td><td><input type="text" name="user" value="<?php echo $user; ?>" size=15></td></tr>
  333.     <tr><td align=right><?php echo $loginStrings[1] ?>: </td><td><input type="password" name="password" value="" size=15 AUTOCOMPLETE="off"></td></tr>
  334.     <?php
  335.         $HTTP_HOST = strtolower($_SERVER["HTTP_HOST"]);
  336.         if (is_array($VDOMAIN_DETECT) && empty($host)){
  337.             $host = $VDOMAIN_DETECT[$HTTP_HOST];
  338.         }
  339.         //empty default host
  340.             //show text box
  341.         //default host is array
  342.             //show list (select $host)
  343.         //default host is string
  344.             //show host
  345.             //don't show host
  346.         if (empty($default_host)){
  347.             echo "<tr><td align=right>".$loginStrings[2].": </td><td><input type=text name=\"host\" value=\"$host\">  </td></tr>";            
  348.         }else if (is_array($default_host)){
  349.             echo  "<tr><td align=right>".$loginStrings[2].":</td><td><select name=\"host\">\n";
  350.             reset($default_host);
  351.             while ( list($server, $name) = each($default_host) ){
  352.                 echo "<option value=\"$server\" ".($server==$host?"SELECTED":"").">$name\n";
  353.             }
  354.             echo "</select></td></tr>";            
  355.         }else{
  356.             echo "<input type=hidden name=\"host\" value=\"$default_host\">";
  357.             if (!$hide_host){
  358.                 echo  "<tr><td align=right>".$loginStrings[2].": </td><td><b>$host</b>  ";
  359.                 echo "</td></tr>";
  360.             }
  361.         }
  362.             
  363.         //initialize default rootdir and port 
  364.         if ((!isset($rootdir))||(empty($rootdir))) $rootdir = $default_rootdir;
  365.         if ((!isset($port))||(empty($port))) $port = $default_port;
  366.         
  367.         //show (or hide) protocol selection
  368.         if (!$hide_protocol){
  369.             echo "<tr>";
  370.             echo "<td align=\"right\">".$loginStrings[3].": </td>\n<td>";
  371.             echo "<select name=\"port\">\n";
  372.             echo "<option value=\"143\" ".($port==143?"SELECTED":"").">IMAP\n";
  373.             if ($SSL_ENABLED) echo "<option value=\"993\" ".($port==993?"SELECTED":"").">IMAP-SSL\n";
  374.             echo "<option value=\"110\" ".($port==110?"SELECTED":"").">POP3\n";
  375.             echo "</select>\n";
  376.             //echo "<td><input type=\"text\" name=\"port\" value=\"$port\" size=\"4\"></td>";
  377.             echo "</td></tr>\n";
  378.         }else{
  379.             echo "<input type=\"hidden\" name=\"port\" value=\"$default_port\">\n";
  380.         }
  381.         
  382.         //show (or hide) root dir box
  383.         if (!$hide_rootdir){
  384.             echo "<tr>";
  385.             echo "<td align=\"right\">".$loginStrings[4].":</td>";
  386.             echo "<td><input type=\"text\" name=\"rootdir\" value=\"$rootdir\" size=\"12\"></td>";
  387.             echo "</tr>\n";
  388.         }else{
  389.             echo "<input type=\"hidden\" name=\"rootdir\" value=\"$default_rootdir\">\n";
  390.         }
  391.         
  392.         if (!$hide_lang){
  393.             echo "<tr><td align=right>".$loginStrings[5].": </td><td>\n";
  394.                 echo "<select name=\"int_lang\">\n";
  395.             echo $langOptions;
  396.             echo "</select></td></tr>\n";
  397.         }
  398.     ?>
  399.     <tr><td align="right" colspan="2"><input type=submit value="<?php echo $loginStrings[6] ?>">  <p> </td></tr>
  400.     </table>
  401.     </form>
  402.     <?php
  403.         include("../conf/login_blurb.inc");
  404.     ?>
  405.     </center>
  406.     </body>
  407.     <?php
  408. }
  409.     ?>
  410. </HTML>