mgmt: management tools
refs #2034
Change-Id: I43ff11e0aa7e67f6207e75f139b7417779590efc
diff --git a/tools/ndns-export-certificate.cpp b/tools/ndns-export-certificate.cpp
new file mode 100644
index 0000000..701aa20
--- /dev/null
+++ b/tools/ndns-export-certificate.cpp
@@ -0,0 +1,103 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mgmt/management-tool.hpp"
+#include "ndns-label.hpp"
+#include "logger.hpp"
+#include <boost/program_options.hpp>
+#include <boost/filesystem.hpp>
+#include <string>
+
+int
+main(int argc, char* argv[])
+{
+ using std::string;
+ using namespace ndn;
+ using namespace ndns;
+
+ ndn::ndns::log::init();
+ string certStr;
+ string db;
+ string output = "-";
+ try {
+ namespace po = boost::program_options;
+ po::variables_map vm;
+
+ po::options_description options("Generic Options");
+ options.add_options()
+ ("help,h", "print help message")
+ ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
+ "Default: " DEFAULT_DATABASE_PATH "/ndns.db");
+
+ po::options_description config("Output Options");
+ config.add_options()
+ ("output,o", po::value<string>(&output), "Set the output path of the to be export cert. "
+ "Default: stdout(-)")
+ ;
+
+ options.add(config);
+
+ po::options_description hidden("Hidden Options");
+ hidden.add_options()
+ ("certName", po::value<string>(&certStr), "the name of the certificate")
+ ;
+
+ po::positional_options_description postion;
+ postion.add("certName", 1);
+
+ po::options_description cmdline_options;
+ cmdline_options.add(options).add(hidden);
+
+ // po::options_description config_file_options;
+ // config_file_options.add(config).add(hidden);
+
+ po::parsed_options parsed =
+ po::command_line_parser(argc, argv).options(cmdline_options).positional(postion).run();
+
+ po::store(parsed, vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cout << "Usage: ndns-export-certificate [-b db] certificateName [-o output] "
+ << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("certName") == 0) {
+ std::cerr << "Error: certificate name must be specified" << std::endl;
+ return 1;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name certName(certStr);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.exportCertificate(certName, output);
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}