commit 08d7614cb5d1e3440f6d6022baef4fc8e976c9b2 Author: Chouchen Date: Mon Oct 15 22:24:12 2012 +0200 Creation of the world diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ebd21a --- /dev/null +++ b/.gitignore @@ -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 diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..0d16060 --- /dev/null +++ b/.htaccess @@ -0,0 +1,15 @@ + +order allow,deny +deny from all + + +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 \ No newline at end of file diff --git a/FileToZip.php b/FileToZip.php new file mode 100644 index 0000000..e74a04f --- /dev/null +++ b/FileToZip.php @@ -0,0 +1,54 @@ +_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; + } +} \ No newline at end of file diff --git a/FileToZipDispatcher.php b/FileToZipDispatcher.php new file mode 100644 index 0000000..f10e351 --- /dev/null +++ b/FileToZipDispatcher.php @@ -0,0 +1,42 @@ +_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(); + } +} \ No newline at end of file diff --git a/FileToZipEmail.php b/FileToZipEmail.php new file mode 100644 index 0000000..03b5b55 --- /dev/null +++ b/FileToZipEmail.php @@ -0,0 +1,37 @@ +_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/"); + } +} \ No newline at end of file diff --git a/ToDownloadIndex.php b/ToDownloadIndex.php new file mode 100644 index 0000000..626d7d7 --- /dev/null +++ b/ToDownloadIndex.php @@ -0,0 +1,50 @@ +_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(); + } +} \ No newline at end of file diff --git a/download.php b/download.php new file mode 100644 index 0000000..12e59ff --- /dev/null +++ b/download.php @@ -0,0 +1,22 @@ +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); +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..ac584a0 --- /dev/null +++ b/index.html @@ -0,0 +1,26 @@ + + + + Shikiryu's exe to zip download proxy + + + + +
+
+ File to proxy + + + +
+ +
+
+ + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..c51821a --- /dev/null +++ b/index.php @@ -0,0 +1,37 @@ +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; \ No newline at end of file diff --git a/todl.txt b/todl.txt new file mode 100644 index 0000000..e69de29