1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
--
-- (C) 2013-22 - ntop.org
--
local dirs = ntop.getDirs()
require "lua_utils"
local template = require "template_utils"
local recording_utils = require "recording_utils"
local ifid = getInterfaceId(ifname)
if((not isAdministrator()) or (not recording_utils.isAvailable()) or (not ntop.isEnterpriseM())) then
return
end
if not isEmptyString(_POST["job_action"]) then
if not isEmptyString(_POST["job_id"]) then
if _POST["job_action"] == "delete" then
recording_utils.deleteJob(_POST["job_id"])
elseif _POST["job_action"] == "stop" then
recording_utils.stopJob(_POST["job_id"])
end
else
-- no job id
if _POST["job_action"] == "delete" then
recording_utils.deleteAndStopAllJobs(ifid)
end
end
end
print("<H2>"..i18n("traffic_recording.traffic_extraction_jobs") .. "</H2>")
print(template.gen("modal_confirm_dialog.html", {
dialog = {
id = "PcapDownloadDialog",
title = i18n("traffic_recording.download"),
custom_alert_class = "alert alert-info",
message = i18n("traffic_recording.multiple_extracted_files", { mb = tostring(math.floor(prefs.max_extracted_pcap_bytes/(1024*1024))) }),
confirm = i18n("confirm"),
}
}))
print(
template.gen("modal_confirm_dialog.html", {
dialog={
id = "PcapDeleteJobDialog",
action = "deleteJob(selected_job_id)",
title = i18n("traffic_recording.delete_job"),
message = i18n("traffic_recording.delete_job_confirm", {job_id = "<span id='job_to_delete'></span>"}),
confirm = i18n("delete"),
}
})
)
print(
template.gen("modal_confirm_dialog.html", {
dialog={
id = "PcapStopJobDialog",
action = "stopJob(selected_job_id)",
title = i18n("traffic_recording.stop_job"),
message = i18n("traffic_recording.stop_job_confirm", {job_id = "<span id='job_to_stop'></span>"}),
confirm = i18n("stop"),
}
})
)
print(
template.gen("modal_confirm_dialog.html", {
dialog={
id = "PcapDeleteAllDialog",
action = "deleteAllExtractionJobs()",
title = i18n("traffic_recording.delete_all_jobs"),
message = i18n("traffic_recording.delete_all_jobs_confirm"),
confirm = i18n("delete"),
}
})
)
print [[
<div id="extractionjobs"></div>
<button class="btn btn-secondary" onclick="$('#PcapDeleteAllDialog').modal('show');" style="float:right; margin-right:1em;"><i class="fas fa-trash" aria-hidden="true" data-original-title="" title=""></i> ]] print(i18n("show_alerts.delete_all")) print[[</button>
<br><br>
<span>]]
print(i18n("notes"))
print[[
<ul>
<li>]] print(i18n("traffic_recording.note_dump")) print[[</li>]]
print[[
</ul>
</span>
<script>
var selected_job_id = null;
$("#extractionjobs").datatable({
title: "",
url: "/lua/traffic_extraction_data.lua",]]
-- Sort by column_id if a specific job_id is set to show it in the first table page
if not isEmptyString(_GET["job_id"]) then
print[[
sort: [ ["column_id", "desc"] ],
]]
end
print[[
columns: [
{
title: "]] print(i18n("traffic_recording.job_id")) print [[",
field: "column_id",
sortable: true,
css: {textAlign:'center'},
}, {
title: "]] print(i18n("traffic_recording.job_date_time")) print [[",
field: "column_job_time",
sortable: true,
}, {
title: "]] print(i18n("chart")) print [[",
field: "column_chart",
sortable: false,
css: {textAlign:'center'},
}, {
title: "]] print(i18n("status")) print [[",
sortable: true,
field: "column_status",
}, {
title: "]] print(i18n("report.begin_date_time")) print [[",
field: "column_begin_time",
}, {
title: "]] print(i18n("report.end_date_time")) print [[",
field: "column_end_time",
}, {
title: "]] print(i18n("traffic_recording.filter_bpf")) print [[",
field: "column_bpf_filter",
}, {
title: "]] print(i18n("packets")) print [[",
field: "column_extracted_packets",
sortable: true,
css: {textAlign:'right'},
}, {
title: "]] print(i18n("bytes")) print [[",
field: "column_extracted_bytes",
sortable: true,
css: {textAlign:'right'},
}, {
title: "]] print(i18n("actions")) print [[",
field: "column_actions",
css: {textAlign:'center'},
}
], rowCallback: function(row, data) {
var actions_td_idx = 10;
var job_id = data.column_id;
var num_job_files = data.column_job_files;
var job_status = data.column_status_raw;
if(job_id == "]] print(_GET["job_id"] or "") print[[")
row.addClass("info");
if(num_job_files > 1) {
var links = "<ul>";
for(var file_id=1; file_id<num_job_files; file_id++)
links = links + "<li><a href=\\']] print(ntop.getHttpPrefix())
print[[/lua/get_extracted_traffic.lua?job_id=" + job_id + "&file_id=" + file_id + "\\'>" + "]]
print(i18n("traffic_recording.download_nth_pcap")) print[[".sformat(file_id) + "</a></li>";
links = links + "</ul>";
datatableAddActionButtonCallback.bind(row)(actions_td_idx,
"downloadJobFiles('" + links + "')", "]] print(i18n("download")) print[[");
} else if (num_job_files == 1) {
datatableAddLinkButtonCallback.bind(row)(actions_td_idx,
"]] print(ntop.getHttpPrefix()) print[[/lua/get_extracted_traffic.lua?job_id=" + job_id, "]] print(i18n("download")) print[[");
}
if(job_status === "processing") {
datatableAddDeleteButtonCallback.bind(row)(actions_td_idx,
"$('#job_to_stop').html('"+ job_id +"'); selected_job_id = "+ job_id +"; $('#PcapStopJobDialog').modal('show')", "]] print(i18n("stop")) print[[");
} else {
datatableAddDeleteButtonCallback.bind(row)(actions_td_idx,
"$('#job_to_delete').html('"+ job_id +"'); selected_job_id = "+ job_id +"; $('#PcapDeleteJobDialog').modal('show')", "]] print(i18n("delete")) print[[");
}
return row;
}
});
function downloadJobFiles(links) {
$('#url_PcapDownloadDialog').html(links);
$('#PcapDownloadDialog').modal('show');
$('#btn-confirm-action_PcapDownloadDialog').css("display", "none");
}
function deleteJob(job_id) {
var params = {}
params.job_action = 'delete';
params.job_id = job_id;
params.csrf = "]] print(ntop.getRandomCSRFValue()) print[[";
NtopUtils.paramsToForm('<form method="post"></form>', params).appendTo('body').submit();
}
function stopJob(job_id) {
var params = {}
params.job_action = 'stop';
params.job_id = job_id;
params.csrf = "]] print(ntop.getRandomCSRFValue()) print[[";
NtopUtils.paramsToForm('<form method="post"></form>', params).appendTo('body').submit();
}
function deleteAllExtractionJobs() {
var params = {}
params.job_action = 'delete';
params.csrf = "]] print(ntop.getRandomCSRFValue()) print[[";
NtopUtils.paramsToForm('<form method="post"></form>', params).appendTo('body').submit();
}
</script>
]]
|