mirror of https://github.com/M66B/NetGuard.git
Show resolved domain names (debug version only)
This commit is contained in:
parent
c5315926d3
commit
5a63c34938
|
@ -75,6 +75,16 @@
|
|||
android:value=".ActivityMain" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ActivityDns"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/setting_show_resolved"
|
||||
android:parentActivityName=".ActivitySettings">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ActivitySettings" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ActivityForwarding"
|
||||
android:configChanges="orientation|screenSize"
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package eu.faircode.netguard;
|
||||
|
||||
/*
|
||||
This file is part of NetGuard.
|
||||
|
||||
NetGuard is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2015-2016 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FilterQueryProvider;
|
||||
import android.widget.ListView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class ActivityDns extends AppCompatActivity {
|
||||
private static final String TAG = "NetGuard.DNS";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Util.setTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.resolving);
|
||||
|
||||
getSupportActionBar().setTitle(R.string.setting_show_resolved);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
ListView lvDns = (ListView) findViewById(R.id.lvDns);
|
||||
lvDns.setAdapter(new DnsAdapter(this, DatabaseHelper.getInstance(this).getDns()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
|
@ -126,6 +126,10 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
PreferenceCategory cat_advanced = (PreferenceCategory) screen.findPreference("category_advanced_options");
|
||||
PreferenceCategory cat_backup = (PreferenceCategory) screen.findPreference("category_backup");
|
||||
PreferenceCategory cat_development = (PreferenceCategory) screen.findPreference("category_development");
|
||||
|
||||
// Handle auto enable
|
||||
Preference pref_auto_enable = screen.findPreference("auto_enable");
|
||||
pref_auto_enable.setTitle(getString(R.string.setting_auto, prefs.getString("auto_enable", "0")));
|
||||
|
@ -163,10 +167,20 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
pref_wifi_homes.setEntryValues(listSSID.toArray(new CharSequence[0]));
|
||||
|
||||
// Filtering always enabled
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
PreferenceCategory options = (PreferenceCategory) screen.findPreference("category_advanced_options");
|
||||
options.removePreference(screen.findPreference("filter"));
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
||||
cat_advanced.removePreference(screen.findPreference("filter"));
|
||||
|
||||
// Show resolved
|
||||
Preference pref_show_resolved = screen.findPreference("show_resolved");
|
||||
if (!Util.isDebuggable(this))
|
||||
cat_advanced.removePreference(pref_show_resolved);
|
||||
pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
startActivity(new Intent(ActivitySettings.this, ActivityDns.class));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Handle port forwarding
|
||||
Preference pref_forwarding = screen.findPreference("forwarding");
|
||||
|
@ -223,13 +237,10 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
final Preference pref_hosts_download = screen.findPreference("hosts_download");
|
||||
|
||||
if (Util.isPlayStoreInstall(this)) {
|
||||
PreferenceCategory pref_category = (PreferenceCategory) screen.findPreference("category_advanced_options");
|
||||
pref_category.removePreference(pref_block_domains);
|
||||
|
||||
PreferenceCategory pref_backup = (PreferenceCategory) screen.findPreference("category_backup");
|
||||
pref_backup.removePreference(pref_hosts_import);
|
||||
pref_backup.removePreference(pref_hosts_url);
|
||||
pref_backup.removePreference(pref_hosts_download);
|
||||
cat_advanced.removePreference(pref_block_domains);
|
||||
cat_backup.removePreference(pref_hosts_import);
|
||||
cat_backup.removePreference(pref_hosts_url);
|
||||
cat_backup.removePreference(pref_hosts_download);
|
||||
|
||||
} else {
|
||||
pref_block_domains.setEnabled(new File(getFilesDir(), "hosts.txt").exists());
|
||||
|
@ -305,7 +316,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
|||
|
||||
// Development
|
||||
if (!(Util.isDebuggable(this) || Util.getSelfVersionName(this).contains("beta"))) {
|
||||
screen.removePreference(screen.findPreference("category_development"));
|
||||
screen.removePreference(cat_development);
|
||||
prefs.edit().remove("loglevel").apply();
|
||||
}
|
||||
|
||||
|
|
|
@ -606,6 +606,19 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public Cursor getDns() {
|
||||
mLock.readLock().lock();
|
||||
try {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
String query = "SELECT ID AS _id, *";
|
||||
query += " FROM dns";
|
||||
query += " ORDER BY qname";
|
||||
return db.rawQuery(query, new String[]{});
|
||||
} finally {
|
||||
mLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Cursor getAccessDns() {
|
||||
mLock.readLock().lock();
|
||||
try {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package eu.faircode.netguard;
|
||||
|
||||
/*
|
||||
This file is part of NetGuard.
|
||||
|
||||
NetGuard is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NetGuard is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2015-2016 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class DnsAdapter extends CursorAdapter {
|
||||
private static String TAG = "NetGuard.DNS";
|
||||
|
||||
private int colTime;
|
||||
private int colQName;
|
||||
private int colAName;
|
||||
private int colResource;
|
||||
private int colTTL;
|
||||
|
||||
public DnsAdapter(Context context, Cursor cursor) {
|
||||
super(context, cursor, 0);
|
||||
colTime = cursor.getColumnIndex("time");
|
||||
colQName = cursor.getColumnIndex("qname");
|
||||
colAName = cursor.getColumnIndex("aname");
|
||||
colResource = cursor.getColumnIndex("resource");
|
||||
colTTL = cursor.getColumnIndex("ttl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
return LayoutInflater.from(context).inflate(R.layout.dns, parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(final View view, final Context context, final Cursor cursor) {
|
||||
// Get values
|
||||
long time = cursor.getLong(colTime);
|
||||
String qname = cursor.getString(colQName);
|
||||
String aname = cursor.getString(colAName);
|
||||
String resource = cursor.getString(colResource);
|
||||
int ttl = cursor.getInt(colTTL);
|
||||
|
||||
// Get views
|
||||
TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
|
||||
TextView tvQName = (TextView) view.findViewById(R.id.tvQName);
|
||||
TextView tvAName = (TextView) view.findViewById(R.id.tvAName);
|
||||
TextView tvResource = (TextView) view.findViewById(R.id.tvResource);
|
||||
TextView tvTTL = (TextView) view.findViewById(R.id.tvTTL);
|
||||
|
||||
// Set values
|
||||
tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
|
||||
tvQName.setText(qname);
|
||||
tvAName.setText(aname);
|
||||
tvResource.setText(resource);
|
||||
tvTTL.setText(Integer.toString(ttl));
|
||||
}
|
||||
}
|
|
@ -983,7 +983,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
private void prepareUidIPFilters() {
|
||||
Map<Long, Map<InetAddress, Boolean>> map = new HashMap<>();
|
||||
|
||||
Cursor cursor = DatabaseHelper.getInstance(SinkholeService.this).getDns();
|
||||
Cursor cursor = DatabaseHelper.getInstance(SinkholeService.this).getAccessDns();
|
||||
int colUid = cursor.getColumnIndex("uid");
|
||||
int colVersion = cursor.getColumnIndex("version");
|
||||
int colProtocol = cursor.getColumnIndex("protocol");
|
||||
|
@ -1017,8 +1017,12 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
if (dresource == null) {
|
||||
if (Util.isNumericAddress(daddr))
|
||||
map.get(key).put(InetAddress.getByName(daddr), block);
|
||||
} else
|
||||
map.get(key).put(InetAddress.getByName(dresource), block);
|
||||
} else {
|
||||
if (Util.isNumericAddress(dresource))
|
||||
map.get(key).put(InetAddress.getByName(dresource), block);
|
||||
else
|
||||
Log.w(TAG, "Address not numeric " + daddr);
|
||||
}
|
||||
} catch (UnknownHostException ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
|
@ -1040,7 +1044,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
// This will result in native callbacks
|
||||
InetAddress.getAllByName(daddr);
|
||||
} catch (UnknownHostException ex) {
|
||||
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
Log.w(TAG, "Update " + ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
|
@ -1221,7 +1225,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
Log.i(TAG, "Filtering " + packet);
|
||||
}
|
||||
} catch (UnknownHostException ex) {
|
||||
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
Log.w(TAG, "Allowed " + ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
tools:context=".ActivityMain">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTime"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvQName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@style/TextSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAName"
|
||||
android:layout_width="72dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:textAppearance="@style/TextSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvResource"
|
||||
android:layout_width="72dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:textAppearance="@style/TextSmall" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTTL"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:gravity="end|right"
|
||||
android:textAppearance="@style/TextSmall" />
|
||||
</LinearLayout>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingEnd="@dimen/activity_horizontal_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingStart="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/lvDns"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarStyle="insideOverlay"
|
||||
android:scrollbars="vertical" />
|
||||
</RelativeLayout>
|
|
@ -73,6 +73,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
|
|||
<string name="setting_access">Notify on internet access</string>
|
||||
<string name="setting_filter">Filter traffic</string>
|
||||
<string name="setting_resolved">Store resolved domain names</string>
|
||||
<string name="setting_show_resolved" translatable="false">Show resolved domain names</string>
|
||||
<string name="setting_block_domains">Block domain names</string>
|
||||
<string name="setting_forwarding">Port forwarding</string>
|
||||
<string name="setting_vpn4">VPN IPv4: %s</string>
|
||||
|
|
|
@ -118,6 +118,9 @@
|
|||
android:key="resolved"
|
||||
android:summary="@string/summary_resolved"
|
||||
android:title="@string/setting_resolved" />
|
||||
<Preference
|
||||
android:key="show_resolved"
|
||||
android:title="@string/setting_show_resolved" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:dependency="filter"
|
||||
|
|
|
@ -118,6 +118,9 @@
|
|||
android:key="resolved"
|
||||
android:summary="@string/summary_resolved"
|
||||
android:title="@string/setting_resolved" />
|
||||
<Preference
|
||||
android:key="show_resolved"
|
||||
android:title="@string/setting_show_resolved" />
|
||||
<eu.faircode.netguard.SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:dependency="filter"
|
||||
|
|
Loading…
Reference in New Issue