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; } } }
public override void InitTest() { base.InitTest(); if (unitTestConfiguration.Contains("domainName") == true) { this.domainName = (string)unitTestConfiguration["domainName"]; Tracing.TraceInfo("Read userName value: " + this.domainName); } if (unitTestConfiguration.Contains("domainAdminUsername") == true) { this.adminUsername = (string)unitTestConfiguration["domainAdminUsername"]; Tracing.TraceInfo("Read userName value: " + this.adminUsername); } if (unitTestConfiguration.Contains("domainAdminPassword") == true) { this.adminPassword = (string)unitTestConfiguration["domainAdminPassword"]; Tracing.TraceInfo("Read userName value: " + this.adminPassword); } this.service = new AppsService(this.domainName, this.adminUsername + "@" + this.domainName, this.adminPassword); this.randomUserName = "******" + Guid.NewGuid().ToString(); this.randomEmailListName = "test_emaillist_" + Guid.NewGuid().ToString(); }
public BookThemAllSample(string domain, string admin, string password) { apps = new AppsService(domain, admin, password); calendar = new CalendarService("BookThemAll"); calendar.setUserCredentials(admin, password); this.admin = admin; }
private static void NicknameOperations(AppsService service) { // Create a new nickname. NicknameEntry insertedEntry = service.CreateNickname(testUserName, testNickname); Console.WriteLine("Created nickname '{0}' for user {1}", insertedEntry.Nickname.Name, insertedEntry.Login.UserName); // Retrieve the newly-created nickname. NicknameEntry entry = service.RetrieveNickname(testNickname); Console.WriteLine("Retrieved nickname {0}", entry.Nickname.Name); // Retrieve all nicknames for testUserName (really, just this one). NicknameFeed feed = service.RetrieveNicknames(testUserName); entry = feed.Entries[0] as NicknameEntry; Console.WriteLine("Retrieved nickname '{0}' for user {1}", entry.Nickname.Name, entry.Login.UserName); // Retrieve a page of nicknames. feed = service.RetrievePageOfNicknames(testNickname); entry = feed.Entries[0] as NicknameEntry; Console.WriteLine("Retrieved page of {0} nicknames, beginning with '{1}'", feed.Entries.Count, entry.Nickname.Name); // Retrieve the feed of all nicknames. feed = service.RetrieveAllNicknames(); entry = feed.Entries[0] as NicknameEntry; Console.WriteLine("Retrieved all {0} nicknames in the domain, beginning with '{1}'", feed.Entries.Count, entry.Nickname.Name); }
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); }
// Gmail data pull public DataTable Get_Gmail_Users(AppsService service, GmailUsers gusersyn, string table, LogFile log) { // nicknames will have to dealt with seperately DataTable returnvalue = new DataTable(); DataRow row; returnvalue.TableName = table; int i = 0; int count = 0; returnvalue.Columns.Add(gusersyn.User_StuID); returnvalue.Columns.Add(gusersyn.User_Fname); returnvalue.Columns.Add(gusersyn.User_Lname); try { UserFeed usersList = service.RetrieveAllUsers(); count = usersList.Entries.Count; //result.AppendText("domain " + service.Domain + "\n"); //result.AppendText("app name " + service.ApplicationName + "\n"); //result.AppendText("users " + count + "\n"); row = returnvalue.NewRow(); for (i = 0; i < count; i++) { UserEntry userEntry = usersList.Entries[i] as UserEntry; // special handling for userID due to % being an illegal character using _ as an escape character row[0] = (System.Web.HttpUtility.UrlDecode(userEntry.Login.UserName.ToString().Replace("_", "%"))); // decode names due to encoding to remove <>= characters row[1] = (System.Web.HttpUtility.UrlDecode(userEntry.Name.GivenName.ToString())); row[2] = (System.Web.HttpUtility.UrlDecode(userEntry.Name.FamilyName.ToString())); //userList.Add(userEntry.Login.UserName.ToString()); returnvalue.Rows.Add(row); row = returnvalue.NewRow(); } } catch (Exception ex) { log.addTrn("failed to pull gmail user list exception " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Error"); } return returnvalue; }
public DataTable Get_Gmail_Nicknames(AppsService service, GmailUsers gusersyn, string table, LogFile log) { // nicknames retrieval DataTable returnvalue = new DataTable(); DataRow row; returnvalue.TableName = table; int i = 0; int count = 0; string nickname = ""; returnvalue.Columns.Add(gusersyn.Writeback_primary_key); returnvalue.Columns.Add("nickname"); returnvalue.Columns.Add("Email"); try { NicknameFeed usersNicknameList = service.RetrieveAllNicknames(); count = usersNicknameList.Entries.Count; //result.AppendText("domain " + service.Domain + "\n"); //result.AppendText("app name " + service.ApplicationName + "\n"); //result.AppendText("users " + count + "\n"); row = returnvalue.NewRow(); for (i = 0; i < count; i++) { NicknameEntry userNicknameEntry = usersNicknameList.Entries[i] as NicknameEntry; // special handling for userID due to % being an illegal character using _ as an escape character row[0] = (System.Web.HttpUtility.UrlDecode(userNicknameEntry.Login.UserName.ToString().Replace("_", "%"))); // decode names due to encoding to remove <>= characters nickname = (System.Web.HttpUtility.UrlDecode(userNicknameEntry.Nickname.Name.ToString())); row[1] = nickname; row[2] = nickname + "@" + gusersyn.Admin_domain.ToString(); returnvalue.Rows.Add(row); row = returnvalue.NewRow(); } } catch (Exception ex) { log.addTrn("failed to pull gmail nickname list exception " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Error"); } return returnvalue; }
public string RemoveUserAlias(AppsService userService, string userAlias) { var _domain = userService.Domain.ToString(); char[] _delimiterChars = { '@' }; string[] _temp = userAlias.Split(_delimiterChars); var _aliasDomain = _temp[1]; var _token = userService.Groups.QueryClientLoginToken(); var _uri = new Uri("https://apps-apis.google.com/a/feeds/alias/2.0/" + _domain + "/" + userAlias); WebRequest _webRequest = WebRequest.Create(_uri); _webRequest.Method = "DELETE"; _webRequest.ContentType = "application/atom+xml; charset=UTF-8"; _webRequest.Headers.Add("Authorization: GoogleLogin auth=" + _token); string _post = ""; byte[] _bytes = Encoding.UTF8.GetBytes(_post); Stream _OS = null; _webRequest.ContentLength = _bytes.Length; _OS = _webRequest.GetRequestStream(); _OS.Write(_bytes, 0, _bytes.Length); WebResponse _webResponse = _webRequest.GetResponse(); if (_webResponse == null) { throw new Exception("WebResponse is null"); } StreamReader _SR = new StreamReader(_webResponse.GetResponseStream()); var _result = _SR.ReadToEnd().Trim(); return _result; }
public string RetriveUserAlias(string id, AppsService userService) { var _domain = userService.Domain.ToString(); char[] _delimiterChars = { '@' }; var _token = userService.Groups.QueryClientLoginToken(); var _uri = new Uri("https://apps-apis.google.com/a/feeds/alias/2.0/" + _domain + "?userEmail=" + id + "@" + _domain); WebRequest _webRequest = WebRequest.Create(_uri); _webRequest.Method = "GET"; _webRequest.ContentType = "application/atom+xml; charset=UTF-8"; _webRequest.Headers.Add("Authorization: GoogleLogin auth=" + _token); WebResponse _webResponse = _webRequest.GetResponse(); if (_webResponse == null) { throw new Exception("WebResponse is null"); } StreamReader _SR = new StreamReader(_webResponse.GetResponseStream()); var _result = _SR.ReadToEnd().Trim(); return _result; }
public string CreateOrganizationUnit(AppsService OrgUnitService, string OrgUnitName, string OrgUnitDescription, string OrgUnitParentOrgUnitPath, bool OrgUnitBlockInheritance) { return null; }
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"); } }
// TROUBLESHOOT TAB private void txt_trb_gmail_alias_submit_Click(object sender, EventArgs e) { // Setup local vars // From config files AppsService service = new AppsService(guserconfig.Admin_domain, guserconfig.Admin_user + "@" + guserconfig.Admin_domain, guserconfig.Admin_password); // Clear troubleshoot log tools.troubleshootLog.Clear(); // Attempt to trigger our method using the optional paramLog parameter tools.GetNewUserNickname( service, txt_trb_gmail_alias_studid.Text, txt_trb_gmail_alias_firstname.Text, txt_trb_gmail_alias_middlename.Text, txt_trb_gmail_alias_lastname.Text, 0, false ); // Show output on the screen txt_trb_output.Lines = tools.getTroubleShootLog(); }
// 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"; } }
private void button5_Click(object sender, EventArgs e) { //decodr.Text = encodr.Text.ToString().Replace("<", "%3c").Replace(">", "%3e").Replace("=", "%3d").Replace("%", "%25"); AppsService service = new AppsService("students.fhchs.edu", "*****@*****.**", "abc123"); //UserEntry gmailUser = service.RetrieveUser(encodr.Text.ToString()); //MessageBox.Show("base check dirt after content set dirty " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName); //gmailUser.Login.AgreedToTerms = true; //service.UpdateUser(gmailUser); //MessageBox.Show("base check dirt after content set dirty and update performed " + gmailUser.Login.AgreedToTerms.ToString() + " " + gmailUser.Login.UserName); SqlConnection sqlConn = new SqlConnection("Data Source=" + DBserver.Text + ";Initial Catalog=" + Catalog.Text + ";Integrated Security=SSPI;"); string user = ""; SqlCommand sqlComm = new SqlCommand("select FHC_test2_gmailnicknamestable.nickname, FHC_test2_gmailnicknamestable.soc_sec from FHC_test2_gmailnicknamestable where FHC_test2_gmailnicknamestable.nickname like '%.__.%'", sqlConn); // create the command object SqlDataReader r; sqlConn.Open(); try { r = sqlComm.ExecuteReader(); log.addTrn(sqlComm.CommandText.ToString(), "Query"); while(r.Read()) { user = (string)r[0]; try { user = user.Remove(user.IndexOf("@students")); } catch { } try { service.DeleteNickname(user); } catch { log.addTrn("deletiing failed " + user, "Transaction"); } log.addTrn("deleted nickname " + user, "Transaction"); } } catch (Exception ex) { log.addTrn("Failed SQL command " + sqlComm.CommandText.ToString() + " error " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Query"); } }
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); //} }
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(); }
private static void GroupOperations(AppsService service) { // Create a new group. AppsExtendedEntry insertedEntry = service.Groups.CreateGroup(testGroup, testGroup, testGroup,null); Console.WriteLine("Created new group '{0}'", insertedEntry.getPropertyByName("groupId" ).Value); // Retrieve the newly-created group. AppsExtendedEntry entry = service.Groups.RetrieveGroup(testGroup); Console.WriteLine("Retrieved group '{0}'", entry.getPropertyByName("groupId").Value); // Add Member To Group AppsExtendedEntry newMemberEntry = service.Groups.AddMemberToGroup(testUserName, testGroup); Console.WriteLine("User '{0}' was added as member to group '{1}'", newMemberEntry.getPropertyByName("memberId").Value, testGroup); // Add Owner to Group AppsExtendedEntry newOwnerEntry = service.Groups.AddOwnerToGroup(testUserName, testGroup); Console.WriteLine("User '{0}' was added as ownter to group '{1}'", newOwnerEntry.getPropertyByName("email").Value, testGroup); // Check if a User is a Group Member Console.WriteLine("Is User '{0}' member of group '{1}'? '{2}'", testUserName, testGroup, service.Groups.IsMember(testUserName, testGroup)); // Check if a User is a Group Member Console.WriteLine("Is User '{0}' owner of group '{1}'? '{2}'", testUserName, testGroup, service.Groups.IsOwner(testUserName, testGroup)); // Remove Member from Group service.Groups.RemoveMemberFromGroup(testUserName, testGroup); Console.WriteLine("User '{0}' was removed as member to group '{1}'", testUserName, testGroup); // Remove Owner from Group service.Groups.RemoveOwnerFromGroup(testUserName, testGroup); Console.WriteLine("User '{0}' was removed as ownter to group '{1}'", testUserName, testGroup); // Retreive all groups AppsExtendedFeed groupsFeed = service.Groups.RetrieveAllGroups(); Console.WriteLine("First Group from All groups: '{0}'", (groupsFeed.Entries[0] as AppsExtendedEntry).getPropertyByName("groupId").Value); }
public string GetCustomerId(AppsService CustIdService) { var Token = CustIdService.Groups.QueryClientLoginToken(); var uri = new Uri("https://apps-apis.google.com/a/feeds/customer/2.0/customerId"); WebRequest WebRequest = WebRequest.Create(uri); WebRequest.Method = "GET"; WebRequest.ContentType = "application/atom+xml; charset=UTF-8"; WebRequest.Headers.Add("Authorization: GoogleLogin auth=" + Token); WebResponse WebResponse = WebRequest.GetResponse(); if (WebResponse == null) { throw new Exception("WebResponse is null"); } StreamReader SR = new StreamReader(WebResponse.GetResponseStream()); var _Result = SR.ReadToEnd().Trim(); var Xml = new ParseXML(_Result); foreach (var x in Xml.ListFormat) { if (x.Name == "customerId") { CustomerId = x.Value; } } return CustomerId; }
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; }
public void NicknameUpdate(AppsService service, SqlDataReader nicknames, string usernameFieldName, string userNicknameField, LogFile log) { // updates nicknames in gmail from sql data reader containing user ids and nicknames // finds the user with the ID listed and returns all the nicknames for that user // iterates trhrough the nicknames and delets all those which do not mathch the nickname from the usernickname field // if the nickname from the usernickname field does not exist it will be created fro the user listed // // usernameFieldName userNicknameField // ------------------------------------ // ID | Nickname // ------------------------------------ // SB289312 | test.user // // int i = 0; int nicknamecount = 0; bool foundnickname = false; try { while (nicknames.Read()) { // get all nicknames for user who has the wrong nickname NicknameFeed userNicknames; userNicknames = service.RetrieveNicknames(nicknames[usernameFieldName].ToString()); // get the count so we can iterate over them\ nicknamecount = userNicknames.Entries.Count; // iterate and delete all nicknames that are not equal to the correct nickname for (i = 0; i < nicknamecount; i++) { try { NicknameEntry nicknameEntry = userNicknames.Entries[nicknamecount] as NicknameEntry; if (nicknameEntry.Nickname.Name.ToString() == nicknames[userNicknameField].ToString()) { foundnickname = true; } else { service.DeleteNickname(nicknameEntry.Nickname.Name.ToString()); log.addTrn("Deleting user nickname " + nicknameEntry.Nickname.Name.ToString(), "Transaction"); } } catch { log.addTrn("Error deleting user nickname " + nicknames[userNicknameField].ToString(), "Error"); } } // if the nickname is not found create the new nickname if (foundnickname == false) { try { service.CreateNickname(nicknames[usernameFieldName].ToString(), nicknames[userNicknameField].ToString()); log.addTrn("Creating user nickname " + nicknames[userNicknameField].ToString() + " for user " + nicknames[usernameFieldName].ToString(), "Transaction"); } catch { log.addTrn("Error adding user nickname " + nicknames[userNicknameField].ToString() + " for user " + nicknames[usernameFieldName].ToString(), "Error"); } } // reset all variables foundnickname = false; i = 0; nicknamecount = 0; } } catch (Exception ex) { log.addTrn("Issue updating nicknames datareader is null " + ex.Message.ToString() + "\n" + ex.StackTrace.ToString(), "Error"); } }
public string CreateUserAlias(string ID, AppsService userService, string userAlias) { var _domain = userService.Domain.ToString(); char[] _delimiterChars = { '@' }; string[] _temp = userAlias.Split(_delimiterChars); var _aliasDomain = _temp[1]; var _token = userService.Groups.QueryClientLoginToken(); var uri = new Uri("https://apps-apis.google.com/a/feeds/alias/2.0/" + _domain); WebRequest _webRequest = WebRequest.Create(uri); _webRequest.Method = "POST"; _webRequest.ContentType = "application/atom+xml; charset=UTF-8"; _webRequest.Headers.Add("Authorization: GoogleLogin auth=" + _token); string _post = "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'><apps:property name=\"aliasEmail\" value=\"" + userAlias + "\" /><apps:property name=\"userEmail\" value=\"" + ID + "@" + _domain + "\" /></atom:entry>"; byte[] _bytes = Encoding.UTF8.GetBytes(_post); Stream _OS = null; _webRequest.ContentLength = _bytes.Length; _OS = _webRequest.GetRequestStream(); _OS.Write(_bytes, 0, _bytes.Length); WebResponse _webResponse = _webRequest.GetResponse(); if (_webResponse == null) { throw new Exception("WebResponse is null"); } StreamReader SR = new StreamReader(_webResponse.GetResponseStream()); var _result = SR.ReadToEnd().Trim(); return _result; }
/* * 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(); } }
public string GetDomainFromAppService(AppsService userService) { string _domain = userService.Domain; return _domain; }
/// <summary> /// Create Google Apps /// </summary> /// <param name="username"></param> private void CreateUserAccount(string username) { if (Util.UserAccountIsExist(username)) return; else { string Email = Util.HashUserName(username).ToLower(); string First = username + "@HF"; string pwd = Util.getRandomPwd(); Google.GData.Apps.AppsService service = new Google.GData.Apps.AppsService("cga.com.cn", "*****@*****.**", "test2006"); service.CreateUser(Email, First, "HoldFast", pwd); System.Threading.Thread.Sleep(3000); /* while (service.RetrieveUser(Email).Login.UserName != Email) { System.Threading.Thread.Sleep(500); } */ Util.AddUserAccount(username, Email, First, "HoldFast", pwd); } }
public string RetrieveOU(AppsService UserService, string OuPath) { var Token = UserService.Groups.QueryClientLoginToken(); var OUService = new Dgc.GoogleAppService(); var CustId = OUService.GetCustomerId(UserService); var uri = new Uri("https://apps-apis.google.com/a/feeds/orgunit/2.0/" + CustId + "/"+OuPath); WebRequest WebRequest = WebRequest.Create(uri); WebRequest.Method = "GET"; WebRequest.ContentType = "application/atom+xml; charset=UTF-8"; WebRequest.Headers.Add("Authorization: GoogleLogin auth=" + Token); WebResponse WebResponse = WebRequest.GetResponse(); if (WebResponse == null) { throw new Exception("WebResponse is null"); } StreamReader SR = new StreamReader(WebResponse.GetResponseStream()); var _Result = SR.ReadToEnd().Trim(); return _Result; }
private static void CleanUp(AppsService service) { // Delete the group that was created service.Groups.DeleteGroup(testGroup); Console.WriteLine("Deleted group {0}", testGroup); // Delete the nickname that was created. service.DeleteNickname(testNickname); Console.WriteLine("Deleted nickname {0}", testNickname); // Delete the user that was created. service.DeleteUser(testUserName); Console.WriteLine("Deleted user {0}", testUserName); }
public void Init() { service = new AppsService("example.com", "admin", "password"); }
private static void RunSample(AppsService service) { try { // Demonstrate operations on user accounts. UserOperations(service); // Demonstrate operations on nicknames. NicknameOperations(service); // Demostrate operations on groups GroupOperations(service); // Clean up (delete the username, nickname and email list // that were created). CleanUp(service); } catch (AppsException a) { Console.WriteLine("A Google Apps error occurred."); Console.WriteLine(); Console.WriteLine("Error code: {0}", a.ErrorCode); Console.WriteLine("Invalid input: {0}", a.InvalidInput); Console.WriteLine("Reason: {0}", a.Reason); } }
protected override void ProcessRecord() { var _DgcGoogleAppsService = new Dgc.GoogleAppService(); var _Domain = _DgcGoogleAppsService.GetDomain(_AdminUser); try { var _UserService = new AppsService(_Domain, _AdminUser, _AdminPassword); WriteObject(_UserService); } catch (AppsException _Exception) { WriteObject(_Exception,true); } }
/// <summary> /// This console application demonstrates all the Google Apps /// Provisioning API calls. It accepts authentication information /// from the command-line and performs a series of create/ /// retrieve/update/delete operations on user accounts, nicknames, /// and email lists, as described in the comments of RunTests. /// </summary> /// <param name="args">Command-line arguments: args[0] is /// the domain, args[1] is the admin email address, and args[2] /// is the admin psasword. /// /// Example: AppsDemo example.com [email protected] my_password</param> public static void Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Syntax: AppsDemo <domain> <admin_email> <admin_password>"); } else { domain = args[0]; adminEmail = args[1]; adminPassword = args[2]; AppsService service = new AppsService(domain, adminEmail, adminPassword); RunSample(service); } }