uc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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: uc.php 36358 2017-01-20 02:05:50Z nemohou $
  7. */
  8. error_reporting(0);
  9. define('UC_CLIENT_VERSION', '1.6.0');
  10. define('UC_CLIENT_RELEASE', '20170101');
  11. define('API_DELETEUSER', 1);
  12. define('API_RENAMEUSER', 1);
  13. define('API_GETTAG', 1);
  14. define('API_SYNLOGIN', 1);
  15. define('API_SYNLOGOUT', 1);
  16. define('API_UPDATEPW', 1);
  17. define('API_UPDATEBADWORDS', 1);
  18. define('API_UPDATEHOSTS', 1);
  19. define('API_UPDATEAPPS', 1);
  20. define('API_UPDATECLIENT', 1);
  21. define('API_UPDATECREDIT', 1);
  22. define('API_GETCREDIT', 1);
  23. define('API_GETCREDITSETTINGS', 1);
  24. define('API_UPDATECREDITSETTINGS', 1);
  25. define('API_ADDFEED', 1);
  26. define('API_RETURN_SUCCEED', '1');
  27. define('API_RETURN_FAILED', '-1');
  28. define('API_RETURN_FORBIDDEN', '1');
  29. define('IN_API', true);
  30. define('CURSCRIPT', 'api');
  31. if(!defined('IN_UC')) {
  32. require_once '../source/class/class_core.php'; if (method_exists("C", "app")) { $discuz = C::app(); $discuz->init(); }
  33. $discuz = C::app();
  34. $discuz->init();
  35. require DISCUZ_ROOT.'./config/config_ucenter.php';
  36. $get = $post = array();
  37. $code = @$_GET['code'];
  38. parse_str(authcode($code, 'DECODE', UC_KEY), $get);
  39. if(time() - $get['time'] > 3600) {
  40. exit('Authracation has expiried');
  41. }
  42. if(empty($get)) {
  43. exit('Invalid Request');
  44. }
  45. include_once DISCUZ_ROOT.'./uc_client/lib/xml.class.php';
  46. $post = xml_unserialize(file_get_contents('php://input'));
  47. if(in_array($get['action'], array('test', 'deleteuser', 'renameuser', 'gettag', 'synlogin', 'synlogout', 'updatepw', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcredit', 'getcreditsettings', 'updatecreditsettings', 'addfeed'))) {
  48. $uc_note = new uc_note();
  49. echo call_user_func(array($uc_note, $get['action']), $get, $post);
  50. exit();
  51. } else {
  52. exit(API_RETURN_FAILED);
  53. }
  54. } else {
  55. exit;
  56. }
  57. class uc_note {
  58. var $dbconfig = '';
  59. var $db = '';
  60. var $tablepre = '';
  61. var $appdir = '';
  62. function _serialize($arr, $htmlon = 0) {
  63. if(!function_exists('xml_serialize')) {
  64. include_once DISCUZ_ROOT.'./uc_client/lib/xml.class.php';
  65. }
  66. return xml_serialize($arr, $htmlon);
  67. }
  68. function _construct() {
  69. }
  70. function test($get, $post) {
  71. return API_RETURN_SUCCEED;
  72. }
  73. function deleteuser($get, $post) {
  74. global $_G;
  75. if(!API_DELETEUSER) {
  76. return API_RETURN_FORBIDDEN;
  77. }
  78. $uids = str_replace("'", '', stripslashes($get['ids']));
  79. $ids = array();
  80. $ids = array_keys(C::t('common_member')->fetch_all($uids));
  81. require_once DISCUZ_ROOT.'./source/function/function_delete.php';
  82. $ids && deletemember($ids);
  83. return API_RETURN_SUCCEED;
  84. }
  85. function renameuser($get, $post) {
  86. global $_G;
  87. if(!API_RENAMEUSER) {
  88. return API_RETURN_FORBIDDEN;
  89. }
  90. $tables = array(
  91. 'common_block' => array('id' => 'uid', 'name' => 'username'),
  92. 'common_invite' => array('id' => 'fuid', 'name' => 'fusername'),
  93. 'common_member_verify_info' => array('id' => 'uid', 'name' => 'username'),
  94. 'common_mytask' => array('id' => 'uid', 'name' => 'username'),
  95. 'common_report' => array('id' => 'uid', 'name' => 'username'),
  96. 'forum_thread' => array('id' => 'authorid', 'name' => 'author'),
  97. 'forum_activityapply' => array('id' => 'uid', 'name' => 'username'),
  98. 'forum_groupuser' => array('id' => 'uid', 'name' => 'username'),
  99. 'forum_pollvoter' => array('id' => 'uid', 'name' => 'username'),
  100. 'forum_post' => array('id' => 'authorid', 'name' => 'author'),
  101. 'forum_postcomment' => array('id' => 'authorid', 'name' => 'author'),
  102. 'forum_ratelog' => array('id' => 'uid', 'name' => 'username'),
  103. 'home_album' => array('id' => 'uid', 'name' => 'username'),
  104. 'home_blog' => array('id' => 'uid', 'name' => 'username'),
  105. 'home_clickuser' => array('id' => 'uid', 'name' => 'username'),
  106. 'home_docomment' => array('id' => 'uid', 'name' => 'username'),
  107. 'home_doing' => array('id' => 'uid', 'name' => 'username'),
  108. 'home_feed' => array('id' => 'uid', 'name' => 'username'),
  109. 'home_feed_app' => array('id' => 'uid', 'name' => 'username'),
  110. 'home_friend' => array('id' => 'fuid', 'name' => 'fusername'),
  111. 'home_friend_request' => array('id' => 'fuid', 'name' => 'fusername'),
  112. 'home_notification' => array('id' => 'authorid', 'name' => 'author'),
  113. 'home_pic' => array('id' => 'uid', 'name' => 'username'),
  114. 'home_poke' => array('id' => 'fromuid', 'name' => 'fromusername'),
  115. 'home_share' => array('id' => 'uid', 'name' => 'username'),
  116. 'home_show' => array('id' => 'uid', 'name' => 'username'),
  117. 'home_specialuser' => array('id' => 'uid', 'name' => 'username'),
  118. 'home_visitor' => array('id' => 'vuid', 'name' => 'vusername'),
  119. 'portal_article_title' => array('id' => 'uid', 'name' => 'username'),
  120. 'portal_comment' => array('id' => 'uid', 'name' => 'username'),
  121. 'portal_topic' => array('id' => 'uid', 'name' => 'username'),
  122. 'portal_topic_pic' => array('id' => 'uid', 'name' => 'username'),
  123. );
  124. if(!C::t('common_member')->update($get['uid'], array('username' => $get[newusername])) && isset($_G['setting']['membersplit'])){
  125. C::t('common_member_archive')->update($get['uid'], array('username' => $get[newusername]));
  126. }
  127. loadcache("posttableids");
  128. if($_G['cache']['posttableids']) {
  129. foreach($_G['cache']['posttableids'] AS $tableid) {
  130. $tables[getposttable($tableid)] = array('id' => 'authorid', 'name' => 'author');
  131. }
  132. }
  133. foreach($tables as $table => $conf) {
  134. DB::query("UPDATE ".DB::table($table)." SET `$conf[name]`='$get[newusername]' WHERE `$conf[id]`='$get[uid]'");
  135. }
  136. return API_RETURN_SUCCEED;
  137. }
  138. function gettag($get, $post) {
  139. global $_G;
  140. if(!API_GETTAG) {
  141. return API_RETURN_FORBIDDEN;
  142. }
  143. return $this->_serialize(array($get['id'], array()), 1);
  144. }
  145. function synlogin($get, $post) {
  146. global $_G;
  147. if(!API_SYNLOGIN) {
  148. return API_RETURN_FORBIDDEN;
  149. }
  150. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  151. $cookietime = 31536000;
  152. $uid = intval($get['uid']);
  153. if(($member = getuserbyuid($uid, 1))) {
  154. dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
  155. }
  156. }
  157. function synlogout($get, $post) {
  158. global $_G;
  159. if(!API_SYNLOGOUT) {
  160. return API_RETURN_FORBIDDEN;
  161. }
  162. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  163. dsetcookie('auth', '', -31536000);
  164. }
  165. function updatepw($get, $post) {
  166. global $_G;
  167. if(!API_UPDATEPW) {
  168. return API_RETURN_FORBIDDEN;
  169. }
  170. $username = $get['username'];
  171. $newpw = md5(time().rand(100000, 999999));
  172. $uid = 0;
  173. if(($uid = C::t('common_member')->fetch_uid_by_username($username))) {
  174. $ext = '';
  175. } elseif(($uid = C::t('common_member_archive')->fetch_uid_by_username($username))) {
  176. $ext = '_archive';
  177. }
  178. if($uid) {
  179. C::t('common_member'.$ext)->update($uid, array('password' => $newpw));
  180. }
  181. return API_RETURN_SUCCEED;
  182. }
  183. function updatebadwords($get, $post) {
  184. global $_G;
  185. if(!API_UPDATEBADWORDS) {
  186. return API_RETURN_FORBIDDEN;
  187. }
  188. $data = array();
  189. if(is_array($post)) {
  190. foreach($post as $k => $v) {
  191. if(substr($v['findpattern'], 0, 1) != '/' || substr($v['findpattern'], -3) != '/is') {
  192. $v['findpattern'] = '/' . preg_quote($v['findpattern'], '/') . '/is';
  193. }
  194. $data['findpattern'][$k] = $v['findpattern'];
  195. $data['replace'][$k] = $v['replacement'];
  196. }
  197. }
  198. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/badwords.php';
  199. $fp = fopen($cachefile, 'w');
  200. $s = "<?php\r\n";
  201. $s .= '$_CACHE[\'badwords\'] = '.var_export($data, TRUE).";\r\n";
  202. fwrite($fp, $s);
  203. fclose($fp);
  204. return API_RETURN_SUCCEED;
  205. }
  206. function updatehosts($get, $post) {
  207. global $_G;
  208. if(!API_UPDATEHOSTS) {
  209. return API_RETURN_FORBIDDEN;
  210. }
  211. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/hosts.php';
  212. $fp = fopen($cachefile, 'w');
  213. $s = "<?php\r\n";
  214. $s .= '$_CACHE[\'hosts\'] = '.var_export($post, TRUE).";\r\n";
  215. fwrite($fp, $s);
  216. fclose($fp);
  217. return API_RETURN_SUCCEED;
  218. }
  219. function updateapps($get, $post) { if($post['UC_API']) { $post['UC_API'] = addslashes($post['UC_API']); }
  220. global $_G;
  221. if(!API_UPDATEAPPS) {
  222. return API_RETURN_FORBIDDEN;
  223. }
  224. $UC_API = '';
  225. if($post['UC_API']) {
  226. $UC_API = str_replace(array('\'', '"', '\\', "\0", "\n", "\r"), '', $post['UC_API']);
  227. unset($post['UC_API']);
  228. }
  229. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/apps.php';
  230. $fp = fopen($cachefile, 'w');
  231. $s = "<?php\r\n";
  232. $s .= '$_CACHE[\'apps\'] = '.var_export($post, TRUE).";\r\n";
  233. fwrite($fp, $s);
  234. fclose($fp);
  235. if($UC_API && is_writeable(DISCUZ_ROOT.'./config/config_ucenter.php')) {
  236. if(preg_match('/^https?:\/\//is', $UC_API)) {
  237. $configfile = trim(file_get_contents(DISCUZ_ROOT.'./config/config_ucenter.php'));
  238. $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
  239. $configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '".addslashes($UC_API)."');", $configfile);
  240. //$configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '".addslashes($UC_API)."');", $configfile);
  241. if($fp = @fopen(DISCUZ_ROOT.'./config/config_ucenter.php', 'w')) {
  242. @fwrite($fp, trim($configfile));
  243. @fclose($fp);
  244. }
  245. }
  246. }
  247. return API_RETURN_SUCCEED;
  248. }
  249. function updateclient($get, $post) {
  250. global $_G;
  251. if(!API_UPDATECLIENT) {
  252. return API_RETURN_FORBIDDEN;
  253. }
  254. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/settings.php';
  255. $fp = fopen($cachefile, 'w');
  256. $s = "<?php\r\n";
  257. $s .= '$_CACHE[\'settings\'] = '.var_export($post, TRUE).";\r\n";
  258. fwrite($fp, $s);
  259. fclose($fp);
  260. return API_RETURN_SUCCEED;
  261. }
  262. function updatecredit($get, $post) {
  263. global $_G;
  264. if(!API_UPDATECREDIT) {
  265. return API_RETURN_FORBIDDEN;
  266. }
  267. $credit = $get['credit'];
  268. $amount = $get['amount'];
  269. $uid = $get['uid'];
  270. if(!getuserbyuid($uid)) {
  271. return API_RETURN_SUCCEED;
  272. }
  273. updatemembercount($uid, array($credit => $amount));
  274. C::t('common_credit_log')->insert(array('uid' => $uid, 'operation' => 'ECU', 'relatedid' => $uid, 'dateline' => time(), 'extcredits'.$credit => $amount));
  275. return API_RETURN_SUCCEED;
  276. }
  277. function getcredit($get, $post) {
  278. global $_G;
  279. if(!API_GETCREDIT) {
  280. return API_RETURN_FORBIDDEN;
  281. }
  282. $uid = intval($get['uid']);
  283. $credit = intval($get['credit']);
  284. $_G['uid'] = $_G['member']['uid'] = $uid;
  285. return getuserprofile('extcredits'.$credit);
  286. }
  287. function getcreditsettings($get, $post) {
  288. global $_G;
  289. if(!API_GETCREDITSETTINGS) {
  290. return API_RETURN_FORBIDDEN;
  291. }
  292. $credits = array();
  293. foreach($_G['setting']['extcredits'] as $id => $extcredits) {
  294. $credits[$id] = array(strip_tags($extcredits['title']), $extcredits['unit']);
  295. }
  296. return $this->_serialize($credits);
  297. }
  298. function updatecreditsettings($get, $post) {
  299. global $_G;
  300. if(!API_UPDATECREDITSETTINGS) {
  301. return API_RETURN_FORBIDDEN;
  302. }
  303. $outextcredits = array();
  304. foreach($get['credit'] as $appid => $credititems) {
  305. if($appid == UC_APPID) {
  306. foreach($credititems as $value) {
  307. $outextcredits[$value['appiddesc'].'|'.$value['creditdesc']] = array(
  308. 'appiddesc' => $value['appiddesc'],
  309. 'creditdesc' => $value['creditdesc'],
  310. 'creditsrc' => $value['creditsrc'],
  311. 'title' => $value['title'],
  312. 'unit' => $value['unit'],
  313. 'ratiosrc' => $value['ratiosrc'],
  314. 'ratiodesc' => $value['ratiodesc'],
  315. 'ratio' => $value['ratio']
  316. );
  317. }
  318. }
  319. }
  320. $tmp = array();
  321. foreach($outextcredits as $value) {
  322. $key = $value['appiddesc'].'|'.$value['creditdesc'];
  323. if(!isset($tmp[$key])) {
  324. $tmp[$key] = array('title' => $value['title'], 'unit' => $value['unit']);
  325. }
  326. $tmp[$key]['ratiosrc'][$value['creditsrc']] = $value['ratiosrc'];
  327. $tmp[$key]['ratiodesc'][$value['creditsrc']] = $value['ratiodesc'];
  328. $tmp[$key]['creditsrc'][$value['creditsrc']] = $value['ratio'];
  329. }
  330. $outextcredits = $tmp;
  331. $cachefile = DISCUZ_ROOT.'./uc_client/data/cache/creditsettings.php';
  332. $fp = fopen($cachefile, 'w');
  333. $s = "<?php\r\n";
  334. $s .= '$_CACHE[\'creditsettings\'] = '.var_export($outextcredits, TRUE).";\r\n";
  335. fwrite($fp, $s);
  336. fclose($fp);
  337. return API_RETURN_SUCCEED;
  338. }
  339. function addfeed($get, $post) {
  340. global $_G;
  341. if(!API_ADDFEED) {
  342. return API_RETURN_FORBIDDEN;
  343. }
  344. return API_RETURN_SUCCEED;
  345. }
  346. }