Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Nov 9, 2022
2 parents 9222b62 + 67eb099 commit 367f2f8
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 162 deletions.
11 changes: 5 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

**Implemented enhancements:**

- Translations update Catalan, Spanish and Russian [\#1817]
- Vietnamese translation [\#1809]
- Grant open ports [\#1868]
- Show date of status change [\#1856]
- Manage USB controllers [\#1851]
- Updates on Catalan, Spanish, Russian and Vietnamese

**Refactors**

**Bugfixes**

- Admin can't change user passwords [\#1805]
- LDAP access control issue [\#1821]
- fix: parrot linux updated [\#1819]

- Clone name with name.surname [\#1843]
22 changes: 11 additions & 11 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -696,30 +696,30 @@ sub _update_isos {
,arch => 'x86_64'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,url => 'https://download.parrot.sh/parrot/iso/5.0.1/'
,file_re => 'Parrot-home-5.0.1_amd64.iso'
,url => 'https://download.parrot.sh/parrot/iso/5.1.\d+/'
,file_re => 'Parrot-home-5.1.\d+_amd64.iso'
,sha256_url => '$url/signed-hashes.txt'
,min_disk_size => '10'
}
,kali_64 => {
name => 'Kali Linux 2021'
,description => 'Kali Linux 2021 64 Bits'
name => 'Kali Linux 2022'
,description => 'Kali Linux 2022 64 Bits'
,arch => 'x86_64'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,url => 'https://cdimage.kali.org/kali-2021.\d+/'
,file_re => 'kali-linux-2021.\d+-installer-amd64.iso'
,url => 'https://cdimage.kali.org/kali-2022.\d+/'
,file_re => 'kali-linux-202\d.\d+-installer-amd64.iso'
,sha256_url => '$url/SHA256SUMS'
,min_disk_size => '10'
}
,kali_64_netinst => {
name => 'Kali Linux 2021 (NetInstaller)'
,description => 'Kali Linux 2021 64 Bits (light NetInstall)'
name => 'Kali Linux 2022 (NetInstaller)'
,description => 'Kali Linux 2022 64 Bits (light NetInstall)'
,arch => 'x86_64'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,url => 'https://cdimage.kali.org/kali-2021.\d+/'
,file_re => 'kali-linux-2021.\d+-installer-netinst-amd64.iso'
,url => 'https://cdimage.kali.org/kali-2022.\d+/'
,file_re => 'kali-linux-202\d.\d+-installer-netinst-amd64.iso'
,sha256_url => '$url/SHA256SUMS'
,min_disk_size => '10'
}
Expand Down Expand Up @@ -1360,7 +1360,7 @@ sub _remove_old_isos {
." AND ( file_re like '%20.04.1%' OR file_re like '%20.04.%d+%')"
,"DELETE FROM iso_images "
." WHERE name like 'Astra Linux 2%'"
." AND url like '%current%'"
." AND ( url like '%current%' OR url like '%orel%')"

,"DELETE FROM iso_images "
." WHERE name like 'Alpine%3.8%'"
Expand Down
20 changes: 16 additions & 4 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,12 @@ sub _set_display_ip($self, $display) {
sub _around_get_info($orig, $self) {
my $info = $self->$orig();
if (ref($self) =~ /^Ravada::Domain/ && $self->is_known()) {
$info->{ip} = $self->ip() if $self->is_active;
if ( $self->is_active
&& (!exists $info->{ip} || !defined $info->{ip} || !$info->{ip})) {
unlock_hash(%$info);
$info->{ip} = $self->ip();
lock_hash(%$info);
}
$self->_data(info => encode_json($info));
}
return $info;
Expand Down Expand Up @@ -1921,7 +1926,7 @@ sub display($self, $user) {

my ($display_info) = grep { $_->{driver} !~ /-tls$/ } @display_info;

confess "Error: I can't find builtin display info for ".$self->name." ".ref($self)
confess "Error: I can't find builtin display info for ".$self->name." ".ref($self)."\n".Dumper($display_info)
if !exists $display_info->{port};

return '' if !$display_info->{driver} || !$display_info->{ip}
Expand Down Expand Up @@ -2027,6 +2032,7 @@ sub info($self, $user) {
,autostart => $self->autostart
,volatile_clones => $self->volatile_clones
,id_vm => $self->_data('id_vm')
,date_changed => $self->_data('date_changed')
};

$info->{alias} = ( $self->_data('alias') or $info->{name} );
Expand Down Expand Up @@ -2994,8 +3000,9 @@ sub _pre_shutdown {

$self->_pre_shutdown_domain();

if ($self->is_paused) {
if ($self->is_paused || $self->is_hibernated) {
$self->resume(user => Ravada::Utils::user_daemon, set_time => 0);
$self->_data('status' => 'active');
}
$self->list_disks;
$self->_remove_start_requests();
Expand Down Expand Up @@ -3478,7 +3485,12 @@ sub _open_exposed_port($self, $internal_port, $name, $restricted) {
$sth->execute($self->id, $internal_port);
my ($id_port, $public_port) = $sth->fetchrow();

my $internal_ip = $self->ip;
my $internal_ip;
for ( 1 .. 5 ) {
$internal_ip = $self->ip;
last if $internal_ip;
sleep 1;
}
die "Error: I can't get the internal IP of ".$self->name." ".($internal_ip or '<UNDEF>').". Retry."
if !$internal_ip || $internal_ip !~ /^(\d+\.\d+)/;

Expand Down
99 changes: 72 additions & 27 deletions lib/Ravada/Domain/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3036,14 +3036,15 @@ sub _default_cpu($self) {
my ($type) = $doc->findnodes("/domain/os/type");

my $data = {
'vcpu'=> {_text => 1 , 'placement' => 'static'}
,'cpu' => { 'model' => { '_text' => 'qemu64' } }
'vcpu'=> {'#text' => 1 , 'placement' => 'static'}
,'cpu' => { 'model' => { '#text' => 'qemu64' }
}
};

my ($x86) = $type->getAttribute('arch') =~ /^x86_(\d+)/;
if ($x86) {
$data->{cpu} = { 'mode' =>'custom'
, 'model' => { '_text' => 'qemu'.$x86 } };
, 'model' => { '#text' => 'qemu'.$x86 } };
} else {
warn "I don't know default CPU for arch ".$type->getAttribute()
." in domain ".$self->name;
Expand All @@ -3054,43 +3055,63 @@ sub _default_cpu($self) {

}

sub _fix_vcpu_from_topology($self, $data) {
if (!exists $data->{cpu}->{topology}
|| !defined($data->{cpu}->{topology})) {

return;
}

if (!keys %{$data->{cpu}->{topology}}) {
$data->{cpu}->{topology} = undef;
return;
}
for (qw(dies sockets cores threads)) {
$data->{cpu}->{topology}->{$_} = 1
if !$data->{cpu}->{topology}->{$_};
}
my $dies = $data->{cpu}->{topology}->{dies} or 1;
my $sockets = $data->{cpu}->{topology}->{sockets} or 1;
my $cores = $data->{cpu}->{topology}->{cores} or 1;
my $threads = $data->{cpu}->{topology}->{threads} or 1;

delete $data->{cpu}->{topology}->{dies} if $self->_vm->_data('version') < 8000000;

$data->{vcpu}->{'#text'} = $dies * $sockets * $cores * $threads ;
}

sub _change_hardware_cpu($self, $index, $data) {
$data = $self->_default_cpu()
if !keys %$data;

$data->{'cpu'}->{'model'}->{'#text'} = 'qemu64'
if !$data->{cpu}->{'model'}->{'#text'};

delete $data->{cpu}->{model}->{'$$hashKey'};
lock_hash(%$data);

my $doc = XML::LibXML->load_xml(string => $self->xml_description);
my $count = 0;
my $changed = 0;

my ($n_vcpu) = $doc->findnodes('/domain/vcpu/text()');
if (exists $data->{vcpu} && $n_vcpu ne $data->{vcpu}->{_text}) {
my ($vcpu) = $doc->findnodes('/domain/vcpu');

$self->_fix_vcpu_from_topology($data);
lock_hash(%$data);

my ($vcpu) = $doc->findnodes('/domain/vcpu');
if (exists $data->{vcpu} && $n_vcpu ne $data->{vcpu}->{'#text'}) {
$vcpu->removeChildNodes();
$vcpu->appendText($data->{vcpu}->{_text});
$vcpu->appendText($data->{vcpu}->{'#text'});
}
my ($domain) = $doc->findnodes('/domain');
my ($cpu) = $doc->findnodes('/domain/cpu');
if (!$cpu) {
my ($domain) = $doc->findnodes('/domain');
$cpu = $domain->addNewChild(undef,'cpu');
}
my $feature = delete $data->{cpu}->{feature};

for my $field (keys %{$data->{cpu}}) {
if (ref($data->{cpu}->{$field})) {
_change_xml($cpu, $field, $data->{cpu}->{$field});
$changed++;
next;
}
$changed += _change_xml($domain, 'cpu', $data->{cpu});

if ( !defined $cpu->getAttribute($field)
|| $cpu->getAttribute($field) ne $data->{cpu}->{$field}) {
$cpu->setAttribute($field, $data->{cpu}->{$field});
$changed++;
}
}
if ( $feature ) {
_change_xml_list($cpu, 'feature', $feature, 'name');
$changed++;
Expand Down Expand Up @@ -3260,22 +3281,46 @@ sub _change_xml($xml, $name, $data) {
confess Dumper([$name, $data])
if !ref($data) || ( ref($data) ne 'HASH' && ref($data) ne 'ARRAY');

my ($node) = $xml->findnodes($name);
$node = $xml->addNewChild(undef,$name) if !$node;
my $changed = 0;

my $text = delete $data->{_text};
if ($text) {
$node->removeChildNodes();
$node->appendText($text);
my ($node) = $xml->findnodes($name);
if (!$node) {
$node = $xml->addNewChild(undef,$name);
$changed++;
}

for my $field (keys %$data) {
if ($field eq '#text') {
my $text = $data->{$field};
if ($node->textContent ne $text) {
$node->setText($text);
}
next;
}
if (!defined $data->{$field}) {
my ($child) = $node->findnodes($field);
$node->removeChild($child) if $child;
next;
}
if (ref($data->{$field})) {
_change_xml($node,$field,$data->{$field});
$changed += _change_xml($node,$field,$data->{$field});
} else {
next if defined $node->getAttribute($field)
&& $node->getAttribute($field) eq $data->{$field};

$node->setAttribute($field, $data->{$field});
$changed++;
}
}
for my $child ( $node->childNodes() ) {
my $name = $child->nodeName();
if (!exists $data->{$name} || !defined $data->{$name} ) {
$node->removeChild($child);
$changed++;
}
}

return $changed;
}

sub _change_hardware_network($self, $index, $data) {
Expand Down
37 changes: 28 additions & 9 deletions lib/Ravada/Domain/Void.pm
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ sub start($self, @args) {
my $password;
$password = Ravada::Utils::random_name() if $set_password;
$self->_set_displays_ip( $password, $listen_ip );
$self->_set_ip_address();

}

sub _set_ip_address($self) {
return if !$self->is_active;

my $hardware = $self->_value('hardware');
my $changed = 0;
for my $net (@{$hardware->{network}}) {
next if !ref($net);
next if exists $net->{address} && $net->{address};
next if $net->{type} ne 'nat';
$net->{address} = '198.51.100.'.int(rand(253)+2);
$changed++;
}
$self->_store('hardware' => $hardware) if $changed;

}

Expand Down Expand Up @@ -688,6 +705,7 @@ sub get_info {
if (!$info->{memory}) {
$info = $self->_set_default_info();
}
$info->{ip} = $self->ip;
lock_keys(%$info);
return $info;
}
Expand All @@ -706,7 +724,6 @@ sub _set_default_info($self, $listen_ip=undef) {
,cpu_time => 1
,n_virt_cpu => 1
,state => 'UNKNOWN'
,ip =>'1.1.1.'.int(rand(254)+1)
,mac => _new_mac()
,time => time
};
Expand Down Expand Up @@ -808,16 +825,18 @@ sub disk_size {

sub ip {
my $self = shift;
my $info = $self->_value('info');
my $ip = $info->{ip};
return $ip if $ip;
my $hardware = $self->_value('hardware');
return if !exists $hardware->{network};
for ( 1 .. 2 ) {
for my $network(@{$hardware->{network}}) {
return $network->{address}
if $network->{address};
}

$self->_set_default_info();
$info = $self->_value('info');
$ip = $info->{ip};
confess if !$ip;
$self->_set_ip_address();
}

return $ip;
return;
}

sub clean_disk($self, $file) {
Expand Down
7 changes: 5 additions & 2 deletions lib/Ravada/Front/Domain/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,13 @@ sub _sort_xml_list($list, $field) {
sub _xml_elements($xml, $item) {
return {} if !defined $xml;
my $text = $xml->textContent;
$item->{_text} = $text if $text && $text !~ /\n/m;
$text = 0+$text if $text =~ /^\d+$/;
$item->{'#text'} = $text if $text && $text !~ /\n/m;

for my $attribute ( $xml->attributes ) {
$item->{$attribute->name} = $attribute->value;
my $value = $attribute->value;
$value = 0+$value if $value=~ /^\d+$/;
$item->{$attribute->name} = $value;
}

for my $node ( $xml->findnodes('*') ) {
Expand Down
5 changes: 2 additions & 3 deletions lib/Ravada/WebSocket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ sub _list_alerts($rvd, $args) {
my @ret2;
for my $alert (@$ret_old) {
push @ret2,($alert) if time - $alert->{time} < 10
&& ! grep {defined $_->{id_request}
&& defined $alert->{id_request}
&& $_->{id_request} == $alert->{id_request} } @ret;
&& ! grep {defined $_->{id_request} && defined $alert->{id_request}
&& $_->{id_request} == $alert->{id_request} } @ret;
}

return [@ret2,@ret];
Expand Down
6 changes: 6 additions & 0 deletions public/css/sb-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,9 @@ span.info {
color: darkgray;
font-style: italic;
}

.disabled {
color: darkgray;
cursor: not-allowed;
}

Loading

0 comments on commit 367f2f8

Please sign in to comment.