From e9377ae1aab3bd944698bf080ef04b1dd788356b Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Tue, 4 Jul 2023 13:42:19 +0200 Subject: [PATCH] add link to node stats in the settings --- electron/main.js | 42 ++++++++++--------- src/components/modals/SettingsModal.jsx | 8 +++- .../styled/modals/SettingsModal.styled.jsx | 4 ++ 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/electron/main.js b/electron/main.js index 69d1620b..66083c3c 100644 --- a/electron/main.js +++ b/electron/main.js @@ -117,15 +117,18 @@ const createMainWindow = () => { // only open valid https urls to prevent remote execution // will throw if url isn't valid const validatedUrl = new URL(originalUrl); - if (validatedUrl.protocol !== 'https:') { - throw Error(`can't open url '${originalUrl}' not https`); + let serializedUrl = ''; + + // make an exception for ipfs stats + if (validatedUrl.toString() === 'http://localhost:5001/webui/') { + serializedUrl = validatedUrl.toString(); + } else if (validatedUrl.protocol === 'https:') { + // open serialized url to prevent remote execution + serializedUrl = validatedUrl.toString(); + } else { + throw Error(`can't open url '${originalUrl}', it's not https and not the allowed http exception`); } - // do not open http protocol, not private - // do not open any other protocol, will lead to remote execution - - // open serialized url to prevent remote execution - const serializedUrl = validatedUrl.toString(); shell.openExternal(serializedUrl); } catch (e) { console.warn(e); @@ -136,7 +139,7 @@ const createMainWindow = () => { // open links (with target="_blank") in external browser // do not open links in plebchan or will lead to remote execution mainWindow.webContents.setWindowOpenHandler(({url}) => { - const originalUrl = url + const originalUrl = url; try { // do not let the user open any url with shell.openExternal // or it will lead to remote execution https://benjamin-altpeter.de/shell-openexternal-dangers/ @@ -144,25 +147,26 @@ const createMainWindow = () => { // only open valid https urls to prevent remote execution // will throw if url isn't valid const validatedUrl = new URL(originalUrl); - if (validatedUrl.protocol !== 'https:') { - throw Error(`can't open url '${originalUrl}' not https`); + let serializedUrl = ''; + + // make an exception for ipfs stats + if (validatedUrl.toString() === 'http://localhost:5001/webui/') { + serializedUrl = validatedUrl.toString(); + } else if (validatedUrl.protocol === 'https:') { + // open serialized url to prevent remote execution + serializedUrl = validatedUrl.toString(); + } else { + throw Error(`can't open url '${originalUrl}', it's not https and not the allowed http exception`); } - // do not open http protocol, not private - // do not open any other protocol, will lead to remote execution - - // open serialized url to prevent remote execution - const serializedUrl = validatedUrl.toString(); shell.openExternal(serializedUrl); - setImmediate(() => { - shell.openExternal(serializedUrl) - }) } catch (e) { console.warn(e); } - return {action: 'deny'} + return {action: 'deny'}; }) + // deny permissions like location, notifications, etc https://www.electronjs.org/docs/latest/tutorial/security#5-handle-session-permission-requests-from-remote-content mainWindow.webContents.session.setPermissionRequestHandler((webContents, permission, callback) => { // deny all permissions diff --git a/src/components/modals/SettingsModal.jsx b/src/components/modals/SettingsModal.jsx index 844e42ed..144e847d 100755 --- a/src/components/modals/SettingsModal.jsx +++ b/src/components/modals/SettingsModal.jsx @@ -223,7 +223,13 @@ const SettingsModal = ({ isOpen, closeModal }) => {
- v{version} + v{version} -  + {window.electron && window.electron.isElectron ? ( + + full node + + ) : (web) + } Settings diff --git a/src/components/styled/modals/SettingsModal.styled.jsx b/src/components/styled/modals/SettingsModal.styled.jsx index 094a4b5e..806afb47 100644 --- a/src/components/styled/modals/SettingsModal.styled.jsx +++ b/src/components/styled/modals/SettingsModal.styled.jsx @@ -417,4 +417,8 @@ export const StyledModal = styled(Modal)` return ''; } }} + + #node-stats { + text-decoration: none; + } `; \ No newline at end of file