Compare commits

..

4 Commits

Author SHA1 Message Date
b1ek a335d5c14f
rewrite generate key script in python 2023-03-17 20:54:21 +10:00
b1ek e4f08d0778
fix 500 on project/* 2023-03-17 20:53:27 +10:00
b1ek 64e780b7af
check for dotenv in scripts 2023-03-17 19:02:48 +10:00
b1ek 513b4c9161
proper ctrl+backspace 2023-03-17 16:38:28 +10:00
10 changed files with 85 additions and 57 deletions

View File

@ -30,5 +30,4 @@ cd to `react/resume` and run `build.sh`.
If you are running in debug mode, run `yarn/npm start` If you are running in debug mode, run `yarn/npm start`
## Generate the key ## Generate the key
Install node modules in following directories: `.`, `./scripts` Cd to root of project and run `scripts/generate_key.py`
Then, cd to root and run `node scripts/generate_key.js`

7
dev.sh
View File

@ -1,5 +1,12 @@
#!/bin/bash #!/bin/bash
if [ ! -f .env ]; then
echo "No .env; Please create .env and try again"
exit
fi
. '.env'
cp docker-compose.dev docker-compose.yml cp docker-compose.dev docker-compose.yml
cp Dockerfile.dev Dockerfile cp Dockerfile.dev Dockerfile

View File

@ -26,7 +26,8 @@ config = {
host: DB_HOSTNAME || config.host, host: DB_HOSTNAME || config.host,
define: { define: {
timestamps: false timestamps: false
} },
logging: false
}; };
/** @type Sequelize */ /** @type Sequelize */

View File

@ -1,5 +1,12 @@
#!/bin/bash #!/bin/bash
if [ ! -f .env ]; then
echo "No .env; Please create .env and try again"
exit
fi
. '.env'
cp docker-compose.prod docker-compose.yml cp docker-compose.prod docker-compose.yml
cp Dockerfile.prod Dockerfile cp Dockerfile.prod Dockerfile

View File

@ -0,0 +1,37 @@
import { Terminal } from 'xterm';
import { saveAs } from 'file-saver';
const fs = require('../fs');
/**
*
* @param { string[] } argv
* @param { Terminal } terminal
*/
module.exports = (argv, terminal) => {
if (argv.indexOf('--help') != -1) {
terminal.write(
`Usage: ${argv[0]} [DESTANATION]\n
Import files from your system to this filesystem.
`
);
return;
}
let el = document.getElementById('upload_file_btn');
if (el == null) {
el = document.createElement('input');
el.style.display = 'none';
el.type = 'file';
el.id = 'upload_file_btn';
el.setAttribute('multiple', 'multiple');
document.body.appendChild(el);
}
const dir = argv[1] || '.';
el.click();
let files = el.files;
global.f = files
}

View File

@ -8,6 +8,7 @@ let cmds = {
'mkdir': require('./mkdir'), 'mkdir': require('./mkdir'),
'wget': require('./wget'), 'wget': require('./wget'),
'export_file': require('./export_file'), 'export_file': require('./export_file'),
'import_file': require('./import_file'),
// alias l='ls -l' // alias l='ls -l'
'l': (a,t) => {require('./ls')([...a, '-l'], t)}, 'l': (a,t) => {require('./ls')([...a, '-l'], t)},

View File

@ -107,8 +107,9 @@ function reset_cmd() {
} }
function cbackspace() { function cbackspace() {
let exploded = cmd.split(' '); let exploded = cmd.substring(0, cmd.length - 2).split(' ');
if (exploded.length >= 1) {
if (exploded.length == 1) {
reprint_prompt(); reprint_prompt();
cmd = ''; cmd = '';
return; return;

View File

@ -1,4 +1,5 @@
const handler = require('express-async-handler'); const handler = require('express-async-handler');
const Helpers = require('../helpers');
async function project(req, res) { async function project(req, res) {
res.template( res.template(

View File

@ -1,53 +1,3 @@
const crypto = require('crypto'); const { exec } = require('child_process');
const path = require('path');
const args = require('args-parser')(process.argv);
const fs = require('fs');
const base64 = require('js-base64');
let key = crypto.randomFillSync(Buffer.alloc(32)).toString('base64'); exec('generate_key.py');
let dotenv = path.resolve('.env');
if (args['help']) {
console.log(path.basename(__filename) + ' [--key-only] [--env|-e] [--set-key] [--dry-run] [--stdout|-s]');
console.log('\n' +
' --help: Display this help\n' +
' --key-only: Generate key only and put it in stdout\n' +
' --env -e: Specify an env file\n' +
' --set-key: Specify your key\n' +
' --dry-run: Don\'t write anything, just do the thing\n' +
' --stdout -s: Don\'t write to file, write to stdout instead'
);
process.exit(0);
}
if (args['key-only']) {
console.log(key);
process.exit(0);
}
if (args['env'] || args['e']) {
dotenv = args['env'] ? args['env'] : args['e'];
}
if (args['set-key']) {
key = args['set-key'];
}
const file = fs.readFileSync(dotenv).toString('utf8');
let lines = file.split('\n');
for (let i = 0; i != lines.length; i++) {
let line = lines[i];
if (line.startsWith('APP_KEY=')) {
lines[i] = 'APP_KEY=' + key;
}
}
const newfile = lines.join('\n');
const w_stdout = args['stdout'] || args['s'];
if (!args['dry-run']) {
if (w_stdout) console.log(newfile);
else
fs.writeFileSync(dotenv, newfile);
}

24
scripts/generate_key.py Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
import os
import secrets
import base64
if (not os.path.exists('.env')):
print('No .env file found. Please create a dotenv to proceed.');
exit(-1);
key_bytes = secrets.token_bytes(32);
dotenv_text = '';
with open('.env', 'tr', encoding='utf-8') as f:
dotenv_text = f.read();
dotenv_lines = dotenv_text.split('\n');
key_line = 0;
for i, line in enumerate(dotenv_lines):
if (line.startswith('APP_KEY=')):
dotenv_lines[i] = 'APP_KEY=' + base64.b64encode(key_bytes).decode('utf-8');
with open('.env', 'tw', encoding='utf-8') as f: print('\n'.join(dotenv_lines), file=f)