commit a3aeb75f5ad5e806d4c77e5aadf9113def457a76 Author: beu Date: Sun Apr 28 15:27:55 2019 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..f3928a8 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# web-ft + +Self-Hosted file transfer tool compatible with curl + +**CAREFUL, I don't know if it's secure** \ No newline at end of file diff --git a/conf/config.sample.php b/conf/config.sample.php new file mode 100644 index 0000000..cdbe0d8 --- /dev/null +++ b/conf/config.sample.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/front.php b/front.php new file mode 100644 index 0000000..37603a3 --- /dev/null +++ b/front.php @@ -0,0 +1,18 @@ + + +VirtIT ft + "> + + + + + + +
+Drag and Drop your file or + +



+
+
+ + diff --git a/index.php b/index.php new file mode 100644 index 0000000..e19dc15 --- /dev/null +++ b/index.php @@ -0,0 +1,58 @@ +isFile()) + { + unlink($f->getRealPath()); + } else if(!$f->isDot() && $f->isDir()) { + rrmdir($f->getRealPath()); + } + } + rmdir(_DATA_DIR . "/" . $data_dir_content ); + } + + } + + // Upload File + if ($_SERVER['REQUEST_METHOD'] === 'PUT') + { + $rnd_data = mt_rand(10000,99999); + mkdir(_DATA_DIR . "/" . $rnd_data); + $info_json->expire = time() + (7 * 24 * 60 * 60); + file_put_contents(_DATA_DIR . "/" . $rnd_data . "/info.json", json_encode($info_json)); + + $putdata = fopen("php://input", "r"); + $fp = fopen(_DATA_DIR . "/" . $rnd_data . "/file", "w"); + while ($data = fread($putdata, 1024)) + { + fwrite($fp, $data); + } + fclose($fp); + fclose($putdata); + print(_HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . 'data/' . $rnd_data . '/file'); + } + + // Informations for user + if ($_SERVER['REQUEST_METHOD'] === 'GET') + { + if (stristr($_SERVER["HTTP_USER_AGENT"], 'curl')) + { + print("To upload file, use # curl --upload-file my_file " . _HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . "index.php\n"); + } + else + { + include("front.php" ); + } + } + +?> \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..571cc77 --- /dev/null +++ b/script.js @@ -0,0 +1,46 @@ +var fileobj; +function upload_file(e) +{ + e.preventDefault(); + fileobj = e.dataTransfer.files[0]; + ajax_file_upload(fileobj); +} + +function file_explorer() { + document.getElementById('uploadfile').click(); + document.getElementById('uploadfile').onchange = function() + { + fileobj = document.getElementById('uploadfile').files[0]; + ajax_file_upload(fileobj); + }; +} + +function copytoclipboard() +{ + var elm = document.getElementById("divresponse"); + var selection = window.getSelection(); + var range = document.createRange(); + range.selectNodeContents(elm); + selection.removeAllRanges(); + selection.addRange(range); + document.execCommand("Copy"); +} + +function ajax_file_upload(file_obj) +{ + $.ajax( + { + type: 'PUT', + url: 'index.php', + contentType: false, + processData: false, + data: file_obj, + success:function(response) + {; + var divresponse = document.getElementById('divresponse'); + divresponse.innerHTML = response ; + document.getElementById('copytoclipboard').style.visibility = "visible"; + } + }); + +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..638e3df --- /dev/null +++ b/style.css @@ -0,0 +1,27 @@ +html { + max-width: 1500px; + margin: auto; + display: inline-block; + padding-top:50px; + text-align: center; + +} + +.dragndrop { + margin: 20%; + margin-top: 10%; + background-color: #a3a3a3; + padding: 1px; + padding-top: 5%; + height:40%; + font-size: 20px; + cursor: pointer; + border: 6px dashed #444444; + border-radius: 20px; + +} +.dragndrop:hover { + + background-color: #888888; + +} \ No newline at end of file