internal void Parse() { if (String.IsNullOrEmpty(FileName)) { throw new InvalidOperationException(); } string extensionDir = String.Empty; using (StreamReader reader = new StreamReader(FileName)) { foreach (object o in PHPIniFile.ParseIniFile(reader)) { PHPIniSetting directive = o as PHPIniSetting; if (directive != null) { Settings.Add(directive); RawEntries.Add(directive); // Get the path to the extension directory - this will be used later if (String.Equals(directive.Name, "extension_dir", StringComparison.OrdinalIgnoreCase)) { extensionDir = directive.GetTrimmedValue(); } } else { PHPIniExtension extension = o as PHPIniExtension; if (extension != null) { Extensions.Add(extension); RawEntries.Add(extension); } else { PHPIniBase entry = o as PHPIniBase; if (entry != null) { RawEntries.Add(entry); } } } } } if (String.IsNullOrEmpty(extensionDir) || !Path.IsPathRooted(extensionDir)) { extensionDir = Path.Combine(Path.GetDirectoryName(FileName), "ext"); } if (Directory.Exists(extensionDir)) { AddAllAvailableExtensions(extensionDir); } }
protected override void BeginProcessing() { EnsureAdminUser(); try { _serverManager = new ServerManager(); ServerManagerWrapper serverManagerWrapper = new ServerManagerWrapper(_serverManager, this.SiteName, this.VirtualPath); _configHelper = new PHPConfigHelper(serverManagerWrapper); _phpIniFile = _configHelper.GetPHPIniFile(); _extensions = new RemoteObjectCollection<PHPIniExtension>(); } catch (FileNotFoundException ex) { DisposeServerManager(); ReportTerminatingError(ex, "FileNotFound", ErrorCategory.ObjectNotFound); } catch (InvalidOperationException ex) { DisposeServerManager(); ReportTerminatingError(ex, "InvalidOperation", ErrorCategory.InvalidOperation); } }
private void OnGetSettingsCompleted(object sender, RunWorkerCompletedEventArgs e) { try { object o = e.Result; _file = new PHPIniFile(); _file.SetData(o); LoadPHPIni(_file); // If updated setting name was saved then use it to re-select it after refresh if (!String.IsNullOrEmpty(_updatedSettingName)) { SelectSettingByName(_updatedSettingName); _updatedSettingName = null; } } catch (Exception ex) { DisplayErrorMessage(ex, Resources.ResourceManager); } }
private void UpdateUI(PHPIniFile file) { PHPIniSetting setting = file.GetSetting(SettingNames[0]); string[] settingValues = null; if (setting != null) { if (String.Equals(setting.TrimmedValue, SettingsDevValues[0])) { _errorReportingPreset = ErrorReportingPreset.Development; settingValues = SettingsDevValues; } else if (String.Equals(setting.TrimmedValue, SettingsProdValues[0])) { _errorReportingPreset = ErrorReportingPreset.Production; settingValues = SettingsProdValues; } int i = 1; while (_errorReportingPreset != ErrorReportingPreset.Undefined && i < SettingNames.Length) { setting = file.GetSetting(SettingNames[i]); if (setting == null || !String.Equals(setting.TrimmedValue, settingValues[i])) { _errorReportingPreset = ErrorReportingPreset.Undefined; } i = i + 1; } } if (_errorReportingPreset == ErrorReportingPreset.Development) { _devMachineRadioButton.Checked = true; } else if (_errorReportingPreset == ErrorReportingPreset.Production) { _prodMachineRadioButton.Checked = true; } setting = file.GetSetting("error_log"); if (setting != null) { _errorLogFile = setting.TrimmedValue; _errorLogFileTextBox.Text = setting.TrimmedValue; } }
private static PHPIniSetting GetToApplyUploadTmpDir(PHPIniFile file) { PHPIniSetting setting = file.GetSetting("upload_tmp_dir"); if (setting == null || !IsAbsoluteFilePath(setting.GetTrimmedValue(), false)) { string value = Environment.ExpandEnvironmentVariables(@"%WINDIR%\Temp\"); setting = new PHPIniSetting("upload_tmp_dir", DoubleQuotesWrap(value), "PHP"); } return setting; }
public void AddOrUpdatePHPIniSettings(IEnumerable<PHPIniSetting> settings) { EnsurePHPIsRegistered(); var file = new PHPIniFile(PHPIniFilePath); file.Parse(); file.AddOrUpdateSettings(settings); file.Save(file.FileName); }
public PHPIniFile GetPHPIniFile() { EnsurePHPIsRegistered(); var file = new PHPIniFile(PHPIniFilePath); file.Parse(); return file; }
private PHPIniSetting GetToApplyErrorLog(PHPIniFile file) { var handlerName = _currentPhpHandler.Name; var setting = file.GetSetting("error_log"); if (setting == null || !IsAbsoluteFilePath(setting.GetTrimmedValue(), true)) { var value = Path.Combine(Environment.ExpandEnvironmentVariables(@"%WINDIR%\Temp\"), handlerName + "_errors.log"); setting = new PHPIniSetting("error_log", DoubleQuotesWrap(value), "PHP"); } return setting; }
public void UpdateExtensions(IEnumerable<PHPIniExtension> extensions) { EnsurePHPIsRegistered(); var file = new PHPIniFile(PHPIniFilePath); file.Parse(); file.UpdateExtensions(extensions); file.Save(file.FileName); }
private static PHPConfigIssue ValidateUploadTmpDir(PHPIniFile file) { PHPConfigIssue configIssue = null; // Check if Upload dir is set to an absolute path and that path exists var setting = file.GetSetting("upload_tmp_dir"); var expectedValue = Environment.ExpandEnvironmentVariables(@"%WINDIR%\Temp\"); if (setting == null || String.IsNullOrEmpty(setting.GetTrimmedValue())) { configIssue = new PHPConfigIssue("upload_tmp_dir", String.Empty, expectedValue, "ConfigIssueUploadDirNotSet", "ConfigIssueUploadDirRecommend", PHPConfigIssueIndex.UploadDir); } else if (!IsAbsoluteFilePath(setting.GetTrimmedValue(), false /* this is supposed to be a directory */)) { configIssue = new PHPConfigIssue("upload_tmp_dir", setting.GetTrimmedValue(), expectedValue, "ConfigIssueUploadDirNotCorrect", "ConfigIssueUploadDirRecommend", PHPConfigIssueIndex.UploadDir); } return configIssue; }
private void OnGetExtensionsCompleted(object sender, RunWorkerCompletedEventArgs e) { try { object o = e.Result; _file = new PHPIniFile(); _file.SetData(o); LoadExtensions(_file); // If name of the updated extension was saved then use it to re-select it. if (!String.IsNullOrEmpty(_updatedExtensionName)) { SelectExtensionByName(_updatedExtensionName); _updatedExtensionName = null; } } catch (Exception ex) { DisplayErrorMessage(ex, Resources.ResourceManager); } }
public void RemovePHPIniSetting(PHPIniSetting setting) { EnsurePHPIsRegistered(); var file = new PHPIniFile(PHPIniFilePath); file.Parse(); if (file.Remove(setting)) { file.Save(file.FileName); } }
private void LoadExtensions(PHPIniFile file) { try { ListView.SuspendLayout(); ListView.Items.Clear(); foreach (PHPIniExtension extension in file.Extensions) { if (_filterBy != null && _filterValue != null) { if (_filterBy == NameString && extension.Name.IndexOf(_filterValue, StringComparison.OrdinalIgnoreCase) == -1) { continue; } } ListView.Items.Add(new PHPExtensionItem(extension)); } if (SelectedGrouping != null) { Group(SelectedGrouping); } } finally { ListView.ResumeLayout(); } }
protected override PropertyBag GetProperties() { PropertyBag result = new PropertyBag(); object o = Module.Proxy.GetPHPIniSettings(); PHPIniFile file = new PHPIniFile(); file.SetData(o); for (int i = 0; i < _settingNames.Length; i++) { PHPIniSetting setting = file.GetSetting(_settingNames[i]); if (setting != null) { result[i] = setting.Value; } } return result; }
private static PHPIniFile LoadPhpFile(string phpFilePath) { if (phpFilePath == null) throw new InvalidOperationException(); var phpFile = new PHPIniFile(phpFilePath); return phpFile; }
private void ApplyRecommendedPHPIniSettings(ArrayList configIssueIndexes) { var file = new PHPIniFile(PHPIniFilePath); file.Parse(); var settings = new List<PHPIniSetting>(); foreach (int configIssueIndex in configIssueIndexes) { switch (configIssueIndex) { case PHPConfigIssueIndex.ExtensionDir: { settings.Add(GetToApplyExtensionDir()); break; } case PHPConfigIssueIndex.LogErrors: { settings.Add(GetToApplyLogErrors()); break; } case PHPConfigIssueIndex.ErrorLog: { settings.Add(GetToApplyErrorLog(file)); break; } case PHPConfigIssueIndex.SessionPath: { settings.Add(GetToApplySessionPath(file)); break; } case PHPConfigIssueIndex.UploadDir: { settings.Add(GetToApplyUploadTmpDir(file)); break; } case PHPConfigIssueIndex.CgiForceRedirect: { settings.Add(GetToApplyCgiForceRedirect()); break; } case PHPConfigIssueIndex.CgiPathInfo: { settings.Add(GetToApplyCgiPathInfo()); break; } case PHPConfigIssueIndex.FastCgiImpersonation: { settings.Add(GetToApplyFastCgiImpersonate()); break; } case PHPConfigIssueIndex.DateTimeZone: { settings.Add(GetToApplyDateTimeZone(file)); break; } } } if (settings.Count > 0) { file.AddOrUpdateSettings(settings); file.Save(PHPIniFilePath); } }
private static PHPConfigIssue ValidateCgiPathInfo(PHPIniFile file) { PHPConfigIssue configIssue = null; // Check if cgi.fix_pathinfo is set correctly var setting = file.GetSetting("cgi.fix_pathinfo"); if (setting == null || String.IsNullOrEmpty(setting.GetTrimmedValue())) { configIssue = new PHPConfigIssue("cgi.fix_pathinfo", String.Empty, "1", "ConfigIssueCgiPathInfoNotSet", "ConfigIssueCgiPathInfoRecommend", PHPConfigIssueIndex.CgiPathInfo); } else if (!String.Equals(setting.GetTrimmedValue(), "1", StringComparison.OrdinalIgnoreCase)) { configIssue = new PHPConfigIssue("cgi.fix_pathinfo", setting.GetTrimmedValue(), "1", "ConfigIssueCgiPathInfoNotCorrect", "ConfigIssueCgiPathInfoRecommend", PHPConfigIssueIndex.CgiPathInfo); } return configIssue; }
private static PHPConfigIssue ValidateLogErrors(PHPIniFile file) { PHPConfigIssue configIssue = null; // Check if log_errors is set to On var setting = file.GetSetting("log_errors"); if (setting == null || String.IsNullOrEmpty(setting.GetTrimmedValue())) { configIssue = new PHPConfigIssue("log_errors", String.Empty, "On", "ConfigIssueLogErrorsNotSet", "ConfigIssueLogErrorsRecommend", PHPConfigIssueIndex.LogErrors); } else if (!String.Equals(setting.GetTrimmedValue(), "On", StringComparison.OrdinalIgnoreCase)) { configIssue = new PHPConfigIssue("log_errors", setting.GetTrimmedValue(), "On", "ConfigIssueLogErrorsNotCorrect", "ConfigIssueLogErrorsRecommend", PHPConfigIssueIndex.LogErrors); } return configIssue; }
public RemoteObjectCollection<PHPConfigIssue> ValidateConfiguration() { EnsurePHPIsRegistered(); var file = new PHPIniFile(PHPIniFilePath); file.Parse(); return ValidateConfiguration(file); }
public PHPConfigInfo GetPHPConfigInfo() { var configInfo = new PHPConfigInfo(); // If PHP is not registered properly then just return information about // how it registered. if (!IsPHPRegistered()) { configInfo.RegistrationType = _registrationType; return configInfo; } configInfo.RegistrationType = _registrationType; configInfo.HandlerName = _currentPhpHandler.Name; configInfo.HandlerIsLocal = _currentPhpHandler.IsLocallyStored; configInfo.Executable = _currentPhpHandler.Executable; configInfo.Version = GetPHPExecutableVersion(_currentPhpHandler.Executable); configInfo.PHPIniFilePath = PHPIniFilePath; var file = new PHPIniFile(PHPIniFilePath); file.Parse(); var setting = file.GetSetting("error_log"); configInfo.ErrorLog = setting != null ? setting.GetTrimmedValue() : String.Empty; configInfo.EnabledExtCount = file.GetEnabledExtensionsCount(); configInfo.InstalledExtCount = file.Extensions.Count; ICollection issues = ValidateConfiguration(file); configInfo.IsConfigOptimal = (issues.Count == 0); return configInfo; }
private RemoteObjectCollection<PHPConfigIssue> ValidateConfiguration(PHPIniFile file) { var configIssues = new RemoteObjectCollection<PHPConfigIssue>(); // IIS and FastCGI settings var configIssue = ValidateDefaultDocument(); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateResourceType(); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidatePHPMaxRequests(); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidatePHPRC(); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateMonitorChanges(); if (configIssue != null) { configIssues.Add(configIssue); } // PHP Settings configIssue = ValidateExtensionDir(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateLogErrors(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateErrorLog(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateSessionPath(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateUploadTmpDir(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateCgiForceRedirect(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateCgiPathInfo(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateFastCgiImpersonate(file); if (configIssue != null) { configIssues.Add(configIssue); } configIssue = ValidateDateTimeZone(file); if (configIssue != null) { configIssues.Add(configIssue); } return configIssues; }
private static PHPIniSetting GetToApplyDateTimeZone(PHPIniFile file) { var setting = file.GetSetting("date.timezone") ?? new PHPIniSetting("date.timezone", DoubleQuotesWrap(GetPHPTimeZone()), "Date"); return setting; }
private static PHPConfigIssue ValidateDateTimeZone(PHPIniFile file) { PHPConfigIssue configIssue = null; var setting = file.GetSetting("date.timezone"); if (setting == null) { configIssue = new PHPConfigIssue("date.timezone", String.Empty, GetPHPTimeZone(), "ConfigIssueDateTimeZoneNotSet", "ConfigIssueDateTimeZoneRecommend", PHPConfigIssueIndex.DateTimeZone); } return configIssue; }
private static PHPIniSetting GetToApplySessionPath(PHPIniFile file) { PHPIniSetting setting = file.GetSetting("session.save_path"); if (setting == null || !IsAbsoluteFilePath(setting.GetTrimmedValue(), false)) { string value = Environment.ExpandEnvironmentVariables(@"%WINDIR%\Temp\"); setting = new PHPIniSetting("session.save_path", DoubleQuotesWrap(value), "Session"); } return setting; }
private PHPConfigIssue ValidateErrorLog(PHPIniFile file) { PHPConfigIssue configIssue = null; // Check if error_log is set to an absolute path and that path exists var setting = file.GetSetting("error_log"); string expectedValue = Path.Combine(Environment.ExpandEnvironmentVariables(@"%WINDIR%\Temp\"), _currentPhpHandler.Name + "_errors.log"); if (setting == null || String.IsNullOrEmpty(setting.GetTrimmedValue())) { configIssue = new PHPConfigIssue("error_log", String.Empty, expectedValue, "ConfigIssueErrorLogNotSet", "ConfigIssueErrorLogRecommend", PHPConfigIssueIndex.ErrorLog); } else if (!IsAbsoluteFilePath(setting.GetTrimmedValue(), true /* this is supposed to be a file */)) { configIssue = new PHPConfigIssue("error_log", setting.GetTrimmedValue(), expectedValue, "ConfigIssueErrorLogNotCorrect", "ConfigIssueErrorLogRecommend", PHPConfigIssueIndex.ErrorLog); } return configIssue; }
private void MakeRecommendedPHPIniChanges() { var file = new PHPIniFile(PHPIniFilePath); file.Parse(); // Set the recommended php.ini settings var settings = new List<PHPIniSetting> { GetToApplyExtensionDir(), GetToApplyLogErrors(), GetToApplyErrorLog(file), GetToApplySessionPath(file), GetToApplyUploadTmpDir(file), GetToApplyDateTimeZone(file), GetToApplyCgiForceRedirect(), GetToApplyCgiPathInfo(), GetToApplyFastCgiImpersonate(), new PHPIniSetting("fastcgi.logging", "0", "PHP"), new PHPIniSetting("max_execution_time", "300", "PHP"), new PHPIniSetting("display_errors", "Off", "PHP") }; // Enable the most common PHP extensions var extensions = new List<PHPIniExtension> { new PHPIniExtension("php_curl.dll", true), new PHPIniExtension("php_gd2.dll", true), new PHPIniExtension("php_gettext.dll", true), new PHPIniExtension("php_mysql.dll", true), new PHPIniExtension("php_mysqli.dll", true), new PHPIniExtension("php_mbstring.dll", true), new PHPIniExtension("php_openssl.dll", true), new PHPIniExtension("php_soap.dll", true), new PHPIniExtension("php_xmlrpc.dll", true) }; file.UpdateExtensions(extensions); file.AddOrUpdateSettings(settings); file.Save(PHPIniFilePath); }
public RemoteObjectCollection<PHPConfigIssue> ValidateConfiguration() { // Check if PHP is not registered if (!IsPHPRegistered()) { return null; } PHPIniFile file = new PHPIniFile(PHPIniFilePath); file.Parse(); return ValidateConfiguration(file); }
private void LoadPHPIni(PHPIniFile file) { try { ListView.SuspendLayout(); ListView.Items.Clear(); foreach (PHPIniSetting setting in file.Settings) { if (_filterBy != null && _filterValue != null) { if (_filterBy == NameString && setting.Name.IndexOf(_filterValue, StringComparison.OrdinalIgnoreCase) == -1) { continue; } else if (_filterBy == ValueString && setting.Value.IndexOf(_filterValue, StringComparison.OrdinalIgnoreCase) == -1) { continue; } else if (_filterBy == SectionString && setting.Section.IndexOf(_filterValue, StringComparison.OrdinalIgnoreCase) == -1) { continue; } } ListView.Items.Add(new PHPSettingItem(setting)); } if (SelectedGrouping != null) { Group(SelectedGrouping); } } finally { ListView.ResumeLayout(); } }
private static PHPConfigIssue ValidateFastCgiImpersonate(PHPIniFile file) { PHPConfigIssue configIssue = null; // Check if fastcgi impersonation is turned on var setting = file.GetSetting("fastcgi.impersonate"); if (setting == null || String.IsNullOrEmpty(setting.GetTrimmedValue())) { configIssue = new PHPConfigIssue("fastcgi.impersonate", String.Empty, "1", "ConfigIssueFastCgiImpersonateNotSet", "ConfigIssueFastCgiImpersonateRecommend", PHPConfigIssueIndex.FastCgiImpersonation); } else if (!String.Equals(setting.GetTrimmedValue(), "1", StringComparison.OrdinalIgnoreCase)) { configIssue = new PHPConfigIssue("fastcgi.impersonate", setting.GetTrimmedValue(), "1", "ConfigIssueFastCgiImpersonateNotCorrect", "ConfigIssueFastCgiImpersonateRecommend", PHPConfigIssueIndex.FastCgiImpersonation); } return configIssue; }
private PHPConfigIssue ValidateExtensionDir(PHPIniFile file) { PHPConfigIssue configIssue = null; var setting = file.GetSetting("extension_dir"); string expectedValue = EnsureTrailingBackslash(Path.Combine(PHPDirectory, "ext")); if (setting == null || String.IsNullOrEmpty(setting.GetTrimmedValue())) { configIssue = new PHPConfigIssue("extension_dir", String.Empty, expectedValue, "ConfigIssueExtensionDirNotSet", "ConfigIssueExtensionDirRecommend", PHPConfigIssueIndex.ExtensionDir); } else { string currentValue = EnsureTrailingBackslash(setting.GetTrimmedValue()); currentValue = EnsureBackslashes(currentValue); if (!String.Equals(currentValue, expectedValue, StringComparison.OrdinalIgnoreCase)) { configIssue = new PHPConfigIssue("extension_dir", setting.GetTrimmedValue(), expectedValue, "ConfigIssueExtensionDirIncorrect", "ConfigIssueExtensionDirRecommend", PHPConfigIssueIndex.ExtensionDir); } } return configIssue; }
private void OnGetSettingsCompleted(object sender, RunWorkerCompletedEventArgs e) { try { object o = e.Result; PHPIniFile file = new PHPIniFile(); file.SetData(o); UpdateUI(file); } catch (Exception ex) { DisplayErrorMessage(ex, Resources.ResourceManager); } }