refactor: change the way domain checks validate a domain

This commit is contained in:
2025-09-30 22:55:14 -07:00
parent d0c8920b98
commit f274b807f2

View File

@@ -28,6 +28,11 @@ import * as crons from 'cron';
*/ */
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
/*
Initialize classes
*/
const cache = new Map(); const cache = new Map();
/* /*
@@ -37,6 +42,7 @@ const cache = new Map();
const { name, author, version, repository, discord, docs } = JSON.parse( fs.readFileSync( './package.json' ) ); const { name, author, version, repository, discord, docs } = JSON.parse( fs.readFileSync( './package.json' ) );
const __filename = fileURLToPath( import.meta.url ); // get resolved path to file const __filename = fileURLToPath( import.meta.url ); // get resolved path to file
const __dirname = path.dirname( __filename ); // get name of directory const __dirname = path.dirname( __filename ); // get name of directory
/* /*
const gitHash = child.execSync( 'git rev-parse HEAD' ).toString().trim(); const gitHash = child.execSync( 'git rev-parse HEAD' ).toString().trim();
*/ */
@@ -83,7 +89,7 @@ let FILE_XML_MODIFIED = 0;
let FILE_GZP_MODIFIED = 0; let FILE_GZP_MODIFIED = 0;
/* /*
Define > Environment Variables || Defaults Define Environment Variables || Defaults
*/ */
const envAppRelease = process.env.RELEASE || 'stable'; const envAppRelease = process.env.RELEASE || 'stable';
@@ -112,7 +118,7 @@ let serverOs = 'Unknown';
let serverStartup = 0; let serverStartup = 0;
/* /*
Define > Externals Define Externals
*/ */
const extURL = `${ envUrlRepo }/tvapp2-externals/raw/branch/main/urls.txt`; const extURL = `${ envUrlRepo }/tvapp2-externals/raw/branch/main/urls.txt`;
@@ -120,7 +126,7 @@ const extXML = `${ envUrlRepo }/XMLTV-EPG/raw/branch/main/xmltv.1.xml`;
const extM3U = `${ envUrlRepo }/tvapp2-externals/raw/branch/main/formatted.dat`; const extM3U = `${ envUrlRepo }/tvapp2-externals/raw/branch/main/formatted.dat`;
/* /*
Define > Defaults Define Defaults
*/ */
let urls = []; let urls = [];
@@ -417,90 +423,94 @@ const clientIp = ( req ) =>
if try 2 fails with the opposite protocol; domain is considered down if try 2 fails with the opposite protocol; domain is considered down
*/ */
async function serviceCheck( service, uri ) async function hostCheck( service, uri )
{ {
/* try 1 */ /* try 1 */
try try
{ {
const resp = await fetch( uri ); const resp = await fetch( uri );
/* try 1 > domain down */ /* try 1 domain down */
if ( resp.status !== 200 ) if ( resp.status !== 200 )
{ {
Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Service Offline; failed to communicate with service, possibly down` ), chalk.redBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uri }` ) ); Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Try: Service Offline; failed to communicate with service, possibly down` ), chalk.redBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uri }` ) );
return; return false;
} }
/* try 1 > domain up */ /* try 1 domain up */
Log.ok( `ping`, chalk.yellow( `[response]` ), chalk.white( `` ), chalk.greenBright( `<msg>` ), chalk.gray( `Service Online` ), chalk.greenBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.greenBright( `<service>` ), chalk.gray( `${ service }` ), chalk.greenBright( `<address>` ), chalk.gray( `${ uri }` ) ); Log.ok( `ping`, chalk.yellow( `[response]` ), chalk.white( `` ), chalk.greenBright( `<msg>` ), chalk.gray( `Domain Online` ), chalk.greenBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.greenBright( `<service>` ), chalk.gray( `${ service }` ), chalk.greenBright( `<address>` ), chalk.gray( `${ uri }` ) );
return true;
} }
catch ( err ) catch ( err )
{ {
/* /*
try 2 > http try 2 https
*/ */
if ( /^https:\/\//i.test( uri ) ) if ( /^https:\/\//i.test( uri ) )
{ {
const uriRetry = uri.replace( /^https:\/\//ig, 'http://' ); const uriRetry = uri.replace( /^https:\/\//ig, 'http://' );
Log.info( `ping`, chalk.yellow( `[response]` ), chalk.white( `⚠️` ), chalk.yellowBright( `<msg>` ), chalk.gray( `Service Offline; failed to communicate with service via SSL; trying http protocol` ), chalk.yellowBright( `<service>` ), chalk.gray( `${ service }` ), chalk.yellowBright( `<uriAttempt1>` ), chalk.gray( `${ uri }` ), chalk.redBright( `(failed)` ), chalk.yellowBright( `<uriAttempt2>` ), chalk.gray( `${ uriRetry }` ), chalk.blueBright( `(pending)` ) ); Log.info( `ping`, chalk.yellow( `[response]` ), chalk.white( `⚠️` ), chalk.yellowBright( `<msg>` ), chalk.gray( `Try: Failed via HTTPS; trying HTTP protocol` ), chalk.yellowBright( `<service>` ), chalk.gray( `${ service }` ), chalk.yellowBright( `<uriAttempt1>` ), chalk.gray( `${ uri }` ), chalk.redBright( `(failed)` ), chalk.yellowBright( `<uriAttempt2>` ), chalk.gray( `${ uriRetry }` ), chalk.blueBright( `(pending)` ) );
try try
{ {
const resp = await fetch( uriRetry ); const resp = await fetch( uriRetry );
/* try 2 > http > domain down */ /* try 2 https domain down */
if ( resp.status !== 200 ) if ( resp.status !== 200 )
{ {
Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Service Offline; failed to communicate with service, possibly down` ), chalk.redBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uriRetry }` ) ); Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Try: Domain Offline; failed to communicate with domain, possibly down` ), chalk.redBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uriRetry }` ) );
return; return false;
} }
/* try 2 > http > domain up */ /* try 2 https domain up */
Log.ok( `ping`, chalk.yellow( `[response]` ), chalk.white( `` ), chalk.greenBright( `<msg>` ), chalk.gray( `Service Online` ), chalk.greenBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.greenBright( `<service>` ), chalk.gray( `${ service }` ), chalk.greenBright( `<address>` ), chalk.gray( `${ uriRetry }` ) ); Log.ok( `ping`, chalk.yellow( `[response]` ), chalk.white( `` ), chalk.greenBright( `<msg>` ), chalk.gray( `Domain Online` ), chalk.greenBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.greenBright( `<service>` ), chalk.gray( `${ service }` ), chalk.greenBright( `<address>` ), chalk.gray( `${ uriRetry }` ) );
return true;
} }
catch ( err ) catch ( err )
{ {
/* try 2 > http > domain not exist */ /* try 2 https domain not exist */
Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Service Offline; failed to communicate with service, address does not exist` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uri }` ), chalk.redBright( `<message>` ), chalk.gray( `${ err }` ) ); Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Try: Domain Offline; failed to communicate with domain, address does not exist` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uri }` ), chalk.redBright( `<message>` ), chalk.gray( `${ err }` ) );
return false;
} }
} }
/* /*
try 2 > https try 2 http
*/ */
else if ( /^http:\/\//i.test( uri ) ) else if ( /^http:\/\//i.test( uri ) )
{ {
const uriRetry = uri.replace( /^http:\/\//ig, 'https://' ); const uriRetry = uri.replace( /^http:\/\//ig, 'https://' );
Log.info( `ping`, chalk.yellow( `[response]` ), chalk.white( `⚠️` ), chalk.yellowBright( `<msg>` ), chalk.gray( `Service Offline; failed to communicate with service via SSL; trying https protocol` ), chalk.yellowBright( `<service>` ), chalk.gray( `${ service }` ), chalk.yellowBright( `<uriAttempt1>` ), chalk.gray( `${ uri }` ), chalk.redBright( `(failed)` ), chalk.yellowBright( `<uriAttempt2>` ), chalk.gray( `${ uriRetry }` ), chalk.blueBright( `(pending)` ) ); Log.info( `ping`, chalk.yellow( `[response]` ), chalk.white( `⚠️` ), chalk.yellowBright( `<msg>` ), chalk.gray( `Try: Failed via HTTP; trying HTTPS protocol` ), chalk.yellowBright( `<service>` ), chalk.gray( `${ service }` ), chalk.yellowBright( `<uriAttempt1>` ), chalk.gray( `${ uri }` ), chalk.redBright( `(failed)` ), chalk.yellowBright( `<uriAttempt2>` ), chalk.gray( `${ uriRetry }` ), chalk.blueBright( `(pending)` ) );
try try
{ {
const resp = await fetch( uriRetry ); const resp = await fetch( uriRetry );
/* try 2 > https > domain down */ /* try 2 http domain down */
if ( resp.status !== 200 ) if ( resp.status !== 200 )
{ {
Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Service Offline; failed to communicate with service, possibly down` ), chalk.redBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uriRetry }` ) ); Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Domain Offline; failed to communicate with domain, possibly down` ), chalk.redBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uriRetry }` ) );
return; return false;
} }
/* try 2 > https > domain up */ /* try 2 http domain up */
Log.ok( `ping`, chalk.yellow( `[response]` ), chalk.white( `` ), chalk.greenBright( `<msg>` ), chalk.gray( `Service Online` ), chalk.greenBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.greenBright( `<service>` ), chalk.gray( `${ service }` ), chalk.greenBright( `<address>` ), chalk.gray( `${ uriRetry }` ) ); Log.ok( `ping`, chalk.yellow( `[response]` ), chalk.white( `` ), chalk.greenBright( `<msg>` ), chalk.gray( `Domain Online` ), chalk.greenBright( `<code>` ), chalk.gray( `${ resp.status }` ), chalk.greenBright( `<service>` ), chalk.gray( `${ service }` ), chalk.greenBright( `<address>` ), chalk.gray( `${ uriRetry }` ) );
return true;
} }
catch ( err ) catch ( err )
{ {
/* try 2 > https > domain not exist */ /* try 2 http domain not exist */
Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Service Offline; failed to communicate with service, address does not exist` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uri }` ), chalk.redBright( `<message>` ), chalk.gray( `${ err }` ) ); Log.error( `ping`, chalk.redBright( `[response]` ), chalk.white( `` ), chalk.redBright( `<msg>` ), chalk.gray( `Domain Offline; failed to communicate with domain, address does not exist` ), chalk.redBright( `<service>` ), chalk.gray( `${ service }` ), chalk.redBright( `<address>` ), chalk.gray( `${ uri }` ), chalk.redBright( `<message>` ), chalk.gray( `${ err }` ) );
return false;
} }
} }
} }
} }
/* /*
Func > Download File Func Download File
@arg str url https://git.binaryninja.net/binaryninja/tvapp2-externals/raw/branch/main/urls.txt @arg str url https://git.binaryninja.net/binaryninja/tvapp2-externals/raw/branch/main/urls.txt
@arg str filePath H:\Repos\github\BinaryNinja\tvapp2\tvapp2\urls.txt @arg str filePath H:\Repos\github\BinaryNinja\tvapp2\tvapp2\urls.txt
@@ -2130,7 +2140,7 @@ const server = http.createServer( ( req, resp ) =>
if ( str2bool( paramSilent ) !== true ) if ( str2bool( paramSilent ) !== true )
{ {
Log.debug( `http`, chalk.yellow( `[requests]` ), chalk.white( `⚙️` ), Log.debug( `http`, chalk.yellow( `[requests]` ), chalk.white( `⚙️` ),
chalk.blueBright( `<msg>` ), chalk.gray( `Request started` ), chalk.blueBright( `<msg>` ), chalk.gray( `New request` ),
chalk.blueBright( `<client>` ), chalk.gray( `${ clientIp( req ) }` ), chalk.blueBright( `<client>` ), chalk.gray( `${ clientIp( req ) }` ),
chalk.blueBright( `<request.url>` ), chalk.gray( `${ req.url }` ), chalk.blueBright( `<request.url>` ), chalk.gray( `${ req.url }` ),
chalk.blueBright( `<reqUrl>` ), chalk.gray( `${ reqUrl }` ), chalk.blueBright( `<reqUrl>` ), chalk.gray( `${ reqUrl }` ),
@@ -2544,11 +2554,7 @@ const server = http.createServer( ( req, resp ) =>
check service status that we depend on check service status that we depend on
*/ */
serviceCheck( 'TVPass.org', 'https://tvpass.org' ); hosts.forEach( ( host ) => hostCheck( host.name, host.url ) );
serviceCheck( 'TheTVApp.to', 'https://thetvapp.to' );
serviceCheck( 'MoveOnJoy.com', 'http://moveonjoy.com' );
serviceCheck( 'Daddylive.dad', 'https://daddylive.dad' );
serviceCheck( 'Newkso.ru', 'https://zekonew.newkso.ru/zeko' );
/* /*
start web server start web server