コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: AustinA/flingr
        public MainWindow(ref OpenSshController controller, ref FolderManager FolderManager)
        {
            this.controller       = controller;
            this.FolderManager    = FolderManager;
            DataBinding           = new MainWindowDataBinding();
            registerWithAwsThread = new Thread(RegisterWithAws);

            InitializeComponent();

            FindOrInstallOpenSshLocation();

            // This can be read in from the settings file.
            // TODO: create persistent settings file.
            this.FolderManager.DirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            DataBinding.LanIp   = controller.GetLocalIp();
            DataBinding.LanPort = controller.GetLocalPort().ToString();
            DataBinding.WanIp   = controller.GetRemoteIp();
            DataBinding.WanPort = controller.GetRemotePort().ToString();


            WanIpTextBox.IsReadOnly   = true;
            WanPortTextBox.IsReadOnly = true;
            LanIpTextBox.IsReadOnly   = true;
            LanPortTextBox.IsReadOnly = true;
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: AustinA/flingr
        private void Connect(object sender, RoutedEventArgs e)
        {
            LogLine("Connecting...");

            // Before we actually do anything, all of the fields need to be uneditable at this point
            WanIpTextBox.IsReadOnly                     = true;
            WanPortTextBox.IsReadOnly                   = true;
            LanIpTextBox.IsReadOnly                     = true;
            LanPortTextBox.IsReadOnly                   = true;
            RegisterWithAwsCheckBox.IsEnabled           = false;
            AutoConfigureCheckBox.IsEnabled             = false;
            OpenSshExecutableLocationTextBox.IsReadOnly = true;
            LocalStorageDirectoryTextBox.IsReadOnly     = true;
            LocateOpenSshFileButton.IsEnabled           = false;
            LocateLocalDirectoryButton.IsEnabled        = false;

            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                LogLine("Network is available.");
                if (!AutoconfigureIpSettings)
                {
                    LogLine("Setting OpenSSH settings from user configured settings.");
                    controller.SetLocalIp(DataBinding.LanIp);

                    int wanPort;
                    if (Int32.TryParse(DataBinding.WanPort, out wanPort))
                    {
                        controller.SetRemotePort(wanPort);
                    }

                    int lanPort;
                    if (Int32.TryParse(DataBinding.LanPort, out lanPort))
                    {
                        controller.SetLocalPort(lanPort);
                    }
                }
                else
                {
                    controller.SetRemotePort(OpenSshController.GetRandomPortValue());
                }

                bool portRedirected = controller.AddPortRedirection();
                LogLine("Redirecting LAN IP/Port combination for WAN availability...");
                LogLine("Server WAN access available: " + portRedirected);

                bool sshdStarted = false;
                if (controller.SetSftpDirectory(FolderManager.DirectoryPath))
                {
                    LogLine("Creating OpenSSH sshd_config and starting OpenSSH service...");
                    controller.CreateSshdConfig();
                    controller.UpdateSshdConfig(DataBinding.OpenSshInstallLocation);
                    sshdStarted = controller.StartSshd();
                    LogLine("OpenSSH service started: " + sshdStarted);

                    // Fill in the WAN info for the UI
                    DataBinding.WanIp   = controller.GetRemoteIp();
                    DataBinding.WanPort = controller.GetRemotePort().ToString();
                }

                if (!portRedirected && !sshdStarted)
                {
                    SetConnectionStatusLabelToDisconnected();
                    LogLine("COULD NOT CONNECT! UNABLE TO REDIRECT PORT, UNABLE TO START OPENSSH.");
                }
                if (!portRedirected && sshdStarted)
                {
                    var converter = new System.Windows.Media.BrushConverter();
                    ConnectionStatusLabel.Background = (Brush)converter.ConvertFromString("#F7f937");
                    LogLine("COULD NOT CONNECT! UNABLE TO REDIRECT PORT.");
                }

                if (portRedirected && sshdStarted)
                {
                    LogLine("Connected. Starting Registration...");
                    var converter = new System.Windows.Media.BrushConverter();
                    ConnectionStatusLabel.Background = (Brush)converter.ConvertFromString("#41F618");

                    if (RegisterWithAwsCheckBox.IsChecked.GetValueOrDefault())
                    {
                        connected = true;
                        StartAwsThread();
                    }
                }
            }
            else
            {
                LogLine("Network was not available. Please connect to a network before starting Flingr.");
            }
        }