Exemplo n.º 1
3
 public static void setPw(string username, string password)
 {
     try
     {
         AppsService service = new AppsService(DOMAIN, USERNAME, PASSWORD);
         UserEntry entry = service.RetrieveUser(username);
         entry.Login.Password = password;
         service.UpdateUser(entry);
     }
     catch (AppsException ex)
     {
         // Probably don't have a Google Apps account yet, do nothing
         if (ex.Reason == "EntityDoesNotExist") { }
         else { throw ex; }
     }
 }
Exemplo n.º 2
0
        private static void UserOperations(AppsService service)
        {
            // Create a new user.
            UserEntry insertedEntry = service.CreateUser(testUserName, "Jane",
                "Doe", "testuser-password");
            Console.WriteLine("Created new user '{0}'", insertedEntry.Login.UserName);

            // Suspend the user.
            UserEntry suspendedEntry = service.SuspendUser(testUserName);
            Console.WriteLine("Suspended account for {0}", suspendedEntry.Login.UserName);

            // Restore the user.
            UserEntry restoredEntry = service.RestoreUser(testUserName);
            Console.WriteLine("Restored user {0}", restoredEntry.Login.UserName);

            // Query for a single user.
            UserEntry entry = service.RetrieveUser(testUserName);
            Console.WriteLine("Retrieved user {0}", entry.Login.UserName);

            // Query for a page of users.
            UserFeed feed = service.RetrievePageOfUsers(testUserName);
            entry = feed.Entries[0] as UserEntry;
            Console.WriteLine("Retrieved page of {0} users, beginning with '{1}'", feed.Entries.Count,
                entry.Login.UserName);

            // Query for all users.
            feed = service.RetrieveAllUsers();
            entry = feed.Entries[0] as UserEntry;
            Console.WriteLine("Retrieved all {0} users in the domain, beginning with '{1}'",
                feed.Entries.Count, entry.Login.UserName);

            // Update the user's given name.
            restoredEntry.Name.GivenName = "John";
            UserEntry updatedEntry = service.UpdateUser(entry);
            Console.WriteLine("Updated user with new given name '{0}'", updatedEntry.Name.GivenName);
        }
Exemplo n.º 3
0
        /*
         * parameters:
         * domain, admin, adminPassword, user, hash, hashFunction, proxyAddress, proxyUser, proxyPassword
         */
        static void Main(string[] args)
        {
            //Open the log file
            string applicationDataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
            string logPath = Path.Combine(applicationDataDirectory, "GoogleHashUpdater.log");
            log = new StreamWriter(logPath, true);
            try
            {
                if (args.Length < 6)
                {
                    //wrong number of argument, exit
                    Log("Program called with an incurrect number of arguments");
                    Environment.ExitCode = 10;
                    return;
                }
                //Connect to google apps
                String domain = args[0];
                String admin = args[1];
                String adminPassword = args[2];
                String user = args[3];
                String hash = args[4];
                String hashFunction = args[5];
                
                AppsService service = new AppsService(domain, admin, adminPassword);
                
                //proxy settings
                if (args.Length >= 7)
                {
	                GDataRequestFactory requestFactory = (GDataRequestFactory) service.CreateRequestFactory();
	                WebProxy myProxy = new WebProxy(args[6], true); // format: http://192.168.0.1:8080/
					//setup credentials on the proxy here
					if (args.Length == 9)
					{
						myProxy.Credentials = new NetworkCredential(args[7], args[8]);
					}
					else
					{
						myProxy.Credentials = CredentialCache.DefaultCredentials;
					}
					requestFactory.Proxy = myProxy;
					service.SetRequestFactory(requestFactory);
                }
				
                try
                {
                    //Search the user
                    UserEntry entry = service.RetrieveUser(user);
                    //change the pasword
                    entry.Login.Password = hash;
                    entry.Login.HashFunctionName = hashFunction;
                    //save modification
                    entry.Update();
                }
                catch (LoggedException ex)
                {
                    //On error log and close
                    Log("Failed to update password: "******"Changed password for user \"{0}\"", user));
            }          
            finally
            {
                log.Close();
            }
        }
Exemplo n.º 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     //decodr.Text = System.Web.HttpUtility.UrlEncode(encodr.Text.ToString()).Replace("+", " ").Replace("*", "%2A").Replace("!", "%21").Replace("(", "%28").Replace(")", "%29").Replace("'", "%27").Replace("_", "%5f").Replace(" ", "%20").Replace("%", "_");
     AppsService service = new AppsService("students.fhchs.edu", "*****@*****.**", "abc123");
     UserEntry gmailUser = service.RetrieveUser(encodr.Text.ToString());
     gmailUser.Dirty = true;
     decodr.Text += gmailUser.Dirty.ToString();
     decodr.Text += gmailUser.IsDirty();
     gmailUser.Update();
     decodr.Text += gmailUser.Dirty.ToString();
     decodr.Text += gmailUser.IsDirty();
     service.UpdateUser(gmailUser);
     decodr.Text += gmailUser.Dirty.ToString();
     decodr.Text += gmailUser.IsDirty();
     gmailUser.Dirty = true;
 }
Exemplo n.º 5
0
        // BUTTONS FOR GMAIL TAB
        private void gmail_Check_Authorization_Click(object sender, EventArgs e)
        {
            authNotify.Text = "Contacting google";
            AppsService service = new AppsService(mailDomain.Text.ToString(), mailUser.Text.ToString() + "@" + mailDomain.Text.ToString(), mailPassword.Text.ToString());

            try
            {
                authNotify.Text = "Checking for user";
                UserEntry gAdmin = service.RetrieveUser(mailUser.Text.ToString());
                authNotify.Text = "Successfully Authenticated! \n" + gAdmin.Login.UserName.ToString();

            }
            catch
            {
                authNotify.Text = "Failed Authentication";
            }
        }
Exemplo n.º 6
0
        private void button3_Click(object sender, EventArgs e)
        {
            // decodr.Text = Regex.Replace(Regex.Replace(encodr.Text.ToString(), @"[^a-z|^A-Z|^0-9|^\.|_|-]|[\^|\|]|", ""), @"\.+", ".");

            AppsService service = new AppsService("students.fhchs.edu", "*****@*****.**", "abc123");
            UserEntry gmailUser = service.RetrieveUser(encodr.Text.ToString());
            //decodr.Text = gmailUser.Dirty.ToString();
            //decodr.Text += gmailUser.IsDirty();

            //gmailUser.Content.Dirty = true;
            SortedList list = gmailUser.Name.Attributes;
            string attribs = "Name attibutes \n" ;
            foreach (DictionaryEntry de in list)
            {
                attribs += de.Key + " " + de.Value + "\n";
            }
            MessageBox.Show(attribs);
            list = gmailUser.Login.Attributes;
            attribs = "login attributes \n";
            foreach (DictionaryEntry de in list)
            {
                attribs += de.Key + " " + de.Value + "\n";
            }
            MessageBox.Show(attribs);

            list = gmailUser.Quota.Attributes;
            attribs = "quota attributes \n";
            foreach (DictionaryEntry de in list)
            {
                attribs += de.Key + " " + de.Value + "\n";
            }
            MessageBox.Show(attribs);

              //          AtomCategory dirty = new AtomCategory();
            //            gmailUser.ToggleCategory(dirty, true);

            gmailUser.Name.GivenName = "Mike";

            MessageBox.Show("base check dirt after content set dirty " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName);
            gmailUser.Login.AgreedToTerms = (bool)false;
            MessageBox.Show("base check dirt after content set dirty " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName);
            service.UpdateUser(gmailUser);
            gmailUser.Name.GivenName = "Michael";
            MessageBox.Show("base check dirt after content set dirty  and update performed " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName);
            service.UpdateUser(gmailUser);
            MessageBox.Show("base check dirt after content set dirty  and update performed " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName + " " + gmailUser.Name.GivenName);

            //GoogleMailSettingsService gmailSettings = new GoogleMailSettingsService("students.fhchs.edu", "FHCHS");
            //gmailSettings.setUserCredentials("*****@*****.**", "password");
            //try
            //{
            //    gmailSettings.CreateSendAs(encodr.Text.ToString(), "Nigeria rocks", "*****@*****.**", "*****@*****.**", "true");
            //}
            //catch (GDataRequestException ex)
            //{
            //    MessageBox.Show(" \\-Data-/ " + ex.Data + " \\-Message-/ " + ex.Message + " \\-Response-/ " + ex.Response + " \\-Response String-/ " + ex.ResponseString);
            //}
        }
Exemplo n.º 7
0
 private void button2_Click(object sender, EventArgs e)
 {
     //  encodr.Text = System.Web.HttpUtility.UrlDecode(decodr.Text.ToString().Replace("_", "%"));\
     AppsService service = new AppsService("students.fhchs.edu", "*****@*****.**", "password");
     UserEntry gmailUser = service.RetrieveUser(encodr.Text.ToString());
     gmailUser.Dirty = true;
     decodr.Text = gmailUser.Dirty.ToString();
     decodr.Text += gmailUser.IsDirty();
     gmailUser.Update();
     service.UpdateUser(gmailUser);
     decodr.Text = gmailUser.Dirty.ToString();
     decodr.Text += gmailUser.IsDirty();
 }
Exemplo n.º 8
0
        public void UpdateGmailUser(AppsService service, GmailUsers gusersyn, SqlDataReader usersToUpdate, LogFile log)
        {
            string userNickName = "";
            string middlename = "";
            try
            {
                while (usersToUpdate.Read())
                {
                    try
                    {
                        UserEntry gmailUser = service.RetrieveUser((string)usersToUpdate[gusersyn.User_StuID]);
                        //special gmail username replace string only allows -_. special character thru
                        gmailUser.Login.UserName = System.Web.HttpUtility.UrlEncode(usersToUpdate[gusersyn.User_StuID].ToString()).Replace("+", " ").Replace("*", "%2A").Replace("!", "%21").Replace("(", "%28").Replace(")", "%29").Replace("'", "%27").Replace("_", "%5f").Replace(" ", "%20").Replace("%", "_");
                        gmailUser.Name.FamilyName = usersToUpdate[gusersyn.User_Lname].ToString().Replace("<", "%3c").Replace(">", "%3e").Replace("=", "%3d").Replace("%", "%25");
                        gmailUser.Name.GivenName = usersToUpdate[gusersyn.User_Fname].ToString().Replace("<", "%3c").Replace(">", "%3e").Replace("=", "%3d").Replace("%", "%25");
                        middlename = usersToUpdate[gusersyn.User_Mname].ToString().Replace("<", "%3c").Replace(">", "%3e").Replace("=", "%3d").Replace("%", "%25");
                        service.UpdateUser(gmailUser);
                        log.addTrn("Updated " + System.Web.HttpUtility.UrlEncode(usersToUpdate[gusersyn.User_StuID].ToString()).Replace("+", " ").Replace("*", "%2A") + " because of name change. New Name is " + gmailUser.Name.FamilyName.ToString() + ", " + gmailUser.Name.GivenName.ToString(), "Transaction");
                       // if (gusersyn.Levenshtein == true)
                       // {
                            userNickName = GetNewUserNickname(service, gmailUser.Login.UserName, gmailUser.Name.GivenName, middlename, gmailUser.Name.FamilyName, 0, false);
                            log.addTrn("Added New Alias for " + gmailUser.Login.UserName + "@" + gusersyn.Admin_domain + " Aliased as " + userNickName + "@" + gusersyn.Admin_domain, "Transaction");
                       // }

                    }
                    catch (Exception ex)
                    {
                        log.addTrn("Failed update gmail account " + System.Web.HttpUtility.UrlEncode(usersToUpdate[gusersyn.User_StuID].ToString()).Replace("+", " ").Replace("*", "%2A").Replace("!", "%21").Replace("(", "%28").Replace(")", "%29").Replace("'", "%27").Replace("_", "%5f").Replace(" ", "%20").Replace("%", "_") + " exception " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Error");
                    }

                }
            }
            catch (Exception ex)
            {
                log.addTrn("Issue updating gmail users datareader is null " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Error");
            }
        }