diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index b37f552..d9bc155 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1810 \ No newline at end of file +1812 \ No newline at end of file diff --git a/Common/Config.cs b/Common/Config.cs index b34229b..d3b85bc 100644 --- a/Common/Config.cs +++ b/Common/Config.cs @@ -29,6 +29,8 @@ namespace FLocal.Common { public readonly string AdminUserName; + public readonly bool IsIndexingDisabled; + protected Config(NameValueCollection data) : base(data) { this.InitTime = DateTime.Now.ToLongTimeString(); this.mainConnection = new MySQLConnector.Connection(data["ConnectionString"], MySQLConnector.PostgresDBTraits.instance); @@ -40,6 +42,7 @@ namespace FLocal.Common { this.UploaderUrl = data["UploaderUrl"]; this.AdminUserName = data["AdminUserName"]; this.ActivityThreshold = TimeSpan.FromMinutes(int.Parse(data["ActivityThreshold"])); + this.IsIndexingDisabled = parseBool(data["DisableIndexing"]); } public static void Init(NameValueCollection data) { diff --git a/Core/Config.cs b/Core/Config.cs index 1acf2d3..2c895ad 100644 --- a/Core/Config.cs +++ b/Core/Config.cs @@ -52,5 +52,24 @@ namespace FLocal.Core { public virtual void Dispose() { } + protected static bool parseBool(string value) { + switch(value.ToLower().Trim()) { + case "1": + case "true": + case "on": + case "enabled": + case "yes": + return true; + case "0": + case "false": + case "off": + case "disabled": + case "no": + return false; + default: + throw new CriticalException("Cannot parse '" + value + "'"); + } + } + } } diff --git a/IISMainHandler/handlers/response/RobotsHandler.cs b/IISMainHandler/handlers/response/RobotsHandler.cs index 42e3d36..d3abe93 100644 --- a/IISMainHandler/handlers/response/RobotsHandler.cs +++ b/IISMainHandler/handlers/response/RobotsHandler.cs @@ -6,6 +6,7 @@ using System.Web; using System.Text.RegularExpressions; using System.IO; using FLocal.Core; +using FLocal.Common; namespace FLocal.IISHandler.handlers.response { class RobotsHandler : AbstractGetHandler { @@ -18,10 +19,12 @@ namespace FLocal.IISHandler.handlers.response { protected override IEnumerable getSpecificData(WebContext context) { context.httpresponse.ContentType = "text/plain"; - context.httpresponse.WriteLine("User-agent: *"); - context.httpresponse.WriteLine("Disallow: /"); - foreach(var subnet in context.remoteHost.matchingSubnets) { - context.httpresponse.WriteLine(subnet.ToString()); + if(Config.instance.IsIndexingDisabled) { + context.httpresponse.WriteLine("User-agent: *"); + context.httpresponse.WriteLine("Disallow: /"); + foreach(var subnet in context.remoteHost.matchingSubnets) { + context.httpresponse.WriteLine(subnet.ToString()); + } } throw new SkipXsltTransformException(); }