File: multi.php

package info (click to toggle)
torrentflux 2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 6,028 kB
  • ctags: 13,559
  • sloc: php: 36,501; python: 12,563; sh: 1,139; sql: 340; makefile: 44; xml: 22
file content (158 lines) | stat: -rwxr-xr-x 5,028 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php

/*************************************************************
*  TorrentFlux - PHP Torrent Manager
*  www.torrentflux.com
**************************************************************/
/*
   This file is part of TorrentFlux.

   TorrentFlux is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   TorrentFlux is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with TorrentFlux; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

include_once("config.php");
include_once("functions.php");

# what to do?
$action = getRequestVar("action");
if($action == "torrent" || $action == "data")
{
   $torrent = getRequestVar("torrent");
   foreach($torrent as $key => $element)
   {
      # since we only have the .torrent file, get the stat
      $alias = getAliasName($element).".stat";
      # this is acctualy a copy and paste from index.php since its not a function
      # and we need to call it serveral times in a row
      $element = urldecode($element);

      if (($cfg["user"] == getOwner($element)) || IsAdmin())
      {
           # the user is the owner of the torrent -> delete it
           # FIRST delete data, then the torrent
           if ($action == "data")
           {

               require_once('BDecode.php');
               $ftorrent=$cfg["torrent_file_path"].$element;
               $fd = fopen($ftorrent, "rd");
               $alltorrent = fread($fd, filesize($ftorrent));
               $btmeta = BDecode($alltorrent);
               $delete = $btmeta['info']['name'];
               if(trim($delete) != "")
               {
                   $delete = $cfg['user']."/".$delete;

                   # this is accutaly from dir.php - its not a function, and we need to call it serval times

                   $del = stripslashes(stripslashes($delete));

                   if (!ereg("(\.\.\/)", $del))
                   {

                       avddelete($cfg["path"].$del);

                       $arTemp = explode("/", $del);
                       if (count($arTemp) > 1)
                       {
                           array_pop($arTemp);
                           $current = implode("/", $arTemp);
                       }
                       AuditAction($cfg["constants"]["fm_delete"], $del);
                   }
                   else
                   {
                       AuditAction($cfg["constants"]["error"], "ILLEGAL DELETE: ".$cfg['user']." tried to delete ".$del);
                   }
               }
           }
           @unlink($cfg["torrent_file_path"].$element);
           @unlink($cfg["torrent_file_path"].$alias);
           @unlink($cfg["torrent_file_path"].getAliasName($element).".prio");
           AuditAction($cfg["constants"]["delete_torrent"], $element);

       }
       else
       {
           AuditAction($cfg["constants"]["error"], $cfg["user"]." attempted to delete ".$element);
       }
   }
}
else if ( $action == "fileDelete" )
{
    $file = getRequestVar("file");
    // Lets delete some files
    if(is_array($file))
    {
        foreach($file as $key => $element)
        {
            $element = urldecode($element);
            delFile($element);
        }
    }
}

if ( isset($_SERVER["HTTP_REFERER"]) )
{
    header("location: ".$_SERVER["HTTP_REFERER"]);
}
else
{
    header("location: index.php");
}


function delFile($del)
{
    global $cfg;

    if(IsAdmin($cfg["user"]) || preg_match("/^" . $cfg["user"] . "/",$del))
    {
        // Yes, then delete it

        // we need to strip slashes twice in some circumstances
        // Ex.  If we are trying to delete test/tester's file/test.txt
        //    $del will be "test/tester\\\'s file/test.txt"
        //    one strip will give us "test/tester\'s file/test.txt
        //    the second strip will give us the correct
        //        "test/tester's file/test.txt"

        $del = stripslashes(stripslashes($del));

        if (!ereg("(\.\.\/)", $del))
        {
            avddelete($cfg["path"].$del);

            $arTemp = explode("/", $del);
            if (count($arTemp) > 1)
            {
                array_pop($arTemp);
                $current = implode("/", $arTemp);
            }
            AuditAction($cfg["constants"]["fm_delete"], $del);
        }
        else
        {
            AuditAction($cfg["constants"]["error"], "ILLEGAL DELETE: ".$cfg['user']." tried to delete ".$del);
        }
    }
    else
    {
        AuditAction($cfg["constants"]["error"], "ILLEGAL DELETE: ".$cfg['user']." tried to delete ".$del);
    }
}

?>