Added dynamically generated sitemap and robots.txt file to prevent crawling of inline version

This commit is contained in:
n1474335 2018-02-20 16:52:27 +00:00
parent cc44fe6557
commit 502a9fbb92
7 changed files with 77 additions and 19 deletions

View File

@ -11,6 +11,7 @@ script:
- grunt node - grunt node
- grunt prod --msg="$COMPILE_MSG" - grunt prod --msg="$COMPILE_MSG"
before_deploy: before_deploy:
- grunt exec:sitemap
- grunt copy:ghPages - grunt copy:ghPages
deploy: deploy:
- provider: pages - provider: pages

View File

@ -218,7 +218,8 @@ module.exports = function (grunt) {
web: { web: {
target: "web", target: "web",
entry: Object.assign({ entry: Object.assign({
main: "./src/web/index.js" main: "./src/web/index.js",
sitemap: "./src/web/static/sitemap.js"
}, moduleEntryPoints), }, moduleEntryPoints),
output: { output: {
path: __dirname + "/build/prod" path: __dirname + "/build/prod"
@ -377,6 +378,10 @@ module.exports = function (grunt) {
expand: true, expand: true,
src: "docs/**", src: "docs/**",
dest: "build/prod/" dest: "build/prod/"
},
{
src: "src/web/static/robots.txt",
dest: "build/prod/"
} }
] ]
} }
@ -406,6 +411,9 @@ module.exports = function (grunt) {
cleanGit: { cleanGit: {
command: "git gc --prune=now --aggressive" command: "git gc --prune=now --aggressive"
}, },
sitemap: {
command: "node build/prod/sitemap.js > build/prod/sitemap.xml"
}
}, },
execute: { execute: {
test: "build/test/index.js" test: "build/test/index.js"

16
package-lock.json generated
View File

@ -9566,6 +9566,16 @@
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true "dev": true
}, },
"sitemap": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/sitemap/-/sitemap-1.13.0.tgz",
"integrity": "sha1-Vpy+IYAgKSamKiZs094Jyc60P4M=",
"dev": true,
"requires": {
"underscore": "1.7.0",
"url-join": "1.1.0"
}
},
"sladex-blowfish": { "sladex-blowfish": {
"version": "0.8.1", "version": "0.8.1",
"resolved": "https://registry.npmjs.org/sladex-blowfish/-/sladex-blowfish-0.8.1.tgz", "resolved": "https://registry.npmjs.org/sladex-blowfish/-/sladex-blowfish-0.8.1.tgz",
@ -10726,6 +10736,12 @@
} }
} }
}, },
"url-join": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-1.1.0.tgz",
"integrity": "sha1-dBxsL0WWxIMNZxhGCSDQySIC3Hg=",
"dev": true
},
"url-loader": { "url-loader": {
"version": "0.6.2", "version": "0.6.2",
"resolved": "https://registry.npmjs.org/url-loader/-/url-loader-0.6.2.tgz", "resolved": "https://registry.npmjs.org/url-loader/-/url-loader-0.6.2.tgz",

View File

@ -58,6 +58,7 @@
"postcss-css-variables": "^0.8.0", "postcss-css-variables": "^0.8.0",
"postcss-import": "^11.0.0", "postcss-import": "^11.0.0",
"postcss-loader": "^2.0.10", "postcss-loader": "^2.0.10",
"sitemap": "^1.13.0",
"style-loader": "^0.19.1", "style-loader": "^0.19.1",
"url-loader": "^0.6.2", "url-loader": "^0.6.2",
"val-loader": "^1.1.0", "val-loader": "^1.1.0",

View File

@ -377,6 +377,7 @@ App.prototype.loadURIParams = function() {
window.location.href.split("#")[1] || window.location.href.split("#")[1] ||
window.location.hash; window.location.hash;
this.uriParams = Utils.parseURIParams(params); this.uriParams = Utils.parseURIParams(params);
this.autoBakePause = true;
// Read in recipe from URI params // Read in recipe from URI params
if (this.uriParams.recipe) { if (this.uriParams.recipe) {
@ -387,35 +388,29 @@ App.prototype.loadURIParams = function() {
} else if (this.uriParams.op) { } else if (this.uriParams.op) {
// If there's no recipe, look for single operations // If there's no recipe, look for single operations
this.manager.recipe.clearRecipe(); this.manager.recipe.clearRecipe();
try {
this.manager.recipe.addOperation(this.uriParams.op);
} catch (err) {
// If no exact match, search for nearest match and add that
const matchedOps = this.manager.ops.filterOperations(this.uriParams.op, false);
if (matchedOps.length) {
this.manager.recipe.addOperation(matchedOps[0].name);
}
// Populate search with the string // Search for nearest match and add it
const search = document.getElementById("search"); const matchedOps = this.manager.ops.filterOperations(this.uriParams.op, false);
if (matchedOps.length) {
search.value = this.uriParams.op; this.manager.recipe.addOperation(matchedOps[0].name);
search.dispatchEvent(new Event("search"));
} }
// Populate search with the string
const search = document.getElementById("search");
search.value = this.uriParams.op;
search.dispatchEvent(new Event("search"));
} }
// Read in input data from URI params // Read in input data from URI params
if (this.uriParams.input) { if (this.uriParams.input) {
this.autoBakePause = true;
try { try {
const inputData = Utils.fromBase64(this.uriParams.input); const inputData = Utils.fromBase64(this.uriParams.input);
this.setInput(inputData); this.setInput(inputData);
} catch (err) { } catch (err) {}
} finally {
this.autoBakePause = false;
}
} }
this.autoBakePause = false;
this.autoBake(); this.autoBake();
}; };

View File

@ -0,0 +1,4 @@
user-agent: *
disallow: /cyberchef.htm
sitemap: https://gchq.github.io/CyberChef/sitemap.xml

33
src/web/static/sitemap.js Normal file
View File

@ -0,0 +1,33 @@
import sm from "sitemap";
import OperationConfig from "../../core/config/MetaConfig.js";
/**
* Generates an XML sitemap for all CyberChef operations and a number of recipes.
*
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
const sitemap = sm.createSitemap({
hostname: "https://gchq.github.io/CyberChef",
});
sitemap.add({
url: "/",
changefreq: "weekly",
priority: 1.0
});
for (let op in OperationConfig) {
sitemap.add({
url: `/op=${encodeURIComponent(op)}`,
changeFreq: "yearly",
priority: 0.5
});
}
const xml = sitemap.toString();
console.log(xml); // eslint-disable-line no-console