Use new API for clearing language
authorJamie Cameron <jcameron@webmin.com>
Tue, 23 Aug 2011 04:41:32 +0000 (21:41 -0700)
committerJamie Cameron <jcameron@webmin.com>
Tue, 23 Aug 2011 04:41:32 +0000 (21:41 -0700)
mount/linux-lib.pl
net/linux-lib.pl
proc/proc-lib.pl
samba/samba-lib.pl
software/apt-lib.pl
system-status/system-status-lib.pl
useradmin/linux-lib.pl
web-lib-funcs.pl
webmin/gnupg-lib.pl

index a102130..e49678a 100755 (executable)
@@ -874,7 +874,9 @@ sub disk_space
 if (&get_mounted($_[1], "*") < 0) { return (); }
 if ($_[0] eq "proc" || $_[0] eq "swap" ||
     $_[0] eq "auto" || $_[0] eq "autofs") { return (); }
-local $out = &backquote_command("LC_ALL='' LANG='' df -k ".quotemeta($_[1]), 1);
+&clean_language();
+local $out = &backquote_command("df -k ".quotemeta($_[1]), 1);
+&reset_environment();
 if ($out =~ /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/) {
        return ($1, $2);
        }
@@ -886,8 +888,10 @@ return ( );
 sub inode_space
 {
 if (&get_mounted($_[1], "*") < 0) { return (); }
-if (&backquote_command("LC_ALL='' LANG='' df -i $_[1]", 1) =~
-    /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/) {
+&clean_language();
+local $out = &backquote_command("df -i $_[1]", 1);
+&reset_environment();
+if ($out =~ /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/) {
        return ($1, $2);
        }
 return ( );
index 1b59144..3d7f490 100755 (executable)
@@ -7,13 +7,15 @@ sub active_interfaces
 {
 local ($empty) = @_;
 local(@rv, @lines, $l);
-&open_execute_command(IFC, "LC_ALL='' LANG='' ifconfig -a", 1, 1);
+&clean_language();
+&open_execute_command(IFC, "ifconfig -a", 1, 1);
 while(<IFC>) {
        s/\r|\n//g;
        if (/^\S+/) { push(@lines, $_); }
        else { $lines[$#lines] .= $_; }
        }
 close(IFC);
+&reset_environment();
 my $ethtool = &has_command("ethtool");
 foreach $l (@lines) {
        local %ifc;
index e27d006..f74a55c 100755 (executable)
@@ -499,7 +499,9 @@ sub get_cpu_info
 if (defined(&os_get_cpu_info)) {
        return &os_get_cpu_info();
        }
-local $out = `uptime 2>&1`;
+&clean_language();
+local $out = &backquote_command("uptime 2>&1");
+&reset_environment();
 return $out =~ /average(s)?:\s+([0-9\.]+),?\s+([0-9\.]+),?\s+([0-9\.]+)/i ?
                ( $2, $3, $4 ) : ( );
 }
index 589cfec..a6be612 100755 (executable)
@@ -222,7 +222,9 @@ sub list_locks
 {
 local($l, $started, @rv);
 local $out;
-&execute_command("LANG=C $config{samba_status_program} -L", undef, \$out, undef);
+&clean_language();
+&execute_command("$config{samba_status_program} -L", undef, \$out, undef);
+&reset_environment();
 foreach $l (split(/\n/, $out)) {
        if ($l =~ /^----/) { $started = 1; }
        if ($started && $l =~ /^(\d+)\s+(\d+)\s+(\S+)\s+(0x\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S.*)\s\s((Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s.*)/i) {
index d537ef8..8cfb82a 100755 (executable)
@@ -140,8 +140,8 @@ local (@rv, $pkg, %done);
 
 # Use dump to get versions
 &execute_command("$apt_get_command update");
-&open_execute_command(DUMP,
-       "LANG='' LC_ALL='' apt-cache dump 2>/dev/null", 1, 1);
+&clean_language();
+&open_execute_command(DUMP, "apt-cache dump 2>/dev/null", 1, 1);
 while(<DUMP>) {
        if (/^\s*Package:\s*(\S+)/) {
                $pkg = { 'name' => $1 };
@@ -160,6 +160,7 @@ while(<DUMP>) {
                }
        }
 close(DUMP);
+&reset_environment();
 
 # Use search to get descriptions
 foreach my $s (&update_system_search('.*')) {
@@ -178,7 +179,8 @@ return @rv;
 sub update_system_search
 {
 local (@rv, $pkg);
-&open_execute_command(DUMP, "LANG='' LC_ALL='' $apt_search_command search ".
+&clean_language();
+&open_execute_command(DUMP, "$apt_search_command search ".
                            quotemeta($_[0])." 2>/dev/null", 1, 1);
 while(<DUMP>) {
        if (/^(\S+)\s*-\s*(.*)/) {
@@ -189,6 +191,7 @@ while(<DUMP>) {
                }
        }
 close(DUMP);
+&reset_environment();
 return @rv;
 }
 
@@ -201,22 +204,23 @@ sub update_system_updates
 # Find held packages by dpkg
 local %holds;
 if ($config{'package_system'} eq 'debian') {
-       &open_execute_command(HOLDS,
-               "LANG='' LC_ALL='' dpkg --get-selections", 1, 1);
+       &clean_language();
+       &open_execute_command(HOLDS, "dpkg --get-selections", 1, 1);
        while(<HOLDS>) {
                if (/^(\S+)\s+hold/) {
                        $holds{$1}++;
                        }
                }
        close(HOLDS);
+       &reset_environment();
        }
 
 if (&has_command("apt-show-versions")) {
        # This awesome command can give us all updates in one hit, and takes
        # pinned versions and backports into account
        local @rv;
-       &open_execute_command(PKGS,
-               "LANG='' LC_ALL='' apt-show-versions 2>/dev/null", 1, 1);
+       &clean_language();
+       &open_execute_command(PKGS, "apt-show-versions 2>/dev/null", 1, 1);
        while(<PKGS>) {
                if (/^(\S+)\/(\S+)\s+upgradeable\s+from\s+(\S+)\s+to\s+(\S+)/ &&
                    !$holds{$1}) {
@@ -230,6 +234,7 @@ if (&has_command("apt-show-versions")) {
                        }
                }
        close(PKGS);
+       &reset_environment();
        return @rv;
        }
 else {
@@ -258,8 +263,8 @@ else {
                        @somenames = @names;
                        @names = ( );
                        }
-               &open_execute_command(PKGS,
-                       "LANG='' LC_ALL='' apt-cache showpkg ".
+               &clean_language();
+               &open_execute_command(PKGS, "apt-cache showpkg ".
                        join(" ", @somenames)." 2>/dev/null", 1, 1);
                local $pkg = undef;
                while(<PKGS>) {
@@ -287,6 +292,7 @@ else {
                                }
                        }
                close(PKGS);
+               &reset_environment();
                }
        &set_pinned_versions(\@rv);
        return @rv;
@@ -300,8 +306,8 @@ sub set_pinned_versions
 {
 local ($pkgs) = @_;
 local %pkgmap = map { $_->{'name'}, $_ } @$pkgs;
-&open_execute_command(PKGS,
-       "LANG='' LC_ALL='' apt-cache policy 2>/dev/null", 1, 1);
+&clean_language();
+&open_execute_command(PKGS, "apt-cache policy 2>/dev/null", 1, 1);
 while(<PKGS>) { 
        s/\r|\n//g;
        if (/\s+(\S+)\s+\-\>\s+(\S+)/) {
@@ -317,5 +323,6 @@ while(<PKGS>) {
                }
        }
 close(PKGS);
+&reset_environment();
 }
 
index 19df43f..a4915d7 100755 (executable)
@@ -171,9 +171,10 @@ if (&foreign_check("net") && $gconfig{'os_type'} =~ /-linux$/) {
                }
        my $ifaces = join(" ", @ifaces);
        foreach my $iname (@ifaces) {
+               &clean_language();
                my $out = &backquote_command(
-                       "LC_ALL='' LANG='' ifconfig ".
-                       quotemeta($iname)." 2>/dev/null");
+                       "ifconfig ".quotemeta($iname)." 2>/dev/null");
+               &reset_environment();
                my $rx = $out =~ /RX\s+bytes:\s*(\d+)/i ? $1 : undef;
                my $tx = $out =~ /TX\s+bytes:\s*(\d+)/i ? $1 : undef;
                $rxtotal += $rx;
index fa79561..84839b5 100755 (executable)
@@ -48,7 +48,8 @@ while(1) {
 sub os_most_recent_logins
 {
 my %rv;
-open(LASTLOG, "LANG=C lastlog |");
+&clean_language();
+open(LASTLOG, "lastlog |");
 while(<LASTLOG>) {
        s/\r|\n//g;
        if (/^(\S+)/) {
@@ -63,6 +64,7 @@ while(<LASTLOG>) {
                }
        }
 close(LASTLOG);
+&reset_environment();
 return \%rv;
 }
 
index 0cdd8a8..d192115 100755 (executable)
@@ -7093,6 +7093,7 @@ sub clean_language
 {
 %UNCLEAN_ENV = %ENV;
 $ENV{'LANG'} = '';
+$ENV{'LANGUAGE'} = '';
 $ENV{'LC_ALL'} = '';
 $ENV{'LOCALE'} = '';
 }
index fa23895..b044935 100755 (executable)
@@ -22,7 +22,8 @@ our $gpgpath = $config{'gpg'} || "gpg";
 sub list_keys
 {
 my (@rv, %kmap);
-open(GPG, "LC_ALL='' LANG='' $gpgpath --list-keys 2>/dev/null |");
+&clean_language();
+open(GPG, "$gpgpath --list-keys 2>/dev/null |");
 while(<GPG>) {
        if (/^pub\s+(\S+)\/(\S+)\s+(\S+)\s+(.*)\s+<(\S+)>/ ||
            /^pub\s+(\S+)\/(\S+)\s+(\S+)\s+(.*)/) {
@@ -56,13 +57,14 @@ while(<GPG>) {
                }
        }
 close(GPG);
-open(GPG, "LC_ALL='' LANG='' $gpgpath --list-secret-keys 2>/dev/null |");
+open(GPG, "$gpgpath --list-secret-keys 2>/dev/null |");
 while(<GPG>) {
        if (/^sec\s+(\S+)\/(\S+)\s+(\S+)\s+(.*)/ && $kmap{$2}) {
                $kmap{$2}->{'secret'}++;
                }
        }
 close(GPG);
+&reset_environment();
 return @rv;
 }
 
@@ -86,13 +88,15 @@ sub key_fingerprint
 {
 my $fp;
 local $_;
-open(GPG, "LC_ALL='' LANG='' $gpgpath --fingerprint \"$_[0]->{'name'}->[0]\" |");
+&clean_language();
+open(GPG, "$gpgpath --fingerprint \"$_[0]->{'name'}->[0]\" |");
 while(<GPG>) {
        if (/fingerprint\s+=\s+(.*)/) {
                $fp = $1;
                }
        }
 close(GPG);
+&reset_environment();
 return $fp;
 }
 
@@ -130,7 +134,8 @@ my $dstfile = &transname();
 my $ascii = $_[3] ? "--armor" : "";
 my $comp = $config{'compress'} eq '' ? "" :
                " --compress-algo $config{'compress'}";
-my $cmd = "LC_ALL='' LANG='' $gpgpath --output $dstfile $rcpt $ascii $comp --encrypt $srcfile";
+&clean_language();
+my $cmd = "$gpgpath --output $dstfile $rcpt $ascii $comp --encrypt $srcfile";
 my ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $cmd);
 while(1) {
        my $rv = &wait_for($fh, "anyway");
@@ -142,6 +147,7 @@ while(1) {
                }
        }
 close($fh);
+&reset_environment();
 unlink($srcfile);
 my $dst = &read_entire_file($dstfile);
 unlink($dstfile);
@@ -162,7 +168,8 @@ sub decrypt_data
 my $srcfile = &transname();
 &write_entire_file($srcfile, $_[0]);
 my $dstfile = &transname();
-my $cmd = "LC_ALL='' LANG='' $gpgpath --output $dstfile --decrypt $srcfile";
+&clean_language();
+my $cmd = "$gpgpath --output $dstfile --decrypt $srcfile";
 my ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $cmd);
 my ($error, $seen_pass, $pass, $key, $keyid);
 while(1) {
@@ -187,6 +194,7 @@ while(1) {
                }
        }
 close($fh);
+&reset_environment();
 unlink($srcfile);
 my $dst = &read_entire_file($dstfile);
 unlink($dstfile);
@@ -227,8 +235,9 @@ elsif ($_[3] == 1) {
 elsif ($_[3] == 2) {
        $cmd = "$gpgpath --armor --output $dstfile --default-key $_[2]->{'key'} --detach-sig $srcfile";
        }
-$cmd = "LC_ALL='' LANG='' $cmd";
+&clean_language();
 my ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $cmd);
+&reset_environment();
 my ($error, $seen_pass);
 my $pass = &get_passphrase($_[2]);
 if (!defined($pass)) {
@@ -277,18 +286,20 @@ my $datafile = &transname();
 my $cmd;
 my $sigfile;
 if (!$_[1]) {
-       $cmd = "LC_ALL='' LANG='' $gpgpath --verify $datafile";
+       $cmd = "$gpgpath --verify $datafile";
        }
 else {
        $sigfile = &transname();
        &write_entire_file($sigfile, $_[1]);
-       $cmd = "LC_ALL='' LANG='' $gpgpath --verify $sigfile $datafile";
+       $cmd = "$gpgpath --verify $sigfile $datafile";
        }
 #local ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $cmd);
 #&wait_for($fh);
 #close($fh);
 #local $out = $wait_for_input;
+&clean_language();
 my $out = &backquote_command("$cmd 2>&1 </dev/null");
+&reset_environment();
 unlink($datafile);
 unlink($sigfile) if ($sigfile);
 if ($out =~ /BAD signature from "(.*)"/i) {
@@ -336,7 +347,8 @@ my $fh;
 # Returns the trust level of a key
 sub get_trust_level
 {
-my $cmd = "LC_ALL='' LANG='' $gpgpath --edit-key \"$_[0]->{'name'}->[0]\"";
+&clean_language();
+my $cmd = "$gpgpath --edit-key \"$_[0]->{'name'}->[0]\"";
 my ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $cmd);
 my $rv = &wait_for($fh, "trust:\\s+(.)", "command>");
 my $tr;
@@ -349,6 +361,7 @@ else {
        }
 syswrite($fh, "quit\n", length("quit\n"));
 close($fh);
+&reset_environment();
 return $tr;
 }
 
@@ -358,7 +371,8 @@ sub delete_key
 {
 my ($key) = @_;
 if ($key->{'secret'}) {
-       my $cmd = "LC_ALL='' LANG='' $gpgpath --delete-secret-key \"$key->{'name'}->[0]\"";
+       &clean_language();
+       my $cmd = "$gpgpath --delete-secret-key \"$key->{'name'}->[0]\"";
        my ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $cmd);
        &wait_for($fh, "\\?");
        syswrite($fh, "y\n");
@@ -366,13 +380,16 @@ if ($key->{'secret'}) {
        syswrite($fh, "y\n");
        sleep(1);
        close($fh);
+       &reset_environment();
        }
-my $cmd = "LC_ALL='' LANG='' $gpgpath --delete-key \"$key->{'name'}->[0]\"";
+&clean_language();
+my $cmd = "$gpgpath --delete-key \"$key->{'name'}->[0]\"";
 my ($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $cmd);
 &wait_for($fh, "\\?");
 syswrite($fh, "y\n");
 sleep(1);
 close($fh);
+&reset_environment();
 }
 
 # default_email_address()