Completed admin panel conversion for user management (bans)

This commit is contained in:
Christian 'ketura' McCarty
2022-08-29 01:41:48 -05:00
parent b03c16aa8c
commit fa92e7efd0
6 changed files with 552 additions and 219 deletions

View File

@@ -118,7 +118,7 @@ public class AdminRequestHandler extends LotroServerRequestHandler implements Ur
List<Player> similarPlayers = _playerDAO.findSimilarAccounts(login); List<Player> similarPlayers = _playerDAO.findSimilarAccounts(login);
if (similarPlayers == null) if (similarPlayers == null)
throw new HttpProcessingException(404); throw new HttpProcessingException(400);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
@@ -165,7 +165,7 @@ public class AdminRequestHandler extends LotroServerRequestHandler implements Ur
String login = getFormParameterSafely(postDecoder, "login"); String login = getFormParameterSafely(postDecoder, "login");
if (login==null) if (login==null)
throw new HttpProcessingException(404); throw new HttpProcessingException(400);
if (!_adminService.banUser(login)) if (!_adminService.banUser(login))
throw new HttpProcessingException(404); throw new HttpProcessingException(404);
@@ -181,9 +181,9 @@ public class AdminRequestHandler extends LotroServerRequestHandler implements Ur
HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request); HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request);
try { try {
List<String> logins = getFormParametersSafely(postDecoder, "login"); List<String> logins = getFormParametersSafely(postDecoder, "login[]");
if (logins == null) if (logins == null)
throw new HttpProcessingException(404); throw new HttpProcessingException(400);
for (String login : logins) { for (String login : logins) {
if (!_adminService.banUser(login)) if (!_adminService.banUser(login))

View File

@@ -27,7 +27,7 @@
<li><a id="landingTab" href="#landing"></a></li> <li><a id="landingTab" href="#landing"></a></li>
<li><a id="generalTab" href="includes/admin/generalAdmin.html">General Admin</a></li> <li><a id="generalTab" href="includes/admin/generalAdmin.html">General Admin</a></li>
<li><a id="leagueTab" href="includes/admin/leagueAdmin.html">League Admin</a></li> <li><a id="leagueTab" href="includes/admin/leagueAdmin.html">League Admin</a></li>
<li><a id="banTab" href="#banAdmin">Ban Users</a></li> <li><a id="banTab" href="includes/admin/userAdmin.html">Manage Users</a></li>
</ol> </ol>
</div> </div>
<div id="landing" style=""> <div id="landing" style="">
@@ -36,39 +36,7 @@
</div> </div>
<div id="banAdmin"> <div id="banAdmin">
<div class="article">
<h1>Ban user</h1>
<h2>Permanently</h2>
<form id="banUserForm" method="POST" action="/gemp-lotr-server/admin/banUser">
Name (case-sensitive): <input type="text" name="login"><br/>
<input id="banUser" type="button" value="Ban user permanently">
</form>
<h2>Temporarily</h2>
<form id="banUserTempForm" method="POST" action="/gemp-lotr-server/admin/banUserTemp">
Name (case-sensitive): <input type="text" name="login"><br/>
Duration:
<select name="duration">
<option value="1">1 day</option>
<option value="3">3 days</option>
<option value="7">7 days</option>
<option value="14">14 days</option>
<option value="30">30 days</option>
</select><br/>
<input id="banUserTemp" type="button" value="Ban user temporarily">
</form>
<h1>Unban user</h1>
<form id="unBanUserForm" method="POST" action="/gemp-lotr-server/admin/unBanUser">
Name (case-sensitive): <input type="text" name="login"><br/>
<input id="unBanUser" type="button" value="Unban user">
</form>
<h1>Find suspicious behaviour</h1>
<h2>Multiple user accounts</h2>
<form id="findMultipleAccountsForm" method="POST" action="/gemp-lotr-server/admin/findMultipleAccounts">
Name (case-sensitive): <input type="text" name="login"><br/>
<input id="findMultipleAccounts" type="button" value="Find similar accounts">
</form>
<div id="displayUsers"></div>
</div>
</div> </div>
</div> </div>

View File

@@ -115,7 +115,7 @@
</td> </td>
<td id="cache-response">Ready.</td> <td id="cache-response">Ready.</td>
<td> <td>
All database operations have their results cached in memory to alleviate load on the DB while the server is running. This command clears that cache and forces any database calls to get the actual DB data. All database operations have their results cached in memory to alleviate load on the DB while the server is running. This command clears that cache and forces any database calls to get the actual DB data (which will then be cached again).
<br><br> <br><br>
Also clears the internal caches of the League and Tournament services, forcing standings to be re-calculated. Also clears the internal caches of the League and Tournament services, forcing standings to be re-calculated.
</td> </td>
@@ -137,6 +137,8 @@
</table> </table>
<hr>
<h1>Message of the Day</h1> <h1>Message of the Day</h1>
<div> <div>
<p>Sets the MOTD in the Game Hall just beneath the action bar at the top of the window. Supports HTML.</p> <p>Sets the MOTD in the Game Hall just beneath the action bar at the top of the window. Supports HTML.</p>
@@ -155,10 +157,10 @@
</div> </div>
<br/> <br/>
</div> </div>
<br>
<hr>
<h1>Collections</h1> <h1>Add Items to Collections</h1>
<h2>Add Items</h2>
<table class="tables"> <table class="tables">
<tr> <tr>

View File

@@ -0,0 +1,139 @@
<script type="text/javascript" src="js/gemp-022/manage.js"></script>
<div id="banMain" class="article">
<h1>Ban User</h1>
<h2>Permanently</h2>
<div>
Name (case-sensitive): <input id="permaban-input" type="text" ><br/>
<button id="permaban-button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" style="padding:4px;">
Permaban User
</button> <span id="permaban-result" style="display:inline-block;">Ready.</span>
</div>
<h2>Temporarily</h2>
<div>
Name (case-sensitive): <input id="tempban-input" type="text" ><br/>
<div>Duration:
<select id="temp-ban-duration-select">
<option value="1">1 day</option>
<option value="3">3 days</option>
<option value="7">7 days</option>
<option value="14">14 days</option>
<option value="30">30 days</option>
</select><br/>
</div>
<button id="tempban-button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" style="padding:4px;">
Tempban User
</button> <span id="tempban-result" style="display:inline-block;">Ready.</span>
</div>
<br><hr>
<h1>Unban user</h1>
<div>
Name (case-sensitive): <input id="unban-input" type="text" ><br/>
<button id="unban-button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" style="padding:4px;">
Unban User
</button> <span id="unban-result" style="display:inline-block;">Ready.</span>
</div>
<br><hr>
<h1>Find Suspicious Behaviour</h1>
<h2>Multiple User Accounts</h2>
<div>
Name (case-sensitive): <input id="sus-input" type="text" ><br/>
<button id="sus-button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" style="padding:4px;">
Find Similar Accounts
</button> <span id="sus-result" style="display:inline-block;">Ready.</span>
<div id="displayUsers"></div>
</div>
</div>
<!--
<script type="text/javascript">
function submitFormToAddress(url, formElem, success, error) {
var data = {};
$.ajax({
type:"POST",
url:serverDomain+url,
cache:false,
data:data,
traditional:true,
success:success,
error:error,
dataType:"xml"
});
}
$(document).ready(
function () {
var actionSuccess = function () {
alert("Operation was successful");
};
var actionFailure = function (xhr) {
var status = xhr.status;
if (status == 404)
alert("Specified resource (player, league) does not exist. Check the spelling and try again.");
else
alert("Unknown error. Status code - "+status);
};
var displayUsers = function (xml) {
var root = xml.documentElement;
if (root.tagName == 'players') {
var playersDiv = $("#displayUsers");
playersDiv.html("");
playersDiv.append("Similar accounts:");
var form = $("<form id='banMultipleForm' method='POST' action='/gemp-lotr-server/admin/banMultiple'></form>");
var table = $("<table class='tables'></table>");
table.append("<tr><th></th><th>Id</th><th>Name</th><th>Password (hash)</th><th>Create IP</th><th>Login IP</th><th>User status</th></tr>");
var players = root.getElementsByTagName("player");
for (var j=0; j<players.length; j++) {
var player = players[j];
var id=player.getAttribute("id");
var name=player.getAttribute("name");
var password = player.getAttribute("password");
var createIp = player.getAttribute("createIp");
var loginIp = player.getAttribute("loginIp");
var status = player.getAttribute("status");
table.append("<tr><td><input type='checkbox' name='login' value='"+name+"'></td><td>"+id+"</td><td>"+name+"</td><td>"+password+"</td><td>"+createIp+"</td><td>"+loginIp+"</td><td>"+status+"</td></tr>");
}
form.append(table);
form.append("<input type='button' value='Ban selected' onClick='banMultiple();'>");
playersDiv.append(form);
}
};
$("#banUser").click(
function() {
submitFormToAddress("/gemp-lotr-server/admin/banUser", $("#banUserForm").eq(0), actionSuccess, actionFailure);
});
$("#banUserTemp").click(
function() {
submitFormToAddress("/gemp-lotr-server/admin/banUserTemp", $("#banUserTempForm").eq(0), actionSuccess, actionFailure);
});
$("#unBanUser").click(
function() {
submitFormToAddress("/gemp-lotr-server/admin/unBanUser", $("#unBanUserForm").eq(0), actionSuccess, actionFailure);
});
$("#findMultipleAccounts").click(
function() {
submitFormToAddress("/gemp-lotr-server/admin/findMultipleAccounts", $("#findMultipleAccountsForm").eq(0), displayUsers, actionFailure);
});
});
</script> -->

View File

@@ -802,6 +802,77 @@ var GempLotrCommunication = Class.extend({
}); });
}, },
permabanUser:function (login, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/admin/banUser",
cache:false,
data:{
login:login
},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"html"
});
},
tempbanUser:function (login, duration, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/admin/banUserTemp",
cache:false,
data:{
login:login,
duration:duration
},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"html"
});
},
unbanUser:function (login, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/admin/unBanUser",
cache:false,
data:{
login:login
},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"html"
});
},
susUserSearch:function (login, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/admin/findMultipleAccounts",
cache:false,
data:{
login:login
},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"html"
});
},
banMultiple:function (login, callback, errorMap) {
$.ajax({
type:"POST",
url:this.url + "/admin/banMultiple",
cache:false,
data:{
login:login
},
success:this.deliveryCheck(callback),
error:this.errorCheck(errorMap),
dataType:"html"
});
},
//NEVER EVER EVER use this for actual authentication //NEVER EVER EVER use this for actual authentication

View File

@@ -0,0 +1,153 @@
$("banMain").ready(
function () {
$("#permaban-button").button().click(
function () {
let resultdiv = $("#permaban-result");
resultdiv.html("Processing...");
hall.comm.permabanUser($("#permaban-input").val(), function (string) {
resultdiv.html(string);
}, banErrorMap(resultdiv));
});
$("#tempban-button").button().click(
function () {
let resultdiv = $("#tempban-result");
resultdiv.html("Processing...");
hall.comm.tempbanUser($("#tempban-input").val(), $("#temp-ban-duration-select").val(), function (string) {
resultdiv.html(string);
}, banErrorMap(resultdiv));
});
$("#unban-button").button().click(
function () {
let resultdiv = $("#unban-result");
resultdiv.html("Processing...");
hall.comm.unbanUser($("#unban-input").val(), function (string) {
resultdiv.html(string);
}, banErrorMap(resultdiv));
});
$("#sus-button").button().click(
function () {
let resultdiv = $("#sus-result");
resultdiv.html("Processing...");
hall.comm.susUserSearch($("#sus-input").val(), susUserPopulate, banErrorMap(resultdiv), function() {
$("#displayUsers").hide();
});
});
});
function susUserPopulate(xml) {
var root = xml.documentElement;
if(root == null)
{
xml = new DOMParser().parseFromString(xml,"text/xml");
root = xml.documentElement;
}
if (root.tagName == 'players') {
var playersDiv = $("#displayUsers");
playersDiv.show();
playersDiv.html("");
playersDiv.append("Similar accounts:");
var form = $("<div id='banMultipleForm' style='overflow-x:scroll; width:min(120%,1350px); margin-left: max(-50%, -150px);'></div>");
var table = $("<table class='tables'></table>");
table.append("<tr style='position:sticky'><th></th><th>Id</th><th>Name</th><th>Password (hash)</th><th>Create IP</th><th>Login IP</th><th>User status</th></tr>");
var players = root.getElementsByTagName("player");
for (var j=0; j<players.length; j++) {
var player = players[j];
var id=player.getAttribute("id");
var name=player.getAttribute("name");
var password = player.getAttribute("password");
var createIp = player.getAttribute("createIp");
var loginIp = player.getAttribute("loginIp");
var status = player.getAttribute("status");
table.append("<tr><td style='position:sticky;left:0;z-index:2;background-color:#121212;'><input type='checkbox' name='login' value='"+name+"'></td><td style='position:sticky;left:20px;z-index:2;background-color:#121212;'>"+id+"</td><td style='position:sticky;left:77px;z-index:2;background-color:#121212;'>"+name+"</td><td>"+password+"</td><td>"+createIp+"</td><td>"+loginIp+"</td><td>"+status+"</td></tr>");
}
form.append(table);
playersDiv.append(form);
playersDiv.append("<input type='button' value='Permaban Selected' onClick='banMultiple();'> <span id='ban-multiple-result' style='display:inline-block;'>Ready.</span>");
$("#sus-result").html("OK");
}
}
function banMultiple() {
var actionSuccess = function () {
alert("Operation was successful");
};
var data = {};
var resultdiv = $("#ban-multiple-result");
resultdiv.html("Processing...");
var inputs = $("input[type='text'], input[type='checkbox']:checked, option:selected", $("#banMultipleForm").eq(0)).each(
function () {
var input = $(this);
var name = null;
var value = null;
if (input.prop("tagName") == "INPUT") {
name = input.attr("name");
value = input.val();
} else if (input.prop("tagName") == "OPTION") {
name = input.parents("select").attr("name");
value = input.attr("value");
}
if (name != null && value != null) {
if (data[name] == null)
data[name] = new Array();
data[name].push(value);
}
});
if(data.login == null)
{
$("#ban-multiple-result").html("Please check one or more users to ban.");
return;
}
hall.comm.banMultiple(data.login, function (string) {
$("#ban-multiple-result").html("OK");
}, banErrorMap(resultdiv));
}
function banErrorMap(outputControl, callback=null) {
return {
"0":function() {
outputControl.html("0: Server has been shut down or there was a problem with your internet connection.", "warningMessage");
if(callback!=null)
callback();
},
"401":function() {
outputControl.html("401: You are not logged in.");
if(callback!=null)
callback();
},
"403": function() {
outputControl.html("403: You do not have permission to perform such actions.");
if(callback!=null)
callback();
},
"404": function() {
outputControl.html("404: User not found. Check that you have capitalized it correctly and removed whitespace and try again.");
if(callback!=null)
callback();
},
"410": function() {
outputControl.html("410: You have been inactive for too long and were loggedout. Refresh the page if you wish to re-stablish connection.");
if(callback!=null)
callback();
}
};
}