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