wagent.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. define('IN_IA', true);
  3. define('STARTTIME', microtime());
  4. define('IA_ROOT', str_replace('\\', '/', dirname(dirname(__FILE__))));
  5. define('MAGIC_QUOTES_GPC', (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) || @ini_get('magic_quotes_sybase'));
  6. define('TIMESTAMP', time());
  7. $_W = $_GPC = array();
  8. $configfile = IA_ROOT . '/data/config.php';
  9. if (!(file_exists($configfile)))
  10. {
  11. exit('配置文件不存在或是不可读,请检查“data/config”文件或是重新安装!');
  12. }
  13. require $configfile;
  14. require IA_ROOT . '/framework/version.inc.php';
  15. require IA_ROOT . '/framework/const.inc.php';
  16. require IA_ROOT . '/framework/class/loader.class.php';
  17. load()->func('global');
  18. load()->func('compat');
  19. load()->func('pdo');
  20. load()->classs('account');
  21. load()->classs('agent');
  22. load()->model('cache');
  23. load()->model('account');
  24. load()->model('setting');
  25. load()->model('user');
  26. load()->func('tpl');
  27. define('CLIENT_IP', getip());
  28. $_W['config'] = $config;
  29. $_W['config']['db']['tablepre'] = ((!(empty($_W['config']['db']['master']['tablepre'])) ? $_W['config']['db']['master']['tablepre'] : $_W['config']['db']['tablepre']));
  30. $_W['timestamp'] = TIMESTAMP;
  31. $_W['charset'] = $_W['config']['setting']['charset'];
  32. $_W['clientip'] = CLIENT_IP;
  33. $_W['token'] = token();
  34. unset($configfile, $config);
  35. define('ATTACHMENT_ROOT', IA_ROOT . '/attachment/');
  36. define('DEVELOPMENT', $_W['config']['setting']['development'] == 1);
  37. if (DEVELOPMENT)
  38. {
  39. ini_set('display_errors', '1');
  40. error_reporting(30719 ^ 8);
  41. }
  42. else
  43. {
  44. error_reporting(0);
  45. }
  46. if (!(in_array($_W['config']['setting']['cache'], array('mysql', 'file', 'memcache'))))
  47. {
  48. $_W['config']['setting']['cache'] = 'mysql';
  49. }
  50. load()->func('cache');
  51. if (function_exists('date_default_timezone_set'))
  52. {
  53. date_default_timezone_set($_W['config']['setting']['timezone']);
  54. }
  55. if (!(empty($_W['config']['memory_limit'])) && function_exists('ini_get') && function_exists('ini_set'))
  56. {
  57. if (@ini_get('memory_limit') != $_W['config']['memory_limit'])
  58. {
  59. @ini_set('memory_limit', $_W['config']['memory_limit']);
  60. }
  61. }
  62. $_W['ishttps'] = ((!(empty($_W['config']['setting']['https'])) ? true : strtolower((($_SERVER['SERVER_PORT'] == 443) || (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? true : false))));
  63. $_W['isajax'] = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  64. $_W['ispost'] = $_SERVER['REQUEST_METHOD'] == 'POST';
  65. $_W['sitescheme'] = (($_W['ishttps'] ? 'https://' : 'http://'));
  66. $_W['script_name'] = htmlspecialchars(scriptname());
  67. $sitepath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  68. $_W['siteroot'] = htmlspecialchars($_W['sitescheme'] . $_SERVER['HTTP_HOST'] . $sitepath);
  69. if (substr($_W['siteroot'], -1) != '/')
  70. {
  71. $_W['siteroot'] .= '/';
  72. }
  73. $urls = parse_url($_W['siteroot']);
  74. $urls['path'] = str_replace(array('/web', '/app', '/payment/wechat', '/payment/alipay', '/api'), '', $urls['path']);
  75. $_W['siteroot'] = $urls['scheme'] . '://' . $urls['host'] . ((!(empty($urls['port'])) && ($urls['port'] != '80') ? ':' . $urls['port'] : '')) . $urls['path'];
  76. $_W['siteurl'] = $urls['scheme'] . '://' . $urls['host'] . ((!(empty($urls['port'])) && ($urls['port'] != '80') ? ':' . $urls['port'] : '')) . $_W['script_name'] . ((empty($_SERVER['QUERY_STRING']) ? '' : '?')) . $_SERVER['QUERY_STRING'];
  77. if (MAGIC_QUOTES_GPC)
  78. {
  79. $_GET = istripslashes($_GET);
  80. $_POST = istripslashes($_POST);
  81. $_COOKIE = istripslashes($_COOKIE);
  82. }
  83. $cplen = strlen($_W['config']['cookie']['pre']);
  84. foreach ($_COOKIE as $key => $value )
  85. {
  86. if (substr($key, 0, $cplen) == $_W['config']['cookie']['pre'])
  87. {
  88. $_GPC[substr($key, $cplen)] = $value;
  89. }
  90. }
  91. unset($cplen, $key, $value);
  92. $_GPC = array_merge($_GET, $_POST, $_GPC);
  93. $_GPC = ihtmlspecialchars($_GPC);
  94. if (!($_W['isajax']))
  95. {
  96. $input = file_get_contents('php://input');
  97. if (!(empty($input)))
  98. {
  99. $__input = @json_decode($input, true);
  100. if (!(empty($__input)))
  101. {
  102. $_GPC['__input'] = $__input;
  103. $_W['isajax'] = true;
  104. }
  105. }
  106. unset($input, $__input);
  107. }
  108. setting_load();
  109. if (empty($_W['setting']['upload']))
  110. {
  111. $_W['setting']['upload'] = array_merge($_W['config']['upload']);
  112. }
  113. $_W['attachurl'] = $_W['attachurl_local'] = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/';
  114. if (!(empty($_W['setting']['remote'][$_GPC['i']]['type'])))
  115. {
  116. $_W['setting']['remote'] = $_W['setting']['remote'][$_GPC['i']];
  117. }
  118. if (!(empty($_W['setting']['remote']['type'])))
  119. {
  120. if ($_W['setting']['remote']['type'] == 1)
  121. {
  122. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['ftp']['url'] . '/';
  123. }
  124. else if ($_W['setting']['remote']['type'] == 2)
  125. {
  126. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['alioss']['url'] . '/';
  127. }
  128. else if ($_W['setting']['remote']['type'] == 3)
  129. {
  130. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['qiniu']['url'] . '/';
  131. }
  132. else if ($_W['setting']['remote']['type'] == 4)
  133. {
  134. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['cos']['url'] . '/';
  135. }
  136. }
  137. header('Content-Type: text/html; charset=' . $_W['charset']);
  138. $session = json_decode(authcode($_GPC['__session']), true);
  139. if (empty($session))
  140. {
  141. $session = json_decode(base64_decode($_GPC['__session']), true);
  142. }
  143. if (is_array($session))
  144. {
  145. $user = user_single(array('uid' => $session['uid']));
  146. if (is_array($user) && ($session['hash'] == md5($user['password'] . $user['salt'])))
  147. {
  148. $_W['uid'] = $user['uid'];
  149. $_W['username'] = $user['username'];
  150. $user['currentvisit'] = $user['lastvisit'];
  151. $user['currentip'] = $user['lastip'];
  152. $user['lastvisit'] = $session['lastvisit'];
  153. $user['lastip'] = $session['lastip'];
  154. $_W['user'] = $user;
  155. $founders = explode(',', $_W['config']['setting']['founder']);
  156. $_W['isfounder'] = in_array($_W['uid'], $founders);
  157. if (0 < $_GPC['sid'])
  158. {
  159. isetcookie('__sid', $_GPC['sid'], 7 * 86400);
  160. }
  161. if (0 < $_GPC['agent_id'])
  162. {
  163. isetcookie('__agent_id', $_GPC['agent_id'], 7 * 86400);
  164. }
  165. unset($founders);
  166. }
  167. else
  168. {
  169. isetcookie('__session', false, -100);
  170. isetcookie('__agent_id', 0, -1000);
  171. }
  172. unset($user);
  173. }
  174. unset($session);
  175. if (!(function_exists('uni_permission')))
  176. {
  177. function uni_permission($uid = 0, $uniacid = 0)
  178. {
  179. global $_W;
  180. $uid = ((empty($uid) ? $_W['uid'] : intval($uid)));
  181. $uniacid = ((empty($uniacid) ? $_W['uniacid'] : intval($uniacid)));
  182. $founders = explode(',', $_W['config']['setting']['founder']);
  183. if (in_array($uid, $founders))
  184. {
  185. return 'founder';
  186. }
  187. $sql = 'SELECT `role` FROM ' . tablename('uni_account_users') . ' WHERE `uid`=:uid AND `uniacid`=:uniacid';
  188. $pars = array();
  189. $pars[':uid'] = $uid;
  190. $pars[':uniacid'] = $uniacid;
  191. $role = pdo_fetchcolumn($sql, $pars);
  192. return (in_array($role, array('manager', 'owner')) ? 'manager' : 'operator');
  193. }
  194. }
  195. if (!(empty($_GPC['i'])))
  196. {
  197. $_W['uniacid'] = intval($_GPC['i']);
  198. $_W['uniaccount'] = $_W['account'] = uni_fetch($_W['uniacid']);
  199. $_W['acid'] = $_W['account']['acid'];
  200. if (!(empty($_W['uid'])))
  201. {
  202. $_W['role'] = uni_permission($_W['uid'], $_W['uniacid']);
  203. if ($_W['role'] == 'owner')
  204. {
  205. $_W['role'] = 'manager';
  206. }
  207. }
  208. }
  209. if (empty($_W['uniacid']))
  210. {
  211. exit('公众号信息错误');
  212. }
  213. if ((empty($_W['isfounder']) && ($_W['role'] != 'manager')) || ((!(empty($_W['isfounder'])) || ($_W['role'] == 'manager')) && empty($_GPC['agent_id'])))
  214. {
  215. $session = json_decode(base64_decode($_GPC['__we7_wmall_agent']), true);
  216. if (is_array($session))
  217. {
  218. $agent = pdo_get('tiny_wmall_agent', array('id' => $session['id']));
  219. if (is_array($session) && ($session['hash'] == $agent['password']))
  220. {
  221. $_W['role'] = 'agenter';
  222. $_W['we7_wmall']['agent'] = $agent;
  223. $_W['agentid'] = $agent['id'];
  224. isetcookie('__agent_id', $agent['id'], 7 * 86400);
  225. if ($_W['uniacid'] != $_GPC['uniacid'])
  226. {
  227. isetcookie('__uniacid', $_W['uniacid'], 7 * 86400);
  228. }
  229. }
  230. else
  231. {
  232. isetcookie('__we7_wmall_agent', false, -100);
  233. isetcookie('__agent_id', 0, -1000);
  234. }
  235. unset($user);
  236. }
  237. unset($session);
  238. }
  239. $entry = array('module' => 'we7_wmall', 'do' => 'web');
  240. define('IN_SYS', true);
  241. define('IN_MODULE', $entry['module']);
  242. load()->web('common');
  243. load()->web('template');
  244. $site = WeUtility::createModuleSite($entry['module']);
  245. if (!(is_error($site)))
  246. {
  247. $method = 'doWeb' . ucfirst($entry['do']);
  248. exit($site->$method());
  249. }
  250. exit();
  251. ?>