/// <summary> /// Generate a QR Barcode with the server information /// </summary> private BitmapSource GenerateBarcode(User auth) { try { ServerDescription desc = new ServerDescription(); desc.QRVersion = QR_VERSION; desc.GeneratorApp = GENERATOR_APP; desc.HardwareAddresses = String.Join(";", NetworkInformation.GetMACAddresses()); desc.Addresses = String.Join(";", NetworkInformation.GetIPAddresses()); desc.Name = Configuration.Services.GetServiceName(); desc.NetbiosName = System.Environment.MachineName; desc.ExternalIp = ExternalAddress.GetAddress(); desc.Services = new List <ServiceDescription>(); User wifiRemoteAuth = WifiRemote.IsInstalled ? WifiRemote.GetAuthentication() : null; foreach (var srv in Installation.GetInstalledServices()) { var srvdesc = new ServiceDescription() { Name = srv.Service, Port = srv.Port }; if (auth != null) { srvdesc.User = (srv.Service == "WifiRemote" ? wifiRemoteAuth : auth).Username; srvdesc.Password = (srv.Service == "WifiRemote" ? wifiRemoteAuth : auth).GetPassword(); } desc.Services.Add(srvdesc); } var writer = new BarcodeWriter() { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions() { Height = 400, Width = 400 } }; var bitmap = writer.Write(desc.ToJSON()); return(bitmap.ToWpfBitmap()); } catch (Exception ex) { Log.Error("Error generating barcode", ex); return(null); } }
private String RequestAccessThroughWifiRemote(string clientName, string ip, CancellationTokenSource cancelToken) { User auth = WifiRemote.GetAuthentication(); var client = new AccessRequestingClient(auth, "localhost", WifiRemote.Port); client.Connect(); bool sentDialog = false; while (!client.ConnectionFailed) { if (client.AuthenticationFailed) { Log.Error("Failed to authorize with WifiRemote"); break; } if (client.Authenticated && client.ServerVersion < REQUIRED_WIFIREMOTE) { Log.Error("Connected to WifiRemote API {0}, but API {1} is required. Please update your WifiRemote.", client.ServerVersion, REQUIRED_WIFIREMOTE); break; } if (cancelToken.IsCancellationRequested) { if (sentDialog) { client.CancelRequestAccessDialog(); } break; } if (!sentDialog && client.Authenticated) { client.SendRequestAccessDialog(clientName, ip, Configuration.Authentication.Users.Select(x => x.Username).ToList()); sentDialog = true; } if (client.LatestDialogResult != null) { // User accepted or denied the request client.Disconnect(); return(client.LatestDialogResult.SelectedOption); } Thread.Sleep(500); } client.Disconnect(); return(ERROR); }