lardawge-rfm 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rfm_command.rb +61 -12
- data/lib/rfm_result.rb +26 -26
- metadata +1 -1
data/lib/rfm_command.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'net/
|
2
|
-
require 'rexml/document'
|
1
|
+
require 'net/https'
|
3
2
|
require 'cgi'
|
3
|
+
require 'hpricot'
|
4
4
|
|
5
5
|
# This module includes classes that represent base FileMaker concepts like servers,
|
6
6
|
# layouts, and scripts. These classes allow you to communicate with FileMaker Server,
|
@@ -58,6 +58,46 @@ module Rfm
|
|
58
58
|
|
59
59
|
class Server
|
60
60
|
|
61
|
+
#
|
62
|
+
# SSL AND CERTIFICATE VERIFICATION ARE ON BY DEFAULT
|
63
|
+
#
|
64
|
+
# Example to turn off SSL:
|
65
|
+
#
|
66
|
+
# response = myServer.do_action(
|
67
|
+
# :host => 'localhost',
|
68
|
+
# :account_name => 'sample',
|
69
|
+
# :password => '12345',
|
70
|
+
# :ssl => false
|
71
|
+
# )
|
72
|
+
#
|
73
|
+
# Example using SSL without *root_cert*:
|
74
|
+
#
|
75
|
+
# response = myServer.do_action(
|
76
|
+
# :host => 'localhost',
|
77
|
+
# :account_name => 'sample',
|
78
|
+
# :password => '12345',
|
79
|
+
# :root_cert => false
|
80
|
+
# )
|
81
|
+
#
|
82
|
+
# Example using SSL with *root_cert* at file root:
|
83
|
+
#
|
84
|
+
# response = myServer.do_action(
|
85
|
+
# :host => 'localhost',
|
86
|
+
# :account_name => 'sample',
|
87
|
+
# :password => '12345',
|
88
|
+
# :root_cert_name => 'example.pem'
|
89
|
+
# )
|
90
|
+
#
|
91
|
+
# Example using SSL with *root_cert* specifying *root_cert_path*:
|
92
|
+
#
|
93
|
+
# response = myServer.do_action(
|
94
|
+
# :host => 'localhost',
|
95
|
+
# :account_name => 'sample',
|
96
|
+
# :password => '12345',
|
97
|
+
# :root_cert_name => 'example.pem'
|
98
|
+
# :root_cert_path => '/usr/cert_file/'
|
99
|
+
# )
|
100
|
+
#
|
61
101
|
# To create a Server obejct, you typically need at least a host name:
|
62
102
|
#
|
63
103
|
# myServer = Rfm::Server.new({:host => 'my.host.com'})
|
@@ -68,12 +108,18 @@ module Rfm
|
|
68
108
|
#
|
69
109
|
# * *port* the port number the WPE is listening no (defaults to 80 unless *ssl* +true+ which sets it to 443)
|
70
110
|
#
|
71
|
-
# * *ssl* +
|
111
|
+
# * *ssl* +false+ if you want to turn SSL (HTTPS) off when connecting to connect to FileMaker (default is +true+)
|
112
|
+
#
|
113
|
+
# If you have SSL on and want
|
114
|
+
# * *root_cert* +false+ if you do not want to verify your SSL session (default is +true+).
|
115
|
+
# You will want to turn this off if you are using a self signed certificate and do not have a certificate authority cert file.
|
116
|
+
# If you choose this option you will need to provide a cert *root_cert_name* and *root_cert_path* (if not in root directory).
|
72
117
|
#
|
73
|
-
# * *
|
118
|
+
# * *root_cert_name* name of pem file for certificate verification (Root cert from certificate authority who issued certificate.
|
74
119
|
# If self signed certificate do not use this option!!). You can download the entire bundle of CA Root Certificates
|
75
|
-
# from http://curl.haxx.se/ca/cacert.pem. Place the pem file in config directory.
|
76
|
-
#
|
120
|
+
# from http://curl.haxx.se/ca/cacert.pem. Place the pem file in config directory.
|
121
|
+
#
|
122
|
+
# * *root_cert_path* path to cert file. (defaults to '/' if no path given)
|
77
123
|
#
|
78
124
|
# * *account_name* the default account name to log in to databases with (you can also supply a
|
79
125
|
# account name on a per-database basis if necessary)
|
@@ -94,12 +140,15 @@ module Rfm
|
|
94
140
|
# * *raise_on_401* although RFM raises error when FileMaker returns error responses, it typically
|
95
141
|
# ignores FileMaker's 401 error (no records found) and returns an empty record set instead; if you
|
96
142
|
# prefer a raised error when a find produces no errors, set this option to +true+
|
143
|
+
|
97
144
|
def initialize(options)
|
98
145
|
@state = {
|
99
146
|
:host => 'localhost',
|
100
147
|
:port => 80,
|
101
|
-
:ssl =>
|
102
|
-
:root_cert =>
|
148
|
+
:ssl => true,
|
149
|
+
:root_cert => true,
|
150
|
+
:root_cert_name => '',
|
151
|
+
:root_cert_path => '/',
|
103
152
|
:account_name => '',
|
104
153
|
:password => '',
|
105
154
|
:log_actions => false,
|
@@ -117,7 +166,7 @@ module Rfm
|
|
117
166
|
|
118
167
|
@host_name = @state[:host]
|
119
168
|
@scheme = @state[:ssl] ? "https" : "http"
|
120
|
-
@port = @state[:ssl] && options[:port].
|
169
|
+
@port = @state[:ssl] && options[:port].nil? ? 443 : @state[:port]
|
121
170
|
|
122
171
|
@db = Rfm::Factory::DbFactory.new(self)
|
123
172
|
end
|
@@ -194,11 +243,11 @@ module Rfm
|
|
194
243
|
request.set_form_data(post_data)
|
195
244
|
|
196
245
|
response = Net::HTTP.new(host_name, port)
|
197
|
-
if @scheme == "https" # enable SSL
|
246
|
+
if @scheme == "https" # enable SSL
|
198
247
|
response.use_ssl = true
|
199
|
-
|
248
|
+
if @state[:root_cert]
|
200
249
|
response.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
201
|
-
response.ca_file = File.join(
|
250
|
+
response.ca_file = File.join(@state[:root_cert_path], @state[:root_cert_name])
|
202
251
|
else
|
203
252
|
response.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
204
253
|
end
|
data/lib/rfm_result.rb
CHANGED
@@ -71,48 +71,47 @@ module Rfm::Result
|
|
71
71
|
@total_count = nil
|
72
72
|
@foundset_count = nil
|
73
73
|
|
74
|
-
doc =
|
75
|
-
root = doc.root
|
74
|
+
doc = Hpricot.XML(fmresultset)
|
76
75
|
|
77
76
|
# check for errors
|
78
|
-
error =
|
77
|
+
error = doc.search('error').attr('code').to_i
|
79
78
|
if error != 0 && (error != 401 || @server.state[:raise_on_401])
|
80
79
|
raise Rfm::Error::FileMakerError.getError(error)
|
81
80
|
end
|
82
81
|
|
83
82
|
# ascertain date and time formats
|
84
|
-
datasource =
|
85
|
-
@date_format = convertFormatString(datasource.
|
86
|
-
@time_format = convertFormatString(datasource.
|
87
|
-
@timestamp_format = convertFormatString(datasource.
|
88
|
-
|
83
|
+
datasource = doc.search('datasource')
|
84
|
+
@date_format = convertFormatString(datasource.attr('date-format'))
|
85
|
+
@time_format = convertFormatString(datasource.attr('time-format'))
|
86
|
+
@timestamp_format = convertFormatString(datasource.attr('timestamp-format'))
|
87
|
+
|
89
88
|
# process count metadata
|
90
89
|
@total_count = datasource.attributes['total-count'].to_i
|
91
90
|
@foundset_count = root.elements['resultset'].attributes['count'].to_i
|
92
91
|
|
93
92
|
# process field metadata
|
94
|
-
|
93
|
+
doc.search('field-definition').each do |field|
|
95
94
|
name = field.attributes['name']
|
96
95
|
@fields[name] = Field.new(self, field)
|
97
|
-
|
96
|
+
end
|
98
97
|
@fields.freeze
|
99
98
|
|
100
99
|
# process relatedset metadata
|
101
|
-
|
102
|
-
table = relatedset.
|
100
|
+
doc.search('relatedset-definition').each do |relatedset|
|
101
|
+
table = relatedset.attr('table')
|
103
102
|
fields = {}
|
104
|
-
relatedset.
|
105
|
-
name = field.
|
103
|
+
relatedset.search('field-definition').each do |field|
|
104
|
+
name = field.attr('name').sub(Regexp.new(table + '::'), '')
|
106
105
|
fields[name] = Field.new(self, field)
|
107
|
-
|
106
|
+
end
|
108
107
|
@portals[table] = fields
|
109
|
-
|
108
|
+
end
|
110
109
|
@portals.freeze
|
111
110
|
|
112
111
|
# build rows
|
113
|
-
|
112
|
+
doc.search('record').each do |record|
|
114
113
|
self << Record.new(record, self, @fields, @layout)
|
115
|
-
|
114
|
+
end
|
116
115
|
end
|
117
116
|
|
118
117
|
attr_reader :server, :fields, :portals, :date_format, :time_format, :timestamp_format, :total_count, :foundset_count, :layout
|
@@ -236,11 +235,13 @@ module Rfm::Result
|
|
236
235
|
|
237
236
|
@loaded = false
|
238
237
|
|
239
|
-
row_element.
|
238
|
+
row_element.search('field').each do |field|
|
240
239
|
field_name = field.attributes['name']
|
241
240
|
field_name.sub!(Regexp.new(portal + '::'), '') if portal
|
242
241
|
datum = []
|
243
|
-
field.
|
242
|
+
field.search('data').each do |x|
|
243
|
+
datum.push(fields[field_name].coerce(x.inner_text))
|
244
|
+
end
|
244
245
|
if datum.length == 1
|
245
246
|
self[field_name] = datum[0]
|
246
247
|
elsif datum.length == 0
|
@@ -248,18 +249,17 @@ module Rfm::Result
|
|
248
249
|
else
|
249
250
|
self[field_name] = datum
|
250
251
|
end
|
251
|
-
|
252
|
+
end
|
252
253
|
|
253
254
|
@portals = Rfm::Util::CaseInsensitiveHash.new
|
254
|
-
row_element.
|
255
|
+
row_element.search('relatedset').each do |relatedset|
|
255
256
|
table = relatedset.attributes['table']
|
256
257
|
records = []
|
257
|
-
relatedset.
|
258
|
+
relatedset.search('record').each do |record|
|
258
259
|
records << Record.new(record, @resultset, @resultset.portals[table], @layout, table)
|
259
|
-
|
260
|
+
end
|
260
261
|
@portals[table] = records
|
261
|
-
|
262
|
-
|
262
|
+
end
|
263
263
|
@loaded = true
|
264
264
|
end
|
265
265
|
|