From 89b3b824c7b94d7a0b77e8146c5b63c104a81e14 Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Fri, 20 Sep 2024 10:34:16 +0200 Subject: [PATCH 1/7] Started changes the file structure --- app/{ => backend}/AudioRecorder(not yet).tsx | 0 app/{ => backend}/InputBackend.tsx | 4 ++-- app/{ => backend}/InputOutputHandler.tsx | 4 ++-- app/{ => backend}/ProcessAPI.js | 0 app/{ => backend}/ProcessMemory.tsx | 0 app/{ => components}/AI.tsx | 2 +- app/{ => components}/ConversationFrontend.tsx | 0 app/{ => components}/Documentation.tsx | 0 app/{ => components}/Faq.tsx | 0 app/{ => components}/Header.tsx | 0 app/{ => components}/History.tsx | 0 app/{ => components}/InputFrontend.tsx | 0 app/{ => components}/Login.tsx | 0 app/{ => components}/Models.tsx | 0 app/{ => components}/Settings.tsx | 0 app/layout.tsx | 2 +- app/page.tsx | 12 ++++++------ 17 files changed, 12 insertions(+), 12 deletions(-) rename app/{ => backend}/AudioRecorder(not yet).tsx (100%) rename app/{ => backend}/InputBackend.tsx (94%) rename app/{ => backend}/InputOutputHandler.tsx (95%) rename app/{ => backend}/ProcessAPI.js (100%) rename app/{ => backend}/ProcessMemory.tsx (100%) rename app/{ => components}/AI.tsx (69%) rename app/{ => components}/ConversationFrontend.tsx (100%) rename app/{ => components}/Documentation.tsx (100%) rename app/{ => components}/Faq.tsx (100%) rename app/{ => components}/Header.tsx (100%) rename app/{ => components}/History.tsx (100%) rename app/{ => components}/InputFrontend.tsx (100%) rename app/{ => components}/Login.tsx (100%) rename app/{ => components}/Models.tsx (100%) rename app/{ => components}/Settings.tsx (100%) diff --git a/app/AudioRecorder(not yet).tsx b/app/backend/AudioRecorder(not yet).tsx similarity index 100% rename from app/AudioRecorder(not yet).tsx rename to app/backend/AudioRecorder(not yet).tsx diff --git a/app/InputBackend.tsx b/app/backend/InputBackend.tsx similarity index 94% rename from app/InputBackend.tsx rename to app/backend/InputBackend.tsx index 78be6bb..a00ceeb 100644 --- a/app/InputBackend.tsx +++ b/app/backend/InputBackend.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; -import InputFrontend from './InputFrontend'; -import ConversationFrontend from './ConversationFrontend'; +import InputFrontend from '../components/InputFrontend'; +import ConversationFrontend from '../components/ConversationFrontend'; import { Mistral } from '@mistralai/mistralai'; diff --git a/app/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx similarity index 95% rename from app/InputOutputHandler.tsx rename to app/backend/InputOutputHandler.tsx index 2bbe5b0..cee1d44 100644 --- a/app/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -1,7 +1,7 @@ "use client" import React, { useEffect, useRef, useState } from "react"; -import ConversationFrontend from "./ConversationFrontend"; -import InputFrontend from "./InputFrontend"; +import ConversationFrontend from "../components/ConversationFrontend"; +import InputFrontend from "../components/InputFrontend"; const handleMicClick = () => { console.log('Mic clicked!'); diff --git a/app/ProcessAPI.js b/app/backend/ProcessAPI.js similarity index 100% rename from app/ProcessAPI.js rename to app/backend/ProcessAPI.js diff --git a/app/ProcessMemory.tsx b/app/backend/ProcessMemory.tsx similarity index 100% rename from app/ProcessMemory.tsx rename to app/backend/ProcessMemory.tsx diff --git a/app/AI.tsx b/app/components/AI.tsx similarity index 69% rename from app/AI.tsx rename to app/components/AI.tsx index b391683..e1d244b 100644 --- a/app/AI.tsx +++ b/app/components/AI.tsx @@ -1,6 +1,6 @@ // AI.tsx import React from 'react'; -import InputOutputBackend from './InputOutputHandler'; +import InputOutputBackend from '../backend/InputOutputHandler'; const AI: React.FC = () => { return ( diff --git a/app/ConversationFrontend.tsx b/app/components/ConversationFrontend.tsx similarity index 100% rename from app/ConversationFrontend.tsx rename to app/components/ConversationFrontend.tsx diff --git a/app/Documentation.tsx b/app/components/Documentation.tsx similarity index 100% rename from app/Documentation.tsx rename to app/components/Documentation.tsx diff --git a/app/Faq.tsx b/app/components/Faq.tsx similarity index 100% rename from app/Faq.tsx rename to app/components/Faq.tsx diff --git a/app/Header.tsx b/app/components/Header.tsx similarity index 100% rename from app/Header.tsx rename to app/components/Header.tsx diff --git a/app/History.tsx b/app/components/History.tsx similarity index 100% rename from app/History.tsx rename to app/components/History.tsx diff --git a/app/InputFrontend.tsx b/app/components/InputFrontend.tsx similarity index 100% rename from app/InputFrontend.tsx rename to app/components/InputFrontend.tsx diff --git a/app/Login.tsx b/app/components/Login.tsx similarity index 100% rename from app/Login.tsx rename to app/components/Login.tsx diff --git a/app/Models.tsx b/app/components/Models.tsx similarity index 100% rename from app/Models.tsx rename to app/components/Models.tsx diff --git a/app/Settings.tsx b/app/components/Settings.tsx similarity index 100% rename from app/Settings.tsx rename to app/components/Settings.tsx diff --git a/app/layout.tsx b/app/layout.tsx index da488bb..994a18a 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,4 +1,4 @@ -import Header from "./Header"; +import Header from "./components/Header"; export const metadata = { diff --git a/app/page.tsx b/app/page.tsx index 54dccc1..f8dcbd3 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,11 +1,11 @@ "use client"; import React, { useState, useEffect, useRef } from 'react'; -import Header from './Header'; -import AI from './AI'; -import FAQ from './Faq'; // Ensure the import path is correct -import Documentation from './Documentation'; // Ensure the import path is correct -import History from './History'; -import Models from './Models'; +import Header from './components/Header'; +import AI from './components/AI'; +import FAQ from './components/Faq'; // Ensure the import path is correct +import Documentation from './components/Documentation'; // Ensure the import path is correct +import History from './components/History'; +import Models from './components/Models'; import './styles/master.css'; const LandingPage: React.FC = () => { From 3775bbc4c50e8e90a3b7da8df3e00edf2e669504 Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Fri, 20 Sep 2024 11:12:28 +0200 Subject: [PATCH 2/7] Last commit before tailwind testing --- tailwind.config.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tailwind.config.ts b/tailwind.config.ts index d43da91..a883ff7 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -9,11 +9,13 @@ const config: Config = { theme: { extend: { colors: { - background: "var(--background)", - foreground: "var(--foreground)", + 'history-background': 'var(--history-background-color)', + 'text-color': 'var(--text-color)', + 'input-button-hover-color': 'var(--input-button-hover-color)', }, }, }, plugins: [], }; + export default config; From 1ee7d55e490153b232c515243ca64b7b29a7401b Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Fri, 20 Sep 2024 11:15:40 +0200 Subject: [PATCH 3/7] ahhh --- py/db.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 py/db.py diff --git a/py/db.py b/py/db.py new file mode 100644 index 0000000..e69de29 From 4a183c0c89611888cdec2b52fd0a43dd59f9b195 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Fri, 20 Sep 2024 11:15:42 +0200 Subject: [PATCH 4/7] wha --- py/api.py | 9 +++++++++ py/db.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/py/api.py b/py/api.py index b25e4d4..a5d2a97 100644 --- a/py/api.py +++ b/py/api.py @@ -2,6 +2,7 @@ from flask import Flask, request, jsonify from flask_cors import CORS import secrets from ai import AI +from db import DB class API: @@ -9,6 +10,7 @@ class API: self.app = Flask(__name__) self.ai_response = {} self.ai = AI() + self.db = DB() CORS(self.app) def run(self): @@ -36,6 +38,13 @@ class API: return jsonify({'status': 401, 'error': 'Invalid access token'}) return jsonify({'status': 200, 'response': self.ai_response[data]}) + @self.app.route('/interstellar/api/db', methods=['POST']) + def db_manipulate(): + action = request.args.get('action') + if action == "create_account": + print("ahh") + + ssl_context = ('cert.pem', 'key.pem') self.app.run(debug=True, host='0.0.0.0', port=5000, ssl_context=ssl_context) diff --git a/py/db.py b/py/db.py index e69de29..5116a93 100644 --- a/py/db.py +++ b/py/db.py @@ -0,0 +1,41 @@ +import json +import hashlib + + +class DB: + def __init__(self): + self.database = {} + + def _hash_password(self, password: str) -> str: + salt = "your_secret_salt" + hashed_password = hashlib.sha256((password + salt).encode()).hexdigest() + return hashed_password + + def add_user(self, username: str, password: str) -> None: + hashed_password = self._hash_password(password) + user_data = {"hashed_password": hashed_password} + self.database[username] = user_data + + def update_password(self, username: str, old_password: str, new_password: str) -> bool: + if not self.check_credentials(username, old_password): + return False + + hashed_new_password = self._hash_password(new_password) + self.database[username].update({"hashed_password": hashed_new_password}) + return True + + def check_credentials(self, username: str, password: str) -> bool: + if username not in self.database: + return False + + stored_hashed_password = self.database[username]["hashed_password"] + entered_hashed_password = self._hash_password(password) + return stored_hashed_password == entered_hashed_password + + def get_additional_info(self, username: str, password: str) -> dict | None: + if not self.check_credentials(username, password): + return None + + send_back = self.database[username] + del send_back['hashed_password'] + return send_back \ No newline at end of file From 115fb1d38d6bad87e58a16580377f8a88a67ee1f Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Fri, 20 Sep 2024 11:34:21 +0200 Subject: [PATCH 5/7] Database Backend --- py/api.py | 9 ++++++++- py/db.py | 32 +++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/py/api.py b/py/api.py index a5d2a97..f9e5ca2 100644 --- a/py/api.py +++ b/py/api.py @@ -41,8 +41,15 @@ class API: @self.app.route('/interstellar/api/db', methods=['POST']) def db_manipulate(): action = request.args.get('action') + data = request.args.get('data') if action == "create_account": - print("ahh") + self.db.add_user(data) + if action == "change_password": + self.db.update_password(data) + if action == "get_data": + self.db.get_additional_info(data) + if action == "check_credentials": + self.db.check_credentials(data) ssl_context = ('cert.pem', 'key.pem') diff --git a/py/db.py b/py/db.py index 5116a93..37c9ca0 100644 --- a/py/db.py +++ b/py/db.py @@ -6,36 +6,46 @@ class DB: def __init__(self): self.database = {} - def _hash_password(self, password: str) -> str: + @staticmethod + def hash_password(password): salt = "your_secret_salt" hashed_password = hashlib.sha256((password + salt).encode()).hexdigest() return hashed_password - def add_user(self, username: str, password: str) -> None: - hashed_password = self._hash_password(password) + def add_user(self, data): + username = data.get['username'] + password = data.get['password'] + hashed_password = self.hash_password(password) user_data = {"hashed_password": hashed_password} self.database[username] = user_data - def update_password(self, username: str, old_password: str, new_password: str) -> bool: - if not self.check_credentials(username, old_password): + def update_password(self, data): + username = data.get['username'] + old_password = data.get['old_password'] + new_password = data.get['new_password'] + if not self.check_credentials(data): return False - hashed_new_password = self._hash_password(new_password) + hashed_new_password = self.hash_password(new_password) self.database[username].update({"hashed_password": hashed_new_password}) return True - def check_credentials(self, username: str, password: str) -> bool: + def check_credentials(self, data): + username = data.get['username'] + password = data.get['password'] if username not in self.database: return False stored_hashed_password = self.database[username]["hashed_password"] - entered_hashed_password = self._hash_password(password) + entered_hashed_password = self.hash_password(password) return stored_hashed_password == entered_hashed_password - def get_additional_info(self, username: str, password: str) -> dict | None: - if not self.check_credentials(username, password): + def get_additional_info(self, data): + username = data.get['username'] + password = data.get['password'] + if not self.check_credentials(data): return None send_back = self.database[username] del send_back['hashed_password'] - return send_back \ No newline at end of file + return send_back From 13c47b9743157ed3fb7e609584dffba201ef5abe Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Fri, 20 Sep 2024 11:35:13 +0200 Subject: [PATCH 6/7] whoops --- py/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/py/api.py b/py/api.py index f9e5ca2..1e1f785 100644 --- a/py/api.py +++ b/py/api.py @@ -51,7 +51,6 @@ class API: if action == "check_credentials": self.db.check_credentials(data) - ssl_context = ('cert.pem', 'key.pem') self.app.run(debug=True, host='0.0.0.0', port=5000, ssl_context=ssl_context) From 054cbf6a5dbb7731711f51da6c0aa630716aedd0 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Fri, 20 Sep 2024 14:40:16 +0200 Subject: [PATCH 7/7] PUSH THE BACKEND TO THE LIMIT --- py/api.py | 39 +++++++++++++++++++++++++++++++++++++-- py/install.sh | 1 - py/requirements.txt | 3 ++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/py/api.py b/py/api.py index 1e1f785..aa226eb 100644 --- a/py/api.py +++ b/py/api.py @@ -3,10 +3,12 @@ from flask_cors import CORS import secrets from ai import AI from db import DB +from OpenSSL import crypto class API: def __init__(self): + self.crypt_size = 4096 self.app = Flask(__name__) self.ai_response = {} self.ai = AI() @@ -16,7 +18,7 @@ class API: def run(self): @self.app.route('/interstellar/api/ai_create', methods=['GET']) def create_ai(): - access_token = secrets.token_urlsafe(4096) + access_token = secrets.token_urlsafe(self.crypt_size) self.ai_response[access_token] = "" return jsonify({'status': 200, 'access_token': access_token}) @@ -51,7 +53,40 @@ class API: if action == "check_credentials": self.db.check_credentials(data) - ssl_context = ('cert.pem', 'key.pem') + email_address = "emailAddress" + common_name = "commonName" + country_name = "NT" + locality_name = "localityName" + state_or_province_name = "stateOrProvinceName" + organization_name = "organizationName" + organization_unit_name = "organizationUnitName" + serial_number = 0 + validity_start_in_seconds = 0 + validity_end_in_seconds = 10 * 365 * 24 * 60 * 60 + k = crypto.PKey() + k.generate_key(crypto.TYPE_RSA, 4096) + cert = crypto.X509() + cert.get_subject().C = country_name + cert.get_subject().ST = state_or_province_name + cert.get_subject().L = locality_name + cert.get_subject().O = organization_name + cert.get_subject().OU = organization_unit_name + cert.get_subject().CN = common_name + cert.get_subject().emailAddress = email_address + cert.set_serial_number(serial_number) + cert.gmtime_adj_notBefore(validity_start_in_seconds) + cert.gmtime_adj_notAfter(validity_end_in_seconds) + cert.set_issuer(cert.get_subject()) + cert.set_pubkey(k) + cert.sign(k, 'sha512') + + with open("cert.pem", "wt") as f: + f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8")) + + with open("key.pem", "wt") as f: + f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8")) + + ssl_context = ("cert.pem", "key.pem") self.app.run(debug=True, host='0.0.0.0', port=5000, ssl_context=ssl_context) diff --git a/py/install.sh b/py/install.sh index 31bb21e..1fbdcba 100644 --- a/py/install.sh +++ b/py/install.sh @@ -1,4 +1,3 @@ -openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 python -m venv venv source venv/bin/activate pip install -r requirements.txt diff --git a/py/requirements.txt b/py/requirements.txt index b4f811a..144c571 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -1,4 +1,5 @@ flask flask-cors ollama -mistralai \ No newline at end of file +mistralai +pyOpenSSL \ No newline at end of file