Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
chore(): download file up
Browse files Browse the repository at this point in the history
  • Loading branch information
Magicalex committed Mar 26, 2017
1 parent 60cfd56 commit 7dcd0d1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 165 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -13,7 +13,8 @@
"symfony/twig-bridge": "^3.2",
"symfony/config": "^3.2",
"symfony/yaml": "^3.2",
"magicalex/write-ini-file": "^1.2"
"magicalex/write-ini-file": "^1.2",
"apfelbox/php-file-download": "^2.1"
},
"authors": [
{
Expand Down
73 changes: 25 additions & 48 deletions src/Controller/DownloadController.php
Expand Up @@ -2,7 +2,10 @@

namespace App\Controller;

use App\Seedbox\Download;
use App\Seedbox\FileConfiguration;
use App\Seedbox\Users;
use App\Seedbox\Utils;
use Apfelbox\FileDownload\FileDownload;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Http\Stream;
Expand All @@ -11,52 +14,26 @@ class DownloadController
{
public function download(ServerRequestInterface $request, ResponseInterface $response, $args)
{
//if ($args['file']) {
//}

$file = __DIR__.'/../../conf/config.ini';

//$stream = new Stream(fopen($file, 'r')); // create a stream instance for the response body

$response->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Content-Disposition', 'attachment; filename="'.basename($file).'"')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->withHeader('Pragma', 'public')
->withHeader('Content-Length', filesize($file));

ob_clean();
flush();
readfile($file);

return $response;
$file = $args['file'];
$host = $request->getServerParams()['HTTP_HOST'];

$username = Utils::getCurrentUser();
$fileini = Utils::getFileini($username);
$user = new Users($fileini, $username);

if ($file == 'filezilla') {
$data = FileConfiguration::filezilla($user, $host);
$file = 'filezilla.xml';
} elseif ($file == 'transdroid') {
$data = FileConfiguration::transdroid($user, $host);
$file = 'settings.json';
} else {
$response->getBody()->write('Aucun fichier trouvé');

return $response->withStatus(404);
}

$fileDownload = FileDownload::createFromString($data);
$fileDownload->sendDownload($file);
}
}

// $downlad = function ($file_config_name, $conf_ext_prog) {
//
// file_put_contents('../conf/users/' . $this->userName . '/' . $file_config_name, $conf_ext_prog);
// set_time_limit(0);
//
// $path_file_name = '../conf/users/' . $this->userName . '/' . $file_config_name;
// $file_name = $file_config_name;
// $file_size = filesize($path_file_name);
//
// ini_set('zlib.output_compression', 0);
// header('Content-Description: File Transfer');
// header('Content-Type: application/octet-stream');
// header('Content-Disposition: attachment; filename="' . $file_name . '"');
// header('Content-Transfer-Encoding: binary');
// header('Expires: 0');
// header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
// header('Pragma: public');
// header('Content-Length: ' . $file_size);
// ob_clean();
// flush();
// readfile($path_file_name);
// //delete file config (transdroid|filezilla) for security.
// unlink('../conf/users/' . $this->userName . '/' . $file_config_name);
// exit;
// }
36 changes: 18 additions & 18 deletions src/Seedbox/Download.php → src/Seedbox/FileConfiguration.php
Expand Up @@ -2,58 +2,58 @@

namespace App\Seedbox;

class Download
class FileConfiguration
{
public static function filezilla(Users $user, $server)
public static function filezilla(Users $user, $host)
{
$filezilla_xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'."\n".
'<FileZilla3>'."\n".
'<Servers>'."\n".
'<Server>'."\n".
'<Host>'.$server['HTTP_HOST'].'</Host>'."\n".
'<Port>'.$user->portFtp().'</Port>'."\n".
'<Host>'.$host.'</Host>'."\n".
'<Port>'.$user->portFtp.'</Port>'."\n".
'<Protocol>0</Protocol>'."\n".
'<Type>0</Type>'."\n".
'<User>'.$user->name().'</User>'."\n".
'<User>'.$user->name.'</User>'."\n".
'<Pass></Pass>'."\n".
'<Logontype>1</Logontype>'."\n".
'<TimezoneOffset>0</TimezoneOffset>'."\n".
'<PasvMode>MODE_DEFAULT</PasvMode>'."\n".
'<MaximumMultipleConnections>0</MaximumMultipleConnections>'."\n".
'<EncodingType>UTF-8</EncodingType>'."\n".
'<BypassProxy>0</BypassProxy>'."\n".
'<Name>seedbox-'.$user->name().'-ftp</Name>'."\n".
'<Name>seedbox-'.$user->username.'-ftp</Name>'."\n".
'<Comments />'."\n".
'<LocalDir />'."\n".
'<RemoteDir />'."\n".
'<SyncBrowsing>0</SyncBrowsing>seedbox-'.$user->name().'-ftp&#x0A;'."\n".
'<SyncBrowsing>0</SyncBrowsing>seedbox-'.$user->username.'-ftp&#x0A;'."\n".
'</Server>'."\n".
'<Server>'."\n".
'<Host>'.$server['HTTP_HOST'].'</Host>'."\n".
'<Port>'.$user->portSftp().'</Port>'."\n".
'<Host>'.$host.'</Host>'."\n".
'<Port>'.$user->portSftp.'</Port>'."\n".
'<Protocol>1</Protocol>'."\n".
'<Type>0</Type>'."\n".
'<User>'.$user->name().'</User>'."\n".
'<User>'.$user->username.'</User>'."\n".
'<Pass></Pass>'."\n".
'<Logontype>1</Logontype>'."\n".
'<TimezoneOffset>0</TimezoneOffset>'."\n".
'<PasvMode>MODE_DEFAULT</PasvMode>'."\n".
'<MaximumMultipleConnections>0</MaximumMultipleConnections>'."\n".
'<EncodingType>Auto</EncodingType>'."\n".
'<BypassProxy>0</BypassProxy>'."\n".
'<Name>seedbox-'.$user->name().'-sftp</Name>'."\n".
'<Name>seedbox-'.$user->username.'-sftp</Name>'."\n".
'<Comments />'."\n".
'<LocalDir />'."\n".
'<RemoteDir />'."\n".
'<SyncBrowsing>0</SyncBrowsing>seedbox-'.$user->name().'-sftp&#x0A;'."\n".
'<SyncBrowsing>0</SyncBrowsing>seedbox-'.$user->username.'-sftp&#x0A;'."\n".
'</Server>'."\n".
'</Servers>'."\n".
'</FileZilla3>';

return $filezilla_xml;
}

public static function transdroid(Users $user, $server)
public static function transdroid(Users $user, $host)
{
$trandroid_data = [
'ui_swipe_labels' => false,
Expand All @@ -70,16 +70,16 @@ public static function transdroid(Users $user, $server)
'search_num_results' => '25',
'servers' => [[
'port' => '443',
'host' => $server['HTTP_HOST'],
'host' => $host,
'ssl' => true,
'type' => 'daemon_rtorrent',
'password' => '',
'os_type' => 'type_linux',
'folder' => $user->scgi_folder(),
'username' => $user->name(),
'folder' => $user->scgi_folder,
'username' => $user->username,
'use_auth' => true,
'name' => 'seedbox-'.$user->name(),
'base_ftp_url' => 'ftp://'.$user->name().'@'.$server['HTTP_HOST'].'/torrents/',
'name' => 'seedbox-'.$user->username,
'base_ftp_url' => 'ftp://'.$user->username.'@'.$host.'/torrents/',
'download_alarm' => true,
'new_torrent_alarm' => true,
'ssl_accept_all' => true
Expand Down
98 changes: 0 additions & 98 deletions src/Seedbox/downloads.old.php

This file was deleted.

0 comments on commit 7dcd0d1

Please sign in to comment.