PageRenderTime 24ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/discuzx_hacks/brand/upload/api/uc.php

https://github.com/bluelovers/Discuz
PHP | 393 lines | 287 code | 88 blank | 18 comment | 34 complexity | 9f2b420a9f1198dc2bbd113d93e572b5 MD5 | raw file
  1. <?php
  2. /**
  3. * [品牌空間] (C)2001-2010 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: uc.php 4374 2010-09-08 08:58:55Z fanshengshuai $
  7. */
  8. define('UC_CLIENT_VERSION', '1.5.0'); //note UCenter 版本標識
  9. define('UC_CLIENT_RELEASE', '20081031');
  10. define('API_DELETEUSER', 1); //note 用戶刪除 API 接口開關
  11. define('API_RENAMEUSER', 1); //note 用戶改名 API 接口開關
  12. define('API_GETTAG', 1); //note 獲取標籤 API 接口開關
  13. define('API_SYNLOGIN', 1); //note 同步登錄 API 接口開關
  14. define('API_SYNLOGOUT', 1); //note 同步登出 API 接口開關
  15. define('API_UPDATEPW', 1); //note 更改用戶密碼 開關
  16. define('API_UPDATEBADWORDS', 1); //note 更新關鍵字列表 開關
  17. define('API_UPDATEHOSTS', 1); //note 更新域名解析緩存 開關
  18. define('API_UPDATEAPPS', 1); //note 更新應用列表 開關
  19. define('API_UPDATECLIENT', 1); //note 更新客戶端緩存 開關
  20. define('API_UPDATECREDIT', 1); //note 更新用戶積分 開關
  21. define('API_GETCREDIT', 1); //向 UC 提供積分 開關
  22. define('API_GETCREDITSETTINGS', 1); //note 向 UCenter 提供積分設置 開關
  23. define('API_UPDATECREDITSETTINGS', 1); //note 更新應用積分設置 開關
  24. define('API_ADDFEED', 1); //向 UCHome 添加feed 開關
  25. define('API_RETURN_SUCCEED', '1');
  26. define('API_RETURN_FAILED', '-1');
  27. define('API_RETURN_FORBIDDEN', '-2');
  28. define('IN_BRAND', true);
  29. define('B_ROOT', substr(dirname(__FILE__), 0, -3));
  30. //獲取時間
  31. $_G['timestamp'] = time();
  32. if(defined('IN_UC')) {
  33. global $_G, $_SGLOBAL, $_SC, $_SCOOKIE;
  34. include_once(B_ROOT.'./common.php');
  35. include_once(B_ROOT.'./source/function/common.func.php');
  36. include_once(B_ROOT.'./data/system/config.cache.php');
  37. //鏈接數據庫
  38. dbconnect();
  39. } else {
  40. error_reporting(0);
  41. set_magic_quotes_runtime(0);
  42. defined('MAGIC_QUOTES_GPC') || define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
  43. include_once(B_ROOT.'./common.php');
  44. include_once(B_ROOT.'./source/function/common.func.php');
  45. include_once(B_ROOT.'./data/system/config.cache.php');
  46. //鏈接數據庫
  47. dbconnect();
  48. $get = $post = array();
  49. $code = @$_GET['code'];
  50. parse_str(authcode($code, 'DECODE', UC_KEY), $get);
  51. if(MAGIC_QUOTES_GPC) {
  52. $get = sstripslashes($get);
  53. }
  54. if($_G['timestamp'] - $get['time'] > 3600) {
  55. exit('Authracation has expiried');
  56. }
  57. if(empty($get)) {
  58. exit('Invalid Request');
  59. }
  60. include_once B_ROOT.'./uc_client/lib/xml.class.php';
  61. $post = xml_unserialize(file_get_contents('php://input'));
  62. if(in_array($get['action'], array('test', 'deleteuser', 'renameuser', 'gettag', 'synlogin', 'synlogout', 'updatepw', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcreditsettings', 'updatecreditsettings', 'addfeed'))) {
  63. $uc_note = new uc_note();
  64. echo $uc_note->$get['action']($get, $post);
  65. exit();
  66. } else {
  67. exit(API_RETURN_FAILED);
  68. }
  69. }
  70. class uc_note {
  71. var $dbconfig = '';
  72. var $db = '';
  73. var $tablepre = '';
  74. var $appdir = '';
  75. function _serialize($arr, $htmlon = 0) {
  76. if(!function_exists('xml_serialize')) {
  77. include_once B_ROOT.'./uc_client/lib/xml.class.php';
  78. }
  79. return xml_serialize($arr, $htmlon);
  80. }
  81. function uc_note() {
  82. global $_G, $_SGLOBAL, $_SC;
  83. $this->appdir = substr(dirname(__FILE__), 0, -3);
  84. $this->dbconfig = B_ROOT.'./config.php';
  85. //$this->db = $_SGLOBAL['db'];
  86. $this->tablepre = $_SC['tablepre'];
  87. }
  88. function test($get, $post) {
  89. return API_RETURN_SUCCEED;
  90. }
  91. function deleteuser($get, $post) {
  92. global $_G, $_SGLOBAL;
  93. if(!API_DELETEUSER) {
  94. return API_RETURN_FORBIDDEN;
  95. }
  96. //note 用戶刪除 API 接口
  97. include_once B_ROOT.'./source/function/admin.func.php';
  98. //獲得用戶
  99. $uids = $get['ids'];
  100. $query = DB::query("SELECT uid FROM ".tname('members')." WHERE uid IN ($uids)");
  101. while ($value = DB::fetch($query)) {
  102. deletespace($value['uid']);
  103. }
  104. return API_RETURN_SUCCEED;
  105. }
  106. function renameuser($get, $post) {
  107. global $_G, $_SGLOBAL;
  108. if(!API_RENAMEUSER) {
  109. return API_RETURN_FORBIDDEN;
  110. }
  111. //編輯用戶
  112. $old_username = $get['oldusername'];
  113. $new_username = $get['newusername'];
  114. DB::query("UPDATE ".tname('members')." SET username='$new_username' WHERE username='$old_username'");
  115. return API_RETURN_SUCCEED;
  116. }
  117. function gettag($get, $post) {
  118. global $_G, $_SGLOBAL;
  119. if(!API_GETTAG) {
  120. return API_RETURN_FORBIDDEN;
  121. }
  122. return API_RETURN_SUCCEED;
  123. }
  124. function synlogin($get, $post) {
  125. global $_G, $_SGLOBAL;
  126. if(!API_SYNLOGIN) {
  127. return API_RETURN_FORBIDDEN;
  128. }
  129. //note 同步登錄 API 接口
  130. obclean();
  131. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  132. $uid = intval($get['uid']);
  133. $cookietime = 2592000;
  134. $ss_auth_key = md5($_G['setting']['sitekey'].$_SERVER['HTTP_USER_AGENT']);
  135. include_once(B_ROOT.'./source/class/db_mysql.class.php');
  136. //鏈接數據庫
  137. dbconnect();
  138. $query = DB::query("SELECT * FROM ".tname('members')." WHERE uid='$uid'");
  139. if($member = DB::fetch($query)) {
  140. ssetcookie('sid', '', 86400 * 365);
  141. ssetcookie('cookietime', $cookietime, 31536000);
  142. ssetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime, 1, true);
  143. } else {
  144. ssetcookie('cookietime', $cookietime, 31536000);
  145. ssetcookie('loginuser', $get['username'], $cookietime);
  146. ssetcookie('activationauth', authcode($get['username'], 'ENCODE'), $cookietime);
  147. }
  148. }
  149. function synlogout($get, $post) {
  150. global $_G, $_SGLOBAL;
  151. if(!API_SYNLOGOUT) {
  152. return API_RETURN_FORBIDDEN;
  153. }
  154. //note 同步登出 API 接口
  155. obclean();
  156. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  157. ssetcookie('auth', '', -86400 * 365);
  158. ssetcookie('sid', '', -86400 * 365);
  159. ssetcookie('loginuser', '', -86400 * 365);
  160. ssetcookie('activationauth', '', -86400 * 365);
  161. }
  162. function updatepw($get, $post) {
  163. global $_G, $_SGLOBAL;
  164. if(!API_UPDATEPW) {
  165. return API_RETURN_FORBIDDEN;
  166. }
  167. //note 同步登出 API 接口
  168. obclean();
  169. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  170. ssetcookie('auth', '', -86400 * 365);
  171. ssetcookie('sid', '', -86400 * 365);
  172. ssetcookie('loginuser', '', -86400 * 365);
  173. ssetcookie('activationauth', '', -86400 * 365);
  174. return API_RETURN_SUCCEED;
  175. }
  176. function updatebadwords($get, $post) {
  177. global $_G, $_SGLOBAL;
  178. if(!API_UPDATEBADWORDS) {
  179. return API_RETURN_FORBIDDEN;
  180. }
  181. $cachefile = UC_CLIENT_ROOT.'./data/cache/badwords.php';
  182. $fp = fopen($cachefile, 'w');
  183. $s = "<?php\r\n";
  184. $s .= '$_CACHE[\'badwords\'] = '.var_export($post, true).";\r\n";
  185. fwrite($fp, $s);
  186. fclose($fp);
  187. return API_RETURN_SUCCEED;
  188. }
  189. function updatehosts($get, $post) {
  190. global $_G, $_SGLOBAL;
  191. if(!API_UPDATEHOSTS) {
  192. return API_RETURN_FORBIDDEN;
  193. }
  194. $cachefile = B_ROOT.'./uc_client/data/cache/hosts.php';
  195. $fp = fopen($cachefile, 'w');
  196. $s = "<?php\r\n";
  197. $s .= '$_CACHE[\'hosts\'] = '.var_export($post, true).";\r\n";
  198. fwrite($fp, $s);
  199. fclose($fp);
  200. return API_RETURN_SUCCEED;
  201. }
  202. function updateapps($get, $post) {
  203. global $_G, $_SGLOBAL;
  204. if(!API_UPDATEAPPS) {
  205. return API_RETURN_FORBIDDEN;
  206. }
  207. $UC_API = '';
  208. if($post['UC_API']) {
  209. $UC_API = $post['UC_API'];
  210. unset($post['UC_API']);
  211. }
  212. $cachefile = B_ROOT.'./uc_client/data/cache/apps.php';
  213. $fp = fopen($cachefile, 'w');
  214. $s = "<?php\r\n";
  215. $s .= '$_CACHE[\'apps\'] = '.var_export($post, true).";\r\n";
  216. fwrite($fp, $s);
  217. fclose($fp);
  218. //配置文件
  219. if($UC_API && is_writeable(B_ROOT.'./config.php')) {
  220. $configfile = trim(file_get_contents(B_ROOT.'./config.php'));
  221. $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
  222. $configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '$UC_API');", $configfile);
  223. if($fp = @fopen(B_ROOT.'./config.php', 'w')) {
  224. @fwrite($fp, trim($configfile));
  225. @fclose($fp);
  226. }
  227. }
  228. return API_RETURN_SUCCEED;
  229. }
  230. function updateclient($get, $post) {
  231. global $_G, $_SGLOBAL;
  232. if(!API_UPDATECLIENT) {
  233. return API_RETURN_FORBIDDEN;
  234. }
  235. $cachefile = B_ROOT.'./uc_client/data/cache/settings.php';
  236. $fp = fopen($cachefile, 'w');
  237. $s = "<?php\r\n";
  238. $s .= '$_CACHE[\'settings\'] = '.var_export($post, true).";\r\n";
  239. fwrite($fp, $s);
  240. fclose($fp);
  241. return API_RETURN_SUCCEED;
  242. }
  243. function updatecredit($get, $post) {
  244. global $_G, $_SGLOBAL;
  245. if(!API_UPDATECREDIT) {
  246. return API_RETURN_FORBIDDEN;
  247. }
  248. $amount = $get['amount'];
  249. $uid = intval($get['uid']);
  250. DB::query("UPDATE ".tname('members')." SET credit=credit+'$amount' WHERE uid='$uid'");
  251. return API_RETURN_SUCCEED;
  252. }
  253. function getcredit($get, $post) {
  254. global $_G, $_SGLOBAL;
  255. if(!API_GETCREDIT) {
  256. return API_RETURN_FORBIDDEN;
  257. }
  258. $uid = intval($get['uid']);
  259. $credit = getcount('members', array('uid'=>$uid), 'credit');
  260. return $credit;
  261. }
  262. function getcreditsettings($get, $post) {
  263. global $_G, $_SGLOBAL, $lang;
  264. if(!API_GETCREDITSETTINGS) {
  265. return API_RETURN_FORBIDDEN;
  266. }
  267. $credits = array();
  268. $credits[1] = array($lang['credit'], $lang['credit_unit']);
  269. return $this->_serialize($credits);
  270. }
  271. function updatecreditsettings($get, $post) {
  272. global $_G, $_SGLOBAL;
  273. if(!API_UPDATECREDITSETTINGS) {
  274. return API_RETURN_FORBIDDEN;
  275. }
  276. $outextcredits = array();
  277. foreach($get['credit'] as $appid => $credititems) {
  278. if($appid == UC_APPID) {
  279. foreach($credititems as $value) {
  280. $outextcredits[$value['appiddesc'].'|'.$value['creditdesc']] = array(
  281. 'creditsrc' => $value['creditsrc'],
  282. 'title' => $value['title'],
  283. 'unit' => $value['unit'],
  284. 'ratio' => $value['ratio']
  285. );
  286. }
  287. }
  288. }
  289. $cachefile = B_ROOT.'./uc_client/data/cache/creditsettings.php';
  290. $fp = fopen($cachefile, 'w');
  291. $s = "<?php\r\n";
  292. $s .= '$_CACHE[\'creditsettings\'] = '.arrayeval($outextcredits).";\r\n";
  293. fwrite($fp, $s);
  294. fclose($fp);
  295. return API_RETURN_SUCCEED;
  296. }
  297. function addfeed($get, $post) {
  298. global $_G, $_SGLOBAL;
  299. if(!API_ADDFEED) {
  300. return API_RETURN_FORBIDDEN;
  301. }
  302. return API_RETURN_SUCCEED;
  303. }
  304. }
  305. ?>