Skip to content
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
18 changes: 18 additions & 0 deletions ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Simple Stack

## Requirements

You need to define 2 environments variables:

```
export AUTH_SECRET=changeme
export AUTH_COOKIE=changeme
```

## Start the UI

```
npm install
node index.js
```
6 changes: 3 additions & 3 deletions ui/definitions/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var opt = {};
opt.secret = CONF.auth_secret;
opt.cookie = CONF.auth_cookie;
opt.secret = process.env.AUTH_SECRET;
opt.cookie = process.env.AUTH_COOKIE;
opt.expire = '3 minutes';
opt.cleaner = '5 minutes';
opt.strict = false;
Expand All @@ -12,7 +12,7 @@ opt.onauthorize = function($) {
let bufferObj = Buffer.from(authorization, "base64");
let decodedString = bufferObj.toString("utf8").split(':');

DATA.read('nosql/users').where('email', decodedString[0]).where('password', decodedString[1].sha256(CONF.auth_secret)).where('isinactive', false).where('isremoved', false).callback(function(err, user){
DATA.read('nosql/users').where('email', decodedString[0]).where('password', decodedString[1].sha256(process.env.AUTH_SECRET)).where('isinactive', false).where('isremoved', false).callback(function(err, user){
if(err){
$.invalid(401);
}
Expand Down
8 changes: 8 additions & 0 deletions ui/index.js.map

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

2 changes: 1 addition & 1 deletion ui/schemas/catalogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ NEWSCHEMA('Catalogs', function(schema) {
.error('@(Settings are undefined)')
.promise($);

const decrypted = JSON.parse(DECRYPT(settings.value, CONF.auth_secret));
const decrypted = JSON.parse(DECRYPT(settings.value, process.env.AUTH_SECRET));

const payload = {
meta: { hosts: decrypted.instance },
Expand Down
4 changes: 2 additions & 2 deletions ui/schemas/infrastructures.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NEWSCHEMA('Infrastructures', function (schema) {
// Populate system fields
model.id = UID();
model.uid = $.user.id;
model.admin_pass = model.admin_pass.sha256(CONF.auth_secret);
model.admin_pass = model.admin_pass.sha256(process.env.AUTH_SECRET);
model.dtcreated = new Date();
model.isarchived = false;
model.tfstate = { version: 4 };
Expand Down Expand Up @@ -138,7 +138,7 @@ NEWSCHEMA('Infrastructures', function (schema) {
$.invalid(`${REGEX_PROJECTS.admin_pass.comment}`);
return;
}
model.admin_pass = model.admin_pass.sha256(CONF.auth_secret);
model.admin_pass = model.admin_pass.sha256(process.env.AUTH_SECRET);
} else {
// Preserve existing hash
const existing = await DATA
Expand Down
2 changes: 1 addition & 1 deletion ui/schemas/softwares.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ NEWSCHEMA('Softwares', function (schema) {
.error('@(Settings are undefined)')
.promise($);

const decryptedSettings = JSON.parse(DECRYPT(settingsRec.value, CONF.auth_secret));
const decryptedSettings = JSON.parse(DECRYPT(settingsRec.value, process.env.AUTH_SECRET));

const catalogName = (await DATA.read('nosql/catalogs')
.where('id', item.software)
Expand Down
2 changes: 1 addition & 1 deletion ui/schemas/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NEWSCHEMA('Users', function (schema) {

const hash = value => value.sha256(CONF.auth_secret);
const hash = value => value.sha256(process.env.AUTH_SECRET);
const expire = (value = CONF.auth_cookie_expire) => NOW.add(value || '1 month');

function validateModel(model, rules) {
Expand Down
22 changes: 11 additions & 11 deletions ui/schemas/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ NEWSCHEMA('Variables', function (schema) {
return;
}

const decrypted = DECRYPT(result.value, CONF.auth_secret);
const decrypted = DECRYPT(result.value, process.env.AUTH_SECRET);
let value;
try {
value = JSON.parse(decrypted);
Expand Down Expand Up @@ -70,10 +70,10 @@ NEWSCHEMA('Variables', function (schema) {

const merged = variables.reduce((acc, variable) => {
try {
const parsed = JSON.parse(DECRYPT(variable.value, CONF.auth_secret));
const parsed = JSON.parse(DECRYPT(variable.value, process.env.AUTH_SECRET));
return { ...acc, ...parsed };
} catch (_) {
const raw = DECRYPT(variable.value, CONF.auth_secret);
const raw = DECRYPT(variable.value, process.env.AUTH_SECRET);
return { ...acc, ...raw };
}
}, {});
Expand All @@ -92,7 +92,7 @@ NEWSCHEMA('Variables', function (schema) {
key: model.key,
key2,
dtupdated: NOW,
value: ENCRYPT(JSON.stringify(yamlToJson(model.value)), CONF.auth_secret)
value: ENCRYPT(JSON.stringify(yamlToJson(model.value)), process.env.AUTH_SECRET)
};

await DATA.insert('nosql/variables', payload)
Expand All @@ -112,7 +112,7 @@ NEWSCHEMA('Variables', function (schema) {

const updatePayload = {
status: model.status,
value: ENCRYPT(JSON.stringify(yamlToJson(model.value)), CONF.auth_secret),
value: ENCRYPT(JSON.stringify(yamlToJson(model.value)), process.env.AUTH_SECRET),
dtupdated: NOW,
key2
};
Expand Down Expand Up @@ -166,7 +166,7 @@ NEWSCHEMA('Variables', function (schema) {
key: model.key,
key2: model.key.replace(/\./g, '_'),
dtupdated: NOW,
value: ENCRYPT({ [model.subkey]: generatePassword(model.userpass, model.nosymbols, model.length) }, CONF.auth_secret)
value: ENCRYPT({ [model.subkey]: generatePassword(model.userpass, model.nosymbols, model.length) }, process.env.AUTH_SECRET)
};
await DATA.insert('nosql/variables', newRecord)
.error('@(Error)')
Expand All @@ -187,9 +187,9 @@ NEWSCHEMA('Variables', function (schema) {

let stored;
try {
stored = JSON.parse(DECRYPT(result.value, CONF.auth_secret));
stored = JSON.parse(DECRYPT(result.value, process.env.AUTH_SECRET));
} catch (_) {
stored = DECRYPT(result.value, CONF.auth_secret);
stored = DECRYPT(result.value, process.env.AUTH_SECRET);
}

if (model.subkey) {
Expand All @@ -202,7 +202,7 @@ NEWSCHEMA('Variables', function (schema) {

if (!subExists && model.missing === 'create') {
stored[model.subkey] = generatePassword(model.userpass, model.nosymbols, model.length);
await DATA.update('nosql/variables', { value: ENCRYPT(stored, CONF.auth_secret), dtupdated: NOW })
await DATA.update('nosql/variables', { value: ENCRYPT(stored, process.env.AUTH_SECRET), dtupdated: NOW })
.where('id', result.id)
// .error('@(Error)')
.promise($);
Expand All @@ -212,7 +212,7 @@ NEWSCHEMA('Variables', function (schema) {

if (model.overwrite) {
stored[model.subkey] = generatePassword(model.userpass, model.nosymbols, model.length);
await DATA.update('nosql/variables', { value: ENCRYPT(stored, CONF.auth_secret), dtupdated: NOW })
await DATA.update('nosql/variables', { value: ENCRYPT(stored, process.env.AUTH_SECRET), dtupdated: NOW })
.where('id', result.id)
// .error('@(Error)')
.promise($);
Expand All @@ -222,7 +222,7 @@ NEWSCHEMA('Variables', function (schema) {

if (model.delete) {
delete stored[model.subkey];
await DATA.update('nosql/variables', { value: ENCRYPT(stored, CONF.auth_secret), dtupdated: NOW })
await DATA.update('nosql/variables', { value: ENCRYPT(stored, process.env.AUTH_SECRET), dtupdated: NOW })
.where('id', result.id)
// .error('@(Error)')
.promise($);
Expand Down