icon: Icon(Icons.vpn_lock),
labelText: 'Origin',
hintText: 'e.g. 192.168.1.2',
- helperText: 'Protocol (https) and default port (8006) implied'),
+ helperText:
+ 'Protocol (https) and default port (8006 or 443) implied'),
controller: widget.originController,
validator: widget.originValidator,
onFieldSubmitted: (value) => widget.onOriginSubmitted!(),
_progressModel = ProxmoxProgressModel();
if (!widget.isCreate! && userModel != null) {
_originController.text = userModel.origin?.toString() ?? '';
+ // Uri does not append 443 for https, so we do it manually
+ if (userModel.origin != null &&
+ userModel.origin!.scheme == "https" &&
+ userModel.origin!.port == 443) {
+ _originController.text += ":443";
+ }
_passwordController.text = widget.password ?? '';
_accessDomains = _getAccessDomains();
_usernameController.text = userModel.username!;
context: context,
builder: (context) => ProxmoxCertificateErrorDialog(),
);
+ } else {
+ showDialog(
+ context: context,
+ builder: (context) => AlertDialog(
+ title: Text('Connection error'),
+ content: Text('Could not establish connection: $e'),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(context).pop(),
+ child: Text('Close'),
+ ),
+ ],
+ ),
+ );
}
}
setState(() {
});
}
+ Future<List<PveAccessDomainModel?>?> _tryGetAccessDomains(
+ Uri uri, bool showConnectionError) async {
+ final settings = await ProxmoxGeneralSettingsModel.fromLocalStorage();
+ List<PveAccessDomainModel?>? response;
+ try {
+ response = await proxclient.accessDomains(uri, settings.sslValidation!);
+ } on proxclient.ProxmoxApiException catch (e) {
+ showDialog(
+ context: context,
+ builder: (context) => ProxmoxApiErrorDialog(
+ exception: e,
+ ),
+ );
+ } catch (e, trace) {
+ print(e);
+ print(trace);
+ if (e.runtimeType == HandshakeException) {
+ showDialog(
+ context: context,
+ builder: (context) => ProxmoxCertificateErrorDialog(),
+ );
+ } else {
+ if (showConnectionError) {
+ showDialog(
+ context: context,
+ builder: (context) => AlertDialog(
+ title: Text('Connection error'),
+ content: Text('Could not establish connection.'),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(context).pop(),
+ child: Text('Close'),
+ ),
+ ],
+ ),
+ );
+ } else {
+ throw e;
+ }
+ }
+ }
+ return response;
+ }
+
Future<List<PveAccessDomainModel?>?> _getAccessDomains() async {
setState(() {
_progressModel
RegExp portRE = new RegExp(r":\d{1,5}$");
+ bool hasPort = true;
if (!portRE.hasMatch(host)) {
- _originController.text += ':8006';
+ hasPort = false;
apiBaseUrl = apiBaseUrl.replace(port: 8006);
}
- final settings = await ProxmoxGeneralSettingsModel.fromLocalStorage();
List<PveAccessDomainModel?>? response;
+
try {
- response =
- await proxclient.accessDomains(apiBaseUrl, settings.sslValidation!);
- } on proxclient.ProxmoxApiException catch (e) {
- showDialog(
- context: context,
- builder: (context) => ProxmoxApiErrorDialog(
- exception: e,
- ),
- );
- } catch (e, trace) {
- print(e);
- print(trace);
- if (e.runtimeType == HandshakeException) {
- showDialog(
- context: context,
- builder: (context) => ProxmoxCertificateErrorDialog(),
- );
- } else {
- showDialog(
- context: context,
- builder: (context) => AlertDialog(
- title: Text('Connection error'),
- content: Text('Could not establish connection.'),
- actions: [
- TextButton(
- onPressed: () => Navigator.of(context).pop(),
- child: Text('Close'),
- ),
- ],
- ),
- );
+ response = await _tryGetAccessDomains(apiBaseUrl, !hasPort);
+ if (!hasPort) {
+ _originController.text = '$host:8006';
+ }
+ } catch (e) {
+ if (!hasPort) {
+ // we were no port given, and we couldn't reach on port 8006, retry with 443
+ apiBaseUrl = apiBaseUrl.replace(port: 443);
+ response = await _tryGetAccessDomains(apiBaseUrl, true);
+ _originController.text = '$host:443';
}
}