mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-27 08:35:22 +00:00
1cbdf76df6
* Log for failed login attempts * Logger configuration for logging to file * interface fixes * login log fix, added logged in too * bootstrap icons setup * font-awesome icons replaced with bootstrap icons * replaced i-tags with django_bootstrap_icons * removed icons library from project * bug fix --------- Co-authored-by: catborise <catborise@gmail.com>
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import json
|
|
import logging
|
|
|
|
from django.http import HttpResponse
|
|
|
|
from admin.decorators import superuser_only
|
|
from instances.models import Instance
|
|
from logs.models import Logs
|
|
|
|
|
|
def addlogmsg(user, host, instance, message):
|
|
"""
|
|
:param user:
|
|
:param host:
|
|
:param instance:
|
|
:param message:
|
|
:return:
|
|
"""
|
|
add_log_msg = Logs(user=user, host=host, instance=instance, message=message)
|
|
add_log_msg.save()
|
|
logger = logging.getLogger("")
|
|
logger.info(user + " " + host+ " " + instance+ " " + message)
|
|
|
|
|
|
@superuser_only
|
|
def vm_logs(request, vname):
|
|
"""
|
|
:param request:
|
|
:param vname:
|
|
:return:
|
|
"""
|
|
|
|
vm = Instance.objects.get(name=vname)
|
|
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by("-date")
|
|
logs = []
|
|
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")
|
|
logs.append(log)
|
|
|
|
return HttpResponse(json.dumps(logs))
|