-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from dappnode/v0.1.14
V0.1.14
- Loading branch information
Showing
13 changed files
with
133 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const credentialsFile = require('../utils/credentialsFile'); | ||
const generate = require('../utils/generate'); | ||
const db = require('../db'); | ||
|
||
const vpnPasswordLength = 20; | ||
const guestsName = 'Guests'; | ||
|
||
async function resetGuestUsersPassword() { | ||
// Fetch devices data from the chap_secrets file | ||
let credentialsArray = await credentialsFile.fetch(); | ||
|
||
const guestsPassword = generate.password(vpnPasswordLength); | ||
db.set('guestsPassword', guestsPassword).write(); | ||
|
||
const guestUsers = credentialsArray.find((u) => u.name === guestsName); | ||
if (guestUsers) { | ||
guestUsers.password = guestsPassword; | ||
await credentialsFile.write(credentialsArray); | ||
} | ||
|
||
return { | ||
message: `Reseted guests password`, | ||
logMessage: true, | ||
userAction: true, | ||
}; | ||
} | ||
|
||
|
||
module.exports = resetGuestUsersPassword; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const credentialsFile = require('../utils/credentialsFile'); | ||
const generate = require('../utils/generate'); | ||
const db = require('../db'); | ||
|
||
const vpnPasswordLength = 20; | ||
const guestsName = 'Guests'; | ||
|
||
async function toggleGuestUsers() { | ||
// Fetch devices data from the chap_secrets file | ||
let credentialsArray = await credentialsFile.fetch(); | ||
const guestUsers = credentialsArray.find((u) => u.name === guestsName); | ||
if (guestUsers) { | ||
// Remove guest users credentials | ||
credentialsArray = credentialsArray.filter((u) => u.name !== guestsName); | ||
} else { | ||
// Use the previous password or create a new one | ||
let guestsPassword = db.get('guestsPassword').value(); | ||
if (!guestsPassword) { | ||
guestsPassword = generate.password(vpnPasswordLength); | ||
db.set('guestsPassword', guestsPassword).write(); | ||
} | ||
// Add guest users credentials | ||
credentialsArray.unshift({ | ||
name: guestsName, | ||
password: guestsPassword, | ||
ip: '*', | ||
}); | ||
} | ||
|
||
await credentialsFile.write(credentialsArray); | ||
|
||
return { | ||
message: `${guestUsers ? 'disabled' : 'enabled'} guests users`, | ||
logMessage: true, | ||
userAction: true, | ||
}; | ||
} | ||
|
||
|
||
module.exports = toggleGuestUsers; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require('file-system'); | ||
const {promisify} = require('util'); | ||
const readFileAsync = promisify(fs.readFile); | ||
const logs = require('../logs.js')(module); | ||
const ipRegex = require('ip-regex'); | ||
|
||
const {INSTALLATION_STATIC_IP} = process.env; | ||
|
||
/* eslint-disable max-len */ | ||
|
||
function getInstallationStaticIp() { | ||
return readFileAsync(INSTALLATION_STATIC_IP, 'utf-8') | ||
.then((data) => String(data).trim()) | ||
// If the file is empty return null | ||
.then((data) => data.length ? data : null) | ||
.then((ip) => ipRegex({exact: true}).test(ip)) | ||
.catch((err) => { | ||
logs.error(`Error reading INSTALLATION_STATIC_IP ${INSTALLATION_STATIC_IP}: ${err.stack || err.message}`); | ||
return null; | ||
}); | ||
} | ||
|
||
module.exports = getInstallationStaticIp; |
This file contains 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
This file contains 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