1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

Added admin application

- Manage users
- Manage groups
- Manage logs
This commit is contained in:
Real-Gecko 2020-05-27 18:24:06 +06:00 committed by catborise
parent 713d565a2d
commit fec59b1dd7
37 changed files with 1106 additions and 517 deletions

View file

@ -1,60 +1,61 @@
{% load i18n %}
{% if request.user.is_superuser %}
<a href="#AddSecret" type="button" class="btn btn-success float-right" data-toggle="modal">
<span class="fa fa-plus" aria-hidden="true"></span>
</a>
<a href="#AddSecret" type="button" class="btn btn-success float-right" data-toggle="modal">
<span class="fa fa-plus" aria-hidden="true"></span>
</a>
<!-- Modal Secret -->
<div class="modal fade" id="AddSecret" tabindex="-1" role="dialog" aria-labelledby="AddSecret" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h5 class="modal-title">{% trans "Create New Secret" %}</h5>
</div>
<div class="modal-body">
<form method="post" action="" role="form" aria-label="Create Secret form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Ephemeral" %}</label>
<div class="col-sm-6">
<select name="ephemeral" class="form-control">
<option value="no">{% trans "no" %}</option>
<option value="yes">{% trans "yes" %}</option>
</select>
</div>
<!-- Modal Secret -->
<div class="modal fade" id="AddSecret" tabindex="-1" role="dialog" aria-labelledby="AddSecret" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans "Create New Secret" %}</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
<form method="post" action="" role="form" aria-label="Create Secret form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Ephemeral" %}</label>
<div class="col-sm-6">
<select name="ephemeral" class="form-control">
<option value="no">{% trans "no" %}</option>
<option value="yes">{% trans "yes" %}</option>
</select>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Private" %}</label>
<div class="col-sm-6">
<select name="private" class="form-control">
<option value="no">{% trans "no" %}</option>
<option value="yes">{% trans "yes" %}</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Usage" %}</label>
<div class="col-sm-6">
<select name="usage_type" class="form-control">
<option value="ceph">{% trans "ceph" %}</option>
<option value="volume">{% trans "volume" %}</option>
<option value="iscsi">{% trans "iscsi" %}</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 col-form-label">{% trans "Data" %}</label>
<div class="col-sm-6">
<input type="text" name="data" class="form-control" value="" required pattern="[a-z0-9\. ]+"/>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary" name="create">{% trans "Create" %}</button>
</div>
</form>
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Private" %}</label>
<div class="col-sm-6">
<select name="private" class="form-control">
<option value="no">{% trans "no" %}</option>
<option value="yes">{% trans "yes" %}</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Usage" %}</label>
<div class="col-sm-6">
<select name="usage_type" class="form-control">
{% for key, usage_type in secret_usage_types.items %}
<option value="{{ usage_type }}">{{ usage_type }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Data" %}</label>
<div class="col-sm-6">
<input type="text" name="data" class="form-control" value="" required
pattern="[a-z0-9\. ]+" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary" name="create">{% trans "Create" %}</button>
</div>
</form>
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endif %}

View file

@ -3,128 +3,129 @@
{% load staticfiles %}
{% block title %}{% trans "Secrets" %} - {{ compute.name }}{% endblock %}
{% block style %}
<link rel="stylesheet" href="{% static "css/sortable-theme-bootstrap.css" %}" />
<link rel="stylesheet" href="{% static "css/sortable-theme-bootstrap.css" %}" />
{% endblock %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_secret_block.html' %}
<h2 class="page-header">{% trans "Secrets" %}</h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
<a href="{% url 'overview' compute.id %}"><i class="fa fa-dashboard"></i> {% trans "Overview" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'instances' compute.id %}"><i class="fa fa-server"></i> {% trans "Instances" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'storages' compute.id %}"><i class="fa fa-hdd-o"></i> {% trans "Storages" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'networks' compute.id %}"><i class="fa fa-sitemap"></i> {% trans "Networks" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'interfaces' compute.id %}"><i class="fa fa-wifi"></i> {% trans "Interfaces" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'nwfilters' compute.id %}"><i class="fa fa-filter"></i> {% trans "NWFilters" %}</a>
</li>
<li class="breadcrumb-item">
<span class="font-weight-bold"><i class="fa fa-key"></i> {% trans "Secrets" %}</span>
</li>
</ol>
</nav>
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_secret_block.html' %}
<h2 class="page-header">{% trans "Secrets" %}</h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
<a href="{% url 'overview' compute.id %}"><i class="fa fa-dashboard"></i> {% trans "Overview" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'instances' compute.id %}"><i class="fa fa-server"></i> {% trans "Instances" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'storages' compute.id %}"><i class="fa fa-hdd-o"></i> {% trans "Storages" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'networks' compute.id %}"><i class="fa fa-sitemap"></i> {% trans "Networks" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'interfaces' compute.id %}"><i class="fa fa-wifi"></i> {% trans "Interfaces" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'nwfilters' compute.id %}"><i class="fa fa-filter"></i> {% trans "NWFilters" %}</a>
</li>
<li class="breadcrumb-item">
<span class="font-weight-bold"><i class="fa fa-key"></i> {% trans "Secrets" %}</span>
</li>
</ol>
</nav>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not secrets_all %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable shadow-sm">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong>
{% trans "Hypervisor doesn't have any Secrets" %}
</div>
</div>
<!-- /.row -->
{% else %}
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-hover sortable-theme-bootstrap" data-sortable>
<thead>
<tr class="active">
<th scope="col">{% trans "UUID" %}</th>
<th scope="col">{% trans "Usage Type" %}</th>
<th scope="col">{% trans "Data" %}</th>
<th scope="col" data-sortable="false" style="width:90px;">{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
{% for secret in secrets_all %}
<tr>
<th scope="row">{{ secret.uuid }}</th>
<td>{{ secret.usageType }}</td>
<td>{{ secret.usage }}</td>
<td>
<form action="" method="post" role="form" aria-label="Delete secret form">{% csrf_token %}
<input type="hidden" name="uuid" value="{{ secret.uuid }}" />
<a data-toggle="modal" href="#editSecret{{ secret.uuid }}"
class="btn btn-sm btn-primary" title="{% trans "Edit" %}">
<span class="fa fa-pencil"></span>
</a>
<button type="submit" class="btn btn-sm btn-danger" name="delete"
title="{% trans "Delete" %}"
onclick="return confirm('{% trans "Are you sure?" %}')">
<span class="fa fa-trash"></span>
</button>
</form>
{% include 'errors_block.html' %}
<div class="row">
{% if not secrets_all %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable shadow-sm">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "Hypervisor doesn't have any Secrets" %}
</div>
</div>
{% else %}
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-hover sortable-theme-bootstrap" data-sortable>
<thead>
<tr class="active">
<th scope="col">{% trans "UUID" %}</th>
<th scope="col">{% trans "Type" %}</th>
<th scope="col">{% trans "Usage" %}</th>
<th scope="col" data-sortable="false" style="width:90px;">{% trans "Action" %}</th>
</tr>
</thead>
<tbody>
{% for secret in secrets_all %}
<tr>
<th scope="row">{{ secret.uuid }}</th>
<td>{% ifequal secret.usageType 0 %}
{% trans "volume" %}
{% endifequal %}
{% ifequal secret.usageType 1 %}
{% trans "iscsi" %}
{% endifequal %}
{% ifequal secret.usageType 2 %}
{% trans "ceph" %}
{% endifequal %}
</td>
<td>{{ secret.usage }}</td>
<td>
<form action="" method="post" role="form" aria-label="Delete secret form">{% csrf_token %}
<input type="hidden" name="uuid" value="{{ secret.uuid }}"/>
<a data-toggle="modal" href="#editSecret{{ secret.uuid }}" class="btn btn-sm btn-primary" title="{% trans "Edit" %}">
<span class="fa fa-pencil"></span>
</a>
<button type="submit" class="btn btn-sm btn-danger" name="delete" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<span class="fa fa-trash"></span>
</button>
</form>
<!-- Modal -->
<div class="modal fade" id="editSecret{{ secret.uuid }}" tabindex="-1" role="dialog"
aria-labelledby="editSecret" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans "Set secret value" %}</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<!-- Modal -->
<div class="modal fade" id="editSecret{{ secret.uuid }}" tabindex="-1" role="dialog"
aria-labelledby="editSecret" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans "Set secret value" %}</h5>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
<form method="post" role="form" aria-label="Edit secret form">
{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Value" %}</label>
<input type="hidden" name="uuid" value="{{ secret.uuid }}">
<div class="col-sm-6">
<input type="text" name="value" class="form-control"
value="{{ secret.value }}" maxlength="45" required
pattern="[a-zA-Z0-9]$+">
</div>
</div>
<div class="modal-body">
<form method="post" role="form" aria-label="Edit secret form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans "Value" %}</label>
<input type="hidden" name="uuid" value="{{ secret.uuid }}">
<div class="col-sm-6">
<input type="text" name="value" class="form-control" value="{{ secret.value }}" maxlength="45" required pattern="[a-zA-Z0-9]$+">
</div>
</div>
</div> <!-- /.modal-content -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary" name="set_value">{% trans "Set" %}</button>
</div>
</form>
</div> <!-- /.tab-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div> <!-- /.modal-content -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary"
name="set_value">{% trans "Set" %}</button>
</div>
</form>
</div> <!-- /.tab-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>
{% endblock %}
{% block script %}
<script src="{% static "js/sortable.min.js" %}"></script>
<script src="{% static 'js/sortable.min.js' %}"></script>
{% endblock %}

View file

@ -1,12 +1,22 @@
from django.shortcuts import render, get_object_or_404
from secrets.forms import AddSecret
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from libvirt import libvirtError
from libvirt import VIR_SECRET_USAGE_TYPE_NONE, \
VIR_SECRET_USAGE_TYPE_CEPH, \
VIR_SECRET_USAGE_TYPE_TLS, \
VIR_SECRET_USAGE_TYPE_VOLUME, \
VIR_SECRET_USAGE_TYPE_ISCSI
from admin.decorators import superuser_only
from computes.models import Compute
from secrets.forms import AddSecret
from vrtManager.secrets import wvmSecrets
@superuser_only
def secrets(request, compute_id):
"""
:param request:
@ -14,36 +24,44 @@ def secrets(request, compute_id):
:return:
"""
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
secrets_all = []
error_messages = []
compute = get_object_or_404(Compute, pk=compute_id)
secret_usage_types = {
VIR_SECRET_USAGE_TYPE_NONE: "none",
VIR_SECRET_USAGE_TYPE_VOLUME: "volume",
VIR_SECRET_USAGE_TYPE_CEPH: "ceph",
VIR_SECRET_USAGE_TYPE_ISCSI: "iscsi",
VIR_SECRET_USAGE_TYPE_TLS: "tls",
}
try:
conn = wvmSecrets(compute.hostname,
compute.login,
compute.password,
compute.type)
conn = wvmSecrets(compute.hostname, compute.login,
compute.password, compute.type)
secrets = conn.get_secrets()
for uuid in secrets:
secrt = conn.get_secret(uuid)
try:
secret_value = conn.get_secret_value(uuid)
secrt_value = conn.get_secret_value(uuid)
except libvirtError as lib_err:
secret_value = None
secrets_all.append({'usage': secrt.usageID(),
'uuid': secrt.UUIDString(),
'usageType': secrt.usageType(),
'value': secret_value
})
secrets_all.append({
'usage': secrt.usageID(),
'uuid': secrt.UUIDString(),
'usageType': secret_usage_types[secrt.usageType()],
'value': secrt_value
})
if request.method == 'POST':
if 'create' in request.POST:
form = AddSecret(request.POST)
if form.is_valid():
data = form.cleaned_data
conn.create_secret(data['ephemeral'], data['private'], data['usage_type'], data['data'])
conn.create_secret(
data['ephemeral'],
data['private'],
data['usage_type'],
data['data'])
return HttpResponseRedirect(request.get_full_path())
else:
for msg_err in form.errors.values():
@ -55,7 +73,10 @@ def secrets(request, compute_id):
if 'set_value' in request.POST:
uuid = request.POST.get('uuid', '')
value = request.POST.get('value', '')
conn.set_secret_value(uuid, value)
try:
conn.set_secret_value(uuid, value)
except Exception as err:
error_messages.append(err)
return HttpResponseRedirect(request.get_full_path())
except libvirtError as err:
error_messages.append(err)