/[pxelator]/lib/PXElator/html.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/html.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 307 by dpavlin, Thu Aug 27 14:31:49 2009 UTC revision 559 by dpavlin, Sat Feb 12 14:47:00 2011 UTC
# Line 1  Line 1 
1  package html;  package html;
2    
3  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
4    use amt;
5    
6  sub table {  sub table {
7          my $cols = shift;          my $cols = shift;
# Line 45  sub tt { Line 46  sub tt {
46  sub select {  sub select {
47          my $name = shift;          my $name = shift;
48          my $selected_option = shift;          my $selected_option = shift;
49            unshift @_, '' unless $selected_option;
50          return join("\n"                  return join("\n"        
51                  , qq|<select type=select name=$name>|                  , qq|<select type=select name=$name>|
52                  , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )                  , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )
53                  , qq|</select>|                  , qq|</select>|
                 , qq|</form>|  
54          );          );
55  }  }
56    
# Line 65  sub pre_dump { Line 66  sub pre_dump {
66          qq|<pre>$dump</pre>|;          qq|<pre>$dump</pre>|;
67  }  }
68    
69    sub conf {
70            my ($ip,$conf,$format) = @_;
71            my @editable = splice(@_,3);
72    
73    #       warn "# conf ",dump( $ip, $conf, $format, [ @editable ] );
74    
75            $format ||= 'inline';
76    
77            my @opts = map {
78                    my $name = $_;
79                    my $html = $conf->{$name};
80    
81                    if ( $format eq 'edit' && grep { m/^$name$/ } @editable ) {
82                            $size = length($html);
83                            ( $name, qq|<input name=$name value="$html" size=$size>| )
84                    } else {
85                            if ( $name eq 'amt' ) {
86                                    my $amt_ip = amt::ip($ip,$html);
87                                    # $html contains password!
88                                    $html = qq|<a href=http://$amt_ip:16992/logon.htm target=$amt_ip>$amt_ip</a>|;
89    
90                                    if ( $format ne 'inline' ) {
91                                            my $power = amt::power_on($ip);
92                                            $html .= qq| power: |
93                                            . ( $power
94                                                    ? qq|<a href=/amt/PowerDown/$ip title="turn off">on</a>|
95                                                    : qq|<a href=/amt/PowerUp/$ip   title="turn on" >off</a>|
96                                            );
97                                            client::conf( $ip, 'power' => $power ? 'on' : 'off' );
98                                    }
99                            } elsif ( $name eq 'ssh' ) {
100                                    $html =~ s{\s(\S{16}).+(\S{16})\s}{ $1..$2 };
101                                    chomp($html);
102                            } elsif ( $name eq 'kvm' ) {
103                                    $html = qq|<a href="/start_stop/kvm?nr=$html">$html</a>|;
104                            } elsif ( $name eq 'munin' ) {
105                                    $html = join("\n", map { my $url = $_; $url =~ s/-d\w+\.\w+$/.html/; qq|<a href="$url"><div style="float:right;overflow:hidden;width:415px;height:180px"><img src="$_" style="margin: -30px 0 0 -60px"></div></a>| } split(/\s+/s,$html));
106                            } elsif ( $name eq 'ports' ) {
107                                    $html =~ s{\b(\S+)\t(\S+)\t(\S+)\b}{<b title="$1/$2">$3</b> }gs;
108                            } else {
109                                    $html = qq|<tt>$html</tt>|;
110                            };
111                    
112                            if ( $format =~ /edit|table/ ) {
113                                    ( $name, $html );
114                            } else {
115                                    qq|<div class="config $name"><em>$name</em> $html</div>|
116                            }
117                    }
118            } grep { length($conf->{$_}) > 0 } sort keys %$conf;
119    
120            $format eq 'inline' ? join("\n", @opts) : @opts;
121    }
122    
123  warn "loaded";  warn "loaded";
124    
125  1;  1;

Legend:
Removed from v.307  
changed lines
  Added in v.559

  ViewVC Help
Powered by ViewVC 1.1.26