Skip to content

Issue2 and issue26 #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
10 changes: 10 additions & 0 deletions app/client/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ <h4>My emails ({{emails.length}})</h4>
</div>
{{/with}}

<h4>My MAC addresses</h4>
<div class="ui raised segment">
<div class="ui list">
{{#each macs localIPCandidates}}
<div class="item">{{MAC}} {{name}}</div>
{{/each}}
</div>
</div>

<h4>My addresses</h4>
<div class="ui raised segment">
<div class="ui list">
<div class="item">My public IP address: {{remoteIPAddress}}</div>
Expand Down
25 changes: 24 additions & 1 deletion app/client/templates/profile.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
Template.profile.events({
Template.profile.onCreated(function () {
Meteor.subscribe('Meteor.arptable');
Meteor.subscribe('Meteor.users');
});

Template.profile.helpers({
macs: function(IP){
cursor = App.Collections.ARPEntries.find({"IP" : IP[0]});
result = [];

cursor.map(entry => {
//TODO: use proper projection
var user = Meteor.users.findOne({'profile.devices.MAC': entry.MAC });
var name;
user.profile.devices.map(MACentry => {
if(MACentry.MAC == entry.MAC){
name = MACentry.name;
}
})
result.push({'MAC': entry.MAC, 'name': name});
});

return result;
}
});
27 changes: 12 additions & 15 deletions app/client/templates/whosthere.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Template.whosthere.onCreated(function () {
Meteor.subscribe('Meteor.arptable');
});

Template.whosthere.onRendered(function() {

this.$('.ui.dropdown')
.dropdown();
});


Template.whosthere.helpers({

this.connectedMembers = function () {
connectedMembers: function() {
var ARPentries = App.Collections.ARPEntries.find();

var i = 0;
Expand All @@ -21,20 +32,6 @@ Template.whosthere.onCreated(function () {
unknown: user ? false : true
};
}), 'name'), 'order');
};
});

Template.whosthere.onRendered(function() {

this.$('.ui.dropdown')
.dropdown();
});


Template.whosthere.helpers({

connectedMembers: function() {
return Template.instance().connectedMembers();
},

unknownMemberClass: function() {
Expand Down
10 changes: 4 additions & 6 deletions app/imports/server/api/endpoints.app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import { chai } from 'meteor/practicalmeteor:chai';
var assert = chai.assert,
expect = chai.expect;

const NoEntries = 'IP address HW type Flags HW address Mask Device';
const ThreeEntries = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0\r\n192.168.1.18 0x1 0x2 3c:15:c2:cc:dc:2a * br0';
const TwoEntries = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0';
const testFilesPath = 'test/arpTable/';

describe('API', function() {

it('accepts correct call', function() {
HTTP.call(
'POST',
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: ThreeEntries } },
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: Assets.getText(testFilesPath + 'threeEntries.txt') } },
function(error, result) {
assert(!error, 'there was an error: \n' + error);
assert(result.statusCode == 200, 'Status code didn\'t match 200 it was ' + result.statusCode);
Expand Down Expand Up @@ -82,12 +80,12 @@ describe('API', function() {
it('removes old MAC addresses', function() {
HTTP.call(
'POST',
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: ThreeEntries } }
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: Assets.getText(testFilesPath + 'threeEntries.txt') } }
);
var entriesBefore = App.Collections.ARPEntries.find().count();
result = HTTP.call(
'POST',
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: TwoEntries } }
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: Assets.getText(testFilesPath + 'twoEntries.txt') } }
);
assert.equal(App.Collections.ARPEntries.find().count(), entriesBefore - 1);
});
Expand Down
42 changes: 15 additions & 27 deletions app/imports/server/api/getEntries.test.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
import { Meteor } from 'meteor/meteor';
import { chai } from 'meteor/practicalmeteor:chai';
import { getEntries } from '../../../server/api/arpTable.js';
import { processedThreeEntries, processedRealARP } from '../api/processed.js';

var assert = chai.assert,
expect = chai.expect;

const NoEntries = 'IP address HW type Flags HW address Mask Device';
const ThreeEntries = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0\r\n192.168.1.18 0x1 0x2 3c:15:c2:cc:dc:2a * br0';

const DoubleIP = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0 192.168.1.17';
const DoubleMAC = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8d:3a:e3:93:83:93 * br0 8c:3a:e3:93:83:93';
const NoMAC = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 * br0 192.168.1.11 ';
const NoIP = 'IP address HW type Flags HW address Mask Device\r\n192.168 0x1 0x2 * br0 8c:3a:e3:93:83:93';
const NoIPnorMAC = 'IP address HW type Flags HW address Mask Device\r\n192.168 0x1 0x2 * br0 ';
const ReUsedMAC = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.18 0x1 0x2 8c:3a:e3:93:83:93 * br0';
const ReUsedIP = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.50 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 8c:3a:e3:93:83:94 * br0\r\n192.168.1.50 0x1 0x2 8c:3a:e3:93:83:92 * br0';
const ReUsedIPandMAC = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.50 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 8c:3a:e3:93:83:93 * br0';

const processedThreeEntries = [{
IP: '192.168.1.11',
MAC: '8C:3A:E3:93:83:93'
}, {
IP: '192.168.1.50',
MAC: '00:26:BB:07:54:80'
}, {
IP: '192.168.1.18',
MAC: '3C:15:C2:CC:DC:2A'
}];
const testFilesPath = 'test/arpTable/';

describe('arpTable', function() {
it('processes correct arpTables', function() {
var result = getEntries(ThreeEntries);
var result = getEntries(Assets.getText(testFilesPath + 'threeEntries.txt'));
for (var i = result.length - 1; i >= 0; i--) {
delete result[i].updatedAt;
}
assert.deepEqual(result, processedThreeEntries);
});

it('processes another correct arpTables', function() {
var result = getEntries(Assets.getText(testFilesPath + 'realARP.txt'));
for (var i = result.length - 1; i >= 0; i--) {
delete result[i].updatedAt;
}
assert.deepEqual(result, processedRealARP);
});

it('processes empty arpTables', function() {
assert.deepEqual(getEntries(NoEntries), []);
assert.deepEqual(getEntries(Assets.getText(testFilesPath + 'noEntries.txt')), []);
});

it('does not allow no MAC address in entry', function() {
assert.throws(function(){
getEntries(NoMAC);
getEntries(Assets.getText(testFilesPath + 'noMAC.txt'));
}, Error, 'no MAC')
});

it('does not allow no IP address in entry', function() {
assert.throws(function(){
getEntries(NoIP);
getEntries(Assets.getText(testFilesPath + 'noIP.txt'));
}, Error, 'no IP')
});

it('does not allow no IP nor MAC address in entry', function() {
assert.throws(function(){
getEntries(NoIPnorMAC);
getEntries(Assets.getText(testFilesPath + 'noIPnorMAC.txt'));
}, Error, 'no IP')
});

Expand Down
42 changes: 42 additions & 0 deletions app/imports/server/api/processed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const processedThreeEntries = [{
IP: '192.168.1.11',
MAC: '8C:3A:E3:93:83:93'
}, {
IP: '192.168.1.50',
MAC: '00:26:BB:07:54:80'
}, {
IP: '192.168.1.18',
MAC: '3C:15:C2:CC:DC:2A'
}];

export const processedRealARP = [{
IP: '192.168.1.132',
MAC: 'B0:E2:35:70:61:A9'
},{
IP: '192.168.1.172',
MAC: 'AC:72:89:6A:B4:D6'
},{
IP: '192.168.1.203',
MAC: 'FC:C2:DE:7A:E7:6F'
},{
IP: '192.168.1.90',
MAC: 'D8:50:E6:BD:A0:0F'
},{
IP: '192.168.1.125',
MAC: '74:A5:28:74:73:76'
},{
IP: '192.168.1.231',
MAC: '44:82:E5:9E:87:C9'
},{
IP: '192.168.1.178',
MAC: 'C0:EE:FB:27:16:DB'
},{
IP: '192.168.1.81',
MAC: '6C:40:08:A9:1B:A0'
},{
IP: '10.1.2.1',
MAC: '30:85:A9:E7:1A:B8'
},{
IP: '192.168.1.84',
MAC: '3C:15:C2:CC:DC:2A'
}];
4 changes: 2 additions & 2 deletions app/lib/collections/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var UserProfileSchema = new SimpleSchema({
optional: true
},
devices: {
type: new SimpleSchema({
type: [new SimpleSchema({
name: {
type: String,
optional: true
Expand All @@ -50,7 +50,7 @@ var UserProfileSchema = new SimpleSchema({
type: String,
optional: true
}
}),
})],
optional: true
}
});
Expand Down
36 changes: 17 additions & 19 deletions app/lib/methods/users.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
Meteor.methods({
'user/updateProfilePicture': function(picture) {
'user/updateProfilePicture': function(picture) {

check(picture, String);
Meteor.users.update(this.userId, {$set: {'profile.picture': picture}});
check(picture, String);
Meteor.users.update(this.userId, { $set: { 'profile.picture': picture } });

return true;
},
return true;
},

'user/updateDevice': function (MAC, name, userId) {
'user/updateDevice': function(MAC, name) {

check(userId, String);
check(MAC, String);
check(name, Match.Optional(name));
userId = Meteor.userId();

if (!userId) {
userId = Meteor.userId();
}
check(userId, String);
check(MAC, String);
check(name, Match.Optional(name));

App.Services.Users.updateDevice(userId, {MAC: MAC, name: name});
},
App.Services.Users.updateDevice(userId, { MAC: MAC, name: name });
},

'user/getRemoteIPAddress': function() {
'user/getRemoteIPAddress': function() {

if (this.isSimulation) return;
if (this.isSimulation) return;

var clientIP = this.connection.clientAddress;
return clientIP;
}
var clientIP = this.connection.clientAddress;
return clientIP;
}
});
2 changes: 2 additions & 0 deletions app/private/test/arpTable/doubleIP.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IP address HW type Flags HW address Mask Device
192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0 192.168.1.17
2 changes: 2 additions & 0 deletions app/private/test/arpTable/doubleMAC.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IP address HW type Flags HW address Mask Device\r\n
192.168.1.11 0x1 0x2 8d:3a:e3:93:83:93 * br0 8c:3a:e3:93:83:93
1 change: 1 addition & 0 deletions app/private/test/arpTable/noEntries.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IP address HW type Flags HW address Mask Device
2 changes: 2 additions & 0 deletions app/private/test/arpTable/noIP.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IP address HW type Flags HW address Mask Device
192.168 0x1 0x2 * br0 8c:3a:e3:93:83:93
2 changes: 2 additions & 0 deletions app/private/test/arpTable/noIPnorMAC.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IP address HW type Flags HW address Mask Device
92.168 0x1 0x2 * br0
2 changes: 2 additions & 0 deletions app/private/test/arpTable/noMAC.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IP address HW type Flags HW address Mask Device
192.168.1.11 0x1 0x2 * br0 192.168.1.11
11 changes: 11 additions & 0 deletions app/private/test/arpTable/realARP.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
IP address HW type Flags HW address Mask Device
192.168.1.132 0x1 0x2 B0:E2:35:70:61:A9 * br0
192.168.1.172 0x1 0x2 AC:72:89:6A:B4:D6 * br0
192.168.1.203 0x1 0x2 FC:C2:DE:7A:E7:6F * br0
192.168.1.90 0x1 0x2 D8:50:E6:BD:A0:0F * br0
192.168.1.125 0x1 0x2 74:A5:28:74:73:76 * br0
192.168.1.231 0x1 0x2 44:82:E5:9E:87:C9 * br0
192.168.1.178 0x1 0x2 C0:EE:FB:27:16:DB * br0
192.168.1.81 0x1 0x2 6C:40:08:A9:1B:A0 * br0
10.1.2.1 0x1 0x2 30:85:A9:E7:1A:B8 * eth0
192.168.1.84 0x1 0x2 3C:15:C2:CC:DC:2A * br0
4 changes: 4 additions & 0 deletions app/private/test/arpTable/threeEntries.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IP address HW type Flags HW address Mask Device
192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0
192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0
192.168.1.18 0x1 0x2 3c:15:c2:cc:dc:2a * br0
3 changes: 3 additions & 0 deletions app/private/test/arpTable/twoEntries.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IP address HW type Flags HW address Mask Device
192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0
192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0
2 changes: 1 addition & 1 deletion app/server/api/arpTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var getEntries = function(arpTable) {
var rows = arpTable.split("\n");

rows.forEach((row, index) => {
if (index === 0)
if (index === 0 || row.length === 0)
return;

row = row.toUpperCase();
Expand Down
1 change: 1 addition & 0 deletions app/server/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UserSchema, UserProfileSchema } from '../../lib/collections/Users.js';

Meteor.methods({
'users.insert'(doc) {
doc.createdAt = new Date();
check(doc, UserSchema);
Meteor.users.insert(doc);
},
Expand Down
Loading