| Server IP : 189.126.111.107 / Your IP : 216.73.217.69 Web Server : Apache System : Linux www.gadotticar.com.br 5.4.0-135-generic #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 x86_64 User : gadotticar ( 1000) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | 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
{
local $url = "http://software.virtualmin.com/cgi-bin/ip.cgi";
local ($host, $port, $page, $ssl) = &parse_http_url($url);
local ($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'};
}
if ($config{'external_ip_cache'} ne $out) {
# Cache it for future calls
$config{'external_ip_cache'} = $out;
&save_module_config();
}
return $out;
}
# update_dynip_service()
# Talk to the configured dynamic DNS service, and return the set IP address
# and an error message (if any)
sub update_dynip_service
{
local $ip = $config{'dynip_auto'} ? &get_external_ip_address()
: &get_default_ip();
if ($config{'dynip_service'} eq 'dyndns') {
# Update DynDNS
local $host = "members.dyndns.org";
local $port = 80;
local $page = "/nic/update?".
"system=dyndns&".
"hostname=".&urlize($config{'dynip_host'})."&".
"myip=$ip&".
"wildcard=NOCHG&".
"mx=NOCHG&".
"backmx=NOCHG";
local ($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'});
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;