Changes to IIS70 provider, etc for changing PHP versions among installed versions. Mimics the behaviour of IIS PHP Manager and works with it, i.e. changes made in PHP Manager is visible in WSP and vice versa.
This commit is contained in:
parent
2d48b7fb33
commit
d7ac9fa36f
8 changed files with 266 additions and 44 deletions
|
@ -28,6 +28,8 @@
|
|||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.DirectoryServices;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
|
@ -280,7 +282,7 @@ namespace WebsitePanel.Providers.Web
|
|||
Name = settings[Constants.IntegratedAspNet40Pool].Trim()
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Populate Dedicated Application Pools
|
||||
// ASP.NET 1.1
|
||||
|
@ -711,9 +713,9 @@ namespace WebsitePanel.Providers.Web
|
|||
if (!String.IsNullOrEmpty(AspPath) && String.Equals(AspPath, processor, StringComparison.InvariantCultureIgnoreCase))
|
||||
virtualDir.AspInstalled = true;
|
||||
|
||||
// Detect whether PHP 5 scripting is enabled
|
||||
if (!String.IsNullOrEmpty(PhpExecutablePath) && String.Equals(PhpExecutablePath, processor, StringComparison.InvariantCultureIgnoreCase))
|
||||
virtualDir.PhpInstalled = PHP_5;
|
||||
//// Detect whether PHP 5 scripting is enabled (non fast_cgi)
|
||||
if (PhpMode != Constants.PhpMode.FastCGI && !String.IsNullOrEmpty(PhpExecutablePath) && String.Equals(PhpExecutablePath, processor, StringComparison.InvariantCultureIgnoreCase))
|
||||
virtualDir.PhpInstalled = PHP_5;
|
||||
|
||||
// Detect whether PHP 4 scripting is enabled
|
||||
if (!String.IsNullOrEmpty(Php4Path) && String.Equals(Php4Path, processor, StringComparison.InvariantCultureIgnoreCase))
|
||||
|
@ -727,7 +729,18 @@ namespace WebsitePanel.Providers.Web
|
|||
if (!String.IsNullOrEmpty(PerlPath) && String.Equals(PerlPath, processor, StringComparison.InvariantCultureIgnoreCase))
|
||||
virtualDir.PerlInstalled = true;
|
||||
}
|
||||
|
||||
|
||||
// Detect PHP 5 Fast_cgi version(s)
|
||||
var activePhp5Handler = GetActivePhpHandlerName(srvman, virtualDir);
|
||||
if (!string.IsNullOrEmpty(activePhp5Handler))
|
||||
{
|
||||
virtualDir.PhpInstalled = PHP_5 + "|" + activePhp5Handler;
|
||||
var versions = GetPhpVersions(srvman, virtualDir);
|
||||
// This versionstring is used in UI to view and change php5 version.
|
||||
var versionString = string.Join("|", versions.Select(v => v.HandlerName + ";" + v.Version).ToArray());
|
||||
virtualDir.Php5VersionsInstalled = versionString;
|
||||
}
|
||||
|
||||
//
|
||||
string fqPath = virtualDir.FullQualifiedPath;
|
||||
if (!fqPath.EndsWith(@"/"))
|
||||
|
@ -865,32 +878,63 @@ namespace WebsitePanel.Providers.Web
|
|||
#endregion
|
||||
|
||||
#region PHP 5 script mappings
|
||||
if (!String.IsNullOrEmpty(PhpExecutablePath) && File.Exists(PhpExecutablePath))
|
||||
{
|
||||
if (virtualDir.PhpInstalled == PHP_5)
|
||||
{
|
||||
switch (PhpMode)
|
||||
{
|
||||
case Constants.PhpMode.FastCGI:
|
||||
handlersSvc.AddScriptMaps(virtualDir, PHP_EXTENSIONS,
|
||||
PhpExecutablePath, Constants.HandlerAlias.PHP_FASTCGI, Constants.FastCgiModule);
|
||||
break;
|
||||
case Constants.PhpMode.CGI:
|
||||
handlersSvc.AddScriptMaps(virtualDir, PHP_EXTENSIONS,
|
||||
PhpExecutablePath, Constants.HandlerAlias.PHP_CGI, Constants.CgiModule);
|
||||
break;
|
||||
case Constants.PhpMode.ISAPI:
|
||||
handlersSvc.AddScriptMaps(virtualDir, PHP_EXTENSIONS,
|
||||
PhpExecutablePath, Constants.HandlerAlias.PHP_ISAPI, Constants.IsapiModule);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
handlersSvc.RemoveScriptMaps(virtualDir, PHP_EXTENSIONS, PhpExecutablePath);
|
||||
}
|
||||
}
|
||||
//
|
||||
if (virtualDir.PhpInstalled.StartsWith(PHP_5))
|
||||
{
|
||||
if (PhpMode == Constants.PhpMode.FastCGI && virtualDir.PhpInstalled.Contains('|'))
|
||||
{
|
||||
var path = PhpExecutablePath;
|
||||
var args = virtualDir.PhpInstalled.Split('|');
|
||||
if (args.Count() > 1)
|
||||
{
|
||||
// Handler name is present, let us try to find the corresponding path to executable
|
||||
var phpVersion = GetPhpVersions(virtualDir).SingleOrDefault(p => p.HandlerName == args[1]);
|
||||
if (phpVersion != null)
|
||||
{
|
||||
path = phpVersion.ExecutionPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(path) && File.Exists(path))
|
||||
{
|
||||
handlersSvc.CopyInheritedHandlers(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath);
|
||||
handlersSvc.MoveHandlerToTop(args[1], ((WebSite) virtualDir).SiteId, virtualDir.VirtualPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.IsNullOrEmpty(PhpExecutablePath) && File.Exists(PhpExecutablePath))
|
||||
{
|
||||
switch (PhpMode)
|
||||
{
|
||||
case Constants.PhpMode.FastCGI:
|
||||
handlersSvc.AddScriptMaps(virtualDir, PHP_EXTENSIONS,
|
||||
PhpExecutablePath, Constants.HandlerAlias.PHP_FASTCGI, Constants.FastCgiModule);
|
||||
break;
|
||||
case Constants.PhpMode.CGI:
|
||||
handlersSvc.AddScriptMaps(virtualDir, PHP_EXTENSIONS,
|
||||
PhpExecutablePath, Constants.HandlerAlias.PHP_CGI, Constants.CgiModule);
|
||||
break;
|
||||
case Constants.PhpMode.ISAPI:
|
||||
handlersSvc.AddScriptMaps(virtualDir, PHP_EXTENSIONS,
|
||||
PhpExecutablePath, Constants.HandlerAlias.PHP_ISAPI, Constants.IsapiModule);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PhpMode == Constants.PhpMode.FastCGI && GetPhpVersions(virtualDir).Any())
|
||||
{
|
||||
// Don't erase handler mappings, if we do, the virtualDir cannot see and choose what version of PHP to run later
|
||||
}
|
||||
else
|
||||
{
|
||||
handlersSvc.RemoveScriptMaps(virtualDir, PHP_EXTENSIONS, PhpExecutablePath);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
#endregion
|
||||
|
||||
#region PHP 4 script mappings (IsapiModule only)
|
||||
|
@ -4437,5 +4481,59 @@ namespace WebsitePanel.Providers.Web
|
|||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Php Management
|
||||
|
||||
protected PhpVersion[] GetPhpVersions(ServerManager srvman, WebVirtualDirectory virtualDir)
|
||||
{
|
||||
var config = srvman.GetWebConfiguration(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath);
|
||||
//var config = srvman.GetApplicationHostConfiguration();
|
||||
var handlersSection = config.GetSection(Constants.HandlersSection);
|
||||
|
||||
var result = new List<PhpVersion>();
|
||||
|
||||
// Loop through available maps and fill installed processors
|
||||
foreach (var handler in handlersSection.GetCollection())
|
||||
{
|
||||
if (string.Equals(handler["path"].ToString(), "*.php", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var executable = handler["ScriptProcessor"].ToString().Split('|')[0];
|
||||
if (string.Equals(handler["Modules"].ToString(), "FastCgiModule", StringComparison.OrdinalIgnoreCase) && File.Exists(executable))
|
||||
{
|
||||
var handlerName = handler["Name"].ToString();
|
||||
result.Add(new PhpVersion() {HandlerName = handlerName, Version = GetPhpExecutableVersion(executable), ExecutionPath = handler["ScriptProcessor"].ToString()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
protected PhpVersion[] GetPhpVersions(WebVirtualDirectory virtualDir)
|
||||
{
|
||||
using (var srvman = new ServerManager())
|
||||
{
|
||||
return GetPhpVersions(srvman, virtualDir);
|
||||
}
|
||||
}
|
||||
|
||||
protected string GetActivePhpHandlerName(ServerManager srvman, WebVirtualDirectory virtualDir)
|
||||
{
|
||||
var config = srvman.GetWebConfiguration(((WebSite)virtualDir).SiteId, virtualDir.VirtualPath);
|
||||
var handlersSection = config.GetSection(Constants.HandlersSection);
|
||||
|
||||
// Find first handler for *.php
|
||||
return (from handler in handlersSection.GetCollection()
|
||||
where string.Equals(handler["path"].ToString(), "*.php", StringComparison.OrdinalIgnoreCase) && string.Equals(handler["Modules"].ToString(), "FastCgiModule", StringComparison.OrdinalIgnoreCase)
|
||||
select handler["name"].ToString()
|
||||
).FirstOrDefault();
|
||||
}
|
||||
|
||||
private static string GetPhpExecutableVersion(string phpexePath)
|
||||
{
|
||||
return FileVersionInfo.GetVersionInfo(phpexePath).ProductVersion;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue