kscript 1.0.8 → 1.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 +4 -4
- data/lib/kscript/base.rb +1 -1
- data/lib/kscript/completions/kscript.bash +1 -1
- data/lib/kscript/completions/kscript.zsh +18 -20
- data/lib/kscript/plugins/kk_apnic_ip_utils.rb +17 -12
- data/lib/kscript/plugins/kk_aws_s3_utils.rb +2 -2
- data/lib/kscript/plugins/kk_cursor_rules_utils.rb +2 -3
- data/lib/kscript/plugins/kk_elastic_cert_finger_utils.rb +2 -2
- data/lib/kscript/plugins/kk_ffmpeg_install_utils.rb +2 -2
- data/lib/kscript/plugins/kk_file_rename_utils.rb +2 -2
- data/lib/kscript/plugins/kk_ip_lookup_utils.rb +2 -2
- data/lib/kscript/plugins/kk_jenkins_manage_utils.rb +2 -2
- data/lib/kscript/plugins/kk_kibana_manage_utils.rb +2 -2
- data/lib/kscript/plugins/kk_lvm_manage_utils.rb +2 -2
- data/lib/kscript/plugins/kk_mac_optimize_utils.rb +2 -2
- data/lib/kscript/plugins/kk_mac_status_utils.rb +2 -2
- data/lib/kscript/plugins/kk_port_scan_utils.rb +2 -2
- data/lib/kscript/plugins/kk_project_scan_utils.rb +4 -3
- data/lib/kscript/plugins/kk_shell_helper_utils.rb +2 -2
- data/lib/kscript/plugins/kk_usd_rate_utils.rb +3 -4
- data/lib/kscript/plugins/kk_vcs_cleaner_utils.rb +2 -2
- data/lib/kscript/plugins/kk_wg_acl_utils.rb +2 -2
- data/lib/kscript/plugins/kk_wg_pass_utils.rb +4 -3
- data/lib/kscript/version.rb +1 -1
- data/lib/kscript.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 063aeed0edf967058b4f711054a6faf7bd1d9b4648944e9d8087e53d4638a2a9
|
4
|
+
data.tar.gz: c1bd30a10d30507dd8be6390d44f65c9e55a68f7a0c8079f55812156143961db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 066b7dd8b0d95de5e5391d1317ff9c86eb7c1c4b0aa4adcb52da652f9d4aebf055b6bc1ea9aa9f1e4b23397789232967bf4739264cdf71d92791f1dcb69c0b65
|
7
|
+
data.tar.gz: 61de9beedfa35069b788c6b6e52c520b01c83bf01d715dad3d0c0d4b91b18ec5e8a2fed65fed589ffbe66774e271e5d322bd039e908e563f81831472b88a47a2
|
data/lib/kscript/base.rb
CHANGED
@@ -8,7 +8,7 @@ _kscript_completions() {
|
|
8
8
|
|
9
9
|
# Main command list as array
|
10
10
|
local opts=(
|
11
|
-
|
11
|
+
apnic_ip aws_s3 cursor_rules elastic_cert_finger ffmpeg_install file_rename ip_lookup jenkins_manage kibana_manage lvm_manage mac_optimize mac_status port_scan project_scan shell_helper usd_rate vcs_cleaner wg_acl wg_pass
|
12
12
|
)
|
13
13
|
|
14
14
|
if [[ ${COMP_CWORD} == 1 ]]; then
|
@@ -2,28 +2,26 @@
|
|
2
2
|
_kscript() {
|
3
3
|
local -a commands
|
4
4
|
commands=(
|
5
|
-
'
|
6
|
-
'
|
7
|
-
'
|
8
|
-
'
|
9
|
-
'
|
10
|
-
'
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'top:kscript command'
|
23
|
-
'usd:kscript command'
|
5
|
+
'apnic_ip:kscript command'
|
6
|
+
'aws_s3:kscript command'
|
7
|
+
'cursor_rules:kscript command'
|
8
|
+
'elastic_cert_finger:kscript command'
|
9
|
+
'ffmpeg_install:kscript command'
|
10
|
+
'file_rename:kscript command'
|
11
|
+
'ip_lookup:kscript command'
|
12
|
+
'jenkins_manage:kscript command'
|
13
|
+
'kibana_manage:kscript command'
|
14
|
+
'lvm_manage:kscript command'
|
15
|
+
'mac_optimize:kscript command'
|
16
|
+
'mac_status:kscript command'
|
17
|
+
'port_scan:kscript command'
|
18
|
+
'project_scan:kscript command'
|
19
|
+
'shell_helper:kscript command'
|
20
|
+
'usd_rate:kscript command'
|
21
|
+
'vcs_cleaner:kscript command'
|
24
22
|
'wg_acl:kscript command'
|
25
23
|
'wg_pass:kscript command'
|
26
24
|
)
|
27
25
|
_describe 'command' commands
|
28
26
|
}
|
29
|
-
compdef _kscript kscript
|
27
|
+
compdef _kscript kscript
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript' # 移除此行
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkApnicIpUtils < Base
|
11
|
+
class KkApnicIpUtils < Kscript::Base
|
12
12
|
attr_reader :country_sn, :cache_file
|
13
13
|
|
14
14
|
# Initialize class instance, set country code and cache file path
|
@@ -21,16 +21,20 @@ module Kscript
|
|
21
21
|
# Download data from APNIC or read from cache
|
22
22
|
def download_data
|
23
23
|
if File.exist?(cache_file) && File.size?(cache_file)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
File.write(cache_file, response.body.to_s)
|
32
|
-
logger.kinfo("Data downloaded and saved to #{cache_file}")
|
24
|
+
mtime = File.mtime(cache_file)
|
25
|
+
if Time.now - mtime < 86_400
|
26
|
+
logger.kinfo("Using cached data from #{cache_file} (updated #{mtime})")
|
27
|
+
return
|
28
|
+
else
|
29
|
+
logger.kinfo("Cache expired (last updated #{mtime}), downloading new data...")
|
30
|
+
end
|
33
31
|
end
|
32
|
+
url = 'https://ftp.apnic.net/stats/apnic/delegated-apnic-latest'
|
33
|
+
response = HTTP.get(url)
|
34
|
+
raise "Failed to download the APNIC data. HTTP Status: #{response.status}" unless response.status.success?
|
35
|
+
|
36
|
+
File.write(cache_file, response.body.to_s)
|
37
|
+
logger.kinfo("Data downloaded and saved to #{cache_file}")
|
34
38
|
end
|
35
39
|
|
36
40
|
# Parse data and return IPv4 address ranges (CIDR format) for specified country
|
@@ -58,8 +62,9 @@ module Kscript
|
|
58
62
|
32 - Math.log2(hosts).to_i
|
59
63
|
end
|
60
64
|
|
61
|
-
def run
|
65
|
+
def run(*args, **_opts)
|
62
66
|
with_error_handling do
|
67
|
+
@country_sn = args[0] if args[0]
|
63
68
|
parse_ip_ranges
|
64
69
|
end
|
65
70
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
# AWS S3 文件上传测试工具
|
11
11
|
# 用法示例:
|
@@ -14,7 +14,7 @@ require 'kscript'
|
|
14
14
|
# 依赖:aws-sdk-s3(已在主入口 require)
|
15
15
|
|
16
16
|
module Kscript
|
17
|
-
class KkAwsS3Utils < Base
|
17
|
+
class KkAwsS3Utils < Kscript::Base
|
18
18
|
# 初始化,支持所有参数通过 CLI 传递
|
19
19
|
def initialize(*args, **opts)
|
20
20
|
super
|
@@ -5,11 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require '
|
9
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
10
9
|
|
11
10
|
module Kscript
|
12
|
-
class KkCursorRulesUtils < Base
|
11
|
+
class KkCursorRulesUtils < Kscript::Base
|
13
12
|
def initialize(*_args, **opts)
|
14
13
|
super(**opts.merge(service: 'kk_cursor_rules'))
|
15
14
|
end
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkElasticCertFingerUtils < Base
|
11
|
+
class KkElasticCertFingerUtils < Kscript::Base
|
12
12
|
DEFAULT_CERT_PATH = 'elasticsearch.crt'
|
13
13
|
|
14
14
|
attr_reader :cert_path
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkFfmpegInstallUtils < Base
|
11
|
+
class KkFfmpegInstallUtils < Kscript::Base
|
12
12
|
def initialize(*args, **opts)
|
13
13
|
super
|
14
14
|
end
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkFileRenameUtils < Base
|
11
|
+
class KkFileRenameUtils < Kscript::Base
|
12
12
|
attr_reader :source_pattern, :target_pattern, :directory
|
13
13
|
|
14
14
|
def initialize(*args, **opts)
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkIpLookupUtils < Base
|
11
|
+
class KkIpLookupUtils < Kscript::Base
|
12
12
|
IP_API_BASE_URL = 'http://ip-api.com/json'
|
13
13
|
IP_CHECK_URL = 'https://api.ipify.org?format=json'
|
14
14
|
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkJenkinsManageUtils < Base
|
11
|
+
class KkJenkinsManageUtils < Kscript::Base
|
12
12
|
def initialize(*args, **opts)
|
13
13
|
super
|
14
14
|
jenkins_url, user, password = args
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkKibanaManageUtils < Base
|
11
|
+
class KkKibanaManageUtils < Kscript::Base
|
12
12
|
def initialize(*args, **opts)
|
13
13
|
super
|
14
14
|
project_name, project_env, base_url, username, password = args
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkLvmManageUtils < Base
|
11
|
+
class KkLvmManageUtils < Kscript::Base
|
12
12
|
DEFAULT_CONFIG = {
|
13
13
|
device: '/dev/sdb',
|
14
14
|
volume_group: 'vg_data',
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkMacOptimizeUtils < Base
|
11
|
+
class KkMacOptimizeUtils < Kscript::Base
|
12
12
|
def initialize(*args, **opts)
|
13
13
|
super
|
14
14
|
end
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkMacStatusUtils < Base
|
11
|
+
class KkMacStatusUtils < Kscript::Base
|
12
12
|
def initialize(*_args, **opts)
|
13
13
|
super(**opts.merge(service: 'kk_mac_status'))
|
14
14
|
end
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkPortScanUtils < Base
|
11
|
+
class KkPortScanUtils < Kscript::Base
|
12
12
|
attr_reader :host, :ports, :thread_count
|
13
13
|
|
14
14
|
# Initialize the scanner with target host and port range
|
@@ -5,16 +5,17 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkProjectScanUtils < Base
|
11
|
+
class KkProjectScanUtils < Kscript::Base
|
12
12
|
def initialize(*args, **opts)
|
13
13
|
super
|
14
14
|
end
|
15
15
|
|
16
|
-
def run
|
16
|
+
def run(*args, **_opts)
|
17
17
|
with_error_handling do
|
18
|
+
@src_path = args[0] || @src_path || Dir.pwd
|
18
19
|
scan_and_display
|
19
20
|
end
|
20
21
|
end
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkShellHelperUtils < Base
|
11
|
+
class KkShellHelperUtils < Kscript::Base
|
12
12
|
CHT_SH_URL = 'https://cht.sh'
|
13
13
|
|
14
14
|
attr_reader :command
|
@@ -5,13 +5,11 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
9
|
-
|
10
8
|
require 'net/http'
|
11
9
|
require 'json'
|
12
10
|
|
13
11
|
module Kscript
|
14
|
-
class KkUsdRateUtils < Base
|
12
|
+
class KkUsdRateUtils < Kscript::Base
|
15
13
|
API_URL = 'https://api.exchangerate-api.com/v4/latest/USD'
|
16
14
|
|
17
15
|
def initialize(currency_code = 'CNY', *args, **opts)
|
@@ -19,8 +17,9 @@ module Kscript
|
|
19
17
|
@currency_code = currency_code
|
20
18
|
end
|
21
19
|
|
22
|
-
def run
|
20
|
+
def run(*args, **_opts)
|
23
21
|
with_error_handling do
|
22
|
+
@currency_code = args[0] if args[0]
|
24
23
|
fetch_rates
|
25
24
|
end
|
26
25
|
end
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkVcsCleanerUtils < Base
|
11
|
+
class KkVcsCleanerUtils < Kscript::Base
|
12
12
|
DEFAULT_RETAIN_VERSIONS = 10
|
13
13
|
|
14
14
|
attr_reader :source_path, :retain_count
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkWgAclUtils < Base
|
11
|
+
class KkWgAclUtils < Kscript::Base
|
12
12
|
WIREGUARD_PORT = 51_821
|
13
13
|
ALLOWED_IPS = %w[127.0.0.1].freeze
|
14
14
|
|
@@ -5,16 +5,17 @@
|
|
5
5
|
# This software is released under the MIT License.
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
|
-
require 'kscript'
|
8
|
+
# require 'kscript'
|
9
9
|
|
10
10
|
module Kscript
|
11
|
-
class KkWgPassUtils < Base
|
11
|
+
class KkWgPassUtils < Kscript::Base
|
12
12
|
def initialize(*args, **opts)
|
13
13
|
super
|
14
14
|
end
|
15
15
|
|
16
|
-
def run
|
16
|
+
def run(*args, **_opts)
|
17
17
|
with_error_handling do
|
18
|
+
@length = (args[0] || 24).to_i
|
18
19
|
generate
|
19
20
|
end
|
20
21
|
end
|
data/lib/kscript/version.rb
CHANGED
data/lib/kscript.rb
CHANGED
@@ -27,11 +27,11 @@ require 'thor'
|
|
27
27
|
require 'aws-sdk-s3'
|
28
28
|
require 'dotenv'
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
require_relative 'kscript/config'
|
31
|
+
require_relative 'kscript/base'
|
32
|
+
require_relative 'kscript/plugins'
|
33
|
+
require_relative 'kscript/logger'
|
34
|
+
require_relative 'kscript/version'
|
35
35
|
|
36
36
|
module Kscript
|
37
37
|
# fluentd 风格插件注册机制
|