Created
August 1, 2016 14:36
-
-
Save clochix/1bf45b2d9681fc31d318cb84d1d6ae82 to your computer and use it in GitHub Desktop.
Manually disable 2FA on a Cozy server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Disable 2FA | |
// | |
var exit, request, runCmd; | |
request = require('request-json'); | |
client = request.createClient('http://localhost:9103'); | |
exit = function(code) { | |
return setTimeout((function() { | |
return process.exit(code); | |
}), 10); | |
}; | |
runCmd = function() { | |
// Fetch current user parameters | |
client.get('api/users', function(err, res, instances) { | |
if (err) { | |
console.error(err); | |
return exit(1); | |
} else if (instances.rows.length === 0) { | |
console.error("Unable to get user"); | |
return exit(1); | |
} else { | |
var user = instances.rows[0]; | |
// Display to user to be able to restore it in case of problem | |
console.log("# Current User"); | |
console.log(JSON.stringify(user, null, 2)); | |
// Update user, disabling 2FA | |
client.post('api/user', { | |
authType: null | |
}, function(err, res, body) { | |
if (err) { | |
console.log(err); | |
} else if (res.statusCode !== 200) { | |
console.log('Something went wrong while updating user'); | |
console.log(body); | |
} else { | |
console.log("2FA disabled"); | |
} | |
return exit(0); | |
}); | |
} | |
}); | |
}; | |
runCmd(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment