More IPv6 friendly function conversions
authorJamie Cameron <jcameron@webmin.com>
Mon, 1 Nov 2010 00:23:47 +0000 (17:23 -0700)
committerJamie Cameron <jcameron@webmin.com>
Mon, 1 Nov 2010 00:23:47 +0000 (17:23 -0700)
16 files changed:
acl/save_sql.cgi
apache/create_virt.cgi
apache/save_vserv.cgi
bacula-backup/fixaddr.cgi
bacula-backup/index.cgi
bacula-backup/save_client.cgi
bacula-backup/save_storage.cgi
bsdexports/save_export.cgi
cluster-shutdown/save_sched.cgi [new file with mode: 0755]
custom/save_sql.cgi
dfsadmin/save_share.cgi
dhcpd/save_options.cgi
dhcpd/save_subnet.cgi
exports/save_export.cgi
fetchmail/fetchmail-lib.pl
fetchmail/save_poll.cgi

index c516133..f0c413c 100755 (executable)
@@ -10,8 +10,8 @@ $p = $in{'proto'};
 
 # Parse inputs
 if ($p eq 'mysql' || $p eq 'postgresql' || $p eq 'ldap') {
-       gethostbyname($in{$p."_host"}) ||
-         $in{$p."_host"} =~ /^(\S+):(\d+)$/ && gethostbyname($1) ||
+       &to_ipaddress($in{$p."_host"}) ||
+         $in{$p."_host"} =~ /^(\S+):(\d+)$/ && &to_ipaddress("$1") ||
            &error($text{'sql_ehost'});
        $in{$p."_user"} =~ /^\S+$/ || &error($text{'sql_euser'});
        $in{$p."_pass"} =~ /^\S*$/ || &error($text{'sql_epass'});
index 8c6191b..906a338 100755 (executable)
@@ -30,8 +30,7 @@ elsif ($in{'addr'} !~ /\S/) {
        }
 else {
        foreach $a (split(/\s+/, $in{'addr'})) {
-               gethostbyname($a) || &check_ipaddress($a) ||
-                   &check_ip6address($a) ||
+               &to_ipaddress($a) || &to_ip6address($a) ||
                        &error(&text('cvirt_eaddr2', $a));
                push(@addrs, &check_ip6address($a) ? "[$a]" : $a);
                }
index 17297ac..38717bb 100755 (executable)
@@ -47,8 +47,8 @@ else {
                        local $ac = $a;
                        $ac =~ s/:(\d+)$//;
                        $ac eq '*' || $ac eq '_default_' ||
-                           gethostbyname($ac) ||
-                           $ac =~ /^\[(\S+)\]$/ && &check_ip6address("$1") ||
+                           &to_ipaddress($ac) ||
+                           $ac =~ /^\[(\S+)\]$/ && &to_ip6address("$1") ||
                                &error(&text('vserv_eaddr2', $ac));
                        }
                $addr = join(" ", @addrs);
@@ -66,9 +66,8 @@ else {
                elsif ($in{'addr'} !~ /\S/) {
                        &error($text{'vserv_eaddr1'});
                        }
-               elsif (!gethostbyname($in{'addr'}) &&
-                      !&check_ipaddress($in{'addr'}) &&
-                      !&check_ip6address($in{'addr'})) {
+               elsif (!&to_ipaddress($in{'addr'}) &&
+                      !&to_ip6address($in{'addr'})) {
                        &error(&text('vserv_eaddr2', $in{'addr'}));
                        }
                elsif (&check_ip6address($in{'addr'})) {
index 02145df..0d81c05 100755 (executable)
@@ -7,7 +7,7 @@ require './bacula-backup-lib.pl';
 $conconf = &get_bconsole_config();
 $condir = &find("Director", $conconf);
 $addr = &get_system_hostname();
-if (!gethostbyname($addr)) {
+if (!&to_ipaddress($addr) && !&to_ip6address($addr)) {
        $addr = "localhost";
        }
 &save_directive($conconf, $condir, "Address", $addr, 1);
index 1827634..8047029 100755 (executable)
@@ -59,7 +59,7 @@ if (&is_bacula_running("bacula-dir")) {
        $conconf = &get_bconsole_config();
        $condir = &find("Director", $conconf);
        $conaddr = &find_value("Address", $condir->{'members'});
-       if (!gethostbyname($conaddr)) {
+       if (!&to_ipaddress($conaddr) && !&to_ip6address($conaddr)) {
                # Offer to fix hostname
                print &text('index_econsole2',
                        "<tt>$console_cmd</tt>", "<tt>$conaddr</tt>"),"<p>\n";
index abecfd5..ec74388 100755 (executable)
@@ -45,7 +45,8 @@ else {
        $in{'pass'} || &error($text{'client_epass'});
        &save_directive($conf, $client, "Password", $in{'pass'}, 1);
 
-       gethostbyname($in{'address'}) || &error($text{'client_eaddress'});
+       &to_ipaddress($in{'address'}) || &to_ip6address($in{'address'}) ||
+               &error($text{'client_eaddress'});
        &save_directive($conf, $client, "Address", $in{'address'}, 1);
 
        $in{'port'} =~ /^\d+$/ && $in{'port'} > 0 && $in{'port'} < 65536 ||
index 98d18a7..9e47e26 100755 (executable)
@@ -45,7 +45,8 @@ else {
        $in{'pass'} || &error($text{'storage_epass'});
        &save_directive($conf, $storage, "Password", $in{'pass'}, 1);
 
-       gethostbyname($in{'address'}) || &error($text{'storage_eaddress'});
+       &to_ipaddress($in{'address'}) || &to_ip6address($in{'address'}) ||
+               &error($text{'storage_eaddress'});
        &save_directive($conf, $storage, "Address", $in{'address'}, 1);
 
        $in{'port'} =~ /^\d+$/ && $in{'port'} > 0 && $in{'port'} < 65536 ||
index 4faf170..5784a71 100755 (executable)
@@ -68,7 +68,7 @@ if ($in{'cmode'} == 0) {
        @hl || &error($text{'save_ehosts'});
        $exp{'hosts'} = \@hl;
        foreach $h (@hl) {
-               $ip = gethostbyname($h);
+               $ip = &to_ipaddress($h) || &to_ip6address($h);
                if ($ip) { push(@iplist, $ip); }
                }
        }
@@ -96,7 +96,7 @@ for($i=0; $i<@exps; $i++) {
                }
        next if (!$samefs);
        foreach $h (@{$exps[$i]->{'hosts'}}) {
-               $ip = gethostbyname($h);
+               $ip = &to_ipaddress($h) || &to_ip6address($h);
                if ($ip && &indexof($ip, @iplist) >= 0) {
                        # Another export on this filesystem is to the same host
                        &error(&text('save_esame1', $samefs, $h));
diff --git a/cluster-shutdown/save_sched.cgi b/cluster-shutdown/save_sched.cgi
new file mode 100755 (executable)
index 0000000..12a7efc
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/local/bin/perl
+# Update scheduled checking
+
+require './cluster-shutdown-lib.pl';
+&ReadParse();
+&error_setup($text{'sched_err'});
+
+# Validate and store inputs
+$job = &find_cron_job();
+if ($in{'sched'}) {
+       $in{'email'} =~ /\S/ || &error($text{'sched_eemail'});
+       $config{'email'} = $in{'email'};
+       if ($in{'smtp_def'}) {
+               delete($config{'smtp'});
+               }
+       else {
+               &to_ipaddress($in{'smtp'}) || &to_ip6address($in{'smtp'}) ||
+                       &error($text{'sched_esmtp'});
+               $config{'smtp'} = $in{'smtp'};
+               }
+       &save_module_config();
+       }
+
+# Create or delete cron job
+&cron::create_wrapper($cron_cmd, $module_name, "check.pl");
+if ($in{'sched'} && !$job) {
+       $job = { 'command' => $cron_cmd,
+                'user' => 'root',
+                'active' => 1,
+                'mins' => '*/5',
+                'hours' => '*',
+                'days' => '*',
+                'months' => '*',
+                'weekdays' => '*',
+               };
+       &cron::create_cron_job($job);
+       }
+elsif (!$in{'sched'} && $job) {
+       &cron::delete_cron_job($job);
+       }
+
+# Tell the user
+&ui_print_header(undef, $text{'sched_title'}, "");
+
+if ($in{'sched'}) {
+       print $text{'sched_enabled'},"<p>\n";
+       }
+else {
+       print $text{'sched_disabled'},"<p>\n";
+       }
+
+&ui_print_footer("", $text{'index_return'});
+
index 96c5be0..92022d5 100755 (executable)
@@ -40,7 +40,8 @@ else {
                delete($cmd->{'host'});
                }
        else {
-               gethostbyname($in{'host'}) || &error($text{'sql_ehost'});
+               &to_ipaddress($in{'host'}) ||
+                       &error($text{'sql_ehost'});
                $cmd->{'host'} = $in{'host'};
                }
        &parse_params_inputs($cmd);
index 9e9cc1e..fdf82fc 100755 (executable)
@@ -141,7 +141,8 @@ sub check_hosts
 local $h;
 if ($gconfig{'os_version'} < 7) {
        foreach $h (@_) {
-               gethostbyname($h) || &error(&text('save_ehost', $h));
+               &to_ipaddress($h) || &to_ip6address($h) ||
+                       &error(&text('save_ehost', $h));
                }
        }
 }
index 57e7947..da89e92 100755 (executable)
@@ -220,7 +220,7 @@ else {
        local $nv = $in{$_[0]};
        local @nv = split(/\s+/, $nv);
        if ($_[1] == 0) {
-               gethostbyname($nv) || &check_ipaddress($nv) ||
+               &to_ipaddress($nv) ||
                        &error("$_[0] '$nv' $text{'sopt_invalidip'}");
                }
        elsif ($_[1] == 1) {
@@ -229,7 +229,7 @@ else {
        elsif ($_[1] == 2) {
                local $ip;
                foreach $ip (@nv) {
-                       gethostbyname($ip) || &check_ipaddress($ip) ||
+                       &to_ipaddress($ip) ||
                                &error("'$ip' $text{'sopt_invalidip'}");
                        }
                $nv = join(", ", @nv);
index 563fb00..0c7bfcb 100755 (executable)
@@ -63,7 +63,7 @@ else {
        else {
                &error_setup($text{'ssub_failsave'});
                # Validate and save inputs
-               gethostbyname($in{'network'}) || &check_ipaddress($in{'network'}) ||
+               &to_ipaddress($in{'network'}) ||
                        &error("'$in{'network'}' $text{'ssub_invalidsubaddr'}");
                &check_ipaddress($in{'netmask'}) ||
                        &error("'$in{'netmask'}' $text{'ssub_invalidnmask'}");
index 9fdcd6c..3bc2f97 100755 (executable)
@@ -42,7 +42,7 @@ else {
                }
        elsif ($in{'mode'} == 3) { $exp{'host'} = ""; }
        else {
-               $in{'host'} =~ /\*/ || gethostbyname($in{'host'}) ||
+               $in{'host'} =~ /\*/ || &to_ipaddress($in{'host'}) ||
                        &error(&text('save_ehost', $in{'host'}));
                $exp{'host'} = $in{'host'};
                }
index 036ad14..67ee9d5 100755 (executable)
@@ -197,14 +197,16 @@ splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1,
 sub poll_lines
 {
 local @rv;
+local $name = $_[0]->{'poll'};
+$name = "\"$name\"" if ($name =~ /[\s:;,]/);
 if ($_[0]->{'skip'}) {
-       push(@rv, "skip $_[0]->{'poll'}");
+       push(@rv, "skip $name");
        }
 elsif ($_[0]->{'defaults'}) {
-       push(@rv, "defaults $_[0]->{'poll'}");
+       push(@rv, "defaults $name");
        }
 else {
-       push(@rv, "poll $_[0]->{'poll'}");
+       push(@rv, "poll $name");
        }
 push(@rv, "\tproto $_[0]->{'proto'}") if ($_[0]->{'proto'});
 push(@rv, "\tauth $_[0]->{'auth'}") if ($_[0]->{'auth'});
index a25b19b..0141d32 100755 (executable)
@@ -112,8 +112,8 @@ else {
 
 sub check_host
 {
-return 1 if (gethostbyname($_[0]));
-return 0 if (gethostbyname("www.webmin.com")); # only fail if we are online
+return 1 if (&to_ipaddress($_[0]) || &to_ip6address($_[0]));
+return 0 if (&to_ipaddress("www.webmin.com")); # only fail if we are online
 return 1;
 }