merge with master

This commit is contained in:
simplonco
2023-01-03 19:54:53 +01:00
10 changed files with 109 additions and 56 deletions

102
make_env.sh Normal file → Executable file
View File

@@ -2,6 +2,11 @@
ENV_FILE_DOCKER=./srcs/.env ENV_FILE_DOCKER=./srcs/.env
ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
NGINX_CONF_FILE=./srcs/requirements/nginx/conf/default.conf
BOLD_RED="\033[1;31m"
BOLD_GREEN="\033[1;32m"
BOLD_BLUE="\033[1;34m"
RESET="\033[0m"
# Function to generate passwords # Function to generate passwords
# #
@@ -13,9 +18,25 @@ ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
echo $(openssl rand -base64 32 | tr "/" "_" ); echo $(openssl rand -base64 32 | tr "/" "_" );
} }
function make_env_for_svelte
{
echo -e "${BOLD_BLUE}Creating a new environment for svelte${RESET}"
grep "^WEBSITE_" "$ENV_FILE_DOCKER" > "$ENV_FILE_SVELTE"
}
function update_nginx_conf
{
echo -e "${BOLD_BLUE}Updating the nginx conf${RESET}"
echo -e "${BOLD_RED}WARNING : If for some reason you've changed the port, you MUST change it inside the nginx conf file. It's not supposed to change.${RESET}"
HOST=$(grep "^WEBSITE_HOST" $ENV_FILE_DOCKER | cut -d "=" -f 2)
sed -i "s/server_name.*/server_name $HOST;/g" "$NGINX_CONF_FILE"
}
function make_env_for_docker_and_svelte function make_env_for_docker_and_svelte
{ {
echo "Creating a new environment for docker" docker rm -f postgresql
docker volume rm -f srcs_data_nest_postgresql
echo -e "${BOLD_BLUE}Creating a new environment for docker${RESET}"
NODE_ENV="" NODE_ENV=""
# Ask if dev or prod environment # Ask if dev or prod environment
while [ "$NODE_ENV" != "1" ] && [ "$NODE_ENV" != "2" ]; do while [ "$NODE_ENV" != "1" ] && [ "$NODE_ENV" != "2" ]; do
@@ -39,43 +60,84 @@ ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env
echo "REDIS_PORT=6379" >> "$ENV_FILE_DOCKER" echo "REDIS_PORT=6379" >> "$ENV_FILE_DOCKER"
echo "REDIS_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER" echo "REDIS_PASSWORD=$(generate_password)" >> "$ENV_FILE_DOCKER"
# Connection to 42 # Connection to 42
echo "In the next steps, we'll need to enter the client secret and client id of the 42 api" echo -e "${BOLD_BLUE}In the next steps, we'll need to enter the client secret and client id of the 42 api${RESET}"
read -p "Enter the client id of the 42 api : " CLIENT_ID read -p "Enter the client id of the 42 api : " CLIENT_ID
echo "FORTYTWO_CLIENT_ID=$CLIENT_ID" >> "$ENV_FILE_DOCKER" echo "FORTYTWO_CLIENT_ID=$CLIENT_ID" >> "$ENV_FILE_DOCKER"
read -p "Enter the client secret of the 42 api : " CLIENT_SECRET read -p "Enter the client secret of the 42 api : " CLIENT_SECRET
echo "FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET" >> "$ENV_FILE_DOCKER" echo "FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET" >> "$ENV_FILE_DOCKER"
FT_CALLBACK="http://\$WEBSITE_HOST:\$WEBSITE_PORT/api/v2/auth/redirect" FT_CALLBACK="http://$PROJECT_HOST:8080/api/v2/auth/redirect"
echo "FORTYTWO_CALLBACK_URL=$FT_CALLBACK" >> "$ENV_FILE_DOCKER" echo "FORTYTWO_CALLBACK_URL=$FT_CALLBACK" >> "$ENV_FILE_DOCKER"
# Other configs # Other configs
echo "COOKIE_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" echo "COOKIE_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER"
echo "PORT=3000" >> "$ENV_FILE_DOCKER" echo "PORT=3000" >> "$ENV_FILE_DOCKER"
echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER" echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER"
echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER"
grep "^WEBSITE_" "$ENV_FILE_DOCKER" > "$ENV_FILE_SVELTE" make_env_for_svelte
update_nginx_conf
echo -e "${BOLD_GREEN}Environment created.${RESET}"
echo -e "${BOLD_GREEN}The script will exit${RESET}"
exit 0
} }
function change_host_and_port_api
{
if [ -f "$ENV_FILE_DOCKER" ]
then
echo -e "${BOLD_BLUE}Changing the host and the port of the api${RESET}"
read -p "Enter the name of the host like \"localhost\" : " PROJECT_HOST
sed -i "s/WEBSITE_HOST=.*/WEBSITE_HOST=$PROJECT_HOST/g" "$ENV_FILE_DOCKER"
read -p "Enter the port of the api : " PROJECT_PORT
sed -i "s/WEBSITE_PORT=.*/WEBSITE_PORT=$PROJECT_PORT/g" "$ENV_FILE_DOCKER"
make_env_for_svelte
update_nginx_conf
else
echo -e "${BOLD_RED}No environment file found. We will regenerate the entire env files.${RESET}"
fi
}
function change_api_fields_for_42_auth_api
{
if [ -f "$ENV_FILE_DOCKER" ]
then
echo -e "${BOLD_BLUE}Changing the secret for the 42 api${RESET}"
read -p "Enter the client id of the 42 api : " CLIENT_ID
sed -i "s/FORTYTWO_CLIENT_ID=.*/FORTYTWO_CLIENT_ID=$CLIENT_ID/g" "$ENV_FILE_DOCKER"
read -p "Enter the client secret of the 42 api : " CLIENT_SECRET
sed -i "s/FORTYTWO_CLIENT_SECRET=.*/FORTYTWO_CLIENT_SECRET=$CLIENT_SECRET/g" "$ENV_FILE_DOCKER"
echo -e "${BOLD_GREEN}The fields concerning the 42 api have been changed.${RESET}"
else
echo -e "${BOLD_RED}No environment file found. We will regenerate the entire env files.${RESET}"
make_env_for_docker_and_svelte
fi
}
function choose_options_and_process { function choose_options_and_process {
if [ -f "$ENV_FILE_DOCKER" ]; then if [ ! -f "$ENV_FILE_DOCKER" ]; then
echo "The file $ENV_FILE_DOCKER already exists. Do you want to overwrite it ? (y/n)" make_env_for_docker_and_svelte
OVERWRITE="" elif [ ! -f "$ENV_FILE_SVELTE" && -f "$ENV_FILE_DOCKER" ]; then
# Ask to overwrite the .env files make_env_for_svelte
while [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "n" ]; do fi
read -p "Enter your choice : " OVERWRITE echo -e "${BOLD_RED}An environment already exists.${RESET}"
echo -e "${BOLD_GREEN}What do you want to do ?${RESET}"
echo -e "${BOLD_GREEN}1. Regenerate entire environment${RESET}"
echo -e "${BOLD_GREEN}2. Only change the fields about the HOSTNAME and the PORT of the API${RESET}"
echo -e "${BOLD_GREEN}3. Only change the fields concerning the 42 API (id and secret)${RESET}"
echo -e "${BOLD_GREEN}4. Exit${RESET}"
CHOICE=""
while [ "$CHOICE" != "1" ] && [ "$CHOICE" != "2" ] && [ "$CHOICE" != "3" ] && [ "$CHOICE" != "4" ]; do
read -p "Enter your choice : " CHOICE
done done
if [ "$OVERWRITE" = "y" ]; then if [ "$CHOICE" = "1" ]; then
rm "$ENV_FILE_DOCKER" && rm "$ENV_FILE_SVELTE"
docker rmi -f postgres
make_env_for_docker_and_svelte make_env_for_docker_and_svelte
elif [ "$CHOICE" = "2" ]; then
change_host_and_port_api
elif [ "$CHOICE" = "3" ]; then
change_api_fields_for_42_auth_api
else else
if [ ! -f "$ENV_FILE_SVELTE" ]; then echo -e "${BOLD_GREEN}The script will exit.${RESET}"
grep "^WEBSITE_" "$ENV_FILE_DOCKER" > "$ENV_FILE_SVELTE"
fi
echo "The file $ENV_FILE_DOCKER will not be overwritten. The script will exit."
exit 0 exit 0
fi fi
else
make_env_for_docker_and_svelte
fi
} }
# Create a new environment for docker # Create a new environment for docker

View File

@@ -22,6 +22,7 @@ services:
COOKIE_SECRET: "${COOKIE_SECRET}" COOKIE_SECRET: "${COOKIE_SECRET}"
TWO_FACTOR_AUTHENTICATION_APP_NAME : "${TWO_FACTOR_AUTHENTICATION_APP_NAME}" TWO_FACTOR_AUTHENTICATION_APP_NAME : "${TWO_FACTOR_AUTHENTICATION_APP_NAME}"
TICKET_FOR_PLAYING_GAME_SECRET : "${TICKET_FOR_PLAYING_GAME_SECRET}" TICKET_FOR_PLAYING_GAME_SECRET : "${TICKET_FOR_PLAYING_GAME_SECRET}"
PORT: "${PORT}"
volumes: volumes:
- ./requirements/nestjs/api_back/src:/usr/app/src - ./requirements/nestjs/api_back/src:/usr/app/src
- ./requirements/nestjs/api_back/test:/usr/app/test/ - ./requirements/nestjs/api_back/test:/usr/app/test/
@@ -38,6 +39,8 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
environment: environment:
NODE_ENV: "${NODE_ENV}" NODE_ENV: "${NODE_ENV}"
WEBSITE_HOST: "${WEBSITE_HOST}"
WEBSITE_PORT: "${WEBSITE_PORT}"
restart: unless-stopped restart: unless-stopped
ports: ports:
- "8042:8042" - "8042:8042"

View File

@@ -37,10 +37,10 @@ export class AuthenticationController {
const user : User = request.user const user : User = request.user
if (user.isEnabledTwoFactorAuth === false || user.isTwoFactorAuthenticated === true){ if (user.isEnabledTwoFactorAuth === false || user.isTwoFactorAuthenticated === true){
console.log('ON VA VERS PROFILE'); console.log('ON VA VERS PROFILE');
return response.status(200).redirect('http://transcendance:8080/#/profile'); return response.status(200).redirect('http://' + process.env.WEBSITE_HOST + ':' + process.env.WEBSITE_PORT + '/#/profile');
} }
console.log('ON VA VERS 2FA') console.log('ON VA VERS 2FA')
return response.status(200).redirect('http://transcendance:8080/#/2fa'); return response.status(200).redirect('http://' + process.env.WEBSITE_HOST + ':' + process.env.WEBSITE_PORT + '/#/2fa');
} }
/** /**
@@ -83,6 +83,6 @@ export class AuthenticationController {
throw new UnauthorizedException('Wrong Code.'); throw new UnauthorizedException('Wrong Code.');
await this.userService.authenticateUserWith2FA(request.user.id); await this.userService.authenticateUserWith2FA(request.user.id);
console.log('ON REDIRIGE'); console.log('ON REDIRIGE');
return response.status(200).redirect('http://transcendance:8080/#/profile'); return response.status(200).redirect('http://' + process.env.WEBSITE_HOST + ':' + process.env.WEBSITE_PORT + '/#/profile');
} }
} }

View File

@@ -8,7 +8,7 @@ import * as connectRedis from 'connect-redis';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true }); const app = await NestFactory.create(AppModule, { cors: true });
const port = process.env.PORT || 3001; const port = process.env.PORT || 3000;
const client = redis.createClient( const client = redis.createClient(
{ {
socket: { host: process.env.REDIS_HOST, port: parseInt(process.env.REDIS_PORT) }, socket: { host: process.env.REDIS_HOST, port: parseInt(process.env.REDIS_PORT) },
@@ -50,6 +50,6 @@ async function bootstrap() {
); );
app.use(passport.initialize()); app.use(passport.initialize());
app.use(passport.session()); app.use(passport.session());
await app.listen(port, () => { console.log(`Listening on port ${port}`); }); await app.listen(port, () => { console.log(`Listening on port ${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}}`); });
} }
bootstrap(); bootstrap();

View File

@@ -1,7 +1,6 @@
server { server {
listen 8080;
listen 8080 default_server; listen [::]:8080;
listen [::]:8080 default_server;
server_name transcendance; server_name transcendance;
location /api/v2 { location /api/v2 {
@@ -17,7 +16,7 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "Upgrade";
proxy_pass http://backend_dev:5000/chat; proxy_pass http://backend_dev:5000/chat;
} }
@@ -43,7 +42,6 @@ server {
} }
server { server {
listen 35729 default_server; listen 35729 default_server;
listen [::]:35729 default_server; listen [::]:35729 default_server;
server_name transcendance; server_name transcendance;

View File

@@ -17368,10 +17368,10 @@ var app = (function () {
// export const soundPongArr: HTMLAudioElement[] = []; // export const soundPongArr: HTMLAudioElement[] = [];
const soundPongArr = [ const soundPongArr = [
new Audio("http://transcendance:8080/sound/pong/" + 1 + ".ogg"), new Audio("http://" + 'transcendance' + ":" + '8080' + "/sound/pong/" + 1 + ".ogg"),
new Audio("http://transcendance:8080/sound/pong/" + 2 + ".ogg") new Audio("http://" + 'transcendance' + ":" + '8080' + "/sound/pong/" + 2 + ".ogg")
]; ];
const soundRoblox = new Audio("http://transcendance:8080/sound/roblox-oof.ogg"); const soundRoblox = new Audio("http://" + 'transcendance' + ":" + '8080' + "/sound/roblox-oof.ogg");
function initAudio(sound) { function initAudio(sound) {
let muteFlag; let muteFlag;
if (sound === "on") { if (sound === "on") {
@@ -17380,11 +17380,6 @@ var app = (function () {
else { else {
muteFlag = true; muteFlag = true;
} }
/* for (let i = 0; i <= 32; i++) {
soundPongArr.push(new Audio("http://transcendance:8080/sound/pong/"+i+".ogg"));
soundPongArr[i].volume = c.soundPongVolume;
soundPongArr[i].muted = muteFlag;
} */
soundPongArr.forEach((value) => { soundPongArr.forEach((value) => {
value.volume = soundRobloxVolume; value.volume = soundRobloxVolume;
value.muted = muteFlag; value.muted = muteFlag;
@@ -17466,7 +17461,7 @@ var app = (function () {
} }
class ClientInfoSpectator { class ClientInfoSpectator {
} }
const wsUrl = "ws://transcendance:8080/pong"; const wsUrl = "ws://" + 'transcendance' + ":" + '8080' + "/pong";
let socket; /* TODO: A way to still use "const" not "let" ? */ let socket; /* TODO: A way to still use "const" not "let" ? */
const clientInfo = new ClientInfo(); const clientInfo = new ClientInfo();
const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this
@@ -21304,7 +21299,7 @@ var app = (function () {
component: ProfilePage, component: ProfilePage,
conditions: [ conditions: [
async(detail) => { async(detail) => {
const user = await fetch('http://transcendance:8080/api/v2/user') const user = await fetch('http://' + 'transcendance' + ":" + '8080' + '/api/v2/user')
.then((resp) => resp.json()); .then((resp) => resp.json());
console.log('in /profile what is in user'); console.log('in /profile what is in user');
@@ -21321,7 +21316,7 @@ var app = (function () {
component: ProfilePage, component: ProfilePage,
conditions: [ conditions: [
async(detail) => { async(detail) => {
const user = await fetch('http://transcendance:8080/api/v2/user') const user = await fetch('http://' + 'transcendance' + ":" + '8080' + '/api/v2/user')
.then((resp) => resp.json()); .then((resp) => resp.json());
console.log('in /profile/* what is in user'); console.log('in /profile/* what is in user');

File diff suppressed because one or more lines are too long

View File

@@ -3,10 +3,10 @@ import * as c from "./constants.js"
// export const soundPongArr: HTMLAudioElement[] = []; // export const soundPongArr: HTMLAudioElement[] = [];
export const soundPongArr: HTMLAudioElement[] = [ export const soundPongArr: HTMLAudioElement[] = [
new Audio("http://transcendance:8080/sound/pong/"+1+".ogg"), new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+1+".ogg"),
new Audio("http://transcendance:8080/sound/pong/"+2+".ogg") new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+2+".ogg")
]; ];
export const soundRoblox = new Audio("http://transcendance:8080/sound/roblox-oof.ogg"); export const soundRoblox = new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/roblox-oof.ogg");
export function initAudio(sound: string) export function initAudio(sound: string)
{ {
@@ -18,11 +18,6 @@ export function initAudio(sound: string)
muteFlag = true; muteFlag = true;
} }
/* for (let i = 0; i <= 32; i++) {
soundPongArr.push(new Audio("http://transcendance:8080/sound/pong/"+i+".ogg"));
soundPongArr[i].volume = c.soundPongVolume;
soundPongArr[i].muted = muteFlag;
} */
soundPongArr.forEach((value) => { soundPongArr.forEach((value) => {
value.volume = c.soundRobloxVolume; value.volume = c.soundRobloxVolume;
value.muted = muteFlag; value.muted = muteFlag;

View File

@@ -35,7 +35,7 @@ class ClientInfoSpectator {
playerRightNextPos: VectorInteger; playerRightNextPos: VectorInteger;
} }
const wsUrl = "ws://transcendance:8080/pong"; const wsUrl = "ws://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/pong";
export let socket: WebSocket; /* TODO: A way to still use "const" not "let" ? */ export let socket: WebSocket; /* TODO: A way to still use "const" not "let" ? */
export const clientInfo = new ClientInfo(); export const clientInfo = new ClientInfo();
export const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this export const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this

View File

@@ -21,7 +21,7 @@ export const primaryRoutes = {
component: ProfilePage, component: ProfilePage,
conditions: [ conditions: [
async(detail) => { async(detail) => {
const user = await fetch('http://transcendance:8080/api/v2/user') const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
.then((resp) => resp.json()) .then((resp) => resp.json())
console.log('in /profile what is in user') console.log('in /profile what is in user')
@@ -38,7 +38,7 @@ export const primaryRoutes = {
component: ProfilePage, component: ProfilePage,
conditions: [ conditions: [
async(detail) => { async(detail) => {
const user = await fetch('http://transcendance:8080/api/v2/user') const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
.then((resp) => resp.json()) .then((resp) => resp.json())
console.log('in /profile/* what is in user') console.log('in /profile/* what is in user')