public string GetFileSystemUrl(params string[] path) { FileSystemSection section = FileSystemSection.GetSection(); if (!section.Enable && !string.IsNullOrEmpty(section.Url)) { string[] args = new string[path.Length + 3]; args[0] = section.Url; args[1] = "/filesystem/"; Array.Copy(path, 0, args, 2, path.Length); args[args.Length - 1] = string.Concat(Utility.DefaultExt, "?token=", HttpUtility.UrlEncode(User.Identity.GetToken())); return(string.Concat(args)); } return(GetUrl("/filesystem/")); }
static FileSystem() { FileSystemSection section = FileSystemSection.GetSection(); ENABLE = section.Enable; PATH = section.Path; URL = section.Url; MARK = section.Mark; TEXT = section.Text; REGION = section.Region; WIDTH = section.Width; HEIGHT = section.Height; if (string.IsNullOrEmpty(PATH)) { PATH = Utility.UploadDir; } }
public void System(string type) { if (CheckRight()) { if (CheckPost(string.Concat("system_", type), new Action(() => { switch (type) { case "config": this["Config"] = new { Theme = Application.Settings.Theme, UrlMode = Application.Settings.UrlMode.ToString(), Management = Application.Settings.Management, Themes = Application.Settings.GetThemes(), WapDomain = Application.Settings.WapDomain, SubDomain = Application.Settings.SubDomain, DataProvider = Application.Settings.DataProvider, CacheMode = Application.Settings.CacheMode, CacheProvider = Application.Settings.CacheProvider, ResourcesUrl = Application.Settings.ResourcesUrl, PassportUrl = Application.Settings.PassportUrl }; this["Conns"] = WebConfigurationManager.ConnectionStrings; break; case "passport": this["Config"] = PassportSection.GetSection(); this["Conns"] = WebConfigurationManager.ConnectionStrings; break; case "captcha": this["Config"] = CaptchaSection.GetSection(); break; case "smscaptcha": this["Config"] = SMSCaptchaSection.GetSection(); break; case "filesystem": this["Config"] = FileSystemSection.GetSection(); break; case "email": this["Config"] = (SmtpSection)WebConfigurationManager.GetSection("system.net/mailSettings/smtp"); break; case "friendlink": this["Config"] = FriendLinkSection.GetSection(); break; case "robots": { string content = string.Empty; try { string file = Server.MapPath("~/robots.txt"); content = Encoding.UTF8.GetString(File.ReadAllBytes(file)); } catch (Exception) { } this["Robots"] = content; } break; case "sitemap": break; } }))) { switch (type) { case "site": { int i = 0; StringBuilder sb = new StringBuilder(); foreach (string key in Request.Form.Keys) { if (i++ > 0) { sb.Append(','); } sb.Append(string.Concat("\"", key, "\"=\"", HttpUtility.HtmlEncode(Request.Form[key]), "\"")); } try { File.WriteAllText(Server.MapPath(string.Concat(Utility.ConfigDir, "site.config")), string.Concat("$set(Site=array(", sb.ToString(), "))")); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } } break; case "config": { try { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); SiteSection ss = SiteSection.GetSection(config); ss.Theme = Request.Form["Theme"]; try { ss.UrlMode = (SiteUrlMode)int.Parse(Request.Form["UrlMode"]); } catch (Exception) { ss.UrlMode = SiteUrlMode.Rewrite; } ss.Management = Request.Form["Management"]; ss.WapDomain = Request.Form["WapDomain"]; ss.SubDomain = Request.Form["SubDomain"]; ss.DataProvider = Request.Form["DataProvider"]; try { ss.CacheMode = (CacheMode)int.Parse(Request.Form["CacheMode"]); } catch (Exception) { ss.CacheMode = CacheMode.Application; } ss.CacheProvider = Request.Form["CacheProvider"]; ss.ResourcesUrl = Request.Form["ResourcesUrl"]; ss.PassportUrl = Request.Form["PassportUrl"]; ss.WapPassportUrl = Request.Form["WapPassportUrl"]; config.Save(); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } } break; case "passport": { try { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); PassportSection section = PassportSection.GetSection(config); section.CookieName = Request.Form["CookieName"]; section.CookieDomain = Request.Form["CookieDomain"]; section.CookieIV = Request.Form["CookieIV"]; section.CookieKey = Request.Form["CookieKey"]; section.MaxInvalidPasswordAttempts = GetInt32Value(Request.Form["MaxInvalidPasswordAttempts"], Utility.PassportMaxInvalidPasswordAttempts); section.PasswordAnswerAttemptLockoutDuration = GetInt32Value(Request.Form["PasswordAnswerAttemptLockoutDuration"], Utility.PassportPasswordAnswerAttemptLockoutDuration); try { section.Level = (PassportLevel)int.Parse(Request.Form["Level"]); } catch (Exception) { section.Level = PassportLevel.Low; } section.VerifyMail = GetBooleanValue(Request.Form["VerifyMail"]); section.VerifyMobile = GetBooleanValue(Request.Form["VerifyMobile"]); section.LoginWithCaptcha = GetBooleanValue(Request.Form["LoginWithCaptcha"]); section.RegisterWithCaptcha = GetBooleanValue(Request.Form["RegisterWithCaptcha"]); section.DefaultApproved = GetBooleanValue(Request.Form["DefaultApproved"]); section.DataProvider = Request.Form["DataProvider"]; config.Save(); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } } break; case "cache": CacheProvider.Current.Clear(); SetResult(() => { WriteLog("CLEAR CACHE"); }); break; case "captcha": { try { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); CaptchaSection section = CaptchaSection.GetSection(config); section.Chars = Request.Form["Chars"]; section.CookiePrefix = Request.Form["CookiePrefix"]; section.CookieDomain = Request.Form["CookieDomain"]; section.DefaultWidth = GetInt32Value(Request.Form["DefaultWidth"], Utility.CaptchaDefaultWidth); section.DefaultHeight = GetInt32Value(Request.Form["DefaultHeight"], Utility.CaptchaDefaultHeight); section.DefaultCount = GetInt32Value(Request.Form["DefaultCount"], Utility.CaptchaDefaultCount); section.Expiration = GetInt32Value(Request.Form["Expiration"], Utility.CaptchaExpiration); config.Save(); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } } break; case "smscaptcha": { try { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); SMSCaptchaSection section = SMSCaptchaSection.GetSection(config); section.Chars = Request.Form["Chars"]; section.DefaultCount = GetInt32Value(Request.Form["DefaultCount"], Utility.SMSCaptchaDefaultCount); section.TimeSpan = GetInt32Value(Request.Form["TimeSpan"], Utility.SMSCaptchaTimeSpan); section.Expiration = GetInt32Value(Request.Form["Expiration"], Utility.SMSCaptchaExpiration); config.Save(); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } } break; case "filesystem": { try { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); FileSystemSection section = FileSystemSection.GetSection(config); section.Enable = Types.GetBooleanFromString(Request.Form["Enable"]); section.Path = Request.Form["Path"]; section.Url = Request.Form["Url"]; try { section.Mark = (ImageMarkType)int.Parse(Request.Form["Mark"]); } catch (Exception) { section.Mark = ImageMarkType.None; } section.Text = Request.Form["Text"]; section.Region = (ImageMarkRegion)int.Parse(Request.Form["Region"]); try { section.Width = int.Parse(Request.Form["Width"]); } catch (Exception) { section.Width = 0; } try { section.Height = int.Parse(Request.Form["Height"]); } catch (Exception) { section.Height = 0; } config.Save(); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } } break; case "email": try { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); SmtpSection section = (SmtpSection)config.GetSection("system.net/mailSettings/smtp"); section.From = Request.Form["UserName"]; section.Network.Host = Request.Form["Host"]; section.Network.Port = GetInt32Value(Request.Form["Port"], 25); section.Network.UserName = Request.Form["UserName"]; section.Network.Password = Request.Form["Password"]; section.Network.EnableSsl = GetBooleanValue(Request.Form["EnableSsl"]); config.Save(); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } break; case "friendlink": { try { System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); FriendLinkSection section = FriendLinkSection.GetSection(config); section.Enable = Types.GetBooleanFromString(Request.Form["Enable"]); section.Approved = Types.GetBooleanFromString(Request.Form["Approved"]); try { section.Mode = (FriendLinkMode)int.Parse(Request.Form["Mode"]); } catch (Exception) { section.Mode = FriendLinkMode.Text; } config.Save(); SetResult(() => { WritePostLog("MOD"); }); } catch (Exception ex) { SetResult(false, ex.Message); } } break; case "robots": try { string file = Server.MapPath("~/robots.txt"); File.WriteAllBytes(file, Encoding.UTF8.GetBytes(Request.Form["Robots"])); SetResult(() => { WritePostLog("SUB"); }); } catch (Exception ex) { SetResult(false, ex.Message); } break; case "sitemap": break; } } } }