1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-11-24 04:20:10 +01:00

The Bare-Minimum login

This commit is contained in:
Galexion 2023-02-16 18:50:32 -05:00
commit 22fd9e36ff
13 changed files with 4142 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
config.json
public/images
node_modules

83
index.js Normal file
View File

@ -0,0 +1,83 @@
const chokidar = require('chokidar');
const fs = require('fs');
const path = require('path');
var createError = require('http-errors');
var express = require('express');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var apiRouter = require('./routes/api');
var config = require("./config.json");
const watcher = chokidar.watch(config.DXMemorialImageDirectory, {
depth: 0,
persistent: true
});
watcher
.on('add', (filePath) => {
const isImage = /\.(jpe?g|png|gif)$/i.test(filePath);
if (isImage) {
const fileName = path.basename(filePath);
const destPath = path.join(config.imageFolder, fileName);
fs.access(destPath, (err) => {
if (err) {
fs.copyFile(filePath, destPath, (err) => {
if (err) throw err;
console.log(`${fileName} Imported.`);
});
} else {
}
});
}
})
.on('error', (error) => {
console.error(`Watcher error: ${error}`);
});
// readFileSync function must use __dirname get current directory
// require use ./ refer to current directory.
const options = {
};
var app = express()
// Create HTTPs server.
//var httpsServer = https.createServer(options, app);
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));
app.use(logger('dev'));
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.json({ extended: false }));
app.use('/', indexRouter);
app.use('/api/', apiRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
var PORT = process.env.PORT || 8000
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
app.listen(PORT, () => console.log(`Server is running in port ${PORT}`));
module.exports = app;

3797
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "aquaimagegrabber",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chokidar": "^3.5.3",
"cookie-parser": "^1.4.6",
"cross-fetch": "^3.1.5",
"ejs": "^3.1.8",
"express": "^4.18.2",
"fs": "^0.0.1-security",
"http-errors": "^2.0.0",
"morgan": "^1.10.0",
"path": "^0.12.7",
"sqlite3": "^5.1.4"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

View File

@ -0,0 +1,34 @@
#ACode {
width:225px;
}
#wrapper {
margin-top: -1%;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
height: auto;
}
#loginContent {
display: block;
margin-left: auto;
margin-right: auto;
margin: 1%;
}
h1 {
font-size: 3em;
}
h5 {
font-size: 1.3em;
}
h4 {
font-size: 1.5em;
}

22
readme.md Normal file
View File

@ -0,0 +1,22 @@
# Open Source MaiMaiDX.Net Interface
This is a Open Source MaiMaiDX.Net Interface.
### This Interface Requires a Server Database.
Currently, I only have access to AQUA, but ARTEMiS could be supported once AQUA support is finished.
# How to use:
## Aqua
Create a `config.json` file and paste this in, with paths to your instance.
```json
{
"DXMemorialImageDirectory": "A:\\path\\to\\aqua\\data",
"imageFolder": "N:\\MaiMaiDXNet\\public\\images"
}
```
Then, create the `/public/image/` folder. this will be where the images will be stored.

30
routes/api.js Normal file
View File

@ -0,0 +1,30 @@
var express = require('express');
var router = express.Router();
var fetch = require('cross-fetch');
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('A:\\db.sqlite');
router.post('/getExtId/', function (req, res, next) {
db.all('SELECT * FROM sega_card', (err, rows) => {
if (err) {
console.error(err);
// Return a Failed Message.
res.status(500).json({ error: err.message, status: "Failed" });
} else {
// Make the Request easier to get to.
var request = req.body;
var mUser = undefined // Leave the Matched User undefined until the user is found.
for (user of rows) { // For Each User in Rows
if (request.input === user.luid) { // If the Access Code for the card is in the system,
mUser = user; // set the Matched User Variable to the User, and break the for Loop.
break
}
}
// Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile.
res.status(200).json({ data: mUser, status: "Complete" });
}
});
});
module.exports = router;

42
routes/index.js Normal file
View File

@ -0,0 +1,42 @@
var express = require('express');
var router = express.Router();
var fetch = require('cross-fetch');
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('A:\\db.sqlite');
/* GET home page. */
var title = 'Webapp Mission Test'
router.get('/', function (req, res, next) {
db.all('SELECT * FROM sega_card', (err, rows) => {
if (err) {
console.error(err);
res.render('error', {error: err});
} else {
console.log(rows);
console.log(`There are Currently ${rows.length} Users Registered.`); // this check could probably be changed into an API
var params = {
totalUsers: rows.length
}
res.render('index', {title: title, params: params});
}
});
});
router.get('/user', function (req, res, next) {
db.all('SELECT * FROM sega_card', (err, rows) => {
if (err) {
console.error(err);
res.render('error', {error: err});
} else {
console.log(rows);
console.log(`There are Currently ${rows.length} Users Registered.`); // this check could probably be changed into an API
var params = {
totalUsers: rows.length
}
res.render('user', {title: title, params: params});
}
});
});
module.exports = router;

14
templates/header.ejs Normal file
View File

@ -0,0 +1,14 @@
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/stylesheets/style.css" rel="stylesheet" type="text/css">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#ef7408">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<body>

6
views/error.ejs Normal file
View File

@ -0,0 +1,6 @@
<% var rootPath='../' ; %>
<%- include(rootPath + 'templates/header.ejs' ); %>
<h1>Fuck. Something Went Wrong or you got 404'd.</h1>
<%=error%>
</body>
</html>

60
views/index.ejs Normal file
View File

@ -0,0 +1,60 @@
<% var rootPath='../' ; %>
<%- include(rootPath + 'templates/header.ejs' ); %>
<div id="wrapper">
<img src="MaiMaiDXNet/maimaidxex.jpg">
</div>
<div id="loginContent">
<h1>MaiMaiDX.Net</h1>
<h5>Total Users Registered: <%= params.totalUsers %>
</h5>
<h4>Please Input your 20 Digit Access Code.</h4>
<form id="myForm">
<input type="text" name="myInput" maxlength="20" placeholder="0000011111222223333344444" required>
<button type="submit">Submit</button>
</form>
<script>
const extId = localStorage.getItem('ext_id');
const luid = localStorage.getItem('luid');
if (extId === null || luid === null) {
console.log('User Data Not Detected! Please Sign In.');
} else {
console.log(`User Data Found! Redirecting to User Page.`);
window.location = "/user";
}
const form = document.getElementById("myForm");
form.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent the default form submission behavior
const input = document.getElementsByName("myInput")[0].value;
const url = "/api/getExtId"; // Replace with your API endpoint URL
// Send the input data to the API endpoint using fetch
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ input: input })
})
.then(response => response.json())
.then(data => {
console.log(data)
let releventData = { luid: data.data.luid, ext_id: data.data.ext_id }
console.log(releventData)
// Save data to local storage
localStorage.setItem('ext_id', data.data.ext_id);
localStorage.setItem('luid', data.data.luid);
window.location = "/user";
})
.catch(error => console.error(error));
});
</script> <!-- ToDo: Move this script to a seperate JS file.-->
</div>
</body>
</html>

28
views/user.ejs Normal file
View File

@ -0,0 +1,28 @@
<% var rootPath='../' ; %>
<%- include(rootPath + 'templates/header.ejs' ); %>
<h1>Yo! Welcome Back ${User}!</h1>
<button id="clear-storage-btn">Sign Out</button>
<script>
const extId = localStorage.getItem('ext_id');
const luid = localStorage.getItem('luid');
if (extId === null || luid === null) {
console.log('User Data Not Detected! Please Sign In.');
window.location = "/";
} else {
console.log(`User Data Found!`);
}
const clearStorageBtn = document.getElementById('clear-storage-btn');
clearStorageBtn.addEventListener('click', () => {
localStorage.removeItem('ext_id');
localStorage.removeItem('luid');
console.log('Local storage cleared.');
window.location = "/";
});
</script>
<details>
<summary>Developer Only Information</summary>
For Development purposes only, send statistics found in this menu when encontering UI Errors.
</details>