Skip to content

Commit

Permalink
Tried to fix sconf
Browse files Browse the repository at this point in the history
  • Loading branch information
VUTxvojac04 committed Dec 2, 2024
1 parent 108d056 commit 87488c2
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 17 deletions.
4 changes: 4 additions & 0 deletions sconf/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ readme = "README.md"
packages = [
{ include = "sconf", from = "src" },
]
include = [
{ path = "icons", format = ["sdist", "wheel"]},
{ path = "phish", format = ["sdist", "wheel"]},
]

[tool.poetry.dependencies]
python = "^3.12"
Expand Down
3 changes: 2 additions & 1 deletion sconf/src/sconf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def main():
_dataWriter: data_writer.ConfigurationWriter
config_folder = os.getcwd()

_dataWriter = data_writer.ConfigurationWriter()
_dataProvider = data_provider.ConfigurationProvider()
_dataWriter = data_writer.ConfigurationWriter()


app = QApplication(sys.argv)
window = MainWindow(_dataProvider, _dataWriter, config_folder)
Expand Down
20 changes: 16 additions & 4 deletions sconf/src/sconf/configuration/configuration_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os.path
from pathlib import Path

from dataclass_wizard import fromdict

Expand All @@ -8,28 +9,39 @@
from sconf.configuration.models.sos_configuration import SOSConfiguration
from sconf.configuration.models.sweb_configuration import SwebConfiguration
from sconf.decorators.decorators import singleton

from sconf.configuration.default_configuration import default_configuration

@singleton
class ConfigurationProvider:
_configFileName: str = ""
_configStoragePath: str = ""
_sosConfiguration: SOSConfiguration

def __init__(self, configFileName: str = 'config.json', configStoragePath: str = os.getcwd()):
def __init__(self, configFileName: str = 'config.json', configStoragePath: str = os.path.join(Path.home(), '.sconf')):
"""
Class providing access to the configuration data of the SOS.
This class has singleton decorator which should allow existence of only singular instance of this class.
:param configFileName: Name of the SOS configuration file
:param configStoragePath: Expected folder path from which the configuration can be loaded into memory
"""
self._configFileName = configFileName
self._configStoragePath = '../sconf'
if os.path.exists(configStoragePath):
if os.path.isdir(configStoragePath):
self._configStoragePath = configStoragePath
else:
print(f"{configStoragePath} exists and is NOT a directory!")
exit(1)
else:
os.mkdir(configStoragePath)

self.__load_configuration()

def __load_configuration(self):
with open(os.path.join(self._configStoragePath, self._configFileName), 'r') as sourceFile:
config_file = os.path.join(self._configStoragePath, self._configFileName)
if not os.path.exists(config_file):
with open(config_file, 'w') as newConfig:
json.dump(default_configuration(), newConfig)
with open(config_file, 'r') as sourceFile:
self._sosConfiguration: SOSConfiguration = fromdict(SOSConfiguration, json.load(sourceFile))

def update_memory_configuration(self, configuration):
Expand Down
5 changes: 3 additions & 2 deletions sconf/src/sconf/configuration/configuration_writer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dataclasses
import json
import os.path
from pathlib import Path

from dataclass_wizard import asdict

Expand All @@ -16,14 +17,14 @@ class ConfigurationWriter:
_configFileName: str = ""
_configStoragePath: str = ""

def __init__(self, configFileName: str = 'config.json', configStoragePath: str = os.getcwd()):
def __init__(self, configFileName: str = 'config.json', configStoragePath: str = os.path.join(Path.home(), '.sconf')):
"""
Class providing ability to save the configuration into the persistent storage
:param configFileName: Name of the SOS configuration file
:param configStoragePath: Expected folder path from which the configuration can be loaded into memory
"""
self._configFileName = configFileName
self._configStoragePath = '../sconf'
self._configStoragePath = configStoragePath

self.__validate_and_create_default_config()

Expand Down
162 changes: 162 additions & 0 deletions sconf/src/sconf/configuration/default_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
def default_configuration():
return {
"initialStartUp": True,
"configurationPassword": "",
"globalConfiguration": {
"language": "en",
"colorMode": "light",
"alertColor": "000000",
"highlightColor": "000000",
"protectionLevel": 1,
},
"swebConfiguration": {
"swebAllowedUrlListV2": [
{"url1": "https://irozhlas.cz/", "icon1": "icons/sweb_www_1.png"},
{
"url2": "https://edition.cnn.com/",
"icon2": "icons/sweb_www_2.png",
},
{"url3": "https://www.vut.cz/", "icon3": "icons/sweb_www_3.png"},
{"url4": "https://google.com/", "icon4": "icons/sweb_www_4.jpg"},
{
"url5": "https://www.aktualne.cz/",
"icon5": "icons/sweb_www_5.png",
},
{"url6": "https://www.denik.cz/", "icon6": "icons/sweb_www_6.png"},
],
"urlsForWebsites": [
"https://irozhlas.cz/",
"https://edition.cnn.com/",
"https://www.vut.cz/",
"https://www.info-zdravi.cz/",
"https://www.aktualne.cz/",
"https://www.denik.cz/",
],
"picturePaths": [
"icons/exit.png",
"icons/sweb_www_1.png",
"icons/sweb_www_2.png",
"icons/sweb_www_3.png",
"icons/sweb_www_4.png",
"icons/sweb_www_5.png",
"icons/sweb_www_6.png",
],
"allowedURL": "phish/sweb_allowed_url.txt",
"phishingDatabase": "phish/sweb_phish.txt",
"phishingGithubDatabase": "https://github.com/mitchellkrogza/Phishing.Database/raw/master/ALL-phishing-domains.tar.gz/",
"sendPhishingWarning": True,
"phishingFormular": True,
"seniorWebsitePosting": True,
"whiteListedWebsitesOnly": False,
"allowWebSearch": True,
"defaultLanguage": "cz",
"text": [
"MENU 1",
"MENU 2",
"Search",
"MENU 1",
"MENU 2",
"Vyhledávání",
"MENU 1",
"MENU 2",
"Suche",
],
},
"smailConfiguration": {
"seniorEmail": "[email protected]",
"seniorPassword": "pafotbpfrrlwvund",
"smtpServer": "smtp.gmail.com",
"smtpPort": 587,
"imapServer": "imap.gmail.com",
"imapPort": 993,
"careGiverEmail": "",
"emailContactsV2": [
{
"email1": "[email protected]",
"icon1": "icons/smail_person_1.png",
},
{
"email2": "[email protected]",
"icon2": "icons/smail_person_2.png",
},
{
"email3": "[email protected]",
"icon3": "icons/smail_person_3.png",
},
{
"email4": "[email protected]",
"icon4": "icons/smail_person_4.png",
},
{
"email5": "[email protected]",
"icon5": "icons/smail_person_5.png",
},
{
"email6": "[email protected]",
"icon6": "icons/smail_person_6.png",
},
],
"emailContacts": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
],
"emailPicturesPath": [
"icons/exit.png",
"icons/smail_person_1.png",
"icons/smail_person_2.png",
"icons/smail_person_3.png",
"icons/smail_person_4.png",
"icons/smail_person_5.png",
"icons/smail_person_6.png",
],
"sendPhishingWarning": True,
"showUrlInEmail": True,
"receiveWhitelistedEmailsOnly": False,
"sendWhitelistedEmailsOnly": False,
"languageSet": {
"smailEnSendToButton": "Send To",
"smailEnInboxLabel": "Inbox:",
"smailEnLoadingInbox": "Loading...",
"smailEnRecipientLabel": "To: ",
"smailEnSubjectLabel": "Subject: ",
"smailEnMessageLabel": "Message: ",
"smailEnFrom": "Information: ",
"smailEnDate": "Date: ",
"smailEnEmailSent": "Email has been sent.",
"smailEnEmailFail": "Email has not been sent.",
"smailEnUndeliveredEmail": "The email was not delivered to the address {recipient_email}.",
"smailEnSensitiveContentWarning": "Warning: \nThe email contains sensitive information. \nPress the button a second time to send the email.",
"smailEnUnconfirmedEmailWarning": "Warning: \nUnconfirmed email in progress. \nPress the button again to cancel.",
"smailCzSendToButton": "Komu",
"smailCzInboxLabel": "Doručená pošta: ",
"smailCzLoadingInbox": "Načítám...",
"smailCzRecipientLabel": "Příjemce: ",
"smailCzSubjectLabel": "Předmět: ",
"smailCzMessageLabel": "Zpráva: ",
"smailCzFrom": "Informace: ",
"smailCzDate": "Datum: ",
"smailCzEmailSent": "E-mail byl úspěšně odeslán.",
"smailCzEmailFail": "E-mail nebyl odeslán.",
"smailCzUndeliveredEmail": "Email nebyl doručen na adresu {recipient_email}.",
"smailCzSensitiveContentWarning": "Varování: \nEmail obsahuje citlivé údaje. \nStisknutím tlačítka podruhé email odešlete.",
"smailCzUnconfirmedEmailWarning": "Varování: \nRozpracovaný email nebyl potvrzen. \nDalším stisknutím dojde k jeho zrušení.",
"smailDeSendToButton": "Senden An",
"smailDeInboxLabel": "Posteingang: ",
"smailDeLoadingInbox": "Laden...",
"smailDeRecipientLabel": "An: ",
"smailDeSubjectLabel": "Betreff: ",
"smailDeMessageLabel": "Nachricht: ",
"smailDeFrom": "Information: ",
"smailDeDate": "Datum: ",
"smailDeEmailSent": "Die E-Mail wurde erfolgreich gesendet.",
"smailDeEmailFail": "Die E-Mail wurde nicht gesendet.",
"smailDeUndeliveredEmail": "Die E-Mail wurde nicht an die Adresse {recipient_email} zugestellt.",
"smailDeSensitiveContentWarning": "Warnung: \nDie E-Mail enthält sensible Daten. \nDurch erneutes Drücken der Taste wird die E-Mail gesendet.",
"smailDeUnconfirmedEmailWarning": "Warnung: \nUnbestätigte E-Mail in Bearbeitung. \nDrücken Sie die Taste erneut, um sie abzubrechen.",
},
},
}
5 changes: 1 addition & 4 deletions smail/src/smail/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
import sconf.configuration.configuration_provider as dataProvider

def main():
current_dir = os.getcwd()
CONFIG_FILE_NAME = 'config.json'
config_folder = os.path.join(current_dir, '../sconf')


_dataProvider = dataProvider.ConfigurationProvider(configFileName=CONFIG_FILE_NAME, configStoragePath=config_folder)
_dataProvider = dataProvider.ConfigurationProvider()

try:

Expand Down
8 changes: 2 additions & 6 deletions sweb/src/sweb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@


import sconf.configuration.configuration_provider as dataProvider
CONFIG_FILE_NAME = 'config.json'
SUBFOLDER_NAME = "sconf"


_dataProvider: dataProvider.ConfigurationProvider

Expand All @@ -39,10 +38,7 @@
import ssl

def main():
current_location = os.getcwd()
path_split = current_location.split("sweb")
config_folder = os.path.join(path_split[0], SUBFOLDER_NAME)
_dataProvider = dataProvider.ConfigurationProvider(configFileName=CONFIG_FILE_NAME, configStoragePath=config_folder)
_dataProvider = dataProvider.ConfigurationProvider()
try:

qApplication = QApplication(sys.argv)
Expand Down

0 comments on commit 87488c2

Please sign in to comment.