2013-02-03 05:06:11 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
using umbraco;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Install
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class FilePermissionHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
internal static readonly string[] PermissionDirs = { SystemDirectories.Css, SystemDirectories.Config, SystemDirectories.Data, SystemDirectories.Media, SystemDirectories.Masterpages, SystemDirectories.Xslt, SystemDirectories.UserControls, SystemDirectories.Preview };
|
|
|
|
|
|
internal static readonly string[] PermissionFiles = { };
|
|
|
|
|
|
internal static readonly string[] PackagesPermissionsDirs = { SystemDirectories.Bin, SystemDirectories.Umbraco, SystemDirectories.UserControls, SystemDirectories.Packages };
|
|
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
public static bool RunFilePermissionTestSuite(out Dictionary<string, List<string>> errorReport)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport = new Dictionary<string, List<string>>();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
List<string> errors;
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (TestDirectories(PermissionDirs, out errors) == false)
|
|
|
|
|
|
errorReport["Folder creation failed"] = errors.ToList();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (TestDirectories(PackagesPermissionsDirs, out errors) == false)
|
|
|
|
|
|
errorReport["File writing for packages failed"] = errors.ToList();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (TestFiles(PermissionFiles, out errors) == false)
|
|
|
|
|
|
errorReport["File writing failed"] = errors.ToList();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (TestContentXml(out errors) == false)
|
|
|
|
|
|
errorReport["Cache file writing failed"] = errors.ToList();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (TestFolderCreation(SystemDirectories.Media, out errors) == false)
|
|
|
|
|
|
errorReport["Media folder creation failed"] = errors.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return errorReport.Any() == false;
|
2013-02-03 05:06:11 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
public static bool TestDirectories(string[] directories, out List<string> errorReport)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport = new List<string>();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
bool succes = true;
|
2015-07-16 15:29:46 +02:00
|
|
|
|
foreach (string dir in directories)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2015-07-16 15:29:46 +02:00
|
|
|
|
if (Directory.Exists(dir) == false) continue;
|
|
|
|
|
|
|
2013-02-03 05:06:11 +06:00
|
|
|
|
bool result = SaveAndDeleteFile(IOHelper.MapPath(dir + "/configWizardPermissionTest.txt"));
|
|
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (result == false)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
|
|
|
|
|
succes = false;
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport.Add(dir);
|
2013-02-03 05:06:11 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return succes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
public static bool TestFiles(string[] files, out List<string> errorReport)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport = new List<string>();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
bool succes = true;
|
2016-06-13 17:42:05 +02:00
|
|
|
|
foreach (string file in files)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
|
|
|
|
|
bool result = OpenFileForWrite(IOHelper.MapPath(file));
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (result == false)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport.Add(file);
|
2013-02-03 05:06:11 +06:00
|
|
|
|
succes = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return succes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
public static bool TestFolderCreation(string folder, out List<string> errorReport)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport = new List<string>();
|
2013-02-03 05:06:11 +06:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string tempDir = IOHelper.MapPath(folder + "/testCreatedByConfigWizard");
|
|
|
|
|
|
Directory.CreateDirectory(tempDir);
|
|
|
|
|
|
Directory.Delete(tempDir);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport.Add(folder);
|
2013-02-03 05:06:11 +06:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-01 16:57:32 +11:00
|
|
|
|
public static bool TestContentXml(out List<string> errorReport)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport = new List<string>();
|
|
|
|
|
|
// Test creating/saving/deleting a file in the same location as the content xml file
|
|
|
|
|
|
// NOTE: We cannot modify the xml file directly because a background thread is responsible for
|
|
|
|
|
|
// that and we might get lock issues.
|
2013-02-03 05:06:11 +06:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2015-07-07 11:24:28 +02:00
|
|
|
|
var xmlFile = content.GetUmbracoXmlDiskFileName() + ".tmp";
|
2015-04-01 16:57:32 +11:00
|
|
|
|
SaveAndDeleteFile(xmlFile);
|
2013-02-03 05:06:11 +06:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2015-04-01 16:57:32 +11:00
|
|
|
|
errorReport.Add(SystemFiles.ContentCacheXml);
|
2013-02-03 05:06:11 +06:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static bool SaveAndDeleteFile(string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
//first check if the directory of the file exists, and if not try to create that first.
|
|
|
|
|
|
FileInfo fi = new FileInfo(file);
|
2015-04-01 16:57:32 +11:00
|
|
|
|
if (fi.Directory.Exists == false)
|
2013-02-03 05:06:11 +06:00
|
|
|
|
{
|
|
|
|
|
|
fi.Directory.Create();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(file,
|
|
|
|
|
|
"This file has been created by the umbraco configuration wizard. It is safe to delete it!");
|
|
|
|
|
|
File.Delete(file);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static bool OpenFileForWrite(string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
File.AppendText(file).Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|