huginn_signalspam_agent 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: e5a315c48d41eb7af60378b335aca6e6f6f32239932e389b887e1a0d332362e7
4
+ data.tar.gz: e799126566da333e38f5bc4e367ceb4707fb9a2e6f232ef921f6d0747c0184f3
5
+ SHA512:
6
+ metadata.gz: 9db56407490bb2078b7d29b6e8cb0abfc641e1de9a8237745bbed32b5935ee1bbb67d3efd27fa3d4fdc663bce765720578b6d0b16c6c66f04a1a11c7e43555e9
7
+ data.tar.gz: ccead12a9b098e656add74cc2661f80f155ddd5de660ae3da85f9d4e07dd431191a18c8f8c85ddc8a41710cdb4ae4905676cf069ee9eff170d57409e498432f4
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2024 Nicolas Germain
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,129 @@
1
+ module Agents
2
+ class SignalspamAgent < Agent
3
+ include FormConfigurable
4
+ can_dry_run!
5
+ no_bulk_receive!
6
+ default_schedule 'never'
7
+
8
+ description do
9
+ <<-MD
10
+ The Signalspam Agent reports spam to signal-spam.fr.
11
+
12
+ `debug` is used for verbose mode.
13
+
14
+ `username` is mandatory for authentication.
15
+
16
+ `password` is mandatory for authentication.
17
+
18
+ `raw_email` is the content of the email in raw.
19
+
20
+ `expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
21
+ that you anticipate passing without this Agent receiving an incoming Event.
22
+ MD
23
+ end
24
+
25
+ event_description <<-MD
26
+ Events look like this:
27
+
28
+ {
29
+ "report_status": "202"
30
+ }
31
+ MD
32
+
33
+ def default_options
34
+ {
35
+ 'username' => '',
36
+ 'password' => '',
37
+ 'raw_email' => '',
38
+ 'debug' => 'false',
39
+ 'expected_receive_period_in_days' => '2',
40
+ }
41
+ end
42
+
43
+ form_configurable :username, type: :string
44
+ form_configurable :password, type: :string
45
+ form_configurable :raw_email, type: :string
46
+ form_configurable :debug, type: :boolean
47
+ form_configurable :expected_receive_period_in_days, type: :string
48
+ def validate_options
49
+ unless options['username'].present?
50
+ errors.add(:base, "username is a required field")
51
+ end
52
+
53
+ unless options['password'].present?
54
+ errors.add(:base, "password is a required field")
55
+ end
56
+
57
+ unless options['raw_email'].present?
58
+ errors.add(:base, "raw_email is a required field")
59
+ end
60
+
61
+ if options.has_key?('debug') && boolify(options['debug']).nil?
62
+ errors.add(:base, "if provided, debug must be true or false")
63
+ end
64
+
65
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
66
+ errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
67
+ end
68
+ end
69
+
70
+ def working?
71
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
72
+ end
73
+
74
+ def receive(incoming_events)
75
+ incoming_events.each do |event|
76
+ interpolate_with(event) do
77
+ log event
78
+ report
79
+ end
80
+ end
81
+ end
82
+
83
+ def check
84
+ report
85
+ end
86
+
87
+ private
88
+
89
+ def set_credential(name, value)
90
+ c = user.user_credentials.find_or_initialize_by(credential_name: name)
91
+ c.credential_value = value
92
+ c.save!
93
+ end
94
+
95
+ def log_curl_output(code,body)
96
+
97
+ log "request status : #{code}"
98
+
99
+ if interpolated['debug'] == 'true'
100
+ log "request status : #{code}"
101
+ log "body"
102
+ log body
103
+ end
104
+
105
+ end
106
+
107
+ def report()
108
+
109
+ url = URI.parse('https://www.signal-spam.fr/api/signaler')
110
+ headers = {
111
+ 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/52.4.0'
112
+ }
113
+
114
+ http = Net::HTTP.new(url.host, url.port)
115
+ http.use_ssl = (url.scheme == 'https')
116
+
117
+ request = Net::HTTP::Post.new(url.path, headers)
118
+ request.basic_auth(interpolated['username'], interpolated['password'])
119
+ request.set_form_data('message' => Base64.strict_encode64(interpolated['raw_email']))
120
+
121
+ response = http.request(request)
122
+
123
+ log_curl_output(response.code,response.body)
124
+
125
+ create_event :payload => { 'report_status' => response.code}
126
+
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_signalspam_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_signalspam_agent/signalspam_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::SignalspamAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::SignalspamAgent.new.default_options
7
+ @checker = Agents::SignalspamAgent.new(:name => "SignalspamAgent", :options => @valid_options)
8
+ @checker.user = users(:bob)
9
+ @checker.save!
10
+ end
11
+
12
+ pending "add specs here"
13
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huginn_signalspam_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Germain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-08 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: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: huginn_agent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Write a longer description or delete this line.
56
+ email:
57
+ - ngermain@hihouhou.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - lib/huginn_signalspam_agent.rb
64
+ - lib/huginn_signalspam_agent/signalspam_agent.rb
65
+ - spec/signalspam_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_signalspam_agent
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Write a short summary, because Rubygems requires one.
89
+ test_files:
90
+ - spec/signalspam_agent_spec.rb