Skip to content

Commit

Permalink
Merge pull request #34 from e-alfred/add-referrer-useragent
Browse files Browse the repository at this point in the history
Add referer and useragent setting for FTP and HTTP downloads
  • Loading branch information
e-alfred authored Sep 19, 2017
2 parents 31b40d0 + 93f0754 commit c60cc8d
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 107 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ You have to install Aria2 on your system. To do this on Debian/Ubuntu you can us

After that, you have to run Aria2 on every boot with the same user that your webserver is running:

`sudo -u www-data aria2c --enable-rpc --rpc-allow-origin-all -c -D --log=/var/log/aria2.log --check-certificate=false --save-session=/var/www/aria2c.sess --save-session-interval=2 --continue=true --input-file=/var/www/aria2c.sess --rpc-save-upload-metadata=true --force-save=true --log-level=warn`
`sudo -u www-data aria2c --enable-rpc --rpc-allow-origin-all -c -D --log=/var/log/aria2.log --check-certificate=false --save-session=/var/local/aria2c.sess --save-session-interval=2 --continue=true --input-file=/var/local/aria2c.sess --rpc-save-upload-metadata=true --force-save=true --log-level=warn`

You have to enable the RPC interface and save the session file of Aria2, otherwise your old downloads won't be listed after you restart Aria2. The file in the example is stored in /var/www/aria2c.sess, but you can put it anywhere as long as the user running your webserver can access/write to it.
You have to enable the RPC interface and save the session file of Aria2, otherwise your old downloads won't be listed after you restart Aria2. The file in the example is stored in /var/local/aria2c.sess, but you can put it anywhere as long as the user running your webserver can access/write to it.

You can find the documentation of Aria2 [here](https://aria2.github.io/manual/en/html/index.html).

Expand Down
6 changes: 6 additions & 0 deletions controller/ftpdownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public function add()
$OPTIONS['ftp-user'] = $_POST['OPTIONS']['FTPUser'];
$OPTIONS['ftp-passwd'] = $_POST['OPTIONS']['FTPPasswd'];
}
if (isset ($_POST['OPTIONS']['FTPReferer']) && strlen (trim ($_POST['OPTIONS']['FTPReferer'])) > 0) {
$OPTIONS['referer'] = $_POST['OPTIONS']['FTPReferer'];
}
if (isset ($_POST['OPTIONS']['FTPUseragent']) && strlen (trim ($_POST['OPTIONS']['FTPUseragent'])) > 0) {
$OPTIONS['user-agent'] = $_POST['OPTIONS']['FTPUseragent'];
}
if (isset($_POST['OPTIONS']['FTPPasv']) && strlen(trim($_POST['OPTIONS']['FTPPasv'])) > 0) {
$OPTIONS['ftp-pasv'] = strcmp($_POST['OPTIONS']['FTPPasv'], "true") == 0 ? true : false;
}
Expand Down
6 changes: 6 additions & 0 deletions controller/httpdownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public function add()
$OPTIONS['http-user'] = $_POST['OPTIONS']['HTTPUser'];
$OPTIONS['http-passwd'] = $_POST['OPTIONS']['HTTPPasswd'];
}
if (isset ($_POST['OPTIONS']['HTTPReferer']) && strlen (trim ($_POST['OPTIONS']['HTTPReferer'])) > 0) {
$OPTIONS['referer'] = $_POST['OPTIONS']['HTTPReferer'];
}
if (isset ($_POST['OPTIONS']['HTTPUseragent']) && strlen (trim ($_POST['OPTIONS']['HTTPUseragent'])) > 0) {
$OPTIONS['user-agent'] = $_POST['OPTIONS']['HTTPUseragent'];
}
if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress)
&& $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
$OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
Expand Down
58 changes: 33 additions & 25 deletions js/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Xavier Beurois <www.sgc-univ.net>
* @copyright Xavier Beurois 2015
*/

$(document).ready (function ()
{
$('#ball').Badger ('...');
Expand All @@ -16,9 +16,9 @@ $(document).ready (function ()
$('#bwaitings').Badger ('...');
$('#bstopped').Badger ('...');
$('#bremoved').Badger ('...');

OCDLR.Utils.UpdateQueue (true, 'add');

// Display or hide the "New Download" menu
$('#NewDL').bind ('click', function ()
{
Expand All @@ -31,7 +31,7 @@ $(document).ready (function ()
$(this).children ('ul').show ();
}
});

// Display or hide content pages depending on the "New Download" menu
$('#NewDL').children ('div').children ('p').bind ('click', function ()
{
Expand All @@ -43,72 +43,80 @@ $(document).ready (function ()
$('#app-content-wrapper .content-page').hide ();
$('#app-content-wrapper .content-page[rel=' + $(this).attr ('data-rel') + ']').show ();
});

// Default options
$('#option-ftp-pasv').prop ('checked', true);
$('#option-yt-extractaudio').prop ('checked', false);
$('#option-yt-forceipv4').prop ('checked', true);
$('#option-bt-rmtorrent').prop ('checked', true);

// Load torrent files when opening the available torrents list
$('#TorrentsList').bind ('click', function ()
{
OCDLR.Utils.GetTorrentsList ($(this).children ('ul'));
});

// Launch HTTP download
$('#app-content-wrapper .content-page[rel=OCDHTTP] div.launch').bind ('click', function ()
{
var InputURL = $(this).parent ().parent ().children ('input.url');

if (OCDLR.Utils.ValidURL (InputURL.val ()))
{
OCDLR.Utils.AddDownload ($(this), 'http', InputURL.val (),
{
HTTPUser: $('#option-http-user').val (),
HTTPPasswd: $('#option-http-pwd').val ()
HTTPPasswd: $('#option-http-pwd').val (),
HTTPReferer: $('#option-http-referer').val (),
HTTPUseragent: $('#option-http-useragent').val ()
});
}
else
{
OCDLR.Utils.PrintError (t ('ocdownloader', 'Invalid URL. Please check the address of the file ...'));
}

InputURL.val ('');
$('#option-http-user').val ('');
$('#option-http-pwd').val ('');
$('#option-http-referer').val ('');
$('#option-http-useragent').val ('');
});

// Launch FTP download
$('#app-content-wrapper .content-page[rel=OCDFTP] div.launch').bind ('click', function ()
{
var InputURL = $(this).parent ().parent ().children ('input.url');

if (OCDLR.Utils.ValidURL (InputURL.val ()))
{
OCDLR.Utils.AddDownload ($(this), 'ftp', InputURL.val (),
{
FTPUser: $('#option-ftp-user').val (),
FTPPasswd: $('#option-ftp-pwd').val (),
FTPPasv: $('#option-ftp-pasv').prop ('checked')
FTPPasv: $('#option-ftp-pasv').prop ('checked'),
FTPReferer: $('#option-ftp-referer').val (),
FTPUseragent: $('#option-ftp-useragent').val ()
});
}
else
{
OCDLR.Utils.PrintError (t ('ocdownloader', 'Invalid URL. Please check the address of the file ...'));
}

InputURL.val ('');
$('#option-ftp-user').val ('');
$('#option-ftp-pwd').val ('');
$('#option-ftp-pasv').prop ('checked', true);
$('#option-ftp-referer').val ('');
$('#option-ftp-useragent').val ('');
});

// Launch YT download
$('#app-content-wrapper .content-page[rel=OCDYT] div.launch').bind ('click', function ()
{
var InputURL = $(this).parent ().parent ().children ('input.url');

if (OCDLR.Utils.ValidURL (InputURL.val ()))
{
OCDLR.Utils.AddDownload ($(this), 'yt', InputURL.val (),
Expand All @@ -121,30 +129,30 @@ $(document).ready (function ()
{
OCDLR.Utils.PrintError (t ('ocdownloader', 'Invalid URL. Please check the address of the file ...'));
}

InputURL.val ('');
$('#option-yt-extractaudio').prop ('checked', false);
$('#option-yt-forceipv4').prop ('checked', true);
});

// Launch BT download
$('#app-content-wrapper .content-page[rel=OCDBT] div.launch').bind ('click', function ()
{
var InputFile = $('#TorrentsList').children ('a');
var SELECTTEXT = t ('ocdownloader', 'Select a file.torrent');

if (InputFile.text ().trim () != SELECTTEXT.trim () && InputFile.prop ('data-rel') == 'File')
{
OCDLR.Utils.AddDownload ($(this), 'bt', InputFile.text (),
{
BTRMTorrent: $('#option-bt-rmtorrent').prop ('checked')
});
}

InputFile.text (SELECTTEXT);
$('#option-bt-rmtorrent').prop ('checked', true);
});

var FileUpload = $('#app-content-wrapper .content-page[rel=OCDBT] div.uploadfile #uploadfile').fileupload (
{
autoUpload: true,
Expand All @@ -155,7 +163,7 @@ $(document).ready (function ()
FileUpload.on ('fileuploadstart', function (E, Data)
{
$('#TorrentsList').children ('ul').hide ();

$('#app-content-wrapper .content-page[rel=OCDBT] div.uploadfile label').removeClass ('icon-upload');
$('#app-content-wrapper .content-page[rel=OCDBT] div.uploadfile label').addClass ('icon-loading-small');
$('#app-content-wrapper .content-page[rel=OCDBT] div.uploadfile input').prop('disabled', true);
Expand All @@ -170,7 +178,7 @@ $(document).ready (function ()
{
OCDLR.Utils.PrintError (Data.result.MESSAGE);
}

$('#app-content-wrapper .content-page[rel=OCDBT] div.uploadfile input').prop('disabled', false);
$('#app-content-wrapper .content-page[rel=OCDBT] div.uploadfile label').removeClass ('icon-loading-small');
$('#app-content-wrapper .content-page[rel=OCDBT] div.uploadfile label').addClass ('icon-upload');
Expand All @@ -179,6 +187,6 @@ $(document).ready (function ()
{
OCDLR.Utils.PrintError (t ('ocdownloader', 'Error while uploading torrent file'));
});

OCDLR.Utils.GetCounters ();
});
});
3 changes: 1 addition & 2 deletions js/add.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c60cc8d

Please sign in to comment.