TorrentFlux.com Welcome, Guest. Please login or register.
03-21-2010, 21:00:53
Home Help Search Login Register donate
TorrentFlux Home | TorrentFlux Hosting

+  TorrentFlux Forums
|-+  Code Hacks and Tools
| |-+  TorrentFlux 2.1 Hacks
| | |-+  Move and Rename files/folders Hack and unRAR Hack Password extension
« previous next »
Pages: [1] 2 3  All Go Down Print
Author Topic: Move and Rename files/folders Hack and unRAR Hack Password extension  (Read 22677 times)
nu_pagadi
Newbie
*
Offline Offline

Posts: 6



View Profile
« on: 06-16-2006, 05:38:36 »

Hi @all,
I wrote for the TorrentFlux 2.1-b4rt-85 the following Hacks. I hope some of you like it.

Move Hack
With this hack is it possible zu move files/folders to a specified destination
on the own server. I also added categories, which are subfolders in the
destination folder.
The destination and categories must be set in the admin settings area.

Here how to install the Move Hack

modify admin.php
Search:
Code:
<tr><td colspan="2" align="center" bgcolor="<?php echo($cfg["table_header_bg"]); ?>"><strong>Bins</strong></td></tr>

Insert before that row this:
   
Code:
<!--// Move Hack -->
<?php include('move_extensionSettings.php'); ?>

Search:
Code:
function updateConfigSettings() {
    global $cfg;
Insert after that:
   
Code:
// move hack...
include('move_functions.php');
createCategoryFolders();

modify dir.php
Search:
Code:
if ($cfg['enable_sfvcheck'] == 1) {

Insert before that row this:
   
Code:
// rename hack
include('rename_dir_extension.php');

Search:
Code:
if ($cfg['enable_rar'] == 1) {

Insert before that row this:
   
Code:
// rename hack
include('rename_dir_extension.php');


modify config.php
Insert before the last "?>" this:
Code:
// include move hack
include('move_const.php');

Copy the following files into the tf folder (all of them are in the move_hack.tar):
   move.php
   move_const.php
   move_dir_extension.php
   move_extensionSetting.js
   move_extensionSettings.php
   move_functions.php
   images/_move.gif

================================================================
Rename Hack
With this hack is it possible zu rename files/folders in the TF directory.

Install Rename Hack
modify admin.php
Search:
Code:
<tr><td colspan="2" align="center" bgcolor="<?php echo($cfg["table_header_bg"]); ?>"><strong>Bins</strong></td></tr>

Insert before that row this:
Code:
<!--// rename files Hack -->
<?php include('rename_extensionSettings.php'); ?>

modify dir.php
Search:
Code:
if ($cfg['enable_sfvcheck'] == 1) {

Insert before that row this:
Code:
// move hack
include('rename_dir_extension.php');

Search:
Code:
if ($cfg['enable_rar'] == 1) {

Insert before that row this:
Code:
// move hack
include('rename_dir_extension.php');

modify config.php
Insert before the last "?>" this:
Code:
//include rename hack
include('rename_const.php');

Copy the following files into the tf folder (all of them are in the rename_hack.tar):
   renameFolder.php
   rename_const.php
   rename_dir_extension.php
   rename_extensionSettings.php
   images/rename.gif
=================================================================
unRAR Hack Password Extension
Extend UnRAR Hack with Password support
I added to the usual UnRAR Hack a Passwordfield for rar files that needs a password
for extraction.
Just enter the right password and hit OK. Thats all then.

modify uncompress.php

Search:
Code:
$arg4 = $argv[4];
Replace with:
Code:
$arg4 = $argv[5];
$arg5 = $argv[4];

Search:
Code:
$Command = escapeshellarg($arg4)." x " . escapeshellarg($arg1) . " " . escapeshellarg($arg2);
Replace with:
Code:
$Command = escapeshellarg($arg4)." x -p". $arg5 ." ". escapeshellarg($arg1) . " " . escapeshellarg($arg2);

Replace the umcomp.php with the one attached in unRAR_hack.zip.

If someone wants to implement all hacks, just extract the allhacks.zip into your TF folder and add
Code:
// include move hack
include('move_const.php');

//include rename hack
include('rename_const.php');
into config.php.
« Last Edit: 06-16-2006, 15:24:02 by nu_pagadi » Logged
Paczesiowa
Full Member
***
Offline Offline

TF Base: Linux 2.x
Posts: 177



View Profile
« Reply #1 on: 06-16-2006, 07:17:43 »

that move hack looks great!
but cant get it to work:
1)
there is no
Code:
<tr><td colspan="2" align="center" bgcolor="<?php echo($cfg["table_header_bg"]); ?>"><strong>Bins</strong></td></tr>
in my admin.php but there is:
Code:
echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\"><div align=\"center\">";

2) I cant find
Code:
if ($cfg['enable_sfvcheck'] == 1) {
cause I don't use sfv hack so I put it somewhere else

3)
Code:
// rename hack
include('rename_dir_extension.php');
that's not move hack:]

but all these are minors
my problem is this hack is disabled in admin.php and I cant enable it (it'a always grayed out and "enable move files" is set to false and after page reload it gets back to false:/ I cant use ur admin.php because of unrecognized function smthsuperadminlink blah blah. does this code use sql? because I have sqlite not mysql.
« Last Edit: 06-16-2006, 07:19:15 by Paczesiowa » Logged

nu_pagadi
Newbie
*
Offline Offline

Posts: 6



View Profile
« Reply #2 on: 06-16-2006, 11:53:50 »

Hi,
what Torrentflux version do you use? The HowTo is for torrentflux TorrentFlux 2.1-b4rt-85, if you want to implement the hack into the usuall Torrentflux use following:

Move Hack
modify admin.php
Search:
Code:
</table>
        <br>
        <input type="Submit" value="Update Settings">

Insert before that row this:
   
Code:
<!--// Move Hack -->
<?php include('move_extensionSettings.php'); ?>

Search:
Code:
function updateConfigSettings() {
    global $cfg;
Insert after that:
   
Code:
// move hack...
include('move_functions.php');
createCategoryFolders();

modify dir.php
Search:
Code:
                // download
                if ($cfg["enable_file_download"])

Insert before that row this:
   
Code:
// move hack
include('move_dir_extension.php');

Search again for:
Code:
                // download
                if ($cfg["enable_file_download"])

And intert before that row again this:
   
Code:
// move hack
include('move_dir_extension.php');

modify config.php
Insert before the last "?>" this:
Code:
// include move hack
include('move_const.php');

Copy the following files into the tf folder (all of them are in the move_hack.tar):
   move.php
   move_const.php
   move_dir_extension.php
   move_extensionSetting.js
   move_extensionSettings.php
   move_functions.php
   images/_move.gif

================================================================
Rename Hack
With this hack is it possible zu rename files/folders in the TF directory.

Install Rename Hack
modify admin.php
Search:
Code:
</table>
        <br>
        <input type="Submit" value="Update Settings">

Insert before that row this:
Code:
<!--// rename files Hack -->
<?php include('rename_extensionSettings.php'); ?>

modify dir.php
Search:
Code:
                // download
                if ($cfg["enable_file_download"])

Insert before that row this:
Code:
// move hack
include('rename_dir_extension.php');

Search again for:
Code:
                // download
                if ($cfg["enable_file_download"])

And intert before that row again this:
   
Code:
// move hack
include('rename_dir_extension.php');


modify config.php
Insert before the last "?>" this:
Code:
//include rename hack
include('rename_const.php');

Copy the following files into the tf folder (all of them are in the rename_hack.tar):
   renameFolder.php
   rename_const.php
   rename_dir_extension.php
   rename_extensionSettings.php
   images/rename.gif
=================================================================
unRAR Hack Password Extension
This Hack will only work, if the unRAR Hack is already implemented. So please implement the unRAR Hack before.

Extending the usual UnRAR Hack a Passwordfield for rar files that needs a password
for extraction.
Just enter the right password and hit OK. Thats all then.

modify uncompress.php

Search:
Code:
$arg4 = $argv[4];
Replace with:
Code:
$arg4 = $argv[5];
$arg5 = $argv[4];

Search:
Code:
$Command = escapeshellarg($arg4)." x " . escapeshellarg($arg1) . " " . escapeshellarg($arg2);
Replace with:
Code:
$Command = escapeshellarg($arg4)." x -p". $arg5 ." ". escapeshellarg($arg1) . " " . escapeshellarg($arg2);

Replace the umcomp.php with the one attached in unRAR_hack.zip.

If someone wants to implement all hacks, just extract the allhacks.zip into your TF folder and add
Code:
// include move hack
include('move_const.php');

//include rename hack
include('rename_const.php');
into config.php.

Quote
but all these are minors
my problem is this hack is disabled in admin.php and I cant enable it (it'a always grayed out and "enable move files" is set to false and after page reload it gets back to false:/ I cant use ur admin.php because of unrecognized function smthsuperadminlink blah blah. does this code use sql? because I have sqlite not mysql.

My code doesn't use sql. I just use the code from torrentflux.
Which browser do you use? I found a bug in move_extensionSettings.js. The Hack didn't work with the Internet Explorer, but I corrected it. Please replace the file with the one in the attachments.

I hope I could help.
« Last Edit: 06-16-2006, 15:29:10 by nu_pagadi » Logged
b4rt
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 543



View Profile WWW
« Reply #3 on: 06-16-2006, 12:26:33 »


hi nu_pagadi,

first impression after flying over thread is "clean and well done" so i cant wait to check out your code later Smiley

regards,
b4rt
Logged

torrentflux-b4rt svn-trunk
Linux 2.4.34.1, Apache 2.0.59, PHP 4.4.5, Perl 5.8.8, Python 2.5, MySQL 4.1.22
Paczesiowa
Full Member
***
Offline Offline

TF Base: Linux 2.x
Posts: 177



View Profile
« Reply #4 on: 06-16-2006, 12:27:38 »

ok now it's better:]
I can see move icons in dir.php (but why only with directories? I want to move files too) but when I click it and choose option there is error:
Code:
mv: cannot move `/data/bittornado/paczesiowa/1' to `/var/www/***/files/Filmy': No such file or directory
An error accured, please try again!

first path is correct but no idea where did second path come from... I choosed path like "/data/Filmy" and I don't use vhost I'm not even german:D
and when I look inside Filmy dir there is another dir Filmy created (what for?) and 2 directories with names like "Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?Huh?" when I try to enter them with mc, it crashes

EDIT:
that was when I choosed category name. choosing blank option says "done" but it doesnt move files and again plenty of weird "??" directories
« Last Edit: 06-16-2006, 17:29:24 by Paczesiowa » Logged

nu_pagadi
Newbie
*
Offline Offline

Posts: 6



View Profile
« Reply #5 on: 06-16-2006, 15:25:56 »

Quote
I can see move icons in dir.php (but why only with directories? I want to move files too) but when I click it and choose option there is error

Again my Fault if forgot to show, that you have to Search in the dir.php for the second
Code:
if ($cfg["enable_file_download"]) {

Insert before that row this:
Code:
// move hack
include('move_dir_extension.php');

The first one is for directories and the second one is for the other entries like rar files and so on...

I also corrected my posts before.


Quote
first path is correct but no idea where did second path come from...
I found the bug, sorry, didn't see it before  :'(
Just replace the the files attached in this reply.

Quote
I look inside Filmy dir there is another dir Filmy created (what for?)
Hmm thats realy weird. should never happen. I also don't know what the Huh?Huh?Huh? files are coming from. Sorry.
But I think the files are not from the Hack, because I use only the "mv" command.


Regards,

nu_pagadi
Logged
b4rt
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 543



View Profile WWW
« Reply #6 on: 06-16-2006, 18:01:19 »

Quote
I can see move icons in dir.php (but why only with directories? I want to move files too) but when I click it and choose option there is error

Again my Fault if forgot to show, that you have to Search in the dir.php for the second
Code:
if ($cfg["enable_file_download"]) {

Insert before that row this:
Code:
// move hack
include('move_dir_extension.php');

The first one is for directories and the second one is for the other entries like rar files and so on...

I also corrected my posts before.


Quote
first path is correct but no idea where did second path come from...
I found the bug, sorry, didn't see it before  :'(
Just replace the the files attached in this reply.

Quote
I look inside Filmy dir there is another dir Filmy created (what for?)
Hmm thats realy weird. should never happen. I also don't know what the Huh?Huh?Huh? files are coming from. Sorry.
But I think the files are not from the Hack, because I use only the "mv" command.


Regards,

nu_pagadi

i am just integrating this and found a source for possible errors (maybe the "weird dirs" Paczesiowa mentioned come from this)

you are not presetting the config-vars with values. (database) thats not so a big problem for the "booleans" as they are just wrong if not present and are set to true when submiting admin-form.
you can run into problems in the case of the other fields move_path and move_categories. eg on a talky php they are preset with a notice-message with html-markup which is no good for a "dir-string".
eg i just had this in one of those fields (complete with newlines and all ~):
Code:

<br />
<b>Notice</b>:  Undefined index:  move_categories in <b>/var/www/admin.php</b> on line <b>2194</b><br />


i guess with such strings in path + category-fields the code processing this may freak out.

presets for all used vars may be a wise thing to do.
(have in mind presetting enable-bools to 1, and move-path to something like /usr/local/torrent/username/incoming, dunno at categories.. didnt look into that so far)

EDIT: erm i just noticed a specific move-path per user is not possible how things are now. maybe this var just should be a suffix and concatenated to the dir /usr/local/torrent/username/.
(still wouldnt be settable per user but a suitable default)

regards,
b4rt
« Last Edit: 06-16-2006, 18:11:06 by b4rt » Logged

torrentflux-b4rt svn-trunk
Linux 2.4.34.1, Apache 2.0.59, PHP 4.4.5, Perl 5.8.8, Python 2.5, MySQL 4.1.22
Paczesiowa
Full Member
***
Offline Offline

TF Base: Linux 2.x
Posts: 177



View Profile
« Reply #7 on: 06-16-2006, 18:05:27 »

ok moving files to "blank" option works fine now. those categories dont: creating new category = 1 or 2  ? ? ? ? ? ? ? directories:/

IMO this category aproach doesn't make sense because this forces user to have one 'move' directory and 1 subdirectory inside it for each category. better aproach would be to have pairs <name,path> and display names in move.php and moving them to corresponding paths which can be unrelated to each other. and this wouldn't require to create directories (because updating settings with new categories makes these Huh? dirs) so there shouldnt be errors.
Logged

b4rt
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 543



View Profile WWW
« Reply #8 on: 06-16-2006, 18:39:37 »

after setting move_categories to empty string and adding a test-entry it is still creating weird dirs.

thats what is in the field in the database (with newline):
Code:

;test

to fix the weird dir-creation i did this:

change in admin.php :
Code:
<input type="hidden" name="move_categories" value="
<?php if ($cfg["enable_move"]) {
echo $cfg["move_categories"];
}
?>
">

to (just remove newlines inside param) :
Code:
<input type="hidden" name="move_categories" value="<?php if ($cfg["enable_move"]) { echo $cfg["move_categories"]; } ?> ">

EDIT: to solve more probs i did :

changed in function updateConfigSettings in admin.php :
Code:
createCategoryFolders();
to this:
Code:
// move hack
unset($_POST['addCatButton']);
unset($_POST['remCatButton']);
unset($_POST['categorylist']);
unset($_POST['category']);
$_POST["move_categories"] = trim($_POST["move_categories"]);
if ($_POST["enable_move"])
  createCategoryFolders();


EDIT: current version of function createCategoryFolders :
Code:
function createCategoryFolders() {
$movePath = $_POST['move_path'];
// add a slash at the end if needed...
if(substr($movePath, strlen($movePath)) != "/")
$movePath .= "/";
// create the needed folders...
if ((isset($_POST["move_categories"])) && (strlen($_POST["move_categories"]) > 0)) {
    $cats = split(";",$_POST["move_categories"]);
    for ($index = 0; $index < count($cats); $index++) {
    $target = trim($movePath.$cats[$index]);
    if ((strlen($target) > 0) && ((substr($target, 0, 1)) != ";"))
      checkDirectory($target,0777);
    }
}
}

where function checkDirectory is defined as :
Code:
/**
 * checks a dir. recursive process to emulate "mkdir -p" if dir not present
 *
 * @param $dir the name of the dir
 * @param $mode the mode of the dir if created. default is 0755
 * @return boolean if dir exists/could be created
 */
function checkDirectory($dir, $mode = 0755) {
  if ((is_dir($dir) && is_writable ($dir)) || @mkdir($dir,$mode))
    return true;
  if (! checkDirectory(dirname($dir),$mode))
    return false;
  return @mkdir($dir,$mode);
}


now cat-list is safed without the empty first field.


regards,
b4rt
« Last Edit: 06-16-2006, 20:20:01 by b4rt » Logged

torrentflux-b4rt svn-trunk
Linux 2.4.34.1, Apache 2.0.59, PHP 4.4.5, Perl 5.8.8, Python 2.5, MySQL 4.1.22
b4rt
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 543



View Profile WWW
« Reply #9 on: 06-16-2006, 19:03:18 »

ok moving files to "blank" option works fine now. those categories dont: creating new category = 1 or 2  ? ? ? ? ? ? ? directories:/

IMO this category aproach doesn't make sense because this forces user to have one 'move' directory and 1 subdirectory inside it for each category. better aproach would be to have pairs <name,path> and display names in move.php and moving them to corresponding paths which can be unrelated to each other. and this wouldn't require to create directories (because updating settings with new categories makes these Huh? dirs) so there shouldnt be errors.

true somehow, in its current form move/category implementation is only suitable for single-user-installation.
easiest way to have it multi-user in parts would be to dont use a abolute move-to path but a suffix in that cfg-string which is concatenated to the users torrents-dir (/usr/local/torrent/username/move)
still there would only be global categories and all users would always have those dirs created.
in my version (which has per-user-settings) both could be solved generic and user-configurable. just a possible solution as i still didnt cross the line "per-user-settings are only presentation-settings. no hacks can be tweaked per user".

i wont modify this hack further (for multi-user-usage) now, waiting what the author of this hack thinks about things first Smiley

EDIT: about the category-dirs created... doing this on demand in the move-process would be better as creating all dirs on admin-safe.

regards,
b4rt
« Last Edit: 06-16-2006, 21:23:29 by b4rt » Logged

torrentflux-b4rt svn-trunk
Linux 2.4.34.1, Apache 2.0.59, PHP 4.4.5, Perl 5.8.8, Python 2.5, MySQL 4.1.22
Paczesiowa
Full Member
***
Offline Offline

TF Base: Linux 2.x
Posts: 177



View Profile
« Reply #10 on: 06-16-2006, 20:13:05 »

ok with b4rt's fixes it works. and those categories can point to any directory: just make main directory point to some 'virtual' directory with symlinks to real directories. and those symlinks have categories name.

last thing is removing categories - it doesn't work. I have 3 blanks and 10 test categories and I cant delete them.
Logged

b4rt
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 543



View Profile WWW
« Reply #11 on: 06-16-2006, 20:14:21 »

check my edit-update in post above.
debugin this atm too.. my only problem left is i cant remove entries i can just add new entries.
i still didnt look into the js-code ~

EDIT:
oh to remove entries by hand you can do something like this :
Code:
UPDATE tf_settings SET tf_value = '' WHERE tf_key = 'move_categories';


regards,
b4rt
« Last Edit: 06-16-2006, 20:17:33 by b4rt » Logged

torrentflux-b4rt svn-trunk
Linux 2.4.34.1, Apache 2.0.59, PHP 4.4.5, Perl 5.8.8, Python 2.5, MySQL 4.1.22
b4rt
Hero Member
*****
Offline Offline

TF Base: Linux 2.x
Posts: 543



View Profile WWW
« Reply #12 on: 06-16-2006, 21:17:54 »


to fix the problem that you cant remove cat-entries you could use this modified function removeEntry :

Code:
function removeEntry() {
var catliststr = document.theForm.move_categories;
if(document.theForm.categorylist.selectedIndex != -1) {
document.theForm.categorylist.remove(document.theForm.categorylist.selectedIndex);
var newValue = "";
for (var j = 0; j < document.theForm.categorylist.options.length; j++) {
            if (j > 0) {
                newValue += ";";
            }
    newValue += mytrim(document.theForm.categorylist.options[j].text);
}
catliststr.value = mytrim(newValue);
} else {
alert("Please select an entry first!");
}
}

regards,
b4rt
Logged

torrentflux-b4rt svn-trunk
Linux 2.4.34.1, Apache 2.0.59, PHP 4.4.5, Perl 5.8.8, Python 2.5, MySQL 4.1.22
nu_pagadi
Newbie
*
Offline Offline

Posts: 6



View Profile
« Reply #13 on: 06-17-2006, 02:48:36 »

Hi,
I'm glad you guys like it and sorry for all the bugs.

As I was writing the hack, I just wanted to move the files to a directory, shared with users, that are not allowed to use torrentflux. I wasn't thinking about multi user support at this point, but it seems to be useful  Wink
Unfortunately I have no ideas how to do that.

@b4rt of course you can modify the hack to multi user support if you want to Smiley

Thanks to you two for looking through and for the corrections.

Regards,

nu_pagadi

p.s. I upped the hack again with all corrections.
Logged
Paczesiowa
Full Member
***
Offline Offline

TF Base: Linux 2.x
Posts: 177



View Profile
« Reply #14 on: 06-17-2006, 06:11:49 »

move hack now works great! big tx!

but can u tell how to do 2 things?
1) how to not display blank option in move.php? (there is no blank option in settings)
2) I don't want that window saying "done" can it autoclose itself?
Logged

Pages: [1] 2 3  All Go Up Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by SMF 1.1.1 | SMF © 2006, Simple Machines LLC Powered by PHP