Create check setup page.

This commit is contained in:
elroy 2017-07-10 22:24:39 +02:00
parent ca4082b13f
commit 4f75026fc3
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,93 @@
package nl.komtek.gpi.controllers;
import nl.komtek.gpi.services.GunbotProxyService;
import nl.komtek.gpi.utils.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Elroy on 10-7-2017.
*/
@Controller
@RequestMapping("/checkSetup/**")
public class CheckSetupController {
@Autowired
private GunbotProxyService gunbotProxyService;
@Autowired
private Util util;
private Map<String, String> setupData = new HashMap<>();
@RequestMapping
public ModelAndView checkSetup(ModelMap modelMap) {
try {
String keyName = "default_apiKey";
String secretName = "default_apiSecret";
String apiKey = util.getEnvProperty(keyName);
String apiSecret = util.getEnvProperty(secretName);
if (StringUtils.isEmpty(apiKey) || StringUtils.isEmpty(apiSecret)) {
setupData.put(keyName, String.format("Please setup %s and %s", keyName, secretName));
} else {
gunbotProxyService.analyzeResult(gunbotProxyService.checkDefaultKey("default"));
setupData.put("defaultKey", "Looking good!");
}
} catch (Exception e) {
setupData.put("defaultKey", e.getMessage());
}
for (int i = 1; i <= 10; i++) {
String keyName = String.format("apiKey%d", i);
String secretName = String.format("apiSecret%d", i);
String apiKey = util.getEnvProperty(keyName);
String apiSecret = util.getEnvProperty(secretName);
if (i == 1 && (StringUtils.isEmpty(apiKey) || StringUtils.isEmpty(apiSecret))) {
setupData.put(keyName, String.format("Please setup %s and %s", keyName, secretName));
break;
}
if (StringUtils.isEmpty(apiKey) || StringUtils.isEmpty(apiSecret)) {
break;
}
try {
gunbotProxyService.analyzeResult(gunbotProxyService.checkTradingKey(apiKey));
setupData.put(keyName, "Looking good!");
} catch (Exception e) {
setupData.put(keyName, e.getMessage());
}
}
//check if hostfile was setup correctly
try {
InetAddress address = InetAddress.getByName("poloniex.com");
if (address.getHostAddress().equals("127.0.0.1")) {
setupData.put("hostfile", "Looking good!");
} else {
setupData.put("hostfile", "poloniex.com is not pointing to 127.0.0.1");
}
} catch (UnknownHostException e) {
setupData.put("hostfile", e.getMessage());
}
try {
InetAddress address = InetAddress.getByName("www.poloniex.com");
if (!address.getHostAddress().equals("127.0.0.1")) {
setupData.put("www.poloniex.com", "Looking good!");
} else {
setupData.put("www.poloniex.com", "www.poloniex.com should not point to 127.0.0.1");
}
} catch (UnknownHostException e) {
setupData.put("www.poloniex.com", e.getMessage());
}
modelMap.put("setupData", setupData);
return new ModelAndView("setupData", modelMap);
}
}

View File

@ -0,0 +1,20 @@
<#setting number_format=",##0.00000000">
<#assign total=0>
<!DOCTYPE html>
<html lang="en">
<body>
<table border="1">
<#list setupData?keys as key>
<tbody>
<tr>
<td>${key}</td>
<td>${setupData[key]} </td>
</tr>
</tbody>
</#list>
</table>
</body>
</html>