IndexingDisabled config setting implemented

main
Inga 🏳‍🌈 14 years ago
parent a8d87058bc
commit 29df0e492b
  1. 2
      Builder/IISMainHandler/build.txt
  2. 3
      Common/Config.cs
  3. 19
      Core/Config.cs
  4. 3
      IISMainHandler/handlers/response/RobotsHandler.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) {

@ -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 + "'");
}
}
}
}

@ -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<FLocal.Common.URL.Robots> {
@ -18,11 +19,13 @@ namespace FLocal.IISHandler.handlers.response {
protected override IEnumerable<System.Xml.Linq.XElement> getSpecificData(WebContext context) {
context.httpresponse.ContentType = "text/plain";
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();
}

Loading…
Cancel
Save