Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nnuudev committed Feb 8, 2024
1 parent b860695 commit ab8f238
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
8 changes: 7 additions & 1 deletion Clover/app/src/main/java/org/floens/chan/Chan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -51,14 +53,21 @@ 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,
@Nullable ProgressRequestBody.ProgressRequestListener progressListener
) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.floens.chan.core.site.sites.chan4;

import android.webkit.CookieManager;
import android.webkit.WebView;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -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) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions Clover/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ Crash reports do not collect any personally identifiable information."

<!-- Custom User-Agent group -->
<string name="setting_group_user_agent">Custom User-Agent</string>
<string name="setting_group_user_agent_ua">User-Agent for posting</string>
<string name="setting_group_user_agent_ua_webview">User-Agent for WebViews (empty for default)</string>
<string name="setting_group_user_agent_ua">Custom User-Agent (empty for system default, requires restart)</string>
<string name="setting_group_user_agent_cfcommand">[DEBUG] Shell command to set cf_clearance</string>

<!-- Media -->
Expand Down

0 comments on commit ab8f238

Please sign in to comment.