kscript 1.0.1 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a72c639d7028f3032a3ab8d6508308cd174a1174f698d5099f86356b1bef9f31
4
- data.tar.gz: 898a2845e93a58bb1760a92850b091b84fcd374d92b138c13022e85dc6868877
3
+ metadata.gz: 01ab48d4e8819e3190707f87bbc3fa8a98df3046c278a6c6a625c8eca25d4585
4
+ data.tar.gz: 15970ccc55e4900e98d0c99a6e3ebb4ebe9555891e63393ec31459c4847d5ab9
5
5
  SHA512:
6
- metadata.gz: 869a3dfa24680f0c6e95cbdb82f0d8e6f981f5868d5f5c30b0183b7d2490b64ee2ce670e08190f095eea1291f26c31293e215759ee9545eab2a1d602b36a9bba
7
- data.tar.gz: 5d24ef70c21851e42b337fd8e0222d50bb9f0def1e61a0121e2edaac8eb5fd16d4233adb8560e428eada8ee5e312a2c717f5ce30826c93891988861a38ee6260
6
+ metadata.gz: 0e45e15a0732f678f90db60384458c542f8d038460a801a60f986c197f975321fbf8ca88e39902f5fd2d1d8c2b39b8f4adae55522253824f8cf9a5afff947a83
7
+ data.tar.gz: 4b0f0f5c5be88b4b248ad9e5d5a8ccca3c0f9a267da5a664afe426917881f16ec173b09e3e287d44fbe9a9aa86aa74ef651c96abaae4b34e77ab1c6b40a85ed1
data/lib/kscript/cli.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'kscript'
4
- require 'io/console'
5
4
  require 'kscript/banner'
6
- require 'thor'
7
5
 
8
6
  module Kscript
9
7
  class CLI < Thor
@@ -55,7 +55,7 @@ module Kscript
55
55
  @logger.send(level, entry.to_json)
56
56
  end
57
57
 
58
- # 极客风格终端输出
58
+ # 终端输出
59
59
  def klog(level, message, context = {})
60
60
  if human_output?
61
61
  puts "[#{level.to_s.upcase}] #{message} #{context.map { |k, v| "#{k}=#{v}" }.join(' ')}".strip
@@ -15,8 +15,9 @@ module Kscript
15
15
 
16
16
  # Initialize with certificate path
17
17
  # @param cert_path [String] path to the certificate file
18
- def initialize(cert_path = DEFAULT_CERT_PATH)
19
- @cert_path = cert_path
18
+ def initialize(cert_path = nil, *_args, **opts)
19
+ super(**opts.merge(service: 'kk_es_fingerprint'))
20
+ @cert_path = cert_path || self.class::DEFAULT_CERT_PATH
20
21
  end
21
22
 
22
23
  def run
@@ -9,6 +9,10 @@ require 'kscript'
9
9
 
10
10
  module Kscript
11
11
  class KkFfmpegUtils < Base
12
+ def initialize(*_args, **opts)
13
+ super(**opts.merge(service: 'kk_ffmpeg'))
14
+ end
15
+
12
16
  def run
13
17
  with_error_handling do
14
18
  install
@@ -7,9 +7,6 @@
7
7
 
8
8
  require 'kscript'
9
9
 
10
- require 'http'
11
- require 'json'
12
-
13
10
  module Kscript
14
11
  class KkIpUtils < Base
15
12
  IP_API_BASE_URL = 'http://ip-api.com/json'
@@ -6,12 +6,6 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  require 'kscript'
9
- require 'http'
10
- require 'base64'
11
- require 'rexml/document'
12
- require 'json'
13
- require 'fileutils'
14
- require 'kscript/base'
15
9
 
16
10
  module Kscript
17
11
  class KkJenkinsUtils < Base
@@ -21,7 +15,9 @@ module Kscript
21
15
  end
22
16
  end
23
17
 
24
- def initialize(jenkins_url, user, password)
18
+ def initialize(*args, **opts)
19
+ super(**opts.merge(service: 'kk_jenkins'))
20
+ jenkins_url, user, password = args
25
21
  @jenkins_url = jenkins_url
26
22
  @user = user
27
23
  @password = password
@@ -6,7 +6,6 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  require 'kscript'
9
- require 'securerandom'
10
9
 
11
10
  module Kscript
12
11
  class KkKibanaUtils < Base
@@ -16,7 +15,9 @@ module Kscript
16
15
  end
17
16
  end
18
17
 
19
- def initialize(project_name, project_env, base_url, username, password)
18
+ def initialize(*args, **opts)
19
+ super(**opts.merge(service: 'kk_kibana'))
20
+ project_name, project_env, base_url, username, password = args
20
21
  @base_url = base_url
21
22
  @username = username
22
23
  @password = password
@@ -20,7 +20,8 @@ module Kscript
20
20
 
21
21
  # Initialize the LVM mounter with configuration
22
22
  # @param config [Hash] configuration options
23
- def initialize(config = {}, *_args, **_opts)
23
+ def initialize(config = {}, *_args, **opts)
24
+ super(**opts.merge(service: 'kk_lvm'))
24
25
  @config = DEFAULT_CONFIG.merge(config)
25
26
  end
26
27
 
@@ -6,7 +6,6 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  require 'kscript'
9
- require 'open3'
10
9
 
11
10
  module Kscript
12
11
  class KkOptimizeUtils < Base
@@ -6,8 +6,6 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  require 'kscript'
9
- require 'socket'
10
- require 'timeout'
11
9
 
12
10
  module Kscript
13
11
  class KkPortscanUtils < Base
@@ -17,10 +15,11 @@ module Kscript
17
15
  # @param host [String] target host to scan
18
16
  # @param ports [Array<Integer>] list of ports to scan
19
17
  # @param thread_count [Integer] number of concurrent threads
20
- def initialize(target = nil, ports = (1..1024), *_args, **opts)
18
+ def initialize(target = nil, ports = (1..1024), thread_count = 50, *_args, **opts)
21
19
  super(**opts.merge(service: 'kk_port_scanner'))
22
20
  @target = target
23
- @ports = ports.is_a?(Range) ? ports : (1..1024)
21
+ @ports = parse_ports(ports)
22
+ @thread_count = (opts[:thread_count] || thread_count || 50).to_i
24
23
  end
25
24
 
26
25
  def run
@@ -31,23 +30,62 @@ module Kscript
31
30
 
32
31
  # Execute port scanning using multiple threads
33
32
  def scan
34
- msg = "Scanning #{@target} ports #{@ports}"
33
+ msg = "Scanning #{@target} ports #{@ports} with concurrency=#{@thread_count}"
35
34
  if human_output?
36
35
  puts msg
37
36
  else
38
37
  logger.kinfo(msg)
39
38
  end
40
- @ports.each do |port|
41
- Socket.tcp(@target, port, connect_timeout: 0.5) do |_sock|
42
- if human_output?
43
- puts "Port #{port} is open"
44
- else
45
- logger.kinfo('Port open', port: port)
46
- logger.kinfo("Port #{port} is open")
39
+ queue = Queue.new
40
+ @ports.each { |port| queue << port }
41
+ threads = []
42
+ @thread_count.times do
43
+ threads << Thread.new do
44
+ until queue.empty?
45
+ port = nil
46
+ begin
47
+ port = queue.pop(true)
48
+ rescue ThreadError
49
+ break
50
+ end
51
+ begin
52
+ Socket.tcp(@target, port, connect_timeout: 0.5) do |_sock|
53
+ if human_output?
54
+ puts "Port #{port} is open"
55
+ else
56
+ logger.kinfo('Port open', port: port)
57
+ logger.kinfo("Port #{port} is open")
58
+ end
59
+ end
60
+ rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError
61
+ # closed or filtered
62
+ end
47
63
  end
48
64
  end
49
- rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError
50
- # closed or filtered
65
+ end
66
+ threads.each(&:join)
67
+ end
68
+
69
+ # 支持多种端口参数格式: 22,80,443 或 1..1024
70
+ def parse_ports(ports)
71
+ return ports.to_a if ports.is_a?(Range)
72
+
73
+ if ports.is_a?(String)
74
+ if ports.include?(',')
75
+ ports.split(',').map(&:to_i)
76
+ elsif ports.include?('..')
77
+ begin
78
+ eval(ports).to_a
79
+ rescue StandardError
80
+ (1..1024).to_a
81
+ end
82
+ else
83
+ [ports.to_i]
84
+ end
85
+ elsif ports.is_a?(Array)
86
+ ports.map(&:to_i)
87
+ else
88
+ (1..1024).to_a
51
89
  end
52
90
  end
53
91
 
@@ -56,11 +94,11 @@ module Kscript
56
94
  end
57
95
 
58
96
  def self.arguments
59
- '<target_host>'
97
+ '<target_host> [ports] [thread_count]'
60
98
  end
61
99
 
62
100
  def self.usage
63
- "kscript portscan 192.168.1.1\nkscript portscan example.com --ports=22,80,443"
101
+ "kscript portscan 192.168.1.1\nkscript portscan example.com 22,80,443 100\nkscript portscan 192.168.1.1 1..1024 200"
64
102
  end
65
103
 
66
104
  def self.group
@@ -6,7 +6,6 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  require 'kscript'
9
- require 'json'
10
9
 
11
10
  module Kscript
12
11
  class KkProjscanUtils < Base
@@ -6,7 +6,6 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  require 'kscript'
9
- require 'nokogiri'
10
9
 
11
10
  module Kscript
12
11
  class KkShUtils < Base
@@ -9,6 +9,10 @@ require 'kscript'
9
9
 
10
10
  module Kscript
11
11
  class KkSyscheckUtils < Base
12
+ def initialize(*_args, **opts)
13
+ super(**opts.merge(service: 'kk_syscheck'))
14
+ end
15
+
12
16
  def run
13
17
  with_error_handling do
14
18
  check
@@ -6,7 +6,6 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  require 'kscript'
9
- require 'bcrypt'
10
9
 
11
10
  module Kscript
12
11
  class KkWgPassUtils < Base
data/lib/kscript/utils.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
4
- require 'fileutils'
5
-
6
3
  module Kscript
7
4
  module Utils
8
5
  class Config
@@ -6,5 +6,5 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  module Kscript
9
- VERSION = '1.0.1'
9
+ VERSION = '1.0.3'
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kk