Exemplo n.º 1
0
        /// <summary>
        /// Returns "true" if an update is available, "false" if one is not and "error" if there was an error.
        /// String because I need more options. If a new update is available or there was an error it already opens a dialog!
        /// </summary>
        /// <returns></returns>
        public static string CheckForUpdates()
        {
            Dictionary <string, string> isNewestVersion = Updates.IsNewestVersion();

            if (isNewestVersion["isNewestVersion"] == "false")
            {
                bool extraButtonPressed = GetInput.ShowInfoDialog(
                    "Update Available",
                    "An update for this app is currently available.",
                    "You are running " + Software.Type + " " + Software.Version + " and the newest version is " + isNewestVersion["newestVersion"] + ".\nClick the button on the bottom left to upgrade.\n\nNew in version " + isNewestVersion["newestVersion"] + ":\n" + isNewestVersion["changes"],
                    new Button {
                    IsEnabled = true, Text = "Download newest build"
                });
                if (extraButtonPressed)
                {
                    Process.Start(isNewestVersion["updateUrl"]);
                }
                return("true");
            }
            else if (isNewestVersion["isNewestVersion"] == "error")
            {
                return("error");
                // nothing
            }
            else
            {
                return("false");
                // nothing
            }
        }
        /// <summary>
        /// Set the location of the device.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setLocationButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false && Globals.DeviceId != "csv")
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            string location    = !String.IsNullOrEmpty(Globals.Location) ? Globals.Location : "Enter a location...";
            string newLocation = GetInput.getInput("What would you like to set the location to?", location, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Add/Change Device Location: " + Globals.SerialNumber : "Add/Change Device Location: " + Globals.DeviceId, new Button {
                IsEnabled = true, Text = "Clear Location"
            });

            if (newLocation == null | newLocation == location)
            {
                outputField.Text = "You didn't enter anything or pressed cancel.";
                return;
            }
            else if (newLocation == "ExtraButtonClicked")
            {
                newLocation = "";
            }

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "location \"" + newLocation + "\""));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " location \"" + newLocation + "\"");
            }
            Globals.Location = newLocation;
            outputField.Text = gamResult + "\nAs long as you don't see an error, the location has been updated.";
        }
        public static void GetTelemetryConsent()
        {
            bool stop = false;

            while (stop == false)
            {
                string decision = GetInput.GetYesOrNo(
                    "Enhanced Telemetry Consent",
                    "Can we send extra crash data?",
                    "It would be really helpful if you would allow us to send data like your email, your current device and other info back to the developers. See the privacy policy for more information.",
                    "Open Privacy Policy...",
                    false
                    );
                switch (decision)
                {
                case "yes":
                    AllowEnhancedTelemetry = true;
                    stop = true;
                    break;

                case "no":
                    AllowEnhancedTelemetry = false;
                    stop = true;
                    break;

                case "extraButtonClicked":
                    Process.Start("https://github.com/iamtheyammer/gam-cros-win-wrapper/blob/master/PrivacyPolicy.md");
                    break;
                }
            }
        }
        private void setUserButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false && Globals.DeviceId != "csv")
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            string user    = !String.IsNullOrEmpty(Globals.User) ? Globals.User : "******";
            string newUser = GetInput.getInput("What would you like to set the user to?", user, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Modify Device User: "******"Modify Device User: "******"You didn't enter anything or you pressed cancel, silly goose!";
                return;
            }
            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "user " + newUser));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " user " + newUser);
            }
            Globals.User     = newUser;
            outputField.Text = gamResult + "\nAs long as you don't see an error, this query completed successfully.";
        }
Exemplo n.º 5
0
        private void ImportFromCSV_Click(object sender, RoutedEventArgs e)
        {
            if (Preferences.ShowWarningWhenImportingFromCSVFile)
            {
                GetInput.ShowInfoDialog("CSV Import Warning", "About importing from CSV",
                                        "When you use this tool to import data from a CSV, you are making many modifications quickly, " +
                                        "which can be hard to undo. \n" +
                                        "To import a CSV, make sure that, in the CSV you want to import, the column with Device IDs is named " +
                                        "\"deviceId\", without the quotes. That will allow ChromebookGUI to run the mass operation.\n" +
                                        "If you want to silence this warning in the future, go to File -> Preferences and untick the appropriate " +
                                        "box."
                                        );
            }
            string filePath = GetInput.GetFileSelection("csv");

            if (filePath == null)
            {
                GetInput.ShowInfoDialog("ChromebookGUI: No file selected", "No File Selected", "You didn't select a file or pressed cancel. Either way no changes have been made.");
                return;
            }
            Globals.ClearGlobals();
            Globals.CsvLocation = filePath;
            Globals.DeviceId    = "csv";
            currentView.ToggleMainWindowButtons(true);
        }
        /// <summary>
        /// Set the asset id of the device. If an asset id is in the Globals, it will prefill that in the text box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setAssetIdButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false && Globals.DeviceId != "csv")
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            string assetId    = !String.IsNullOrEmpty(Globals.AssetId) ? Globals.AssetId : "Enter an Asset ID...";
            string newAssetId = GetInput.getInput("What would you like to set the asset ID to?", assetId, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Enter/Change Device Asset ID: " + Globals.SerialNumber : "Enter/Change Device Asset ID: " + Globals.DeviceId, new Button {
                IsEnabled = true, Text = "Clear Asset ID"
            });

            if (newAssetId == null)
            {
                outputField.Text = "You didn't enter anything or you pressed cancel, silly goose!";
                return;
            }
            else if (newAssetId == "ExtraButtonClicked")
            {
                newAssetId = "";
            }
            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros ", "assetid \"" + newAssetId + "\""));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " assetid \"" + newAssetId + "\"");
            }
            Globals.AssetId  = newAssetId;
            outputField.Text = gamResult + "\nAs long as you don't see an error, this query completed successfully.";
        }
Exemplo n.º 7
0
 public static BasicDeviceInfo HandleGetDeviceId(List <BasicDeviceInfo> possibleDevices)
 {
     if (possibleDevices.Count == 1)
     {
         return(possibleDevices[0]);
     }
     return(GetInput.GetDeviceSelection("Which device would you like to select?", "Click on a row or enter a Device ID or Serial Number.", "Device Selector", possibleDevices));
 }
        private async void deprovisionButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            int    depChoice = GetInput.GetDeprovisionReason();
            string depAction = null;

            switch (depChoice)
            {
            case 0:
                outputField.Text = "Either you cancelled or selected nothing.";
                return;

            case 1:
                // same model replacement
                depAction = "deprovision_same_model_replace";
                break;

            case 2:
                // different model replacement
                depAction = "deprovision_different_model_replace";
                break;

            case 3:
                // retiring device
                depAction = "deprovision_retiring_device";
                break;

            default:
                depAction = "thisbetterfailbecausesomethingiswrong";
                return;
            }

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "action " + depAction + " acknowledge_device_touch_requirement")));

                IsLoading = false;
            }
            else
            {
                IsLoading = true;
                gamResult = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " action " + depAction + " acknowledge_device_touch_requirement"));

                IsLoading = false;
            }
            outputField.Text = gamResult += "\nAs long as you don't see an error, this query completed successfully.";
        }
        private async void noteButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
            }
            string note = null;

            IsLoading = true;
            if (String.IsNullOrEmpty(Globals.Note) && Globals.DeviceId != "csv")
            {
                List <string> gamResult = await Task.Run(() => GAM.RunGAM("info cros " + Globals.DeviceId + " fields notes"));

                if (gamResult.Count < 2)
                {
                    note = "No note found. Enter a new one here...";
                }
                else
                {
                    note = gamResult[1].Substring(9);
                }
            }
            else if (!String.IsNullOrEmpty(Globals.Note))
            {
                note = Globals.Note;
            }
            else if (Globals.DeviceId == "csv")
            {
                note = "Set a note for all devices from this CSV...";
            }

            string newNote = GetInput.getInput("Edit/modify note:", note, !String.IsNullOrEmpty(Globals.SerialNumber) ? "Add/Change Device Note: " + Globals.SerialNumber : "Add/Change Device Note: " + Globals.DeviceId);

            if (newNote == null | newNote == note)
            {
                outputField.Text = "You didn't change the note so I'm leaving it as it is.";
                return;
            }

            string finalGamResult;

            if (Globals.DeviceId == "csv")
            {
                finalGamResult = await Task.Run(() => GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "notes \"" + newNote + "\"")));
            }
            else
            {
                finalGamResult = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " notes \"" + newNote + "\""));
            }
            IsLoading        = false;
            Globals.Note     = newNote;
            outputField.Text = "As long as there's no error, the note was updated.";
        }
Exemplo n.º 10
0
        public static Dictionary <string, string> IsNewestVersion()
        {
            Console.WriteLine("Starting newest version check...");
            HttpClient    http = Globals.HttpClientObject;
            Task <string> newestVersionsString         = http.GetStringAsync("https://iamtheyammer.github.io/gam-cros-win-wrapper/updates/" + Software.Type + ".json");
            Dictionary <string, string> newestVersions = null;

            try
            {
                newestVersionsString.Wait();
                newestVersions = JsonConvert.DeserializeObject <Dictionary <string, string> >(newestVersionsString.Result);
            } catch /*(Exception e)*/
            {
                GetInput.ShowInfoDialog("Internet Issue", "No internet connection", "Could not connect to the internet to check for updates.\nPlease make sure that github.io is accessible on your network.\n\nThe full URL this software is trying to access is:\nhttps://iamtheyammer.github.io/gam-cros-win-wrapper/releases.json");
                return(new Dictionary <string, string>()
                {
                    ["error"] = "true",
                    ["errorCode"] = "2" // no internet
                });
            }

            if (newestVersions == null)
            {
                GetInput.ShowInfoDialog("Error", "error checking for updates", "error!");
            }
            string currentVersion = Software.Version;
            string newestVersion  = newestVersions["newestVersion"];

            if (newestVersion == currentVersion)
            {
                return(new Dictionary <string, string>()
                {
                    ["isNewestVersion"] = "true"
                });
            }
            else
            {
                Console.WriteLine(newestVersions["newestVersion"]);
                return(new Dictionary <string, string>()
                {
                    ["isNewestVersion"] = "false",
                    ["newestVersion"] = !String.IsNullOrEmpty(newestVersions["newestVersion"]) ? newestVersions["newestVersion"] : "(could not be determined)",
                    ["changes"] = !String.IsNullOrEmpty(newestVersions["changes"]) ? newestVersions["changes"] : "(there was an issue getting the changelog)",
                    ["updateUrl"] = (newestVersions["updateUrl"].StartsWith("https://github.com/iamtheyammer") ||
                                     newestVersions["updateUrl"].StartsWith("https://iamtheyammer.github.io"))
                        ? newestVersions["updateUrl"] : "The update URL was deemed to be unsafe (not from iamtheyammmer!!!!). This is a MASSIVE DEAL. REPORT IMMEDIATELY."
                });
            }
        }
Exemplo n.º 11
0
        private async void ImportFromGoogleAdminQueryStringBulk_Click(object sender, RoutedEventArgs e)
        {
            currentView.IsLoading = true;
            string inputBoxPrefill = "example: user:jsmith\nThat imports all devices with the user:jsmith.\nClick the link on the bottom left for more information.";
            string queryString     = GetInput.getInput(
                "Enter an Admin Console query string.",
                inputBoxPrefill,
                "Import from Google Admin query string",
                new Button()
            {
                IsEnabled = true,
                Text      = "Open Help Page"
            }
                );

            if (queryString == "ExtraButtonClicked")
            {
                Process.Start("https://support.google.com/chrome/a/answer/1698333#search");
                ImportFromGoogleAdminQueryStringBulk_Click(sender, e);
                return;
            }
            else if (queryString == inputBoxPrefill || queryString == null)
            {
                GetInput.ShowInfoDialog("ChromebookGUI: No input", "No Input", "No query string entered, silly goose!");
                currentView.IsLoading = false;
                return;
            }

            List <string> gamResult = await Task.Run(() => GAM.RunGAM("print cros query \"" + queryString + "\""));

            if (gamResult.Count == 0)
            {
                GetInput.ShowInfoDialog("ChromebookGUI: Invalid Query String", "Invalid Query String", "That's an invalid query string. If you don't think it is, try running this in cmd:\n\ngam print cros query \"" + queryString + "\"");
                currentView.IsLoading = false;
                return;
            }
            else if (gamResult.Count < 2)
            {
                GetInput.ShowInfoDialog("ChromebookGUI: No Results", "No Results from Query String", "No results from that query (" + queryString + ")");
                currentView.IsLoading = false;
                return;
            }
            File.WriteAllLines(System.IO.Path.GetTempPath() + "ChromebookGUI.csv", gamResult.ToArray());
            Globals.ClearGlobals();
            Globals.CsvLocation   = System.IO.Path.GetTempPath() + "ChromebookGUI.csv";
            Globals.DeviceId      = "csv";
            currentView.IsLoading = false;
            GetInput.ShowInfoDialog("ChromebookGUI: Success", "Successful Query", "Found " + (gamResult.Count - 1) + " devices using query " + queryString + "."); // subtract 1 because the first is "deviceId"
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get info about the device. Does NOT support CSVs.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void getInfoButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            else if (Globals.DeviceId == "csv")
            {
                GetInput.ShowInfoDialog("Not Supported", "This action is not supported with a CSV", "We don't support using CSVs for info because they put out unreadable output.");
                return;
            }
            string deviceId = Globals.DeviceId;

            //if (deviceId == null || deviceId.Length < 1) ;
            outputField.Text = GAM.RunGAMFormatted("info cros " + Globals.DeviceId + " allfields");
        }
Exemplo n.º 13
0
        private void HelpCheckForUpdates_Click(object sender, RoutedEventArgs e)
        {
            string updates = Updates.CheckForUpdates();

            switch (updates)
            {
            case "false":
                GetInput.ShowInfoDialog("ChromebookGUI Updater", "No updates available", "This product, ChromebookGUI by iamtheyammer, is up to date. You are running " + Software.Type + " " + Software.Version + ".");
                return;

            case "true":
                return;
                //case "error":
                //    GetInput.ShowInfoDialog("ChromebookGUI Updater", "Error checking for updates.", "There was an error checking for updates."); // this should never happen!
                //    return;
            }
        }
Exemplo n.º 14
0
 private void copyId_Click(object sender, RoutedEventArgs e)
 {
     if (Globals.DeviceId != null && Globals.DeviceId != "csv")
     {
         Clipboard.SetText(Globals.DeviceId, TextDataFormat.UnicodeText);
         outputField.Text += "\n\nCopied to clipboard.";
     }
     else if (Globals.DeviceId == "csv")
     {
         GetInput.ShowInfoDialog("Not Supported", "This action is not supported from a CSV", "We don't support copying all IDs from a CSV at this time.");
         return;
     }
     else
     {
         outputField.Text += "\n\nNo device ID currently in memory.";
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Handles OrgUnit.AwaitableGetOrgUnitFromSelector.
        /// Returns an empty string if the user didn't pick anything.
        /// </summary>
        /// <param name="orgUnits">Data returned from OrgUnit.GetOrgUnitFromSelector</param>
        /// <returns></returns>
        public static string HandleAwaitableGetOrgUnitFromSelector(List <OrgUnit> orgUnits)
        {
            List <string> orgSelection = GetInput.GetDataGridSelection("Pick an org!", "Click on an row to select it, or paste the full path here and press submit...", "Organizational Unit Selector", orgUnits);
            string        orgPath      = null;

            foreach (string item in orgSelection)
            {
                if (item.Contains("/"))
                {
                    orgPath = item;
                    break;
                }
            }
            if (orgPath == null || orgSelection.Contains("Click on an row to select it, or paste the full path here and press submit..."))
            {
                return("");
            }

            return(orgPath);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Easily get an org path. Handles all of the logic of opening the data selector window and finding which is the path.
        /// </summary>
        /// <returns>A string containing the full path to the organizational unit.</returns>
        public static string GetOrgUnitFromSelector()
        {
            List <List <string> > fixedOrgs = GAM.RunGAMCommasFixed("print orgs allfields");

            List <OrgUnit> orgUnits = new List <OrgUnit>();

            foreach (List <string> org in fixedOrgs)
            {
                if (org[0] == "orgUnitPath")
                {
                    continue;
                }

                orgUnits.Add(new OrgUnit()
                {
                    OrgUnitPath        = !String.IsNullOrEmpty(org[0]) ? org[0] : null,
                    OrgUnitName        = !String.IsNullOrEmpty(org[2]) ? (org[2].StartsWith("id:") ? "(no description provided)" : org[2]) : null,
                    OrgUnitDescription = !String.IsNullOrEmpty(org[3]) ? (org[3].StartsWith("id:") ? "(no description provided)" : org[3]) : null
                });
            }
            if (orgUnits.Count < 2)
            {
                return("There was an error getting your org units. You don't seem to have any.");
            }
            List <string> orgSelection = GetInput.GetDataGridSelection("Pick an org!", "Click on an row to select it, or paste the full path here and press submit...", "Organizational Unit Selector", orgUnits);
            string        orgPath      = null;

            foreach (string item in orgSelection)
            {
                if (item.Contains("/"))
                {
                    orgPath = item;
                }
            }
            if (orgPath == null | orgSelection.Contains("Click on an row to select it, or paste the full path here and press submit..."))
            {
                return("Either you didn't enter anything or there was an error. Nothing has been changed.");
            }

            return(orgPath);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Returns "true" if an update is available, "false" if one is not and "error" if there was an error.
        /// String because I need more options. If a new update is available or there was an error it already opens a dialog!
        /// </summary>
        /// <returns></returns>
        public static string CheckForUpdates()
        {
            Dictionary <string, string> isNewestVersion = Updates.IsNewestVersion();

            if (isNewestVersion["isNewestVersion"] == "false")
            {
                bool extraButtonPressed = GetInput.ShowInfoDialog(
                    "Update Available",
                    "An update for this app is currently available.",
                    "You are running " + Software.Type + " " + Software.Version + " and the newest version is " + isNewestVersion["newestVersion"] + ".\nClick the button on the bottom left to upgrade.\n\nNew in version " + isNewestVersion["newestVersion"] + ":\n" + isNewestVersion["changes"],
                    new Button {
                    IsEnabled = true, Text = "Download newest build"
                });
                if (extraButtonPressed)
                {
                    switch (Software.Type)
                    {
                    case "alpha":
                        Process.Start("https://github.com/iamtheyammer/gam-cros-win-wrapper/raw/master/ChromebookGUI/Installer/Tool+Installer/Installer.msi");
                        break;

                    default:
                        Process.Start("https://github.com/iamtheyammer/releases/latest");
                        break;
                    }
                }
                return("true");
            }
            else if (isNewestVersion["isNewestVersion"] == "error")
            {
                return("error");
                // nothing
            }
            else
            {
                return("false");
                // nothing
            }
        }
Exemplo n.º 18
0
        private async void OrganizationalUnitBrowseButton_Click(object sender, RoutedEventArgs e)
        {
            string currentOutput = outputField.Text;

            IsLoading = true;
            string orgUnit = OrgUnit.HandleAwaitableGetOrgUnitFromSelector(await Task.Run(OrgUnit.AwaitableGetOrgUnitFromSelector));

            IsLoading = false;
            if (string.IsNullOrEmpty(orgUnit))
            {
                GetInput.ShowInfoDialog("No org unit selected",
                                        "No org unit selected",
                                        "For best results, please select an org unit.");
                outputField.Text = currentOutput;
                return;
            }
            else
            {
                OrganizationalUnitField.Text = orgUnit;
            }
            outputField.Text = currentOutput;
        }
        private async void ApplyChangesButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IsLoading = true;
                // check to see which fields have been changed (ones that aren't the global or "<no value present>", should make this an independent function)
                ProgressBarDialog progressBar = GetInput.ShowProgressBarDialog("Updating Device", 50, "Updating device info...");
                progressBar.UpdateBarAndText(50, "Updating device info...");
                var gamCommands = new List <string>();
                var wasChanged  = new List <string>();

                if (LocationField.Text != Globals.Location)
                {
                    if (ShouldEmptyField(LocationField.Text, Globals.Location))
                    {
                        switch (GetInput.GetYesOrNo("Empty Location?", "Clear the field?", "Click yes if you want to empty the Location field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            IsLoading = false;
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("location \"" + LocationField.Text + "\"");
                    Globals.Location = LocationField.Text;
                    wasChanged.Add("Location");
                }
                if (AssetIdField.Text != Globals.AssetId)
                {
                    if (ShouldEmptyField(AssetIdField.Text, Globals.AssetId))
                    {
                        switch (GetInput.GetYesOrNo("Empty Asset ID?", "Clear the field?", "Click yes if you want to empty the Asset ID field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            IsLoading = false;
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("asset_id \"" + AssetIdField.Text + "\"");
                    Globals.AssetId = LocationField.Text;
                    wasChanged.Add("Asset ID");
                }
                if (UserField.Text != Globals.User)
                {
                    if (ShouldEmptyField(UserField.Text, Globals.User))
                    {
                        switch (GetInput.GetYesOrNo("Empty User?", "Clear the field?", "Click yes if you want to empty the User field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("user \"" + UserField.Text + "\"");
                    Globals.User = UserField.Text;
                    wasChanged.Add("User");
                }
                if (NoteField.Text != Globals.Note)
                {
                    if (ShouldEmptyField(NoteField.Text, Globals.Note))
                    {
                        switch (GetInput.GetYesOrNo("Empty Note?", "Clear the field?", "Click yes if you want to empty the Note field. Click no to cancel."))
                        {
                        case "yes":
                            break;

                        case "no":
                            outputField.Text = "Cancelling because you didn't want to empty a field.";
                            progressBar.Close();
                            IsLoading = false;
                            return;

                        default:
                            progressBar.Close();
                            return;
                        }
                    }
                    gamCommands.Add("notes \"" + NoteField.Text.Replace("\"", "\\\"") + "\""); // will output a note like this: "He told me \"Hello!\" yesterday."
                    Globals.Note = NoteField.Text;
                    wasChanged.Add("Note");
                }
                if (StatusDisabledRadio.IsChecked == true && Globals.Status != "DISABLED")
                {
                    progressBar.UpdateBarAndText(55, "Disabling...");
                    await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action disable"));

                    Globals.Status = "DISABLED";
                    wasChanged.Add("Status");
                }
                if (StatusActiveRadio.IsChecked == true && Globals.Status != "ACTIVE")
                {
                    progressBar.UpdateBarAndText(55, "Enabling...");
                    await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action reenable"));

                    Globals.Status = "ACTIVE";
                    wasChanged.Add("Status");
                }
                if (StatusDeprovisionedRadio.IsChecked == true && Globals.Status != "DEPROVISIONED")
                {
                    //deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device [acknowledge_device_touch_requirement]
                    int depReason = GetInput.GetDeprovisionReason();
                    switch (depReason)
                    {
                    case 1:
                        progressBar.UpdateBarAndText(55, "Deprovisioning...");
                        await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_same_model_replace acknowledge_device_touch_requirement"));

                        break;

                    case 2:
                        progressBar.UpdateBarAndText(55, "Deprovisioning...");
                        await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_different_model_replace acknowledge_device_touch_requirement"));

                        break;  // different

                    case 3:     // retire
                        progressBar.UpdateBarAndText(55, "Deprovisioning...");
                        await Task.Run(() => GAM.RunGAM("update cros " + Globals.DeviceId + " action deprovision_retiring_device acknowledge_device_touch_requirement"));

                        break;

                    default:
                        outputField.Text = "No deprovision reason was selected so that choice was not saved.\n";
                        break;     // do nothing: they selected nothing.
                    }
                    if (depReason != 0)
                    {
                        Globals.Status = "DEPROVISIONED";
                        wasChanged.Add("Status");
                        StatusActiveRadio.IsEnabled        = false;
                        StatusDeprovisionedRadio.IsEnabled = false;
                        StatusDisabledRadio.IsEnabled      = false;
                    }
                }

                if (OrganizationalUnitField.Text != Globals.OrgUnitPath)
                {
                    if (ShouldEmptyField(OrganizationalUnitField.Text, Globals.OrgUnitPath))
                    {
                        GetInput.ShowInfoDialog("Empty org unit path.", "Your org unit path can't be blank.", "You can't have a blank org unit path.");
                        return;
                    }
                    gamCommands.Add("ou \"" + OrganizationalUnitField.Text + "\"");
                    Globals.OrgUnitPath = OrganizationalUnitField.Text;
                    wasChanged.Add("Organizational Unit");
                }

                progressBar.UpdateBarAndText(75, "Updating info...");
                if (gamCommands.Count > 0) // if something was changed
                {
                    Console.WriteLine(string.Join(" ", gamCommands));
                    string gamOutput = await Task.Run(() => GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " " + string.Join(" ", gamCommands)));

                    Console.WriteLine(gamOutput);
                }
                progressBar.UpdateBarAndText(99, "Finishing up...");
                IsLoading = false;
                if (wasChanged.Count > 0)
                {
                    outputField.Text = string.Join(", ", wasChanged) + " was changed.";
                }
                progressBar.Close();
                // build a GAM command from that information
                // run it
                // update globals
                // show success in output field
            }
            catch (Exception err)
            {
                Debug.CaptureRichException(err, CollectFieldsForRichException());
                Debug.ShowErrorMessage();
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Takes in a GAM query, and returns a single device.
        /// </summary>
        /// <param name="query">The gam query to search for: like "user:myUser"</param>
        /// <returns></returns>
        public static BasicDeviceInfo GetDeviceByGAMQuery(string query)
        {
            List <string>            gamResults = RunGAM("print cros query \"" + query + "\" fields deviceId,lastSync,serialNumber,status,user,location,assetId,notes");
            Dictionary <string, int> fieldOrder = new Dictionary <string, int>();

            if (gamResults[0].StartsWith("deviceId"))
            {
                string[] gamFieldOrder = gamResults[0].Split(',');
                for (int i = 0; i < gamResults[0].Split(',').Length; i++)
                {
                    fieldOrder.Add(gamFieldOrder[i], i);
                }
                gamResults.RemoveAt(0);
            }
            if (gamResults.Count == 0)
            {
                return new BasicDeviceInfo()
                       {
                           Error     = true,
                           ErrorText = "Invalid query string or no results for that query string.",
                       }
            }
            ;
            List <List <string> > deviceInfos = FixCSVCommas.FixCommas(gamResults);

            if (deviceInfos.Count == 1)
            {
                if (deviceInfos[0].Count > 1)                         // using 2 if statements here because I can't check for [0] if it doesn't exist
                {
                    return(new BasicDeviceInfo()
                    {
                        DeviceId = deviceInfos[0][fieldOrder["deviceId"]],
                        LastSync = deviceInfos[0][fieldOrder["lastSync"]],
                        SerialNumber = deviceInfos[0][fieldOrder["serialNumber"]],
                        Status = deviceInfos[0][fieldOrder["status"]],
                        User = deviceInfos[0][fieldOrder["annotatedUser"]],
                        Error = false
                    });
                }
            }
            // there is more than one result
            Console.WriteLine(gamResults[0]);
            List <BasicDeviceInfo> infoObjects = new List <BasicDeviceInfo>();

            for (int i = 0; i < deviceInfos.Count; i++)
            {
                infoObjects.Add(new BasicDeviceInfo()
                {
                    DeviceId     = deviceInfos[i][fieldOrder["deviceId"]],
                    LastSync     = deviceInfos[i][fieldOrder["lastSync"]],
                    SerialNumber = deviceInfos[i][fieldOrder["serialNumber"]],
                    Status       = deviceInfos[i][fieldOrder["status"]],
                    User         = deviceInfos[i][fieldOrder["annotatedUser"]],
                    Error        = false
                });
            }
            List <string> selection = GetInput.GetDataGridSelection("Which device would you like to select?", "Click on a row or enter a Device ID or Serial Number.", "Device Selector", infoObjects);
            string        deviceId  = null;

            foreach (string item in selection)
            {
                if (IsDeviceId(item))
                {
                    deviceId = item;
                }
                break;
            }
            if (deviceId == null)
            {
                return(new BasicDeviceInfo
                {
                    ErrorText = "There was an error. You didn't pick anything.",
                    Error = true
                });
            }
            else
            {
                for (int i = 1; i < deviceInfos.Count; i++)
                {
                    if (deviceId == deviceInfos[i][0])
                    {
                        return(new BasicDeviceInfo
                        {
                            DeviceId = deviceInfos[i][fieldOrder["deviceId"]],
                            LastSync = deviceInfos[i][fieldOrder["lastSync"]],
                            SerialNumber = deviceInfos[i][fieldOrder["serialNumber"]],
                            Status = deviceInfos[i][fieldOrder["status"]],
                            User = deviceInfos[i][fieldOrder["annotatedUser"]],
                            Error = false
                        });
                    }
                }
                // we have not found a match for the device id
                return(new BasicDeviceInfo
                {
                    DeviceId = deviceId,
                    Error = true,
                    ErrorText = "No devices found for that query. (404)"
                });
            }
        }
Exemplo n.º 21
0
 private void FileAboutChromebookGUI_Click(object sender, RoutedEventArgs e)
 {
     GetInput.ShowInfoDialog("About ChromebookGUI", "Open source, by iamtheyammer", "This project was made by iamtheyammer on GitHub. It lives at https://git.io/fxYBf, and was made because of my disdain for the speed of Google's Admin Console.\n\nI hope you enjoy it! If you'd like to contribute (this project is written in C# with .NET) please submit a pull request!\n\nThank you for using my software.");
 }
        /// <summary>
        /// Essentially, run GAM.GetDeviceId() on whatever is entered into the text field.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void SubmitDeviceId_Click(object sender, RoutedEventArgs e)
        {
            ToggleMainWindowButtons(false);
            ProgressBarDialog progressBar = GetInput.ShowProgressBarDialog("Getting Device Info", 5, "Searching for devices...");

            if (deviceInputField.Text.Length < 1 || deviceInputField.Text.ToLower() == "enter a device id, asset id, serial number, query string or email...")
            {
                outputField.Text = "You must enter something into the field at the top.";
                progressBar.Close();
                return;
            }

            //outputField.Text = GAM.GetDeviceId(deviceInputField.Text);
            BasicDeviceInfo deviceInfo = GAM.GetDeviceId(deviceInputField.Text);

            Globals.ClearGlobals(); // clear the globals before adding new ones
            Globals.SetGlobalsFromBasicDeviceInfo(deviceInfo);
            if (deviceInfo.Error)
            {
                outputField.Text = deviceInfo.ErrorText;
                progressBar.Close();
                return;
            }
            await progressBar.UpdateBarAndText(30, "Getting more device info...");


            BasicDeviceInfo fullDeviceInfo = GAM.GetAllDeviceInfo(deviceInfo.DeviceId);

            fullDeviceInfo.LastSync     = !string.IsNullOrEmpty(deviceInfo.LastSync) ? deviceInfo.LastSync : null;
            fullDeviceInfo.DeviceId     = deviceInfo.DeviceId;
            fullDeviceInfo.SerialNumber = !string.IsNullOrEmpty(deviceInfo.SerialNumber) ? deviceInfo.SerialNumber : null;
            fullDeviceInfo.Status       = !string.IsNullOrEmpty(deviceInfo.Status) ? deviceInfo.Status : null;
            fullDeviceInfo.User         = !string.IsNullOrEmpty(deviceInfo.User) ? deviceInfo.User : null;
            await progressBar.UpdateBarAndText(40, "Saving variables...");

            Globals.SetGlobalsFromBasicDeviceInfo(fullDeviceInfo);
            await progressBar.UpdateBarAndText(55, "Populating fields...");

            if (!String.IsNullOrEmpty(fullDeviceInfo.Notes))
            {
                NoteField.Text = fullDeviceInfo.Notes;
            }
            else
            {
                NoteField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.AssetId))
            {
                AssetIdField.Text = fullDeviceInfo.AssetId;
            }
            else
            {
                AssetIdField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.Location))
            {
                LocationField.Text = fullDeviceInfo.Location;
            }
            else
            {
                LocationField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.User))
            {
                UserField.Text = fullDeviceInfo.User;
            }
            else
            {
                UserField.Text = "";
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.OrgUnitPath))
            {
                OrganizationalUnitField.Text = fullDeviceInfo.OrgUnitPath;
            }
            else
            {
                OrganizationalUnitField.Text = "";
            }

            if (!String.IsNullOrEmpty(fullDeviceInfo.Status))
            {
                switch (fullDeviceInfo.Status)
                {
                case "ACTIVE":
                    StatusActiveRadio.IsChecked        = true;
                    StatusDisabledRadio.IsEnabled      = true;
                    StatusActiveRadio.IsEnabled        = true;
                    StatusDeprovisionedRadio.IsEnabled = true;
                    break;

                case "DISABLED":
                    StatusDisabledRadio.IsChecked      = true;
                    StatusDisabledRadio.IsEnabled      = true;
                    StatusActiveRadio.IsEnabled        = true;
                    StatusDeprovisionedRadio.IsEnabled = true;
                    break;

                case "DEPROVISIONED":
                    StatusDeprovisionedRadio.IsChecked = true;
                    StatusDeprovisionedRadio.IsEnabled = false;
                    StatusActiveRadio.IsChecked        = false;
                    StatusActiveRadio.IsEnabled        = false;
                    StatusDisabledRadio.IsChecked      = false;
                    StatusDisabledRadio.IsEnabled      = false;
                    break;
                }
            }

            await progressBar.UpdateBarAndText(85, "Filling in output box...");

            outputField.Text = "Found device. ID: " + fullDeviceInfo.DeviceId + ".";
            if (!String.IsNullOrEmpty(fullDeviceInfo.SerialNumber))
            {
                outputField.Text += "\nSerial Number: " + fullDeviceInfo.SerialNumber;
            }
            if (!String.IsNullOrEmpty(fullDeviceInfo.LastSync))
            {
                outputField.Text += "\nLast Sync: " + fullDeviceInfo.LastSync;
            }

            await progressBar.UpdateBarAndText(100, "Done!");

            ToggleMainWindowButtons(true);
            progressBar.Close();
            //deviceInputField.Text = deviceId;
        }
        private async void ApplyChangesButton_Click(object sender, RoutedEventArgs e)
        {
            // check to see which fields have been changed (ones that aren't the global or "<no value present>", should make this an independent function)
            ProgressBarDialog progressBar = GetInput.ShowProgressBarDialog("Updating Device", 50, "Updating device info...");
            await progressBar.UpdateBarAndText(50, "Updating device info...");

            string gamCommand = "update cros " + Globals.DeviceId + " ";
            string outputText = "";

            if (LocationField.Text != Globals.Location)
            {
                if (LocationField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty Location?", "Clear the field?", "Click yes if you want to empty the Location field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand      += "location \"" + LocationField.Text + "\" ";
                Globals.Location = LocationField.Text;
                outputText      += "Location, ";
            }
            if (AssetIdField.Text != Globals.AssetId)
            {
                if (AssetIdField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty Asset ID?", "Clear the field?", "Click yes if you want to empty the Asset ID field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand     += "asset_id \"" + AssetIdField.Text + "\" ";
                Globals.AssetId = LocationField.Text;
                outputText     += "Asset ID, ";
            }
            if (UserField.Text != Globals.User)
            {
                if (UserField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty User?", "Clear the field?", "Click yes if you want to empty the User field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand  += "user \"" + UserField.Text + "\" ";
                Globals.User = UserField.Text;
                outputText  += "User, ";
            }
            if (NoteField.Text != Globals.Note)
            {
                if (NoteField.Text.Length < 1)
                {
                    switch (GetInput.GetYesOrNo("Empty Note?", "Clear the field?", "Click yes if you want to empty the Note field. Click no to cancel."))
                    {
                    case "yes":
                        break;

                    case "no":
                        outputField.Text = "Cancelling because you didn't want to empty a field.";
                        progressBar.Close();
                        return;

                    default:
                        progressBar.Close();
                        return;
                    }
                }
                gamCommand  += "notes \"" + NoteField.Text.Replace("\"", "\\\"") + "\" "; // will output a note like this: "He told me \"Hello!\" yesterday."
                Globals.Note = NoteField.Text;
                outputText  += "Note, ";
            }
            if (StatusDisabledRadio.IsChecked == true && Globals.Status != "DISABLED")
            {
                gamCommand    += "action disable ";
                Globals.Status = "DISABLED";
                outputText    += "Status, ";
            }
            if (StatusActiveRadio.IsChecked == true && Globals.Status != "ACTIVE")
            {
                gamCommand    += "action reenable ";
                Globals.Status = "ACTIVE";
                outputText    += "Status, ";
            }
            if (StatusDeprovisionedRadio.IsChecked == true && Globals.Status != "DEPROVISIONED")
            {
                //deprovision_same_model_replace|deprovision_different_model_replace|deprovision_retiring_device [acknowledge_device_touch_requirement]
                int depReason = GetInput.GetDeprovisionReason();
                switch (depReason)
                {
                case 1:
                    gamCommand += "action deprovision_same_model_replace acknowledge_device_touch_requirement ";     // same
                    break;

                case 2:
                    gamCommand += "action deprovision_different_model_replace acknowledge_device_touch_requirement ";
                    break;  // different

                case 3:     // retire
                    gamCommand += "action deprovision_retiring_device acknowledge_device_touch_requirement ";
                    break;

                default:
                    outputField.Text = "No deprovision reason was selected so that choice was not saved.\n";
                    break;     // do nothing: they selected nothing.
                }
                if (depReason != 0)
                {
                    Globals.Status = "DEPROVISIONED";
                    outputText    += "Status, ";
                    StatusActiveRadio.IsEnabled        = false;
                    StatusDeprovisionedRadio.IsEnabled = false;
                    StatusDisabledRadio.IsEnabled      = false;
                }
            }
            if (OrganizationalUnitField.Text != Globals.OrgUnitPath && Globals.OrgUnitPath.Length > 0)
            {
                gamCommand         += "ou " + OrganizationalUnitField.Text + " ";
                Globals.OrgUnitPath = OrganizationalUnitField.Text;
                outputText         += "Orgizational Unit ";
            }

            if (gamCommand != "update cros " + Globals.DeviceId + " ") // if something was changed
            {
                string gamOutput = GAM.RunGAMFormatted(gamCommand);
                Console.WriteLine(gamOutput);
            }
            await progressBar.UpdateBarAndText(99, "Finishing up...");

            if (outputText.Length > 1)
            {
                outputField.Text = outputText += "was updated.";
            }
            progressBar.Close();
            // build a GAM command from that information
            // run it
            // update globals
            // show success in output field
        }
Exemplo n.º 24
0
        private void changeOuButton_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.DeviceIdExists() == false)
            {
                outputField.Text = "No device ID currently in memory. Press " + submitDeviceId.Content + " then try again.";
                return;
            }
            outputField.Text = "You should see the org selector in a second...";
            //return;

            List <string>         allOrgs   = GAM.RunGAM("print orgs allfields");
            List <List <string> > fixedOrgs = FixCSVCommas.FixCommas(allOrgs);

            List <OrgUnit> orgUnits = new List <OrgUnit>();

            foreach (List <string> org in fixedOrgs)
            {
                if (org[0] == "orgUnitPath")
                {
                    continue;
                }

                orgUnits.Add(new OrgUnit()
                {
                    OrgUnitPath        = !String.IsNullOrEmpty(org[0]) ? org[0] : null,
                    OrgUnitName        = !String.IsNullOrEmpty(org[2]) ? (org[2].StartsWith("id:") ? "(no description provided)" : org[2]) : null,
                    OrgUnitDescription = !String.IsNullOrEmpty(org[3]) ? (org[3].StartsWith("id:") ? "(no description provided)" : org[3]) : null
                });
            }
            if (orgUnits.Count < 2)
            {
                outputField.Text = "There was an error getting your org units. You don't seem to have any.";
                return;
            }
            List <string> orgSelection = GetInput.GetDataGridSelection("Pick an org!", "Click on an row to select it, or paste the full path here and press submit...", "Organizational Unit Selector", orgUnits);
            string        orgPath      = null;

            foreach (string item in orgSelection)
            {
                if (item.Contains("/"))
                {
                    orgPath = item;
                }
            }
            if (orgPath == null | orgSelection.Contains("Click on an row to select it, or paste the full path here and press submit..."))
            {
                outputField.Text = "Either you didn't enter anything or there was an error. Nothing has been changed.";
                return;
            }

            string gamResult = null;

            if (Globals.DeviceId == "csv")
            {
                gamResult = GAM.RunGAMFormatted(GAM.GetGAMCSVCommand(Globals.CsvLocation, "update cros", "ou \"" + orgPath + "\""));
            }
            else
            {
                gamResult = GAM.RunGAMFormatted("update cros " + Globals.DeviceId + " ou \"" + orgPath + "\"");
            }
            outputField.Text = "Done! Your OU has been changed.";
        }