From 0915b3ef56dfac3113cce55a59a5765dc94976be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:34:54 +0200 Subject: Adding upstream version 2.13.6. Signed-off-by: Daniel Baumann --- lib/cli/calistcommand.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 lib/cli/calistcommand.cpp (limited to 'lib/cli/calistcommand.cpp') diff --git a/lib/cli/calistcommand.cpp b/lib/cli/calistcommand.cpp new file mode 100644 index 0000000..f693ad7 --- /dev/null +++ b/lib/cli/calistcommand.cpp @@ -0,0 +1,89 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#include "cli/calistcommand.hpp" +#include "remote/apilistener.hpp" +#include "remote/pkiutility.hpp" +#include "base/logger.hpp" +#include "base/application.hpp" +#include "base/tlsutility.hpp" +#include "base/json.hpp" +#include + +using namespace icinga; +namespace po = boost::program_options; + +REGISTER_CLICOMMAND("ca/list", CAListCommand); + +/** + * Provide a long CLI description sentence. + * + * @return text + */ +String CAListCommand::GetDescription() const +{ + return "Lists pending certificate signing requests."; +} + +/** + * Provide a short CLI description. + * + * @return text + */ +String CAListCommand::GetShortDescription() const +{ + return "lists pending certificate signing requests"; +} + +/** + * Initialize available CLI parameters. + * + * @param visibleDesc Register visible parameters. + * @param hiddenDesc Register hidden parameters. + */ +void CAListCommand::InitParameters(boost::program_options::options_description& visibleDesc, + boost::program_options::options_description& hiddenDesc) const +{ + visibleDesc.add_options() + ("all", "List all certificate signing requests, including signed. Note: Old requests are automatically cleaned by Icinga after 1 week.") + ("removed", "List all removed CSRs (for use with 'ca restore')") + ("json", "encode output as JSON"); +} + +/** + * The entry point for the "ca list" CLI command. + * + * @return An exit status. + */ +int CAListCommand::Run(const boost::program_options::variables_map& vm, const std::vector& ap) const +{ + Dictionary::Ptr requests = PkiUtility::GetCertificateRequests(vm.count("removed")); + + if (vm.count("json")) + std::cout << JsonEncode(requests); + else { + ObjectLock olock(requests); + + std::cout << "Fingerprint | Timestamp | Signed | Subject\n"; + std::cout << "-----------------------------------------------------------------|--------------------------|--------|--------\n"; + + for (auto& kv : requests) { + Dictionary::Ptr request = kv.second; + + /* Skip signed requests by default. */ + if (!vm.count("all") && request->Contains("cert_response")) + continue; + + std::cout << kv.first + << " | " +/* << Utility::FormatDateTime("%Y/%m/%d %H:%M:%S", request->Get("timestamp")) */ + << request->Get("timestamp") + << " | " + << (request->Contains("cert_response") ? "*" : " ") << " " + << " | " + << request->Get("subject") + << "\n"; + } + } + + return 0; +} -- cgit v1.2.3