Files
SiteProxy/proxy/index.go
2025-12-15 01:19:25 +08:00

264 lines
6.8 KiB
Go

// proxy/index.go
package proxy
import (
"net/http"
)
func ServeIndexPage(w http.ResponseWriter, r *http.Request) {
html := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secure Site Proxy</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
padding: 40px;
border-radius: 15px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
width: 100%;
max-width: 700px;
}
.header {
text-align: center;
margin-bottom: 30px;
}
.header h1 {
font-size: 32px;
color: #333;
margin-bottom: 10px;
}
.header p {
color: #666;
font-size: 14px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
color: #555;
font-weight: 500;
font-size: 14px;
}
.input-wrapper {
position: relative;
display: flex;
gap: 10px;
}
input[type="url"] {
flex: 1;
padding: 14px 16px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 15px;
transition: all 0.3s;
}
input[type="url"]:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
button {
padding: 14px 30px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
white-space: nowrap;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
button:active {
transform: translateY(0);
}
.info-box {
background: #f8f9fa;
border-left: 4px solid #667eea;
padding: 15px;
border-radius: 5px;
margin-top: 20px;
}
.info-box h3 {
font-size: 14px;
color: #333;
margin-bottom: 8px;
}
.info-box ul {
list-style: none;
padding-left: 0;
}
.info-box li {
font-size: 13px;
color: #666;
margin-bottom: 5px;
padding-left: 20px;
position: relative;
}
.info-box li:before {
content: "✓";
position: absolute;
left: 0;
color: #667eea;
font-weight: bold;
}
.footer {
margin-top: 20px;
text-align: center;
display: flex;
justify-content: space-between;
align-items: center;
}
.footer a {
color: #667eea;
text-decoration: none;
font-size: 14px;
transition: color 0.3s;
}
.footer a:hover {
color: #764ba2;
}
.stats {
font-size: 12px;
color: #999;
}
@media (max-width: 600px) {
.container {
padding: 25px;
}
.header h1 {
font-size: 24px;
}
.input-wrapper {
flex-direction: column;
}
button {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔒 Secure Site Proxy</h1>
<p>Access websites securely through encrypted proxy</p>
</div>
<form id="proxyForm">
<div class="form-group">
<label for="targetUrl">Enter URL to access:</label>
<div class="input-wrapper">
<input
type="url"
id="targetUrl"
name="url"
placeholder="https://example.com"
required
autofocus
pattern="https?://.+"
>
<button type="submit">Access</button>
</div>
</div>
</form>
<div class="info-box">
<h3>Security Features:</h3>
<ul>
<li>End-to-end encrypted connection</li>
<li>No logging of accessed URLs</li>
<li>Automatic content rewriting</li>
<li>Protection against private network access</li>
</ul>
</div>
<div class="footer">
<a href="/logout">Logout</a>
<span class="stats" id="stats"></span>
</div>
</div>
<script>
document.getElementById('proxyForm').addEventListener('submit', function(e) {
e.preventDefault();
const url = document.getElementById('targetUrl').value;
// 基本验证
if (!url.startsWith('http://') && !url.startsWith('https://')) {
alert('URL must start with http:// or https://');
return;
}
// 跳转到代理页面
window.location.href = '/proxy?url=' + encodeURIComponent(url);
});
// 加载统计信息(可选)
fetch('/stats')
.then(r => r.json())
.then(data => {
document.getElementById('stats').textContent =
'Cache: ' + data.entries + ' entries, ' +
(data.size / 1024 / 1024).toFixed(2) + ' MB';
})
.catch(() => {});
</script>
</body>
</html>`
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(html))
}