Example #1
0
	    void FrequentRebootsConfiguration::parseOptions() {
		boost::program_options::variables_map vals;
		if (!_parseOptions(vals)) {
		    return;
		}

		if (vals.count(CFG_APP_DEF)) {
		    appDef = boost::filesystem::path(vals[CFG_APP_DEF].as<std::string> ());
		}

		if (vals.count(CFG_STATE_DIR)) {
                    stateDir = boost::filesystem::path(vals[CFG_STATE_DIR].as<std::string > ());
		}

                if (vals.count(CFG_EVENTS_AT_REBOOT)) {
		    eventsAtReboot = vals[CFG_EVENTS_AT_REBOOT].as<int> ();
		}

                if (vals.count(CFG_BOOT_TIME_WINDOW)) {
		    bootTimeWindow = vals[CFG_BOOT_TIME_WINDOW].as<int> ();
		}

                if (vals.count(CFG_WATCH_TIME)) {
		    watchTime = vals[CFG_WATCH_TIME].as<int> ();
		}

                if (vals.count(CFG_REBOOT_COUNT)) {
		    rebootCount = vals[CFG_REBOOT_COUNT].as<int> ();
		}
	    }
Example #2
0
void HBFSynappConfiguration::parseOptions() {
	boost::program_options::variables_map vals;
	if (!_parseOptions(vals)) {
		return;
	}

	if (!vals.count("max-flows")) {
		_errorMsg.assign("max-flows not specified.");
		_error = true;
		return;
	}
	_maxFlows = vals["max-flows"].as<size_t>();
	if (_maxFlows == 0) {
		_errorMsg.assign("max-flows cannot be 0.");
		_error = true;
		return;
	}

	if (!vals.count("idle-timeout")) {
		_error = true;
		_errorMsg.assign("idle-timeout not specified.");
		return;
	}
	_idleTimeout.set(vals["idle-timeout"].as<uint32_t>(), 0);

	if (vals.count("min-payload")) {
		_minPayload = vals["min-payload"].as<size_t>();
	}
}
Example #3
0
	    void EvasiveTrafficConfiguration::parseOptions() {
		boost::program_options::variables_map vals;
		if (!_parseOptions(vals)) {
		    return;
		}

		if (vals.count(CFG_TTL_VALUE)) {
		    ttl = vals[CFG_TTL_VALUE].as<int> ();
		}
	    }
Example #4
0
	    void DNSFreeFlowsConfiguration::parseOptions() {
		boost::program_options::variables_map vals;
		if (!_parseOptions(vals)) {
		    return;
		}

		if (vals.count(CFG_DNS_TIMEOUT)) {
		    timeout = vals[CFG_DNS_TIMEOUT].as<int> ();
		}

                if (vals.count(CFG_STATE_FILE)) {
		    state = boost::filesystem::path(vals[CFG_STATE_FILE].as<std::string> ());
		}
	    }
Example #5
0
void DefaultSynappArguments::parseOptions() {
	boost::program_options::variables_map opts;
	if (!_parseOptions(opts)) {
		return;
	}

	// optional options
	if (opts.count("help")) {
		_help = true;
		return;
	}

	if (opts.count("config-file")) {
		_configFile = boost::filesystem::path
								(opts["config-file"].as<std::string>());
	}
	if (!boost::filesystem::exists(_configFile)) {
		_errorMsg.assign("invalid config-file: file \"");
		_errorMsg.append(_configFile.file_string());
		_errorMsg.append("\" does not exist.");
		_error = true;
		return;
	}
	if (!boost::filesystem::is_regular_file(_configFile)) {
		_errorMsg.assign("invalid config-file: file \"");
		_errorMsg.append(_configFile.file_string());
		_errorMsg.append("\" is not a regular file.");
		_error = true;
		return;
	}	

	if (opts.count("output-file")) {
		_outputFile = boost::filesystem::path
								(opts["output-file"].as<std::string>());
		if (boost::filesystem::exists(_outputFile)) {
			_errorMsg.assign("invalid output-file: \"");
			_errorMsg.append(_outputFile.file_string());
			_errorMsg.append("\" already exists.");
			_error = true;
			return;
		}
		if (_outputFile.parent_path() != boost::filesystem::path()) {
			if (!boost::filesystem::exists(_outputFile.parent_path())) {
				_errorMsg.assign("invalid output-file: directory \"");
				_errorMsg.append(_outputFile.parent_path().file_string());
				_errorMsg.append("\" does not exist.");
				_error = true;
				return;
			}
			if (!boost::filesystem::is_directory(_outputFile.parent_path())) {
				_errorMsg.assign("invalid output-file: \"");
				_errorMsg.append(_outputFile.parent_path().file_string());
				_errorMsg.append("\" is not a directory.");
				_error = true;
				return;
			}
		}
	}

	// required opts
	if (!opts.count("start-time")) {
		_errorMsg.assign("start-time not specified.");
		_error = true;
		return;
	}
	struct tm tmpTime;
	if (strptime(opts["start-time"].as<std::string>().c_str(), 
				 "%a %b %d %H:%M:%S %Z %Y",
				 &tmpTime) == NULL)
	{
		_errorMsg.assign("invalid start-time.");
		_error = true;
		return;
	}
	time_t tmpTimet = timegm(&tmpTime);
	_startTime.set(static_cast <uint32_t>(tmpTimet), 0);

	if (!opts.count("end-time")) {
		_errorMsg.assign("end-time not specified.");
		_error = true;
		return;
	}
	if (strptime(opts["end-time"].as<std::string>().c_str(), 
				 "%a %b %d %H:%M:%S %Z %Y",
				 &tmpTime) == NULL)
	{
		_errorMsg.assign("invalid end-time.");
		_error = true;
		return;
	}
	tmpTimet = timegm(&tmpTime);
	_endTime.set(static_cast <uint32_t>(tmpTimet), 0);

	if (_endTime <= _startTime) {
		_errorMsg.assign("invalid time range: end-time <= start-time.");
		_error = true;
		return;
	}

	if (!opts.count("input-dir")) {
		_errorMsg.assign("input-dir not specified.");
		_error = true;
		return;
	}
	_inputDir = boost::filesystem::path(opts["input-dir"].as<std::string>());
	if (!boost::filesystem::exists(_inputDir)) {
		_errorMsg.assign("invalid input-dir: directory \"");
		_errorMsg.append(_inputDir.file_string());
		_errorMsg.append("\" does not exist.");
		_error = true;
		return;
	}
	if (!boost::filesystem::is_directory(_inputDir)) {
		_errorMsg.assign("invalid input-dir: \"");
		_errorMsg.append(_inputDir.file_string());
		_errorMsg.append("\" is not a directory.");
		_error = true;
		return;
	}

	if (opts.count("output-file")) {
		// only parse output-dir if output-file is not specified
		return;
	}

	if (!opts.count("output-dir")) {
		_errorMsg.assign("output-dir not specified.");
		_error = true;
		return;
	}
	_outputDir = boost::filesystem::path(opts["output-dir"].as<std::string>());
	if (!boost::filesystem::exists(_outputDir)) {
		_errorMsg.assign("invalid output-dir: directory \"");
		_errorMsg.append(_outputDir.file_string());
		_errorMsg.append("\" does not exist.");
		_error = true;
		return;
	}
	if (!boost::filesystem::is_directory(_outputDir)) {
		_errorMsg.assign("invalid output-dir: \"");
		_errorMsg.append(_outputDir.file_string());
		_errorMsg.append("\" is not a directory.");
		_error = true;
		return;
	}
}