This commit is contained in:
2024-12-26 00:29:13 +01:00
commit d7c8972072
25 changed files with 10342 additions and 0 deletions

9
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,9 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@losslessone_private/nullresolve',
version: '1.0.29',
description:
'servezone service. the null service takes care of handling requests and giving feedback for those that would otherwise not be served.',
};

17
ts/index.ts Normal file
View File

@ -0,0 +1,17 @@
import './nullresolve.logging.js';
import { NullResolve } from './nullresolve.classes.nullresolve.js';
export { NullResolve };
let mainNullResolve: NullResolve;
export const runCli = async () => {
mainNullResolve = new NullResolve();
await mainNullResolve.start();
};
export const stop = async () => {
if (mainNullResolve) {
await mainNullResolve.stop();
mainNullResolve = null;
}
};

View File

@ -0,0 +1,147 @@
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();
}
}

3
ts/nullresolve.config.ts Normal file
View File

@ -0,0 +1,3 @@
export const configObject = {
sentryDsn: 'https://85d4a993eac74dd389c56c1f842b2dff@sentry.io/1486007',
};

View File

@ -0,0 +1,8 @@
import * as plugins from './nullresolve.plugins.js';
import * as paths from './nullresolve.paths.js';
const projectInfoNpm = new plugins.projectinfo.ProjectinfoNpm(paths.packageDir);
import { commitinfo } from './00_commitinfo_data.js';
export const logger = plugins.smartlog.Smartlog.createForCommitinfo(commitinfo);

6
ts/nullresolve.paths.ts Normal file
View File

@ -0,0 +1,6 @@
import * as plugins from './nullresolve.plugins.js';
export const packageDir = plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
'../',
);

18
ts/nullresolve.plugins.ts Normal file
View File

@ -0,0 +1,18 @@
// native
import * as path from 'path';
export { path };
// @api.global scope
import * as typedserver from '@api.global/typedserver';
import * as typedserverInfoHtml from '@api.global/typedserver/infohtml';
export { typedserver, typedserverInfoHtml };
// @push.rocks scope
import * as projectinfo from '@push.rocks/projectinfo';
import * as smartlog from '@push.rocks/smartlog';
import * as smartpath from '@push.rocks/smartpath';
import * as smartstatus from '@push.rocks/smartstatus';
export { projectinfo, smartlog, smartpath, smartstatus };

View File

@ -0,0 +1,4 @@
import * as plugins from './nullresolve.plugins.js';
import * as paths from './nullresolve.paths.js';
export const projectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);