index.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: index.php 23508 2011-07-21 06:34:40Z cnteacher $
  7. */
  8. define('IN_API', true);
  9. define('CURSCRIPT', 'api_mserver');
  10. define('APPTYPEID', 200);
  11. $_ENV['remote'] = new discuz_remote();
  12. $_ENV['remote']->init();
  13. $_ENV['remote']->loadservice();
  14. class discuz_remote {
  15. var $mod;
  16. var $modobj;
  17. var $core;
  18. function init() {
  19. require_once('../../source/class/class_core.php');
  20. $cachelist = array();
  21. $this->core = C::app();
  22. $this->core->cachelist = $cachelist;
  23. $this->core->init_setting = true;
  24. $this->core->init_cron = false;
  25. $this->core->init_user = false;
  26. $this->core->init_session = false;
  27. $this->core->init_misc = false;
  28. $this->core->init_mobile = false;
  29. $this->core->init();
  30. define('SERVICE_DIR', getglobal('config/remote/dir') ? getglobal('config/remote/dir') : 'remote');
  31. $this->core->reject_robot();
  32. if (empty($_GET['mod']) || preg_match('/[^0-9a-z]/i', $_GET['mod'])) {
  33. $this->mod = 'index';
  34. } else {
  35. $this->mod = $_GET['mod'];
  36. }
  37. }
  38. function loadservice() {
  39. if(!$this->core->config['remote']['on']) {
  40. remote_service::error(1, 'remote service is down');
  41. }
  42. if(!$this->core->config['remote']['appkey']) {
  43. remote_service::error(1, 'remote service need a appkey, please edit you config.global.php');
  44. }
  45. if ($this->mod != 'index') {
  46. $sign = $_GET['sign'];
  47. unset($_GET['sign']);
  48. if (empty($sign) || $sign != $this->sign($_GET)) {
  49. }
  50. }
  51. if(!$this->check_timestamp()) {
  52. remote_service::error(5, 'your request is time out');
  53. }
  54. $modfile = DISCUZ_ROOT . './api/' . SERVICE_DIR . '/mod/mod_' . $this->mod . '.php';
  55. if (!is_file($modfile)) {
  56. remote_service::error(3, 'mod file is missing');
  57. }
  58. require $modfile;
  59. $classname = 'mod_'.$this->mod;
  60. if(class_exists($classname)) {
  61. $service = new $classname;
  62. $service->run();
  63. }
  64. }
  65. function check_timestamp()
  66. {
  67. if(empty($_GET['timestamp'])) {
  68. return 1;
  69. }
  70. $ttl = abs(empty($_GET['ttl']) ? 600 : $_GET['ttl']);
  71. $check = abs(TIMESTAMP - $_GET['timestamp']);
  72. return $check > $ttl ? 0 : 1;
  73. }
  74. function sign($arg) {
  75. $str = '';
  76. foreach ($arg as $k => $v) {
  77. $str .= $k . '=' . $v . '&';
  78. }
  79. return md5($str . getglobal('config/remote/appkey'));
  80. }
  81. }
  82. class remote_service {
  83. var $version = '1.0.0';
  84. var $config;
  85. function remote_service() {
  86. $this->config = getglobal('config/remote');
  87. }
  88. function run() {
  89. remote_service::success('service is done.');
  90. }
  91. function error($code, $msg) {
  92. $code = sprintf("%04d", $code);
  93. echo $code.':'.ucfirst($msg);
  94. exit();
  95. }
  96. function success($msg) {
  97. remote_service::error(0, $msg);
  98. }
  99. }
  100. ?>