return @rv;
}
+=head2 create_foobar_website(&site)
+
+Adds a new website, specified by the C<site> hash reference parameter, which
+must contain C<domain> and C<directory> keys.
+
+=cut
+sub create_foobar_website
+{
+my ($site) = @_;
+open_tempfile(CONF, ">>$config{'foobar_conf'}");
+print_tempfile(CONF, $site->{'domain'}." ".$site->{'directory'}."\n");
+close_tempfile(CONF);
+}
+
+=head2 modify_foobar_website(&site)
+
+Updates a website specified by the C<site> hash reference parameter, which
+must be a modified entry returned from the C<list_foobar_websites> function.
+
+=cut
+sub modify_foobar_website
+{
+my ($site) = @_;
+my $lref = read_file_lines($config{'foobar_conf'});
+$lref->[$site->{'line'}] = $site->{'domain'}." ".$site->{'directory'};
+flush_file_lines($config{'foobar_conf'});
+}
+
+=head2 delete_foobar_website(&site)
+
+Deletes a website, specified by the C<site> hash reference parameter, which
+must have been one of the elements returned by C<list_foobar_websites>
+
+=cut
+sub delete_foobar_website
+{
+my ($site) = @_;
+my $lref = read_file_lines($config{'foobar_conf'});
+splice(@$lref, $site->{'line'}, 1);
+flush_file_lines($config{'foobar_conf'});
+}
+
+=head2 apply_configuration()
+
+Signal the Foobar webserver process to re-read it's configuration files.
+
+=cut
+sub apply_configuration
+{
+kill_byname_logged('HUP', 'foobard');
+}
+
1;
--- /dev/null
+
+do 'foobar-lib.pl';
+
+=head2 is_installed(mode)
+
+For mode 1, returns 2 if Foobar is installed and configured for use by
+Webmin, 1 if installed but not configured, or 0 otherwise.
+For mode 0, returns 1 if installed, 0 if not
+
+=cut
+sub is_installed
+{
+my ($mode) = @_;
+
+# This is the code that you'd want if the Foobar webserver really existed
+#if (-r $config{'foobar_conf'}) {
+# return $mode + 1;
+# }
+#return 0;
+
+return $mode + 1;
+}
+
edit_header=Foobar Webserver website details
edit_domain=Website domain name
edit_directory=Directory containing website contents
+
+save_err=Failed to save website
+save_edomain=Missing or invalid domain name
+save_edirectory=Directory must be an absolute path
+save_edirectory2=Directory does not exist
+save_egone=Website no longer exists
+
+log_create=Created website $1
+log_modify=Modified website $1
+log_delete=Deleted website $1
--- /dev/null
+# log_parser.pl
+# Functions for parsing this module's logs
+
+do 'foobar-lib.pl';
+
+=head2 parse_webmin_log(user, script, action, type, object, ¶ms)
+
+Converts logged information from this module into human-readable form
+
+=cut
+sub parse_webmin_log
+{
+my ($user, $script, $action, $type, $object, $p) = @_;
+return &text('log_'.$action, '<tt>'.html_escape($object).'</tt>');
+}
+
--- /dev/null
+#!/usr/bin/perl
+# Create, update or delete a website
+
+require 'foobar-lib.pl';
+ReadParse();
+error_setup($text{'save_err'});
+lock_file($config{'foobar_conf'});
+
+# Get the old site object
+if (!$in{'new'}) {
+ my @sites = list_foobar_websites();
+ ($site) = grep { $_->{'domain'} eq $in{'old'} } @sites;
+ $site || error($text{'save_egone'});
+ }
+
+if ($in{'delete'}) {
+ # Just delete it
+ delete_foobar_website($site);
+ }
+else {
+ # Validate inputs
+ $in{'domain'} =~ /^[a-z0-9\.\-\_]+$/i ||
+ error($text{'save_edomain'});
+ $in{'directory'} =~ /^\// ||
+ error($text{'save_edirectory'});
+ -d $in{'directory'} ||
+ error($text{'save_edirectory2'});
+ $site->{'domain'} = $in{'domain'};
+ $site->{'directory'} = $in{'directory'};
+
+ # Update or create
+ if ($in{'new'}) {
+ create_foobar_website($site);
+ }
+ else {
+ modify_foobar_website($site);
+ }
+ }
+
+# Log the change
+unlock_file($config{'foobar_conf'});
+apply_configuration();
+webmin_log($in{'new'} ? 'create' :
+ $in{'delete'} ? 'delete' : 'modify',
+ 'site',
+ $site->{'domain'});
+&redirect('');
+