Skip to content

Commit

Permalink
Enable Kick Connection, Kick IP and Ban IP in the GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stratehm committed Jun 18, 2015
1 parent b4ff229 commit 1077201
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -495,7 +496,15 @@ protected void onRequestReceived(JsonRpcRequest request) {
* @return
*/
public String getConnectionName() {
return socket != null ? socket.getRemoteSocketAddress().toString() : "Undefined";
String name = "Undefined";
if (socket != null) {
if (socket.getRemoteSocketAddress() instanceof InetSocketAddress) {
name = ((InetSocketAddress) socket.getRemoteSocketAddress()).getAddress().getHostAddress();
} else {
name = socket.getRemoteSocketAddress().toString();
}
}
return name;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@ private PoolDetailsDTO convertPoolToDTO(Pool pool) {

private WorkerConnectionDTO convertWorkerConnectionToDTO(WorkerConnection connection) {
WorkerConnectionDTO result = new WorkerConnectionDTO();
result.setRemoteHost(connection.getRemoteAddress().toString());
result.setRemoteHost(connection.getRemoteAddress().getHostAddress());
result.setRemotePort(Integer.toString(connection.getRemotePort()));
result.setAcceptedHashesPerSeconds(Double.valueOf(connection.getAcceptedHashrate()).longValue());
result.setRejectedHashesPerSeconds(Double.valueOf(connection.getRejectedHashrate()).longValue());
result.setPoolName(connection.getPool().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class WorkerConnectionDTO {

private String remoteHost;
private String remotePort;
private List<String> authorizedUsers;
private Long acceptedHashesPerSeconds;
private Long rejectedHashesPerSeconds;
Expand All @@ -46,6 +47,14 @@ public void setRemoteHost(String remoteHost) {
this.remoteHost = remoteHost;
}

public String getRemotePort() {
return remotePort;
}

public void setRemotePort(String remotePort) {
this.remotePort = remotePort;
}

public List<String> getAuthorizedUsers() {
return authorizedUsers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void closeWithError(Exception e) {

@Override
public String getConnectionName() {
return "Getwork-" + getRemoteAddress().toString();
return "Getwork-" + getRemoteAddress().getHostAddress();
}

@Override
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/webapp/js/controllers/connectionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,27 @@ define(['jquery', 'ractivejs', 'rv!templates/connectionItem', 'i18n!locales', 'c
this.connectionItemJquery.remove();
};

ConnectionItem.prototype.getKickButton = function() {
return this.connectionItemJquery.find(".kickConnection");
};

ConnectionItem.prototype.getBanIpButton = function() {
return this.connectionItemJquery.find(".banIp");
};

ConnectionItem.prototype.getKickIpButton = function() {
return this.connectionItemJquery.find(".kickIp");
};

/**
* Update the displayed items based on the authorization.
*/
ConnectionItem.prototype.updateAccessibleItems = function() {
if(!authenticationManager.isAuthenticated) {
this.connectionItemJquery.find('.kickConnection, .kickIp, .banIp').hide();
} else {
this.connectionItemJquery.find('.kickConnection, .kickIp, .banIp').show();
}
};

return ConnectionItem;
Expand Down
118 changes: 116 additions & 2 deletions src/main/resources/webapp/js/controllers/connectionsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,122 @@ define(['jquery', 'ractivejs', 'controllers/abstractPageController', 'rv!templat
var item = new ConnectionItem(this.getContainer().find('.connectionsItemContainer')), controller = this;
item.setConnection(connection);
this.items.push(item);

// Initialize all buttons handlers
item.getKickButton().click(function() {
controller.kickConnection(connection);
});

item.getBanIpButton().click(function() {
controller.banIp(connection);
});

item.getKickIpButton().click(function() {
controller.kickIp(connection);
});

};

ConnectionsPageController.prototype.kickConnection = function(connection) {
var controller = this;

$.ajax({
url: 'proxy/connection/kick',
dataType: "json",
type: "POST",
data: JSON.stringify({
address: connection.remoteHost,
port: connection.remotePort
}),
contentType: "application/json",
success: function(data) {
if (data.status != 'Done') {
window.alert('Failed to kick the connection. Message: ' + data.message);
} else {
controller.refresh();
}
},
error: function(request, textStatus, errorThrown) {
var jsonObject = JSON.parse(request.responseText);
window.alert('Failed to kick the connection. Status: ' + textStatus + ', error: ' + errorThrown
+ ', message: ' + jsonObject.message);
}
});
}

ConnectionsPageController.prototype.banIp = function(connection) {
var controller = this;

var banIpFunction = function() {
$.ajax({
url: 'proxy/address/ban',
dataType: "json",
type: "POST",
data: JSON.stringify({
address: connection.remoteHost
}),
contentType: "application/json",
success: function(data) {
if (data.status != 'Done') {
window.alert('Failed to ban the IP. Message: ' + data.message);
} else {
controller.refresh();
}
},
error: function(request, textStatus, errorThrown) {
var jsonObject = JSON.parse(request.responseText);
window.alert('Failed to ban the IP. Status: ' + textStatus + ', error: ' + errorThrown
+ ', message: ' + jsonObject.message);
}
});
};

var modal = new ConfirmationPopup({
title: i18next.t('connectionsPage.banIp.confirmationPopup.title'),
message: i18next.t('connectionsPage.banIp.confirmationPopup.message', {
ip: connection.remoteHost
}),
yesCallback: banIpFunction,
displayCancelButton: false
});
}

ConnectionsPageController.prototype.kickIp = function(connection) {
var controller = this;

var kickIpFunction = function() {
$.ajax({
url: 'proxy/address/kick',
dataType: "json",
type: "POST",
data: JSON.stringify({
address: connection.remoteHost
}),
contentType: "application/json",
success: function(data) {
if (data.status != 'Done') {
window.alert('Failed to kick the IP. Message: ' + data.message);
} else {
controller.refresh();
}
},
error: function(request, textStatus, errorThrown) {
var jsonObject = JSON.parse(request.responseText);
window.alert('Failed to kick the IP. Status: ' + textStatus + ', error: ' + errorThrown
+ ', message: ' + jsonObject.message);
}
});
};

var modal = new ConfirmationPopup({
title: i18next.t('connectionsPage.kickIp.confirmationPopup.title'),
message: i18next.t('connectionsPage.kickIp.confirmationPopup.message', {
ip: connection.remoteHost
}),
yesCallback: kickIpFunction,
displayCancelButton: false
});
}

ConnectionsPageController.prototype.refresh = function(onSuccess) {
var controller = this;
Expand All @@ -89,7 +203,7 @@ define(['jquery', 'ractivejs', 'controllers/abstractPageController', 'rv!templat
data.forEach(function(connection) {
// Look for the connectionItem with the given name
var connectionItem = controller.items.find(function(item) {
return item.connection.remoteHost == connection.remoteHost;
return item.connection.remoteHost == connection.remoteHost && item.connection.remotePort == connection.remotePort;
});

// If the connection item does not exist, create it.
Expand All @@ -107,7 +221,7 @@ define(['jquery', 'ractivejs', 'controllers/abstractPageController', 'rv!templat
// Look for the connection of the connectionItem in
// the received connections.
var connection = data.find(function(connection) {
return connection.remoteHost == connectionItem.connection.remoteHost;
return connection.remoteHost == connectionItem.connection.remoteHost && connection.remotePort == connectionItem.connection.remotePort;
});
// If the connection is not in the received
// connections, then delete it.
Expand Down
22 changes: 21 additions & 1 deletion src/main/resources/webapp/locales/en-gb/stratumProxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,28 @@
"connectionsPage": {
"autoRefresh": "Auto refresh in __count__ second.",
"autoRefresh_plural": "Auto refresh in __count__ seconds.",
"autoRefresh_undefinite": "Auto refresh in -- second."
"autoRefresh_undefinite": "Auto refresh in -- second.",
"banIp":
{
"confirmationPopup":
{
"title": "Ban IP confirmation",
"message": "Do you really want to ban __ip__ ? The IP will be banned until the next proxy start."
}
},
"kickIp":
{
"confirmationPopup":
{
"title": "Kick IP confirmation",
"message": "Do you really want to kick __ip__ ? All the connections with this IP will be kicked."
}
}
},

"connectionItem": {
"remoteHostLabel": "Remote host",
"remotePortLabel": "Remote port",
"authorizedUsersLabel": "Authorized users",
"acceptedHashrateLabel": "Accepted hashrate",
"rejectedHashrateLabel": "Rejected hashrate",
Expand All @@ -304,6 +321,9 @@
"extranonceNotificationSupportedLabel": "Is extranonce notification supported",
"connectionTypeLabel": "Connection type",
"workerVersionLabel": "Worker version",
"kickConnectionButtonLabel": "Kick Connection",
"kickIpButtonLabel": "Kick Connection",
"banIpButtonLabel": "Ban IP",
"workerVersionUnknown": "Unknown"
},

Expand Down
32 changes: 26 additions & 6 deletions src/main/resources/webapp/locales/fr-fr/stratumProxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,41 @@
},

"connectionsPage": {
"autoRefresh": "Auto refresh in __count__ second.",
"autoRefresh_plural": "Auto refresh in __count__ seconds.",
"autoRefresh_undefinite": "Auto refresh in -- second."
"autoRefresh": "Rafraichissement dans __count__ seconde.",
"autoRefresh_plural": "Rafraichissement dans __count__ secondes.",
"autoRefresh_undefinite": "Rafraichissement dans -- secondes.",
"banIp":
{
"confirmationPopup":
{
"title": "Confirmer le bannissement de l'IP",
"message": "Etes-vous sûr de vouloir bannir l'IP __ip__ ? L'IP sera alors bannie jusqu'au prochain redémarrage du proxy."
}
},
"kickIp":
{
"confirmationPopup":
{
"title": "Confirmer la déconnexion de l'IP",
"message": "Etes-vous sûr de vouloir déconnecter l'IP __ip__ ? Toutes les connexions avec cette IP seront déconnectées."
}
}
},

"connectionItem": {
"remoteHostLabel": "Adresse distante",
"remotePortLabel": "Port distant",
"authorizedUsersLabel": "Utilisateurs autorisés",
"acceptedHashrateLabel": "Puissance de calcul accepté",
"rejectedHashrateLabel": "Puissance de calcul rejeté",
"acceptedHashrateLabel": "Puissance de calcul acceptée",
"rejectedHashrateLabel": "Puissance de calcul rejetée",
"isActiveSinceLabel": "Actif depuis",
"workingOnPoolLabel": "Attribué au pool",
"workingOnPoolLabel": "Attribuée au pool",
"extranonceNotificationSupportedLabel": "Support du changement d'extranonce",
"connectionTypeLabel": "Type de connection",
"workerVersionLabel": "Version du mineur",
"kickConnectionButtonLabel": "Déconnecter la Connexion",
"kickIpButtonLabel": "Déconnecter l'IP",
"banIpButtonLabel": "Bannir l'IP",
"workerVersionUnknown": "Inconnue"
},

Expand Down
36 changes: 17 additions & 19 deletions src/main/resources/webapp/ui/templates/connectionItem.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ <h3 class="panel-title">{{remoteHost}}</h3>
data-i18n="connectionItem.remoteHostLabel">Remote host</label>
<div class="col-sm-3 tooltipOnOverflow">{{remoteHost}}</div>
<label class="col-sm-3 control-label"
data-i18n="connectionItem.authorizedUsersLabel">Authorized users</label>
<div class="col-sm-3 tooltipOnOverflow">{{authorizedUsers}}</div>
data-i18n="connectionItem.remotePortLabel">Remote port</label>
<div class="col-sm-3 tooltipOnOverflow">{{remotePort}}</div>
</div>
<div class="row">
<label class="col-sm-3 control-label"
Expand Down Expand Up @@ -44,24 +44,22 @@ <h3 class="panel-title">{{remoteHost}}</h3>
<div class="col-sm-3 tooltipOnOverflow">{{#workerVersion}} {{ workerVersion }} {{/workerVersion}}
{{^workerVersion}} <span data-i18n="connectionItem.workerVersionUnknown">Unknown</span>
{{/workerVersion}}</div>
<!-- <label class="col-sm-3 control-label" -->
<!-- data-i18n="connectionItem.connectionTypeLabel">Connection type</label> -->
<!-- <div class="col-sm-3 tooltipOnOverflow">{{connectionType}}</div> -->
<label class="col-sm-3 control-label"
data-i18n="connectionItem.authorizedUsersLabel">Authorized users</label>
<div class="col-sm-3 tooltipOnOverflow">{{authorizedUsers}}</div>
</div>

<!-- <div class="row top20 bottom20"> -->
<!-- <div class="text-center"> -->
<!-- <div class="btn-group"> -->
<!-- <a class="btn btn-warning kickUser" -->
<!-- data-i18n="connectionItem.kickButtonLabel" -->
<!-- {{^user.isActive}} -->
<!-- disabled="disabled"{{/user.isActive}}>Kick</a><a -->
<!-- class="btn btn-danger banUser" -->
<!-- data-i18n="connectionItem.banButtonLabel" -->
<!-- {{^user.isActive}} -->
<!-- disabled="disabled"{{/user.isActive}}>Ban</a> -->
<!-- </div> -->
<!-- </div> -->
<!-- </div> -->
<div class="row top20 bottom20">
<div class="text-center">
<div class="btn-group">
<a class="btn btn-warning kickConnection"
data-i18n="connectionItem.kickConnectionButtonLabel">Kick Connection</a><a
class="btn btn-danger kickIp"
data-i18n="connectionItem.kickIpButtonLabel">Kick IP</a><a
class="btn btn-danger banIp"
data-i18n="connectionItem.banIpButtonLabel">Ban IP</a>
</div>
</div>
</div>
</div>
</div>

0 comments on commit 1077201

Please sign in to comment.