kscript 1.0.8 → 1.0.9

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: c849a066ee71710301195b2291bdfc84ef1e94544273010bc081c2654af9a198
4
- data.tar.gz: ec56f9ebe0ad082112060f6d53a63efae05c7095ecd0ead03bbd237c78001db7
3
+ metadata.gz: 587c4a1f08230cd5085bace44a9fbb4035f52a62a4f1fdb35e00fb5ef4e52567
4
+ data.tar.gz: efb3539204a0b0dddb0a8a375a6d58574d668b96bdef01dacd0d1e394f309542
5
5
  SHA512:
6
- metadata.gz: '0068635e992da14c93ac3525a631157c62eb57f66271cdea4818672e7a05afe35507a87c0eee713fecbfe17941bf0cba617a89038581b928f76a7c7165c99f2b'
7
- data.tar.gz: 2e708a65ccb4de60db91990360f3705e1545b1d51fbe81973e2dd78ce6f510a22c3237d9b69f8051805af56e12c82e50e5e6218cd1af2ee90264e6ef4850776f
6
+ metadata.gz: 54c44443112073b48dda6b9d4c7f9707ab99b94b8fb5e4a04c1320cdcd1becaacd34c81c452d21bd84bc20be797900e05fed004d07e5423c7081e49a96379b66
7
+ data.tar.gz: c155b0a6eb3c047c73e5b90c0c6353aaff99e47eab12acdab905cfa287090475ff35c681d95674a92b85268f886ad4351e0ce58209d0b00f727e696d3ff4ffe3
data/lib/kscript/base.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kscript'
3
+ require_relative '../kscript'
4
4
 
5
5
  module Kscript
6
6
  # Base class for all kscript scripts
@@ -8,7 +8,7 @@ _kscript_completions() {
8
8
 
9
9
  # Main command list as array
10
10
  local opts=(
11
- version help list apnic cleaner es_fingerprint ffmpeg ip jenkins kibana lvm optimize portscan projscan rename sh syscheck top usd wg_acl wg_pass
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
- 'version:kscript command'
6
- 'help:kscript command'
7
- 'list:kscript command'
8
- 'apnic:kscript command'
9
- 'cleaner:kscript command'
10
- 'es_fingerprint:kscript command'
11
- 'ffmpeg:kscript command'
12
- 'ip:kscript command'
13
- 'jenkins:kscript command'
14
- 'kibana:kscript command'
15
- 'lvm:kscript command'
16
- 'optimize:kscript command'
17
- 'portscan:kscript command'
18
- 'projscan:kscript command'
19
- 'rename:kscript command'
20
- 'sh:kscript command'
21
- 'syscheck:kscript command'
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
- logger.kinfo("Using cached data from #{cache_file}")
25
- else
26
- url = 'https://ftp.apnic.net/stats/apnic/delegated-apnic-latest'
27
- response = HTTP.get(url)
28
-
29
- raise "Failed to download the APNIC data. HTTP Status: #{response.status}" unless response.status.success?
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 'fileutils'
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,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 KkProjectScanUtils < Base
11
+ class KkProjectScanUtils < 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 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)
@@ -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,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 KkWgPassUtils < Base
11
+ class KkWgPassUtils < Kscript::Base
12
12
  def initialize(*args, **opts)
13
13
  super
14
14
  end
@@ -6,5 +6,5 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  module Kscript
9
- VERSION = '1.0.8'
9
+ VERSION = '1.0.9'
10
10
  end
data/lib/kscript.rb CHANGED
@@ -27,11 +27,11 @@ require 'thor'
27
27
  require 'aws-sdk-s3'
28
28
  require 'dotenv'
29
29
 
30
- require 'kscript/config'
31
- require 'kscript/plugins'
32
- require 'kscript/base'
33
- require 'kscript/logger'
34
- require 'kscript/version'
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 风格插件注册机制
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.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kk