Add admin login
This commit is contained in:
@@ -1,28 +1,22 @@
|
|||||||
package de.jeyp91.tippligaforum;
|
package de.jeyp91.tippligaforum;
|
||||||
|
|
||||||
import org.apache.http.NameValuePair;
|
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.impl.client.BasicCookieStore;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TippligaWebsiteConnector {
|
public class TippligaWebsiteConnector {
|
||||||
CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
|
CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
|
||||||
@@ -31,6 +25,9 @@ public class TippligaWebsiteConnector {
|
|||||||
private static final Logger logger = LogManager.getLogger(TippligaWebsiteConnector.class);
|
private static final Logger logger = LogManager.getLogger(TippligaWebsiteConnector.class);
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
|
|
||||||
|
private final String username = "Julian";
|
||||||
|
private final String password = "original";
|
||||||
|
|
||||||
public TippligaWebsiteConnector() throws IOException {
|
public TippligaWebsiteConnector() throws IOException {
|
||||||
CookieHandler.setDefault(cm);
|
CookieHandler.setDefault(cm);
|
||||||
|
|
||||||
@@ -39,53 +36,186 @@ public class TippligaWebsiteConnector {
|
|||||||
.connectTimeout(Duration.ofSeconds(10))
|
.connectTimeout(Duration.ofSeconds(10))
|
||||||
.build();
|
.build();
|
||||||
login();
|
login();
|
||||||
|
adminLogin();
|
||||||
|
updateResultsAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void login() throws IOException {
|
private void login() throws IOException {
|
||||||
HttpRequest firstReq = HttpRequest.newBuilder()
|
HttpRequest req = HttpRequest.newBuilder()
|
||||||
.uri(URI.create("https://tippliga-wuerzburg.de/ucp.php?mode=login"))
|
.uri(URI.create("https://tippliga-wuerzburg.de/ucp.php?mode=login"))
|
||||||
.GET().build();
|
.GET().build();
|
||||||
|
|
||||||
String firstReqBody = "";
|
String reqBody = "";
|
||||||
try {
|
try {
|
||||||
firstReqBody = client.send(firstReq, HttpResponse.BodyHandlers.ofString()).body();
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
reqBody = client.send(req, HttpResponse.BodyHandlers.ofString()).body();
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<HttpCookie> firstReqCookieList = cookieStore.getCookies();
|
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("^[\\s\\S]*<input type=\"hidden\" name=\"creation_time\" value=\"([\\d]{10})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"form_token\" value=\"([\\d\\w]{40})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"sid\" value=\"([\\d\\w]{32})\" \\/>[\\s\\S]*$");
|
Pattern pattern = Pattern.compile("^[\\s\\S]*<input type=\"hidden\" name=\"creation_time\" value=\"([\\d]{10})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"form_token\" value=\"([\\d\\w]{40})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"sid\" value=\"([\\d\\w]{32})\" \\/>[\\s\\S]*$");
|
||||||
Matcher matcher = pattern.matcher(firstReqBody);
|
Matcher matcher = pattern.matcher(reqBody);
|
||||||
matcher.find();
|
matcher.find();
|
||||||
|
|
||||||
String creationTime = matcher.group(1);
|
String creationTime = matcher.group(1);
|
||||||
String formToken = matcher.group(2);
|
String formToken = matcher.group(2);
|
||||||
String sid = matcher.group(3);
|
String sid = matcher.group(3);
|
||||||
|
|
||||||
List<NameValuePair> urlParameters = new ArrayList<>();
|
Map<String, String> loginParameters = new HashMap<>();
|
||||||
urlParameters.add(new BasicNameValuePair("username", "Julian"));
|
loginParameters.put("login", "Anmelden");
|
||||||
urlParameters.add(new BasicNameValuePair("password", "original"));
|
loginParameters.put("redirect", "index.php");
|
||||||
urlParameters.add(new BasicNameValuePair("creation_time", creationTime));
|
loginParameters.put("autologin", "on");
|
||||||
urlParameters.add(new BasicNameValuePair("form_token", formToken));
|
loginParameters.put("viewonline", "on");
|
||||||
urlParameters.add(new BasicNameValuePair("sid", sid));
|
loginParameters.put("username", username);
|
||||||
urlParameters.add(new BasicNameValuePair("login", "Anmelden"));
|
loginParameters.put("password", password);
|
||||||
|
loginParameters.put("creation_time", creationTime);
|
||||||
|
loginParameters.put("form_token", formToken);
|
||||||
|
loginParameters.put("sid", sid);
|
||||||
|
|
||||||
|
String loginForm = loginParameters.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(e -> e.getKey() + "=" + URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8))
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
|
||||||
|
HttpRequest loginReq = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create("https://tippliga-wuerzburg.de/ucp.php?mode=login"))
|
||||||
|
.headers("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(loginForm))
|
||||||
|
.build();
|
||||||
|
|
||||||
HttpPost loginReq = new HttpPost("https://tippliga-wuerzburg.de/ucp.php?mode=login");
|
|
||||||
try {
|
|
||||||
loginReq.setEntity(new UrlEncodedFormEntity(urlParameters));
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
String form = new String(loginReq.getEntity().getContent().readAllBytes());
|
|
||||||
String loginReqBody = "";
|
String loginReqBody = "";
|
||||||
try {
|
try {
|
||||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
TimeUnit.SECONDS.sleep(1);
|
||||||
CloseableHttpResponse response = httpClient.execute(loginReq);
|
loginReqBody = client.send(loginReq, HttpResponse.BodyHandlers.ofString()).body();
|
||||||
loginReqBody = EntityUtils.toString(response.getEntity());
|
} catch (IOException | InterruptedException e) {
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
List<HttpCookie> loginReqCookieList = cookieStore.getCookies();
|
List<HttpCookie> loginReqCookieList = cookieStore.getCookies();
|
||||||
logger.info(loginReqBody);
|
}
|
||||||
|
|
||||||
|
private void adminLogin() throws IOException {
|
||||||
|
String sid = getSidFromCookie();
|
||||||
|
String url = "https://tippliga-wuerzburg.de/adm/index.php?sid=" + sid;
|
||||||
|
HttpRequest req = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.headers("referer", "https://tippliga-wuerzburg.de/index.php?sid=" + sid)
|
||||||
|
.GET().build();
|
||||||
|
|
||||||
|
String reqBody = "";
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
reqBody = client.send(req, HttpResponse.BodyHandlers.ofString()).body();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile("^[\\s\\S]*<input type=\"hidden\" name=\"creation_time\" value=\"([\\d]{10})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"form_token\" value=\"([\\d\\w]{40})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"sid\" value=\"([\\d\\w]{32})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"credential\" value=\"([\\d\\w]{32})\" \\/>[\\s\\S]*$");
|
||||||
|
Matcher matcher = pattern.matcher(reqBody);
|
||||||
|
matcher.find();
|
||||||
|
|
||||||
|
String creationTime = matcher.group(1);
|
||||||
|
String formToken = matcher.group(2);
|
||||||
|
sid = matcher.group(3);
|
||||||
|
String credential = matcher.group(4);
|
||||||
|
|
||||||
|
Map<String, String> loginParameters = new HashMap<>();
|
||||||
|
loginParameters.put("login", "Anmelden");
|
||||||
|
loginParameters.put("redirect", "./../adm/index.php?sid=" + sid);
|
||||||
|
loginParameters.put("username", username);
|
||||||
|
loginParameters.put("password_" + credential, password);
|
||||||
|
loginParameters.put("creation_time", creationTime);
|
||||||
|
loginParameters.put("form_token", formToken);
|
||||||
|
loginParameters.put("sid", sid);
|
||||||
|
loginParameters.put("credential", credential);
|
||||||
|
|
||||||
|
String loginForm = loginParameters.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(e -> e.getKey() + "=" + URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8))
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
|
||||||
|
HttpRequest loginReq = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.headers("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(loginForm))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
String loginReqBody = "";
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
HttpResponse<String> loginReqResponse = client.send(loginReq, HttpResponse.BodyHandlers.ofString()); // Response 302
|
||||||
|
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
List<HttpCookie> loginReqCookieList = cookieStore.getCookies();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateResultsAdmin() {
|
||||||
|
String sid = getSidFromCookie();
|
||||||
|
String url = "https://tippliga-wuerzburg.de/adm/index.php?i=-football-football-acp-results_module&mode=manage&sid=" + sid;
|
||||||
|
|
||||||
|
HttpRequest req = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.GET().build();
|
||||||
|
|
||||||
|
String reqBody = "";
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
reqBody = client.send(req, HttpResponse.BodyHandlers.ofString()).body();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile("^[\\s\\S]*<input type=\"hidden\" name=\"creation_time\" value=\"([\\d]{10})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"form_token\" value=\"([\\d\\w]{40})\" \\/>[\\s\\S]*$");
|
||||||
|
Matcher matcher = pattern.matcher(reqBody);
|
||||||
|
matcher.find();
|
||||||
|
|
||||||
|
String creationTime = matcher.group(1);
|
||||||
|
String formToken = matcher.group(2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateResults() {
|
||||||
|
Map<String, String> resultParameters = new HashMap<>();
|
||||||
|
|
||||||
|
resultParameters.put("s", "2023");
|
||||||
|
resultParameters.put("l", "2");
|
||||||
|
resultParameters.put("m", "32");
|
||||||
|
resultParameters.put("action", "result");
|
||||||
|
resultParameters.put("goalsh384", "4");
|
||||||
|
resultParameters.put("oldgoalsh384", "4");
|
||||||
|
resultParameters.put("goalsg384", "3");
|
||||||
|
resultParameters.put("oldgoalsg384", "4");
|
||||||
|
resultParameters.put("goalsh380", "");
|
||||||
|
resultParameters.put("oldgoalsh380", "");
|
||||||
|
resultParameters.put("goalsg380", "");
|
||||||
|
resultParameters.put("oldgoalsg380", "");
|
||||||
|
|
||||||
|
String resultForm = resultParameters.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(e -> e.getKey() + "=" + URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8))
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
|
||||||
|
HttpRequest resultReq = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create("https://tippliga-wuerzburg.de/app.php/football/results?s=2023&l=2&m=32&action=result"))
|
||||||
|
.headers("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(resultForm))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
String resultReqBody = "";
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
resultReqBody = client.send(resultReq, HttpResponse.BodyHandlers.ofString()).body();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(resultReqBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSidFromCookie() {
|
||||||
|
HttpCookie sidCookie = cookieStore.getCookies().get(2);
|
||||||
|
String sid = sidCookie.getValue();
|
||||||
|
return sid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user