mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-12-31 03:05:58 +08:00
Log function is completed
This commit is contained in:
parent
6d3091b2a2
commit
6825d728c2
7 changed files with 77 additions and 28 deletions
|
@ -106,9 +106,7 @@
|
||||||
# Must have for each peer
|
# Must have for each peer
|
||||||
```
|
```
|
||||||
|
|
||||||
- Python 3.7+ & Pip3
|
- **Python 3.10** for v4.0+, **Python 3.7 - 3.9** for v2.0 - v3.0.6.2
|
||||||
|
|
||||||
- Browser support CSS3 and ES6
|
|
||||||
|
|
||||||
## 🛠 Install
|
## 🛠 Install
|
||||||
1. Download WGDashboard
|
1. Download WGDashboard
|
||||||
|
|
8
docs/api-documents.md
Normal file
8
docs/api-documents.md
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# API Documents for WGDashboard
|
||||||
|
|
||||||
|
**Version: v4.0**
|
||||||
|
|
||||||
|
**Created by: Donald Zou**
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
0
docs/changelogs.md
Normal file
0
docs/changelogs.md
Normal file
|
@ -104,7 +104,34 @@ class Log:
|
||||||
def __dict__(self):
|
def __dict__(self):
|
||||||
return self.toJson()
|
return self.toJson()
|
||||||
|
|
||||||
class Logger:
|
class DashboardLogger:
|
||||||
|
def __init__(self):
|
||||||
|
self.loggerdb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard_log.db'),
|
||||||
|
check_same_thread=False)
|
||||||
|
self.loggerdb.row_factory = sqlite3.Row
|
||||||
|
self.loggerdbCursor = self.loggerdb.cursor()
|
||||||
|
self.__createLogDatabase()
|
||||||
|
self.log(Message="WGDashboard started")
|
||||||
|
def __createLogDatabase(self):
|
||||||
|
existingTable = self.loggerdbCursor.execute("SELECT name from sqlite_master where type='table'").fetchall()
|
||||||
|
existingTable = [t['name'] for t in existingTable]
|
||||||
|
|
||||||
|
if "DashboardLog" not in existingTable:
|
||||||
|
self.loggerdbCursor.execute("CREATE TABLE DashboardLog (LogID VARCHAR NOT NULL, LogDate DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%S','now', 'localtime')), URL VARCHAR, IP VARCHAR, Status VARCHAR, Message VARCHAR, PRIMARY KEY (LogID))")
|
||||||
|
self.loggerdb.commit()
|
||||||
|
|
||||||
|
def log(self, URL: str = "", IP: str = "", Status: str = "true", Message: str = "") -> bool:
|
||||||
|
try:
|
||||||
|
self.loggerdbCursor.execute("INSERT INTO DashboardLog (LogID, URL, IP, Status, Message) VALUES (?, ?, ?, ?, ?)", (str(uuid.uuid4()), URL, IP, Status, Message,))
|
||||||
|
self.loggerdb.commit()
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PeerJobLogger:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.loggerdb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard_log.db'),
|
self.loggerdb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard_log.db'),
|
||||||
check_same_thread=False)
|
check_same_thread=False)
|
||||||
|
@ -1208,6 +1235,13 @@ API Routes
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def auth_req():
|
def auth_req():
|
||||||
|
if "api" in request.path:
|
||||||
|
if str(request.method) == "GET":
|
||||||
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=str(request.args))
|
||||||
|
elif str(request.method) == "POST":
|
||||||
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=f"Request Args: {str(request.args)} Body:{str(request.get_json())}")
|
||||||
|
|
||||||
|
|
||||||
authenticationRequired = DashboardConfig.GetConfig("Server", "auth_req")[1]
|
authenticationRequired = DashboardConfig.GetConfig("Server", "auth_req")[1]
|
||||||
d = request.headers
|
d = request.headers
|
||||||
if authenticationRequired:
|
if authenticationRequired:
|
||||||
|
@ -1215,6 +1249,7 @@ def auth_req():
|
||||||
apiKeyEnabled = DashboardConfig.GetConfig("Server", "dashboard_api_key")[1]
|
apiKeyEnabled = DashboardConfig.GetConfig("Server", "dashboard_api_key")[1]
|
||||||
if apiKey is not None and len(apiKey) > 0 and apiKeyEnabled:
|
if apiKey is not None and len(apiKey) > 0 and apiKeyEnabled:
|
||||||
apiKeyExist = len(list(filter(lambda x : x.Key == apiKey, DashboardConfig.DashboardAPIKeys))) == 1
|
apiKeyExist = len(list(filter(lambda x : x.Key == apiKey, DashboardConfig.DashboardAPIKeys))) == 1
|
||||||
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=f"API Key Access: {('true' if apiKeyExist else 'false')} - Key: {apiKey}")
|
||||||
if not apiKeyExist:
|
if not apiKeyExist:
|
||||||
response = Flask.make_response(app, {
|
response = Flask.make_response(app, {
|
||||||
"status": False,
|
"status": False,
|
||||||
|
@ -1268,8 +1303,10 @@ def API_AuthenticateLogin():
|
||||||
resp = ResponseObject(True, DashboardConfig.GetConfig("Other", "welcome_session")[1])
|
resp = ResponseObject(True, DashboardConfig.GetConfig("Other", "welcome_session")[1])
|
||||||
resp.set_cookie("authToken", authToken)
|
resp.set_cookie("authToken", authToken)
|
||||||
session.permanent = True
|
session.permanent = True
|
||||||
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=f"Login success: {data['username']}")
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=f"Login failed: {data['username']}")
|
||||||
if totpEnabled:
|
if totpEnabled:
|
||||||
return ResponseObject(False, "Sorry, your username, password or OTP is incorrect.")
|
return ResponseObject(False, "Sorry, your username, password or OTP is incorrect.")
|
||||||
else:
|
else:
|
||||||
|
@ -1839,7 +1876,11 @@ def gunicornConfig():
|
||||||
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
||||||
return app_ip, app_port
|
return app_ip, app_port
|
||||||
|
|
||||||
|
import sys
|
||||||
|
if sys.version_info < (3, 10):
|
||||||
|
from typing_extensions import ParamSpec
|
||||||
|
else:
|
||||||
|
from typing import ParamSpec
|
||||||
|
|
||||||
sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False)
|
sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False)
|
||||||
sqldb.row_factory = sqlite3.Row
|
sqldb.row_factory = sqlite3.Row
|
||||||
|
@ -1847,7 +1888,8 @@ cursor = sqldb.cursor()
|
||||||
DashboardConfig = DashboardConfig()
|
DashboardConfig = DashboardConfig()
|
||||||
|
|
||||||
AllPeerJobs: PeerJobs = PeerJobs()
|
AllPeerJobs: PeerJobs = PeerJobs()
|
||||||
JobLogger: Logger = Logger()
|
JobLogger: PeerJobLogger = PeerJobLogger()
|
||||||
|
DashboardLogger: DashboardLogger = DashboardLogger()
|
||||||
_, app_ip = DashboardConfig.GetConfig("Server", "app_ip")
|
_, app_ip = DashboardConfig.GetConfig("Server", "app_ip")
|
||||||
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
||||||
_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path")
|
_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path")
|
||||||
|
@ -1862,5 +1904,6 @@ scheduleJobThread = threading.Thread(target=peerJobScheduleBackgroundThread)
|
||||||
scheduleJobThread.daemon = True
|
scheduleJobThread.daemon = True
|
||||||
scheduleJobThread.start()
|
scheduleJobThread.start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host=app_ip, debug=False, port=app_port)
|
app.run(host=app_ip, debug=False, port=app_port)
|
||||||
|
|
2
src/static/app/dist/assets/index.css
vendored
2
src/static/app/dist/assets/index.css
vendored
File diff suppressed because one or more lines are too long
40
src/static/app/dist/assets/index.js
vendored
40
src/static/app/dist/assets/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -183,7 +183,7 @@ install_wgd(){
|
||||||
_installPythonPip
|
_installPythonPip
|
||||||
|
|
||||||
|
|
||||||
version_pass=$(python3 -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 7) else print("0");')
|
version_pass=$(python3 -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 10) else print("0");')
|
||||||
if [ $version_pass == "0" ]
|
if [ $version_pass == "0" ]
|
||||||
then
|
then
|
||||||
printf "[WGDashboard] WGDashboard required Python 3.7 or above\n"
|
printf "[WGDashboard] WGDashboard required Python 3.7 or above\n"
|
||||||
|
|
Loading…
Reference in a new issue