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 / Login.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  11.9 KB  |  428 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: 14th February 2002
  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.         // Are we enforcing log ins?
  50.         
  51.         if ($ibforums->vars['force_login'] == 1)
  52.         {
  53.             $msg = 'admin_force_log_in';
  54.         }
  55.         else
  56.         {
  57.             $msg = "";
  58.         }
  59.         
  60.         // What to do?
  61.         
  62.         switch($ibforums->input['CODE']) {
  63.             case '01':
  64.                 $this->do_log_in();
  65.                 break;
  66.             case '02':
  67.                 $this->log_in_form();
  68.                 break;
  69.             case '03':
  70.                 $this->do_log_out();
  71.                 break;
  72.                 
  73.             case '04':
  74.                 $this->markforum();
  75.                 break;
  76.                 
  77.             case '05':
  78.                 $this->markboard();
  79.                 break;
  80.                 
  81.             case '06':
  82.                 $this->delete_cookies();
  83.                 break;
  84.                 
  85.             default:
  86.                 $this->log_in_form($msg);
  87.                 break;
  88.         }
  89.         
  90.         // If we have any HTML to print, do so...
  91.         
  92.         $print->add_output("$this->output");
  93.         $print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 0, NAV => $this->nav ) );
  94.             
  95.      }
  96.      
  97.      function delete_cookies()
  98.      {
  99.          global $ibforums, $DB, $std, $HTTP_COOKIE_VARS;
  100.          
  101.          if (is_array($HTTP_COOKIE_VARS))
  102.          {
  103.              foreach( $HTTP_COOKIE_VARS as $cookie => $value)
  104.              {
  105.                  if (preg_match( "/^(".$ibforums->vars['cookie_id']."fread.*$)/", $cookie, $match))
  106.                  {
  107.                      $std->my_setcookie( str_replace( $ibforums->vars['cookie_id'], "", $match[0] ) , '-1', -1 );
  108.                  }
  109.                  
  110.                  if (preg_match( "/^(".$ibforums->vars['cookie_id']."ibforum.*$)/i", $cookie, $match))
  111.                  {
  112.                      $std->my_setcookie( str_replace( $ibforums->vars['cookie_id'], "", $match[0] ) , '-', -1 );
  113.                  }
  114.              }
  115.          }
  116.          
  117.          $std->my_setcookie('pass_hash' , '-1');
  118.          $std->my_setcookie('member_id' , '-1');
  119.          $std->my_setcookie('session_id', '-1');
  120.          $std->my_setcookie('topicsread', '-1');
  121.          $std->my_setcookie('anonlogin' , '-1');
  122.          
  123.         $std->boink_it($ibforums->base_url);
  124.         exit();
  125.     }  
  126.     
  127.      
  128.      function markboard()
  129.      {
  130.          global $ibforums, $DB, $std;
  131.          
  132.          if(! $ibforums->member['id'])
  133.         {
  134.             $std->Error( array( LEVEL => 1, MSG => 'no_guests') );
  135.         }
  136.         
  137.         $DB->query("UPDATE ibf_members SET last_visit='".time()."', last_activity='".time()."' WHERE id='".$ibforums->member['id']."'");
  138.         
  139.         $std->boink_it($ibforums->base_url);
  140.         exit();
  141.     }  
  142.     
  143.     
  144.     function markforum() {
  145.         global $ibforums, $DB, $std;
  146.         
  147.         $ibforums->input['f'] = preg_replace( "/^(\d+)$/", "\\1", $ibforums->input['f'] );
  148.         
  149.         if ($ibforums->input['f'] == "")
  150.         {
  151.             $std->Error( array( LEVEL => 1, MSG => 'missing_files' ) );
  152.         }
  153.         
  154.         $std->my_setcookie( "fread_".$ibforums->input['f'], time() );
  155.         
  156.         $std->boink_it($ibforums->base_url);
  157.         exit();
  158.         
  159.     }
  160.     
  161.     
  162.     
  163.     
  164.     function log_in_form($message="") {
  165.         global $ibforums, $DB, $std, $print, $HTTP_REFERER;
  166.         
  167.         //+--------------------------------------------
  168.         //| Are they banned?
  169.         //+--------------------------------------------
  170.         
  171.         if ($ibforums->vars['ban_ip'])
  172.         {
  173.             $ips = explode( "|", $ibforums->vars['ban_ip'] );
  174.             foreach ($ips as $ip)
  175.             {
  176.                 $ip = preg_replace( "/\*/", '.*' , $ip );
  177.                 if (preg_match( "/$ip/", $ibforums->input['IP_ADDRESS'] ))
  178.                 {
  179.                     $std->Error( array( LEVEL => 1, MSG => 'you_are_banned' ) );
  180.                 }
  181.             }
  182.         }
  183.         
  184.         //+--------------------------------------------
  185.         
  186.         if ($message != "")
  187.         {
  188.             $message = $ibforums->lang[ $message ];
  189.             $message = preg_replace( "/<#NAME#>/", "<b>{$ibforums->input[UserName]}</b>", $message );
  190.         
  191.             $this->output .= $this->login_html->errors($message);
  192.         }
  193.         
  194.         $this->login_html->IN[REFERER] = $HTTP_REFERER;
  195.         
  196.         $this->output .= $this->login_html->ShowForm( $ibforums->lang['please_log_in'] );
  197.         
  198.         $this->nav        = array( $ibforums->lang['log_in'] );
  199.          $this->page_title = $ibforums->lang['log_in'];
  200.         
  201.         $print->add_output("$this->output");
  202.         $print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 0, NAV => $this->nav ) );
  203.         
  204.         exit();
  205.         
  206.     }
  207.     
  208.     function do_log_in() {
  209.         global $DB, $ibforums, $std, $print, $sess, $HTTP_USER_AGENT, $HTTP_POST_VARS;
  210.         
  211.         $url = "";
  212.         
  213.         //-------------------------------------------------
  214.         // Make sure the username and password were entered
  215.         //-------------------------------------------------
  216.         
  217.         if ($HTTP_POST_VARS['UserName'] == "")
  218.         {
  219.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_username' ) );
  220.         }
  221.     
  222.          if ($HTTP_POST_VARS['PassWord'] == "")
  223.          {
  224.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'pass_blank' ) );
  225.         }   
  226.  
  227.         
  228.         //-------------------------------------------------
  229.         // Check for input length
  230.         //-------------------------------------------------
  231.         
  232.         if (strlen($ibforums->input['UserName']) > 32)
  233.         {
  234.             $std->Error( array( LEVEL => 1, MSG => 'username_long' ) );
  235.         }
  236.         
  237.         if (strlen($ibforums->input['PassWord']) > 32)
  238.         {
  239.             $std->Error( array( LEVEL => 1, MSG => 'pass_too_long' ) );
  240.         }
  241.         
  242.         $username    = strtolower($ibforums->input['UserName']);
  243.         $password    = md5( $ibforums->input['PassWord'] );
  244.         
  245.         //-------------------------------------------------
  246.         // Attempt to get the user details
  247.         //-------------------------------------------------
  248.         
  249.         $DB->query("SELECT id, name, mgroup, password, new_pass FROM ibf_members WHERE LOWER(name)='$username'");
  250.         
  251.         if ($DB->get_num_rows())
  252.         {
  253.             $member = $DB->fetch_row();
  254.             
  255.             if ( empty($member['id']) or ($member['id'] == "") )
  256.             {
  257.                 $this->log_in_form( 'wrong_name' );
  258.             }
  259.             
  260.             if ($member['password'] != $password)
  261.             {
  262.                 $this->log_in_form( 'wrong_pass' );
  263.             }
  264.             
  265.             //------------------------------
  266.             
  267.             if ($ibforums->input['CookieDate'])
  268.             {
  269.                 $std->my_setcookie("member_id"   , $member['id'], 1);
  270.                 $std->my_setcookie("pass_hash"   , $password, 1);
  271.             }
  272.             
  273.             //------------------------------
  274.             
  275.             if ($ibforums->input['s'])
  276.             {
  277.                 $session_id = $ibforums->input['s'];
  278.                 
  279.                 // Delete any old sessions with this users IP addy that doesn't match our
  280.                 // session ID.
  281.                 
  282.                 $DB->query("DELETE FROM ibf_sessions WHERE ip_address='".$ibforums->input['IP_ADDRESS']."' AND id <> '$session_id'");
  283.                 
  284.                 $db_string = $DB->compile_db_update_string( array (
  285.                                                                      'member_name'  => $member['name'],
  286.                                                                      'member_pass'  => "",
  287.                                                                      'member_id'    => $member['id'],
  288.                                                                      'running_time' => time(),
  289.                                                                      'member_group' => $member['mgroup'],
  290.                                                                      'login_type'   => $ibforums->input['Privacy'] ? 1 : 0
  291.                                                           )       );
  292.                                                           
  293.                 $db_query = "UPDATE ibf_sessions SET $db_string WHERE id='".$ibforums->input['s']."'";
  294.             }
  295.             else
  296.             {
  297.                 $session_id = md5( uniqid(microtime()) );
  298.                 
  299.                 // Delete any old sessions with this users IP addy.
  300.                 
  301.                 $DB->query("DELETE FROM ibf_sessions WHERE ip_address='".$ibforums->input['IP_ADDRESS']."'");
  302.                 
  303.                 $db_string = $DB->compile_db_insert_string( array (
  304.                                                                      'id'           => $session_id,
  305.                                                                      'member_name'  => $member['name'],
  306.                                                                      'member_pass'  => "",
  307.                                                                      'member_id'    => $member['id'],
  308.                                                                      'running_time' => time(),
  309.                                                                      'member_group' => $member['mgroup'],
  310.                                                                      'ip_address'   => substr($ibforums->input['IP_ADDRESS'], 0, 50),
  311.                                                                      'browser'      => substr($HTTP_USER_AGENT, 0, 50),
  312.                                                                      'start_session'=> time(),
  313.                                                                      'login_type'   => $ibforums->input['Privacy'] ? 1 : 0
  314.                                                           )       );
  315.                                                          
  316.                 $db_query = "INSERT INTO ibf_sessions (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")";
  317.             }
  318.             
  319.             $DB->query( $db_query );
  320.             
  321.             //-----------------------------------
  322.             // If a bogus reset passy action occured,
  323.             // and we managed to log in, we'll assume
  324.             // that the user did nothing, so we remove
  325.             // this new pass setting.
  326.             //-----------------------------------
  327.             
  328.             if ($member['new_pass'] != "")
  329.             {
  330.                 $DB->query("UPDATE ibf_members SET new_pass='' WHERE id='".$member['id']."'");
  331.             }
  332.             
  333.             $ibforums->member           = $member;
  334.             $ibforums->session_id       = $session_id;
  335.             
  336.             if ($ibforums->input['referer'] && ($ibforums->input['act'] != 'Reg'))
  337.             {
  338.                 $url = $ibforums->input['referer'];
  339.                 $url = preg_replace( "!^\?!"       , ""   , $url );
  340.                 $url = preg_replace( "!s=(\w){32}!", ""   , $url );
  341.                 $url = preg_replace( "!act=(login|reg|lostpass)!i", "", $url );
  342.             }
  343.             
  344.             //-----------------------------------
  345.             // set our privacy cookie
  346.             //-----------------------------------
  347.             
  348.             if ($ibforums->input['Privacy'] == 1)
  349.             {
  350.                 $std->my_setcookie( "anonlogin", 1 );
  351.             }
  352.             
  353.             //-----------------------------------
  354.             // Redirect them to either the board
  355.             // index, or where they came from
  356.             //-----------------------------------
  357.             
  358.             $print->redirect_screen( "{$ibforums->lang[thanks_for_login]} {$ibforums->member['name']}", $url );
  359.             
  360.             
  361.         }
  362.         else
  363.         {
  364.             $this->log_in_form( 'wrong_name' );
  365.         }
  366.         
  367.     }
  368.     
  369.     
  370.     
  371.     
  372.     
  373.  
  374.     function do_log_out() {
  375.         global $std, $ibforums, $DB, $print, $sess, $HTTP_COOKIE_VARS;
  376.         
  377.         /*if(! $ibforums->member['id'])
  378.         {
  379.             $std->Error( array( LEVEL => 1, MSG => 'no_guests') );
  380.         }*/
  381.         
  382.         // Update the DB
  383.         
  384.         $DB->query("UPDATE ibf_sessions SET ".
  385.                      "member_name='',".
  386.                      "member_id='0',".
  387.                      "member_pass='',".
  388.                      "login_type='0' ".
  389.                      "WHERE id='". $sess->session_id ."'");
  390.                      
  391.         $DB->query("UPDATE ibf_members SET last_visit='".time()."', last_activity='".time()."' WHERE id='".$ibforums->member['id']."'");
  392.                      
  393.         // Set some cookies
  394.         
  395.         $std->my_setcookie( "member_id" , "0"  );
  396.         $std->my_setcookie( "pass_hash" , "0"  );
  397.         $std->my_setcookie( "anonlogin" , "-1" );
  398.         
  399.         if (is_array($HTTP_COOKIE_VARS))
  400.          {
  401.              foreach( $HTTP_COOKIE_VARS as $cookie => $value )
  402.              {
  403.                  if (preg_match( "/^(".$ibforums->vars['cookie_id']."fread.*$)/", $cookie, $match))
  404.                  {
  405.                      $std->my_setcookie( str_replace( $ibforums->vars['cookie_id'], "", $match[0] ) , '-1', -1 );
  406.                  }
  407.                  
  408.                  if (preg_match( "/^(".$ibforums->vars['cookie_id']."ibforum.*$)/i", $cookie, $match))
  409.                  {
  410.                      $std->my_setcookie( str_replace( $ibforums->vars['cookie_id'], "", $match[0] ) , '-', -1 );
  411.                  }
  412.              }
  413.          }
  414.         
  415.         // Redirect...
  416.         
  417.         $print->redirect_screen( $ibforums->lang['thanks_for_logout'], "" );
  418.         
  419.     }
  420.  
  421.  
  422.  
  423.  
  424.         
  425. }
  426.  
  427. ?>
  428.