mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-21 14:29:12 +00:00
Added override ssl check
This commit is contained in:
parent
4285630508
commit
2716ed17c1
8 changed files with 160 additions and 7 deletions
9
lib/classes/http_override.dart
Normal file
9
lib/classes/http_override.dart
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
class MyHttpOverrides extends HttpOverrides {
|
||||||
|
@override
|
||||||
|
HttpClient createHttpClient(SecurityContext? context){
|
||||||
|
return super.createHttpClient(context)
|
||||||
|
..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -99,5 +99,12 @@
|
||||||
"noSavedLogs": "No saved logs",
|
"noSavedLogs": "No saved logs",
|
||||||
"logs": "Logs",
|
"logs": "Logs",
|
||||||
"copyLogsClipboard": "Copy logs to clipboard",
|
"copyLogsClipboard": "Copy logs to clipboard",
|
||||||
"logsCopiedClipboard": "Logs copied to clipboard"
|
"logsCopiedClipboard": "Logs copied to clipboard",
|
||||||
|
"advancedSettings": "Advanced settings",
|
||||||
|
"dontCheckCertificate": "Don't check SSL certificate",
|
||||||
|
"dontCheckCertificateDescription": "Overrides the server's SSL certificate validation",
|
||||||
|
"advancedSetupDescription": "Advanced options",
|
||||||
|
"settingsUpdatedSuccessfully": "Settings updated successfully.",
|
||||||
|
"cannotUpdateSettings": "Settings cannot be updated.",
|
||||||
|
"restartAppTakeEffect": "Restart the application"
|
||||||
}
|
}
|
|
@ -99,5 +99,12 @@
|
||||||
"noSavedLogs": "No hay logs guardados",
|
"noSavedLogs": "No hay logs guardados",
|
||||||
"logs": "Registros",
|
"logs": "Registros",
|
||||||
"copyLogsClipboard": "Copiar logs al portapapeles",
|
"copyLogsClipboard": "Copiar logs al portapapeles",
|
||||||
"logsCopiedClipboard": "Registros copiados al portapapeles"
|
"logsCopiedClipboard": "Registros copiados al portapapeles",
|
||||||
|
"advancedSettings": "Ajustes avanzados",
|
||||||
|
"dontCheckCertificate": "No comprobar el certificado SSL",
|
||||||
|
"dontCheckCertificateDescription": "Anula la validación del certificado SSL del servidor",
|
||||||
|
"advancedSetupDescription": "Opciones avanzadas",
|
||||||
|
"settingsUpdatedSuccessfully": "Ajustes actualizados correctamente.",
|
||||||
|
"cannotUpdateSettings": "No se han podido actualizar los ajustes.",
|
||||||
|
"restartAppTakeEffect": "Reinicia la aplicación para que se apliquen los cambios."
|
||||||
}
|
}
|
|
@ -12,6 +12,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/base.dart';
|
import 'package:adguard_home_manager/base.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/classes/http_override.dart';
|
||||||
import 'package:adguard_home_manager/services/database.dart';
|
import 'package:adguard_home_manager/services/database.dart';
|
||||||
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||||
|
@ -28,6 +29,11 @@ void main() async {
|
||||||
ServersProvider serversProvider = ServersProvider();
|
ServersProvider serversProvider = ServersProvider();
|
||||||
|
|
||||||
final dbData = await loadDb();
|
final dbData = await loadDb();
|
||||||
|
|
||||||
|
if (dbData['appConfig']['overrideSslCheck'] == 1) {
|
||||||
|
HttpOverrides.global = MyHttpOverrides();
|
||||||
|
}
|
||||||
|
|
||||||
serversProvider.setDbInstance(dbData['dbInstance']);
|
serversProvider.setDbInstance(dbData['dbInstance']);
|
||||||
appConfigProvider.saveFromDb(dbData['dbInstance'], dbData['appConfig']);
|
appConfigProvider.saveFromDb(dbData['dbInstance'], dbData['appConfig']);
|
||||||
serversProvider.saveFromDb(dbData['servers']);
|
serversProvider.saveFromDb(dbData['servers']);
|
||||||
|
|
|
@ -19,6 +19,8 @@ class AppConfigProvider with ChangeNotifier {
|
||||||
|
|
||||||
final List<AppLog> _logs = [];
|
final List<AppLog> _logs = [];
|
||||||
|
|
||||||
|
int _overrideSslCheck = 0;
|
||||||
|
|
||||||
PackageInfo? get getAppInfo {
|
PackageInfo? get getAppInfo {
|
||||||
return _appInfo;
|
return _appInfo;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +63,10 @@ class AppConfigProvider with ChangeNotifier {
|
||||||
return _logs;
|
return _logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get overrideSslCheck {
|
||||||
|
return _overrideSslCheck == 1 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
void setDbInstance(Database db) {
|
void setDbInstance(Database db) {
|
||||||
_dbInstance = db;
|
_dbInstance = db;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +93,19 @@ class AppConfigProvider with ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> setOverrideSslCheck(bool status) async {
|
||||||
|
final updated = await _updateOverrideSslCheck(status == true ? 1 : 0);
|
||||||
|
if (updated == true) {
|
||||||
|
_overrideSslCheck = status == true ? 1 : 0;
|
||||||
|
notifyListeners();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<bool> setSelectedTheme(int value) async {
|
Future<bool> setSelectedTheme(int value) async {
|
||||||
final updated = await _updateThemeDb(value);
|
final updated = await _updateThemeDb(value);
|
||||||
if (updated == true) {
|
if (updated == true) {
|
||||||
|
@ -112,8 +131,22 @@ class AppConfigProvider with ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> _updateOverrideSslCheck(int value) async {
|
||||||
|
try {
|
||||||
|
return await _dbInstance!.transaction((txn) async {
|
||||||
|
await txn.rawUpdate(
|
||||||
|
'UPDATE appConfig SET overrideSslCheck = $value',
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void saveFromDb(Database dbInstance, Map<String, dynamic> dbData) {
|
void saveFromDb(Database dbInstance, Map<String, dynamic> dbData) {
|
||||||
_selectedTheme = dbData['theme'];
|
_selectedTheme = dbData['theme'];
|
||||||
|
_overrideSslCheck = dbData['overrideSslCheck'];
|
||||||
|
|
||||||
_dbInstance = dbInstance;
|
_dbInstance = dbInstance;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
65
lib/screens/settings/advanced_setings.dart
Normal file
65
lib/screens/settings/advanced_setings.dart
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/screens/settings/custom_list_tile.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
||||||
|
|
||||||
|
class AdvancedSettings extends StatelessWidget {
|
||||||
|
const AdvancedSettings({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||||
|
|
||||||
|
Future updateSslCheck(bool newStatus) async {
|
||||||
|
final result = await appConfigProvider.setOverrideSslCheck(newStatus);
|
||||||
|
if (result == true) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.restartAppTakeEffect),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.cannotUpdateSettings),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(AppLocalizations.of(context)!.advancedSettings),
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
children: [
|
||||||
|
CustomListTile(
|
||||||
|
leadingIcon: Icons.lock,
|
||||||
|
label: AppLocalizations.of(context)!.dontCheckCertificate,
|
||||||
|
description: AppLocalizations.of(context)!.dontCheckCertificateDescription,
|
||||||
|
trailing: Switch(
|
||||||
|
value: appConfigProvider.overrideSslCheck,
|
||||||
|
onChanged: updateSslCheck,
|
||||||
|
activeColor: Theme.of(context).primaryColor,
|
||||||
|
),
|
||||||
|
onTap: () => updateSslCheck(!appConfigProvider.overrideSslCheck),
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10,
|
||||||
|
bottom: 10,
|
||||||
|
left: 20,
|
||||||
|
right: 10
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:adguard_home_manager/screens/settings/advanced_setings.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
@ -76,6 +77,18 @@ class Settings extends StatelessWidget {
|
||||||
: AppLocalizations.of(context)!.noServerSelected,
|
: AppLocalizations.of(context)!.noServerSelected,
|
||||||
onTap: navigateServers,
|
onTap: navigateServers,
|
||||||
),
|
),
|
||||||
|
CustomListTile(
|
||||||
|
leadingIcon: Icons.settings,
|
||||||
|
label: AppLocalizations.of(context)!.advancedSettings,
|
||||||
|
description: AppLocalizations.of(context)!.advancedSetupDescription,
|
||||||
|
onTap: () => {
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => const AdvancedSettings()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
SectionLabel(label: AppLocalizations.of(context)!.aboutApp),
|
SectionLabel(label: AppLocalizations.of(context)!.aboutApp),
|
||||||
CustomListTile(
|
CustomListTile(
|
||||||
|
|
|
@ -4,16 +4,29 @@ Future<Map<String, dynamic>> loadDb() async {
|
||||||
List<Map<String, Object?>>? servers;
|
List<Map<String, Object?>>? servers;
|
||||||
List<Map<String, Object?>>? appConfig;
|
List<Map<String, Object?>>? appConfig;
|
||||||
|
|
||||||
|
Future upgradeDbToV2(Database db) async {
|
||||||
|
await db.execute("ALTER TABLE appConfig ADD COLUMN overrideSslCheck NUMERIC");
|
||||||
|
await db.execute("UPDATE appConfig SET overrideSslCheck = 0");
|
||||||
|
|
||||||
|
await db.transaction((txn) async{
|
||||||
|
await txn.rawQuery(
|
||||||
|
'SELECT * FROM appConfig',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Database db = await openDatabase(
|
Database db = await openDatabase(
|
||||||
'adguard_home_manager.db',
|
'adguard_home_manager.db',
|
||||||
version: 1,
|
version: 2,
|
||||||
onCreate: (Database db, int version) async {
|
onCreate: (Database db, int version) async {
|
||||||
await db.execute("CREATE TABLE servers (id TEXT PRIMARY KEY, name TEXT, connectionMethod TEXT, domain TEXT, path TEXT, port INTEGER, user TEXT, password TEXT, defaultServer INTEGER, authToken TEXT)");
|
await db.execute("CREATE TABLE servers (id TEXT PRIMARY KEY, name TEXT, connectionMethod TEXT, domain TEXT, path TEXT, port INTEGER, user TEXT, password TEXT, defaultServer INTEGER, authToken TEXT)");
|
||||||
await db.execute("CREATE TABLE appConfig (theme NUMERIC)");
|
await db.execute("CREATE TABLE appConfig (theme NUMERIC, overrideSslCheck NUMERIC)");
|
||||||
await db.execute("INSERT INTO appConfig (theme) VALUES (0)");
|
await db.execute("INSERT INTO appConfig (theme, overrideSslCheck) VALUES (0, 0)");
|
||||||
},
|
},
|
||||||
onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
||||||
|
if (oldVersion == 1) {
|
||||||
|
await upgradeDbToV2(db);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onOpen: (Database db) async {
|
onOpen: (Database db) async {
|
||||||
await db.transaction((txn) async{
|
await db.transaction((txn) async{
|
||||||
|
|
Loading…
Add table
Reference in a new issue