home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / misc / ib3.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  11.5 KB  |  369 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Log in / log out module
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 12th December 2001
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new Login;
  26.  
  27. class Login {
  28.  
  29.     var $output     = "";
  30.     var $page_title = "";
  31.     var $nav        = array();
  32.     var $login_html = "";
  33.     
  34.     function Login() {
  35.         global $ibforums, $DB, $std, $print;
  36.         
  37.         // Make sure our code number is numerical only
  38.         
  39.         //$ibforums->input[CODE] = preg_replace("/^([0-9]+)$/", "$1", $ibforums->input[CODE]);
  40.         
  41.         // Require the HTML and language modules
  42.         
  43.         $ibforums->lang = $std->load_words($ibforums->lang, 'lang_login', $ibforums->lang_id);
  44.         
  45.         require "./Skin/".$ibforums->skin_id."/skin_login.php";
  46.         $this->login_html = new skin_login();
  47.  
  48.         
  49.         // What to do?
  50.         
  51.         switch($ibforums->input[CODE]) {
  52.             case '01':
  53.                 $this->do_log_in();
  54.                 break;
  55.             case '02':
  56.                 $this->log_in_form();
  57.                 break;
  58.             case '03':
  59.                 $this->do_log_out();
  60.                 break;
  61.             default:
  62.                 $this->log_in_form();
  63.                 break;
  64.         }
  65.         
  66.         // If we have any HTML to print, do so...
  67.         
  68.         $print->add_output("$this->output");
  69.         $print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 0, NAV => $this->nav ) );
  70.             
  71.      }   
  72.     
  73.     
  74.     
  75.     
  76.     
  77.     function log_in_form($message="") {
  78.         global $ibforums, $DB, $std, $print, $HTTP_REFERER;
  79.         
  80.         //+--------------------------------------------
  81.         //| Are they banned?
  82.         //+--------------------------------------------
  83.         
  84.         if ($message != "")
  85.         {
  86.             $this->output .= $this->login_html->errors( $ibforums->lang[ $message ] );
  87.         }
  88.         
  89. $html = <<<EOF
  90.  
  91.     <script language='JavaScript'>
  92.     <!--
  93.     function ValidateForm() {
  94.         var Check = 0;
  95.         if (document.LOGIN.UserName.value == '') { Check = 1; }
  96.         if (document.LOGIN.PassWord.value == '') { Check = 1; }
  97.  
  98.         if (Check == 1) {
  99.             alert("{$ibforums->lang[blank_fields]}");
  100.             return false;
  101.         } else {
  102.             document.LOGIN.submit.disabled = true;
  103.             return true;
  104.         }
  105.     }
  106.     //-->
  107.     </script>     
  108.      <br>
  109.      <table cellpadding='3' cellspacing='1' border='0' align='center' width='{$ibforums->skin['tbl_width']}'>
  110.      <tr>
  111.      <td align='left'>{$ibforums->lang['login_text']}</td>
  112.      </tr>
  113.      <tr>
  114.      <td align='left'><b>{$ibforums->lang[forgot_pass]} <a href='{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?act=Reg&CODE=10'>{$ibforums->lang[pass_link]}</a></b></td>
  115.      </tr>
  116.      </table>
  117.      <form action="{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}" method="post" name='LOGIN' onSubmit='return ValidateForm()'>
  118.      <input type='hidden' name='act' value='ib3'>
  119.      <input type='hidden' name='CODE' value='01'>
  120.      <input type='hidden' name='s' value='{$ibforums->session_id}'>
  121.      <input type='hidden' name='referer' value="">
  122.      <table cellpadding='0' cellspacing='0' border='0' width='{$ibforums->skin['tbl_width']}' bgcolor='{$ibforums->skin['tbl_border']}' align='center'>
  123.         <tr>
  124.             <td>
  125.                 <table cellpadding='3' cellspacing='1' border='0' width='100%'>
  126.                 <tr>
  127.                 <td align='left' colspan='2' id='titlemedium'>Please enter your old Ikonboard 3 Username and Password</td>
  128.                 </tr>
  129.                 <tr>
  130.                 <td id='row1' width='40%'>Your Ikonboard 3 Username</td>
  131.                 <td id='row1'><input type='text' size='20' maxlength='64' name='UserName' class='forminput'></td>
  132.                 </tr>
  133.                 <tr>
  134.                 <td id='row1' width='40%'>Your Ikonboard 3 Password</td>
  135.                 <td id='row1'><input type='password' size='20' name='PassWord' class='forminput'></td>
  136.                 </tr>
  137.                 </table>
  138.              </td>
  139.          </tr>
  140.      </table>
  141.      <br>
  142.      <table cellpadding='0' cellspacing='0' border='0' width='{$ibforums->skin['tbl_width']}' bgcolor='{$ibforums->skin['tbl_border']}' align='center'>
  143.         <tr>
  144.             <td>
  145.                 <table cellpadding='3' cellspacing='1' border='0' width='100%'>
  146.                 <tr>
  147.                 <td align='left' colspan='2' id='titlemedium'>{$ibforums->lang[options]}</td>
  148.                 </tr>
  149.                 <tr>
  150.                 <td id='row1' width='40%' align='left' valign='top'>{$ibforums->lang[cookies]}</td>
  151.                 <td id='row1' width='40%'><input type="radio" name="CookieDate" value="1" checked>{$ibforums->lang[cookie_yes]}<br><input type="radio" name="CookieDate" value="0">{$ibforums->lang[cookie_no]}</td>
  152.                 </tr>
  153.                 <tr>
  154.                 <td id='row1' width='40%' align='left' valign='top'>{$ibforums->lang[privacy]}</td>
  155.                 <td id='row1' width='40%'><input type="checkbox" name="Privacy" value="1">{$ibforums->lang[anon_name]}</td>
  156.                 </tr>
  157.                 <tr>
  158.                 <td id='row2' align='center' colspan='2'>
  159.                 <input type="submit" name='submit' value="{$ibforums->lang[log_in_submit]}" class='forminput'>
  160.                 </td></tr></table>
  161.                 </td></tr></table>
  162.                 </form>
  163.  
  164.  
  165. EOF;
  166.         
  167.         $this->output .= $html;
  168.         
  169.         $this->nav        = array( "Upgrade my old Ikonboard Account" );
  170.          $this->page_title = "Upgrade my old Ikonboard Account";
  171.         
  172.         $print->add_output("$this->output");
  173.         $print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 0, NAV => $this->nav ) );
  174.         
  175.         exit();
  176.         
  177.     }
  178.     
  179.     function do_log_in() {
  180.         global $DB, $ibforums, $std, $print, $sess, $HTTP_USER_AGENT, $HTTP_POST_VARS;
  181.         
  182.         $url = "";
  183.         
  184.         //-------------------------------------------------
  185.         // Make sure the username and password were entered
  186.         //-------------------------------------------------
  187.         
  188.         if ($HTTP_POST_VARS['UserName'] == "")
  189.         {
  190.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_username' ) );
  191.         }
  192.     
  193.          if ($HTTP_POST_VARS['PassWord'] == "")
  194.          {
  195.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'pass_blank' ) );
  196.         }   
  197.  
  198.         
  199.         //-------------------------------------------------
  200.         // Check for input length
  201.         //-------------------------------------------------
  202.         
  203.         if (strlen($ibforums->input['UserName']) > 32)
  204.         {
  205.             $std->Error( array( LEVEL => 1, MSG => 'username_long' ) );
  206.         }
  207.         
  208.         if (strlen($ibforums->input['PassWord']) > 32)
  209.         {
  210.             $std->Error( array( LEVEL => 1, MSG => 'pass_too_long' ) );
  211.         }
  212.         
  213.         $username    = strtolower($ibforums->input['UserName']);
  214.         $password    = crypt( $ibforums->input['PassWord'], substr( strtolower($ibforums->input['UserName']), 0, 2) );
  215.         
  216.         //-------------------------------------------------
  217.         // Attempt to get the user details
  218.         //-------------------------------------------------
  219.         
  220.         $DB->query("SELECT id, name, mgroup, password, new_pass FROM ibf_members WHERE LOWER(name)='$username'");
  221.         
  222.         if ($DB->get_num_rows())
  223.         {
  224.             $member = $DB->fetch_row();
  225.             
  226.             if ( empty($member['id']) or ($member['id'] == "") )
  227.             {
  228.                 $this->log_in_form( 'wrong_name' );
  229.             }
  230.             
  231.             if ($member['password'] != $password)
  232.             {
  233.                 $this->log_in_form( 'wrong_pass' );
  234.             }
  235.             
  236.             // SET REAL PASSY
  237.             
  238.             $real_pass = md5($ibforums->input['PassWord']);
  239.             
  240.             //------------------------------
  241.             
  242.             if ($ibforums->input['s'])
  243.             {
  244.                 $session_id = $ibforums->input['s'];
  245.                 
  246.                 // Delete any old sessions with this users IP addy that doesn't match our
  247.                 // session ID.
  248.                 
  249.                 $DB->query("DELETE FROM ibf_sessions WHERE ip_address='".$ibforums->input['IP_ADDRESS']."' AND id <> '$session_id'");
  250.                 
  251.                 $db_string = $DB->compile_db_update_string( array (
  252.                                                                      'member_name'  => $member['name'],
  253.                                                                      'member_pass'  => $real_pass,
  254.                                                                      'member_id'    => $member['id'],
  255.                                                                      'running_time' => time(),
  256.                                                                      'member_group' => $member['mgroup']
  257.                                                           )       );
  258.                                                           
  259.                 $db_query = "UPDATE ibf_sessions SET $db_string WHERE id='".$ibforums->input['s']."'";
  260.             }
  261.             else
  262.             {
  263.                 $session_id = md5( uniqid(microtime()) );
  264.                 
  265.                 // Delete any old sessions with this users IP addy.
  266.                 
  267.                 $DB->query("DELETE FROM ibf_sessions WHERE ip_address='".$ibforums->input['IP_ADDRESS']."'");
  268.                 
  269.                 $db_string = $DB->compile_db_insert_string( array (
  270.                                                                      'id'           => $session_id,
  271.                                                                      'member_name'  => $member['name'],
  272.                                                                      'member_pass'  => $real_pass,
  273.                                                                      'member_id'    => $member['id'],
  274.                                                                      'running_time' => time(),
  275.                                                                      'member_group' => $member['mgroup'],
  276.                                                                      'ip_address'   => substr($ibforums->input['IP_ADDRESS'], 0, 50),
  277.                                                                      'browser'      => substr($HTTP_USER_AGENT, 0, 50),
  278.                                                                      'start_session'=> time(),
  279.                                                           )       );
  280.                                                          
  281.                 $db_query = "INSERT INTO ibf_sessions (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")";
  282.             }
  283.             
  284.             $DB->query( $db_query );
  285.             
  286.             //-----------------------------------
  287.             // RESET PASS IN MD5
  288.             //-----------------------------------
  289.             
  290.             $DB->query("UPDATE ibf_members SET password='$real_pass' WHERE id='".$member['id']."'");
  291.             
  292.             $ibforums->member           = $member;
  293.             $ibforums->session_id       = $session_id;
  294.             
  295.             //------------------------------
  296.             
  297.             if ($ibforums->input['CookieDate'])
  298.             {
  299.                 $std->my_setcookie("pass_hash"   , $real_pass, 1);
  300.                 $std->my_setcookie("member_id"   , $member['id'], 1);
  301.             }
  302.             
  303.             //-----------------------------------
  304.             // set our privacy cookie
  305.             //-----------------------------------
  306.             
  307.             if ($ibforums->input[Privacy] == 1)
  308.             {
  309.                 $std->my_setcookie( "anonlogin", 1 );
  310.             }
  311.             
  312.             //-----------------------------------
  313.             // Redirect them to either the board
  314.             // index, or where they came from
  315.             //-----------------------------------
  316.             
  317.             $print->redirect_screen( "{$ibforums->lang[thanks_for_login]} {$ibforums->member['name']}", $url );
  318.             
  319.             
  320.         }
  321.         else
  322.         {
  323.             $this->log_in_form( 'wrong_name' );
  324.         }
  325.         
  326.     }
  327.     
  328.     
  329.     
  330.     
  331.     
  332.  
  333.     function do_log_out() {
  334.         global $std, $ibforums, $DB, $print;
  335.         
  336.         if(! $ibforums->member['id'])
  337.         {
  338.             $std->Error( array( LEVEL => 1, MSG => 'no_guests') );
  339.         }
  340.         
  341.         // Update the DB
  342.         
  343.         $DB->query("UPDATE ibf_sessions SET ".
  344.                      "member_name='NULL',".
  345.                      "member_id='0',".
  346.                      "member_pass='NULL',".
  347.                      "login_type='0' ".
  348.                      "WHERE id='". $ibforums->session_id ."'");
  349.                      
  350.         // Set some cookies
  351.         
  352.         $std->my_setcookie( "member_id" , "0"  );
  353.         $std->my_setcookie( "pass_hash" , "0"  );
  354.         $std->my_setcookie( "skin"       , "-1" );
  355.         
  356.         // Redirect...
  357.         
  358.         $print->redirect_screen( $ibforums->lang['thanks_for_logout'], "" );
  359.         
  360.     }
  361.  
  362.  
  363.  
  364.  
  365.         
  366. }
  367.  
  368. ?>
  369.