Added log export
This commit is contained in:
parent
9c1f09a50e
commit
d9e80b394a
@ -24,7 +24,7 @@ import org.itxtech.daedalus.service.DaedalusVpnService;
|
|||||||
import org.itxtech.daedalus.util.Configurations;
|
import org.itxtech.daedalus.util.Configurations;
|
||||||
import org.itxtech.daedalus.util.Logger;
|
import org.itxtech.daedalus.util.Logger;
|
||||||
import org.itxtech.daedalus.util.Rule;
|
import org.itxtech.daedalus.util.Rule;
|
||||||
import org.itxtech.daedalus.util.RulesResolver;
|
import org.itxtech.daedalus.util.RuleResolver;
|
||||||
import org.itxtech.daedalus.util.server.DNSServer;
|
import org.itxtech.daedalus.util.server.DNSServer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -95,7 +95,8 @@ public class Daedalus extends Application {
|
|||||||
|
|
||||||
public static Configurations configurations;
|
public static Configurations configurations;
|
||||||
|
|
||||||
public static String rulesPath = null;
|
public static String rulePath = null;
|
||||||
|
public static String logPath = null;
|
||||||
private static String configPath = null;
|
private static String configPath = null;
|
||||||
|
|
||||||
private static Daedalus instance = null;
|
private static Daedalus instance = null;
|
||||||
@ -110,27 +111,33 @@ public class Daedalus extends Application {
|
|||||||
|
|
||||||
Logger.init();
|
Logger.init();
|
||||||
|
|
||||||
mResolver = new Thread(new RulesResolver());
|
mResolver = new Thread(new RuleResolver());
|
||||||
mResolver.start();
|
mResolver.start();
|
||||||
|
|
||||||
initData();
|
initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initDirectory(String dir){
|
||||||
|
File directory = new File(dir);
|
||||||
|
if (!directory.isDirectory()) {
|
||||||
|
Logger.warning(dir + " is not a directory. Delete result: " + String.valueOf(directory.delete()));
|
||||||
|
}
|
||||||
|
if (!directory.exists()) {
|
||||||
|
Logger.debug(dir + " does not exist. Create result: " + String.valueOf(directory.mkdirs()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initData() {
|
private void initData() {
|
||||||
PreferenceManager.setDefaultValues(this, R.xml.perf_settings, false);
|
PreferenceManager.setDefaultValues(this, R.xml.perf_settings, false);
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
if (getExternalFilesDir(null) != null) {
|
if (getExternalFilesDir(null) != null) {
|
||||||
rulesPath = getExternalFilesDir(null).getPath() + "/rules/";
|
rulePath = getExternalFilesDir(null).getPath() + "/rules/";
|
||||||
|
logPath = getExternalFilesDir(null).getPath() + "/logs/";
|
||||||
configPath = getExternalFilesDir(null).getPath() + "/config.json";
|
configPath = getExternalFilesDir(null).getPath() + "/config.json";
|
||||||
|
|
||||||
File configDir = new File(rulesPath);
|
initDirectory(rulePath);
|
||||||
if (!configDir.isDirectory()) {
|
initDirectory(logPath);
|
||||||
Logger.warning("Configuration directory is not a directory. Delete result: " + String.valueOf(configDir.delete()));
|
|
||||||
}
|
|
||||||
if (!configDir.exists()) {
|
|
||||||
Logger.debug("Configuration directory does not exist. Create result: " + String.valueOf(configDir.mkdirs()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configPath != null) {
|
if (configPath != null) {
|
||||||
@ -153,7 +160,7 @@ public class Daedalus extends Application {
|
|||||||
if (usingRules != null && usingRules.size() > 0) {
|
if (usingRules != null && usingRules.size() > 0) {
|
||||||
for (Rule rule : usingRules) {
|
for (Rule rule : usingRules) {
|
||||||
if (rule.isUsing()) {
|
if (rule.isUsing()) {
|
||||||
pendingLoad.add(rulesPath + rule.getFileName());
|
pendingLoad.add(rulePath + rule.getFileName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pendingLoad.size() > 0) {
|
if (pendingLoad.size() > 0) {
|
||||||
@ -161,10 +168,10 @@ public class Daedalus extends Application {
|
|||||||
pendingLoad.toArray(arr);
|
pendingLoad.toArray(arr);
|
||||||
switch (usingRules.get(0).getType()) {
|
switch (usingRules.get(0).getType()) {
|
||||||
case Rule.TYPE_HOSTS:
|
case Rule.TYPE_HOSTS:
|
||||||
RulesResolver.startLoadHosts(arr);
|
RuleResolver.startLoadHosts(arr);
|
||||||
break;
|
break;
|
||||||
case Rule.TYPE_DNAMASQ:
|
case Rule.TYPE_DNAMASQ:
|
||||||
RulesResolver.startLoadDnsmasq(arr);
|
RuleResolver.startLoadDnsmasq(arr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,9 +197,9 @@ public class Daedalus extends Application {
|
|||||||
|
|
||||||
instance = null;
|
instance = null;
|
||||||
prefs = null;
|
prefs = null;
|
||||||
RulesResolver.shutdown();
|
RuleResolver.shutdown();
|
||||||
mResolver.interrupt();
|
mResolver.interrupt();
|
||||||
RulesResolver.clear();
|
RuleResolver.clear();
|
||||||
mResolver = null;
|
mResolver = null;
|
||||||
Logger.shutdown();
|
Logger.shutdown();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
package org.itxtech.daedalus.fragment;
|
package org.itxtech.daedalus.fragment;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import org.itxtech.daedalus.Daedalus;
|
||||||
import org.itxtech.daedalus.R;
|
import org.itxtech.daedalus.R;
|
||||||
import org.itxtech.daedalus.util.Logger;
|
import org.itxtech.daedalus.util.Logger;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Daedalus Project
|
* Daedalus Project
|
||||||
*
|
*
|
||||||
@ -38,6 +42,19 @@ public class LogFragment extends ToolbarFragment implements Toolbar.OnMenuItemCl
|
|||||||
((TextView) getView().findViewById(R.id.textView_log)).setText(Logger.getLog());
|
((TextView) getView().findViewById(R.id.textView_log)).setText(Logger.getLog());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void export() {
|
||||||
|
try {
|
||||||
|
String file = Daedalus.logPath + String.valueOf(System.currentTimeMillis()) + ".log";
|
||||||
|
FileWriter fileWriter = new FileWriter(file);
|
||||||
|
fileWriter.write(Logger.getLog());
|
||||||
|
fileWriter.close();
|
||||||
|
Snackbar.make(getView(), getString(R.string.notice_export_complete) + file, Snackbar.LENGTH_SHORT)
|
||||||
|
.setAction("Action", null).show();
|
||||||
|
} catch (Throwable e){
|
||||||
|
Logger.logException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkStatus() {
|
public void checkStatus() {
|
||||||
menu.findItem(R.id.nav_log).setChecked(true);
|
menu.findItem(R.id.nav_log).setChecked(true);
|
||||||
@ -58,6 +75,9 @@ public class LogFragment extends ToolbarFragment implements Toolbar.OnMenuItemCl
|
|||||||
case R.id.action_refresh:
|
case R.id.action_refresh:
|
||||||
refresh();
|
refresh();
|
||||||
break;
|
break;
|
||||||
|
case R.id.action_export:
|
||||||
|
export();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -313,7 +313,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
case MSG_RULE_DOWNLOADED:
|
case MSG_RULE_DOWNLOADED:
|
||||||
try {
|
try {
|
||||||
RuleData ruleData = (RuleData) msg.obj;
|
RuleData ruleData = (RuleData) msg.obj;
|
||||||
File file = new File(Daedalus.rulesPath + ruleData.getFilename());
|
File file = new File(Daedalus.rulePath + ruleData.getFilename());
|
||||||
FileOutputStream stream = new FileOutputStream(file);
|
FileOutputStream stream = new FileOutputStream(file);
|
||||||
stream.write(ruleData.getData().getBytes());
|
stream.write(ruleData.getData().getBytes());
|
||||||
stream.close();
|
stream.close();
|
||||||
|
@ -178,7 +178,7 @@ public class RulesFragment extends ToolbarFragment implements Toolbar.OnMenuItem
|
|||||||
holder.textViewName.setText(rule.getName());
|
holder.textViewName.setText(rule.getName());
|
||||||
holder.textViewAddress.setText(rule.getFileName());
|
holder.textViewAddress.setText(rule.getFileName());
|
||||||
|
|
||||||
File file = new File(Daedalus.rulesPath + rule.getFileName());
|
File file = new File(Daedalus.rulePath + rule.getFileName());
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
builder.append(new DecimalFormat("0.00").format(((float) file.length() / 1024)));
|
builder.append(new DecimalFormat("0.00").format(((float) file.length() / 1024)));
|
||||||
|
@ -13,7 +13,7 @@ import de.measite.minidns.record.A;
|
|||||||
import de.measite.minidns.record.AAAA;
|
import de.measite.minidns.record.AAAA;
|
||||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||||
import org.itxtech.daedalus.util.Logger;
|
import org.itxtech.daedalus.util.Logger;
|
||||||
import org.itxtech.daedalus.util.RulesResolver;
|
import org.itxtech.daedalus.util.RuleResolver;
|
||||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||||
import org.pcap4j.packet.*;
|
import org.pcap4j.packet.*;
|
||||||
import org.pcap4j.packet.factory.PacketFactoryPropertiesLoader;
|
import org.pcap4j.packet.factory.PacketFactoryPropertiesLoader;
|
||||||
@ -348,7 +348,7 @@ public class UdpProvider extends Provider {
|
|||||||
String dnsQueryName = dnsMsg.getQuestion().name.toString();
|
String dnsQueryName = dnsMsg.getQuestion().name.toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String response = RulesResolver.resolve(dnsQueryName, dnsMsg.getQuestion().type);
|
String response = RuleResolver.resolve(dnsQueryName, dnsMsg.getQuestion().type);
|
||||||
if (response != null && dnsMsg.getQuestion().type == Record.TYPE.A) {
|
if (response != null && dnsMsg.getQuestion().type == Record.TYPE.A) {
|
||||||
Logger.info("Provider: Resolved " + dnsQueryName + " Local resolver response: " + response);
|
Logger.info("Provider: Resolved " + dnsQueryName + " Local resolver response: " + response);
|
||||||
DNSMessage.Builder builder = dnsMsg.asBuilder();
|
DNSMessage.Builder builder = dnsMsg.asBuilder();
|
||||||
|
@ -20,7 +20,7 @@ import org.itxtech.daedalus.provider.TcpProvider;
|
|||||||
import org.itxtech.daedalus.provider.UdpProvider;
|
import org.itxtech.daedalus.provider.UdpProvider;
|
||||||
import org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver;
|
import org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver;
|
||||||
import org.itxtech.daedalus.util.Logger;
|
import org.itxtech.daedalus.util.Logger;
|
||||||
import org.itxtech.daedalus.util.RulesResolver;
|
import org.itxtech.daedalus.util.RuleResolver;
|
||||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
@ -160,7 +160,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
|||||||
stopSelf();
|
stopSelf();
|
||||||
|
|
||||||
if (shouldRefresh) {
|
if (shouldRefresh) {
|
||||||
RulesResolver.clear();
|
RuleResolver.clear();
|
||||||
DNSServerHelper.clearPortCache();
|
DNSServerHelper.clearPortCache();
|
||||||
Logger.info("Daedalus VPN service has stopped");
|
Logger.info("Daedalus VPN service has stopped");
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,7 @@ public class Configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
|
Logger.info("Loading configuration failed. Generating default configurations.");
|
||||||
config = new Configurations();
|
config = new Configurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import java.util.HashMap;
|
|||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
public class RulesResolver implements Runnable {
|
public class RuleResolver implements Runnable {
|
||||||
|
|
||||||
public static final int STATUS_LOADED = 0;
|
public static final int STATUS_LOADED = 0;
|
||||||
public static final int STATUS_LOADING = 1;
|
public static final int STATUS_LOADING = 1;
|
||||||
@ -37,7 +37,7 @@ public class RulesResolver implements Runnable {
|
|||||||
private static HashMap<String, String> rulesAAAA;
|
private static HashMap<String, String> rulesAAAA;
|
||||||
private static boolean shutdown = false;
|
private static boolean shutdown = false;
|
||||||
|
|
||||||
public RulesResolver() {
|
public RuleResolver() {
|
||||||
status = STATUS_NOT_LOADED;
|
status = STATUS_NOT_LOADED;
|
||||||
hostsFiles = new String[0];
|
hostsFiles = new String[0];
|
||||||
dnsmasqFiles = new String[0];
|
dnsmasqFiles = new String[0];
|
9
app/src/main/res/drawable/ic_import_export.xml
Normal file
9
app/src/main/res/drawable/ic_import_export.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M9,3L5,6.99h3L8,14h2L10,6.99h3L9,3zM16,17.01L16,10h-2v7.01h-3L15,21l4,-3.99h-3z"/>
|
||||||
|
</vector>
|
@ -1,6 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item android:id="@+id/action_export"
|
||||||
|
android:title="@string/export"
|
||||||
|
android:icon="@drawable/ic_import_export"
|
||||||
|
android:alphabeticShortcut="e"
|
||||||
|
android:numericShortcut="0"
|
||||||
|
app:showAsAction="always"/>
|
||||||
<item android:id="@+id/action_delete"
|
<item android:id="@+id/action_delete"
|
||||||
android:title="@string/delete"
|
android:title="@string/delete"
|
||||||
android:icon="@drawable/ic_delete"
|
android:icon="@drawable/ic_delete"
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
<string name="settings_server_port">服务器端口</string>
|
<string name="settings_server_port">服务器端口</string>
|
||||||
<string name="delete">删除</string>
|
<string name="delete">删除</string>
|
||||||
<string name="apply">应用</string>
|
<string name="apply">应用</string>
|
||||||
|
<string name="export">导出</string>
|
||||||
<string name="notice_fill_in_all">请填写所有配置项。</string>
|
<string name="notice_fill_in_all">请填写所有配置项。</string>
|
||||||
<string name="settings_dns_over_tcp">DNS over TCP</string>
|
<string name="settings_dns_over_tcp">DNS over TCP</string>
|
||||||
<string name="action_removed">已移除。</string>
|
<string name="action_removed">已移除。</string>
|
||||||
@ -81,4 +82,5 @@
|
|||||||
<string name="settings_allow_dynamic_rule_reload">允许动态更新规则</string>
|
<string name="settings_allow_dynamic_rule_reload">允许动态更新规则</string>
|
||||||
<string name="action_reload">重新加载规则</string>
|
<string name="action_reload">重新加载规则</string>
|
||||||
<string name="notice_check_dynamic_rule_reload">请在设置中勾选“允许动态更新规则”</string>
|
<string name="notice_check_dynamic_rule_reload">请在设置中勾选“允许动态更新规则”</string>
|
||||||
|
<string name="notice_export_complete">导出完成。</string>
|
||||||
</resources>
|
</resources>
|
@ -56,6 +56,7 @@
|
|||||||
<string name="settings_server_port">伺服器埠</string>
|
<string name="settings_server_port">伺服器埠</string>
|
||||||
<string name="delete">刪除</string>
|
<string name="delete">刪除</string>
|
||||||
<string name="apply">套用</string>
|
<string name="apply">套用</string>
|
||||||
|
<string name="export">导出</string>
|
||||||
<string name="notice_fill_in_all">請填寫所有設定項。</string>
|
<string name="notice_fill_in_all">請填寫所有設定項。</string>
|
||||||
<string name="settings_dns_over_tcp">DNS over TCP</string>
|
<string name="settings_dns_over_tcp">DNS over TCP</string>
|
||||||
<string name="action_removed">已移除。</string>
|
<string name="action_removed">已移除。</string>
|
||||||
@ -81,4 +82,5 @@
|
|||||||
<string name="settings_allow_dynamic_rule_reload">允許動態規則重新載入</string>
|
<string name="settings_allow_dynamic_rule_reload">允許動態規則重新載入</string>
|
||||||
<string name="action_reload">重新載入</string>
|
<string name="action_reload">重新載入</string>
|
||||||
<string name="notice_check_dynamic_rule_reload">請在設定中開啟「允許動態規則重新載入」</string>
|
<string name="notice_check_dynamic_rule_reload">請在設定中開啟「允許動態規則重新載入」</string>
|
||||||
|
<string name="notice_export_complete">导出完成。</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
<string name="notice_delete_confirm_prompt">Are you sure you want to remove this configuration?</string>
|
<string name="notice_delete_confirm_prompt">Are you sure you want to remove this configuration?</string>
|
||||||
<string name="notice_after_stop">Please modify activated rules after stopping service.</string>
|
<string name="notice_after_stop">Please modify activated rules after stopping service.</string>
|
||||||
<string name="notice_check_dynamic_rule_reload">Please enable "Allow dynamic rule reload" in Settings</string>
|
<string name="notice_check_dynamic_rule_reload">Please enable "Allow dynamic rule reload" in Settings</string>
|
||||||
|
<string name="notice_export_complete">Export completed.</string>
|
||||||
|
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="action_about">About</string>
|
<string name="action_about">About</string>
|
||||||
@ -31,6 +32,7 @@
|
|||||||
|
|
||||||
<string name="delete">Delete</string>
|
<string name="delete">Delete</string>
|
||||||
<string name="apply">Apply</string>
|
<string name="apply">Apply</string>
|
||||||
|
<string name="export">Export</string>
|
||||||
|
|
||||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user