ws_session_user.php 2.3 KB

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