mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 07:46:18 +00:00
Update Plugins
This commit is contained in:
@@ -37,7 +37,7 @@ from client import createClientBlueprint
|
||||
from logging.config import dictConfig
|
||||
|
||||
from modules.DashboardClients import DashboardClients
|
||||
from modules.DashboardPlugin import DashboardPlugin
|
||||
from modules.DashboardPlugins import DashboardPlugins
|
||||
|
||||
dictConfig({
|
||||
'version': 1,
|
||||
@@ -1443,7 +1443,7 @@ WireguardConfigurations: dict[str, WireguardConfiguration] = {}
|
||||
AllPeerShareLinks: PeerShareLinks = PeerShareLinks(DashboardConfig, WireguardConfigurations)
|
||||
AllPeerJobs: PeerJobs = PeerJobs(DashboardConfig, WireguardConfigurations)
|
||||
DashboardLogger: DashboardLogger = DashboardLogger()
|
||||
DashboardPlugin: DashboardPlugin = DashboardPlugin(app, WireguardConfigurations)
|
||||
DashboardPlugin: DashboardPlugins = DashboardPlugins(app, WireguardConfigurations)
|
||||
|
||||
|
||||
InitWireguardConfigurationsList(startup=True)
|
||||
|
@@ -7,7 +7,7 @@ date = datetime.today().strftime('%Y_%m_%d_%H_%M_%S')
|
||||
|
||||
def post_worker_init(worker):
|
||||
dashboard.startThreads()
|
||||
dashboard.DashboardPlugin.startThreads()
|
||||
dashboard.DashboardPlugins.startThreads()
|
||||
|
||||
worker_class = 'gthread'
|
||||
workers = 1
|
||||
|
@@ -6,7 +6,7 @@ from typing import Dict, Callable, List, Optional
|
||||
import threading
|
||||
|
||||
|
||||
class DashboardPlugin:
|
||||
class DashboardPlugins:
|
||||
|
||||
def __init__(self, app, WireguardConfigurations, directory: str = 'plugins'):
|
||||
self.directory = Path('plugins')
|
123
src/plugins/DashboardPluginsManager.py
Normal file
123
src/plugins/DashboardPluginsManager.py
Normal file
@@ -0,0 +1,123 @@
|
||||
# Not using it
|
||||
|
||||
# import os.path
|
||||
# import shutil
|
||||
# import requests
|
||||
# import subprocess
|
||||
#
|
||||
# class DashboardPluginsManager:
|
||||
# def __init__(self):
|
||||
# self.baseUrl = "https://api.github.com/repos/WGDashboard/WGDashboard-Plugins/contents/"
|
||||
# self.discoveredPlugins = {}
|
||||
#
|
||||
# def discoverPlugins(self):
|
||||
# self.discoveredPlugins.clear()
|
||||
# print('[#] Discovering plugins on GitHub')
|
||||
# try:
|
||||
# pluginsRepo = requests.get(self.baseUrl)
|
||||
# repoData = pluginsRepo.json()
|
||||
# except Exception as e:
|
||||
# print(f"[!] Failed to fetch list of plugins. Reason: {str(e)}")
|
||||
# exit(1)
|
||||
#
|
||||
# for plugin in repoData:
|
||||
# if plugin['type'] == 'dir' and not plugin['path'].startswith('.'):
|
||||
# self.discoveredPlugins[plugin['name']] = plugin['url']
|
||||
# print(f'[#] Discovered {len(self.discoveredPlugins.keys())} plugin(s)')
|
||||
#
|
||||
# def downloadPlugin(self, url: str, level = 1):
|
||||
# chunkSize = 8192
|
||||
# try:
|
||||
# data = requests.get(url)
|
||||
# files = data.json()
|
||||
# for f in files:
|
||||
# if f['type'] == 'dir':
|
||||
# if not os.path.exists(f['path']):
|
||||
# os.mkdir(f['path'])
|
||||
# print(f"[#] {" " * level}|__ {f['path']}")
|
||||
# self.downloadPlugin(f['url'], level+1)
|
||||
# elif f['type'] == 'file':
|
||||
#
|
||||
# data = requests.get(f['download_url'], stream=True)
|
||||
# totalSize = int(f['size'])
|
||||
# downloadedSize = 0
|
||||
# with open(f['path'], 'wb+') as fb:
|
||||
# for chunk in data.iter_content(chunk_size=chunkSize):
|
||||
# if chunk:
|
||||
# fb.write(chunk)
|
||||
# if chunkSize >= totalSize or downloadedSize + chunkSize > totalSize:
|
||||
# downloadedSize = totalSize
|
||||
# else:
|
||||
# downloadedSize += chunkSize
|
||||
# percentage = round((downloadedSize / totalSize) * 100, 2)
|
||||
# print(f'\r[#] {" " * level}|__ {f['name']}: {percentage}%', end='', flush=True)
|
||||
# print()
|
||||
# sha = subprocess.check_output(['git', 'hash-object', f['path']]).decode('utf-8').strip('\n')
|
||||
# if sha != f['sha']:
|
||||
# print(f"[!] File corrupted: {f['path']}")
|
||||
# exit(1)
|
||||
# except Exception as e:
|
||||
# print(f"[!] Failed to download. Reason: {str(e)}")
|
||||
# print(e.__traceback__)
|
||||
# exit(1)
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# if __name__ == "__main__":
|
||||
# title = "WGDashboard Plugin Manager [by @donaldzou]"
|
||||
# border = "=" * (len(title) + 4)
|
||||
#
|
||||
# print(border)
|
||||
# print(f"| {title} |")
|
||||
# print(border)
|
||||
# print()
|
||||
#
|
||||
# downloader = DashboardPluginsManager()
|
||||
# downloader.discoverPlugins()
|
||||
#
|
||||
# if not downloader.discoveredPlugins:
|
||||
# print('[!] No plugin available')
|
||||
# exit(1)
|
||||
#
|
||||
# print()
|
||||
# pluginMenuTitle = 'Available Plugin(s)'
|
||||
# print(border)
|
||||
# print(f"| {pluginMenuTitle: ^{len(title)}} |")
|
||||
# print(border)
|
||||
# print()
|
||||
# for p in downloader.discoveredPlugins.keys():
|
||||
# print(f'[>] {p}')
|
||||
# print()
|
||||
# print(border)
|
||||
#
|
||||
# choice = None
|
||||
#
|
||||
# print("[?] Which plugin you want to install")
|
||||
# print("[?] Or type [exit] to terminate")
|
||||
# while choice is None:
|
||||
# c = input("[?] Plugin name: ")
|
||||
# if c == 'exit':
|
||||
# exit(1)
|
||||
# if c in downloader.discoveredPlugins.keys():
|
||||
# choice = c
|
||||
# else:
|
||||
# print(f"[!] {c} is not a available plugin")
|
||||
#
|
||||
# if os.path.exists(choice):
|
||||
# print(f"[!] {choice} already installed. Install it again will remove previous installation.")
|
||||
# c = input("[?] Are you sure to continue [y/Y | n/N]: ")
|
||||
# if c.lower() == 'n':
|
||||
# print("[!] Exiting now...")
|
||||
# exit(0)
|
||||
# print("[#] Removing previous installation")
|
||||
# shutil.rmtree(choice)
|
||||
# os.mkdir(choice)
|
||||
# print(f"\n[#] Starting to download {choice}")
|
||||
# downloader.downloadPlugin(downloader.discoveredPlugins[choice])
|
||||
#
|
@@ -1,12 +0,0 @@
|
||||
import rrdtool
|
||||
|
||||
rrdtool.graph(
|
||||
'daily_wg0.png',
|
||||
'--start', '-300',
|
||||
'--end', 'now',
|
||||
'--title', 'Daily Traffic',
|
||||
'DEF:in=./plugins/rrd_data/wg0.rrd:in:AVERAGE',
|
||||
'DEF:out=./plugins/rrd_data/wg0.rrd:out:AVERAGE',
|
||||
'LINE1:in#00FF00:Incoming Traffic',
|
||||
'LINE1:out#0000FF:Outgoing Traffic'
|
||||
)
|
@@ -1,50 +0,0 @@
|
||||
"""
|
||||
Update this to fit your need, currently it is 300 seconds
|
||||
"""
|
||||
__INTERVAL = 10
|
||||
|
||||
def main(WireguardConfigurations: dict = None):
|
||||
import os.path
|
||||
from time import sleep, time
|
||||
import rrdtool
|
||||
|
||||
while True:
|
||||
for c in WireguardConfigurations.keys():
|
||||
rrd_path = f"./plugins/rrd_data/{c}.rrd"
|
||||
|
||||
if not os.path.exists(rrd_path):
|
||||
print(f"Creating RRD for {c}")
|
||||
rrdtool.create(
|
||||
rrd_path,
|
||||
'--step', str(__INTERVAL),
|
||||
f'DS:in:COUNTER:{__INTERVAL * 2}:0:U',
|
||||
f'DS:out:COUNTER:{__INTERVAL * 2}:0:U',
|
||||
'RRA:AVERAGE:0.5:1:8640',
|
||||
'RRA:AVERAGE:0.5:12:720',
|
||||
'RRA:AVERAGE:0.5:288:365',
|
||||
'RRA:AVERAGE:0.5:2016:52',
|
||||
'RRA:AVERAGE:0.5:8640:1'
|
||||
)
|
||||
|
||||
configuration = WireguardConfigurations[c]
|
||||
current_time = int(time())
|
||||
|
||||
json_data = configuration.toJson()
|
||||
receive_gb = json_data["DataUsage"]["Receive"]
|
||||
sent_gb = json_data["DataUsage"]["Sent"]
|
||||
receive_bytes = int(receive_gb * (1024 ** 3))
|
||||
sent_bytes = int(sent_gb * (1024 ** 3))
|
||||
|
||||
print(f"{c}: Receive={receive_gb}GB ({receive_bytes} bytes), Sent={sent_gb}GB ({sent_bytes} bytes)")
|
||||
|
||||
update_string = f'{current_time}:{receive_bytes}:{sent_bytes}'
|
||||
print(f"Updating {c} with: {update_string}")
|
||||
|
||||
try:
|
||||
rrdtool.update(rrd_path, update_string)
|
||||
print(f"Successfully updated {c}")
|
||||
except Exception as e:
|
||||
print(f"Error updating {c}: {e}")
|
||||
|
||||
sleep(__INTERVAL)
|
||||
|
@@ -1 +0,0 @@
|
||||
rrdtool
|
@@ -1,2 +0,0 @@
|
||||
def main(WireguardConfigurations):
|
||||
print("This is a plugin")
|
Reference in New Issue
Block a user