inetmgr 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/README.rdoc +159 -0
  2. data/RELEASE-NOTES.rdoc +35 -0
  3. data/doc/Application.html +177 -0
  4. data/doc/ApplicationPool.html +177 -0
  5. data/doc/AutoStartProvider.html +177 -0
  6. data/doc/BindingInformation.html +349 -0
  7. data/doc/Configuration.html +283 -0
  8. data/doc/IisConfiguration.html +383 -0
  9. data/doc/IisObject.html +484 -0
  10. data/doc/IisObjectCollection.html +534 -0
  11. data/doc/Inetmgr.html +179 -0
  12. data/doc/Inetmgr/InetmgrTask.html +338 -0
  13. data/doc/Object.html +254 -0
  14. data/doc/PeriodicRestart.html +177 -0
  15. data/doc/ProcessModel.html +192 -0
  16. data/doc/README_rdoc.html +114 -0
  17. data/doc/RSpecExtensions.html +257 -0
  18. data/doc/Recycling.html +177 -0
  19. data/doc/Site.html +228 -0
  20. data/doc/SiteConfiguration.html +269 -0
  21. data/doc/SiteLimit.html +177 -0
  22. data/doc/VirtualDirectory.html +177 -0
  23. data/doc/images/brick.png +0 -0
  24. data/doc/images/brick_link.png +0 -0
  25. data/doc/images/bug.png +0 -0
  26. data/doc/images/bullet_black.png +0 -0
  27. data/doc/images/bullet_toggle_minus.png +0 -0
  28. data/doc/images/bullet_toggle_plus.png +0 -0
  29. data/doc/images/date.png +0 -0
  30. data/doc/images/find.png +0 -0
  31. data/doc/images/loadingAnimation.gif +0 -0
  32. data/doc/images/macFFBgHack.png +0 -0
  33. data/doc/images/package.png +0 -0
  34. data/doc/images/page_green.png +0 -0
  35. data/doc/images/page_white_text.png +0 -0
  36. data/doc/images/page_white_width.png +0 -0
  37. data/doc/images/plugin.png +0 -0
  38. data/doc/images/ruby.png +0 -0
  39. data/doc/images/tag_green.png +0 -0
  40. data/doc/images/wrench.png +0 -0
  41. data/doc/images/wrench_orange.png +0 -0
  42. data/doc/images/zoom.png +0 -0
  43. data/doc/index.html +166 -0
  44. data/doc/js/darkfish.js +116 -0
  45. data/doc/js/jquery.js +32 -0
  46. data/doc/js/quicksearch.js +114 -0
  47. data/doc/js/thickbox-compressed.js +10 -0
  48. data/doc/rdoc.css +706 -0
  49. data/inetmgr.gemspec +21 -0
  50. data/lib/inetmgr.rb +30 -0
  51. data/lib/inetmgr/configuration.rb +23 -0
  52. data/lib/inetmgr/iis_configuration.rb +36 -0
  53. data/lib/inetmgr/iis_object.rb +85 -0
  54. data/lib/inetmgr/iis_object/application.rb +11 -0
  55. data/lib/inetmgr/iis_object/application_pool.rb +19 -0
  56. data/lib/inetmgr/iis_object/auto_start_provider.rb +3 -0
  57. data/lib/inetmgr/iis_object/binding_information.rb +26 -0
  58. data/lib/inetmgr/iis_object/periodic_restart.rb +3 -0
  59. data/lib/inetmgr/iis_object/process_model.rb +18 -0
  60. data/lib/inetmgr/iis_object/recycling.rb +5 -0
  61. data/lib/inetmgr/iis_object/site.rb +24 -0
  62. data/lib/inetmgr/iis_object/site_limit.rb +7 -0
  63. data/lib/inetmgr/iis_object/virtual_directory.rb +5 -0
  64. data/lib/inetmgr/iis_object_collection.rb +51 -0
  65. data/lib/inetmgr/site_configuration.rb +34 -0
  66. data/lib/rake/inetmgrtask.rb +74 -0
  67. data/lib/string.rb +5 -0
  68. data/nbproject/private/config.properties +0 -0
  69. data/nbproject/private/private.properties +4 -0
  70. data/nbproject/private/private.xml +4 -0
  71. data/nbproject/private/rake-d.txt +2 -0
  72. data/nbproject/project.properties +10 -0
  73. data/nbproject/project.xml +16 -0
  74. data/spec/application_pool_spec.rb +120 -0
  75. data/spec/application_spec.rb +38 -0
  76. data/spec/auto_start_provider_spec.rb +25 -0
  77. data/spec/bingin_information_spec.rb +21 -0
  78. data/spec/iis_configuration_spec.rb +35 -0
  79. data/spec/site_app_settings_spec.rb +61 -0
  80. data/spec/site_configuration_spec.rb +24 -0
  81. data/spec/site_connection_strings_spec.rb +17 -0
  82. data/spec/site_spec.rb +34 -0
  83. data/spec/site_validation_settings_spec.rb +18 -0
  84. data/spec/spec_env.rb +22 -0
  85. data/spec/string_spec.rb +16 -0
  86. data/spec/virtual_directory_spec.rb +1 -0
  87. data/test/create_site.rb +26 -0
  88. data/test/print_iis_config.rb +56 -0
  89. data/test/rakefile.rb +27 -0
  90. metadata +156 -0
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ spec = Gem::Specification.new do |s|
5
+
6
+ s.name = "inetmgr"
7
+ s.version = "0.4.0"
8
+ s.summary = "A library for managing IIS configuration settings."
9
+ s.description = "inetmgr allows you to inspect/configure IIS configuration sections and elements."
10
+
11
+ s.required_ruby_version = '>= 1.9.2'
12
+ s.required_rubygems_version = ">= 1.3.6"
13
+
14
+ s.author = "Gino Heyman"
15
+ s.email = "gino.heyman@gmail.com"
16
+ s.homepage = "http://typesafe.be/inetmgr/"
17
+
18
+ s.files = FileList["**/**/*"].to_a
19
+ s.require_path = "lib"
20
+
21
+ end
@@ -0,0 +1,30 @@
1
+ require 'win32ole'
2
+
3
+ path = File.expand_path(File.dirname(__FILE__))
4
+
5
+ require File.join(path, 'string.rb')
6
+
7
+ requires =
8
+ [
9
+ 'inetmgr/iis_object_collection.rb',
10
+ 'inetmgr/iis_object.rb'
11
+ ]
12
+
13
+ requires.each do |file|
14
+ require File.join(path, file)
15
+ end
16
+
17
+ requires =
18
+ [
19
+ 'inetmgr/configuration.rb',
20
+ 'inetmgr/iis_configuration.rb',
21
+ 'inetmgr/site_configuration.rb'
22
+ ]
23
+
24
+ requires.each do |file|
25
+ require File.join(path, file)
26
+ end
27
+
28
+ Dir.glob(File.join(path, 'inetmgr/iis_object/*.rb')).each do |f|
29
+ require f unless requires.include?(f)
30
+ end
@@ -0,0 +1,23 @@
1
+
2
+ class Configuration
3
+
4
+ def initialize(path)
5
+ @admin_manager = WIN32OLE.new "Microsoft.ApplicationHost.WritableAdminManager"
6
+ @admin_manager.CommitPath = path;
7
+ end
8
+
9
+ # applies/commits all changes made since the creation of the
10
+ # IisConfiguration instance or the last time this method was called.
11
+ def apply_changes
12
+ @admin_manager.CommitChanges
13
+ end
14
+
15
+ private
16
+
17
+ def get_admin_section section_name
18
+ @admin_manager.GetAdminSection(section_name, @admin_manager.CommitPath)
19
+ end
20
+
21
+
22
+
23
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'iis_object/site.rb')
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'iis_object/application_pool.rb')
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'iis_object/auto_start_provider.rb')
4
+
5
+ # Represents the local IIS configuration settings (meta base).
6
+ class IisConfiguration < Configuration
7
+
8
+ def initialize
9
+ super "MACHINE/WEBROOT/APPHOST"
10
+ end
11
+
12
+ def self.configure
13
+ cfg = IisConfiguration.new
14
+ yield cfg
15
+ cfg.apply_changes
16
+ end
17
+
18
+ # Gets all configured web sites.
19
+ def get_sites
20
+ s = get_admin_section "system.applicationHost/sites"
21
+ IisObjectCollection.new s.Collection, :site, Site, lambda { |site| site.id = s.Collection.Count + 1 }
22
+ end
23
+
24
+ # Gets all configure application pools.
25
+ def get_application_pools
26
+ s = get_admin_section "system.applicationHost/applicationPools"
27
+ IisObjectCollection.new s.Collection, :add, ApplicationPool
28
+ end
29
+
30
+ # Gets all configured service auto start providers.
31
+ def get_auto_start_providers
32
+ s = get_admin_section "system.applicationHost/serviceAutoStartProviders"
33
+ IisObjectCollection.new s.Collection, :add, AutoStartProvider
34
+ end
35
+
36
+ end
@@ -0,0 +1,85 @@
1
+ # Represents an IIS configuration element. Serves as the base class for all
2
+ # IIS artifacts like Site, Application and VirtualDirectory.
3
+ class IisObject
4
+
5
+ def initialize element
6
+ @element = element
7
+ end
8
+
9
+ # Creates a property with the specified name.
10
+ #
11
+ # ==== Parameters
12
+ # * <tt>name</tt> - The name of the property to create
13
+ # * <tt>actual_name</tt> - Optional, The actual name of the attribute or
14
+ # element in the IIS configuration schema.
15
+ # * <tt>setter</tt> - Optional, a lambda or proc to convert the property
16
+ # value to a value in the IIS configuration schema.
17
+ # * <tt>reader</tt> - Optional, a lambda or proc to convert the IIS
18
+ # configuration value to the desired property value.
19
+ def self.prop name, actual_name, setter = lambda { |v| v }, reader = lambda { |v| v }
20
+ define_method(name.to_s) do
21
+ reader.call(@element.Properties.Item(actual_name.to_s).Value)
22
+ end
23
+
24
+ define_method("#{name.to_s}=") do |val|
25
+ @element.Properties.Item(actual_name.to_s).Value = setter.call(val)
26
+ end
27
+ end
28
+
29
+ # Creates a collection property with the specified name.
30
+ #
31
+ # ==== Parameters
32
+ # * <tt>name</tt> - The name of the property to create
33
+ # * <tt>type</tt> - The collection's item type.
34
+ def self.collection name, item_name, type
35
+ define_method(name.to_s) do
36
+ IisObjectCollection.new @element.Collection, item_name.to_s, type
37
+ end
38
+ end
39
+
40
+ # Creates a collection property with the specified name.
41
+ #
42
+ # ==== Parameters
43
+ # * <tt>name</tt> - The name of the property to create
44
+ # * <tt>item_name</tt> - The name of the element in the configuration schema.
45
+ # * <tt>type</tt> - The collection's item type.
46
+ def self.children name, item_name, type
47
+ define_method(name.to_s) do
48
+ IisObjectCollection.new @element.ChildElements.Item(name.to_s).Collection, item_name.to_s, type
49
+ end
50
+ end
51
+
52
+ def self.child name, element_name, type
53
+ define_method(name.to_s) do
54
+ type.new @element.ChildElements.Item(element_name.to_s)
55
+ end
56
+ end
57
+
58
+ def invoke_method name
59
+ method = @element.Methods.Item(name.to_s).CreateInstance()
60
+
61
+ # TODO: if block_given? change method_missing to change this:
62
+ # method.Input.Properties.Item("key").Value = value
63
+ # in to this:
64
+ # method.key = value
65
+
66
+ yield method if block_given?
67
+ method.Execute()
68
+ end
69
+
70
+ private
71
+
72
+ def method_missing(symbol, *args)
73
+ name = symbol.to_s.to_camel_case
74
+ if (/=$/.match(name))
75
+
76
+ @element.Properties.Item(name.sub(/=$/, '')).Value = args[0]
77
+ else
78
+ @element.Properties.Item(name).Value
79
+ end
80
+ rescue WIN32OLERuntimeError
81
+ raise "property '#{symbol}' -> #{$!}"
82
+ end
83
+
84
+ end
85
+
@@ -0,0 +1,11 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'virtual_directory.rb')
2
+
3
+ class Application < IisObject
4
+
5
+ prop :auto_start, "serviceAutoStartEnabled"
6
+ prop :auto_start_provider, "serviceAutoStartProvider"
7
+ prop :application_pool, :applicationPool
8
+
9
+ collection :virtual_directories, :virtualDirectory, VirtualDirectory
10
+
11
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'process_model.rb')
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'recycling.rb')
3
+
4
+ class ApplicationPool < IisObject
5
+
6
+ # prop :managed_runtime_version, :managedRuntimeVersion
7
+ # prop :pass_anonymous_token, :passAnonymousToken
8
+ # prop :queue_length, :queueLength
9
+
10
+ prop :auto_start, :autoStart, lambda { |a| a == true ? "true" : "false" }, lambda {|value| value == "true" }
11
+ prop :classic_pipeline, :managedPipelineMode, lambda { |a| a == true ? 1 : 0 }, lambda {|value| value.to_i == 1 }
12
+ prop :enable_32bit, :enable32BitAppOnWin64
13
+ prop :always_running, :startMode, lambda { |a| a == true ? "AlwaysRunning" : "OnDemand" },lambda {|value| value.to_i == 1 }
14
+
15
+ child :process_model, :processModel, ProcessModel
16
+ child :recycling, :recycling, Recycling
17
+
18
+ end
19
+
@@ -0,0 +1,3 @@
1
+ class AutoStartProvider < IisObject
2
+
3
+ end
@@ -0,0 +1,26 @@
1
+
2
+ class BindingInformation < IisObject
3
+
4
+ prop :protocol, :protocol
5
+ prop :binding_information, :bindingInformation
6
+ prop :ds_mapper_enabled?, :isDsMapperEnabled
7
+
8
+ def add_ssl_certificate thumprint, store
9
+ invoke_method("AddSslCertificate") do |method|
10
+ method.Input.Properties.Item("certificateHash").Value = thumprint
11
+ method.Input.Properties.Item("certificateStoreName").Value = store
12
+ end
13
+ end
14
+
15
+ def remove_ssl_certificate
16
+ invoke_method("RemoveSslCertificate")
17
+ end
18
+
19
+ def enable_ds_mapper
20
+ invoke_method("EnableDsMapper")
21
+ end
22
+
23
+ def disable_ds_mapper
24
+ invoke_method("DisableDsMapper")
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ class PeriodicRestart < IisObject
2
+ children :schedule, :schedule, IisObject
3
+ end
@@ -0,0 +1,18 @@
1
+ # Specifies security, performance, health, and reliability features of application pools.
2
+ class ProcessModel < IisObject
3
+
4
+ Identity_type_map = [:system, :local_service, :network_service, :specific_user, :application_pool_identity]
5
+
6
+ ##
7
+ # Specifies the logon type for the process identity.
8
+ # - :batch indicates that the application pool identity should logon as a batch user.
9
+ # - :service indicates that the application pool identity should logon as a service.
10
+
11
+ prop :logon_type, :logonType, lambda {|value| value == :batch ? 0 : 1 }, lambda { |a| a == 0 ? :batch : :service }
12
+
13
+ prop :identity_type, :identityType, lambda {|value| Identity_type_map.index(value)}, lambda { |a| Identity_type_map[a] }
14
+ prop :user_name, :userName
15
+ #prop :password
16
+ prop :load_user_profile, :loadUserProfile
17
+
18
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'periodic_restart.rb')
2
+
3
+ class Recycling < IisObject
4
+ child :periodic_restart, :periodicRestart, PeriodicRestart
5
+ end
@@ -0,0 +1,24 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'site_limit.rb')
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'binding_information.rb')
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'application.rb')
4
+
5
+ class Site < IisObject
6
+
7
+ # name
8
+ # id
9
+
10
+ prop :auto_start, :serverAutoStart
11
+
12
+ collection :applications, :application, Application
13
+
14
+ children :bindings, :binding, BindingInformation
15
+
16
+ child :limits, :limits, SiteLimit
17
+
18
+ def configure
19
+ cfg = SiteConfiguration.new name
20
+ yield cfg
21
+ cfg.apply_changes
22
+ end
23
+
24
+ end
@@ -0,0 +1,7 @@
1
+ class SiteLimit < IisObject
2
+
3
+ prop :max_bandwidth, :maxBandwidth
4
+ prop :max_connections, :maxConnections
5
+ prop :connection_timeout, :connectionTimeout
6
+
7
+ end
@@ -0,0 +1,5 @@
1
+ class VirtualDirectory < IisObject
2
+
3
+ prop :path, "path"
4
+ prop :physical_path, :physicalPath
5
+ end
@@ -0,0 +1,51 @@
1
+ # Represents a collection of IIS configuration objects.
2
+ class IisObjectCollection
3
+
4
+ def initialize element, item_name, type, add_callback = nil
5
+ @collection_element = element
6
+ @item_name = item_name
7
+ @type = type
8
+ @add_callback = add_callback
9
+ end
10
+
11
+ def size
12
+ @collection_element.Count
13
+ end
14
+
15
+ def count
16
+ size
17
+ end
18
+
19
+ def [](index)
20
+ return @type.new @collection_element.Item index
21
+ end
22
+
23
+ def each
24
+ size.times { |i| yield self[i] }
25
+ end
26
+
27
+ def add
28
+ e = @collection_element.CreateNewElement @item_name.to_s
29
+ added = @type.new e
30
+ @add_callback.call added unless @add_callback.nil?
31
+ yield added
32
+ @collection_element.AddElement e
33
+ added
34
+ end
35
+
36
+ def find
37
+ size.times do |i|
38
+ instance = self[i]
39
+ return instance if yield(instance)
40
+ end
41
+ nil
42
+ end
43
+
44
+ def exists(name)
45
+ !(find {|s| s.name == name}).nil?
46
+ end
47
+
48
+ def remove(index)
49
+ @collection_element.DeleteElement index
50
+ end
51
+ end
@@ -0,0 +1,34 @@
1
+
2
+ class SiteConfiguration < Configuration
3
+
4
+ def initialize(name)
5
+ super "MACHINE/WEBROOT/APPHOST/#{name}"
6
+ end
7
+
8
+ def get_app_settings
9
+ get_collection "appSettings"
10
+ end
11
+
12
+ def get_connection_strings
13
+ get_collection "connectionStrings"
14
+ end
15
+
16
+ def get_validation_settings
17
+ IisObject.new get_admin_section("system.webServer/validation")
18
+ end
19
+
20
+ def get_static_content_settings
21
+ IisObject.new get_admin_section("system.webServer/staticContent")
22
+ end
23
+
24
+ def get_service_model_settings
25
+ IisObject.new get_admin_section("system.serviceModel")
26
+ end
27
+
28
+ private
29
+
30
+ def get_collection(name)
31
+ IisObjectCollection.new get_admin_section(name).Collection, :add, IisObject
32
+ end
33
+
34
+ end
@@ -0,0 +1,74 @@
1
+ require 'rake/tasklib'
2
+
3
+ module Inetmgr
4
+
5
+ class InetmgrTask < ::Rake::TaskLib
6
+ attr_accessor :name
7
+
8
+ def initialize(name, *args, &block)
9
+ @block = block
10
+ args = args.insert(0, name)
11
+ define name, args
12
+ end
13
+
14
+ def define(name, args)
15
+ task *args do |task, task_args|
16
+ @task_args = task_args
17
+ execute name.to_s
18
+ end
19
+ end
20
+
21
+ def call_task_block(obj)
22
+ if !@block.nil?
23
+ if @block.arity == 1
24
+ @block.call(obj)
25
+ else
26
+ @block.call(obj, @task_args)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def create_task(taskname, task_object_proc, &execute_body)
34
+ taskclass = :"Inetmgr_TaskFor_#{taskname}"
35
+ taskmethod = taskname.to_s.downcase.to_sym
36
+
37
+ Object.class_eval(<<-EOF, __FILE__, __LINE__)
38
+ def #{taskmethod}(name=:#{taskname}, *args, &block)
39
+ Inetmgr.const_get("#{taskclass}").new(name, *args, &block)
40
+ end
41
+ EOF
42
+
43
+ Inetmgr.class_eval do
44
+ const_set(taskclass, Class.new(Inetmgr::InetmgrTask) do
45
+ define_method :execute do |name|
46
+ task_object = task_object_proc.call
47
+
48
+ call_task_block(task_object)
49
+ execute_body.call(task_object) unless execute_body.nil?
50
+ end
51
+ end)
52
+ end
53
+ end
54
+
55
+
56
+ create_task :application_pool, Proc.new { ApplicationPool.new } do |pool|
57
+ pool.create
58
+ end
59
+
60
+ create_task :application, Proc.new { Application.new } do |pool|
61
+ pool.create
62
+ end
63
+
64
+ create_task :site, Proc.new { Site.new } do |site|
65
+ site.create
66
+ end
67
+
68
+ create_task :auto_start_provider, Proc.new { AutoStartProvider.new } do |p|
69
+ p.create
70
+ end
71
+
72
+ create_task :virtual_directory, Proc.new { VirtualDirectory.new } do |dir|
73
+ dir.create
74
+ end