commit
08d7614cb5
12 changed files with 499 additions and 0 deletions
@ -0,0 +1,22 @@ |
||||
# Auto detect text files and perform LF normalization |
||||
* text=auto |
||||
|
||||
# Custom for Visual Studio |
||||
*.cs diff=csharp |
||||
*.sln merge=union |
||||
*.csproj merge=union |
||||
*.vbproj merge=union |
||||
*.fsproj merge=union |
||||
*.dbproj merge=union |
||||
|
||||
# Standard to msysgit |
||||
*.doc diff=astextplain |
||||
*.DOC diff=astextplain |
||||
*.docx diff=astextplain |
||||
*.DOCX diff=astextplain |
||||
*.dot diff=astextplain |
||||
*.DOT diff=astextplain |
||||
*.pdf diff=astextplain |
||||
*.PDF diff=astextplain |
||||
*.rtf diff=astextplain |
||||
*.RTF diff=astextplain |
@ -0,0 +1,163 @@ |
||||
################# |
||||
## Eclipse |
||||
################# |
||||
|
||||
*.pydevproject |
||||
.project |
||||
.metadata |
||||
bin/ |
||||
tmp/ |
||||
*.tmp |
||||
*.bak |
||||
*.swp |
||||
*~.nib |
||||
local.properties |
||||
.classpath |
||||
.settings/ |
||||
.loadpath |
||||
|
||||
# External tool builders |
||||
.externalToolBuilders/ |
||||
|
||||
# Locally stored "Eclipse launch configurations" |
||||
*.launch |
||||
|
||||
# CDT-specific |
||||
.cproject |
||||
|
||||
# PDT-specific |
||||
.buildpath |
||||
|
||||
|
||||
################# |
||||
## Visual Studio |
||||
################# |
||||
|
||||
## Ignore Visual Studio temporary files, build results, and |
||||
## files generated by popular Visual Studio add-ons. |
||||
|
||||
# User-specific files |
||||
*.suo |
||||
*.user |
||||
*.sln.docstates |
||||
|
||||
# Build results |
||||
[Dd]ebug/ |
||||
[Rr]elease/ |
||||
*_i.c |
||||
*_p.c |
||||
*.ilk |
||||
*.meta |
||||
*.obj |
||||
*.pch |
||||
*.pdb |
||||
*.pgc |
||||
*.pgd |
||||
*.rsp |
||||
*.sbr |
||||
*.tlb |
||||
*.tli |
||||
*.tlh |
||||
*.tmp |
||||
*.vspscc |
||||
.builds |
||||
*.dotCover |
||||
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment this |
||||
#packages/ |
||||
|
||||
# Visual C++ cache files |
||||
ipch/ |
||||
*.aps |
||||
*.ncb |
||||
*.opensdf |
||||
*.sdf |
||||
|
||||
# Visual Studio profiler |
||||
*.psess |
||||
*.vsp |
||||
|
||||
# ReSharper is a .NET coding add-in |
||||
_ReSharper* |
||||
|
||||
# Installshield output folder |
||||
[Ee]xpress |
||||
|
||||
# DocProject is a documentation generator add-in |
||||
DocProject/buildhelp/ |
||||
DocProject/Help/*.HxT |
||||
DocProject/Help/*.HxC |
||||
DocProject/Help/*.hhc |
||||
DocProject/Help/*.hhk |
||||
DocProject/Help/*.hhp |
||||
DocProject/Help/Html2 |
||||
DocProject/Help/html |
||||
|
||||
# Click-Once directory |
||||
publish |
||||
|
||||
# Others |
||||
[Bb]in |
||||
[Oo]bj |
||||
sql |
||||
TestResults |
||||
*.Cache |
||||
ClientBin |
||||
stylecop.* |
||||
~$* |
||||
*.dbmdl |
||||
Generated_Code #added for RIA/Silverlight projects |
||||
|
||||
# Backup & report files from converting an old project file to a newer |
||||
# Visual Studio version. Backup files are not needed, because we have git ;-) |
||||
_UpgradeReport_Files/ |
||||
Backup*/ |
||||
UpgradeLog*.XML |
||||
|
||||
|
||||
|
||||
############ |
||||
## Windows |
||||
############ |
||||
|
||||
# Windows image file caches |
||||
Thumbs.db |
||||
|
||||
# Folder config file |
||||
Desktop.ini |
||||
|
||||
|
||||
############# |
||||
## Python |
||||
############# |
||||
|
||||
*.py[co] |
||||
|
||||
# Packages |
||||
*.egg |
||||
*.egg-info |
||||
dist |
||||
build |
||||
eggs |
||||
parts |
||||
bin |
||||
var |
||||
sdist |
||||
develop-eggs |
||||
.installed.cfg |
||||
|
||||
# Installer logs |
||||
pip-log.txt |
||||
|
||||
# Unit test / coverage reports |
||||
.coverage |
||||
.tox |
||||
|
||||
#Translations |
||||
*.mo |
||||
|
||||
#Mr Developer |
||||
.mr.developer.cfg |
||||
|
||||
# Mac crap |
||||
.DS_Store |
@ -0,0 +1,15 @@ |
||||
<Files .htaccess> |
||||
order allow,deny |
||||
deny from all |
||||
</Files> |
||||
|
||||
Options -Indexes |
||||
Options +FollowSymLinks |
||||
|
||||
RewriteEngine On |
||||
RewriteBase / |
||||
RewriteRule download index.php?action=download [QSA,L] |
||||
RewriteRule ^$ index.php?action=form [QSA,L] |
||||
RewriteRule ^(.*+)$ index.php?action=shortcut&sc=$1 [QSA,L] |
||||
|
||||
DirectoryIndex filename.html |
@ -0,0 +1,54 @@ |
||||
<?php |
||||
/** |
||||
* Class for the downloaded and zipped file |
||||
* @author Shikiryu |
||||
*/ |
||||
class FileToZip{ |
||||
private $_fileName = ''; // original file name |
||||
private $_finalFileName = ''; // zipped file name |
||||
private $_filePath = ''; // original URL |
||||
private $_fileContent = null; // content of the original file |
||||
private $_zipFile = null; // ZipArchive file |
||||
|
||||
public function __construct($path){ |
||||
$this->_filePath = $path; |
||||
$this->_fileName = end(explode('/',$this->_filePath)); |
||||
$this->_finalFileName = $this->_fileName.'.zip'; |
||||
|
||||
// create a new CURL resource |
||||
$ch = curl_init(); |
||||
|
||||
// set URL and other appropriate options |
||||
curl_setopt($ch, CURLOPT_URL, $this->_filePath); //set an url |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //do not output directly, use variable |
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //do a binary transfer |
||||
curl_setopt($ch, CURLOPT_FAILONERROR, 1); //stop if an error occurred |
||||
|
||||
$this->_fileContent = curl_exec($ch); //store the content in variable |
||||
// close CURL resource, and free up system resources |
||||
curl_close($ch); |
||||
} |
||||
|
||||
/** |
||||
* Create a zip with the original file in it |
||||
* @return null or $this |
||||
*/ |
||||
public function build(){ |
||||
$this->_zipFile = new ZipArchive; |
||||
$res = $this->_zipFile->open($this->_finalFileName, ZipArchive::CREATE); |
||||
if ($res === TRUE) { |
||||
$this->_zipFile->addFromString($this->_fileName, $this->_fileContent); |
||||
$this->_zipFile->close(); |
||||
return $this; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* just a getter |
||||
*/ |
||||
public function getFinalFileName(){ |
||||
return $this->_finalFileName; |
||||
} |
||||
} |
@ -0,0 +1,42 @@ |
||||
<?php |
||||
/** |
||||
* Class to dispatch the zipped file with the given method |
||||
* @author Shikiryu |
||||
*/ |
||||
class FileToZipDispatcher{ |
||||
private $_method = array(); |
||||
private $_zip; |
||||
|
||||
public function __construct(array $method, FileToZip $zip){ |
||||
$this->_method = $method; |
||||
$this->_zip = $zip; |
||||
} |
||||
|
||||
public function dispatch($options){ |
||||
foreach($this->_method as $method){ |
||||
if(method_exists($this, '_'.$method)) { |
||||
return call_user_func(array($this, '_'.$method), $options); |
||||
}else{ |
||||
throw new Exception(sprintf('The required method "%s" does not exist for %s', $method, get_class($this))); |
||||
} |
||||
} |
||||
if(!in_array('toDownloadLater', $this->_method)){ |
||||
unlink($this->_zip->getFinalFileName()); |
||||
} |
||||
} |
||||
|
||||
private function _toDownloadNow($options){ |
||||
header("Content-type: application/zip"); |
||||
header("Content-Disposition: attachment; filename=".$this->_zip->getFinalFileName()); |
||||
header("Pragma: no-cache"); |
||||
header("Expires: 0"); |
||||
readfile($this->_zip->getFinalFileName()); |
||||
} |
||||
|
||||
private function _toDownloadLater($options){ |
||||
$index = new ToDownloadIndex(); |
||||
$shortcut = $index->saveNewLine($this->_zip->getFinalFileName()); |
||||
$email = new FileToZipEmail($options['email'], $shortcut); |
||||
$email->send(); |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
<?php |
||||
/** |
||||
* Class for sending the hashed link into the given email |
||||
* @author Shikiryu |
||||
*/ |
||||
class FileToZipEmail{ |
||||
private $_email; // email obviously |
||||
private $_shortcut; // shortcut (uniqid) |
||||
|
||||
public function __construct($email, $zip){ |
||||
$this->_email = $email; |
||||
$this->_shortcut = $zip; |
||||
$this->_protection(); |
||||
} |
||||
|
||||
/** |
||||
* Prevent hackingn see php doc |
||||
*/ |
||||
private function _protection(){ |
||||
$email = trim($this->_email); |
||||
if ((strpos ($email,"\\r")!==false) || |
||||
(strpos ($email,"\\n")!==false) || |
||||
(stripos ($email,"Content-Transfer-Encoding")!==false) || |
||||
(stripos ($email,"MIME-Version")!==false) || |
||||
(stripos ($email,"Content-Type")!==false) || |
||||
(empty($_SERVER['HTTP_USER_AGENT']))) |
||||
die('Incorrect request') ; //stop spammers |
||||
mail('shikiryu@gmail.com', '[SPAMMER] someone is trying to hack you.', "Hello, \n\n".$this->_email." tried to hack you.\n\nBye o/"); |
||||
} |
||||
|
||||
/** |
||||
* obvious |
||||
*/ |
||||
public function send(){ |
||||
mail($this->_email, 'A new file to download', "Hello, \n\nYou can download a new file here : ".BASE_URL."/".$this->_shortcut."\n\nBye o/"); |
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
<?php |
||||
/** |
||||
* Class managing todl.txt (file which match zipped file to a uniqid |
||||
* @author Shikiryu |
||||
*/ |
||||
class ToDownloadIndex{ |
||||
const FILE = 'todl.txt'; |
||||
private $_content = ''; |
||||
private $_lines = array(); |
||||
|
||||
public function __construct(){ |
||||
$this->_content = file_get_contents(dirname(__FILE__).'/'.self::FILE); |
||||
$lines = explode("\n", $this->_content); |
||||
foreach($lines as $line){ |
||||
$parts = explode(' => ', $line); |
||||
if(count($parts) == 2) $this->_lines[$parts[0]] = $parts[1]; |
||||
} |
||||
} |
||||
|
||||
public function saveNewLine($url, $shortcut = ''){ |
||||
if(empty($shortcut)) $shortcut = $this->_generateUID(); |
||||
$this->_lines[$shortcut] = $url; |
||||
$this->_rebuildFile(); |
||||
return $shortcut; |
||||
} |
||||
|
||||
public function readLine($shortcut){ |
||||
return array_key_exists($shortcut, $this->_lines) ? $this->_lines[$shortcut] : ''; |
||||
} |
||||
|
||||
public function deleteLine($shortcut){ |
||||
if(array_key_exists($shortcut, $this->_lines)){ |
||||
unset($this->_lines[$shortcut]); |
||||
} |
||||
$this->_rebuildFile(); |
||||
} |
||||
|
||||
private function _rebuildFile(){ |
||||
$stringBuffer = ''; |
||||
foreach($this->_lines as $shortcut => $url){ |
||||
$stringBuffer .= $shortcut.' => '.$url."\n"; |
||||
} |
||||
$this->_content = $stringBuffer; |
||||
file_put_contents(dirname(__FILE__).'/'.self::FILE, $stringBuffer); |
||||
} |
||||
|
||||
private function _generateUID(){ |
||||
return uniqid(); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
<?php |
||||
if(isset($_POST['url']) && isset($_POST['method'])){ |
||||
|
||||
$file2zip = new FileToZip(filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL)); |
||||
|
||||
$method = filter_has_var(INPUT_POST, 'method') ? is_array($_POST['method']) ? $_POST['method'] : array($_POST['method']) : null; |
||||
|
||||
$fileDispatcher = new FileToZipDispatcher($method, $file2zip->build()); |
||||
|
||||
$options = $_REQUEST; |
||||
unset($options['method']); |
||||
unset($options['url']); |
||||
|
||||
$fileDispatcher->dispatch($options); |
||||
|
||||
if(!in_array('toDownloadNow', $method)){ |
||||
header('Location: '.BASE_URL); |
||||
exit; |
||||
} |
||||
}else{ |
||||
header('Location: '.BASE_URL); |
||||
} |
@ -0,0 +1,26 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>Shikiryu's exe to zip download proxy</title> |
||||
<style> |
||||
#emailWrapper{display:none;} |
||||
</style> |
||||
<script type="text/javascript"> |
||||
function toggleEmailWrapper(elt){ |
||||
document.getElementById('emailWrapper').style.display = elt.checked ? "inline-block" : "none"; |
||||
} |
||||
</script> |
||||
</head> |
||||
<body> |
||||
<form action="download" method="post"> |
||||
<fieldset> |
||||
<legend>File to proxy</legend> |
||||
<label for="url">URL : </label><input type="text" name="url" id="url" /> |
||||
<label for="toDownloadNow">Download now : </label><input type="checkbox" name="method[]" id="toDownloadNow" value="toDownloadNow" checked="checked" /> |
||||
<label for="toDownloadLater">Download later : </label><input onclick="toggleEmailWrapper(this)" type="checkbox" name="method[]" id="toDownloadLater" value="toDownloadLater" /> |
||||
<div id="emailWrapper"><label for="email">email for the link : </label><input type="email" name="email" id="email" /></div> |
||||
<input type="submit" value="download"/> |
||||
</fieldset> |
||||
</form> |
||||
</body> |
||||
</html> |
@ -0,0 +1,37 @@ |
||||
<?php |
||||
// No display, log everything |
||||
error_reporting(E_ALL); |
||||
ini_set('display_errors', 0); |
||||
ini_set('log_errors', 1); |
||||
ini_set('error_log',dirname(__FILE__).'/error.log'); |
||||
|
||||
// include everything |
||||
include_once 'FileToZip.php'; |
||||
include_once 'FileToZipDispatcher.php'; |
||||
include_once 'ToDownloadIndex.php'; |
||||
include_once 'FileToZipEmail.php'; |
||||
|
||||
$action = filter_input(INPUT_GET, 'action'); |
||||
$possibleActions = array('download', 'form', 'shortcut'); |
||||
|
||||
define('BASE_URL', 'http://mywebsite.com'); |
||||
|
||||
if($action == null || !in_array($action, $possibleActions)){ |
||||
header('HTTP/1.0 404 Not Found'); |
||||
exit; |
||||
} |
||||
|
||||
if($action == 'form'){ |
||||
include_once 'index.html'; |
||||
exit; |
||||
} |
||||
|
||||
if($action == 'download'){ |
||||
include_once 'download.php'; |
||||
exit; |
||||
} |
||||
|
||||
if($action == 'shortcut'){ |
||||
include_once 'shortcut.php'; |
||||
exit; |
||||
} |
@ -0,0 +1,31 @@ |
||||
<?php |
||||
/** |
||||
We need to find the matching file thanks to the todl.txt file |
||||
Read it, send it then delete it from the txt file |
||||
*/ |
||||
$idx = new ToDownloadIndex(); |
||||
|
||||
$shortcut = !empty($_GET['sc']) ? $_GET['sc'] : ''; |
||||
|
||||
if($shortcut == ''){ |
||||
header('HTTP/1.0 404 Not Found'); |
||||
exit; |
||||
} |
||||
|
||||
$file = $idx->readLine($shortcut); |
||||
|
||||
if($file == null || !is_readable(dirname(__FILE__).'/'.$file)){ |
||||
header('HTTP/1.0 404 Not Found'); |
||||
exit; |
||||
} |
||||
|
||||
header("Content-type: application/zip"); |
||||
header("Content-Disposition: attachment; filename=".$file); |
||||
header("Pragma: no-cache"); |
||||
header("Expires: 0"); |
||||
readfile(dirname(__FILE__).'/'.$file); |
||||
unlink(dirname(__FILE__).'/'.$file); |
||||
|
||||
$idx->deleteLine($shortcut); |
||||
|
||||
exit; |
Loading…
Reference in new issue