Fixed 'Parse URI' operation and improved error handling from worker

This commit is contained in:
n1474335 2017-10-13 11:29:22 +00:00
parent ec7294d734
commit 599fefb39b
9 changed files with 61 additions and 56 deletions

View File

@ -68,9 +68,10 @@ Chef.prototype.bake = async function(inputText, recipeConfig, options, progress,
try { try {
progress = await recipe.execute(this.dish, progress); progress = await recipe.execute(this.dish, progress);
} catch (err) { } catch (err) {
// Return the error in the result so that everything else gets correctly updated console.log(err);
// rather than throwing it here and losing state info. error = {
error = err; displayStr: err.displayStr,
};
progress = err.progress; progress = err.progress;
} }

View File

@ -760,14 +760,14 @@ const OperationConfig = {
] ]
}, },
"URL Decode": { "URL Decode": {
module: "Default", module: "URL",
description: "Converts URI/URL percent-encoded characters back to their raw values.<br><br>e.g. <code>%3d</code> becomes <code>=</code>", description: "Converts URI/URL percent-encoded characters back to their raw values.<br><br>e.g. <code>%3d</code> becomes <code>=</code>",
inputType: "string", inputType: "string",
outputType: "string", outputType: "string",
args: [] args: []
}, },
"URL Encode": { "URL Encode": {
module: "Default", module: "URL",
description: "Encodes problematic characters into percent-encoding, a format supported by URIs/URLs.<br><br>e.g. <code>=</code> becomes <code>%3d</code>", description: "Encodes problematic characters into percent-encoding, a format supported by URIs/URLs.<br><br>e.g. <code>=</code> becomes <code>%3d</code>",
inputType: "string", inputType: "string",
outputType: "string", outputType: "string",
@ -780,7 +780,7 @@ const OperationConfig = {
] ]
}, },
"Parse URI": { "Parse URI": {
module: "Default", module: "URL",
description: "Pretty prints complicated Uniform Resource Identifier (URI) strings for ease of reading. Particularly useful for Uniform Resource Locators (URLs) with a lot of arguments.", description: "Pretty prints complicated Uniform Resource Identifier (URI) strings for ease of reading. Particularly useful for Uniform Resource Locators (URLs) with a lot of arguments.",
inputType: "string", inputType: "string",
outputType: "string", outputType: "string",

View File

@ -26,7 +26,6 @@ import SeqUtils from "../../operations/SeqUtils.js";
import StrUtils from "../../operations/StrUtils.js"; import StrUtils from "../../operations/StrUtils.js";
import Tidy from "../../operations/Tidy.js"; import Tidy from "../../operations/Tidy.js";
import Unicode from "../../operations/Unicode.js"; import Unicode from "../../operations/Unicode.js";
import URL_ from "../../operations/URL.js";
import UUID from "../../operations/UUID.js"; import UUID from "../../operations/UUID.js";
@ -77,9 +76,6 @@ OpModules.Default = {
"From HTML Entity": HTML.runFromEntity, "From HTML Entity": HTML.runFromEntity,
"Strip HTML tags": HTML.runStripTags, "Strip HTML tags": HTML.runStripTags,
"Parse colour code": HTML.runParseColourCode, "Parse colour code": HTML.runParseColourCode,
"URL Encode": URL_.runTo,
"URL Decode": URL_.runFrom,
"Parse URI": URL_.runParse,
"Unescape Unicode Characters": Unicode.runUnescape, "Unescape Unicode Characters": Unicode.runUnescape,
"To Quoted Printable": QuotedPrintable.runTo, "To Quoted Printable": QuotedPrintable.runTo,
"From Quoted Printable": QuotedPrintable.runFrom, "From Quoted Printable": QuotedPrintable.runFrom,

View File

@ -19,6 +19,7 @@ import ImageModule from "./Image.js";
import JSBNModule from "./JSBN.js"; import JSBNModule from "./JSBN.js";
import PublicKeyModule from "./PublicKey.js"; import PublicKeyModule from "./PublicKey.js";
import ShellcodeModule from "./Shellcode.js"; import ShellcodeModule from "./Shellcode.js";
import URLModule from "./URL.js";
Object.assign( Object.assign(
OpModules, OpModules,
@ -33,7 +34,8 @@ Object.assign(
ImageModule, ImageModule,
JSBNModule, JSBNModule,
PublicKeyModule, PublicKeyModule,
ShellcodeModule ShellcodeModule,
URLModule
); );
export default OpModules; export default OpModules;

View File

@ -0,0 +1,23 @@
import URL_ from "../../operations/URL.js";
/**
* URL module.
*
* Libraries:
* - Utils.js
* - url
*
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
let OpModules = typeof self === "undefined" ? {} : self.OpModules || {};
OpModules.URL = {
"URL Encode": URL_.runTo,
"URL Decode": URL_.runFrom,
"Parse URI": URL_.runParse,
};
export default OpModules;

View File

@ -1,5 +1,6 @@
/* globals unescape */ /* globals unescape */
import Utils from "../Utils.js"; import Utils from "../Utils.js";
import url from "url";
/** /**
@ -58,56 +59,36 @@ const URL_ = {
* @returns {string} * @returns {string}
*/ */
runParse: function(input, args) { runParse: function(input, args) {
if (!document) { const uri = url.parse(input, true);
throw "This operation only works in a browser.";
}
const a = document.createElement("a"); let output = "";
// Overwrite base href which will be the current CyberChef URL to reduce confusion. if (uri.protocol) output += "Protocol:\t" + uri.protocol + "\n";
a.href = "http://example.com/"; if (uri.auth) output += "Auth:\t\t" + uri.auth + "\n";
a.href = input; if (uri.hostname) output += "Hostname:\t" + uri.hostname + "\n";
if (uri.port) output += "Port:\t\t" + uri.port + "\n";
if (uri.pathname) output += "Path name:\t" + uri.pathname + "\n";
if (uri.query) {
let keys = Object.keys(uri.query),
padding = 0;
if (a.protocol) { keys.forEach(k => {
let output = ""; padding = (k.length > padding) ? k.length : padding;
if (a.hostname !== window.location.hostname) { });
output = "Protocol:\t" + a.protocol + "\n";
if (a.hostname) output += "Hostname:\t" + a.hostname + "\n";
if (a.port) output += "Port:\t\t" + a.port + "\n";
}
if (a.pathname && a.pathname !== window.location.pathname) { output += "Arguments:\n";
let pathname = a.pathname; for (let key in uri.query) {
if (pathname.indexOf(window.location.pathname) === 0) output += "\t" + Utils.padRight(key, padding);
pathname = pathname.replace(window.location.pathname, ""); if (uri.query[key].length) {
if (pathname) output += " = " + uri.query[key] + "\n";
output += "Path name:\t" + pathname + "\n"; } else {
} output += "\n";
if (a.hash && a.hash !== window.location.hash) {
output += "Hash:\t\t" + a.hash + "\n";
}
if (a.search && a.search !== window.location.search) {
output += "Arguments:\n";
const args_ = (a.search.slice(1, a.search.length)).split("&");
let splitArgs = [], padding = 0, i;
for (i = 0; i < args_.length; i++) {
splitArgs.push(args_[i].split("="));
padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding;
}
for (i = 0; i < splitArgs.length; i++) {
output += "\t" + Utils.padRight(splitArgs[i][0], padding);
if (splitArgs[i].length > 1 && splitArgs[i][1].length)
output += " = " + splitArgs[i][1] + "\n";
else output += "\n";
} }
} }
return output;
} }
if (uri.hash) output += "Hash:\t\t" + uri.hash + "\n";
return "Invalid URI"; return output;
}, },

View File

@ -88,9 +88,10 @@ App.prototype.loaded = function() {
* An error handler for displaying the error to the user. * An error handler for displaying the error to the user.
* *
* @param {Error} err * @param {Error} err
* @param {boolean} [logToConsole=false]
*/ */
App.prototype.handleError = function(err) { App.prototype.handleError = function(err, logToConsole) {
console.error(err); if (logToConsole) console.error(err);
const msg = err.displayStr || err.toString(); const msg = err.displayStr || err.toString();
this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors); this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors);
}; };

View File

@ -382,7 +382,7 @@
<p>Released under the Apache Licence, Version 2.0.</p> <p>Released under the Apache Licence, Version 2.0.</p>
<p> <p>
<a href="https://gitter.im/gchq/CyberChef"> <a href="https://gitter.im/gchq/CyberChef">
<img src="https://badges.gitter.im/gchq/CyberChef.svg"> <img src="<%- require('../static/images/gitter-badge.svg') %>">
</a> </a>
</p> </p>
<br> <br>

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="92" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="92" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h34v20H0z"/><path fill="#46BC99" d="M34 0h58v20H34z"/><path fill="url(#b)" d="M0 0h92v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="17" y="15" fill="#010101" fill-opacity=".3">chat</text><text x="17" y="14">chat</text><text x="62" y="15" fill="#010101" fill-opacity=".3">on gitter</text><text x="62" y="14">on gitter</text></g></svg>

After

Width:  |  Height:  |  Size: 733 B