Skip to content

Commit

Permalink
Merge pull request #1 from firewalla/beta_7_0
Browse files Browse the repository at this point in the history
sync beta_7_0 back
  • Loading branch information
MelvinTo committed Nov 6, 2018
2 parents a669c09 + 51d1baf commit 4c89e33
Show file tree
Hide file tree
Showing 26 changed files with 393 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"rules": {
"indent": [
"error",
"off",
2
],
"linebreak-style": [
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ coverage
build/Release

# Dependency directories
node_modules
node_modules*
jspm_packages

# Optional npm cache directory
Expand Down Expand Up @@ -105,6 +105,9 @@ api/db/token.json

.idea/
.idea/workspace.xml

.vscode/

/test
/.gitmodules
/extension/frp/frpc.ini
2 changes: 0 additions & 2 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ follow direction to flash this to a card
- Boot Pi and update
```
sudo apt-get update
sudo apt-get -y dist-upgrade
sudo apt-get -y dist-upgrade
sudo apt-get -y install git
```
Expand Down
18 changes: 11 additions & 7 deletions alarm/PolicyManager2.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,8 @@ class PolicyManager2 {
return domainBlock.blockDomain(policy.target, {
exactMatch: policy.domainExactMatch,
blockSet: Block.getDstSet(policy.pid),
no_dnsmasq_entry: true
no_dnsmasq_entry: true,
no_dnsmasq_reload: true
})
} else {
return domainBlock.blockDomain(policy.target, {exactMatch: policy.domainExactMatch})
Expand All @@ -992,7 +993,8 @@ class PolicyManager2 {
return categoryBlock.blockCategory(policy.target, {
blockSet: Block.getDstSet(policy.pid),
macSet: Block.getMacSet(policy.pid),
no_dnsmasq_entry: true
no_dnsmasq_entry: true,
no_dnsmasq_reload: true
})
} else {
return categoryBlock.blockCategory(policy.target)
Expand Down Expand Up @@ -1093,12 +1095,13 @@ class PolicyManager2 {
case "dns":
return async(() => {
if(scope) {
await (Block.advancedUnblock(policy.pid, scope, []))
return domainBlock.unblockDomain(policy.target, {
await (domainBlock.unblockDomain(policy.target, {
exactMatch: policy.domainExactMatch,
blockSet: Block.getDstSet(policy.pid),
no_dnsmasq_entry: true
})
no_dnsmasq_entry: true,
no_dnsmasq_reload: true
}))
return Block.advancedUnblock(policy.pid, scope, [])
} else {
return domainBlock.unblockDomain(policy.target, {exactMatch: policy.domainExactMatch})
}
Expand All @@ -1120,7 +1123,8 @@ class PolicyManager2 {
blockSet: Block.getDstSet(policy.pid),
macSet: Block.getMacSet(policy.pid),
ignoreUnapplyBlock: true,
no_dnsmasq_entry: true
no_dnsmasq_entry: true,
no_dnsmasq_reload: true
}))
return Block.advancedUnblock(policy.pid, scope, [])
} else {
Expand Down
1 change: 1 addition & 0 deletions etc/brotab
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ SHELL=/bin/bash
*/5 * * * * logger "Firewalla checkpoint every 5 mins" &>/dev/null
*/30 * * * * /home/pi/firewalla/scripts/free-memory &>/dev/null
0 * * * * /home/pi/firewalla/scripts/health_check.sh &> /tmp/health_check.log
0 0 * * * timeout 30 /home/pi/firewalla/scripts/diag_hello.sh &>/dev/null
2 changes: 1 addition & 1 deletion extension/dnsmasq/dnsmasq.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ module.exports = class DNSMASQ {
onSpoofChanged() {
if (this.dhcpMode) {
this.needWriteHostsFile = true;
log.info("Spoof status changed, set need write hosts file to be true");
log.debug("Spoof status changed, set need write hosts file to be true");
}
}

Expand Down
70 changes: 65 additions & 5 deletions extension/install/diag.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
let instance = null;

const exec = require('child-process-promise').exec;
const network = require('network');
const Promise = require('bluebird');
const fConfig = require('../../net2/config.js').getConfig();
const log = require('../../net2/logger.js')(__filename);
const rclient = require('../../util/redis_manager.js').getRedisClient();

const get_interfaces_list_async = Promise.promisify(network.get_interfaces_list);
const get_interfaces_list_async = require('bluebird').promisify(require('network').get_interfaces_list);
const activeInterface = fConfig.monitoringInterface || "eth0";

const platformLoader = require('../../platform/PlatformLoader.js');
const platform = platformLoader.getPlatform();
const model = platform.getName();
const serial = platform.getBoardSerial();

const rp = require('request-promise');

Expand Down Expand Up @@ -58,6 +57,25 @@ class FWDiag {
return name.replace(/\n$/, '')
}

async getBranchInfo() {
const result = await exec("git rev-parse --abbrev-ref HEAD");
return result && result.stdout && result.stdout.replace(/\n$/, '')
}

getVersion() {
return fConfig.version;
}

async getLongVersion() {
const result = await exec("git describe --tags");
return result && result.stdout && result.stdout.replace(/\n$/, '')
}

async getTotalMemory() {
const result = await exec("free -m | awk '/Mem:/ {print $2}'");
return result && result.stdout && result.stdout.replace(/\n$/, '')
}

async prepareData(payload) {
const inter = await this.getNetworkInfo();

Expand All @@ -77,13 +95,15 @@ class FWDiag {
ts: ts,
gw_mac: gatewayMac,
gw_name: gatewayName,
model: platform.getName()
model: model
});
}

async submitInfo(payload) {
const data = await this.prepareData(payload);
if(data.gw) {
const rclient = require('../../util/redis_manager.js').getRedisClient();

const options = {
uri: `${fConfig.firewallaDiagServerURL}/${data.gw}` || `https://api.firewalla.com/diag/api/v1/device/${data.gw}`,
method: 'POST',
Expand All @@ -101,6 +121,46 @@ class FWDiag {
log.info("submitted info to diag server successfully with result", result);
}
}

async prepareHelloData() {
const inter = await this.getNetworkInfo();

const firewallaIP = inter.ip_address;
const mac = inter.mac_address;
const gateway = inter.gateway_ip;

const version = this.getVersion();

const [gatewayMac, branch, longVersion, memory] = await require('bluebird').all([
this.getGatewayMac(gateway),
this.getBranchInfo(),
this.getLongVersion(),
this.getTotalMemory()
]);

return {
mac,
firewallaIP,
gatewayMac,
branch,
version,
longVersion,
memory,
model,
serial
};
}

async sayHello() {
const data = await this.prepareHelloData();
const options = {
uri: `${fConfig.firewallaDiagServerURL}/hello` || `https://api.firewalla.com/diag/api/v1/device/hello`,
method: 'POST',
json: data
}
await rp(options);
log.info("said hello to Firewalla Cloud");
}
}

module.exports = new FWDiag();
Loading

0 comments on commit 4c89e33

Please sign in to comment.