public static List <Site> ListAll( AppCmd appCmd) { return(appCmd.GetLines("list sites /text:name") .Select(s => new Site(s, appCmd)) .ToList()); }
public static List <AppPool> ListAll( AppCmd appCmd) { return(appCmd.GetLines("list apppools /text:name") .Select(s => new AppPool(s, appCmd)) .ToList()); }
public static Iis Export( AppCmd appCmd, bool pools = true, bool sites = true) { return(new Iis(appCmd, pools, sites)); }
public static List <App> ListAll( string site, AppCmd appCmd) { return(appCmd.GetLines($"list app /site.name:\"{site}\" /text:app.name") .Select(s => new App(s, appCmd)) .ToList()); }
public static List <VDir> ListAll( string app, AppCmd appCmd) { return(appCmd.GetLines($"list vdir /app.name:\"{app}\" /text:vdir.name") .Select(s => new VDir(s, appCmd)) .ToList()); }
public AnonymousAuthentication( string site, AppCmd appCmd) { Enabled = bool.Parse(appCmd.GetLine($"list config \"{site}\" /section:system.webServer/security/authentication/anonymousAuthentication /text:enabled")); Username = appCmd.GetLine($"list config \"{site}\" /section:system.webServer/security/authentication/anonymousAuthentication /text:username"); Password = appCmd.GetLine($"list config \"{site}\" /section:system.webServer/security/authentication/anonymousAuthentication /text:password"); }
public App( string name, AppCmd appCmd) { Name = name; Path = appCmd.GetLine($"list app \"{Name}\" /text:path"); ApplicationPool = appCmd.GetLine($"list app \"{Name}\" /text:apppool.name"); Authentication = new Authentication(Name, appCmd); VDirs = VDir.ListAll(Name, appCmd); }
public VDir( string name, AppCmd appCmd) { Name = name; Path = appCmd.GetLine($"list vdir /vdir.name:\"{Name}\" /text:path"); PhysicalPath = appCmd.GetLine($"list vdir /vdir.name:\"{Name}\" /text:physicalPath"); Username = appCmd.GetLine($"list vdir /vdir.name:\"{Name}\" /text:username"); Password = appCmd.GetLine($"list vdir /vdir.name:\"{Name}\" /text:password"); }
public Site( string name, AppCmd appCmd) { Name = name; Console.WriteLine($"\t{Name}"); Bindings = appCmd.GetLine($"list site \"{Name}\" /text:bindings"); Apps = App.ListAll(Name, appCmd); }
public AppPool( string name, AppCmd appCmd) { Name = name; Console.WriteLine($"\t{Name}"); IdentityType = appCmd.GetLine($"list apppool \"{Name}\" /text:processmodel.identityType"); Username = appCmd.GetLine($"list apppool \"{Name}\" /text:processmodel.username"); Password = appCmd.GetLine($"list apppool \"{Name}\" /text:processmodel.password"); ManagedRuntimeVersion = appCmd.GetLine($"list apppool \"{Name}\" /text:managedRuntimeVersion"); ManagedPipelineMode = appCmd.GetLine($"list apppool \"{Name}\" /text:managedPipelineMode"); Enable32BitAppOnWin64 = bool.Parse(appCmd.GetLine($"list apppool \"{Name}\" /text:enable32BitAppOnWin64")); }
private Iis( AppCmd appCmd, bool pools = true, bool sites = true) { if (pools) { Console.WriteLine("* Application Pools"); Console.WriteLine(); AppPools = AppPool.ListAll(appCmd); } if (sites) { Console.WriteLine("* Sites"); Console.WriteLine(); Sites = Site.ListAll(appCmd); } }
public void Import( AppCmd appCmd) { string result; foreach (var appPool in AppPools) { result = appCmd.ExecuteCommand($"add apppool /name:\"{appPool.Name}\" /processModel.identityType:\"{appPool.IdentityType}\" /processModel.userName:\"{appPool.Username}\" /processModel.password:\"{appPool.Password}\" /managedRuntimeVersion:\"{appPool.ManagedRuntimeVersion}\" /enable32BitAppOnWin64:\"{appPool.Enable32BitAppOnWin64}\""); Console.WriteLine(result); } foreach (var site in Sites) { result = appCmd.ExecuteCommand($"add site /name:\"{site.Name}\" /bindings:{site.Bindings}"); Console.WriteLine(result); foreach (var app in site.Apps) { result = appCmd.ExecuteCommand($"add app /site.name:\"{site.Name}\" /path:\"{app.Path}\" /applicationPool:\"{app.ApplicationPool}\""); Console.WriteLine(result); result = appCmd.ExecuteCommand($"set config \"{app.Name}\" /section:system.webServer/security/authentication/anonymousAuthentication /enabled:\"{app.Authentication.Anonymous.Enabled}\" /userName:\"{app.Authentication.Anonymous.Username}\" /password:\"{app.Authentication.Anonymous.Password}\" /commit:apphost"); Console.WriteLine(result); foreach (var vDir in app.VDirs) { result = appCmd.ExecuteCommand($"add vdir /app.name:\"{app.Name}\" /path:\"{vDir.Path}\" /physicalPath:\"{vDir.PhysicalPath}\" /username:\"{vDir.Username}\" /password:\"{vDir.Password}\""); Console.WriteLine(result); } } } }
static void Main(string [] args) { if (args.Length != 2) { Console.WriteLine("Usage: IisMigration.exe [OPTION]... [FILE]..."); Console.WriteLine("Export/Import IIS Configurations."); Console.WriteLine(); Console.WriteLine(" {0,-30} Export Pools and Sites.", "/export [FILE.XML]"); Console.WriteLine(" {0,-30} Export Pools.", "/export-pools [FILE.XML]"); Console.WriteLine(" {0,-30} Export Sites.", "/export-sites [FILE.XML]"); Console.WriteLine(); Console.WriteLine(" {0,-30} Import configurations", "/import [FILE.XML]"); Console.WriteLine(" {0,-30} Import users to Active Directory", "/import-users [FILE.XML]"); Console.WriteLine(" {0,-30} Create directory structure from IIS configuration", "/import-dirs [FILE.XML]"); return; } try { var file = args[1]; var appCmd = new AppCmd(ConfigurationManager.AppSettings["AppCmd"]); var serializer = new XmlSerializer(typeof(Iis)); switch (args[0].ToLower()) { case "/import": using (var reader = new StreamReader(file)) { var iis = (Iis)serializer.Deserialize(reader); iis.Import(appCmd); } break; case "/import-users": using (var reader = new StreamReader(file)) { var iis = (Iis)serializer.Deserialize(reader); var users = iis.AppPools .Where(w => !string.IsNullOrEmpty(w.Username)) .Select(s => new User(s.Username, s.Password)) .GroupBy(gb => gb.Username) .Select(s => s.First()) .ToList(); foreach (var user in users) { user.Create(); } } break; case "/import-dirs": using (var reader = new StreamReader(file)) { var iis = (Iis)serializer.Deserialize(reader); var dirs = iis.Sites .SelectMany(s => s.Apps) .SelectMany(s => s.VDirs) .GroupBy(gb => gb.PhysicalPath) .Select(s => s.Key) .ToList(); foreach (var dir in dirs.Where(w => !Directory.Exists(w))) { Directory.CreateDirectory(dir); Console.WriteLine(dir); } } break; case "/export": using (var writer = new StreamWriter(file, false)) { serializer.Serialize(writer, Iis.Export(appCmd)); } break; case "/export-pools": using (var writer = new StreamWriter(file, false)) { serializer.Serialize(writer, Iis.Export(appCmd, true, false)); } break; case "/export-sites": using (var writer = new StreamWriter(file, false)) { serializer.Serialize(writer, Iis.Export(appCmd, false)); } break; } } catch (Exception e) { var message = e.Message; if (e.InnerException != null) { message += Environment.NewLine; message += e.InnerException.Message; } Console.WriteLine("Exception: {0}", message); } }