mgmt: management tools
refs #2034
Change-Id: I43ff11e0aa7e67f6207e75f139b7417779590efc
diff --git a/tools/ndns-add-rr-from-file.cpp b/tools/ndns-add-rr-from-file.cpp
new file mode 100644
index 0000000..4fc2066
--- /dev/null
+++ b/tools/ndns-add-rr-from-file.cpp
@@ -0,0 +1,118 @@
+/* -*- 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>
+
+
+// @todo combine this command with ndns-add-rr
+int
+main(int argc, char* argv[])
+{
+ using std::string;
+ using namespace ndn;
+ using namespace ndns;
+
+ ndn::ndns::log::init();
+ int ttlInt = -1;
+ string zoneStr;
+ string dskStr;
+ string db;
+ string file = "-";
+ 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("Record Options");
+ config.add_options()
+ ("file,f", po::value<string>(&file), "Path to the data. Default is stdin(-)")
+ ("dsk,d", po::value<std::string>(&dskStr), "Set the name of DSK's certificate. "
+ "Default: use default DSK and its default certificate")
+ ("ttl,a", po::value<int>(&ttlInt), "Set ttl of the rrset. Default: 3600 seconds")
+ ;
+
+ options.add(config);
+
+ po::options_description hidden("Hidden Options");
+ hidden.add_options()
+ ("zone", po::value<string>(&zoneStr), "host zone name")
+ ;
+
+ po::positional_options_description postion;
+ postion.add("zone", 1);
+ postion.add("file", 1);
+
+ po::options_description cmdlineOptions;
+ cmdlineOptions.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(cmdlineOptions).positional(postion).run();
+
+ po::store(parsed, vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cout << "Usage: ndns-add-rr-from-file [-b db] zone [-f file] [-d dskCert] [-a ttl]"
+ " [file]" << std::endl
+ << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("zone") == 0) {
+ std::cerr << "Error: zone must be specified" << std::endl;
+ return 1;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name zoneName(zoneStr);
+ Name dskName(dskStr);
+ time::seconds ttl;
+ if (ttlInt == -1)
+ ttl = ndns::DEFAULT_CACHE_TTL;
+ else
+ ttl = time::seconds(ttlInt);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.addRrSet(zoneName, file, ttl, dskName);
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}
diff --git a/tools/ndns-add-rr.cpp b/tools/ndns-add-rr.cpp
new file mode 100644
index 0000000..47e7121
--- /dev/null
+++ b/tools/ndns-add-rr.cpp
@@ -0,0 +1,161 @@
+/* -*- 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 "util/util.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();
+ int ttlInt = -1;
+ int versionInt = -1;
+ string zoneStr;
+ Name dsk;
+ string db;
+ string rrLabelStr;
+ string rrTypeStr;
+ string ndnsTypeStr;
+ std::vector<std::string> content;
+ 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("Record Options");
+ config.add_options()
+ ("content-type,t", po::value<string>(&ndnsTypeStr), "Set the ndnsType of the resource record."
+ "Options: resp|nack|auth|raw (will try guess type by default)")
+ ("dsk,d", po::value<Name>(&dsk), "Set the name of DSK's certificate. "
+ "Default: use default DSK and its default certificate")
+ ("content,c", po::value<std::vector<std::string>>(&content),
+ "Set the content of resource record. Default: empty string")
+ ("ttl,a", po::value<int>(&ttlInt), "Set ttl of the rrset. Default: 3600 seconds")
+ ("version,v", po::value<int>(&ttlInt), "Set version of the rrset. Default: Unix Timestamp")
+ ;
+
+ // add "Record Options" as a separate section
+ options.add(config);
+
+ po::options_description hidden("Hidden Options");
+ hidden.add_options()
+ ("zone", po::value<string>(&zoneStr), "host zone name")
+ ("label", po::value<string>(&rrLabelStr), "label of resource record.")
+ ("type", po::value<string>(&rrTypeStr), "Set the type of resource record.")
+ ;
+
+ po::positional_options_description positional;
+ positional.add("zone", 1);
+ positional.add("label", 1);
+ positional.add("type", 1);
+ positional.add("content", -1);
+
+ po::options_description cmdlineOptions;
+ cmdlineOptions.add(options).add(hidden);
+
+ // po::options_description configFileOptions;
+ // configFileOptions.add(config).add(hidden);
+
+ po::parsed_options parsed =
+ po::command_line_parser(argc, argv).options(cmdlineOptions).positional(positional).run();
+
+ po::store(parsed, vm);
+ po::notify(vm);
+
+
+ if (vm.count("help")) {
+ std::cout << "Usage: ndns-add-rr [options] zone label type [content ...]" << std::endl
+ << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("zone") == 0) {
+ std::cerr << "Error: zone, label, and type must be specified" << std::endl;
+ return 1;
+ }
+
+ if (vm.count("label") == 0) {
+ std::cerr << "Error: label and type must be specified" << std::endl;
+ return 1;
+ }
+
+ if (vm.count("type") == 0) {
+ std::cerr << "Error: type must be specified" << std::endl;
+ return 1;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name zoneName(zoneStr);
+ Name label(rrLabelStr);
+ name::Component type(rrTypeStr);
+
+ if (ndnsTypeStr.empty()) {
+ if (rrTypeStr == "NS" || rrTypeStr == "TXT")
+ ndnsTypeStr = "resp";
+ else if (rrTypeStr == "ID-CERT") {
+ ndnsTypeStr = "raw";
+ }
+ else {
+ std::cerr << "Error: content type needs to be explicitly set using --content-type option"
+ << std::endl;
+ return 1;
+ }
+ }
+ NdnsType ndnsType = ndns::toNdnsType(ndnsTypeStr);
+ time::seconds ttl;
+ if (ttlInt == -1)
+ ttl = ndns::DEFAULT_CACHE_TTL;
+ else
+ ttl = time::seconds(ttlInt);
+ uint64_t version = static_cast<uint64_t>(versionInt);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.addRrSet(zoneName, label, type, ndnsType, version, content, dsk, ttl);
+
+ /// @todo Report success or failure
+ // May be also show the inserted record in ndns-list-zone format
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}
diff --git a/tools/ndns-create-zone.cpp b/tools/ndns-create-zone.cpp
new file mode 100644
index 0000000..0893bc7
--- /dev/null
+++ b/tools/ndns-create-zone.cpp
@@ -0,0 +1,133 @@
+/* -*- 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 "config.hpp"
+
+#include <boost/program_options.hpp>
+#include <boost/filesystem.hpp>
+#include <string>
+
+int
+main(int argc, char* argv[])
+{
+ using std::string;
+ using namespace ndn;
+ ndn::ndns::log::init();
+ int cacheTtlInt = -1;
+ int certTtlInt = -1;
+ string zoneStr;
+ string parentStr;
+ string dskStr;
+ string kskStr;
+ string db;
+ 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("Zone Options");
+ config.add_options()
+ ("cacheTtl,a", po::value<int>(&cacheTtlInt), "Set ttl of records of the zone and its "
+ "DSK ID-CERT. Default: 3600 seconds")
+ ("certTtl,e", po::value<int>(&certTtlInt), "Set ttl of DSK and KSK certificates. "
+ "Default: 365 days")
+ ("parent,p", po::value<std::string>(&parentStr), "Set the parent zone of the zone to be "
+ "created. Default: the zone's direct parent")
+ ("dsk,d", po::value<std::string>(&dskStr), "Set the name of DSK's certificate, "
+ "Default: generate new key and certificate")
+ ("ksk,k", po::value<std::string>(&kskStr), "Set the name of KSK's certificate, "
+ "Default: generate new key and certificate")
+ ;
+
+ options.add(config);
+
+ po::options_description hidden("Hidden Options");
+ hidden.add_options()
+ ("zone", po::value<string>(&zoneStr), "name of the zone to be created")
+ ;
+ po::positional_options_description postion;
+ postion.add("zone", 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-create-zone [-b db] zone [-a cacheTtl] [-e certTtl] [-p parent] "
+ "[-d dskCert] [-k kskCert]" << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("zone") == 0) {
+ std::cerr << "Error: zone must be specified" << std::endl;
+ return 1;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name zone(zoneStr);
+ Name parent(parentStr);
+ if (!zone.empty() && parentStr.empty())
+ parent = zone.getPrefix(-1);
+
+ Name ksk(kskStr);
+ Name dsk(dskStr);
+
+ time::seconds cacheTtl;
+ time::seconds certTtl;
+ if (cacheTtlInt == -1)
+ cacheTtl = ndns::DEFAULT_CACHE_TTL;
+ else
+ cacheTtl = time::seconds(cacheTtlInt);
+
+ if (certTtlInt == -1)
+ certTtl = ndns::DEFAULT_CERT_TTL;
+ else
+ certTtl = time::seconds(certTtlInt);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.createZone(zone, parent, cacheTtl, certTtl, ksk, dsk);
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}
diff --git a/tools/ndns-delete-zone.cpp b/tools/ndns-delete-zone.cpp
new file mode 100644
index 0000000..12bc7f3
--- /dev/null
+++ b/tools/ndns-delete-zone.cpp
@@ -0,0 +1,88 @@
+/* -*- 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;
+ ndn::ndns::log::init();
+ string zoneStr;
+ string db;
+ 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 hidden("Hidden Options");
+ hidden.add_options()
+ ("zone", po::value<string>(&zoneStr), "name of the zone to be deleted")
+ ;
+ po::positional_options_description postion;
+ postion.add("zone", 1);
+
+ po::options_description cmdline_options;
+ cmdline_options.add(options).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-delete-zone zone [-b db]" << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("zone") == 0) {
+ std::cerr << "Error: zone must be specified" << std::endl;
+ return 1;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name zone(zoneStr);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.deleteZone(zone);
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}
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;
+ }
+}
diff --git a/tools/ndns-get-rr.cpp b/tools/ndns-get-rr.cpp
new file mode 100644
index 0000000..bdf86e0
--- /dev/null
+++ b/tools/ndns-get-rr.cpp
@@ -0,0 +1,109 @@
+/* -*- 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 zoneStr;
+ string db;
+ string rrLabelStr;
+ string rrTypeStr;
+ 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 hidden("Hidden Options");
+ hidden.add_options()
+ ("zone", po::value<string>(&zoneStr), "host zone name")
+ ("label", po::value<string>(&rrLabelStr), "label of the resource record.")
+ ("type", po::value<string>(&rrTypeStr), "type of the resource record.")
+ ;
+
+ po::positional_options_description postion;
+ postion.add("zone", 1);
+ postion.add("label", 1);
+ postion.add("type", 1);
+
+ po::options_description cmdline_options;
+ cmdline_options.add(options).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-get-rr zone label type [-b db]" << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("zone") == 0) {
+ std::cerr << "Error: zone must be specified" << std::endl;
+ return 1;
+ }
+
+ if (vm.count("label") == 0) {
+ std::cerr << "Error: label must be specified" << std::endl;
+ return 1;
+ }
+
+ if (vm.count("type") == 0) {
+ std::cerr << "Error: type must be specified" << std::endl;
+ return 1;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name zoneName(zoneStr);
+ Name label(rrLabelStr);
+ name::Component type(rrTypeStr);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.getRrSet(zoneName, label, type, std::cout);
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}
diff --git a/tools/ndns-list-all-zones.cpp b/tools/ndns-list-all-zones.cpp
new file mode 100644
index 0000000..98c33f3
--- /dev/null
+++ b/tools/ndns-list-all-zones.cpp
@@ -0,0 +1,80 @@
+/* -*- 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>
+#include <iostream>
+
+int
+main(int argc, char* argv[])
+{
+ using std::string;
+ using namespace ndn;
+ using namespace ndns;
+
+ ndn::ndns::log::init();
+ string zoneStr;
+ string db;
+ 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::positional_options_description postion;
+ postion.add("zone", 1);
+
+ po::options_description cmdline_options;
+ cmdline_options.add(options);
+
+ 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-list-all-zones [-b db]" << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ ndn::ndns::ManagementTool tool(db);
+ tool.listAllZones(std::cout);
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}
diff --git a/tools/ndns-list-zone.cpp b/tools/ndns-list-zone.cpp
new file mode 100644
index 0000000..f1a85a2
--- /dev/null
+++ b/tools/ndns-list-zone.cpp
@@ -0,0 +1,107 @@
+/* -*- 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>
+#include <iostream>
+
+int
+main(int argc, char* argv[])
+{
+ using std::string;
+ using namespace ndn;
+ using namespace ndns;
+
+ ndn::ndns::log::init();
+ string zoneStr;
+ string db;
+ bool printRaw = false;
+ 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()
+ ("printRaw,p", "Set to print raw data")
+ ;
+
+ options.add(config);
+
+ po::options_description hidden("Hidden Options");
+ hidden.add_options()
+ ("zone", po::value<string>(&zoneStr), "zone name to investigate")
+ ;
+
+ po::positional_options_description positional;
+ positional.add("zone", 1);
+
+ po::options_description cmdlineOptions;
+ cmdlineOptions.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(cmdlineOptions).positional(positional).run();
+
+ po::store(parsed, vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cout << "Usage: ndns-list-zone zone [-b db] [-p printRaw]" << std::endl
+ << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("zone") == 0) {
+ std::cerr << "Error: zone must be specified" << std::endl;
+ return 1;
+ }
+
+ if (vm.count("printRaw") != 0) {
+ printRaw = true;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name zoneName(zoneStr);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.listZone(zoneName, std::cout, printRaw);
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}
diff --git a/tools/ndns-remove-rr.cpp b/tools/ndns-remove-rr.cpp
new file mode 100644
index 0000000..a3fdf89
--- /dev/null
+++ b/tools/ndns-remove-rr.cpp
@@ -0,0 +1,115 @@
+/* -*- 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 zoneStr;
+ string db;
+ string rrLabelStr;
+ string rrTypeStr;
+ 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 hidden("Hidden Options");
+ hidden.add_options()
+ ("zone", po::value<string>(&zoneStr), "host zone name")
+ ("label", po::value<string>(&rrLabelStr), "label of the resource record.")
+ ("type", po::value<string>(&rrTypeStr), "type of the resource record.")
+ ;
+
+ po::positional_options_description positional;
+ positional.add("zone", 1);
+ positional.add("label", 1);
+ positional.add("type", 1);
+
+ po::options_description cmdlineOptions;
+ cmdlineOptions.add(options).add(hidden);
+
+ // po::options_description configFileOptions;
+ // config_file_options.add(config).add(hidden);
+
+ po::parsed_options parsed =
+ po::command_line_parser(argc, argv).options(cmdlineOptions).positional(positional).run();
+
+ po::store(parsed, vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cout << "Usage: ndns-remove-rr [-b db] zone label type" << std::endl
+ << std::endl;
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ if (vm.count("zone") == 0) {
+ std::cerr << "Error: zone, label, and type must be specified" << std::endl;
+ return 1;
+ }
+
+ if (vm.count("label") == 0) {
+ std::cerr << "Error: label and type must be specified" << std::endl;
+ return 1;
+ }
+
+ if (vm.count("type") == 0) {
+ std::cerr << "Error: type must be specified" << std::endl;
+ return 1;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Parameter Error: " << ex.what() << std::endl;
+ return 1;
+ }
+
+ try {
+ Name zoneName(zoneStr);
+ Name label(rrLabelStr);
+ name::Component type(rrTypeStr);
+
+ ndn::ndns::ManagementTool tool(db);
+ tool.removeRrSet(zoneName, label, type);
+
+ /// @todo Report how many records have been removed
+ // (or that the record was removed or record wasn't found)
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
+}