senthor_rails_legacy 0.1.0

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: 02ccdd51d5af32544442de14e20b5773ec6f3b9c7a6e537ef0c1511f0cc78691
4
+ data.tar.gz: 3081a3e6dcbd1304916f4e10e5038f7c64a7331e214ab38ee5ef7a05562e0516
5
+ SHA512:
6
+ metadata.gz: afe8eadf70413f6df7ca0d874aa8b4356c936bc612ebf51ae978acc112fbdefeffd7969942651474893916b9170e99de425bd1894e1dda8b6cfcfe8c4f15be6d
7
+ data.tar.gz: 716e389076c12c41bcbb3003b42a6b32936bfd5cbdd92f5c8e6d2d7185587b480abad42b912a3a8ae14512e70346d533497a0fbe25bb597cef0e8a077290fe16
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
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 senthor_rails_legacy.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 TODO: Write your name
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,36 @@
1
+ # Senthor_rails
2
+
3
+ Drop-in Senthor middleware for Ruby on Rails
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add senthor_rails_legacy
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install senthor_rails_legacy
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ In `config/application.rb`, activate the middleware
22
+
23
+ ```
24
+ class Application < Rails::Application
25
+ (...)
26
+ config.middleware.use Senthor::Middleware
27
+ end
28
+ ```
29
+
30
+ This middleware will :
31
+
32
+ - Intercept GET requests
33
+ - Call the Senthor API
34
+ - Detect if it's from AI and act accordingly based on your Senthor settings
35
+
36
+ If your website isn't configured on Senthor, all requests will pass through.
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 "senthor_rails_legacy"
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,84 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'openssl'
5
+
6
+ module Senthor
7
+ class Middleware
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ request = Rack::Request.new(env)
14
+
15
+ unless request.get?
16
+ return @app.call(env)
17
+ end
18
+
19
+ client_ip =
20
+ request.get_header('HTTP_X_FORWARDED_FOR')&.split(',')&.first&.strip ||
21
+ request.get_header('HTTP_X_REAL_IP') ||
22
+ request.get_header('HTTP_CF_CONNECTING_IP') ||
23
+ request.get_header('REMOTE_ADDR') ||
24
+ 'unknown'
25
+
26
+ headers = {}
27
+ excluded_headers = %w[
28
+ AUTHORIZATION
29
+ COOKIE
30
+ SET_COOKIE
31
+ PROXY_AUTHORIZATION
32
+ X_CSRF_TOKEN
33
+ X_XSRF_TOKEN
34
+ X_API_KEY
35
+ X_ACCESS_TOKEN
36
+ ]
37
+ env.each do |key, value|
38
+ if key.start_with?('HTTP_')
39
+ header_name = key.sub(/^HTTP_/, '').upcase
40
+ next if excluded_headers.include?(header_name)
41
+
42
+ # Format header name back to normal-case (e.g., "User-Agent")
43
+ pretty_name = header_name.split('_').map(&:capitalize).join('-')
44
+ headers[pretty_name] = value
45
+ end
46
+ end
47
+
48
+ payload = {
49
+ headers: headers,
50
+ request_url: request.url,
51
+ client_ip: client_ip
52
+ }
53
+
54
+ uri = URI('https://waf-api.senthor.io/api/check-request')
55
+ http = Net::HTTP.new(uri.host, uri.port)
56
+ http.use_ssl = true
57
+
58
+ # Disable SSL verification only in development/local
59
+ if Rails.env.development? || Rails.env.test?
60
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
61
+ http.verify_depth = 0
62
+ http.cert_store = OpenSSL::X509::Store.new
63
+ end
64
+
65
+ request = Net::HTTP::Post.new(uri)
66
+ request['Content-Type'] = 'application/json'
67
+ request.body = payload.to_json
68
+
69
+ response = http.request(request)
70
+
71
+ # Handle 402 response
72
+ if response.code.to_i == 402
73
+ return [
74
+ 402,
75
+ { 'Content-Type' => 'text/plain' },
76
+ ['This content is protected by a paywall. Visit https://senthor.io to find out how to access the content.']
77
+ ]
78
+ end
79
+
80
+ # Otherwise continue as normal
81
+ @app.call(env)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module SenthorRailsLegacy
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "senthor_rails_legacy/version"
2
+ require "senthor_rails_legacy/middleware"
3
+
4
+ module Senthor
5
+ end
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "senthor_rails_legacy/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "senthor_rails_legacy"
8
+ spec.version = SenthorRailsLegacy::VERSION
9
+ spec.authors = ["Senthor"]
10
+ spec.email = ["contact@senthor.io"]
11
+
12
+ spec.summary = "Senthor middleware for Ruby on Rails applications"
13
+ spec.description = "Protect your content from AI crawlers and monetize every request with Senthor. Real-time detection, crawler control, and detailed analytics."
14
+ spec.homepage = "https://www.senthor.io"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.end_with?(".gem") }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.17"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: senthor_rails_legacy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Senthor
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bundler
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.17'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.17'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.0'
40
+ description: Protect your content from AI crawlers and monetize every request with
41
+ Senthor. Real-time detection, crawler control, and detailed analytics.
42
+ email:
43
+ - contact@senthor.io
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/senthor_rails_legacy.rb
56
+ - lib/senthor_rails_legacy/middleware.rb
57
+ - lib/senthor_rails_legacy/version.rb
58
+ - senthor_rails_legacy.gemspec
59
+ homepage: https://www.senthor.io
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ homepage_uri: https://www.senthor.io
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.6.9
79
+ specification_version: 4
80
+ summary: Senthor middleware for Ruby on Rails applications
81
+ test_files: []