diff --git a/admin/templates/admin/logs.html b/admin/templates/admin/logs.html index 906fa21..39849ef 100644 --- a/admin/templates/admin/logs.html +++ b/admin/templates/admin/logs.html @@ -24,6 +24,7 @@ # {% trans "Date" %} {% trans "User" %} + {% trans "Host" %} {% trans "Instance" %} {% trans "Message" %} @@ -34,6 +35,7 @@ {{ log.id }} {{ log.date|date:"M d H:i:s" }} {{ log.user }} + {{ log.host }} {{ log.instance }} {{ log.message }} diff --git a/appsettings/views.py b/appsettings/views.py index 5446c9a..2d7bc80 100644 --- a/appsettings/views.py +++ b/appsettings/views.py @@ -24,7 +24,7 @@ def appsettings(request): themes_list = os.listdir(sass_dir.value + "/wvc-theme") except FileNotFoundError as err: messages.error(request, err) - addlogmsg(request.user.username, "", err) + addlogmsg(request.user.username, "-", "", err) # Bootstrap settings related with filesystems, because of that they are excluded from other settings appsettings = AppSettings.objects.exclude(description__startswith="Bootstrap").order_by("name") @@ -41,7 +41,7 @@ def appsettings(request): msg = err messages.error(request, msg) - addlogmsg(request.user.username, "", msg) + addlogmsg(request.user.username, "-", "", msg) return HttpResponseRedirect(request.get_full_path()) if "BOOTSTRAP_THEME" in request.POST: @@ -70,7 +70,7 @@ def appsettings(request): msg = err messages.error(request, msg) - addlogmsg(request.user.username, "", msg) + addlogmsg(request.user.username, "-", "", msg) return HttpResponseRedirect(request.get_full_path()) for setting in appsettings: @@ -85,7 +85,7 @@ def appsettings(request): msg = err messages.error(request, msg) - addlogmsg(request.user.username, "", msg) + addlogmsg(request.user.username, "-", "", msg) return HttpResponseRedirect(request.get_full_path()) return render(request, "appsettings.html", locals()) diff --git a/console/templates/console-vnc-full.html b/console/templates/console-vnc-full.html index f7c58d1..05bf5b4 100755 --- a/console/templates/console-vnc-full.html +++ b/console/templates/console-vnc-full.html @@ -219,7 +219,8 @@
  • - + +
  • diff --git a/instances/views.py b/instances/views.py index 67130d5..2fb3ab5 100644 --- a/instances/views.py +++ b/instances/views.py @@ -106,12 +106,12 @@ def instance(request, pk): # instance.uuid = uuid # instance.save() # msg = _(f"Fixing UUID {uuid}") - # addlogmsg(request.user.username, instance.name, msg) + # addlogmsg(request.user.username, instance.compute.name, instance.name, msg) # except Instance.DoesNotExist: # instance = Instance(compute=compute, name=vname, uuid=uuid) # instance.save() # msg = _("Instance does not exist: Creating new instance") - # addlogmsg(request.user.username, instance.name, msg) + # addlogmsg(request.user.username, instance.compute.name, instance.name, msg) # userinstances = UserInstance.objects.filter(instance=instance).order_by('user__username') userinstances = instance.userinstance_set.order_by("user__username") @@ -249,7 +249,7 @@ def poweron(request, pk): messages.warning(request, _("Templates cannot be started.")) else: instance.proxy.start() - addlogmsg(request.user.username, instance.name, _("Power On")) + addlogmsg(request.user.username, instance.compute.name, instance.name, _("Power On")) return redirect(request.META.get("HTTP_REFERER")) @@ -258,14 +258,14 @@ def powercycle(request, pk): instance = get_instance(request.user, pk) instance.proxy.force_shutdown() instance.proxy.start() - addlogmsg(request.user.username, instance.name, _("Power Cycle")) + addlogmsg(request.user.username, instance.compute.name, instance.name, _("Power Cycle")) return redirect(request.META.get("HTTP_REFERER")) def poweroff(request, pk): instance = get_instance(request.user, pk) instance.proxy.shutdown() - addlogmsg(request.user.username, instance.name, _("Power Off")) + addlogmsg(request.user.username, instance.compute.name, instance.name, _("Power Off")) return redirect(request.META.get("HTTP_REFERER")) @@ -274,7 +274,7 @@ def poweroff(request, pk): def suspend(request, pk): instance = get_instance(request.user, pk) instance.proxy.suspend() - addlogmsg(request.user.username, instance.name, _("Suspend")) + addlogmsg(request.user.username, instance.compute.name, instance.name, _("Suspend")) return redirect(request.META.get("HTTP_REFERER")) @@ -282,14 +282,14 @@ def suspend(request, pk): def resume(request, pk): instance = get_instance(request.user, pk) instance.proxy.resume() - addlogmsg(request.user.username, instance.name, _("Resume")) + addlogmsg(request.user.username, instance.compute.name, instance.name, _("Resume")) return redirect(request.META.get("HTTP_REFERER")) def force_off(request, pk): instance = get_instance(request.user, pk) instance.proxy.force_shutdown() - addlogmsg(request.user.username, instance.name, _("Force Off")) + addlogmsg(request.user.username, instance.compute.name, instance.name, _("Force Off")) return redirect(request.META.get("HTTP_REFERER")) @@ -316,7 +316,7 @@ def destroy(request, pk): instance.proxy.delete(VIR_DOMAIN_UNDEFINE_KEEP_NVRAM) instance.delete() - addlogmsg(request.user, instance.name, _("Destroy")) + addlogmsg(request.user.username, instance.compute.name, instance.name, _("Destroy")) return redirect(reverse("instances:index")) return render( @@ -350,7 +350,7 @@ def migrate(request, pk): messages.error(request, err) msg = _("Instance is migrated to %(hostname)s") % {"hostname": new_compute.hostname} - addlogmsg(request.user, instance.name, msg) + addlogmsg(request.user.username, instance.compute.hostname, instance.name, msg) return redirect(request.META.get("HTTP_REFERER")) @@ -373,7 +373,7 @@ def set_root_pass(request, pk): s.close() if result["return"] == "success": msg = _("Reset root password") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) messages.success(request, msg) else: messages.error(request, result["message"]) @@ -400,7 +400,7 @@ def add_public_key(request, pk): msg = result["message"] else: msg = _("Installed new SSH public key %(keyname)s") % {"keyname": publickey.keyname} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) if result["return"] == "success": messages.success(request, msg) @@ -436,7 +436,7 @@ def resizevm_cpu(request, pk): vcpu = new_vcpu instance.proxy.resize_cpu(cur_vcpu, vcpu) msg = _("CPU is resized: %(old)s to %(new)s") % {"old": cur_vcpu, "new": vcpu} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) messages.success(request, msg) return redirect(reverse("instances:instance", args=[instance.id]) + "#resize") @@ -476,7 +476,7 @@ def resize_memory(request, pk): "new_cur": new_cur_memory, "new_max": new_memory, } - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) messages.success(request, msg) return redirect(reverse("instances:instance", args=[instance.id]) + "#resize") @@ -512,7 +512,7 @@ def resize_disk(request, pk): else: instance.proxy.resize_disk(disks_new) msg = _("Disk is resized: %(dev)s") % {"dev": disk["dev"]} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) messages.success(request, msg) return redirect(reverse("instances:instance", args=[instance.id]) + "#resize") @@ -551,7 +551,7 @@ def add_new_vol(request, pk): ) instance.proxy.attach_disk(target_dev, source, target_bus=bus, driver_type=format, cache_mode=cache) msg = _("Attach new disk: %(name)s (%(format)s)") % {"name": name, "format": format} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -582,7 +582,7 @@ def add_existing_vol(request, pk): instance.proxy.attach_disk(target_dev, source, target_bus=bus, driver_type=driver_type, cache_mode=cache) msg = _("Attach Existing disk: %(target_dev)s") % {"target_dev": target_dev} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -644,7 +644,7 @@ def edit_volume(request, pk): else: messages.success(request, _("Volume is changed successfully.")) msg = _("Edit disk: %(target_dev)s") % {"target_dev": target_dev} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -669,7 +669,7 @@ def delete_vol(request, pk): instance.proxy.detach_disk(dev) conn_delete.del_volume(name) - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -682,7 +682,7 @@ def detach_vol(request, pk): path = request.POST.get("path", "") instance.proxy.detach_disk(dev) msg = _("Detach disk: %(dev)s") % {"dev": dev} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -695,7 +695,7 @@ def add_cdrom(request, pk): target = utils.get_new_disk_dev(instance.media, instance.disks, bus) instance.proxy.attach_disk(target, "", disk_device="cdrom", cache_mode="none", target_bus=bus, readonly=True) msg = _("Add CD-ROM: %(target)s") % {"target": target} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -708,7 +708,7 @@ def detach_cdrom(request, pk, dev): # dev = request.POST.get('detach_cdrom', '') instance.proxy.detach_disk(dev) msg = _("Detach CD-ROM: %(dev)s") % {"dev": dev} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -721,7 +721,7 @@ def unmount_iso(request, pk): dev = request.POST.get("umount_iso", "") instance.proxy.umount_iso(dev, image) msg = _("Mount media: %(dev)s") % {"dev": dev} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -734,7 +734,7 @@ def mount_iso(request, pk): dev = request.POST.get("mount_iso", "") instance.proxy.mount_iso(dev, image) msg = _("Unmount media: %(dev)s") % {"dev": dev} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#disks") @@ -747,7 +747,7 @@ def snapshot(request, pk): name = request.POST.get("name", "") instance.proxy.create_snapshot(name) msg = _("Create snapshot: %(snap)s") % {"snap": name} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#managesnapshot") @@ -758,7 +758,7 @@ def delete_snapshot(request, pk): snap_name = request.POST.get("name", "") instance.proxy.snapshot_delete(snap_name) msg = _("Delete snapshot: %(snap)s") % {"snap": snap_name} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#managesnapshot") @@ -772,7 +772,7 @@ def revert_snapshot(request, pk): msg += snap_name messages.success(request, msg) msg = _("Revert snapshot: %(snap)s") % {"snap": snap_name} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#managesnapshot") @@ -786,7 +786,7 @@ def set_vcpu(request, pk): else: instance.proxy.set_vcpu(id, 0) msg = _("VCPU %(id)s is enabled=%(enabled)s") % {"id": id, "enabled": enabled} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#resize") @@ -796,7 +796,7 @@ def set_vcpu_hotplug(request, pk): status = request.POST.get("vcpu_hotplug", "") msg = _("VCPU Hot-plug is enabled=%(status)s") % {"status": status} instance.proxy.set_vcpu_hotplug(eval(status)) - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#resize") @@ -805,7 +805,7 @@ def set_autostart(request, pk): instance = get_instance(request.user, pk) instance.proxy.set_autostart(1) msg = _("Set autostart") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#boot_opt") @@ -814,7 +814,7 @@ def unset_autostart(request, pk): instance = get_instance(request.user, pk) instance.proxy.set_autostart(0) msg = _("Unset autostart") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#boot_opt") @@ -823,7 +823,7 @@ def set_bootmenu(request, pk): instance = get_instance(request.user, pk) instance.proxy.set_bootmenu(1) msg = _("Enable boot menu") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#boot_opt") @@ -832,7 +832,7 @@ def unset_bootmenu(request, pk): instance = get_instance(request.user, pk) instance.proxy.set_bootmenu(0) msg = _("Disable boot menu") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#boot_opt") @@ -855,7 +855,7 @@ def set_bootorder(request, pk): ) else: messages.success(request, _("Boot order changed successfully.")) - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#boot_opt") @@ -866,7 +866,7 @@ def change_xml(request, pk): if new_xml: instance.proxy._defineXML(new_xml) msg = _("Change instance XML") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#xmledit") @@ -880,7 +880,7 @@ def set_guest_agent(request, pk): instance.proxy.remove_guest_agent() msg = _("Set Guest Agent: %(status)s") % {"status": status} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#options") @@ -890,7 +890,7 @@ def set_video_model(request, pk): video_model = request.POST.get("video_model", "vga") instance.proxy.set_video_model(video_model) msg = _("Set Video Model: %(model)s") % {"model": video_model} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#options") @@ -920,7 +920,7 @@ def change_network(request, pk): network_data[post] = request.POST.get(post, "") instance.proxy.change_network(network_data) - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) msg = _("Network Device Config is changed. Please shutdown instance to activate.") if instance.proxy.get_status() != 5: messages.success(request, msg) @@ -947,7 +947,7 @@ def add_network(request, pk): instance.proxy.add_network(mac, source, source_type, nwfilter=nwfilter) msg = _("Add network: %(mac)s") % {"mac": mac} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#network") @@ -958,7 +958,7 @@ def delete_network(request, pk): instance.proxy.delete_network(mac_address) msg = _("Delete Network: %(mac)s") % {"mac": mac_address} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#network") @@ -971,7 +971,7 @@ def set_link_state(request, pk): state = "down" if state == "up" else "up" instance.proxy.set_link_state(mac_address, state) msg = _("Set Link State: %(state)s") % {"state": state} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#network") @@ -1042,7 +1042,7 @@ def add_owner(request, pk): add_user_inst.save() user = User.objects.get(id=user_id) msg = _("Add owner: %(user)s") % {"user": user} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#users") @@ -1053,7 +1053,7 @@ def del_owner(request, pk): userinstance = UserInstance.objects.get(pk=userinstance_id) userinstance.delete() msg = _("Delete owner: %(userinstance_id)s ") % {"userinstance_id": userinstance_id} - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#users") @@ -1151,7 +1151,7 @@ def update_console(request, pk): messages.error(request, msg) else: msg = _("Set VNC password") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) if "keymap" in form.changed_data or "clear_keymap" in form.changed_data: if form.cleaned_data["clear_keymap"]: @@ -1160,17 +1160,17 @@ def update_console(request, pk): instance.proxy.set_console_keymap(form.cleaned_data["keymap"]) msg = _("Set VNC keymap") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) if "type" in form.changed_data: instance.proxy.set_console_type(form.cleaned_data["type"]) msg = _("Set VNC type") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) if "listen_on" in form.changed_data: instance.proxy.set_console_listen_addr(form.cleaned_data["listen_on"]) msg = _("Set VNC listen address") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#vncsettings") @@ -1193,7 +1193,7 @@ def change_options(request, pk): instance.proxy.set_options(options) msg = _("Edit options") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#options") @@ -1207,7 +1207,7 @@ def getvvfile(request, pk): ) msg = _("Send console.vv file") - addlogmsg(request.user.username, instance.name, msg) + addlogmsg(request.user.username, instance.compute.name, instance.name, msg) response = HttpResponse( content="", content_type="application/x-virt-viewer", diff --git a/logs/migrations/0003_logs_host.py b/logs/migrations/0003_logs_host.py new file mode 100644 index 0000000..b68b24f --- /dev/null +++ b/logs/migrations/0003_logs_host.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.20 on 2021-05-31 08:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('logs', '0002_auto_20200615_0637'), + ] + + operations = [ + migrations.AddField( + model_name='logs', + name='host', + field=models.CharField(default='-', max_length=50, verbose_name='host'), + ), + ] diff --git a/logs/models.py b/logs/models.py index ad9946b..bcbb733 100644 --- a/logs/models.py +++ b/logs/models.py @@ -3,6 +3,7 @@ from django.utils.translation import gettext_lazy as _ class Logs(Model): user = CharField(_("user"), max_length=50) + host = CharField(_("host"), max_length=50, default="-") instance = CharField(_("instance"), max_length=50) message = CharField(_("message"), max_length=255) date = DateTimeField(_("date"), auto_now=True) diff --git a/logs/views.py b/logs/views.py index 0f94940..eee9a8b 100644 --- a/logs/views.py +++ b/logs/views.py @@ -7,14 +7,15 @@ from instances.models import Instance from logs.models import Logs -def addlogmsg(user, instance, message): +def addlogmsg(user, host, instance, message): """ :param user: + :param host: :param instance: :param message: :return: """ - add_log_msg = Logs(user=user, instance=instance, message=message) + add_log_msg = Logs(user=user, host=host, instance=instance, message=message) add_log_msg.save() @@ -32,6 +33,7 @@ def vm_logs(request, vname): for l in logs_: log = dict() log["user"] = l.user + log["host"] = l.host log["instance"] = l.instance log["message"] = l.message log["date"] = l.date.strftime("%x %X") diff --git a/nwfilters/views.py b/nwfilters/views.py index 7cb690d..d6cfa98 100644 --- a/nwfilters/views.py +++ b/nwfilters/views.py @@ -50,10 +50,10 @@ def nwfilters(request, compute_id): try: msg = _("%(filter)s network filter is created") % {"filter": name} conn.create_nwfilter(xml) - addlogmsg(request.user.username, compute.hostname, msg) + addlogmsg(request.user.username, compute.hostname, "", msg) except libvirtError as lib_err: messages.error(request, lib_err) - addlogmsg(request.user.username, compute.hostname, lib_err) + addlogmsg(request.user.username, compute.hostname, "", lib_err) if "del_nwfilter" in request.POST: name = request.POST.get("nwfiltername", "") @@ -75,14 +75,14 @@ def nwfilters(request, compute_id): in_use = True msg = _("NWFilter is in use by %(instance)s. Cannot be deleted.") % {"instance": inst} messages.error(request, msg) - addlogmsg(request.user.username, compute.hostname, msg) + addlogmsg(request.user.username, compute.hostname, "", msg) i_conn.close() break is_conn.close() if nwfilter and not in_use: nwfilter.undefine() - addlogmsg(request.user.username, compute.hostname, msg) + addlogmsg(request.user.username, compute.hostname, "", msg) if "cln_nwfilter" in request.POST: @@ -91,15 +91,15 @@ def nwfilters(request, compute_id): conn.clone_nwfilter(name, cln_name) msg = _("Cloning NWFilter %(name)s as %(clone)s") % {"name":name, "clone": cln_name} - addlogmsg(request.user.username, compute.hostname, msg) + addlogmsg(request.user.username, compute.hostname, "", msg) conn.close() except libvirtError as lib_err: messages.error(request, lib_err) - addlogmsg(request.user.username, compute.hostname, lib_err) + addlogmsg(request.user.username, compute.hostname, "", lib_err) except Exception as err: messages.error(request, err) - addlogmsg(request.user.username, compute.hostname, err) + addlogmsg(request.user.username, compute.hostname, "", err) return render( request,