Skip to content

Commit

Permalink
Merge pull request #103 from patryksz/feature/darwin-support
Browse files Browse the repository at this point in the history
Darwin support
  • Loading branch information
Jyben committed Jun 12, 2023
2 parents f323fb2 + 8e22bd1 commit b246623
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,8 +1,11 @@
#misc
.idea

#directories
bower_components
node_modules
dist

#files
*.tgz
*.log
*.log
11 changes: 6 additions & 5 deletions app/main-process/firewall.js
Expand Up @@ -5,11 +5,12 @@ const PingWrapper = require('./ping');
const ServersService = require('../services/servers');
const Files = require('./util');
const log = require('./log');
const Darwin = require("../services/darwin");

let Firewall = function (win, clustersId, clusters) {
this._clustersId = clustersId;
let Firewall = function (win, clusters) {
this._clusters = clusters;
this._win = win;
this._darwin = new Darwin(this._win, _execBash);
}

Firewall.prototype.exec = function (ipList) {
Expand All @@ -25,7 +26,7 @@ Firewall.prototype.exec = function (ipList) {
break;

case 'darwin':

this._darwin.block(ipList);
break;

default:
Expand Down Expand Up @@ -61,7 +62,7 @@ Firewall.prototype.reset = function () {
break;

case 'darwin':

this._darwin.reset();
break;

default:
Expand Down Expand Up @@ -100,4 +101,4 @@ function _ping(win) {
});
}

module.exports = Firewall;
module.exports = Firewall;
4 changes: 2 additions & 2 deletions app/main-process/left-menu.js
Expand Up @@ -32,8 +32,8 @@ ipcMain.on('request-reset-firewall', (event) => {
const clusters = new Clusters(response.data);
clusters.convert();

if (process.platform === 'linux') {
new Firewall(win, clusters.clustersId, clusters).reset();
if (process.platform === 'linux' || process.platform === 'darwin') {
new Firewall(win, clusters).reset();
}

if (process.platform === 'win32') {
Expand Down
32 changes: 32 additions & 0 deletions app/services/darwin.js
@@ -0,0 +1,32 @@
const { app } = require('electron');
const fs = require("fs");

let Darwin = function (win, execCallback) {
this._win = win;
this._execCallback = execCallback;
}

let readPfFileToArray = function() {
return fs
.readFileSync("/etc/pf.conf", 'utf-8')
.split("\n")
.filter(line => line.substring(0, 1) !== "#");
}

Darwin.prototype.block = function(ipList) {
let block = function (ipAddresses) {
return ipAddresses.map(ip => {
return `block drop from any to ${ip}`
});
};
let newPf = readPfFileToArray().concat(block(ipList)).join("\n") + "\n";

fs.writeFileSync(`${app.getPath('home')}/csgo-mm-server-picker-pf.conf`, newPf);
this._execCallback(`pfctl -e -f ${app.getPath('home')}/csgo-mm-server-picker-pf.conf`, this._win);
};

Darwin.prototype.reset = function() {
this._execCallback(`rm -rf ${app.getPath('home')}/csgo-mm-server-picker-pf.conf && pfctl -ef /etc/pf.conf`, this._win);
};

module.exports = Darwin;

0 comments on commit b246623

Please sign in to comment.