shugoi 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4c40b825ec8554f779b8db8be5db9b19ad530a8c74c7636843aa056d0c7f8b4
4
- data.tar.gz: d00db587141e3e7b0a414454b0146d0264725cd84d49004063150858805eb62b
3
+ metadata.gz: 5f4f914059d5facba020a1ddbe26fc1394df276186fc60544d26ebe4b392d05c
4
+ data.tar.gz: 4e640e98060ad48fe5da630b909dfad3a1d8bd4bde3b7498619a440bd070a2d6
5
5
  SHA512:
6
- metadata.gz: 5ff3954380df4725967dd0d1bcb2a4bcff363126411ddfa72d35ad0c4c28343ff4c06a097b9c3026f0246d15da18b62465b8386c276e5ac06eaeeb89661f39b1
7
- data.tar.gz: b43348fcba2dddb1571e6084708d6659c5e246bf237b1f8948b3e3738914c900042868fa7c98985c44bedee866ebdb82781dcf1fc205f5bd13a9b67b1aed1c20
6
+ metadata.gz: e53401d85a8700c5599b9fe7b4017c97bff86446036bd12903309e054e9e395d9c2947129a3aebf46b9790263f47974069475802c81aa93005df9a5cc32f6fd5
7
+ data.tar.gz: 8b91f85485915fde86dd1c6818256f4ed54be6f033a2b41fd96b4b8d8fdb96ce230446ccfa9fe3844a3da4d4c364359b7bf5703a8bf9a95de08c2e985036ae29
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shugoi
4
+ # Injection de la notice de consentement dans le HTML rendu.
5
+ # Parité avec injectNoticeScript (render.ts du module Node) : la notice est injectée
6
+ # dans le HTML APRÈS le split-render (elle ne disparaît pas quand le render remplace
7
+ # le document). L'ack est décidé côté SERVEUR via /notice (machineId), pas de cookie.
8
+ class Notice
9
+ # Le script est identique au module Node (NOTICE_SCRIPT). Les placeholders `mid` et
10
+ # `sk` sont remplacés à l'injection (le guard n'a pas encore défini window.__sg_mid
11
+ # quand le HTML est rendu).
12
+ SCRIPT = <<~'JS'
13
+ <script>
14
+ (function(){
15
+ var mid=window.__sg_mid||'';
16
+ var sk=window.__sg_siteKey||'';
17
+ if(!mid||!sk||window.__sg_noticeEnabled===false)return;
18
+ var base=window.__sg_baseUrl||'';
19
+ var origin=base.replace(/\/api\/v1\/?$/,'');
20
+ function ack(){try{fetch(base+'/notice',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({machineId:mid,siteKey:sk}),keepalive:true,signal:AbortSignal.timeout(4000)}).catch(function(){})}catch(e){}}
21
+ function build(){var o=document.createElement('div');o.id='__sg_o';o.style.cssText='position:fixed!important;inset:0!important;z-index:2147483647!important;background:rgba(0,0,0,.6)!important;display:flex!important;align-items:center!important;justify-content:center!important;padding:1.2rem!important';var c=document.createElement('div');c.id='__sg_cd';c.style.cssText='background:#fff!important;border:4px solid #000!important;border-radius:28px 6px 32px 10px!important;box-shadow:14px 14px 0 #000!important;padding:0!important;max-width:720px!important;width:100%!important;text-align:center!important;font-family:Arial,sans-serif!important;display:flex!important;overflow:hidden!important';c.innerHTML='<div style="flex:0 0 320px;display:flex;align-items:center;justify-content:center;padding:1.5rem 1rem 1.5rem 3rem;overflow:hidden"><img src="'+origin+'/favicon.png" alt="" style="width:100%;height:auto;max-width:220px;pointer-events:none"></div><div style="flex:1;padding:1.6rem 1.8rem;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center"><img src="'+origin+'/brand-block.png" alt="Shugoi" style="display:block;margin:0 0 .3rem;pointer-events:none;max-width:100%;height:auto;max-height:40px"><div style="border:2px solid #000;display:inline-block;border-radius:8px 2px 12px 4px;padding:.2rem .6rem;font-size:.5rem;font-weight:700;text-transform:uppercase;letter-spacing:.1em;color:#E87090;margin-bottom:.6rem">Protection anti-abus</div><p style="font-size:.8rem;color:#555;line-height:1.7;margin:0 .4rem .6rem;max-width:280px">Ce site utilise Shugoi pour se protéger contre les abus et la fraude. Des caractéristiques techniques de votre navigateur sont analysées pour détecter les scripts automatisés, Tor, les VPN et les environnements virtuels. Aucune donnée personnelle n'est collectée.</p><button id="__sg_ok" style="background:#E87090;color:#fff;border:3px solid #000;border-radius:12px 3px 14px 5px;padding:.35rem 1.4rem;font-size:.8rem;font-weight:700;cursor:pointer">OK</button><div style="margin-top:.5rem;font-size:.5rem;color:#ccc"><a href="'+origin+'/legal/shugoi-notice" target="_blank" style="color:#E87090;text-decoration:underline">En savoir plus · shugoi.com</a></div></div>';o.appendChild(c);document.documentElement.appendChild(o);document.body.style.overflow='hidden';document.documentElement.style.overflow='hidden';var ok=document.getElementById('__sg_ok');if(ok)ok.onclick=function(){ack();var el=document.getElementById('__sg_o');if(el&&el.parentNode)el.parentNode.removeChild(el);document.body.style.overflow='';document.documentElement.style.overflow=''};}
22
+ function show(){if(document.body)build();else if(document.addEventListener)document.addEventListener('DOMContentLoaded',build);else setTimeout(show,50)}
23
+ fetch(base+'/notice?machineId='+encodeURIComponent(mid)+'&siteKey='+encodeURIComponent(sk),{signal:AbortSignal.timeout(4000)}).then(function(r){return r.json()}).then(function(d){if(!d.acknowledged)show()}).catch(function(){show()});
24
+ })();
25
+ </script>
26
+ JS
27
+
28
+ # Injecte la notice dans le HTML rendu (avant </body>).
29
+ # @param html [String] HTML rendu
30
+ # @param mid [String] machineId du client
31
+ # @param site_key [String] siteKey
32
+ # @return [String] HTML avec la notice injectée
33
+ def self.inject(html, mid, site_key)
34
+ script = SCRIPT
35
+ .gsub("var mid=window.__sg_mid||'';", "var mid=#{JSON.generate(mid)}||'';")
36
+ .gsub("var sk=window.__sg_siteKey||'';", "var sk=#{JSON.generate(site_key)}||'';")
37
+ if html.include?("</body>")
38
+ html.sub("</body>", "#{script}</body>")
39
+ else
40
+ "#{html}#{script}"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -32,12 +32,12 @@ module Shugoi
32
32
 
33
33
  content_replace_on = content_replace_flag?(token)
34
34
  html = @html_store.read(token)
35
- return { html: html } if html
35
+ return { html: inject_notice(html, mid) } if html
36
36
 
37
37
  # Fallback content-replace OFF : renvoie le HTML du site.
38
38
  unless content_replace_on
39
39
  site_html = @html_store.site_html(tok_site_key)
40
- return { html: site_html } if site_html
40
+ return { html: inject_notice(site_html, mid) } if site_html
41
41
  end
42
42
 
43
43
  return { error: "not_found" } unless @token_signer.verify_token(token)
@@ -47,6 +47,12 @@ module Shugoi
47
47
 
48
48
  private
49
49
 
50
+ # Injecte la notice de consentement (parité handleRender : `if (data.html && mid)`).
51
+ def inject_notice(html, mid)
52
+ return html if mid.to_s.empty?
53
+ Notice.inject(html, mid, @config.site_key)
54
+ end
55
+
50
56
  def content_replace_flag?(token)
51
57
  site_key = token.split(":")[0]
52
58
  flags = @config_cache.fetch(site_key)[:flags]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shugoi
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/shugoi.rb CHANGED
@@ -11,6 +11,7 @@ require_relative "shugoi/api_client"
11
11
  require_relative "shugoi/guard_cache"
12
12
  require_relative "shugoi/config_cache"
13
13
  require_relative "shugoi/html_store"
14
+ require_relative "shugoi/notice"
14
15
  require_relative "shugoi/skeleton_generator"
15
16
  require_relative "shugoi/render_handler"
16
17
  require_relative "shugoi/core"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shugoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugoi
@@ -69,6 +69,7 @@ files:
69
69
  - lib/shugoi/errors.rb
70
70
  - lib/shugoi/guard_cache.rb
71
71
  - lib/shugoi/html_store.rb
72
+ - lib/shugoi/notice.rb
72
73
  - lib/shugoi/pow.rb
73
74
  - lib/shugoi/rack/middleware.rb
74
75
  - lib/shugoi/rails/configuration.rb