Skip to content

Instantly share code, notes, and snippets.

@danieltroger
Created November 23, 2014 16:01
Show Gist options
  • Save danieltroger/1839e3a92c971a633566 to your computer and use it in GitHub Desktop.
Save danieltroger/1839e3a92c971a633566 to your computer and use it in GitHub Desktop.
Get and extract imagr from github. Dirty but works. Uses 2MB RAM max.
<?php
$od = $_REQUEST['dir'];
$ul = $_REQUEST['ul'];
if($ul == "true"){$ul = true;}else{$ul = false;}
if(is_dir($od) || file_exists($od) || strlen($od) < 3 || strpos($od,"..") !== false){die("u made shit, dir is undefined");}
$server = "codeload.github.com";
$sock = fsockopen("ssl://" . $server,443);
fputs($sock,"GET /danieltroger/imagr/zip/master HTTP/1.1\nHost: {$server}\r\n\r\n");
$h = fopen("tmp.zip","w");
$p = false;
while($data = fread($sock,1048576))
{
if(!$p)
{
$l = explode("\r\n\r\n",$data);
unset($l[0]);
fwrite($h,implode("\r\n\r\n",$l));
$p = true;
}
else
{
fwrite($h,$data);
}
}
fclose($h);
fclose($sock);
$zip = new ZipArchive;
$zip->open("tmp.zip");
$zip->extractTo('.');
$zip->close();
unlink("tmp.zip");
if(!$ul){unlink("imagr-master/upload.php");}
rename("imagr-master",$od);
header("Location: {$od}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment