#include <sstream>
#include "datatypes.h"
+#include "version.h"
+
#include "options.h"
#include "log.h"
#include "authAlgoFactory.h"
chroot_dir_ = "";
pid_file_ = "";
+ debug_ = false;
+
file_name_ = "";
bind_to_.addr = "127.0.0.1";
bind_to_.port = "2323";
std::string str(argv[i]);
argc--;
- if(str == "-h" || str == "--help")
+ if(str == "-h" || str == "--help") {
+ printUsage();
return false;
+ }
+ else if(str == "-v" || str == "--version") {
+ printVersion();
+ return false;
+ }
#if defined(ANYTUN_OPTIONS) || defined(ANYCTR_OPTIONS)
- #ifndef NO_DAEMON
+ #ifndef _MSC_VER
PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", daemonize_, NOTHING)
PARSE_SCALAR_PARAM("-u","--username", username_, NOTHING)
PARSE_SCALAR_PARAM("-g","--groupname", groupname_, NOTHING)
#endif
PARSE_STRING_LIST("-L","--log", log_targets_, NOTHING)
+ PARSE_BOOL_PARAM("-U","--debug", debug_, NOTHING)
#if defined(ANYCTR_OPTIONS)
PARSE_SCALAR_PARAM("-d","--dev", dev_name_, NOTHING)
PARSE_SCALAR_PARAM("-t","--type", dev_type_, NOTHING)
PARSE_SCALAR_PARAM("-n","--ifconfig", ifconfig_param_, NOTHING)
- #ifndef NO_EXEC
PARSE_SCALAR_PARAM("-x","--post-up-script", post_up_script_, NOTHING)
- #endif
#endif
#if defined(ANYTUN_OPTIONS) || defined(ANYCONF_OPTIONS)
throw syntax_error("unknown role name: " + role, -1);
}
+ if(debug_) {
+ log_targets_.push_back("stdout:5");
+ daemonize_ = false;
+ }
+
+ if(log_targets_.empty()) {
+#ifndef _MSC_VER
+ #if !defined(ANYCONF_OPTIONS)
+ log_targets_.push_back(std::string("syslog:3,").append(progname_).append(",daemon"));
+ #else
+ log_targets_.push_back("stderr:2");
+ #endif
+#else
+ #ifdef WIN_SERVICE
+ log_targets_.push_back(std::string("eventlog:3,").append(progname_));
+ #else
+ log_targets_.push_back("stdout:3");
+ #endif
+#endif
+ }
+
return true;
}
dev_type_ = "tun";
}
+void Options::printVersion()
+{
+#if defined(ANYCTR_OPTIONS)
+ std::cout << "anytun-controld";
+#elif defined(ANYCONF_OPTIONS)
+ std::cout << "anytun-config";
+#else
+ std::cout << "anytun";
+#endif
+ std::cout << VERSION_STRING_0 << std::endl;
+ std::cout << VERSION_STRING_1 << std::endl;
+}
+
void Options::printUsage()
{
std::cout << "USAGE:" << std::endl;
#endif
std::cout << " [-h|--help] prints this..." << std::endl;
+ std::cout << " [-v|--version] print version info and exit" << std::endl;
#if defined(ANYTUN_OPTIONS) || defined(ANYCTR_OPTIONS)
- #ifndef NO_DAEMON
+ #ifndef _MSC_VER
std::cout << " [-D|--nodaemonize] don't run in background" << std::endl;
std::cout << " [-u|--username] <username> change to this user" << std::endl;
std::cout << " [-g|--groupname] <groupname> change to this group" << std::endl;
std::cout << " [-L|--log] <target>:<level>[,<param1>[,<param2>..]]" << std::endl;
std::cout << " add a log target, can be invoked several times" << std::endl;
+ std::cout << " i.e.: stdout:5" << std::endl;
+ std::cout << " [-U|--debug] don't daemonize and log to stdout with maximum log level" << std::endl;
#if defined(ANYCTR_OPTIONS)
std::cout << " [-d|--dev] <name> device name" << std::endl;
std::cout << " [-t|--type] <tun|tap> device type" << std::endl;
std::cout << " [-n|--ifconfig] <local>/<prefix> the local address for the tun/tap device and the used prefix length" << std::endl;
- #ifndef NO_EXEC
std::cout << " [-x|--post-up-script] <script> script gets called after interface is created" << std::endl;
- #endif
#endif
#if defined(ANYTUN_OPTIONS) || defined(ANYCONF_OPTIONS)
StringList::const_iterator lit = log_targets_.begin();
for(; lit != log_targets_.end(); ++lit)
std::cout << " '" << *lit << "',";
- std::cout << std::endl << std::endl;
+ std::cout << std::endl;
+ std::cout << "debug = " << debug_ << std::endl;
+ std::cout << std::endl;
std::cout << "file_name = '" << file_name_ << "'" << std::endl;
std::cout << "bind_to.addr = '" << bind_to_.addr << "'" << std::endl;
std::cout << "bind_to.port = '" << bind_to_.port << "'" << std::endl;
}
-
StringList Options::getLogTargets()
{
ReadersLock lock(mutex);
return log_targets_;
}
+bool Options::getDebug()
+{
+ ReadersLock lock(mutex);
+ return debug_;
+}
+
+Options& Options::setDebug(bool d)
+{
+ WritersLock lock(mutex);
+ debug_ = d;
+ return *this;
+}
std::string Options::getFileName()