How to Create a Custom Webmin Module

How to Create a Custom Webmin Module thumbnail
Creating a custom Webmin module is easier than it sounds.

Webmin is a web-based interface that is used for system administration in Unix-based systems. It allows you to set up user accounts and file sharing. Due to its design, you can add new modules with ease without changing the existing code. Webmin modules are similar to iPhone applications in terms of integration. Although a module should administer one service or server, complex system functions can be handled by more than one module.

Instructions

    • 1

      Create a new folder in the Webmin base directory and name it "foobar." A Webmin module is basically a directory that contains the CGI programs run by the Webmin's web server. The default path to the base directory is "/usr/libexec/webmin."

    • 2

      Create a file in your new directory and name it "module.info." This file contains the meta information of your module. This file must contain at least the "desc," "os_support" and "category" tags.

    • 3

      Open the "module.info" file with a text editor and add these lines:

      desc=Foo Web Server
      os_support=*-linux
      category=servers

      "desc" contains the description of your new module, "os_support" contains a list of operating systems supported by the module and "category" specifies the menu category under which the module is displayed.

    • 4

      Create a new file in your module's directory. It must have the same name as the folder, plus a "-lib.pl" part. In our example, the new file will be named "foobar-lib.pl." This file must contain functions called by your module's CGI programs and will call initialization functions in Webmin.

    • 5

      Open the "foobar-lib.pl" file with a text editor and add this sample code:

      =head1 foobar-lib.pl
      foreign_require("foobar", "foobar-lib.pl");
      @sites = foobar::list_foobar_websites()
      =cut
      BEGIN { push(@INC, ".."); };
      use WebminCore;
      init_config();
      =head2 get_foobar_config()
      =cut
      sub get_foobar_config
      {
      my $lref = &read_file_lines($config{'foobar_conf'});
      my @rv;
      my $lnum = 0;
      foreach my $line (@$lref) {
      my ($n, $v) = split(/\s+/, $line, 2);
      if ($n) {
      push(@rv, { 'name' => $n, 'value' => $v, 'line' => $lnum });
      }
      $lnum++;
      }
      return @rv;
      }

      The "init_config();" line initializes the environment of your new module. The "get_foobar_config" sub is a simple example of a function that can be called by a CGI script that manages one of your servers to read the server's config file.

    • 6

      Create a new file named "index.cgi." This file links to all the CGI programs your module serves. Open the file with a text editor. Here is an example of an "index.cgi" file:

      #!/usr/bin/perl
      require 'foobar-lib.pl';
      ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
      $conf = get_foobar_config();
      $dir = find($conf, "root");
      print &text('index_root', $dir),"<p>\n";
      ui_print_footer("/", $text{'index'});

      The "require 'foobar-lib.pl';" line accesses your module's function library and calls the initialization function, the "ui_print_header" generates the page's HTML header and the "ui_print_footer" is used to create a link to Webmin's main menu.

    • 7

      Create a new folder in the module's directory and name it "lang." Create a new file in this folder and name it "en." It will contain all messages used by your scripts in lines of text, one per message. Here is a sample "en" file:"

      index_title=Foobar Web Server
      index_root=The root directory is $1.

Related Searches:

References

Resources

  • Photo Credit Comstock/Comstock/Getty Images

Comments

Related Ads

Featured