cloudflare 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cloudflare/connection.rb +529 -528
- data/lib/cloudflare/version.rb +4 -4
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b32a40ccbdae3de9973839f3cf8c3294633cb7b2
|
4
|
+
data.tar.gz: ee7bd4dfcdbb1394c5ebcb531fbe01df27cdfa65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e955547a518f061827cbbd395158b824b0535118f40167010ca7bd951dc242167b779ff82b33d04b009ca7ce5965a5ea8606143106e6c64ce3ae787e6bfd222
|
7
|
+
data.tar.gz: 66a66ba091a22e43862898503d5dad947105ea3ab03d47230e24de2e87c5a461e232356c76a941c0c2117366227d7cdff23587d8c37c0d4b1e3a33e9cf84cbbc
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# Copyright, 2012, by Marcin Prokop.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
5
5
|
# in the Software without restriction, including without limitation the rights
|
6
6
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
7
|
# copies of the Software, and to permit persons to whom the Software is
|
8
8
|
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# The above copyright notice and this permission notice shall be included in
|
11
11
|
# all copies or substantial portions of the Software.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
14
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
15
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -26,529 +26,530 @@ require 'json'
|
|
26
26
|
# - http://www.cloudflare.com/docs/host-api.html
|
27
27
|
#
|
28
28
|
module CloudFlare
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
29
|
+
class RequestError < StandardError
|
30
|
+
def initialize(what, response)
|
31
|
+
super(what)
|
32
|
+
|
33
|
+
@response = response
|
34
|
+
end
|
35
|
+
|
36
|
+
attr :response
|
37
|
+
end
|
38
|
+
|
39
|
+
class Connection
|
40
|
+
# URL for Client and Host API
|
41
|
+
URL_API = {
|
42
|
+
client: 'https://www.cloudflare.com/api_json.html',
|
43
|
+
host: 'https://api.cloudflare.com/host-gw.html'
|
44
|
+
}
|
45
|
+
|
46
|
+
TIMEOUT = 5 # Default is 5 seconds
|
47
|
+
|
48
|
+
# @param api_key [String] user or Host API key.
|
49
|
+
# @param email [String] it is for a Client API.
|
50
|
+
def initialize(api_key, email = nil)
|
51
|
+
@params = Hash.new
|
52
|
+
|
53
|
+
if email.nil?
|
54
|
+
@params[:api_key] = api_key
|
55
|
+
else
|
56
|
+
@params[:api_key] = api_key
|
57
|
+
@params[:email] = email
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# CLIENT
|
63
|
+
|
64
|
+
# This function can be used to get currently settings of values such as the security level.
|
65
|
+
#
|
66
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.1
|
67
|
+
#
|
68
|
+
# @param zone [String]
|
69
|
+
# @param interval [Integer]
|
70
|
+
|
71
|
+
def stats(zone, interval = 20)
|
72
|
+
send_req({a: :stats, z: zone, interval: interval})
|
73
|
+
end
|
74
|
+
|
75
|
+
# This function lists all domains in a CloudFlare account along with other data.
|
76
|
+
#
|
77
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.2
|
78
|
+
|
79
|
+
def zone_load_multi
|
80
|
+
send_req(a: :zone_load_multi)
|
81
|
+
end
|
82
|
+
|
83
|
+
# This function lists all of the DNS records from a particular domain in a CloudFlare account.
|
84
|
+
#
|
85
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.3
|
86
|
+
#
|
87
|
+
# @param zone [String]
|
88
|
+
|
89
|
+
def rec_load_all(zone, offset = 0)
|
90
|
+
send_req({a: :rec_load_all, z: zone, o: offset})
|
91
|
+
end
|
92
|
+
|
93
|
+
# This function checks whether one or more websites/domains are active under an account and return the zone ids (zids) for these.
|
94
|
+
#
|
95
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.4
|
96
|
+
#
|
97
|
+
# @param zones [String or Array]
|
98
|
+
|
99
|
+
def zone_check(*zones)
|
100
|
+
send_req({a: :zone_check, zones: zones.kind_of?(Array) ? zones.join(',') : zones})
|
101
|
+
end
|
102
|
+
|
103
|
+
# This function pulls recent IPs hitting your site.
|
104
|
+
#
|
105
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.5
|
106
|
+
#
|
107
|
+
# @param zone [String]
|
108
|
+
# @param hours [Integer] max 48
|
109
|
+
# @param classification [String] (optional) values: r|c|t
|
110
|
+
# @param geo [Fixnum] (optional)
|
111
|
+
|
112
|
+
def zone_ips(zone, classification = nil, hours = 24, geo = 1)
|
113
|
+
send_req({a: :zone_ips, z: zone, hours: hours, "class" => classification, geo: geo})
|
114
|
+
end
|
115
|
+
|
116
|
+
# This function checks the threat score for a given IP.
|
117
|
+
#
|
118
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.6
|
119
|
+
#
|
120
|
+
# @param ip [String]
|
121
|
+
|
122
|
+
def ip_lkup(ip)
|
123
|
+
send_req({a: :ip_lkup, ip: ip})
|
124
|
+
end
|
125
|
+
|
126
|
+
# This function retrieves all current settings for a given domain.
|
127
|
+
#
|
128
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s3.7
|
129
|
+
#
|
130
|
+
# @param zone [String]
|
131
|
+
|
132
|
+
def zone_settings(zone)
|
133
|
+
send_req({a: :zone_settings, z: zone})
|
134
|
+
end
|
135
|
+
|
136
|
+
# This function sets the Basic Security Level to HELP I'M UNDER ATTACK / HIGH / MEDIUM / LOW / ESSENTIALLY OFF.
|
137
|
+
#
|
138
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.1
|
139
|
+
#
|
140
|
+
# @param zone [String]
|
141
|
+
# @param value [String] values: low|med|high|help|eoff
|
142
|
+
|
143
|
+
def sec_lvl(zone, value)
|
144
|
+
send_req({a: :sec_lvl, z: zone, v: value})
|
145
|
+
end
|
146
|
+
|
147
|
+
# This function sets the Caching Level to Aggressive or Basic.
|
148
|
+
#
|
149
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.2
|
150
|
+
#
|
151
|
+
# @param zone [String]
|
152
|
+
# @param value [String] values: agg|basic
|
153
|
+
|
154
|
+
def cache_lvl(zone, value)
|
155
|
+
send_req({a: :cache_lvl, z: zone, v: value})
|
156
|
+
end
|
157
|
+
|
158
|
+
# This function allows you to toggle Development Mode on or off for a particular domain.
|
159
|
+
#
|
160
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.3
|
161
|
+
#
|
162
|
+
# @param zone [String]
|
163
|
+
# @param value [Boolean]
|
164
|
+
|
165
|
+
def devmode(zone, value)
|
166
|
+
send_req({a: :devmode, z: zone, v: value ? 1 : 0})
|
167
|
+
end
|
168
|
+
|
169
|
+
# This function will purge CloudFlare of any cached files.
|
170
|
+
#
|
171
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.4
|
172
|
+
#
|
173
|
+
# @param zone [String]
|
174
|
+
|
175
|
+
def fpurge_ts(zone)
|
176
|
+
send_req({a: :fpurge_ts, z: zone, v: 1})
|
177
|
+
end
|
178
|
+
|
179
|
+
# This function will purge a single file from CloudFlare's cache.
|
180
|
+
#
|
181
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.5
|
182
|
+
#
|
183
|
+
# @param zone [String]
|
184
|
+
# @param url [String]
|
185
|
+
|
186
|
+
def zone_file_purge(zone, url)
|
187
|
+
send_req({a: :zone_file_purge, z: zone, url: url})
|
188
|
+
end
|
189
|
+
|
190
|
+
# This function updates the snapshot of your site for CloudFlare's challenge page.
|
191
|
+
#
|
192
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.6
|
193
|
+
#
|
194
|
+
# @param zoneid [Integer]
|
195
|
+
|
196
|
+
def zone_grab(zoneid)
|
197
|
+
send_req({a: :zone_grab, zid: zoneid})
|
198
|
+
end
|
199
|
+
|
200
|
+
# This function adds an IP address to your white lists.
|
201
|
+
#
|
202
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
|
203
|
+
#
|
204
|
+
# @param ip [String]
|
205
|
+
|
206
|
+
def whitelist(ip)
|
207
|
+
send_req({a: :wl, key: ip})
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
# This function adds an IP address to your black lists.
|
212
|
+
#
|
213
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
|
214
|
+
#
|
215
|
+
# @param ip [String]
|
216
|
+
|
217
|
+
def blacklist(ip)
|
218
|
+
send_req({a: :ban, key: ip})
|
219
|
+
end
|
220
|
+
|
221
|
+
# This function removes the IP from whitelist or blacklist.
|
222
|
+
#
|
223
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.7
|
224
|
+
#
|
225
|
+
# @param ip [String]
|
226
|
+
|
227
|
+
def remove_ip(ip)
|
228
|
+
send_req({a: :nul, key: ip})
|
229
|
+
end
|
230
|
+
|
231
|
+
# This function toggles IPv6 support.
|
232
|
+
#
|
233
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.8
|
234
|
+
#
|
235
|
+
# @param zone [String]
|
236
|
+
# @param value [Boolean]
|
237
|
+
|
238
|
+
def ipv46(zone, value)
|
239
|
+
send_req({a: :ipv46, z: zone, v: value ? 1 : 0})
|
240
|
+
end
|
241
|
+
|
242
|
+
# This function changes Rocket Loader setting.
|
243
|
+
#
|
244
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.9
|
245
|
+
#
|
246
|
+
# @param zone [String]
|
247
|
+
# @param value [Integer or String] values: 0|a|m
|
248
|
+
|
249
|
+
def async(zone, value)
|
250
|
+
send_req({a: :async, z: zone, v: value})
|
251
|
+
end
|
252
|
+
|
253
|
+
# This function changes minification settings.
|
254
|
+
#
|
255
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.10
|
256
|
+
#
|
257
|
+
# @param zone [String]
|
258
|
+
# @param value [Integer] values: 0|2|3|4|5|6|7
|
259
|
+
|
260
|
+
def minify(zone, value)
|
261
|
+
send_req({a: :minify, z: zone, v: value})
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
# This function changes mirage2 settings.
|
266
|
+
#
|
267
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s4.11
|
268
|
+
#
|
269
|
+
# @param zone [String]
|
270
|
+
# @param value [Integer] values: 0|1
|
271
|
+
|
272
|
+
def mirage2(zone, value)
|
273
|
+
send_req({a: :mirage2, z: zone, v: value})
|
274
|
+
end
|
275
|
+
|
276
|
+
# This function creates a new DNS record for your site. This can be either a CNAME or A record.
|
277
|
+
#
|
278
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s5.1
|
279
|
+
#
|
280
|
+
# @param zone [String]
|
281
|
+
# @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
|
282
|
+
# @param name [String]
|
283
|
+
# @param content [String]
|
284
|
+
# @param ttl [Integer] values: 1|120...4294967295
|
285
|
+
# @param prio [Integer] (applies to MX/SRV)
|
286
|
+
# @param service [String] (applies to SRV)
|
287
|
+
# @param srvname [String] (applies to SRV)
|
288
|
+
# @param protocol [Integer] (applies to SRV) values: _tcp|_udp|_tls
|
289
|
+
# @param weight [Intger] (applies to SRV)
|
290
|
+
# @param port [Integer] (applies to SRV)
|
291
|
+
# @param target [String] (applies to SRV)
|
292
|
+
|
293
|
+
def rec_new(zone, type, name, content, ttl, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
|
294
|
+
send_req({
|
295
|
+
a: :rec_new,
|
296
|
+
z: zone,
|
297
|
+
type: type,
|
298
|
+
name: name,
|
299
|
+
content: content,
|
300
|
+
ttl: ttl,
|
301
|
+
prio: prio,
|
302
|
+
service: service,
|
303
|
+
srvname: srvname,
|
304
|
+
protocol: protocol,
|
305
|
+
weight: weight,
|
306
|
+
port: port,
|
307
|
+
target: target,
|
308
|
+
service_mode: '1'
|
309
|
+
})
|
310
|
+
end
|
311
|
+
|
312
|
+
# This function edits a DNS record for a zone.
|
313
|
+
#
|
314
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s5.2
|
315
|
+
#
|
316
|
+
# @param zone [String]
|
317
|
+
# @param type [String] values: A|CNAME|MX|TXT|SPF|AAAA|NS|SRV|LOC
|
318
|
+
# @param record_id [Integer]
|
319
|
+
# @param name [String]
|
320
|
+
# @param content [String]
|
321
|
+
# @param ttl [Integer] values: 1|120...4294967295
|
322
|
+
# @param service_mode [Boolean] (applies to A/AAAA/CNAME)
|
323
|
+
# @param prio [Integer] (applies to MX/SRV)
|
324
|
+
# @param service [String] (applies to SRV)
|
325
|
+
# @param srvname [String] (applies to SRV)
|
326
|
+
# @param protocol [Integer] (applies to SRV) values: _tcp/_udp/_tls
|
327
|
+
# @param weight [Intger] (applies to SRV)
|
328
|
+
# @param port [Integer] (applies to SRV)
|
329
|
+
# @param target [String] (applies to SRV)
|
330
|
+
|
331
|
+
def rec_edit(zone, type, record_id, name, content, ttl, service_mode = nil, prio = nil, service = nil, srvname = nil, protocol = nil, weight = nil, port = nil, target = nil)
|
332
|
+
send_req({
|
333
|
+
a: :rec_edit,
|
334
|
+
z: zone,
|
335
|
+
type: type,
|
336
|
+
id: record_id,
|
337
|
+
name: name,
|
338
|
+
content: content,
|
339
|
+
ttl: ttl,
|
340
|
+
service_mode: service_mode ? 1 : 0,
|
341
|
+
prio: prio,
|
342
|
+
service: service,
|
343
|
+
srvname: srvname,
|
344
|
+
protocol: protocol,
|
345
|
+
weight: weight,
|
346
|
+
port: port,
|
347
|
+
target: target
|
348
|
+
})
|
349
|
+
end
|
350
|
+
|
351
|
+
# This functon deletes a record for a domain.
|
352
|
+
#
|
353
|
+
# @see http://www.cloudflare.com/docs/client-api.html#s5.3
|
354
|
+
#
|
355
|
+
# @param zone [String]
|
356
|
+
# @param zoneid [Integer]
|
357
|
+
|
358
|
+
def rec_delete(zone, zoneid)
|
359
|
+
send_req({a: :rec_delete, z: zone, id: zoneid})
|
360
|
+
end
|
361
|
+
|
362
|
+
# HOST
|
363
|
+
|
364
|
+
# This function creates a CloudFlare account mapped to your user.
|
365
|
+
#
|
366
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.1
|
367
|
+
#
|
368
|
+
# @param email [String]
|
369
|
+
# @param pass [String]
|
370
|
+
# @param login [String] (optional) cloudflare_username
|
371
|
+
# @param id [Integer] (optional) unique_id
|
372
|
+
# @param cui [Integer] (optional) clobber_unique_id
|
373
|
+
|
374
|
+
def create_user(email, pass, login = nil, id = nil, cui = nil)
|
375
|
+
send_req({
|
376
|
+
act: :user_create,
|
377
|
+
cloudflare_email: email,
|
378
|
+
cloudflare_pass: pass,
|
379
|
+
cloudflare_username: login,
|
380
|
+
unique_id: id,
|
381
|
+
clobber_unique_id: cui
|
382
|
+
})
|
383
|
+
end
|
384
|
+
|
385
|
+
# This function setups a User's zone for CNAME hosting.
|
386
|
+
#
|
387
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.2
|
388
|
+
#
|
389
|
+
# @param user_key [String]
|
390
|
+
# @param zone [String]
|
391
|
+
# @param resolve_to [String]
|
392
|
+
# @param subdomains [String or Array]
|
393
|
+
|
394
|
+
def add_zone(user_key, zone, resolve_to, subdomains)
|
395
|
+
send_req({
|
396
|
+
act: :zone_set,
|
397
|
+
user_key: user_key,
|
398
|
+
zone_name: zone,
|
399
|
+
resolve_to: resolve_to,
|
400
|
+
subdomains: subdomains.kind_of?(Array) ? zones.join(',') : subdomains
|
401
|
+
})
|
402
|
+
end
|
403
|
+
|
404
|
+
# This function lookups a user's CloudFlare account information.
|
405
|
+
#
|
406
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.3
|
407
|
+
#
|
408
|
+
# *Example:*
|
409
|
+
#
|
410
|
+
# cf = CloudFlare('your_host_key')
|
411
|
+
# cf.user_lookup('unique_id', true)
|
412
|
+
#
|
413
|
+
# If +id+ is set to true, email is a unique_id.
|
414
|
+
#
|
415
|
+
# @param email [String or Integer]
|
416
|
+
# @param id [Boolean]
|
417
|
+
|
418
|
+
def user_lookup(email, id = false)
|
419
|
+
if id
|
420
|
+
send_req({act: :user_lookup, unique_id: email})
|
421
|
+
else
|
422
|
+
send_req({act: :user_lookup, cloudflare_email: email})
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
# This function authorizes access to a user's existing CloudFlare account.
|
427
|
+
#
|
428
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.4
|
429
|
+
#
|
430
|
+
# @param email [String]
|
431
|
+
# @param pass [String]
|
432
|
+
# @param unique_id [Integer] (optional)
|
433
|
+
# @param cui [Integer] (optional) clobber_unique_id
|
434
|
+
|
435
|
+
def user_auth(email, pass, id = nil, cui = nil)
|
436
|
+
send_req({
|
437
|
+
act: :user_auth,
|
438
|
+
cloudflare_email: email,
|
439
|
+
cloudflare_pass: pass,
|
440
|
+
unique_id: id,
|
441
|
+
clobber_unique_id: cui
|
442
|
+
})
|
443
|
+
end
|
444
|
+
|
445
|
+
# This function lookups a specific user's zone.
|
446
|
+
#
|
447
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.5
|
448
|
+
#
|
449
|
+
# @param user_key [String]
|
450
|
+
# @param zone [String]
|
451
|
+
|
452
|
+
def zone_lookup(user_key, zone)
|
453
|
+
send_req({act: :zone_lookup, user_key: user_key, zone_name: zone})
|
454
|
+
end
|
455
|
+
|
456
|
+
# This function deletes a specific zone on behalf of a user.
|
457
|
+
#
|
458
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.6
|
459
|
+
#
|
460
|
+
# @param user_key [String]
|
461
|
+
# @param zone [String]
|
462
|
+
|
463
|
+
def del_zone(user_key, zone)
|
464
|
+
send_req({act: :zone_delete, user_key: user_key, zone_name: zone})
|
465
|
+
end
|
466
|
+
|
467
|
+
# This function creates a new child host provider.
|
468
|
+
#
|
469
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.7
|
470
|
+
#
|
471
|
+
# @param host_name [String]
|
472
|
+
# @param pub_name [String]
|
473
|
+
# @param prefix [String]
|
474
|
+
# @param website [String]
|
475
|
+
# @param email [String]
|
476
|
+
|
477
|
+
def host_child_new(host_name, pub_name, prefix, website, email)
|
478
|
+
send_req({
|
479
|
+
act: :host_child_new,
|
480
|
+
pub_name: pub_name,
|
481
|
+
prefix: prefix,
|
482
|
+
website: website,
|
483
|
+
email: email
|
484
|
+
})
|
485
|
+
end
|
486
|
+
|
487
|
+
# This function regenerates your host key.
|
488
|
+
#
|
489
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.8
|
490
|
+
|
491
|
+
def host_key_regen
|
492
|
+
send_req(act: :host_key_regen)
|
493
|
+
end
|
494
|
+
|
495
|
+
# This function stops a child host provider account.
|
496
|
+
#
|
497
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.9
|
498
|
+
#
|
499
|
+
# @param id [Integer] child_id
|
500
|
+
|
501
|
+
def host_child_stop(id)
|
502
|
+
send_req({act: :host_child_stop, child_id: id})
|
503
|
+
end
|
504
|
+
|
505
|
+
# This function lists the domains currently active on CloudFlare for the given host.
|
506
|
+
#
|
507
|
+
# @see http://www.cloudflare.com/docs/host-api.html#s3.2.10
|
508
|
+
#
|
509
|
+
# @param limit [Integer] (optional)
|
510
|
+
# @param offset [Integer] (optional)
|
511
|
+
# @param name [String] (optional) zone_name
|
512
|
+
# @param sub_id [Integer] (optional) sub_id
|
513
|
+
# @param status [String] (optional) values: V|D|ALL
|
514
|
+
|
515
|
+
def zone_list(limit = 100, offset = 0, name = nil, sub_id = nil, status = nil)
|
516
|
+
send_req({
|
517
|
+
act: :zone_list,
|
518
|
+
offset: offset,
|
519
|
+
zone_name: name,
|
520
|
+
sub_id: sub_id,
|
521
|
+
zone_status: status
|
522
|
+
})
|
523
|
+
end
|
524
|
+
|
525
|
+
private
|
526
|
+
|
527
|
+
def send_req(params)
|
528
|
+
if @params[:email]
|
529
|
+
params[:tkn] = @params[:api_key]
|
530
|
+
params[:u] = @params[:email]
|
531
|
+
uri = URI(URL_API[:client])
|
532
|
+
else
|
533
|
+
params[:host_key] = @params[:api_key]
|
534
|
+
uri = URI(URL_API[:host])
|
535
|
+
end
|
536
|
+
|
537
|
+
req = Net::HTTP::Post.new(uri.path)
|
538
|
+
req.set_form_data(params)
|
539
|
+
|
540
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
541
|
+
http.use_ssl = true
|
542
|
+
http.read_timeout = TIMEOUT
|
543
|
+
|
544
|
+
res = http.request(req)
|
545
|
+
out = JSON.parse(res.body)
|
546
|
+
|
547
|
+
# If there is an error, raise an exception:
|
548
|
+
if out['result'] == 'error'
|
549
|
+
raise RequestError.new(out['msg'], out)
|
550
|
+
else
|
551
|
+
return out
|
552
|
+
end
|
553
|
+
end
|
554
|
+
end
|
554
555
|
end
|
data/lib/cloudflare/version.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Copyright, 2012, by Marcin Prokop.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
5
5
|
# in the Software without restriction, including without limitation the rights
|
6
6
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
7
|
# copies of the Software, and to permit persons to whom the Software is
|
8
8
|
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# The above copyright notice and this permission notice shall be included in
|
11
11
|
# all copies or substantial portions of the Software.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
14
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
15
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -19,5 +19,5 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
module CloudFlare
|
22
|
-
|
22
|
+
VERSION = '2.0.2'
|
23
23
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Prokop
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: A Ruby wrapper for the CloudFlare API.
|
@@ -61,19 +61,19 @@ licenses:
|
|
61
61
|
metadata: {}
|
62
62
|
post_install_message:
|
63
63
|
rdoc_options:
|
64
|
-
- --main
|
64
|
+
- "--main"
|
65
65
|
- README.md
|
66
|
-
- --charset=UTF-8
|
66
|
+
- "--charset=UTF-8"
|
67
67
|
require_paths:
|
68
68
|
- lib
|
69
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: 1.9.0
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- -
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|