diff --git a/Clover/app/src/main/java/org/floens/chan/Chan.java b/Clover/app/src/main/java/org/floens/chan/Chan.java
index 408342c5b..cc95aebc5 100644
--- a/Clover/app/src/main/java/org/floens/chan/Chan.java
+++ b/Clover/app/src/main/java/org/floens/chan/Chan.java
@@ -24,6 +24,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
+import android.webkit.WebSettings;
import org.codejargon.feather.Feather;
import org.floens.chan.core.database.DatabaseManager;
@@ -184,7 +185,12 @@ public ForegroundChangedMessage(boolean inForeground) {
}
private String createUserAgent() {
- return ChanSettings.customUserAgent.get();
+ String customUserAgent = ChanSettings.customUserAgent.get();
+ if (!customUserAgent.isEmpty()) {
+ return customUserAgent;
+ } else {
+ return WebSettings.getDefaultUserAgent(this);
+ }
}
public RuntimePermissionsHelper getRuntimePermissionsHelper() {
diff --git a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
index 778680646..5d948b3c6 100644
--- a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
+++ b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
@@ -200,7 +200,6 @@ public int getBitmask() {
public static final BooleanSetting dnsOverHttps;
public static final StringSetting customUserAgent;
- public static final StringSetting customUserAgentWebView;
public static final StringSetting customCFClearanceCommand;
static {
@@ -300,8 +299,7 @@ public int getBitmask() {
dnsOverHttps = new BooleanSetting(p, "dns_over_https", false);
- customUserAgent = new StringSetting(p, "custom_user_agent", "Kuroba-dev/v4.13.6-1d48096");
- customUserAgentWebView = new StringSetting(p, "custom_user_agent_webview", "");
+ customUserAgent = new StringSetting(p, "custom_user_agent", "");
customCFClearanceCommand = new StringSetting(p, "custom_cfclearance_command", "");
// Old (but possibly still in some users phone)
diff --git a/Clover/app/src/main/java/org/floens/chan/core/site/common/CommonReplyHttpCall.java b/Clover/app/src/main/java/org/floens/chan/core/site/common/CommonReplyHttpCall.java
index 9f2176dda..f4ac11903 100644
--- a/Clover/app/src/main/java/org/floens/chan/core/site/common/CommonReplyHttpCall.java
+++ b/Clover/app/src/main/java/org/floens/chan/core/site/common/CommonReplyHttpCall.java
@@ -27,7 +27,9 @@
import org.jsoup.Jsoup;
import java.io.IOException;
+import java.util.Locale;
import java.util.Random;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -51,6 +53,12 @@ public CommonReplyHttpCall(Site site, Reply reply) {
this.reply = reply;
}
+ private static String generateHttpBoundary() {
+ // this shouldn't be here but I'm not going to waste more time on
+ // an app that will be completely dead before the end of the year
+ return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(Locale.ENGLISH).substring(0, 16);
+ }
+
@Override
public void setup(
Request.Builder requestBuilder,
@@ -58,7 +66,8 @@ public void setup(
) {
replyResponse.password = Long.toHexString(RANDOM.nextLong());
- MultipartBody.Builder formBuilder = new MultipartBody.Builder();
+ String boundary = "------WebKitFormBoundary" + generateHttpBoundary();
+ MultipartBody.Builder formBuilder = new MultipartBody.Builder(boundary);
formBuilder.setType(MultipartBody.FORM);
addParameters(formBuilder, progressListener);
diff --git a/Clover/app/src/main/java/org/floens/chan/core/site/sites/chan4/Chan4.java b/Clover/app/src/main/java/org/floens/chan/core/site/sites/chan4/Chan4.java
index 8a6f6c036..47489d486 100644
--- a/Clover/app/src/main/java/org/floens/chan/core/site/sites/chan4/Chan4.java
+++ b/Clover/app/src/main/java/org/floens/chan/core/site/sites/chan4/Chan4.java
@@ -17,6 +17,7 @@
*/
package org.floens.chan.core.site.sites.chan4;
+import android.webkit.CookieManager;
import android.webkit.WebView;
import androidx.annotation.Nullable;
@@ -295,7 +296,23 @@ public HttpUrl report(Post post) {
private SiteRequestModifier siteRequestModifier = new SiteRequestModifier() {
@Override
- public void modifyHttpCall(HttpCall httpCall, Request.Builder requestBuilder) { }
+ public void modifyHttpCall(HttpCall httpCall, Request.Builder requestBuilder) {
+ requestBuilder.addHeader("Host", "sys.4chan.org");
+ requestBuilder.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
+ requestBuilder.addHeader("Accept-Language", "en-US,en;q=0.5");
+ requestBuilder.addHeader("Accept-Encoding", "identity");
+ requestBuilder.addHeader("Origin", "https://boards.4chan.org");
+ requestBuilder.addHeader("Connection", "Keep-Alive");
+ requestBuilder.addHeader("Referer", "https://boards.4chan.org/");
+ String cookies = CookieManager.getInstance().getCookie("https://sys.4chan.org");
+ if (cookies != null) {
+ requestBuilder.addHeader("Cookie", cookies);
+ }
+ requestBuilder.addHeader("Sec-Fetch-Dest", "document");
+ requestBuilder.addHeader("Sec-Fetch-Mode", "navigate");
+ requestBuilder.addHeader("Sec-Fetch-Site", "same-site");
+ requestBuilder.addHeader("Sec-Fetch-User", "?1");
+ }
@Override
public void modifyWebView(WebView webView) { }
diff --git a/Clover/app/src/main/java/org/floens/chan/ui/captcha/NewCaptchaLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/captcha/NewCaptchaLayout.java
index 8a7e24075..840036266 100644
--- a/Clover/app/src/main/java/org/floens/chan/ui/captcha/NewCaptchaLayout.java
+++ b/Clover/app/src/main/java/org/floens/chan/ui/captcha/NewCaptchaLayout.java
@@ -92,7 +92,7 @@ public void initialize(Loadable loadable, AuthenticationLayoutCallback callback)
WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true);
- String userAgent = ChanSettings.customUserAgentWebView.get();
+ String userAgent = ChanSettings.customUserAgent.get();
if (!userAgent.isEmpty()) {
settings.setUserAgentString(userAgent);
}
diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java
index 7bbcb05e8..c41f83b90 100644
--- a/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java
+++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java
@@ -189,8 +189,6 @@ private void populatePreferences() {
ua.add(new StringSettingView(this, ChanSettings.customUserAgent,
R.string.setting_group_user_agent_ua, R.string.setting_group_user_agent_ua));
- ua.add(new StringSettingView(this, ChanSettings.customUserAgentWebView,
- R.string.setting_group_user_agent_ua_webview, R.string.setting_group_user_agent_ua_webview));
if (BuildConfig.FLAVOR.equals("dev")) {
// please see the note about this setting in NewCaptchaLayout
ua.add(new StringSettingView(this, ChanSettings.customCFClearanceCommand,
diff --git a/Clover/app/src/main/res/values/strings.xml b/Clover/app/src/main/res/values/strings.xml
index 6a403e8d9..4f8b5f568 100644
--- a/Clover/app/src/main/res/values/strings.xml
+++ b/Clover/app/src/main/res/values/strings.xml
@@ -520,8 +520,7 @@ Crash reports do not collect any personally identifiable information."
Custom User-Agent
- User-Agent for posting
- User-Agent for WebViews (empty for default)
+ Custom User-Agent (empty for system default, requires restart)
[DEBUG] Shell command to set cf_clearance