-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the control panel and workspace reload (#489)
* Refactored the control panel and workspace reload I Used BroadcastChannel to trigger an event through browser tabs and/or windows if a challenge (re)started. VSCode reloads the page. noVNC changes the iframe src. I added a description to the control panel and moved the notifications to the bottom of the control panel. I Limited the max-size to 50vh and made it scrollable. Therefor I changed the scrollbar to be more visible. I added the description to the test of active_module. * Improve reconnection / Control Panel increased the wait time as we now fetch the iframe url async via api. Refactor workspace API and update templates - Added `service` parameter to `view_desktop` endpoint in `workspace.py`. - Updated iframe source handling based on `service` parameter in `workspace.py`. - Simplified `view_workspace` route in `pages/workspace.py`. - Removed async URL loading and share URLs script from `iframe.html`. - Created new `workspace.html` template for dynamic iframe loading. Refactor workspace API and update templates - Added `service` parameter to `view_desktop` endpoint in `workspace.py`. - Updated iframe source handling based on `service` parameter in `workspace.py`. - Simplified `view_workspace` route in `pages/workspace.py`. - Removed async URL loading and share URLs script from `iframe.html`. - Created new `workspace.html` template for dynamic iframe loading. Improve reconnection on challenge (re)start - Added API endpoint to retrieve the current iframe URL. - Moved `container_password` to `utils`. - Relocated `start_on_demand_service` to `utils/workspace`. - Removed special route for workspace desktop. - Added edge-case handling to the workspace `<service>` route. - Updated `iframe.html` to support new functionality. - Modified `navbar.js` to use the new API endpoint. * Improve reconnection / Control Panel increased the wait time as we now fetch the iframe url async via api. Refactor workspace API and update templates - Added `service` parameter to `view_desktop` endpoint in `workspace.py`. - Updated iframe source handling based on `service` parameter in `workspace.py`. - Simplified `view_workspace` route in `pages/workspace.py`. - Removed async URL loading and share URLs script from `iframe.html`. - Created new `workspace.html` template for dynamic iframe loading. Refactor workspace API and update templates - Added `service` parameter to `view_desktop` endpoint in `workspace.py`. - Updated iframe source handling based on `service` parameter in `workspace.py`. - Simplified `view_workspace` route in `pages/workspace.py`. - Removed async URL loading and share URLs script from `iframe.html`. - Created new `workspace.html` template for dynamic iframe loading. Improve reconnection on challenge (re)start - Added API endpoint to retrieve the current iframe URL. - Moved `container_password` to `utils`. - Relocated `start_on_demand_service` to `utils/workspace`. - Removed special route for workspace desktop. - Added edge-case handling to the workspace `<service>` route. - Updated `iframe.html` to support new functionality. - Modified `navbar.js` to use the new API endpoint.
- Loading branch information
1 parent
0c88bba
commit 9009948
Showing
12 changed files
with
230 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from flask_restx import Namespace, Resource | ||
from flask import request, render_template, url_for, abort | ||
from CTFd.utils.user import get_current_user | ||
from CTFd.utils.decorators import authed_only | ||
from ...utils import get_current_container, container_password | ||
from ...utils.workspace import exec_run, start_on_demand_service | ||
|
||
|
||
workspace_namespace = Namespace( | ||
"workspace", description="Endpoint to manage workspace iframe urls" | ||
) | ||
|
||
|
||
@workspace_namespace.route("") | ||
class view_desktop(Resource): | ||
@authed_only | ||
def get(self): | ||
user_id = request.args.get("user") | ||
password = request.args.get("password") | ||
service = request.args.get("service") | ||
|
||
if not service: | ||
return { "active": False } | ||
|
||
|
||
if user_id and not password and not is_admin(): | ||
abort(403) | ||
|
||
user = get_current_user() if not user_id else Users.query.filter_by(id=int(user_id)).first_or_404() | ||
container = get_current_container(user) | ||
if not container: | ||
return { "active": False } | ||
|
||
|
||
if service == "desktop": | ||
interact_password = container_password(container, "desktop", "interact") | ||
view_password = container_password(container, "desktop", "view") | ||
|
||
if user_id and password: | ||
if not hmac.compare_digest(password, interact_password) and not hmac.compare_digest(password, view_password): | ||
abort(403) | ||
password = password[:8] | ||
else: | ||
password = interact_password[:8] | ||
|
||
view_only = user_id is not None | ||
service_param = "~".join(("desktop", str(user.id), container_password(container, "desktop"))) | ||
|
||
vnc_params = { | ||
"autoconnect": 1, | ||
"reconnect": 1, | ||
"reconnect_delay": 200, | ||
"resize": "remote", | ||
"path": url_for("pwncollege_workspace.forward_workspace", service=service_param, service_path="websockify"), | ||
"view_only": int(view_only), | ||
"password": password, | ||
} | ||
iframe_src = url_for("pwncollege_workspace.forward_workspace", service=service_param, service_path="vnc.html", **vnc_params) | ||
else: | ||
iframe_src = f"/workspace/{service}/" | ||
|
||
if start_on_demand_service(user, service) is False: | ||
return { "active": False } | ||
|
||
return { | ||
"iframe_src": iframe_src, | ||
"service": service, | ||
"active": True | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.