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

Contents of /lib/PXElator/html.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 380 - (show annotations)
Sun Aug 30 16:36:37 2009 UTC (13 years, 5 months ago) by dpavlin
File size: 2675 byte(s)
seems like cleanup, but is really amt information improvement
especially power state

1 package html;
2
3 use Data::Dump qw/dump/;
4 use amt;
5
6 sub table {
7 my $cols = shift;
8 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 my @td = map { "<td>$_</td>" } @_;
17 my $html = qq{<table>\n<tr>$th};
18 my $row = 0;
19
20 foreach ( 0 .. $#td ) {
21 $html .= $td[$_];
22 if ( ( $_ + 1 ) % $cols == 0 ) {
23 $zebra = $row++ % 2 == 0 ? qq{ style="background: #eee"} : '';
24 $html .= qq{</tr>\n<tr$zebra>};
25 };
26 }
27 $html .= qq{</tr>\n</table>};
28 }
29
30 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 sub tt {
43 qq|<tt>| . join(' ', @_) . qq|</tt>| if @_;
44 }
45
46 sub select {
47 my $name = shift;
48 my $selected_option = shift;
49 unshift @_, '' unless $selected_option;
50 return join("\n"
51 , qq|<select type=select name=$name>|
52 , join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ )
53 , qq|</select>|
54 , qq|</form>|
55 );
56 }
57
58 sub pre {
59 qq|<pre>| . join(' ', @_) . qq|</pre>| if @_;
60 }
61
62 sub pre_dump {
63 my $data = shift;
64 my $dump = dump( $data );
65 $dump =~ s{"([^"]+)"(\s*=>)}{$1 $2}gs;
66 $dump =~ s{"([^"]*)"}{"<b>$1</b>"}gs;
67 qq|<pre>$dump</pre>|;
68 }
69
70 sub conf {
71 my ($ip,$conf,$format) = @_;
72 my @editable = splice(@_,3);
73
74 warn "# conf ",dump( $ip, $conf, $format, [ @editable ] );
75
76 $format ||= 'inline';
77
78 my @opts = map {
79 my $name = $_;
80 my $html = $conf->{$name};
81
82 if ( $format eq 'edit' && grep { m/^$name$/ } @editable ) {
83 $size = length($html);
84 ( $name, qq|<input name=$name value="$html" size=$size>| )
85 } else {
86 if ( $name eq 'amt' ) {
87 my $amt_ip = amt::ip($ip,$html);
88 $html = qq|<a title="$html" 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 }
103 $html = qq|<pre style="display: inline">$html</pre>|
104 unless
105 $html =~ s{\b(\S+)\t(\S+)\t(\S+)\b}{<b title="$1/$2">$3</b> }gs;
106
107 if ( $format =~ /edit|table/ ) {
108 ( $name, $html );
109 } else {
110 qq|<em>$name</em> $html<br>|
111 }
112 }
113 } sort keys %$conf;
114
115 $format eq 'inline' ? join("\n", @opts) : @opts;
116 }
117
118 warn "loaded";
119
120 1;

  ViewVC Help
Powered by ViewVC 1.1.26