mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 12:56:11 +01:00
Add popover for tasks mobile
Add support logs download feature
This commit is contained in:
parent
13b14bfaed
commit
9f798ff291
@ -1,3 +1,4 @@
|
||||
from tempfile import tempdir
|
||||
from app.classes.shared.translation import Translation
|
||||
import json
|
||||
import logging
|
||||
@ -7,6 +8,8 @@ import bleach
|
||||
import time
|
||||
import datetime
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from tornado import locale
|
||||
from tornado import iostream
|
||||
@ -765,6 +768,58 @@ class PanelHandler(BaseHandler):
|
||||
del chunk
|
||||
self.redirect("/panel/server_detail?id={}&subpage=files".format(server_id))
|
||||
|
||||
elif page == "support_logs":
|
||||
tempDir = tempfile.mkdtemp()
|
||||
tempZipStorage = tempfile.mkdtemp()
|
||||
full_temp = os.path.join(tempDir, 'support_logs')
|
||||
os.mkdir(full_temp)
|
||||
tempZipStorage = os.path.join(tempZipStorage, "support_logs")
|
||||
crafty_path = os.path.join(full_temp, "crafty")
|
||||
os.mkdir(crafty_path)
|
||||
server_path = os.path.join(full_temp, "server")
|
||||
os.mkdir(server_path)
|
||||
if exec_user['superuser']:
|
||||
auth_servers = self.controller.servers.get_all_defined_servers()
|
||||
else:
|
||||
auth_servers = self.controller.servers.get_authorized_servers(int(exec_user_id))
|
||||
#we'll iterate through our list of log paths from auth servers.
|
||||
for server in auth_servers:
|
||||
final_path = os.path.join(server_path, str(server['server_name']))
|
||||
os.mkdir(final_path)
|
||||
shutil.copy(server['log_path'], final_path)
|
||||
#Copy crafty logs to archive dir
|
||||
full_log_name = os.path.join(crafty_path, 'logs')
|
||||
shutil.copytree("logs", full_log_name)
|
||||
shutil.make_archive(tempZipStorage, "zip", tempDir)
|
||||
|
||||
tempZipStorage += '.zip'
|
||||
self.set_header('Content-Type', 'application/octet-stream')
|
||||
self.set_header('Content-Disposition', 'attachment; filename=' + "support_logs.zip")
|
||||
chunk_size = 1024 * 1024 * 4 # 4 MiB
|
||||
|
||||
with open(tempZipStorage, 'rb') as f:
|
||||
while True:
|
||||
chunk = f.read(chunk_size)
|
||||
if not chunk:
|
||||
break
|
||||
try:
|
||||
self.write(chunk) # write the chunk to response
|
||||
self.flush() # send the chunk to client
|
||||
except iostream.StreamClosedError:
|
||||
# this means the client has closed the connection
|
||||
# so break the loop
|
||||
break
|
||||
finally:
|
||||
# deleting the chunk is very important because
|
||||
# if many clients are downloading files at the
|
||||
# same time, the chunks in memory will keep
|
||||
# increasing and will eat up the RAM
|
||||
del chunk
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
self.render(
|
||||
template,
|
||||
|
@ -29,6 +29,7 @@
|
||||
{% end %}
|
||||
<p class="font-weight-light text-muted mb-0">Email: {{ data['user_data']['email'] }}</p>
|
||||
</div>
|
||||
<a class="dropdown-item" href="/panel/support_logs"><i class="dropdown-item-icon mdi mdi-download-outline text-primary"></i> Support Logs</i></a>
|
||||
{% if "Super User" in data['user_role'] %}
|
||||
<a class="dropdown-item" href="/panel/activity_logs"><i class="dropdown-item-icon mdi mdi-calendar-check-outline text-primary"></i> Activity</a>
|
||||
{% end %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user