Commit 9d15feda authored by Daniel Wolf's avatar Daniel Wolf
Browse files

[WIP!] now using ORM

parent 79ed9800
......@@ -19,8 +19,6 @@ android {
}
debug{
initWith(buildTypes.debug)
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
......
......@@ -30,6 +30,7 @@ import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import com.frostnerd.dnschanger.database.entities.IPPortPair;
import com.frostnerd.dnschanger.fragments.RulesFragment;
import com.frostnerd.dnschanger.util.PreferencesAccessor;
import com.frostnerd.dnschanger.util.Util;
......@@ -584,18 +585,18 @@ public class MainActivity extends NavigationDrawerActivity {
public void openDefaultDNSDialog(View v) {
LogFactory.writeMessage(this, LOG_TAG, "Opening DefaultDNSDialog");
defaultDnsDialog = new DefaultDNSDialog(this, ThemeHandler.getDialogTheme(this), new DefaultDNSDialog.OnProviderSelectedListener(){
defaultDnsDialog = new DefaultDNSDialog(this, ThemeHandler.getDialogTheme(this), new DefaultDNSDialog.OnProviderSelectedListener() {
@Override
public void onProviderSelected(String name, String dns1, String dns2, String dns1V6, String dns2V6) {
public void onProviderSelected(String name, IPPortPair dns1, IPPortPair dns2, IPPortPair dns1V6, IPPortPair dns2V6) {
if(mainFragment.settingV6){
if(!dns1V6.equals(""))mainFragment.dns1.setText(dns1V6);
mainFragment.dns2.setText(dns2V6);
if(!dns1.equals(""))Preferences.put(MainActivity.this, "dns1", dns1);
mainFragment.dns1.setText(dns1V6.toString());
mainFragment.dns2.setText(dns2V6.toString());
Preferences.put(MainActivity.this, "dns1", dns1);
Preferences.put(MainActivity.this, "dns2", dns2);
}else{
if(!dns1.equals(""))mainFragment.dns1.setText(dns1);
mainFragment.dns2.setText(dns2);
if(!dns1V6.equals(""))Preferences.put(MainActivity.this, "dns1-v6", dns1V6);
mainFragment.dns1.setText(dns1.toString());
mainFragment.dns2.setText(dns2.toString());
Preferences.put(MainActivity.this, "dns1-v6", dns1V6);
Preferences.put(MainActivity.this, "dns2-v6", dns2V6);
}
}
......
......@@ -74,7 +74,7 @@ public class SettingsImportActivity extends Activity {
while ((line = reader.readLine()) != null) {
if (line.equals("") || line.startsWith("[")) continue;
if(line.startsWith("'")){
Util.createShortcut(c, Shortcut.fromString(line.split("'")[1]));
//Util.createShortcut(c, Shortcut.fromString(line.split("'")[1]));
}
else data += line;
}
......
......@@ -12,9 +12,9 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import com.frostnerd.dnschanger.R;
import com.frostnerd.dnschanger.database.DatabaseHelper;
import com.frostnerd.dnschanger.dialogs.NewRuleDialog;
import com.frostnerd.dnschanger.util.Util;
import com.frostnerd.dnschanger.database.DatabaseHelper;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -197,17 +197,17 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder>{
if(count > MAX_ROW_ID_CACHE_COUNT){
loadRowRemap(position);
int rowID = rowRemap.containsKey(position) ? rowRemap.get(position) : position+1;
cursor = databaseHelper.getReadableDatabase().rawQuery("SELECT Domain, IPv6, Target, Wildcard FROM DNSRules WHERE ROWID=" + rowID, null);
cursor = databaseHelper.getReadableDatabase().rawQuery("SELECT Host, IPv6, Target, Wildcard FROM DNSRules WHERE ROWID=" + rowID, null);
}else{
cursor = databaseHelper.getReadableDatabase().rawQuery("SELECT Domain, IPv6, Target, Wildcard FROM DNSRules WHERE ROWID=" + rows.get(position), null);
cursor = databaseHelper.getReadableDatabase().rawQuery("SELECT Host, IPv6, Target, Wildcard FROM DNSRules WHERE ROWID=" + rows.get(position), null);
}
}else {
loadRowRemap(position);
int rowID = rowRemap.containsKey(position) ? rowRemap.get(position) : position+1;
cursor = databaseHelper.getReadableDatabase().rawQuery("SELECT Domain, IPv6, Target, Wildcard FROM DNSRules WHERE ROWID=" + rowID, null);
cursor = databaseHelper.getReadableDatabase().rawQuery("SELECT Host, IPv6, Target, Wildcard FROM DNSRules WHERE ROWID=" + rowID, null);
}
cursor.moveToFirst();
final String host = cursor.getString(cursor.getColumnIndex("Domain")),
final String host = cursor.getString(cursor.getColumnIndex("Host")),
target = cursor.getString(cursor.getColumnIndex("Target"));
final boolean ipv6 = cursor.getInt(cursor.getColumnIndex("IPv6")) == 1,
wildcard = cursor.getInt(cursor.getColumnIndex("Wildcard")) == 1;
......@@ -289,7 +289,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder>{
}, HOST_SEARCH{
@Override
public String appendToQuery(String query, String argument, HashMap<Filter, String> filterValues) {
return query + "Domain LIKE '%" + argument + "%'";
return query + "Host LIKE '%" + argument + "%'";
}
}
}
......
......@@ -7,15 +7,22 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.frostnerd.dnschanger.database.entities.DNSEntry;
import com.frostnerd.dnschanger.database.entities.DNSQuery;
import com.frostnerd.dnschanger.database.entities.DNSRule;
import com.frostnerd.dnschanger.database.entities.DNSRuleImport;
import com.frostnerd.dnschanger.database.entities.IPPortPair;
import com.frostnerd.dnschanger.database.entities.Shortcut;
import com.frostnerd.utils.database.orm.Entity;
import com.frostnerd.utils.database.orm.parser.ParsedEntity;
import com.frostnerd.utils.database.orm.statementoptions.queryoptions.WhereCondition;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Copyright Daniel Wolf 2017
......@@ -23,301 +30,97 @@ import java.util.List;
* <p>
* development@frostnerd.com
*/
public class DatabaseHelper extends SQLiteOpenHelper {
private static final List<DNSEntry> defaultDNSEntries = new ArrayList<>();
private static final HashMap<String, DNSEntry> additionalDefaultEntries = new HashMap<>();
static {
defaultDNSEntries.add(new DNSEntry(0, "Google", "Google", "8.8.8.8", "8.8.4.4", "2001:4860:4860::8888", "2001:4860:4860::8844", "",false));
defaultDNSEntries.add(new DNSEntry(0, "OpenDNS", "OpenDNS", "208.67.222.222", "208.67.220.220", "2620:0:ccc::2", "2620:0:ccd::2", "",false));
defaultDNSEntries.add(new DNSEntry(0, "Level3", "Level3", "209.244.0.3", "209.244.0.4", "", "", "",false));
defaultDNSEntries.add(new DNSEntry(0, "FreeDNS", "FreeDNS", "37.235.1.174", "37.235.1.177", "", "", "",false));
defaultDNSEntries.add(new DNSEntry(0, "Yandex", "Yandex", "77.88.8.8", "77.88.8.1", "2a02:6b8::feed:0ff", "2a02:6b8:0:1::feed:0ff", "",false));
defaultDNSEntries.add(new DNSEntry(0, "Verisign", "Verisign", "64.6.64.6", "64.6.65.6", "2620:74:1b::1:1", "2620:74:1c::2:2", "",false));
defaultDNSEntries.add(new DNSEntry(0, "Alternate", "Alternate", "198.101.242.72", "23.253.163.53", "", "", "",false));
defaultDNSEntries.add(new DNSEntry(0, "Norton Connectsafe - Security", "Norton Connectsafe", "199.85.126.10", "199.85.127.10", "", "", "",false));
defaultDNSEntries.add(new DNSEntry(0, "Norton Connectsafe - Security + Pornography" , "Norton Connectsafe", "199.85.126.20", "199.85.127.20", "", "", "",false));
defaultDNSEntries.add(new DNSEntry(0, "Norton Connectsafe - Security + Pornography + Other", "Norton Connectsafe", "199.85.126.30", "199.85.127.30", "", "", "",false));
Collections.sort(defaultDNSEntries);
additionalDefaultEntries.put("unblockr", new DNSEntry(0, "Unblockr", "Unblockr", "178.62.57.141", "139.162.231.18", "", "", "Non-public DNS server for kodi. Visit unblockr.net for more information.",false));
}
public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper {
private static final String DATABASE_NAME = "data";
private static final int DATABASE_VERSION = 2;
private SQLiteDatabase currentDB;
private Context context;
private static final Set<Class<? extends Entity>> entities = new HashSet<Class<? extends Entity>>(){{
add(DNSEntry.class);
add(DNSQuery.class);
add(DNSRule.class);
add(DNSRuleImport.class);
add(IPPortPair.class);
add(Shortcut.class);
}};
private SQLiteDatabase currentDB;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
super(context, DATABASE_NAME, DATABASE_VERSION, entities);
this.context = context;
}
public Context getContext() {
return context;
}
@Override
public synchronized void close() {
context = null;
super.close();
}
@Override
public void onConfigure(SQLiteDatabase db) {
super.onConfigure(db);
}
@Override
public void onCreate(SQLiteDatabase db) {
super.onCreate(db);
currentDB = db;
db.execSQL("CREATE TABLE IF NOT EXISTS Shortcut(ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)");
db.execSQL("CREATE TABLE IF NOT EXISTS DNSEntries(ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, ShortName TEXT, dns1 TEXT, dns2 TEXT, dns1v6 TEXT, dns2v6 TEXT,description TEXT DEFAULT '', CustomEntry BOOLEAN DEFAULT 0)");
db.execSQL("CREATE TABLE IF NOT EXISTS DNSRules(Domain TEXT NOT NULL, IPv6 BOOL DEFAULT 0, Target TEXT NOT NULL, Wildcard BOOL DEFAULT 0, PRIMARY KEY(Domain, IPv6))");
db.execSQL("CREATE TABLE IF NOT EXISTS DNSQueries(Host TEXT NOT NULL, IPv6 BOOL DEFAULT 0, Time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(Host, Time))");
db.execSQL("CREATE TABLE IF NOT EXISTS DNSRuleImports(Filename TEXT NOT NULL, Time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, RowStart INTEGER, RowEnd INTEGER, PRIMARY KEY(Filename, Time))");
db.execSQL("CREATE TABLE IF NOT EXISTS ShortcutAddress(ShortcutID INTEGER, Address VARCHAR(50)," +
" Port INTEGER, IPv6 BOOL, FOREIGN KEY(ShortcutID) REFERENCES Shortcut(ID))");
for(DNSEntry entry: defaultDNSEntries){
saveDNSEntry(entry);
for(DNSEntry entry: DNSEntry.defaultDNSEntries){
insert(entry);
}
for (String s : additionalDefaultEntries.keySet()) {
saveDNSEntry(additionalDefaultEntries.get(s));
for (DNSEntry entry: DNSEntry.additionalDefaultEntries.values()) {
insert(entry);
}
currentDB = null;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
currentDB = db;
if(oldVersion < 2){
db.execSQL("ALTER TABLE DNSEntries ADD COLUMN ShortName TEXT");
for(DNSEntry entry: getDNSEntries()){
if(!entry.isCustomEntry()){
DNSEntry def = findDefaultEntryByName(entry.getName());
entry.setShortName(def == null ? entry.getName() : def.getShortName());
}else entry.setShortName(entry.getName());
editEntry(entry);
}
db.execSQL("CREATE TABLE IF NOT EXISTS DNSRule(Domain TEXT NOT NULL, IPv6 BOOL DEFAULT 0, Target TEXT NOT NULL, Wildcard BOOL DEFAULT 0, PRIMARY KEY(Domain, IPv6))");
db.execSQL("CREATE TABLE IF NOT EXISTS DNSQuery(Host TEXT NOT NULL, IPv6 BOOL DEFAULT 0, Time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(Host, Time))");
db.execSQL("CREATE TABLE IF NOT EXISTS DNSRuleImport(Filename TEXT NOT NULL, Time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, RowStart INTEGER, RowEnd INTEGER, PRIMARY KEY(Filename, Time))");
Cursor cursor = db.rawQuery("SELECT * FROM Shortcuts", new String[]{});
List<String[]> data = new ArrayList<>();
if (cursor.moveToFirst()) {
do{
data.add(new String[]{cursor.getString(cursor.getColumnIndex("Name")), cursor.getString(cursor.getColumnIndex("dns1")), cursor.getString(cursor.getColumnIndex("dns2")),
cursor.getString(cursor.getColumnIndex("dns1v6")), cursor.getString(cursor.getColumnIndex("dns2v6"))});
}while (cursor.moveToNext());
}
cursor.close();
db.execSQL("DROP TABLE Shortcuts");
db.execSQL("CREATE TABLE IF NOT EXISTS Shortcut(ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT)");
db.execSQL("CREATE TABLE IF NOT EXISTS ShortcutAddress(ShortcutID INTEGER, Address VARCHAR(50)," +
" Port INTEGER, IPv6 BOOL, FOREIGN KEY(ShortcutID) REFERENCES Shortcut(ID), PRIMARY KEY(ShortcutID))");
ContentValues values = new ContentValues();
int id;
for(String[] d: data){
values.put("Name", d[0]);
id = (int)db.insert("Shortcut", null, values);
values.clear();
values.put("ShortcutID", id);
values.put("Port", 53);
for(int i = 1; i <= 4; i++){
if(d[i].equals(""))continue;
values.put("Address", d[i]);
db.insert("ShortcutAddress", null, values);
}
}
}
currentDB = null;
public SQLiteDatabase getWritableDatabase() {
return currentDB == null ? super.getWritableDatabase() : currentDB;
}
@Override
public SQLiteDatabase getWritableDatabase() {
if(currentDB != null){
return currentDB;
}
return super.getWritableDatabase();
public SQLiteDatabase getReadableDatabase() {
return currentDB == null ? super.getReadableDatabase() : currentDB;
}
@Override
public SQLiteDatabase getReadableDatabase() {
if(currentDB != null){
return currentDB;
}
return super.getReadableDatabase();
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
super.onUpgrade(db, oldVersion, newVersion);
}
private DNSEntry findDefaultEntryByName(String name){
for(DNSEntry entry: defaultDNSEntries)if(entry.getName().equals(name))return entry;
for(DNSEntry entry: additionalDefaultEntries.values())if(entry.getName().equals(name))return entry;
return null;
@Override
public synchronized void close() {
context = null;
super.close();
}
public void createRuleEntry(String host, String target, boolean ipv6, boolean wildcard){
ContentValues values = new ContentValues(3);
values.put("Domain", host);
values.put("IPv6", ipv6);
values.put("Target", target);
values.put("Wildcard", wildcard);
getWritableDatabase().insert("DNSRules", null, values);
public Context getContext() {
return context;
}
public boolean dnsRuleExists(String host){
Cursor cursor = getReadableDatabase().rawQuery("SELECT ROWID FROM DNSRules WHERE Domain=?",
new String[]{host});
int count = cursor.getCount();
cursor.close();
return count == 1;
return this.rowExists(DNSRule.class, WhereCondition.equal(findColumn(DNSRule.class, "host"), host));
}
public boolean dnsRuleExists(String host, boolean ipv6){
Cursor cursor = getReadableDatabase().rawQuery("SELECT ROWID FROM DNSRules WHERE Domain=? and IPv6=?",
new String[]{host, ipv6 ? "1" : "0"});
int count = cursor.getCount();
cursor.close();
return count == 1;
return this.rowExists(DNSRule.class,
WhereCondition.equal(findColumn(DNSRule.class, "host"), host),
WhereCondition.equal(findColumn(DNSRule.class, "ipv6"), ipv6 ? "1" : "0"));
}
public void editDNSRule(String host, boolean ipv6, String newTarget){
ContentValues values = new ContentValues(1);
values.put("Target", newTarget);
getWritableDatabase().update("DNSRules", values, "Domain=? AND IPv6=?", new String[]{host, ipv6 ? "1" : "0"});
public DNSRule getDNSRule(String host, boolean ipv6){
return getSQLHandler(DNSRule.class).selectFirstRow(this, false,
WhereCondition.equal(findColumn(DNSRule.class, "host"), host),
WhereCondition.equal(findColumn(DNSRule.class, "ipv6"), ipv6 ? "1" : "0"));
}
public boolean deleteDNSRule(String host, boolean ipv6){
return getWritableDatabase().delete("DNSRules", "Domain=? AND IPv6=?", new String[]{host, ipv6 ? "1" : "0"}) > 0;
}
public synchronized void saveDNSEntry(DNSEntry entry){
ContentValues values = new ContentValues(7);
values.put("Name", entry.getName());
values.put("dns1", entry.getDns1());
values.put("dns2", entry.getDns2());
values.put("dns1v6", entry.getDns1V6());
values.put("dns2v6", entry.getDns2V6());
values.put("description", entry.getDescription());
values.put("CustomEntry", entry.isCustomEntry());
values.put("ShortName", entry.getShortName());
getWritableDatabase().insert("DNSEntries", null, values);
}
public synchronized void editEntry(DNSEntry entry){
ContentValues values = new ContentValues(7);
values.put("Name", entry.getName());
values.put("dns1", entry.getDns1());
values.put("dns2", entry.getDns2());
values.put("dns1v6", entry.getDns1V6());
values.put("dns2v6", entry.getDns2V6());
values.put("description", entry.getDescription());
values.put("CustomEntry", entry.isCustomEntry());
values.put("ShortName", entry.getShortName());
getWritableDatabase().update("DNSEntries", values, "ID=" + entry.getID(), null);
return delete(DNSRule.class,
WhereCondition.equal(findColumn(DNSRule.class, "host"), host),
WhereCondition.equal(findColumn(DNSRule.class, "ipv6"), ipv6 ? "1" : "0")) != 0;
}
public synchronized void removeDNSEntry(int ID){
getWritableDatabase().execSQL("DELETE FROM DNSEntries WHERE ID=" + ID);
public int editDNSRule(String host, boolean ipv6, String newTarget){
DNSRule rule = getDNSRule(host, ipv6);
rule.setTarget(newTarget);
return update(rule);
}
public synchronized void saveShortcut(ArrayList<IPPortPair> servers, String name) {
ContentValues values = new ContentValues();
values.put("Name", name);
SQLiteDatabase db = getWritableDatabase();
db.insert("Shortcut", null, values);
values.clear();
values.put("ShortcutID", getLastInsertedRowID(db));
for(IPPortPair pair: servers){
values.put("Address", pair.getAddress());
values.put("Port", pair.getPort());
values.put("IPv6", pair.isIpv6());
db.insert("ShortcutAddress", null, values);
}
}
public int getLastInsertedRowID(SQLiteDatabase db){
Cursor cursor = db.rawQuery("SELECT last_insert_rowid()", null);
int id = -1;
if(cursor.moveToFirst())id = cursor.getInt(0);
cursor.close();
return id;
public void createDNSRule(String host, String target, boolean ipv6, boolean wildcard){
insert(new DNSRule(host, target, ipv6, wildcard));
}
public synchronized void createDNSRuleImport(String filename, int rowIDStart, int rowIDEnd){
ContentValues values = new ContentValues(3);
values.put("Filename", filename);
values.put("RowStart", rowIDStart);
values.put("RowEnd", rowIDEnd);
getWritableDatabase().insert("DNSRuleImports", null, values);
}
public int getHighestRowID(String table){
Cursor cursor = getReadableDatabase().rawQuery("SELECT MAX(ROWID) FROM " + table, null);
int max = -1;
if(cursor.moveToFirst()) max = cursor.getInt(0);
cursor.close();
return max;
}
public synchronized DNSRuleImport[] getDNSRuleImports(){
Cursor cursor = getReadableDatabase().rawQuery("SELECT Filename, Time, ROWID FROM DNSRuleImports", new String[]{});
if(cursor.moveToFirst()){
DNSRuleImport[] imports = new DNSRuleImport[cursor.getCount()];
int i = 0;
do{
imports[i++] = new DNSRuleImport(cursor.getString(0), Timestamp.valueOf(cursor.getString(1)), cursor.getInt(2));
}while(cursor.moveToNext());
cursor.close();
return imports;
}else{
cursor.close();
return new DNSRuleImport[]{};
}
}
public synchronized List<Shortcut> getShortcuts() {
Cursor cursor = getReadableDatabase().rawQuery("SELECT Shortcut.ID, Name, Address, Port, IPv6 FROM " +
"Shortcut LEFT JOIN ShortcutAddress ON Shortcut.ID=ShortcutAddress.ShortcutID ORDER " +
"BY Shortcut.ID, ShortcutAddress.ID ASC", new String[]{});
List<Shortcut> shortcuts = new ArrayList<>();
if (cursor.moveToFirst()) {
List<IPPortPair> pairs = new ArrayList<>();
int id = -1, newID;
do{
newID = cursor.getInt(cursor.getColumnIndex("Shortcut.ID"));
if(id == -1 || newID == id){
pairs.add(new IPPortPair(cursor.getString(cursor.getColumnIndex("Address")),
cursor.getInt(cursor.getColumnIndex("Port")),
cursor.getInt(cursor.getColumnIndex("IPv6")) == 1));
}else{
shortcuts.add(new Shortcut(cursor.getString(cursor.getColumnIndex("Name")), new ArrayList<>(pairs)));
pairs.clear();
}
id = newID;
}while(cursor.moveToNext());
}
cursor.close();
return shortcuts;
}
public synchronized List<DNSEntry> getDNSEntries(){
List<DNSEntry> entries = new ArrayList<>();
try {
Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM DNSEntries", new String[]{});
if (cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex("Name"));
int shortName = cursor.getColumnIndex("ShortName");
entries.add(new DNSEntry(cursor.getInt(cursor.getColumnIndex("ID")), name,
cursor.isNull(shortName) ? name : cursor.getString(shortName),
cursor.getString(cursor.getColumnIndex("dns1")), cursor.getString(cursor.getColumnIndex("dns2")),
cursor.getString(cursor.getColumnIndex("dns1v6")), cursor.getString(cursor.getColumnIndex("dns2v6")),
cursor.getString(cursor.getColumnIndex("description")), cursor.getInt(cursor.getColumnIndex("CustomEntry")) == 1));
} while (cursor.moveToNext());
}
cursor.close();
} catch (Exception e) {
e.printStackTrace();
}
return entries;
public void createShortcut(String name, IPPortPair dns1, IPPortPair dns2, IPPortPair dns1v6, IPPortPair dns2v6){
insert(new Shortcut(dns1, dns2, dns1v6, dns2v6, name));
}
}
......@@ -2,40 +2,108 @@ package com.frostnerd.dnschanger.database.entities;
import android.support.annotation.NonNull;
public class DNSEntry implements Comparable<DNSEntry> {
private String name, dns1, dns2, dns1V6, dns2V6, description, shortName;
private int ID;
import com.frostnerd.dnschanger.database.serializers.IPPortSerializer;
import com.frostnerd.utils.database.orm.Entity;
import com.frostnerd.utils.database.orm.annotations.AutoIncrement;
import com.frostnerd.utils.database.orm.annotations.Named;
import com.frostnerd.utils.database.orm.annotations.PrimaryKey;
import com.frostnerd.utils.database.orm.annotations.Serialized;
import com.frostnerd.utils.database.orm.annotations.Table;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@Table(name = "DNSEntry")
public class DNSEntry extends Entity implements Comparable<DNSEntry>{
@Serialized(using = IPPortSerializer.class)
@Named(name = "dns1")
private IPPortPair dns1;
@Named(name = "dns2")
@Serialized(using = IPPortSerializer.class)
private IPPortPair dns2;
@Named(name = "dns1v6")
@Serialized(using = IPPortSerializer.class)
private IPPortPair dns1V6;
@Named(name = "dns2v6")
@Serialized(using = IPPortSerializer.class)
private IPPortPair dns2V6;
@Named(name = "name")
private String name;
@Named(name = "description")
private String description;
@Named(name = "shortname")
private String shortName;
@Named(name = "customentry")
private boolean customEntry;
public DNSEntry(int id, String name, String shortName, String dns1, String dns2, String dns1V6, String dns2V6, String description, boolean customEntry) {
@PrimaryKey
@AutoIncrement
@Named(name = "id")
private int ID;
public static final List<DNSEntry> defaultDNSEntries = new ArrayList<>();
public static final HashMap<String, DNSEntry> additionalDefaultEntries = new HashMap<>();
static {
defaultDNSEntries.add(DNSEntry.constructSimple("Google", "Google", "8.8.8.8", "8.8.4.4", "2001:4860:4860::8888", "2001:4860:4860::8844", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple( "OpenDNS", "OpenDNS", "208.67.222.222", "208.67.220.220", "2620:0:ccc::2", "2620:0:ccd::2", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("Level3", "Level3", "209.244.0.3", "209.244.0.4", "", "", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("FreeDNS", "FreeDNS", "37.235.1.174", "37.235.1.177", "", "", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("Yandex", "Yandex", "77.88.8.8", "77.88.8.1", "2a02:6b8::feed:0ff", "2a02:6b8:0:1::feed:0ff", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("Verisign", "Verisign", "64.6.64.6", "64.6.65.6", "2620:74:1b::1:1", "2620:74:1c::2:2", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("Alternate", "Alternate", "198.101.242.72", "23.253.163.53", "", "", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("Norton Connectsafe - Security", "Norton Connectsafe", "199.85.126.10", "199.85.127.10", "", "", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("Norton Connectsafe - Security + Pornography" , "Norton Connectsafe", "199.85.126.20", "199.85.127.20", "", "", "",false));
defaultDNSEntries.add(DNSEntry.constructSimple("Norton Connectsafe - Security + Pornography + Other", "Norton Connectsafe", "199.85.126.30", "199.85.127.30", "", "", "",false));
Collections.sort(defaultDNSEntries);
additionalDefaultEntries.put("unblockr", DNSEntry.constructSimple("Unblockr", "Unblockr", "178.62.57.141", "139.162.231.18", "", "", "Non-public DNS server for kodi. Visit unblockr.net for more information.",false));
}
public DNSEntry(String name, String shortName, IPPortPair dns1, IPPortPair dns2, IPPortPair dns1V6, IPPortPair dns2V6, String description, boolean customEntry) {
this.name = name;