PageRenderTime 24ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/php/includes_bak/modules/integrates/phpbb.php

https://github.com/matthewxu/doc
PHP | 232 lines | 134 code | 41 blank | 57 comment | 20 complexity | 823d9d434f0c007e200b057464899062 MD5 | raw file
  1. <?php
  2. /**
  3. * ECSHOP 会员数据处理类
  4. * ============================================================================
  5. * 版权所有 2005-2010 上海商派网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.ecshop.com
  7. * ----------------------------------------------------------------------------
  8. * 这是一个免费开源的软件;这意味着您可以在不用于商业目的的前提下对程序代码
  9. * 进行修改、使用和再发布。
  10. * ============================================================================
  11. * $Author: liuhui $
  12. * $Id: phpbb.php 17063 2010-03-25 06:35:46Z liuhui $
  13. */
  14. if (!defined('IN_ECS'))
  15. {
  16. die('Hacking attempt');
  17. }
  18. /* 模块的基本信息 */
  19. if (isset($set_modules) && $set_modules == TRUE)
  20. {
  21. $i = (isset($modules)) ? count($modules) : 0;
  22. /* 会员数据整合插件的代码必须和文件名保持一致 */
  23. $modules[$i]['code'] = 'phpbb';
  24. /* 被整合的第三方程序的名称 */
  25. $modules[$i]['name'] = 'phpBB';
  26. /* 被整合的第三方程序的版本 */
  27. $modules[$i]['version'] = '2.0.x';
  28. /* 插件的作者 */
  29. $modules[$i]['author'] = 'ECSHOP R&D TEAM';
  30. /* 插件作者的官方网站 */
  31. $modules[$i]['website'] = 'http://www.ecshop.com';
  32. /* 插件的初始的默认值 */
  33. $modules[$i]['default']['db_host'] = 'localhost';
  34. $modules[$i]['default']['db_user'] = 'root';
  35. $modules[$i]['default']['prefix'] = 'phpbb_';
  36. //$modules[$i]['default']['cookie_prefix'] = 'xn_';
  37. return;
  38. }
  39. require_once(ROOT_PATH . 'includes/modules/integrates/integrate.php');
  40. class phpbb extends integrate
  41. {
  42. var $cookie_prefix = '';
  43. function __construct($cfg)
  44. {
  45. $this->phpbb($cfg);
  46. }
  47. /**
  48. *
  49. *
  50. * @access public
  51. * @param
  52. *
  53. * @return void
  54. */
  55. function phpbb($cfg)
  56. {
  57. parent::integrate($cfg);
  58. if ($this->error)
  59. {
  60. /* 数据库连接出错 */
  61. return false;
  62. }
  63. //$this->cookie_prefix = $cfg['cookie_prefix'];
  64. $this->field_id = 'user_id';
  65. $this->field_name = 'username';
  66. $this->field_email = 'user_email';
  67. $this->field_gender = 'NULL';
  68. $this->field_bday = 'NULL';
  69. $this->field_pass = 'user_password';
  70. $this->field_reg_date = 'user_regdate';
  71. $this->user_table = 'users';
  72. /* 检查数据表是否存在 */
  73. $sql = "SHOW TABLES LIKE '" . $this->prefix . "%'";
  74. $exist_tables = $this->db->getCol($sql);
  75. if (empty($exist_tables) || (!in_array($this->prefix.$this->user_table, $exist_tables)) || (!in_array($this->prefix.'config', $exist_tables)))
  76. {
  77. $this->error = 2;
  78. /* 缺少数据表 */
  79. return false;
  80. }
  81. $this->cookie_prefix = $this->db->getOne("SELECT config_value FROM " .$this->table('config'). " WHERE config_name='cookie_name'");
  82. }
  83. /**
  84. * 设置论坛cookie
  85. *
  86. * @access public
  87. * @param
  88. *
  89. * @return void
  90. */
  91. function set_cookie ($username="")
  92. {
  93. parent::set_cookie($username);
  94. if (empty($username))
  95. {
  96. $time = time() - 3600;
  97. setcookie($this->cookie_prefix.'_data', '', $time, $this->cookie_path, $this->cookie_domain);
  98. setcookie($this->cookie_prefix.'_sid', '', $time, $this->cookie_path, $this->cookie_domain);
  99. }
  100. else
  101. {
  102. if ($this->charset != 'UTF8')
  103. {
  104. $username = ecs_iconv('UTF8', $this->charset, $username);
  105. }
  106. $sql = "SELECT " .$this->field_id. " AS user_id, " .$this->field_name. " AS user_name, " .$this->field_email." AS email ".
  107. " FROM " .$this->table($this->user_table).
  108. " WHERE " .$this->field_name. " = '$username'";
  109. $row = $this->db->getRow($sql);
  110. $auto_login_key = md5($this->dss_rand() . $this->dss_rand());
  111. /* 向整合对象的数据表里写入cookie值 */
  112. $this->db->query("INSERT INTO " .$this->table('sessions_keys')." (key_id, user_id, last_login) ".
  113. "VALUES ('" .$auto_login_key. "', '$row[user_id]', '".time()."')");
  114. $client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
  115. $sql = "INSERT INTO ".$this->table('sessions')." (session_id, session_user_id, session_start, session_time, session_ip, session_logged_in, session_admin) VALUES('$auto_login_key', '".$row[$this->field_id]."','".time()."','".time()."','".$this->encode_ip($client_ip)."',1, 0)";
  116. $this->db->query($sql);
  117. $sessiondata = array('autologinid'=>$auto_login_key, 'userid'=>$row['user_id']);
  118. setcookie($this->cookie_prefix . '_data', serialize($sessiondata), time() + 31536000, $this->cookie_path, $this->cookie_domain);
  119. setcookie($this->cookie_prefix . '_sid', $auto_login_key, time() + 31536000, $this->cookie_path, $this->cookie_domain);
  120. }
  121. }
  122. /**
  123. * 检查cookie
  124. *
  125. * @access public
  126. * @param
  127. *
  128. * @return void
  129. */
  130. function check_cookie ()
  131. {
  132. if (empty($_COOKIE[$this->cookie_prefix . '_data']) || empty($_COOKIE[$this->cookie_prefix . '_sid']))
  133. {
  134. return '';
  135. }
  136. /* 序列化cookie,取得用户信息 */
  137. $cookie_data = addslashes_deep(@unserialize(stripslashes_deep($_COOKIE[$this->cookie_prefix . '_data'])));
  138. $cookie_session_id = addslashes_deep(trim($_COOKIE[$this->cookie_prefix . '_sid']));
  139. if (empty($cookie_data['userid']) || empty($cookie_data['autologinid']))
  140. {
  141. return '';
  142. }
  143. $sql = "SELECT " . $this->field_name .
  144. " FROM " . $this->table('sessions') . " AS s ".
  145. " LEFT JOIN " . $this->table($this->user_table) . " AS u ON s.session_user_id = u.user_id".
  146. " WHERE session_id = '$cookie_session_id' AND session_user_id = '$cookie_data[userid]'";
  147. $username = $this->db->getOne($sql);
  148. if (empty($username))
  149. {
  150. return '';
  151. }
  152. else
  153. {
  154. if ($this->charset != 'UTF8')
  155. {
  156. $username = ecs_iconv($this->charset, 'UTF8', $username);
  157. }
  158. return $username;
  159. }
  160. }
  161. /**
  162. * Our own generator of random values
  163. * This uses a constantly changing value as the base for generating the values
  164. * The board wide setting is updated once per page if this code is called
  165. * With thanks to Anthrax101 for the inspiration on this one
  166. * Added in phpBB 2.0.20
  167. */
  168. function dss_rand()
  169. {
  170. $dss_seeded = false;
  171. $rand_seed = $this->db->getOne("SELECT config_value FROM " .$this->table('config'). " WHERE config_name = 'rand_seed'");
  172. $val = $rand_seed . microtime();
  173. $val = md5($val);
  174. $rand_seed = md5($rand_seed . $val . 'a');
  175. if ($dss_seeded !== true)
  176. {
  177. $sql = "UPDATE ".$this->table('config')." SET config_value = '".$rand_seed."' WHERE config_name = 'rand_seed'";
  178. if (!$this->db->query($sql))
  179. {
  180. die('error');
  181. }
  182. $dss_seeded = true;
  183. }
  184. return substr($val, 16);
  185. }
  186. function encode_ip($dotquad_ip)
  187. {
  188. $ip_sep = explode('.', $dotquad_ip);
  189. return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
  190. }
  191. }