From 051808fb612ac8832fa569a294b6641677a8f1b6 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 22 Sep 2020 11:57:11 +0100 Subject: [PATCH] Made --remix-ide flag optional --- bin/remixd.ts | 20 ++++++++++---------- src/websocket.ts | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/bin/remixd.ts b/bin/remixd.ts index 718ab16dec..d04f2ed56b 100644 --- a/bin/remixd.ts +++ b/bin/remixd.ts @@ -23,17 +23,17 @@ import * as path from 'path' const killCallBack: Array = [] if (!program.remixIde) { - console.log('\x1b[31m%s\x1b[0m', '[ERR] URL Remix IDE instance has to be provided.') - } - const isValid = await isValidOrigin(program.remixIde) - - /* Allow unsupported domains for users running remixd without fetched origin.json file. */ - if (!isValid) { - console.log('\x1b[33m%s\x1b[0m', '[WARN] You are using IDE from an unsupported origin.') - console.log('\x1b[33m%s\x1b[0m', 'Check https://gist.github.com/EthereumRemix/091ccc57986452bbb33f57abfb13d173 for list of all supported origins.\n') - // return + console.log('\x1b[33m%s\x1b[0m', '[WARN] You can only connect to remixd from one of the supported origins.') + } else { + const isValid = await isValidOrigin(program.remixIde) + /* Allow unsupported origins and display warning. */ + if (!isValid) { + console.log('\x1b[33m%s\x1b[0m', '[WARN] You are using IDE from an unsupported origin.') + console.log('\x1b[33m%s\x1b[0m', 'Check https://gist.github.com/EthereumRemix/091ccc57986452bbb33f57abfb13d173 for list of all supported origins.\n') + // return + } + console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + program.remixIde + ' to connect to that instance') } - console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + program.remixIde + ' to connect to that instance') if (program.sharedFolder) { console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.') diff --git a/src/websocket.ts b/src/websocket.ts index a4f648a4a4..4697188b04 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -53,5 +53,24 @@ export default class WebSocket { } function originIsAllowed (origin: string, self: WebSocket): boolean { - return origin === self.opt.remixIdeUrl || origin === getDomain(self.opt.remixIdeUrl) + if (self.opt.remixIdeUrl) { + if (self.opt.remixIdeUrl.endsWith('/')) self.opt.remixIdeUrl = self.opt.remixIdeUrl.slice(0, -1) + return origin === self.opt.remixIdeUrl || origin === getDomain(self.opt.remixIdeUrl) + } else { + try { + const origins = require('../bin/origins.json') + const domain = getDomain(origin) + const { data } = origins + + if (data.includes(origin) || data.includes(domain)) { + self.opt.remixIdeUrl = origin + console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + self.opt.remixIdeUrl + ' to connect to that instance') + return true + } else { + return false + } + } catch (e) { + return false + } + } }