hastebin 0.2.0 → 0.2.8

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 +4 -4
  2. data/bin/hastebin +60 -8
  3. data/lib/hastebin.rb +98 -13
  4. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce87c32125e84ea211fff094c00d909395bcf84c716523fc525b52a87f10ebf0
4
- data.tar.gz: f028e5ddef098f9caa9436101a070dd8583e08d75f084cd0c52a171ab996eccc
3
+ metadata.gz: 9f2403d89dedc5fffd474a7a1c969803d72dceb1232036eab5a7f6dc5ca11d5a
4
+ data.tar.gz: 026d6f84a282a6056d8afd06df08ea034234e0c738b4467dbd9ff5d506eced58
5
5
  SHA512:
6
- metadata.gz: 1dd2c401feb07a17829dc686be6572e4d9d5dfa5757dd64fdbd4fc4d48adb1419103a9ae48bf77c74ecdaecd025181de849af08dab238210c1127adf8bb70af1
7
- data.tar.gz: 2bc8d52d34752a845fb5f23c1559858da54a17430189abd9598f6386ec5d85eb657cb6d7123081071c9ac32457d29a0573c35bb57a8729a01ddf0d02271b667d
6
+ metadata.gz: 337543e93bd37aaf65400c08b3ce488853d05f50603a9da5c441c2f04d98c0a4f9e18dc02c6d3b378fc1099bd7c8ec268509292a0866b0beed74d2ac576e5194
7
+ data.tar.gz: 1251e9f4790841aa5beff2bd9b1e72b6a1a4b71d3ca716052d4fc6790c279f00df04e696e39d2ee767a33ac2ddf54cd41f931a73f76b31906617b02fb93f3ec2
@@ -3,36 +3,88 @@ require 'optparse'
3
3
  require "uri"
4
4
  require "net/http"
5
5
  require "hastebin"
6
+ require "colorize"
6
7
 
7
8
  opts = OptionParser.new do |opts|
8
9
  opts.banner = "\n«««««««««««««««««»»»»»»»»»»»»»»»»»»»"
9
10
  opts.separator "««««««««««« Hastebin CLI »»»»»»»»»»»"
10
11
  opts.separator "«««««««««««««««««»»»»»»»»»»»»»»»»»»»"
11
12
  opts.separator ""
12
- opts.separator 'Usage: hastebin -c "scritp" -> write'
13
- opts.separator 'Usage: hastebin -r "/path/to/file" -> read file'
13
+ opts.separator 'Usage: hastebin --write "script" -> write'
14
+ opts.separator 'Usage: hastebin --up "/path/to/file" -> upload file'
15
+ opts.separator 'Usage: hastebin --download "key or key.rb" -> download via hasteb.in'
16
+ opts.separator 'Usage: hastebin --run "key or key.rb" -> run ruby via hasteb.in'
17
+ opts.separator 'Usage: hastebin --read "key or key.rb" -> Read files via hasteb.in'
14
18
  opts.separator ""
15
19
  opts.separator "Examples:"
16
- opts.separator ' hastebin -c "puts("hello")"'
17
- opts.separator ' hastebin -r "./text.txt"'
20
+ opts.separator ' hastebin --write "puts("hello")"'
21
+ opts.separator ' hastebin --up "./text.txt"'
22
+ opts.separator ' hastebin --download "oquluqic"'
23
+ opts.separator ' hastebin --run "oquluqic"'
24
+ opts.separator ' hastebin --download "oquluqic"'
18
25
  opts.separator ""
19
26
  opts.separator "Options:"
20
27
 
21
- opts.on("-c script") do |a|
28
+ opts.on("--write script") do |a|
22
29
 
23
- puts "View in: https://hasteb.in/#{Hastebin.code(a)}"
30
+ puts "View in: https://hasteb.in/#{Hastebin.write(a)}"
24
31
 
25
32
  exit
26
33
  end
27
34
 
28
- opts.on("-r file") do |a|
35
+ opts.on("--up file") do |a|
29
36
  file = File.open(a)
30
37
  data = []
31
38
  file.each do |line|
32
39
  data.push(line)
33
40
  $text = data.join("")
34
41
  end
35
- puts "View in: https://hasteb.in/#{Hastebin.code($text)}"
42
+ puts "View in: https://hasteb.in/#{Hastebin.write($text)}"
43
+
44
+ exit
45
+ end
46
+
47
+ opts.on("--download key") do |key|
48
+ https = Net::HTTP.new('hasteb.in', 443)
49
+
50
+ https.use_ssl = true
51
+
52
+ res = https.get("/raw/#{key}")
53
+
54
+ File.open("#{key}", 'w') do |line|
55
+ line.puts(res.body)
56
+ end
57
+
58
+ exit
59
+ end
60
+
61
+ opts.on("--run key") do |key|
62
+
63
+ https = Net::HTTP.new('hasteb.in', 443)
64
+ https.use_ssl = true
65
+
66
+ res = https.get("/raw/#{key}")
67
+
68
+ File.open("#{key}.rb", 'w') do |line|
69
+ line.puts(res.body)
70
+ end
71
+
72
+ require("./#{key}")
73
+
74
+ require("./#{key}")
75
+ File.delete("./#{key}.rb")
76
+
77
+ exit
78
+ end
79
+
80
+ opts.on("--read key") do |key|
81
+ https = Net::HTTP.new('hasteb.in', 443)
82
+
83
+ https.use_ssl = true
84
+
85
+ res = https.get("/raw/#{key}")
86
+
87
+ puts res.body
36
88
 
37
89
  exit
38
90
  end
@@ -1,30 +1,115 @@
1
1
  require "uri"
2
2
  require "net/http"
3
3
  require "json"
4
+ require "colorize"
4
5
 
5
6
  module Hastebin
6
7
 
8
+ $base_url = "https://hasteb.in/"
9
+ $domain = $base_url.gsub("https://","").gsub('/','')
7
10
 
8
- def self.code(code)
9
- url = URI("https://hasteb.in/documents")
10
11
 
11
- https = Net::HTTP.new(url.host, url.port);
12
- https.use_ssl = true
12
+ def self.write(code)
13
+ url = URI($base_url + "documents")
13
14
 
14
- request = Net::HTTP::Post.new(url)
15
- request["Connection"] = "keep-alive"
16
- request["Accept"] = "application/json, text/javascript, */*; q=0.01"
17
- request["X-Requested-With"] = "XMLHttpRequest"
18
- request["Content-Type"] = "application/json; charset=UTF-8"
19
- request["Origin"] = "https://hasteb.in"
20
- request["Referer"] = "https://hasteb.in/"
21
- request["Accept-Language"] = "pt-BR,pt;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5"
22
- request.body = code
15
+ https = Net::HTTP.new(url.host, url.port);
16
+ https.use_ssl = true
23
17
 
18
+ request = Net::HTTP::Post.new(url)
19
+ request.body = code
20
+ puts "[INFO] ".red + "Sent with success".green
24
21
  $res = https.request(request)
25
22
 
26
23
  return JSON.parse($res.read_body)['key']
27
24
  end
28
25
 
29
26
 
27
+ def self.sendFile(path)
28
+
29
+ file = File.open(path)
30
+ data = []
31
+ file.each do |line|
32
+ data.push(line)
33
+ $text = data.join("")
34
+ end
35
+ return write($text)
36
+ end
37
+
38
+ def self.readRaw(key)
39
+
40
+ https = Net::HTTP.new($domain, 443)
41
+
42
+ https.use_ssl = true
43
+
44
+ res = https.get("/raw/#{key}")
45
+
46
+ if res.code.to_i == 404
47
+ puts "[INFO] ".red+"#{JSON.parse(res.body)['message']}".red
48
+ else
49
+ puts "[INFO] ".red+"Received with success".green
50
+ return res.body
51
+ end
52
+
53
+ end
54
+
55
+ def self.run(key)
56
+
57
+ https = Net::HTTP.new($domain, 443)
58
+
59
+ https.use_ssl = true
60
+
61
+ res = https.get("/raw/#{key}")
62
+
63
+ File.open("#{key}.rb", 'w') do |line|
64
+ line.puts(res.body)
65
+ end
66
+
67
+ require("./#{key}")
68
+
69
+ require("./#{key}")
70
+ File.delete("./#{key}.rb")
71
+ end
72
+
73
+ def self.download(key)
74
+
75
+ https = Net::HTTP.new($domain, 443)
76
+
77
+ https.use_ssl = true
78
+
79
+ res = https.get("/raw/#{key}")
80
+
81
+ File.open("#{key}", 'w') do |line|
82
+ line.puts(res.body)
83
+ end
84
+
85
+ end
86
+ def self.base_url=(url)
87
+ $base_url = url
88
+ $domain = $base_url.gsub("https://","").gsub('/','')
89
+ puts "[INFO] ".red+"URL switched to: ".green + url + " and domain switched to: ".green + $domain
90
+ return url
91
+ end
92
+
93
+ def self.base_url
94
+ return $base_url
95
+ end
96
+
97
+ def self.domain
98
+ return $domain
99
+ end
100
+
101
+ def self.ping
102
+ t = Time.now()
103
+ uri = URI($base_url)
104
+ res = Net::HTTP.get(uri)
105
+ t = (Time.now().to_f - t.to_f) * 1000
106
+ return t.to_i
107
+ end
108
+
109
+ # Warns
110
+
111
+ def self.code(code)
112
+ return "[INFO] ".red+"Please use " + "write".green + " instead of " + "code".red
113
+ end
114
+
30
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hastebin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Astin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-17 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: ''
28
42
  email:
29
43
  - ''
@@ -61,5 +75,5 @@ requirements: []
61
75
  rubygems_version: 3.1.2
62
76
  signing_key:
63
77
  specification_version: 4
64
- summary: CLI tool that uploads text to hasteb.in .
78
+ summary: CLI tool that works with hasteb.in and hastebin.com .
65
79
  test_files: []