<?php
session_start();
$site = "https://adresse.de.mon.site.igalerie.fr";
$lien = "/login";
$lien3 = "/admin/?q=ftp";
$path_cookie = '/tmp/cookie.'.session_id().'.txt';
if (file_exists(realpath($path_cookie))) unlink($path_cookie);
if (!file_exists(realpath($path_cookie))) touch($path_cookie);
$curl = curl_init();
$postfields = array();
$postfields['auth_login'] = 'mon.user';
$postfields['auth_password'] = 'mon.password';
$postfields['submit'] = 'Valider';
$postfields = http_build_query($postfields);
curl_setopt($curl, CURLOPT_URL, $site.$lien);
curl_setopt($curl, CURLOPT_COOKIEFILE, realpath($path_cookie));
curl_setopt($curl, CURLOPT_COOKIEJAR, realpath($path_cookie));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
$return = curl_exec($curl);
$headers = curl_getinfo($curl);
if (!$headers['http_code'] == '200'){
echo "Erreur Step 1";
exit(1);
}
curl_setopt($curl, CURLOPT_URL, $site.$lien3);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, realpath($path_cookie));
curl_setopt($curl, CURLOPT_COOKIEJAR, realpath($path_cookie));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
$return = curl_exec($curl);
$headers = curl_getinfo($curl);
if (!$headers['http_code'] == '200'){
echo "Erreur Step 2";
exit(1);
}
$dom = new DOMDocument;
@$dom->loadHTML($return);
$inputs = $dom->getElementsByTagName('input');
foreach ($inputs as $input) {
$cle = $input->getAttribute('name');
$valeur = "";
if($cle=="anticsrf"){
$valeur = $input->getAttribute('value');
}
if(!$valeur=="") break;
}
$postfields = array();
$postfields['publish_images'] = 'on';
$postfields['anticsrf'] = "$valeur";
$postfields['action'] = 'scan';
$postfields = http_build_query($postfields);
curl_setopt($curl, CURLOPT_URL, $site.$lien3);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, realpath($path_cookie));
curl_setopt($curl, CURLOPT_COOKIEJAR, realpath($path_cookie));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
$return = curl_exec($curl);
$headers = curl_getinfo($curl);
if (!$headers['http_code'] == '200'){
echo "Erreur Step 3";
exit(1);
}
@$dom->loadHTML($return);
$div = $dom->getElementById('ftp_report');
$ps = $div->getElementsByTagName('p');
foreach ($ps as $p => $value) {
echo "$value->nodeValue\n";
}
curl_close($curl);
exit(0);