mirror of
https://github.com/tiennm99/is-a-good-dev.git
synced 2026-08-05 18:24:29 +00:00
Merge pull request #240 from is-a-good-dev/WilliamDavidHarrison/checks
add invalid domain check + cleanup
This commit is contained in:
+17
-14
@@ -3,25 +3,28 @@ const getJSON = require('../utils/getJSON.js');
|
||||
const data = getJSON(process.env.FILES);
|
||||
|
||||
async function addRecord(type, name, value) {
|
||||
|
||||
const response = await fetch(`https://api.is-a-good.dev/api/is-a-good-dev/zones/add?apiKey=${process.env.API_KEY}&type=${type}&name=${name}&content=${value}`);
|
||||
const data = await response.json();
|
||||
return data
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
if (!data) return
|
||||
const records = Object.keys(data.target)
|
||||
for (const i in records) {
|
||||
recordType = records[i]
|
||||
name = data.target[recordType].name;
|
||||
value = data.target[recordType].value;
|
||||
const result = await addRecord(recordType, name, value);
|
||||
console.log(result);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error adding records")
|
||||
console.log(e)
|
||||
if (!data) return;
|
||||
|
||||
const records = Object.keys(data.target);
|
||||
|
||||
for (const i in records) {
|
||||
recordType = records[i];
|
||||
name = data.target[recordType].name;
|
||||
value = data.target[recordType].value;
|
||||
|
||||
const res = await addRecord(recordType, name, value);
|
||||
console.log(res);
|
||||
}
|
||||
} catch(e) {
|
||||
console.log('Failed to add records.');
|
||||
console.log(e);
|
||||
}
|
||||
})();
|
||||
|
||||
+9
-3
@@ -2,15 +2,21 @@ const fetch = require('node-fetch');
|
||||
const core = require('@actions/core');
|
||||
|
||||
async function checkEmail(email) {
|
||||
console.log(`Checking: ${email}`)
|
||||
console.log(`Checking: ${email}`);
|
||||
|
||||
const url = `https://api.is-a-good.dev/email-check?key=6lPyUV2dX8&email=${encodeURIComponent(email)}`;
|
||||
|
||||
const options = {
|
||||
method: 'GET'
|
||||
};
|
||||
}
|
||||
|
||||
const res = await fetch(url, options).then(res => res.json());
|
||||
console.log(res);
|
||||
|
||||
core.setOutput('infoReason', res.reason);
|
||||
if (res.data.valid == true) return true;
|
||||
|
||||
if (res.data.valid) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -1,12 +1,17 @@
|
||||
const { checkIfValidIP, checkIfValidFQDN } = require('./utils.js');
|
||||
|
||||
function checkRecords(data) {
|
||||
const recordType = Object.keys(data.target)[0]
|
||||
if (recordType.toLowerCase() === "a") {
|
||||
return checkIfValidIP(data.target[recordType].value)
|
||||
const recordType = Object.keys(data.target)[0];
|
||||
|
||||
if (recordType.toLowerCase() === 'a') {
|
||||
return checkIfValidIP(data.target[recordType].value);
|
||||
}
|
||||
if (recordType.toLowerCase() === "cname") {
|
||||
return checkIfValidFQDN(data.target[recordType].value)
|
||||
|
||||
if (recordType.toLowerCase() === 'cname') {
|
||||
return checkIfValidFQDN(data.target[recordType].value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = checkRecords;
|
||||
|
||||
+26
-14
@@ -1,23 +1,35 @@
|
||||
const fs = require('fs');
|
||||
const invalidDomains = require('./invalid-domains.json');
|
||||
|
||||
function getFileExtension(filename) {
|
||||
return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename) : undefined;
|
||||
}
|
||||
function getJSON(file) {
|
||||
const path = `${process.env.actions_path}/${file}`; //json file path.
|
||||
const ext = getFileExtension(file)
|
||||
if (!ext) return false; //if no file extension, return.
|
||||
if (ext != "json") return false; //if file extension is not ".json" return.
|
||||
|
||||
function getJSON(file, filename) {
|
||||
const path = `${process.env.actions_path}/${file}`; // File path.
|
||||
const ext = getFileExtension(file);
|
||||
|
||||
if (!ext) return false; // If no file extension, return.
|
||||
if (ext != 'json') return false; // If file extension is not '.json' return.
|
||||
|
||||
invalidDomains.forEach(domain => {
|
||||
if (filename === domain) return false;
|
||||
})
|
||||
|
||||
try {
|
||||
if (fs.existsSync(path)) { //check if file exists in domain directory
|
||||
//it exists
|
||||
const rawdata = fs.readFileSync(path); //read the file
|
||||
const data = JSON.parse(rawdata); //parse it
|
||||
return data; //return true or false, depending if tests pass or fail.
|
||||
};
|
||||
return false; //it doesn't exist
|
||||
if (fs.existsSync(path)) { // Check if file exists in domain directory
|
||||
// It exists
|
||||
const rawdata = fs.readFileSync(path); // Read the file
|
||||
const data = JSON.parse(rawdata); // Parse it
|
||||
return data; // Return true or false, depending if tests pass or fail.
|
||||
}
|
||||
|
||||
return false; // It doesn't exist
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = getJSON;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
[
|
||||
"_acme-challenge",
|
||||
"_github-challenge-is-a-good-dev",
|
||||
"_github-pages-challenge-is-a-good-dev",
|
||||
"help",
|
||||
"no-reply",
|
||||
"noreply",
|
||||
"notification",
|
||||
"notifications",
|
||||
"support",
|
||||
"ww",
|
||||
"ww1",
|
||||
"ww2",
|
||||
"ww3",
|
||||
"ww4",
|
||||
"wwww",
|
||||
"your-domain-name"
|
||||
]
|
||||
+6
-7
@@ -1,14 +1,13 @@
|
||||
module.exports.checkIfValidIP = function(str) {
|
||||
// Regular expression to check if string is a IP address
|
||||
const regexExp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi
|
||||
// Check if the IP address is valid
|
||||
const regexExp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi;
|
||||
|
||||
return regexExp.test(str);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.checkIfValidFQDN = function(str) {
|
||||
// Regular expression to check if string is a FQDN
|
||||
const regexExp = /(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/gi
|
||||
// Check if the FQDN is valid
|
||||
const regexExp = /(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/gi;
|
||||
|
||||
return regexExp.test(str);
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user