libriciel 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f75691fcd516c56ad41b703c8d406685c4ccae5ba84b2709f8509f885949aed8
4
+ data.tar.gz: f4b57f164d625b13a1ec678a74d7b5a1f940c90154dc84b4b7b7aa3010ad87ea
5
+ SHA512:
6
+ metadata.gz: 0bac166ab2ed5759751478263e48c96078ff583d53b528d7168d1ffaedc13f8acdc6a607f1b515cd4a7d6a114a7a9c19a049e8f9eedd687255aac10b49c56fee
7
+ data.tar.gz: 7f07b9e67f2a353461e381f385c4769c6c9abde965559658f910e7c3332964dfae6a73fb55fd63dc3bda474f9c8d6a74e3e63477bda7b688f801a8ce08ce7574
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,75 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at axel.chevrier@libriciel.coop
59
+ . All
60
+ complaints will be reviewed and investigated and will result in a response that
61
+ is deemed necessary and appropriate to the circumstances. The project team is
62
+ obligated to maintain confidentiality with regard to the reporter of an incident.
63
+ Further details of specific enforcement policies may be posted separately.
64
+
65
+ Project maintainers who do not follow or enforce the Code of Conduct in good
66
+ faith may face temporary or permanent repercussions as determined by other
67
+ members of the project's leadership.
68
+
69
+ ## Attribution
70
+
71
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72
+ available at [http://contributor-covenant.org/version/1/4][version]
73
+
74
+ [homepage]: http://contributor-covenant.org
75
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in libriciel.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Axel CHEVRIER
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Libriciel
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/libriciel`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'libriciel'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install libriciel
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/libriciel. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Libriciel project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/libriciel/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "libriciel"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Libriciel
2
+ VERSION = "0.1.2"
3
+ end
data/lib/libriciel.rb ADDED
@@ -0,0 +1,662 @@
1
+ require 'json'
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'csv'
5
+ require 'openssl'
6
+ require "libriciel/version"
7
+
8
+ module Libriciel
9
+
10
+ # Class ApiXivo to use Xivo Api
11
+ class ApiXivo
12
+ # Génération du token permettant l'authent ADMIN (ATTENTION) pour l'api Xivo
13
+ def self.token_generate(user, pass)
14
+
15
+ couplae_base64_pass_user = base64()
16
+ url = URI("https://xivo.libriciel.fr:9497/0.1/token")
17
+
18
+ http = Net::HTTP.new(url.host, url.port)
19
+ http.use_ssl = true
20
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
21
+
22
+ request = Net::HTTP::Post.new(url)
23
+ request["content-type"] = 'application/json'
24
+ request["authorization"] = "Basic #{couplae_base64_pass_user}"
25
+ request["cache-control"] = 'no-cache'
26
+
27
+ request.body = "{\n \"backend\": \"xivo_admin\",\n \"expiration\": 5\n}"
28
+
29
+ response = http.request(request)
30
+ token = JSON.parse(response.read_body)['data']['token']
31
+
32
+ return token
33
+ end
34
+
35
+ # Liste de tous les devices qui sont soit en autoprov (avec leur mac)
36
+ # soit en not_configured
37
+ def self.get_free_devices(token)
38
+ url = URI("https://xivo.libriciel.fr:9486/1.1/devices")
39
+
40
+ http = Net::HTTP.new(url.host, url.port)
41
+ http.use_ssl = true
42
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
43
+
44
+ request = Net::HTTP::Get.new(url)
45
+ request["x-auth-token"] = "#{token}"
46
+ request["cache-control"] = 'no-cache'
47
+
48
+ response = http.request(request)
49
+
50
+ json = JSON.parse(response.read_body)
51
+ json["items"].each do |devices|
52
+ if devices["status"] == "autoprov"
53
+ puts "\nThe Device #{devices["id"]} is #{devices["status"]}"
54
+ puts "The Devices #{devices["id"]} mac is #{devices["mac"]}\n"
55
+ elsif devices["status"] == "not_configured"
56
+ puts "\nThe Device #{devices["id"]} is #{devices["status"]}"
57
+ puts "The Devices #{devices["id"]} mac is #{devices["mac"]}\n"
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ # Fonction qui donne un numéro SIP disponible pour un nouveau user
64
+ def self.get_free_sip(min_sip, max_sip, token)
65
+ sip_number = min_sip
66
+ array_numbers = []
67
+ url = URI("https://xivo.libriciel.fr:9486/1.1/lines")
68
+
69
+ http = Net::HTTP.new(url.host, url.port)
70
+ http.use_ssl = true
71
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
72
+
73
+ request = Net::HTTP::Get.new(url)
74
+ request["x-auth-token"] = "#{token}"
75
+ request["cache-control"] = 'no-cache'
76
+
77
+ response = http.request(request)
78
+ json = JSON.parse(response.read_body)
79
+ json2 = json["items"].to_a
80
+ json2.each do |number_check|
81
+ array_numbers << number_check["caller_id_num"]
82
+ end
83
+
84
+ while sip_number < max_sip
85
+ if array_numbers.include?(sip_number.to_s)
86
+ sip_number += 1
87
+ else
88
+ return sip_number
89
+
90
+ end
91
+ end
92
+ end
93
+
94
+ # Liste complète detous les devices avec leurs infos (format ouput: json)
95
+ def self.get_devices(token)
96
+ url = URI("https://xivo.libriciel.fr:9486/1.1/devices")
97
+
98
+ http = Net::HTTP.new(url.host, url.port)
99
+ http.use_ssl = true
100
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
101
+
102
+ request = Net::HTTP::Get.new(url)
103
+ request["x-auth-token"] = "#{token}"
104
+ request["cache-control"] = 'no-cache'
105
+
106
+ response = http.request(request)
107
+ json = JSON.parse(response.read_body)
108
+ puts json["items"]
109
+ end
110
+
111
+ # Obtention de l'ID de la ligne avec le numéro de tel
112
+ def self.get_line_id_from_number(number, token)
113
+ line_id = 0
114
+ url = URI("https://xivo.libriciel.fr:9486/1.1/lines")
115
+
116
+ http = Net::HTTP.new(url.host, url.port)
117
+ http.use_ssl = true
118
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
119
+
120
+ request = Net::HTTP::Get.new(url)
121
+ request["x-auth-token"] = "#{token}"
122
+ request["cache-control"] = 'no-cache'
123
+
124
+ response = http.request(request)
125
+ json = JSON.parse(response.read_body)
126
+ json2 = json["items"].to_a
127
+ json2.each do |number_check|
128
+ if number_check["caller_id_num"].to_i == number.to_i
129
+ line_id = number_check["id"]
130
+ else
131
+ end
132
+
133
+ end
134
+ return line_id
135
+ end
136
+
137
+ # Obtention de l'ID du téléphone avec l'ID de la ligne
138
+ def self.get_device_id_from_line(line_id, token)
139
+ url = URI("https://xivo.libriciel.fr:9486/1.1/lines/#{line_id}/devices")
140
+
141
+ http = Net::HTTP.new(url.host, url.port)
142
+ http.use_ssl = true
143
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
144
+
145
+ request = Net::HTTP::Get.new(url)
146
+ request["x-auth-token"] = "#{token}"
147
+ request["cache-control"] = 'no-cache'
148
+
149
+ response = http.request(request)
150
+ device_id = JSON.parse(response.read_body)
151
+
152
+ return device_id["device_id"]
153
+ end
154
+
155
+ # Obtention de la mac du téléphone avec l'ID de ce dernier
156
+ def self.get_device_mac_from_id(device_id, token)
157
+ url = URI("https://xivo.libriciel.fr:9486/1.1/devices")
158
+
159
+ http = Net::HTTP.new(url.host, url.port)
160
+ http.use_ssl = true
161
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
162
+
163
+ request = Net::HTTP::Get.new(url)
164
+ request["x-auth-token"] = "#{token}"
165
+ request["cache-control"] = 'no-cache'
166
+
167
+ response = http.request(request)
168
+ json = JSON.parse(response.read_body)
169
+
170
+ json["items"].each do |devices|
171
+ if devices["id"].to_s == device_id.to_s
172
+ return devices["mac"]
173
+
174
+ else
175
+ end
176
+ end
177
+
178
+ end
179
+
180
+ # Obtention de l'ID d'un téléphone avec sa mac
181
+ def self.get_device_id_from_mac(mac, token)
182
+ url = URI("https://xivo.libriciel.fr:9486/1.1/devices")
183
+
184
+ http = Net::HTTP.new(url.host, url.port)
185
+ http.use_ssl = true
186
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
187
+
188
+ request = Net::HTTP::Get.new(url)
189
+ request["x-auth-token"] = "#{token}"
190
+ request["cache-control"] = 'no-cache'
191
+
192
+ response = http.request(request)
193
+ json = JSON.parse(response.read_body)
194
+
195
+ json["items"].each do |devices|
196
+ if devices["mac"].to_s == mac.to_s
197
+ return devices["id"]
198
+
199
+ else
200
+ end
201
+ end
202
+
203
+ end
204
+
205
+ # Suppression d'une associtaiton ligne / numéro
206
+ # Attention ERROR 36 si pas associé à un device
207
+ def self.del_association(line_id, device_id, token)
208
+ url = URI("https://xivo.libriciel.fr:9486/1.1/lines/#{line_id}/devices/#{device_id}")
209
+
210
+ http = Net::HTTP.new(url.host, url.port)
211
+ http.use_ssl = true
212
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
213
+
214
+ request = Net::HTTP::Delete.new(url)
215
+ request["x-auth-token"] = "#{token}"
216
+ request["cache-control"] = 'no-cache'
217
+
218
+
219
+ response = http.request(request)
220
+
221
+ unless response.read_body.to_s.strip.empty?
222
+ STDERR.puts("Line is not associated with Device")
223
+ exit(36)
224
+ end
225
+
226
+ end
227
+
228
+ # Ajout d'une association entre un numéro et un téléphone
229
+ # Attention ERROR 36 si deja associé à un device
230
+ def self.add_association(line_id, device_id, token)
231
+ url = URI("https://xivo.libriciel.fr:9486/1.1/lines/#{line_id}/devices/#{device_id}")
232
+
233
+ http = Net::HTTP.new(url.host, url.port)
234
+ http.use_ssl = true
235
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
236
+
237
+ request = Net::HTTP::Put.new(url)
238
+ request["x-auth-token"] = "#{token}"
239
+ request["cache-control"] = 'no-cache'
240
+
241
+
242
+ response = http.request(request)
243
+ unless response.read_body.to_s.strip.empty?
244
+ STDERR.puts("Line is already associated to a Device")
245
+ exit(36)
246
+ end
247
+
248
+ end
249
+
250
+ # Synchronisation du device avec son ID
251
+ def self.synchro_device_id(device_id, token)
252
+ url = URI("https://xivo.libriciel.fr:9486/1.1/devices/#{device_id}/synchronize")
253
+
254
+ http = Net::HTTP.new(url.host, url.port)
255
+ http.use_ssl = true
256
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
257
+
258
+ request = Net::HTTP::Get.new(url)
259
+ request["x-auth-token"] = "#{token}"
260
+ request["cache-control"] = 'no-cache'
261
+
262
+ response = http.request(request)
263
+ puts response.read_body
264
+
265
+ end
266
+
267
+ # Export en csv de tous les utilisateurs xivo
268
+ def self.export_all_users_to_csv(xivo_csv_file, token)
269
+ url = URI("https://xivo.libriciel.fr:9486/1.1/users/export")
270
+
271
+ http = Net::HTTP.new(url.host, url.port)
272
+ http.use_ssl = true
273
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
274
+
275
+ request = Net::HTTP::Get.new(url)
276
+ request["x-auth-token"] = "#{token}"
277
+ request["cache-control"] = 'no-cache'
278
+
279
+
280
+ response = http.request(request)
281
+
282
+ File.open("#{xivo_csv_file}", "w") {|f| f.write(response.read_body)}
283
+ return xivo_csv_file
284
+
285
+ end
286
+
287
+ # Ajotu d'un nouvel utilisateurs avec création de son numéro (get_free_sip)
288
+ # et passage du password dans le csv_entry
289
+ def self.add_new_user(csv_entry, token)
290
+ url = URI("https://xivo.libriciel.fr:9486/1.1/users/import")
291
+
292
+ http = Net::HTTP.new(url.host, url.port)
293
+ http.use_ssl = true
294
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
295
+
296
+ request = Net::HTTP::Post.new(url)
297
+ request["x-auth-token"] = "#{token}"
298
+ request["content-type"] = 'text/csv; charset=utf-8'
299
+ request["cache-control"] = 'no-cache'
300
+ request.body = csv_entry
301
+
302
+ response = http.request(request)
303
+
304
+ end
305
+
306
+ end
307
+
308
+ # Class GetConfig for chef deploy
309
+ class GetConfig
310
+ require 'fileutils'
311
+
312
+ ## Partie pour Pastell à contnuer
313
+ def self.compare_files_pastell(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)
314
+ if !default_config_file_parse[libriciel]
315
+ default_config_file_parse[libriciel] = {}
316
+
317
+ end
318
+
319
+ if File.readlines(conf_file).grep(/BD_/).size > 0
320
+ conf_file_parse = JSON.parse(File.read(conf_file))
321
+ if !default_config_file_parse[libriciel]["database"]
322
+ default_config_file_parse[libriciel]["database"] = {}
323
+
324
+ end
325
+
326
+ conf_file_parse.keys.each do |valeur_tableau_configuration|
327
+
328
+ if valeur_tableau_configuration.include? "BD_"
329
+ case valeur_tableau_configuration
330
+ when "BD_USER"
331
+ default_config_file_parse[libriciel]["database"]["user"] = conf_file_parse[valeur_tableau_configuration]
332
+
333
+ when "BD_PASS"
334
+ default_config_file_parse[libriciel]["database"]["password"] = conf_file_parse[valeur_tableau_configuration]
335
+
336
+ when "BD_DSN"
337
+
338
+ default_config_file_parse[libriciel]["database"]["host_conf"] = conf_file_parse[valeur_tableau_configuration]
339
+
340
+ end
341
+ elsif valeur_tableau_configuration == "hostname"
342
+ default_config_file_parse[libriciel]["fullname"] = conf_file_parse[valeur_tableau_configuration]
343
+
344
+ elsif valeur_tableau_configuration == "mail.from"
345
+ default_config_file_parse[libriciel]["domain"] = conf_file_parse[valeur_tableau_configuration].gsub(/\S*@/, "")
346
+
347
+ end
348
+ end
349
+ end
350
+ end
351
+
352
+ # Partie pour Webdelib à continuer
353
+ def self.compare_files_webdelib(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)
354
+
355
+ end
356
+
357
+ def self.compare_files_iparapheur(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)
358
+ ## Schema pour le Xmx
359
+ ## default['iparapheur']['ctl']['xms'] pour le iParapheur
360
+ ## ["-Xmx": "xxxxm", "-Xms": "xxxxm"] pour le parse_spec_conf
361
+ if !default_config_file_parse[libriciel]
362
+ default_config_file_parse[libriciel] = {}
363
+
364
+ end
365
+
366
+ case
367
+
368
+ ## Xmx et Xms
369
+ ## Lancement du parse pour voir les bonnes valeurs des Xmx et xms
370
+ ## Puis mise en place dans le config.json au cas ou pas existant
371
+ when File.readlines(conf_file).grep(/Xms|Xmx/).size > 0
372
+ tableau = {}
373
+ tabs = parse_spec_conf(conf_file, caracs_to_extract_from, tableau, nil)
374
+
375
+ if !default_config_file_parse[libriciel]["ctl"]
376
+ default_config_file_parse[libriciel]["ctl"] = {}
377
+
378
+ end
379
+
380
+ if default_config_file_parse[libriciel]["ctl"].empty?
381
+ default_config_file_parse[libriciel]["ctl"] = default_config_file_parse[libriciel]["ctl"].merge(tabs)
382
+
383
+ else
384
+ default_config_file_parse[libriciel]["ctl"] = tabs
385
+
386
+
387
+
388
+ end
389
+
390
+ ## database vérification et surcharge des
391
+ ## entrée dans le config.json pour régénération
392
+ when File.readlines(conf_file).grep(/db./).size > 0
393
+ conf_file_parse = JSON.parse(File.read(conf_file))
394
+ if !default_config_file_parse[libriciel]["database"]
395
+ default_config_file_parse[libriciel]["database"] = {}
396
+
397
+ end
398
+
399
+ conf_file_parse.keys.each do |valeur_tableau_configuration|
400
+
401
+ if valeur_tableau_configuration.include? "db."
402
+ case valeur_tableau_configuration
403
+ when "db.username"
404
+ default_config_file_parse[libriciel]["database"]["user"] = conf_file_parse[valeur_tableau_configuration]
405
+
406
+ when "db.password"
407
+ default_config_file_parse[libriciel]["database"]["password"] = conf_file_parse[valeur_tableau_configuration]
408
+
409
+ when "db.name"
410
+ default_config_file_parse[libriciel]["database"]["name"] = conf_file_parse[valeur_tableau_configuration]
411
+
412
+ when "db.url"
413
+ default_config_file_parse[libriciel]["database"]["host_conf"] = conf_file_parse[valeur_tableau_configuration].gsub("jdbc:mysql://", "").gsub(/\/#{conf_file_parse["db.name"]}\z/, "")
414
+
415
+ end
416
+ elsif valeur_tableau_configuration == "hostname"
417
+ default_config_file_parse[libriciel]["fullname"] = conf_file_parse[valeur_tableau_configuration]
418
+
419
+ elsif valeur_tableau_configuration == "mail.from"
420
+ default_config_file_parse[libriciel]["domain"] = conf_file_parse[valeur_tableau_configuration].gsub(/\S*@/, "")
421
+
422
+ end
423
+ end
424
+ else
425
+ puts "autres parametres"
426
+ end
427
+
428
+ ## Ici pour surcharge de mes valeurs par défaut du config .JSON
429
+ ## Qui est généré par défaut
430
+ File.open("#{default_config_file}", "w") {|f| f.write(JSON.pretty_generate(default_config_file_parse))}
431
+ end
432
+
433
+ ## Fonction pour la table de correspondance qui va permettre
434
+ ## D'ajouter au config.json existant les bonnes valeurs
435
+ ## Par exemple le db.host avec le "database" : "hostname" = "" pour
436
+ def self.table_comparaison(all_conf_files, caracs_to_extract_from, libriciel, default_config_file)
437
+ default_config_file_parse = JSON.parse(File.read(default_config_file))
438
+ all_conf_files.each do |conf_file|
439
+ conf_file_open = File.open(conf_file)
440
+
441
+ case libriciel
442
+ when "iparapheur"
443
+ compare_files_iparapheur(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)
444
+
445
+ when "webdelib"
446
+ compare_files_webdelib(default_config_file_parse, conf_file_open,conf_file, libriciel, caracs_to_extract_from, default_config_file)
447
+
448
+ when "pastell"
449
+ compare_files_pastell(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)
450
+
451
+ else
452
+ puts "Outils pas dans la liste"
453
+ end
454
+ end
455
+ end
456
+
457
+
458
+ ## Fonction pour l'extraction d'une chaine de caractère
459
+ ## (par exemple le xmx et le xms dans le ctl.sh)
460
+ ## Fichier en entrée, la ou les chaines de caractères à parser
461
+ ## Petit tableau en retours pour pouvoir le faire corrspondre au tableau
462
+ def self.parse_spec_conf(conf_file, caracs_to_extract_from, carac_tableau, separateur)
463
+ conf_file_open = File.open(conf_file)
464
+
465
+ conf_file_open.each_line do |line|
466
+ line_split = line.split
467
+
468
+ caracs_to_extract_from.each do |carac_to_split|
469
+ if line.include? carac_to_split
470
+ line_grep = line_split.grep(/#{carac_to_split}/)
471
+ carac_mis_en_forme = carac_to_split.gsub(/[^0-9A-Za-z]/, '').to_s.downcase
472
+
473
+ line_grep.each do |line_to_gsub|
474
+ if !carac_mis_en_forme.empty?
475
+ carac_tableau[carac_mis_en_forme] = line_to_gsub.gsub("#{carac_to_split}", '').gsub(/[^0-9A-Za-z]/, '')
476
+
477
+ else
478
+ # puts "entrée vide"
479
+ end
480
+
481
+ end
482
+ end
483
+ end
484
+ end
485
+ return carac_tableau
486
+
487
+ end
488
+
489
+ # Fonction qui va prendre le tableau généré par celle ci pour le lire et inscrire dans
490
+ #le conf.json parsé au bon endroit "iparpaheur": {} par exemple les valeurs pour etre ready pour la mise à jour
491
+ def self.concat_config_json(config_json_file, tableau, libriciel)
492
+ config_json_file_parse = JSON.parse(File.read(config_json_file))
493
+ config_json_file_parse[libriciel] = config_json_file_parse[libriciel].merge(tableau)
494
+
495
+ ## Ici pour surcharge de mes valeurs par défaut du config .JSON
496
+ ## Qui est généré par défaut
497
+ File.open("#{config_json_file}", "w") {|f| f.write(JSON.pretty_generate(config_json_file_parse))}
498
+
499
+ end
500
+
501
+ #faire une seconde fonction qui va prendre le tableau généré par celle ci pour le lire et inscrire dans
502
+ #le conf.json parsé au bon endroit "iparapheur": {} par exemple les valeurs pour etre ready pour la mise à jour
503
+ def self.compare_json(template_json, conf_json, table_valeur_diff)
504
+ if !FileUtils.compare_file(template_json, conf_json)
505
+
506
+ template_file_json = JSON.parse(File.read(template_json))
507
+ conf_file_json = JSON.parse(File.read(conf_json))
508
+
509
+ template_file_json.keys.each do |keys_template_file_lvl_1|
510
+
511
+ if !conf_file_json.keys.include? keys_template_file_lvl_1
512
+ puts "Attention pas bonne syntaxe de la configuration"
513
+ exit 222
514
+ else
515
+ if conf_file_json[keys_template_file_lvl_1] == template_file_json[keys_template_file_lvl_1]
516
+
517
+ else
518
+
519
+ ## Les if suivants sur le conf_json sont exclusif pour le iParapheur et
520
+ ## la mise en place de l'aborescence du config.json
521
+ if File.basename(conf_json) == "iparapheur-global.properties.json"
522
+ keys_template_file_ip = "ihm"
523
+
524
+ if !table_valeur_diff[keys_template_file_ip]
525
+ table_valeur_diff[keys_template_file_ip] = {}
526
+
527
+ end
528
+ table_valeur_diff["ihm"][keys_template_file_lvl_1] = conf_file_json[keys_template_file_lvl_1]
529
+
530
+ elsif File.basename(conf_json) == "alfresco-global.properties.json"
531
+ keys_template_file_ip = "alf"
532
+
533
+ if !table_valeur_diff[keys_template_file_ip]
534
+ table_valeur_diff[keys_template_file_ip] = {}
535
+
536
+ end
537
+ table_valeur_diff["alf"][keys_template_file_lvl_1] = conf_file_json[keys_template_file_lvl_1]
538
+
539
+ else
540
+ table_valeur_diff[keys_template_file_lvl_1] = conf_file_json[keys_template_file_lvl_1]
541
+
542
+ end
543
+ end
544
+ end
545
+ end
546
+
547
+ else
548
+ # Mettre en place gestion des erreurs et raises
549
+ end
550
+
551
+ # Return du tableau avec les infos à ajouter au tableau config.json parsé
552
+ return table_valeur_diff
553
+ end
554
+
555
+ # Générateur du config.json avec les infos modifiées du fichier de configuration
556
+ # par rapport au template
557
+ def self.config_json_generator(template_json_file, config_json_file, libriciel, default_config_json)
558
+ tableau = {}
559
+ template_json_file.each do |each_template|
560
+ config_json_file.each do |each_conf_files|
561
+ if File.basename(each_template) == File.basename(each_conf_files)
562
+ compare_json(each_template, each_conf_files, tableau)
563
+ concat_config_json(default_config_json, tableau, libriciel)
564
+ #else
565
+ # Le test donne deux fichier différents qui n'ont pas à etre comparés
566
+ end
567
+ end
568
+ end
569
+ end
570
+
571
+ ## Fonction permettant de parser les fichiers de properties iParapheur en JSON
572
+ def self.ip_conf_to_json(line, tableau)
573
+ array_properties_value = line.split(/[=\n]+/)
574
+ array_properties_dot_split = array_properties_value[0].split(/[\.\n]+/)
575
+
576
+ if array_properties_dot_split[0].include? "parapheur"
577
+ array_properties_parapheur_split = array_properties_value[0].split(/parapheur\./)
578
+ tableau[array_properties_parapheur_split[1]] = array_properties_value[1]
579
+
580
+ elsif array_properties_value[0].include? "authentication.chain" or array_properties_value[0].include? "alfresco.authentication.allowGuestLogin" or array_properties_value[0].include? "synchronization.autoCreatePeopleOnLogin"
581
+ if array_properties_value[0].include? "#"
582
+ array_properties_value[0] = array_properties_value[0].gsub("#", "")
583
+ tableau[array_properties_value[0]] = array_properties_value[1]
584
+ else
585
+ tableau[array_properties_value[0]] = array_properties_value[1]
586
+ end
587
+ else
588
+ tableau[array_properties_value[0]] = array_properties_value[1]
589
+
590
+ end
591
+ return tableau
592
+ end
593
+
594
+ ## Fonction permettant de parser les fichiers de conf pastell en json
595
+ def self.pa_conf_to_json(line, tableau)
596
+ tmp_clean = line.gsub(/define\(/, "").gsub(/\);/, "")
597
+ array_properties_value = tmp_clean.split(/[, \n]+/)
598
+
599
+ tableau[array_properties_value[0]] = array_properties_value[1].gsub(/\\;/, "")
600
+
601
+ return tableau
602
+ end
603
+
604
+ ## Fonction permettant de parser les fichiers de conf webdelib en json
605
+ def self.wd_conf_to_json(line, tableau)
606
+ tmp_clean = line.gsub(/Configure::write\(/, "").gsub(/\);/, "")
607
+ array_properties_value = tmp_clean.split(/[, \n]+/)
608
+
609
+ tableau[array_properties_value[0]] = array_properties_value[1]
610
+
611
+ return tableau
612
+ end
613
+
614
+ # Fonction qui fait le parsing des fichiers en confs en data_bag
615
+ def self.parsing_conf(files, directory_json)
616
+ Array(files).each do |file|
617
+
618
+ # Récupération des nom de fichier dans la chemin absolu
619
+ array_absolute_path_to_file = file.split('/')
620
+ config_file_to_write = "/tmp/#{array_absolute_path_to_file.last}.json"
621
+
622
+ config_files = File.open(file).read
623
+
624
+ # Si existant on surcharge
625
+ File.open("#{config_file_to_write}", "w") {|f| f.write("") }
626
+
627
+ tableau = {}
628
+ ## Passage de chaque ligne en json pour le fichier de conf en cours
629
+ config_files.each_line do |line|
630
+ if line.include? "define("
631
+ pa_conf_to_json(line, tableau)
632
+
633
+ elsif line.include? "Configure::write("
634
+ wd_conf_to_json(line, tableau)
635
+
636
+ elsif line.include? "="
637
+ if !line[0,1].include? "#" or line.include? "ldap"
638
+ ip_conf_to_json(line, tableau)
639
+ end
640
+
641
+ end
642
+ end
643
+
644
+ ## Ecriture du parsing en json du tableau généré par les fonctions dans le fichier json
645
+ File.open("#{config_file_to_write}", "a") {|f| f.write(JSON.pretty_generate(tableau)) }
646
+
647
+ ## Copie des fichiers dans le répertoire commun
648
+ mv_json("#{config_file_to_write}", directory_json.to_s)
649
+ end
650
+ end
651
+
652
+
653
+
654
+ def self.mv_json(files, directory)
655
+ FileUtils.mv(files, directory)
656
+ end
657
+
658
+ def self.cp_json(files, directory)
659
+ FileUtils.cp(files, directory)
660
+ end
661
+ end
662
+ end
data/libriciel.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "libriciel/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "libriciel"
7
+ spec.version = Libriciel::VERSION
8
+ spec.authors = ["Axel CHEVRIER"]
9
+ spec.email = ["axel.chevrier@libriciel.coop"]
10
+
11
+ spec.summary = %q{Gem Libriciel with all classes included}
12
+ spec.description = %q{Gem Libriciel with all classes includes, called in ruby code like `Libriciel::ApiXivo.xxxx`}
13
+ spec.homepage = "https://gitlab.libriciel.fr/outils/gem-libriciel"
14
+ spec.license = "MIT"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libriciel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Axel CHEVRIER
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Gem Libriciel with all classes includes, called in ruby code like `Libriciel::ApiXivo.xxxx`
42
+ email:
43
+ - axel.chevrier@libriciel.coop
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/libriciel.rb
57
+ - lib/libriciel/version.rb
58
+ - libriciel.gemspec
59
+ homepage: https://gitlab.libriciel.fr/outils/gem-libriciel
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.0.4
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Gem Libriciel with all classes included
82
+ test_files: []