Skip to content

Commit

Permalink
NClientV2 2.9.9
Browse files Browse the repository at this point in the history
* Cloudflare should now be easier to solve
  • Loading branch information
Dar9586 committed Feb 28, 2023
1 parent f8a741c commit 72f9a4d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Expand Up @@ -7,9 +7,9 @@ android {
applicationId "com.dar.nclientv2"
minSdkVersion 14
targetSdkVersion 33
versionCode 298
versionCode 299
multiDexEnabled true
versionName "2.9.8-stable"
versionName "2.9.9-stable"
vectorDrawables.useSupportLibrary true
proguardFiles 'proguard-rules.pro'
}
Expand Down Expand Up @@ -52,14 +52,14 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.12.12'//Because of min SDK
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
//implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation 'org.jsoup:jsoup:1.15.3'
implementation 'org.jsoup:jsoup:1.15.4'
implementation 'ch.acra:acra-core:5.7.0'
implementation('com.github.bumptech.glide:glide:4.14.2') {
implementation('com.github.bumptech.glide:glide:4.15.0') {
exclude group: "com.android.support"
}
implementation "androidx.multidex:multidex:2.0.1"
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.15.0'
implementation 'com.github.yukuku:ambilwarna:2.0.1'
implementation 'me.zhanghai.android.fastscroll:library:1.2.0'

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/dar/nclientv2/LoginActivity.java
Expand Up @@ -3,7 +3,6 @@
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

Expand Down Expand Up @@ -42,9 +41,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUserAgentString(Global.getUserAgent());
webView.loadUrl(Utility.getBaseUrl() + "login/");
waiter = new CookieWaiter();
waiter.start();
Expand Down
Expand Up @@ -2,22 +2,18 @@

import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;

import androidx.annotation.NonNull;

import com.dar.nclientv2.components.activities.GeneralActivity;
import com.dar.nclientv2.components.views.CFTokenView;
import com.dar.nclientv2.settings.Global;
import com.dar.nclientv2.utility.LogUtility;
import com.dar.nclientv2.utility.Utility;

import java.util.HashMap;

public class CookieInterceptor {
private static volatile boolean intercepting = false;
private static final int MAX_RETRIES = 200;
private static volatile boolean webViewHidden = false;

public static void hideWebView() {
Expand All @@ -31,6 +27,7 @@ public static void hideWebView() {
@NonNull
private final Manager manager;
String cookies = null;
private CFTokenView web = null;

public CookieInterceptor(@NonNull Manager manager) {
this.manager = manager;
Expand All @@ -40,18 +37,14 @@ private CFTokenView setupWebView() {
CFTokenView tokenView = GeneralActivity.getLastCFView();
if (tokenView == null) return null;
tokenView.post(() -> {
WebView webView=tokenView.getWebView();
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUserAgentString(Global.getUserAgent());
CFTokenView.CFTokenWebView webView = tokenView.getWebView();
webView.loadUrl(Utility.getBaseUrl());
});
return tokenView;
}

@NonNull
private CFTokenView getWebView() {
CFTokenView web = setupWebView();
while (web == null) {
Utility.threadSleep(100);
web = setupWebView();
Expand All @@ -65,7 +58,6 @@ private void interceptInternal() {
web.post(() -> web.setVisibility(View.VISIBLE));
CookieManager manager = CookieManager.getInstance();
HashMap<String, String> cookiesMap = new HashMap<>();
int retryCount = 0;
do {
Utility.threadSleep(100);
cookies = manager.getCookie(Utility.getBaseUrl());
Expand All @@ -81,10 +73,6 @@ private void interceptInternal() {
}
}
}
retryCount += 1;
if (retryCount == MAX_RETRIES) {
return;
}
} while (!this.manager.endInterceptor());
web.post(() -> web.setVisibility(View.GONE));
}
Expand Down
@@ -1,10 +1,12 @@
package com.dar.nclientv2.components.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;

Expand All @@ -13,8 +15,7 @@

import com.dar.nclientv2.R;
import com.dar.nclientv2.components.CookieInterceptor;

import java.util.Date;
import com.dar.nclientv2.settings.Global;

public class CFTokenView {

Expand Down Expand Up @@ -47,8 +48,6 @@ public void post(Runnable o) {


public static class CFTokenWebView extends WebView{
private volatile long lastLoad=0;
private static final long MIN_TIME=5000;
public CFTokenWebView(@NonNull Context context) {
super(context);
init();
Expand All @@ -66,6 +65,7 @@ public CFTokenWebView(@NonNull Context context, @Nullable @org.jetbrains.annotat

private void init() {
forceAcceptCookies();
applyWebViewSettings();
}

private void forceAcceptCookies() {
Expand All @@ -75,16 +75,21 @@ private void forceAcceptCookies() {
}
}

@Override
public void loadUrl(@NonNull String url) {
long actualTime = new Date().getTime();
synchronized (this) {
if (lastLoad + MIN_TIME <= actualTime) {
lastLoad = actualTime;
super.loadUrl(url);
}
}
@SuppressLint("SetJavaScriptEnabled")
private void applyWebViewSettings() {
WebSettings webSettings = getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setUserAgentString(Global.getUserAgent());
}

}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/dar/nclientv2/settings/Global.java
Expand Up @@ -157,7 +157,7 @@ public static boolean isDestroyed(Activity activity) {
}

public static String getUserAgent() {
return "NClientV2 " + Global.getLastVersion(null);
return "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Mobile Safari/537.36";
}

public static String getDefaultFileParent(Context context) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_login.xml
Expand Up @@ -17,7 +17,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<WebView
<view class="com.dar.nclientv2.components.views.CFTokenView$CFTokenWebView"
android:id="@+id/webView"
android:layout_width="0dp"
android:layout_height="0dp"
Expand Down

0 comments on commit 72f9a4d

Please sign in to comment.