mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 14:02:48 +00:00
Connect with no authentication
This commit is contained in:
parent
df6af8a29a
commit
9cf505e27a
3 changed files with 27 additions and 55 deletions
|
@ -5,10 +5,10 @@ class Server {
|
||||||
String domain;
|
String domain;
|
||||||
String? path;
|
String? path;
|
||||||
int? port;
|
int? port;
|
||||||
String user;
|
String? user;
|
||||||
String password;
|
String? password;
|
||||||
bool defaultServer;
|
bool defaultServer;
|
||||||
String authToken;
|
String? authToken;
|
||||||
bool runningOnHa;
|
bool runningOnHa;
|
||||||
|
|
||||||
Server({
|
Server({
|
||||||
|
@ -18,10 +18,10 @@ class Server {
|
||||||
required this.domain,
|
required this.domain,
|
||||||
this.path,
|
this.path,
|
||||||
this.port,
|
this.port,
|
||||||
required this.user,
|
this.user,
|
||||||
required this.password,
|
this.password,
|
||||||
required this.defaultServer,
|
required this.defaultServer,
|
||||||
required this.authToken,
|
this.authToken,
|
||||||
required this.runningOnHa,
|
required this.runningOnHa,
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -35,7 +35,9 @@ Future<Map<String, dynamic>> apiRequest({
|
||||||
HttpClient httpClient = HttpClient();
|
HttpClient httpClient = HttpClient();
|
||||||
if (method == 'get') {
|
if (method == 'get') {
|
||||||
HttpClientRequest request = await httpClient.getUrl(Uri.parse(connectionString));
|
HttpClientRequest request = await httpClient.getUrl(Uri.parse(connectionString));
|
||||||
|
if (server.authToken != null) {
|
||||||
request.headers.set('Authorization', 'Basic ${server.authToken}');
|
request.headers.set('Authorization', 'Basic ${server.authToken}');
|
||||||
|
}
|
||||||
HttpClientResponse response = overrideTimeout == true
|
HttpClientResponse response = overrideTimeout == true
|
||||||
? await request.close()
|
? await request.close()
|
||||||
: await request.close().timeout(const Duration(seconds: 10));
|
: await request.close().timeout(const Duration(seconds: 10));
|
||||||
|
@ -60,7 +62,9 @@ Future<Map<String, dynamic>> apiRequest({
|
||||||
}
|
}
|
||||||
else if (method == 'post') {
|
else if (method == 'post') {
|
||||||
HttpClientRequest request = await httpClient.postUrl(Uri.parse(connectionString));
|
HttpClientRequest request = await httpClient.postUrl(Uri.parse(connectionString));
|
||||||
|
if (server.authToken != null) {
|
||||||
request.headers.set('Authorization', 'Basic ${server.authToken}');
|
request.headers.set('Authorization', 'Basic ${server.authToken}');
|
||||||
|
}
|
||||||
request.headers.set('content-type', 'application/json');
|
request.headers.set('content-type', 'application/json');
|
||||||
request.add(utf8.encode(json.encode(body)));
|
request.add(utf8.encode(json.encode(body)));
|
||||||
HttpClientResponse response = overrideTimeout == true
|
HttpClientResponse response = overrideTimeout == true
|
||||||
|
|
|
@ -44,10 +44,8 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
String? portError;
|
String? portError;
|
||||||
|
|
||||||
final TextEditingController userController = TextEditingController();
|
final TextEditingController userController = TextEditingController();
|
||||||
String? userError;
|
|
||||||
|
|
||||||
final TextEditingController passwordController = TextEditingController();
|
final TextEditingController passwordController = TextEditingController();
|
||||||
String? passwordError;
|
|
||||||
|
|
||||||
bool defaultServer = false;
|
bool defaultServer = false;
|
||||||
|
|
||||||
|
@ -114,9 +112,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
ipDomainController.text != '' &&
|
ipDomainController.text != '' &&
|
||||||
ipDomainError == null &&
|
ipDomainError == null &&
|
||||||
pathError == null &&
|
pathError == null &&
|
||||||
portError == null &&
|
portError == null
|
||||||
userController.text != '' &&
|
|
||||||
passwordController.text != ''
|
|
||||||
) {
|
) {
|
||||||
setState(() {
|
setState(() {
|
||||||
allDataValid = true;
|
allDataValid = true;
|
||||||
|
@ -196,34 +192,6 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
checkDataValid();
|
checkDataValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
void validateUser(String? value) {
|
|
||||||
if (value != null && value != '') {
|
|
||||||
setState(() {
|
|
||||||
userError = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setState(() {
|
|
||||||
userError = AppLocalizations.of(context)!.userNotEmpty;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
checkDataValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
void validatePassword(String? value) {
|
|
||||||
if (value != null && value != '') {
|
|
||||||
setState(() {
|
|
||||||
passwordError = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setState(() {
|
|
||||||
passwordError = AppLocalizations.of(context)!.passwordNotEmpty;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
checkDataValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
if (widget.server != null) {
|
if (widget.server != null) {
|
||||||
|
@ -232,8 +200,8 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
ipDomainController.text = widget.server!.domain;
|
ipDomainController.text = widget.server!.domain;
|
||||||
pathController.text = widget.server!.path ?? '';
|
pathController.text = widget.server!.path ?? '';
|
||||||
portController.text = widget.server!.port != null ? widget.server!.port.toString() : "";
|
portController.text = widget.server!.port != null ? widget.server!.port.toString() : "";
|
||||||
userController.text = widget.server!.user;
|
userController.text = widget.server!.user ?? "";
|
||||||
passwordController.text = widget.server!.password;
|
passwordController.text = widget.server!.password ?? "";
|
||||||
defaultServer = widget.server!.defaultServer;
|
defaultServer = widget.server!.defaultServer;
|
||||||
homeAssistant = widget.server!.runningOnHa;
|
homeAssistant = widget.server!.runningOnHa;
|
||||||
}
|
}
|
||||||
|
@ -255,12 +223,12 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
connectionMethod: connectionType.name,
|
connectionMethod: connectionType.name,
|
||||||
domain: ipDomainController.text,
|
domain: ipDomainController.text,
|
||||||
port: portController.text != '' ? int.parse(portController.text) : null,
|
port: portController.text != '' ? int.parse(portController.text) : null,
|
||||||
user: userController.text,
|
user: userController.text != "" ? userController.text : null,
|
||||||
password: passwordController.text,
|
password: passwordController.text != "" ? passwordController.text : null,
|
||||||
defaultServer: defaultServer,
|
defaultServer: defaultServer,
|
||||||
authToken: homeAssistant == true
|
authToken: homeAssistant == true
|
||||||
? encodeBase64UserPass(userController.text, passwordController.text)
|
? encodeBase64UserPass(userController.text, passwordController.text)
|
||||||
: '',
|
: null,
|
||||||
runningOnHa: homeAssistant
|
runningOnHa: homeAssistant
|
||||||
);
|
);
|
||||||
setState(() => isConnecting = true);
|
setState(() => isConnecting = true);
|
||||||
|
@ -272,7 +240,9 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
setState(() => isConnecting = false);
|
setState(() => isConnecting = false);
|
||||||
|
|
||||||
if (result['result'] == 'success') {
|
if (result['result'] == 'success') {
|
||||||
serverObj.authToken = encodeBase64UserPass(serverObj.user, serverObj.password);
|
if (serverObj.user != null && serverObj.password != null) {
|
||||||
|
serverObj.authToken = encodeBase64UserPass(serverObj.user!, serverObj.password!);
|
||||||
|
}
|
||||||
final serverCreated = await serversProvider.createServer(serverObj);
|
final serverCreated = await serversProvider.createServer(serverObj);
|
||||||
if (serverCreated == null) {
|
if (serverCreated == null) {
|
||||||
serversProvider.setServerStatusLoad(0);
|
serversProvider.setServerStatusLoad(0);
|
||||||
|
@ -366,12 +336,12 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
connectionMethod: connectionType.name,
|
connectionMethod: connectionType.name,
|
||||||
domain: ipDomainController.text,
|
domain: ipDomainController.text,
|
||||||
port: portController.text != '' ? int.parse(portController.text) : null,
|
port: portController.text != '' ? int.parse(portController.text) : null,
|
||||||
user: userController.text,
|
user: userController.text != "" ? userController.text : null,
|
||||||
password: passwordController.text,
|
password: passwordController.text != "" ? passwordController.text : null,
|
||||||
defaultServer: defaultServer,
|
defaultServer: defaultServer,
|
||||||
authToken: homeAssistant == true
|
authToken: homeAssistant == true
|
||||||
? encodeBase64UserPass(userController.text, passwordController.text)
|
? encodeBase64UserPass(userController.text, passwordController.text)
|
||||||
: '',
|
: null,
|
||||||
runningOnHa: homeAssistant
|
runningOnHa: homeAssistant
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -380,7 +350,9 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
: await login(serverObj);
|
: await login(serverObj);
|
||||||
|
|
||||||
if (result['result'] == 'success') {
|
if (result['result'] == 'success') {
|
||||||
serverObj.authToken = encodeBase64UserPass(serverObj.user, serverObj.password);
|
if (serverObj.user != null && serverObj.password != null) {
|
||||||
|
serverObj.authToken = encodeBase64UserPass(serverObj.user!, serverObj.password!);
|
||||||
|
}
|
||||||
final serverSaved = await serversProvider.editServer(serverObj);
|
final serverSaved = await serversProvider.editServer(serverObj);
|
||||||
if (serverSaved == null) {
|
if (serverSaved == null) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
@ -576,8 +548,6 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
label: AppLocalizations.of(context)!.username,
|
label: AppLocalizations.of(context)!.username,
|
||||||
controller: userController,
|
controller: userController,
|
||||||
icon: Icons.person_rounded,
|
icon: Icons.person_rounded,
|
||||||
onChanged: validateUser,
|
|
||||||
error: userError
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
textField(
|
textField(
|
||||||
|
@ -585,8 +555,6 @@ class _AddServerModalState extends State<AddServerModal> {
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
icon: Icons.lock_rounded,
|
icon: Icons.lock_rounded,
|
||||||
keyboardType: TextInputType.visiblePassword,
|
keyboardType: TextInputType.visiblePassword,
|
||||||
onChanged: validatePassword,
|
|
||||||
error: passwordError,
|
|
||||||
obscureText: true
|
obscureText: true
|
||||||
),
|
),
|
||||||
sectionLabel(AppLocalizations.of(context)!.other),
|
sectionLabel(AppLocalizations.of(context)!.other),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue