Commit a0a8b13f authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Manage bases from the web frontend

parent 633532d4
......@@ -6,6 +6,7 @@ use Carp qw(confess);
use Data::Dumper;
use DBIx::Connector;
use Getopt::Long;
use Hash::Util qw(lock_hash);
use Mojolicious::Lite;
use YAML qw(LoadFile);
......@@ -73,6 +74,7 @@ sub login {
if ( $login && $password ) {
if (Ravada::Auth::login($login, $password)) {
$c->session('login' => $login);
return quick_start($c);
} else {
push @error,("Access denied");
}
......@@ -131,8 +133,24 @@ get '/ip/*' => sub {
show_link($c,base_id($base_name),$ip);
};
any '/bases' => sub {
my $c = shift;
return access_denied($c) if !_logged_in($c);
my @error = ();
$c->render(template => 'bootstrap/new_base'
,image => _list_images()
,error => \@error
);
};
#######################################################
sub access_denied {
my $c = shift;
$c->render(data => "Access denied");
}
sub base_id {
my $name = shift;
......@@ -282,6 +300,23 @@ sub list_bases {
return \%base;
}
sub _list_images {
my $dbh = $CON->dbh();
my $sth = $dbh->prepare(
"SELECT * FROM iso_images"
." ORDER BY name"
);
$sth->execute;
my %image;
while ( my $row = $sth->fetchrow_hashref) {
$image{$row->{id}} = $row;
}
$sth->finish;
lock_hash(%image);
return \%image;
}
sub _init_db {
my $db_user = ($CONFIG->{db}->{user} or getpwnam($>));;
my $db_password = ($CONFIG->{db}->{password} or undef);
......
......@@ -17,6 +17,14 @@
% if (! $_logged_in ) {
<li><a href="/login">Login</a></li>
% } else {
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Tools <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="/bases">Bases</a></li>
<li><a href="/nodes">Nodes</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><%= $_logged_in %> <span class="caret"></span></a>
<ul class="dropdown-menu">
......
<!DOCTYPE html>
<html>
%= include 'bootstrap/header'
<body role="document">
%= include 'bootstrap/navigation'
<div class="container theme-showcase" role="main">
<div class="jumbotron">
<h2>New Base</h2>
<form method="post">
<input type="text" size="20" name=""><br/>
% if (keys %$image) {
boot CD: <select name="id_image">
% for my $option (sort keys %$image) {
<option value="<%= $option %>"><%= $image->{$option}->{name} %></option>
% }
</select><br/>
% } else {
<b>Error :</b> No base ISO Images available.
% }
Backend:<br/>
<input type="radio" name="backend value="kvm">kvm</input><br/>
<input type="radio" name="backend value="lxc">lxc</input><br/>
Disk: <input type="text" name="disk" size="2" value="8">Gb<br/>
Ram: <input type="text" name="ram" size="2" value="2">Gb<br/>
<input type="submit" name="submit" value="create">
</form>
% if (scalar @$error) {
<ul>
% for my $i (@$error) {
<li><%= $i %></li>
% }
</ul>
% }
</div>
</div>
%= include 'bootstrap/scripts'
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment