Server IP : 195.201.23.43 / Your IP : 3.148.109.137 Web Server : Apache System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64 User : kdecoratie ( 1041) PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/webmin/virtual-server/ |
Upload File : |
# Functions for updating a dynamic IP address # list_dynip_services() # Returns a list of supported dynamic DNS services sub list_dynip_services { return ( { 'name' => 'dyndns', 'desc' => $text{'dynip_dyndns'} }, { 'name' => 'none', 'desc' => $text{'dynip_none'} }, { 'name' => 'external', 'desc' => $text{'dynip_external'}, 'external' => 1, }, ); } # get_last_dynip_update(service) # Returns the IP last sent to this dynamic DNS service, and when it was # sent (if called in an array context) sub get_last_dynip_update { local ($service) = @_; local $file = "$module_config_directory/dynip.$service"; local $ip = &read_file_contents($file); $ip =~ s/\r|\n//g; local @st = stat($file); return wantarray ? ( $ip, $st[9] ) : $ip; } # set_last_dynip_update(service, ip) # Stores the IP that was successfully sent to the dynamic DNS service sub set_last_dynip_update { local ($service, $ip) = @_; local $file = "$module_config_directory/dynip.$service"; if ($ip) { &open_tempfile(DYNIP, ">$file"); &print_tempfile(DYNIP, $ip,"\n"); &close_tempfile(DYNIP); } else { &unlink_file($file); } } # get_external_ip_address() # Returns the IP address of this system, as seen by other hosts on the Internet. sub get_external_ip_address { my $now = time(); if ($config{'external_ip_cache'} && $now - $config{'external_ip_cache_time'} < 24*60*60) { # Can use last cached value return $config{'external_ip_cache'}; } my $url = "http://software.virtualmin.com/cgi-bin/ip.cgi"; my ($host, $port, $page, $ssl) = &parse_http_url($url); my ($out, $error); &http_download($host, $port, $page, \$out, \$error, undef, $ssl, undef, undef, 5, 0, 1); $out =~ s/\r|\n//g; if ($error) { # Fall back to last cached value return $config{'external_ip_cache'}; } # Cache it for future calls &lock_file($module_config_file); $config{'external_ip_cache'} = $out; $config{'external_ip_cache_time'} = $now; &save_module_config(); &unlock_file($module_config_file); return $out; } # update_dynip_service(new-ip, old-ip) # Talk to the configured dynamic DNS service, and return the set IP address # and an error message (if any) sub update_dynip_service { my ($ip, $oldip) = @_; if ($config{'dynip_service'} eq 'dyndns') { # Update DynDNS my $host = "members.dyndns.org"; my $port = 443; my $page = "/nic/update?". "system=dyndns&". "hostname=".&urlize($config{'dynip_host'})."&". "myip=$ip&". "wildcard=NOCHG&". "mx=NOCHG&". "backmx=NOCHG"; my ($out, $error); &http_download($host, $port, $page, \$out, \$error, undef, 0, $config{'dynip_user'}, $config{'dynip_pass'}, 10, 0, 1); if ($error =~ /401/) { return (undef, "Invalid login or password"); } elsif ($error) { return (undef, $error); } elsif ($out =~ /^(good|nochg)\s+(\S+)/) { return ($2, undef); } elsif ($out =~ /^nohost/) { return (undef, "Invalid hostname"); } else { return (undef, $out); } } elsif ($config{'dynip_service'} eq 'external') { # Just run an external script with the IP and hostname as args my $cmd = $config{'dynip_external'}." ".quotemeta($ip). " ".quotemeta($config{'dynip_host'}). " ".quotemeta($oldip); my $out = &backquote_logged("$cmd 2>&1 </dev/null"); if ($?) { return (undef, "$cmd failed : $out"); } else { return ($ip, undef); } } elsif ($config{'dynip_service'} eq 'none') { # Assume that nothing needs to be run return ($ip, undef); } else { return (undef, "Unknown dynamic IP service $config{'dynip_service'}"); } } # update_all_domain_ip_addresses(oldip, newip) # Update any virtual servers using some old IP to the new one. May print stuff. sub update_all_domain_ip_addresses { local ($ip, $oldip) = @_; local $dc = 0; foreach my $d (&list_domains()) { if (($d->{'ip'} eq $oldip || $d->{'dns_ip'} eq $oldip) && !$d->{'virt'}) { # Need to fix this server .. # Update the object local $oldd = { %$d }; $d->{'ip'} = $ip if ($d->{'ip'} eq $oldip); $d->{'dns_ip'} = $ip if ($d->{'dns_ip'} eq $oldip); # Run the before command &set_domain_envs(\%oldd, "MODIFY_DOMAIN", $d); $merr = &making_changes(); &reset_domain_envs(\%oldd); &error(&text('save_emaking', "<tt>$merr</tt>")) if (defined($merr)); # Update all features foreach my $f (@features) { local $mfunc = "modify_$f"; if ($config{$f} && $d->{$f}) { &try_function($f, $mfunc, $d, $oldd); } } foreach my $f (&list_feature_plugins()) { if ($d->{$f}) { &plugin_call($f, "feature_modify", $d, $oldd); } } # Save new domain details &$first_print($text{'save_domain'}); &save_domain($d); &$second_print($text{'setup_done'}); # Run the after command &set_domain_envs($d, "MODIFY_DOMAIN", undef, \%oldd); local $merr = &made_changes(); &$second_print(&text('setup_emade', "<tt>$merr</tt>")) if (defined($merr)); &reset_domain_envs($d); $dc++; } } return $dc; } 1;Private