--- /dev/null
+foobar_conf=/etc/foobar.conf
--- /dev/null
+foobar_conf=Foobar Webserver configuration file,8
--- /dev/null
+#!/usr/bin/perl
+# Show a form to create or edit a website
+
+require 'foobar-lib.pl';
+ReadParse();
+
+# Show page header and get the site being edited
+my $site;
+if ($in{'new'}) {
+ ui_print_header(undef, $text{'create_title'}, "");
+ $site = { };
+ }
+else {
+ ui_print_header(undef, $text{'edit_title'}, "");
+ my @sites = list_foobar_websites();
+ ($site) = grep { $_->{'domain'} eq $in{'domain'} } @sites;
+ }
+
+# Generate form and inputs table start
+print ui_form_start('save.cgi');
+print ui_hidden('new', $in{'new'});
+print ui_hidden('old', $in{'domain'});
+print ui_table_start($text{'edit_header'}, undef, 2);
+
+# Input for domain name
+print ui_table_row($text{'edit_domain'},
+ ui_textbox('domain', $site->{'domain'}, 40));
+
+# Input for HTML directory
+print ui_table_row($text{'edit_directory'},
+ ui_filebox('directory', $site->{'directory'}, 40));
+
+# Show buttons at the end of the form
+print ui_table_end();
+if ($in{'new'}) {
+ print ui_form_end([ [ undef, $text{'create'} ] ]);
+ }
+else {
+ print ui_form_end([ [ undef, $text{'save'} ],
+ [ 'delete', $text{'delete'} ] ]);
+ }
+
+
+ui_print_footer('', $text{'index_return'});
+
--- /dev/null
+=head1 foobar-lib.pl
+
+Functions for the Foobar Web Server. This is an example Webmin module for a
+simple fictional webserver.
+
+=cut
+
+use WebminCore;
+init_config();
+
+=head2 list_foobar_websites()
+
+Returns a list of all websites served by the Foobar webserver, as hash
+references with C<domain> and C<directory> keys.
+
+=cut
+sub list_foobar_websites
+{
+my @rv;
+my $lnum = 0;
+open(CONF, $config{'foobar_conf'});
+while(<CONF>) {
+ s/\r|\n//g;
+ s/#.*$//;
+ my ($dom, $dir) = split(/\s+/, $_);
+ if ($dom && $dir) {
+ push(@rv, { 'domain' => $dom,
+ 'directory' => $dir,
+ 'line' => $lnum });
+ }
+ $lnum++;
+ }
+close(CONF);
+return @rv;
+}
+
+1;
+
--- /dev/null
+#!/usr/bin/perl
+# Show all Foobar webserver websites
+
+require 'foobar-lib.pl';
+
+ui_print_header(undef, $module_info{'desc'}, "", undef, 1, 1);
+
+# Build table contents
+my @sites = list_foobar_websites();
+my @table = ( );
+foreach my $s (@sites) {
+ push(@table, [ "<a href='edit.cgi?domain=".urlize($s->{'domain'}).
+ "'>".html_escape($s->{'domain'})."</a>",
+ html_escape($s->{'directory'})
+ ]);
+ }
+
+# Show the table with add links
+print ui_form_columns_table(
+ undef,
+ undef,
+ 0,
+ [ [ 'edit.cgi?new=1', $text{'index_add'} ] ],
+ undef,
+ [ $text{'index_domain'}, $text{'index_directory'} ],
+ 100,
+ \@table,
+ undef,
+ 0,
+ undef,
+ $text{'index_none'},
+ );
+
+ui_print_footer('/', $text{'index'});
--- /dev/null
+index_domain=Website domain
+index_directory=Serve pages from directory
+index_none=No websites have been created yet.
+index_add=Add a new website.
+index_return=website list
+
+edit_title=Edit Website
+create_title=Create Website
+edit_header=Foobar Webserver website details
+edit_domain=Website domain name
+edit_directory=Directory containing website contents
--- /dev/null
+desc=Foobar Web Server
+category=servers
+version=1.0