initial checkin from subversion
This commit is contained in:
509
index.php
Normal file
509
index.php
Normal file
@@ -0,0 +1,509 @@
|
|||||||
|
<?php
|
||||||
|
$FP="files/".$_SERVER['PHP_AUTH_USER']."/";
|
||||||
|
system ("mkdir -p '" . $FP . "'");
|
||||||
|
|
||||||
|
define('CHUNK_SIZE', 1024*1024); // Size (in bytes) of tiles chunk
|
||||||
|
|
||||||
|
// Read a file and display its content chunk by chunk
|
||||||
|
function readfile_chunked($filename, $retbytes = TRUE) {
|
||||||
|
$buffer = '';
|
||||||
|
$cnt =0;
|
||||||
|
// $handle = fopen($filename, 'rb');
|
||||||
|
$handle = fopen($filename, 'rb');
|
||||||
|
if ($handle === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while (!feof($handle)) {
|
||||||
|
$buffer = fread($handle, CHUNK_SIZE);
|
||||||
|
echo $buffer;
|
||||||
|
ob_flush();
|
||||||
|
flush();
|
||||||
|
if ($retbytes) {
|
||||||
|
$cnt += strlen($buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$status = fclose($handle);
|
||||||
|
if ($retbytes && $status) {
|
||||||
|
return $cnt; // return num. bytes delivered like readfile() does.
|
||||||
|
}
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write stdin to a file chunk by chunk
|
||||||
|
function writefile_chunked($filename, $retbytes = TRUE) {
|
||||||
|
$buffer = '';
|
||||||
|
$cnt =0;
|
||||||
|
// $handle = fopen($filename, 'rb');
|
||||||
|
$handleIn = fopen("php://input", 'rb');
|
||||||
|
if ($handleIn === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//$handleOut = fopen($filename, 'wb');
|
||||||
|
$handleOut = fopen($filename, 'wb');
|
||||||
|
if ($handleOut === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while (!feof($handleIn)) {
|
||||||
|
$buffer = fread($handleIn, CHUNK_SIZE);
|
||||||
|
$retbytes=fwrite($handleOut,$buffer);
|
||||||
|
if ($retbytes) {
|
||||||
|
$cnt += strlen($buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$statusOut = fclose($handleOut);
|
||||||
|
$statusIn = fclose($handleIn);
|
||||||
|
$status = $statusIn;
|
||||||
|
if ($retbytes && $statusOut) {
|
||||||
|
return $cnt; // return num. bytes written.
|
||||||
|
}
|
||||||
|
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['dlFile'])){
|
||||||
|
# doesn't work -- always gets killed (out of memory?)
|
||||||
|
header('Content-disposition: attachment; filename='. $_GET["dlFile"]);
|
||||||
|
header('Content-type: application/octet-stream');
|
||||||
|
header('Content-Length: ' . filesize($FP . $_GET["dlFile"]));
|
||||||
|
header("Pragma: no-cache");
|
||||||
|
header("Expires: 0");
|
||||||
|
readfile_chunked($FP . $_GET["dlFile"]);
|
||||||
|
#readfile($FP . $_GET["dlFile"]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['url'])) {
|
||||||
|
system("cd '" . $FP . "';/usr/bin/wget --progress=dot '" . $_GET["url"] . "' 2>&1");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['getFileList'])) {
|
||||||
|
header('Content-type: application/json');
|
||||||
|
header("Pragma: no-cache");
|
||||||
|
header("Expires: 0");
|
||||||
|
|
||||||
|
system("cd '" . $FP . "';/bin/echo -n '{\"FileList\":['; /bin/ls | /usr/bin/sort | while read x; do if [ ! -f \".\${x}.md5\" ]; then /usr/bin/md5sum \"\${x}\" | /usr/bin/cut -c1-32 > \".\${x}.md5\"; fi; /bin/echo -n '{\"file\":{\"name\":\"'\${x}'\", \"md5\":\"'`/bin/cat \".\${x}.md5\"`'\", \"size\":\"'`/usr/bin/du -m \"\${x}\" | /usr/bin/cut -f1`'\"}},'; done; /bin/echo -n '{}]}'");
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_SERVER['HTTP_X_FILENAME'])) {
|
||||||
|
// create new file if the name already exists - don't override
|
||||||
|
$origFileName=$_SERVER['HTTP_X_FILENAME'];
|
||||||
|
$fileName=$origFileName;
|
||||||
|
$i=0;
|
||||||
|
while (file_exists($FP . $fileName)) {
|
||||||
|
$fileName=$origFileName . "." . ++$i;
|
||||||
|
}
|
||||||
|
|
||||||
|
//file_put_contents( $FP . $fileName, file_get_contents('php://input'));
|
||||||
|
writefile_chunked($FP . $fileName);
|
||||||
|
echo $fileName . " uploaded";
|
||||||
|
system("cd '" . $FP . "';/usr/bin/md5sum '" . $fileName . "' | /usr/bin/cut -c1-32 > '." . $fileName . ".md5'");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['kill'])) {
|
||||||
|
unlink($FP . $_GET['kill']);
|
||||||
|
unlink($FP . "." . $_GET['kill'] . ".md5");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>NetSquat-Downloader
|
||||||
|
<?php
|
||||||
|
echo "[". $_SERVER['PHP_AUTH_USER'] . "]";
|
||||||
|
?>
|
||||||
|
</title>
|
||||||
|
<style>
|
||||||
|
#filedrag {
|
||||||
|
display: none;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
padding: 1em 0;
|
||||||
|
margin: 1em 0;
|
||||||
|
color: #555;
|
||||||
|
border: 2px dashed #555;
|
||||||
|
border-radius: 7px;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
#filedrag.hover {
|
||||||
|
color: #f00;
|
||||||
|
border-color: #f00;
|
||||||
|
border-style: solid;
|
||||||
|
box-shadow: inset 0 3px 4px #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.fileList {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover {
|
||||||
|
background-color: #bbbbbb;
|
||||||
|
}
|
||||||
|
|
||||||
|
th.fileList {
|
||||||
|
border: 2px solid black;
|
||||||
|
font-weight: bold;
|
||||||
|
background: #ffcccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.fileList {
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset.upload {
|
||||||
|
background: #f2f2f2;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
legend.upload {
|
||||||
|
background: #EEEEEE;
|
||||||
|
border: 1px solid black;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family:Verdana,sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<span style='font-size:40px'><span style='color:#777777'>Down</span>-<span style='color:#FF0000'>loader</span></span><span style='font-size:14px'> by <a href='mailto:joe@netsquat.com'>joe@netsquat.com</a></span>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<fieldset class='upload'><legend class='upload'>Upload local file</legend>
|
||||||
|
<form action="" id='localFileUpload' method="POST" enctype="multipart/form-data">
|
||||||
|
<input type="file" id='fileselect' name="files[]" multiple="multiple">
|
||||||
|
<div id='filedrag'>or drop files here</div>
|
||||||
|
</form>
|
||||||
|
<div id="UploadProgressBars">
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<fieldset class='upload'><legend class='upload'>Download remote url</legend>
|
||||||
|
<input name="url" id="url" size="100">
|
||||||
|
<button id='btnDownload' onclick="downloader.downloadURL(document.getElementById('url').value)" >Download</button>
|
||||||
|
<div id="DownloadProgressBars">
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<hr>
|
||||||
|
<table id="fileList" class='fileList' style="font-family:monospace">
|
||||||
|
<tbody>
|
||||||
|
<tr><th class='fileList'>File</th><th class='fileList'>Size(MB)</th><th class='fileList'>MD5</th><th class='fileList'>KILL</th></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div id="messages">
|
||||||
|
<p>Status Messages</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--div id="myDiv">
|
||||||
|
CONSOLE
|
||||||
|
</div-->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
/*
|
||||||
|
var myDiv;
|
||||||
|
console.origLog = console.log;
|
||||||
|
console.log = function(x) {
|
||||||
|
if(!myDiv) myDiv = document.getElementById('myDiv');
|
||||||
|
if(myDiv) myDiv.innerHTML = myDiv.innerHTML + "<br>" + x;
|
||||||
|
else console.origLog('can not determine myDiv');
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
var downloader = (function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function $id(id) {
|
||||||
|
return document.getElementById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function delRequest(file){
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
fillFileList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.open("GET", "?kill=" + encodeURIComponent(file), true);
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillFileList(){
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
var fileData = JSON.parse(xhr.responseText);
|
||||||
|
var tFL = document.getElementById("fileList");
|
||||||
|
|
||||||
|
tFL.deleteDataRows();
|
||||||
|
var i;
|
||||||
|
for(i =0;i<fileData.FileList.length-1;i+=1) {
|
||||||
|
tFL.addFile(fileData.FileList[i].file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.open("GET", "?getFileList", true);
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
// cancel event and hover styling
|
||||||
|
function FileDragHover(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
e.target.className = (e.type === "dragover" ? "hover" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function ParseFile(file) {
|
||||||
|
Output(
|
||||||
|
"<p>File information: <strong>" + file.name +
|
||||||
|
"</strong> type: <strong>" + file.type +
|
||||||
|
"</strong> size: <strong>" + file.size +
|
||||||
|
"</strong> bytes</p>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FileSelectHandler(e) {
|
||||||
|
FileDragHover(e);
|
||||||
|
|
||||||
|
var files = e.target.files || e.dataTransfer.files;
|
||||||
|
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < files.length; i++) {
|
||||||
|
ParseFile(files[i]);
|
||||||
|
UploadFile(files[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Init() {
|
||||||
|
var fileselect = $id("fileselect");
|
||||||
|
fileselect.addEventListener("change", FileSelectHandler, false);
|
||||||
|
|
||||||
|
var filedrag = $id("filedrag");
|
||||||
|
filedrag.addEventListener("dragover", FileDragHover, false);
|
||||||
|
filedrag.addEventListener("dragleave", FileDragHover, false);
|
||||||
|
filedrag.addEventListener("drop", FileSelectHandler, false);
|
||||||
|
filedrag.style.display = "block";
|
||||||
|
|
||||||
|
|
||||||
|
fillFileList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadURL(url) {
|
||||||
|
var progressBarId=Math.random()*100000000000000000;
|
||||||
|
$id("DownloadProgressBars").add(progressBarId,url)
|
||||||
|
$id("DownloadProgressBars").setMax(progressBarId,100)
|
||||||
|
$id("url").value = "";
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
$id("DownloadProgressBars").remove(progressBarId)
|
||||||
|
fillFileList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhr.open("GET", "?url=" + encodeURIComponent(url), true);
|
||||||
|
xhr.send();
|
||||||
|
|
||||||
|
var timer;
|
||||||
|
timer = window.setInterval(function() {
|
||||||
|
if (xhr.readyState === 4) {
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
Output('UrlDownload done <br />');
|
||||||
|
}
|
||||||
|
var tmpResponse=xhr.responseText;
|
||||||
|
var lastIndex=tmpResponse.lastIndexOf("%");
|
||||||
|
if (lastIndex>0) {
|
||||||
|
var pctFinish=tmpResponse.substring(lastIndex-3,lastIndex);
|
||||||
|
$id("DownloadProgressBars").setProgress(progressBarId,pctFinish);
|
||||||
|
}
|
||||||
|
// console.log(xhr.responseText);
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
function UploadFile(file) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var progressBarId=Math.random()*100000000000000000;
|
||||||
|
|
||||||
|
$id("UploadProgressBars").add(progressBarId,file.name);
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
Output(xhr.responseText);
|
||||||
|
fillFileList();
|
||||||
|
$id("UploadProgressBars").remove(progressBarId);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// progress bar
|
||||||
|
xhr.upload.addEventListener("progress", function(e) {
|
||||||
|
$id("UploadProgressBars").setMax(progressBarId, e.total);
|
||||||
|
$id("UploadProgressBars").setProgress(progressBarId, e.loaded);
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
xhr.open("POST", $id("localFileUpload").action, true);
|
||||||
|
xhr.setRequestHeader("X_FILENAME", file.name);
|
||||||
|
xhr.send(file);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// output information
|
||||||
|
function Output(msg) {
|
||||||
|
var m = $id("messages");
|
||||||
|
m.innerHTML = msg + "<br>"+ m.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
// call initialization file
|
||||||
|
if (window.File && window.FileList && window.FileReader) {
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
$id:$id,
|
||||||
|
delRequest:delRequest,
|
||||||
|
downloadURL:downloadURL
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
|
||||||
|
downloader.progressBar = (function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var min,max,current;
|
||||||
|
|
||||||
|
function $id(id){
|
||||||
|
return(downloader.$id(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
function add(id,description){
|
||||||
|
var tn = document.createElement("div");
|
||||||
|
tn.setAttribute("id", "ProgressFile" + id);
|
||||||
|
tn.appendChild(document.createTextNode("Name: " + description));
|
||||||
|
this.appendChild(tn);
|
||||||
|
|
||||||
|
var newPB=document.createElement("progress");
|
||||||
|
newPB.setAttribute("id" ,"progressUL" + id);
|
||||||
|
this.appendChild(newPB);
|
||||||
|
|
||||||
|
var pt=document.createElement("span");
|
||||||
|
pt.setAttribute("id" ,"progressPct" + id);
|
||||||
|
this.appendChild(pt);
|
||||||
|
|
||||||
|
setMin(id,0);
|
||||||
|
setMax(id,100);
|
||||||
|
setProgress(id,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setPct(id){
|
||||||
|
var pct=0;
|
||||||
|
if ((max >0)&&(current>0)) {
|
||||||
|
pct=Math.round(current/max*100);
|
||||||
|
}
|
||||||
|
$id("progressPct" + id).innerText = "["+Math.round(current/max*100)+" %]";
|
||||||
|
}
|
||||||
|
|
||||||
|
function setProgress(id,value){
|
||||||
|
current=value;
|
||||||
|
$id("progressUL" + id).value = value;
|
||||||
|
setPct(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(id){
|
||||||
|
$id("progressPct" + id).parentNode.removeChild($id("progressPct" + id));
|
||||||
|
$id("progressUL" + id).parentNode.removeChild($id("progressUL" + id));
|
||||||
|
$id("ProgressFile" + id).parentNode.removeChild($id("ProgressFile" + id));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setMin(id,value){
|
||||||
|
min=value;
|
||||||
|
$id("progressUL" + id).min = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setMax(id,value){
|
||||||
|
max=value
|
||||||
|
$id("progressUL" + id).max = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bind(theDomElement) {
|
||||||
|
theDomElement.add=add;
|
||||||
|
theDomElement.setProgress=setProgress;
|
||||||
|
theDomElement.setMin=setMin;
|
||||||
|
theDomElement.setMax=setMax;
|
||||||
|
theDomElement.remove=remove;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
bind:bind
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
||||||
|
downloader.fileBrowser = (function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function addFile(fileData){
|
||||||
|
var row;
|
||||||
|
var cell1;
|
||||||
|
var cell2;
|
||||||
|
var cell3;
|
||||||
|
var cell4;
|
||||||
|
row = this.insertRow(this.rows.length);
|
||||||
|
cell1 = row.insertCell(0);
|
||||||
|
cell1.innerHTML="<a href='<?php echo $FP ?>" + fileData.name +"'>" + fileData.name + "</a>" ;
|
||||||
|
cell1.className='fileList';
|
||||||
|
cell2 = row.insertCell(1);
|
||||||
|
cell2.innerHTML=fileData.size ;
|
||||||
|
try { // dirty trick: iOS Safari doesn't like the next line...
|
||||||
|
cell2.style='text-align:right';
|
||||||
|
} catch(e) {}
|
||||||
|
cell2.className='fileList';
|
||||||
|
cell3 = row.insertCell(2);
|
||||||
|
cell3.innerHTML=fileData.md5 ;
|
||||||
|
cell3.className='fileList';
|
||||||
|
cell4 = row.insertCell(3);
|
||||||
|
cell4.innerHTML='<button onclick="downloader.delRequest(\''+fileData.name+'\')">X</button>';
|
||||||
|
cell4.className='fileList';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteDataRows() {
|
||||||
|
var i;
|
||||||
|
for(i = this.rows.length-1; i > 0;i-=1) {
|
||||||
|
this.deleteRow(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("fileList").addFile=addFile;
|
||||||
|
document.getElementById("fileList").deleteDataRows=deleteDataRows;
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
||||||
|
window.onload = function(){
|
||||||
|
downloader.progressBar.bind(downloader.$id("UploadProgressBars"));
|
||||||
|
downloader.progressBar.bind(downloader.$id("DownloadProgressBars"));
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<!--
|
||||||
|
vim: sw=2 ts=2 si expandtab nowrap
|
||||||
|
-->
|
||||||
324
index.php~
Normal file
324
index.php~
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
<?php
|
||||||
|
$FP="files/".$_SERVER['PHP_AUTH_USER']."/";
|
||||||
|
system ("mkdir -p '" . $FP . "'");
|
||||||
|
|
||||||
|
define('CHUNK_SIZE', 1024*1024); // Size (in bytes) of tiles chunk
|
||||||
|
|
||||||
|
// Read a file and display its content chunk by chunk
|
||||||
|
function readfile_chunked($filename, $retbytes = TRUE) {
|
||||||
|
$buffer = '';
|
||||||
|
$cnt =0;
|
||||||
|
// $handle = fopen($filename, 'rb');
|
||||||
|
$handle = fopen($filename, 'rb');
|
||||||
|
if ($handle === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while (!feof($handle)) {
|
||||||
|
$buffer = fread($handle, CHUNK_SIZE);
|
||||||
|
echo $buffer;
|
||||||
|
ob_flush();
|
||||||
|
flush();
|
||||||
|
if ($retbytes) {
|
||||||
|
$cnt += strlen($buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$status = fclose($handle);
|
||||||
|
if ($retbytes && $status) {
|
||||||
|
return $cnt; // return num. bytes delivered like readfile() does.
|
||||||
|
}
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['dlFile'])){
|
||||||
|
# doesn't work -- always gets killed (out of memory?)
|
||||||
|
header('Content-disposition: attachment; filename='. $_GET["dlFile"]);
|
||||||
|
header('Content-type: application/octet-stream');
|
||||||
|
header('Content-Length: ' . filesize($FP . $_GET["dlFile"]));
|
||||||
|
header("Pragma: no-cache");
|
||||||
|
header("Expires: 0");
|
||||||
|
readfile_chunked($FP . $_GET["dlFile"]);
|
||||||
|
#readfile($FP . $_GET["dlFile"]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['url'])) {
|
||||||
|
system("cd '" . $FP . "';/usr/bin/wget --progress=dot '" . $_GET["url"] . "' 2>&1");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['getFileList'])) {
|
||||||
|
header('Content-type: application/json');
|
||||||
|
header("Pragma: no-cache");
|
||||||
|
header("Expires: 0");
|
||||||
|
|
||||||
|
system("cd '" . $FP . "';/bin/echo -n '{\"FileList\":['; /bin/ls | /usr/bin/sort | while read x; do if [ ! -f \".\${x}.md5\" ]; then /usr/bin/md5sum \"\${x}\" | /usr/bin/cut -c1-32 > \".\${x}.md5\"; fi; /bin/echo -n '{\"file\":{\"name\":\"'\${x}'\", \"md5\":\"'`/bin/cat \".\${x}.md5\"`'\", \"size\":\"'`/usr/bin/du -m \"\${x}\" | /usr/bin/cut -f1`'\"}},'; done; /bin/echo -n '{}]}'");
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_SERVER['HTTP_X_FILENAME'])) {
|
||||||
|
file_put_contents( $FP . $_SERVER['HTTP_X_FILENAME'], file_get_contents('php://input'));
|
||||||
|
echo $_SERVER['HTTP_X_FILENAME'] . " uploaded";
|
||||||
|
system("cd '" . $FP . "';/usr/bin/md5sum '" . $_SERVER['HTTP_X_FILENAME'] . "' | /usr/bin/cut -c1-32 > '." . $_SERVER['HTTP_X_FILENAME'] . ".md5'");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['kill'])) {
|
||||||
|
unlink($FP . $_GET['kill']);
|
||||||
|
unlink($FP . "." . $_GET['kill'] . ".md5");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>NetSquat-Downloader
|
||||||
|
<?php
|
||||||
|
echo "[". $_SERVER['PHP_AUTH_USER'] . "]";
|
||||||
|
?>
|
||||||
|
</title>
|
||||||
|
<style>
|
||||||
|
#filedrag
|
||||||
|
{
|
||||||
|
display: none;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
padding: 1em 0;
|
||||||
|
margin: 1em 0;
|
||||||
|
color: #555;
|
||||||
|
border: 2px dashed #555;
|
||||||
|
border-radius: 7px;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
#filedrag.hover
|
||||||
|
{
|
||||||
|
color: #f00;
|
||||||
|
border-color: #f00;
|
||||||
|
border-style: solid;
|
||||||
|
box-shadow: inset 0 3px 4px #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Enter URL</h1>
|
||||||
|
<form action="" id='localFileUpload' method="POST" enctype="multipart/form-data">
|
||||||
|
<fieldset><legend>Upload local file</legend>
|
||||||
|
<input type="file" id='fileselect' name="files[]" multiple="multiple">
|
||||||
|
<div id='filedrag'>or drop files here</div>
|
||||||
|
</fieldset>
|
||||||
|
<div id="UploadProgressBars">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<fieldset><legend>Download remote url</legend>
|
||||||
|
<input name="url" id="url" size="100">
|
||||||
|
<button id='btnDownload' onclick="downloader.downloadURL(document.getElementById('url').value)" >Download</button>
|
||||||
|
<progress id='progress' style='display:none' value='0' max='100'></progress>
|
||||||
|
</fieldset>
|
||||||
|
<table id="fileList" border="0" style="font-family:monospace">
|
||||||
|
<tbody>
|
||||||
|
<tr><th>File</th><th>Size(MB)</th><th>MD5</th><th>KILL</th></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="messages">
|
||||||
|
<p>Status Messages</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var downloader = (function () {
|
||||||
|
"use strinct";
|
||||||
|
|
||||||
|
var allFiles= [];
|
||||||
|
|
||||||
|
// getElementById
|
||||||
|
function $id(id) {
|
||||||
|
return document.getElementById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function delRequest(file){
|
||||||
|
var xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xmlhttp.onreadystatechange = function() {
|
||||||
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
|
//var fileData = JSON.parse(xmlhttp.responseText);
|
||||||
|
fillFileList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xmlhttp.open("GET", "?kill=" + encodeURIComponent(file), true);
|
||||||
|
xmlhttp.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillFileList(){
|
||||||
|
var xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xmlhttp.onreadystatechange = function() {
|
||||||
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
|
var fileData = JSON.parse(xmlhttp.responseText);
|
||||||
|
|
||||||
|
var tFL = document.getElementById("fileList");
|
||||||
|
//alert(fileData);
|
||||||
|
for(var i = tFL.rows.length-1; i > 0;i--) {
|
||||||
|
tFL.deleteRow(i);
|
||||||
|
}
|
||||||
|
for(var i =0;i<fileData.FileList.length-1;i++) {
|
||||||
|
var row = tFL.insertRow(tFL.rows.length);
|
||||||
|
var cell1 = row.insertCell(0);
|
||||||
|
cell1.innerHTML="<a href='<?php echo $FP ?>" + fileData.FileList[i].file.name +"'>" + fileData.FileList[i].file.name + "</a>" ;
|
||||||
|
var cell2 = row.insertCell(1);
|
||||||
|
cell2.innerHTML=fileData.FileList[i].file.size ;
|
||||||
|
var cell3 = row.insertCell(2);
|
||||||
|
cell3.innerHTML=fileData.FileList[i].file.md5 ;
|
||||||
|
var cell4 = row.insertCell(3);
|
||||||
|
cell4.innerHTML='<button onCLick="downloader.delRequest(\''+fileData.FileList[i].file.name+'\')">X</button>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xmlhttp.open("GET", "?getFileList", true);
|
||||||
|
xmlhttp.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize
|
||||||
|
function Init() {
|
||||||
|
var fileselect = $id("fileselect"),
|
||||||
|
filedrag = $id("filedrag");
|
||||||
|
|
||||||
|
// file select
|
||||||
|
fileselect.addEventListener("change", FileSelectHandler, false);
|
||||||
|
|
||||||
|
// file drop
|
||||||
|
filedrag.addEventListener("dragover", FileDragHover, false);
|
||||||
|
filedrag.addEventListener("dragleave", FileDragHover, false);
|
||||||
|
filedrag.addEventListener("drop", FileSelectHandler, false);
|
||||||
|
filedrag.style.display = "block";
|
||||||
|
|
||||||
|
fillFileList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// file drag hover
|
||||||
|
function FileDragHover(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
e.target.className = (e.type == "dragover" ? "hover" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// file selection
|
||||||
|
function FileSelectHandler(e) {
|
||||||
|
|
||||||
|
// cancel event and hover styling
|
||||||
|
FileDragHover(e);
|
||||||
|
|
||||||
|
// fetch FileList object
|
||||||
|
var files = e.target.files || e.dataTransfer.files;
|
||||||
|
|
||||||
|
// process all File objects
|
||||||
|
for (var i = 0, f; f = files[i]; i++) {
|
||||||
|
ParseFile(f);
|
||||||
|
UploadFile(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function ParseFile(file) {
|
||||||
|
Output(
|
||||||
|
"<p>File information: <strong>" + file.name +
|
||||||
|
"</strong> type: <strong>" + file.type +
|
||||||
|
"</strong> size: <strong>" + file.size +
|
||||||
|
"</strong> bytes</p>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download URL
|
||||||
|
function downloadURL(url) {
|
||||||
|
// create progress bar
|
||||||
|
$id("url").readOnly = true;
|
||||||
|
$id("btnDownload").style.display='none';
|
||||||
|
$id("progress").value=0;
|
||||||
|
$id("progress").style.display='';
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||||
|
$id("btnDownload").style.display='';
|
||||||
|
$id("progress").style.display='none';
|
||||||
|
$id("url").value = "";
|
||||||
|
$id("url").readOnly = false;
|
||||||
|
fillFileList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhr.open("GET", "?url=" + encodeURIComponent(url), true);
|
||||||
|
xhr.send();
|
||||||
|
|
||||||
|
var timer;
|
||||||
|
timer = window.setInterval(function() {
|
||||||
|
if (xhr.readyState == XMLHttpRequest.DONE) {
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
Output('UrlDownload done <br />');
|
||||||
|
}
|
||||||
|
var tmpResponse=xhr.responseText;
|
||||||
|
var lastIndex=tmpResponse.lastIndexOf("%");
|
||||||
|
if (lastIndex>0) {
|
||||||
|
var pctFinish=tmpResponse.substring(lastIndex-3,lastIndex);
|
||||||
|
$id("progress").value = pctFinish;
|
||||||
|
}
|
||||||
|
// console.log(xhr.responseText);
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
// upload JPEG files
|
||||||
|
function UploadFile(file) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
var newPB=document.createElement("progress");
|
||||||
|
newPB.setAttribute("id" ,"progressUL" + file.name);
|
||||||
|
|
||||||
|
var tn = document.createElement("div");
|
||||||
|
tn.setAttribute("id", "ProgressFile" + file.name);
|
||||||
|
tn.appendChild(document.createTextNode("FILE: " + file.name));
|
||||||
|
|
||||||
|
$id("UploadProgressBars").appendChild(tn);
|
||||||
|
$id("UploadProgressBars").appendChild(newPB);
|
||||||
|
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||||
|
Output(xhr.responseText);
|
||||||
|
fillFileList();
|
||||||
|
$id("progressUL" + file.name).parentNode.removeChild($id("progressUL" + file.name));
|
||||||
|
$id("ProgressFile" + file.name).parentNode.removeChild($id("ProgressFile" + file.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xhr.open("POST", $id("localFileUpload").action, true);
|
||||||
|
xhr.setRequestHeader("X_FILENAME", file.name);
|
||||||
|
xhr.send(file);
|
||||||
|
// progress bar
|
||||||
|
xhr.upload.addEventListener("progress", function(e) {
|
||||||
|
$id("progressUL" + file.name).max = e.total;
|
||||||
|
$id("progressUL" + file.name).value = e.loaded;
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// output information
|
||||||
|
function Output(msg) {
|
||||||
|
var m = $id("messages");
|
||||||
|
m.innerHTML = msg + "<br>"+ m.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
// call initialization file
|
||||||
|
if (window.File && window.FileList && window.FileReader) {
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
delRequest:delRequest,
|
||||||
|
downloadURL:downloadURL
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<!--
|
||||||
|
vim: sw=2 ts=2 si expandtab nowrap
|
||||||
|
-->
|
||||||
Reference in New Issue
Block a user