PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/b2b/core/assistant/api.php

http://phpfor.googlecode.com/
PHP | 187 lines | 172 code | 15 blank | 0 comment | 41 complexity | 49d7e2cfe6b64099aa076b46a28d7df2 MD5 | raw file
  1. <?php
  2. if (!defined('IN_ASSIS_SERVICE')) exit();
  3. require_once(CORE_DIR.'/func_ext.php');
  4. require_once(CORE_DIR.'/include/shopCore.php');
  5. class assisCore extends shopCore{
  6. function run(){}
  7. }
  8. $system = new assisCore(array());
  9. $GLOBALS['system'] = &$system;
  10. $GLOBALS['as_debug'] = false;
  11. if (!defined('DIRECTORY_SEPARATOR')) define('DIRECTORY_SEPARATOR', '/');
  12. define('AS_DIR', dirname(__FILE__));
  13. define('AS_SERVICE_DIR', AS_DIR.'/service/');
  14. define('AS_VALIDATOR_DIR', AS_DIR.'/validator/');
  15. define('AS_TMP_DIR', HOME_DIR.'/tmp/');
  16. define('AS_LOG_DIR', HOME_DIR.'/logs/');
  17. define('AS_SYNC_DELETED', -1);
  18. define('AS_SYNC_UNCHANGED', 0);
  19. define('AS_SYNC_ADDED', 1);
  20. define('AS_SYNC_MODIFIED', 2);
  21. define('DATABACK_DIR', HOME_DIR.'/backup/');
  22. define('AS_TOKEN_TIMEOUT', 30);
  23. $token = isset($_GET['token']) ? $_GET['token'] : '';
  24. $redirect = isset($_GET['redirect']) ? $_GET['redirect'] : '';
  25. if (!empty($redirect) && !empty($token)){
  26. $token_file = AS_TMP_DIR . 'astoken.php';
  27. if (file_exists($token_file)) include($token_file);
  28. if (isset($redirect_tokes) && is_array($redirect_tokes))
  29. {
  30. foreach ($redirect_tokes as $item){
  31. if ($item['token'] == $token && (time()-$item['time']) <= AS_TOKEN_TIMEOUT)
  32. {
  33. $db = $system->database();
  34. $aResult = $db->selectrow("select * from sdb_operators where status=1 and username=".$db->quote($item['user']));
  35. if ($aResult){
  36. $session = $system->loadModel('opSession');
  37. $session->start();
  38. unset($_SESSION["loginmsg"]);
  39. unset($_SESSION['_PageData']);
  40. unset($_SESSION['OPID']);
  41. unset($_SESSION['SUPER']);
  42. $profile = $system->loadModel('adminProfile');
  43. $profile->load($aResult['op_id']);
  44. $_SESSION['OPID'] = $aResult['op_id'];
  45. $_SESSION['SUPER'] = $aResult['super'];
  46. $_SESSION['profile'] = &$profile;
  47. $session->login();
  48. }
  49. }
  50. }
  51. }
  52. header('location:'.$redirect);
  53. exit();
  54. }
  55. require_once(AS_DIR.'/lib/LogUtils.php');
  56. require_once(AS_DIR.'/lib/GeneralFunc.php');
  57. require_once(AS_DIR.'/lib/nudime.php');
  58. require_once(AS_DIR.'/lib/ServerUtils.php');
  59. require_once(AS_DIR.'/lib/TextUtils.php');
  60. require_once(AS_DIR.'/lib/BaseService.php');
  61. require_once(AS_DIR.'/lib/BaseValidator.php');
  62. $server = new nusoapserverdime();
  63. $server->configureWSDL('shopexapiwsdl', 'urn:shopexapi');
  64. $server->wsdl->schemaTargetNamespace = 'urn:shopexapi';
  65. $server->charset = 'utf-8';
  66. $server->validate_factory = 'validate_soap';
  67. $GLOBALS['as_server'] = &$server;
  68. function validate_soap($clientid,&$body,$signature,$DigestMethod,$methodname,$DigestOpts)
  69. {
  70. if (@ini_get('magic_quotes_gpc')) $data = stripcslashes($data);
  71. $auth_method_list = array('cert', 'role');
  72. $auth_method = 'cert';
  73. $clintid_arr = split(':', $clientid);
  74. if (is_array($clintid_arr) && count($clintid_arr) > 1){
  75. $sMethod = strtolower($clintid_arr[0]);
  76. if (in_array($sMethod, $auth_method_list)) {
  77. $auth_method = $sMethod;
  78. array_shift($clintid_arr);
  79. }
  80. if( md5($clintid_arr[count($clintid_arr)-1]) == '2331b2ae67da3312f33dd4c79bd1c49a') {
  81. $GLOBALS['as_debug'] = true;
  82. array_pop($clintid_arr);
  83. }
  84. }
  85. LogUtils::log_str('start set sql_mode');
  86. $sys = &$GLOBALS['system'];
  87. $db = $sys->database();
  88. if ($db) $db->exec("set sql_mode=''");
  89. LogUtils::log_str('start auth:'.$auth_method);
  90. LogUtils::log_obj($clintid_arr);
  91. $auth_ret = false;
  92. switch($auth_method){
  93. case 'role':
  94. $rolename = $username = '';
  95. if (is_array($clintid_arr) && count($clintid_arr) > 1){
  96. $rolename = $clintid_arr[0];
  97. $username = $clintid_arr[1];
  98. }
  99. if (!empty($rolename) && !empty($username)){
  100. $auth_ret = auth_role($rolename,$username,$body,$signature,$DigestMethod,$methodname,$DigestOpts);
  101. }
  102. if (!$auth_ret) $GLOBALS['validate_signatrue_errmsg'] = '??????????????';
  103. break;
  104. case 'cert':
  105. if (is_array($clintid_arr) && count($clintid_arr) > 0){
  106. $clientid = $clintid_arr[0];
  107. }
  108. $auth_ret = auth_cert($clientid,$body,$signature,$DigestMethod,$methodname,$DigestOpts);
  109. if (!$auth_ret) $GLOBALS['validate_signatrue_errmsg'] = '?????????????ShopEx???';
  110. break;
  111. }
  112. LogUtils::log_str('auth ret:'.($auth_ret?'true':'false'));
  113. return $auth_ret;
  114. }
  115. function auth_cert($clientid,&$body,$signature,$DigestMethod,$methodname,$DigestOpts)
  116. {
  117. $sys = &$GLOBALS['system'];
  118. $certs = $sys->loadModel('service/certificate');
  119. if ($certs && ($clientid == $certs->getCerti()) )
  120. {
  121. if (strtolower($DigestMethod) == "md5")
  122. return md5($body.$certs->getToken()) == $signature;
  123. }
  124. return true;
  125. return false;
  126. }
  127. function auth_role($rolename,$username,&$body,$signature,$DigestMethod,$methodname,$DigestOpts)
  128. {
  129. $sys = &$GLOBALS['system'];
  130. $rolename = strtoupper($rolename);
  131. $role_list = array(
  132. 'ASR_DOWNLOADER' => array('GetVersion','Login','GetPartView','GetShopInfo','GetFileSize','DownloadFile','GetRecordCount','DownloadRecord')
  133. );
  134. LogUtils::log_str('methodname:'.$methodname);
  135. if (array_key_exists($rolename,$role_list) && in_array($methodname, $role_list[$rolename])){
  136. $db = $sys->database();
  137. $sql = "SELECT op.userpass FROM sdb_lnk_roles lr
  138. inner join sdb_operators op on lr.op_id=op.op_id
  139. inner join sdb_admin_roles r on lr.role_id=r.role_id
  140. where op.disabled='false' and op.status=1 and r.disabled='false' and
  141. r.role_name=".$db->quote($rolename)." and op.username=".$db->quote($username);
  142. LogUtils::log_str($sql);
  143. $row = $db->selectrow($sql);
  144. if ($row)
  145. {
  146. if (strtolower($DigestMethod) == "md5")
  147. return md5($body.strtolower($row['userpass'])) == $signature;
  148. }
  149. }
  150. return false;
  151. }
  152. foreach (as_find_files(AS_SERVICE_DIR, '/service.([a-zA-Z0-9_]*).php/') as $file => $matches)
  153. {
  154. include_once(AS_SERVICE_DIR.$file);
  155. $clsname = $matches[1].'Service';
  156. if (class_exists($clsname))
  157. {
  158. $cls = new $clsname();
  159. if (is_a($cls, 'BaseService'))
  160. {
  161. $cls->init($server);
  162. }
  163. }
  164. }
  165. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  166. if (empty($HTTP_RAW_POST_DATA)){
  167. $fp = fopen("php://input",'rb');
  168. while(!feof($fp)) $HTTP_RAW_POST_DATA .= fread($fp,4096);
  169. fclose($fp);
  170. }
  171. $server->service($HTTP_RAW_POST_DATA);
  172. ?>