Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .mvn/toolchains.xml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ RUN apk update \
&& apk add --no-cache ca-certificates fontconfig ttf-dejavu \
&& update-ca-certificates \
&& rm -rf /var/cache/apk/*
ENTRYPOINT ["java", "--add-opens=java.base/java.lang=ALL-UNNAMED", "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED", "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED", "--add-opens=java.base/java.io=ALL-UNNAMED", "--add-opens=java.base/java.net=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
ENTRYPOINT ["java", "--add-opens=java.base/java.lang=ALL-UNNAMED", "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED", "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED", "--add-opens=java.base/java.io=ALL-UNNAMED", "--add-opens=java.base/java.net=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
16 changes: 0 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,4 @@
</plugins>
</build>

<!--<repositories>-->
<!--<repository>-->
<!--<name>spring-releases</name>-->
<!--<name>Spring Releases</name>-->
<!--<url>https://repo.spring.io/libs-release</url>-->
<!--</repository>-->
<!--</repositories>-->
<!--<pluginRepositories>-->
<!--<pluginRepository>-->
<!--<name>spring-releases</name>-->
<!--<name>Spring Releases</name>-->
<!--<url>https://repo.spring.io/libs-release</url>-->
<!--</pluginRepository>-->
<!--</pluginRepositories>-->


</project>
75 changes: 14 additions & 61 deletions src/main/java/ru/holyway/botplatform/config/BotConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ru.holyway.botplatform.config;

import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.ssl.TrustStrategy;
import org.apache.hc.core5.util.Timeout;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -32,13 +31,6 @@
import ru.holyway.botplatform.security.AnonymousChatTokenSecurityFilter;
import ru.holyway.botplatform.telegram.TelegramBot;

import javax.net.ssl.SSLContext;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -49,18 +41,6 @@ public class BotConfiguration {
@Value("${bot.config.datatype}")
private String dataType;

@Value("${proxy.config.host}")
private String proxyHost;

@Value("${proxy.config.port}")
private String proxyPort;

@Value("${proxy.config.user}")
private String proxyUser;

@Value("${proxy.config.pass}")
private String proxyPass;

@Value("${instaprovider.url}")
private String instaproviderUrl;

Expand Down Expand Up @@ -116,72 +96,45 @@ public TaskScheduler scriptScheduler() {
return new ConcurrentTaskScheduler();
}

private static final int CONNECT_TIMEOUT_MS = 10_000;
private static final int READ_TIMEOUT_MS = 30_000;

@Bean
@Primary
public RestTemplate restTemplate()
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
public RestTemplate restTemplate() {
HttpComponentsClientHttpRequestFactory requestFactory = buildRequestFactory();
return new RestTemplate(requestFactory);
}

@NotNull
private HttpComponentsClientHttpRequestFactory buildRequestFactory()
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
private HttpComponentsClientHttpRequestFactory buildRequestFactory() {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(Timeout.ofMilliseconds(CONNECT_TIMEOUT_MS))
.setResponseTimeout(Timeout.ofMilliseconds(READ_TIMEOUT_MS))
.build();

CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
.setSslContext(sslContext)
.build())
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create().build())
.build())
.build();

HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
requestFactory.setConnectTimeout(CONNECT_TIMEOUT_MS);
return requestFactory;
}

@Bean("instaproviderTemplate")
public RestTemplate instaproviderTemplate()
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
public RestTemplate instaproviderTemplate() {
HttpComponentsClientHttpRequestFactory requestFactory = buildRequestFactory();
RestTemplate template = new RestTemplate(requestFactory);
template.setUriTemplateHandler(new DefaultUriBuilderFactory(instaproviderUrl));
return template;
}

private void setProxy(final String host, final String port, final String user,
final String pass) {
System.setProperty("socksProxyHost", host);
System.setProperty("socksProxyPort", port);
if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(pass)) {
System.setProperty("java.net.socks.username", user);
System.setProperty("java.net.socks.password", pass);
}

Authenticator.setDefault(new ProxyAuth(user, pass));
}

public static class ProxyAuth extends Authenticator {

private PasswordAuthentication auth;

private ProxyAuth(String user, String password) {
auth = new PasswordAuthentication(user,
password == null ? new char[]{} : password.toCharArray());
}

protected PasswordAuthentication getPasswordAuthentication() {
return auth;
}
}

@Bean
public RetryTemplate retryTemplate() {
RetryTemplate retryTemplate = new RetryTemplate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.holyway.botplatform.core.data;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import ru.holyway.botplatform.core.entity.Chat;
Expand All @@ -15,6 +17,8 @@
*/
public class MongoDataHelper implements DataHelper {

private static final Logger LOGGER = LoggerFactory.getLogger(MongoDataHelper.class);

private JSettings settings;

@Autowired
Expand Down Expand Up @@ -61,6 +65,7 @@ public List<String> getSimple() {
try {
return simpleRepository.findById("1").map(s -> s.dictionary).orElse(new ArrayList<>());
} catch (Exception e) {
LOGGER.error("Error loading simple dictionary", e);
return new ArrayList<>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public synchronized void init() {
list2Easy.clear();
dictionarySize.clear();

Map<String, List<String>> learnWords = null;
Map<String, List<String>> learnWords;

List<String> simpleWords = null;
List<String> simpleWords;
try {
learnWords = dataHelper.getLearn();
simpleWords = dataHelper.getSimple();

} catch (Exception e) {
LOGGER.error("Error loading learning data", e);
return;
}
for (Map.Entry<String, List<String>> line : learnWords.entrySet()) {
final List<List<String>> tokenizedAnswers = new ArrayList<>();
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/ru/holyway/botplatform/core/entity/JSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
public class JSettings {

private final static Map<String, UserAccessInfo> userTokens = new ConcurrentHashMap<>();
@Id
public String id;
private Set<String> muteChats;
Expand Down Expand Up @@ -170,26 +169,6 @@ public String generateNewToken(final String chatId) {
return token;
}

public String getUserToken(final String chatId, final String login, final String userName) {
for (Map.Entry<String, UserAccessInfo> userAccessInfo : userTokens.entrySet()) {
if (userAccessInfo.getValue().getChatId().equals(chatId) && userAccessInfo.getValue()
.getUserLogin().equals(login)) {
if (userAccessInfo.getValue().getExpirationTime() > System.currentTimeMillis()) {
return userAccessInfo.getKey();
}
}
}

final String token = UUID.randomUUID().toString().replace("-", "");
userTokens.put(token, new UserAccessInfo(userName, login, chatId));

return token;
}

public UserAccessInfo getUserAccessInfo(final String token) {
return userTokens.get(token);
}

public Set<String> getMuteChats() {
return muteChats;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import ru.holyway.botplatform.scripting.util.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

Expand All @@ -27,7 +26,9 @@ public final class DefaultShellRules {
BytecodeSequence.class);

public static final String[] starImportsWhiteArray =
new String[]{"ru.holyway"};
new String[]{
"ru.holyway.botplatform.scripting.entity",
"ru.holyway.botplatform.scripting.util"};

public static final List<String> starImportsWhitelist = Arrays.asList(starImportsWhiteArray);

Expand Down Expand Up @@ -72,9 +73,19 @@ public final class DefaultShellRules {
ParseMode.class.getName());

public static final List<String> receiversBlackList =
Collections.singletonList(Thread.class.getName());
Arrays.asList(
Thread.class.getName(),
Runtime.class.getName(),
ProcessBuilder.class.getName(),
System.class.getName(),
Class.class.getName(),
ClassLoader.class.getName());

public static List<String> methodsBlacklist = Arrays.asList("getClass", "class", "forName",
"wait", "notify", "notifyAll", "invokeMethod", "finalize", "sleep", "exit");
"wait", "notify", "notifyAll", "invokeMethod", "finalize", "sleep", "exit",
"exec", "getRuntime", "halt", "load", "loadLibrary", "addShutdownHook",
"newInstance", "getMethod", "getDeclaredMethod", "getField", "getDeclaredField",
"setAccessible", "getMetaClass", "setMetaClass", "define", "defineClass",
"evaluate", "getClassLoader");

}
Loading
Loading