ui-lib conversion
authorJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 18:58:06 +0000 (18:58 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 28 Dec 2007 18:58:06 +0000 (18:58 +0000)
man/CHANGELOG
man/index.cgi
man/man-lib.pl
man/view_doc.cgi
man/view_howto.cgi
man/view_kde.cgi
man/view_kernel.cgi
man/view_man.cgi
man/view_perl.cgi

index 931ab7f..161d7b4 100644 (file)
@@ -1,2 +1,3 @@
----- Changes since 1.150 ----
-
+---- Changes since 1.390 ----
+Updated all code that generates HTML to use the new Webmin UI library.
+General code cleanups and support for images in documentation files.
index e8c5e4c..1c52314 100755 (executable)
@@ -34,53 +34,47 @@ if (-d $config{'custom_dir'}) {
 push(@search, "google");
 
 # display the search form
-print "<form action=search.cgi>\n";
-print "<table border>\n";
-print "<tr $tb> <td><b>$text{'index_header'}</b></td> </tr>\n";
-print "<tr $cb> <td><table>\n";
+print &ui_form_start("search.cgi");
+print &ui_table_start($text{'index_header'}, undef, 2);
 
-print "<tr> <td><b>$text{'index_for'}</b></td>\n";
-print "<td><input name=for size=30></td> </tr>\n";
+# Search box and boolean mode
+print &ui_table_row($text{'index_for'},
+       &ui_textbox("for", undef, 50)."<br>".
+       &ui_radio("and", 1, [ [ 1, $text{'index_and'} ],
+                             [ 0, $text{'index_or'} ] ]));
 
-print "<tr> <td></td>\n";
-print "<td><input type=radio name=and value=1 checked> $text{'index_and'}\n";
-print "<input type=radio name=and value=0> $text{'index_or'}</td> </tr>\n";
+# Exact match
+print &ui_table_row($text{'index_type'},
+       &ui_radio("exact", 1, [ [ 1, $text{'index_name'} ],
+                               [ 0, $text{'index_data'} ] ]));
 
-print "<tr> <td><b>$text{'index_type'}</b></td>\n";
-print "<td><input type=radio name=exact value=1 checked> $text{'index_name'}\n";
-print "<input type=radio name=exact value=0> $text{'index_data'}</td> </tr>\n";
-
-print "<tr> <td valign=top><b>$text{'index_where'}</b></td> <td>\n";
+# Sections to search
+$sects = "";
 foreach $s (@search) {
        $txt = $text{"index_${s}"};
        $txt = $config{'custom_desc'}
                if ($s eq "custom" && $config{'custom_desc'});
-       printf "<input type=checkbox name=section value=%s %s> %s<br>\n",
-               $s, $s eq 'man' ? 'checked' : '', $txt;
+       $sects .= &ui_checkbox("section", $s, $txt, $s eq 'man')."<br>\n";
        }
-print "</td> </tr>\n";
+print &ui_table_row($text{'index_where'}, $sects);
 
-print "<tr> <td colspan=2 align=right>",
-      "<input type=submit value=\"$text{'index_search'}\">\n",
-      "<input type=reset value=\"$text{'index_reset'}\"></td> </tr>\n";
-print "</table></td></tr></table></form>\n";
+print &ui_table_end();
+print &ui_form_end([ [ undef, $text{'index_search'} ] ]);
 
+# Form to control search from other modules
 if (!$module_info{'usermin'}) {
        @check = $config{'check'} ? split(/\s+/, $config{'check'}) : @search;
        print "<hr>\n";
-       print "<form action=save_check.cgi>\n";
-       printf "<input type=hidden name=count value=%d>\n", scalar(@search);
+       print &ui_form_start("save_check.cgi");
+       print &ui_hidden("count", scalar(@search));
        print "<b>$text{'index_others'}</b><br>\n";
-       print "<table width=100%>\n";
+       @grid = ( );
        foreach $s (@search) {
-               print "<tr>\n" if ($c % 3 == 0);
-               printf "<td><input type=checkbox name=check value=%s %s> %s</td>\n",
-                       $s, &indexof($s, @check) >= 0 ? 'checked' : '', 
-                       $text{"index_other_${s}"};
-               print "<tr>\n" if ($c++ % 3 == 2);
+               push(@grid, &ui_checkbox("check", $s, $text{"index_other_${s}"},
+                                        &indexof($s, @check) >= 0));
                }
-       print "</table>\n";
-       print "<input type=submit value='$text{'save'}'></form>\n";
+       print &ui_grid_table(\@grid, 3);
+       print &ui_form_end([ [ undef, $text{'save'} ] ]);
        }
 
 &ui_print_footer("/", $text{'index'});
index a3d3313..82e4bf8 100644 (file)
@@ -32,5 +32,15 @@ $ENV{'MANPATH'} = join(":", split(/:/, $config{'man_dir'}),
                            "/usr/share/man");
 }
 
+# show_view_table(heading, html)
+# Prints a block showing the contents of a documentation page
+sub show_view_table
+{
+local ($heading, $html) = @_;
+print &ui_table_start($heading, "width=100%", 2);
+print &ui_table_row(undef, $html, 2);
+print &ui_table_end();
+}
+
 1;
 
index 7aaa344..86b0d26 100755 (executable)
@@ -5,15 +5,14 @@
 require './man-lib.pl';
 &ReadParse();
 
-$in{'file'} !~ /\.\./ ||
-       &error($text{'doc_epath'});
+$in{'file'} = &simplify_path($in{'file'});
 $in{'file'} !~ /[\\\&\;\`\'\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
        &error($text{'doc_epath'});
 foreach $d (split(/\s+/, $config{'doc_dir'})) {
-       $ok++ if (substr($in{'file'}, 0, length($d)) eq $d);
+       $ok++ if (&is_under_directory($d, $in{'file'}));
        }
-$ok++ if ($config{'custom_dir'} && substr($in{'file'}, 0,
-               length($config{'custom_dir'})) eq $config{'custom_dir'});
+$ok++ if ($config{'custom_dir'} &&
+         &is_under_directory($config{'custom_dir'}, $in{'file'}));
 $ok || &error($text{'doc_epath'});
 if (!-r $in{'file'}) {
        if (-r "$in{'file'}.gz") {
@@ -24,11 +23,17 @@ if (!-r $in{'file'}) {
                }
        }
 
+# Just output if this is an image
+$mt = &guess_mime_type($in{'file'});
+if ($mt =~ /^image\//) {
+       print "Content-type: $mt\r\n\r\n";
+       print &read_file_contents($in{'file'});
+       exit;
+       }
+
 &ui_print_header(undef, $text{'doc_title'}, "");
 
-print "<table border width=100%>\n";
-print "<tr $tb> <td><b>",&text('doc_header', $in{'file'}),"</b></td> </tr>\n";
-print "<tr $cb> <td>";
+# Work out compression format
 open(FILE, $in{'file'});
 read(FILE, $two, 2);
 $qm = quotemeta($in{'file'});
@@ -41,19 +46,21 @@ elsif ($two eq "BZ") {
        &open_execute_command(FILE, "bunzip2 -c $qm", 1, 1);
        }
 seek(FILE, 0, 0);
+
+$out = "";
 if ($in{'file'} =~ /\.htm/i) {
        # Display HTML documentation
        ($dir = $in{'file'}) =~ s/\/[^\/]+$//;
        while($line = <FILE>) {
-               $line =~ s/href="([^"#][^"]*)"/href="view_doc.cgi?file=$dir\/$1"/ig;
-               $line =~ s/href='([^'#][^']*)'/href='view_doc.cgi?file=$dir\/$1'/ig;
-               $line =~ s/href=([^'"\s#][^'"\s>]*)/href='view_doc.cgi?file=$dir\/$1'/ig;
-               print $line;
+               $line =~ s/(href|src)="([^"#][^"]*)"/$1="view_doc.cgi?file=$dir\/$2"/ig;
+               $line =~ s/(href|src)='([^'#][^']*)'/$1='view_doc.cgi?file=$dir\/$2'/ig;
+               $line =~ s/(href|src)=([^'"\s#][^'"\s>]*)/$1='view_doc.cgi?file=$dir\/$2'/ig;
+               $out .= $line;
                }
        }
 else {
        # Display text file
-       print "<pre>";
+       $out .= "<pre>";
        @for = split(/\s+/, $in{'for'});
        while($line = <FILE>) {
                $line =~ s/.\010//g;
@@ -61,12 +68,12 @@ else {
                foreach $f (@for) {
                        $line =~ s/($f)/<b>$1<\/b>/ig;
                        }
-               print $line;
+               $out .= $line;
                }
-       print "</pre>";
+       $out .= "</pre>";
        }
 close(FILE);
-print "</td></tr></table><p>\n";
+&show_view_table(&text('doc_header', $in{'file'}), $out);
 
 &ui_print_footer("", $text{'index_return'});
 
index 6d290f4..c4b5526 100755 (executable)
@@ -5,21 +5,18 @@
 require './man-lib.pl';
 &ReadParse();
 
-$in{'file'} !~ /\.\./ ||
-       &error($text{'howto_epath'});
+$in{'file'} = &simplify_path($in{'file'});
 $in{'file'} !~ /[\\\&\;\`\'\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
        &error($text{'howto_epath'});
 foreach $h (split(/\s+/, $config{'howto_dir'})) {
-       $ok++ if (substr($in{'file'}, 0, length($h)) eq $h);
+       $ok++ if (&is_under_directory($h, $in{'file'}));
        }
 $ok || &error($text{'howto_epath'});
 -r $in{'file'} || &error($text{'howto_epath'});
 
 &ui_print_header(undef, $text{'howto_title'}, "");
 
-print "<table border width=100%>\n";
-print "<tr $tb> <td><b>",&text('howto_header', $in{'file'}),"</b></td> </tr>\n";
-print "<tr $cb> <td><pre>";
+# Work out compression format
 open(FILE, $in{'file'});
 read(FILE, $two, 2);
 $qm = quotemeta($in{'file'});
@@ -32,6 +29,8 @@ elsif ($two eq "BZ") {
        &open_execute_command(FILE, "bunzip2 -c $qm", 1, 1);
        }
 seek(FILE, 0, 0);
+
+$out = "<pre>";
 @for = split(/\s+/, $in{'for'});
 while($line = <FILE>) {
        $line = &html_escape($line);
@@ -39,10 +38,11 @@ while($line = <FILE>) {
                $line =~ s/.\010//g;
                $line =~ s/($f)/<b>$1<\/b>/ig;
                }
-       print $line;
+       $out .= $line;
        }
 close(FILE);
-print "</pre></td></tr></table><p>\n";
+$out .= "</pre>";
+&show_view_table(&text('howto_header', $in{'file'}), $out);
 
 &ui_print_footer("", $text{'index_return'});
 
index 61306b9..869d8f1 100755 (executable)
@@ -5,33 +5,23 @@
 require './man-lib.pl';
 &ReadParse();
 
-$in{'file'} !~ /\.\./ ||
-       &error($text{'kde_epath'});
+$in{'file'} = &simplify_path($in{'file'});
 $in{'file'} !~ /[\\\&\;\`\'\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
        &error($text{'kde_epath'});
-substr($in{'file'}, 0, length($config{'kde_dir'})) eq $config{'kde_dir'} ||
+&is_under_directory($config{'kde_dir'}, $in{'file'}) ||
        &error($text{'kde_epath'});
 -r $in{'file'} ||
        &error($text{'kde_epath'});
 
-if ($in{'file'} =~ /\.(gif|jpg|jpeg|tif|png)$/i) {
-       printf "Content-type: %s\n\n",
-               $1 eq "gif" ? "image/gif" :
-               $1 eq "jpg" || $1 eq "jpeg" ? "image/jpeg" :
-               $1 eq "tif" ? "image/tiff" : "image/png";
-       open(FILE, $in{'file'});
-       while(read(FILE, $buf, 1024)) {
-               print $buf;
-               }
-       close(FILE);
+# Just output if this is an image
+$mt = &guess_mime_type($in{'file'});
+if ($mt =~ /^image\//) {
+       print "Content-type: $mt\r\n\r\n";
+       print &read_file_contents($in{'file'});
        }
 else {
        &ui_print_header(undef, $text{'kde_title'}, "");
 
-       print "<table border width=100%>\n";
-       print "<tr $tb> <td><b>",&text('kde_header', $in{'file'}),
-             "</b></td> </tr>\n";
-       print "<tr $cb> <td>";
        ($dir = $in{'file'}) =~ s/\/[^\/]+$//;
        open(FILE, $in{'file'});
        while($line = <FILE>) {
@@ -41,10 +31,10 @@ else {
                $line =~ s/src="([^"]+)"/src="view_kde.cgi?file=$dir\/$1"/ig;
                $line =~ s/src='([^']+)'/src='view_kde.cgi?file=$dir\/$1'/ig;
                $line =~ s/src=([^'"\s>]+)/src='view_kde.cgi?file=$dir\/$1'/ig;
-               print $line;
+               $out .= $line;
                }
        close(FILE);
-       print "</td></tr></table><p>\n";
+       &show_view_table(&text('kde_header', $in{'file'}), $out);
 
        &ui_print_footer("", $text{'index_return'});
        }
index f1c9f97..070dd66 100755 (executable)
@@ -5,22 +5,18 @@
 require './man-lib.pl';
 &ReadParse();
 
-$in{'file'} !~ /\.\./ ||
-       &error($text{'kernel_epath'});
+$in{'file'} = &simplify_path($in{'file'});
 $in{'file'} !~ /[\\\&\;\`\'\"\|\*\?\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
        &error($text{'kernel_epath'});
 foreach $h (split(/\s+/, $config{'kernel_dir'})) {
-       $ok++ if (substr($in{'file'}, 0, length($h)) eq $h);
+       $ok++ if (&is_under_directory($config{'kernel_dir'}, $in{'file'}));
        }
 $ok || &error($text{'kernel_epath'});
 -r $in{'file'} || &error($text{'kernel_epath'});
 
 &ui_print_header(undef, $text{'kernel_title'}, "");
 
-print "<table border width=100%>\n";
-print "<tr $tb> <td><b>",&text('kernel_header', $in{'file'}),
-      "</b></td> </tr>\n";
-print "<tr $cb> <td>";
+# Work out compression format
 open(FILE, $in{'file'});
 read(FILE, $two, 2);
 $qm = quotemeta($in{'file'});
@@ -33,6 +29,8 @@ elsif ($two eq "BZ") {
        &open_execute_command(FILE, "bunzip2 -c $qm", 1, 1);
        }
 seek(FILE, 0, 0);
+
+$out = "";
 if ($in{'file'} =~ /\.htm/i) {
        # Display HTML documentation
        ($dir = $in{'file'}) =~ s/\/[^\/]+$//;
@@ -40,24 +38,24 @@ if ($in{'file'} =~ /\.htm/i) {
                $line =~ s/href="([^"]+)"/href="view_doc.cgi?file=$dir\/$1"/ig;
                $line =~ s/href='([^']+)'/href='view_doc.cgi?file=$dir\/$1'/ig;
                $line =~ s/href=([^'"\s>]+)/href='view_doc.cgi?file=$dir\/$1'/ig;
-               print $line;
+               $out .= $line;
                }
        }
 else {
        # Display text file
-       print "<pre>";
+       $out .= "<pre>";
        @for = split(/\s+/, $in{'for'});
        while($line = <FILE>) {
                $line = &html_escape($line);
                foreach $f (@for) {
                        $line =~ s/($f)/<b>$1<\/b>/ig;
                        }
-               print $line;
+               $out .= $line;
                }
-       print "</pre>";
+       $out .= "</pre>";
        }
 close(FILE);
-print "</td></tr></table><p>\n";
+&show_view_table(&text('kernel_header', $in{'file'}), $out);
 
 &ui_print_footer("", $text{'index_return'});
 
index 81e4a4e..f1c84dc 100755 (executable)
@@ -70,22 +70,16 @@ else {
                        $out =~ s/<A HREF="file:[^"]+">([^<]+)<\/a>/$1/ig;
                        $out =~ s/<A HREF="view_man.cgi">/<A HREF=\"\">/i;
                        }
-               print "<table border width=100%>\n";
-               print "<tr $tb> <td><b>",&text('man_header', $in{'page'},
-                                              $in{'sec'}),"</b></td> </tr>\n";
-               print "<tr $cb> <td>",$out,"</td> </tr>\n";
-               print "</table>\n";
+               &show_view_table(&text('man_header', $in{'page'}, $in{'sec'}),
+                                $out);
        } else {
                $out =~ s/.\010//g;
                $out =~ s/^(man:\s*)?(re)?formatting.*//i;
                $out =~ s/&/&amp;/g;
                $out =~ s/</&lt;/g;
                $out =~ s/>/&gt;/g;
-               print "<table border width=100%>\n";
-               print "<tr $tb> <td><b>",&text('man_header', $in{'page'},
-                                              $in{'sec'}),"</b></td> </tr>\n";
-               print "<tr $cb> <td><pre>",$out,"</pre></td> </tr>\n";
-               print "</table><p>\n";
+               &show_view_table(&text('man_header', $in{'page'}, $in{'sec'}),
+                                "<pre>$out</pre>");
                }
        }
 
index be6eaf6..ac6fd08 100755 (executable)
@@ -10,20 +10,19 @@ $in{'mod'} !~ /[\\\&\;\`\'\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\n\r]/ ||
 
 &ui_print_header(undef, $text{'perl_title'}, "");
 
-print "<table border width=100%>\n";
-print "<tr $tb> <td><b>",&text('perl_header', $in{'mod'}),"</b></td> </tr>\n";
-print "<tr $cb> <td><pre>";
 @for = split(/\s+/, $in{'for'});
 &open_execute_command(DOC, "$perl_doc -t ".quotemeta($in{'mod'}), 1, 1);
+$out = "<pre>";
 while($line = <DOC>) {
        $line = &html_escape($line);
        foreach $f (@for) {
                $line =~ s/($f)/<b>$1<\/b>/ig;
                }
-       print $line;
+       $out .= $line;
        }
 close(DOC);
-print "</pre></td></tr></table><p>\n";
+$out .= "</pre>";
+&show_view_table(&text('perl_header', $in{'mod'}), $out);
 
 &ui_print_footer("", $text{'index_return'});