ws_session_user.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * A script to test session details by user web service.
  6. */
  7. require_once __DIR__.'/../config.php';
  8. api_protect_admin_script();
  9. // exit;
  10. $plugin = AdvancedSubscriptionPlugin::create();
  11. $hookPlugin = Container::instantiateHook(HookAdvancedSubscription::class);
  12. // Get params from request (GET or POST)
  13. $params = [];
  14. // Init result array
  15. $params['user_id'] = intval($_REQUEST['u']);
  16. $params['user_field'] = 'drupal_user_id';
  17. $params['session_id'] = intval($_REQUEST['s']);
  18. $params['profile_completed'] = 100;
  19. $params['is_connected'] = true;
  20. /**
  21. * Copied code from WSHelperVerifyKey function.
  22. */
  23. /**
  24. * Start WSHelperVerifyKey.
  25. */
  26. //error_log(print_r($params,1));
  27. $check_ip = false;
  28. $ip = trim($_SERVER['REMOTE_ADDR']);
  29. // if we are behind a reverse proxy, assume it will send the
  30. // HTTP_X_FORWARDED_FOR header and use this IP instead
  31. if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  32. list($ip1, $ip2) = split(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  33. $ip = trim($ip1);
  34. }
  35. // Check if a file that limits access from webservices exists and contains
  36. // the restraining check
  37. if (is_file(api_get_path(WEB_CODE_PATH).'webservices/webservice-auth-ip.conf.php')) {
  38. include api_get_path(WEB_CODE_PATH).'webservices/webservice-auth-ip.conf.php';
  39. if (!empty($ws_auth_ip)) {
  40. $check_ip = true;
  41. }
  42. }
  43. global $_configuration;
  44. if ($check_ip) {
  45. $security_key = $_configuration['security_key'];
  46. } else {
  47. $security_key = $ip.$_configuration['security_key'];
  48. //error_log($secret_key.'-'.$security_key);
  49. }
  50. /**
  51. * End WSHelperVerifyKey.
  52. */
  53. $params['secret_key'] = sha1($security_key);
  54. // Registration soap wsdl
  55. $wsUrl = api_get_path(WEB_CODE_PATH).'webservices/registration.soap.php?wsdl';
  56. $options = [
  57. 'location' => $wsUrl,
  58. 'uri' => $wsUrl,
  59. ];
  60. /**
  61. * WS test.
  62. */
  63. try {
  64. // Init soap client
  65. $client = new SoapClient(null, $options);
  66. // Soap call to WS
  67. $result = $client->__soapCall('HookAdvancedSubscription..WSSessionGetDetailsByUser', [$params]);
  68. if (is_object($result) && isset($result->action_url)) {
  69. echo '<br />';
  70. echo Display::url("message".$result->message, $result->action_url);
  71. }
  72. } catch (\Exception $e) {
  73. var_dump($e);
  74. }