added client hostname and deploy of configuration over web
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 5 Aug 2009 23:22:17 +0000 (23:22 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 5 Aug 2009 23:22:17 +0000 (23:22 +0000)
lib/PXElator/config.pm
lib/PXElator/dhcpd.pm
lib/PXElator/html.pm
lib/PXElator/httpd.pm
lib/PXElator/pxelinux.pm
lib/PXElator/server.pm
lib/PXElator/t/html.t

index 7e717ad..68aad52 100644 (file)
@@ -8,6 +8,8 @@ use server;
 use pxelinux;
 use File::Slurp;
 
+sub available { qw/debian_live webconverger debirf tinycore/ };
+
 sub debian_live {
        $dhcpd::file = "pxelinux.0";
        $pxelinux::path_prefix = 'live-helper/tftpboot/';
@@ -25,18 +27,19 @@ L<http://webconverger.org/>
 =cut
 
 sub webconverger {
-       my ($ip,$append) = @_;
+       my ($ip) = @_;
 
        upstream::iso( 'http://download.webconverger.com/webc-5.2.iso' );
 
-       $append ||= 'homepage=http://' . $server::ip . ':7777';
+       my $homepage = server::shared( "$ip/homepage" ) || "http://${server::ip}:7777/client";
+       my $hostname = server::shared( "$ip/hostname" ) || 'webconverger';
 
        pxelinux::config_for_ip( $ip, qq{
 
 default webconverger
 label webconverger
        kernel iso/live/vmlinuz-2.6.30-backports.1-486
-       append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=http://172.16.10.1:7777/webconverger/iso/live/filesystem.squashfs boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=webconverger union=aufs $append
+       append initrd=iso/live/initrd.img-2.6.30-backports.1-486 fetch=http://172.16.10.1:7777/webconverger/iso/live/filesystem.squashfs boot=live quiet nosudo splash video=vesa:ywrap,mtrr vga=788 nopersistent username=webc hostname=$hostname union=aufs homepage=$homepage
 
        });
 
index 6c3c4b8..2934aaf 100644 (file)
@@ -49,8 +49,6 @@ sub client_ip {
                return $ip;
        }
 
-       mkdir $_ foreach grep { ! -e $_ } map { "$conf/$_" } ( 'ip', 'mac' );
-
        my $p = Net::Ping->new;
 
        my $prefix = $server::ip;
index 6ac4df3..857f923 100644 (file)
@@ -27,6 +27,17 @@ sub tt {
        qq|<tt>| . join(' ', @_) . qq|</tt>|;
 }
 
+sub select {
+       my $name = shift;
+       my $checked_option = shift;
+       return join("\n"        
+               , qq|<select type=select name=$name>|
+               , join("\n", map { my $checked = $_ eq $checked_option ? 'checked' : ''; qq|<option name=$_ $checked>$_</option>| } @_ )
+               , qq|</select>|
+               , qq|</form>|
+       );
+}
+
 warn "loaded";
 
 1;
index d0d61df..b9e42a3 100644 (file)
@@ -23,6 +23,7 @@ sub menu {qq{
 <div style="font-size: 80%; color: #888">
 <a href=/>home</a>
 <a href=/server>server</a>
+<a href=/client>client</a>
 </div>
 
 }}
@@ -47,6 +48,7 @@ our $url = "http://$server::ip:$port";
 use html;
 our $static_pids;
 use progress_bar;
+use config;
 
 sub static {
        my ($client,$path) = @_;
@@ -222,6 +224,22 @@ sub get_request {
                        , menu()
                        , html::table( 2, map { ( $_, eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir' ) )
                        ;
+       } elsif ( $path =~ m{^/client} ) {
+               my $ip = $client->peerhost;
+               my $hostname = server::shared( "hostname/$ip", $param->{hostname} );
+               my $deploy   = server::shared( "deploy/$ip",   $param->{deploy}   );
+               print $client $ok
+                       , menu()
+                       , qq|<form method=get>|
+                       , html::table( 2,
+                               'ip' => $ip,
+                               'hostname' => qq|<input type=text name=hostname value=$hostname>|,
+                               'deploy' => html::select( 'deploy', $deploy, config::available ),
+                       )
+                       , qq|<input type=submit value=change></form><pre>|
+                       , config::for_ip( $ip )
+                       , qq|</pre>|
+                       ;
        } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
                eval 'our $' . $1 . ' = ' . $2;
                warn $@ if $@;
index 2837db2..c9b88bf 100644 (file)
@@ -41,7 +41,7 @@ sub config_for_ip {
 
        warn "# config: $path ", -s $path;
 
-
+       return $config;
 }
 
 1;
index 67f1367..e8674e8 100644 (file)
@@ -16,6 +16,8 @@ our $base_dir = '/srv/pxelator';
 use Module::Refresh qw//;
 sub refresh { Module::Refresh->refresh };
 
+mkdir $_ foreach grep { ! -e $_ } map { "$base_dir/conf/$server::ip/$_" } ( 'ip', 'mac', 'hostname', 'deploy' );
+
 use File::Slurp;
 sub shared {
        my ($name, $value) = @_;
@@ -23,6 +25,7 @@ sub shared {
        my $path ="$base_dir/conf/$server::ip/$name";
        if ( defined $value ) {
                write_file $path, $value;
+               warn "update $path = $value";
        } else {
                $value = read_file $path if -e $path;
        }
index 4bac0c4..289de0b 100755 (executable)
@@ -4,10 +4,12 @@ use warnings;
 use strict;
 use autodie;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 
 use_ok 'html';
 
 ok( my $html = html::table( 2, qw/a1 a2 b1 b2 c1 c2/ ), 'table' );
 diag $html;
 
+ok( $html = html::select( 'dropdown', 2, 1, 2, 3 ), 'select' );
+diag $html;