### Install Webmin::API Module Source: https://webmin.com/docs/development/api/libraries Commands to extract and install the Webmin::API Perl module as root. ```bash tar xvzf Webmin-API-1.0.tar.gz cd Webmin-API perl Makefile.PL make install ``` -------------------------------- ### Install ConfigServer Security & Firewall via CLI Source: https://webmin.com/docs/third-party-modules/configserver-security-and-firewall Execute these commands as root to download, extract, and run the installation script for CSF. ```bash cd /usr/local/src curl -O https://download.configserver.com/csf.tgz tar -xzf csf.tgz cd csf ./install.sh ``` -------------------------------- ### init::start_action Source: https://webmin.com/docs/development/api/module/init Executes the start command for a specified action. ```APIDOC ## start_action(name) ### Description Starts the action with the given name using the appropriate OS method. ### Returns - **status** (int) - 0 for failure, 1 for success - **output** (string) - Output from the action script ``` -------------------------------- ### Install iSCSI initiator tools Source: https://webmin.com/docs/modules/iscsi-client Install the necessary packages for managing iSCSI connections on Debian or RHEL-based Linux distributions. ```bash sudo apt-get install open-iscsi # For Debian derivatives sudo dnf install iscsi-initiator-utils # For RHEL derivatives ``` -------------------------------- ### Example configuration file Source: https://webmin.com/docs/development/creating-modules A sample configuration file defining module-specific parameters. ```text foobar_conf=/etc/foobar.conf sort_mode=0 ``` -------------------------------- ### ui_columns_start Source: https://webmin.com/docs/development/api/webmincore Returns HTML for the start of a multi-column table. ```APIDOC ## ui_columns_start(&headings, [width-percent], [noborder], [&tdtags], [heading]) ### Description Returns HTML for the start of a multi-column table, with the given headings. ### Parameters - **headings** (array reference) - Headers for the table’s columns - **width-percent** (integer) - Desired width as a percentage - **noborder** (integer) - Set to 1 if the table should not have a border - **tdtags** (array reference) - HTML attributes for the table’s td tags - **heading** (string) - Optional heading to put above the table ``` -------------------------------- ### init::enable_at_boot Source: https://webmin.com/docs/development/api/module/init Configures an action to start at boot time, creating the necessary scripts if required. ```APIDOC ## enable_at_boot(action, description, startcode, stopcode, statuscode) ### Description Makes an action start at boot time. If the action already exists, only the action name is required. ### Parameters - **action** (string) - Name of the action to create or enable - **description** (string) - Human-readable description - **startcode** (string) - Shell commands to run at boot - **stopcode** (string) - Shell commands to run at shutdown - **statuscode** (string) - Shell code to output status ``` -------------------------------- ### Create a new partition in fdisk Source: https://webmin.com/docs/modules/partitions-on-local-disks Starts the interactive process to create a new partition. ```text n ``` -------------------------------- ### Example Batch User Creation Line Source: https://webmin.com/docs/modules/users-and-groups A sample line for creating a user with an automatically assigned ID. ```text :create:jcameron:mysecret::3001:Jamie Cameron:/home/jcameron:/bin/bash::::: ``` -------------------------------- ### Install GRUB 2 to MBR Source: https://webmin.com/docs/modules/grub-boot-loader Installs the GRUB 2 boot loader to the specified drive. Replace sdX with the target device identifier. ```bash sudo grub-install /dev/sdX ``` -------------------------------- ### ui_form_start Source: https://webmin.com/docs/development/api/webmincore Generates HTML for the start of a form. ```APIDOC ## ui_form_start(script, method, [target], [tags]) ### Description Returns HTML for the start of a form that submits to a specified script. ### Parameters - **script** (string) - Required - CGI script to submit to - **method** (string) - Required - HTTP method (get, post, or form-data) - **target** (string) - Optional - Target window or frame - **tags** (string) - Optional - Additional HTML attributes ``` -------------------------------- ### ui_table_start Source: https://webmin.com/docs/development/api/webmincore Returns HTML for the start of a form block. ```APIDOC ## ui_table_start(heading, [tabletags], [cols], [&default-tds], [right-heading]) ### Description Returns HTML for the start of a form block into which labelled inputs can be placed. ### Parameters - **heading** (string) - Text to show at the top of the form - **tabletags** (string) - HTML attributes to put in the outer table - **cols** (integer) - Desired number of columns for labels and fields - **default-tds** (array reference) - Optional HTML attributes for the td tags - **right-heading** (string) - HTML to appear in the heading, aligned to the right ``` -------------------------------- ### Start targetcli shell Source: https://webmin.com/docs/modules/iscsi-server Command to launch the interactive targetcli configuration shell. ```bash sudo targetcli ``` -------------------------------- ### Configure /etc/exports Source: https://webmin.com/docs/modules/nfs-exports Example configuration lines for defining export permissions for specific clients. ```text /shared_data client1.example.com(rw,sync,no_root_squash) /shared_data client2.example.com(ro,sync,no_root_squash) ``` -------------------------------- ### Example mdadm.conf configuration Source: https://webmin.com/docs/modules/linux-raid Shows the expected format for an array entry within the /etc/mdadm/mdadm.conf configuration file. ```text ARRAY /dev/md0 uuid=31b036a3:e57803f4:98017b49:bfe6d693 ``` -------------------------------- ### Define backstores Source: https://webmin.com/docs/modules/iscsi-server Example command to create a file-backed storage resource within the targetcli shell. ```bash /backstores/fileio create name=myfileio dev=/path/to/file.img size=10G ``` -------------------------------- ### Install targetcli on Linux Source: https://webmin.com/docs/modules/iscsi-server Commands to install the targetcli-fb package on Debian-based or RHEL-based distributions. ```bash sudo apt-get install targetcli-fb # For Debian derivatives sudo dnf install targetcli # For RHEL derivatives ``` -------------------------------- ### Install NFS Server Software Source: https://webmin.com/docs/modules/nfs-exports Commands to install the necessary NFS server packages on Debian-based and RedHat-based distributions. ```bash sudo apt update sudo apt install nfs-kernel-server ``` ```bash sudo dnf install nfs-utils ``` -------------------------------- ### Reset Webmin Password for Package Installs Source: https://webmin.com/docs/tutorials/changing-a-webmin-password-when-you-cant-log-in Use these commands for systems where Webmin was installed via rpm or deb packages. ```bash webmin passwd username ``` ```bash webmin passwd --user username ``` -------------------------------- ### Manage User Quotas with quota-lib.pl Source: https://webmin.com/docs/development/api/module/quota Demonstrates how to import the quota library, set a user quota, and iterate through filesystems to display usage statistics. ```perl foreign_require('quota'); quota::edit_user_quota('joe', '/home', 1000000, 1200000, 1000, 1200); my $n = quota::user_filesystems('joe'); for (my $i = 0; $i < $n; $i++) { print "filesystem=",$filesys{$i,'filesys'}," ", "block quota=",$filesys{$i,'hblocks'}," ", "blocks used=",$filesys{$i,'ublocks'},"\n"; } ``` -------------------------------- ### Reset Webmin Password for Source Installs Source: https://webmin.com/docs/tutorials/changing-a-webmin-password-when-you-cant-log-in Use these commands when the webmin command is not in the system path, specifying the installation directory or configuration path. ```bash /usr/libexec/webmin/bin/webmin passwd --user username ``` ```bash /usr/share/webmin/bin/webmin passwd --user username ``` ```bash /usr/local/webmin/bin/webmin passwd --user username ``` ```bash /usr/local/webmin/bin/webmin passwd --config /path/to/webmin-config --user username ``` -------------------------------- ### Malicious HTML Link Example Source: https://webmin.com/docs/modules/webmin-configuration An example of an HTML link that could be used to trigger unauthorized commands on a Webmin server if referrer checking is disabled. ```html click me ``` -------------------------------- ### Define module installation status in install_check.pl Source: https://webmin.com/docs/development/creating-modules Implement the is_installed function to allow Webmin to detect if the managed service is present. Return 0 if not installed, or mode + 1 if it is. ```perl do 'foobar-lib.pl'; sub is_installed { my $mode = $_[0]; if (!-r $config{'foo_config_file'}) { return 0; } else { return $mode + 1; } } ``` -------------------------------- ### List and Describe Webmin Log Actions Source: https://webmin.com/docs/development/api/module/webmin-log Demonstrates how to import the webminlog module and iterate through log entries to print human-readable descriptions. ```perl foreign_require("webminlog"); my @actions = webminlog::list_webmin_log(undef, "useradmin", undef, undef); foreach my $a (@actions) { print webminlog::get_action_description($a),"\n"; } ``` -------------------------------- ### init::list_actions Source: https://webmin.com/docs/development/api/module/init Retrieves a list of all boot time action names. ```APIDOC ## list_actions() ### Description Returns a list of boot time action names from init.d. ``` -------------------------------- ### Manual configuration installation commands Source: https://webmin.com/docs/development/creating-modules Shell commands to manually copy a module's configuration file to the Webmin configuration directory. ```bash cd /usr/libexec/webmin/foobar mkdir /etc/webmin/foobar cp config /etc/webmin/foobar ``` -------------------------------- ### get_all_module_infos(cachemode) Source: https://webmin.com/docs/development/api/webmincore Retrieves information for all installed modules. ```APIDOC ## get_all_module_infos(cachemode) ### Description Returns a list containing information on all modules in the Webmin install, including clones. ### Parameters - **cachemode** (integer) - Required - 0 = read and write, 1 = don't read or write, 2 = read only. ``` -------------------------------- ### Implement post-installation logic in postinstall.pl Source: https://webmin.com/docs/development/creating-modules Define a module_install function to execute tasks after module installation or upgrade. Ensure logic is idempotent to prevent overwriting existing configurations. ```perl require 'foobar-lib.pl'; sub module_install { if (!-r "$config_directory/somefile") { copy_source_dest("$module_root_directory/somefile", "$config_directory/somefile"); } } ``` -------------------------------- ### foreign_available(module) Source: https://webmin.com/docs/development/api/webmincore Checks if a module is installed and accessible. ```APIDOC ## foreign_available(module) ### Description Returns 1 if some module is installed, and acessible to the current user. ``` -------------------------------- ### Create an ext4 filesystem Source: https://webmin.com/docs/modules/partitions-on-local-disks Formats a specific partition with the ext4 filesystem. ```bash sudo mkfs.ext4 /dev/sda1 ``` -------------------------------- ### ui_hidden_table_start Source: https://webmin.com/docs/development/api/webmincore Returns HTML for the start of a collapsible form block. ```APIDOC ## ui_hidden_table_start(heading, [tabletags], [cols], name, status, [&default-tds], [rightheading]) ### Description Returns HTML for the start of a form block into which labelled inputs can be placed, which is collapsible by clicking on the header. ``` -------------------------------- ### ui_hidden_start Source: https://webmin.com/docs/development/api/webmincore Returns HTML for the start of a collapsible hidden section. ```APIDOC ## ui_hidden_start(title, name, status, thisurl) ### Description Returns HTML for the start of a collapsible hidden section, such as for advanced options. When clicked on, the section header will expand to display whatever is between this function and ui_hidden_end. ``` -------------------------------- ### Manage Webmin Users with acl-lib.pl Source: https://webmin.com/docs/development/api/module/acl Example showing how to import the ACL module, list existing users, and create a new user with specific module access. ```perl foreign_require("acl"); my @users = acl::list_users(); $newguy = { 'name' => 'newguy', 'pass' => acl::encrypt_password('smeg'), 'modules' => [ 'useradmin' ] }; acl::create_user($newguy); ``` -------------------------------- ### ui_table_row Source: https://webmin.com/docs/development/api/webmincore Returns HTML for a row in a table started by ui_table_start. ```APIDOC ## ui_table_row(label, value, [cols], [&td-tags]) ### Description Returns HTML for a row in a table started by ui_table_start, with a 1-column label and 1+ column value. ### Parameters - **label** (string) - Label for the input field - **value** (string) - HTML for the input part of the row - **cols** (integer) - Number of columns the value should take up - **td-tags** (array reference) - HTML attributes for the td tags ``` -------------------------------- ### Initialize Physical Volumes Source: https://webmin.com/docs/modules/logical-volume-management Prepare disks for LVM usage using the pvcreate command. ```bash # Initialize two disks for use by LVM pvcreate /dev/sda1 /dev/sdb1 ``` -------------------------------- ### Structure a module library file Source: https://webmin.com/docs/development/creating-modules The -lib.pl file contains common functions and initializes the Webmin environment using WebminCore. ```perl =head1 foobar-lib.pl Functions for managing the Foobar webserver configuration file. foreign_require("foobar"); my @sites = foobar::list_foobar_websites() =cut BEGIN { push(@INC, ".."); }; use WebminCore; init_config(); =head2 get_foobar_config() Returns the Foobar Webserver configuration as a list of hash references with name and value keys. =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; } ``` -------------------------------- ### foreign_installed(module, mode) Source: https://webmin.com/docs/development/api/webmincore Checks if the server for a module is installed and configured. ```APIDOC ## foreign_installed(module, mode) ### Description Checks if the server for some module is installed, and possibly also checks if the module has been configured by Webmin. For mode 1, returns 2 if the server 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. ```