private void setSiteValues(bool bSetChange = false) { if (!bSetChange) { this.lblName.Text = string.Empty; this.txtPath.Text = string.Empty; } string sBranch = null != this.cbBranch.SelectedItem ? this.cbBranch.SelectedItem.ToString() : string.Empty; if (!string.IsNullOrEmpty(sBranch)) { string sSite = null != this.clbSites.SelectedItem ? this.clbSites.SelectedItem.ToString() : string.Empty; if (!string.IsNullOrEmpty(sSite)) { Branch oBranch = !string.IsNullOrEmpty(sBranch) ? this.Config.GetBranch(sBranch) : null; if (null != oBranch) { IISSite oSite = oBranch.GetSite(sSite); if (null != oSite) { if (!bSetChange) { this.lblName.Text = oSite.Name; this.txtPath.Text = oSite.Path; } else { oSite.Path = this.txtPath.Text; } } } } } }
private List <IISSite> getSites(Branch oBranchUpdate = null) { List <IISSite> lstReturn = new List <IISSite>(); if (null != oBranchUpdate) { this.loadIISSites(); } this._LstApplication.ForEach(app => { VirtualDirectory oVirtualDirectory = app.VirtualDirectories.Where(vDir => vDir.Path == "/").Single(); if (null != oVirtualDirectory) { IISSite oSite = new IISSite(); oSite.Name = Path.GetFileName(app.Path); oSite.Path = oVirtualDirectory.PhysicalPath; oSite.Checked = null == oBranchUpdate ? false : this.valueCurrentSite(oBranchUpdate, oSite.Name); lstReturn.Add(oSite); } }); return(lstReturn); }
private void setSitesInBranch() { string sBranch = this.cbBranch.SelectedItem.ToString(); Branch oBranch = !string.IsNullOrEmpty(sBranch) ? this.Config.GetBranch(sBranch) : null; if (null != oBranch) { for (int iIndex = 0; iIndex < this.clbSites.Items.Count; iIndex++) { string sSite = clbSites.Items[iIndex].ToString(); IISSite oSite = oBranch.GetSite(sSite); bool bChecked = null != oSite ? oSite.Checked : false; if (null == oSite) { string sVirtualDirectory = this.getVirtualDirectory(sSite); if (!string.IsNullOrEmpty(sVirtualDirectory)) { oSite = new IISSite(); oSite.Name = sSite; oSite.Path = sVirtualDirectory; oBranch.Sites.Add(oSite); } } this.clbSites.SetItemChecked(iIndex, bChecked); } } }
private static void MinimumAspDotNet4onIIS6ConfigExample(MsgOut msgOut) { string serverComment = "zzz"; string path = @"C:\Inetpub\zzz"; string serverBindings = "http::80:zzz.contoso.com;https::443:zzz.contoso.com"; string appPool = "DotNet4AppPool"; Directory.CreateDirectory(path); IISSite site = IIS.Tools.CreateNewSite(new IISServerCommentIdentifier(serverComment), serverBindings, path); site.SetBindings(serverBindings); site.DefaultDoc = "index.aspx"; site.AccessFlags = AccessFlags.AccessRead | AccessFlags.AccessExecute; site.AuthFlags = AuthFlags.AuthNTLM | AuthFlags.AuthAnonymous; site.AppPoolId = appPool; site.SetASPDotNetVersion(AspDotNetVersion.AspNetV4); try { site.Start(); } catch (Exception exp) { msgOut(exp.Message); } }
public static List <IISSite> GetSites() { var siteList = new List <IISSite>(); using (var serverManager = new ServerManager()) { foreach (var smSite in serverManager.Sites) { try { var site = new IISSite { Name = smSite.Name, Bindings = new List <IISSiteBinding>(), Applications = new List <IISApplication>(), DefaultAppPoolName = smSite.ApplicationDefaults.ApplicationPoolName }; foreach (var smBinding in smSite.Bindings) { var binding = new IISSiteBinding { BindingInformation = smBinding.BindingInformation, Protocol = smBinding.Protocol, Hostname = smBinding.Host, IpAddress = smBinding?.EndPoint?.Address?.ToString()?.Replace("0.0.0.0", "*") ?? "", Port = smBinding?.EndPoint?.Port ?? null }; site.Bindings.Add(binding); } foreach (var smApp in smSite.Applications) { var app = PopulateApplication(smApp); if (app != null) { site.Applications.Add(app); } } siteList.Add(site); } catch (Exception ex) { Trace.TraceError("Error getting site information. Error: {0}", ex.ToString()); Console.Error.WriteLine("Error getting site information for site {0}", ex.ToString()); } } } return(siteList); }
private void setSiteChecked(string sSite, bool bChecked) { if (null != this.cbBranch.SelectedItem) { string sBranch = this.cbBranch.SelectedItem.ToString(); Branch oBranch = !string.IsNullOrEmpty(sBranch) ? this.Config.GetBranch(sBranch) : null; if (null != oBranch) { IISSite oSite = oBranch.GetSite(sSite); if (null != oSite) { oSite.Checked = bChecked; } } } }
public static string SaveChanges(Config oConfig) { string sReturn = string.Empty; try { Branch oBranch = oConfig.GetLastBranch(); if (null != oBranch) { using (ServerManager iisManager = new ServerManager()) { foreach (Site site in iisManager.Sites) { foreach (Application app in site.Applications) { string sSite = Path.GetFileName(app.Path); if (!string.IsNullOrEmpty(sSite)) { IISSite oSite = oBranch.GetSite(Path.GetFileName(sSite)); if (null != oSite) { VirtualDirectory oVirtualDirectory = app.VirtualDirectories.Where(vDir => vDir.Path == "/").Single(); if (null != oVirtualDirectory) { oVirtualDirectory.PhysicalPath = oSite.Path; } } } } } iisManager.CommitChanges(); } } else { sReturn = "Seleccionar Branch"; } } catch (Exception Ex) { sReturn = Ex.Message; } return(sReturn); }
private Target Target(IISSiteOptions options) { var plugin = new IISSite(log, iis, helper, options); return(plugin.Generate()); }
private Target Target(IISSiteOptions options) { var plugin = new IISSite(log, userRoleService, helper, options); return(plugin.Generate().Result); }
private bool valueCurrentSite(Branch oBranchUpdate, string sSite) { IISSite oSite = oBranchUpdate.GetSite(sSite); return(null != oSite && oSite.Checked); }
public void Run(String[] CmdArguments) { try { //We do not want to run if there are invalid arguments... otherwise the end user //will think that it ran with success when it did not String[] invalids = CommandLineParamsParser.GetInvalidParams(CmdArguments, typeof(CommandParams)); if (invalids.Length > 0) { OutputError("Invalid argument(s) were found."); foreach (String arg in invalids) { OutputError("{0} is an invalid argument", arg); } OutputError("Fix this before continuing."); return; } //Make sure that the user did in fact pass in some valid params CommandParams cp = new CommandParams(); if (!CommandLineParamsParser.PopulateParamObject(CmdArguments, cp)) { OutputError("There were no valid arguments passed in. Use --Help to determine all valid arguments."); return; } OutputStatus(String.Format("w3wp (IIS) version: {0}", IIS.Version.FileVersion)); if (cp.Help != null) { String hlp = String.Join(Environment.NewLine, DocHelp.GenerateHelp(typeof(CommandParams))); OutputStatus(hlp); return; } if (cp.GetInstalledCertificates != null) { SSLCertificates.GetInstalledCertificates(OutputStatus); } //First we want to check if we need to delete a site if (cp.DeleteSite != null) { if (IIS.Tools.DeleteSite(new IISServerCommentIdentifier(cp.DeleteSite))) //returns true if the site is found { OutputStatus("Site {0} deleted", cp.DeleteSite); } else { OutputStatus("Site {0} not deleted because it was not found", cp.DeleteSite); //does not warrant an error because that was the desired outcome } //Exit out if we are not finding by site id or creating a site here if ((cp.CreateSite == null) && (cp.FindByServerComment == null) && (cp.FindByBinding == null)) { return; } } IISSite site = null; //Check if we need to create a new site if (cp.CreateSite != null) { if (cp.CreateSite.Trim() == "") { OutputError("Create site cannot specify a blank site."); return; } if (String.IsNullOrEmpty(cp.PhysicalPath)) { OutputError("In order to create a website, a valid \"PhysicalPath\" must be specified."); return; } try { site = IIS.Tools.CreateNewSite(new IISServerCommentIdentifier(cp.CreateSite), cp.Bindings ?? "", cp.PhysicalPath); OutputStatus("Site {0} created", cp.CreateSite); } catch (Exception exp) { OutputError("Error creating site {0}: {1}", cp.CreateSite, exp.Message); } } //If the find parameter is specified, it will override the site that may have been created if (cp.FindByServerComment != null) { site = IIS.Tools.FindSite(new IISServerCommentIdentifier(cp.FindByServerComment)); if (site == null) { OutputError(String.Format("Unable to find site \"{0}\" by server comment.", cp.FindByServerComment)); return; } else { OutputStatus("Found site {0} with id {1}", cp.FindByServerComment, site.SiteId); } } else if (cp.FindByBinding != null) { site = IIS.Tools.FindSite(new IISBindingIdentifier(cp.FindByBinding)); if (site == null) { OutputError(String.Format("Unable to find site \"{0}\" by binding.", cp.FindByBinding)); return; } else { OutputStatus("Found site {0} with id {1}", cp.FindByBinding, site.SiteId); } } //At this time if we do not have a site object... then we cannot do anything if (site == null) { OutputError("Unable to create or find a site. Nothing can be done until proper CreateSite or FindByXXXXX parameters have been specified."); return; } if (cp.Bindings != null) { try { site.SetBindings(cp.Bindings); OutputStatus("Bindings set to {0}", cp.Bindings); } catch (Exception exp) { OutputError(String.Format("Error while setting bindings. {0}", exp.Message)); return; } } if (cp.DefaultDoc != null) { site.DefaultDoc = cp.DefaultDoc; OutputStatus("Default document set to {0}", cp.DefaultDoc); } if (cp.AccessFlags != null) { try { site.AccessFlags = CommandLineParamsParser.BuildFlagFromDelimString(cp.AccessFlags, typeof(AccessFlags)); OutputStatus("AccessFlags set to {0}", cp.AccessFlags); } catch (Exception exp) { OutputError(String.Format("Error while setting AccessFlags. {0}", exp.Message)); return; } } if (cp.AuthFlags != null) { try { site.AuthFlags = CommandLineParamsParser.BuildFlagFromDelimString(cp.AuthFlags, typeof(AuthFlags)); OutputStatus("AuthFlags set to {0}", cp.AuthFlags); } catch (Exception exp) { OutputError(String.Format("Error while setting AuthFlags. {0}", exp.Message)); return; } } if (cp.AppPoolId != null) { site.AppPoolId = cp.AppPoolId; OutputStatus("AppPoolId set to {0}", cp.AppPoolId); } if (cp.ASPDotNetVersion != null) { AspDotNetVersion version; try { version = (AspDotNetVersion)Enum.Parse(typeof(AspDotNetVersion), cp.ASPDotNetVersion, true); } catch (Exception exp) { OutputError(String.Format("An invalid ASPDotNetVersion value was specified. \"{0}\" is invalid.", cp.ASPDotNetVersion)); return; } site.SetASPDotNetVersion(version); OutputStatus("ASP DotNet version set to {0}", version); } if (cp.StartSite != null) { try { site.Start(); OutputStatus("Site started with success"); } catch (Exception exp) { OutputError("Error starting site: " + exp.Message); return; } } } catch (Exception exp) { OutputError("An exception took place during execution: " + exp.Message + exp.StackTrace); } }