-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.php
More file actions
143 lines (120 loc) · 4.45 KB
/
Copy pathremote.php
File metadata and controls
143 lines (120 loc) · 4.45 KB
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
<?php
/* ------------------------------------------------------------------------------------
* GooseTOR - The fast, privacy oriented torrent search tool that just works.
*
* COPYRIGHT NOTICE
* Copyright 2023-2026 Arnan de Gans. All Rights Reserved.
*
* COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
* By using this code you agree to indemnify Arnan de Gans from any
* liability that might arise from its use.
------------------------------------------------------------------------------------ */
if(!defined('MAIN_PATH')) {
define('MAIN_PATH', __DIR__);
}
require_once(MAIN_PATH . '/config.php');
require_once(MAIN_PATH . '/functions/functions.php');
// Basic "security"
$access_key = isset($_GET['access']) ? sanitize($_GET['access']) : '';
if(empty($access_key) OR $access_key !== trim(ACCESS)) {
die("Access key incorrect!");
if(ERROR_LOG) logger('Remote: Access key incorrect.');
exit;
}
// Process url arguments
$hash = isset($_GET['hash']) ? sanitize($_GET['hash']) : '';
// Make sure certain files and folders exist and clean up cache
check_config();
if (!empty($hash)) {
$headers = array(
"Accept: application/json, text/plain, */*;q=0.8",
"Referer: ".MAIN_URL."/",
"Origin: ".MAIN_URL
);
if(TORRENT_REMOTE == "qbittorrent" OR TORRENT_REMOTE == "qbit") {
$url = TORRENT_REMOTE_URL."/api/v2/auth/login";
list($username, $password) = explode(":", TORRENT_REMOTE_ACCESS);
$post_data = http_build_query(array('username' => $username, 'password' => $password));
} else if (TORRENT_REMOTE == "transmission" OR TORRENT_REMOTE == "tm") {
$url = TORRENT_REMOTE_URL."/transmission/rpc";
$headers[] = "Authorization: Basic ".base64_encode(TORRENT_REMOTE_ACCESS);
$post_data = "";
} else {
die("Remote service configured incorrectle!");
if(ERROR_LOG) logger('Remote: Remote service incorrect.');
exit;
}
// Get a Session ID
$ch = curl_options($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
if(!$response = curl_exec($ch)) {
$result = 'CURL: Could not get Session ID. Error '.curl_error($ch).'.';
if(ERROR_LOG) logger($result);
} else {
curl_close($ch);
// Put together a basic magnet link
$magnet = "magnet:?xt=urn:btih:" . $hash;
// Determine the client type based on the response headers
$is_transmission = strpos($response, 'X-Transmission-Session-Id') !== false;
if($is_transmission) {
// Find Session ID (Transmission)
preg_match('/X-Transmission-Session-Id: (.*)/', $response, $matches);
$session_id = isset($matches[1]) ? sanitize($matches[1]) : '';
// Add extra header with Session ID
$headers[] = "X-Transmission-Session-Id: ".$session_id;
// Prepare data
$post_data = json_encode(array("method" => "torrent-add", "arguments" => array("filename" => $magnet)));
} else {
// Find Session ID (QBittorrent)
preg_match('/SID=([^;]+)/', $response, $matches);
$session_id = isset($matches[1]) ? sanitize($matches[1]) : '';
if(!empty($session_id)) {
// Add extra header with Session ID
$headers[] = "Cookie: SID=".$session_id;
}
// Change the url so we can add the magnet
$url = TORRENT_REMOTE_URL."/api/v2/torrents/add";
// Prepare data
$post_data = http_build_query(array('urls' => $magnet, 'category' => 'GooseTOR'));
}
unset($response);
// Try to submit the magnet link
$ch = curl_options($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
if(!$response = curl_exec($ch)) {
$result = 'CURL: Error '.curl_error($ch).'.';
if(ERROR_LOG) logger($result);
} else {
// Check if the torrent was added successfully
if (strpos($response, '"result":"success"') !== false OR $response == "Ok.") {
$result = 'Torrent ('.$hash.') added successfully.';
if(SUCCESS_LOG) logger("ADDED: ".$result, false);
} else {
$result = 'Torrent ('.$hash.') could not be added.';
if(ERROR_LOG) logger("ERROR: ".$result);
}
}
}
curl_close($ch);
} else {
$result = 'Hash not set!';
if(ERROR_LOG) logger("ERROR: ".$result);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Magnet Grabber</title>
</head>
<body>
<p><?php echo $result; ?><br />
The tab closes after a second...</p>
<script>setTimeout(function() { window.close(); }, 1000);</script>
</body>
</html>