PageRenderTime 36ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/api/uc.php

http://phpfor.googlecode.com/
PHP | 306 lines | 225 code | 66 blank | 15 comment | 42 complexity | 30a726e06c7ed720dde45f1e8abd33c7 MD5 | raw file
  1. <?php
  2. define('UC_VERSION', '1.0.0'); //UCenter ????
  3. define('API_DELETEUSER', 1); //???? API ????
  4. define('API_RENAMEUSER', 1); //???? API ????
  5. define('API_UPDATEPW', 1); //????? API ????
  6. define('API_GETTAG', 1); //???? API ????
  7. define('API_SYNLOGIN', 1); //???? API ????
  8. define('API_SYNLOGOUT', 1); //???? API ????
  9. define('API_UPDATEBADWORDS', 0); //??????? ??
  10. define('API_UPDATEHOSTS', 0); //???????? ??
  11. define('API_UPDATEAPPS', 0); //?????? ??
  12. define('API_UPDATECLIENT', 1); //??????? ??
  13. define('API_UPDATECREDIT', 1); //?????? ??
  14. define('API_GETCREDITSETTINGS', 1); //? UCenter ?????? ??
  15. define('API_UPDATECREDITSETTINGS', 1); //???????? ??
  16. define('API_RETURN_SUCCEED', '1');
  17. define('API_RETURN_FAILED', '-1');
  18. define('API_RETURN_FORBIDDEN', '-2');
  19. ob_start();
  20. define('PHP_SELF',dirname($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']));
  21. if(include(dirname(__FILE__).'/../config/config.php')){
  22. ob_end_clean();
  23. if(!defined('CORE_INCLUDE_DIR')){
  24. define('CORE_INCLUDE_DIR',CORE_DIR.
  25. ((!defined('SHOP_DEVELOPER') || !constant('SHOP_DEVELOPER')) && version_compare(PHP_VERSION,'5.0','>=')?'/include_v5':'/include'));
  26. }
  27. require(CORE_DIR.'/kernel.php');
  28. require(CORE_INCLUDE_DIR.'/shopCore.php');
  29. require_once(CORE_DIR.'/func_ext.php');
  30. require(CORE_DIR.'/lib/uc_client/lib/xml.class.php');
  31. class ucCore extends shopCore{
  32. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  33. $ckey_length = 4;
  34. $key = md5($key ? $key : UC_KEY);
  35. $keya = md5(substr($key, 0, 16));
  36. $keyb = md5(substr($key, 16, 16));
  37. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
  38. $cryptkey = $keya.md5($keya.$keyc);
  39. $key_length = strlen($cryptkey);
  40. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  41. $string_length = strlen($string);
  42. $result = '';
  43. $box = range(0, 255);
  44. $rndkey = array();
  45. for($i = 0; $i <= 255; $i++) {
  46. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  47. }
  48. for($j = $i = 0; $i < 256; $i++) {
  49. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  50. $tmp = $box[$i];
  51. $box[$i] = $box[$j];
  52. $box[$j] = $tmp;
  53. }
  54. for($a = $j = $i = 0; $i < $string_length; $i++) {
  55. $a = ($a + 1) % 256;
  56. $j = ($j + $box[$a]) % 256;
  57. $tmp = $box[$a];
  58. $box[$a] = $box[$j];
  59. $box[$j] = $tmp;
  60. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  61. }
  62. if($operation == 'DECODE') {
  63. if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
  64. return substr($result, 26);
  65. } else {
  66. return '';
  67. }
  68. } else {
  69. return $keyc.str_replace('=', '', base64_encode($result));
  70. }
  71. }
  72. function dsetcookie($var, $value, $life = 0, $prefix = 1) {
  73. global $cookiedomain, $cookiepath, $timestamp, $_SERVER;
  74. setcookie($var, $value,
  75. $life ? $timestamp + $life : 0, $cookiepath,
  76. $cookiedomain, $_SERVER['SERVER_PORT'] == 443 ? 1 : 0);
  77. }
  78. function dstripslashes($string) {
  79. if(is_array($string)) {
  80. foreach($string as $key => $val) {
  81. $string[$key] = $this->dstripslashes($val);
  82. }
  83. } else {
  84. $string = stripslashes($string);
  85. }
  86. return $string;
  87. }
  88. function uc_serialize($arr, $htmlon = 0) {
  89. return xml_serialize($arr, $htmlon);
  90. }
  91. // function uc_unserialize($s) {
  92. // include_once UC_CLIENT_ROOT.'./lib/xml.class.php';
  93. // return xml_unserialize($s);
  94. // }
  95. function run(){
  96. $this->definevar();
  97. require_once(CORE_DIR.'/lib/uc_client/client.php');
  98. $code = $_GET['code'];
  99. parse_str($this->authcode($code, 'DECODE', UC_KEY), $get);
  100. if(MAGIC_QUOTES_GPC) {
  101. $get = $this->dstripslashes($get);
  102. }
  103. if(time() - $get['time'] > 3600) {
  104. exit('Authracation has expiried');
  105. }
  106. if(empty($get)) {
  107. exit('Invalid Request');
  108. }
  109. $action = $get['action'];
  110. $timestamp = time();
  111. $method = 'action_'.$action;
  112. if(method_exists($this,$method)){
  113. $this->$method($get);
  114. }else{
  115. exit(API_RETURN_FAILED);
  116. }
  117. }
  118. function action_test(){
  119. exit(API_RETURN_SUCCEED);
  120. }
  121. function action_deleteuser($get=''){
  122. !API_DELETEUSER && exit(API_RETURN_FORBIDDEN);
  123. //???? API ??
  124. $account = $this->loadModel('member/account');
  125. $account->PlugUserDelete($get['ids']);
  126. exit(API_RETURN_SUCCEED);
  127. }
  128. function action_renameuser() {
  129. !API_RENAMEUSER && exit(API_RETURN_FORBIDDEN);
  130. //???? API ??
  131. $uid = $get['uid'];
  132. $usernamenew = $get['newusername'];
  133. $db->query("UPDATE {$tablepre}members SET username='$usernamenew' WHERE uid='$uid'");
  134. exit(API_RETURN_SUCCEED);
  135. }
  136. function action_updatepw($get='') {
  137. !API_UPDATEPW && exit(API_RETURN_FORBIDDEN);
  138. //??????
  139. exit(API_RETURN_SUCCEED);
  140. }
  141. function action_gettag() {
  142. !API_GETTAG && exit(API_RETURN_FORBIDDEN);
  143. //???? API ??
  144. $return = array($name, array());
  145. echo $this->uc_serialize($return, 1);
  146. }
  147. function action_synlogin($get='') {
  148. if(time() - $get['time']<=3600){
  149. !API_SYNLOGIN && exit(API_RETURN_FORBIDDEN);
  150. $account = $this->loadModel('member/account');
  151. $o=$this->loadModel('utility/charset');
  152. if (strtoupper(UC_DBCHARSET)<>"UTF8")
  153. $get['username'] = $o->local2utf($get['username'],'zh');
  154. if ($data=uc_get_user($get['username'])){
  155. list($uid, $uname, $email) = $data;
  156. }
  157. $account->PlugUserRegist('',$get['uid'],$get['username'],$get['password'],$email);
  158. }else{
  159. exit(API_RETURN_FAILED);
  160. }
  161. }
  162. function action_synlogout() {
  163. !API_SYNLOGOUT && exit(API_RETURN_FORBIDDEN);
  164. $account = $this->loadModel('member/account');
  165. $account->PlugUserExit();
  166. }
  167. function action_updatebadwords() {
  168. !API_UPDATEBADWORDS && exit(API_RETURN_FORBIDDEN);
  169. //???????
  170. exit(API_RETURN_SUCCEED);
  171. }
  172. function action_updatehosts() {
  173. !API_UPDATEHOSTS && exit(API_RETURN_FORBIDDEN);
  174. //??HOST??
  175. exit(API_RETURN_SUCCEED);
  176. }
  177. function action_updateapps() {
  178. !API_UPDATEAPPS && exit(API_RETURN_FORBIDDEN);
  179. //??????
  180. exit(API_RETURN_SUCCEED);
  181. }
  182. function action_updateclient() {
  183. !API_UPDATECLIENT && exit(API_RETURN_FORBIDDEN);
  184. $post = xml_unserialize(file_get_contents('php://input'));
  185. $cachefile = CORE_DIR . '/lib/uc_client/data/cache/settings.php';
  186. $fp = fopen($cachefile, 'w');
  187. $s = "<?php\r\n";
  188. $s .= '$_CACHE[\'settings\'] = '.var_export($post, TRUE).";\r\n";
  189. fwrite($fp, $s);
  190. fclose($fp);
  191. //???????
  192. exit(API_RETURN_SUCCEED);
  193. }
  194. function action_updatecredit() {
  195. !UPDATECREDIT && exit(API_RETURN_FORBIDDEN);
  196. //??????
  197. exit(API_RETURN_SUCCEED);
  198. }
  199. function action_getcreditsettings() {
  200. !GETCREDITSETTINGS && exit(API_RETURN_FORBIDDEN);
  201. //? UCenter ??????
  202. echo $this->uc_serialize($credits);
  203. }
  204. function action_updatecreditsettings() {
  205. !API_UPDATECREDITSETTINGS && exit(API_RETURN_FORBIDDEN);
  206. //????????
  207. exit(API_RETURN_SUCCEED);
  208. }
  209. function definevar(){
  210. $passport = $this->loadModel('member/passport');
  211. $data = $passport->getOptions('ucenter');
  212. define('UC_CONNECT', 'mysql');
  213. define('UC_DBHOST', $data['ucserver']['value']);
  214. define('UC_DBUSER', $data['ucdbuser']['value']);
  215. define('UC_DBPW', $data['ucdbpass']['value']);
  216. define('UC_DBNAME', $data['ucdbname']['value']);
  217. define('UC_DBCHARSET', $data['ucdbcharset']['value']);
  218. define('UC_DBTABLEPRE', '`'.$data['ucdbname']['value'].'`.'.$data['ucprefix']['value']);
  219. define('UC_DBCONNECT', 0);
  220. define('UC_KEY', $data['uckey']['value']);
  221. define('UC_API', $data['ucapi']['value']);
  222. define('UC_CHARSET', $data['encoding']['value']);
  223. $tmp=parse_url($data['ucapi']['value']);
  224. if (preg_match('/([0-9]{1,3}\.){3}/',$tmp['host'])){
  225. define('UC_IP', $data['ucserver']['value']);
  226. }
  227. else{
  228. define('UC_IP', gethostbyname($data['ucserver']['value']));
  229. }
  230. define('UC_APPID', $data['ucserver']['value']);
  231. define('UC_PPP', $data['ucserver']['value']);
  232. }
  233. }
  234. $system = new ucCore(array());
  235. $system->run();
  236. }else{
  237. header('HTTP/1.1 503 Service Unavailable',true,503);
  238. die('<h1>Service Unavailable</h1>');
  239. }
  240. ?>