bootstrap.inc.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. define('IN_IA', true);
  7. define('IA_ROOT', str_replace('\\', '/', dirname(dirname(__FILE__))));
  8. define('STARTTIME', microtime());
  9. define('MAGIC_QUOTES_GPC', (version_compare(PHP_VERSION, '7.4.0', '<') ? function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() : 0) || @ini_get('magic_quotes_sybase'));
  10. define('TIMESTAMP', time());
  11. //var_dump(IA_ROOT);
  12. $configfile = IA_ROOT . '/config.php';
  13. if (!file_exists($configfile)) {
  14. header('Content-Type: text/html; charset=utf-8');
  15. exit('配置文件不存在或是不可读,请检查“data/config.php”文件或是<a href="./install.php"> 重新安装 </a>!');
  16. }
  17. require $configfile;
  18. $_W = $_GPC = array();
  19. $_W['config'] = $config;
  20. $allow_origin = array('https://user.w7.cc', 'https://m.w7.cc', 'https://console.w7.cc', 'http://console.w7.cc', 'http://user.w7.cc', 'http://m.w7.cc');
  21. if (!empty($_W['config']['setting']['allow_origin']) && is_array($_W['config']['setting']['allow_origin'])) {
  22. $allow_origin = array_merge($allow_origin, $_W['config']['setting']['allow_origin']);
  23. }
  24. if (isset($_SERVER['HTTP_ORIGIN']) && in_array($_SERVER['HTTP_ORIGIN'], $allow_origin)) {
  25. header('Access-Control-Allow-Headers:Origin,X-Requested-With,Content-Type,Accept,Authorization,cancelload,X-W7-Oauthtoken,W7-Oauthtoken');
  26. header('Access-Control-Allow-Credentials:true');
  27. header('Access-Control-Allow-Method:POST,GET,OPTIONS');
  28. header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
  29. }
  30. if ('OPTIONS' == (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '')) {
  31. $vars = array();
  32. $vars['message'] = array('errno' => 0, 'message' => null);
  33. $vars['redirect'] = '';
  34. $vars['type'] = 'ajax';
  35. exit(json_encode($vars));
  36. }
  37. require IA_ROOT . '/framework/const.inc.php';
  38. require IA_ROOT . '/framework/class/loader.class.php';
  39. load()->func('global');
  40. load()->func('compat');
  41. load()->func('compat.biz');
  42. load()->func('pdo');
  43. load()->classs('account');
  44. load()->model('cache');
  45. load()->model('account');
  46. load()->model('setting');
  47. load()->model('module');
  48. load()->library('agent');
  49. load()->classs('db');
  50. load()->func('communication');
  51. define('CLIENT_IP', getip());
  52. $_W['config']['db']['tablepre'] = !empty($_W['config']['db']['master']['tablepre']) ? $_W['config']['db']['master']['tablepre'] : $_W['config']['db']['tablepre'];
  53. $_W['timestamp'] = TIMESTAMP;
  54. $_W['charset'] = $_W['config']['setting']['charset'];
  55. $_W['clientip'] = CLIENT_IP;
  56. if (!empty($_W['config']['setting']['https']) && $_W['config']['setting']['https'] == '1') {
  57. $_W['ishttps'] = $_W['config']['setting']['https'];
  58. } else {
  59. $_W['ishttps'] = !empty($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT'] ||
  60. !empty($_SERVER['HTTP_FROM_HTTPS']) && 'on' == strtolower($_SERVER['HTTP_FROM_HTTPS']) ||
  61. (!empty($_SERVER['HTTPS']) && 'off' != strtolower($_SERVER['HTTPS'])) ||
  62. !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) ||
  63. !empty($_SERVER['HTTP_X_CLIENT_SCHEME']) && 'https' == strtolower($_SERVER['HTTP_X_CLIENT_SCHEME']) ||
  64. !empty($_SERVER['HTTP_X_CLIENT_PROTO']) && 'https' == strtolower($_SERVER['HTTP_X_CLIENT_PROTO'])
  65. ? STATUS_ON : STATUS_OFF;
  66. }
  67. $_W['sitescheme'] = $_W['ishttps'] ? 'https://' : 'http://';
  68. $_W['script_name'] = htmlspecialchars(scriptname());
  69. $sitepath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  70. $_W['siteroot'] = htmlspecialchars($_W['sitescheme'] . (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $sitepath);
  71. if ('/' != substr($_W['siteroot'], -1)) {
  72. $_W['siteroot'] .= '/';
  73. }
  74. $urls = parse_url($_W['siteroot']);
  75. $urls['path'] = empty($urls['path']) ? '' : $urls['path'];
  76. $urls['path'] = str_replace(array('/web', '/app', '/payment/wechat', '/payment/alipay', '/api'), '', $urls['path']);
  77. $urls['scheme'] = !empty($urls['scheme']) ? $urls['scheme'] : 'http';
  78. $urls['host'] = !empty($urls['host']) ? $urls['host'] : '';
  79. $_W['siteroot'] = $urls['scheme'] . '://' . $urls['host'] . ((!empty($urls['port']) && '80' != $urls['port']) ? ':' . $urls['port'] : '') . $urls['path'];
  80. $_W['isajax'] = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && 'xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH']);
  81. $pdo_if_start = (pdo()->getPDO() instanceof PDO);
  82. if (!$pdo_if_start && file_exists(IA_ROOT . '/install.php')) {
  83. header('Content-Type: text/html; charset=utf-8');
  84. require IA_ROOT . '/framework/version.inc.php';
  85. echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
  86. if (!empty(getenv('APP_ID')) && !empty(getenv('APP_SECRET')) && !empty(getenv('MYSQL_DATABASE')) && !empty($_SERVER['HTTP_SEC_FETCH_DEST']) && 'document' == $_SERVER['HTTP_SEC_FETCH_DEST']) {
  87. header('Location: https://console.w7.cc/app/' . getenv('APP_ID') . '/founder/micro/installWe7');
  88. exit;
  89. } else {
  90. $message = "如果你还没安装本程序,请运行<a href='" . (false === strpos($_SERVER['SCRIPT_NAME'], 'web') ? './install.php' : '../install.php') . "'> install.php 进入安装&gt;&gt; </a><br/><br/>";
  91. $message .= "&nbsp;&nbsp;<a href='http://www.w7.cc' style='font-size:12px' target='_blank'>Power by W7 " . IMS_VERSION . ' &nbsp;微擎公众平台自助开源引擎</a>';
  92. echo ierror_page($message);
  93. }
  94. exit();
  95. }
  96. unset($configfile, $config, $pdo_if_start);
  97. define('ATTACHMENT_ROOT', IA_ROOT . '/attachment/');
  98. error_reporting(0);
  99. define('DEVELOPMENT', $_W['config']['setting']['development'] == 1);
  100. if (STATUS_ON == $_W['config']['setting']['development']) {
  101. $_W['config']['setting']['local_dev'] = STATUS_ON;
  102. ini_set('display_errors', '1');
  103. error_reporting(E_ALL ^ E_NOTICE);
  104. } else {
  105. $_W['config']['setting']['local_dev'] = STATUS_OFF;
  106. }
  107. if (!in_array($_W['config']['setting']['cache'], array('mysql', 'memcache', 'redis', 'memcached'))) {
  108. $_W['config']['setting']['cache'] = 'mysql';
  109. }
  110. load()->func('cache');
  111. if (function_exists('date_default_timezone_set')) {
  112. date_default_timezone_set($_W['config']['setting']['timezone']);
  113. }
  114. if (!empty($_W['config']['setting']['memory_limit']) && function_exists('ini_get') && function_exists('ini_set')) {
  115. if ($_W['config']['setting']['memory_limit'] != @ini_get('memory_limit')) {
  116. @ini_set('memory_limit', $_W['config']['setting']['memory_limit']);
  117. }
  118. }
  119. $_W['ispost'] = !empty($_SERVER['REQUEST_METHOD']) && 'POST' == strtoupper($_SERVER['REQUEST_METHOD']);
  120. if (MAGIC_QUOTES_GPC) {
  121. $_GET = istripslashes($_GET);
  122. $_POST = istripslashes($_POST);
  123. $_COOKIE = istripslashes($_COOKIE);
  124. }
  125. $cplen = strlen($_W['config']['cookie']['pre']);
  126. foreach ($_COOKIE as $key => $value) {
  127. if ($_W['config']['cookie']['pre'] == substr($key, 0, $cplen)) {
  128. $_GPC[substr($key, $cplen)] = $value;
  129. }
  130. }
  131. unset($cplen, $key, $value);
  132. $_GPC = array_merge($_GET, $_GPC, $_POST);
  133. $_GPC = ihtmlspecialchars($_GPC);
  134. $_W['siteurl'] = $urls['scheme'] . '://' . $urls['host'] . ((!empty($urls['port']) && '80' != $urls['port']) ? ':' . $urls['port'] : '') . $_W['script_name'] . '?' . http_build_query($_GET, '', '&');
  135. if (!$_W['isajax']) {
  136. $input = file_get_contents('php://input');
  137. if (!empty($input)) {
  138. $__input = @json_decode($input, true);
  139. if (!empty($__input)) {
  140. $_GPC['__input'] = $__input;
  141. $_W['isajax'] = true;
  142. }
  143. }
  144. unset($input, $__input);
  145. }
  146. $_W['uniacid'] = $_W['uid'] = 0;
  147. setting_load();
  148. if (empty($_W['setting']['upload'])) {
  149. $_W['setting']['upload'] = array_merge($_W['config']['upload']);
  150. }
  151. if (!empty($_W['setting']['local_version_info']['family']) || !empty($_W['setting']['site']['family'])) {
  152. define('IMS_FAMILY', !empty($_W['setting']['local_version_info']['family']) ? $_W['setting']['local_version_info']['family'] : $_W['setting']['site']['family']);
  153. define('IMS_VERSION', !empty($_W['setting']['local_version_info']['version']) ? $_W['setting']['local_version_info']['version'] : $_W['setting']['site']['version']);
  154. define('IMS_RELEASE_DATE', !empty($_W['setting']['local_version_info']['release_date']) ? $_W['setting']['local_version_info']['release_date'] : $_W['setting']['site']['release']);
  155. } else {
  156. require IA_ROOT . '/framework/version.inc.php';
  157. }
  158. $_W['os'] = Agent::deviceType();
  159. if (Agent::DEVICE_MOBILE == $_W['os']) {
  160. $_W['os'] = 'mobile';
  161. } elseif (Agent::DEVICE_DESKTOP == $_W['os']) {
  162. $_W['os'] = 'windows';
  163. } else {
  164. $_W['os'] = 'unknown';
  165. }
  166. $_W['container'] = Agent::browserType();
  167. if (Agent::MICRO_MESSAGE_YES == Agent::isMicroMessage()) {
  168. $_W['container'] = 'wechat';
  169. if (Agent::MICRO_WXWORK_YES == Agent::isWxWork()) {
  170. $_W['container'] = 'workwechat';
  171. }
  172. } elseif (Agent::BROWSER_TYPE_ANDROID == $_W['container']) {
  173. $_W['container'] = 'android';
  174. } elseif (Agent::BROWSER_TYPE_IPAD == $_W['container']) {
  175. $_W['container'] = 'ipad';
  176. } elseif (Agent::BROWSER_TYPE_IPHONE == $_W['container']) {
  177. $_W['container'] = 'iphone';
  178. } elseif (Agent::BROWSER_TYPE_IPOD == $_W['container']) {
  179. $_W['container'] = 'ipod';
  180. } else {
  181. $_W['container'] = 'unknown';
  182. }
  183. if ('wechat' == $_W['container'] || 'baidu' == $_W['container']) {
  184. $_W['platform'] = 'account';
  185. }
  186. $controller = !empty($_GPC['c']) ? $_GPC['c'] : '';
  187. $action = !empty($_GPC['a']) ? $_GPC['a'] : '';
  188. $do = !empty($_GPC['do']) ? $_GPC['do'] : '';
  189. if (strtoupper(php_sapi_name()) != 'CLI') {
  190. header('Content-Type: text/html; charset=' . $_W['charset']);
  191. }