-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverftp.php
More file actions
137 lines (113 loc) · 3.68 KB
/
Copy pathserverftp.php
File metadata and controls
137 lines (113 loc) · 3.68 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
$title = "Server Web FTP";
$page = "serverftp";
$return = "serverftp.php?id=" . urlencode($_GET["id"] ?? "");
require __DIR__ . '/configuration.php';
require __DIR__ . '/include.php';
require __DIR__ . '/includes/ftp.php';
$serverid = sanitizeInput($_GET["id"] ?? "");
$path = sanitizeInput($_GET["path"] ?? "");
$file = sanitizeInput($_GET["file"] ?? "");
$rows = dbRow(
"SELECT serverid, ipid, boxid, user, password, webftp
FROM server
WHERE serverid='$serverid' AND clientid='{$_SESSION["clientid"]}'
LIMIT 1"
);
if (empty($rows) || empty($rows["webftp"])) {
header("Location: serversummary.php?id=" . urlencode($serverid));
exit;
}
$folders = [];
$files = [];
$links = [];
$filecontents = "";
if (!empty($rows["ipid"])) {
$rows1 = dbRow("SELECT ip FROM ip WHERE ipid='{$rows["ipid"]}' LIMIT 1");
$rows2 = dbRow("SELECT ftpport, passive FROM box WHERE boxid='{$rows["boxid"]}' LIMIT 1");
$ip = $rows1["ip"] ?? "";
$ftpport = $rows2["ftpport"] ?? 21;
$passive = (($rows2["passive"] ?? "") === "On");
if ($ip !== "") {
$ftpconnection = get_ftp_connection($ip, $ftpport, $rows["user"], $rows["password"], $passive);
if ($ftpconnection) {
if ($file === "") {
$array = ftp_rawlist($ftpconnection, $path);
if (!is_array($array)) {
$path = normalizeFtpPath($path);
$array = ftp_rawlist($ftpconnection, $path);
}
if (is_array($array)) {
foreach ($array as $entry) {
$current = preg_split("/[\\s]+/", $entry, 9);
if (count($current) < 9) {
continue;
}
$name = str_replace("//", "", $current[8]);
if ($name === "." || $name === "..") {
continue;
}
$struc = [];
$struc["perms"] = $current[0];
$struc["permsn"] = permsToChmod($current[0]);
$struc["number"] = $current[1];
$struc["owner"] = $current[2];
$struc["group"] = $current[3];
$struc["size"] = formatBytesIEC((int)$current[4]);
$struc["month"] = $current[5];
$struc["day"] = $current[6];
$struc["time"] = $current[7];
$struc["name"] = $name;
if (substr($path, 0, 1) === "/") {
$struc["path"] = urlencode(rtrim($path, "/") . "/" . $name);
} else {
$struc["path"] = urlencode($path . $name . "/");
}
$type = getFtpItemType($struc["perms"]);
if ($type === "folder") {
$folders[] = $struc;
} elseif ($type === "link") {
$links[] = $struc;
} else {
$struc["link"] = makeFtpFileLink($struc["name"]);
$files[] = $struc;
}
}
}
} else {
$tempHandle = fopen("php://temp", "r+");
if (substr($path, -1) === "/") {
if (!@ftp_fget($ftpconnection, $tempHandle, $path . $file, FTP_BINARY)) {
$path = normalizeFtpPath($path);
@ftp_fget($ftpconnection, $tempHandle, rtrim($path, "/") . "/" . $file, FTP_BINARY);
}
} else {
if (!@ftp_fget($ftpconnection, $tempHandle, $path . "/" . $file, FTP_BINARY)) {
$path = normalizeFtpPath($path);
@ftp_fget($ftpconnection, $tempHandle, $path . $file, FTP_BINARY);
}
}
rewind($tempHandle);
$filecontents = (string)stream_get_contents($tempHandle);
}
}
}
}
$pathEncoded = urlencode($path);
$pathDecoded = $path;
$breadCrumb = buildFtpBreadcrumb($path);
$msg1 = $_SESSION["msg1"] ?? null;
$msg2 = $_SESSION["msg2"] ?? null;
unset($_SESSION["msg1"], $_SESSION["msg2"]);
$maxFilesize = ini_get("upload_max_filesize");
// Bridge to the names the view partial expects.
$srv = $rows;
$e_msg1 = $msg1;
$e_msg2 = $msg2;
$bread_crumb = $breadCrumb;
$path_decoded = $pathDecoded;
$file_contents = $filecontents;
$max_filesize = $maxFilesize;
include tpl('header');
include tpl('serverftp');
include tpl('footer');