コード例 #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
        public void UpdateSshdConfig(string sshdExecutable)
        {
            const string changeService        = "sc config sshd binpath= ";
            string       sshd_config_fullpath = Path.Combine(baseDir, sshd_config_filename);
            string       SSHD_CONFIG_LOCATION = " -f \\\"" + sshd_config_fullpath + "\\\"\"";


            if (string.IsNullOrEmpty(sshdExecutable))
            {
                sshdExecutable = OpenSshController.LocateSshdExecutable();
            }

            if (!string.IsNullOrEmpty(sshdExecutable))
            {
                string output = ExecuteCmd(changeService + sshdExecutable + SSHD_CONFIG_LOCATION);
                // TODO: check the output to make sure the command is successful
            }
        }
コード例 #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            controller    = new OpenSshController();
            folderManager = new FolderManager();
            MainWindow    = new MainWindow(ref controller, ref folderManager);
            ShowMainWindow();

            FileListingWindow = new FileListing(ref folderManager, new Action(() => ShowMainWindow()));

            NotifyIcon              = new System.Windows.Forms.NotifyIcon();
            NotifyIcon.DoubleClick += (s, args) => ShowFileListingWindow();
            NotifyIcon.Icon         = Flingr.Properties.Resources.FlingrIcon;
            NotifyIcon.Visible      = true;

            CreateContextMenu();
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: AustinA/flingr
        private void FindOrInstallOpenSshLocation()
        {
            ConnectButton.IsEnabled = false;
            LogLine("Looking for OpenSSH Installation...");

            Task.Run(() =>
            {
                string sshLocation = OpenSshController.LocateSshdExecutable();

                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    if (sshLocation == null)
                    {
                        OpenSshExecutableLocationTextBox.IsReadOnly = true;
                        DataBinding.OpenSshInstallLocation = DEFAULT_OPENSSH_LOCATION;
                        LogLine("OpenSSH is not currently installed. Flingr will install it in the following location: " + DEFAULT_OPENSSH_LOCATION);
                    }
                    else
                    {
                        OpenSshExecutableLocationTextBox.IsReadOnly = false;
                        DataBinding.OpenSshInstallLocation = sshLocation;
                        LogLine("OpenSSH is currently installed. This is where Flingr thinks it lives on the device: " + sshLocation);
                    }
                }));

                if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                {
                    bool installationSuccess = OpenSshController.InstallOpenSshd();
                    LogLine("OpenSSH Installed: " + installationSuccess);
                    if (installationSuccess)
                    {
                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            ConnectButton.IsEnabled = true;
                        }));
                    }
                }
                else
                {
                    LogLine("Could not install OpenSSH because network is not available");
                }
            });
        }
コード例 #5
0
 public OpenSshController()
 {
     SetLocalIp(OpenSshController.GetLocalIPAddress());
 }
コード例 #6
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.");
            }
        }