zm-ruby-client 0.10.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +58 -0
- data/Gemfile +8 -0
- data/LICENSE +674 -0
- data/README.md +47 -0
- data/SECURITY.md +21 -0
- data/lib/zm/client/account/account.rb +335 -0
- data/lib/zm/client/account/account_dls_membership_collection.rb +22 -0
- data/lib/zm/client/account/account_dls_owner_collection.rb +22 -0
- data/lib/zm/client/account/accounts_builder.rb +19 -0
- data/lib/zm/client/account/accounts_collection.rb +48 -0
- data/lib/zm/client/account.rb +7 -0
- data/lib/zm/client/ace/ace.rb +32 -0
- data/lib/zm/client/ace/aces_builder.rb +25 -0
- data/lib/zm/client/ace/aces_collection.rb +36 -0
- data/lib/zm/client/ace.rb +5 -0
- data/lib/zm/client/appointment/appointment.rb +143 -0
- data/lib/zm/client/appointment/appointment_jsns_builder.rb +125 -0
- data/lib/zm/client/appointment/appointment_jsns_initializer.rb +129 -0
- data/lib/zm/client/appointment/appointments_builder.rb +33 -0
- data/lib/zm/client/appointment/appointments_collection.rb +106 -0
- data/lib/zm/client/appointment.rb +7 -0
- data/lib/zm/client/backup/backup.rb +59 -0
- data/lib/zm/client/backup/backups_builder.rb +26 -0
- data/lib/zm/client/backup/backups_collection.rb +22 -0
- data/lib/zm/client/backup.rb +5 -0
- data/lib/zm/client/base/account_object.rb +17 -0
- data/lib/zm/client/base/admin_object.rb +45 -0
- data/lib/zm/client/base/object.rb +80 -0
- data/lib/zm/client/base/objects_builder.rb +31 -0
- data/lib/zm/client/base/objects_collection.rb +135 -0
- data/lib/zm/client/base.rb +7 -0
- data/lib/zm/client/cluster/cluster.rb +117 -0
- data/lib/zm/client/cluster/cluster_config.rb +100 -0
- data/lib/zm/client/cluster.rb +4 -0
- data/lib/zm/client/common/message.rb +10 -0
- data/lib/zm/client/common/recipients.rb +67 -0
- data/lib/zm/client/common.rb +4 -0
- data/lib/zm/client/config.rb +12 -0
- data/lib/zm/client/connector/rest_account.rb +74 -0
- data/lib/zm/client/connector/soap_account.rb +562 -0
- data/lib/zm/client/connector/soap_admin.rb +512 -0
- data/lib/zm/client/connector/soap_base.rb +65 -0
- data/lib/zm/client/connector/soap_error.rb +26 -0
- data/lib/zm/client/connector/soap_xml_builder.rb +68 -0
- data/lib/zm/client/constant.rb +217 -0
- data/lib/zm/client/contact/contact.rb +124 -0
- data/lib/zm/client/contact/contact_member.rb +73 -0
- data/lib/zm/client/contact/contacts_builder.rb +24 -0
- data/lib/zm/client/contact/contacts_collection.rb +26 -0
- data/lib/zm/client/contact/mod_group_contact.rb +74 -0
- data/lib/zm/client/contact.rb +7 -0
- data/lib/zm/client/cos/cos.rb +59 -0
- data/lib/zm/client/cos/coses_builder.rb +29 -0
- data/lib/zm/client/cos/coses_collection.rb +33 -0
- data/lib/zm/client/cos.rb +5 -0
- data/lib/zm/client/data_source.rb +5 -0
- data/lib/zm/client/distributionlist/distributionlist.rb +125 -0
- data/lib/zm/client/distributionlist/distributionlists_builder.rb +29 -0
- data/lib/zm/client/distributionlist/distributionlists_collection.rb +41 -0
- data/lib/zm/client/distributionlist.rb +5 -0
- data/lib/zm/client/document/document.rb +47 -0
- data/lib/zm/client/document/documents_builder.rb +31 -0
- data/lib/zm/client/document/documents_collection.rb +93 -0
- data/lib/zm/client/document.rb +5 -0
- data/lib/zm/client/domain/domain.rb +74 -0
- data/lib/zm/client/domain/domains_builder.rb +32 -0
- data/lib/zm/client/domain/domains_collection.rb +36 -0
- data/lib/zm/client/domain.rb +5 -0
- data/lib/zm/client/folder/folder.rb +215 -0
- data/lib/zm/client/folder/folder_grant.rb +58 -0
- data/lib/zm/client/folder/folder_retention_policy.rb +48 -0
- data/lib/zm/client/folder/folders_builder.rb +58 -0
- data/lib/zm/client/folder/folders_collection.rb +70 -0
- data/lib/zm/client/folder/mod_document_folder.rb +17 -0
- data/lib/zm/client/folder.rb +8 -0
- data/lib/zm/client/identity/identities_builder.rb +25 -0
- data/lib/zm/client/identity/identities_collection.rb +26 -0
- data/lib/zm/client/identity/identity.rb +75 -0
- data/lib/zm/client/identity.rb +5 -0
- data/lib/zm/client/license/license.rb +29 -0
- data/lib/zm/client/license/licenses_collection.rb +28 -0
- data/lib/zm/client/license.rb +4 -0
- data/lib/zm/client/message/message.rb +225 -0
- data/lib/zm/client/message/messages_builder.rb +31 -0
- data/lib/zm/client/message/messages_collection.rb +111 -0
- data/lib/zm/client/message.rb +5 -0
- data/lib/zm/client/mountpoint/mountpoint.rb +95 -0
- data/lib/zm/client/mountpoint/mountpoints_builder.rb +38 -0
- data/lib/zm/client/mountpoint/mountpoints_collection.rb +61 -0
- data/lib/zm/client/mountpoint.rb +5 -0
- data/lib/zm/client/mta_queue/mta_queue.rb +60 -0
- data/lib/zm/client/mta_queue/mta_queues_builder.rb +26 -0
- data/lib/zm/client/mta_queue/mta_queues_collection.rb +95 -0
- data/lib/zm/client/mta_queue.rb +5 -0
- data/lib/zm/client/mta_queue_item/mta_queue_item.rb +51 -0
- data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +27 -0
- data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +99 -0
- data/lib/zm/client/mta_queue_item.rb +5 -0
- data/lib/zm/client/resource/resource.rb +149 -0
- data/lib/zm/client/resource/resources_builder.rb +29 -0
- data/lib/zm/client/resource/resources_collection.rb +41 -0
- data/lib/zm/client/resource.rb +5 -0
- data/lib/zm/client/search_folder/search_folder.rb +63 -0
- data/lib/zm/client/search_folder/search_folders_builder.rb +26 -0
- data/lib/zm/client/search_folder/search_folders_collection.rb +28 -0
- data/lib/zm/client/search_folder.rb +5 -0
- data/lib/zm/client/server/server.rb +516 -0
- data/lib/zm/client/server/servers_builder.rb +26 -0
- data/lib/zm/client/server/servers_collection.rb +37 -0
- data/lib/zm/client/server.rb +5 -0
- data/lib/zm/client/share/share.rb +60 -0
- data/lib/zm/client/share/shares_builder.rb +23 -0
- data/lib/zm/client/share/shares_collection.rb +48 -0
- data/lib/zm/client/share.rb +5 -0
- data/lib/zm/client/signature/signature.rb +62 -0
- data/lib/zm/client/signature/signature_jsns_builder.rb +29 -0
- data/lib/zm/client/signature/signatures_builder.rb +26 -0
- data/lib/zm/client/signature/signatures_collection.rb +28 -0
- data/lib/zm/client/signature.rb +6 -0
- data/lib/zm/client/tag/tag.rb +45 -0
- data/lib/zm/client/tag/tags_builder.rb +25 -0
- data/lib/zm/client/tag/tags_collection.rb +26 -0
- data/lib/zm/client/tag.rb +5 -0
- data/lib/zm/client/task/task.rb +74 -0
- data/lib/zm/client/task/tasks_builder.rb +31 -0
- data/lib/zm/client/task/tasks_collection.rb +100 -0
- data/lib/zm/client/task.rb +5 -0
- data/lib/zm/client/upload/upload.rb +154 -0
- data/lib/zm/client/upload.rb +3 -0
- data/lib/zm/client/version.rb +18 -0
- data/lib/zm/client.rb +5 -0
- data/lib/zm/modules/common/account_common.rb +71 -0
- data/lib/zm/modules/common/cos_common.rb +463 -0
- data/lib/zm/modules/common/dl_common.rb +33 -0
- data/lib/zm/modules/common/identity_common.rb +19 -0
- data/lib/zm/modules/common/resource_common.rb +59 -0
- data/lib/zm/modules/common/signature_common.rb +16 -0
- data/lib/zm/modules/common/zimbra-attrs.json +1 -0
- data/lib/zm/utils/thread_pool.rb +72 -0
- data/lib/zm-ruby-client.rb +1 -0
- data/test/accounts.rb +62 -0
- data/test/cluster_config.rb +30 -0
- data/test/coses.rb +26 -0
- data/test/domains.rb +62 -0
- data/zm-ruby-client.gemspec +24 -0
- metadata +243 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Zm
|
6
|
+
module Client
|
7
|
+
module Base
|
8
|
+
# Abstract Class Provisionning AdminObject
|
9
|
+
class AdminObject < Object
|
10
|
+
|
11
|
+
def soap_admin_connector
|
12
|
+
@parent.soap_admin_connector
|
13
|
+
end
|
14
|
+
|
15
|
+
alias sac soap_admin_connector
|
16
|
+
|
17
|
+
def soap_account_connector
|
18
|
+
@parent.soap_account_connector
|
19
|
+
end
|
20
|
+
|
21
|
+
alias sacc soap_account_connector
|
22
|
+
|
23
|
+
def init_from_json(json)
|
24
|
+
# TODO : know in advance the typing of variables
|
25
|
+
super(json)
|
26
|
+
return unless json[:a].is_a? Array
|
27
|
+
|
28
|
+
# fix car le tableau peut contenir des {} vide !
|
29
|
+
json[:a].reject! { |n| n[:n].nil? }
|
30
|
+
json_map = json[:a].map { |n| ["@#{n[:n]}", n[:_content]] }.freeze
|
31
|
+
|
32
|
+
json_hash = json_map.reduce({}) { |h, (k, v)| (h[k] ||= []); h[k].push(v); h }.inject({}) { |h, (k, v)| v.length == 1 ? h[k] = v.first : h[k] = v; h }
|
33
|
+
|
34
|
+
json_hash.each do |k, v|
|
35
|
+
instance_variable_set(k, convert_json_string_value(v))
|
36
|
+
end
|
37
|
+
|
38
|
+
# Hash[json_map].each do |k, v|
|
39
|
+
# instance_variable_set(k, convert_json_string_value(v))
|
40
|
+
# end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
module Base
|
6
|
+
# Abstract Class Provisionning Object
|
7
|
+
class Object
|
8
|
+
attr_accessor :parent, :token, :name, :id
|
9
|
+
attr_reader :grantee_type
|
10
|
+
|
11
|
+
def initialize(parent)
|
12
|
+
@parent = parent
|
13
|
+
yield(self) if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def init_from_json(json)
|
17
|
+
@id = json[:id]
|
18
|
+
@name = json[:name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def concat
|
22
|
+
instance_variables.map { |variable| instance_variable_get(variable) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
concat.join(DOUBLEPOINT)
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_json_string_value(value)
|
30
|
+
return value unless value.is_a?(String)
|
31
|
+
return 0 if value == '0'
|
32
|
+
|
33
|
+
c = value.to_i
|
34
|
+
c.to_s == value ? c : value
|
35
|
+
end
|
36
|
+
|
37
|
+
def recorded?
|
38
|
+
!@id.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
def save!
|
42
|
+
recorded? ? modify! : create!
|
43
|
+
end
|
44
|
+
|
45
|
+
def instance_variables_array(zcs_attrs)
|
46
|
+
selected_attrs = zcs_attrs.map { |a| arrow_name(a).to_sym }
|
47
|
+
attrs_only_set = instance_variables & selected_attrs
|
48
|
+
|
49
|
+
arr = attrs_only_set.map do |name|
|
50
|
+
n = name.to_s[1..-1]
|
51
|
+
value = instance_variable_get(name)
|
52
|
+
[n, value]
|
53
|
+
end
|
54
|
+
|
55
|
+
multi_value = arr.select { |a| a.last.is_a?(Array) }
|
56
|
+
arr.reject! { |a| a.last.is_a?(Array) }
|
57
|
+
multi_value.each { |a| arr += a.last.map { |v| [a.first, v] } }
|
58
|
+
arr
|
59
|
+
end
|
60
|
+
|
61
|
+
def instance_variables_hash(zcs_attrs)
|
62
|
+
Hash[instance_variables_array(zcs_attrs)]
|
63
|
+
end
|
64
|
+
|
65
|
+
def arrow_name(name)
|
66
|
+
return name if name.to_s.start_with?('@')
|
67
|
+
|
68
|
+
"@#{name}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def clone
|
72
|
+
obj = super
|
73
|
+
obj.remove_instance_variable(:@id)
|
74
|
+
yield(obj) if block_given?
|
75
|
+
obj
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
module Base
|
6
|
+
# Abstract Class Builder [object]
|
7
|
+
class ObjectsBuilder
|
8
|
+
def initialize(parent, json)
|
9
|
+
@parent = parent
|
10
|
+
@json = json
|
11
|
+
end
|
12
|
+
|
13
|
+
def make
|
14
|
+
return [] if json_items.nil?
|
15
|
+
|
16
|
+
json_items.map do |entry|
|
17
|
+
child = @child_class.new(@parent)
|
18
|
+
child.init_from_json(entry)
|
19
|
+
child
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def json_key
|
26
|
+
@json_key ||= @json[:Body].keys.first
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
module Zm
|
5
|
+
module Client
|
6
|
+
module Base
|
7
|
+
# Abstract Class Collection
|
8
|
+
class ObjectsCollection
|
9
|
+
METHODS_MISSING_LIST = %i[select each map length].to_set.freeze
|
10
|
+
attr_reader :parent
|
11
|
+
|
12
|
+
def new
|
13
|
+
child = @child_class.new(@parent)
|
14
|
+
yield(child) if block_given?
|
15
|
+
child
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(id)
|
19
|
+
find_by(id: id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_from_entry(entry)
|
23
|
+
child = @child_class.new(@parent)
|
24
|
+
child.init_from_json(entry)
|
25
|
+
child
|
26
|
+
end
|
27
|
+
|
28
|
+
def first
|
29
|
+
@limit = 1
|
30
|
+
build_response.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def all
|
34
|
+
@all || all!
|
35
|
+
end
|
36
|
+
|
37
|
+
def all!
|
38
|
+
@all = build_response
|
39
|
+
end
|
40
|
+
|
41
|
+
def where(ldap_query)
|
42
|
+
return self if @ldap_query == ldap_query
|
43
|
+
|
44
|
+
@all = nil
|
45
|
+
@ldap_query = ldap_query
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def per_page(limit)
|
50
|
+
return self if @limit == limit
|
51
|
+
|
52
|
+
@all = nil
|
53
|
+
@limit = limit
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def page(offset)
|
58
|
+
return self if @offset == offset
|
59
|
+
|
60
|
+
@all = nil
|
61
|
+
@offset = offset
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def order(sort_by, sort_ascending = SoapUtils::ON)
|
66
|
+
return self if @sort_by == sort_by && @sort_ascending == sort_ascending
|
67
|
+
|
68
|
+
@all = nil
|
69
|
+
@sort_by = sort_by
|
70
|
+
@sort_ascending = sort_ascending
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
def count
|
75
|
+
@count_only = SoapUtils::ON
|
76
|
+
make_query[:Body][:SearchDirectoryResponse][:num]
|
77
|
+
end
|
78
|
+
|
79
|
+
def attrs(*attrs)
|
80
|
+
return self if @attrs == attrs
|
81
|
+
|
82
|
+
@all = nil
|
83
|
+
@attrs = attrs
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def method_missing(method, *args, &block)
|
88
|
+
if METHODS_MISSING_LIST.include?(method)
|
89
|
+
build_response.send(method, *args, &block)
|
90
|
+
else
|
91
|
+
super
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def respond_to_missing?(method, *)
|
96
|
+
METHODS_MISSING_LIST.include?(method) || super
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def soap_admin_connector
|
102
|
+
@parent.soap_admin_connector
|
103
|
+
end
|
104
|
+
|
105
|
+
alias sac soap_admin_connector
|
106
|
+
|
107
|
+
def make_query
|
108
|
+
json = sac.search_directory(
|
109
|
+
@ldap_query, @max_result, @limit, @offset,
|
110
|
+
@domain_name, @apply_cos, nil, @sort_by, @search_type,
|
111
|
+
@sort_ascending, @count_only, attrs_comma
|
112
|
+
)
|
113
|
+
reset_query_params
|
114
|
+
json
|
115
|
+
end
|
116
|
+
|
117
|
+
def attrs_comma
|
118
|
+
return @attrs unless @attrs.is_a?(Array)
|
119
|
+
|
120
|
+
@attrs.uniq!
|
121
|
+
@attrs.join(COMMA)
|
122
|
+
end
|
123
|
+
|
124
|
+
def reset_query_params
|
125
|
+
@max_result = SoapUtils::MAX_RESULT
|
126
|
+
@limit = nil
|
127
|
+
@offset = nil
|
128
|
+
@sort_by = nil
|
129
|
+
@sort_ascending = SoapUtils::ON
|
130
|
+
@count_only = SoapUtils::OFF
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zm/client/connector/soap_admin'
|
4
|
+
require 'zm/client/connector/soap_account'
|
5
|
+
require 'zm/client/common'
|
6
|
+
# require 'zm/client/data_source'
|
7
|
+
require 'zm/client/domain'
|
8
|
+
require 'zm/client/account'
|
9
|
+
require 'zm/client/resource'
|
10
|
+
require 'zm/client/distributionlist'
|
11
|
+
require 'zm/client/server'
|
12
|
+
require 'zm/client/cos'
|
13
|
+
require 'zm/client/license'
|
14
|
+
# require 'zm/client/distributionlist'
|
15
|
+
|
16
|
+
module Zm
|
17
|
+
module Client
|
18
|
+
# class admin connection
|
19
|
+
class Cluster
|
20
|
+
attr_reader :soap_admin_connector, :config
|
21
|
+
|
22
|
+
def initialize(config)
|
23
|
+
@config = config
|
24
|
+
@soap_admin_connector = SoapAdminConnector.new(
|
25
|
+
@config.zimbra_admin_scheme,
|
26
|
+
@config.zimbra_admin_host,
|
27
|
+
@config.zimbra_admin_port
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def login
|
32
|
+
@soap_admin_connector.auth(
|
33
|
+
@config.zimbra_admin_login,
|
34
|
+
@config.zimbra_admin_password
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def logged?
|
39
|
+
!@soap_admin_connector.token.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def alive?
|
43
|
+
@soap_admin_connector.noop
|
44
|
+
true
|
45
|
+
rescue Zm::Client::SoapError => _
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def soap_account_connector
|
50
|
+
@soap_account_connector ||= SoapAccountConnector.new(
|
51
|
+
@config.zimbra_public_scheme,
|
52
|
+
@config.zimbra_public_host,
|
53
|
+
@config.zimbra_public_port
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def license
|
58
|
+
@license ||= LicensesCollection.new(self).find
|
59
|
+
rescue Zm::Client::SoapError => e
|
60
|
+
puts e.message
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def domains
|
65
|
+
@domains ||= DomainsCollection.new self
|
66
|
+
end
|
67
|
+
|
68
|
+
def accounts
|
69
|
+
@accounts ||= AccountsCollection.new self
|
70
|
+
end
|
71
|
+
|
72
|
+
def resources
|
73
|
+
@resources ||= ResourcesCollection.new self
|
74
|
+
end
|
75
|
+
|
76
|
+
def servers
|
77
|
+
@servers ||= ServersCollection.new self
|
78
|
+
end
|
79
|
+
|
80
|
+
def coses
|
81
|
+
@coses ||= CosesCollection.new self
|
82
|
+
end
|
83
|
+
|
84
|
+
def distributionlists
|
85
|
+
@distributionlists ||= DistributionListsCollection.new self
|
86
|
+
end
|
87
|
+
|
88
|
+
alias distribution_lists distributionlists
|
89
|
+
|
90
|
+
def domain_key(domain_name)
|
91
|
+
key = @config.domain_key(domain_name)
|
92
|
+
key ||= find_domain_key(domain_name)
|
93
|
+
key
|
94
|
+
end
|
95
|
+
|
96
|
+
def count_object(type)
|
97
|
+
raise ZmError, 'Unknown object type' unless Zm::Client::CountTypes::ALL.include?(type)
|
98
|
+
|
99
|
+
resp = soap_admin_connector.count_object(type)
|
100
|
+
resp[:Body][:CountObjectsResponse][:num]
|
101
|
+
end
|
102
|
+
|
103
|
+
def email_exist?(email)
|
104
|
+
filter = "(mail=#{email})"
|
105
|
+
resp = soap_admin_connector.search_directory(filter, nil, nil, nil, nil, nil, nil, nil, 'accounts,distributionlists,aliases,resources',nil, 1)
|
106
|
+
num = resp[:Body][:SearchDirectoryResponse][:num]
|
107
|
+
!num.zero?
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def find_domain_key(domain_name)
|
113
|
+
domains.find_by({ name: domain_name }, 'zimbraPreAuthKey').zimbraPreAuthKey
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Zm
|
6
|
+
module Client
|
7
|
+
# class config for cluster connection
|
8
|
+
class ClusterConfig
|
9
|
+
attr_reader :to_h
|
10
|
+
attr_accessor :zimbra_admin_host, :zimbra_admin_scheme,
|
11
|
+
:zimbra_admin_port, :zimbra_admin_login,
|
12
|
+
:zimbra_admin_password, :zimbra_public_host,
|
13
|
+
:zimbra_public_scheme, :zimbra_public_port,
|
14
|
+
:domains
|
15
|
+
|
16
|
+
def initialize(parameters = nil)
|
17
|
+
@zimbra_admin_scheme = 'https'
|
18
|
+
@zimbra_admin_port = 7071
|
19
|
+
@zimbra_public_scheme = 'https'
|
20
|
+
@zimbra_public_port = 443
|
21
|
+
@domains = []
|
22
|
+
|
23
|
+
if parameters.is_a?(String)
|
24
|
+
init_from_file(parameters)
|
25
|
+
elsif parameters.is_a?(Hash)
|
26
|
+
@to_h = parameters
|
27
|
+
end
|
28
|
+
|
29
|
+
unless @to_h.nil?
|
30
|
+
init_from_h
|
31
|
+
make_config_domain
|
32
|
+
end
|
33
|
+
|
34
|
+
yield(self) if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
def init_from_file(file_config_path)
|
38
|
+
if file_config_path.end_with?('.json')
|
39
|
+
init_from_json(file_config_path)
|
40
|
+
elsif file_config_path.end_with?('.yml', '.yaml')
|
41
|
+
init_from_yml(file_config_path)
|
42
|
+
else
|
43
|
+
raise ClusterConfigError, 'no valid config file extension'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def init_from_h
|
48
|
+
@zimbra_admin_host = @to_h[:zimbra_admin_host] unless @to_h[:zimbra_admin_host].nil?
|
49
|
+
@zimbra_admin_scheme = @to_h[:zimbra_admin_scheme] unless @to_h[:zimbra_admin_scheme].nil?
|
50
|
+
@zimbra_admin_port = @to_h[:zimbra_admin_port] unless @to_h[:zimbra_admin_port].nil?
|
51
|
+
@zimbra_admin_login = @to_h[:zimbra_admin_login] unless @to_h[:zimbra_admin_login].nil?
|
52
|
+
@zimbra_admin_password = @to_h[:zimbra_admin_password] unless @to_h[:zimbra_admin_password].nil?
|
53
|
+
@zimbra_public_host = @to_h[:zimbra_public_host] unless @to_h[:zimbra_public_host].nil?
|
54
|
+
@zimbra_public_scheme = @to_h[:zimbra_public_scheme] unless @to_h[:zimbra_public_scheme].nil?
|
55
|
+
@zimbra_public_port = @to_h[:zimbra_public_port] unless @to_h[:zimbra_public_port].nil?
|
56
|
+
end
|
57
|
+
|
58
|
+
def init_from_yml(file_config_path)
|
59
|
+
@to_h = YAML.safe_load(File.read(file_config_path), symbolize_names: true)
|
60
|
+
end
|
61
|
+
|
62
|
+
def init_from_json(file_config_path)
|
63
|
+
@to_h = JSON.parse(File.read(file_config_path), symbolize_names: true)
|
64
|
+
end
|
65
|
+
|
66
|
+
def make_config_domain
|
67
|
+
return if @to_h[:domains].nil?
|
68
|
+
|
69
|
+
@domains = @to_h[:domains].map do |h|
|
70
|
+
ClusterConfigDomain.new(h[:name], h[:key])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_domain(domain_name)
|
75
|
+
@domains.find { |d| d.name == domain_name }
|
76
|
+
end
|
77
|
+
|
78
|
+
def domain_key(domain_name)
|
79
|
+
domain = find_domain(domain_name)
|
80
|
+
return nil if domain.nil?
|
81
|
+
|
82
|
+
domain.key
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# class config for connection
|
87
|
+
class ClusterConfigDomain
|
88
|
+
attr_reader :name, :key
|
89
|
+
|
90
|
+
def initialize(name, key)
|
91
|
+
@name = name
|
92
|
+
@key = key
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# class error for config
|
97
|
+
class ClusterConfigError < StandardError
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
|
6
|
+
# Collection recipients
|
7
|
+
class Recipients
|
8
|
+
def initialize
|
9
|
+
@recipients = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def map(&block)
|
13
|
+
@recipients.map(&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(recipient)
|
17
|
+
return unless recipient.is_a?(Recipient)
|
18
|
+
|
19
|
+
@recipients.push(recipient)
|
20
|
+
end
|
21
|
+
|
22
|
+
def del(recipient)
|
23
|
+
if recipient.is_a?(Recipient)
|
24
|
+
@recipients.delete(recipient)
|
25
|
+
elsif recipient.is_a?(String)
|
26
|
+
@recipients.delete_if { |r| r.email == recipient }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear
|
31
|
+
@recipients.clear
|
32
|
+
end
|
33
|
+
|
34
|
+
def to
|
35
|
+
@recipients.select { |r| r.field == Recipient::TO }
|
36
|
+
end
|
37
|
+
|
38
|
+
def cc
|
39
|
+
@recipients.select { |r| r.field == Recipient::CC }
|
40
|
+
end
|
41
|
+
|
42
|
+
def bcc
|
43
|
+
@recipients.select { |r| r.field == Recipient::BCC }
|
44
|
+
end
|
45
|
+
|
46
|
+
def from
|
47
|
+
@recipients.select { |r| r.field == Recipient::FROM }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Class one recipient for email
|
52
|
+
class Recipient
|
53
|
+
FROM = :f
|
54
|
+
TO = :t
|
55
|
+
CC = :c
|
56
|
+
BCC = :b
|
57
|
+
|
58
|
+
attr_accessor :field, :email, :display_name
|
59
|
+
|
60
|
+
def initialize(field, email, display_name = nil)
|
61
|
+
@email = email
|
62
|
+
@field = field.to_sym
|
63
|
+
@display_name = display_name
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'curb'
|
5
|
+
|
6
|
+
module Zm
|
7
|
+
module Client
|
8
|
+
class RestAccountConnector
|
9
|
+
attr_reader :verbose, :follow_location
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@verbose = false
|
13
|
+
@follow_location = true
|
14
|
+
@curl = easy_curl
|
15
|
+
end
|
16
|
+
|
17
|
+
def verbose!
|
18
|
+
@verbose = true
|
19
|
+
@curl.verbose = @verbose
|
20
|
+
end
|
21
|
+
|
22
|
+
def cookie(cookie)
|
23
|
+
@curl.headers['Cookie'] = cookie
|
24
|
+
end
|
25
|
+
|
26
|
+
def download(url, dest_file_path)
|
27
|
+
@curl.url = URI.escape(url)
|
28
|
+
File.open(dest_file_path, 'wb') do |f|
|
29
|
+
@curl.on_body do |data|
|
30
|
+
f << data
|
31
|
+
data.size
|
32
|
+
end
|
33
|
+
@curl.perform
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def upload(url, src_file_path)
|
38
|
+
@curl.url = URI.escape(url)
|
39
|
+
@curl.http_post(Curl::PostField.file('file', src_file_path))
|
40
|
+
|
41
|
+
if @curl.status.to_i >= 400
|
42
|
+
messages = [
|
43
|
+
"Upload failure ! #{src_file_path}",
|
44
|
+
extract_title(@curl.body_str)
|
45
|
+
].compact
|
46
|
+
raise RestError, messages.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
@curl.body_str
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def easy_curl
|
55
|
+
Curl::Easy.new do |curl|
|
56
|
+
curl.timeout = 300
|
57
|
+
curl.enable_cookies = false
|
58
|
+
curl.encoding = ''
|
59
|
+
curl.ssl_verify_peer = false
|
60
|
+
curl.ssl_verify_host = 0
|
61
|
+
curl.multipart_form_post = true
|
62
|
+
curl.verbose = verbose
|
63
|
+
curl.follow_location = follow_location
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def extract_title(str)
|
68
|
+
str.scan(%r{<title>(.*)</title>}).first.first
|
69
|
+
rescue StandardError
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|