aboutsummaryrefslogtreecommitdiffstats
path: root/lib/srtgui/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/srtgui/views.py')
-rw-r--r--lib/srtgui/views.py184
1 files changed, 172 insertions, 12 deletions
diff --git a/lib/srtgui/views.py b/lib/srtgui/views.py
index 79bf7b17..7f819fd1 100644
--- a/lib/srtgui/views.py
+++ b/lib/srtgui/views.py
@@ -994,6 +994,26 @@ def publish(request):
# does this user have permission to see this record?
if not UserSafe.is_creator(request.user):
return redirect(landing)
+
+ context = {
+ }
+ return render(request, 'publish.html', context)
+
+def publish_summary(request):
+ # does this user have permission to see this record?
+ if not UserSafe.is_creator(request.user):
+ return redirect(landing)
+
+ context = {
+ }
+ return render(request, 'management.html', context)
+
+def publish_diff_snapshot(request):
+ # does this user have permission to see this record?
+ if not UserSafe.is_creator(request.user):
+ return redirect(landing)
+
+ main_app = SrtSetting.get_setting('SRT_MAIN_APP','yp')
if request.method == "GET":
# Prepare available snapshots
@@ -1037,9 +1057,145 @@ def publish(request):
]
# List of available reports
generated_report_list = []
- for entry in os.scandir('data/wr'):
- if entry.name.startswith('cve-svns-srtool'):
- generated_report_list.append(ReportFile(entry.name,entry.stat().st_size,datetime.fromtimestamp(entry.stat().st_mtime)))
+ if os.path.isdir('data/publish'):
+ for entry in os.scandir('data/publish'):
+ if entry.name.startswith('cve-svns-srtool'):
+ generated_report_list.append(ReportFile(entry.name,entry.stat().st_size,datetime.fromtimestamp(entry.stat().st_mtime)))
+# generated_report_list.sort()
+ generated_report_list = sorted(generated_report_list,key=lambda x: x.name)
+
+ # Prepare History data
+ last_calc = SrtSetting.get_setting('publish_last_calc','06/08/2019')
+ date_start = SrtSetting.get_setting('publish_date_start','06/08/2019')
+ date_stop = SrtSetting.get_setting('publish_date_stop','06/21/2019')
+
+ context = {
+ 'date_start' : date_start,
+ 'date_stop' : date_stop,
+ 'last_calc' : last_calc,
+
+ 'snap_date_start' : snap_date_start,
+ 'snap_date_stop' : snap_date_stop,
+ 'snap_date_base' : snap_date_base,
+ 'snap_date_top' : snap_date_top,
+ 'snapshot_list' : snapshot_list,
+ 'snap_start_index' : '%02d' % snap_start_index,
+ 'snap_stop_index' : '%02d' % snap_stop_index,
+ 'snap_last_calc' : snap_last_calc,
+ 'generated_report_list' : generated_report_list,
+
+ 'snapshot_frequency_list' : snapshot_frequency_list,
+ 'snap_frequency_select' : snap_frequency_select,
+ }
+ return render(request, 'publish_diff_snapshot.html', context)
+ elif request.method == "POST":
+ action = request.POST['action']
+
+ if request.POST["action"] == "download":
+ report_name = request.POST['report_name']
+ file_path = 'data/publish/%s' % (report_name)
+ if file_path:
+ fsock = open(file_path, "rb")
+ content_type = MimeTypeFinder.get_mimetype(file_path)
+ response = HttpResponse(fsock, content_type = content_type)
+ disposition = 'attachment; filename="{}"'.format(file_path)
+ response['Content-Disposition'] = 'attachment; filename="{}"'.format(file_path)
+ _log("EXPORT_POST_Q{%s} %s || %s " % (response, response['Content-Disposition'], disposition))
+ return response
+ else:
+ return render(request, "unavailable_artifact.html", context={})
+
+ # Dates (make as no timezone)
+ msg = ''
+ try:
+ msg = 'Start:%s' % request.POST.get('date_start', '')
+ date_start = datetime.strptime(request.POST.get('date_start', ''), '%m/%d/%Y')
+ msg = 'Stop:%s' % request.POST.get('date_stop', '')
+ date_stop = datetime.strptime(request.POST.get('date_stop', ''), '%m/%d/%Y')
+ if date_stop < date_start:
+# return 'Error:stop date is before start date'
+ _log('Error:stop date is before start date')
+ pass
+ except Exception as e:
+# return 'Error:bad format for dates (must be mm/dd/yyyy) (%s)(%s)' % (msg,e),''
+ _log('Error:bad format for dates (must be mm/dd/yyyy) (%s)(%s)' % (msg,e))
+ pass
+ SrtSetting.set_setting('publish_date_start',date_start.strftime('%m/%d/%Y'))
+ SrtSetting.set_setting('publish_date_stop',date_stop.strftime('%m/%d/%Y'))
+ if 'recalculate' == action:
+ # Calculate
+ publishCalculate(date_start,date_stop)
+ return redirect('publish')
+ if 'view' == action:
+ # Go to publish list page
+ return redirect('publish-list')
+ if 'add-cve' == action:
+ # Go to publish list page
+ return redirect('publish-cve')
+ if 'add-defect' == action:
+ # Go to publish list page
+ return redirect('publish-defect')
+ if 'reset' == action:
+ publishReset(date_start,date_stop)
+ publishCalculate(date_start,date_stop)
+ return redirect('publish')
+ if 'export' == action:
+ return redirect('/%s/report/publish' % main_app)
+ return redirect('publish')
+
+def publish_diff_history(request):
+ # does this user have permission to see this record?
+ if not UserSafe.is_creator(request.user):
+ return redirect(landing)
+
+ main_app = SrtSetting.get_setting('SRT_MAIN_APP','yp')
+ if request.method == "GET":
+
+ # Prepare available snapshots
+ snapshot_list = []
+ snap_start_index = 0
+ snap_stop_index = 0
+ snap_date_base = SrtSetting.get_setting('publish_snap_date_base','2019-06-08')
+ snap_date_top = SrtSetting.get_setting('publish_snap_date_top','2019-06-16')
+ snap_date_start = SrtSetting.get_setting('publish_snap_date_start','2019-06-08')
+ snap_date_stop = SrtSetting.get_setting('publish_snap_date_stop','2019-06-16')
+ snap_last_calc = SrtSetting.get_setting('publish_snap_last_calc','')
+ backup_returncode,backup_stdout,backup_result = execute_process('bin/common/srtool_backup.py','--list-backups-db')
+ for i,line in enumerate(backup_stdout.decode("utf-8").splitlines()):
+ # Week|backup_2019_19|2019-05-18|12:51:51|Saturday, May 18 2019
+ backup_mode,backup_dir,backup_date,backup_time,backup_day = line.split('|')
+ if 'Now' != backup_mode:
+ snap = Snap(i,backup_mode,backup_dir,backup_date,backup_time,backup_day)
+ snapshot_list.append(snap)
+ if snap_date_base == snap.date:
+ snap_start_index = i
+ if snap_date_start < snap.date:
+ snap_date_start = snap.date
+ if snap_date_stop < snap.date:
+ snap_date_stop = snap.date
+ if snap_date_top == snap.date:
+ snap_stop_index = i
+ if snap_date_stop > snap.date:
+ snap_date_stop = snap.date
+ if not snap_stop_index:
+ snap_stop_index = i
+ if snap_date_stop < snap.date:
+ snap_date_stop = snap.date
+ # Report automation
+ snap_frequency_select = SrtSetting.get_setting('publish_snap_frequency','Off')
+ snapshot_frequency_list = [
+ 'Off',
+ 'Monthly',
+ 'Bi-monthly',
+ 'Weekly',
+ 'Daily',
+ ]
+ # List of available reports
+ generated_report_list = []
+ if os.path.isdir('data/publish'):
+ for entry in os.scandir('data/publish'):
+ if entry.name.startswith('cve-svns-srtool'):
+ generated_report_list.append(ReportFile(entry.name,entry.stat().st_size,datetime.fromtimestamp(entry.stat().st_mtime)))
# generated_report_list.sort()
generated_report_list = sorted(generated_report_list,key=lambda x: x.name)
@@ -1072,7 +1228,7 @@ def publish(request):
if request.POST["action"] == "download":
report_name = request.POST['report_name']
- file_path = 'data/wr/%s' % report_name
+ file_path = 'data/publish/%s' % (report_name)
if file_path:
fsock = open(file_path, "rb")
content_type = MimeTypeFinder.get_mimetype(file_path)
@@ -1119,10 +1275,12 @@ def publish(request):
publishCalculate(date_start,date_stop)
return redirect('publish')
if 'export' == action:
- return redirect('/wr/report/publish')
+ return redirect('/%s/report/publish' % main_app)
return redirect('publish')
+
+
def manage_report(request):
# does this user have permission to see this record?
if not UserSafe.is_creator(request.user):
@@ -2146,6 +2304,8 @@ def xhr_investigation_commit(request):
def xhr_publish(request):
_log("xhr_publish(%s)" % request.POST)
+ main_app = SrtSetting.get_setting('SRT_MAIN_APP','yp')
+
def remove_mark(mark,line):
pos1 = line.find(mark)
if -1 == pos1:
@@ -2185,18 +2345,18 @@ def xhr_publish(request):
if (not top_dir) and (snap_date_top == backup_date) and ('Now' != backup_mode):
top_dir = 'backups/%s' % backup_dir
- _log('Publish:./bin/wr/srtool_publish.py --srt2update ' + base_dir)
- report_returncode,report_stdout,report_error = execute_process('./bin/wr/srtool_publish.py','--srt2update',base_dir)
+ _log('Publish:./bin/%s/srtool_publish.py --srt2update %s' % (main_app,base_dir))
+ report_returncode,report_stdout,report_error = execute_process('./bin/%s/srtool_publish.py' % main_app,'--srt2update',base_dir)
if 0 != report_returncode:
return_data = {"error": "Error: base dir prep:%s:%s" % (report_error,report_stdout),}
return HttpResponse(json.dumps( return_data ), content_type = "application/json")
- _log('Publish:./bin/wr/srtool_publish.py --srt2update ' + top_dir)
- report_returncode,report_stdout,report_error = execute_process('./bin/wr/srtool_publish.py','--srt2update',top_dir)
+ _log('Publish:./bin/%s/srtool_publish.py --srt2update %s' % (main_app,top_dir))
+ report_returncode,report_stdout,report_error = execute_process('./bin/%s/srtool_publish.py' % main_app,'--srt2update',top_dir)
if 0 != report_returncode:
return_data = {"error": "Error: top dir prep:%s:%s" % (report_error,report_stdout),}
return HttpResponse(json.dumps( return_data ), content_type = "application/json")
- _log('Publish:./bin/wr/srtool_publish.py --validate-update-svns --previous '+base_dir+' --current '+top_dir+' --start '+snap_date_start+' --stop '+snap_date_stop)
- report_returncode,report_stdout,report_error = execute_process('./bin/wr/srtool_publish.py',
+ _log('Publish:./bin/'+main_app+'/srtool_publish.py --validate-update-svns --previous '+base_dir+' --current '+top_dir+' --start '+snap_date_start+' --stop '+snap_date_stop)
+ report_returncode,report_stdout,report_error = execute_process('./bin/%s/srtool_publish.py' % main_app,
'--validate-update-svns','--previous',base_dir,'--current',top_dir,
'--start',snap_date_start,'--stop',snap_date_stop)
if 0 != report_returncode:
@@ -2212,7 +2372,7 @@ def xhr_publish(request):
_log('Publish:Done!')
elif 'submit-trashreport' == action:
report_name = request.POST['report_name']
- os.remove('data/wr/%s' % report_name)
+ os.remove('data/%s/%s' % (main_app,report_name))
else:
srtool_today_time = datetime.today()
srtool_today = datetime.today().strftime("%Y-%m-%d")