#!/usr/bin/perl
##############################################################################################
-# uagen (http://www.fabiankeil.de/sourcecode/uagen/)
-#
-# $Id: uagen.pl,v 1.11 2011/03/08 18:43:46 fabiankeil Exp $
+# uagen (https://www.fabiankeil.de/sourcecode/uagen/)
#
# Generates a pseudo-random Firefox user agent and writes it into a Privoxy action file
# and optionally into a Mozilla prefs file. For documentation see 'perldoc uagen(.pl)'.
#
-# Examples (created with v1.0):
+# Examples (created with v1.2.2):
#
-# Mozilla/5.0 (X11; U; NetBSD i386; en-US; rv:1.8.0.2) Gecko/20060421 Firefox/1.5.0.2
-# Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-CA; rv:1.8.0.2) Gecko/20060425 Firefox/1.5.0.2
-# Mozilla/5.0 (X11; U; SunOS i86pc; no-NO; rv:1.8.0.2) Gecko/20060420 Firefox/1.5.0.2
-# Mozilla/5.0 (X11; U; Linux x86_64; de-AT; rv:1.8.0.2) Gecko/20060422 Firefox/1.5.0.2
-# Mozilla/5.0 (X11; U; NetBSD i386; en-US; rv:1.8.0.2) Gecko/20060415 Firefox/1.5.0.2
-# Mozilla/5.0 (X11; U; OpenBSD sparc64; pl-PL; rv:1.8.0.2) Gecko/20060429 Firefox/1.5.0.2
-# Mozilla/5.0 (X11; U; Linux i686; en-CA; rv:1.8.0.2) Gecko/20060413 Firefox/1.5.0.2
+# Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
+# Mozilla/5.0 (Macintosh; PPC Mac OS X; rv:78.0) Gecko/20100101 Firefox/78.0
+# Mozilla/5.0 (X11; NetBSD i386; rv:78.0) Gecko/20100101 Firefox/78.0
+# Mozilla/5.0 (X11; OpenBSD alpha; rv:78.0) Gecko/20100101 Firefox/78.0
+# Mozilla/5.0 (X11; FreeBSD amd64; rv:78.0) Gecko/20100101 Firefox/78.0
+# Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
+# Mozilla/5.0 (X11; ElectroBSD amd64; rv:78.0) Gecko/20100101 Firefox/78.0
+# Mozilla/5.0 (X11; FreeBSD i386; rv:78.0) Gecko/20100101 Firefox/78.0
#
-# Copyright (c) 2006-2009 Fabian Keil <fk@fabiankeil.de>
+# Copyright (c) 2006-2022 Fabian Keil <fk@fabiankeil.de>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
use constant {
- UAGEN_VERSION => 'uagen 1.0.10',
+ UAGEN_VERSION => 'uagen 1.2.5',
UAGEN_LOGFILE => '/var/log/uagen.log',
ACTION_FILE => '/etc/privoxy/user-agent.action',
SLEEPING_TIME => 5,
# As of Firefox 4, the "Gecko token" has been frozen
- # http://hacks.mozilla.org/2010/09/final-user-agent-string-for-firefox-4/
+ # https://hacks.mozilla.org/2010/09/final-user-agent-string-for-firefox-4/
RANDOMIZE_RELEASE_DATE => 0,
# These variables belong together. If you only change one of them, the generated
# are too lazy to check, but want to change them anyway, take the values you
# see in the "Help/About Mozilla Firefox" menu.
- BROWSER_VERSION => "3.6.15",
- BROWSER_REVISION => '1.9.2.15',
- BROWSER_RELEASE_DATE => '20110305',
+ BROWSER_VERSION => "115.0",
+ BROWSER_REVISION => '109.0',
+ BROWSER_RELEASE_DATE => '20100101',
};
use constant LANGUAGES => qw(
#######################################################################################
sub generate_creation_time($) {
- my $release_date = $_ = shift;
+ my $release_date = shift;
my ($rel_year, $rel_mon, $rel_day);
my ($c_day, $c_mon, $c_year);
my $now = time;
- my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
- localtime $now;
+ my (undef, undef, undef, $mday, $mon, $year, undef, undef, undef) = localtime($now);
$mon += 1;
$year += 1900;
- unless ( m/\d{6}/ ) {
+ unless ($release_date =~ m/\d{6}/) {
log_error("Invalid release date format: $release_date. Using "
. BROWSER_RELEASE_DATE . " instead.");
$release_date = BROWSER_RELEASE_DATE;
}
- $rel_year = substr $release_date, 0, 4;
- $rel_mon = substr $release_date, 4, 2;
- $rel_day = substr $release_date, 6, 2;
+ $rel_year = substr($release_date, 0, 4);
+ $rel_mon = substr($release_date, 4, 2);
+ $rel_day = substr($release_date, 6, 2);
#1, 2, 3, Check.
- die "release year in the future" if ( $year < $rel_year );
+ die "release year in the future" if ($year < $rel_year);
die "release month in the future"
- if ( ( $year == $rel_year ) and ( $mon < $rel_mon ) );
+ if (($year == $rel_year) and ($mon < $rel_mon));
die "release day in the future"
- if ( ( $year == $rel_year )
- and ( $mon == $rel_mon )
- and ( $mday < $rel_day ) );
+ if (($year == $rel_year) and ($mon == $rel_mon) and ($mday < $rel_day));
my @c_time = (0, 0, 0, $rel_day, $rel_mon - 1, $rel_year - 1900, 0, 0, 0);
- my $c_seconds = &timelocal( @c_time );
+ my $c_seconds = timelocal(@c_time);
$c_seconds = $now - (int rand ($now - $c_seconds));
- @c_time = localtime $c_seconds;
- ($sec, $min, $hour, $c_day, $c_mon, $c_year, $wday, $yday, $isdst) = @c_time;
+ @c_time = localtime($c_seconds);
+ (undef, undef, undef, $c_day, $c_mon, $c_year, undef, undef, undef) = @c_time;
$c_mon += 1;
$c_year += 1900;
#3, 2, 1, Test.
- die "Compilation year in the future" if ( $year < $c_year );
+ die "Compilation year in the future" if ($year < $c_year);
die "Compilation month in the future"
- if ( ( $year == $c_year ) and ( $mon < $c_mon ) );
+ if (($year == $c_year) and ($mon < $c_mon));
die "Compilation day in the future"
- if ( ( $year == $c_year ) and ( $mon == $c_mon ) and ( $mday < $c_day ) );
+ if (($year == $c_year) and ($mon == $c_mon) and ($mday < $c_day));
- return sprintf "%.2i%.2i%.2i", $c_year, $c_mon, $c_day;
+ return sprintf("%.2i%.2i%.2i", $c_year, $c_mon, $c_day);
}
sub generate_language_settings() {
sub generate_platform_and_os() {
my %os_data = (
+ ElectroBSD => {
+ karma => 1,
+ platform => 'X11',
+ architectures => [ 'i386', 'amd64' ],
+ order_is_inversed => 0,
+ },
FreeBSD => {
karma => 1,
platform => 'X11',
- architectures => [ 'i386', 'amd64', 'sparc64', 'alpha' ],
+ architectures => [ 'i386', 'amd64' ],
order_is_inversed => 0,
},
OpenBSD => {
karma => 1,
platform => 'X11',
- architectures => [ 'i386', 'amd64', 'sparc64', 'alpha' ],
+ architectures => [ 'arm64', 'i386', 'amd64', 'sparc64', 'alpha' ],
order_is_inversed => 0,
},
NetBSD => {
Linux => {
karma => 1,
platform => 'X11',
- architectures => [ 'i586', 'i686', 'x86_64' ],
+ architectures => [ 'aarch64', 'i586', 'i686', 'x86_64' ],
order_is_inversed => 0,
},
SunOS => {
our $randomize_release_date;
my $mozillaversion = '5.0';
- my $security = "U";
my $creation_time = $randomize_release_date ?
generate_creation_time($browser_release_date) : $browser_release_date;
my ( $platform, $os_or_cpu ) = generate_platform_and_os;
my $firefox_user_agent =
- sprintf "Mozilla/%s (%s; %s; %s; %s; rv:%s) Gecko/%s Firefox/%s",
- $mozillaversion, $platform, $security, $os_or_cpu, $locale, $browser_revision,
+ sprintf "Mozilla/%s (%s; %s; rv:%s) Gecko/%s Firefox/%s",
+ $mozillaversion, $platform, $os_or_cpu, $browser_revision,
$creation_time, $browser_version;
return $accept_language, $firefox_user_agent;
return if $no_logging;
- open(my $log_fd, ">>" . $logfile) || die "Writing " . $logfile . " failed";
+ open(my $log_fd, ">>", $logfile) || die "Writing " . $logfile . " failed";
printf $log_fd UAGEN_VERSION . " ($logtime) $message\n";
close($log_fd);
}
$action_file_content .= sprintf " +hide-user-agent{%s} \\\n}\n/\n",
$user_agent;
}
- open(my $actionfile_fd, ">" . $action_file)
+ open(my $actionfile_fd, ">", $action_file)
or log_error "Writing action file $action_file failed!";
print $actionfile_fd $action_file_content;
close($actionfile_fd);
my $prefs_file_content = '';
my $prefsfile_fd;
- if (open($prefsfile_fd, $mozilla_prefs_file)) {
+ if (open($prefsfile_fd, "<", $mozilla_prefs_file)) {
while (<$prefsfile_fd>) {
s@user_pref\(\"general.useragent.override\",.*\);\n?@@;
sprintf("user_pref(\"intl.accept_languages\", \"%s\");\n", $accept_language)
unless $clean_prefs;
- open($prefsfile_fd, ">" . $mozilla_prefs_file)
+ open($prefsfile_fd, ">", $mozilla_prefs_file)
or log_error "Writing prefs file $mozilla_prefs_file failed!";
print $prefsfile_fd $prefs_file_content;
close($prefsfile_fd);
}
sub VersionMessage() {
- printf UAGEN_VERSION . "\n" . 'Copyright (C) 2006-2009 Fabian Keil <fk@fabiankeil.de> ' .
- "\nhttp://www.fabiankeil.de/sourcecode/uagen/\n";
+ printf UAGEN_VERSION . "\n" . 'Copyright (c) 2006-2022 Fabian Keil <fk@fabiankeil.de> ' .
+ "\nhttps://www.fabiankeil.de/sourcecode/uagen/\n";
}
sub help() {
}
main();
-exit(0);
=head1 NAME
B<--browser-release-date> I<browser_release_date> Date to use.
The format is YYYYMMDD. Some sanity checks are done, but you
-shouldn't rely on them.
+shouldn't rely on them. Note that the Mozilla project has frozen
+the "Gecko token" starting with Firefox 4 so using a different
+one than the default is somewhat suspicious.
B<--browser-revision> I<browser_revision> Use a custom revision.
B<uagen> will use it without any sanity checks.
=head1 CAVEATS
-If the browser opens an encrypted connection, Privoxy can't inspect
-the content and the browser's headers reach the server unmodified.
-It is the user's job to use Privoxy's limit-connect action to make sure
-there are no encrypted connections to untrusted sites.
+Use the https-inspection action to make sure Privoxy can modify
+the browser's headers for encrypted traffic as well.
Mozilla users can alter the browser's User-Agent with the
B<--prefs-file> option. But note that the preference file is only read
=head1 SEE ALSO
-privoxy(1)
+privoxy(8)
=head1 AUTHOR
Fabian Keil <fk@fabiankeil.de>
-http://www.fabiankeil.de/sourcecode/uagen/
+https://www.fabiankeil.de/sourcecode/uagen/
-http://www.fabiankeil.de/blog-surrogat/2006/01/26/firefox-user-agent-generator.html (German)
+https://www.fabiankeil.de/blog-surrogat/2006/01/26/firefox-user-agent-generator.html (German)
=cut