uc.php 13 KB

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