mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-06-28 09:16:55 +00:00
Moved connection string to an individual file
This commit is contained in:
parent
173cc57490
commit
58f944c72e
22
src/modules/ConnectionString.py
Normal file
22
src/modules/ConnectionString.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import configparser
|
||||||
|
import os
|
||||||
|
|
||||||
|
from sqlalchemy_utils import database_exists, create_database
|
||||||
|
|
||||||
|
from DashboardConfig import DashboardConfig
|
||||||
|
|
||||||
|
def ConnectionString(database) -> str or None:
|
||||||
|
parser = configparser.ConfigParser(strict=False)
|
||||||
|
parser.read_file(open('wg-dashboard.ini', "r+"))
|
||||||
|
sqlitePath = os.path.join("db")
|
||||||
|
if not os.path.isdir(sqlitePath):
|
||||||
|
os.mkdir(sqlitePath)
|
||||||
|
if parser.get("Database", "type") == "postgresql":
|
||||||
|
cn = f'postgresql+psycopg2://{parser.get("Database", "username")}:{parser.get("Database", "password")[1]}@{parser.get("Database", "host")[1]}/{database}'
|
||||||
|
elif parser.get("Database", "type")[1] == "mysql":
|
||||||
|
cn = f'mysql+mysqldb://{parser.get("Database", "username")[1]}:{parser.get("Database", "password")[1]}@{parser.get("Database", "host")[1]}/{database}'
|
||||||
|
else:
|
||||||
|
cn = f'sqlite:///{os.path.join(sqlitePath, f"{database}.db")}'
|
||||||
|
if not database_exists(cn):
|
||||||
|
create_database(cn)
|
||||||
|
return cn
|
3
src/modules/DashboardClient.py
Normal file
3
src/modules/DashboardClient.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class DashboardClient:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
@ -6,6 +6,8 @@ from sqlalchemy_utils import database_exists, create_database
|
|||||||
import sqlalchemy as db
|
import sqlalchemy as db
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from .ConnectionString import ConnectionString
|
||||||
from .Utilities import (
|
from .Utilities import (
|
||||||
GetRemoteEndpoint, ValidateDNSAddress
|
GetRemoteEndpoint, ValidateDNSAddress
|
||||||
)
|
)
|
||||||
@ -84,7 +86,7 @@ class DashboardConfig:
|
|||||||
if not exist:
|
if not exist:
|
||||||
self.SetConfig(section, key, value, True)
|
self.SetConfig(section, key, value, True)
|
||||||
|
|
||||||
self.engine = db.create_engine(self.getConnectionString('wgdashboard'))
|
self.engine = db.create_engine(ConnectionString('wgdashboard'))
|
||||||
self.dbMetadata = db.MetaData()
|
self.dbMetadata = db.MetaData()
|
||||||
self.__createAPIKeyTable()
|
self.__createAPIKeyTable()
|
||||||
self.DashboardAPIKeys = self.__getAPIKeys()
|
self.DashboardAPIKeys = self.__getAPIKeys()
|
||||||
|
@ -4,10 +4,12 @@ Dashboard Logger Class
|
|||||||
import uuid
|
import uuid
|
||||||
import sqlalchemy as db
|
import sqlalchemy as db
|
||||||
|
|
||||||
|
from .ConnectionString import ConnectionString
|
||||||
|
|
||||||
|
|
||||||
class DashboardLogger:
|
class DashboardLogger:
|
||||||
def __init__(self, DashboardConfig):
|
def __init__(self, DashboardConfig):
|
||||||
self.engine = db.create_engine(DashboardConfig.getConnectionString("wgdashboard_log"))
|
self.engine = db.create_engine(ConnectionString("wgdashboard_log"))
|
||||||
self.metadata = db.MetaData()
|
self.metadata = db.MetaData()
|
||||||
self.dashboardLoggerTable = db.Table('DashboardLog', self.metadata,
|
self.dashboardLoggerTable = db.Table('DashboardLog', self.metadata,
|
||||||
db.Column('LogID', db.String(255), nullable=False, primary_key=True),
|
db.Column('LogID', db.String(255), nullable=False, primary_key=True),
|
||||||
|
@ -3,11 +3,13 @@ Peer Job Logger
|
|||||||
"""
|
"""
|
||||||
import uuid
|
import uuid
|
||||||
import sqlalchemy as db
|
import sqlalchemy as db
|
||||||
|
|
||||||
|
from .ConnectionString import ConnectionString
|
||||||
from .Log import Log
|
from .Log import Log
|
||||||
|
|
||||||
class PeerJobLogger:
|
class PeerJobLogger:
|
||||||
def __init__(self, AllPeerJobs, DashboardConfig):
|
def __init__(self, AllPeerJobs, DashboardConfig):
|
||||||
self.engine = db.create_engine(DashboardConfig.getConnectionString("wgdashboard_log"))
|
self.engine = db.create_engine(ConnectionString("wgdashboard_log"))
|
||||||
self.metadata = db.MetaData()
|
self.metadata = db.MetaData()
|
||||||
self.jobLogTable = db.Table('JobLog', self.metadata,
|
self.jobLogTable = db.Table('JobLog', self.metadata,
|
||||||
db.Column('LogID', db.String(255), nullable=False, primary_key=True),
|
db.Column('LogID', db.String(255), nullable=False, primary_key=True),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Peer Jobs
|
Peer Jobs
|
||||||
"""
|
"""
|
||||||
|
from .ConnectionString import ConnectionString
|
||||||
from .PeerJob import PeerJob
|
from .PeerJob import PeerJob
|
||||||
from .PeerJobLogger import PeerJobLogger
|
from .PeerJobLogger import PeerJobLogger
|
||||||
import sqlalchemy as db
|
import sqlalchemy as db
|
||||||
@ -9,7 +10,7 @@ from datetime import datetime
|
|||||||
class PeerJobs:
|
class PeerJobs:
|
||||||
def __init__(self, DashboardConfig, WireguardConfigurations):
|
def __init__(self, DashboardConfig, WireguardConfigurations):
|
||||||
self.Jobs: list[PeerJob] = []
|
self.Jobs: list[PeerJob] = []
|
||||||
self.engine = db.create_engine(DashboardConfig.getConnectionString('wgdashboard_job'))
|
self.engine = db.create_engine(ConnectionString('wgdashboard_job'))
|
||||||
self.metadata = db.MetaData()
|
self.metadata = db.MetaData()
|
||||||
self.peerJobTable = db.Table('PeerJobs', self.metadata,
|
self.peerJobTable = db.Table('PeerJobs', self.metadata,
|
||||||
db.Column('JobID', db.String(255), nullable=False, primary_key=True),
|
db.Column('JobID', db.String(255), nullable=False, primary_key=True),
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from .ConnectionString import ConnectionString
|
||||||
from .PeerShareLink import PeerShareLink
|
from .PeerShareLink import PeerShareLink
|
||||||
import sqlalchemy as db
|
import sqlalchemy as db
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -9,7 +10,7 @@ Peer Share Links
|
|||||||
class PeerShareLinks:
|
class PeerShareLinks:
|
||||||
def __init__(self, DashboardConfig):
|
def __init__(self, DashboardConfig):
|
||||||
self.Links: list[PeerShareLink] = []
|
self.Links: list[PeerShareLink] = []
|
||||||
self.engine = db.create_engine(DashboardConfig.getConnectionString("wgdashboard"))
|
self.engine = db.create_engine(ConnectionString("wgdashboard"))
|
||||||
self.metadata = db.MetaData()
|
self.metadata = db.MetaData()
|
||||||
self.peerShareLinksTable = db.Table(
|
self.peerShareLinksTable = db.Table(
|
||||||
'PeerShareLinks', self.metadata,
|
'PeerShareLinks', self.metadata,
|
||||||
|
@ -6,6 +6,7 @@ from zipfile import ZipFile
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
|
|
||||||
|
from .ConnectionString import ConnectionString
|
||||||
from .DashboardConfig import DashboardConfig
|
from .DashboardConfig import DashboardConfig
|
||||||
from .Peer import Peer
|
from .Peer import Peer
|
||||||
from .PeerJobs import PeerJobs
|
from .PeerJobs import PeerJobs
|
||||||
@ -56,7 +57,7 @@ class WireguardConfiguration:
|
|||||||
self.DashboardConfig = DashboardConfig
|
self.DashboardConfig = DashboardConfig
|
||||||
self.AllPeerShareLinks = AllPeerShareLinks
|
self.AllPeerShareLinks = AllPeerShareLinks
|
||||||
self.configPath = os.path.join(self.__getProtocolPath(), f'{self.Name}.conf')
|
self.configPath = os.path.join(self.__getProtocolPath(), f'{self.Name}.conf')
|
||||||
self.engine: sqlalchemy.engine = sqlalchemy.create_engine(self.DashboardConfig.getConnectionString("wgdashboard"))
|
self.engine: sqlalchemy.engine = sqlalchemy.create_engine(ConnectionString("wgdashboard"))
|
||||||
self.metadata: sqlalchemy.MetaData = sqlalchemy.MetaData()
|
self.metadata: sqlalchemy.MetaData = sqlalchemy.MetaData()
|
||||||
self.dbType = self.DashboardConfig.GetConfig("Database", "type")[1]
|
self.dbType = self.DashboardConfig.GetConfig("Database", "type")[1]
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ const submit = (e) => {
|
|||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
autofocus
|
autofocus
|
||||||
class="form-control rounded-3" id="email" placeholder="email">
|
class="form-control rounded-3" id="email" placeholder="email">
|
||||||
<label for="floatingInput" class="d-flex">
|
<label for="email" class="d-flex">
|
||||||
<i class="bi bi-person-circle me-2"></i>
|
<i class="bi bi-person-circle me-2"></i>
|
||||||
Email
|
Email
|
||||||
</label>
|
</label>
|
||||||
@ -41,9 +41,9 @@ const submit = (e) => {
|
|||||||
required
|
required
|
||||||
v-model="formData.password"
|
v-model="formData.password"
|
||||||
name="password"
|
name="password"
|
||||||
autocomplete="password"
|
autocomplete="current-password"
|
||||||
class="form-control rounded-3" id="password" placeholder="Password">
|
class="form-control rounded-3" id="password" placeholder="Password">
|
||||||
<label for="floatingInput" class="d-flex">
|
<label for="password" class="d-flex">
|
||||||
<i class="bi bi-key me-2"></i>
|
<i class="bi bi-key me-2"></i>
|
||||||
Password
|
Password
|
||||||
</label>
|
</label>
|
||||||
|
@ -22,7 +22,7 @@ const formData = reactive({
|
|||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
autofocus
|
autofocus
|
||||||
class="form-control rounded-3" id="email" placeholder="email">
|
class="form-control rounded-3" id="email" placeholder="email">
|
||||||
<label for="floatingInput" class="d-flex">
|
<label for="email" class="d-flex">
|
||||||
<i class="bi bi-person-circle me-2"></i>
|
<i class="bi bi-person-circle me-2"></i>
|
||||||
Email
|
Email
|
||||||
</label>
|
</label>
|
||||||
@ -32,10 +32,10 @@ const formData = reactive({
|
|||||||
required
|
required
|
||||||
v-model="formData.password"
|
v-model="formData.password"
|
||||||
name="password"
|
name="password"
|
||||||
autocomplete="password"
|
autocomplete="new-password"
|
||||||
autofocus
|
autofocus
|
||||||
class="form-control rounded-3" id="password" placeholder="password">
|
class="form-control rounded-3" id="password" placeholder="password">
|
||||||
<label for="floatingInput" class="d-flex">
|
<label for="password" class="d-flex">
|
||||||
<i class="bi bi-key me-2"></i>
|
<i class="bi bi-key me-2"></i>
|
||||||
Password
|
Password
|
||||||
</label>
|
</label>
|
||||||
@ -45,10 +45,10 @@ const formData = reactive({
|
|||||||
required
|
required
|
||||||
v-model="formData.password"
|
v-model="formData.password"
|
||||||
name="confirm_password"
|
name="confirm_password"
|
||||||
autocomplete="confirm_password"
|
autocomplete="new-password"
|
||||||
autofocus
|
autofocus
|
||||||
class="form-control rounded-3" id="confirm_password" placeholder="confirm_password">
|
class="form-control rounded-3" id="confirm_password" placeholder="confirm_password">
|
||||||
<label for="floatingInput" class="d-flex">
|
<label for="confirm_password" class="d-flex">
|
||||||
<i class="bi bi-key me-2"></i>
|
<i class="bi bi-key me-2"></i>
|
||||||
Confirm Password
|
Confirm Password
|
||||||
</label>
|
</label>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user