slackwebhook 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +50 -0
  3. data/lib/slackwebhook.rb +72 -0
  4. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae018f8c2f486d95da72ee35d58b91bcb1a54806
4
+ data.tar.gz: f36a0937207a1f2d74deeb3d62bc2b7b1f0ea794
5
+ SHA512:
6
+ metadata.gz: dfb7d16a2f439671f772db60dda015d80ebfc341c63fb67323113642c92fa5ddd32eb64a1882bb1a6fc31fc5b88f9bdbd8837c0dc614b0feb77855247b1fb887
7
+ data.tar.gz: 74aaff2cbe97025c5b0d60133017d04d6d45a39f6301fb299c41c7af22c030835bf3734771ccac497e3246f1ef616c11f37b49a732ab1800a63333a06a177380
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Wireless Access Point Scanner <a href="https://badge.fury.io/rb/waps"><img src="https://badge.fury.io/rb/waps.svg" alt="Gem Version" height="18"></a>
2
+
3
+ WAPS uses iwlist to scan for wireless access points and convert the output into ruby hash format. Following is the usage of the gem.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install waps
9
+ ```
10
+ Require
11
+
12
+ ```
13
+ require 'waps'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ * First Require the gem: ``` require 'waps' ```
19
+ * Creating new instance require interface name. Leave it empty if not sure. ``` new_scan = Waps.new('Interface_name')```
20
+ * Start Scan. ```results = new_scan.scan```
21
+ * Get specific field. ``` mac_address = new_scan.get('address') ```
22
+
23
+ ```
24
+ require 'waps'
25
+
26
+ new_scan = Waps.new('')
27
+ new_scan.scan
28
+ new_scan.output
29
+ mac_addresses = new_scan.get('address')
30
+ ```
31
+
32
+ ## Response Field
33
+
34
+ * Address
35
+ * SSID
36
+ * Signal Level
37
+ * Encryption
38
+ * Channel
39
+ * Frequency
40
+ * Quality
41
+
42
+ ## Authors
43
+
44
+ * **Gurjant Singh** - *Initial work* - [gurjant31](https://github.com/gurjant31)
45
+
46
+ See also the list of [contributors](https://github.com/gurjant31/waps/contributors) who participated in this project.
47
+
48
+ ## License
49
+
50
+ This project is licensed under the MIT License - see the LICENSE.md file for details
@@ -0,0 +1,72 @@
1
+ # Requires
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ class Slackwebhook
8
+
9
+ attr_accessor :webhook,:headers,:type
10
+ attr_reader :output
11
+
12
+
13
+ def initialize(webhook)
14
+ #Output Variable to see th output of the scan
15
+ @output = ""
16
+ #Check the url and assign it
17
+ @webhook = check_url(webhook)
18
+ #Headers to set for the slack post request
19
+ @headers = {'Content-Type': 'text/json'}
20
+ #Type of request to send to the hook
21
+ @type = "normal"
22
+
23
+ end
24
+
25
+ def send=(data)
26
+ #Set the https request
27
+ https = Net::HTTP.new(@webhook.host, @webhook.port)
28
+ https.use_ssl = true
29
+ #Set the hearders and path for the request
30
+ request = Net::HTTP::Post.new(@webhook.request_uri, @header)
31
+ #set the output message
32
+ request.body = data_format(data).to_json
33
+ #send the request and assing the response to output variable
34
+ @output = https.request(request)
35
+ puts @output.code
36
+ end
37
+
38
+
39
+ def data_format(data)
40
+ #format the message depend upon the type field
41
+ @body = {}
42
+ case @type.downcase
43
+ when 'info'
44
+ @body[:attachments] = [{color: "#0FF612",text: data}]
45
+ when 'warning'
46
+ @body[:attachments] = [{color: "#F2F60F",text: data}]
47
+ when 'alert'
48
+ @body[:attachments] = [{color: "#e33d3b",text: data}]
49
+ else
50
+ @body[:text] = data
51
+ end
52
+ puts @body
53
+ @body
54
+
55
+ end
56
+
57
+ def check_url(webhook)
58
+ #Parse url
59
+ uri = URI.parse(webhook)
60
+ # If parsing of url and host of the url matches the hooks.slack.com then return url
61
+ (webhook =~ URI::regexp && uri.host == "hooks.slack.com") ? uri : error("Invalid URL")
62
+ end
63
+
64
+ def error(text)
65
+ #Display the error
66
+ puts "[-] #{text}. Check the url documentation: https://api.slack.com/incoming-webhooks"
67
+ #assing to output variable
68
+ @output = text
69
+ end
70
+
71
+ end
72
+
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slackwebhook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gurjant Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
27
+ description: Gem send messages to slack web hooks depend upon the type of the message.
28
+ email:
29
+ - info@defensestation.ca
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - README.md
34
+ files:
35
+ - README.md
36
+ - lib/slackwebhook.rb
37
+ homepage: https://github.com/gurjant31/slackwebhook
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.5.2.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Gem to send slack web hook messages.
61
+ test_files: []