Skip to content
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

Custom directory wipe #344

Merged
merged 6 commits into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions lib/agent/actions/wipe/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var join = require('path').join,
var fs = require('fs'),
path = require('path'),
Emitter = require('events').EventEmitter,
wipe = require('./wipe'),
common = require('./../../common'),
join = path.join,
os_name = common.os_name,
logger = common.logger.prefix('wipe'),
system = common.system;
Expand All @@ -14,13 +16,26 @@ var node_bin = join(system.paths.current, 'bin', 'node');
if (os_name == 'windows')
node_bin = node_bin + '.exe';

var validDirs = function(dirs) {
dirs = dirs.split(',');

dirs.forEach(function(dir, index) {
dirs[index] = dir.trim();
if (path.isAbsolute(dirs[index])) {
exports.directories.push(dirs[index]);
} else logger.info("Invalid directory path: " + dirs[index]);
})
if (exports.directories.length == 0) return false;
return true;
}

var valid_types = function(hash) {
var list = [];

// hash keys should be 'wipe_cookies', 'wipe_passwords', etc
for (var key in hash) {
var val = hash[key].toString().trim();
if (val == 'on' || val == 'true') {
if ((val != 'false' && val != 'off' && key.includes('wipe_')) && ( val == 'on' || val == 'true' || validDirs(val) )) {
var method = key.replace('wipe_', ''); // just 'cookies'
if (typeof wipe[method] == 'function')
list.push(method);
Expand All @@ -32,6 +47,7 @@ var valid_types = function(hash) {

exports.start = function(opts, cb) {

exports.directories = [];
var opts = opts || {};
var confirm = opts.confirm == 'ireallyknowwhatiamdoing';
var items = valid_types(opts);
Expand Down Expand Up @@ -63,7 +79,7 @@ exports.start = function(opts, cb) {

// run it as another process, using impersonation (to avoid permission errors)
var spawn = function() {
var args = [join(__dirname, 'runner.js')].concat(items);
var args = [join(__dirname, 'runner.js')].concat(items).concat(exports.directories.toString());

system.spawn_as_logged_user(node_bin, args, function(err, child) {
if (err) {
Expand All @@ -80,6 +96,8 @@ exports.start = function(opts, cb) {
if (line.toString().match('File removed')) {
logger.warn(line.trim());
removed++;
} else if (line.toString().match('Error while removing dir')) {
logger.warn(line.trim());
} else if (line.trim() != '') {
logger.debug(line.trim());
}
Expand Down Expand Up @@ -112,7 +130,7 @@ exports.start = function(opts, cb) {

emitter = new Emitter;
cb(null, emitter);
spawn();
fs.existsSync(node_bin) ? spawn() : finished(new Error('Node binary not present'));

}

Expand All @@ -124,3 +142,6 @@ exports.stop = function(){

emitter = null;
}

exports.valid_types = valid_types;
exports.directories = [];
3 changes: 2 additions & 1 deletion lib/agent/actions/wipe/linux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ exports.paths = {
],
cloud_files: [
'Dropbox'
]
],
directories: []
}
Binary file modified lib/agent/actions/wipe/linux/wipe-linux
100644 → 100755
Binary file not shown.
3 changes: 2 additions & 1 deletion lib/agent/actions/wipe/mac/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ exports.paths = {
cloud_files: [
'Google\ Drive',
'Dropbox'
]
],
directories: []
}
Binary file modified lib/agent/actions/wipe/mac/wipe-osx
100644 → 100755
Binary file not shown.
9 changes: 7 additions & 2 deletions lib/agent/actions/wipe/runner.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env node

var wipe = require('./wipe'),
what = process.argv;
var wipe = require('./wipe'),
os_name = require('./../../common').os_name,
os_wipe = require('./' + os_name),
what = process.argv;

// variable to store last error
var last_err;

// insert custom directories in the wipe paths
os_wipe.paths.directories = what.pop().split(',');

// pad node binary and script path
what.shift();
what.shift();
Expand Down
3 changes: 2 additions & 1 deletion lib/agent/actions/wipe/windows/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ exports.paths = {
'Google Drive',
'Dropbox',
'OneDrive'
]
],
directories: []
}

/*
Expand Down
Binary file modified lib/agent/actions/wipe/windows/wipe-win.exe
100644 → 100755
Binary file not shown.
31 changes: 20 additions & 11 deletions lib/agent/actions/wipe/wipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ exports.cloud = function(cb) {
})
}

exports.directories = function(cb) {
wipe('directories', cb)
}

exports.stop = function() {
remover.stop();
}
Expand All @@ -149,16 +153,21 @@ var wipe = function(what, cb) {
--dirs || cb(last_err, removed);
}

fs.readdir(root, function(err, list) {
if (err) return cb(err);

list.forEach(function(user) {
paths[what].forEach(function(dir) {
dirs++;
remover = remove(join(root, user, dir, '*'), secure_wipe_cmd, done)
})
if (what == 'directories') {
paths.directories.forEach(function(dir) {
dirs++;
remover = remove(join(dir, '*'), secure_wipe_cmd, done);
})
} else {
fs.readdir(root, function(err, list) {
if (err) return cb(err);

list.forEach(function(user) {
paths[what].forEach(function(dir) {
dirs++;
remover = remove(join(root, user, dir, '*'), secure_wipe_cmd, done)
})
});
});

});

}
}
8 changes: 4 additions & 4 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading