def gen_hosts(request): filename = "/tmp/__hosts.txt" hm = HostsManager() hm.generate_host_file(filename) from wsgiref.util import FileWrapper with open(filename, "r", encoding="utf-8") as myfile: # generate the file response = HttpResponse(FileWrapper(myfile), content_type='text/plain') response['Content-Disposition'] = 'attachment; filename=hosts.txt' return response return HttpResponse("error")
def status(request): """View function for home page of site.""" context = { 'server_status': SecureDNSServer.isRunning(), 'ttl_status': HostsManager.isTTLThreadRunning() } return render(request, 'status.html', context=context)
def index(request): """View function for home page of site.""" num_hosts = 0 num_logs = 0 hosts = None if db_table_exists("webui_host"): num_hosts = Host.objects.all().count() hosts = StatsHosts.objects.filter(hits__gt=1).order_by('-hits') num_logs = Logs.objects.all().count() context = { 'num_hosts': num_hosts, 'hosts': hosts, 'num_logs': num_logs, 'server_status': SecureDNSServer.isRunning(), 'ttl_status': HostsManager.isTTLThreadRunning() } return render(request, 'index.html', context=context)
def start_ttl(request): hm = HostsManager() hm.start_ttl_monitoring() hm.start_auto_update_hosts() hm.start_auto_backup() return HttpResponse("done")
def update_yt(request): hm = HostsManager() hm.update_yt() return HttpResponse("done")
def start_server(request): hm = HostsManager() hm.restore_backup() SecureDNSServer.start() return HttpResponse("done")
def import_hosts(request): hm = HostsManager() hm.import_host_files("/tmp/hosts/") return HttpResponse("done")