Скрипт с curl возвращает 400, только если вызов формируется с одного сервера и показывает HTTP / 1.1 вместо HTTP / 1.0 - PullRequest
0 голосов
/ 06 мая 2020

Я использую сценарий, который работает на всех серверах, но не работает на одном сервере.

код

flush();

$cookiePath = __DIR__ . "/". "log1in.txt";

//get url admin
$urlAdmin = 'http://smt5presta17.xxxxxxxx.com/Backoffice';

//url to log in
$url = $urlAdmin . "/index.php?controller=AdminLogin&submitLogin=1&login";
$user = 'aris@wwwwwwww.com';
$password = 'smt1234*';

$credentialsquery = "email=$user&passwd=$password";

// Get token

//init request
$request = curl_init();

//configure request
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_HEADER, 1);
curl_setopt($request, CURLOPT_COOKIEJAR, $cookiePath);
curl_setopt($request, CURLOPT_COOKIEFILE, $cookiePath);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($request, CURLOPT_NOBODY, true);

//auth config
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $credentialsquery);

//me logueo
$login = curl_exec($request);

$info = curl_getinfo($request);
curl_close($request);


// Debug log
$fp = fopen(dirname(__FILE__).'/'.'errorlog.txt', 'w');

// Check login
$request = curl_init();
curl_setopt($request, CURLOPT_VERBOSE, true);
curl_setopt($request, CURLOPT_STDERR, $fp);
curl_setopt($request, CURLOPT_URL, $urlAdmin.'/index.php?controller=AdminDashboard');
curl_setopt($request, CURLOPT_HEADER, 1);
curl_setopt($request, CURLOPT_COOKIEJAR, $cookiePath);
curl_setopt($request, CURLOPT_COOKIEFILE, $cookiePath);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($request, CURLOPT_POST, true);
$final = curl_exec($request);

print_r($final);

$resulOk = strpos($final,'/index.php?controller=AdminDashboard') > -1;

echo "<br>Resultado:".$resulOk;

Журналы при вызове с плохого сервера

==> /var/www/vhosts/system/smt5presta17.xxxxxxxxxxx.com/logs/access_log <==
51.91.xxx.197 - - [06/May/2020:20:26:17 +0200] "POST /Backoffice/index.php?controller=AdminLogin&submitLogin=1&login HTTP/1.0" 302 1182 "-" "-"
51.91.xxx.197 - - [06/May/2020:20:26:18 +0200] "GET /Backoffice/index.php?controller=AdminDashboard&token=7be2eebd06506b142d587ae76224d475 HTTP/1.0" 200 118041 "-" "-"

==> /var/www/vhosts/system/smt5presta17.xxxxxxxxxxx.com/logs/proxy_access_log <==
51.91.xxx.197 - - [06/May/2020:20:26:19 +0200] "POST /Backoffice/index.php?controller=AdminDashboard HTTP/1.1" 400 166 "-" "-"

Регистрировать, когда правильно

==> /var/www/vhosts/system/smt5presta17.xxxxxxxxxxx.com/logs/access_log <==
83.44.182.xxx - - [06/May/2020:20:31:06 +0200] "POST /Backoffice/index.php?controller=AdminLogin&submitLogin=1&login HTTP/1.0" 302 1150 "-" "-"
83.44.182.xxx - - [06/May/2020:20:31:07 +0200] "GET /Backoffice/index.php?controller=AdminDashboard&token=7be2eebd06506b142d587ae76224d475 HTTP/1.0" 200 118343 "-" "-"
83.44.182.xxx - - [06/May/2020:20:31:09 +0200] "POST /Backoffice/index.php?controller=AdminDashboard HTTP/1.0" 200 118276 "-" "-"

Debug curl

> POST /Backoffice/index.php?controller=AdminDashboard HTTP/1.1
Host: smt5presta17.xxxxxxx.com
Accept: */*
Cookie: PHPSESSID=9fhoru7pke9iqweqpjeu4m3d0t; PrestaShop-23cfc83dfb58asdadadsdasdf=def502003b3284a03be865ea5a078373a995c11976a367cabbe3f0e7ddc5d7cbaa8a4661247d1ccbac24275079ff72561fa28996a0dcca0c77e477ef3ee86a0f574a7c3a1ebfda93b0e2e4335e91738bbb5d62d2a59458a15d2c0edc4b69fb8d3fae705f3d69fdafb8ed0b6975901932337e9de1b4b2064e3844d3a1bf3779ecf8315af5393080cce458623f55fa9f6af0cd854073c012a5069e7f9084eef305ebbdc234f7ab8f491674a96661108eeb15f90f958ce2de78aab0387bf6ca2c8bad85221411d4342f8fa333f3246dc7075d439cee03ec591a4b8a1927bc8a7494b2890ca4b8e6b68ff1b5c221fe0193a270b04cedf2384b669b3407eb68ecbc51a17695c364216117ebc56adab4714c529cfa6866ca9cffe5934751737aea3031c364e8c6ee7f0334d924cc76945d1c05faf16b9307bbc58a5fbfe6ede39a950f6112a0a832da4437605a03e446572427edc9772fe905ca3e0681f55c6913
Content-Length: -1
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

< HTTP/1.1 400 Bad Request
< Server: nginx
< Date: Wed, 06 May 2020 18:26:19 GMT
< Content-Type: text/html
< Content-Length: 166
< Connection: close
<
* Closing connection 1

Уникальное отличие состоит в том, что после входа в систему протоколом для POST является неправильный сервер HTTP / 1.1 вместо HTTP / 1.0

...