Пример #1
0
        public virtual StatsSite GetSite(string siteId)
        {
            string configFileName = ConfigFileName.Replace("[DOMAIN_NAME]", siteId);
            string configFilePath = Path.Combine(AwStatsFolder, configFileName);

            if (!File.Exists(configFilePath))
            {
                return(null);
            }

            StatsSite site = new StatsSite();

            site.Name   = siteId;
            site.SiteId = siteId;

            // process stats URL
            string url = null;

            if (!String.IsNullOrEmpty(StatisticsUrl))
            {
                url = StringUtils.ReplaceStringVariable(StatisticsUrl, "domain_name", site.Name);
                url = StringUtils.ReplaceStringVariable(url, "site_id", siteId);
            }

            site.StatisticsUrl = url;

            return(site);
        }
Пример #2
0
 public string AddSite(StatsSite site)
 {
     object[] results = this.Invoke("AddSite", new object[] {
         site
     });
     return((string)(results[0]));
 }
Пример #3
0
        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);
        }
Пример #4
0
 /// <remarks/>
 public void UpdateSiteAsync(StatsSite site, object userState)
 {
     if ((this.UpdateSiteOperationCompleted == null))
     {
         this.UpdateSiteOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateSiteOperationCompleted);
     }
     this.InvokeAsync("UpdateSite", new object[] {
         site
     }, this.UpdateSiteOperationCompleted, userState);
 }
Пример #5
0
 public virtual void UpdateSite(StatsSite site)
 {
     // nope
 }
Пример #6
0
        public virtual string AddSite(StatsSite site)
        {
            // check for AWStats folder existance
            string awFolder = AwStatsFolder;

            if (!Directory.Exists(awFolder))
            {
                // try to create directory
                Directory.CreateDirectory(awFolder);
            }

            // create a new configuration file
            string configFileName = ConfigFileName;

            // ...and substitute variables
            configFileName = configFileName.Replace("[DOMAIN_NAME]", site.Name);
            string configFilePath = Path.Combine(awFolder, configFileName);

            // check if the file already exists
            if (File.Exists(configFilePath))
            {
                return(site.Name);    // nothing to create
            }

            // get config file template
            string configFileTemplate = ConfigFileTemplate;

            if (!String.IsNullOrEmpty(ConfigFileTemplatePath) &&
                File.Exists(ConfigFileTemplatePath))
            {
                // read template from file
                StreamReader reader = new StreamReader(ConfigFileTemplatePath);
                configFileTemplate = reader.ReadToEnd();
                reader.Close();
            }

            // ...and substitute variables
            configFileTemplate = configFileTemplate.Replace("[DOMAIN_NAME]", site.Name);
            configFileTemplate = site.DomainAliases.Length == 0 ? configFileTemplate.Replace("[DOMAIN_ALIASES]", "localhost 127.0.0.1") : configFileTemplate.Replace("[DOMAIN_ALIASES]", String.Join(" ", site.DomainAliases));
            configFileTemplate = configFileTemplate.Replace("[LOGS_FOLDER]", site.LogDirectory);

            // create config file
            StreamWriter writer = new StreamWriter(configFilePath);

            writer.Write(configFileTemplate);
            writer.Close();

            // add line to the batch file
            string batchFilePath = Path.Combine(awFolder, BatchFileName);

            // create file if not exists
            if (!File.Exists(batchFilePath))
            {
                writer = new StreamWriter(batchFilePath);
                writer.Close();
            }

            // read batch file
            List <string> lines = LoadBatchFile(batchFilePath);

            // check if the record is already added
            bool exists = false;

            foreach (string line in lines)
            {
                if (line.IndexOf("=" + site.Name) != -1)
                {
                    exists = true;
                    break;
                }
            }

            if (!exists)
            {
                // add new line to the batch
                string line = BatchLineTemplate;
                line = line.Replace("[DOMAIN_NAME]", site.Name);

                lines.Add(line);

                // save batch file
                SaveBatchFile(batchFilePath, lines);
            }

            return(site.Name);
        }
Пример #7
0
 /// <remarks/>
 public void UpdateSiteAsync(StatsSite site)
 {
     this.UpdateSiteAsync(site, null);
 }
Пример #8
0
 /// <remarks/>
 public System.IAsyncResult BeginUpdateSite(StatsSite site, System.AsyncCallback callback, object asyncState)
 {
     return(this.BeginInvoke("UpdateSite", new object[] {
         site
     }, callback, asyncState));
 }
Пример #9
0
 public void UpdateSite(StatsSite site)
 {
     this.Invoke("UpdateSite", new object[] {
         site
     });
 }
Пример #10
0
 /// <remarks/>
 public void AddSiteAsync(StatsSite site)
 {
     this.AddSiteAsync(site, null);
 }
Пример #11
0
        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);
                    }
                }
            }
        }
Пример #12
0
        public virtual StatsSite GetSite(string siteId)
        {
            SiteAdmin stAdmin = new SiteAdmin();

            PrepareProxy(stAdmin);

            int            sid    = Int32.Parse(siteId);
            SiteInfoResult result = stAdmin.GetSite(Username, Password, sid);

            if (result.Site == null)
            {
                return(null);
            }

            StatsSite site = new StatsSite();

            site.Name          = result.Site.DomainName;
            site.ExportPath    = result.Site.ExportPath;
            site.ExportPathUrl = result.Site.ExportPathURL;
            site.LogDirectory  = result.Site.LogDirectory;
            site.TimeZoneId    = TimeZoneId;
            site.Status        = result.Site.SiteStatus;

            // process stats URL
            string url = null;

            if (!String.IsNullOrEmpty(StatisticsUrl))
            {
                url = StringUtils.ReplaceStringVariable(StatisticsUrl, "domain_name", site.Name);
                url = StringUtils.ReplaceStringVariable(url, "site_id", siteId);
            }

            // get site users
            UserAdmin usrAdmin = new UserAdmin();

            PrepareProxy(usrAdmin);

            UserInfoResultArray usrResult = usrAdmin.GetUsers(Username, Password, sid);

            if (usrResult.user != null)
            {
                site.Users = new StatsUser[usrResult.user.Length];
                for (int i = 0; i < site.Users.Length; i++)
                {
                    site.Users[i]           = new StatsUser();
                    site.Users[i].Username  = usrResult.user[i].UserName;
                    site.Users[i].Password  = usrResult.user[i].Password;
                    site.Users[i].FirstName = usrResult.user[i].FirstName;
                    site.Users[i].LastName  = usrResult.user[i].LastName;
                    site.Users[i].IsAdmin   = usrResult.user[i].IsAdmin;
                    site.Users[i].IsOwner   = usrResult.user[i].IsSiteOwner;
                }

                if (site.Users.Length > 0 && !String.IsNullOrEmpty(url))
                {
                    url = StringUtils.ReplaceStringVariable(url, "username", site.Users[0].Username);
                    url = StringUtils.ReplaceStringVariable(url, "password", site.Users[0].Password);
                }
            }

            site.StatisticsUrl = url;

            return(site);
        }