Skip to content

Commit

Permalink
Merge pull request #7 from nunofernandes/6-address-changes-icinga2-211
Browse files Browse the repository at this point in the history
Change the icinga ca list command line to address changes in Icinga 2.11
  • Loading branch information
nunofernandes authored May 14, 2019
2 parents 8e83892 + 6adab78 commit dfde67a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 32 additions & 2 deletions application/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion module.info
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit dfde67a

Please sign in to comment.