Skip to content

Commit

Permalink
Added interface field (local IP addresses)
Browse files Browse the repository at this point in the history
Fixed ProfileExport plugin
  • Loading branch information
Xzandro committed Mar 11, 2017
1 parent 9c014a4 commit b9cf9d1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/components/Head.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { ipcRenderer, remote } = require('electron');

import React from 'react';

import { Menu, Button, Input } from 'semantic-ui-react';
import { Menu, Button, Input, Select } from 'semantic-ui-react';

class Head extends React.Component {
constructor() {
Expand All @@ -28,8 +28,14 @@ class Head extends React.Component {
}

render () {
const interfaces = ipcRenderer.sendSync('proxyGetInterfaces').map((interfaceEntry, i) => {
return { "key": i, "text": interfaceEntry, "value": i }
})
return (
<Menu className="main-menu">
<Menu.Item>
<Select label='Interfaces' options={interfaces} defaultValue={0} />
</Menu.Item>
<Menu.Item>
<Input label='Port' defaultValue={this.config.Proxy.port} onChange={this.changePort.bind(this)} />
</Menu.Item>
Expand Down
4 changes: 4 additions & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ ipcMain.on('proxyIsRunning', (event, arg) => {
event.returnValue = proxy.isRunning();
})

ipcMain.on('proxyGetInterfaces', (event, arg) => {
event.returnValue = proxy.getInterfaces();
})

ipcMain.on('proxyStart', (event, arg) => {
proxy.start(config.Proxy.port);
})
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/profile-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
enabled: true
},
pluginName: 'ProfileExport',
init(proxy) {
init(proxy, config) {
proxy.on('HubUserLogin', (req, resp) => {
if (config.enabled)
this.writeProfileToFile(proxy, req, resp);
Expand Down
16 changes: 15 additions & 1 deletion app/proxy/SWProxy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const EventEmitter = require('events');
const http = require('http')
const httpProxy = require('http-proxy');
const os = require('os');

const {decrypt_request, decrypt_response} = require('./smon_decryptor');

Expand All @@ -10,6 +11,7 @@ class SWProxy extends EventEmitter {
this.httpServer = null;
this.proxy = null;
this.logEntries = [];
this.addresses = [];
}
start(port) {
const self = this; // so event callbacks can access this SWProxy class
Expand Down Expand Up @@ -62,7 +64,6 @@ class SWProxy extends EventEmitter {

this.proxy.web(req, resp, { target: req.url, prependPath: false });
}).listen(port);

this.log({ type: 'info', source: 'proxy', message: `Now listening on port ${port}` })
}

Expand All @@ -72,6 +73,19 @@ class SWProxy extends EventEmitter {
this.log({ type: 'info', source: 'proxy', message: `Proxy stopped` })
}

getInterfaces() {
let interfaces = os.networkInterfaces();
for (let k in interfaces) {
for (let k2 in interfaces[k]) {
let address = interfaces[k][k2];
if (address.family === 'IPv4' && !address.internal) {
this.addresses.push(address.address);
}
}
}
return this.addresses;
}

isRunning() {
if (this.httpServer && this.httpServer.address()) {
return true;
Expand Down

0 comments on commit b9cf9d1

Please sign in to comment.