]> granicus.if.org Git - icinga2/blob - lib/cli/calistcommand.cpp
ApiListener#ApiTimerHandler(): delete all replayed logs
[icinga2] / lib / cli / calistcommand.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/)      *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #include "cli/calistcommand.hpp"
21 #include "remote/apilistener.hpp"
22 #include "remote/pkiutility.hpp"
23 #include "base/logger.hpp"
24 #include "base/application.hpp"
25 #include "base/tlsutility.hpp"
26 #include "base/json.hpp"
27 #include <iostream>
28
29 using namespace icinga;
30 namespace po = boost::program_options;
31
32 REGISTER_CLICOMMAND("ca/list", CAListCommand);
33
34 String CAListCommand::GetDescription() const
35 {
36         return "Lists all certificate signing requests.";
37 }
38
39 String CAListCommand::GetShortDescription() const
40 {
41         return "lists all certificate signing requests";
42 }
43
44 void CAListCommand::InitParameters(boost::program_options::options_description& visibleDesc,
45         boost::program_options::options_description& hiddenDesc) const
46 {
47         visibleDesc.add_options()
48                 ("json", "encode output as JSON")
49         ;
50 }
51
52 /**
53  * The entry point for the "ca list" CLI command.
54  *
55  * @returns An exit status.
56  */
57 int CAListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
58 {
59         Dictionary::Ptr requests = PkiUtility::GetCertificateRequests();
60
61         if (vm.count("json"))
62                 std::cout << JsonEncode(requests);
63         else {
64                 ObjectLock olock(requests);
65
66                 std::cout << "Fingerprint                                                      | Timestamp                | Signed | Subject\n";
67                 std::cout << "-----------------------------------------------------------------|--------------------------|--------|--------\n";
68
69                 for (auto& kv : requests) {
70                         Dictionary::Ptr request = kv.second;
71
72                         std::cout << kv.first
73                                 << " | "
74 /*                          << Utility::FormatDateTime("%Y/%m/%d %H:%M:%S", request->Get("timestamp")) */
75                                 << request->Get("timestamp")
76                                 << " | "
77                                 << (request->Contains("cert_response") ? "*" : " ") << "     "
78                                 << " | "
79                                 << request->Get("subject")
80                                 << "\n";
81                 }
82         }
83
84         return 0;
85 }