| @@ 43-93 (lines=51) @@ | ||
| 40 | * @param array $params |
|
| 41 | * @return bool |
|
| 42 | */ |
|
| 43 | function WSHelperVerifyKey($params) |
|
| 44 | { |
|
| 45 | global $_configuration, $debug; |
|
| 46 | if (is_array($params)) { |
|
| 47 | $secret_key = $params['secret_key']; |
|
| 48 | } else { |
|
| 49 | $secret_key = $params; |
|
| 50 | } |
|
| 51 | //error_log(print_r($params,1)); |
|
| 52 | $check_ip = false; |
|
| 53 | $ip_matches = false; |
|
| 54 | $ip = trim($_SERVER['REMOTE_ADDR']); |
|
| 55 | // if we are behind a reverse proxy, assume it will send the |
|
| 56 | // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
| 57 | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 58 | list($ip1, $ip2) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
| 59 | $ip = trim($ip1); |
|
| 60 | } |
|
| 61 | if ($debug) |
|
| 62 | error_log("ip: $ip"); |
|
| 63 | // Check if a file that limits access from webservices exists and contains |
|
| 64 | // the restraining check |
|
| 65 | if (is_file('webservice-auth-ip.conf.php')) { |
|
| 66 | include 'webservice-auth-ip.conf.php'; |
|
| 67 | if ($debug) |
|
| 68 | error_log("webservice-auth-ip.conf.php file included"); |
|
| 69 | if (!empty($ws_auth_ip)) { |
|
| 70 | $check_ip = true; |
|
| 71 | $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip); |
|
| 72 | if ($debug) |
|
| 73 | error_log("ip_matches: $ip_matches"); |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||
| 77 | if ($debug) { |
|
| 78 | error_log("checkip " . intval($check_ip)); |
|
| 79 | } |
|
| 80 | ||
| 81 | if ($check_ip) { |
|
| 82 | $security_key = $_configuration['security_key']; |
|
| 83 | } else { |
|
| 84 | $security_key = $ip.$_configuration['security_key']; |
|
| 85 | //error_log($secret_key.'-'.$security_key); |
|
| 86 | } |
|
| 87 | ||
| 88 | $result = api_is_valid_secret_key($secret_key, $security_key); |
|
| 89 | //error_log($secret_key.'-'.$security_key); |
|
| 90 | if ($debug) |
|
| 91 | error_log('WSHelperVerifyKey result: '.intval($result)); |
|
| 92 | return $result; |
|
| 93 | } |
|
| 94 | ||
| 95 | // Create the server instance |
|
| 96 | $server = new soap_server(); |
|
| @@ 48-98 (lines=51) @@ | ||
| 45 | * @param array $params |
|
| 46 | * @return bool |
|
| 47 | */ |
|
| 48 | function WSHelperVerifyKey($params) |
|
| 49 | { |
|
| 50 | global $_configuration, $debug; |
|
| 51 | if (is_array($params)) { |
|
| 52 | $secret_key = $params['secret_key']; |
|
| 53 | } else { |
|
| 54 | $secret_key = $params; |
|
| 55 | } |
|
| 56 | //error_log(print_r($params,1)); |
|
| 57 | $check_ip = false; |
|
| 58 | $ip_matches = false; |
|
| 59 | $ip = trim($_SERVER['REMOTE_ADDR']); |
|
| 60 | // if we are behind a reverse proxy, assume it will send the |
|
| 61 | // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
| 62 | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 63 | list($ip1) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
| 64 | $ip = trim($ip1); |
|
| 65 | } |
|
| 66 | if ($debug) |
|
| 67 | error_log("ip: $ip"); |
|
| 68 | // Check if a file that limits access from webservices exists and contains |
|
| 69 | // the restraining check |
|
| 70 | if (is_file('webservice-auth-ip.conf.php')) { |
|
| 71 | include 'webservice-auth-ip.conf.php'; |
|
| 72 | if ($debug) |
|
| 73 | error_log("webservice-auth-ip.conf.php file included"); |
|
| 74 | if (!empty($ws_auth_ip)) { |
|
| 75 | $check_ip = true; |
|
| 76 | $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip); |
|
| 77 | if ($debug) |
|
| 78 | error_log("ip_matches: $ip_matches"); |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||
| 82 | if ($debug) { |
|
| 83 | error_log("checkip " . intval($check_ip)); |
|
| 84 | } |
|
| 85 | ||
| 86 | if ($check_ip) { |
|
| 87 | $security_key = $_configuration['security_key']; |
|
| 88 | } else { |
|
| 89 | $security_key = $ip.$_configuration['security_key']; |
|
| 90 | //error_log($secret_key.'-'.$security_key); |
|
| 91 | } |
|
| 92 | ||
| 93 | $result = api_is_valid_secret_key($secret_key, $security_key); |
|
| 94 | ||
| 95 | if ($debug) |
|
| 96 | error_log('WSHelperVerifyKey result: '.intval($result)); |
|
| 97 | return $result; |
|
| 98 | } |
|
| 99 | ||
| 100 | // Create the server instance |
|
| 101 | $server = new soap_server(); |
|