public virtual string AddSite(StatsSite site) { // generate unique SiteID //int iSiteId = site.Name.GetHashCode(); //if (iSiteId < 0) // iSiteId *= -1; //string siteId = iSiteId.ToString(); // create logs folder if not exists //if (!FileUtils.DirectoryExists(site.LogDirectory)) // FileUtils.CreateDirectory(site.LogDirectory); // add site SiteAdmin stAdmin = new SiteAdmin(); PrepareProxy(stAdmin); if (site.Users == null || site.Users.Length == 0) { throw new Exception("At least one user (site owner) should be specified when creating new statistics site"); } string ownerUsername = site.Users[0].Username.ToLower(); GenericResult1 result = stAdmin.AddSite(Username, Password, site.Users[0].Username, site.Users[0].Password, site.Users[0].FirstName, site.Users[0].LastName, ServerId, 0, site.Name, site.LogDirectory, LogFormat, LogWildcard, LogDeleteDays, SmarterLogsPath, SmarterLogDeleteMonths, "", "", TimeZoneId); if (!result.Result) { throw new Exception("Error creating statistics site: " + result.Message); } string siteId = GetSiteId(site.Name); int iSiteId = Int32.Parse(siteId); // add other users UserAdmin usrAdmin = new UserAdmin(); PrepareProxy(usrAdmin); foreach (StatsUser user in site.Users) { if (user.Username.ToLower() != ownerUsername) { // add user GenericResult2 r = usrAdmin.AddUser(Username, Password, iSiteId, user.Username, user.Password, user.FirstName, user.LastName, user.IsAdmin); if (!r.Result) { throw new Exception("Error adding site user: " + r.Message); } } } return(siteId); }
public virtual void DeleteSite(string siteId) { // delete site SiteAdmin stAdmin = new SiteAdmin(); PrepareProxy(stAdmin); int sid = Int32.Parse(siteId); GenericResult1 result = stAdmin.DeleteSite(Username, Password, sid, true); if (!result.Result) { throw new Exception("Error deleting statistics site: " + result.Message); } }
public override void CreateAccount(MailAccount mailbox) { try { svcUserAdmin users = new svcUserAdmin(); PrepareProxy(users); GenericResult1 result = users.AddUser(AdminUsername, AdminPassword, mailbox.Name, mailbox.Password, GetDomainName(mailbox.Name), mailbox.FirstName, mailbox.LastName, false //domain admin is false ); if (!result.Result) { throw new Exception(result.Message); } // set forwarding settings result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword, mailbox.Name, mailbox.DeleteOnForward, (mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : "")); if (!result.Result) { throw new Exception(result.Message); } // set additional settings result = users.SetRequestedUserSettings(AdminUsername, AdminPassword, mailbox.Name, new string[] { "isenabled=" + mailbox.Enabled.ToString(), "maxsize=" + mailbox.MaxMailboxSize.ToString(), "passwordlocked=" + mailbox.PasswordLocked.ToString(), "replytoaddress=" + (mailbox.ReplyTo != null ? mailbox.ReplyTo : ""), "signature=" + (mailbox.Signature != null ? mailbox.Signature : ""), "spamforwardoption=none" }); if (!result.Result) { throw new Exception(result.Message); } // set autoresponder settings result = users.UpdateUserAutoResponseInfo(AdminUsername, AdminPassword, mailbox.Name, mailbox.ResponderEnabled, (mailbox.ResponderSubject != null ? mailbox.ResponderSubject : ""), (mailbox.ResponderMessage != null ? mailbox.ResponderMessage : "")); if (!result.Result) { throw new Exception(result.Message); } } catch (Exception ex) { throw new Exception("Could not create mailbox", ex); } }
public override void UpdateAccount(MailAccount mailbox) { try { //get original account MailAccount account = GetAccount(mailbox.Name); svcUserAdmin users = new svcUserAdmin(); PrepareProxy(users); string strPassword = mailbox.Password; //Don't change password. Get it from mail server. if (!mailbox.ChangePassword) { strPassword = account.Password; } GenericResult1 result = users.UpdateUser(AdminUsername, AdminPassword, mailbox.Name, strPassword, mailbox.FirstName, mailbox.LastName, account.IsDomainAdmin ); if (!result.Result) { throw new Exception(result.Message); } // set forwarding settings result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword, mailbox.Name, mailbox.DeleteOnForward, (mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : "")); if (!result.Result) { throw new Exception(result.Message); } // set additional settings result = users.SetRequestedUserSettings(AdminUsername, AdminPassword, mailbox.Name, new string[] { "isenabled=" + mailbox.Enabled.ToString(), "maxsize=" + mailbox.MaxMailboxSize.ToString(), "passwordlocked=" + mailbox.PasswordLocked.ToString(), "replytoaddress=" + (mailbox.ReplyTo != null ? mailbox.ReplyTo : ""), "signature=" + (mailbox.Signature != null ? mailbox.Signature : ""), "spamforwardoption=none" }); if (!result.Result) { throw new Exception(result.Message); } // set autoresponder settings result = users.UpdateUserAutoResponseInfo(AdminUsername, AdminPassword, mailbox.Name, mailbox.ResponderEnabled, (mailbox.ResponderSubject != null ? mailbox.ResponderSubject : ""), (mailbox.ResponderMessage != null ? mailbox.ResponderMessage : "")); if (!result.Result) { throw new Exception(result.Message); } } catch (Exception ex) { throw new Exception("Could not update mailbox", ex); } }
public virtual void UpdateSite(StatsSite site) { // update site SiteAdmin stAdmin = new SiteAdmin(); PrepareProxy(stAdmin); int siteId = Int32.Parse(site.SiteId); // get original site SiteInfoResult siteResult = stAdmin.GetSite(Username, Password, siteId); if (siteResult.Site == null) { return; } SiteInfo origSite = siteResult.Site; // update site with only required properties GenericResult1 result = stAdmin.UpdateSite(Username, Password, siteId, site.Name, origSite.LogDirectory, origSite.LogFormat, origSite.LogWildcard, origSite.LogDaysBeforeDelete, origSite.SmarterLogDirectory, origSite.SmarterLogMonthsBeforeDelete, origSite.ExportPath, origSite.ExportPathURL, origSite.TimeZoneID); if (!result.Result) { throw new Exception("Error updating statistics site: " + result.Message); } // update site users UserAdmin usrAdmin = new UserAdmin(); PrepareProxy(usrAdmin); // get original users if (site.Users != null) { List <string> origUsers = new List <string>(); List <string> newUsers = new List <string>(); string ownerUsername = null; UserInfoResultArray usrResult = usrAdmin.GetUsers(Username, Password, siteId); foreach (UserInfo user in usrResult.user) { // add to original users origUsers.Add(user.UserName.ToLower()); // remember owner (he can't be deleted) if (user.IsSiteOwner) { ownerUsername = user.UserName.ToLower(); } } // add, update users foreach (StatsUser user in site.Users) { if (!origUsers.Contains(user.Username.ToLower())) { // add user GenericResult2 r = usrAdmin.AddUser(Username, Password, siteId, user.Username, user.Password, user.FirstName, user.LastName, user.IsAdmin); if (!r.Result) { throw new Exception("Error adding site user: "******"Error updating site user: " + r.Message); } } // add to new users list newUsers.Add(user.Username.ToLower()); } // delete users foreach (string username in origUsers) { if (!newUsers.Contains(username) && username != ownerUsername) { // delete user GenericResult2 r = usrAdmin.DeleteUser(Username, Password, siteId, username); } } } }