-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontribute.html
More file actions
295 lines (270 loc) · 13.2 KB
/
contribute.html
File metadata and controls
295 lines (270 loc) · 13.2 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contribute - ImgurUK</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0a0a0a; color: #fff; min-height: 100vh; }
nav { background: #1a1a1a; padding: 1rem 2rem; border-bottom: 1px solid #333; }
nav .container { max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; }
nav h1 { font-size: 1.5rem; }
nav h1 a { color: #fff; text-decoration: none; }
nav .links a { color: #fff; text-decoration: none; margin-left: 1.5rem; padding: 0.5rem 1rem; border-radius: 4px; transition: background 0.2s; }
nav .links a:hover { background: #333; }
.container { max-width: 1000px; margin: 2rem auto; padding: 2rem; }
.section { background: #1a1a1a; padding: 2rem; border-radius: 8px; margin-bottom: 2rem; border: 1px solid #333; }
h2 { margin-bottom: 1rem; color: #4CAF50; }
.info { color: #aaa; margin-bottom: 1.5rem; line-height: 1.6; }
.token-box { background: #0a0a0a; padding: 1rem; border-radius: 4px; display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.token-box input { flex: 1; background: transparent; border: 1px solid #333; color: #fff; padding: 0.5rem; border-radius: 4px; font-family: monospace; }
.btn { background: #4CAF50; color: #fff; padding: 0.75rem 1.5rem; border-radius: 4px; border: none; cursor: pointer; font-weight: bold; transition: background 0.2s; }
.btn:hover { background: #45a049; }
.btn.secondary { background: #333; }
.btn.secondary:hover { background: #444; }
.btn.danger { background: #f44336; }
.btn.danger:hover { background: #da190b; }
.form-group { margin-bottom: 1.5rem; }
label { display: block; margin-bottom: 0.5rem; color: #aaa; }
input[type="url"] { width: 100%; padding: 0.75rem; background: #0a0a0a; border: 1px solid #333; border-radius: 4px; color: #fff; }
.message { padding: 0.75rem; margin-bottom: 1rem; border-radius: 4px; display: none; }
.message.error { background: #f44336; }
.message.success { background: #4CAF50; }
.proxy-list { margin-top: 1rem; }
.proxy-item { background: #0a0a0a; padding: 1rem; border-radius: 4px; margin-bottom: 0.5rem; display: flex; justify-content: space-between; align-items: center; }
.proxy-url { flex: 1; font-family: monospace; }
.proxy-status { padding: 0.25rem 0.75rem; border-radius: 4px; font-size: 0.9rem; margin: 0 1rem; }
.proxy-status.active { background: #4CAF50; }
.proxy-status.inactive { background: #666; }
.proxy-actions { display: flex; gap: 0.5rem; }
.btn-small { padding: 0.5rem 1rem; font-size: 0.9rem; }
code { background: #0a0a0a; padding: 0.25rem 0.5rem; border-radius: 4px; font-family: monospace; color: #4CAF50; }
.empty-state { text-align: center; color: #666; padding: 2rem; }
</style>
</head>
<body>
<nav>
<div class="container">
<h1><a href="/">ImgurUK</a></h1>
<div class="links">
<a href="/">Home</a>
<a href="/upload.html">Upload</a>
<a href="/api.php?action=logout">Logout</a>
</div>
</div>
</nav>
<div class="container">
<h1>Contribute to the Network</h1>
<div class="section">
<h2>How It Works</h2>
<div class="info">
Help distribute the load by hosting a proxy script on your server. When users request imgur content through ImgurUK,
we'll randomly distribute requests to contributor proxies. Your proxy fetches the content from imgur and returns it to our network.
<br><br>
<strong>Benefits:</strong>
<ul style="margin-left: 2rem; margin-top: 0.5rem;">
<li>Distribute bandwidth across multiple servers</li>
<li>Help keep the service fast and reliable</li>
<li>Support the community</li>
</ul>
</div>
</div>
<div class="section">
<h2>Your API Token</h2>
<div class="info">
This token authenticates your proxy script. Keep it secret!
</div>
<div class="token-box">
<input type="text" id="apiToken" readonly value="Loading...">
<button class="btn secondary" onclick="copyToken()">Copy</button>
<button class="btn secondary" onclick="regenerateToken()">Regenerate</button>
</div>
</div>
<div class="section">
<h2>Download Proxy Script</h2>
<div class="info">
Download this PHP script and upload it to any web-accessible path on your server.
The script validates requests from ImgurUK and proxies content from imgur.com.
<br><br>
Examples of valid setups:
<ul style="margin-left: 2rem; margin-top: 0.5rem;">
<li><code>https://yoursite.com/imguruk-proxy.php</code></li>
<li><code>https://cdn.yoursite.com/proxy/index.php</code></li>
<li><code>https://yoursite.com/images/</code> (as index.php)</li>
</ul>
</div>
<button class="btn" onclick="downloadScript()">Download imguruk-proxy.php</button>
</div>
<div class="section">
<h2>Register Your Proxy</h2>
<div id="proxyMessage" class="message"></div>
<form id="addProxyForm">
<div class="form-group">
<label for="proxyUrl">Proxy URL</label>
<input type="url" id="proxyUrl" name="proxyUrl" placeholder="https://yoursite.com/imguruk-proxy.php" required>
<small style="color: #666;">The full URL (including filename) where your proxy script is accessible. Requests will be made to this URL with the filename appended (e.g., your-url/image.jpg)</small>
</div>
<button type="submit" class="btn">Add Proxy</button>
</form>
</div>
<div class="section">
<h2>Your Proxies</h2>
<div id="proxyList" class="proxy-list">
<div class="empty-state">Loading...</div>
</div>
</div>
</div>
<script>
let apiToken = '';
async function loadApiToken() {
try {
const response = await fetch('/api.php?action=get_api_token');
const result = await response.json();
if (result.success) {
apiToken = result.token;
document.getElementById('apiToken').value = apiToken;
}
} catch (error) {
document.getElementById('apiToken').value = 'Error loading token';
}
}
async function loadProxies() {
try {
const response = await fetch('/api.php?action=get_proxies');
const result = await response.json();
const proxyList = document.getElementById('proxyList');
if (result.success && result.proxies.length > 0) {
proxyList.innerHTML = result.proxies.map(proxy => `
<div class="proxy-item">
<div class="proxy-url">${proxy.proxy_url}</div>
<span class="proxy-status ${proxy.is_active ? 'active' : 'inactive'}">
${proxy.is_active ? 'Active' : 'Inactive'}
</span>
<div class="proxy-actions">
<button class="btn btn-small secondary" onclick="toggleProxy(${proxy.id})">
${proxy.is_active ? 'Disable' : 'Enable'}
</button>
<button class="btn btn-small danger" onclick="deleteProxy(${proxy.id})">Delete</button>
</div>
</div>
`).join('');
} else {
proxyList.innerHTML = '<div class="empty-state">No proxies registered yet</div>';
}
} catch (error) {
document.getElementById('proxyList').innerHTML = '<div class="empty-state">Error loading proxies</div>';
}
}
function copyToken() {
const input = document.getElementById('apiToken');
input.select();
document.execCommand('copy');
alert('Token copied to clipboard!');
}
async function regenerateToken() {
if (!confirm('Are you sure? This will invalidate your current token and all proxies will need the new script.')) {
return;
}
try {
const response = await fetch('/api.php?action=regenerate_token', { method: 'POST' });
const result = await response.json();
if (result.success) {
apiToken = result.token;
document.getElementById('apiToken').value = apiToken;
alert('Token regenerated! Download the new script and update your proxies.');
}
} catch (error) {
alert('Failed to regenerate token');
}
}
async function downloadScript() {
if (!apiToken) {
alert('Please wait for token to load');
return;
}
try {
const response = await fetch('/api.php?action=download_script');
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'imguruk-proxy.php';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
} catch (error) {
alert('Failed to download script');
}
}
document.getElementById('addProxyForm').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const proxyUrl = formData.get('proxyUrl');
try {
const response = await fetch('/api.php?action=add_proxy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ proxy_url: proxyUrl })
});
const result = await response.json();
const messageDiv = document.getElementById('proxyMessage');
if (result.success) {
messageDiv.className = 'message success';
messageDiv.textContent = result.message;
messageDiv.style.display = 'block';
e.target.reset();
loadProxies();
setTimeout(() => messageDiv.style.display = 'none', 3000);
} else {
messageDiv.className = 'message error';
messageDiv.textContent = result.error;
messageDiv.style.display = 'block';
}
} catch (error) {
const messageDiv = document.getElementById('proxyMessage');
messageDiv.className = 'message error';
messageDiv.textContent = 'An error occurred';
messageDiv.style.display = 'block';
}
});
async function toggleProxy(id) {
try {
const response = await fetch('/api.php?action=toggle_proxy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ proxy_id: id })
});
const result = await response.json();
if (result.success) {
loadProxies();
}
} catch (error) {
alert('Failed to toggle proxy');
}
}
async function deleteProxy(id) {
if (!confirm('Are you sure you want to delete this proxy?')) {
return;
}
try {
const response = await fetch('/api.php?action=delete_proxy', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ proxy_id: id })
});
const result = await response.json();
if (result.success) {
loadProxies();
}
} catch (error) {
alert('Failed to delete proxy');
}
}
// Load data on page load
loadApiToken();
loadProxies();
</script>
</body>
</html>