Created windows download logic
This commit is contained in:
parent
810a369059
commit
a41fc59c10
|
@ -1,12 +1,14 @@
|
|||
{
|
||||
"name": "sikofitt/tor-spider",
|
||||
"description": "Tor Spider",
|
||||
"type": "library",
|
||||
"type": "project",
|
||||
"license": "GPL-3.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "sikofitt",
|
||||
"email": "sikofitt@gmail.com"
|
||||
"email": "sikofitt@gmail.com",
|
||||
"role": "Developer",
|
||||
"homepage": "http://rewiv.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
|
@ -16,8 +18,9 @@
|
|||
},
|
||||
"require": {
|
||||
"php": ">=5.5",
|
||||
"megahertz/guzzle-tor": "^1.0",
|
||||
"ext-curl":"*",
|
||||
"guzzlehttp/guzzle": "^6.2",
|
||||
"megahertz/guzzle-tor": "^1.0",
|
||||
"symfony/browser-kit": "^2.8",
|
||||
"symfony/css-selector": "^2.8",
|
||||
"symfony/process": "^2.8",
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "7a82807babab3d996722517a360f1566",
|
||||
"content-hash": "c31f2eb8e902c95a35f2557762156959",
|
||||
"hash": "f32953690bad3de29ca6b2542acc1b29",
|
||||
"content-hash": "149eb0993f5007ea0ffa28c7f9762f3b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
|
@ -2219,7 +2219,8 @@
|
|||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=5.5"
|
||||
"php": ">=5.5",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"platform-overrides": {
|
||||
|
|
|
@ -10,13 +10,29 @@ namespace Sikofitt\OS;
|
|||
|
||||
|
||||
class OSReleaseProber {
|
||||
const DEBIAN_DIST = 1;
|
||||
const GENTOO_DIST = 2;
|
||||
const REDHAT_DIST = 3;
|
||||
const WINDOWS = 4;
|
||||
private $releaseType;
|
||||
|
||||
public function getReleaseFile()
|
||||
{
|
||||
|
||||
if(in_array(PHP_OS, array('WIN', 'WINNT'), false)) {
|
||||
return self::WINDOWS;
|
||||
}
|
||||
if(file_exists('/etc/gentoo-release')) {
|
||||
return self::GENTOO_DIST;
|
||||
}
|
||||
if(file_exists('/etc/redhat-release')) {
|
||||
return self::REDHAT_DIST;
|
||||
}
|
||||
if(file_exists('/etc/debian-release')) {
|
||||
return self::DEBIAN_DIST;
|
||||
}
|
||||
}
|
||||
|
||||
public function ParseReleaseFile()
|
||||
private function parseReleaseFile()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
namespace Sikofitt\Tor\Console\Command;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Sikofitt\OS\OSReleaseProber;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -29,7 +30,7 @@ class TorDownloadCommand extends Command {
|
|||
const TOR_APT_COMMAND = 'apt-get install tor -y'; //etc/os-release
|
||||
const TOR_EMERGE_COMMAND = 'emerge -v net-misc/tor'; //etc/os-release
|
||||
const TOR_YUM_COMMAND = 'yum install tor'; //etc/redhat-release
|
||||
|
||||
const TOR_WINDOWS_COMMAND = '\tor-win32-0.2.8.11\Tor\tor.exe';
|
||||
private $downloadUrls = [
|
||||
'linux' => [
|
||||
'file' => 'https://www.torproject.org/dist/tor-0.2.9.8.tar.gz',
|
||||
|
@ -38,7 +39,8 @@ class TorDownloadCommand extends Command {
|
|||
'b64' => 'LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSWNCQUFCQWdBR0JRSllWL043QUFvSkVHcis1dFNla3JZQkxPMFAvMGpxYU5GbW0vOVQxOGlUWFE1eWg1SWcKZVNqRENWZndvSFhCSXFjTC9GbGc0dkxGOWlaSEFDNWhTVU5BTjA1VVcrSWRFcllpb1lNSGFpdW5EbGJEdEh3Nwp2N2FRTDY0eHMxaWxJamh5Q0VlWXdqYXU0L0gwci9kVFNvREw1eFozOGpsOFlMY21MVXBmaDFmcWxxb1prbENTCnZDdHc5dDhsb2ppSlVZK1pyNVZCd1hrL2h4LzdEM2tSVzcxRzJBYTh6ODMxMFN3Q1JjRy8xTnh6dElQdlJWczAKeDZFYlorMTk1Zk1CMUwyL0FHeHFDSmdyeGQrekNqRGp2dGh6S0wrbldrTkQrUUk0MStmRTNiWUdFVHRkZ1B0Tgp0WkVlQU9sUVV3Ujl5RW5FbjlQYlpyQzdVZktCaFBtV0hFM3BSNzltUzNVa0ZVcWJXSUVkUVJrcDIvODh4RFpWCi9hbUtMMWdoVCtOUStCMXUrenJQamhvSGFHZzZRaUp0eGQzTTVMdHZjdytjUU1KblZKeFlTdXRYVXA4Y0c0WUIKN2UrQVhyM2szWTg5OTV1MUJ5UC9uYzd6ekdtSnJTZitSV3RuYnN6d01kK0x1RWpjajQ1TUY4MU84WHdlbXVtcwp2anorWGpzWUJPMDJuSXpYVUNKWER6QURGSlJTbEtRWDh2Y0haTXVtOVg2Rnl4eUp6MXF6TFlBL1dkWUtKMjdFCk11Yk9pSzZua3BmR3dRY1pFbFNCcjI3M1hvR01zRlFTTlZ0SHJnNEtiT2wyVm5ha2lObFVJZVlteFdadlkraisKUll3allpcVk4SjVCSDBId1pYcFBNU0MvSGV1d3I4K1o2bFJ2bXVoVDBpQU03cXNYdHJ2YzYwdCtVQ1RQSTU4cgp5L0t1NDI1VThIa1BuSkRpVVdGQwo9THZtOQotLS0tLUVORCBQR1AgU0lHTkFUVVJFLS0tLS0K',
|
||||
],
|
||||
'windows' => [
|
||||
'file' => 'https://www.torproject.org/dist/torbrowser/6.0.8/tor-win32-0.2.8.11.zip',
|
||||
'file' => 'http://www.torproject.org/dist/torbrowser/6.0.8/tor-win32-0.2.8.11.zip',
|
||||
'filename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JzSzZUVi9kZnFVdTVjdVU1ekVWLwpBbTNSRjJHQU5vUUg4TzVFS0Z1Vgo9ZnBPOQotLS0tLUVORCBQR1AgU0lHTkFUVVJFLS0tLS0K',
|
||||
],
|
||||
|
@ -57,20 +59,41 @@ class TorDownloadCommand extends Command {
|
|||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if(false === file_exists($this->baseDir . '/' . $this->downloadUrls['linux']['filename']))
|
||||
{
|
||||
$guzzle = new Client();
|
||||
$file = $guzzle->get($this->downloadUrls['linux']['file']);
|
||||
file_put_contents($this->baseDir . '/' . $this->downloadUrls['linux']['filename'], $file->getBody()->getContents());
|
||||
}
|
||||
$prober = new OSReleaseProber();
|
||||
$dist = $prober->getReleaseFile();
|
||||
switch($dist) {
|
||||
case OSReleaseProber::DEBIAN_DIST;
|
||||
default:
|
||||
$command = self::TOR_APT_COMMAND;
|
||||
break;
|
||||
case OSReleaseProber::REDHAT_DIST;
|
||||
$command = self::TOR_YUM_COMMAND;
|
||||
break;
|
||||
case OSReleaseProber::GENTOO_DIST;
|
||||
$command = self::TOR_EMERGE_COMMAND;
|
||||
break;
|
||||
case OSReleaseProber::WINDOWS;
|
||||
$command = self::TOR_WINDOWS_COMMAND;
|
||||
break;
|
||||
}
|
||||
if($command !== self::TOR_WINDOWS_COMMAND) {
|
||||
print 'run ' . $command . ' to install tor';
|
||||
exit;
|
||||
}
|
||||
$fileData = $this->downloadUrls['windows'];
|
||||
|
||||
$tar = new ProcessBuilder();
|
||||
$tar->setPrefix('/bin/tar')
|
||||
->setWorkingDirectory($this->baseDir)
|
||||
->setArguments(array('-zxvf', $this->downloadUrls['linux']['filename']));
|
||||
$process = $tar->getProcess();
|
||||
$process->run();
|
||||
if(false === file_exists($this->baseDir . '/' . $this->downloadUrls['windows']['filename'])) {
|
||||
$guzzle = new Client(['verify' => false]);
|
||||
|
||||
$file = $guzzle->get($this->downloadUrls['windows']['file']);
|
||||
|
||||
file_put_contents($this->baseDir . '/' . $this->downloadUrls['windows']['filename'], $file->getBody()->getContents());
|
||||
}
|
||||
$zip = new \ZipArchive($this->baseDir . '/' . $this->downloadUrls['windows']['filename']);
|
||||
|
||||
$zip->open($this->baseDir . '/' . $this->downloadUrls['windows']['filename']);
|
||||
$zip->extractTo($this->baseDir . '/tor');
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue