From 1ef9422955883a3d0eb64f44ad6a98f700d99644 Mon Sep 17 00:00:00 2001
From: Anton Laktionov
+
+
+ Документация
+
+
+
'; + print_r($mirror_list); + echo ''; + } + + $file_list = []; + if (is_array($_REQUEST['file_list'])) + { + foreach ($_REQUEST['file_list'] as $file => $str) + { + if (!$f = unserialize($str)) + { + $strErrMsg = 'Unserialize failure: ' . $str; + break; + } + $file_list[$file] = $f; + $url = 'https://' . $mirror . '/' . $f['path']; + CMultiGet::startLoad($url, $file); + } + } + + $concurrency = 20; + $num = 0; + $bFirst = true; + while (!$strErrMsg) + { + while (haveTime() && count(CMultiGet::$connections) < $concurrency && (false !== $line = fgets($rsFile))) + { + $num++; + if (mb_strpos($line, '<' . '?php') === 0) + { + continue; + } + if (!preg_match('#^(\d{4}-\d{2}-\d{2} [\d:]{8})[ \t]+(\d+)[ \t]+(.+)$#', trim($line), $regs)) + { + $strErrMsg = 'File parse error ' . RESTORE_CLOUD_FILE_LIST . ' for line ' . $num . ': ' . $line; + break; + } + + $date = $regs[1]; + $size = $regs[2]; + $path = str_replace(' ', '%20', $regs[3]); + $save_path = preg_replace('#^[^/]+/#', '', $regs[3]); + + if (preg_match('#^[^/]*(cache/|tmp/|test.txt)#', $save_path)) + { + continue; + } + + $url = 'https://' . $mirror . '/' . $path; + $file = $_SERVER['DOCUMENT_ROOT'] . '/upload/' . $save_path; + + if (file_exists($file)) + { + if (filesize($file) == $size) + { + continue; + } + if (filesize($file) > $size) + { + bx_unlink($file); + } + } + + if (!CMultiGet::startLoad($url, $file)) + { + $strErrMsg = nl2br(htmlspecialcharsbx(CMultiGet::$error)); + break; + } + + $file_list[$file] = [ + 'date' => $date, + 'size' => $size, + 'path' => $path, + 'mirror' => $mirror, + ]; + } + + if (!CMultiGet::getPart()) + { + debug(CMultiGet::$error); + + $connection = CMultiGet::$connections[CMultiGet::$current]; + $url = $connection['url']; + CMultiGet::dropConnection(CMultiGet::$current); + + unset($file_list[$connection['file']]); // файла нет + + if ($bFirst) + { + $mirror_list_orig = $mirror_list; + $bFirst = false; + } + + foreach ($mirror_list as $mirror => $speed) + { + if (mb_strpos($url, 'https://' . $mirror) === 0) + { + unset($mirror_list[$mirror]); + CMultiGet::$bytes = 0; + break; + } + } + + if (count($mirror_list)) + { + $mirror = key($mirror_list); + foreach ($file_list as $file => $f) + { + $file_list[$file]['mirror'] = $mirror; + } + continue; + } + + if (!file_exists(RESTORE_CLOUD_FILE_LIST_404)) + { + file_put_contents(RESTORE_CLOUD_FILE_LIST_404, '<' . '?php die(); ?' . '>' . "\n"); + } + file_put_contents(RESTORE_CLOUD_FILE_LIST_404, nl2br(htmlspecialcharsbx(CMultiGet::$error)) . "\n", FILE_APPEND); + } + + if (!haveTime()) + { + break; + } + } + // для следующего хита обновим список зеркал + if ($bFirst === false) + { + $mirror_list = $mirror_list_orig; + } + + if (!$strErrMsg && (!feof($rsFile) || count(CMultiGet::$connections))) + { + $position = ftell($rsFile); + $size = filesize(RESTORE_CLOUD_FILE_LIST); + SetCurrentProgress($position, $size); + if (mb_strlen($file) > 80) + { + $file = '...' . mb_substr($file, -80); + } + $text = getMsg('ARC_DOWN_PROCESS') . ' ' . htmlspecialcharsbx($file) . '' . + $status . + GetHidden(['source', 'dump_name', 'arc_name', 'init_time']) . ' + + '; + + foreach ($file_list as $file => $f) + { + if (!file_exists($file) || filesize($file) < $f['size']) + { + $text .= ''; + } + } + + $mirror_list[$mirror] = round(CMultiGet::$bytes * 8 / 1024 / 1024 / STEP_TIME, 2); // Mbit/s + foreach ($mirror_list as $mirror => $speed) + { + $text .= ''; + } + + $bottom = '' . getMsg('BUT_TEXT_BACK') . '' . + ' '; + showMsg(getMsg('TITLE3'), $text, $bottom); + ?> + + die(); + } + fclose($rsFile); + } + else + { + $strErrMsg = getMsg("LOADER_LOAD_CANT_OPEN_READ", ["#FILE#" => RESTORE_CLOUD_FILE_LIST]); + } + + if (!$strErrMsg) + { + bx_unlink(RESTORE_CLOUD_FILE_LIST) || $strErrMsg = getMsg('FINISH_ERR_DELL_TITLE') . ': ' . RESTORE_CLOUD_FILE_LIST; + $bSelectDumpStep = true; + } + + if ($strErrMsg) + { + $ar = [ + 'TITLE' => getMsg("TITLE3"), + 'TEXT' => '
| ' . getMsg("BASE_HOST") . ': | |
| ' . getMsg("USER_NAME") . ': | |
| ' . getMsg("USER_PASS") . ': | |
| ' . getMsg("BASE_NAME") . ': | |
| ' . getMsg("BASE_CREATE_DB") . ' |