Initial commit to set up repo and add the script
This commit is contained in:
Родитель
66006b3b3b
Коммит
bc096e6cca
|
@ -0,0 +1,32 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
"eslint:recommended",
|
||||
"plugin:node/recommended",
|
||||
],
|
||||
plugins: [
|
||||
"node",
|
||||
],
|
||||
root: true,
|
||||
rules: {
|
||||
"comma-dangle": ["error", {arrays: "always-multiline", objects: "always-multiline"}],
|
||||
"eol-last": ["error", "always"],
|
||||
"eqeqeq": "error",
|
||||
"no-console": "off",
|
||||
"no-process-exit": "off",
|
||||
"no-process-env": "off",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-unused-vars": ["error", {vars: "all", args: "none", ignoreRestSiblings: false}],
|
||||
"no-var": "error",
|
||||
"no-warning-comments": "warn",
|
||||
"prefer-const": "error",
|
||||
"quotes": ["error", "double"],
|
||||
"require-jsdoc": "off",
|
||||
"semi": ["error", "always"],
|
||||
"strict": ["error", "safe"],
|
||||
"valid-jsdoc": "warn",
|
||||
}
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "fxmonitor-remotesettings-updater",
|
||||
"description": "Firefox Monitor Remote Settings Updater",
|
||||
"version": "1.0.0",
|
||||
"author": "Mozilla",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mozilla/fxmonitor-remotesettings-updater/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"got": "^8.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.18.1",
|
||||
"eslint-plugin-node": "^6.0.1",
|
||||
"npm-run-all": "^4.1.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.11.1"
|
||||
},
|
||||
"homepage": "https://github.com/mozilla/fxmonitor-remotesettings-updater",
|
||||
"keywords": [
|
||||
"firefox",
|
||||
"monitor",
|
||||
"mozilla"
|
||||
],
|
||||
"license": "MPL-2.0",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mozilla/fxmonitor-remotesettings-updater.git"
|
||||
},
|
||||
"scripts": {
|
||||
"eslint": "eslint . --ext jsm,js,json",
|
||||
"lint": "npm-run-all lint:*",
|
||||
"lint:eslint": "npm run eslint",
|
||||
"run": "node updatebreaches.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
"use strict";
|
||||
|
||||
const DEBUG = !process.env.PUSH_TO_KINTO;
|
||||
|
||||
const got = require("got");
|
||||
|
||||
const KINTO_UPDATE_ENDPOINT = "https://settings-writer.prod.mozaws.net/v1/buckets/main-workspace/collections/fxmonitor-breaches/records";
|
||||
const PROD_RECORDS_ENDPOINT = "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/fxmonitor-breaches/records";
|
||||
|
||||
const USERNAME = process.env.KINTO_USERNAME;
|
||||
const PASSWORD = process.env.KINTO_PASSWORD;
|
||||
|
||||
if (!DEBUG && (!USERNAME || !PASSWORD)) {
|
||||
console.error("Please set credentials in the environment.");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const AUTH = Buffer.from(`${USERNAME}:${PASSWORD}`).toString("base64");
|
||||
|
||||
async function run() {
|
||||
const RemoteSettingsBreachesSet = new Set((await got(
|
||||
PROD_RECORDS_ENDPOINT,
|
||||
{ json: true }
|
||||
)).body.data.map(b => b.Name));
|
||||
|
||||
const hibp_breaches = (await got(
|
||||
"https://haveibeenpwned.com/api/v2/breaches",
|
||||
{ json: true }
|
||||
)).body;
|
||||
|
||||
const new_breaches = [];
|
||||
|
||||
for (const breach of hibp_breaches) {
|
||||
if (breach.IsSpamList || breach.IsRetired || !breach.IsVerified || !breach.Domain) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RemoteSettingsBreachesSet.has(breach.Name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
new_breaches.push(breach);
|
||||
}
|
||||
|
||||
console.log(`${new_breaches.length} new breach(es) found.`);
|
||||
|
||||
for (const breach of new_breaches) {
|
||||
const data = {
|
||||
Name: breach.Name,
|
||||
Domain: breach.Domain,
|
||||
BreachDate: breach.BreachDate,
|
||||
PwnCount: breach.PwnCount,
|
||||
AddedDate: breach.AddedDate,
|
||||
};
|
||||
|
||||
if (DEBUG) {
|
||||
console.log(data);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await got.post(KINTO_UPDATE_ENDPOINT, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"authorization": `Basic ${AUTH}`,
|
||||
},
|
||||
body: JSON.stringify({data: data}),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
Загрузка…
Ссылка в новой задаче