{% extends "ImplantMain.html" %}
{% block main2 %}
<!-- TODO: Refactor and improve performance and readability -->
<div class="row">
<div class="col-lg-3">
<form action="/{{ cid }}/implant/register_cmd" method="POST" role="form" class="form-horizontal" id="AnswerForm">
<!--<fieldset>-->
<!--<legend>Command Input</legend>-->
<!--<!–<label for="comment">Implant Command:</label>–>-->
<!-- TODO: insert Implants into selectable. -->
<div class="form-group">
<label for="sel1">Select implant:</label>
<select class="form-control" id="sel1" name="ImplantSelect">
{% if Implants %}
<option name="a" id="b">ALL</option>
{% for imp in Implants %}
<option name="{{ imp.unique_implant_id }}" id="{{ imp.unique_implant_id }}">{{ imp.generated_title }}</option>
{% endfor %}
{% endif %}
</select>
</div>
<div class="form-group" >
<label class="control-label">Implant Command:</label>
<input onfocus="this.placeholder=''" type="text" name="cmd" class="form-control" id="implantCmd" placeholder="cmd">
</div>
</fieldset>
<button type="submit" class="btn btn-default" id="AnswerBtn">Submit</button>
</form>
<div><hr><p>Queued Commands</p></div>
<div id="awaiting">
</div>
</div>
<div class="col-lg-6" id="Response"></div>
<div class="col-lg-3" id="ImplantStatus">
Implant Check in:
<div class="" id="ImplantStatusValues">
{% if Implants %}
{% for implant in Implants %}
<p>{{ implant.generated_title}}: {{ implant.last_check_in }}</p><br>
{% endfor %}
{% endif %}
</div>
</div>
</div>
<script src="{{ url_for('static', filename='ImplantController.js') }}"></script>
<script>
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function unix_to_human_time(unixtime){
var utcSeconds = unixtime;
var d = new Date(0);
d.setUTCSeconds(utcSeconds);
var date = new Date(unixtime*1000);
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var hours = "0" + date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
time_last_seen = hours.substr(-2)+":"+minutes.substr(-2)+':'+seconds.substr(-2)+' '+day+'/'+month+'/'+year
return time_last_seen
}
// Gets command results and outputs to screen.
var contained_list=[];
async function get_command_response (){
while(true){
$.ajax({
url:"/{{ cid }}/cmd_response",
type:"GET",
success: function (response) {
// Get list of responses
var pageContainer = document.getElementById('Response');
for (element in response){
// Check for the log_id existing, if it doesn't add to list and write to top of page to remove weird loading page
if ( contained_list.includes(response[element].log_id) ) {
//console.log('Entry found');
} else {
contained_list.push(response[element].log_id);
// pageContainer = response[element].log_id+ pageContainer;
// alert(pageContainer)
GG = response[element].log_id;
var utcSeconds = response[element].time;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d=unix_to_human_time(response[element].time)
// console.log(response[element]);
GG = "<div><p>IID: "+response[element].title+"<br>Time: "+d+"<br>Rsp: <code>"+response[element].log_entry+"</code></p></div><hr>";
WP = document.getElementById('Response').innerHTML;
// alert(WP);
document.getElementById('Response').innerHTML = GG + WP;
}
}
//console.log(contained_list)
}
})
await sleep(10000);
}
}
get_command_response()
// Submits the commands to the backend.
$(function() {
$('#AnswerBtn').on('click', function (e) {
e.preventDefault(); // disable the default form submit event
var $form = $('#AnswerForm');
$.ajax({
url: $form.attr("action"),
type: $form.attr("method"),
data: $form.serialize(),
success: function (response) {
document.getElementById('implantCmd').value="";
if (response['cmd_reg']['result']===false){alert(response['cmd_reg']['reason'])}
},
error: function (response) {
alert('ajax failed');
},
});
});
});
Get_ImplantCallback ({{cid}})
Get_Awaiting_Cmds ({{cid}})
</script>
{% endblock %}