redo proxy a bit
This commit is contained in:
@@ -2,68 +2,95 @@ minisrv_service_file = true;
|
|||||||
request_is_async = true;
|
request_is_async = true;
|
||||||
|
|
||||||
proxyUrl = minisrv_config.services[service_name].wrp_url;
|
proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||||
if (!proxyUrl.endsWith('/')) {
|
if (!proxyUrl) {
|
||||||
proxyUrl += '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!request_headers.query.url) {
|
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
Content-Type: text/html`;
|
Content-Type: text/html
|
||||||
|
wtv-expire-all: wtv-proxy:/`;
|
||||||
data = `
|
data = `
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Web Rendering Proxy</title>
|
<title>Web Rendering Proxy</title>
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff">
|
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff">
|
||||||
<h1>Web Rendering Proxy</h1>
|
<h1>Web Rendering Proxy</h1>
|
||||||
<p>Welcome to the Web Rendering Proxy.<br>Please provide a valid URL to render.</p>
|
Sorry, the Web Rendering Proxy is not enabled on this service.<br>
|
||||||
<form method="POST" action="wtv-proxy:/proxy">
|
</body>
|
||||||
<label for="url"> URL:</label>
|
</html>`;
|
||||||
<input type="text" id="url" name="url" value="https://" size=38>
|
|
||||||
<input type="hidden" name="z" value="1.0">
|
|
||||||
<input type="hidden" name="t" value="jpg">
|
|
||||||
<input type="hidden" name="c" value="256">
|
|
||||||
<input type="hidden" name="m" value="ismap">
|
|
||||||
<input type="submit" value="Go">
|
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>`
|
|
||||||
sendToClient(socket, headers, data);
|
sendToClient(socket, headers, data);
|
||||||
} else {
|
} else {
|
||||||
if (request_headers.query.err) {
|
|
||||||
finishPage(`<h1>Error</h1><p>${request_headers.query.err}</p>`).join('<br>');
|
if (!proxyUrl.endsWith('/')) {
|
||||||
|
proxyUrl += '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!request_headers.query.url) {
|
||||||
|
headers = `200 OK
|
||||||
|
Content-Type: text/html
|
||||||
|
wtv-expire-all: wtv-proxy:/`;
|
||||||
|
data = `
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Web Rendering Proxy</title>
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff">
|
||||||
|
<h1>Web Rendering Proxy</h1>
|
||||||
|
<p>Welcome to the Web Rendering Proxy.<br>
|
||||||
|
Please provide a valid URL to render.</p>
|
||||||
|
<form method="POST" action="wtv-proxy:/proxy">
|
||||||
|
<label for="url"> URL:</label>
|
||||||
|
<input type="text" id="url" name="url" value="https://" size=38>
|
||||||
|
<input type="hidden" name="z" value="1.0">
|
||||||
|
<input type="hidden" name="t" value="jpg">
|
||||||
|
<input type="hidden" name="c" value="256">
|
||||||
|
<input type="hidden" name="h" value="416">
|
||||||
|
<input type="hidden" name="w" value="640">
|
||||||
|
<input type="hidden" name="m" value="ismap">
|
||||||
|
<input type="submit" value="Go">
|
||||||
|
</form>
|
||||||
|
<hr>
|
||||||
|
<center>
|
||||||
|
<a href="wtv-tricks:/tricks">Back to Tricks</a>
|
||||||
|
</center>
|
||||||
|
</body>
|
||||||
|
</html>`
|
||||||
|
sendToClient(socket, headers, data);
|
||||||
} else {
|
} else {
|
||||||
const params = new URLSearchParams({
|
if (request_headers.query.err) {
|
||||||
url: request_headers.query.url,
|
finishPage(`<h1>Error</h1><p>${request_headers.query.err}</p>`).join('<br>');
|
||||||
z: request_headers.query.z || '1.0',
|
|
||||||
t: request_headers.query.t || 'jpg',
|
|
||||||
c: request_headers.query.c || '256',
|
|
||||||
m: request_headers.query.m || 'ismap'
|
|
||||||
});
|
|
||||||
const fullUrl = proxyUrl + '?' + params.toString();
|
|
||||||
const urlObj = new URL(fullUrl);
|
|
||||||
const lib = urlObj.protocol === 'https:' ? https : http;
|
|
||||||
if (request_headers.query.id) {
|
|
||||||
finishPage(`<a href="/map/${request_headers.query.id}.map"><img src="/img/${request_headers.query.id}.${params.get('t')}" ISMAP></a>`);
|
|
||||||
} else {
|
} else {
|
||||||
function fetch(url) {
|
const params = new URLSearchParams({
|
||||||
return new Promise((resolve, reject) => {
|
url: request_headers.query.url,
|
||||||
lib.get(url, (res) => {
|
z: request_headers.query.z || '1.0',
|
||||||
let data = '';
|
t: request_headers.query.t || 'jpg',
|
||||||
res.on('data', chunk => data += chunk);
|
c: request_headers.query.c || '256',
|
||||||
res.on('end', () => resolve({ text: () => Promise.resolve(data) }));
|
h: request_headers.query.h || '416',
|
||||||
}).on('error', reject);
|
w: request_headers.query.w || '640',
|
||||||
});
|
m: request_headers.query.m || 'ismap'
|
||||||
|
});
|
||||||
|
const fullUrl = proxyUrl + '?' + params.toString();
|
||||||
|
const urlObj = new URL(fullUrl);
|
||||||
|
const lib = urlObj.protocol === 'https:' ? https : http;
|
||||||
|
if (request_headers.query.id) {
|
||||||
|
finishPage(`<a href="/map/${request_headers.query.id}.map"><img src="/img/${request_headers.query.id}.${params.get('t')}" ISMAP></a>`);
|
||||||
|
} else {
|
||||||
|
function fetch(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
lib.get(url, (res) => {
|
||||||
|
let data = '';
|
||||||
|
res.on('data', chunk => data += chunk);
|
||||||
|
res.on('end', () => resolve({ text: () => Promise.resolve(data) }));
|
||||||
|
}).on('error', reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
fetch(fullUrl)
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(text => { process(text); })
|
||||||
|
.catch(err => { finishPage(`Error fetching page: ${err.message}`); });
|
||||||
}
|
}
|
||||||
fetch(fullUrl)
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(text => { process(text); })
|
|
||||||
.catch(err => { finishPage(`Error fetching page: ${err.message}`); });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function process(content) {
|
function process(content) {
|
||||||
if (content.startsWith('<HTML')) {
|
if (content.startsWith('<HTML')) {
|
||||||
// success page
|
// success page
|
||||||
@@ -89,12 +116,14 @@ function process(content) {
|
|||||||
|
|
||||||
function finishPage(content) {
|
function finishPage(content) {
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
Content-Type: text/html`;
|
Content-Type: text/html
|
||||||
|
wtv-expire-all: wtv-proxy:/`;
|
||||||
data = `
|
data = `
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Web Rendering Proxy</title>
|
<title>Web Rendering Proxy</title>
|
||||||
</head>
|
</head>
|
||||||
|
<display nooptions>
|
||||||
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff">
|
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff">
|
||||||
<form method="POST" action="wtv-proxy:/proxy">
|
<form method="POST" action="wtv-proxy:/proxy">
|
||||||
<label for="url">URL:</label>
|
<label for="url">URL:</label>
|
||||||
@@ -105,13 +134,10 @@ Content-Type: text/html`;
|
|||||||
<input type="submit" value="Go">
|
<input type="submit" value="Go">
|
||||||
<input type="submit" name="Fn" value="Bk">
|
<input type="submit" name="Fn" value="Bk">
|
||||||
<input type="submit" name="Fn" value="Re">
|
<input type="submit" name="Fn" value="Re">
|
||||||
|
<a href="/proxy">*</a>
|
||||||
<hr>
|
<hr>
|
||||||
${content}
|
${content}
|
||||||
</form>
|
</form>
|
||||||
<hr>
|
|
||||||
<center>
|
|
||||||
<a href="/proxy">Start Over</a>
|
|
||||||
</center>
|
|
||||||
</body>
|
</body>
|
||||||
</html>`;
|
</html>`;
|
||||||
sendToClient(socket, headers, data);
|
sendToClient(socket, headers, data);
|
||||||
|
|||||||
@@ -395,13 +395,12 @@
|
|||||||
},
|
},
|
||||||
"wtv-search": {
|
"wtv-search": {
|
||||||
"disabled": true,
|
"disabled": true,
|
||||||
"port": 1695,
|
"port": 1695
|
||||||
"searxng_url": "http://192.168.11.20:9999/" // replace with your own searxng instance
|
// "searxng_url": "" // replace with your own searxng instance
|
||||||
},
|
},
|
||||||
"wtv-proxy": {
|
"wtv-proxy": {
|
||||||
"disabled": true,
|
"port": 1696
|
||||||
"port": 1696,
|
// "wrp_url": "" // replace with your own tenox9/wrp
|
||||||
"wrp_url": "http://192.168.11.20:8889/" // replace with your own tenox9/wrp
|
|
||||||
},
|
},
|
||||||
"pb_services": {
|
"pb_services": {
|
||||||
// PC Services for PageBuilder
|
// PC Services for PageBuilder
|
||||||
|
|||||||
Reference in New Issue
Block a user