mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-07-01 02:36:58 +00:00
Update
This commit is contained in:
parent
41bf9b8baa
commit
55027fd3cd
@ -26,7 +26,7 @@ def login_required(f):
|
|||||||
|
|
||||||
def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration], dashboardConfig: DashboardConfig):
|
def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration], dashboardConfig: DashboardConfig):
|
||||||
from modules.DashboardClients import DashboardClients
|
from modules.DashboardClients import DashboardClients
|
||||||
DashboardClients = DashboardClients()
|
DashboardClients = DashboardClients(wireguardConfigurations)
|
||||||
client = Blueprint('client', __name__, template_folder=os.path.abspath("./static/client/dist"))
|
client = Blueprint('client', __name__, template_folder=os.path.abspath("./static/client/dist"))
|
||||||
prefix = f'{dashboardConfig.GetConfig("Server", "app_prefix")[1]}/client'
|
prefix = f'{dashboardConfig.GetConfig("Server", "app_prefix")[1]}/client'
|
||||||
|
|
||||||
@ -96,6 +96,6 @@ def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration],
|
|||||||
@client.get(f'{prefix}/api/configurations')
|
@client.get(f'{prefix}/api/configurations')
|
||||||
@login_required
|
@login_required
|
||||||
def ClientAPI_Configurations():
|
def ClientAPI_Configurations():
|
||||||
return ResponseObject(True, "Ping Pong!")
|
return ResponseObject(True, data=DashboardClients.GetClientAssignedPeers(session['ClientID']))
|
||||||
|
|
||||||
return client
|
return client
|
@ -11,10 +11,11 @@ from .DashboardClientsTOTP import DashboardClientsTOTP
|
|||||||
from .Utilities import ValidatePasswordStrength
|
from .Utilities import ValidatePasswordStrength
|
||||||
from .DashboardLogger import DashboardLogger
|
from .DashboardLogger import DashboardLogger
|
||||||
|
|
||||||
|
from flask import session
|
||||||
|
|
||||||
|
|
||||||
class DashboardClients:
|
class DashboardClients:
|
||||||
def __init__(self):
|
def __init__(self, wireguardConfigurations):
|
||||||
self.logger = DashboardLogger()
|
self.logger = DashboardLogger()
|
||||||
self.engine = db.create_engine(ConnectionString("wgdashboard"))
|
self.engine = db.create_engine(ConnectionString("wgdashboard"))
|
||||||
self.metadata = db.MetaData()
|
self.metadata = db.MetaData()
|
||||||
@ -46,7 +47,7 @@ class DashboardClients:
|
|||||||
self.Clients = []
|
self.Clients = []
|
||||||
self.__getClients()
|
self.__getClients()
|
||||||
self.DashboardClientsTOTP = DashboardClientsTOTP()
|
self.DashboardClientsTOTP = DashboardClientsTOTP()
|
||||||
self.DashboardClientsPeerAssignment = DashboardClientsPeerAssignment()
|
self.DashboardClientsPeerAssignment = DashboardClientsPeerAssignment(wireguardConfigurations)
|
||||||
|
|
||||||
def __getClients(self):
|
def __getClients(self):
|
||||||
with self.engine.connect() as conn:
|
with self.engine.connect() as conn:
|
||||||
@ -72,6 +73,7 @@ class DashboardClients:
|
|||||||
if existingClient:
|
if existingClient:
|
||||||
checkPwd = bcrypt.checkpw(Password.encode("utf-8"), existingClient.get("Password").encode("utf-8"))
|
checkPwd = bcrypt.checkpw(Password.encode("utf-8"), existingClient.get("Password").encode("utf-8"))
|
||||||
if checkPwd:
|
if checkPwd:
|
||||||
|
session['ClientID'] = existingClient.get("ClientID")
|
||||||
return True, self.DashboardClientsTOTP.GenerateToken(existingClient.get("ClientID"))
|
return True, self.DashboardClientsTOTP.GenerateToken(existingClient.get("ClientID"))
|
||||||
return False, "Email or Password is incorrect"
|
return False, "Email or Password is incorrect"
|
||||||
|
|
||||||
@ -145,5 +147,8 @@ class DashboardClients:
|
|||||||
|
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
def GetClientAssignedPeers(self, ClientID):
|
||||||
|
return self.DashboardClientsPeerAssignment.GetAssignedPeers(ClientID)
|
||||||
|
|
||||||
def UpdatePassword(self, CurrentPassword, NewPassword, ConfirmNewPassword):
|
def UpdatePassword(self, CurrentPassword, NewPassword, ConfirmNewPassword):
|
||||||
pass
|
pass
|
@ -1,14 +1,18 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from .ConnectionString import ConnectionString
|
from .ConnectionString import ConnectionString
|
||||||
from .DashboardLogger import DashboardLogger
|
from .DashboardLogger import DashboardLogger
|
||||||
import sqlalchemy as db
|
import sqlalchemy as db
|
||||||
|
|
||||||
|
from .WireguardConfiguration import WireguardConfiguration
|
||||||
|
|
||||||
|
|
||||||
class DashboardClientsPeerAssignment:
|
class DashboardClientsPeerAssignment:
|
||||||
def __init__(self):
|
def __init__(self, wireguardConfigurations: dict[str, WireguardConfiguration]):
|
||||||
self.logger = DashboardLogger()
|
self.logger = DashboardLogger()
|
||||||
self.engine = db.create_engine(ConnectionString("wgdashboard"))
|
self.engine = db.create_engine(ConnectionString("wgdashboard"))
|
||||||
self.metadata = db.MetaData()
|
self.metadata = db.MetaData()
|
||||||
|
self.wireguardConfigurations = wireguardConfigurations
|
||||||
self.dashboardClientsPeerAssignmentTable = db.Table(
|
self.dashboardClientsPeerAssignmentTable = db.Table(
|
||||||
'DashboardClientsPeerAssignment', self.metadata,
|
'DashboardClientsPeerAssignment', self.metadata,
|
||||||
db.Column('AssignmentID', db.String(255), nullable=False, primary_key=True),
|
db.Column('AssignmentID', db.String(255), nullable=False, primary_key=True),
|
||||||
@ -24,17 +28,43 @@ class DashboardClientsPeerAssignment:
|
|||||||
)
|
)
|
||||||
self.metadata.create_all(self.engine)
|
self.metadata.create_all(self.engine)
|
||||||
self.assignments = []
|
self.assignments = []
|
||||||
|
self.__getAssignments()
|
||||||
|
|
||||||
|
self.AssignClient("0117a895-bd8b-4ba2-9116-6658372417fb", "wg0", "3kv6Bo46u7ULT07B3I1VHw/rYomVnrCD5TFU369jRSc=")
|
||||||
|
self.GetAssignedPeers("0117a895-bd8b-4ba2-9116-6658372417fb")
|
||||||
|
|
||||||
def __getAssignments(self):
|
def __getAssignments(self):
|
||||||
with self.engine.connect() as conn:
|
with self.engine.connect() as conn:
|
||||||
self.assignments = conn.execute(
|
self.assignments = conn.execute(
|
||||||
self.dashboardClientsPeerAssignmentTable.select().where(
|
self.dashboardClientsPeerAssignmentTable.select().where(
|
||||||
self.dashboardClientsPeerAssignmentTable.c.UnassignedDate is None
|
self.dashboardClientsPeerAssignmentTable.c.UnassignedDate == db.null()
|
||||||
)
|
)
|
||||||
).mappings().fetchall()
|
).mappings().fetchall()
|
||||||
|
|
||||||
def AssignClient(self, ClientID, ConfigurationName, PeerID):
|
def AssignClient(self, ClientID, ConfigurationName, PeerID):
|
||||||
pass
|
existing = list(
|
||||||
|
filter(lambda e:
|
||||||
|
e['ClientID'] == ClientID and
|
||||||
|
e['ConfigurationName'] == ConfigurationName and
|
||||||
|
e['PeerID'] == PeerID, self.assignments)
|
||||||
|
)
|
||||||
|
if len(existing) == 0:
|
||||||
|
if ConfigurationName in self.wireguardConfigurations.keys():
|
||||||
|
config = self.wireguardConfigurations.get(ConfigurationName)
|
||||||
|
peer = list(filter(lambda x : x.id == PeerID, config.Peers))
|
||||||
|
if len(peer) == 1:
|
||||||
|
with self.engine.begin() as conn:
|
||||||
|
data = {
|
||||||
|
"AssignmentID": uuid.uuid4(),
|
||||||
|
"ClientID": ClientID,
|
||||||
|
"ConfigurationName": ConfigurationName,
|
||||||
|
"PeerID": PeerID
|
||||||
|
}
|
||||||
|
conn.execute(
|
||||||
|
self.dashboardClientsPeerAssignmentTable.insert().values(data)
|
||||||
|
)
|
||||||
|
return True, data
|
||||||
|
return False, None
|
||||||
|
|
||||||
def UnassignClient(self, AssignmentID):
|
def UnassignClient(self, AssignmentID):
|
||||||
pass
|
pass
|
||||||
@ -43,4 +73,30 @@ class DashboardClientsPeerAssignment:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def GetAssignedPeers(self, ClientID):
|
def GetAssignedPeers(self, ClientID):
|
||||||
pass
|
peers = []
|
||||||
|
assigned = list(
|
||||||
|
filter(lambda e:
|
||||||
|
e['ClientID'] == ClientID, self.assignments)
|
||||||
|
)
|
||||||
|
|
||||||
|
for a in assigned:
|
||||||
|
peer = filter(lambda e : e.id == a['PeerID'],
|
||||||
|
self.wireguardConfigurations[a['ConfigurationName']].Peers)
|
||||||
|
for p in peer:
|
||||||
|
peers.append({
|
||||||
|
'id': p.id,
|
||||||
|
'private_key': p.private_key,
|
||||||
|
'name': p.name,
|
||||||
|
'received_data': p.total_receive + p.cumu_receive,
|
||||||
|
'sent_data': p.total_sent + p.cumu_sent,
|
||||||
|
'data': p.total_data + p.cumu_data,
|
||||||
|
'status': p.status,
|
||||||
|
'latest_handshake': p.latest_handshake,
|
||||||
|
'allowed_ip': p.allowed_ip,
|
||||||
|
'jobs': p.jobs,
|
||||||
|
'configuration_name': a['ConfigurationName'],
|
||||||
|
'peer_configuration_data': p.downloadPeer()
|
||||||
|
})
|
||||||
|
|
||||||
|
print(peers)
|
||||||
|
return peers
|
@ -1,5 +1,15 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
|
import {onMounted} from "vue";
|
||||||
|
import {axiosGet} from "@/utilities/request.js";
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
const data = await axiosGet("/api/configurations")
|
||||||
|
if (data){
|
||||||
|
console.log(data)
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user