Skip to content

Commit

Permalink
Merge pull request #87 from CryptoScamDB/en-endpoint_adds
Browse files Browse the repository at this point in the history
Endpoint fixes
  • Loading branch information
409H authored Jul 7, 2019
2 parents 17d63c2 + 2807628 commit d6fd7ed
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
- Start development web app with: `npm run start:dev` (recommended)
- Start production web app with: `npm run start:prod` (warning: please use a dev instance on first run, for configuration purposes)
- Navigate to http://localhost:5111 in your browser, and you should be shown a fresh instance of CryptoScamDB :sparkles:

**Remember to clean your cache (located in `data/`) when you go to a new branch!**
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"request": "2.88.0",
"sqlite3": "^4.0.4",
"typescript": "3.1.6",
"uuid": "^3.3.2",
"web3": "1.0.0-beta.36",
"web3-utils": "^1.0.0-beta.55"
},
Expand Down
20 changes: 20 additions & 0 deletions src/routes/v1/domain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as db from '../../utils/db';
import { Request, Response } from 'express';
import generateAbuseReport from '../../utils/abusereport';
import Scam from '../../classes/scam.class';
import { getGoogleSafeBrowsing, getURLScan, getVirusTotal } from '../../utils/lookup';
import config from '../../utils/config';

export default async (req: Request, res: Response) => {
const entry: any = await db.all(
Expand Down Expand Up @@ -30,6 +34,22 @@ export default async (req: Request, res: Response) => {
entry[0].addresses = addressesByCoin;
}

const objScam = new Scam(entry[0]);
entry[0].abusereport = generateAbuseReport(objScam);

entry[0].lookups = {};
if (config.apiKeys.Google_SafeBrowsing) {
entry[0].lookups.Google_SafeBrowsing = await getGoogleSafeBrowsing(entry[0].url);
} else {
entry[0].lookups.Google_SafeBrowsing = '';
}
if (config.apiKeys.VirusTotal) {
entry[0].lookups.VirusTotal = await getVirusTotal(entry[0].url);
} else {
entry[0].lookups.VirusTotal = '';
}
entry[0].lookups.URLScan = await getURLScan(entry[0].hostname);

res.json({ success: true, result: entry });
}
};
2 changes: 1 addition & 1 deletion src/routes/v1/featured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default async (req: Request, res: Response) => {
res.json({
success: true,
result: await db.all(
"SELECT id,name,description FROM entries WHERE type='verified' AND featured=1"
"SELECT id,name,description,url FROM entries WHERE type='verified' AND featured=1"
)
});
};
9 changes: 7 additions & 2 deletions src/routes/v1/postReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ import config from '../../utils/config';
import * as captcha from '../../utils/gcaptcha';
import * as slack from '../../utils/slack';
import { Request, Response } from 'express';
const uuidv1 = require('uuid/v1');

export default async (req: Request, res: Response) => {
const strReportId = uuidv1();
if (
config.apiKeys.Google_Captcha &&
config.apiKeys.Slack_Webhook &&
req.body &&
req.body.args &&
req.body.args.captcha
) {
req.body.args.report_id = strReportId;
const isValidCaptcha = await captcha.verifyResponse(req.body.args.captcha);
if (isValidCaptcha) {
slack.sendReport(req.body);
res.json({
success: true
success: true,
report_id: strReportId
});
} else {
res.json({
Expand All @@ -26,7 +30,8 @@ export default async (req: Request, res: Response) => {
} else if (config.apiKeys.Slack_Webhook && req.body && req.body.args && req.body.args.captcha) {
slack.sendReport(req.body);
res.json({
success: true
success: true,
report_id: strReportId
});
} else {
res.json({
Expand Down
13 changes: 8 additions & 5 deletions src/routes/v1/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ export default async (req: Request, res: Response) => {
featured: featured.count,
addresses: addresses.count,
ips: ips.count,
actives: statuses.find(en => en.status === 'Active').count,
actives: statuses.length > 0 ? statuses.find(en => en.status === 'Active').count : -1,
inactives:
statuses.find(en => en.status === 'Inactive').count +
statuses.find(en => en.status === 'Offline').count,
offline: statuses.find(en => en.status === 'Offline').count,
suspended: statuses.find(en => en.status === 'Suspended').count,
statuses.length > 0
? statuses.find(en => en.status === 'Inactive').count +
statuses.find(en => en.status === 'Offline').count
: -1,
offline: statuses.length > 0 ? statuses.find(en => en.status === 'Offline').count : -1,
suspended:
statuses.length > 0 ? statuses.find(en => en.status === 'Suspended').count : -1,
reporters: await db.all(
'SELECT reporter,count(reporter) as count FROM entries WHERE reporter IS NOT NULL GROUP BY reporter'
),
Expand Down
6 changes: 3 additions & 3 deletions src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const init = async (): Promise<void> => {

export const get = (query, data?) => {
return new Promise((resolve, reject) => {
debug('GET %s %o', query, data);
//debug('GET %s %o', query, data);
db.get(query, data, (error, row) => {
if (error) {
debug('ERROR %s %o', query, data);
Expand All @@ -57,7 +57,7 @@ export const get = (query, data?) => {

export const all = (query, data?) => {
return new Promise((resolve, reject) => {
debug('ALL %s %o', query, data);
//debug('ALL %s %o', query, data);
db.all(query, data, (error, rows) => {
if (error) {
debug('ERROR %s %o', query, data);
Expand All @@ -71,7 +71,7 @@ export const all = (query, data?) => {

export const run = (query, data?) => {
return new Promise((resolve, reject) => {
debug('RUN %s %o', query, data);
//debug('RUN %s %o', query, data);
db.run(query, data, function(error) {
if (error) {
debug('ERROR %s %o', query, data);
Expand Down

0 comments on commit d6fd7ed

Please sign in to comment.