nullresolve/ts/nullresolve.classes.nullresolve.ts
2024-12-26 00:29:13 +01:00

148 lines
5.6 KiB
TypeScript

import * as plugins from './nullresolve.plugins.js';
import { projectinfo } from './nullresolve.projectinfo.js';
import { configObject } from './nullresolve.config.js';
export class NullResolve {
public serviceServer: plugins.typedserver.utilityservers.UtilityServiceServer;
constructor() {
this.serviceServer = new plugins.typedserver.utilityservers.UtilityServiceServer({
serviceDomain: 'nullresolve.lossless.one',
serviceName: 'nullresolve',
serviceVersion: projectinfo.npm.version,
addCustomRoutes: async (serverArg) => {
serverArg.addRoute(
'/status/:code',
new plugins.typedserver.servertools.Handler('GET', async (req, res) => {
let infoHtmlOptions: plugins.typedserverInfoHtml.IHtmlInfoOptions;
switch (req.params.code) {
case 'ipblock':
infoHtmlOptions = {
title: 'Lossless Network: Blocked IP',
heading: 'Blocked IP',
text: 'Your IP (::CLIENT_IP::) is not allowed to access this ressource.',
sentryDsn: configObject.sentryDsn,
sentryMessage: 'ipblock',
redirectTo: 'https://lossless.com',
};
break;
case 'firewall':
infoHtmlOptions = {
title: 'Lossless Network: Firewall',
heading: 'Firewall',
text: 'Your request has been blocked by our firewall since it showed possibly harmful behaviour.',
sentryDsn: configObject.sentryDsn,
sentryMessage: 'firewall',
redirectTo: 'https://lossless.com',
};
break;
case '500class':
infoHtmlOptions = {
title: 'Lossless Network: 5xx',
heading: '5xx',
text: '::CLOUDFLARE_ERROR_500S_BOX::',
sentryDsn: configObject.sentryDsn,
sentryMessage: '5xx error',
redirectTo: 'https://lossless.com',
};
break;
case '1000class':
infoHtmlOptions = {
title: 'Lossless Network: DNS Resolution failed',
heading: '1xxx',
text: '::CLOUDFLARE_ERROR_1000S_BOX::',
sentryDsn: configObject.sentryDsn,
sentryMessage: '1000 class error',
redirectTo: 'https://lossless.com',
};
break;
case 'alwaysonline':
infoHtmlOptions = {
title: 'Lossless Network: No Cache',
heading: 'No Cache',
text: '::ALWAYS_ONLINE_NO_COPY_BOX::',
sentryDsn: configObject.sentryDsn,
sentryMessage: 'alwaysonline triggered. Potentially offline!',
redirectTo: 'https://lossless.com',
};
break;
case 'waf':
infoHtmlOptions = {
title: 'Lossless Network: Firewall Challenge',
heading: 'Firewall Challenge',
text: '::CAPTCHA_BOX::',
redirectTo: 'https://lossless.com',
};
break;
case 'country':
infoHtmlOptions = {
title: 'Lossless Network: Country Challenge',
heading: 'Country Challenge',
text: '::CAPTCHA_BOX::',
redirectTo: 'https://lossless.com',
};
break;
case 'attack':
infoHtmlOptions = {
title: 'Lossless Network: Advanced User Challenge',
heading: 'Advanced User Challenge',
text: '::IM_UNDER_ATTACK_BOX::',
redirectTo: 'https://lossless.com',
};
break;
default:
const statusInstance = plugins.smartstatus.HttpStatus.getHttpStatusByString(
req.params.code,
);
infoHtmlOptions = {
title: `Lossless Network: ${statusInstance.code.toString()}`,
heading: statusInstance.code.toString(),
text: statusInstance.text,
};
break;
}
const infoHtmlInstance =
await plugins.typedserverInfoHtml.InfoHtml.fromOptions(infoHtmlOptions);
res.status(200);
res.send(infoHtmlInstance.htmlString);
}),
);
serverArg.addRoute(
'/custom',
new plugins.typedserver.servertools.Handler('GET', async (req, res) => {
console.log(req.query);
const options: any = {
title: 'Lossless Network',
heading: 'Error!',
text: 'Please wait...',
redirectTo: 'https://lossless.com',
...req.query,
};
const infoHtmlInstance = await plugins.typedserverInfoHtml.InfoHtml.fromOptions({
title: decodeURI(options.title),
heading: decodeURI(options.heading),
text: decodeURI(options.text),
redirectTo: decodeURI(options.redirectTo),
sentryDsn: configObject.sentryDsn,
sentryMessage: `nullresolve custom: ${decodeURI(options.title)}`,
});
res.status(200);
res.send(infoHtmlInstance.htmlString);
}),
);
},
});
}
public async start() {
await this.serviceServer.start();
}
public async stop() {
await this.serviceServer.stop();
}
}