Skip to content

Commit

Permalink
add updating UAs
Browse files Browse the repository at this point in the history
  • Loading branch information
h00die committed Dec 30, 2024
1 parent fa0ba96 commit a426b41
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/weekly-data-and-external-tool-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
run: |
ruby tools/dev/update_wordpress_vulnerabilities.rb
ruby tools/dev/update_joomla_components.rb
ruby tools/dev/update_user_agent_strings.rb
ruby tools/dev/check_external_scripts.rb -u
#- name: Commit changes
Expand Down Expand Up @@ -84,5 +85,6 @@ jobs:
- ruby tools/dev/update_wordpress_vulnerabilities.rb
- ruby tools/dev/update_joomla_components.rb
- ruby tools/dev/update_user_agent_strings.rb
- ruby tools/dev/check_external_scripts.rb -u
draft: false
56 changes: 0 additions & 56 deletions tools/dev/update_user_agent_strings.py

This file was deleted.

44 changes: 44 additions & 0 deletions tools/dev/update_user_agent_strings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'net/http'
require 'uri'

def fetch_user_agent(url, regex)
uri = URI.parse(url)
response = Net::HTTP.get(uri)
match = response.match(Regexp.new(regex))
match ? match[1] : nil
end

def replace_agent_string(lines, agent_name, url, regex)
user_agent = fetch_user_agent(url, regex)
return unless user_agent

lines.map! do |line|
if line.include?(agent_name)
line.gsub(/".*"/, "\"#{user_agent}\"")
else
line
end
end
end

chrome_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome"
edge_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/edge"
safari_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/safari"
firefox_url = "https://www.whatismybrowser.com/guides/the-latest-user-agent/firefox"

user_agent_filename = 'lib/rex/user_agent.rb'
lines = File.read(user_agent_filename).split("\n")

replace_agent_string(lines, 'Chrome Windows', chrome_url, '<td>Chrome \\(Standard\\)</td>\\s*<td>\\s*<ul>\\s*<li><span class="code">([{VALID_CHARS}]*Windows NT[{VALID_CHARS}]*)</span>')
replace_agent_string(lines, 'Chrome MacOS', chrome_url, '<td>Chrome \\(Standard\\)</td>\\s*<td>\\s*<ul>\\s*<li><span class="code">([{VALID_CHARS}]*Macintosh[{VALID_CHARS}]*)</span>')
replace_agent_string(lines, 'Edge Windows', edge_url, '<td>Edge \\(Standard\\)</td>\\s*<td>\\s*<ul>\\s*<li><span class="code">([{VALID_CHARS}]*Windows NT[{VALID_CHARS}]*)</span>')
replace_agent_string(lines, 'Safari iPad', safari_url, '<td>\\s*Safari on <b>Ipad</b>\\s*</td>\\s*<td>\\s*<ul>\\s*<li><span class="code">([{VALID_CHARS}]*iPad[{VALID_CHARS}]*)</span>')
replace_agent_string(lines, 'Safari MacOS', safari_url, '<td>Safari \\(Standard\\)</td>\\s*<td>\\s*<ul>\\s*<li><span class="code">([{VALID_CHARS}]*Macintosh[{VALID_CHARS}]*)</span>')
replace_agent_string(lines, 'Firefox Windows', firefox_url, '<td>\\s*Firefox on <b>Windows</b>\\s*</td>\\s*<td>\\s*<ul>\\s*<li><span class="code">([{VALID_CHARS}]*Windows NT[{VALID_CHARS}]*)</span>')
replace_agent_string(lines, 'Firefox MacOS', firefox_url, '<td>\\s*Firefox on <b>Macos</b>\\s*</td>\\s*<td>\\s*<ul>\\s*<li><span class="code">([{VALID_CHARS}]*Macintosh[{VALID_CHARS}]*)</span>')

File.open(user_agent_filename, 'w') do |file|
file.puts lines
end

puts 'Done'

0 comments on commit a426b41

Please sign in to comment.