redo proxy a bit
This commit is contained in:
@@ -2,68 +2,95 @@ minisrv_service_file = true;
|
||||
request_is_async = true;
|
||||
|
||||
proxyUrl = minisrv_config.services[service_name].wrp_url;
|
||||
if (!proxyUrl.endsWith('/')) {
|
||||
proxyUrl += '/';
|
||||
}
|
||||
|
||||
if (!request_headers.query.url) {
|
||||
if (!proxyUrl) {
|
||||
headers = `200 OK
|
||||
Content-Type: text/html`;
|
||||
Content-Type: text/html
|
||||
wtv-expire-all: wtv-proxy:/`;
|
||||
data = `
|
||||
<html>
|
||||
<head>
|
||||
<head>
|
||||
<title>Web Rendering Proxy</title>
|
||||
</head>
|
||||
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff">
|
||||
</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="m" value="ismap">
|
||||
<input type="submit" value="Go">
|
||||
</form>
|
||||
</body>
|
||||
</html>`
|
||||
Sorry, the Web Rendering Proxy is not enabled on this service.<br>
|
||||
</body>
|
||||
</html>`;
|
||||
sendToClient(socket, headers, data);
|
||||
} 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 {
|
||||
const params = new URLSearchParams({
|
||||
url: request_headers.query.url,
|
||||
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>`);
|
||||
if (request_headers.query.err) {
|
||||
finishPage(`<h1>Error</h1><p>${request_headers.query.err}</p>`).join('<br>');
|
||||
} 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);
|
||||
});
|
||||
const params = new URLSearchParams({
|
||||
url: request_headers.query.url,
|
||||
z: request_headers.query.z || '1.0',
|
||||
t: request_headers.query.t || 'jpg',
|
||||
c: request_headers.query.c || '256',
|
||||
h: request_headers.query.h || '416',
|
||||
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) {
|
||||
if (content.startsWith('<HTML')) {
|
||||
// success page
|
||||
@@ -89,12 +116,14 @@ function process(content) {
|
||||
|
||||
function finishPage(content) {
|
||||
headers = `200 OK
|
||||
Content-Type: text/html`;
|
||||
Content-Type: text/html
|
||||
wtv-expire-all: wtv-proxy:/`;
|
||||
data = `
|
||||
<html>
|
||||
<head>
|
||||
<title>Web Rendering Proxy</title>
|
||||
</head>
|
||||
<display nooptions>
|
||||
<body bgcolor="#191919" text="#44cc55" link="36d5ff" vlink="36d5ff">
|
||||
<form method="POST" action="wtv-proxy:/proxy">
|
||||
<label for="url">URL:</label>
|
||||
@@ -105,13 +134,10 @@ Content-Type: text/html`;
|
||||
<input type="submit" value="Go">
|
||||
<input type="submit" name="Fn" value="Bk">
|
||||
<input type="submit" name="Fn" value="Re">
|
||||
<a href="/proxy">*</a>
|
||||
<hr>
|
||||
${content}
|
||||
</form>
|
||||
<hr>
|
||||
<center>
|
||||
<a href="/proxy">Start Over</a>
|
||||
</center>
|
||||
</body>
|
||||
</html>`;
|
||||
sendToClient(socket, headers, data);
|
||||
|
||||
@@ -395,13 +395,12 @@
|
||||
},
|
||||
"wtv-search": {
|
||||
"disabled": true,
|
||||
"port": 1695,
|
||||
"searxng_url": "http://192.168.11.20:9999/" // replace with your own searxng instance
|
||||
"port": 1695
|
||||
// "searxng_url": "" // replace with your own searxng instance
|
||||
},
|
||||
"wtv-proxy": {
|
||||
"disabled": true,
|
||||
"port": 1696,
|
||||
"wrp_url": "http://192.168.11.20:8889/" // replace with your own tenox9/wrp
|
||||
"port": 1696
|
||||
// "wrp_url": "" // replace with your own tenox9/wrp
|
||||
},
|
||||
"pb_services": {
|
||||
// PC Services for PageBuilder
|
||||
|
||||
Reference in New Issue
Block a user