Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
<?php
2
 
3
/*************************************************************
4
*  TorrentFlux - PHP Torrent Manager
5
*  www.torrentflux.com
6
**************************************************************/
7
/*
8
    This file is part of TorrentFlux.
9
 
10
    TorrentFlux is free software; you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation; either version 2 of the License, or
13
    (at your option) any later version.
14
 
15
    TorrentFlux is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with TorrentFlux; if not, write to the Free Software
22
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
*/
24
 
25
include_once("config.php");
26
include_once("functions.php");
27
 
28
if(!IsAdmin())
29
{
30
     // the user probably hit this page direct
31
    AuditAction($cfg["constants"]["access_denied"], $_SERVER['PHP_SELF']);
32
    header("location: index.php");
33
}
34
 
35
//****************************************************************************
36
// addLink -- adding a link
37
//****************************************************************************
38
function addLink($newLink)
39
{
40
    if(!empty($newLink)){
41
        global $cfg;
42
        addNewLink($newLink);
43
        AuditAction($cfg["constants"]["admin"], "New "._LINKS_MENU.": ".$newLink);
44
    }
45
    header("location: admin.php?op=editLinks");
46
}
47
 
48
//****************************************************************************
49
// addRSS -- adding a RSS link
50
//****************************************************************************
51
function addRSS($newRSS)
52
{
53
    if(!empty($newRSS)){
54
        global $cfg;
55
        addNewRSS($newRSS);
56
        AuditAction($cfg["constants"]["admin"], "New RSS: ".$newRSS);
57
    }
58
    header("location: admin.php?op=editRSS");
59
}
60
 
61
//****************************************************************************
62
// addUser -- adding a user
63
//****************************************************************************
64
function addUser($newUser, $pass1, $userType)
65
{
66
    global $cfg;
67
    $newUser = strtolower($newUser);
68
    if (IsUser($newUser))
69
    {
70
        DisplayHead(_ADMINISTRATION);
71
 
72
        // Admin Menu
73
        displayMenu();
74
 
75
        echo "<br><div align=\"center\">"._TRYDIFFERENTUSERID."<br><strong>".$newUser."</strong> "._HASBEENUSED."</div><br><br><br>";
76
 
77
        DisplayFoot();
78
    }
79
    else
80
    {
81
        addNewUser($newUser, $pass1, $userType);
82
        AuditAction($cfg["constants"]["admin"], _NEWUSER.": ".$newUser);
83
        header("location: admin.php?op=CreateUser");
84
    }
85
}
86
 
87
//****************************************************************************
88
// updateUser -- updating a user
89
//****************************************************************************
90
function updateUser($user_id, $org_user_id, $pass1, $userType, $hideOffline)
91
{
92
    global $cfg;
93
    $user_id = strtolower($user_id);
94
    if (IsUser($user_id) && ($user_id != $org_user_id))
95
    {
96
        DisplayHead(_ADMINISTRATION);
97
 
98
        // Admin Menu
99
        displayMenu();
100
 
101
        echo "<br><div align=\"center\">"._TRYDIFFERENTUSERID."<br><strong>".$user_id."</strong> "._HASBEENUSED."<br><br><br>";
102
 
103
        echo "[<a href=\"admin.php?op=editUser&user_id=".$org_user_id."\">"._RETURNTOEDIT." ".$org_user_id."</a>]</div><br><br><br>";
104
 
105
        DisplayFoot();
106
    }
107
    else
108
    {
109
        // Admin is changing id or password through edit screen
110
        if(($user_id == $cfg["user"] || $cfg["user"] == $org_user_id) && $pass1 != "")
111
        {
112
            // this will expire the user
113
            $_SESSION['user'] = md5($cfg["pagetitle"]);
114
        }
115
        updateThisUser($user_id, $org_user_id, $pass1, $userType, $hideOffline);
116
        AuditAction($cfg["constants"]["admin"], _EDITUSER.": ".$user_id);
117
        header("location: admin.php");
118
    }
119
}
120
 
121
//****************************************************************************
122
// deleteLink -- delete a link
123
//****************************************************************************
124
function deleteLink($lid)
125
{
126
    global $cfg;
127
    AuditAction($cfg["constants"]["admin"], _DELETE." Link: ".getLink($lid));
128
    deleteOldLink($lid);
129
    header("location: admin.php?op=editLinks");
130
}
131
 
132
//****************************************************************************
133
// deleteRSS -- delete a RSS link
134
//****************************************************************************
135
function deleteRSS($rid)
136
{
137
    global $cfg;
138
    AuditAction($cfg["constants"]["admin"], _DELETE." RSS: ".getRSS($rid));
139
    deleteOldRSS($rid);
140
    header("location: admin.php?op=editRSS");
141
}
142
 
143
//****************************************************************************
144
// deleteUser -- delete a user (only non super admin)
145
//****************************************************************************
146
function deleteUser($user_id)
147
{
148
    global $cfg;
149
    if (!IsSuperAdmin($user_id))
150
    {
151
        DeleteThisUser($user_id);
152
        AuditAction($cfg["constants"]["admin"], _DELETE." "._USER.": ".$user_id);
153
    }
154
    header("location: admin.php");
155
}
156
 
157
//****************************************************************************
158
// showIndex -- default view
159
//****************************************************************************
160
function showIndex($min = 0)
161
{
162
    global $cfg;
163
    DisplayHead(_ADMINISTRATION);
164
 
165
    // Admin Menu
166
    displayMenu();
167
 
168
    // Show User Section
169
    displayUserSection();
170
 
171
    echo "<br>";
172
 
173
    // Display Activity
174
    displayActivity($min);
175
 
176
    DisplayFoot();
177
 
178
}
179
 
180
 
181
//****************************************************************************
182
// showUserActivity -- Activity for a user
183
//****************************************************************************
184
function showUserActivity($min=0, $user_id="", $srchFile="", $srchAction="")
185
{
186
    global $cfg;
187
 
188
    DisplayHead(_ADMINUSERACTIVITY);
189
 
190
    // Admin Menu
191
    displayMenu();
192
 
193
    // display Activity for user
194
    displayActivity($min, $user_id, $srchFile, $srchAction);
195
 
196
    DisplayFoot();
197
 
198
}
199
 
200
 
201
 
202
//****************************************************************************
203
// backupDatabase -- backup the database
204
//****************************************************************************
205
function backupDatabase()
206
{
207
    global $cfg;
208
 
209
    $file = $cfg["db_name"]."_".date("Ymd").".tar.gz";
210
    $back_file = $cfg["torrent_file_path"].$file;
211
    $sql_file = $cfg["torrent_file_path"].$cfg["db_name"].".sql";
212
 
213
    $sCommand = "";
214
    switch($cfg["db_type"])
215
    {
216
        case "mysql":
217
            $sCommand = "mysqldump -h ".$cfg["db_host"]." -u ".$cfg["db_user"]." --password=".$cfg["db_pass"]." --all -f ".$cfg["db_name"]." > ".$sql_file;
218
            break;
219
        default:
220
            // no support for backup-on-demand.
221
            $sCommand = "";
222
            break;
223
    }
224
 
225
    if($sCommand != "")
226
    {
227
        shell_exec($sCommand);
228
        shell_exec("tar -czvf ".$back_file." ".$sql_file);
229
 
230
        // Get the file size
231
        $file_size = filesize($back_file);
232
 
233
        // open the file to read
234
        $fo = fopen($back_file, 'r');
235
        $fr = fread($fo, $file_size);
236
        fclose($fo);
237
 
238
        // Set the headers
239
        header("Content-type: APPLICATION/OCTET-STREAM");
240
        header("Content-Length: ".$file_size.";");
241
        header("Content-Disposition: attachement; filename=".$file);
242
 
243
        // send the tar baby
244
        echo $fr;
245
 
246
        // Cleanup
247
        shell_exec("rm ".$sql_file);
248
        shell_exec("rm ".$back_file);
249
        AuditAction($cfg["constants"]["admin"], _BACKUP_MENU.": ".$file);
250
    }
251
}
252
 
253
 
254
//****************************************************************************
255
// displayMenu -- displays Admin Menu
256
//****************************************************************************
257
function displayMenu()
258
{
259
    global $cfg;
260
    echo "<table width=\"760\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\">";
261
    echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\"><div align=\"center\">";
262
    echo "<a href=\"admin.php\"><font class=\"adminlink\">"._ADMIN_MENU."</font></a> | ";
263
    echo "<a href=\"admin.php?op=configSettings\"><font class=\"adminlink\">"._SETTINGS_MENU."</font></a> | ";
264
    echo "<a href=\"admin.php?op=queueSettings\"><font class=\"adminlink\">"._QMANAGER_MENU."</font></a> | ";
265
    echo "<a href=\"admin.php?op=searchSettings\"><font class=\"adminlink\">"._SEARCHSETTINGS_MENU."</font></a> | ";
266
    echo "<a href=\"admin.php?op=showUserActivity\"><font class=\"adminlink\">"._ACTIVITY_MENU."</font></a> | ";
267
    echo "<a href=\"admin.php?op=editLinks\"><font class=\"adminlink\">"._LINKS_MENU."</font></a> | ";
268
    echo "<a href=\"admin.php?op=editRSS\"><font class=\"adminlink\">rss</font></a> | ";
269
    echo "<a href=\"admin.php?op=CreateUser\"><font class=\"adminlink\">"._NEWUSER_MENU."</font></a> | ";
270
    echo "<a href=\"admin.php?op=backupDatabase\"><font class=\"adminlink\">"._BACKUP_MENU."</font></a>";
271
    echo "</div></td></tr>";
272
    echo "</table><br>";
273
 
274
}
275
 
276
 
277
//****************************************************************************
278
// displayActivity -- displays Activity
279
//****************************************************************************
280
function displayActivity($min=0, $user="", $srchFile="", $srchAction="")
281
{
282
    global $cfg, $db;
283
 
284
    $sqlForSearch = "";
285
 
286
    $userdisplay = $user;
287
 
288
    if($user != "")
289
    {
290
        $sqlForSearch .= "user_id='".$user."' AND ";
291
    }
292
    else
293
    {
294
        $userdisplay = _ALLUSERS;
295
    }
296
 
297
    if($srchFile != "")
298
    {
299
        $sqlForSearch .= "file like '%".$srchFile."%' AND ";
300
    }
301
 
302
    if($srchAction != "")
303
    {
304
        $sqlForSearch .= "action like '%".$srchAction."%' AND ";
305
    }
306
 
307
    $offset = 50;
308
    $inx = 0;
309
    if (!isset($min)) $min=0;
310
    $max = $min+$offset;
311
    $output = "";
312
    $morelink = "";
313
 
314
    $sql = "SELECT user_id, file, action, ip, ip_resolved, user_agent, time FROM tf_log WHERE ".$sqlForSearch."action!=".$db->qstr($cfg["constants"]["hit"])." ORDER BY time desc";
315
 
316
    $result = $db->SelectLimit($sql, $offset, $min);
317
    while(list($user_id, $file, $action, $ip, $ip_resolved, $user_agent, $time) = $result->FetchRow())
318
    {
319
        $user_icon = "images/user_offline.gif";
320
        if (IsOnline($user_id))
321
        {
322
            $user_icon = "images/user.gif";
323
        }
324
 
325
        $ip_info = $ip_resolved."<br>".$user_agent;
326
 
327
        $output .= "<tr>";
328
        if (IsUser($user_id))
329
        {
330
            $output .= "<td><a href=\"message.php?to_user=".$user_id."\"><img src=\"".$user_icon."\" width=17 height=14 title=\""._SENDMESSAGETO." ".$user_id."\" border=0 align=\"bottom\">".$user_id."</a>&nbsp;&nbsp;</td>";
331
        }
332
        else
333
        {
334
            $output .= "<td><img src=\"".$user_icon."\" width=17 height=14 title=\"n/a\" border=0 align=\"bottom\">".$user_id."&nbsp;&nbsp;</td>";
335
        }
336
        $output .= "<td><div class=\"tiny\">".$action."</div></td>";
337
        $output .= "<td><div align=center><div class=\"tiny\" align=\"left\">";
338
        $output .= $file;
339
        $output .= "</div></td>";
340
        $output .= "<td><div class=\"tiny\" align=\"left\"><a href=\"javascript:void(0)\" onclick=\"return overlib('".$ip_info."<br>', STICKY, CSSCLASS);\" onmouseover=\"return overlib('".$ip_info."<br>', CSSCLASS);\" onmouseout=\"return nd();\"><img src=\"images/properties.png\" width=\"18\" height=\"13\" border=\"0\"><font class=tiny>".$ip."</font></a></div></td>";
341
        $output .= "<td><div class=\"tiny\" align=\"center\">".date(_DATETIMEFORMAT, $time)."</div></td>";
342
        $output .= "</tr>";
343
 
344
        $inx++;
345
    }
346
 
347
    if($inx == 0)
348
    {
349
        $output = "<tr><td colspan=6><center><strong>-- "._NORECORDSFOUND." --</strong></center></td></tr>";
350
    }
351
 
352
    $prev = ($min-$offset);
353
    if ($prev>=0)
354
    {
355
        $prevlink = "<a href=\"admin.php?op=showUserActivity&min=".$prev."&user_id=".$user."&srchFile=".$srchFile."&srchAction=".$srchAction."\">";
356
        $prevlink .= "<font class=\"TinyWhite\">&lt;&lt;".$min." "._SHOWPREVIOUS."]</font></a> &nbsp;";
357
    }
358
    if ($inx>=$offset)
359
    {
360
        $morelink = "<a href=\"admin.php?op=showUserActivity&min=".$max."&user_id=".$user."&srchFile=".$srchFile."&srchAction=".$srchAction."\">";
361
        $morelink .= "<font class=\"TinyWhite\">["._SHOWMORE."&gt;&gt;</font></a>";
362
    }
363
?>
364
    <div id="overDiv" style="position:absolute;visibility:hidden;z-index:1000;"></div>
365
    <script language="JavaScript">
366
        var ol_closeclick = "1";
367
        var ol_close = "<font color=#ffffff><b>X</b></font>";
368
        var ol_fgclass = "fg";
369
        var ol_bgclass = "bg";
370
        var ol_captionfontclass = "overCaption";
371
        var ol_closefontclass = "overClose";
372
        var ol_textfontclass = "overBody";
373
        var ol_cap = "&nbsp;IP Info";
374
    </script>
375
    <script src="overlib.js" type="text/javascript"></script>
376
    <div align="center">
377
    <table>
378
    <form action="admin.php?op=showUserActivity" name="searchForm" method="post">
379
    <tr>
380
        <td>
381
        <strong><?php echo _ACTIVITYSEARCH ?></strong>&nbsp;&nbsp;&nbsp;
382
        <?php echo _FILE ?>:
383
        <input type="Text" name="srchFile" value="<?php echo $srchFile ?>" width="30"> &nbsp;&nbsp;
384
        <?php echo _ACTION ?>:
385
        <select name="srchAction">
386
        <option value="">-- <?php echo _ALL ?> --</option>
387
<?php
388
        $selected = "";
389
        foreach ($cfg["constants"] as $action)
390
        {
391
            $selected = "";
392
            if($action != $cfg["constants"]["hit"])
393
            {
394
                if($srchAction == $action)
395
                {
396
                    $selected = "selected";
397
                }
398
                echo "<option value=\"".$action."\" ".$selected.">".$action."</option>";
399
            }
400
        }
401
?>
402
        </select>&nbsp;&nbsp;
403
        <?php echo _USER ?>:
404
        <select name="user_id">
405
        <option value="">-- <?php echo _ALL ?> --</option>
406
<?php
407
        $users = GetUsers();
408
        $selected = "";
409
        for($inx = 0; $inx < sizeof($users); $inx++)
410
        {
411
            $selected = "";
412
            if($user == $users[$inx])
413
            {
414
                $selected = "selected";
415
            }
416
            echo "<option value=\"".$users[$inx]."\" ".$selected.">".$users[$inx]."</option>";
417
        }
418
?>
419
        </select>
420
        <input type="Submit" value="<?php echo _SEARCH ?>">
421
 
422
        </td>
423
    </tr>
424
    </form>
425
    </table>
426
    </div>
427
 
428
 
429
<?php
430
    echo "<table width=\"760\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
431
    echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
432
    echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr><td>";
433
    echo "<img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\">"._ACTIVITYLOG." ".$cfg["days_to_keep"]." "._DAYS." (".$userdisplay.")</font>";
434
    if(!empty($prevlink) && !empty($morelink))
435
        echo "</td><td align=\"right\">".$prevlink.$morelink."</td></tr></table>";
436
    elseif(!empty($prevlink))
437
        echo "</td><td align=\"right\">".$prevlink."</td></tr></table>";
438
    elseif(!empty($prevlink))
439
        echo "</td><td align=\"right\">".$morelink."</td></tr></table>";
440
    else
441
        echo "</td><td align=\"right\"></td></tr></table>";
442
    echo "</td></tr>";
443
    echo "<tr>";
444
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\"><div align=center class=\"title\">"._USER."</div></td>";
445
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\"><div align=center class=\"title\">"._ACTION."</div></td>";
446
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\"><div align=center class=\"title\">"._FILE."</div></td>";
447
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"13%\"><div align=center class=\"title\">"._IP."</div></td>";
448
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"15%\"><div align=center class=\"title\">"._TIMESTAMP."</div></td>";
449
    echo "</tr>";
450
 
451
    echo $output;
452
 
453
    if(!empty($prevlink) || !empty($morelink))
454
    {
455
        echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\">";
456
        echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr><td align=\"left\">";
457
        if(!empty($prevlink)) echo $prevlink;
458
        echo "</td><td align=\"right\">";
459
        if(!empty($morelink)) echo $morelink;
460
        echo "</td></tr></table>";
461
        echo "</td></tr>";
462
    }
463
 
464
    echo "</table>";
465
 
466
}
467
 
468
 
469
 
470
//****************************************************************************
471
// displayUserSection -- displays the user section
472
//****************************************************************************
473
function displayUserSection()
474
{
475
    global $cfg, $db;
476
 
477
    echo "<table width=\"760\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
478
    echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\"><img src=\"images/user_group.gif\" width=17 height=14 border=0>&nbsp;&nbsp;<font class=\"title\">"._USERDETAILS."</font></div></td></tr>";
479
    echo "<tr>";
480
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"15%\"><div align=center class=\"title\">"._USER."</div></td>";
481
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"6%\"><div align=center class=\"title\">"._HITS."</div></td>";
482
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\"><div align=center class=\"title\">"._UPLOADACTIVITY." (".$cfg["days_to_keep"]." "._DAYS.")</div></td>";
483
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"6%\"><div align=center class=\"title\">"._JOINED."</div></td>";
484
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"15%\"><div align=center class=\"title\">"._LASTVISIT."</div></td>";
485
    echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"8%\"><div align=center class=\"title\">"._ADMIN."</div></td>";
486
    echo "</tr>";
487
 
488
    $total_activity = GetActivityCount();
489
 
490
    $sql= "SELECT user_id, hits, last_visit, time_created, user_level FROM tf_users ORDER BY user_id";
491
    $result = $db->Execute($sql);
492
    while(list($user_id, $hits, $last_visit, $time_created, $user_level) = $result->FetchRow())
493
    {
494
        $user_activity = GetActivityCount($user_id);
495
 
496
        if ($user_activity == 0)
497
        {
498
            $user_percent = 0;
499
        }
500
        else
501
        {
502
            $user_percent = number_format(($user_activity/$total_activity)*100);
503
        }
504
        $user_icon = "images/user_offline.gif";
505
        if (IsOnline($user_id))
506
        {
507
            $user_icon = "images/user.gif";
508
        }
509
 
510
        echo "<tr>";
511
        if (IsUser($user_id))
512
        {
513
            echo "<td><a href=\"message.php?to_user=".$user_id."\"><img src=\"".$user_icon."\" width=17 height=14 title=\""._SENDMESSAGETO." ".$user_id."\" border=0 align=\"bottom\">".$user_id."</a></td>";
514
        }
515
        else
516
        {
517
            echo "<td><img src=\"".$user_icon."\" width=17 height=14 title=\"n/a\" border=0 align=\"bottom\">".$user_id."</td>";
518
        }
519
        echo "<td><div class=\"tiny\" align=\"right\">".$hits."</div></td>";
520
        echo "<td><div align=center>";
521
?>
522
        <table width="310" border="0" cellpadding="0" cellspacing="0">
523
        <tr>
524
        <td width="200">
525
            <table width="200" border="0" cellpadding="0" cellspacing="0">
526
            <tr>
527
                <td background="themes/<?php echo $cfg["theme"] ?>/images/proglass.gif" width="<?php echo $user_percent*2 ?>"><img src="images/blank.gif" width="1" height="12" border="0"></td>
528
                <td background="themes/<?php echo $cfg["theme"] ?>/images/noglass.gif" width="<?php echo (200 - ($user_percent*2)) ?>"><img src="images/blank.gif" width="1" height="12" border="0"></td>
529
            </tr>
530
            </table>
531
        </td>
532
        <td align="right" width="40"><div class="tiny" align="right"><?php echo $user_activity ?></div></td>
533
        <td align="right" width="40"><div class="tiny" align="right"><?php echo $user_percent ?>%</div></td>
534
        <td align="right"><a href="admin.php?op=showUserActivity&user_id=<?php echo $user_id ?>"><img src="images/properties.png" width="18" height="13" title="<?php echo $user_id."'s "._USERSACTIVITY ?>" border="0"></a></td>
535
        </tr>
536
        </table>
537
<?php
538
        echo "</td>";
539
        echo "<td><div class=\"tiny\" align=\"center\">".date(_DATEFORMAT, $time_created)."</div></td>";
540
        echo "<td><div class=\"tiny\" align=\"center\">".date(_DATETIMEFORMAT, $last_visit)."</div></td>";
541
        echo "<td><div align=\"right\" class=\"tiny\">";
542
        $user_image = "images/user.gif";
543
        $type_user = _NORMALUSER;
544
        if ($user_level == 1)
545
        {
546
            $user_image = "images/admin_user.gif";
547
            $type_user = _ADMINISTRATOR;
548
        }
549
        if ($user_level == 2)
550
        {
551
            $user_image = "images/superadmin.gif";
552
            $type_user = _SUPERADMIN;
553
        }
554
        if ($user_level <= 1 || IsSuperAdmin())
555
        {
556
            echo "<a href=\"admin.php?op=editUser&user_id=".$user_id."\"><img src=\"images/edit.png\" width=12 height=13 title=\""._EDIT." ".$user_id."\" border=0></a>";
557
        }
558
        echo "<img src=\"".$user_image."\" title=\"".$user_id." - ".$type_user."\">";
559
        if ($user_level <= 1)
560
        {
561
            echo "<a href=\"admin.php?op=deleteUser&user_id=".$user_id."\"><img src=\"images/delete_on.gif\" border=0 width=16 height=16 title=\""._DELETE." ".$user_id."\" onclick=\"return ConfirmDeleteUser('".$user_id."')\"></a>";
562
        }
563
        else
564
        {
565
            echo "<img src=\"images/delete_off.gif\" width=16 height=16 title=\"n/a\">";
566
        }
567
 
568
        echo "</div></td>";
569
        echo "</tr>";
570
    }
571
 
572
    echo "</table>";
573
?>
574
    <script language="JavaScript">
575
    function ConfirmDeleteUser(user)
576
    {
577
        return confirm("<?php echo _WARNING.": "._ABOUTTODELETE ?>: " + user)
578
    }
579
    </script>
580
<?php
581
}
582
 
583
 
584
//****************************************************************************
585
// editUser -- edit a user
586
//****************************************************************************
587
function editUser($user_id)
588
{
589
    global $cfg, $db;
590
    DisplayHead(_USERADMIN);
591
 
592
    $editUserImage = "images/user.gif";
593
    $selected_n = "selected";
594
    $selected_a = "";
595
 
596
    $hide_checked = "";
597
 
598
    // Admin Menu
599
    displayMenu();
600
 
601
    $total_activity = GetActivityCount();
602
 
603
    $sql= "SELECT user_id, hits, last_visit, time_created, user_level, hide_offline, theme, language_file FROM tf_users WHERE user_id=".$db->qstr($user_id);
604
 
605
    list($user_id, $hits, $last_visit, $time_created, $user_level, $hide_offline, $theme, $language_file) = $db->GetRow($sql);
606
 
607
    $user_type = _NORMALUSER;
608
    if ($user_level == 1)
609
    {
610
        $user_type = _ADMINISTRATOR;
611
        $selected_n = "";
612
        $selected_a = "selected";
613
        $editUserImage = "images/admin_user.gif";
614
    }
615
    if ($user_level >= 2)
616
    {
617
        $user_type = _SUPERADMIN;
618
        $editUserImage = "images/superadmin.gif";
619
    }
620
 
621
    if ($hide_offline == 1)
622
    {
623
        $hide_checked = "checked";
624
    }
625
 
626
 
627
    $user_activity = GetActivityCount($user_id);
628
 
629
    if ($user_activity == 0)
630
    {
631
        $user_percent = 0;
632
    }
633
    else
634
    {
635
        $user_percent = number_format(($user_activity/$total_activity)*100);
636
    }
637
 
638
    echo "<div align=\"center\">";
639
    echo "<table width=\"100%\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
640
    echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
641
    echo "<img src=\"".$editUserImage."\" width=17 height=14 border=0>&nbsp;&nbsp;&nbsp;<font class=\"title\">"._EDITUSER.": ".$user_id."</font>";
642
    echo "</td></tr><tr><td align=\"center\">";
643
?>
644
 
645
    <table width="100%" border="0" cellpadding="3" cellspacing="0">
646
    <tr>
647
        <td width="50%" bgcolor="<?php echo $cfg["table_data_bg"]?>" valign="top">
648
 
649
        <div align="center">
650
        <table border="0" cellpadding="0" cellspacing="0">
651
        <tr>
652
            <td align="right"><?php echo $user_id." "._JOINED ?>:&nbsp;</td>
653
            <td><strong><?php echo date(_DATETIMEFORMAT, $time_created) ?></strong></td>
654
        </tr>
655
        <tr>
656
            <td align="right"><?php echo _LASTVISIT ?>:&nbsp;</td>
657
            <td><strong><?php echo date(_DATETIMEFORMAT, $last_visit) ?></strong></td>
658
        </tr>
659
        <tr>
660
            <td colspan="2" align="center">&nbsp;</td>
661
        </tr>
662
        <tr>
663
            <td align="right"><?php echo _UPLOADPARTICIPATION ?>:&nbsp;</td>
664
            <td>
665
                <table width="200" border="0" cellpadding="0" cellspacing="0">
666
                <tr>
667
                    <td background="themes/<?php echo $cfg["theme"] ?>/images/proglass.gif" width="<?php echo $user_percent*2 ?>"><img src="images/blank.gif" width="1" height="12" border="0"></td>
668
                    <td background="themes/<?php echo $cfg["theme"] ?>/images/noglass.gif" width="<?php echo (200 - ($user_percent*2)) ?>"><img src="images/blank.gif" width="1" height="12" border="0"></td>
669
                </tr>
670
                </table>
671
            </td>
672
        </tr>
673
        <tr>
674
            <td align="right"><?php echo _UPLOADS ?>:&nbsp;</td>
675
            <td><strong><?php echo $user_activity ?></strong></td>
676
        </tr>
677
        <tr>
678
            <td align="right"><?php echo _PERCENTPARTICIPATION ?>:&nbsp;</td>
679
            <td><strong><?php echo $user_percent ?>%</strong></td>
680
        </tr>
681
        <tr>
682
            <td colspan="2" align="center"><div align="center" class="tiny">(<?php echo _PARTICIPATIONSTATEMENT. " ".$cfg['days_to_keep']." "._DAYS ?>)</div><br></td>
683
        </tr>
684
        <tr>
685
            <td align="right"><?php echo _TOTALPAGEVIEWS ?>:&nbsp;</td>
686
            <td><strong><?php echo $hits ?></strong></td>
687
        </tr>
688
        <tr>
689
            <td align="right" valign="top"><?php echo _THEME ?>:&nbsp;</td>
690
            <td valign="top"><strong><?php echo $theme ?></strong><br></td>
691
        </tr>
692
        <tr>
693
            <td align="right" valign="top"><?php echo _LANGUAGE ?>:&nbsp;</td>
694
            <td valign="top"><strong><?php echo GetLanguageFromFile($language_file) ?></strong><br><br></td>
695
        </tr>
696
        <tr>
697
            <td align="right" valign="top"><?php echo _USERTYPE ?>:&nbsp;</td>
698
            <td valign="top"><strong><?php echo $user_type ?></strong><br></td>
699
        </tr>
700
        <tr>
701
            <td colspan="2" align="center"><div align="center">[<a href="admin.php?op=showUserActivity&user_id=<?php echo $user_id ?>"><?php echo _USERSACTIVITY ?></a>]</div></td>
702
        </tr>
703
        </table>
704
        </div>
705
 
706
        </td>
707
        <td valign="top" bgcolor="<?php echo $cfg["body_data_bg"] ?>">
708
        <div align="center">
709
        <table cellpadding="5" cellspacing="0" border="0">
710
        <form name="theForm" action="admin.php?op=updateUser" method="post" onsubmit="return validateUser()">
711
        <tr>
712
            <td align="right"><?php echo _USER ?>:</td>
713
            <td>
714
            <input name="user_id" type="Text" value="<?php echo $user_id ?>" size="15">
715
            <input name="org_user_id" type="Hidden" value="<?php echo $user_id ?>">
716
            </td>
717
        </tr>
718
        <tr>
719
            <td align="right"><?php echo _NEWPASSWORD ?>:</td>
720
            <td>
721
            <input name="pass1" type="Password" value="" size="15">
722
            </td>
723
        </tr>
724
        <tr>
725
            <td align="right"><?php echo _CONFIRMPASSWORD ?>:</td>
726
            <td>
727
            <input name="pass2" type="Password" value="" size="15">
728
            </td>
729
        </tr>
730
        <tr>
731
            <td align="right"><?php echo _USERTYPE ?>:</td>
732
            <td>
733
<?php if ($user_level <= 1) { ?>
734
            <select name="userType">
735
                <option value="0" <?php echo $selected_n ?>><?php echo _NORMALUSER ?></option>
736
                <option value="1" <?php echo $selected_a ?>><?php echo _ADMINISTRATOR ?></option>
737
            </select>
738
<?php } else { ?>
739
            <strong><?php echo _SUPERADMIN ?></strong>
740
            <input type="Hidden" name="userType" value="2">
741
<?php } ?>
742
            </td>
743
        </tr>
744
        <tr>
745
            <td colspan="2">
746
            <input name="hideOffline" type="Checkbox" value="1" <?php echo $hide_checked ?>> <?php echo _HIDEOFFLINEUSERS ?><br>
747
            </td>
748
        </tr>
749
        <tr>
750
            <td align="center" colspan="2">
751
            <input type="Submit" value="<?php echo _UPDATE ?>">
752
            </td>
753
        </tr>
754
        </form>
755
        </table>
756
        </div>
757
        </td>
758
    </tr>
759
    </table>
760
 
761
 
762
    <script language="JavaScript">
763
    function validateUser()
764
    {
765
        var msg = ""
766
        if (theForm.user_id.value == "")
767
        {
768
            msg = msg + "* <?php echo _USERIDREQUIRED ?>\n";
769
            theForm.user_id.focus();
770
        }
771
 
772
        if (theForm.pass1.value != "" || theForm.pass2.value != "")
773
        {
774
            if (theForm.pass1.value.length <= 5 || theForm.pass2.value.length <= 5)
775
            {
776
                msg = msg + "* <?php echo _PASSWORDLENGTH ?>\n";
777
                theForm.pass1.focus();
778
            }
779
            if (theForm.pass1.value != theForm.pass2.value)
780
            {
781
                msg = msg + "* <?php echo _PASSWORDNOTMATCH ?>\n";
782
                theForm.pass1.value = "";
783
                theForm.pass2.value = "";
784
                theForm.pass1.focus();
785
            }
786
        }
787
 
788
        if (msg != "")
789
        {
790
            alert("<?php echo _PLEASECHECKFOLLOWING ?>:\n\n" + msg);
791
            return false;
792
        }
793
        else
794
        {
795
            return true;
796
        }
797
    }
798
    </script>
799
 
800
<?php
801
    echo "</td></tr>";
802
    echo "</table></div>";
803
    echo "<br><br>";
804
 
805
    // Show User Section
806
    displayUserSection();
807
 
808
    echo "<br><br>";
809
 
810
    DisplayFoot();
811
}
812
 
813
 
814
//****************************************************************************
815
// CreateUser -- Create a user
816
//****************************************************************************
817
function CreateUser()
818
{
819
    global $cfg;
820
    DisplayHead(_USERADMIN);
821
 
822
    // Admin Menu
823
    displayMenu();
824
    echo "<div align=\"center\">";
825
    echo "<table border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
826
    echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
827
    echo "<img src=\"images/user.gif\" width=17 height=14 border=0>&nbsp;&nbsp;&nbsp;<font class=\"title\">"._NEWUSER."</font>";
828
    echo "</td></tr><tr><td align=\"center\">";
829
?>
830
    <div align="center">
831
        <table cellpadding="5" cellspacing="0" border="0">
832
        <form name="theForm" action="admin.php?op=addUser" method="post" onsubmit="return validateProfile()">
833
        <tr>
834
            <td align="right"><?php echo _USER ?>:</td>
835
            <td>
836
            <input name="newUser" type="Text" value="" size="15">
837
            </td>
838
        </tr>
839
        <tr>
840
            <td align="right"><?php echo _PASSWORD ?>:</td>
841
            <td>
842
            <input name="pass1" type="Password" value="" size="15">
843
            </td>
844
        </tr>
845
        <tr>
846
            <td align="right"><?php echo _CONFIRMPASSWORD ?>:</td>
847
            <td>
848
            <input name="pass2" type="Password" value="" size="15">
849
            </td>
850
        </tr>
851
        <tr>
852
            <td align="right"><?php echo _USERTYPE ?>:</td>
853
            <td>
854
            <select name="userType">
855
                <option value="0"><?php echo _NORMALUSER ?></option>
856
                <option value="1"><?php echo _ADMINISTRATOR ?></option>
857
            </select>
858
            </td>
859
        </tr>
860
        <tr>
861
            <td align="center" colspan="2">
862
            <input type="Submit" value="<?php echo _CREATE ?>">
863
            </td>
864
        </tr>
865
        </form>
866
        </table>
867
        </div>
868
 
869
    <br>
870
 
871
    <script language="JavaScript">
872
    function validateProfile()
873
    {
874
        var msg = ""
875
        if (theForm.newUser.value == "")
876
        {
877
            msg = msg + "* <?php echo _USERIDREQUIRED ?>\n";
878
            theForm.newUser.focus();
879
        }
880
        if (theForm.pass1.value != "" || theForm.pass2.value != "")
881
        {
882
            if (theForm.pass1.value.length <= 5 || theForm.pass2.value.length <= 5)
883
            {
884
                msg = msg + "* <?php echo _PASSWORDLENGTH ?>\n";
885
                theForm.pass1.focus();
886
            }
887
            if (theForm.pass1.value != theForm.pass2.value)
888
            {
889
                msg = msg + "* <?php echo _PASSWORDNOTMATCH ?>\n";
890
                theForm.pass1.value = "";
891
                theForm.pass2.value = "";
892
                theForm.pass1.focus();
893
            }
894
        }
895
        else
896
        {
897
            msg = msg + "* <?php echo _PASSWORDLENGTH ?>\n";
898
            theForm.pass1.focus();
899
        }
900
 
901
        if (msg != "")
902
        {
903
            alert("<?php echo _PLEASECHECKFOLLOWING ?>:\n\n" + msg);
904
            return false;
905
        }
906
        else
907
        {
908
            return true;
909
        }
910
    }
911
    </script>
912
 
913
<?php
914
    echo "</td></tr>";
915
    echo "</table></div>";
916
    echo "<br><br>";
917
 
918
    // Show User Section
919
    displayUserSection();
920
 
921
    echo "<br><br>";
922
 
923
    DisplayFoot();
924
}
925
 
926
//****************************************************************************
927
// editLinks -- Edit Links
928
//****************************************************************************
929
function editLinks()
930
{
931
    global $cfg;
932
    DisplayHead(_ADMINEDITLINKS);
933
 
934
    // Admin Menu
935
    displayMenu();
936
    echo "<div align=\"center\">";
937
    echo "<table border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
938
    echo "<tr><td bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
939
    echo "<img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\">"._ADMINEDITLINKS."</font>";
940
    echo "</td></tr><tr><td align=\"center\">";
941
?>
942
    <form action="admin.php?op=addLink" method="post">
943
    <?php echo _FULLURLLINK ?>:
944
    <input type="Text" size="50" maxlength="255" name="newLink">
945
    <input type="Submit" value="<?php echo _UPDATE ?>"><br>
946
    </form>
947
<?php
948
    echo "</td></tr>";
949
    $arLinks = GetLinks();
950
    $arLid = Array_Keys($arLinks);
951
    $inx = 0;
952
    foreach($arLinks as $link)
953
    {
954
        $lid = $arLid[$inx++];
955
        echo "<tr><td><a href=\"admin.php?op=deleteLink&lid=".$lid."\"><img src=\"images/delete_on.gif\" width=16 height=16 border=0 title=\""._DELETE." ".$lid."\" align=\"absmiddle\"></a>&nbsp;";
956
        echo "<a href=\"".$link."\" target=\"_blank\">".$link."</a></td></tr>\n";
957
    }
958
 
959
    echo "</table></div><br><br><br>";
960
 
961
    DisplayFoot();
962
 
963
}
964
 
965
 
966
//****************************************************************************
967
// editRSS -- Edit RSS Feeds
968
//****************************************************************************
969
function editRSS()
970
{
971
    global $cfg;
972
    DisplayHead("Administration - RSS");
973
 
974
    // Admin Menu
975
    displayMenu();
976
    echo "<div align=\"center\">";
977
    echo "<table border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
978
    echo "<tr><td bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
979
    echo "<img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\">RSS Feeds</font>";
980
    echo "</td></tr><tr><td align=\"center\">";
981
?>
982
    <form action="admin.php?op=addRSS" method="post">
983
    <?php echo _FULLURLLINK ?>:
984
    <input type="Text" size="50" maxlength="255" name="newRSS">
985
    <input type="Submit" value="<?php echo _UPDATE ?>"><br>
986
    </form>
987
<?php
988
    echo "</td></tr>";
989
    $arLinks = GetRSSLinks();
990
    $arRid = Array_Keys($arLinks);
991
    $inx = 0;
992
    foreach($arLinks as $link)
993
    {
994
        $rid = $arRid[$inx++];
995
        echo "<tr><td><a href=\"admin.php?op=deleteRSS&rid=".$rid."\"><img src=\"images/delete_on.gif\" width=16 height=16 border=0 title=\""._DELETE." ".$rid."\" align=\"absmiddle\"></a>&nbsp;";
996
        echo "<a href=\"".$link."\" target=\"_blank\">".$link."</a></td></tr>\n";
997
    }
998
 
999
    echo "</table></div><br><br><br>";
1000
 
1001
    DisplayFoot();
1002
 
1003
}
1004
 
1005
//****************************************************************************
1006
// validateFile -- Validates the existance of a file and returns the status image
1007
//****************************************************************************
1008
function validateFile($the_file)
1009
{
1010
    $msg = "<img src=\"images/red.gif\" align=\"absmiddle\" title=\"Path is not Valid\"><br><font color=\"#ff0000\">Path is not Valid</font>";
1011
    if (isFile($the_file))
1012
    {
1013
        $msg = "<img src=\"images/green.gif\" align=\"absmiddle\" title=\"Valid\">";
1014
    }
1015
    return $msg;
1016
}
1017
 
1018
//****************************************************************************
1019
// validatePath -- Validates TF Path and Permissions
1020
//****************************************************************************
1021
function validatePath($path)
1022
{
1023
    $msg = "<img src=\"images/red.gif\" align=\"absmiddle\" title=\"Path is not Valid\"><br><font color=\"#ff0000\">Path is not Valid</font>";
1024
    if (is_dir($path))
1025
    {
1026
        if (is_writable($path))
1027
        {
1028
            $msg = "<img src=\"images/green.gif\" align=\"absmiddle\" title=\"Valid\">";
1029
        }
1030
        else
1031
        {
1032
            $msg = "<img src=\"images/red.gif\" align=\"absmiddle\" title=\"Path is not Writable\"><br><font color=\"#ff0000\">Path is not Writable -- make sure you chmod +w this path</font>";
1033
        }
1034
    }
1035
    return $msg;
1036
}
1037
 
1038
//****************************************************************************
1039
// configSettings -- Config the Application Settings
1040
//****************************************************************************
1041
function configSettings()
1042
{
1043
    global $cfg;
1044
    include_once("AliasFile.php");
1045
    include_once("RunningTorrent.php");
1046
 
1047
    DisplayHead("Administration - Settings");
1048
 
1049
    // Admin Menu
1050
    displayMenu();
1051
 
1052
    // Main Settings Section
1053
    echo "<div align=\"center\">";
1054
    echo "<table width=\"100%\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
1055
    echo "<tr><td bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
1056
    echo "<img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\">TorrentFlux Settings</font>";
1057
    echo "</td></tr><tr><td align=\"center\">";
1058
 
1059
?>
1060
 
1061
    <script language="JavaScript">
1062
    function validateSettings()
1063
    {
1064
        var rtnValue = true;
1065
        var msg = "";
1066
        if (isNumber(document.theForm.max_upload_rate.value) == false)
1067
        {
1068
            msg = msg + "* Max Upload Rate must be a valid number.\n";
1069
            document.theForm.max_upload_rate.focus();
1070
        }
1071
        if (isNumber(document.theForm.max_download_rate.value) == false)
1072
        {
1073
            msg = msg + "* Max Download Rate must be a valid number.\n";
1074
            document.theForm.max_download_rate.focus();
1075
        }
1076
        if (isNumber(document.theForm.max_uploads.value) == false)
1077
        {
1078
            msg = msg + "* Max # Uploads must be a valid number.\n";
1079
            document.theForm.max_uploads.focus();
1080
        }
1081
        if ((isNumber(document.theForm.minport.value) == false) || (isNumber(document.theForm.maxport.value) == false))
1082
        {
1083
            msg = msg + "* Port Range must have valid numbers.\n";
1084
            document.theForm.minport.focus();
1085
        }
1086
        if (isNumber(document.theForm.rerequest_interval.value) == false)
1087
        {
1088
            msg = msg + "* Rerequest Interval must have a valid number.\n";
1089
            document.theForm.rerequest_interval.focus();
1090
        }
1091
        if (document.theForm.rerequest_interval.value < 10)
1092
        {
1093
            msg = msg + "* Rerequest Interval must 10 or greater.\n";
1094
            document.theForm.rerequest_interval.focus();
1095
        }
1096
        if (isNumber(document.theForm.days_to_keep.value) == false)
1097
        {
1098
            msg = msg + "* Days to keep Audit Actions must be a valid number.\n";
1099
            document.theForm.days_to_keep.focus();
1100
        }
1101
        if (isNumber(document.theForm.minutes_to_keep.value) == false)
1102
        {
1103
            msg = msg + "* Minutes to keep user online must be a valid number.\n";
1104
            document.theForm.minutes_to_keep.focus();
1105
        }
1106
        if (isNumber(document.theForm.rss_cache_min.value) == false)
1107
        {
1108
            msg = msg + "* Minutes to Cache RSS Feeds must be a valid number.\n";
1109
            document.theForm.rss_cache_min.focus();
1110
        }
1111
        if (isNumber(document.theForm.page_refresh.value) == false)
1112
        {
1113
            msg = msg + "* Page Refresh must be a valid number.\n";
1114
            document.theForm.page_refresh.focus();
1115
        }
1116
        if (isNumber(document.theForm.sharekill.value) == false)
1117
        {
1118
            msg = msg + "* Keep seeding until Sharing % must be a valid number.\n";
1119
            document.theForm.sharekill.focus();
1120
        }
1121
        if ((document.theForm.maxport.value > 65535) || (document.theForm.minport.value > 65535))
1122
        {
1123
            msg = msg + "* Port can not be higher than 65535.\n";
1124
            document.theForm.minport.focus();
1125
        }
1126
        if ((document.theForm.maxport.value < 0) || (document.theForm.minport.value < 0))
1127
        {
1128
            msg = msg + "* Can not have a negative number for port value.\n";
1129
            document.theForm.minport.focus();
1130
        }
1131
        if (document.theForm.maxport.value < document.theForm.minport.value)
1132
        {
1133
            msg = msg + "* Port Range is not valid.\n";
1134
            document.theForm.minport.focus();
1135
        }
1136
 
1137
        if (msg != "")
1138
        {
1139
            rtnValue = false;
1140
            alert("Please check the following:\n\n" + msg);
1141
        }
1142
 
1143
        return rtnValue;
1144
    }
1145
 
1146
    function isNumber(sText)
1147
    {
1148
        var ValidChars = "0123456789";
1149
        var IsNumber = true;
1150
        var Char;
1151
 
1152
        for (i = 0; i < sText.length && IsNumber == true; i++)
1153
        {
1154
            Char = sText.charAt(i);
1155
            if (ValidChars.indexOf(Char) == -1)
1156
            {
1157
                IsNumber = false;
1158
            }
1159
        }
1160
 
1161
        return IsNumber;
1162
    }
1163
    </script>
1164
 
1165
    <div align="center">
1166
 
1167
        <table cellpadding="5" cellspacing="0" border="0" width="100%">
1168
        <form name="theForm" action="admin.php?op=updateConfigSettings" method="post" onsubmit="return validateSettings()">
1169
        <input type="Hidden" name="continue" value="configSettings">
1170
        <tr>
1171
            <td align="left" width="350" valign="top"><strong>Path</strong><br>
1172
            Define the PATH where the downloads will go <br>(make sure it ends with a / [slash]).
1173
            It must be chmod'd to 777:
1174
            </td>
1175
            <td valign="top">
1176
                <input name="path" type="Text" maxlength="254" value="<?php    echo($cfg["path"]); ?>" size="55"><?php echo validatePath($cfg["path"]) ?>
1177
            </td>
1178
        </tr>
1179
        <tr>
1180
            <td align="left" width="350" valign="top"><strong>Python Path</strong><br>
1181
            Specify the path to the Python binary (usually /usr/bin/python or /usr/local/bin/python):
1182
            </td>
1183
            <td valign="top">
1184
                <input name="pythonCmd" type="Text" maxlength="254" value="<?php    echo($cfg["pythonCmd"]); ?>" size="55"><?php echo validateFile($cfg["pythonCmd"]) ?>
1185
            </td>
1186
        </tr>
1187
        <tr>
1188
            <td align="left" width="350" valign="top"><strong>btphptornado.py Path</strong><br>
1189
            Specify the path to the btphptornado.py python script:
1190
            </td>
1191
            <td valign="top">
1192
                <input name="btphpbin" type="Text" maxlength="254" value="<?php    echo($cfg["btphpbin"]); ?>" size="55"><?php echo validateFile($cfg["btphpbin"]) ?>
1193
            </td>
1194
        </tr>
1195
        <tr>
1196
            <td align="left" width="350" valign="top"><strong>btshowmetainfo.py Path</strong><br>
1197
            Specify the path to the btshowmetainfo.py python script:
1198
            </td>
1199
            <td valign="top">
1200
                <input name="btshowmetainfo" type="Text" maxlength="254" value="<?php    echo($cfg["btshowmetainfo"]); ?>" size="55"><?php echo validateFile($cfg["btshowmetainfo"]) ?>
1201
            </td>
1202
        </tr>
1203
        <tr>
1204
            <td align="left" width="350" valign="top"><strong>Use Advanced Start Dialog</strong><br>
1205
            When enabled, users will be given the advanced start dialog popup when starting a torrent:
1206
            </td>
1207
            <td valign="top">
1208
                <select name="advanced_start">
1209
                        <option value="1">true</option>
1210
                        <option value="0" <?php
1211
                        if (!$cfg["advanced_start"])
1212
                        {
1213
                            echo "selected";
1214
                        }
1215
                        ?>>false</option>
1216
                </select>
1217
            </td>
1218
        </tr>
1219
        <tr>
1220
            <td align="left" width="350" valign="top"><strong>Enable File Priority</strong><br>
1221
            When enabled, users will be allowed to select particular files from the torrent to download:
1222
            </td>
1223
            <td valign="top">
1224
                <select name="enable_file_priority">
1225
                        <option value="1">true</option>
1226
                        <option value="0" <?php
1227
                        if (!$cfg["enable_file_priority"])
1228
                        {
1229
                            echo "selected";
1230
                        }
1231
                        ?>>false</option>
1232
                </select>
1233
            </td>
1234
        </tr>
1235
        <tr>
1236
            <td align="left" width="350" valign="top"><strong>Max Upload Rate</strong><br>
1237
            Set the default value for the max upload rate per torrent:
1238
            </td>
1239
            <td valign="top">
1240
                <input name="max_upload_rate" type="Text" maxlength="5" value="<?php    echo($cfg["max_upload_rate"]); ?>" size="5"> KB/second
1241
            </td>
1242
        </tr>
1243
        <tr>
1244
            <td align="left" width="350" valign="top"><strong>Max Download Rate</strong><br>
1245
            Set the default value for the max download rate per torrent (0 for no limit):
1246
            </td>
1247
            <td valign="top">
1248
                <input name="max_download_rate" type="Text" maxlength="5" value="<?php    echo($cfg["max_download_rate"]); ?>" size="5"> KB/second
1249
            </td>
1250
        </tr>
1251
        <tr>
1252
            <td align="left" width="350" valign="top"><strong>Max Upload Connections</strong><br>
1253
            Set the default value for the max number of upload connections per torrent:
1254
            </td>
1255
            <td valign="top">
1256
                <input name="max_uploads" type="Text" maxlength="5" value="<?php    echo($cfg["max_uploads"]); ?>" size="5">
1257
            </td>
1258
        </tr>
1259
        <tr>
1260
            <td align="left" width="350" valign="top"><strong>Port Range</strong><br>
1261
            Set the default values for the for port range (Min - Max):
1262
            </td>
1263
            <td valign="top">
1264
                <input name="minport" type="Text" maxlength="5" value="<?php    echo($cfg["minport"]); ?>" size="5"> -
1265
                <input name="maxport" type="Text" maxlength="5" value="<?php    echo($cfg["maxport"]); ?>" size="5">
1266
            </td>
1267
        </tr>
1268
        <tr>
1269
            <td align="left" width="350" valign="top"><strong>Rerequest Interval</strong><br>
1270
            Set the default value for the rerequest interval to the tracker (default 1800 seconds):
1271
            </td>
1272
            <td valign="top">
1273
                <input name="rerequest_interval" type="Text" maxlength="5" value="<?php    echo($cfg["rerequest_interval"]); ?>" size="5">
1274
            </td>
1275
        </tr>
1276
        <tr>
1277
            <td align="left" width="350" valign="top"><strong>Extra BitTornado Commandline Options</strong><br>
1278
            DO NOT include --max_upload_rate, --minport, --maxport, --max_uploads here as they are
1279
            included by TorrentFlux settings above:
1280
            </td>
1281
            <td valign="top">
1282
                <input name="cmd_options" type="Text" maxlength="254" value="<?php    echo($cfg["cmd_options"]); ?>" size="55">
1283
            </td>
1284
        </tr>
1285
        <tr>
1286
            <td align="left" width="350" valign="top"><strong>Enable Torrent Search</strong><br>
1287
            When enabled, users will be allowed to perform torrent searches from the home page:
1288
            </td>
1289
            <td valign="top">
1290
                <select name="enable_search">
1291
                        <option value="1">true</option>
1292
                        <option value="0" <?php
1293
                        if (!$cfg["enable_search"])
1294
                        {
1295
                            echo "selected";
1296
                        }
1297
                        ?>>false</option>
1298
                </select>
1299
            </td>
1300
        </tr>
1301
        <tr>
1302
            <td align="left" width="350" valign="top"><strong>Default Torrent Search Engine</strong><br>
1303
            Select the default search engine for torrent searches:
1304
            </td>
1305
            <td valign="top">
1306
<?php
1307
                echo buildSearchEngineDDL($cfg["searchEngine"]);
1308
?>
1309
            </td>
1310
        </tr>
1311
        <tr>
1312
            <td align="left" width="350" valign="top"><strong>Enable Make Torrent</strong><br>
1313
            When enabled, users will be allowed make torrent files from the directory view:
1314
            </td>
1315
            <td valign="top">
1316
                <select name="enable_maketorrent">
1317
                        <option value="1">true</option>
1318
                        <option value="0" <?php
1319
                        if (!$cfg["enable_maketorrent"])
1320
                        {
1321
                            echo "selected";
1322
                        }
1323
                        ?>>false</option>
1324
                </select>
1325
            </td>
1326
        </tr>
1327
        <tr>
1328
            <td align="left" width="350" valign="top"><strong>btmakemetafile.py Path</strong><br>
1329
            Specify the path to the btmakemetafile.py python script (used for making torrents):
1330
            </td>
1331
            <td valign="top">
1332
                <input name="btmakemetafile" type="Text" maxlength="254" value="<?php echo($cfg["btmakemetafile"]); ?>" size="55"><?php echo validateFile($cfg["btmakemetafile"]); ?>
1333
            </td>
1334
        </tr>
1335
        <tr>
1336
            <td align="left" width="350" valign="top"><strong>Enable Torrent File Download</strong><br>
1337
            When enabled, users will be allowed download the torrent meta file from the torrent list view:
1338
            </td>
1339
            <td valign="top">
1340
                <select name="enable_torrent_download">
1341
                        <option value="1">true</option>
1342
                        <option value="0" <?php
1343
                        if (!$cfg["enable_torrent_download"])
1344
                        {
1345
                            echo "selected";
1346
                        }
1347
                        ?>>false</option>
1348
                </select>
1349
            </td>
1350
        </tr>
1351
        <tr>
1352
            <td align="left" width="350" valign="top"><strong>Enable File Download</strong><br>
1353
            When enabled, users will be allowed download from the directory view:
1354
            </td>
1355
            <td valign="top">
1356
                <select name="enable_file_download">
1357
                        <option value="1">true</option>
1358
                        <option value="0" <?php
1359
                        if (!$cfg["enable_file_download"])
1360
                        {
1361
                            echo "selected";
1362
                        }
1363
                        ?>>false</option>
1364
                </select>
1365
            </td>
1366
        </tr>
1367
        <tr>
1368
            <td align="left" width="350" valign="top"><strong>Enable Text/NFO Viewer</strong><br>
1369
            When enabled, users will be allowed to view Text/NFO files from the directory listing:
1370
            </td>
1371
            <td valign="top">
1372
                <select name="enable_view_nfo">
1373
                        <option value="1">true</option>
1374
                        <option value="0" <?php
1375
                        if (!$cfg["enable_view_nfo"])
1376
                        {
1377
                            echo "selected";
1378
                        }
1379
                        ?>>false</option>
1380
                </select>
1381
            </td>
1382
        </tr>
1383
        <tr>
1384
            <td align="left" width="350" valign="top"><strong>Download Package Type</strong><br>
1385
            When File Download is enabled, users will be allowed download from the directory view using
1386
            a packaging system.  Make sure your server supports the package type you select:
1387
            </td>
1388
            <td valign="top">
1389
                <select name="package_type">
1390
                        <option value="tar" selected>tar</option>
1391
                        <option value="zip" <?php
1392
                        if ($cfg["package_type"] == "zip")
1393
                        {
1394
                            echo "selected";
1395
                        }
1396
                        ?>>zip</option>
1397
                </select>
1398
            </td>
1399
        </tr>
1400
        <tr>
1401
            <td align="left" width="350" valign="top"><strong>Show Server Load</strong><br>
1402
            Enable showing the average server load over the last 15 minutes from <? echo $cfg["loadavg_path"] ?> file:
1403
            </td>
1404
            <td valign="top">
1405
                <select name="show_server_load">
1406
                        <option value="1">true</option>
1407
                        <option value="0" <?php
1408
                        if (!$cfg["show_server_load"])
1409
                        {
1410
                            echo "selected";
1411
                        }
1412
                        ?>>false</option>
1413
                </select>
1414
            </td>
1415
        </tr>
1416
        <tr>
1417
            <td align="left" width="350" valign="top"><strong>loadavg Path</strong><br>
1418
            Path to the loadavg file:
1419
            </td>
1420
            <td valign="top">
1421
                <input name="loadavg_path" type="Text" maxlength="254" value="<?php    echo($cfg["loadavg_path"]); ?>" size="55"><?php echo validateFile($cfg["loadavg_path"]) ?>
1422
            </td>
1423
        </tr>
1424
        <tr>
1425
            <td align="left" width="350" valign="top"><strong>Days to keep Audit Actions in the Log</strong><br>
1426
            Number of days that audit actions will be held in the database:
1427
            </td>
1428
            <td valign="top">
1429
                <input name="days_to_keep" type="Text" maxlength="3" value="<?php    echo($cfg["days_to_keep"]); ?>" size="3">
1430
            </td>
1431
        </tr>
1432
        <tr>
1433
            <td align="left" width="350" valign="top"><strong>Minutes to Keep User Online Status</strong><br>
1434
            Number of minutes before a user status changes to offline after leaving TorrentFlux:
1435
            </td>
1436
            <td valign="top">
1437
                <input name="minutes_to_keep" type="Text" maxlength="2" value="<?php    echo($cfg["minutes_to_keep"]); ?>" size="2">
1438
            </td>
1439
        </tr>
1440
        <tr>
1441
            <td align="left" width="350" valign="top"><strong>Minutes to Cache RSS Feeds</strong><br>
1442
            Number of minutes to cache the RSS XML feed on server (speeds up reload):
1443
            </td>
1444
            <td valign="top">
1445
                <input name="rss_cache_min" type="Text" maxlength="3" value="<?php    echo($cfg["rss_cache_min"]); ?>" size="3">
1446
            </td>
1447
        </tr>
1448
        <tr>
1449
            <td align="left" width="350" valign="top"><strong>Page Refresh (in seconds)</strong><br>
1450
            Number of seconds before the torrent list page refreshes:
1451
            </td>
1452
            <td valign="top">
1453
                <input name="page_refresh" type="Text" maxlength="3" value="<?php    echo($cfg["page_refresh"]); ?>" size="3">
1454
            </td>
1455
        </tr>
1456
        <tr>
1457
            <td align="left" width="350" valign="top"><strong>Default Theme</strong><br>
1458
            Select the default theme that users will have (including login screen):
1459
            </td>
1460
            <td valign="top">
1461
                <select name="default_theme">
1462
<?php
1463
    $arThemes = GetThemes();
1464
    for($inx = 0; $inx < sizeof($arThemes); $inx++)
1465
    {
1466
        $selected = "";
1467
        if ($cfg["default_theme"] == $arThemes[$inx])
1468
        {
1469
            $selected = "selected";
1470
        }
1471
        echo "<option value=\"".$arThemes[$inx]."\" ".$selected.">".$arThemes[$inx]."</option>";
1472
    }
1473
?>
1474
                </select>
1475
            </td>
1476
        </tr>
1477
        <tr>
1478
            <td align="left" width="350" valign="top"><strong>Default Language</strong><br>
1479
            Select the default language that users will have:
1480
            </td>
1481
            <td valign="top">
1482
                <select name="default_language">
1483
<?php
1484
    $arLanguage = GetLanguages();
1485
    for($inx = 0; $inx < sizeof($arLanguage); $inx++)
1486
    {
1487
        $selected = "";
1488
        if ($cfg["default_language"] == $arLanguage[$inx])
1489
        {
1490
            $selected = "selected";
1491
        }
1492
        echo "<option value=\"".$arLanguage[$inx]."\" ".$selected.">".GetLanguageFromFile($arLanguage[$inx])."</option>";
1493
    }
1494
?>
1495
            </select>
1496
            </td>
1497
        </tr>
1498
        <tr>
1499
            <td align="left" width="350" valign="top"><strong>Show SQL Debug Statements</strong><br>
1500
            SQL Errors will always be displayed but when this feature is enabled the SQL Statement
1501
            that caused the error will be displayed as well:
1502
            </td>
1503
            <td valign="top">
1504
                <select name="debug_sql">
1505
                        <option value="1">true</option>
1506
                        <option value="0" <?php
1507
                        if (!$cfg["debug_sql"])
1508
                        {
1509
                            echo "selected";
1510
                        }
1511
                        ?>>false</option>
1512
                </select>
1513
            </td>
1514
        </tr>
1515
        <tr>
1516
            <td align="left" width="350" valign="top"><strong>Default Torrent Completion Activity</strong><br>
1517
            Select whether or not a torrent should keep seeding when download is complete
1518
            (please seed your torrents):
1519
            </td>
1520
            <td valign="top">
1521
                <select name="torrent_dies_when_done">
1522
                        <option value="True">Die When Done</option>
1523
                        <option value="False" <?php
1524
                        if ($cfg["torrent_dies_when_done"] == "False")
1525
                        {
1526
                            echo "selected";
1527
                        }
1528
                        ?>>Keep Seeding</option>
1529
                </select>
1530
            </td>
1531
        </tr>
1532
        <tr>
1533
            <td align="left" width="350" valign="top"><strong>Default Percentage When Seeding should Stop</strong><br>
1534
            Set the default share pecentage where torrents will shutoff
1535
            when running torrents that do not die when done.
1536
            Value '0' will seed forever.
1537
            </td>
1538
            <td valign="top">
1539
                <input name="sharekill" type="Text" maxlength="3" value="<?php    echo($cfg["sharekill"]); ?>" size="3">%
1540
            </td>
1541
        </tr>
1542
        </table>
1543
        <br>
1544
        <input type="Submit" value="Update Settings">
1545
        </form>
1546
    </div>
1547
    <br>
1548
<?php
1549
    echo "</td></tr>";
1550
    echo "</table></div>";
1551
 
1552
    DisplayFoot();
1553
}
1554
 
1555
//****************************************************************************
1556
// updateConfigSettings -- updating App Settings
1557
//****************************************************************************
1558
function updateConfigSettings()
1559
{
1560
    global $cfg;
1561
 
1562
    $tmpPath = getRequestVar("path");
1563
    if (!empty($tmpPath) && substr( $_POST["path"], -1 )  != "/")
1564
    {
1565
        // path requires a / on the end
1566
        $_POST["path"] = $_POST["path"] . "/";
1567
    }
1568
 
1569
    if ($_POST["AllowQueing"] != $cfg["AllowQueing"] ||
1570
        $_POST["maxServerThreads"] != $cfg["maxServerThreads"] ||
1571
        $_POST["maxUserThreads"] != $cfg["maxUserThreads"] ||
1572
        $_POST["sleepInterval"] != $cfg["sleepInterval"] ||
1573
        $_POST["debugTorrents"] != $cfg["debugTorrents"] ||
1574
        $_POST["tfQManager"] != $cfg["tfQManager"] ||
1575
        $_POST["btphpbin"] != $cfg["btphpbin"]
1576
        )
1577
    {
1578
        // kill QManager process;
1579
        if(getQManagerPID() != "")
1580
        {
1581
            stopQManager();
1582
        }
1583
 
1584
            $settings = $_POST;
1585
 
1586
            saveSettings($settings);
1587
            AuditAction($cfg["constants"]["admin"], " Updating TorrentFlux Settings");
1588
 
1589
        // if enabling Start QManager
1590
        if($_POST["AllowQueing"])
1591
        {
1592
            sleep(2);
1593
            startQManager($_POST["maxServerThreads"], $_POST["maxUserThreads"], $_POST["sleepInterval"]);
1594
        sleep(1);
1595
        }
1596
    }
1597
    else
1598
    {
1599
         $settings = $_POST;
1600
 
1601
             saveSettings($settings);
1602
             AuditAction($cfg["constants"]["admin"], " Updating TorrentFlux Settings");
1603
    }
1604
 
1605
    $continue = getRequestVar('continue');
1606
    header("Location: admin.php?op=".$continue);
1607
}
1608
 
1609
//****************************************************************************
1610
// queueSettings -- Config the Queue Settings
1611
//****************************************************************************
1612
function queueSettings()
1613
{
1614
    global $cfg;
1615
    include_once("AliasFile.php");
1616
    include_once("RunningTorrent.php");
1617
 
1618
    DisplayHead("Administration - Search Settings");
1619
 
1620
    // Admin Menu
1621
    displayMenu();
1622
 
1623
        // Queue Manager Section
1624
    echo "<div align=\"center\">";
1625
    echo "<a name=\"QManager\" id=\"QManager\"></a>";
1626
    echo "<table width=\"100%\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
1627
    echo "<tr><td bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
1628
    echo "<font class=\"title\">";
1629
    if(checkQManager() > 0)
1630
    {
1631
         echo "&nbsp;&nbsp;<img src=\"images/green.gif\" align=\"absmiddle\" align=\"absmiddle\"> Queue Manager Running [PID=".getQManagerPID()." with ".strval(getRunningTorrentCount())." torrent(s)]";
1632
    }
1633
    else
1634
    {
1635
        echo "&nbsp;&nbsp;<img src=\"images/black.gif\" align=\"absmiddle\"> Queue Manager Off";
1636
    }
1637
    echo "</font>";
1638
    echo "</td></tr><tr><td align=\"center\">";
1639
?>
1640
    <script language="JavaScript">
1641
    function validateSettings()
1642
    {
1643
        var rtnValue = true;
1644
        var msg = "";
1645
        if (isNumber(document.theForm.maxServerThreads.value) == false)
1646
        {
1647
            msg = msg + "* Max Server Threads must be a valid number.\n";
1648
            document.theForm.maxServerThreads.focus();
1649
        }
1650
        if (isNumber(document.theForm.maxUserThreads.value) == false)
1651
        {
1652
            msg = msg + "* Max User Threads must be a valid number.\n";
1653
            document.theForm.maxUserThreads.focus();
1654
        }
1655
        if (isNumber(document.theForm.sleepInterval.value) == false)
1656
        {
1657
            msg = msg + "* Sleep Interval must be a valid number.\n";
1658
            document.theForm.sleepInterval.focus();
1659
        }
1660
 
1661
        if (msg != "")
1662
        {
1663
            rtnValue = false;
1664
            alert("Please check the following:\n\n" + msg);
1665
        }
1666
 
1667
        return rtnValue;
1668
    }
1669
 
1670
    function isNumber(sText)
1671
    {
1672
        var ValidChars = "0123456789.";
1673
        var IsNumber = true;
1674
        var Char;
1675
 
1676
        for (i = 0; i < sText.length && IsNumber == true; i++)
1677
        {
1678
            Char = sText.charAt(i);
1679
            if (ValidChars.indexOf(Char) == -1)
1680
            {
1681
                IsNumber = false;
1682
            }
1683
        }
1684
 
1685
        return IsNumber;
1686
    }
1687
    </script>
1688
 
1689
    <div align="center">
1690
 
1691
         <table cellpadding="5" cellspacing="0" border="0" width="100%">
1692
            <form name="theForm" action="admin.php?op=updateConfigSettings" method="post" onsubmit="return validateSettings()">
1693
            <input type="Hidden" name="continue" value="queueSettings">
1694
            <tr>
1695
                <td align="left" width="350" valign="top"><strong>Enable Queue Manager</strong><br>
1696
                Enable the Queue Manager to allow users to queue torrents:
1697
                </td>
1698
                <td>
1699
                    <select name="AllowQueing">
1700
                            <option value="1">true</option>
1701
                            <option value="0" <?php
1702
                            if (!$cfg["AllowQueing"])
1703
                            {
1704
                                echo "selected";
1705
                            }
1706
                            ?>>false</option>
1707
                    </select>
1708
                </td>
1709
            </tr>
1710
            <tr>
1711
                <td align="left" width="350" valign="top"><strong>tfQManager Path</strong><br>
1712
                Specify the path to the tfQManager.py python script:
1713
                </td>
1714
                <td valign="top">
1715
                    <input name="tfQManager" type="Text" maxlength="254" value="<?php    echo($cfg["tfQManager"]); ?>" size="55"><?php echo validateFile($cfg["tfQManager"]) ?>
1716
                </td>
1717
            </tr>
1718
<!-- Only used for develpment or if you really really know what you are doing
1719
            <tr>
1720
                <td align="left" width="350" valign="top"><strong>Enable Queue Manager Debugging</strong><br>
1721
                Creates huge log files only for debugging.  DO NOT KEEP THIS MODE ON:
1722
                </td>
1723
                <td>
1724
                    <select name="debugTorrents">
1725
                        <option value="1">true</option>
1726
                        <option value="0" <?php
1727
            if (array_key_exists("debugTorrents",$cfg))
1728
            {
1729
				if (!$cfg["debugTorrents"])
1730
				{
1731
				    echo "selected";
1732
				}
1733
			}
1734
			else
1735
			{
1736
				insertSetting("debugTorrents",false);
1737
				echo "selected";
1738
			}
1739
                        ?>>false</option>
1740
                    </select>
1741
                </td>
1742
            </tr>
1743
-->
1744
            <tr>
1745
                <td align="left" width="350" valign="top"><strong>Max Server Threads</strong><br>
1746
                Specify the maximum number of torrents the server will allow to run at
1747
                one time (admins may override this):
1748
                </td>
1749
                <td valign="top">
1750
                    <input name="maxServerThreads" type="Text" maxlength="3" value="<?php    echo($cfg["maxServerThreads"]); ?>" size="3">
1751
                </td>
1752
            </tr>
1753
            <tr>
1754
                <td align="left" width="350" valign="top"><strong>Max User Threads</strong><br>
1755
                Specify the maximum number of torrents a single user may run at
1756
                one time:
1757
                </td>
1758
                <td valign="top">
1759
                    <input name="maxUserThreads" type="Text" maxlength="3" value="<?php    echo($cfg["maxUserThreads"]); ?>" size="3">
1760
                </td>
1761
            </tr>
1762
            <tr>
1763
                <td align="left" width="350" valign="top"><strong>Polling Interval</strong><br>
1764
                Number of seconds the Queue Manager will sleep before checking for new torrents to run:
1765
                </td>
1766
                <td valign="top">
1767
                    <input name="sleepInterval" type="Text" maxlength="3" value="<?php    echo($cfg["sleepInterval"]); ?>" size="3">
1768
                </td>
1769
            </tr>
1770
            <tr>
1771
                <td align="center" colspan="2">
1772
                <br><br>
1773
                <input type="Submit" value="Update Settings">
1774
                </td>
1775
            </tr>
1776
            </form>
1777
        </table>
1778
 
1779
 
1780
        </div>
1781
    <br>
1782
<?php
1783
    echo "</td></tr>";
1784
    echo "</table></div>";
1785
 
1786
    $displayQueue = True;
1787
    $displayRunningTorrents = True;
1788
 
1789
    // Its a timming thing.
1790
    if ($displayRunningTorrents)
1791
    {
1792
          // get Running Torrents.
1793
        $runningTorrents = getRunningTorrents();
1794
    }
1795
 
1796
    if ($displayQueue)
1797
    {
1798
        $output = "";
1799
 
1800
        echo "\n";
1801
        echo "<table width=\"760\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
1802
        echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
1803
        echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>";
1804
        echo "<td><img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\"> Queued Items </font></td>";
1805
        echo "</tr></table>";
1806
        echo "</td></tr>";
1807
        echo "<tr>";
1808
        echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"15%\"><div align=center class=\"title\">"._USER."</div></td>";
1809
        echo "<td bgcolor=\"".$cfg["table_header_bg"]."\"><div align=center class=\"title\">"._FILE."</div></td>";
1810
        echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"15%\"><div align=center class=\"title\">"._TIMESTAMP."</div></td>";
1811
        echo "</tr>";
1812
        echo "\n";
1813
 
1814
        $qDir = $cfg["torrent_file_path"]."queue/";
1815
        if (is_dir($cfg["torrent_file_path"]))
1816
        {
1817
            if (is_writable($cfg["torrent_file_path"]) && !is_dir($qDir))
1818
            {
1819
                @mkdir($qDir, 0777);
1820
            }
1821
 
1822
            // get Queued Items and List them out.
1823
            $output .= "";
1824
            $handle = @opendir($qDir);
1825
            while($filename = readdir($handle))
1826
            {
1827
                if ($filename != "tfQManager.log")
1828
                {
1829
                    if ($filename != "." && $filename != ".." && strpos($filename,".pid") == 0)
1830
                    {
1831
                    $output .= "<tr>";
1832
                    $output .= "<td><div class=\"tiny\">";
1833
                    $af = new AliasFile(str_replace("queue/","",$qDir).str_replace(".Qinfo","",$filename), "");
1834
                    $output .= $af->torrentowner;
1835
                    $output .= "</div></td>";
1836
                    $output .= "<td><div align=center><div class=\"tiny\" align=\"left\">".str_replace(array(".Qinfo",".stat"),"",$filename)."</div></td>";
1837
                    $output .= "<td><div class=\"tiny\" align=\"center\">".date(_DATETIMEFORMAT, strval(filectime($qDir.$filename)))."</div></td>";
1838
                    $output .= "</tr>";
1839
                    $output .= "\n";
1840
                    }
1841
                }
1842
            }
1843
            closedir($handle);
1844
        }
1845
 
1846
        if( strlen($output) == 0 )
1847
        {
1848
            $output = "<tr><td colspan=3><div class=\"tiny\" align=center>Queue is Empty</div></td></tr>";
1849
        }
1850
        echo $output;
1851
 
1852
        echo "</table>";
1853
    }
1854
 
1855
    if ($displayRunningTorrents)
1856
    {
1857
        $output = "";
1858
 
1859
        echo "\n";
1860
        echo "<table width=\"760\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
1861
        echo "<tr><td colspan=6 bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
1862
        echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>";
1863
        echo "<td><img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\"> Running Items </font></td>";
1864
        echo "</tr></table>";
1865
        echo "</td></tr>";
1866
        echo "<tr>";
1867
        echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"15%\"><div align=center class=\"title\">"._USER."</div></td>";
1868
        echo "<td bgcolor=\"".$cfg["table_header_bg"]."\"><div align=center class=\"title\">"._FILE."</div></td>";
1869
        echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" width=\"1%\"><div align=center class=\"title\">".str_replace(" ","<br>",_FORCESTOP)."</div></td>";
1870
        echo "</tr>";
1871
        echo "\n";
1872
 
1873
        // get running torrents and List them out.
1874
        $runningTorrents = getRunningTorrents();
1875
        foreach ($runningTorrents as $key => $value)
1876
        {
1877
            $rt = new RunningTorrent($value);
1878
            $output .= $rt->BuildAdminOutput();
1879
        }
1880
 
1881
        if( strlen($output) == 0 )
1882
        {
1883
            $output = "<tr><td colspan=3><div class=\"tiny\" align=center>No Running Torrents</div></td></tr>";
1884
        }
1885
        echo $output;
1886
 
1887
        echo "</table>";
1888
 
1889
    }
1890
 
1891
    DisplayFoot();
1892
}
1893
 
1894
 
1895
//****************************************************************************
1896
// searchSettings -- Config the Search Engine Settings
1897
//****************************************************************************
1898
function searchSettings()
1899
{
1900
    global $cfg;
1901
    include_once("AliasFile.php");
1902
    include_once("RunningTorrent.php");
1903
    include_once("searchEngines/SearchEngineBase.php");
1904
 
1905
    DisplayHead("Administration - Search Settings");
1906
 
1907
    // Admin Menu
1908
    displayMenu();
1909
 
1910
    // Main Settings Section
1911
    echo "<div align=\"center\">";
1912
    echo "<table width=\"100%\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\">";
1913
    echo "<tr><td bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\">";
1914
    echo "<img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\">Search Settings</font>";
1915
    echo "</td></tr><tr><td align=\"center\">";
1916
 
1917
?>
1918
    <div align="center">
1919
 
1920
        <table cellpadding="5" cellspacing="0" border="0" width="100%">
1921
        <form name="theForm" action="admin.php?op=searchSettings" method="post">
1922
        <tr>
1923
            <td align="right" width="350" valign="top"><strong>Select Search Engine</strong><br>
1924
            </td>
1925
            <td valign="top">
1926
<?php
1927
                $searchEngine = getRequestVar('searchEngine');
1928
                if (empty($searchEngine)) $searchEngine = $cfg["searchEngine"];
1929
                echo buildSearchEngineDDL($searchEngine,true)
1930
?>
1931
            </td>
1932
        </tr>
1933
        </form>
1934
        </table>
1935
 
1936
        <table cellpadding="0" cellspacing="0" border="0" width="100%">
1937
        <tr><td>
1938
<?php
1939
    if (is_file('searchEngines/'.$searchEngine.'Engine.php'))
1940
    {
1941
        include_once('searchEngines/'.$searchEngine.'Engine.php');
1942
        $sEngine = new SearchEngine(serialize($cfg));
1943
        if ($sEngine->initialized)
1944
        {
1945
            echo "<table width=\"100%\" border=1 bordercolor=\"".$cfg["table_admin_border"]."\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"".$cfg["table_data_bg"]."\"><tr>";
1946
            echo "<td bgcolor=\"".$cfg["table_header_bg"]."\" background=\"themes/".$cfg["theme"]."/images/bar.gif\"><img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\">".$sEngine->mainTitle." Search Settings</font></td>";
1947
            echo "</tr></table></td>";
1948
            echo "<form name=\"theSearchEngineSettings\" action=\"admin.php?op=updateSearchSettings\" method=\"post\">\n";
1949
            echo "<input type=\"hidden\" name=\"searchEngine\" value=\"".$searchEngine."\">";
1950
?>
1951
            </td>
1952
        </tr>
1953
        <tr>
1954
            <td>
1955
 
1956
        <table cellpadding="5" cellspacing="0" border="0" width="100%">
1957
        <tr>
1958
            <td align="left" width="350" valign="top"><strong>Search Engine URL:</strong></td>
1959
            <td valign="top">
1960
                <?php echo "<a href=\"http://".$sEngine->mainURL."\" target=\"_blank\">".$sEngine->mainTitle."</a>"; ?>
1961
            </td>
1962
        </tr>
1963
        <tr>
1964
            <td align="left" width="350" valign="top"><strong>Search Module Author:</strong></td>
1965
            <td valign="top">
1966
                <?php echo $sEngine->author; ?>
1967
            </td>
1968
        </tr>
1969
        <tr>
1970
            <td align="left" width="350" valign="top"><strong>Version:</strong></td>
1971
            <td valign="top">
1972
                <?php echo $sEngine->version; ?>
1973
            </td>
1974
        </tr>
1975
<?php
1976
        if(strlen($sEngine->updateURL)>0)
1977
        {
1978
?>
1979
        <tr>
1980
            <td align="left" width="350" valign="top"><strong>Update Location:</strong></td>
1981
            <td valign="top">
1982
                <?php echo "<a href=\"".$sEngine->updateURL."\" target=\"_blank\">Check for Update</a>"; ?>
1983
            </td>
1984
        </tr>
1985
<?php
1986
        }
1987
            if (! $sEngine->catFilterName == '')
1988
            {
1989
?>
1990
        <tr>
1991
            <td align="left" width="350" valign="top"><strong>Search Filter:</strong><br>
1992
            Select the items that you DO NOT want to show in the torrent search:
1993
            </td>
1994
            <td valign="top">
1995
<?php
1996
                echo "<select multiple name=\"".$sEngine->catFilterName."[]\" size=\"8\" STYLE=\"width: 125px\">";
1997
                echo "<option value=\"\">[NO FILTER]</option>";
1998
                foreach ($sEngine->getMainCategories(false) as $mainId => $mainName)
1999
                {
2000
                    echo "<option value=\"".$mainId."\" ";
2001
                    if (@in_array($mainId, $sEngine->catFilter))
2002
                    {
2003
                        echo " selected";
2004
                    }
2005
                    echo ">".$mainName."</option>";
2006
                }
2007
                echo "</select>";
2008
                echo "            </td>\n";
2009
                echo "        </tr>\n";
2010
            }
2011
        }
2012
    }
2013
 
2014
    echo "        </table>\n";
2015
    echo "         </td></tr></table>";
2016
    echo "        <br>\n";
2017
    echo "        <input type=\"Submit\" value=\"Update Settings\">";
2018
    echo "        </form>\n";
2019
    echo "    </div>\n";
2020
    echo "    <br>\n";
2021
    echo "</td></tr>";
2022
    echo "</table></div>";
2023
 
2024
    DisplayFoot();
2025
}
2026
 
2027
//****************************************************************************
2028
// updateSearchSettings -- updating Search Engine Settings
2029
//****************************************************************************
2030
function updateSearchSettings()
2031
{
2032
    global $cfg;
2033
 
2034
    foreach ($_POST as $key => $value)
2035
    {
2036
        if ($key != "searchEngine")
2037
        {
2038
            $settings[$key] = $value;
2039
        }
2040
    }
2041
 
2042
    saveSettings($settings);
2043
    AuditAction($cfg["constants"]["admin"], " Updating TorrentFlux Search Settings");
2044
 
2045
    $searchEngine = getRequestVar('searchEngine');
2046
    if (empty($searchEngine)) $searchEngine = $cfg["searchEngine"];
2047
    header("location: admin.php?op=searchSettings&searchEngine=".$searchEngine);
2048
}
2049
 
2050
//****************************************************************************
2051
//****************************************************************************
2052
//****************************************************************************
2053
//****************************************************************************
2054
// TRAFFIC CONTROLER
2055
$op = getRequestVar('op');
2056
 
2057
switch ($op)
2058
{
2059
 
2060
    default:
2061
        $min = getRequestVar('min');
2062
        if(empty($min)) $min=0;
2063
        showIndex($min);
2064
    break;
2065
 
2066
    case "showUserActivity":
2067
        $min = getRequestVar('min');
2068
        if(empty($min)) $min=0;
2069
        $user_id = getRequestVar('user_id');
2070
        $srchFile = getRequestVar('srchFile');
2071
        $srchAction = getRequestVar('srchAction');
2072
        showUserActivity($min, $user_id, $srchFile, $srchAction);
2073
    break;
2074
 
2075
    case "backupDatabase":
2076
        backupDatabase();
2077
    break;
2078
 
2079
    case "editRSS":
2080
        editRSS();
2081
    break;
2082
 
2083
    case "addRSS":
2084
        $newRSS = getRequestVar('newRSS');
2085
        addRSS($newRSS);
2086
    break;
2087
 
2088
    case "deleteRSS":
2089
        $rid = getRequestVar('rid');
2090
        deleteRSS($rid);
2091
    break;
2092
 
2093
    case "editLinks":
2094
        editLinks();
2095
    break;
2096
 
2097
    case "addLink":
2098
        $newLink = getRequestVar('newLink');
2099
        addLink($newLink);
2100
    break;
2101
 
2102
    case "deleteLink":
2103
        $lid = getRequestVar('lid');
2104
        deleteLink($lid);
2105
    break;
2106
 
2107
    case "CreateUser":
2108
        CreateUser();
2109
    break;
2110
 
2111
    case "addUser":
2112
        $newUser = getRequestVar('newUser');
2113
        $pass1 = getRequestVar('pass1');
2114
        $userType = getRequestVar('userType');
2115
        addUser($newUser, $pass1, $userType);
2116
    break;
2117
 
2118
    case "deleteUser":
2119
        $user_id = getRequestVar('user_id');
2120
        deleteUser($user_id);
2121
    break;
2122
 
2123
    case "editUser":
2124
        $user_id = getRequestVar('user_id');
2125
        editUser($user_id);
2126
    break;
2127
 
2128
    case "updateUser":
2129
        $user_id = getRequestVar('user_id');
2130
        $org_user_id = getRequestVar('org_user_id');
2131
        $pass1 = getRequestVar('pass1');
2132
        $userType = getRequestVar('userType');
2133
        $hideOffline = getRequestVar('hideOffline');
2134
        updateUser($user_id, $org_user_id, $pass1, $userType, $hideOffline);
2135
    break;
2136
 
2137
    case "configSettings":
2138
        configSettings();
2139
    break;
2140
 
2141
    case "updateConfigSettings":
2142
        if (! array_key_exists("debugTorrents", $_REQUEST))
2143
        {
2144
            $_REQUEST["debugTorrents"] = false;
2145
        }
2146
        updateConfigSettings();
2147
    break;
2148
 
2149
    case "queueSettings":
2150
        queueSettings();
2151
    break;
2152
 
2153
    case "searchSettings":
2154
        searchSettings();
2155
    break;
2156
 
2157
    case "updateSearchSettings":
2158
        updateSearchSettings();
2159
    break;
2160
 
2161
}
2162
//****************************************************************************
2163
//****************************************************************************
2164
//****************************************************************************
2165
//****************************************************************************
2166
 
2167
?>