mirror of
https://github.com/pezkuwichain/phishing.git
synced 2026-06-26 06:21:01 +00:00
Cleanups
This commit is contained in:
@@ -7,17 +7,7 @@ import { fetch } from '@polkadot/x-fetch';
|
||||
|
||||
import { retrieveAddrList } from '.';
|
||||
|
||||
function logMissing (values: Record<string, string[]>): void {
|
||||
const sites = Object.keys(values);
|
||||
|
||||
sites.length && process.env.CI_LOG && fs.appendFileSync('./.github/addrcheck.md', `
|
||||
|
||||
${sites.length} urls with missing entries found at ${new Date().toUTCString()}:
|
||||
|
||||
${JSON.stringify(values, null, 2)}
|
||||
`);
|
||||
}
|
||||
|
||||
// a timeout with a 2s timeout
|
||||
async function fetchWithTimeout (url: string, timeout = 2000): Promise<Response> {
|
||||
const controller = new AbortController();
|
||||
const id = setTimeout(() => controller.abort(), timeout);
|
||||
@@ -28,7 +18,8 @@ async function fetchWithTimeout (url: string, timeout = 2000): Promise<Response>
|
||||
return response;
|
||||
}
|
||||
|
||||
async function loopSome (ours: Record<string, string[]>, site: string, matcher: () => Promise<string[] | null>): Promise<[string, string[]]> {
|
||||
// loop through each site for a number of times, applying the transform
|
||||
async function loopSome (site: string, matcher: () => Promise<string[] | null>): Promise<[string, string[]]> {
|
||||
const found: string[] = [];
|
||||
|
||||
for (let i = 0; i < 20; i++) {
|
||||
@@ -51,8 +42,8 @@ async function loopSome (ours: Record<string, string[]>, site: string, matcher:
|
||||
}
|
||||
|
||||
// shared between polkadot.center & polkadot-event.com (addresses are also the same on first run)
|
||||
function checkGetWallet (ours: Record<string, string[]>, site: string): Promise<[string, string[]]> {
|
||||
return loopSome(ours, site, async (): Promise<string[] | null> => {
|
||||
function checkGetWallet (site: string): Promise<[string, string[]]> {
|
||||
return loopSome(site, async (): Promise<string[] | null> => {
|
||||
const result = await (await fetchWithTimeout(`https://${site}/get_wallet.php`)).json() as Record<string, string>;
|
||||
|
||||
return (result && result.wallet)
|
||||
@@ -62,10 +53,10 @@ function checkGetWallet (ours: Record<string, string[]>, site: string): Promise<
|
||||
}
|
||||
|
||||
// check a specific tag with attributes
|
||||
function checkTag (ours: Record<string, string[]>, url: string, tag: string, attr?: string): Promise<[string, string[]]> {
|
||||
function checkTag (url: string, tag: string, attr?: string): Promise<[string, string[]]> {
|
||||
const site = url.split('/')[2];
|
||||
|
||||
return loopSome(ours, site, async (): Promise<string[] | null> => {
|
||||
return loopSome(site, async (): Promise<string[] | null> => {
|
||||
const result = await (await fetchWithTimeout(url)).text();
|
||||
|
||||
// /<p id="trnsctin">(.*?)<\/p>/g
|
||||
@@ -91,15 +82,15 @@ describe('addrcheck', (): void => {
|
||||
return all;
|
||||
}, []);
|
||||
const results = await Promise.all([
|
||||
checkGetWallet(ours, 'polkadot.center'),
|
||||
checkGetWallet(ours, 'polkadot-event.com'),
|
||||
checkTag(ours, 'https://polkadotlive.network/block-assets/index.html', 'p', 'id="trnsctin"'),
|
||||
checkTag(ours, 'https://polkadots.network/block.html', 'p', 'id="trnsctin"'),
|
||||
checkTag(ours, 'https://claimpolka.live/claim/index.html', 'span', 'class="real-address"'),
|
||||
checkTag(ours, 'https://polkadot-airdrop.org/block/index.html', 'span', 'class="real-address"'),
|
||||
checkTag(ours, 'https://polkadotairdrop.com/address/', 'cool'),
|
||||
checkTag(ours, 'https://polkadot-get.com/', 'span', 'id="cosh"'),
|
||||
checkTag(ours, 'https://dot4.org/promo/', 'p', 'class="payment-title"')
|
||||
checkGetWallet('polkadot.center'),
|
||||
checkGetWallet('polkadot-event.com'),
|
||||
checkTag('https://polkadotlive.network/block-assets/index.html', 'p', 'id="trnsctin"'),
|
||||
checkTag('https://polkadots.network/block.html', 'p', 'id="trnsctin"'),
|
||||
checkTag('https://claimpolka.live/claim/index.html', 'span', 'class="real-address"'),
|
||||
checkTag('https://polkadot-airdrop.org/block/index.html', 'span', 'class="real-address"'),
|
||||
checkTag('https://polkadotairdrop.com/address/', 'cool'),
|
||||
checkTag('https://polkadot-get.com/', 'span', 'id="cosh"'),
|
||||
checkTag('https://dot4.org/promo/', 'p', 'class="payment-title"')
|
||||
]);
|
||||
const mapFound = results.reduce((all, [site, found]) => ({ ...all, [site]: found }), {});
|
||||
const mapMiss = results
|
||||
@@ -111,7 +102,7 @@ describe('addrcheck', (): void => {
|
||||
console.log('All available\n', JSON.stringify(mapFound, null, 2));
|
||||
console.log('All missing\n', JSON.stringify(mapMiss, null, 2));
|
||||
|
||||
logMissing(mapMiss);
|
||||
sites.length && process.env.CI_LOG && fs.appendFileSync('./.github/addrcheck.md', `\n\n${sites.length} urls with missing entries found at ${new Date().toUTCString()}:\n\n${JSON.stringify(mapMiss, null, 2)}\n`);
|
||||
|
||||
expect(sites).toEqual([]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user