Skip to content

Instantly share code, notes, and snippets.

@andy-uq
Created July 24, 2014 21:51
Show Gist options
  • Save andy-uq/ef6908f850495b867d63 to your computer and use it in GitHub Desktop.
Save andy-uq/ef6908f850495b867d63 to your computer and use it in GitHub Desktop.
Umbraco Security Patch
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace PatchLiveServer
{
class Program
{
static void Main(string[] args)
{
var root = args[0];
foreach (var umbraco in GetUmbracoFrom(root))
{
DeleteInstallDirectory(umbraco);
DeleteFiles(umbraco);
ReplaceProxyHtml(umbraco);
}
}
// Define other methods and classes here
static void DeleteInstallDirectory(string umbracoRoot)
{
var path = Path.Combine(umbracoRoot, "/install");
var directoryInfo = new DirectoryInfo(path);
if (directoryInfo.Exists)
{
directoryInfo.Delete(recursive:true);
Console.WriteLine("Removed {0}", directoryInfo.FullName);
}
}
static void DeleteFiles(string umbracoRoot)
{
DeleteFile(umbracoRoot, "config/splashes/booting.aspx");
DeleteFile(umbracoRoot, "umbraco/dashboard/Swfs/AIRInstallBadge.swf");
}
private static void DeleteFile(string umbracoRoot, string fileName)
{
var path = Path.Combine(umbracoRoot, fileName);
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
fileInfo.Delete();
Console.WriteLine("Deleted {0}", fileInfo.FullName);
}
}
static void ReplaceProxyHtml(string umbracoRoot)
{
var path = Path.Combine(umbracoRoot, @"umbraco/developer/Packages/proxy.htm");
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
File.Copy(@"proxy.htm", fileInfo.FullName, overwrite:true);
Console.WriteLine("Replace {0}", fileInfo.FullName);
}
}
static IEnumerable<string> GetUmbracoFrom(string path)
{
var results = new List<string>();
var directory = new DirectoryInfo(path);
if (directory.Name == "build")
return Enumerable.Empty<string>();
var contents = directory.GetFiles();
if (contents.Any(x => x.Extension == ".csproj" || x.Name.Equals("web.config", StringComparison.OrdinalIgnoreCase)))
{
var subDir = directory.GetDirectories();
if (subDir.Any(d => d.Name.Equals("umbraco", StringComparison.OrdinalIgnoreCase)) && subDir.Any(d => d.Name.Equals("umbraco_client", StringComparison.OrdinalIgnoreCase)))
{
return new[] { directory.FullName };
}
return Enumerable.Empty<string>();
}
foreach (var subDir in directory.GetDirectories())
{
results.AddRange(GetUmbracoFrom(subDir.FullName));
}
return results;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment