diff --git a/README.md b/README.md index 63e718c..a7e8c6f 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Clone the repository via Git to your Icinga Web 2 `modules` directory. ``` # vi /etc/sudoers.d/apache -Cmnd_Alias CA_CMDS = /usr/sbin/icinga2 ca list, /usr/sbin/icinga2 ca sign * +Cmnd_Alias CA_CMDS = /usr/sbin/icinga2 ca list, /usr/sbin/icinga2 ca sign *, /usr/sbin/icinga2 ca list --all Cmnd_Alias APACHE_COMMANDS = CA_CMDS User_Alias APACHEUSERS = apache diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index c3a1449..7f870e0 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -67,11 +67,41 @@ public function signCertificate($fingerprint) return $output; } + public function icinga2Version() + { + $command = $this->icinga2bin . " --version"; + $output = shell_exec($command." 2>&1"); + + $temp = preg_split('/\n/', $output, -1, PREG_SPLIT_NO_EMPTY); + $lines = preg_grep('/RLIMIT_/', $temp, PREG_GREP_INVERT); + $lines = array_values($lines); + # get first line + $version = $lines[0]; + # Match version string + if (preg_match('/r(\d+)\.(\d+)/', $version, $matches)) { + $ret['major'] = $matches[1]; + $ret['minor'] = $matches[2]; + return $ret; + } else { + return; + } + } + public function parseIcingaCaList() { - $command = $this->command . " ca list"; - $output = shell_exec($command." 2>&1"); + # check version of icinga2 (https://github.com/nunofernandes/icingaweb2-module-ca/issues/6) + $version = $this->icinga2Version(); + if (!empty($version) and !empty($version['major']) and !empty($version['minor'])) { + if ($version['major'] == "2" and ((int)$version['minor'])<11) { + $command = $this->command . " ca list"; + } else { + $command = $this->command . " ca list --all"; + } + } else { # fallback to the new defaults and hope for the best + $command = $this->command . " ca list --all"; + } + $output = shell_exec($command." 2>&1"); $temp = preg_split('/\n/', $output, -1, PREG_SPLIT_NO_EMPTY); $lines = preg_grep('/RLIMIT_/', $temp, PREG_GREP_INVERT); $lines = array_values($lines); diff --git a/module.info b/module.info index 1a7501d..b95b5ee 100644 --- a/module.info +++ b/module.info @@ -1,5 +1,5 @@ Name: Ca -Version: 1.0.2 +Version: 1.0.3 Depends: monitoring (>= 2.5.1) Description: Icinga CA Manager This module manages the certificate requests for Icinga CA.