iisconfig 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,101 +1,101 @@
1
- $:.push File.expand_path(File.dirname(__FILE__))
2
-
3
- require 'rexml/document'
4
- require 'app_pool'
5
- require 'ftp_site'
6
- require 'site'
7
-
8
- module IISConfig
9
-
10
- class IISConfiguration
11
- @@dry_run = false
12
-
13
- def initialize(options = {})
14
- @options = {recycle_apppools: false}.merge(options)
15
- @app_pools = []
16
- @sites = []
17
- @ftp_sites = []
18
- @before = []
19
- @after = []
20
- end
21
-
22
- def self.dry_run=dry_run
23
- @@dry_run = dry_run
24
- end
25
-
26
- def self.dry_run?
27
- @@dry_run
28
- end
29
-
30
- def app_pool(&block)
31
- add_instance @app_pools, IISConfig::AppPool, block
32
- end
33
-
34
- def site(&block)
35
- add_instance @sites, IISConfig::Site, block
36
- end
37
-
38
- def ftp_site(&block)
39
- add_instance @ftp_sites, IISConfig::FtpSite, block
40
- end
41
-
42
- def before(&block)
43
- @before << block
44
- end
45
-
46
- def after(&block)
47
- @after << block
48
- end
49
-
50
- def load(path)
51
- instance_eval IO.read(path), path
52
- end
53
-
54
- def run
55
- @before.each { |a| a.call }
56
-
57
- if @options[:recycle_apppools]
58
- recycle_application_pools
59
- else
60
- rebuild_all
61
- end
62
-
63
- @after.each { |a| a.call }
64
- end
65
-
66
- private
67
-
68
- def rebuild_all
69
- execute @app_pools
70
- execute @sites
71
- execute @ftp_sites
72
- end
73
-
74
- def recycle_application_pools
75
- @app_pools.each do |p|
76
- commands = p.recycle
77
- Runner.run_commands [commands] unless commands.empty?
78
- end
79
- end
80
-
81
- def execute(objects)
82
- objects.each do |p|
83
- commands = p.build_commands
84
- Runner.run_commands commands
85
-
86
- p.required_paths.each do |path|
87
- FileUtils.mkdir_p path unless Dir.exist? path
88
- end
89
- end
90
- end
91
-
92
- def add_instance(collection, type, block)
93
- instance = type.new
94
- collection << instance
95
- block.call instance if block
96
- end
97
-
98
- end
99
-
100
- end
101
-
1
+ $:.push File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'rexml/document'
4
+ require 'app_pool'
5
+ require 'ftp_site'
6
+ require 'site'
7
+
8
+ module IISConfig
9
+
10
+ class IISConfiguration
11
+ @@dry_run = false
12
+
13
+ def initialize(options = {})
14
+ @options = {recycle_apppools: false}.merge(options)
15
+ @app_pools = []
16
+ @sites = []
17
+ @ftp_sites = []
18
+ @before = []
19
+ @after = []
20
+ end
21
+
22
+ def self.dry_run=dry_run
23
+ @@dry_run = dry_run
24
+ end
25
+
26
+ def self.dry_run?
27
+ @@dry_run
28
+ end
29
+
30
+ def app_pool(&block)
31
+ add_instance @app_pools, IISConfig::AppPool, block
32
+ end
33
+
34
+ def site(&block)
35
+ add_instance @sites, IISConfig::Site, block
36
+ end
37
+
38
+ def ftp_site(&block)
39
+ add_instance @ftp_sites, IISConfig::FtpSite, block
40
+ end
41
+
42
+ def before(&block)
43
+ @before << block
44
+ end
45
+
46
+ def after(&block)
47
+ @after << block
48
+ end
49
+
50
+ def load(path)
51
+ instance_eval IO.read(path), path
52
+ end
53
+
54
+ def run
55
+ @before.each { |a| a.call }
56
+
57
+ if @options[:recycle_apppools]
58
+ recycle_application_pools
59
+ else
60
+ rebuild_all
61
+ end
62
+
63
+ @after.each { |a| a.call }
64
+ end
65
+
66
+ private
67
+
68
+ def rebuild_all
69
+ execute @app_pools
70
+ execute @sites
71
+ execute @ftp_sites
72
+ end
73
+
74
+ def recycle_application_pools
75
+ @app_pools.each do |p|
76
+ commands = p.recycle
77
+ Runner.run_commands [commands] unless commands.empty?
78
+ end
79
+ end
80
+
81
+ def execute(objects)
82
+ objects.each do |p|
83
+ commands = p.build_commands
84
+ Runner.run_commands commands
85
+
86
+ p.required_paths.each do |path|
87
+ FileUtils.mkdir_p path unless Dir.exist? path
88
+ end
89
+ end
90
+ end
91
+
92
+ def add_instance(collection, type, block)
93
+ instance = type.new
94
+ collection << instance
95
+ block.call instance if block
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+
@@ -1,92 +1,92 @@
1
- require 'iis_object'
2
- require 'application'
3
-
4
- module IISConfig
5
-
6
- class FtpSite < IISObject
7
-
8
- def initialize
9
- @bindings = []
10
- @authentication = []
11
- @allow_authorization = []
12
- end
13
-
14
- def name(name = nil)
15
- @name = name unless name.nil?
16
- @name
17
- end
18
-
19
- def binding(binding)
20
- @bindings << binding
21
- end
22
-
23
- def app_pool(pool)
24
- @app_pool = pool
25
- end
26
-
27
- def physical_path(path)
28
- @physical_path = path
29
- end
30
-
31
- def enable_authentication(*authentication)
32
- @authentication += authentication
33
- end
34
-
35
- def allow_authorization(permissions, access)
36
- @allow_authorization << { :permissions => permissions, :access => access }
37
- end
38
-
39
- def allow_ssl
40
- @ssl = :allow
41
- end
42
-
43
- def delete
44
- %W{DELETE SITE #{@name}}
45
- end
46
-
47
- def add
48
- args = []
49
- args << 'ADD'
50
- args << 'SITE'
51
- args << "/name:#{@name}"
52
- args << "/bindings:\"#{@bindings.join('","')}\""
53
- args << "/physicalPath:#{@physical_path.gsub(/\//, '\\')}"
54
-
55
- args
56
- end
57
-
58
- def required_paths
59
- paths = []
60
- paths << @physical_path
61
- paths
62
- end
63
-
64
- def build_commands()
65
- commands = []
66
- commands << delete if exist? :site, @name
67
- commands << add
68
-
69
- commands << %W{SET SITE /site.name:#{@name} /[path='/'].applicationPool:#{@app_pool}} unless @app_pool.nil?
70
-
71
- @allow_authorization.each do |a|
72
- permissions = a[:permissions].map { |p| p.capitalize }.join(',')
73
- roles = a[:access][:roles]
74
- users = a[:access][:users]
75
- commands << %W{SET CONFIG #{@name} /section:system.ftpserver/security/authorization /+[accessType='Allow',permissions='#{permissions}',roles='#{roles}',users='#{users}'] /commit:apphost}
76
- end
77
-
78
- @authentication.each do |a|
79
- commands << %W{SET CONFIG -section:system.applicationHost/sites /[name='#{@name}'].ftpServer.security.authentication.#{a}Authentication.enabled:true}
80
- end
81
-
82
- unless @ssl.nil?
83
- commands << %W{SET CONFIG -section:system.applicationHost/sites /[name='#{@name}'].ftpServer.security.ssl.controlChannelPolicy:"Ssl#{@ssl.capitalize}"}
84
- commands << %W{SET CONFIG -section:system.applicationHost/sites /[name='#{@name}'].ftpServer.security.ssl.dataChannelPolicy:"Ssl#{@ssl.capitalize}"}
85
- end
86
-
87
- commands
88
- end
89
-
90
- end
91
-
1
+ require 'iis_object'
2
+ require 'application'
3
+
4
+ module IISConfig
5
+
6
+ class FtpSite < IISObject
7
+
8
+ def initialize
9
+ @bindings = []
10
+ @authentication = []
11
+ @allow_authorization = []
12
+ end
13
+
14
+ def name(name = nil)
15
+ @name = name unless name.nil?
16
+ @name
17
+ end
18
+
19
+ def binding(binding)
20
+ @bindings << binding
21
+ end
22
+
23
+ def app_pool(pool)
24
+ @app_pool = pool
25
+ end
26
+
27
+ def physical_path(path)
28
+ @physical_path = path
29
+ end
30
+
31
+ def enable_authentication(*authentication)
32
+ @authentication += authentication
33
+ end
34
+
35
+ def allow_authorization(permissions, access)
36
+ @allow_authorization << { :permissions => permissions, :access => access }
37
+ end
38
+
39
+ def allow_ssl
40
+ @ssl = :allow
41
+ end
42
+
43
+ def delete
44
+ %W{DELETE SITE #{@name}}
45
+ end
46
+
47
+ def add
48
+ args = []
49
+ args << 'ADD'
50
+ args << 'SITE'
51
+ args << "/name:#{@name}"
52
+ args << "/bindings:\"#{@bindings.join('","')}\""
53
+ args << "/physicalPath:#{@physical_path.gsub(/\//, '\\')}"
54
+
55
+ args
56
+ end
57
+
58
+ def required_paths
59
+ paths = []
60
+ paths << @physical_path
61
+ paths
62
+ end
63
+
64
+ def build_commands()
65
+ commands = []
66
+ commands << delete if exist? :site, @name
67
+ commands << add
68
+
69
+ commands << %W{SET SITE /site.name:#{@name} /[path='/'].applicationPool:#{@app_pool}} unless @app_pool.nil?
70
+
71
+ @allow_authorization.each do |a|
72
+ permissions = a[:permissions].map { |p| p.capitalize }.join(',')
73
+ roles = a[:access][:roles]
74
+ users = a[:access][:users]
75
+ commands << %W{SET CONFIG #{@name} /section:system.ftpserver/security/authorization /+[accessType='Allow',permissions='#{permissions}',roles='#{roles}',users='#{users}'] /commit:apphost}
76
+ end
77
+
78
+ @authentication.each do |a|
79
+ commands << %W{SET CONFIG -section:system.applicationHost/sites /[name='#{@name}'].ftpServer.security.authentication.#{a}Authentication.enabled:true}
80
+ end
81
+
82
+ unless @ssl.nil?
83
+ commands << %W{SET CONFIG -section:system.applicationHost/sites /[name='#{@name}'].ftpServer.security.ssl.controlChannelPolicy:"Ssl#{@ssl.capitalize}"}
84
+ commands << %W{SET CONFIG -section:system.applicationHost/sites /[name='#{@name}'].ftpServer.security.ssl.dataChannelPolicy:"Ssl#{@ssl.capitalize}"}
85
+ end
86
+
87
+ commands
88
+ end
89
+
90
+ end
91
+
92
92
  end
@@ -1,35 +1,35 @@
1
- require 'runner'
2
-
3
- module IISConfig
4
-
5
- class IISObject
6
-
7
- def exist?(type, name)
8
- args = []
9
- args << 'LIST'
10
- args << type.to_s.upcase
11
- args << '/xml'
12
- result = Runner.execute_command args
13
-
14
- exists = false
15
- doc = REXML::Document.new(result)
16
-
17
- doc.elements.each("appcmd/#{type.to_s.upcase}[@#{type.to_s.upcase}.NAME='#{name}']") do
18
- exists = true
19
- break
20
- end
21
-
22
- exists
23
- end
24
-
25
- protected
26
-
27
- def add_instance(collection, type, block)
28
- instance = type.new
29
- collection << instance
30
- block.call instance if block
31
- end
32
-
33
- end
34
-
1
+ require 'runner'
2
+
3
+ module IISConfig
4
+
5
+ class IISObject
6
+
7
+ def exist?(type, name)
8
+ args = []
9
+ args << 'LIST'
10
+ args << type.to_s.upcase
11
+ args << '/xml'
12
+ result = Runner.execute_command args
13
+
14
+ exists = false
15
+ doc = REXML::Document.new(result)
16
+
17
+ doc.elements.each("appcmd/#{type.to_s.upcase}[@#{type.to_s.upcase}.NAME='#{name}']") do
18
+ exists = true
19
+ break
20
+ end
21
+
22
+ exists
23
+ end
24
+
25
+ protected
26
+
27
+ def add_instance(collection, type, block)
28
+ instance = type.new
29
+ collection << instance
30
+ block.call instance if block
31
+ end
32
+
33
+ end
34
+
35
35
  end