cw332 commited on
Commit
3ec47db
·
verified ·
1 Parent(s): b9c61c0

PERFORM THE FOLLOWING OPERATIONS:

Browse files

- **WHAT**: create and Implement the REAL proxy service
- **WHERE**: at and around the source code lines (number 105) in the file `index.html` — the lines containing the code comment that reads `// In a real implementation, this would redirect through your proxy service`,

Files changed (4) hide show
  1. index.html +25 -4
  2. proxy.js +73 -0
  3. script.js +58 -0
  4. style.css +20 -2
index.html CHANGED
@@ -102,11 +102,32 @@
102
  e.preventDefault();
103
  const url = document.getElementById('url').value;
104
  if (url) {
105
- // In a real implementation, this would redirect through your proxy service
106
- window.location.href = `/proxy?url=${encodeURIComponent(url)}`;
107
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  });
109
  </script>
110
- <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
111
  </body>
112
  </html>
 
102
  e.preventDefault();
103
  const url = document.getElementById('url').value;
104
  if (url) {
105
+ // Show loading state
106
+ const form = document.getElementById('proxyForm');
107
+ form.classList.add('submitting');
108
+
109
+ // Call proxy endpoint
110
+ fetch(`/proxy?url=${encodeURIComponent(url)}`)
111
+ .then(response => {
112
+ if (!response.ok) throw new Error('Network response was not ok');
113
+ return response.text();
114
+ })
115
+ .then(html => {
116
+ // Create a new document with the proxied content
117
+ const proxiedDoc = document.open('text/html', 'replace');
118
+ proxiedDoc.write(html);
119
+ proxiedDoc.close();
120
+ })
121
+ .catch(error => {
122
+ console.error('Proxy error:', error);
123
+ alert('Error loading the requested URL. Please try again.');
124
+ })
125
+ .finally(() => {
126
+ form.classList.remove('submitting');
127
+ });
128
+ }
129
  });
130
  </script>
131
+ <!-- <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script> -->
132
  </body>
133
  </html>
proxy.js ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const cors = require('cors');
3
+ const axios = require('axios');
4
+ const cheerio = require('cheerio');
5
+
6
+ const app = express();
7
+ const PORT = process.env.PORT || 3000;
8
+
9
+ // Middleware
10
+ app.use(cors());
11
+ app.use(express.json());
12
+
13
+ // Proxy endpoint
14
+ app.get('/proxy', async (req, res) => {
15
+ try {
16
+ const targetUrl = req.query.url;
17
+ if (!targetUrl) {
18
+ return res.status(400).send('URL parameter is required');
19
+ }
20
+
21
+ // Validate URL
22
+ try {
23
+ new URL(targetUrl);
24
+ } catch (e) {
25
+ return res.status(400).send('Invalid URL');
26
+ }
27
+
28
+ // Fetch the target page
29
+ const response = await axios.get(targetUrl, {
30
+ headers: {
31
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
32
+ }
33
+ });
34
+
35
+ // Process the HTML to rewrite links
36
+ const $ = cheerio.load(response.data);
37
+
38
+ // Rewrite all links to go through our proxy
39
+ $('a[href]').each((i, el) => {
40
+ const href = $(el).attr('href');
41
+ try {
42
+ const url = new URL(href, targetUrl);
43
+ $(el).attr('href', `/proxy?url=${encodeURIComponent(url.href)}`);
44
+ } catch (e) {
45
+ // Skip invalid URLs
46
+ }
47
+ });
48
+
49
+ // Rewrite all form actions to go through our proxy
50
+ $('form[action]').each((i, el) => {
51
+ const action = $(el).attr('action');
52
+ try {
53
+ const url = new URL(action, targetUrl);
54
+ $(el).attr('action', `/proxy?url=${encodeURIComponent(url.href)}`);
55
+ } catch (e) {
56
+ // Skip invalid URLs
57
+ }
58
+ });
59
+
60
+ // Send the modified content
61
+ res.set('Content-Type', response.headers['content-type']);
62
+ res.send($.html());
63
+
64
+ } catch (error) {
65
+ console.error('Proxy error:', error);
66
+ res.status(500).send('Error fetching the requested URL');
67
+ }
68
+ });
69
+
70
+ // Start server
71
+ app.listen(PORT, () => {
72
+ console.log(`Proxy server running on port ${PORT}`);
73
+ });
script.js CHANGED
@@ -1,6 +1,64 @@
 
1
  // Shared functionality across pages
2
  console.log('GhostSurf proxy service initialized');
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  // Form validation for proxy input
5
  function validateUrl(url) {
6
  try {
 
1
+
2
  // Shared functionality across pages
3
  console.log('GhostSurf proxy service initialized');
4
 
5
+ // Proxy URL validator
6
+ function isValidProxyUrl(url) {
7
+ try {
8
+ const urlObj = new URL(url);
9
+ return ['http:', 'https:'].includes(urlObj.protocol);
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ // Initialize proxy form
16
+ function initProxyForm() {
17
+ const form = document.getElementById('proxyForm');
18
+ if (form) {
19
+ form.addEventListener('submit', function(e) {
20
+ e.preventDefault();
21
+ const urlInput = document.getElementById('url');
22
+ const url = urlInput.value.trim();
23
+
24
+ if (!isValidProxyUrl(url)) {
25
+ alert('Please enter a valid http:// or https:// URL');
26
+ return;
27
+ }
28
+
29
+ // Ensure URL has protocol
30
+ const fullUrl = url.startsWith('http') ? url : `https://${url}`;
31
+
32
+ // Show loading state
33
+ form.classList.add('submitting');
34
+
35
+ // Call proxy endpoint
36
+ fetch(`/proxy?url=${encodeURIComponent(fullUrl)}`)
37
+ .then(response => {
38
+ if (!response.ok) throw new Error('Network response was not ok');
39
+ return response.text();
40
+ })
41
+ .then(html => {
42
+ // Create a new document with the proxied content
43
+ const proxiedDoc = document.open('text/html', 'replace');
44
+ proxiedDoc.write(html);
45
+ proxiedDoc.close();
46
+ })
47
+ .catch(error => {
48
+ console.error('Proxy error:', error);
49
+ alert('Error loading the requested URL. Please try again.');
50
+ })
51
+ .finally(() => {
52
+ form.classList.remove('submitting');
53
+ });
54
+ });
55
+ }
56
+ }
57
+
58
+ // Initialize when DOM is loaded
59
+ document.addEventListener('DOMContentLoaded', function() {
60
+ initProxyForm();
61
+ });
62
  // Form validation for proxy input
63
  function validateUrl(url) {
64
  try {
style.css CHANGED
@@ -15,7 +15,25 @@ body {
15
  transform: scale(1.02);
16
  }
17
  }
18
-
19
  .submitting {
20
  animation: pulse 1.5s infinite;
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  transform: scale(1.02);
16
  }
17
  }
 
18
  .submitting {
19
  animation: pulse 1.5s infinite;
20
+ opacity: 0.8;
21
+ pointer-events: none;
22
+ }
23
+
24
+ /* Loading indicator */
25
+ .submitting::after {
26
+ content: '';
27
+ display: inline-block;
28
+ width: 16px;
29
+ height: 16px;
30
+ margin-left: 8px;
31
+ border: 2px solid rgba(255,255,255,0.3);
32
+ border-radius: 50%;
33
+ border-top-color: #fff;
34
+ animation: spin 1s ease-in-out infinite;
35
+ }
36
+
37
+ @keyframes spin {
38
+ to { transform: rotate(360deg); }
39
+ }