mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-06-28 01:06: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):
|
||||
from modules.DashboardClients import DashboardClients
|
||||
DashboardClients = DashboardClients()
|
||||
DashboardClients = DashboardClients(wireguardConfigurations)
|
||||
client = Blueprint('client', __name__, template_folder=os.path.abspath("./static/client/dist"))
|
||||
prefix = f'{dashboardConfig.GetConfig("Server", "app_prefix")[1]}/client'
|
||||
|
||||
@ -96,6 +96,6 @@ def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration],
|
||||
@client.get(f'{prefix}/api/configurations')
|
||||
@login_required
|
||||
def ClientAPI_Configurations():
|
||||
return ResponseObject(True, "Ping Pong!")
|
||||
return ResponseObject(True, data=DashboardClients.GetClientAssignedPeers(session['ClientID']))
|
||||
|
||||
return client
|
@ -11,10 +11,11 @@ from .DashboardClientsTOTP import DashboardClientsTOTP
|
||||
from .Utilities import ValidatePasswordStrength
|
||||
from .DashboardLogger import DashboardLogger
|
||||
|
||||
from flask import session
|
||||
|
||||
|
||||
class DashboardClients:
|
||||
def __init__(self):
|
||||
def __init__(self, wireguardConfigurations):
|
||||
self.logger = DashboardLogger()
|
||||
self.engine = db.create_engine(ConnectionString("wgdashboard"))
|
||||
self.metadata = db.MetaData()
|
||||
@ -46,7 +47,7 @@ class DashboardClients:
|
||||
self.Clients = []
|
||||
self.__getClients()
|
||||
self.DashboardClientsTOTP = DashboardClientsTOTP()
|
||||
self.DashboardClientsPeerAssignment = DashboardClientsPeerAssignment()
|
||||
self.DashboardClientsPeerAssignment = DashboardClientsPeerAssignment(wireguardConfigurations)
|
||||
|
||||
def __getClients(self):
|
||||
with self.engine.connect() as conn:
|
||||
@ -72,6 +73,7 @@ class DashboardClients:
|
||||
if existingClient:
|
||||
checkPwd = bcrypt.checkpw(Password.encode("utf-8"), existingClient.get("Password").encode("utf-8"))
|
||||
if checkPwd:
|
||||
session['ClientID'] = existingClient.get("ClientID")
|
||||
return True, self.DashboardClientsTOTP.GenerateToken(existingClient.get("ClientID"))
|
||||
return False, "Email or Password is incorrect"
|
||||
|
||||
@ -145,5 +147,8 @@ class DashboardClients:
|
||||
|
||||
return True, None
|
||||
|
||||
def GetClientAssignedPeers(self, ClientID):
|
||||
return self.DashboardClientsPeerAssignment.GetAssignedPeers(ClientID)
|
||||
|
||||
def UpdatePassword(self, CurrentPassword, NewPassword, ConfirmNewPassword):
|
||||
pass
|
@ -1,14 +1,18 @@
|
||||
import uuid
|
||||
|
||||
from .ConnectionString import ConnectionString
|
||||
from .DashboardLogger import DashboardLogger
|
||||
import sqlalchemy as db
|
||||
|
||||
from .WireguardConfiguration import WireguardConfiguration
|
||||
|
||||
|
||||
class DashboardClientsPeerAssignment:
|
||||
def __init__(self):
|
||||
def __init__(self, wireguardConfigurations: dict[str, WireguardConfiguration]):
|
||||
self.logger = DashboardLogger()
|
||||
self.engine = db.create_engine(ConnectionString("wgdashboard"))
|
||||
self.metadata = db.MetaData()
|
||||
|
||||
self.wireguardConfigurations = wireguardConfigurations
|
||||
self.dashboardClientsPeerAssignmentTable = db.Table(
|
||||
'DashboardClientsPeerAssignment', self.metadata,
|
||||
db.Column('AssignmentID', db.String(255), nullable=False, primary_key=True),
|
||||
@ -24,17 +28,43 @@ class DashboardClientsPeerAssignment:
|
||||
)
|
||||
self.metadata.create_all(self.engine)
|
||||
self.assignments = []
|
||||
self.__getAssignments()
|
||||
|
||||
self.AssignClient("0117a895-bd8b-4ba2-9116-6658372417fb", "wg0", "3kv6Bo46u7ULT07B3I1VHw/rYomVnrCD5TFU369jRSc=")
|
||||
self.GetAssignedPeers("0117a895-bd8b-4ba2-9116-6658372417fb")
|
||||
|
||||
def __getAssignments(self):
|
||||
with self.engine.connect() as conn:
|
||||
self.assignments = conn.execute(
|
||||
self.dashboardClientsPeerAssignmentTable.select().where(
|
||||
self.dashboardClientsPeerAssignmentTable.c.UnassignedDate is None
|
||||
self.dashboardClientsPeerAssignmentTable.c.UnassignedDate == db.null()
|
||||
)
|
||||
).mappings().fetchall()
|
||||
|
||||
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):
|
||||
pass
|
||||
@ -43,4 +73,30 @@ class DashboardClientsPeerAssignment:
|
||||
pass
|
||||
|
||||
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>
|
||||
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>
|
||||
|
||||
<template>
|
||||
|
Loading…
x
Reference in New Issue
Block a user