ronin-support-web 0.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +4 -0
- data/.github/workflows/ruby.yml +47 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.rubocop.yml +19 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +165 -0
- data/ChangeLog.md +10 -0
- data/Gemfile +36 -0
- data/README.md +321 -0
- data/Rakefile +31 -0
- data/gemspec.yml +31 -0
- data/lib/ronin/support/web/agent/mixin.rb +361 -0
- data/lib/ronin/support/web/agent.rb +1386 -0
- data/lib/ronin/support/web/html/mixin.rb +115 -0
- data/lib/ronin/support/web/html.rb +116 -0
- data/lib/ronin/support/web/mixin.rb +40 -0
- data/lib/ronin/support/web/version.rb +28 -0
- data/lib/ronin/support/web/websocket/client.rb +129 -0
- data/lib/ronin/support/web/websocket/mixin.rb +888 -0
- data/lib/ronin/support/web/websocket/server.rb +212 -0
- data/lib/ronin/support/web/websocket/socket.rb +185 -0
- data/lib/ronin/support/web/websocket/url_methods.rb +91 -0
- data/lib/ronin/support/web/websocket.rb +360 -0
- data/lib/ronin/support/web/xml/mixin.rb +111 -0
- data/lib/ronin/support/web/xml.rb +110 -0
- data/lib/ronin/support/web.rb +43 -0
- data/ronin-support-web.gemspec +62 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '089304b3ff4267deef83cef4b882ad044686866a89602a2be076db9b15fdf95f'
|
4
|
+
data.tar.gz: af737ed89f5b6ccce135822eac932f0fd508a1b1dc3fff10952b72922c996015
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 994d4405bf67505c514359632c1e1f2c158df16251e52baef280b3cfab84bad861e05625da02fb4e8d321c8e6f1eccc5430986ae06423194d7c5cec1c13b32a5
|
7
|
+
data.tar.gz: 9b25a6265a567da63eb784ac0f4a7b0f128b93f679afbffc13d24ab85a5391875a3732d30b9c91bf336327450e49aef4bf5733705bebf609cd13886e70f6d565
|
data/.document
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [ push, pull_request ]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
tests:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby:
|
12
|
+
- '3.0'
|
13
|
+
- '3.1'
|
14
|
+
- '3.2'
|
15
|
+
- '3.3'
|
16
|
+
- jruby
|
17
|
+
# - truffleruby
|
18
|
+
name: Ruby ${{ matrix.ruby }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v4
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true
|
26
|
+
# - name: Install dependencies
|
27
|
+
# run: |
|
28
|
+
# sudo apt update -y && \
|
29
|
+
# sudo apt install -y --no-install-recommends --no-install-suggests FIXME
|
30
|
+
- name: Install dependencies
|
31
|
+
run: bundle install --jobs 4 --retry 3
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake test
|
34
|
+
|
35
|
+
# rubocop linting
|
36
|
+
rubocop:
|
37
|
+
runs-on: ubuntu-latest
|
38
|
+
steps:
|
39
|
+
- uses: actions/checkout@v4
|
40
|
+
- name: Set up Ruby
|
41
|
+
uses: ruby/setup-ruby@v1
|
42
|
+
with:
|
43
|
+
ruby-version: 3.0
|
44
|
+
- name: Install dependencies
|
45
|
+
run: bundle install --jobs 4 --retry 3
|
46
|
+
- name: Run rubocop
|
47
|
+
run: bundle exec rubocop --parallel
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
SuggestExtensions: false
|
4
|
+
TargetRubyVersion: 3.1
|
5
|
+
|
6
|
+
inherit_gem:
|
7
|
+
rubocop-ronin: rubocop.yml
|
8
|
+
|
9
|
+
#
|
10
|
+
# ronin-support-web specific exceptions
|
11
|
+
#
|
12
|
+
|
13
|
+
# Need explicit whitespace for the JRuby's specific HTML heredocs.
|
14
|
+
Layout/TrailingWhitespace:
|
15
|
+
Exclude:
|
16
|
+
- spec/agent/mixin_spec.rb
|
17
|
+
- spec/agent_spec.rb
|
18
|
+
- spec/html/mixin_spec.rb
|
19
|
+
- spec/html_spec.rb
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.1
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title 'Ronin::Support::Web Documentation' --protected
|
data/COPYING.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
### 0.1.0 / 2024-XX-XX
|
2
|
+
|
3
|
+
* Initial release:
|
4
|
+
* Provides helper methods for parsing HTML/XML.
|
5
|
+
* Also provides additional extensions to [Nokogiri][nokogiri] using
|
6
|
+
[nokogiri-ext].
|
7
|
+
* Provides helper methods for working with WebSockets.
|
8
|
+
|
9
|
+
[nokogiri]: https://nokogiri.org/
|
10
|
+
[nokogiri-ext]: https://github.com/postmodern/nokogiri-ext#readme
|
data/Gemfile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
platform :jruby do
|
8
|
+
gem 'jruby-openssl', '~> 0.7'
|
9
|
+
end
|
10
|
+
|
11
|
+
# gem 'nokogiri-ext', '~> 0.1', github: 'postmodern/nokogiri-ext',
|
12
|
+
# branch: 'main'
|
13
|
+
|
14
|
+
# Ronin dependencies
|
15
|
+
# gem 'ronin-support', '~> 1.1', github: 'ronin-rb/ronin-support',
|
16
|
+
# branch: 'main'
|
17
|
+
|
18
|
+
group :development do
|
19
|
+
gem 'rake'
|
20
|
+
gem 'rubygems-tasks', '~> 0.2'
|
21
|
+
|
22
|
+
gem 'rspec', '~> 3.0'
|
23
|
+
gem 'webmock', '~> 3.0'
|
24
|
+
gem 'simplecov', '~> 0.20'
|
25
|
+
|
26
|
+
gem 'kramdown', '~> 2.0'
|
27
|
+
gem 'redcarpet', platform: :mri
|
28
|
+
gem 'yard', '~> 0.9'
|
29
|
+
gem 'yard-spellcheck', require: false
|
30
|
+
|
31
|
+
gem 'dead_end', require: false
|
32
|
+
gem 'sord', require: false, platform: :mri
|
33
|
+
gem 'stackprof', require: false, platform: :mri
|
34
|
+
gem 'rubocop', require: false, platform: :mri
|
35
|
+
gem 'rubocop-ronin', require: false, platform: :mri
|
36
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,321 @@
|
|
1
|
+
# ronin-support-web
|
2
|
+
|
3
|
+
[![CI](https://github.com/ronin-rb/ronin-support-web/actions/workflows/ruby.yml/badge.svg)](https://github.com/ronin-rb/ronin-support-web/actions/workflows/ruby.yml)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/ronin-rb/ronin-support-web.svg)](https://codeclimate.com/github/ronin-rb/ronin-support-web)
|
5
|
+
|
6
|
+
* [Website](https://ronin-rb.dev/)
|
7
|
+
* [Source](https://github.com/ronin-rb/ronin-support-web)
|
8
|
+
* [Issues](https://github.com/ronin-rb/ronin-support-web/issues)
|
9
|
+
* [Documentation](https://ronin-rb.dev/docs/ronin-support-web)
|
10
|
+
* [Discord](https://discord.gg/6WAb3PsVX9) |
|
11
|
+
[Mastodon](https://infosec.exchange/@ronin_rb)
|
12
|
+
|
13
|
+
## Description
|
14
|
+
|
15
|
+
ronin-support-web is a web support library for ronin-rb. ronin-support-web
|
16
|
+
provides many helper methods for parsing HTML/XML, fetching web pages, etc.
|
17
|
+
|
18
|
+
## Features
|
19
|
+
|
20
|
+
* Provides helper methods for parsing HTML/XML.
|
21
|
+
* Also provides additional extensions to [Nokogiri][nokogiri] using
|
22
|
+
[nokogiri-ext].
|
23
|
+
* Provides helper methods for working with WebSockets.
|
24
|
+
|
25
|
+
## Examples
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'ronin/support/web'
|
29
|
+
include Ronin::Support::Web
|
30
|
+
|
31
|
+
html_parse "<html>...</html>"
|
32
|
+
# => #<Nokogiri::HTML::Document:...>
|
33
|
+
```
|
34
|
+
|
35
|
+
### HTML
|
36
|
+
|
37
|
+
Parse an HTML string:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
doc = html_parse("<html>\n <body>\n <p>Hello world</p>\n </body>\n</html>\n")
|
41
|
+
# =>
|
42
|
+
# #(Document:0x6ab8 {
|
43
|
+
# name = "document",
|
44
|
+
# children = [
|
45
|
+
# #(DTD:0x6be4 { name = "html" }),
|
46
|
+
# #(Element:0x6cd4 {
|
47
|
+
# name = "html",
|
48
|
+
# children = [
|
49
|
+
# #(Text "\n "),
|
50
|
+
# #(Element:0x6e64 {
|
51
|
+
# name = "body",
|
52
|
+
# children = [
|
53
|
+
# #(Text "\n "),
|
54
|
+
# #(Element:0x6ff4 { name = "p", children = [ #(Text "Hello world")] }),
|
55
|
+
# #(Text "\n ")]
|
56
|
+
# }),
|
57
|
+
# #(Text "\n")]
|
58
|
+
# })]
|
59
|
+
# })
|
60
|
+
```
|
61
|
+
|
62
|
+
Parse a HTML file:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
doc = html_open("index.html")
|
66
|
+
# => #<Nokogiri::HTML::Document:...>
|
67
|
+
```
|
68
|
+
|
69
|
+
Searching an HTML document using [XPath] or CSS-path:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
nodes = doc.search('//div/p')
|
73
|
+
nodes = doc.search('div p.class')
|
74
|
+
# => [#<Nokogiri::HTML::Element:...>, ...]
|
75
|
+
|
76
|
+
node = doc.at('#id')
|
77
|
+
# => #<Nokogiri::HTML::Element:...>
|
78
|
+
```
|
79
|
+
|
80
|
+
Build a HTML document:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
doc = html_build do
|
84
|
+
html {
|
85
|
+
head {
|
86
|
+
script(type: 'text/javascript', src: 'redirect.js')
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
puts doc.to_html
|
92
|
+
# <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
93
|
+
# <html><head><script src="redirect.js" type="text/javascript"></script></head></html>
|
94
|
+
```
|
95
|
+
|
96
|
+
### XML
|
97
|
+
|
98
|
+
Parse an XML response body:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
xml_parse("<?xml version=\"1.0\"?>\n<users>\n <user>\n <name>admin</name>\n <password>0mni</password>\n <user>\n</users>\n")
|
102
|
+
# =>
|
103
|
+
# #(Document:0xdebc {
|
104
|
+
# name = "document",
|
105
|
+
# children = [
|
106
|
+
# #(Element:0xdfe8 {
|
107
|
+
# name = "users",
|
108
|
+
# children = [
|
109
|
+
# #(Text "\n "),
|
110
|
+
# #(Element:0xe178 {
|
111
|
+
# name = "user",
|
112
|
+
# children = [
|
113
|
+
# #(Text "\n "),
|
114
|
+
# #(Element:0xe308 { name = "name", children = [ #(Text "admin")] }),
|
115
|
+
# #(Text "\n "),
|
116
|
+
# #(Element:0xe538 { name = "password", children = [ #(Text "0mni")] }),
|
117
|
+
# #(Text "\n "),
|
118
|
+
# #(Element:0xe768 { name = "user", children = [ #(Text "\n")] }),
|
119
|
+
# #(Text "\n")]
|
120
|
+
# })]
|
121
|
+
# })]
|
122
|
+
# })
|
123
|
+
```
|
124
|
+
|
125
|
+
Parse a XML file:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
doc = html_open("data.xml")
|
129
|
+
# => #<Nokogiri:XML:::Document:...>
|
130
|
+
```
|
131
|
+
|
132
|
+
Searching an XML document using [XPath]:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
users = doc.search('//user')
|
136
|
+
# => [#<Nokogiri::XML::Element:...>, ...]
|
137
|
+
|
138
|
+
admin = doc.at('//user[@name="admin"]')
|
139
|
+
# => #<Nokogiri::XML::Element:...>
|
140
|
+
```
|
141
|
+
|
142
|
+
Build a XML document:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
doc = xml_build do
|
146
|
+
playlist {
|
147
|
+
mp3 {
|
148
|
+
file { text('02 THE WAIT.mp3') }
|
149
|
+
artist { text('Evil Nine') }
|
150
|
+
track { text('The Wait feat David Autokratz') }
|
151
|
+
duration { text('1000000000') }
|
152
|
+
}
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
puts doc.to_xml
|
157
|
+
# <?xml version="1.0"?>
|
158
|
+
# <playlist>
|
159
|
+
# <mp3>
|
160
|
+
# <file>02 THE WAIT.mp3</file>
|
161
|
+
# <artist>Evil Nine</artist>
|
162
|
+
# <track>The Wait feat David Autokratz</track>
|
163
|
+
# <duration>1000000000</duration>
|
164
|
+
# </mp3>
|
165
|
+
# </playlist>
|
166
|
+
```
|
167
|
+
|
168
|
+
### Web Requests
|
169
|
+
|
170
|
+
Gets a URL and follows any redirects:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
get 'https://example.com/'
|
174
|
+
# => #<Net::HTTPResponse:...>
|
175
|
+
```
|
176
|
+
|
177
|
+
Gets a URL and parses the HTML response:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
get_html 'https://example.com/'
|
181
|
+
# => #<Nokogiri::HTML::Document:...>
|
182
|
+
```
|
183
|
+
|
184
|
+
Gets a URL and parses the XML response:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
get_xml 'https://example.com/sitemap.xml'
|
188
|
+
# => #<Nokogiri::XML::Document:...>
|
189
|
+
```
|
190
|
+
|
191
|
+
Gets a URL and parses the JSON response:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
get_json 'https://example.com/api/endpoint.json'
|
195
|
+
# => {...}
|
196
|
+
```
|
197
|
+
|
198
|
+
POSTs to a URL and follows any redirects:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
post 'https://example.com/form', form_data: {'foo' => 'bar'}
|
202
|
+
# => #<Net::HTTPResponse:...>
|
203
|
+
```
|
204
|
+
|
205
|
+
POSTs to a URL and parses the HTML response:
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
post_html 'https://example.com/form', form_data: {'foo' => 'bar'}
|
209
|
+
# => #<Nokogiri::HTML::Document:...>
|
210
|
+
```
|
211
|
+
|
212
|
+
POSTs to a URL and parses the XML response:
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
post_xml 'https://example.com/form', form_data: {'foo' => 'bar'}
|
216
|
+
# => #<Nokogiri::XML::Document:...>
|
217
|
+
```
|
218
|
+
|
219
|
+
POSTs to a URL and parses the JSON response:
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
post_json 'https://example.com/api/endpoint.json', json: {foo: 'bar'}
|
223
|
+
# => {...}
|
224
|
+
```
|
225
|
+
|
226
|
+
### WebSockets
|
227
|
+
|
228
|
+
Connecting to a WebSocket:
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
websocket = websocket_connect('ws://websocket-echo.com')
|
232
|
+
|
233
|
+
websocket.send_frame("foo bar")
|
234
|
+
# => 13
|
235
|
+
websocket.recv_frame
|
236
|
+
# => <WebSocket::Frame::Incoming::Client:0x000227a4 @decoded=true, @code=nil, @data="foo bar", @version=13, @handler=#<WebSocket::Frame::Handler::Handler07:0x00007f7d4c9b0ed0 @frame=<WebSocket::Frame::Incoming::Client:0x000227a4 @decoded=true, @code=nil, @data="foo bar", @version=13, @handler=#<WebSocket::Frame::Handler::Handler07:0x00007f7d4c9b0ed0 ...>, @type=:text>, @application_data_buffer=nil>, @type=:text>
|
237
|
+
websocket.send_frame("hello world")
|
238
|
+
# => 17
|
239
|
+
websocket.recv
|
240
|
+
# => "hello world"
|
241
|
+
```
|
242
|
+
|
243
|
+
Starting a WebSocket server and receiving connections:
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
server = websocket_server('ws://localhost:1337/')
|
247
|
+
client = server.accept
|
248
|
+
client.send("hello")
|
249
|
+
client.recv
|
250
|
+
# => "good, how are you"
|
251
|
+
```
|
252
|
+
```ruby
|
253
|
+
client = websocket_client('ws://localhost:1337/')
|
254
|
+
client.recv
|
255
|
+
# => "hello"
|
256
|
+
client.send("good, how are you")
|
257
|
+
```
|
258
|
+
|
259
|
+
## Requirements
|
260
|
+
|
261
|
+
* [Ruby] >= 3.0.0
|
262
|
+
* [ronin-support] ~> 1.1
|
263
|
+
* [nokogiri] ~> 1.4
|
264
|
+
* [nokogiri-ext] ~> 0.1
|
265
|
+
* [websocket] ~> 1.2
|
266
|
+
|
267
|
+
## Install
|
268
|
+
|
269
|
+
```shell
|
270
|
+
$ gem install ronin-support-web
|
271
|
+
```
|
272
|
+
|
273
|
+
### Gemfile
|
274
|
+
|
275
|
+
```ruby
|
276
|
+
gem 'ronin-support-web', '~> 0.1'
|
277
|
+
```
|
278
|
+
|
279
|
+
### gemspec
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
gem.add_dependency 'ronin-support-web', '~> 0.1'
|
283
|
+
```
|
284
|
+
|
285
|
+
## Development
|
286
|
+
|
287
|
+
1. [Fork It!](https://github.com/ronin-rb/ronin-support-web/fork)
|
288
|
+
2. Clone It!
|
289
|
+
3. `cd ronin-support-web/`
|
290
|
+
4. `bundle install`
|
291
|
+
5. `git checkout -b my_feature`
|
292
|
+
6. Code It!
|
293
|
+
7. `bundle exec rake spec`
|
294
|
+
8. `git push origin my_feature`
|
295
|
+
|
296
|
+
## License
|
297
|
+
|
298
|
+
ronin-support-web - A web support library for ronin-rb.
|
299
|
+
|
300
|
+
Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
|
301
|
+
|
302
|
+
ronin-support-web is free software: you can redistribute it and/or modify
|
303
|
+
it under the terms of the GNU Lesser General Public License as published
|
304
|
+
by the Free Software Foundation, either version 3 of the License, or
|
305
|
+
(at your option) any later version.
|
306
|
+
|
307
|
+
ronin-support-web is distributed in the hope that it will be useful,
|
308
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
309
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
310
|
+
GNU Lesser General Public License for more details.
|
311
|
+
|
312
|
+
You should have received a copy of the GNU Lesser General Public License
|
313
|
+
along with ronin-support-web. If not, see <https://www.gnu.org/licenses/>.
|
314
|
+
|
315
|
+
[Ruby]: https://www.ruby-lang.org
|
316
|
+
[nokogiri]: https://nokogiri.org/
|
317
|
+
[nokogiri-ext]: https://github.com/postmodern/nokogiri-ext#readme
|
318
|
+
[ronin-support]: https://github.com/ronin-rb/ronin-support#readme
|
319
|
+
[websocket]: https://github.com/imanel/websocket-ruby#readme
|
320
|
+
|
321
|
+
[XPath]: https://developer.mozilla.org/en-US/docs/Web/XPath
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError => e
|
6
|
+
warn e.message
|
7
|
+
warn "Run `gem install bundler` to install Bundler"
|
8
|
+
exit(-1)
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:development)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
warn e.message
|
15
|
+
warn "Run `bundle install` to install missing gems"
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake'
|
20
|
+
|
21
|
+
require 'rubygems/tasks'
|
22
|
+
Gem::Tasks.new(sign: {checksum: true, pgp: true})
|
23
|
+
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
RSpec::Core::RakeTask.new
|
26
|
+
task :test => :spec
|
27
|
+
task :default => :spec
|
28
|
+
|
29
|
+
require 'yard'
|
30
|
+
YARD::Rake::YardocTask.new
|
31
|
+
task :docs => :yard
|