.
diff --git a/docs/resources/nagios.rst b/docs/resources/nagios.rst
new file mode 100644
index 0000000..6bf9383
--- /dev/null
+++ b/docs/resources/nagios.rst
@@ -0,0 +1,11 @@
+Nagios
+------
+
+Nagios and nrpe client are produced by `Nagios`_
+
+.. _`Nagios`: https://www.nagios.com/
+
+`Nagios Exchange`_ provides plugins, addons, docs, extensions and other tools
+
+.. _`Nagios Exchange`: https://exchange.nagios.org/
+
diff --git a/docs/resources/security.rst b/docs/resources/security.rst
new file mode 100644
index 0000000..a007e87
--- /dev/null
+++ b/docs/resources/security.rst
@@ -0,0 +1,20 @@
+.. This is a comment. Note how any initial comments are moved by
+ transforms to after the document title, subtitle, and docinfo.
+
+.. demo.rst from: http://docutils.sourceforge.net/docs/user/rst/demo.txt
+
+.. |EXAMPLE| image:: static/yi_jing_01_chien.jpg
+ :width: 1em
+
+**********************
+Security
+**********************
+
+Below are common items for securing your instance::
+
+ Disable root login
+ Change SSH port to non-standard (22) port
+ Change Webmin port to non-standard (10000) port
+ Install IP Tables
+ Restrict access to Webmin to your IP
+ Disable all services not in use
diff --git a/docs/resources/support.rst b/docs/resources/support.rst
new file mode 100644
index 0000000..7908939
--- /dev/null
+++ b/docs/resources/support.rst
@@ -0,0 +1,41 @@
+
+Project Support
+---------------
+
+Contributing
+========================
+We welcome all contributors.
+
+Issues
+========================
+If you've found a bug, let us know.
+
+Pull Requests
+========================
+
+Create a fork of our repo.
+
+To submit a pull request for a **new feature**:
+
+1. Run the tests. Every pull request for a new feature should have an accompanying unit test and docs changes.
+2. Create a new branch off of the `master` branch for your feature.
+3. Add a test (or multiple tests) for your feature.
+4. Add your new feature.
+5. Push to your fork and submit the pull request.
+
+To submit a **bug fix**:
+
+1. Create a new branch off of the `master` branch.
+2. Add a test that demonstrates the bug.
+3. Make the test pass.
+4. Push to your fork and submit the pull request!
+
+To submit a **documentation fix**:
+
+1. Create a new branch off of the `master` branch.
+2. Add your documentation fixes (no tests required).
+3. Push to your fork and submit the pull request!
+
+
+
+
diff --git a/docs/services/index.rst b/docs/services/index.rst
new file mode 100644
index 0000000..9191c61
--- /dev/null
+++ b/docs/services/index.rst
@@ -0,0 +1 @@
+sda
diff --git a/docs/services/nagios/_static/index.rst b/docs/services/nagios/_static/index.rst
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/docs/services/nagios/_static/index.rst
@@ -0,0 +1 @@
+
diff --git a/docs/services/nagios/_static/nagios-service.png b/docs/services/nagios/_static/nagios-service.png
new file mode 100644
index 0000000..88e919f
Binary files /dev/null and b/docs/services/nagios/_static/nagios-service.png differ
diff --git a/docs/services/nagios/index.rst b/docs/services/nagios/index.rst
new file mode 100644
index 0000000..9b9b382
--- /dev/null
+++ b/docs/services/nagios/index.rst
@@ -0,0 +1,55 @@
+.. This is a comment. Note how any initial comments are moved by
+ transforms to after the document title, subtitle, and docinfo.
+
+.. demo.rst from: http://docutils.sourceforge.net/docs/user/rst/demo.txt
+
+.. |EXAMPLE| image:: static/yi_jing_01_chien.jpg
+ :width: 1em
+
+**********************
+Nagios Service
+**********************
+
+.. contents:: Table of Contents
+Overview
+==================
+
+Nagios is installed as a service.
+
+The service file is located under::
+
+ /lib/systemd/system/nagios.service
+
+It has the contents below:
+
+.. code-block:: bash
+ :linenos:
+
+ [Unit]
+ Description=Nagios Core 4.4.5
+ Documentation=https://www.nagios.org/documentation
+ After=network.target local-fs.target
+
+ [Service]
+ Type=forking
+ ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
+ ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
+ ExecStop=/bin/kill -s TERM ${MAINPID}
+ ExecStopPost=/bin/rm -f /usr/local/nagios/var/rw/nagios.cmd
+ ExecReload=/bin/kill -s HUP ${MAINPID}
+
+ [Install]
+ WantedBy=multi-user.target
+
+Start and Stop
+==============
+
+The Nagios service can be started and stopped via the module or via command line.
+
+To start and stop via the module, go to Servers > Nagios and click the Start or Stop button:
+
+ .. image:: _static/nagios-service.png
+
+To start and stop via command line, as root, issue::
+
+ service nagios stop | start
diff --git a/docs/services/nrpe/_static/index.rst b/docs/services/nrpe/_static/index.rst
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/docs/services/nrpe/_static/index.rst
@@ -0,0 +1 @@
+
diff --git a/docs/services/nrpe/_static/nrpe-service.png b/docs/services/nrpe/_static/nrpe-service.png
new file mode 100644
index 0000000..3b41f99
Binary files /dev/null and b/docs/services/nrpe/_static/nrpe-service.png differ
diff --git a/docs/services/nrpe/index.rst b/docs/services/nrpe/index.rst
new file mode 100644
index 0000000..0f0266c
--- /dev/null
+++ b/docs/services/nrpe/index.rst
@@ -0,0 +1,65 @@
+.. This is a comment. Note how any initial comments are moved by
+ transforms to after the document title, subtitle, and docinfo.
+
+.. demo.rst from: http://docutils.sourceforge.net/docs/user/rst/demo.txt
+
+.. |EXAMPLE| image:: static/yi_jing_01_chien.jpg
+ :width: 1em
+
+**********************
+Nrpe Service
+**********************
+
+.. contents:: Table of Contents
+Overview
+==================
+
+Nrpe is installed as a service.
+
+The service file is located under::
+
+ /lib/systemd/system/nrpe.service
+
+It has the contents below:
+
+.. code-block:: bash
+ :linenos:
+
+ [Unit]
+ Description=Nagios Remote Plugin Executor
+ Documentation=http://www.nagios.org/documentation
+ After=var-run.mount nss-lookup.target network.target local-fs.target time-sync.target
+ Before=getty@tty1.service plymouth-quit.service xdm.service
+ Conflicts=nrpe.socket
+
+ [Install]
+ WantedBy=multi-user.target
+
+ [Service]
+ Type=simple
+ Restart=on-abort
+ PIDFile=/usr/local/nagios/var/nrpe.pid
+ RuntimeDirectory=nrpe
+ RuntimeDirectoryMode=0755
+ ExecStart=/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f
+ ExecReload=/bin/kill -HUP $MAINPID
+ ExecStopPost=/bin/rm -f /usr/local/nagios/var/nrpe.pid
+ TimeoutStopSec=60
+ User=nagios
+ Group=nagios
+ PrivateTmp=true
+ OOMScoreAdjust=-500
+
+
+Start and Stop
+==============
+
+The Nrpe service can be started and stopped via the module or via command line.
+
+To start and stop via the module, go to Servers > Nagios and click the Start or Stop button:
+
+ .. image:: _static/nrpe-service.png
+
+To start and stop via command line, as root, issue::
+
+ service nrpe stop | start
diff --git a/docs/webmin.rst b/docs/webmin.rst
new file mode 100644
index 0000000..fc451ab
--- /dev/null
+++ b/docs/webmin.rst
@@ -0,0 +1,10 @@
+Webmin
+------
+
+Webmin can be accessed via::
+
+ https://yourdomain.com:10000
+
+The Nagios module is found under Servers > Nagios as shown below:
+
+ .. image:: _static/nagios-webmin.png
diff --git a/docs/wizard.rst b/docs/wizard.rst
new file mode 100644
index 0000000..bf8d240
--- /dev/null
+++ b/docs/wizard.rst
@@ -0,0 +1,35 @@
+.. _wizard-label:
+
+************
+Wizard
+************
+
+Once the module is installed, the Wizard is used to configure the components.
+
+Go to Servers > Nagios:
+
+The main Wizard screen contains a link for completing each step.
+
+.. image:: _static/nagiosWizard.png
+
+The steps are self-explanatory, and you simply need to click through each step.
+
+.. note::
+ Due to compiling of components, completion of the Wizard may take up to 10 minutes to complete.
+
+**Nrpe**
+
+Installation of nrpe service is optional.
+
+
+Once installation is completed, the page will appear as below:
+
+.. image:: _static/nagios-main.png
+
+
+
+About nrpe
+===================
+
+NRPE allows you to remotely execute Nagios plugins on on compatible servers.
+
diff --git a/edit_cfg.cgi b/edit_cfg.cgi
new file mode 100644
index 0000000..a5148d4
--- /dev/null
+++ b/edit_cfg.cgi
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&ReadParse();
+&ui_print_header(undef, $text{'manual_title'}, "");
+
+# Work out and show the files
+@files = get_cfg_files(get_nagios_home().'/etc');
+$in{'file'} ||= $files[0];
+&indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
+
+print &ui_form_start("edit_cfg.cgi");
+print "$text{'manual_file'}\n";
+print &ui_select("file", $in{'file'}, [ map { [ $_ ] } @files ], 1, 0);
+print &ui_submit($text{'manual_ok'});
+print &ui_form_end();
+
+# Show the file contents
+print &ui_form_start("save_cfg.cgi", "form-data");
+print &ui_hidden("file", $in{'file'}),"\n";
+$data = &read_file_contents($in{'file'});
+print &ui_textarea("data", $data, 20, 80),"\n";
+print &ui_form_end([ [ "save", $text{'save'} ] ]);
+
+&ui_print_footer("", $text{'index_return'});
diff --git a/edit_objects.cgi b/edit_objects.cgi
new file mode 100644
index 0000000..f4e8dc2
--- /dev/null
+++ b/edit_objects.cgi
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&ReadParse();
+&ui_print_header(undef, $text{'objects_title'}, "");
+
+# Work out and show the files
+@files = get_cfg_files(get_nagios_home().'/etc/objects');
+$in{'file'} ||= $files[0];
+&indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
+
+print &ui_form_start("create_cfg.cgi", 'post');
+print "$text{'create_cfg_file'}".&ui_textbox("new_filename", '', 20, 0).&ui_submit($text{'create_ok'});
+print &ui_form_end();
+
+print &ui_form_start("edit_objects.cgi");
+print "$text{'manual_file'}\n";
+print &ui_select("file", $in{'file'}, [ map { [ $_ ] } @files ], 1, 0);
+print &ui_submit($text{'manual_ok'});
+print &ui_form_end();
+
+# Show the file contents
+print &ui_form_start("save_objects.cgi", "form-data");
+print &ui_hidden("file", $in{'file'}),"\n";
+$data = &read_file_contents($in{'file'});
+print &ui_textarea("data", $data, 20, 80),"\n";
+print &ui_form_end([ [ "save", $text{'save'} ] ]);
+
+&ui_print_footer("", $text{'index_return'});
diff --git a/en b/en
new file mode 100644
index 0000000..7e8a641
--- /dev/null
+++ b/en
@@ -0,0 +1,30 @@
+index_title=Nagios
+index_root=The root directory is $1.
+
+index_start=Start Nagios
+index_startmsg=Click to start Nagios Service
+index_stop=Stop Nagios
+index_stopmsg=Click to stop Nagios Service
+
+
+index_start_nrpe=Start Nrpe
+index_startmsg_nrpe=Click to start Nrpe Service
+index_stop_nrpe=Stop Nrpe
+index_stopmsg_nrpe=Click to stop Nrpe Service
+
+index_return=Nagios
+
+manual_title=Main Confs
+manual_ecannot=You are not allowed to edit the file
+manual_ok=Edit
+manual_efile=Selected file is not part of configuration
+manual_file=Edit config file:
+manual_edata=Nothing entered!
+manual_err=Failed to save config file
+
+objects_title=Objects
+
+create_ok=Create
+create_cfg_file=New Filename:
+
+setup_title=Setup
diff --git a/help/intro.html b/help/intro.html
new file mode 100644
index 0000000..00146d1
--- /dev/null
+++ b/help/intro.html
@@ -0,0 +1,13 @@
+
+
+This module is used to install and manage Nagios via Webmin
+
+Nagios is open soft software and use is subject to terms provided by
+the Nagios Foundation.
+
+
+Module produced by Cited, Inc.
+
+© 2020, Cited, Inc.
+
+
diff --git a/images/edit-file.png b/images/edit-file.png
new file mode 100644
index 0000000..9ee10d7
Binary files /dev/null and b/images/edit-file.png differ
diff --git a/images/objects.png b/images/objects.png
new file mode 100644
index 0000000..43af62c
Binary files /dev/null and b/images/objects.png differ
diff --git a/index.cgi b/index.cgi
new file mode 100644
index 0000000..8d192c8
--- /dev/null
+++ b/index.cgi
@@ -0,0 +1,60 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+
+# Check if config file exists
+if (! -r $config{'nagios_config'}) {
+ &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
+ print &text('index_econfig', "$config{'nagios_config'}",
+ "$gconfig{'webprefix'}/config.cgi?$module_name"),"\n";
+ &ui_print_footer("/", $text{"index"});
+ exit;
+}
+
+if(-f "$module_root_directory/setup.cgi"){
+ &redirect('setup.cgi');
+}
+
+# Check if tomcat is the right version
+%version = &get_nagios_version();
+&ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
+ &help_search_link("Nagios", "nrpe"), undef, undef,
+ 'Nagios ver.'.$version{'number'}.'
Cited, Inc. © 2020');
+
+
+
+push(@links, "edit_cfg.cgi");
+push(@titles, $text{'manual_title'});
+push(@icons, "images/edit-file.png");
+
+push(@links, "edit_objects.cgi");
+push(@titles, $text{'objects_title'});
+push(@icons, "images/objects.png");
+
+
+&icons_table(\@links, \@titles, \@icons, 2);
+
+print &ui_hr();
+print &ui_buttons_start();
+
+my $is_running = nagios_is_running();
+if ($is_running == 1) {
+ print &ui_buttons_row("stop.cgi", $text{'index_stop'}, $text{'index_stopmsg'});
+}else {
+ print &ui_buttons_row("start.cgi", $text{'index_start'}, $text{'index_startmsg'});
+}
+print &ui_buttons_end();
+
+
+print &ui_buttons_start();
+
+my $is_running = nrpe_is_running();
+if ($is_running == 1) {
+ print &ui_buttons_row("stop_nrpe.cgi", $text{'index_stop_nrpe'}, $text{'index_stopmsg_nrpe'});
+}else {
+ print &ui_buttons_row("start_nrpe.cgi", $text{'index_start_nrpe'}, $text{'index_startmsg_nrpe'});
+}
+print &ui_buttons_end();
+
+
+&ui_print_footer("/", $text{"index_return"});
diff --git a/install_check.pl b/install_check.pl
new file mode 100644
index 0000000..a0fe1ec
--- /dev/null
+++ b/install_check.pl
@@ -0,0 +1,13 @@
+# install_check.pl
+
+do 'nagios-lib.pl';
+
+# is_installed(mode)
+# 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
+sub is_installed
+{
+return 0 if (!-r $config{'nagios_config'} || !&has_command('check_nrpe'));
+return $_[0] ? 2 : 1;
+}
diff --git a/lang/en b/lang/en
new file mode 100644
index 0000000..7e8a641
--- /dev/null
+++ b/lang/en
@@ -0,0 +1,30 @@
+index_title=Nagios
+index_root=The root directory is $1.
+
+index_start=Start Nagios
+index_startmsg=Click to start Nagios Service
+index_stop=Stop Nagios
+index_stopmsg=Click to stop Nagios Service
+
+
+index_start_nrpe=Start Nrpe
+index_startmsg_nrpe=Click to start Nrpe Service
+index_stop_nrpe=Stop Nrpe
+index_stopmsg_nrpe=Click to stop Nrpe Service
+
+index_return=Nagios
+
+manual_title=Main Confs
+manual_ecannot=You are not allowed to edit the file
+manual_ok=Edit
+manual_efile=Selected file is not part of configuration
+manual_file=Edit config file:
+manual_edata=Nothing entered!
+manual_err=Failed to save config file
+
+objects_title=Objects
+
+create_ok=Create
+create_cfg_file=New Filename:
+
+setup_title=Setup
diff --git a/module.info b/module.info
new file mode 100644
index 0000000..e2e924a
--- /dev/null
+++ b/module.info
@@ -0,0 +1,3 @@
+desc=Nagios
+os_support=*-linux freebsd archlinux
+category=servers
diff --git a/nagios-lib.pl b/nagios-lib.pl
new file mode 100644
index 0000000..4ab09f2
--- /dev/null
+++ b/nagios-lib.pl
@@ -0,0 +1,134 @@
+BEGIN { push(@INC, ".."); };
+use WebminCore;
+
+init_config();
+
+sub get_nagios_config{
+ my $lref = &read_file_lines($config{'nagios_config'});
+ 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;
+}
+
+sub get_nagios_home(){
+ return '/usr/local/nagios';
+}
+
+sub get_nagios_version(){
+ my %version;
+ my $nagios_home = get_nagios_home();
+
+ &open_execute_command(CMD, $nagios_home.'/bin/nagios -h', 1);
+ while(my $line = ) {
+ if ($line =~ /Nagios Core ([0-9\.]+)$/i) {
+ $version{'number'} = $1;
+ last;
+ }
+ }
+ close(CMD);
+
+ return %version;
+}
+
+sub nagios_is_running(){
+ my $rv = 0;
+ my $nagios_bin = get_nagios_home().'/bin/nagios';
+
+ &open_execute_command(CMD, '/bin/ps -ef', 1);
+ while(my $line = ) {
+ if ($line =~ /$nagios_bin/i) {
+ $rv = 1;
+ last;
+ }
+ }
+ close(CMD);
+
+ return $rv;
+}
+
+
+sub nrpe_is_running(){
+ my $rv = 0;
+ my $nrpe_bin = get_nagios_home().'/bin/nrpe';
+
+ &open_execute_command(CMD, '/bin/ps -ef', 1);
+ while(my $line = ) {
+ if ($line =~ /$nrpe_bin/i) {
+ $rv = 1;
+ last;
+ }
+ }
+ close(CMD);
+
+ return $rv;
+}
+
+
+
+sub get_cfg_files{
+ my $dirpath = $_[0];
+ my @files;
+
+ opendir(DIR, $dirpath) or die $!;
+ my @cfg_files = grep {
+ /\.cfg$/ # ends in .cfg
+ && -f $dirpath.'/'.$_ # its a file
+ } readdir(DIR);
+ closedir(DIR);
+
+ #make file have full path name
+ @cfg_files = map { $dirpath.'/'.$_} @cfg_files;
+ push(@files, @cfg_files);
+
+ return @files;
+}
+
+
+sub exec_cmd{
+ my $cmd = $_[0];
+ my $cmd_out='';
+
+ my $rv = &execute_command($cmd, undef, \$cmd_out, \$cmd_out, 0, 0);
+ if($cmd_out){
+ $cmd_out = &html_escape($cmd_out);
+ $cmd_out =~ s/[\r\n]/<\/br>/g;
+ print $cmd_out;
+ }
+ return $rv;
+}
+
+sub download_file{
+ my $url = $_[0];
+
+ my ($proto, $x, $host, $path) = split('/', $url, 4);
+ my @paths = split('/', $url);
+ my $filename = $paths[-1];
+ if($filename eq ''){
+ $filename = 'index.html';
+ }
+
+ my $sslmode = $proto eq 'https:';
+ my $port = 80;
+ if($sslmode){
+ $port = 443;
+ }
+
+ &error_setup(&text('install_err3', $url));
+ my $tmpfile = &transname($filename);
+ $progress_callback_url = $url;
+
+ &http_download($host, $port, '/'.$path, $tmpfile, \$error, \&progress_callback, $sslmode);
+
+ if($error){
+ print &html_escape($error);
+ return '';
+ }
+ return $tmpfile;
+}
diff --git a/save_cfg.cgi b/save_cfg.cgi
new file mode 100644
index 0000000..78dc5b1
--- /dev/null
+++ b/save_cfg.cgi
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&error_setup($text{'manual_err'});
+&ReadParseMime();
+
+# Work out the file
+@files = get_cfg_files(get_nagios_home().'/etc');
+&indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
+$in{'data'} =~ s/\r//g;
+$in{'data'} =~ /\S/ || &error($text{'manual_edata'});
+
+# Write to it
+&open_lock_tempfile(DATA, ">$in{'file'}");
+&print_tempfile(DATA, $in{'data'});
+&close_tempfile(DATA);
+
+&webmin_log("manual", undef, $in{'file'});
+&redirect("");
diff --git a/save_objects.cgi b/save_objects.cgi
new file mode 100644
index 0000000..5b9c358
--- /dev/null
+++ b/save_objects.cgi
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&error_setup($text{'manual_err'});
+&ReadParseMime();
+
+# Work out the file
+@files = get_cfg_files(get_nagios_home().'/etc/objects');
+&indexof($in{'file'}, @files) >= 0 || &error($text{'manual_efile'});
+$in{'data'} =~ s/\r//g;
+$in{'data'} =~ /\S/ || &error($text{'manual_edata'});
+
+# Write to it
+&open_lock_tempfile(DATA, ">$in{'file'}");
+&print_tempfile(DATA, $in{'data'});
+&close_tempfile(DATA);
+
+&webmin_log("manual", undef, $in{'file'});
+&redirect("");
diff --git a/scripts/nagios.wbm.gz b/scripts/nagios.wbm.gz
new file mode 100644
index 0000000..e88e9bd
Binary files /dev/null and b/scripts/nagios.wbm.gz differ
diff --git a/scripts/nrpe.sh b/scripts/nrpe.sh
new file mode 100644
index 0000000..51e5ee4
--- /dev/null
+++ b/scripts/nrpe.sh
@@ -0,0 +1,156 @@
+# !/bin/bash -e
+# nrpe client installer for CentOS and Ubuntu
+# Info: This script installs a NRPE client, following [1]
+# [1] https://support.nagios.com/kb/article.php?id=515
+# For use on clean CentOS or Ubuntu box only
+# Usage:
+# wget https://raw.githubusercontent.com/DavidGhedini/nagios-webmin-module/master/scripts/pre-install.sh
+# chmod +x pre-installer
+# ./pre-installer.sh
+
+
+
+#Nagious server, that will monitor this client node
+NAGIOS_MON_HOST='1.2.3.4'
+NAGIOS_HOME='/usr/local/nagios/'
+
+function detect_distro(){
+ if [ -f /etc/centos-release ]; then
+ DISTRO='centos'
+ DISTRO_VER=$(grep VERSION_ID /etc/os-release | tr -d '"' | cut -f2 -d= | cut -f1 -d.)
+
+ #opensuse,debian,slackware, ubuntu
+ elif [ -f /etc/os-release ]; then
+ DISTRO=$(grep -m 1 ID /etc/os-release | cut -f2 -d= | tr -d '"')
+ DISTRO_VER=$(grep VERSION_ID /etc/os-release | tr -d '"' | cut -f2 -d= | cut -f1 -d.)
+ else
+ echo "Error: Failed to detect distribution"; exit 1;
+ fi
+}
+
+function install_deps(){
+
+ if [ ${DISTRO} == 'centos' ]; then
+ yum install -y gcc glibc glibc-common openssl openssl-devel perl wget
+ elif [ ${DISTRO} == 'ubuntu' ]; then
+ export DEBIAN_FRONTEND=noninteractive
+ if [ ${DISTRO_VER} -eq 18 ]; then
+ apt-add-repository universe
+ fi
+ apt-get install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget openssl make
+ fi
+}
+
+function install_nrpe(){
+ NRPE_VER='3.2.1'
+
+ if [ $(grep -m 1 -c '^nagios:' /etc/passwd) -eq 0 ]; then
+ useradd -s /bin/false nagios
+ fi
+
+ pushd ${HOME}
+ if [ ! -f nrpe-${NRPE_VER}.tar.gz ]; then
+ wget --no-check-certificate https://github.com/NagiosEnterprises/nrpe/archive/nrpe-${NRPE_VER}.tar.gz
+ fi
+
+ tar xzf nrpe-${NRPE_VER}.tar.gz
+ rm -f nrpe-${NRPE_VER}.tar.gz
+
+ pushd nrpe-nrpe-${NRPE_VER}/
+
+ if [ $(which systemctl 2>/dev/null | grep -c yum) -eq 1 ]; then
+ ./configure --enable-command-args --with-init-type=systemd
+ else
+ ./configure --enable-command-args
+ fi
+
+ make all install install-groups-users install-plugin install-config install-init
+ popd
+ rm -f nrpe-nrpe-${NRPE_VER}/
+ popd
+}
+
+function config_nrpe(){
+
+ sed -i "/^allowed_hosts=/s/\$/,${NAGIOS_MON_HOST}/" ${NAGIOS_HOME}/etc/nrpe.cfg
+ sed -i 's/^dont_blame_nrpe=.*/dont_blame_nrpe=1/g' ${NAGIOS_HOME}/etc/nrpe.cfg
+
+ #Standard command found in source/package plugins
+ cat >> ${NAGIOS_HOME}/etc/nrpe.cfg <> ${NAGIOS_HOME}/etc/nrpe.cfg <> ${NAGIOS_HOME}/etc/nrpe.cfg
+ done
+
+
+ if [ $(which systemctl 2>/dev/null | grep -c systemctl) -eq 1 ]; then
+ systemctl enable nrpe.service
+ systemctl start nrpe
+ else
+ chkconfig --set nrpe on
+ service nrpe start
+ fi
+}
+
+function install_plugins_source(){
+ PLUG_VER='2.3.1'
+
+ if [ ${DISTRO} == 'centos' ]; then
+ yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release perl-Net-SNMP
+ elif [ ${DISTRO} == 'ubuntu' ]; then
+ apt-get install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
+ fi
+
+ pushd ${HOME}
+ wget --no-check-certificate https://github.com/nagios-plugins/nagios-plugins/archive/release-${PLUG_VER}.tar.gz
+ tar xzf release-${PLUG_VER}.tar.gz
+ rm -f release-${PLUG_VER}.tar.gz
+
+ pushd nagios-plugins-release-${PLUG_VER}/
+ ./tools/setup
+ ./configure
+ make
+ make install
+ popd
+ rm -rf nagios-plugins-release-${PLUG_VER}/
+ popd
+
+ NAGIOS_PLUGINS_HOME='/usr/local/nagios/libexec/'
+}
+
+#Install plugins not found in source or packages
+function install_plugins(){
+
+ install_plugins_source
+}
+
+function test_nrpe(){
+
+ if [ ! -f ${NAGIOS_HOME}/etc/nrpe.cfg ]; then
+ echo 'Error: nrpe.cfg is missing!'
+ fi
+
+ OUT=$(${NAGIOS_HOME}/libexec/check_nrpe -H 127.0.0.1)
+ if [ "${OUT}" == "NRPE v${NRPE_VER}" ]; then
+ echo "NRPE Test OK"
+ else
+ echo "NRPE Test FAILED"
+ exit 1;
+ fi
+}
+
+detect_distro;
+install_deps;
+install_nrpe;
+install_plugins;
+config_nrpe;
+
+test_nrpe;
diff --git a/scripts/pre-install.sh b/scripts/pre-install.sh
new file mode 100644
index 0000000..c208611
--- /dev/null
+++ b/scripts/pre-install.sh
@@ -0,0 +1,119 @@
+# !/bin/bash -e
+# nagios-webmin-module Pre-Install Script for CentOS and Ubuntu
+# For use on clean CentOS or Ubuntu box only
+# Usage:
+# wget https://raw.githubusercontent.com/cited/nagios-webmin-module/master/scripts/pre-install.sh
+# chmod +x pre-installer
+# ./pre-installer.sh
+
+function get_repo(){
+ if [ -f /etc/centos-release ]; then
+ REPO='rpm'
+
+ elif [ -f /etc/debian_version ]; then
+ REPO='apt'
+fi
+}
+
+function install_webmin(){
+
+ if [ "${REPO}" == 'apt' ]; then
+
+ echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list
+ wget -qO - http://www.webmin.com/jcameron-key.asc | apt-key add -
+ apt-get -y update
+ apt-get -y install webmin
+
+ elif [ "${REPO}" == 'rpm' ]; then
+
+cat >/etc/yum.repos.d/webmin.repo < Nagios to complete installation"
+
+}
+
+function install_certbot_module(){
+pushd /opt/
+ if [ "${REPO}" == 'apt' ]; then
+ /usr/share/webmin/install-module.pl certbot.wbm.gz
+ elif [ "${REPO}" == 'rpm' ]; then
+ /usr/libexec/webmin/install-module.pl certbot.wbm.gz
+ fi
+popd
+ echo -e "Certbot is now installed. Go to Servers > Certbot to complete installation"
+
+}
+
+function get_deps(){
+if [ "${REPO}" == 'apt' ]; then
+ apt-get -y install wget unzip
+ elif [ "${REPO}" == 'rpm' ]; then
+ yum -y install wget unzip bzip2
+ fi
+}
+
+function install_apache(){
+ if [ "${REPO}" == 'apt' ]; then
+ apt-get -y install apache2
+ elif [ "${REPO}" == 'rpm' ]; then
+ yum -y install httpd
+ fi
+}
+
+get_repo;
+get_deps;
+install_webmin;
+install_apache;
+download_nagios_webmin_module;
+download_certbot_module;
+install_certbot_module;
+install_nagios_webmin_module;
diff --git a/scripts/ubuntu-preinstall.sh b/scripts/ubuntu-preinstall.sh
new file mode 100644
index 0000000..78122ca
--- /dev/null
+++ b/scripts/ubuntu-preinstall.sh
@@ -0,0 +1,88 @@
+# !/bin/bash -e
+# nagios-webmin-module Pre-Install Script for CentOS and Ubuntu
+# For use on Ubuntu box only
+# Usage:
+# wget https://raw.githubusercontent.com/cited/nagios-webmin-module/master/scripts/pre-install.sh
+# chmod +x pre-installer
+# ./pre-installer.sh
+
+function install_webmin(){
+
+
+
+ echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list
+ wget -qO - http://www.webmin.com/jcameron-key.asc | apt-key add -
+ apt-get -y update
+ apt-get -y install webmin
+
+}
+
+function download_nagios_webmin_module(){
+pushd /tmp/
+ wget https://github.com/cited/nagios-webmin-module/archive/master.zip
+ unzip master.zip
+ mv nagios-webmin-module-master nagios
+ tar -czf /opt/nagios.wbm.gz nagios
+ rm -rf nagios master.zip
+popd
+
+}
+
+function download_certbot_module(){
+pushd /tmp/
+ wget https://github.com/cited/Certbot-Webmin-Module/archive/master.zip
+ unzip master.zip
+ mv Certbot-Webmin-Module-master certbot
+ tar -czf /opt/certbot.wbm.gz certbot
+ rm -rf certbot master.zip
+popd
+}
+
+function install_apache(){
+
+ apt-get -y install apache2
+
+}
+
+function install_nagios_webmin_module(){
+pushd /opt/
+
+ /usr/share/webmin/install-module.pl nagios.wbm.gz
+
+popd
+ echo -e "Nagios Module is now installed. Go to Servers > Nagios to complete installation"
+
+}
+
+function install_certbot_module(){
+pushd /opt/
+
+ /usr/share/webmin/install-module.pl certbot.wbm.gz
+ popd
+ echo -e "Certbot is now installed. Go to Servers > Certbot to complete installation"
+
+}
+
+function get_deps(){
+
+ apt-get -y install wget unzip
+
+
+
+}
+
+function install_apache(){
+
+ apt-get -y install apache2
+
+
+
+}
+
+get_deps;
+install_webmin;
+install_apache;
+download_nagios_webmin_module;
+download_certbot_module;
+install_certbot_module;
+install_nagios_webmin_module;
diff --git a/setup.cgi b/setup.cgi
new file mode 100644
index 0000000..f3164a4
--- /dev/null
+++ b/setup.cgi
@@ -0,0 +1,218 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+require '../webmin/webmin-lib.pl'; #for OS detection
+
+foreign_require('apache', 'apache-lib.pl');
+foreign_require('software', 'software-lib.pl');
+
+$www_user = 'www-data';
+$nrpe_ver = '3.2.1';
+
+sub install_nagios_core{
+ my $nagios_ver = '4.4.5';
+ my $tmpfile = download_file('https://github.com/NagiosEnterprises/nagioscore/archive/nagios-'.$nagios_ver.'.tar.gz');
+
+ exec_cmd('groupadd -r nagios');
+ exec_cmd('usermod -a -G nagios '.$www_user);
+
+ &apache::add_configured_apache_module('rewrite');
+ &apache::add_configured_apache_module('cgi');
+ &apache::restart_apache();
+
+ my $sh_file = &transname('nagios.sh');
+ open($fh, '>', $sh_file) or die "open:$!";
+ printf $fh 'cd /tmp'."\n";
+ printf $fh 'tar -xf '.$tmpfile."\n";
+ printf $fh 'cd /tmp/nagioscore-nagios-'.$nagios_ver."\n";
+ if(-d '/etc/apache2/sites-enabled'){
+ printf $fh './configure --with-httpd-conf=/etc/apache2/sites-enabled'."\n";
+ }elsif(-d '/etc/httpd/conf.d/'){
+ printf $fh './configure --with-httpd-conf=/etc/httpd/conf.d'."\n";
+ }
+ printf $fh 'make all install-groups-users install install-daemoninit install-commandmode install-config install-webconf'."\n";
+ close $fh;
+ exec_cmd('bash '.$sh_file);
+
+ my $nag_pass;
+ my @pw_chars = ("A".."Z", "a".."z", "0".."9", "_", "-");
+ $nag_pass .= $pw_chars[rand @pw_chars] for 1..10;
+
+ exec_cmd('echo "'.$nag_pass.'" | htpasswd -i -c /usr/local/nagios/etc/htpasswd.users nagiosmin');
+
+ printf "
Nagios HTTP password saved in ".$module_config_directory.'/auth.txt';
+ open($fh, '>>', $module_config_directory.'/auth.txt') or die "open:$!";
+ print $fh 'nagiosmin http pass:'.$nag_pass."\n";
+ close $fh;
+
+ &unlink_file('/tmp/nagioscore-nagios-'.$nagios_ver);
+}
+
+sub install_nagios_plugins{
+ my $plugins_ver = '2.3.1';
+ my $tmpfile = download_file('https://github.com/nagios-plugins/nagios-plugins/archive/release-'.$plugins_ver.'.tar.gz');
+
+ my $sh_file = &transname('plugins.sh');
+ open($fh, '>', $sh_file) or die "open:$!";
+ printf $fh 'cd /tmp'."\n";
+ printf $fh 'tar -xf '.$tmpfile."\n";
+ printf $fh 'cd /tmp/nagios-plugins-release-'.$plugins_ver."\n";
+ printf $fh './tools/setup'."\n";
+ printf $fh './configure'."\n";
+ printf $fh 'make'."\n";
+ printf $fh 'make install'."\n";
+ close $fh;
+
+ exec_cmd('bash '.$sh_file);
+
+ exec_cmd('systemctl restart nagios.service');
+ &unlink_file('/tmp/nagios-plugins-release-'.$plugins_ver);
+}
+
+sub install_nagios_nrpe_service{
+ my $sh_file = &transname('nrpe.sh');
+ open($fh, '>', $sh_file) or die "open:$!";
+
+ if(! -d '/tmp/nrpe-'.$nrpe_ver){
+ my $tmpfile = download_file('https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-'.$nrpe_ver.'/nrpe-'.$nrpe_ver.'.tar.gz');
+ printf $fh 'cd /tmp'."\n";
+ printf $fh 'tar -xf '.$tmpfile."\n";
+ printf $fh 'cd nrpe-'.$nrpe_ver."\n";
+ printf $fh './configure'."\n";
+ }
+ printf $fh 'cd /tmp/nrpe-'.$nrpe_ver."\n";
+ printf $fh 'make nrpe install-daemon install-config install-init'."\n";
+ close $fh;
+
+ exec_cmd('bash '.$sh_file);
+}
+
+sub install_nagios_nrpe_plugin{
+
+ my $sh_file = &transname('nrpe.sh');
+ open($fh, '>', $sh_file) or die "open:$!";
+
+ if(! -d '/tmp/nrpe-'.$nrpe_ver){
+ my $tmpfile = download_file('https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-'.$nrpe_ver.'/nrpe-'.$nrpe_ver.'.tar.gz');
+ printf $fh 'cd /tmp'."\n";
+ printf $fh 'tar -xf '.$tmpfile."\n";
+ printf $fh 'cd nrpe-'.$nrpe_ver."\n";
+ printf $fh './configure'."\n";
+ }
+ printf $fh 'cd /tmp/nrpe-'.$nrpe_ver."\n";
+ printf $fh 'make check_nrpe install-plugin'."\n";
+ close $fh;
+
+ exec_cmd('bash '.$sh_file);
+}
+
+sub setup_checks{
+
+ #Check for commands
+ if (!&has_command('tar')) {
+ print 'Warning: tar command is not found. Install it manually or '.
+ "click here to have it downloaded and installed.
";
+ }
+
+ if($osinfo{'real_os_type'} =~ /centos/i){ #CentOS
+ my @pinfo = software::package_info('epel-release', undef, );
+ if(!@pinfo){
+ print "Warning: EPEL repository is not installed. Install it manually or ".
+ "click here to have it downloaded and installed.
";
+ }
+ }
+
+ my @dep_pkgs;
+ if( ( $osinfo{'real_os_type'} =~ /centos/i) or #CentOS
+ ($osinfo{'real_os_type'} =~ /fedora/i) or #Fedora
+ ($osinfo{'real_os_type'} =~ /scientific/i) ){
+ @dep_pkgs = ('httpd', 'httpd-tools', 'gcc', 'glibc', 'glibc-common', 'gd', 'gd-devel', 'perl', 'perl-Net-SNMP', 'make', 'gettext', 'automake', 'autoconf', 'openssl-devel', 'net-snmp', 'net-snmp-utils', 'krb5-devel');
+ }elsif( ($osinfo{'real_os_type'} =~ /ubuntu/i) or
+ ($osinfo{'real_os_type'} =~ /debian/i) ){ #ubuntu or debian
+ @dep_pkgs = ('apache2', 'autoconf', 'gcc', 'libc6', 'make', 'unzip', 'php', 'libapache2-mod-php', 'libgd-dev', 'libwww-perl', 'libmcrypt-dev', 'libssl-dev', 'bc', 'gawk', 'dc', 'build-essential', 'snmp', 'libnet-snmp-perl', 'gettext', 'libkrb5-dev');
+ }
+
+ my @pkg_missing;
+ foreach my $pkg (@dep_pkgs){
+ my @pinfo = software::package_info($pkg);
+ if(!@pinfo){
+ push(@pkg_missing, $pkg);
+ }
+ }
+
+ if(@pkg_missing){
+ my $url_pkg_list = '';
+ foreach my $pkg (@pkg_missing){
+ $url_pkg_list .= '&u='.&urlize($pkg);
+ }
+ my $pkg_list = join(', ', @pkg_missing);
+
+ print "Warning: Missing Nagios dependencies - $pkg_list packages are not installed. Install them manually or ".
+ "click here to have them installed.
";
+ }
+
+ if(! -d '/usr/local/nagios/'){
+ print "Nagios core not installed. ".
+ "Click here install it";
+ }
+
+ if(! -f '/usr/local/nagios/libexec/check_apt'){
+ print "
Nagios Plugins not installed. ".
+ "Click here install it";
+ }
+
+ if(! -f '/usr/local/nagios/etc/nrpe.cfg'){
+ print "
Nagios NRPE Service is not installed. ".
+ "Click here install it";
+ }
+
+ if(! -f '/usr/local/nagios/libexec/check_nrpe'){
+ print "
Nagios NRPE Plugin is not installed. ".
+ "Click here install it";
+ }
+
+ print '
If you don\'t see any warnings above, you can complete setup by clicking '.
+ "here
";
+}
+
+#Remove all setup files
+sub setup_cleanup{
+ print "Completing Set Up....";
+ &unlink_file($module_root_directory.'/setup.cgi');
+ &unlink_file('/tmp/nrpe-'.$nrpe_ver);
+ print &js_redirect("index.cgi");
+}
+
+
+&ui_print_header(undef, $text{'setup_title'}, "");
+
+if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) {
+ &ReadParseMime();
+}else {
+ &ReadParse(); $no_upload = 1;
+}
+
+my $mode = $in{'mode'} || "checks";
+%osinfo = &detect_operating_system();
+
+if( ( $osinfo{'real_os_type'} =~ /centos/i) or #CentOS
+ ($osinfo{'real_os_type'} =~ /fedora/i) or #Fedora
+ ($osinfo{'real_os_type'} =~ /scientific/i) ){
+ $www_user = 'apache';
+}
+
+if($mode eq "checks"){ setup_checks();
+ &ui_print_footer('', $text{'index_return'});
+ exit 0;
+}elsif($mode eq "cleanup"){ setup_cleanup();
+ &ui_print_footer('', $text{'index_return'});
+ exit 0;
+}elsif($mode eq "install_nagios_core"){ install_nagios_core();
+}elsif($mode eq "install_nagios_plugins"){ install_nagios_plugins();
+}elsif($mode eq "install_nagios_nrpe_service"){ install_nagios_nrpe_service();
+}elsif($mode eq "install_nagios_nrpe_plugin"){ install_nagios_nrpe_plugin();
+}else{
+ print "Error: Invalid setup mode\n";
+}
+
+&ui_print_footer('setup.cgi', $text{'setup_title'});
diff --git a/start.cgi b/start.cgi
new file mode 100644
index 0000000..9f19b76
--- /dev/null
+++ b/start.cgi
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&ReadParse();
+&error_setup($text{'start_err'});
+
+my ($err, $out) = exec_cmd('systemctl start nagios');
+&error($out) if ($err);
+
+&redirect("");
diff --git a/start_nrpe.cgi b/start_nrpe.cgi
new file mode 100644
index 0000000..9527d3e
--- /dev/null
+++ b/start_nrpe.cgi
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&ReadParse();
+&error_setup($text{'start_err'});
+
+my ($err, $out) = exec_cmd('systemctl start nrpe');
+&error($out) if ($err);
+
+&redirect("");
diff --git a/stop.cgi b/stop.cgi
new file mode 100644
index 0000000..d994a94
--- /dev/null
+++ b/stop.cgi
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&ReadParse();
+&error_setup($text{'start_err'});
+
+my ($err, $out) = exec_cmd('systemctl stop nagios');
+&error($out) if ($err);
+
+&redirect("");
diff --git a/stop_nrpe.cgi b/stop_nrpe.cgi
new file mode 100644
index 0000000..0f52c38
--- /dev/null
+++ b/stop_nrpe.cgi
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+require './nagios-lib.pl';
+&ReadParse();
+&error_setup($text{'start_err'});
+
+my ($err, $out) = exec_cmd('systemctl stop nrpe');
+&error($out) if ($err);
+
+&redirect("");
diff --git a/template.cfg b/template.cfg
new file mode 100644
index 0000000..a99870b
--- /dev/null
+++ b/template.cfg
@@ -0,0 +1,57 @@
+# Host configuration file
+
+define host {
+ use linux-server
+ host_name
+ alias
+ address
+ register 1
+}
+
+define service {
+ host_name
+ service_description PING
+ check_command check_ping!100.0,20%!500.0,60%
+ max_check_attempts 2
+ check_interval 2
+ retry_interval 2
+ check_period 24x7
+ check_freshness 1
+ contact_groups admins,slackmins
+ notification_interval 2
+ notification_period 24x7
+ notifications_enabled 1
+ register 1
+}
+
+define service {
+ host_name
+ service_description Check SSH
+ check_command check_ssh!-p 3838
+ max_check_attempts 2
+ check_interval 2
+ retry_interval 2
+ check_period 24x7
+ check_freshness 1
+ contact_groups admins
+ notification_interval 2
+ notification_period 24x7
+ notifications_enabled 1
+ register 1
+}
+
+define service {
+ host_name
+ service_description Check HTTP
+ check_command check_http
+ max_check_attempts 2
+ check_interval 2
+ retry_interval 2
+ check_period 24x7
+ check_freshness 1
+ contact_groups admins
+ notification_interval 2
+ notification_period 24x7
+ notifications_enabled 1
+ register 1
+}