This commit is contained in:
2024-12-29 18:31:06 -05:00
parent 1b894dcc49
commit 0fb1e5583d
2 changed files with 40 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ const session = require('express-session');
const QRCode=require('qrcode');
const crypto=require('crypto');
const path=require('path');
const fs = require('fs');
const app = express();
app.set('view engine','ejs');
@@ -30,9 +31,9 @@ const QRSalt ="!SaltyMagic5392370662";
// + Send email when new tickets are issued/offered
// + Make one Update button on editcamp (Admin)
// + Make one Update button on manytickets (User)
// Turn ticket use on/off from Settings (Admin)
// Turn email on/off from Settings (Admin)
// Magic-link Login System
// + Turn ticket use on/off from Settings (Admin)
// + Turn email on/off from Settings (Admin)
// + Magic-link Login System
// Deactivate individual magic links (User)
// Deactivate individual magic links (Admin)
// See how much each camp/ticket has paid (Admin)
@@ -118,10 +119,10 @@ function MagicLinkValid(email,hash) {
// };
// const camps = { "habitat": { leader: "teppy@egenesis.com", lastid:6 } };
const users={};
const tickets={};
const camps={};
const settings={};
let users={};
let tickets={};
let camps={};
let settings={};
function InitDatabase() {
for (const key in users ) delete users[key];
@@ -132,6 +133,22 @@ function InitDatabase() {
}
InitDatabase();
function SerializeAll() {
const tables={ users, tickets, camps, settings };
fs.writeFileSync('foftickets.json', JSON.stringify(tables, null, 2), 'utf8');
}
function DeserializeAll() {
const data = fs.readFileSync('foftickets.json', 'utf8');
const tables = JSON.parse(data);
users=tables.users;
tickets=tables.tickets;
camps=tables.camps;
settings=tables.settings;
}
// Middleware setup
app.use(bodyParser.urlencoded({ extended: true }));
app.use(session({
@@ -542,6 +559,16 @@ app.post('/wipedb',requireSuperUser, (req,res) => {
res.render('settings',{ username:req.session.username, superuser:req.session.superuser, message: "Wiped the database, but not the logfile." })
});
app.post('/serialize',requireSuperUser, (req,res) => {
SerializeAll();
res.render('settings',{ username:req.session.username, superuser:req.session.superuser, message: "Wrote database to disk." })
});
app.post('/deserialize',requireSuperUser, (req,res) => {
DeserializeAll();
res.render('settings',{ username:req.session.username, superuser:req.session.superuser, message: "Read database from disk." })
});
app.post('/purge',requireSuperUser, (req,res) => {
let count=0;
for (const t in tickets) if (tickets[t].status=='r') { count++; delete tickets[t]; }

View File

@@ -16,6 +16,12 @@
<form action='/wipedb' method='post'>
<button type="submit" >Wipe the Database</button>
</form>
<form action='/serialize' method='post'>
<button type="submit" >Serialize</button>
</form>
<form action='/deserialize' method='post'>
<button type="submit" >Deserialize</button>
</form>
</div>
</body>
<script>