home and login pages, support lib, components folder

master
Cristiano Pires 2 years ago
parent 7aba6aa58e
commit 074e186b0e

@ -0,0 +1,813 @@
const mysql = require('mysql')
const Spawner = require('child_process');
const crypto = require('crypto');
const request = require('request');
const cheerio = require('cheerio');
class Child
{
/**
*
* @param {String} userID -User's Hash
*/
constructor(userID)
{
this.ID = userID;
this.child = Spawner.fork('./worker.js',[this.ID]);
this.birth = process.uptime();
this.timeOut = setTimeout(() => {
this.child.kill('SIGINT');
},2*60*60*1000);
}
get EOL()
{
const EOL = Math.trunc((this.timeOut._idleTimeout - ((process.uptime()*1000)-this.birth))/1000);
return EOL>0?EOL:0;
}
getMapData()
{
return new Promise((resolve, reject)=>
{
this.child.send('MapData');
this.child.on('message', m=>
{
if(typeof m == Object)
{
resolve(m.name);
}
})
})
}
waitStart()
{
return new Promise((resolve, reject)=>
{
var status = setInterval(() => {
if(this.isOpen)
{
clearInterval(status);
resolve(true)
}
}, 100);
})
}
createMapImage()
{
return new Promise((resolve, reject)=>
{
this.child.send('MapImage')
this.child.on('message', m=>
{
if(typeof m == String && m === 'Done')
{
resolve(m);
}
})
})
}
getConsole()
{
return new Promise((resolve, reject)=>
{
this.child.send('Console')
this.child.on('message', m=>
{
resolve(m);
})
})
}
}module.exports.Child = Child;
class playerCache
{
/**
*
* @param {String} Name
* @param {String} SteamID
* @param {Number} Ping
* @param {String} Address IP
* @param {Number} ConnectedSeconds
* @param {Number} Health
* @param {Object} Teammates ??'Not in a team'
* @param {String} Position ??'Not spawned yet'
*/
constructor(Name, SteamID, Ping, Address,ConnectedSeconds, Health, Teammates, Position)
{
this.Displayname = Name;
this.SteamID = SteamID;
this.Address = Address;
this.Health = Health;
this.Teammates = Teammates??'NOT IN A TEAM';
this.Position = Position??'NOT SPAWNED YET';
this.Ping = Ping;
this.ConnectedSeconds = ConnectedSeconds;
}
}module.exports.playerCache = playerCache;
class ServerCache
{
constructor(ID,Hostname,MaxPlayers, GameTime, Framerate, NetworkIn, NetworkOut, Seed, WorldSize)
{
this.ID = ID;
this.Hostname=Hostname;
this.MaxPlayers =MaxPlayers;
this.GameTime = GameTime;
this.Framerate = Framerate;
this.NetworkIn = NetworkIn;
this.NetworkOut = NetworkOut;
this.Seed = Seed;
this.WorldSize = WorldSize;
this.Console = [];
}
get WorldData ()
{
return {
Seed:this.Seed,
Size:this.WorldSize,
Time:this.GameTime
}
}
get NetWorkData ()
{
return {
Framerate:this.Framerate,
In:this.NetworkIn,
Out:this.NetworkIn
}
}
get ConsoleData ()
{
return this.Console;
}
get BasicData ()
{
return {
HostName:this.Hostname,
MaxPlayers:this.MaxPlayers,
GameTime:this.GameTime
}
}
}module.exports.ServerCache = ServerCache;
class pChild
{
constructor(ip, port, pw)
{
this.ip = ip;
this.port = port;
this.pw = pw;
this.child = Spawner.fork('./pWorker.js');
}
/**
* @argument {*} - Anything
*/
sendData()
{
for (var i = 0; i < arguments.length; i++)
{
}
}
/**
* To be used with programmed commands
* @param {String} command - Command to be sent
*/
send(command)
{
return new Promise((resolve, reject)=>
{
this.child.send({'command':command, 'ip':this.ip, 'port':this.port, 'pw':this.pw});
this.child.on('message', (m)=>
{
if(typeof m=='string')
{
if(m ==='end')
{
resolve();
}
}
else
{
reject("Worker didn't respond to querry.")
}
})
})
}
close ()
{
return new Promise((resolve, reject)=>
{
resolve(this.child.disconnect());
})
}
}module.exports.pChild = pChild;
class rustChild
{
constructor(size, seed)
{
this.child = Spawner.exec(`cmd /c updateServer.bat ${size} ${seed}`)
}
}module.exports.rustChild = rustChild;
class DBConnection
{
constructor()
{
this.connection = mysql.createConnection(
{
host:'localhost',
user:'root',
password:'root',
database:'legendary'
})
this.connection.connect();
}
close()
{
setTimeout(() =>
{
this.connection.destroy();
}, 2000);
}
//User
get Users()
{
return new Promise((resolve, reject)=>
{
this.connection.query('Select * from administrator', (e, r, f)=>
{
if(!e)
{
let aux = JSON.parse(JSON.stringify(r))
var payload =[];
for( var i = 0; i<aux.length; i++)
{
payload.push(aux[i].Hash)
}
resolve(payload);
this.close();
}
else
{
reject(e)
this.close();
}
});
})
}
hasSVData(Hash)
{
return new Promise((resolve, reject)=>
{
this.UData(Hash).then(
m=>
{
if(m.Server=='No server')
{
reject(false)
}
else
{
resolve(true)
}
}
)
})
}
UData(HASH)
{
return new Promise((resolve, reject)=>
{
this.connection.query(`SELECT * FROM administrator WHERE Hash = '${HASH}' `, (e, r, f)=>
{
if(e)reject(e);
r = JSON.parse(JSON.stringify(r))[0];
resolve({
id:r.A_ID,
Hash:r.Hash,
Email:r.EHash,
Server:r.IP || 'No server',
Port: JSON.stringify(r.Port) || 'No server',
SPW:r.sv_pw,
Epoch:r.Epoch
})
this.close();
})
})
}
get_ID(hash)
{
return new Promise((resolve, reject)=>
{
//User
this.Users.then((x)=>
{
for(var i =0; i<x.length; i++)
{
if(x[i]==hash)
{
this.UData(hash).then((m)=>
{
resolve(m.id);
})
.catch(()=>reject('no ID for this hash'))
}
}
}).catch(m=>
{
console.log(m);
reject('no ID for this HASH');
});
})
}
getCommands(Hash)
{
return new Promise((resolve, reject)=>
{
this.get_ID(Hash).then(id=>
{
this.connection.query(`Select * from legendary.timed_com where administrator_A_ID = '${id}'`, (e, r, f)=>
{
if(e)reject(e);
resolve(JSON.parse(JSON.stringify(r)));
})
})
})
}
addCommand(Hash, Command, Loop, Send, tz)
{
this.get_ID(Hash).then(id=>
{
this.connection.query(`INSERT INTO legendary.timed_com (\`Command\`, \`Loop\`, \`Send\`, \`administrator_A_ID\`) VALUES ('${Command}', '${Loop}', '${Send}', '${id}')`);
this.close();
})
}
removeCommand(id)
{
return new Promise((resolve, reject)=>
{
this.connection.query(`DELETE FROM legendary.timed_com WHERE (T_ID = ${id});`, (e, r, f)=>
{
if(e)reject(e)
if(r.affectedRows>0)resolve()
})
this.close()
})
}
editCommand(id, Command, Loop, Send, tz)
{
this.connection.query(`UPDATE legendary.timed_com SET \`Command\` = '${Command}', \`Loop\` = '${Loop}',\`Send\` = '${Send}' WHERE (T_ID = '${id}')`)
this.close()
}
addUser(Hash, EHash, Epoch)
{
if(Hash||EHash||Epoch)
{
this.connection.query(`INSERT INTO legendary.administrator (Hash, EHash, Epoch) VALUES ('${Hash}', '${EHash}', '${Epoch}')`)
this.close()
}
}
updateUser(HASH, NewHASH)
{
return new Promise((resolve, reject)=>
{
this.get_ID(HASH).then((m)=>
{
this.connection.query(`UPDATE administrator SET Hash='${NewHASH}' WHERE A_ID = ${m}`);
this.close();
resolve(NewHASH);
}).catch((err)=>reject(err));
})
}
addServer(HASH, IP, PW, PORT)
{
//needs to know what user should it be connected to
this.connection.query(`INSERT INTO adminsitrator (ServerIP, ServerPW, ServerPort) VALUES ('${HASH}', '${IP}','${PW}', '${PORT}')`)
this.close();
}
updateServer(Hash, IP, PW, PORT)
{
this.get_ID(Hash).then((id)=>
{
this.connection.query(`UPDATE administrator SET IP = '${IP}', sv_pw = '${PW}', port='${PORT}' WHERE A_ID = ${id}`);
this.close();
}).catch(e=>console.log('error',e))
}
get_Players(Hash)
{
return new Promise((resolve, reject)=>
{
this.connection.query(`SELECT * FROM player INNER JOIN time ON player.p_id = time.player_p_id
where administrator_a_id = (SELECT A_ID FROM administrator WHERE Hash = '${Hash}')
order by player_p_id asc;`,(e,r,f)=>
{
if(e)reject(e);this.close;
try
{
// console.log('Classes: DBConnection: Get_Players: r: ', r);
r = JSON.parse(JSON.stringify(r));
resolve(r)
} catch (err)
{
reject(err)
}
this.close;
})
})
}
}module.exports.DBConnection = DBConnection;
class _Crypto
{
constructor(User, Password)
{
this.salt = 'H$44Q3RVCd9X8Ef63tB4';
this.secret = 'mYFUZX9NSx7K74r7Jh@O';
this.pepper = String.fromCharCode(this.getRandomInt(65, 90));
this.password = Password;
this.user = User;
this.algorithm = 'aes-192-cbc';
}
get Hash() // to use on register
{
return this.hash()
}
hash(p)
{
if(!p)
{
return crypto.createHmac('sha256', this.secret).update(this.user+this.password+this.salt+this.pepper).digest('hex');
}
else
{
return crypto.createHmac('sha256', this.secret).update(this.user+this.password+this.salt+p).digest('hex');
}
}
eHash(Email)
{
return new Buffer.from(Email).toString('base64');
}
decrypt(eHash)
{
return new Buffer.from(eHash, 'base64').toString('utf8');
}
getRandomInt(min, max)
{
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
compare() // to use on login
{
return new Promise((resolve, reject)=>
{
new DBConnection().Users
.then((Users)=>
{
for(var i=0; i<26;i++)
{
const nPepper = String.fromCharCode(65+i);
const hash = this.hash(nPepper);
for(var j = 0; j<Users.length; j++)
{
if(Users[j]==hash) resolve(hash);
}
}
reject(false);
})
.catch((m)=>
{
console.log('error'+m);
})
});
}
}module.exports._Crypto = _Crypto;
class Epoch
{
/**
*
* @param {Number} Days - Must be and integer.
*/
constructor(Days)
{
this.Days = (Days*(24*60*60));
this.epoch = this.epocher();
}
epocher()
{
return Math.floor(this.Days + Date.now()/1000)
}
/**
* @param {String} time - Must follow the format of '18:12'.
*/
sEpoch(time)
{
let hours = time.split(':')[0];
let minutes = time.split(':')[1];
return Math.floor(this.next(hours, minutes)/1000);
}
/**
* @param {Number} time - Must be and integer.
*/
toDate(time)
{
//console.log('classes:toDate:', time)
const d = new Date(time*1000);
return d.getHours()+':'+ d.getMinutes();
}
/**
* Returns the next possible time for the command to be sent. Meaning if the hours inputed by the user
* have already gone past this day then the epoch will be set for the next.
* If not the epoch will be created like usual.
*
* @param {Number} hours
* @param {Number} minutes
*/
next(hours, minutes)
{
var d= new Date();
var payload = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), hours, minutes, 0, 0).getTime();
//console.log('Classes:Next:',hours, minutes, payload)
return payload;
}
}module.exports.Epoch = Epoch;
class IPTranslator
{
constructor(IP)
{
this.IP = IP;
}
translate()
{
return new Promise((resolve, reject)=>
{
request(`http://ip-api.com/json/${this.IP}`, (e,r,b)=>
{
var body
if(!e)
{
try {
body = JSON.parse(b);
} catch (error) {
console.log('IP Transalator: Bad Parse.');
resolve('Err')
}
resolve(body);
}
else
{
resolve( {'status':'error'});
}
})
})
}
CC()
{
return new Promise((resolve, reject)=>
{
this.translate().then(m=>resolve(m.countryCode)).catch(e=>
{
console.log('IP Translator: CountryCode:'+e);
reject(e);
})
})
}
}module.exports.IPTranslator = IPTranslator;
class VAC
{
constructor(SteamID)
{
this.SteamID = SteamID;
}
get ban()
{
return new Promise((resolve,reject)=>
{
request(`http://vacbanned.com/engine/check?qsearch=${this.SteamID}`, (e,r,b)=>
{
if(e)reject('VAC: Request:'+e)
const $ = cheerio.load(b);
// console.log('Worker: VAC: body: ', $('td').text());
$('.strong').remove()
request(`http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=DCA47FAA9F3D1485FA8C1F4FA15A5266&steamid=${this.SteamID}&format=json`, (e,r,steamb)=>
{
if(e)reject('VAC: FS: Request:'+e)
var fs;
let aux
//console.log('Vac class: SteamAPI', steamb)
try
{
aux = JSON.parse(steamb)['response'].games;
} catch (error)
{
console.log('JSON parse error: ',error);
}
if(aux)
{
for (let i = 0; i < aux.length; i++)
{
// console.log('VAC: FS: Request2: '+aux[i].appid, '252490');
if(aux[i].appid)
{
if(aux[i].appid=='252490')
{
i = aux.length;
fs = 'NO'
}
else
{
fs='Yes'
}
}
}
var vac;
try {
vac = $('td').text().replace(/ /g, '').split('Hex)')[1].replace(/\n/g, 'SPLIT').split('SPLIT')[1];
} catch (error) {
vac = 'Error';
}
let payload = {
'vac':vac,
'fs':fs
}
// console.log('VAC: Payload: ', payload)
resolve(payload);
}
else
{
var vac;
try {
vac = $('td').text().replace(/ /g, '').split('Hex)')[1].replace(/\n/g, 'SPLIT').split('SPLIT')[1];
} catch (error) {
vac = 'Error';
}
let payload = {
'vac':vac,
'fs':fs
}
resolve(payload);
}
})
});
})
}
}module.exports.VAC = VAC;
/**
* Use it to transform an hour value into miliseconds.
* @param {Number} Hours - Hours to transform
*/
function hours(Hours)
{
return Hours*60*60*1000;
}
/**
* This function writes a cookie on the client side.
* Primary use: Store users Hash for every other page.
* @argument {Response} res - Response: express response object.
* @argument {String} name - Name of the cookie.
* @argument {*} value - Value of the cookie.
*/
exports.baker = (res, name, value) =>
{
return new Promise((resolve,reject)=>
{
try
{
res.cookie(name, '',{maxAge:0});
res.cookie(name, value, {maxAge:hours(2),path:'/',secure:false,httpOnly:false});
resolve();
}
catch (e)
{
reject(e)
}
})
}
/**
* Hash used on register to check if there is already a user with the same credentials.
* @param {String} user - User's email
* @param {String} password - User's Password
* @param {String} hash - User's identifying hash
*/
exports.bouncer = (user, password, hash) =>
{
return new Promise((resolve, reject)=>
{
new _Crypto(user, password).compare().then(m=>
{
if(hash)
{
if(m==hash)
{
resolve(m)
}
else
{
reject('You are on a different account.')
}
}
else
{
resolve(m)
}
}).catch(m=>
{
reject(m)
})
})
}
/**
* Reduces the number of decimal cases to the required value.
* @param {Number} num - The number you want to cut to size.
* @param {Number} decimal - Ammount of decimal cases.
*/
exports.toFixed = (num, decimal)=>
{
decimal = decimal || 0;
decimal = Math.pow(10, decimal);
return Math.floor(num * decimal) / decimal;
}
/**
* Transforms a value into a 0-1 value given the max value it could take.
* @param {Number} val - Value to transform to percentage
* @param {Number} max - Maximum the value could be
*/
exports.toPercent = (val, max)=>
{
return val/max;
}
/**
* Removes the timezone difference to a time.
* @param {String} time - Must follow 'HH:MM' format.
* @param {Number} offSet - Number of minutes from gmt+0.
*/
exports.removeTZ = (time, offSet)=>
{
var h = parseInt(time.split(':')[0]);
var maux = parseInt(time.split(':')[1]);
var m = maux - offSet;
var d = new Date();
var payload = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), h, m, 0, 0).toString().split(' ')[4].split(' ')[0].slice(0,-3);
return payload;
}
/**
* Adds timezone difference to a time.
* @param {String} time - Must follow 'HH:MM' format.
* @param {Number} offset - Number of minutes from gmt+0.
*/
exports.addTZ = (time, offset) =>
{
offset = parseInt(offset);
let h = parseInt(time.split(':')[0]);
let m = parseInt(time.split(':')[1])+offset;
var d= new Date();
return payload = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDay(), h, m, 0, 0).toString().split(' ')[4].split(' ')[0].slice(0,-3);
}

54
package-lock.json generated

@ -12,6 +12,9 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.2",
"crypto": "^1.0.1",
"eslint-config-react-app": "^7.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
@ -3317,6 +3320,16 @@
}
}
},
"node_modules/@popperjs/core": {
"version": "2.11.8",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
"integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==",
"peer": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/popperjs"
}
},
"node_modules/@rollup/plugin-babel": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz",
@ -5843,6 +5856,24 @@
"optional": true,
"peer": true
},
"node_modules/bootstrap": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.2.tgz",
"integrity": "sha512-D32nmNWiQHo94BKHLmOrdjlL05q1c8oxbtBphQFb9Z5to6eGRDCm0QgeaZ4zFBHzfg2++rqa2JkqCcxDy0sH0g==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/twbs"
},
{
"type": "opencollective",
"url": "https://opencollective.com/bootstrap"
}
],
"peerDependencies": {
"@popperjs/core": "^2.11.8"
}
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -6452,6 +6483,12 @@
"node": ">= 8"
}
},
"node_modules/crypto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
"deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in."
},
"node_modules/crypto-random-string": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",
@ -20652,6 +20689,12 @@
"source-map": "^0.7.3"
}
},
"@popperjs/core": {
"version": "2.11.8",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
"integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==",
"peer": true
},
"@rollup/plugin-babel": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz",
@ -22576,6 +22619,12 @@
"optional": true,
"peer": true
},
"bootstrap": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.2.tgz",
"integrity": "sha512-D32nmNWiQHo94BKHLmOrdjlL05q1c8oxbtBphQFb9Z5to6eGRDCm0QgeaZ4zFBHzfg2++rqa2JkqCcxDy0sH0g==",
"requires": {}
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -23019,6 +23068,11 @@
"which": "^2.0.1"
}
},
"crypto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig=="
},
"crypto-random-string": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz",

@ -9,6 +9,8 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.2",
"crypto": "^1.0.1",
"eslint-config-react-app": "^7.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
@ -39,5 +41,8 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"browser": {
"crypto": false
}
}

@ -7,18 +7,24 @@ const ipc = {
'close',
'maximize',
'minimze',
'login',
'register',
],
// From main to render.
'receive': [
'close',
'maximize',
'minimze',
'login',
'register',
],
// From render to main and back again.
'sendReceive':[
'close',
'maximize',
'minimze',
'login',
'register',
]
}
};

@ -1,38 +0,0 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@ -1,25 +0,0 @@
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;

@ -1,8 +0,0 @@
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

@ -0,0 +1,43 @@
.Frame
{
display: flex;
justify-content: flex-end;
position: fixed;
left:0%;
width: 100%;
height: auto;
-webkit-user-select: none;
gap: 1px;
}
.Title
{
border: 1px solid rgba(240, 248, 255, 0);
width: 100%;
-webkit-app-region: drag;
color:ivory;
font-weight: bold;
font-family:Verdana, Geneva, Tahoma, sans-serif;
font-size: small;
padding-left: 1em;
padding-top: 0.25em;
}
.btControl
{
background-color: rgb(22, 27, 28);
width: 20px;
height: 20px;
border: 1px solid black;
cursor: pointer;
font-weight: bold;
text-align: center;
vertical-align: middle;
color:ivory;
}
span {
position: relative;
top:-23%;
}

@ -7,9 +7,10 @@ function Controls() {
return (
<div className="Frame">
<div className='minimize' onClick={minimize}><span>_</span></div>
<div className='Maximize' onClick={maximize}><span>-</span></div>
<div className='Close' onClick={close}><span>X</span></div>
<div className='Title'>Legendary</div>
<div className='minimize btControl' onClick={minimize}><span>_</span></div>
<div className='Maximize btControl' onClick={maximize}><span>-</span></div>
<div className='Close btControl' onClick={close}><span>X</span></div>
</div>
);
}

@ -0,0 +1,40 @@
.container
{
position: relative;
width: 14em;
top: 15em;
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: stretch;
text-align: center;
}
span
{
font-weight: bold;
color:ivory;
text-align: center;
}
.bt
{
width: auto;
height: 2em;
background-color: rgba(0, 0, 0, 0);
border: 1px solid rgba(0, 0, 0, 0);
color:ivory;
font-weight: bold;
cursor: pointer;
}
.Login
{
float:left;
position: relative;
left:2em;
}
.Register
{
float:right;
position: relative;
right: 1em;
}

@ -2,8 +2,15 @@ import './Login.css';
function Login()
{
function sendForm(formData)
{
window.ipcRender.send('login', formData)
}
function callRegister()
{
window.ipcRender.send('register')
}
return(
<div className='container'>
@ -12,6 +19,8 @@ function Login()
<input className='emailImput'></input>
<label><span>Password</span></label>
<input className='password'></input>
<button className='bt Login' onClick={sendForm(this)}>Login</button>
<button className='bt Register' onClick={callRegister}> Register</button>
</form>
</div>
)

@ -1,43 +0,0 @@
.Frame
{
display: flex;
position: fixed;
right: 0%;
}
.minimize
{
width: 20px;
height: 20px;
border: 1px solid black;
cursor: pointer;
font-weight: bold;
text-align: center;
color:ivory;
}
.Maximize
{
width: 20px;
height: 20px;
border: 1px solid black;
font-weight: bold;
text-align: center;
cursor: pointer;
color:ivory;
}
.Close
{
width: 20px;
height: 20px;
border: 1px solid black;
cursor: pointer;
font-weight: bold;
text-align: center;
vertical-align: middle;
color:ivory;
}
span {
position: relative;
top:-23%;
}

@ -0,0 +1,19 @@
import Login from "../Components/Login";
const { cookieSlicer } = require("../lib");
function Home() {
var Hash = cookieSlicer(document.cookie,'Hash');
console.log(Hash)
return (
<div className="BODY">
{Hash ? (
<h1>Welcome back!</h1>
//TODO: Actual Page
) : (
<Login/>
)}
</div>
);
}
export default Home;

@ -4,16 +4,14 @@ import { createRoot } from "react-dom/client";
import 'bootstrap/dist/css/bootstrap.min.css'
import './index.css'
import App from './App'
import Controls from './Controls'
import Login from './Login'
import Controls from './Components/Controls'
import Home from './Pages/Home'
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
console.log(document.cookie)
root.render(
<StrictMode>
<Controls />
<Login />
<Home />
</StrictMode>
);

@ -0,0 +1,176 @@
import crypto from 'crypto';
export class _Crypto
{
constructor(User, Password)
{
this.salt = 'H$44Q3RVCd9X8Ef63tB4';
this.secret = 'mYFUZX9NSx7K74r7Jh@O';
this.pepper = String.fromCharCode(this.getRandomInt(65, 90));
this.password = Password;
this.user = User;
this.algorithm = 'aes-192-cbc';
}
get Hash() // to use on register
{
return this.hash()
}
hash(p)
{
return crypto.createHmac('sha256', this.secret).update(this.user+this.password+this.salt + (p?p:this.pepper) ).digest('hex');
}
eHash(Email)
{
return new Buffer.from(Email).toString('base64');
}
decrypt(eHash)
{
return new Buffer.from(eHash, 'base64').toString('utf8');
}
getRandomInt(min, max)
{
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
//TODO: compare(hash)
//Get hash from db run through the peper possibilties and see if there is a match.
//return hash if true, null if false
}
export class Epoch
{
/**
*
* @param {Number} Days - Must be and integer.
*/
constructor(Days)
{
this.Days = (Days*(24*60*60));
this.epoch = this.epocher();
}
epocher()
{
return Math.floor(this.Days + Date.now()/1000)
}
/**
* @param {String} time - Must follow the format of '18:12'.
*/
sEpoch(time)
{
let hours = time.split(':')[0];
let minutes = time.split(':')[1];
return Math.floor(this.next(hours, minutes)/1000);
}
/**
* @param {Number} time - Must be and integer.
*/
toDate(time)
{
//console.log('classes:toDate:', time)
const d = new Date(time*1000);
return d.getHours()+':'+ d.getMinutes();
}
/**
* Returns the next possible time for the command to be sent. Meaning if the hours inputed by the user
* have already gone past this day then the epoch will be set for the next.
* If not the epoch will be created like usual.
*
* @param {Number} hours
* @param {Number} minutes
*/
next(hours, minutes)
{
var d= new Date();
var payload = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), hours, minutes, 0, 0).getTime();
//console.log('Classes:Next:',hours, minutes, payload)
return payload;
}
}
/**
* Use it to transform an hour value into miliseconds.
* @param {Number} Hours - Hours to transform
*/
function hours(Hours)
{
return Hours*60*60*1000;
}
/**
* This function writes a cookie on the client side.
* Primary use: Store users Hash for every other page.
* @argument {Response} res - Response: express response object.
* @argument {String} name - Name of the cookie.
* @argument {*} value - Value of the cookie.
*/
export function baker(res, name, value)
{
return new Promise((resolve,reject)=>
{
try
{
res.cookie(name, '',{maxAge:0});
res.cookie(name, value, {maxAge:hours(2),path:'/',secure:false,httpOnly:false});
resolve();
}
catch (e)
{
reject(e)
}
})
}
/**
* Hash used on register to check if there is already a user with the same credentials.
* @param {String} user - User's email
* @param {String} password - User's Password
* @param {String} hash - User's identifying hash
*/
export function bouncer (user, password, hash)
{
return new Promise((resolve, reject)=>
{
//!Crypto compare needs to be reworked so this is legacy code not supposed to work
// new _Crypto(user, password).compare().then(m=>
// {
// if(hash)
// {
// if(m==hash)
// {
// resolve(m)
// }
// else
// {
// reject('You are on a different account.')
// }
// }
// else
// {
// resolve(m)
// }
// }).catch(m=>
// {
// reject(m)
// })
})
}
export function cookieSlicer(cookie, id)
{
cookie = cookie.split(';');
var result = new Map();
for(var item of cookie)
{
let aux = item.split('=');
result.set(aux[0], aux[1]);
}
return id?result.get(id):result;
}

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

16163
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save