-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtakeedit.php
145 lines (115 loc) · 3.29 KB
/
takeedit.php
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
<?php
/**
**************************
** FreeTSP Version: 1.0 **
**************************
** http://www.freetsp.info
** https://github.com/Krypto/FreeTSP
** Licence Info: GPL
** Copyright (C) 2010 FreeTSP v1.0
** A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
** Project Leaders: Krypto, Fireknight.
**/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'function_main.php');
require_once(FUNC_DIR.'function_user.php');
require_once(FUNC_DIR.'function_vfunctions.php');
require_once(FUNC_DIR.'function_page_verify.php');
db_connect();
logged_in();
$newpage = new page_verify();
$newpage->check('_edit_');
if (!mkglobal("id:name:descr:type"))
{
error_message("error", "Edit Failed!", "Missing Form Data");
}
$id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
if (!is_valid_id($id))
{
die();
}
$res = sql_query("SELECT owner, filename, save_as
FROM torrents
WHERE id = $id");
$row = mysql_fetch_assoc($res);
if (!$row)
{
die();
}
if ($CURUSER['id'] != $row['owner'] && get_user_class() < UC_MODERATOR)
{
error_message("error", "Edit Failed!", "You're Not the Owner! How did that happen?");
}
$updateset = array();
$fname = $row['filename'];
preg_match('/^(.+)\.torrent$/si', $fname, $matches);
$shortfname = $matches[1];
$dname = $row['save_as'];
$nfoaction = $_POST['nfoaction'];
if (!empty($_POST['poster']))
{
$poster = unesc($_POST['poster']);
}
if ($nfoaction == 'update')
{
$nfofile = $_FILES['nfo'];
if (!$nfofile)
{
die("No Data ".var_dump($_FILES));
}
if ($nfofile['size'] > 65535)
{
error_message("error", "Edit Failed!", "NFO is too Big! Max 65,535 bytes.");
}
$nfofilename = $nfofile['tmp_name'];
if (@is_uploaded_file($nfofilename) && @filesize($nfofilename) > 0)
{
$updateset[] = "nfo = ".sqlesc(str_replace("\x0d\x0d\x0a", "\x0d\x0a", file_get_contents($nfofilename)));
}
}
else
{
if ($nfoaction == 'remove')
{
$updateset[] = 'nfo = ""';
}
}
$updateset[] = "name = ".sqlesc($name);
$updateset[] = "anonymous = '".($_POST["anonymous"] ? "yes" : "no")."'";
$updateset[] = "search_text = ".sqlesc(searchfield("$shortfname $dname $torrent"));
$updateset[] = "descr = ".sqlesc($descr);
$updateset[] = "ori_descr = ".sqlesc($descr);
$updateset[] = "category = ".(0 + $type);
if (get_user_class() >= UC_MODERATOR)
{
if (isset($_POST['banned']))
{
$updateset[] = 'banned = "yes"';
$_POST['visible'] = 0;
}
else
{
$updateset[] = 'banned = "no"';
}
if ($_POST["sticky"] == "yes")
{
$updateset[] = "sticky = 'yes'";
}
else
{
$updateset[] = "sticky = 'no'";
}
}
$updateset[] = "freeleech = '".( isset($_POST['freeleech']) ? 'yes' : 'no')."'";
$updateset[] = "visible = '".(isset($_POST['visible']) ? 'yes' : 'no')."'";
$updateset[] = "poster = ".sqlesc($poster);
sql_query("UPDATE torrents
SET ".join(",", $updateset)."
WHERE id = $id");
write_log(htmlspecialchars($name).' was edited by '.htmlspecialchars($CURUSER['username']));
$returl = "details.php?id=$id&edited=1";
if (isset($_POST["returnto"]))
{
$returl .= "&returnto=".urlencode($_POST["returnto"]);
}
header("Refresh: 0; url=$returl");
?>