Пример #1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DriveListBoxItem dlbi = (DriveListBoxItem)DriveLetterCB.SelectedItem;

            if (dlbi != null)
            {
                string drive = dlbi.info.Name;

                if (config.sshEnabled)
                {
                    string path = System.IO.Path.Combine(drive, "ssh");
                    using (StreamWriter writer = new StreamWriter(path))
                    {
                        writer.WriteLine("For headless setup, ");
                        writer.WriteLine("SSH can be enabled by placing a file named 'ssh', ");
                        writer.WriteLine("without any extension, onto the boot partition of the SD card. ");
                        writer.WriteLine("When the Pi boots, it looks for the 'ssh' file. ");
                        writer.WriteLine("If it is found, SSH is enabled, and the file is deleted. ");
                        writer.WriteLine("The content of the file does not matter: it could contain text, ");
                        writer.WriteLine("or nothing at all.");
                        writer.WriteLine("source: https://www.raspberrypi.org/documentation/remote-access/ssh/");
                        writer.WriteLine("source: https://www.raspberrypi.org/blog/a-security-update-for-raspbian-pixel/");
                    }
                }



                string wifiConfigPath = System.IO.Path.Combine(drive, "wpa_supplicant.conf");
                using (StreamWriter writer = new StreamWriter(wifiConfigPath))
                {
                    /*
                     * http://raspberrypi.stackexchange.com/questions/10251/prepare-sd-card-for-wifi-on-headless-pi
                     * according to the documentation its possible to put more then one
                     * wifi network in the file. But for me that didnt work. if its not possible it would make more
                     * sense to only write the selecte network to the file with the next line...
                     * (instead of the foreach loop)
                     *
                     * WifiListBoxItem wifi = (WifiListBoxItem)ssidComboBox.SelectedItem;
                     */

                    foreach (WifiListBoxItem wifi in ssidComboBox.Items)
                    {
                        writer.WriteLine("network={");
                        writer.WriteLine(string.Format("    ssid=\"{0}\"", wifi.ssid));
                        writer.WriteLine(string.Format("    psk=\"{0}\"", wifi.psk));
                        writer.WriteLine("}");
                        writer.WriteLine("");
                    }
                }
            }
        }
Пример #2
0
        private void DriveLetterCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Regex ssidRegex = new Regex("[\\s\\S]*ssid=\"([\\s\\S]*)\"");
            Regex pskRegex  = new Regex("[\\s\\S]*psk=\"([\\s\\S]*)\"");

            DriveListBoxItem dlbi = (DriveListBoxItem)DriveLetterCB.SelectedItem;

            if (dlbi != null)
            {
                string drive = dlbi.info.Name;
                string path  = System.IO.Path.Combine(drive, WPAFILENAME);
                if (File.Exists(path))
                {
                    string[]        fileContent = System.IO.File.ReadAllLines(path);
                    WifiListBoxItem tempWifi    = new WifiListBoxItem();
                    foreach (string line in fileContent)
                    {
                        Match ssidMatch = ssidRegex.Match(line);
                        Match pskMatch  = pskRegex.Match(line);

                        if (line.IndexOf("network") != -1)
                        {
                            tempWifi = new WifiListBoxItem();
                        }

                        if (ssidMatch.Success)
                        {
                            tempWifi.ssid    = ssidMatch.Groups[1].Value;
                            tempWifi.Content = ssidMatch.Groups[1].Value;
                        }

                        if (pskMatch.Success)
                        {
                            tempWifi.psk = pskMatch.Groups[1].Value;
                        }

                        if (line.IndexOf("}") != -1)
                        {
                            ssidComboBox.Items.Add(tempWifi);
                        }
                    }
                }

                if (ssidComboBox.Items.Count > 0)
                {
                    ssidComboBox.SelectedIndex = 0;
                }
            }
        }
Пример #3
0
        public MainWindow()
        {
            InitializeComponent();

            IpListBox.Items.SortDescriptions.Add(
                new System.ComponentModel.SortDescription("",
                                                          System.ComponentModel.ListSortDirection.Ascending));


            sshEnabled.IsChecked = config.sshEnabled;

            foreach (WifiListBoxItem wItem in config.wifiList)
            {
                ssidComboBox.Items.Add(wItem);
            }
            ssidComboBox.SelectedIndex = 0;

            PuttyPathTextBox.Text = config.puttyPath;
            UserNameTextBox.Text  = config.userName;
            RangeTextBox.Text     = config.ipRange;

            // load drive data into DriveLetterCB
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            DriveLetterCB.Items.Clear();

            foreach (DriveInfo d in allDrives)
            {
                if (d.IsReady && d.DriveType == DriveType.Removable)
                {
                    DriveListBoxItem itm = new DriveListBoxItem();
                    itm.Content = string.Format("[{0}] - {1} ({2})", d.Name, d.VolumeLabel, d.DriveFormat);
                    itm.info    = d;
                    DriveLetterCB.Items.Add(itm);
                }
            }

            if (DriveLetterCB.Items.Count > 0)
            {
                DriveLetterCB.SelectedIndex = 0;
            }
        }