Compare commits

..

1 Commits

Author SHA1 Message Date
Ilia Ross
2c8ec1bfff Fix not to return short hostname unless set 2023-08-25 15:58:35 +03:00
19 changed files with 36 additions and 53 deletions

View File

@@ -120,7 +120,7 @@ if (@filters || &get_global_spamassassin()) {
# Work out nice condition and action descriptions
local $cond;
($cond, $lastalways) = &describe_condition($f);
$cond = &ui_link("edit.cgi?idx=$f->{'index'}", $cond);
$cond = &ui_link("edit.cgi?idx=$f->{'index'}", &html_escape($cond));
local $action = &describe_action($f, \@folders);
# Create mover links

View File

@@ -371,7 +371,7 @@ return &get_system_hostname();
sub save_hostname
{
&system_logged("hostname $_[0] >/dev/null 2>&1");
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -583,7 +583,7 @@ if (&has_command("hostnamectl")) {
" >/dev/null 2>&1");
}
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -583,7 +583,7 @@ my ($hostname) = @_;
&system_logged("hostname ".quotemeta($hostname)." >/dev/null 2>&1");
&save_rc_conf('hostname', $_[0]);
&unlock_file("/etc/rc.conf");
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub routing_config_files

View File

@@ -396,7 +396,7 @@ my ($hostname) = @_;
&lock_file($hostconfig);
&set_hostconfig("HOSTNAME", $hostname);
&unlock_file($hostconfig);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub routing_config_files

View File

@@ -437,7 +437,7 @@ if (&has_command("hostnamectl")) {
" >/dev/null 2>&1");
}
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -334,7 +334,7 @@ if (&has_command("hostnamectl")) {
" >/dev/null 2>&1");
}
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -131,7 +131,7 @@ local %conf;
$conf{'HOSTNAME'} = $_[0];
&write_file($network_config, \%conf);
&unlock_file($network_config);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -417,7 +417,7 @@ my ($hostname) = @_;
&open_lock_tempfile(MYNAME, ">/etc/myname");
&print_tempfile(MYNAME, $hostname,"\n");
&close_tempfile(MYNAME);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub set_line {

View File

@@ -506,7 +506,7 @@ if (&has_command("hostnamectl")) {
" >/dev/null 2>&1");
}
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -274,7 +274,7 @@ sub save_hostname
&open_lock_tempfile(HOST, ">/etc/HOSTNAME");
&print_tempfile(HOST, $_[0],"\n");
&close_tempfile(HOST);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub routing_config_files

View File

@@ -236,7 +236,7 @@ sub save_hostname
&open_lock_tempfile(HOST, ">/etc/HOSTNAME");
&print_tempfile(HOST, $_[0],"\n");
&close_tempfile(HOST);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub routing_config_files

View File

@@ -442,7 +442,7 @@ if (-r "/etc/nodename") {
&print_tempfile(NODENAME, $_[0],"\n");
&close_tempfile(NODENAME);
}
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -172,7 +172,7 @@ local %conf;
&open_lock_tempfile(HOST, ">/etc/HOSTNAME");
&print_tempfile(HOST, $_[0],"\n");
&close_tempfile(HOST);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub routing_config_files

View File

@@ -258,7 +258,7 @@ local %conf;
&open_lock_tempfile(HOST, ">/etc/HOSTNAME");
&print_tempfile(HOST, $_[0],"\n");
&close_tempfile(HOST);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub routing_config_files

View File

@@ -200,7 +200,7 @@ local $rc = &parse_rc_config();
# run SuSEconfig, as this function is called last
&system_logged("SuSEconfig -quick >/dev/null 2>&1");
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
sub routing_config_files

View File

@@ -136,7 +136,7 @@ local %conf;
$conf{'HOSTNAME'} = $_[0];
&write_env_file($network_config, \%conf);
&unlock_file($network_config);
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -314,7 +314,7 @@ return &get_system_hostname();
sub save_hostname
{
&system_logged("hostname $_[0] >/dev/null 2>&1");
&get_system_hostname(undef, undef, 2); # clear cache
undef(@main::get_system_hostname); # clear cache
}
# get_domainname()

View File

@@ -4237,36 +4237,19 @@ my $func = "${pkg}::${sub}";
return defined(&$func);
}
=head2 get_system_hostname([short], [skip-file], [nocache])
=head2 get_system_hostname([short], [skip-file])
Returns the hostname of this system. If the short parameter is set to 1 then
the domain name is not prepended - otherwise, Webmin will attempt to get the
fully qualified hostname, like foo.example.com.
If the nocache parameter is set to 1 it will flush the cache and re-read the
hostname from the system. If the nocache parameter is set to 2 it will flush
the cache and exit.
Returns the hostname of this system. If the short parameter is set to 1,
then the domain name is not prepended - otherwise, Webmin will attempt to get
the fully qualified hostname, like foo.example.com.
=cut
sub get_system_hostname
{
my ($m , $skipfile, $nocache) = @_;
$m = int($m);
state @system_hostname;
undef(@system_hostname) if ($nocache);
return if ($nocache == 2);
if (!$system_hostname[$m]) {
my $m = int($_[0]);
my $skipfile = $_[1];
if (!$main::get_system_hostname[$m]) {
if ($gconfig{'os_type'} ne 'windows') {
# Try hostnamectl command on Linux
if (&has_command("hostnamectl")) {
my $hostname =
&backquote_command("hostnamectl --static");
chop($hostname);
if ($? == 0 && $hostname =~ /\./) {
$hostname =~ s/\..*$// if ($m);
$system_hostname[$m] = $hostname;
return $hostname;
}
}
# Try some common Linux hostname files first
my $fromfile;
if ($skipfile) {
@@ -4346,25 +4329,25 @@ if (!$system_hostname[$m]) {
if ($fromfile && ($m || $fromfile =~ /\./)) {
if ($m) {
$fromfile =~ s/\..*$//;
$main::get_system_hostname[$m] = $fromfile;
}
$system_hostname[$m] = $fromfile;
return $fromfile;
}
# Can use hostname command on Unix
&execute_command("hostname", undef,
\$system_hostname[$m], undef, 0, 1);
chop($system_hostname[$m]);
\$main::get_system_hostname[$m], undef, 0, 1);
chop($main::get_system_hostname[$m]);
if ($?) {
eval "use Sys::Hostname";
if (!$@) {
$system_hostname[$m] = eval "hostname()";
$main::get_system_hostname[$m] = eval "hostname()";
}
if ($@ || !$system_hostname[$m]) {
$system_hostname[$m] = "UNKNOWN";
if ($@ || !$main::get_system_hostname[$m]) {
$main::get_system_hostname[$m] = "UNKNOWN";
}
}
elsif ($system_hostname[$m] !~ /\./ &&
elsif ($main::get_system_hostname[$m] !~ /\./ &&
$gconfig{'os_type'} =~ /linux$/ &&
!$gconfig{'no_hostname_f'} && !$_[0]) {
# Try with -f flag to get fully qualified name
@@ -4373,7 +4356,7 @@ if (!$system_hostname[$m]) {
undef, 0, 1);
chop($flag);
if (!$ex && $flag ne "") {
$system_hostname[$m] = $flag;
$main::get_system_hostname[$m] = $flag;
}
}
}
@@ -4385,14 +4368,14 @@ if (!$system_hostname[$m]) {
# Fall back to net name command
my $out = `net name 2>&1`;
if ($out =~ /\-+\r?\n(\S+)/) {
$system_hostname[$m] = $1;
$main::get_system_hostname[$m] = $1;
}
else {
$system_hostname[$m] = "windows";
$main::get_system_hostname[$m] = "windows";
}
}
}
return $system_hostname[$m];
return $main::get_system_hostname[$m];
}
=head2 get_webmin_version