forked from Bigjoos/U-232-V5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitbucket.php
276 lines (273 loc) · 15.2 KB
/
bitbucket.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
/**
|--------------------------------------------------------------------------|
| https://github.com/Bigjoos/ |
|--------------------------------------------------------------------------|
| Licence Info: WTFPL |
|--------------------------------------------------------------------------|
| Copyright (C) 2010 U-232 V5 |
|--------------------------------------------------------------------------|
| A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon. |
|--------------------------------------------------------------------------|
| Project Leaders: Mindless, Autotron, whocares, Swizzles. |
|--------------------------------------------------------------------------|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( U | - | 2 | 3 | 2 )-( S | o | u | r | c | e )-( C | o | d | e )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
*/
// by system
// pic management by pdq
// no rights reserved - public domain FTW!
require_once (__DIR__.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
require_once (INCL_DIR.'user_functions.php');
require_once (INCL_DIR.'bbcode_functions.php');
dbconn();
loggedinorreturn();
$lang = array_merge(load_language('global') , load_language('bitbucket'));
$HTMLOUT = "";
/* Image folder located outside of webroot */
// BITBUCKET_DIR Now defined in config.php
//define('BITBUCKET_DIR', DIRECTORY_SEPARATOR.'var'.DIRECTORY_SEPARATOR.'bucket');
/* Avatar folder located inside BITBUCKET_DIR */
define('AVATAR_DIR', BITBUCKET_DIR.DIRECTORY_SEPARATOR.'avatar');
if (!is_dir(AVATAR_DIR)) {
mkdir(AVATAR_DIR);
}
$SaLt = 'mE0wI924dsfsfs!@B'; // change this!
$SaLty = '8368364562'; // NEW!
$skey = 'eTe5$Ybnsccgbsfdsfsw4h6W'; // change this!
$maxsize = $INSTALLER09['bucket_maxsize'];
/* seperate images into */
$folders = date('Y/m');
// valid file formats
$formats = array(
'.gif',
'.jpg',
'.jpeg',
'.png',
);
// path to bucket/avatar directories
$bucketdir = (isset($_POST["avy"]) ? AVATAR_DIR.'/' : BITBUCKET_DIR.'/'.$folders.'/');
$bucketlink = ((isset($_POST["avy"]) || (isset($_GET['images']) && $_GET['images'] == 2)) ? 'avatar/' : $folders.'/');
$address = $INSTALLER09['baseurl'].'/';
$PICSALT = md5($SaLt . $CURUSER['username']);
//rename files and obscufate uploader
$USERSALT = substr(md5($SaLty.$CURUSER['id']) , 0, 6);
/* this is a hack, you should create folders named 2012, 2013, 2014, etc,
* inside these folders you should have folders for the months named 01 to 12
* then comment out the following 2 lines
*/
make_year(BITBUCKET_DIR);
make_month(BITBUCKET_DIR);
if (!isset($_FILES['file'])) {
if (isset($_GET["delete"])) {
$getfile = htmlsafechars($_GET['delete']);
$delfile = urldecode(decrypt($getfile));
$delhash = md5($delfile.$USERSALT.$SaLt);
//$delhash = md5($delfile . $CURUSER['username'] . $SaLt);
if ($delhash != $_GET['delhash']) stderr($lang['bitbucket_umm'], "{$lang['bitbucket_wayd']}");
//$myfile = ROOT_DIR . '/' . $delfile; //== for pdq define directories
//$myfile = '/home/yourdir/public_html/'.$delfile; // Full relative path to web root
$myfile = BITBUCKET_DIR.'/'.$delfile;
if ((($pi = pathinfo($myfile)) && preg_match('#^(jpg|jpeg|gif|png)$#i', $pi['extension'])) && is_file($myfile))
//if (is_file($myfile))
unlink($myfile);
else stderr($lang['bitbucket_hey'], "{$lang['bitbucket_imagenf']}");
$folder_m = (!isset($_GET['month']) ? '&month='.date('m') : '&month='.(int)$_GET['month']);
$yea = (!isset($_GET['year']) ? '&year='.date('Y') : '&year='.(int)$_GET['year']);
if (isset($_GET["type"]) && $_GET["type"] == 2) header("Refresh: 2; url={$INSTALLER09['baseurl']}/bitbucket.php?images=2");
else header("Refresh: 2; url={$INSTALLER09['baseurl']}/bitbucket.php?images=1".$yea.$folder_m);
die($lang['bitbucket_deleting'] . $delfile . $lang['bitbucket_redir']);
}
if (isset($_GET["avatar"]) && $_GET["avatar"] != '' && (($_GET["avatar"]) != $CURUSER["avatar"])) {
$type = ((isset($_GET["type"]) && $_GET["type"] == 1) ? 1 : 2);
if (preg_match("/^http:\/\/$/i", $_GET["avatar"]) OR preg_match("/[?&;]/", $_GET["avatar"]) OR preg_match("#javascript:#is", $_GET["avatar"]) OR !preg_match("#^https?://(?:[^<>*\"]+|[a-z0-9/\._\-!]+)$#iU", $_GET["avatar"])) stderr($lang['bitbucket_error'], "{$lang['bitbucket_mustbe']}");
$avatar = sqlesc($_GET['avatar']);
sql_query("UPDATE users SET avatar = $avatar WHERE id = {$CURUSER['id']}") or sqlerr(__FILE__, __LINE__);
$mc1->begin_transaction('MyUser_'.$CURUSER['id']);
$mc1->update_row(false, array(
'avatar' => $_GET['avatar']
));
$mc1->commit_transaction($INSTALLER09['expires']['curuser']);
$mc1->begin_transaction('user'.$CURUSER['id']);
$mc1->update_row(false, array(
'avatar' => $_GET['avatar']
));
$mc1->commit_transaction($INSTALLER09['expires']['user_cache']);
header("Refresh: 0; url={$INSTALLER09['baseurl']}/bitbucket.php?images=$type&updated=avatar");
}
if (isset($_GET["updated"]) && $_GET["updated"] == 'avatar') {
$HTMLOUT.= "<h3>{$lang['bitbucket_updated']}<img src='".htmlsafechars($CURUSER['avatar'])."' border='0' alt='' /></h3>";
}
$HTMLOUT.= "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" enctype=\"multipart/form-data\">
<table width=\"300\" align=\"center\">
<tr>
<td class=\"clearalt6\" align=\"center\"><p><b>{$lang['bitbucket_invalid_extension']}".join(', ', $formats)."</b></p>
<p><b>{$lang['bitbucket_max']}".mksize($maxsize)."</b></p>
<p>{$lang['bitbucket_disclaimer']}</p></td>
</tr>
<tr>
<td align=\"center\"><input type=\"file\" name=\"file\" /></td>
</tr>
<tr><td align=\"center\"> <input type=\"checkbox\" name=\"avy\" value=\"1\" />{$lang['bitbucket_tick']}</td> </tr>
<tr>
<td align=\"center\"><input class=\"btn\" type=\"submit\" value=\"{$lang['bitbucket_upload']}\" /></td>
</tr>
</table>
</form>";
$HTMLOUT.= "<script type=\"text/javascript\">
/*<![CDATA[*/
function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}
/*]]>*/
</script>";
if (isset($_GET['images']) && $_GET['images'] == 1) {
$folder_month = (!isset($_GET['month']) ? date('m') : ($_GET['month'] < 10 ? '0' : '').(int)$_GET['month']);
$year = (!isset($_GET['year']) ? '&year='.date('Y') : '&year='.(int)$_GET['year']);
$HTMLOUT.= '<p align="center"><a href="bitbucket.php?images=2">' . $lang['bitbucket_viewmya'] . '</a></p>
<p align="center"><a href="bitbucket.php">' . $lang['bitbucket_hideimgs'] . '</a></p>
<p align="center"><b>' . $lang['bitbucket_previousimg'] . '</b><br />
<a href="bitbucket.php?images=1&month='.$folder_month.'&year='.(isset($_GET['year']) && $_GET['year'] != date('Y') ? date('Y').'">This' : (date('Y') - 1).'">' . $lang['bitbucket_last'] . '').'' . $lang['bitbucket_year'] . '</a>
<a href="bitbucket.php?images=1&month=01'.$year.'">' . $lang['bitbucket_jan'] . '</a>
<a href="bitbucket.php?images=1&month=02'.$year.'">' . $lang['bitbucket_feb'] . '</a>
<a href="bitbucket.php?images=1&month=03'.$year.'">' . $lang['bitbucket_mar'] . '</a>
<a href="bitbucket.php?images=1&month=04'.$year.'">' . $lang['bitbucket_apr'] . '</a>
<a href="bitbucket.php?images=1&month=05'.$year.'">' . $lang['bitbucket_may'] . '</a>
<a href="bitbucket.php?images=1&month=06'.$year.'">' . $lang['bitbucket_june'] . '</a>
<a href="bitbucket.php?images=1&month=07'.$year.'">' . $lang['bitbucket_jul'] . '</a>
<a href="bitbucket.php?images=1&month=08'.$year.'">' . $lang['bitbucket_aug'] . '</a>
<a href="bitbucket.php?images=1&month=09'.$year.'">' . $lang['bitbucket_sep'] . '</a>
<a href="bitbucket.php?images=1&month=10'.$year.'">' . $lang['bitbucket_oct'] . '</a>
<a href="bitbucket.php?images=1&month=11'.$year.'">' . $lang['bitbucket_nov'] . '</a>
<a href="bitbucket.php?images=1&month=12'.$year.'">' . $lang['bitbucket_dec'] . '</a>
</p>';
} elseif (isset($_GET['images']) && $_GET['images'] == 2) {
$HTMLOUT.= "<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php?images=1\">{$lang['bitbucket_viewmonths']}</a></p>
<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php\">{$lang['bitbucket_hidemya']}</a></p>";
} else {
$HTMLOUT.= "<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php?images=1\">{$lang['bitbucket_viewmonths']}</a></p>
<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php?images=2\">{$lang['bitbucket_viewmya']}</a></p>";
}
if (isset($_GET['images'])) {
$folder_month = (!isset($_GET['month']) ? date('m') : ($_GET['month'] < 10 ? '0' : '').(int)$_GET['month']);
$folder_name = (!isset($_GET['year']) ? date('Y').'/' : (int)$_GET['year'].'/').$folder_month;
$bucketlink2 = ((isset($_POST["avy"]) || (isset($_GET['images']) && $_GET['images'] == 2)) ? 'avatars/' : $folder_name.'/');
foreach ((array)glob(($_GET['images'] == 2 ? AVATAR_DIR.'/'.$USERSALT : BITBUCKET_DIR.'/'.$folder_name.'/'.$USERSALT).'_*') as $filename) {
if (!empty($filename)) {
$filename = basename($filename);
$filename = $bucketlink2.$filename;
$encryptedfilename = urlencode(encrypt($filename));
$eid = md5($filename);
$HTMLOUT.= "<a href=\"{$address}img.php/{$filename}\"><img src=\"{$address}img.php/{$filename}\" width=\"200\" alt=\"\" /><br />{$address}img.php/{$filename}</a><br />";
$HTMLOUT.= "<p>{$lang['bitbucket_directlink']}<br /><input style=\"font-size: 9pt;text-align: center;\" id=\"d".$eid."d\" onclick=\"SelectAll('d".$eid."d');\" type=\"text\" size=\"70\" value=\"{$address}img.php/{$filename}\" readonly=\"readonly\" /></p>";
$HTMLOUT.= "<p align=\"center\">{$lang['bitbucket_tags']}<br /><input style=\"font-size: 9pt;text-align: center;\" id=\"t".$eid."t\" onclick=\"SelectAll('t".$eid."t');\" type=\"text\" size=\"70\" value=\"[img]{$address}img.php/{$filename}[/img]\" readonly=\"readonly\" /></p>";
$HTMLOUT.= "<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php?type=".((isset($_GET['images']) && $_GET['images'] == 2) ? '2' : '1')."&avatar={$address}img.php/{$filename}\">{$lang['bitbucket_maketma']}</a></p>";
$HTMLOUT.= "<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php?type=".((isset($_GET['images']) && $_GET['images'] == 2) ? '2' : '1')."&delete=".$encryptedfilename."&delhash=".md5($filename.$USERSALT.$SaLt)."&month=".(!isset($_GET['month']) ? date('m') : ($_GET['month'] < 10 ? '0' : '').(int)$_GET['month'])."&year=".(!isset($_GET['year']) ? date('Y') : (int)$_GET['year'])."\">{$lang['bitbucket_delete']}</a></p><br />";
} else $HTMLOUT.= "{$lang['bitbucket_noimages']}";
}
}
echo stdhead($lang['bitbucket_bitbucket']).$HTMLOUT.stdfoot();
exit();
}
if ($_FILES['file']['size'] == 0) stderr($lang['bitbucket_error'], $lang['bitbucket_upfail']);
if ($_FILES['file']['size'] > $maxsize) stderr($lang['bitbucket_error'], $lang['bitbucket_to_large']);
$file = preg_replace('`[^a-z0-9\-\_\.]`i', '', $_FILES['file']['name']);
if (false === in_array('.'.pathinfo($file, PATHINFO_EXTENSION), $formats)) stderr($lang['bitbucket_err'], $lang['bitbucket_invalid']);
if (!function_exists('exif_imagetype')) {
function exif_imagetype($filename)
{
if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) {
return $type;
}
return false;
}
}
$it1 = exif_imagetype($_FILES['file']['tmp_name']);
if ($it1 != IMAGETYPE_GIF && $it1 != IMAGETYPE_JPEG && $it1 != IMAGETYPE_PNG) {
$HTMLOUT.= "<h1>{$lang['bitbucket_upfail']}<br />{$lang['bitbucket_sorry']}";
exit;
}
$file = strtolower($file);
$path = $bucketdir.$USERSALT.'_'.$file;
$pathlink = $bucketlink.$USERSALT.'_'.$file;
$loop = 0;
while (true) {
if ($loop > 10) stderr($lang['bitbucket_error'], $lang['bitbucket_upfail']);
if (!file_exists($path)) break;
$randb = bucketrand();
$path = $bucketdir.$USERSALT.'_'.$randb.$file;
$pathlink = $bucketlink.$USERSALT.'_'.$randb.$file;
$loop++;
}
if (!move_uploaded_file($_FILES['file']['tmp_name'], $path)) stderr($lang['bitbucket_error'], $lang['bitbucket_upfail']);
if (isset($_POST["from"]) && $_POST["from"] == "upload") {
echo "<p><b><font color='red'>{$lang['bitbucket_success']}</b></p>
<p><b><strong>".$address."img.php/".$pathlink."</strong></font></b></p>";
exit;
}
$HTMLOUT.= "<table width=\"300\" align=\"center\">
<tr class=\"clear\">
<td align=\"center\"><p><a href=\"".$_SERVER['PHP_SELF']."\"><strong>{$lang['bitbucket_up_another']}</strong></a></p>
<p>{$lang['bitbucket_thefile']}</p>
<p><img src=\"".$address."img.php/".$pathlink."\" border=\"0\" alt=\"\"/></p>";
$HTMLOUT.= "<script type=\"text/javascript\">
/*<![CDATA[*/
function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}
/*]]>*/
</script>";
$HTMLOUT.= "<p>{$lang['bitbucket_directlink']}<br />
<input style=\"font-size: 9pt;text-align: center;\" id=\"direct\" onclick=\"SelectAll('direct');\" type=\"text\" size=\"70\" value=\"".$address."img.php/".$pathlink."\" readonly=\"readonly\" /></p>
<p align=\"center\">{$lang['bitbucket_tags']}
<input style=\"font-size: 9pt;text-align: center;\" id=\"tag\" onclick=\"SelectAll('tag');\" type=\"text\" size=\"70\" value=\"[img]".$address."img.php/".$pathlink."[/img]\" readonly=\"readonly\" /></p>
<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php?images=1\">{$lang['bitbucket_viewmyi']}</a></p>
<p align=\"center\"><a href=\"{$INSTALLER09['baseurl']}/bitbucket.php?images=2\">{$lang['bitbucket_viewmya']}</a></p>
</td>
</tr>
</table>";
echo stdhead($lang['bitbucket_bitbucket']).$HTMLOUT.stdfoot();
function bucketrand()
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$out = '';
for ($i = 0; $i < 6; $i++) $out.= $chars[mt_rand(0, 61) ];
return $out;
}
function encrypt($text)
{
global $PICSALT;
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $PICSALT, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB) , MCRYPT_RAND))));
}
function decrypt($text)
{
global $PICSALT;
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $PICSALT, base64_decode($text) , MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB) , MCRYPT_RAND)));
}
/* Sanity checking by pdq */
function valid_path($root, $input)
{
$fullpath = $root.$input;
$fullpath = realpath($fullpath);
$root = realpath($root);
$rl = strlen($root);
return ($root != substr($fullpath, 0, $rl)) ? NULL : $fullpath;
}
function make_year($path)
{
$dir = $path.'/'.date('Y');
if (!is_dir($dir)) mkdir($dir);
}
function make_month($path)
{
$dir = $path.'/'.date('Y/m');
if (!is_dir($dir)) mkdir($dir);
}
// EndFile
?>