Start of example module for docs
authorJamie Cameron <jcameron@webmin.com>
Mon, 30 Mar 2009 21:46:36 +0000 (21:46 +0000)
committerJamie Cameron <jcameron@webmin.com>
Mon, 30 Mar 2009 21:46:36 +0000 (21:46 +0000)
foobar/config [new file with mode: 0644]
foobar/config.info [new file with mode: 0644]
foobar/edit.cgi [new file with mode: 0755]
foobar/foobar-lib.pl [new file with mode: 0644]
foobar/index.cgi [new file with mode: 0755]
foobar/lang/en [new file with mode: 0644]
foobar/module.info [new file with mode: 0644]

diff --git a/foobar/config b/foobar/config
new file mode 100644 (file)
index 0000000..050bf18
--- /dev/null
@@ -0,0 +1 @@
+foobar_conf=/etc/foobar.conf
diff --git a/foobar/config.info b/foobar/config.info
new file mode 100644 (file)
index 0000000..75be5d0
--- /dev/null
@@ -0,0 +1 @@
+foobar_conf=Foobar Webserver configuration file,8
diff --git a/foobar/edit.cgi b/foobar/edit.cgi
new file mode 100755 (executable)
index 0000000..08baad2
--- /dev/null
@@ -0,0 +1,45 @@
+#!/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'});
+
diff --git a/foobar/foobar-lib.pl b/foobar/foobar-lib.pl
new file mode 100644 (file)
index 0000000..d06d0f1
--- /dev/null
@@ -0,0 +1,38 @@
+=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;
+
diff --git a/foobar/index.cgi b/foobar/index.cgi
new file mode 100755 (executable)
index 0000000..dafa784
--- /dev/null
@@ -0,0 +1,34 @@
+#!/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'});
diff --git a/foobar/lang/en b/foobar/lang/en
new file mode 100644 (file)
index 0000000..c364ad4
--- /dev/null
@@ -0,0 +1,11 @@
+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
diff --git a/foobar/module.info b/foobar/module.info
new file mode 100644 (file)
index 0000000..971cbf9
--- /dev/null
@@ -0,0 +1,3 @@
+desc=Foobar Web Server
+category=servers
+version=1.0