aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/phishing-detect.js
blob: 5ef99f181f6523d99a3c959e5e328da6ba205a04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
window.onload = function () {
  if (window.location.pathname === '/phishing.html') {
    const {hostname} = parseHash()
    document.getElementById('esdbLink').innerHTML = '<b>To read more about this site and why it was blocked, <a href="https://etherscamdb.info/domain/' + hostname + '"> please navigate here</a>.</b>'
  }
}

const querystring = require('querystring')
const dnode = require('dnode')
const { EventEmitter } = require('events')
const PortStream = require('extension-port-stream')
const extension = require('extensionizer')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const { getEnvironmentType } = require('./lib/util')
const ExtensionPlatform = require('./platforms/extension')

document.addEventListener('DOMContentLoaded', start)

function start () {
  const windowType = getEnvironmentType(window.location.href)

  global.platform = new ExtensionPlatform()
  global.METAMASK_UI_TYPE = windowType

  const extensionPort = extension.runtime.connect({ name: windowType })
  const connectionStream = new PortStream(extensionPort)
  const mx = setupMultiplex(connectionStream)
  setupControllerConnection(mx.createStream('controller'), (err, metaMaskController) => {
    if (err) {
      return
    }

    const suspect = parseHash()
    const unsafeContinue = () => {
      window.location.href = suspect.href
    }
    const continueLink = document.getElementById('unsafe-continue')
    continueLink.addEventListener('click', () => {
      metaMaskController.whitelistPhishingDomain(suspect.hostname)
      unsafeContinue()
    })
  })
}

function setupControllerConnection (connectionStream, cb) {
  const eventEmitter = new EventEmitter()
  const accountManagerDnode = dnode({
    sendUpdate (state) {
      eventEmitter.emit('update', state)
    },
  })
  connectionStream.pipe(accountManagerDnode).pipe(connectionStream)
  accountManagerDnode.once('remote', (accountManager) => cb(null, accountManager))
}

function parseHash () {
  const hash = window.location.hash.substring(1)
  return querystring.parse(hash)
}
endabot/npm_and_yarn/devel/electron4/files/eslint-utils-1.4.3&id=c830042769f26309b16e0b0ace05fc30fec7b236'>Update the default version of GCC in the Ports Collection from GCC 4.7.4gerald2014-09-112-1/+2 * Upgrade OpenEXR and ilmbase to 2.2.0.mandree2014-08-161-0/+1 * Use OPTIONS helpers.adamw2014-07-041-14/+4 * Update to 4.2.5.jkim2014-06-241-2/+2 * Update to libreoffice 4.2.4bapt2014-06-111-2/+2 * - USE_BZIP2 -> USES=tar:bzip2ohauer2014-06-013-4/+4 * KDE/FreeBSD team presents KDE SC 4.12.5 and KDE Workspace 4.11.9!makc2014-05-111-2/+2 * Update to 4.1.6.jkim2014-05-071-2/+2 * Convert all :U to :tu and :L to :tlbapt2014-05-051-1/+1 * KDE/FreeBSD team presents KDE SC 4.12.4 and KDE Workspace 4.11.8!makc2014-04-031-2/+2 * KDE/FreeBSD team presents KDE SC 4.12.3 and KDE Workspace 4.11.7!makc2014-03-051-2/+2 * Update to 4.1.5. It is partially based on the following PR.jkim2014-02-261-2/+2 * KDE/FreeBSD team presents KDE SC 4.12.2 and KDE Workspace 4.11.6!makc2014-02-183-10/+4 * - Update distinfo due to a little change in a PFB font filenivit2013-12-064-214/+215 * Stagifybapt2013-11-041-1/+0 * - Update to 4.0.6.jkim2013-10-262-3/+2 * Support stage.vanilla2013-09-255-6/+61 * Support stage.vanilla2013-09-254-30/+6 * Add NO_STAGE all over the place in accessibility in preparation for the stagi...bapt2013-09-209-0/+9 * Update to 4.0.5.jkim2013-08-231-2/+2 * KDE3 and QT3 expired on 2013-07-01, remove these ports.rene2013-07-27