UNPKG

guest

Version:

Lets you enable or disable guest account access on Linux, Mac and Windows.

52 lines (39 loc) 1.27 kB
var fs = require('fs'); var file = '/etc/lightdm/lightdm.conf'; var get_current = function(cb) { fs.readFile(file, function(err, data) { if (err) return cb(err); var match = data.toString().match(/allow-guest=(.+)/); if (!match) return cb(null, null, data); var bool = match[1]; cb(null, bool, data); }); } var toggle = function(enabling, cb) { get_current(function(err, current, data) { if (err) return cb(err); if (current === null) { // not there, so let's append it to the bottom var str = data.toString().trim() + '\nallow-guest=' + enabling.toString() + '\n'; } else if (current.toString() == enabling.toString()) { return cb() // nothing to do } else { var str = data.toString().replace(/allow-guest=(.*)/, 'allow-guest=' + enabling.toString()); } fs.writeFile(file, str, cb); }) } exports.check = function(cb) { get_current(function(err, current) { if (err) return cb(err); // if no value is found, the default behaviour is to show the guest user option. var disabled = current !== null && current.toString() == 'false'; cb(null, !disabled); }) } exports.enable = function(cb) { toggle(true, cb); } exports.disable = function(cb) { toggle(false, cb); }