Outils pour utilisateurs

Outils du site


No renderer 'odt' found for mode 'odt'
kb:linux:apache2:rutorrent

Ceci est une ancienne révision du document !


ruTorrent

Introduction

ruTorrent est une solution d'interface WEB de rTorrent.
Il permet de créer, télécharger, supprimer des torrent via une interface WEB.

Installation

Prérequis

Pour des raisons de simplicité de droits, on va utiliser le compte www-data pour le service rtorrent, ce qui n'est pas sécurisé en cas de multi-site.

Installation

il faut installer les packets via :

# apt update && apt upgrade -y && apt install rtorrent php5 apache2 git -y 
Configuration du compte www-data

On va ensuite rendre l'utilisateur www-data utilisable :

# passwd www-data

puis changer la ligne dans /etc/passwd

www-data:x:33:33:www-data:/var/www:/bin/bash

Le compte est désormais disponible avec le mot de passe.

Configuration de Apache2

Il faut juste changer la localisation du dossier dans les VirtualHosts.
Si vous savez comment cela fonctionne, sautez cette partie.

Il va modifier le fichier /etc/apache2/sites-available/000-default.conf comme ceci :

<VirtualHost *:80>

        DocumentRoot /var/www/ruTorrent

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory "/var/www/ruTorrent">
                AuthType Basic
                AuthName "RT AUTH"
                AuthUserFile /etc/apache2/.htpasswd
                Require valid-user
        </Directory>
</VirtualHost>

Puis on va créer le premier utilisateur Apache2 :

# htpasswd -c /etc/apache2/.htpasswd TOTO

puis pour en rajouter :

# htpasswd /etc/apache2/.htpasswd TATA

Pour finir il faudra recharger le service Apache2 :

# /etc/init.d/apache2 reload
Installation de ruTorrent

On va se déplacer dans le dossier suivant

# cd /var/www/

puis récupérer la source :

# git clone https://github.com/Novik/ruTorrent.git
Configuration de rtorrent

Il va falloir créer les répertoires suivant :

# mkdir -p /var/www/ruTorrent/DATA/files
# mkdir /var/www/ruTorrent/DATA/session

puis créer le fichier .rtorrent.rc

directory = /var/www/ruTorrent/DATA/files/
session = /var/www/ruTorrent/DATA/session/
port_range = 6900-6999
port_random = yes
check_hash = yes
scgi_port = 127.0.0.1:5000

il ne reste plus qu'a rendre les droits a www-data :

chown -R www-data:www-data /var/www/
Automatisation de la solution

Pour que rtorrent ce lance au démarrage, il faut se connecter avec le compte www-data

# su - www-data

Puis rajouter une tache cron :

# crontab -e

Choisissait nano, puis rajouter a la fin:

@reboot rm -rf /var/www/ruTorrent/DATA/session/*.lock
@reboot screen -dmS ruto rtorrent

Patch streaming

J'ai rapidement développé un script pour lire les fichiers vidéos, il faut alors rajouter la ligne dans le fichier index.html en remplaçant le nom de domaine :

                        <a id="mnu_settings" href="javascript://void();" onclick="theWebUI.showSettings(); return(false);" onfocus="this.blur()" title="Settings">
                                <div id="setting"></div>
                        </a>
                        <div class="TB_Separator"></div>
                        <a id="mnu_help" href="javascript://void();" onclick="theDialogManager.toggle('dlgHelp'); return(false);" onfocus="this.blur()" title="Help">
                                <div id="help"></div>
                        </a>
#Rajouter suivante la ligne suivante ici
                        <a id="mnu_help" href="https://rt.virtit.fr/videobeta.php" onfocus="this.blur()" title="Streaming"> 
                                <div id="start"></div>
                        </a>

et créer le fichier /var/www/ruTorrent/videobeta.php

<html>
        <body>
                <?php
                        function getDirContents($dir, &$results = array())
                        {
                                $files = scandir($dir);
                                foreach($files as $key => $value)
                                {
                                        $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
                                        if(is_dir($path) == false)
                                        {
                                                $results[] = substr($path,19,strlen($path));
                                        }
                                        else if($value != "." && $value != "..")
                                        {
                                                getDirContents($path, $results);
                                                if(is_dir($path) == false) {
                                                        $results[] = substr($path,19,strlen($path));
                                                }
                                        }
                                }
                                return $results;

                        }

                        $filesdir = getDirContents('/var/www/ruTorrent/DATA/files/');
                        $arrlength = count($filesdir);
                        for($x = 0; $x < $arrlength; $x++)
                        {
                                $lenfilesdir = strlen($filesdir[$x]);
                                $format = substr($filesdir[$x], $lenfilesdir-4, $lenfilesdir);
                                if ( strcmp($format,".mp4") == 0 || strcmp($format,".avi")==0 || strcmp($format,".mkv")==0)
                                {
                                        $file = substr($filesdir[$x], strrpos($filesdir[$x],"/")+1,$lenfilesdir);
                                        echo '<a href="' . $filesdir[$x] . ".html" . '">'. $file . '</a>' ;
                                        echo "<br>";
                                        $fichier = fopen($filesdir[$x].".html","w") or die ("Unable to open file!");
                                        $txt = "<html>\n";
                                        fwrite($fichier, $txt) ;
                                        $txt = "<video controls>\n";
                                        fwrite($fichier, $txt) ;
                                        $txt = "<source src=". $file ." type="."video/webm".">\n";
                                        fwrite($fichier, $txt) ;
                                        $txt = "</video>\n";
                                        fwrite($fichier, $txt) ;
                                        $txt = '<a href="' . $file . '"> Download</a>' ;
                                        fwrite($fichier, $txt) ;
                                        $txt = "</html>\n";
                                        fwrite($fichier, $txt) ;
                                        fclose($fichier);

                                }
                        }
                ?>
        </body>
</html>

Si le tuto a été suivit a la lettre, il n'y a rien a modifier dans le fichier videobeta.php.

kb/linux/apache2/rutorrent.1488447928.txt.gz · Dernière modification : 2017/12/09 00:19 (modification externe)