File: index.php

package info (click to toggle)
rtgui 0.2.81-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 576 kB
  • sloc: php: 1,194; sh: 14; makefile: 10
file content (366 lines) | stat: -rwxr-xr-x 19,354 bytes parent folder | download | duplicates (2)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?php
//
//  This file is part of rtGui.  http://rtgui.googlecode.com/
//  Copyright (C) 2007-2011 Simon Hall.
//
//  rtGui 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 3 of the License, or
//  (at your option) any later version.
//
//  rtGui 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 rtGui.  If not, see <http://www.gnu.org/licenses/>.

$execstart=$start=microtime(true);
session_start();
include "config.php";
include "functions.php";

foreach ($_POST as $key => $val) { $v = "r_$key"; $$v = $val; }
foreach ($_GET  as $key => $val) { $v = "r_$key"; $$v = $val; }
foreach ($_FILES as $key => $val) { $v = "r_$key"; $$v = $val; }

// Try using alternative XMLRPC library from http://sourceforge.net/projects/phpxmlrpc/  (see http://code.google.com/p/rtgui/issues/detail?id=19)
if(!function_exists('xml_parser_create')) {
   include("xmlrpc.inc");
   include("xmlrpc_extension_api.inc");
}

// Sort out the session variables for sort order, sort key and current view...
if (!isset($_SESSION['sortkey'])) $_SESSION['sortkey']="name";
if (isset($r_setsortkey)) $_SESSION['sortkey']=$r_setsortkey;

if (!isset($_SESSION['sortord'])) $_SESSION['sortord']="asc";
if (isset($r_setsortord)) $_SESSION['sortord']=$r_setsortord;

if (!isset($_SESSION['view'])) $_SESSION['view']="main";
if (isset($r_setview)) $_SESSION['view']=$r_setview;

if (!isset($_SESSION['tracker_filter'])) $_SESSION['tracker_filter']="";
if (isset($r_settrackerfilter)) $_SESSION['tracker_filter']=$r_settrackerfilter;

if (!isset($_SESSION['filter_invert'])) $_SESSION['filter_invert']=0;
if (isset($r_setfilterinvert)) $_SESSION['filter_invert']=$r_setfilterinvert;

if (isset($r_reload)) unset($_SESSION['lastget']);

if (!isset($_SESSION['refresh'])) $_SESSION['refresh']=$defaultrefresh;

if (!isset($r_debug)) $r_debug=0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="submodal/subModal.css" />
<script type="text/javascript" src="submodal/common.js"></script>
<script type="text/javascript" src="submodal/subModal.js"></script>
<script type="text/javascript" src="rtgui.js"></script>
<script type="text/javascript" language="Javascript">
function start(view,timer) {
   <?php if (isset($r_reload)) echo "ajax(view);"; ?>
   ajax(view);
   setInterval("ajax('"+view+"')",timer)
}
</script>
<title><?php echo php_uname('n') ?>::rtGui</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<?php
echo "<body ".($_SESSION['refresh']!=0 ? "onLoad=\"start('".$_SESSION['view']."',".$_SESSION['refresh'].")\"" : "").">\n";
echo "<div id='wrap'>\n";

$globalstats=get_global_stats();
$rates=get_global_rates();

// Title Block...
echo "<div id=header>\n";
echo "<h1><a href='index.php?reload=1'>rt<span class=green>gui</span></a></h1><br/>\n";

echo "<div id='boxright'>\n";

// Global upload/download...
echo "<p>\n";
echo "Down: <span class='inline download' id='glob_down_rate'>".(format_bytes($rates[0]['ratedown'])=="" ? "0 KB" : format_bytes($rates[0]['ratedown']))."/sec</span> ".($globalstats['download_cap']!=0 ? "<span class='smalltext'>[".format_bytes($globalstats['download_cap'])."]</span>" : "")."&nbsp;&nbsp;&nbsp;\n";
echo "Up: <span class='inline upload' id='glob_up_rate'>".(format_bytes($rates[0]['rateup'])=="" ? "0 KB" : format_bytes($rates[0]['rateup']))."/sec</span> ".($globalstats['upload_cap']!=0 ? "<span class='smalltext'>[".format_bytes($globalstats['upload_cap'])."]</span>" : "")."\n";
echo "</p>\n";

if (isset($downloaddir)) {
   echo "<div id='glob_diskfree'>";
   echo "<div ".( (round($rates[0]['diskspace']/disk_total_space($downloaddir)*100) <= $alertthresh  )  ? "class='diskalert'"  : ""  ).">\n";
   echo "Disk Free: ".format_bytes($rates[0]['diskspace'])." / ".format_bytes(disk_total_space($downloaddir))." (".(round($rates[0]['diskspace']/disk_total_space($downloaddir)*100))."%)\n";
   echo "</div>\n";
   echo "</div>\n";
}


// Tracker filter
echo "<form method='post'>\n";
if ($_SESSION['tracker_filter']=="") {
   echo "<p>Group filter:";
   echo "<select name='settrackerfilter'>";
   foreach ($tracker_hilite as $num=>$tracker) {
      echo "<option value='_group_".$num."'>".$tracker[1].(isset($tracker[2]) ? "..." : "")."</option>";
   }
   echo "</select><input type='submit' value='Go'></p>\n";
} else {
   echo "<p>Showing ".($_SESSION['filter_invert']==0 ? "ONLY" : "all EXCEPT")." <b>";
   if (substr($_SESSION['tracker_filter'],0,7)=="_group_") {
      echo "Group (".$tracker_hilite[str_ireplace("_group_","",$_SESSION['tracker_filter'])][1].(isset($tracker_hilite[str_ireplace("_group_","",$_SESSION['tracker_filter'])][2]) ? "..." : "").")";
   } else {
      echo $_SESSION['tracker_filter'];
   }
   echo "</b> [ <a href='?settrackerfilter=&setfilterinvert=0'>Reset</a> | <a href='?setfilterinvert=".($_SESSION['filter_invert']==0 ? "1" : "0")."'>Invert</a> ] </p>\n";
}
echo "</form>\n";

// Settings/Add Torrent etc...
echo "<p><a class='submodal-600-520' href='settings.php'>Settings</a> | <a href=\"javascript:toggleLayer('divadd');\">Add Torrent</a></p>\n";

// Hidden Add Torrent form...
echo "<div id='divadd' class='togglevis' style='width:350px;float:right;' align='right'>";
echo "<form method='post' action='control.php' enctype='multipart/form-data'>\n";
echo "URL: <input type=text name='addurl' size=38 maxlength=500 /> <input type='submit' value='Go' /><br/>\n";
echo "File: <input name='uploadtorrent' type='file' size=25 /> <input type='submit' value='Go' />\n";
echo "</form>\n";
echo "</div>\n";  // end of divadd div

echo "</div>\n";  // end of boxright div

echo "</div>\n";  // end of header div
// Title Block End

// Get the list of torrents downloading
$data=get_full_list($_SESSION['view']);

// Get tracker URL for each torrent - this does an RPC query for every torrent - might be heavy on server so you might want to disable in config.php
if ($displaytrackerurl==TRUE && is_array($data)) {
   foreach($data as $key=>$item) {
      $data[$key]['tracker_url']=tracker_url($item['hash']);
   }
}

// Sort the list
if (is_array($data)) {
   if (strtolower($_SESSION['sortord']=="asc")) {
      $sortkey=$_SESSION['sortkey'];
      usort($data,'sort_matches_asc');
   } else {
      $sortkey=$_SESSION['sortkey'];
      usort($data,'sort_matches_desc');
   }
} else {
   $data=array();
}

echo "<form action='control.php' method='post' name='control'>";

// View selection...
echo "<div id='navcontainer' style='clear:both;'>\n";

echo "<ul id='navlist'>\n";
echo "<li><a ".($_SESSION['view']=="main" ? "id='current'" : "")." href='?setview=main'>All</a></li>\n";
echo "<li><a ".($_SESSION['view']=="started" ? "id='current'" : "")." href='?setview=started'>Started</a></li>\n";
echo "<li><a ".($_SESSION['view']=="stopped" ? "id='current'" : "")." href='?setview=stopped'>Stopped</a></li>\n";
echo "<li><a ".($_SESSION['view']=="complete" ? "id='current'" : "")." href='?setview=complete'>Complete</a></li>\n";
echo "<li><a ".($_SESSION['view']=="incomplete" ? "id='current'" : "")." href='?setview=incomplete'>Incomplete</a></li>\n";
echo "<li><a ".($_SESSION['view']=="seeding" ? "id='current'" : "")." href='?setview=seeding'>Seeding</a></li>\n";
echo "<li><a ".($_SESSION['view']=="active" ? "id='current'" : "")." href='?setview=active'>Active</a></li>\n";
if ($debugtab) {
   echo "<li><a ".($r_debug==1 ? "id='current'" : "")." href='?setview=main&amp;debug=1'>Debug</a></li>\n";
}
echo "</ul>\n";
echo "</div>\n";

echo "<div class ='container'>\n";

// The headings, with sort links...
$uparr="<img src='images/uparrow.gif' height=8 width=5 alt='Descending' />";
$downarr="<img src='images/downarrow.gif' height=8 width=5 alt='Ascending' />";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=name&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Name</a> ".($_SESSION['sortkey']=="name" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"");
echo " / <a href='?setsortkey=filemtime&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>age</a> ".($_SESSION['sortkey']=="filemtime" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"");
echo "</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=status_string&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Status</a> ".($_SESSION['sortkey']=="status_string" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=percent_complete&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Done</a> ".($_SESSION['sortkey']=="percent_complete" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=bytes_diff&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Remain</a> ".($_SESSION['sortkey']=="bytes_diff" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=size_bytes&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Size</a> ".($_SESSION['sortkey']=="size_bytes" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=down_rate&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Down</a> ".($_SESSION['sortkey']=="down_rate" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=up_rate&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Up</a> ".($_SESSION['sortkey']=="up_rate" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=up_total&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Seeded</a> ".($_SESSION['sortkey']=="up_total" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=ratio&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Ratio</a> ".($_SESSION['sortkey']=="ratio" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:89px;'><a href='?setsortkey=peers_connected&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Peers</a> ".($_SESSION['sortkey']=="peers_connected" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"")."</div>\n";
echo "<div class='headcol' style='width:84px;'>";
echo "<a href='?setsortkey=priority_str&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Pri</a> ".($_SESSION['sortkey']=="priority_str" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"");
if ($displaytrackerurl==TRUE) {
   echo "/ <a href='?setsortkey=tracker_url&amp;setsortord=".($_SESSION['sortord']=="asc" ? "desc" : "asc")."'>Trk</a> ".($_SESSION['sortkey']=="tracker_url" ? ($_SESSION['sortord']=="asc" ? "$downarr" : "$uparr") :"");
}
echo "</div>\n";
// End of headings

echo "<div class=spacer></div>\n";

if ($r_debug==1) {
   echo "<br><pre>";
   echo htmlspecialchars(var_export($data));
   echo "</pre>";
}

// List the torrents...
$totdisp=0;
$thisrow="row1";
$tottorrents=0;
foreach($data AS $item) {
   $tottorrents++;
   $displaythis=FALSE;
   if ($_SESSION['tracker_filter']=="") { 
      $displaythis=TRUE; 
   }
   if ($_SESSION['filter_invert']==0) {
      // Filter by tracker URL
      if (@stristr($item['tracker_url'],$_SESSION['tracker_filter'])==TRUE) {
         $displaythis=TRUE;
      }
      // Filter by group (defined in config)
      if (substr($_SESSION['tracker_filter'],0,7)=="_group_") {
         $groupid=str_replace("_group_","",$_SESSION['tracker_filter']);
         foreach($tracker_hilite[$groupid] as $tracker) {
            if (stristr($item['tracker_url'],$tracker)) {
               $displaythis=TRUE;
            }
         }
      }
   } else {
      // Filter by NOT tracker URL
      if (@stristr($item['tracker_url'],$_SESSION['tracker_filter'])==FALSE) {
         $displaythis=TRUE;
      }
      // Filter by NOT group
      if (substr($_SESSION['tracker_filter'],0,7)=="_group_") {
         $displaythis=TRUE;
         $groupid=str_replace("_group_","",$_SESSION['tracker_filter']);
         foreach($tracker_hilite[$groupid] as $tracker) {
            if (stristr($item['tracker_url'],$tracker)) {
               $displaythis=FALSE;
            }
         }
      }
      
   }   
   if ($displaythis) {
      $totdisp++;
      echo "<div class='$thisrow'>\n";

      if ($item['complete']==1) { $statusstyle="complete"; } else { $statusstyle="incomplete"; }
      if ($item['is_active']==1) { $statusstyle.="active"; } else { $statusstyle.="inactive"; }
      $eta="";
      if ($item['down_rate']>0) {
         $eta=formateta(($item['size_bytes']-$item['completed_bytes'])/$item['down_rate']);
      }

      echo "<div class='namecol' id='t".$item['hash']."name'>\n";
      // Tracker URL
      if ($displaytrackerurl==TRUE) {
         // echo $item['tracker_url'];
         $urlstyle=$tracker_hilite_default;
         foreach($tracker_hilite as $hilite) {
            foreach ($hilite as $thisurl) { 
               if (stristr($item['tracker_url'],$thisurl)==TRUE) { $urlstyle=$hilite[0]; }
            }
         }
         echo "<div class='trackerurl' id='tracker' ><a style='color: $urlstyle ;' id='tracker' href='?settrackerfilter=".$item['tracker_url']."&setfilterinvert=0'>".$item['tracker_url']."</a>&nbsp;</div>";
      }
      
      // Torrent name
      echo "<input type='checkbox' name='select[]' value='".$item['hash']."'  /> ";
      echo "<a class='submodal-600-520 $statusstyle' href='view.php?hash=".$item['hash']."'>".htmlspecialchars($item['name'], ENT_QUOTES)."</a>&nbsp;";
      echo "<span class='age' id='t".$item['hash']."filemtime'>".age($item['filemtime'])."</span>\n";
      echo "</div>\n";

      // message...
      echo "<div class='errorcol' id='t".$item['hash']."message'>\n";
      if ($eta!="") echo $eta." Remaining... ";
      if ($item['message']!="") echo $item['message']."\n";
      echo "</div>\n";

      // Stop/start controls...
      echo "<div class='datacol'  style='width:89px;'>\n";
      echo "<a href='control.php?hash=".$item['hash']."&amp;cmd=".($item['is_active']==1 ? "stop" : "start")."'>".($item['is_active']==1 ? "<img alt='Stop torrent' border=0 src='images/stop.gif' width=16 height=16 />" : "<img alt='Start torrent' border=0 src='images/start.gif' width=16 height=16 />")."</a> \n";
      echo "<a href='control.php?hash=".$item['hash']."&amp;cmd=delete' onClick='return confirm(\"Delete torrent - are you sure? (This will not delete data from disk)\");'><img align='bottom' alt='Delete torrent' border=0 src='images/delete.gif' width=16 height=16 /></a> \n";
      echo "<a class='submodal-600-520' href='view.php?hash=".$item['hash']."'><img alt='Torrent info' src='images/view.gif' width=16 height=16 /></a><br/>\n";
      echo "</div>\n";
      
      // Stats row...
      echo "<div class='datacol' style='width:89px;' id='t".$item['hash']."status_string'><img src='images/".$statusstyle.".gif' width=10 height=9 alt='Status' />".$item['status_string']."</div>\n";
      echo "<div class='datacol' style='width:89px;' id='t".$item['hash']."percent_complete'>".$item['percent_complete']." %<br/>".percentbar(@round(($item['percent_complete']/2)))."</div>\n";
      echo "<div class='datacol' style='width:89px;' id='t".$item['hash']."bytes_diff'>".completed_bytes_diff($item['size_bytes'],$item['completed_bytes'])."</div>\n";
      echo "<div class='datacol' style='width:89px;' id='t".$item['hash']."size_bytes'>".format_bytes($item['size_bytes'])."</div>\n";
      echo "<div class='datacol download' style='width:89px;' id='t".$item['hash']."down_rate'>".format_bytes($item['down_rate'])."</div>\n";
      echo "<div class='datacol upload' style='width:89px;' id='t".$item['hash']."up_rate'>".format_bytes($item['up_rate'])."</div>\n";
      echo "<div class='datacol' style='width:89px;' id='t".$item['hash']."up_total'>".format_bytes($item['up_total'])."</div>\n";
      echo "<div class='datacol' style='width:70px;' id='t".$item['hash']."ratio'>".@round(($item['ratio']/1000),2)."</div>\n";
      echo "<div class='datacol' style='width:105px;' id='t".$item['hash']."peers'>".$item['peers_connected']."/".$item['peers_not_connected']." (".$item['peers_complete'].")"."</div>\n";
      echo "<div class='datacollast' style='width:70px;' id='t".$item['hash']."priority_str'>".$item['priority_str']."</div>\n";
      echo "<div class=spacer> </div>\n";

      echo "</div>\n"; // end of thisrow div
      if ($thisrow=="row1") {$thisrow="row2";} else {$thisrow="row1";}
   }
}

// Display message if no torrents to list...
if (!$data || $totdisp==0 ) {
   echo "<div class='row1'>\n";
   echo "<div class='namecol' align='center'><p>&nbsp;</p>No torrents to display.<p>&nbsp;</p></div>\n";
   echo "</div>\n";
}

echo "</div>\n";  // end of container div

// Bulk control...
echo "<div class='bottomtab'>";
echo "<div style='float:left;'>\n";
echo "<input type='button' value='Select All' onClick='checkAll(this.form)' />\n";
echo "<input type='button' value='Unselect All' onClick='uncheckAll(this.form)' />\n";

echo "<select name='bulkaction' >\n";
echo "<optgroup label='With Selected...'>\n";
echo "<option value='stop'>Stop</option>\n";
echo "<option value='start'>Start</option>\n";
echo "<option value='delete'>Delete</option>\n";
echo "</optgroup>\n";
echo "<optgroup label='Set Priority...'>\n";
echo "<option value='pri_high'>High</option>\n";
echo "<option value='pri_normal'>Normal</option>\n";
echo "<option value='pri_low'>Low</option>\n";
echo "<option value='pri_off'>Off</option>\n";
echo "</optgroup>\n";
echo "</select>\n";
echo "<input type='submit' value='Go' />\n";
echo "</div>";

// Number of torrents displayed/total torrents for this view
echo "<div style='float:right;'>\n";
echo $totdisp."/".$tottorrents;
echo "</div>";

echo "<br style='clear:both;'></div>";
echo "</form>\n";

// Footer...
echo "<p>&nbsp;</p>";
echo "<div align='center' class='smalltext'>\n";
echo "<a href='http://libtorrent.rakshasa.no/' target='_blank'>rTorrent ".$globalstats['client_version']."/".$globalstats['library_version']."</a> | ";
echo "<a href='rssfeed.php'>RSS Feed</a> | ";
echo "Page created in ".$restime=round(microtime(true)-$execstart,3)." secs.<br/>\n";
echo "<a href='http://rtgui.googlecode.com' target='_blank'>rtGui v0.2.8</a> - by Simon Hall 2007-2011\n";
echo "</div>\n";
?>
</div>
</body>
</html>