freebox_api 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +201 -0
- data/README.md +165 -28
- data/lib/freebox_api.rb +2 -114
- data/lib/freebox_api/application.rb +15 -0
- data/lib/freebox_api/freebox.rb +56 -0
- data/lib/freebox_api/resources/interface.rb +4 -30
- data/lib/freebox_api/resources/lan_host.rb +15 -24
- data/lib/freebox_api/resources/port_forwarding.rb +35 -0
- data/lib/freebox_api/resources/static_lease.rb +22 -9
- data/lib/freebox_api/resources/upnp_redir.rb +23 -0
- data/lib/freebox_api/session.rb +25 -0
- data/lib/freebox_api/version.rb +1 -1
- metadata +11 -12
- data/lib/freebox_api/resources/redir.rb +0 -27
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTRhOTA2NWI2NTZhM2E1NGEwMzA1MzE4OGRhMzhlZWNmNDE1MTljNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzAwZmY4YzI2MzFlODliOTE3NTljOGJiNTliYTQxMDE3NDRkNDY2Nw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDcyYjNhNTRhYWZhZTRmMjBjZDFkMWE5ZTI1MGM3YjVmOTIwOWM4ZmM0N2U3
|
10
|
+
NDgyY2Q1MzRmMTRkZjAxOWZjYjhiNWFlNjBiMTFkZDA4ZGMxN2M3ZWE4ZGI2
|
11
|
+
MTJhMGM0MTBlNjQ5MjcyYWU4YjgzMjQzOGNjMWJmYzg2MzE3ODE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWZiZGYxYjk1YTY0ZGRmZjNiMDMzZWQ2MmFkMTJiNzQ2NTdmNTNkODc0Nzg3
|
14
|
+
M2Q0YThjYzliNjEzZDk3OTFmNWIwY2JhYmI0ZGY0YzM1NWVlOTAwZTdjYzM4
|
15
|
+
NWY2MDFhNzI4MWJjNzNhMDA0ZTg5MjM2MGVjNTI5YTY2MjYwOGU=
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -5,73 +5,210 @@ WARNING: Work In Progress.
|
|
5
5
|
|
6
6
|
Overview
|
7
7
|
--------
|
8
|
-
|
9
8
|
This gem contains Freebox OS API bindings for the Ruby language.
|
10
9
|
I started working on that to use it with https://github.com/mcanevet/puppet-freebox
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
Building the Freebox object
|
12
|
+
---------------------------
|
14
13
|
|
15
14
|
```ruby
|
16
15
|
require 'freebox_api'
|
17
16
|
|
18
|
-
|
17
|
+
myFreebox = FreeboxApi::Freebox.new
|
19
18
|
```
|
20
19
|
|
21
|
-
|
22
|
-
----------------------
|
20
|
+
or
|
23
21
|
|
24
22
|
```ruby
|
25
23
|
require 'freebox_api'
|
26
24
|
|
27
|
-
|
25
|
+
myFreebox = FreeboxApi::Freebox.new({
|
26
|
+
:freebox_ip => 'mafreebox.example.com',
|
27
|
+
:freebox_port => 4242,
|
28
|
+
})
|
29
|
+
```
|
30
|
+
|
31
|
+
Login
|
32
|
+
-----
|
33
|
+
|
34
|
+
### Obtaining an app\_token
|
35
|
+
|
36
|
+
#### Request authorization
|
37
|
+
|
38
|
+
This is the first step, the app will ask for an app\_token using the following call. A message will be displayed on the Freebox LCD asking the user to grant/deny access to the requesting app.
|
39
|
+
|
40
|
+
Once the app has obtained a valid app\_token, it will not have to do this procedure again unless the user revokes the app\_token.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
token_request = {
|
44
|
+
:app_id => 'fr.freebox.testapp',
|
45
|
+
:app_name => 'Test App',
|
46
|
+
:app_version => '0.0.7',
|
47
|
+
:device_name => 'Pc de Xavier'
|
48
|
+
}
|
49
|
+
|
50
|
+
auth_request = myFreebox.authorize(token_request)
|
51
|
+
|
52
|
+
app_token = auth_request['app_token']
|
53
|
+
```
|
54
|
+
|
55
|
+
#### Track authorization progress
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
puts myFreebox.track_auth(auth_request['track_id'])
|
59
|
+
```
|
60
|
+
|
61
|
+
### Obtaining a session\_token
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
myApp = {
|
65
|
+
:app_id => 'fr.freebox.testapp',
|
66
|
+
:app_version => '0.0.7',
|
67
|
+
:app_token => 'dyNYgfK0Ya6FWGqq83sBHa7TwzWo+pg4fDFUJHShcjVYzTfaRrZzm93p7OTAfH/0',
|
68
|
+
}
|
69
|
+
mySession = FreeboxApi::Session.new(myApp, myFreebox)
|
28
70
|
```
|
29
71
|
|
30
|
-
|
31
|
-
-------------------------
|
72
|
+
#### Getting the current challenge value
|
32
73
|
|
33
74
|
```ruby
|
34
|
-
|
75
|
+
myFreebox.challenge
|
35
76
|
```
|
36
77
|
|
37
|
-
|
38
|
-
------------------------
|
78
|
+
#### Opening a session
|
39
79
|
|
40
80
|
```ruby
|
41
|
-
|
81
|
+
mySession.session_token
|
42
82
|
```
|
43
83
|
|
44
|
-
|
45
|
-
|
84
|
+
LAN Browser
|
85
|
+
-----------
|
86
|
+
|
87
|
+
### Getting the list of browsable LAN interfaces
|
46
88
|
|
47
89
|
```ruby
|
48
|
-
|
90
|
+
interfaces = FreeboxApi::Resources::Interface.new(mySession)
|
91
|
+
interfaces.index
|
49
92
|
```
|
50
93
|
|
51
|
-
|
52
|
-
----------------------------------------
|
94
|
+
### Getting the list of hosts
|
53
95
|
|
54
96
|
```ruby
|
55
|
-
|
97
|
+
lan_hosts = FreeboxApi::Resources::LanHost.new(mySession)
|
98
|
+
lan_hosts.index
|
56
99
|
```
|
57
100
|
|
58
|
-
|
59
|
-
-------------------------
|
101
|
+
### Getting an host information
|
60
102
|
|
61
103
|
```ruby
|
62
|
-
|
104
|
+
lan_hosts.show('ether-00:24:d4:7e:00:4c')
|
63
105
|
```
|
64
106
|
|
65
|
-
|
66
|
-
|
107
|
+
### Updating an host information
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
lan_hosts.update({
|
111
|
+
:id => 'ether-00:24:d4:7e:00:4c',
|
112
|
+
:primary_name => 'Freebox Tv',
|
113
|
+
})
|
114
|
+
```
|
115
|
+
|
116
|
+
DHCP
|
117
|
+
----
|
118
|
+
|
119
|
+
### Get the list of DHCP static leases
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
static_leases = FreeboxApi::Resources::StaticLease.new(mySession)
|
123
|
+
static_leases.index
|
124
|
+
```
|
125
|
+
|
126
|
+
### Get a given DHCP static lease
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
static_leases.show('00:DE:AD:B0:0B:55)
|
130
|
+
```
|
131
|
+
|
132
|
+
### Update DHCP static lease
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
static_leases.update({
|
136
|
+
:id => '00:DE:AD:B0:0B:55',
|
137
|
+
:comment => 'Mon PC',
|
138
|
+
})
|
139
|
+
```
|
140
|
+
|
141
|
+
### Delete a DHCP static lease
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
static_lease.destroy('00:DE:AD:B0:0B:55')
|
145
|
+
```
|
146
|
+
|
147
|
+
### Add a DHCP static lease
|
148
|
+
```ruby
|
149
|
+
static_lease.create({
|
150
|
+
:ip => '192.168.1.222',
|
151
|
+
:mac => '00:00:00:11:11:11',
|
152
|
+
})
|
153
|
+
```
|
154
|
+
|
155
|
+
Port Forwarding
|
156
|
+
---------------
|
157
|
+
|
158
|
+
### Getting the list of port forwarding
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
port_forwardings = FreeboxApi::Resources::PortForwarding.new(mySession)
|
162
|
+
port_forwardings.index
|
163
|
+
```
|
164
|
+
|
165
|
+
### Getting a specific port forwarding
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
port_forwardings.show(1)
|
169
|
+
```
|
170
|
+
|
171
|
+
### Updating a port forwarding
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
port_forwardings.update({
|
175
|
+
:id => 1,
|
176
|
+
:enabled => false,
|
177
|
+
})
|
178
|
+
```
|
179
|
+
|
180
|
+
### Add a port forwarding
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
port_forwardings.create({
|
184
|
+
:enabled => true,
|
185
|
+
:comment => 'test',
|
186
|
+
:lan_port => 4242,
|
187
|
+
:wan_port_end => 4242,
|
188
|
+
:wan_port_start => 4242,
|
189
|
+
:lan_ip => '192.168.1.42',
|
190
|
+
:ip_proto => 'tcp',
|
191
|
+
})
|
192
|
+
```
|
193
|
+
|
194
|
+
### Delete a port forwarding
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
port_forwardings.destroy(3)
|
198
|
+
```
|
199
|
+
|
200
|
+
UPnP IGD
|
201
|
+
--------
|
202
|
+
|
203
|
+
### Get the list of current redirection
|
67
204
|
|
68
205
|
```ruby
|
69
|
-
|
206
|
+
upnp_redir = FreeboxApi::Resources::UPnPRedir.new(mySession)
|
207
|
+
upnp_redir.index
|
70
208
|
```
|
71
209
|
|
72
|
-
|
73
|
-
--------------------------------
|
210
|
+
### Delete a redirection
|
74
211
|
|
75
212
|
```ruby
|
76
|
-
|
213
|
+
upnp_redir.destroy('0.0.0.0-53644-udp')
|
77
214
|
```
|
data/lib/freebox_api.rb
CHANGED
@@ -1,120 +1,8 @@
|
|
1
|
-
require 'rest_client'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module FreeboxApi
|
5
|
-
|
6
|
-
class Freebox
|
7
|
-
|
8
|
-
attr_reader :app_token, :app_id, :app_name, :app_version, :device_name, :base_url
|
9
|
-
|
10
|
-
def initialize(app_token, app_id, app_name, app_version, device_name, base_url = 'http://mafreebox.free.fr')
|
11
|
-
@app_id = app_id
|
12
|
-
@app_name = app_name
|
13
|
-
@app_version = app_version
|
14
|
-
@device_name = device_name
|
15
|
-
@app_token = app_token
|
16
|
-
@base_url = base_url
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.app_token(app_id, app_name, app_version, device_name)
|
20
|
-
JSON.parse(RestClient.post(
|
21
|
-
"#{@base_url}/api/v1/login/authorize",
|
22
|
-
{
|
23
|
-
:app_id => app_id,
|
24
|
-
:app_name => app_name,
|
25
|
-
:app_version => app_version,
|
26
|
-
:device_name => device_name,
|
27
|
-
}.to_json,
|
28
|
-
:content_type => :json,
|
29
|
-
:accept => :json
|
30
|
-
))['result']['app_token']
|
31
|
-
end
|
32
|
-
|
33
|
-
def challenge
|
34
|
-
JSON.parse(RestClient.get("#{@base_url}/api/v1/login/"))['result']['challenge']
|
35
|
-
end
|
36
|
-
|
37
|
-
def password
|
38
|
-
Digest::HMAC.hexdigest(challenge, @app_token, Digest::SHA1)
|
39
|
-
end
|
40
|
-
|
41
|
-
def session_token
|
42
|
-
JSON.parse(
|
43
|
-
RestClient.post(
|
44
|
-
"#{@base_url}/api/v1/login/session/",
|
45
|
-
{
|
46
|
-
:app_id => @app_id,
|
47
|
-
:password => password,
|
48
|
-
}.to_json,
|
49
|
-
:content_type => :json,
|
50
|
-
:accept => :json
|
51
|
-
)
|
52
|
-
)['result']['session_token']
|
53
|
-
end
|
54
|
-
|
55
|
-
def interfaces
|
56
|
-
JSON.parse(
|
57
|
-
RestClient.get(
|
58
|
-
"#{@base_url}/api/v1/lan/browser/interfaces",
|
59
|
-
:'X_Fbx_App_Auth' => session_token
|
60
|
-
)
|
61
|
-
)['result'].collect { |interface|
|
62
|
-
FreeboxApi::Resources::Interface.new(interface['name'], interface['host_count'], self)
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
def lan_hosts
|
67
|
-
interfaces.collect { |interface|
|
68
|
-
interface.lan_hosts
|
69
|
-
}.flatten
|
70
|
-
end
|
71
|
-
|
72
|
-
def static_leases
|
73
|
-
JSON.parse(
|
74
|
-
RestClient.get(
|
75
|
-
"#{@base_url}/api/v1/dhcp/static_lease/",
|
76
|
-
:'X_Fbx_App_Auth' => session_token
|
77
|
-
)
|
78
|
-
)['result'].collect { |static_lease|
|
79
|
-
FreeboxApi::Resources::StaticLease.new(
|
80
|
-
static_lease['id'],
|
81
|
-
static_lease['mac'],
|
82
|
-
static_lease['comment'],
|
83
|
-
static_lease['hostname'],
|
84
|
-
static_lease['ip'],
|
85
|
-
lan_hosts.select { |lan_host| lan_host.id == static_lease['host']['id'] },
|
86
|
-
self
|
87
|
-
)
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
def redirs
|
92
|
-
JSON.parse(
|
93
|
-
RestClient.get(
|
94
|
-
"#{@base_url}/api/v1/fw/redir/",
|
95
|
-
:'X_Fbx_App_Auth' => session_token
|
96
|
-
)
|
97
|
-
)['result'].collect { |redir|
|
98
|
-
FreeboxApi::Resources::Redir.new(
|
99
|
-
redir['id'],
|
100
|
-
redir['enabled'],
|
101
|
-
redir['ip_proto'],
|
102
|
-
redir['wan_port_start'],
|
103
|
-
redir['wan_port_end'],
|
104
|
-
redir['lan_ip'],
|
105
|
-
redir['lan_port'],
|
106
|
-
redir['hostname'],
|
107
|
-
lan_hosts.select { |lan_host| lan_host.id == redir['host']['id'] },
|
108
|
-
redir['comment'],
|
109
|
-
self
|
110
|
-
)
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
2
|
end
|
117
3
|
|
4
|
+
require 'freebox_api/freebox'
|
5
|
+
require 'freebox_api/session'
|
118
6
|
require 'freebox_api/version'
|
119
7
|
resource_files = Dir[File.expand_path("#{File.dirname(__FILE__)}/freebox_api/resources/*.rb", __FILE__)]
|
120
8
|
resource_files.each { |f| require f }
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module FreeboxApi
|
5
|
+
|
6
|
+
class Freebox < Hash
|
7
|
+
|
8
|
+
def initialize(hash = {})
|
9
|
+
self[:freebox_ip] = hash[:freebox_ip] ? hash[:freebox_ip] : 'mafreebox.free.fr'
|
10
|
+
self[:freebox_port] = hash[:freebox_port] ? hash[:freebox_port] : '80'
|
11
|
+
@client = RestClient::Resource.new("http://#{self[:freebox_ip]}:#{self[:freebox_port]}")
|
12
|
+
self[:uid] = discover['uid']
|
13
|
+
self[:device_name] = discover['device_name']
|
14
|
+
self[:api_version] = discover['api_version']
|
15
|
+
self[:api_base_url] = discover['api_base_url']
|
16
|
+
self[:device_type] = discover['device_type']
|
17
|
+
end
|
18
|
+
|
19
|
+
def discover
|
20
|
+
args = ['get']
|
21
|
+
@discover ||= JSON.parse(@client['/api_version'].send(*args))
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_url(api_url)
|
25
|
+
"#{self[:api_base_url]}v#{self[:api_version].split('.')[0]}#{api_url}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize(token_request)
|
29
|
+
http_call('post', '/login/authorize/', token_request)
|
30
|
+
end
|
31
|
+
|
32
|
+
def track_auth(track_id)
|
33
|
+
http_call('get', "/login/authorize/#{track_id}")
|
34
|
+
end
|
35
|
+
|
36
|
+
def challenge
|
37
|
+
http_call('get', '/login/')['challenge']
|
38
|
+
end
|
39
|
+
|
40
|
+
def http_call(http_method, path, params = {}, session = nil)
|
41
|
+
headers = {}
|
42
|
+
|
43
|
+
args = [http_method]
|
44
|
+
if %w[post put].include?(http_method.to_s)
|
45
|
+
args << params.to_json
|
46
|
+
else
|
47
|
+
headers[:params] = params if params
|
48
|
+
end
|
49
|
+
headers[:'X_Fbx_App_Auth'] = session.session_token if session
|
50
|
+
args << headers if headers
|
51
|
+
JSON.parse(@client[build_url(path)].send(*args))['result']
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -4,38 +4,12 @@ module FreeboxApi
|
|
4
4
|
|
5
5
|
class Interface
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(name, host_count, freebox)
|
10
|
-
@name = name
|
11
|
-
@host_count = host_count
|
12
|
-
@freebox = freebox
|
7
|
+
def initialize(session)
|
8
|
+
@session = session
|
13
9
|
end
|
14
10
|
|
15
|
-
def
|
16
|
-
|
17
|
-
RestClient.get(
|
18
|
-
"#{@freebox.base_url}/api/v1/lan/browser/#{@name}",
|
19
|
-
:'X_Fbx_App_Auth' => @freebox.session_token
|
20
|
-
)
|
21
|
-
)['result'].collect { |lan_host|
|
22
|
-
FreeboxApi::Resources::LanHost.new(
|
23
|
-
lan_host['id'],
|
24
|
-
lan_host['primary_name'],
|
25
|
-
lan_host['host_type'],
|
26
|
-
lan_host['primary_name_manual'],
|
27
|
-
lan_host['l2ident'],
|
28
|
-
lan_host['vendor_name '],
|
29
|
-
lan_host['persistent'],
|
30
|
-
lan_host['reachable'],
|
31
|
-
lan_host['last_time_reachable'],
|
32
|
-
lan_host['active'],
|
33
|
-
lan_host['last_activity'],
|
34
|
-
lan_host['names'],
|
35
|
-
lan_host['l3connectivities'],
|
36
|
-
self,
|
37
|
-
@freebox)
|
38
|
-
}
|
11
|
+
def index
|
12
|
+
@session.http_call('get', '/lan/browser/interfaces')
|
39
13
|
end
|
40
14
|
|
41
15
|
end
|
@@ -4,35 +4,26 @@ module FreeboxApi
|
|
4
4
|
|
5
5
|
class LanHost
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(id, primary_name, host_type, primary_name_manual, l2ident, vendor_name, persistent, reachable, last_time_reachable, active, last_activity, names, l3connectivities, interface, freebox)
|
10
|
-
@id = id
|
11
|
-
@primary_name = primary_name
|
12
|
-
@host_type = host_type
|
13
|
-
@primary_name_manual = primary_name_manual
|
14
|
-
@l2ident = l2ident
|
15
|
-
@vendor_name = vendor_name
|
16
|
-
@persistent = persistent
|
17
|
-
@reachable = reachable
|
18
|
-
@last_time_reachable = last_time_reachable
|
19
|
-
@active = active
|
20
|
-
@last_activity = last_activity
|
21
|
-
@names = names
|
22
|
-
@l3connectivities = l3connectivities
|
23
|
-
@interface = interface
|
24
|
-
@freebox = freebox
|
7
|
+
def initialize(session)
|
8
|
+
@session = session
|
25
9
|
end
|
26
10
|
|
27
|
-
def
|
28
|
-
@
|
29
|
-
|
30
|
-
|
11
|
+
def index
|
12
|
+
Interface.new(@session).index.collect { |interface|
|
13
|
+
@session.http_call('get', "/lan/browser/#{interface['name']}")
|
14
|
+
}.flatten
|
31
15
|
end
|
32
16
|
|
17
|
+
def show(id, interface = 'pub')
|
18
|
+
@session.http_call('get', "/lan/browser/#{interface}/#{id}/")
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(params = {}, interface = 'pub')
|
22
|
+
@session.http_call('put', "/lan/browser/#{interface}/#{params['id']}", params)
|
23
|
+
end
|
24
|
+
|
33
25
|
end
|
34
|
-
|
26
|
+
|
35
27
|
end
|
36
28
|
|
37
29
|
end
|
38
|
-
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module FreeboxApi
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
class PortForwarding
|
6
|
+
|
7
|
+
def initialize(session)
|
8
|
+
@session = session
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
@session.http_call('get', '/fw/redir/')
|
13
|
+
end
|
14
|
+
|
15
|
+
def show(id)
|
16
|
+
@session.http_call('get', "/fw/redir/#{id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(params = {})
|
20
|
+
@session.http_call('put', "/fw/redir/#{params['id']}", params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy(id)
|
24
|
+
@session.http_call('delete', "/fw/redir/#{id}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def create(params = {})
|
28
|
+
@session.http_call('post', '/fw/redir/', params)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -4,15 +4,28 @@ module FreeboxApi
|
|
4
4
|
|
5
5
|
class StaticLease
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
def initialize(session)
|
8
|
+
@session = session
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
@session.http_call('get', '/dhcp/static_lease/')
|
13
|
+
end
|
14
|
+
|
15
|
+
def show(id)
|
16
|
+
@session.http_call('get', "/dhcp/static_lease/#{id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(params = {})
|
20
|
+
@session.http_call('put', "/dhcp/static_lease/#{params['id']}", params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy(id)
|
24
|
+
@session.http_call('delete', "/dhcp/static_lease/#{id}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def create(params = {})
|
28
|
+
@session.http_call('post', '/dhcp/static_lease/', params)
|
16
29
|
end
|
17
30
|
|
18
31
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FreeboxApi
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
class UPnPRedir
|
6
|
+
|
7
|
+
def initialize(session)
|
8
|
+
@session = session
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
@session.http_call('get', '/upnpigd/redir/')
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy(id)
|
16
|
+
@session.http_call('delete', "/upnpigd/redir/#{id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module FreeboxApi
|
2
|
+
|
3
|
+
class Session
|
4
|
+
|
5
|
+
def initialize(app, freebox)
|
6
|
+
@app = app
|
7
|
+
@freebox = freebox
|
8
|
+
end
|
9
|
+
|
10
|
+
def password
|
11
|
+
Digest::HMAC.hexdigest(@freebox.challenge, @app[:app_token], Digest::SHA1)
|
12
|
+
end
|
13
|
+
|
14
|
+
def session_token
|
15
|
+
@freebox.http_call('post', '/login/session/',
|
16
|
+
{:app_id => @app[:app_id], :password => password}, nil)['session_token']
|
17
|
+
end
|
18
|
+
|
19
|
+
def http_call(http_method, path, params = {})
|
20
|
+
@freebox.http_call(http_method, path, params, self)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/freebox_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freebox_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mickaël Canévet
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rest-client
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -50,36 +45,40 @@ extensions: []
|
|
50
45
|
extra_rdoc_files: []
|
51
46
|
files:
|
52
47
|
- .gitignore
|
48
|
+
- LICENSE
|
53
49
|
- README.md
|
54
50
|
- freebox_api.gemspec
|
55
51
|
- lib/freebox_api.rb
|
52
|
+
- lib/freebox_api/application.rb
|
53
|
+
- lib/freebox_api/freebox.rb
|
56
54
|
- lib/freebox_api/resources/interface.rb
|
57
55
|
- lib/freebox_api/resources/lan_host.rb
|
58
|
-
- lib/freebox_api/resources/
|
56
|
+
- lib/freebox_api/resources/port_forwarding.rb
|
59
57
|
- lib/freebox_api/resources/static_lease.rb
|
58
|
+
- lib/freebox_api/resources/upnp_redir.rb
|
59
|
+
- lib/freebox_api/session.rb
|
60
60
|
- lib/freebox_api/version.rb
|
61
61
|
homepage: http://github.com/mcanevet/freebox_api
|
62
62
|
licenses: []
|
63
|
+
metadata: {}
|
63
64
|
post_install_message:
|
64
65
|
rdoc_options: []
|
65
66
|
require_paths:
|
66
67
|
- lib
|
67
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
69
|
requirements:
|
70
70
|
- - ! '>='
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
74
|
requirements:
|
76
75
|
- - ! '>='
|
77
76
|
- !ruby/object:Gem::Version
|
78
77
|
version: '0'
|
79
78
|
requirements: []
|
80
79
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 2.1.5
|
82
81
|
signing_key:
|
83
|
-
specification_version:
|
82
|
+
specification_version: 4
|
84
83
|
summary: Ruby bindings for Freebox OS's rest API
|
85
84
|
test_files: []
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module FreeboxApi
|
2
|
-
|
3
|
-
module Resources
|
4
|
-
|
5
|
-
class Redir
|
6
|
-
|
7
|
-
attr_reader :id, :enabled, :ip_proto, :wan_port_start, :wan_port_end, :lan_ip, :lan_port, :hostname, :host, :comment
|
8
|
-
|
9
|
-
def initialize(id, enabled, ip_proto, wan_port_start, wan_port_end, lan_ip, lan_port, hostname, host, comment, freebox)
|
10
|
-
@id = id
|
11
|
-
@enabled = enabled
|
12
|
-
@ip_proto = ip_proto
|
13
|
-
@wan_port_start = wan_port_start
|
14
|
-
@wan_port_end = wan_port_end
|
15
|
-
@lan_ip = lan_ip
|
16
|
-
@lan_port = lan_port
|
17
|
-
@hostname = hostname
|
18
|
-
@host = host
|
19
|
-
@comment = comment
|
20
|
-
@freebox = freebox
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|