Rev 1148 | Rev 1150 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1148 | Rev 1149 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | use ViaThinkSoft\OIDplus\OIDplus; |
20 | use ViaThinkSoft\OIDplus\OIDplus; |
- | 21 | use ViaThinkSoft\OIDplus\OIDplusException; |
|
21 | 22 | ||
22 | /** |
23 | /** |
23 | * @param string $privKey |
24 | * @param string $privKey |
24 | * @return bool |
25 | * @return bool |
25 | */ |
26 | */ |
Line 330... | Line 331... | ||
330 | return \bb\Sha3\Sha3::hash_pbkdf2($password, $salt, $iterations, 512, $length, $binary); |
331 | return \bb\Sha3\Sha3::hash_pbkdf2($password, $salt, $iterations, 512, $length, $binary); |
331 | } |
332 | } |
332 | } |
333 | } |
333 | 334 | ||
334 | /** |
335 | /** |
- | 336 | * @return bool |
|
- | 337 | */ |
|
- | 338 | function url_post_contents_available(): bool { |
|
- | 339 | return function_exists('curl_init'); |
|
- | 340 | } |
|
- | 341 | ||
- | 342 | /** |
|
335 | * @param string $url |
343 | * @param string $url |
- | 344 | * @param array $params |
|
- | 345 | * @param array $extraHeaders |
|
336 | * @param string $userAgent |
346 | * @param string $userAgent |
337 | * @return string|false |
347 | * @return string|false |
- | 348 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
|
338 | */ |
349 | */ |
- | 350 | function url_post_contents(string $url, array $params=array(), array $extraHeaders=array(), string $userAgent='ViaThinkSoft-OIDplus/2.0') { |
|
- | 351 | $postFields = http_build_query($params); |
|
- | 352 | ||
- | 353 | $headers = array( |
|
- | 354 | "User-Agent: $userAgent", |
|
- | 355 | "Content-Length: ".strlen($postFields) |
|
- | 356 | ); |
|
- | 357 | ||
- | 358 | foreach ($extraHeaders as $name => $val) { |
|
- | 359 | $headers[] = "$name: $val"; |
|
- | 360 | } |
|
- | 361 | ||
- | 362 | if (function_exists('curl_init')) { |
|
- | 363 | $ch = curl_init(); |
|
- | 364 | if (class_exists(OIDplus::class)) { |
|
- | 365 | if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::localpath() . 'vendor/cacert.pem'); |
|
- | 366 | } |
|
- | 367 | curl_setopt($ch, CURLOPT_URL, $url); |
|
- | 368 | curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); |
|
- | 369 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
- | 370 | curl_setopt($ch, CURLOPT_POST, true); |
|
- | 371 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); |
|
- | 372 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
- | 373 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
- | 374 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
|
- | 375 | $res = @curl_exec($ch); |
|
- | 376 | $error_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
- | 377 | @curl_close($ch); |
|
- | 378 | if ($error_code >= 400) return false; |
|
- | 379 | if ($res === false) return false; |
|
- | 380 | } else { |
|
- | 381 | throw new OIDplusException(_L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl')); |
|
- | 382 | } |
|
- | 383 | return $res; |
|
- | 384 | } |
|
- | 385 | ||
- | 386 | /** |
|
- | 387 | * @param string $url |
|
- | 388 | * @param array $extraHeaders |
|
- | 389 | * @param string $userAgent |
|
- | 390 | * @return string|false |
|
- | 391 | */ |
|
339 | function url_get_contents(string $url, string $userAgent='ViaThinkSoft-OIDplus/2.0') { |
392 | function url_get_contents(string $url, array $extraHeaders=array(), string $userAgent='ViaThinkSoft-OIDplus/2.0') { |
- | 393 | $headers = array("User-Agent: $userAgent"); |
|
- | 394 | foreach ($extraHeaders as $name => $val) { |
|
- | 395 | $headers[] = "$name: $val"; |
|
- | 396 | } |
|
340 | if (function_exists('curl_init')) { |
397 | if (function_exists('curl_init')) { |
341 | $ch = curl_init(); |
398 | $ch = curl_init(); |
342 | if (class_exists(OIDplus::class)) { |
399 | if (class_exists(OIDplus::class)) { |
343 | if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::localpath() . 'vendor/cacert.pem'); |
400 | if (ini_get('curl.cainfo') == '') curl_setopt($ch, CURLOPT_CAINFO, OIDplus::localpath() . 'vendor/cacert.pem'); |
344 | } |
401 | } |
345 | curl_setopt($ch, CURLOPT_URL, $url); |
402 | curl_setopt($ch, CURLOPT_URL, $url); |
346 | curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); |
403 | curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); |
- | 404 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
347 | curl_setopt($ch, CURLOPT_POST, 0); |
405 | curl_setopt($ch, CURLOPT_POST, false); |
348 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
406 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
349 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
407 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
350 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
408 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
351 | $res = @curl_exec($ch); |
409 | $res = @curl_exec($ch); |
352 | $error_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); |
410 | $error_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); |
Line 357... | Line 415... | ||
357 | // Attention: HTTPS only works if OpenSSL extension is enabled. |
415 | // Attention: HTTPS only works if OpenSSL extension is enabled. |
358 | // Our supplement does not help... |
416 | // Our supplement does not help... |
359 | $opts = [ |
417 | $opts = [ |
360 | "http" => [ |
418 | "http" => [ |
361 | "method" => "GET", |
419 | "method" => "GET", |
362 | "header" => "User-Agent: $userAgent\r\n" |
420 | "header" => implode("\r\n",$headers)."\r\n" |
363 | ] |
421 | ] |
364 | ]; |
422 | ]; |
365 | $context = stream_context_create($opts); |
423 | $context = stream_context_create($opts); |
366 | $res = @file_get_contents($url, false, $context); |
424 | $res = @file_get_contents($url, false, $context); |
367 | if ($res === false) return false; |
425 | if ($res === false) return false; |