Skip to content

Commit c7d3809

Browse files
authored
Improve exception handling in Guacamole view & Vpshere (#2655)
* Improve exception handling in Guacamole view & Vpshere exception
1 parent c325da5 commit c7d3809

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

modules/machinery/vsphere.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def _initialize_check(self):
113113
raise CuckooCriticalError(
114114
f"Snapshot for machine {machine.label} not in powered-on state, please create one"
115115
)
116-
except Exception:
117-
raise CuckooCriticalError("Couldn't connect to vSphere host")
116+
except Exception as e:
117+
logging.exception("Couldn't connect to vSphere host")
118+
raise CuckooCriticalError(f"Couldn't connect to vSphere host: {e}")
118119

119120
super(vSphere, self)._initialize_check()
120121

web/guac/templates/guac/error.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load static %}
12
<!DOCTYPE html>
23
<html>
34
<head>

web/guac/views.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
from base64 import urlsafe_b64decode
22
from xml.etree import ElementTree as ET
3-
43
from django.shortcuts import render
5-
64
from lib.cuckoo.common.config import Config
75

86
try:
97
import libvirt
8+
9+
LIBVIRT_AVAILABLE = True
1010
except ImportError:
1111
print("Missed python-libvirt. Use extra/libvirt_installer.sh")
12+
LIBVIRT_AVAILABLE = False
1213

1314
machinery = Config().cuckoo.machinery
15+
machinery_available = ["kvm", "qemu"]
1416
machinery_dsn = getattr(Config(machinery), machinery).get("dsn", "qemu:///system")
1517

1618

1719
def index(request, task_id, session_data):
18-
conn = libvirt.open(machinery_dsn)
20+
if not LIBVIRT_AVAILABLE:
21+
return render(
22+
request,
23+
"guac/error.html",
24+
{"error_msg": "Libvirt not available", "error": "remote session", "task_id": task_id},
25+
)
26+
27+
if machinery not in machinery_available:
28+
return render(
29+
request,
30+
"guac/error.html",
31+
{"error_msg": f"Machinery type '{machinery}' is not supported", "error": "remote session", "task_id": task_id},
32+
)
33+
34+
conn = None
35+
state = None
1936
recording_name = ""
37+
38+
conn = libvirt.open(machinery_dsn)
2039
if conn:
2140
try:
2241
session_id, label, guest_ip = urlsafe_b64decode(session_data).decode("utf8").split("|")

0 commit comments

Comments
 (0)