/[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

Annotation of /lib/PXElator/html.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 560 - (hide annotations)
Sat Feb 12 14:54:42 2011 UTC (10 years, 8 months ago) by dpavlin
File size: 3118 byte(s)
float munin graphs to left
1 dpavlin 43 package html;
2    
3 dpavlin 180 use Data::Dump qw/dump/;
4 dpavlin 376 use amt;
5 dpavlin 180
6 dpavlin 43 sub table {
7     my $cols = shift;
8 dpavlin 172 my $th;
9    
10     if ( $cols < 0 ) {
11     $cols = abs($cols);
12     $th .= qq|<th>| . shift(@_) . qq|</td>| foreach ( 1 .. $cols );
13     $th .= qq|</tr>\n<tr>|;
14     }
15    
16 dpavlin 43 my @td = map { "<td>$_</td>" } @_;
17 dpavlin 172 my $html = qq{<table>\n<tr>$th};
18 dpavlin 307 my $row = 0;
19    
20 dpavlin 43 foreach ( 0 .. $#td ) {
21     $html .= $td[$_];
22 dpavlin 307 if ( ( $_ + 1 ) % $cols == 0 ) {
23     $zebra = $row++ % 2 == 0 ? qq{ style="background: #eee"} : '';
24     $html .= qq{</tr>\n<tr$zebra>};
25     };
26 dpavlin 43 }
27     $html .= qq{</tr>\n</table>};
28     }
29    
30 dpavlin 72 sub tabs {
31     return unless @_;
32     my $html = qq{<table border=1>\n<tr>};
33     foreach my $row ( @_ ) {
34     $row =~ s{\t}{</td><td>}g;
35     $html .= qq|<tr><td>$row</td><tr>\n|;
36     }
37     $html .= qq|</table>|;
38     return $html;
39     }
40    
41    
42 dpavlin 64 sub tt {
43 dpavlin 188 qq|<tt>| . join(' ', @_) . qq|</tt>| if @_;
44 dpavlin 64 }
45    
46 dpavlin 153 sub select {
47     my $name = shift;
48 dpavlin 161 my $selected_option = shift;
49 dpavlin 315 unshift @_, '' unless $selected_option;
50 dpavlin 153 return join("\n"
51     , qq|<select type=select name=$name>|
52 dpavlin 161 , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )
53 dpavlin 153 , qq|</select>|
54     );
55     }
56    
57 dpavlin 188 sub pre {
58     qq|<pre>| . join(' ', @_) . qq|</pre>| if @_;
59     }
60    
61 dpavlin 180 sub pre_dump {
62     my $data = shift;
63     my $dump = dump( $data );
64 dpavlin 182 $dump =~ s{"([^"]+)"(\s*=>)}{$1 $2}gs;
65 dpavlin 187 $dump =~ s{"([^"]*)"}{"<b>$1</b>"}gs;
66 dpavlin 180 qq|<pre>$dump</pre>|;
67     }
68    
69 dpavlin 346 sub conf {
70     my ($ip,$conf,$format) = @_;
71     my @editable = splice(@_,3);
72    
73 dpavlin 420 # warn "# conf ",dump( $ip, $conf, $format, [ @editable ] );
74 dpavlin 346
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 dpavlin 380 my $amt_ip = amt::ip($ip,$html);
87 dpavlin 435 # $html contains password!
88     $html = qq|<a href=http://$amt_ip:16992/logon.htm target=$amt_ip>$amt_ip</a>|;
89 dpavlin 376
90 dpavlin 380 if ( $format ne 'inline' ) {
91     my $power = amt::power_on($ip);
92     $html .= qq| power: |
93     . ( $power
94 dpavlin 376 ? qq|<a href=/amt/PowerDown/$ip title="turn off">on</a>|
95     : qq|<a href=/amt/PowerUp/$ip title="turn on" >off</a>|
96 dpavlin 380 );
97     client::conf( $ip, 'power' => $power ? 'on' : 'off' );
98     }
99 dpavlin 354 } elsif ( $name eq 'ssh' ) {
100     $html =~ s{\s(\S{16}).+(\S{16})\s}{ $1..$2 };
101 dpavlin 361 chomp($html);
102 dpavlin 404 } elsif ( $name eq 'kvm' ) {
103     $html = qq|<a href="/start_stop/kvm?nr=$html">$html</a>|;
104 dpavlin 521 } elsif ( $name eq 'munin' ) {
105 dpavlin 560 $html = join("\n", map { my $url = $_; $url =~ s/-d\w+\.\w+$/.html/; qq|<a href="$url"><div style="float:left;overflow:hidden;width:415px;height:180px"><img src="$_" style="margin: -30px 0 0 -60px"></div></a>| } split(/\s+/s,$html));
106 dpavlin 557 } 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 dpavlin 346
112     if ( $format =~ /edit|table/ ) {
113     ( $name, $html );
114     } else {
115 dpavlin 389 qq|<div class="config $name"><em>$name</em> $html</div>|
116 dpavlin 346 }
117     }
118 dpavlin 386 } grep { length($conf->{$_}) > 0 } sort keys %$conf;
119 dpavlin 346
120     $format eq 'inline' ? join("\n", @opts) : @opts;
121     }
122    
123 dpavlin 45 warn "loaded";
124    
125 dpavlin 43 1;

  ViewVC Help
Powered by ViewVC 1.1.26