feat(web): Add unlimited IP controls to users page
This commit is contained in:
@ -76,6 +76,7 @@
|
||||
<th class="text-nowrap">Expiry Date</th>
|
||||
<th class="text-nowrap">Expiry Days</th>
|
||||
<th>Enable</th>
|
||||
<th class="text-nowrap">Unlimited IP</th>
|
||||
<th class="text-nowrap">Configs</th>
|
||||
<th class="text-nowrap">Actions</th>
|
||||
</tr>
|
||||
@ -84,7 +85,7 @@
|
||||
{% for user in users|sort(attribute='username', case_sensitive=false) %}
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" class="user-checkbox" value="{{ user.username }}">
|
||||
<input type="checkbox" class="user-checkbox" value="{{ user['username'] }}">
|
||||
</td>
|
||||
<td>{{ loop.index }}</td>
|
||||
<td>
|
||||
@ -96,35 +97,42 @@
|
||||
<i class="fas fa-circle text-danger"></i> {{ user['status'] }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td data-username="{{ user.username }}">{{ user.username }}</td>
|
||||
<td>{{ user.traffic_used }}</td>
|
||||
<td>{{ user.expiry_date }}</td>
|
||||
<td>{{ user.expiry_days }}</td>
|
||||
<td data-username="{{ user['username'] }}">{{ user['username'] }}</td>
|
||||
<td>{{ user['traffic_used'] }}</td>
|
||||
<td>{{ user['expiry_date'] }}</td>
|
||||
<td>{{ user['expiry_days'] }}</td>
|
||||
<td>
|
||||
{% if user.enable %}
|
||||
{% if user['enable'] %}
|
||||
<i class="fas fa-check-circle text-success"></i>
|
||||
{% else %}
|
||||
<i class="fas fa-times-circle text-danger"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user['unlimited_ip'] %}
|
||||
<i class="fas fa-shield-alt text-primary"></i>
|
||||
{% else %}
|
||||
<i class="fas fa-times-circle text-muted"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-nowrap">
|
||||
<a href="#" class="config-link" data-toggle="modal" data-target="#qrcodeModal"
|
||||
data-username="{{ user.username }}">
|
||||
data-username="{{ user['username'] }}">
|
||||
<i class="fas fa-qrcode"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td class="text-nowrap">
|
||||
<button type="button" class="btn btn-sm btn-info edit-user"
|
||||
data-user='{{ user.username }}' data-toggle="modal"
|
||||
data-user="{{ user['username'] }}" data-toggle="modal"
|
||||
data-target="#editUserModal">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-warning reset-user"
|
||||
data-user='{{ user.username }}'>
|
||||
data-user="{{ user['username'] }}">
|
||||
<i class="fas fa-undo"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-danger delete-user"
|
||||
data-user='{{ user.username }}'>
|
||||
data-user="{{ user['username'] }}">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
@ -173,6 +181,10 @@
|
||||
<input type="number" class="form-control" id="addExpirationDays" name="expiration_days"
|
||||
required>
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input type="checkbox" class="form-check-input" id="addUnlimited" name="unlimited">
|
||||
<label class="form-check-label" for="addUnlimited">Unlimited IP (Exempt from IP limit checks)</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" id="addSubmitButton">Add User</button>
|
||||
</form>
|
||||
</div>
|
||||
@ -206,9 +218,13 @@
|
||||
<input type="number" class="form-control" id="editExpirationDays" name="new_expiration_days">
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="editBlocked" name="blocked" value="true">
|
||||
<input type="checkbox" class="form-check-input" id="editBlocked" name="blocked">
|
||||
<label class="form-check-label" for="editBlocked">Blocked</label>
|
||||
</div>
|
||||
<div class="form-check mb-3">
|
||||
<input type="checkbox" class="form-check-input" id="editUnlimitedIp" name="unlimited_ip">
|
||||
<label class="form-check-label" for="editUnlimitedIp">Unlimited IP (Exempt from IP limit checks)</label>
|
||||
</div>
|
||||
<input type="hidden" id="originalUsername" name="username">
|
||||
<button type="submit" class="btn btn-primary" id="editSubmitButton">Save Changes</button>
|
||||
</form>
|
||||
@ -259,7 +275,6 @@
|
||||
}
|
||||
|
||||
$("#addSubmitButton").prop("disabled", true);
|
||||
// $("#editSubmitButton").prop("disabled", true);
|
||||
|
||||
$("#addUsername").on("input", function () {
|
||||
const username = $(this).val();
|
||||
@ -387,11 +402,12 @@
|
||||
}
|
||||
$("#addSubmitButton").prop("disabled", true);
|
||||
|
||||
const formData = $(this).serializeArray();
|
||||
const jsonData = {};
|
||||
formData.forEach(field => {
|
||||
jsonData[field.name] = field.value;
|
||||
});
|
||||
const jsonData = {
|
||||
username: $("#addUsername").val(),
|
||||
traffic_limit: $("#addTrafficLimit").val(),
|
||||
expiration_days: $("#addExpirationDays").val(),
|
||||
unlimited: $("#addUnlimited").is(":checked")
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: " {{ url_for('add_user_api') }} ",
|
||||
@ -435,6 +451,7 @@
|
||||
const trafficUsageText = row.find("td:eq(4)").text().trim();
|
||||
const expiryDaysText = row.find("td:eq(6)").text().trim();
|
||||
const blocked = row.find("td:eq(7) i").hasClass("text-danger");
|
||||
const unlimited_ip = row.find("td:eq(8) i").hasClass("text-primary");
|
||||
|
||||
const expiryDaysValue = (expiryDaysText.toLowerCase() === 'unlimited') ? 0 : parseInt(expiryDaysText, 10);
|
||||
|
||||
@ -455,6 +472,7 @@
|
||||
$("#editTrafficLimit").val(trafficLimitValue);
|
||||
$("#editExpirationDays").val(expiryDaysValue);
|
||||
$("#editBlocked").prop("checked", blocked);
|
||||
$("#editUnlimitedIp").prop("checked", unlimited_ip);
|
||||
|
||||
const isValid = validateUsername(username, "editUsernameError");
|
||||
$("#editUserForm button[type='submit']").prop("disabled", !isValid);
|
||||
@ -465,12 +483,19 @@
|
||||
if (!validateUsername($("#editUsername").val(), "editUsernameError")) {
|
||||
return;
|
||||
}
|
||||
$("#editSubmitButton").prop("disabled", true);
|
||||
|
||||
const jsonData = {
|
||||
new_username: $("#editUsername").val(),
|
||||
new_traffic_limit: $("#editTrafficLimit").val() || null,
|
||||
new_expiration_days: $("#editExpirationDays").val() || null,
|
||||
blocked: $("#editBlocked").is(":checked"),
|
||||
unlimited_ip: $("#editUnlimitedIp").is(":checked")
|
||||
};
|
||||
|
||||
const formData = $(this).serializeArray();
|
||||
const jsonData = {};
|
||||
formData.forEach(field => {
|
||||
jsonData[field.name] = field.value;
|
||||
});
|
||||
if (jsonData.new_username === $("#originalUsername").val()) {
|
||||
delete jsonData.new_username;
|
||||
}
|
||||
|
||||
const editUserUrl = "{{ url_for('edit_user_api', username='USERNAME_PLACEHOLDER') }}";
|
||||
const url = editUserUrl.replace("USERNAME_PLACEHOLDER", encodeURIComponent($("#originalUsername").val()));
|
||||
@ -481,22 +506,8 @@
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(jsonData),
|
||||
success: function (response) {
|
||||
if (typeof response === 'string' && response.includes("User updated successfully")) {
|
||||
if (response && response.detail) {
|
||||
$("#editUserModal").modal("hide");
|
||||
Swal.fire({
|
||||
title: "Success!",
|
||||
text: "User updated successfully!",
|
||||
icon: "success",
|
||||
confirmButtonText: "OK",
|
||||
}).then(() => {
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
else if (response && response.detail) {
|
||||
// Hide the modal
|
||||
$("#editUserModal").modal("hide");
|
||||
|
||||
// Show a success message
|
||||
Swal.fire({
|
||||
title: "Success!",
|
||||
text: response.detail,
|
||||
@ -509,29 +520,29 @@
|
||||
$("#editUserModal").modal("hide");
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: response.error || "An error occurred.",
|
||||
text: (response && response.error) || "An unknown error occurred.",
|
||||
icon: "error",
|
||||
confirmButtonText: "OK",
|
||||
});
|
||||
$("#editSubmitButton").prop("disabled", false);
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
console.error(error);
|
||||
error: function (jqXHR) {
|
||||
let errorMessage = "An error occurred while updating user.";
|
||||
if (jqXHR.responseJSON && jqXHR.responseJSON.detail) {
|
||||
errorMessage = jqXHR.responseJSON.detail;
|
||||
}
|
||||
Swal.fire({
|
||||
title: "Error!",
|
||||
text: "An error occurred while updating user",
|
||||
text: errorMessage,
|
||||
icon: "error",
|
||||
confirmButtonText: "OK",
|
||||
});
|
||||
$("#editSubmitButton").prop("disabled", false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#editUserForm button[type='submit']").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
$(this).closest("form").submit();
|
||||
});
|
||||
|
||||
// Reset User Button Click
|
||||
$("#userTable").on("click", ".reset-user", function () {
|
||||
const username = $(this).data("user");
|
||||
@ -653,15 +664,12 @@
|
||||
method: "GET",
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
// console.log("API Response:", response);
|
||||
|
||||
const configs = [
|
||||
{ type: "IPv4", link: response.ipv4 },
|
||||
{ type: "IPv6", link: response.ipv6 },
|
||||
{ type: "Normal-SUB", link: response.normal_sub }
|
||||
];
|
||||
|
||||
|
||||
configs.forEach(config => {
|
||||
if (config.link) {
|
||||
const displayType = config.type;
|
||||
@ -765,10 +773,10 @@
|
||||
}
|
||||
|
||||
$('#addUserModal').on('show.bs.modal', function (event) {
|
||||
$('#addUsername').val('');
|
||||
$('#addUserForm')[0].reset();
|
||||
$('#addUsernameError').text('');
|
||||
$('#addTrafficLimit').val('30');
|
||||
$('#addExpirationDays').val('30');
|
||||
$('#addUsernameError').text('');
|
||||
$('#addSubmitButton').prop('disabled', true);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user