-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfile-webfetch.php
87 lines (69 loc) · 2.3 KB
/
file-webfetch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
header('content-type: text/plain; charset=utf-8');
require("ii-functions.php");
function getfile_ram($add) {
echo "fetch ".$add."\n";
return file_get_contents($add);
}
function parseFullFEchoList($echobundle) {
global $file_access;
$echos2d=array();
$lastecho="";
for($i=0;$i<count($echobundle);$i++) {
if(!empty($echobundle[$i])) {
$search=strpos($echobundle[$i], ":");
if($search===false) {
$lastecho=$echobundle[$i];
$echos2d[$lastecho]=array();
} else {
$echos2d[$lastecho][]=$echobundle[$i];
}
}
}
return $echos2d;
}
function parseEntries($list) {
global $file_access;
foreach ($list as &$entry) {
$entry = $file_access -> transport -> parseFileEntry(
$entry, $size=true, $remote_size=true);
}
return $list;
}
function fetch_files($config, $fetch_limit=false, $force_download_files=[]) {
global $file_access;
$address = $config[0];
$echoesToFetch=array_slice($config,1);
$bundleAdress=$address."f/e/".implode("/", $echoesToFetch);
$bundleAdress.=($fetch_limit) ? "/-".$fetch_limit.":".$fetch_limit : "";
$echoBundle=explode("\n", getfile_ram($bundleAdress));
$remoteEchos2d=parseFullFEchoList($echoBundle);
foreach($echoesToFetch as $echo) {
$localMessages=$file_access->getRawFileList($echo);
$remoteMessages=$remoteEchos2d[$echo];
$difference=array_diff($remoteMessages, $localMessages);
$difference=parseEntries($difference);
foreach ($difference as $target) {
$size = intval($target["size"]) + 1024;
$hash = $target["id"];
$filename = $target["filename"];
echo "$echo : $filename\n";
$fuckcontinue = 0;
foreach (parseEntries($localMessages) as $msg) {
if (isset($msg["id"]) && $msg["id"] == $hash) {
echo "file already exists ".$hash."\n";
$fuckcontinue = 1;
}
}
if ($fuckcontinue) continue;
$check = $file_access -> saveFile($hash, $echo, ["size" => $size],
$filename, $target["address"], $target["desc"], $check_only=true);
if ($check===true or array_search($hash, $force_download_files) != false) {
exec("echo ".$address."f/f/".$echo."/".$hash." | wget -Q".$size." -i - -O ".$file_access->transport->filedir."/".$hash);
$raw_entry = $hash . ":" . $filename . "::" . $target["address"] . ":" . $target["desc"];
$file_access -> transport -> appendMsgList($echo, [$raw_entry]);
}
}
}
}
?>