felbinger / netbox_cybex

Features for cyber exercises in NetBox
2 stars 0 forks source link

Adjust virtualmachine / device template to display credentials inline #1

Open felbinger opened 4 months ago

felbinger commented 4 months ago

The inline credentials card needs to be added to virtualmachine.html:84 and device.html:159.

I don't know yet how to override these templates (which are part of Netbox). Until we figured it out, you can simply overwrite them in your Netbox installation. In case you're using Docker to deploy Netbox, it's easiest can remount them.

<!-- templates/virtualization/virtualmachine.html -->
<div class="row">
  <div class="col col-md-12">
    <div class="card">
      <h5 class="card-header">{% trans "Credentials" %}</h5>
      <div class="card-body htmx-container table-responsive"
        hx-get="{% url 'plugins:netbox_cybex:credential_list' %}?virtual_machine_id={{ object.pk }}"
        hx-trigger="load"></div>
      <div class="card-footer text-end noprint">
        <a href="{% url 'plugins:netbox_cybex:credential_add' %}?device={{ object.device.pk }}&virtual_machine={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-sm btn-primary">
          <span class="mdi mdi-plus-thick" aria-hidden="true"></span> {% trans "Add Credential" %}
        </a>
      </div>
    </div>
  </div>
</div><br/>
  <!-- templates/dcim/device.html -->
  <div class="row">
    <div class="col col-md-12">
      <div class="card">
        <h5 class="card-header">{% trans "Credentials" %}</h5>
        <div class="card-body htmx-container table-responsive"
          hx-get="{% url 'plugins:netbox_cybex:credential_list' %}?device={{ object.pk }}"
          hx-trigger="load"></div>
        <div class="card-footer text-end noprint">
          <a href="{% url 'plugins:netbox_cybex:credential_add' %}?device={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-sm btn-primary">
            <span class="mdi mdi-plus-thick" aria-hidden="true"></span> {% trans "Add Credential" %}
          </a>
        </div>
      </div>
    </div>
  </div><br/>
felbinger commented 3 months ago

see netbox-topology-views / netbox-qrcode plugin:

# template_content.py
from extras.plugins import PluginTemplateExtension

class CybexDevice(PluginTemplateExtension):
    model = 'dcim.device'
    # TODO

template_extensions = [CybexDevice]