Skip to content

Commit

Permalink
Merge branch 'main' into feature/network
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Oct 27, 2023
2 parents b7a7af1 + 715113a commit bd74468
Show file tree
Hide file tree
Showing 41 changed files with 3,370 additions and 499 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ log
rvd_front.conf
pkg-debian-out
public/img/screenshots
public/js/custom
yarn.lock
node_modules/
t/vm/b10*
Expand Down
76 changes: 76 additions & 0 deletions etc/missing_strings.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

my $DIR = "lib/Ravada/I18N";

my %LIST = map { $_ => 1 } @ARGV;

sub selected {
my $file = shift;
my ($name) = $file =~ m{(.*)\.\w+};

return 0 if !exists $LIST{$name};
return $LIST{$name};
}

sub load_strings {
my $file = shift;

if ($file !~ m{/}) {
$file = "$DIR/$file";
}
open my $in,"<",$file or die "$! $file";

my $msgid;
my %found;
my $string;
while (my $line = <$in>) {
my ($msgstr) = $line =~ /^msgstr/;
if ($msgstr && $string) {
$found{$string}++;
$string = undef;
next;
}
my ($string1) = $line =~ /^msgid "(.*)"/;
if (defined $string1) {
$string = $string1;
next;
}
if (!defined $string1 && defined $string) {
my ($string2) = $line =~ /^"(.*)"/;
if (defined $string2) {
$msgid=0;
$string = "$string$string2";
}
}
next if !$string;
}
close $in;
return \%found;
}

my $english = load_strings('en.po');
my $found=0;


opendir my $in,$DIR or die "$! $DIR";
while (my $file = readdir $in) {
next if $file !~ /\.po$/;
next if keys %LIST && !selected($file);
my $path = "$DIR/$file";
next if !-f $path;
print "$path\n";

my $string = load_strings($file);
for my $key (sort keys %$english) {
next if $string->{$key};
print "msgid \"$key\"\n"
."msgstr \"\"\n\n";
$found++;
}
last if $found;
}
closedir $in;
3 changes: 3 additions & 0 deletions etc/rvd_front.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@
# Insert widget in /js/custom/insert_here_widget.js
# this widget embed js in templates/bootstrap/scripts.html.ep
,widget => ''
# Content-Security-Policy HTTP response header helps you reduce XSS risks
# define custom directives. More info https://content-security-policy.com/
,security_policy => 'foo.bar.com'
};
115 changes: 99 additions & 16 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ sub _update_isos {
my $self = shift;
my $table = 'iso_images';
my $field = 'name';
my @now = localtime(time);
my $year = $now[5]+1900;
my %data = (
androidx86 => {
name => 'Android 8.1 x86'
Expand Down Expand Up @@ -788,24 +790,24 @@ sub _update_isos {
,min_disk_size => '10'
}
,kali_64 => {
name => 'Kali Linux 2022'
,description => 'Kali Linux 2022 64 Bits'
name => "Kali Linux $year"
,description => "Kali Linux $year 64 Bits"
,arch => 'x86_64'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,url => 'https://cdimage.kali.org/kali-2022.\d+/'
,file_re => 'kali-linux-202\d.\d+-installer-amd64.iso'
,url => "https://cdimage.kali.org/kali-$year".'.\d+/'
,file_re => "kali-linux-$year.".'\d+-installer-amd64.iso'
,sha256_url => '$url/SHA256SUMS'
,min_disk_size => '10'
}
,kali_64_netinst => {
name => 'Kali Linux 2022 (NetInstaller)'
,description => 'Kali Linux 2022 64 Bits (light NetInstall)'
name => "Kali Linux $year (NetInstaller)"
,description => "Kali Linux $year 64 Bits (light NetInstall)"
,arch => 'x86_64'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,url => 'https://cdimage.kali.org/kali-2022.\d+/'
,file_re => 'kali-linux-202\d.\d+-installer-netinst-amd64.iso'
,url => "https://cdimage.kali.org/kali-$year".'.\d+/'
,file_re => "kali-linux-$year.".'\d+-installer-netinst-amd64.iso'
,sha256_url => '$url/SHA256SUMS'
,min_disk_size => '10'
}
Expand Down Expand Up @@ -2568,6 +2570,59 @@ sub _sql_insert_defaults($self){
,name => 'auto_view'
,value => $conf->{auto_view}
}
,{ id_parent => $id_frontend
,name => "widget"
}
,{
id_parent => $id_frontend
,name => 'content_security_policy'
}
,{
id_parent => "/frontend/content_security_policy"
,name => "all"
,value => ''
}
,{
id_parent => "/frontend/content_security_policy"
,name => "default-src"
,value => ''
}
,{
id_parent => "/frontend/content_security_policy"
,name => "style-src"
,value => ''
}
,{
id_parent => "/frontend/content_security_policy"
,name => "script-src"
,value => ''
}
,{
id_parent => "/frontend/content_security_policy"
,name => "object-src"
,value => ''
}
,{
id_parent => "/frontend/content_security_policy"
,name => "frame-src"
,value => ''
}
,{
id_parent => "/frontend/content_security_policy"
,name => "font-src"
,value => ''
}

,{
id_parent => "/frontend/content_security_policy"
,name => "connect-src"
,value => ''
}
,{
id_parent => "/frontend/content_security_policy"
,name => "media-src"
,value => ''
}
,{
id_parent => $id_backend
,name => 'start_limit'
Expand Down Expand Up @@ -3280,6 +3335,7 @@ sub _req_add_disk($uid, $id_domain, $type, $size, $request, $storage=undef) {
,name => 'disk'
,data => $data
,@after_req
,at => time + 1
);
}
sub _start_domain_after_create($domain, $request, $uid,$previous_request) {
Expand Down Expand Up @@ -3834,7 +3890,7 @@ sub process_requests {
"pid=".($req->pid or '')." ".$req->status()
."$txt_retry "
.$req->command
." ".Dumper($req->args) if $DEBUG || $debug;
." ".Dumper($req->args) if ( $DEBUG || $debug ) && $req->command ne 'set_time';

my ($n_retry) = $req->status() =~ /retry (\d+)/;
$n_retry = 0 if !$n_retry;
Expand All @@ -3844,14 +3900,16 @@ sub process_requests {
next if !$DEBUG && !$debug;

warn ''.localtime." req ".$req->id." , cmd: ".$req->command." ".$req->status()
." , err: '".($req->error or '')."'\n" if $DEBUG || $VERBOSE;
." , err: '".($req->error or '')."'\n" if ($DEBUG || $VERBOSE )
&& $req->command ne 'set_time';
# sleep 1 if $DEBUG;

}

my @reqs2 = grep { $_->command ne 'set_time' } @reqs;
warn Dumper([map { $_->id." ".($_->pid or '')." ".$_->command." ".$_->status }
grep { $_->id } @reqs ])
if ($DEBUG || $debug ) && @reqs;
grep { $_->id } @reqs2 ])
if ($DEBUG || $debug ) && @reqs2;

return scalar(@reqs);
}
Expand Down Expand Up @@ -4492,7 +4550,7 @@ sub _wait_pids($self) {
$request->status('done') if $request->status =~ /working/i;
};
warn("$$ request id=$id_req ".$request->command." ".$request->status()
.", error='".($request->error or '')."'\n") if $DEBUG && $request;
.", error='".($request->error or '')."'\n") if $DEBUG && $request && $request->command ne 'set_time';
}
}

Expand Down Expand Up @@ -4866,14 +4924,38 @@ sub _cmd_prepare_base {
my $id_domain = $request->id_domain or confess "Missing request id_domain";
my $uid = $request->args('uid') or confess "Missing argument uid";

my $domain = $self->search_domain_by_id($id_domain);
die "Unknown domain id '$id_domain'\n" if !$domain;

my $user = Ravada::Auth::SQL->search_by_id( $uid)
or confess "Error: Unknown user id $uid in request ".Dumper($request);

my $with_cd = $request->defined_arg('with_cd');
die "User ".$user->name." [".$user->id."] not allowed to prepare base "
.$domain->name."\n"
unless $user->is_admin || (
$domain->id_owner == $user->id && $user->can_create_base());

my $domain = $self->search_domain_by_id($id_domain);

die "Unknown domain id '$id_domain'\n" if !$domain;
my $with_cd = $request->defined_arg('with_cd');

if ($domain->is_active) {
my $req_shutdown = Ravada::Request->shutdown_domain(
uid => $user->id
,id_domain => $domain->id
,timeout => 0
);
$request->after_request($req_shutdown->id);
$request->at(time + 10);
if ( !defined $request->retry() ) {
$request->retry(5);
$request->status("retry");
} elsif($request->retry>0) {
$request->retry($request->retry-1);
$request->status("retry");
}
$request->error("Machine must be shut down ".$domain->name." [".$domain->id."]");
return;
}

$self->_remove_unnecessary_request($domain);
$self->_remove_unnecessary_downs($domain);
Expand Down Expand Up @@ -6178,6 +6260,7 @@ sub _req_method {
,list_cpu_models => \&_cmd_list_cpu_models
,enforce_limits => \&_cmd_enforce_limits
,force_shutdown => \&_cmd_force_shutdown
,force_shutdown_domain => \&_cmd_force_shutdown
,force_reboot => \&_cmd_force_reboot
,shutdown_start => \&_cmd_shutdown_start
,rebase => \&_cmd_rebase
Expand Down
1 change: 1 addition & 0 deletions lib/Ravada/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use strict;
our $LDAP_OK;
our $SSO_OK;

use Data::Dumper;
use Ravada::Auth::SQL;

=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion lib/Ravada/Auth/SQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ sub add_user {
." VALUES(?,?,?,?,?,?)");
};
confess $@ if $@;
if ($password) {
if ($password && !$external_auth) {
$password = sha1_hex($password);
} else {
$password = '*LK* no pss';
Expand Down
6 changes: 6 additions & 0 deletions lib/Ravada/Auth/SSO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ sub _get_session_userid_by_ticket
my ($cookie) = @_;
my $result;
die 'Can\'t read pubkey file (sso->cookie->pub_key value at ravada.conf file)' if (! -r $$CONFIG->{sso}->{cookie}->{pub_key});

eval { $result = Authen::ModAuthPubTkt::pubtkt_verify(publickey => $$CONFIG->{sso}->{cookie}->{pub_key}, keytype => $$CONFIG->{sso}->{cookie}->{type}, ticket => $cookie); };
die $@ ? $@ : 'Cannot validate ticket' if ((! $result) || ($@));
my %data = Authen::ModAuthPubTkt::pubtkt_parse($cookie);
Expand Down Expand Up @@ -123,6 +124,11 @@ sub init {
return 0;
}
}
if (!$$CONFIG->{sso}->{cookie}->{type}) {
$ERR = "Error: missing sso / cookie / type in config file\n";
warn $ERR unless $warn++;
return 0;
}
for my $field (qw(priv_key pub_key)) {
if ( !exists $$CONFIG->{sso}->{cookie}->{$field}
|| ! $$CONFIG->{sso}->{cookie}->{$field}) {
Expand Down
13 changes: 7 additions & 6 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,9 @@ sub _around_add_volume {
($name) = $file =~ m{.*/(.*)} if !$name && $file;
$name = $self->name if !$name;

$name .= "-".$args{target}."-".Ravada::Utils::random_name(4);
$name .= "-".$args{target}."-".Ravada::Utils::random_name(4)
if $name !~ /\.iso$/;

$args{name} = $name;
}

Expand All @@ -717,10 +719,12 @@ sub _around_add_volume {
$args{allocation} = Ravada::Utils::size_to_number($args{allocation})
if exists $args{allocation} && defined $args{allocation};

my $free = $self->_vm->free_disk();
my $storage = $args{storage};

my $free = $self->_vm->free_disk($storage);
my $free_out = int($free / 1024 / 1024 / 1024 ) * 1024 *1024 *1024;

confess "Error creating volume, out of space $size . Disk free: "
die "Error creating volume, out of space $size . Disk free: "
.Ravada::Utils::number_to_size($free_out)
."\n"
if exists $args{size} && $args{size} && $args{size} >= $free;
Expand Down Expand Up @@ -1945,9 +1949,6 @@ 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)."\n".Dumper($display_info)
if !exists $display_info->{port};

return '' if !$display_info->{driver} || !$display_info->{ip}
|| !$display_info->{port};

Expand Down
Loading

0 comments on commit bd74468

Please sign in to comment.