349 lines
17 KiB
HTML
349 lines
17 KiB
HTML
{% extends "base.html" %}
|
|
{% load static %}
|
|
|
|
{% block title %}Terminate Session - Session Management{% endblock %}
|
|
|
|
{% block content %}
|
|
<!-- BEGIN breadcrumb -->
|
|
<ol class="breadcrumb float-xl-end">
|
|
<li class="breadcrumb-item"><a href="{% url 'core:dashboard' %}">Dashboard</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'accounts:user_list' %}">Users</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'accounts:session_list' %}">Sessions</a></li>
|
|
<li class="breadcrumb-item active">Terminate Session</li>
|
|
</ol>
|
|
<!-- END breadcrumb -->
|
|
|
|
<!-- BEGIN page-header -->
|
|
<h1 class="page-header">
|
|
Terminate Session
|
|
<small>Confirmation Required</small>
|
|
</h1>
|
|
<!-- END page-header -->
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-xl-8">
|
|
<!-- BEGIN panel -->
|
|
<div class="panel panel-inverse">
|
|
<div class="panel-heading">
|
|
<h4 class="panel-title">
|
|
<i class="fa fa-sign-out-alt text-warning me-2"></i>
|
|
Confirm Session Termination
|
|
</h4>
|
|
</div>
|
|
<div class="panel-body">
|
|
<!-- Warning Alert -->
|
|
<div class="alert alert-warning d-flex align-items-center mb-4">
|
|
<i class="fa fa-exclamation-triangle fa-2x me-3"></i>
|
|
<div>
|
|
<h6 class="alert-heading mb-1">Session Termination</h6>
|
|
<p class="mb-0">You are about to terminate an active user session. The user will be immediately logged out and will need to authenticate again.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Session Information -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-6">
|
|
<h6 class="mb-3">Session Details</h6>
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td class="fw-bold" width="140">Session Key:</td>
|
|
<td><code class="small">{{ object.session_key|truncatechars:32 }}...</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold">User:</td>
|
|
<td>
|
|
{% if object.user %}
|
|
{{ object.user.get_full_name }}
|
|
<br><small class="text-muted">{{ object.user.username }}</small>
|
|
{% else %}
|
|
<span class="text-muted">Anonymous Session</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold">IP Address:</td>
|
|
<td>{{ object.ip_address|default:"Unknown" }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold">Created:</td>
|
|
<td>{{ object.created_at|date:"M d, Y H:i:s" }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold">Last Activity:</td>
|
|
<td>
|
|
{{ object.last_activity|date:"M d, Y H:i:s" }}
|
|
<br><small class="text-muted">{{ object.last_activity|timesince }} ago</small>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h6 class="mb-3">Session Status</h6>
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td class="fw-bold" width="140">Status:</td>
|
|
<td>
|
|
{% if object.is_active %}
|
|
<span class="badge bg-success">Active</span>
|
|
{% else %}
|
|
<span class="badge bg-secondary">Expired</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold">Duration:</td>
|
|
<td>{{ object.duration }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold">Browser:</td>
|
|
<td>
|
|
{% if object.user_agent %}
|
|
{{ object.browser_info.name }} {{ object.browser_info.version }}
|
|
<br><small class="text-muted">{{ object.browser_info.os }}</small>
|
|
{% else %}
|
|
<span class="text-muted">Unknown</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold">Expires:</td>
|
|
<td>
|
|
{% if object.expires_at %}
|
|
{{ object.expires_at|date:"M d, Y H:i:s" }}
|
|
{% if object.is_active %}
|
|
<br><small class="text-muted">{{ object.expires_at|timeuntil }} remaining</small>
|
|
{% endif %}
|
|
{% else %}
|
|
<span class="text-muted">No expiration</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Impact Assessment -->
|
|
{% if object.is_active %}
|
|
<div class="alert alert-info mb-4">
|
|
<h6 class="alert-heading">
|
|
<i class="fa fa-info-circle me-2"></i>Impact Assessment
|
|
</h6>
|
|
<ul class="mb-0">
|
|
<li><strong>User Experience:</strong> The user will be immediately logged out</li>
|
|
<li><strong>Unsaved Data:</strong> Any unsaved work may be lost</li>
|
|
<li><strong>Active Processes:</strong> Any ongoing operations will be interrupted</li>
|
|
<li><strong>Re-authentication:</strong> User will need to log in again to continue</li>
|
|
{% if object.user %}
|
|
<li><strong>Other Sessions:</strong> User's other active sessions will remain unaffected</li>
|
|
{% endif %}
|
|
</ul>
|
|
</div>
|
|
{% else %}
|
|
<div class="alert alert-secondary mb-4">
|
|
<h6 class="alert-heading">
|
|
<i class="fa fa-info-circle me-2"></i>Session Already Expired
|
|
</h6>
|
|
<p class="mb-0">This session has already expired and is no longer active. Termination will only remove it from the database.</p>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Security Information -->
|
|
{% if object.suspicious_activity %}
|
|
<div class="alert alert-danger mb-4">
|
|
<h6 class="alert-heading">
|
|
<i class="fa fa-shield-alt me-2"></i>Security Alert
|
|
</h6>
|
|
<p class="mb-2">This session has been flagged for suspicious activity.</p>
|
|
<p class="mb-0"><strong>Immediate termination is recommended for security reasons.</strong></p>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Related Sessions -->
|
|
{% if object.user and related_sessions %}
|
|
<div class="card border-info mb-4">
|
|
<div class="card-header bg-light">
|
|
<h6 class="card-title mb-0">
|
|
<i class="fa fa-users me-2"></i>Related Active Sessions
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<p class="card-text">This user has {{ related_sessions|length }} other active session(s):</p>
|
|
<div class="table-responsive">
|
|
<table class="table table-sm">
|
|
<thead>
|
|
<tr>
|
|
<th>IP Address</th>
|
|
<th>Browser</th>
|
|
<th>Last Activity</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for session in related_sessions %}
|
|
<tr>
|
|
<td>{{ session.ip_address|default:"Unknown" }}</td>
|
|
<td>{{ session.browser_info.name|default:"Unknown" }}</td>
|
|
<td>{{ session.last_activity|timesince }} ago</td>
|
|
<td>
|
|
<a href="{% url 'accounts:session_detail' session.session_key %}" class="btn btn-xs btn-outline-primary">
|
|
View
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="mt-3">
|
|
<button class="btn btn-sm btn-warning" onclick="terminateAllUserSessions()">
|
|
<i class="fa fa-sign-out-alt me-2"></i>Terminate All User Sessions
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Termination Form -->
|
|
<form method="post" id="terminate-form">
|
|
{% csrf_token %}
|
|
|
|
<div class="card border-warning">
|
|
<div class="card-header bg-warning text-dark">
|
|
<h6 class="card-title mb-0">
|
|
<i class="fa fa-sign-out-alt me-2"></i>Termination Confirmation
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
{% if object.is_active %}
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" id="confirm-understanding" required>
|
|
<label class="form-check-label" for="confirm-understanding">
|
|
I understand that this will immediately log out the user
|
|
</label>
|
|
</div>
|
|
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" id="confirm-impact" required>
|
|
<label class="form-check-label" for="confirm-impact">
|
|
I acknowledge that unsaved work may be lost
|
|
</label>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Reason for Termination <span class="text-danger">*</span></label>
|
|
<select class="form-select" name="termination_reason" required>
|
|
<option value="">Select reason...</option>
|
|
<option value="SECURITY_CONCERN">Security concern</option>
|
|
<option value="SUSPICIOUS_ACTIVITY">Suspicious activity</option>
|
|
<option value="ADMINISTRATIVE">Administrative action</option>
|
|
<option value="USER_REQUEST">User request</option>
|
|
<option value="POLICY_VIOLATION">Policy violation</option>
|
|
<option value="MAINTENANCE">System maintenance</option>
|
|
<option value="OTHER">Other</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Additional Notes</label>
|
|
<textarea class="form-control" name="termination_notes" rows="3"
|
|
placeholder="Provide additional details about why this session is being terminated..."></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Action Buttons -->
|
|
<div class="d-flex justify-content-between mt-4">
|
|
<div>
|
|
<a href="{% url 'accounts:session_detail' object.session_key %}" class="btn btn-secondary">
|
|
<i class="fa fa-arrow-left me-2"></i>Cancel
|
|
</a>
|
|
</div>
|
|
<button type="submit" class="btn btn-warning" id="terminate-btn" {% if object.is_active %}disabled{% endif %}>
|
|
<i class="fa fa-sign-out-alt me-2"></i>
|
|
{% if object.is_active %}Terminate Session{% else %}Remove Session{% endif %}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<!-- END panel -->
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block js %}
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Enable/disable terminate button based on checkboxes
|
|
function updateTerminateButton() {
|
|
{% if object.is_active %}
|
|
var allChecked = true;
|
|
$('input[type="checkbox"][required]').each(function() {
|
|
if (!$(this).is(':checked')) {
|
|
allChecked = false;
|
|
return false;
|
|
}
|
|
});
|
|
|
|
var reasonSelected = $('select[name="termination_reason"]').val() !== '';
|
|
|
|
$('#terminate-btn').prop('disabled', !(allChecked && reasonSelected));
|
|
{% else %}
|
|
var reasonSelected = $('select[name="termination_reason"]').val() !== '';
|
|
$('#terminate-btn').prop('disabled', !reasonSelected);
|
|
{% endif %}
|
|
}
|
|
|
|
// Check on checkbox change
|
|
$('input[type="checkbox"], select[name="termination_reason"]').on('change', updateTerminateButton);
|
|
|
|
// Form submission confirmation
|
|
$('#terminate-form').on('submit', function(e) {
|
|
{% if object.is_active %}
|
|
var confirmText = 'Are you sure you want to terminate this session?\n\nThe user will be immediately logged out.';
|
|
{% else %}
|
|
var confirmText = 'Are you sure you want to remove this expired session from the database?';
|
|
{% endif %}
|
|
|
|
if (!confirm(confirmText)) {
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
|
|
// Auto-focus on first checkbox or reason select
|
|
{% if object.is_active %}
|
|
$('#confirm-understanding').focus();
|
|
{% else %}
|
|
$('select[name="termination_reason"]').focus();
|
|
{% endif %}
|
|
});
|
|
|
|
{% if object.user and related_sessions %}
|
|
function terminateAllUserSessions() {
|
|
if (confirm('Are you sure you want to terminate ALL active sessions for this user?\n\nThis will log them out from all devices.')) {
|
|
$.ajax({
|
|
url: '{% url "accounts:user_terminate_sessions" object.user.pk %}',
|
|
method: 'POST',
|
|
data: {
|
|
'csrfmiddlewaretoken': '{{ csrf_token }}'
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
toastr.success('All user sessions terminated successfully');
|
|
window.location.href = '{% url "accounts:session_list" %}';
|
|
} else {
|
|
toastr.error('Failed to terminate user sessions');
|
|
}
|
|
},
|
|
error: function() {
|
|
toastr.error('An error occurred while terminating user sessions');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
{% endif %}
|
|
</script>
|
|
{% endblock %}
|
|
|