diff --git a/netbox_proxbox/main.py b/netbox_proxbox/main.py index a16bdf8..e4a3afe 100755 --- a/netbox_proxbox/main.py +++ b/netbox_proxbox/main.py @@ -25,6 +25,10 @@ from netbox import configuration +""" +CORS ORIGINS +""" + plugin_configuration = configuration.PLUGINS_CONFIG uvicorn_host = plugin_configuration["netbox_proxbox"]["fastapi"]["uvicorn_host"] @@ -39,6 +43,8 @@ netbox_port = plugin_configuration["netbox_proxbox"]["netbox"]["http_port"] netbox_endpoint_port80 = f"http://{netbox_host}:80" +netbox_endpoint_port8000 = f"http://{netbox_host}:8000" + netbox_endpoint = f"http://{netbox_host}:{netbox_port}" https_netbox_endpoint = f"https://{netbox_host}:{netbox_port}" @@ -51,12 +57,17 @@ version="0.0.1" ) +""" +CORS Middleware +""" + origins = [ fastapi_endpoint, https_fastapi_endpoint, netbox_endpoint, https_netbox_endpoint, netbox_endpoint_port80, + netbox_endpoint_port8000, fastapi_endpoint_port8000, fastapi_endpoint_port80, "http://localhost", @@ -108,47 +119,6 @@ async def websocket_endpoint( # Routes (Endpoints) # -html = """ - - - - Chat - - -

Log Messages

- - - - - -""" - -@app.get("/websocket") -async def get(): - return HTMLResponse(html) - - # Netbox Routes app.include_router(netbox_router, prefix="/netbox", tags=["netbox"]) app.include_router(nb_dcim_router, prefix="/netbox/dcim", tags=["netbox / dcim"]) diff --git a/netbox_proxbox/templates/netbox_proxbox/home.html b/netbox_proxbox/templates/netbox_proxbox/home.html index 74b066a..d969265 100755 --- a/netbox_proxbox/templates/netbox_proxbox/home.html +++ b/netbox_proxbox/templates/netbox_proxbox/home.html @@ -26,6 +26,8 @@

Log Messages

fastapi_endpoint = `http://${uvicorn_host}:${uvicorn_port}` websocket_endpoint = `ws://${uvicorn_host}:${uvicorn_port}/ws` + + console.log(fastapi_endpoint) console.log(websocket_endpoint) var ws = new WebSocket(websocket_endpoint); @@ -54,24 +56,48 @@

Log Messages

event.preventDefault() } - const xhr = new XMLHttpRequest(); - xhr.open('GET', `${fastapi_endpoint}?source=netbox&list_all=false&plugin_name=netbox_proxbox`, true); + //function getProxmoxVersion() { - xhr.onload = function() { - if (xhr.status === 200) { - const data = JSON.parse(xhr.responseText); - console.log(data); - } else { - console.error(`Request failed. Status: ${xhr.status}`); - } - }; + //console.log(domain) - xhr.onerror = function() { - console.error('Network error'); - }; + function getBody () { + body = document.getElementsByTagName("body") + body = body[0] + + let arrai = Array.from(document.getElementsByTagName("tr")) + console.log("arrai0", arrai) - xhr.send(); + body.onload = getVersion + console.log("body", body) + } + + getBody() + + async function getVersion() { + + let elemento = document.getElementsByClassName("proxmox_version") + + for (let item of elemento) { + + let td = item.getElementsByTagName("td") + + if (td[0].id) { + + try { + request = await fetch(`${fastapi_endpoint}/proxmox/version?source=netbox&list_all=false&plugin_name=netbox_proxbox&domain=${td[0].id}`) + response = await request.json() + + console.log(response[0]) + } catch (error) { + console.log(error) + } + + td[0].textContent = JSON.stringify(response) + + } + } + }
@@ -105,104 +131,100 @@

{% for px in configuration.netbox_proxbox.proxmox %} -
-
-
-
- - Proxmox Logo - -
-
- - - +
+
+
+
+ + Proxmox Logo + +
+
+
Domain / IP
+ + + {% if px.domain %} + + {% else %} + + {% endif %} + + + + {% if px.http_port %} + + {% else %} + + {% endif %} + + + + {% if px.user %} + + {% else %} + + {% endif %} + + + + {% if px.password %} + + {% else %} + + {% endif %} + + + {% if px.token.name %} + + {% else %} + + {% endif %} + + + + + + + {% if px.ssl %} + + {% else %} + + {% endif %} + + + + + +
Domain / IP{{ px.domain }}{{ default_config.proxmox.domain }} (default)
HTTP Port{{ px.http_port }}{{ default_config.proxmox.http_port }} (default)
Proxmox User{{ px.user }}{{ default_config.proxmox.user }} (default)
Proxmox Passwordpassword defined in configuration.py(secret) (default)
Token Name{{ px.token.name }}{{ default_config.proxmox.token.name }} (default)
Token Value(secret)
SSL{{ px.ssl }}{{ default_config.proxmox.ssl }} (default)
Proxmox Version
+
{% if px.domain %} - {{ px.domain }} - {% else %} - {{ default_config.proxmox.domain }} (default) - {% endif %} - - - HTTP Port - {% if px.http_port %} - {{ px.http_port }} +
+ + + Proxmox Update +
{% else %} - {{ default_config.proxmox.http_port }} (default) - {% endif %} - - - Proxmox User - {% if px.user %} - {{ px.user }} - {% else %} - {{ default_config.proxmox.user }} (default) - {% endif %} - - - Proxmox Password - {% if px.password %} - password defined in configuration.py - {% else %} - (secret) (default) - {% endif %} - - Token Name - {% if px.token.name %} - {{ px.token.name }} - {% else %} - {{ default_config.proxmox.token.name }} (default) - {% endif %} - - Token Value - (secret) - - - SSL - {% if px.ssl %} - {{ px.ssl }} - {% else %} - {{ default_config.proxmox.ssl }} (default) - {% endif %} - - - Proxmox Version - {% if px.ssl %} - {{ px.ssl }} - {% else %} - {{ default_config.proxmox.ssl }} (default) - {% endif %} - - -
- {% if px.domain %} -
- - Proxmox Update -
- {% else %} - Proxmox Update - {% endif %} - + {% endif %} + +
-
{% endfor %}
diff --git a/netbox_proxbox/views.py b/netbox_proxbox/views.py index a947a94..b609be5 100755 --- a/netbox_proxbox/views.py +++ b/netbox_proxbox/views.py @@ -42,6 +42,12 @@ def get(self, request): # print("plugin_configuration: ", plugin_configuration, "\n\n") # print("default_config: ", default_config) + + uvicorn_host = plugin_configuration["netbox_proxbox"]["fastapi"]["uvicorn_host"] + uvicorn_port = plugin_configuration["netbox_proxbox"]["fastapi"]["uvicorn_port"] + + fastapi_endpoint = f"http://{uvicorn_host}:{uvicorn_port}" + return render( request, self.template_name,