This commit is contained in:
CICD - Pipeline 2023-02-18 22:09:04 +01:00
parent 6c861a6d78
commit 4f022a0d97
33 changed files with 5415 additions and 173 deletions

View File

@ -1,92 +0,0 @@
# Neutral
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.com/raphixscrap/neutral.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.com/raphixscrap/neutral/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

20
app.js
View File

@ -2,10 +2,18 @@ var createError = require('http-errors');
var express = require('express'); var express = require('express');
var path = require('path'); var path = require('path');
var cookieParser = require('cookie-parser'); var cookieParser = require('cookie-parser');
var favicon = require('express-favicon');
var logger = require('morgan'); var logger = require('morgan');
var fs = require("fs")
var uuid = require('uuid');
var CryptoJS = require("crypto-js")
var indexRouter = require('./routes/index'); var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users'); var loginRouter = require('./routes/login');
var signoutRouter = require('./routes/signout');
var app = express(); var app = express();
@ -18,9 +26,13 @@ app.use(express.json());
app.use(express.urlencoded({ extended: false })); app.use(express.urlencoded({ extended: false }));
app.use(cookieParser()); app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
app.use(favicon(path.join(__dirname + '/public/' + 'favicon.ico')))
app.use('/', indexRouter); app.use('/', indexRouter);
app.use('/users', usersRouter); app.use('/login', loginRouter);
app.use('/signout', signoutRouter);
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {
@ -38,4 +50,8 @@ app.use(function(err, req, res, next) {
res.render('error'); res.render('error');
}); });
module.exports = app; module.exports = app;

View File

@ -12,7 +12,7 @@ var http = require('http');
* Get port from environment and store in Express. * Get port from environment and store in Express.
*/ */
var port = normalizePort(process.env.PORT || '3000'); var port = normalizePort(process.env.PORT || '80');
app.set('port', port); app.set('port', port);
/** /**

121
neutral-functions.js Normal file
View File

@ -0,0 +1,121 @@
var fs = require("fs")
var uuid = require('uuid')
var path = require("path")
var CryptoJS = require("crypto-js")
module.exports.createUser = (name, password) => {
const passcrypt = CryptoJS.AES.encrypt(password, "D*G-KaPdSgVkYp3s");
const userUUID = uuid.v4();
const userData = {
"username":name,
"password": passcrypt.toString(),
"uuid": userUUID,
"token":{
}
}
fs.writeFileSync(__dirname + path.sep + "users" + path.sep + userUUID + ".json", JSON.stringify(userData, null, 2))
}
module.exports.checkToken = (req, res) => {
const tokens = this.getAllToken()
const users = this.getUsers()
if(req.cookies.tokenID == null) {
return false;
} else if(tokens.has(req.cookies.tokenID)) {
const user = tokens.get(req.cookies.tokenID)
const userData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + users.get(user) + ".json"))
if(userData.token.livableToken == true) {
return user;
} else {
const tokenDate = new Date(userData.token.createdAt)
const nowDate = new Date(Date.now())
if(tokenDate.getDay() == nowDate.getDay() && tokenDate.getMonth() == nowDate.getMonth()) {
return user;
} else {
res.delete('tokenID');
return false;
}
}
} else {
return false;
}
return false;
}
module.exports.generateTokenID = (username, userData, req, users) => {
const tokenID = uuid.v4()
const date = Date.now()
var newUserData = userData;
var livable = false;
if(req.body.remindus == true) {
livable = true;
}
Object.defineProperties(newUserData, {
token: {
value: {
"tokenID":tokenID,
"livableToken": livable,
"createdAt": date
},
writable: true
}
})
fs.writeFileSync(__dirname + path.sep + "users" + path.sep + users.get(username) + ".json", JSON.stringify(newUserData, null, 2))
return tokenID
}
module.exports.getUsers = () => {
const users = new Map();
fs.readdirSync(__dirname + path.sep + "users").forEach(file => {
const fileData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + file))
users.set(fileData.username, fileData.uuid)
})
return users
}
module.exports.getAllToken = () => {
const token = new Map();
fs.readdirSync(__dirname + path.sep + "users").forEach(file => {
const fileData = JSON.parse(fs.readFileSync(__dirname + path.sep + "users" + path.sep + file))
token.set(fileData.token.tokenID, fileData.username)
})
return token
}

4833
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,42 @@
{ {
"name": "neutral", "name": "neutral",
"version": "0.0.0", "version": "DEV_1.0",
"private": true, "private": true,
"nodemonConfig": {
"ext": "js",
"ignore": [
"*.json"
],
"delay": "2"
},
"scripts": { "scripts": {
"start": "node ./bin/www" "start": "nodemon ./bin/www"
}, },
"dependencies": { "dependencies": {
"@popperjs/core": "^2.11.6",
"bootstrap": "^5.2.2",
"cookie-parser": "~1.4.4", "cookie-parser": "~1.4.4",
"crypto-js": "^4.1.1",
"debug": "~2.6.9", "debug": "~2.6.9",
"ejs": "~2.6.1", "ejs": "~2.6.1",
"express": "~4.16.1", "express": "~4.16.1",
"express-basic-auth": "^1.2.1",
"express-favicon": "^2.0.4",
"http-errors": "~1.6.3", "http-errors": "~1.6.3",
"morgan": "~1.9.1" "jquery": "^3.6.3",
"morgan": "~1.9.1",
"nodemon": "^2.0.20",
"uuid": "^9.0.0"
},
"devDependencies": {
"@fortawesome/fontawesome-free": "^6.2.1",
"autoprefixer": "^10.4.13",
"css-loader": "^6.7.1",
"postcss-loader": "^7.0.1",
"sass": "^1.56.1",
"sass-loader": "^13.1.0",
"style-loader": "^3.3.1",
"webpack": "^5.75.0",
"webpack-cli": "^4.10.0"
} }
} }

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

BIN
public/images/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
public/images/logo.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
public/images/minlogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
public/images/minlogo.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -0,0 +1,32 @@
const logoutBtn = document.getElementById("logout")
logoutBtn.addEventListener("click", () => {
fetch('/signout', {
method: 'GET',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
})
.then(response => response.json())
.then(response => redirect(response))
function redirect(response) {
if(response.success == true) {
window.location.href = "/login"
} else if(response.token == "auth_success") {
window.location.href = "/"
}
}
})

View File

@ -0,0 +1,57 @@
const userField = document.getElementById("username");
const passwordField = document.getElementById("password");
const remindus = document.getElementById("remindus");
const loginButton = document.getElementById("loginButton");
const info = document.getElementById("info");
loginButton.addEventListener("click", () => {
info.innerHTML = ""
const userValue = userField.value;
const passwordValue = passwordField.value;
if(userValue == "" | passwordValue == "") {
info.innerHTML = "Tous les champs doivent être remplis."
} else if(userValue.includes(" ")) {
info.innerHTML = "Le nom d'utilisateur ne peut pas contenir un espace"
} else {
const loginData = {
"username":userValue,
"password": passwordValue,
"remindus": remindus.checked
}
fetch('/login', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(loginData)
})
.then(response => response.json())
.then(response => redirect(response))
function redirect(response) {
if(response.token == "auth_failed") {
info.innerHTML = "Le nom d'utilisateur ou le mot de passe est éronné"
} else if(response.token == "auth_success") {
window.location.href = "/"
}
}
}
});

2
public/neutron.bundle.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,30 @@
/*!
* Bootstrap v5.2.3 (https://getbootstrap.com/)
* Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
/*!
* Sizzle CSS Selector Engine v2.3.9
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://js.foundation/
*
* Date: 2022-12-19
*/
/*!
* jQuery JavaScript Library v3.6.3
* https://jquery.com/
*
* Includes Sizzle.js
* https://sizzlejs.com/
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2022-12-20T21:28Z
*/

View File

@ -1,8 +1,123 @@
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap');
body { body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; background: rgb(58, 56, 56);
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
color: white;
} }
a { .content {
color: #00B7FF;
padding: 3%;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
@media (max-width: 768px) {
.box {
text-align: center;
padding: 5%;
width: 100%;
background-color: rgb(80, 80, 80);
border-radius: 1vw;
box-shadow: 5px 5px 5px rgba(80, 80, 80, 0.477) ;
}
}
@media (min-width: 768px) {
.box {
text-align: center;
padding: 5%;
width: 50%;
background-color: rgb(80, 80, 80);
border-radius: 1vw;
box-shadow: 5px 5px 5px rgba(80, 80, 80, 0.477) ;
}
}
.box form {
margin: 4%;
}
.box form input {
border-style: hidden;
border-radius: 1vw;
transition: all 0.2s ease 0s;
}
.box form input:hover {
box-shadow: 5px 5px 5px rgba(0, 174, 255, 0.477) ;
}
.box form .inp {
margin: 2%;
}
.box button {
border-style:solid;
border-radius: 1vw;
padding: 1%;
margin: 3%;
transition: all 0.2s ease 0s;
color: white;
background-color: transparent;
}
.box button:hover {
background: white;
color: black;
border-color: transparent;
box-shadow: 2px 2px 5px rgba(0, 174, 255, 0.477);
}
.box button:active {
border-style:solid;
border-radius: 1vw;
padding: 1%;
margin: 3%;
transition: all 0.2s ease 0s;
color: white;
background-color: transparent;
border-color: black;
box-shadow: none;
}
#remindus:hover {
box-shadow: 1px 1px 5px rgba(0, 174, 255, 0.477);
}
#info {
color: #ff0012;
font-size: larger;
} }

View File

@ -1,9 +1,24 @@
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
var ntr = require("../neutral-functions.js")
/* GET home page. */ /* GET home page. */
router.get('/', function(req, res, next) { router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
var check = ntr.checkToken(req, res)
if(check == false) {
res.redirect(302, "/login")
} else {
res.render('index', { title: check });
}
}); });
module.exports = router; module.exports = router;

76
routes/login.js Normal file
View File

@ -0,0 +1,76 @@
var express = require('express');
var router = express.Router();
var path = require("path")
var fs = require("fs")
var CryptoJS = require("crypto-js");
var uuid = require("uuid")
var ntr = require("../neutral-functions.js")
/* GET home page. */
router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res)
if(check != false) {
res.redirect(302, "/")
} else {
res.render('login', {error: ""});
}
});
router.post("/", function(req, res, next) {
const users = new Map();
fs.readdirSync(__dirname.replace("routes", "users")).forEach(file => {
const fileData = JSON.parse(fs.readFileSync(__dirname.replace("routes", "users") + path.sep + file))
users.set(fileData.username, fileData.uuid)
})
const bod = req.body
if(users.has(bod.username)) {
const userData = JSON.parse(fs.readFileSync(__dirname.replace("routes", "users") + path.sep + users.get(req.body.username) + ".json"))
var userpassword = CryptoJS.AES.decrypt(userData.password,"D*G-KaPdSgVkYp3s").toString(CryptoJS.enc.Utf8)
if(bod.password == userpassword) {
userpassword = null;
const tokenID = ntr.generateTokenID(bod.username, userData, req, users)
res.cookie('tokenID' , tokenID)
res.status(202).send({"token":"auth_success"})
} else {
userpassword = null;
res.status(202).send({"token":"auth_failed"})
}
} else {
res.status(202).send({"token":"auth_failed"})
}
})
module.exports = router;

24
routes/signout.js Normal file
View File

@ -0,0 +1,24 @@
var express = require('express');
var router = express.Router();
var ntr = require("../neutral-functions.js")
/* GET home page. */
router.get('/', function(req, res, next) {
var check = ntr.checkToken(req, res)
if(check == false) {
res.redirect(302, "/login")
} else {
res.clearCookie('tokenID')
res.send({"success":true})
}
});
module.exports = router;

11
src/js/main.js Normal file
View File

@ -0,0 +1,11 @@
// Import our custom CSS
import '../scss/styles.scss'
import '@fortawesome/fontawesome-free/css/all.css'
// Import all of Bootstrap's JS
import * as bootstrap from 'bootstrap'
import * as jquery from 'jquery'
console.log("Webpack Loaded");

1
src/scss/styles.scss Normal file
View File

@ -0,0 +1 @@
@import "~bootstrap/scss/bootstrap";

BIN
stuff/blogo.kra Normal file

Binary file not shown.

BIN
stuff/blogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
stuff/logo.kra Normal file

Binary file not shown.

BIN
stuff/logo.kra~ Normal file

Binary file not shown.

BIN
stuff/minblogo.kra Normal file

Binary file not shown.

BIN
stuff/minblogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
stuff/minlogo.kra Normal file

Binary file not shown.

BIN
stuff/minlogo.kra~ Normal file

Binary file not shown.

View File

@ -0,0 +1,10 @@
{
"username": "raphix",
"password": "U2FsdGVkX18qYuDgnMfjve6jokb1mqH1f7wuktw9YO8=",
"uuid": "9ace80e0-1ee3-4eed-924f-8a55fc55822b",
"token": {
"tokenID": "23e2178e-3ad0-400b-ae42-c8efa35de27c",
"livableToken": false,
"createdAt": 1676754468956
}
}

View File

@ -7,5 +7,7 @@
<body> <body>
<h1><%= title %></h1> <h1><%= title %></h1>
<p>Welcome to <%= title %></p> <p>Welcome to <%= title %></p>
<button id="logout">Deconnexion</button>
<script src="/javascripts/dashboard.js"></script>
</body> </body>
</html> </html>

37
views/login.ejs Normal file
View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>Neutron - Login</title>
<script src="neutron.bundle.js"></script>
<link rel='stylesheet' href='/stylesheets/style.css'>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<div class="content">
<div class="box mx-auto">
<img alt="logo" class="title w-100" src="/images/logo.png">
<form>
<div class="row inp">
<label class="col-lg-6" for="username">Nom d'utilisateur</label>
<input class="col-lg-6" id="username" type="text">
</div>
<div class="row inp">
<label class="col-lg-6" for="pasoswrd">Mot de passe</label>
<input class="col-lg-6" id="password" type="password">
</div>
</form>
<div>
<input id="remindus" type="checkbox">
<label for="remindus">Resté connecté</label>
</div>
<button id="loginButton">Connexion</button>
<p id="info"><%- error %></p>
<p>Pas de compte pour se connecter, demande à Raphix !</p>
</div>
</div>
<script src="/javascripts/loginscript.js"></script>
</body>
</html>

64
webpack.config.js Normal file
View File

@ -0,0 +1,64 @@
const path = require('path')
var webpack = require("webpack");
module.exports = {
entry: './src/js/main.js',
output: {
filename: 'neutron.bundle.js',
path: path.resolve(__dirname, 'public')
} ,
module: {
rules: [
{
test: /\.(scss)$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: () => [
require('autoprefixer')
]
}
}
},
{
loader: 'sass-loader'
}
]
}, {
test: /\.css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: () => [
require('autoprefixer')
]
}
}
}
]
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
}