mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-19 02:29:16 -05:00
I've used the following command to replace the original copyright header
lines in a C-style comment block:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
For files that use shell-style comments (#) like CMakeLists.txt, I've
used this command:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
And for SQL files:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
90 lines
2.5 KiB
C++
90 lines
2.5 KiB
C++
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#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 <iostream>
|
|
|
|
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,
|
|
[[maybe_unused]] 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, [[maybe_unused]] const std::vector<std::string>& 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;
|
|
}
|