Esempio n. 1
0
int main1()
{
	srand(static_cast<int>(time(NULL)));
	Cconfig config;
	if (config.load(g_conf_file))
#ifdef WIN32
	{
		char b[MAX_PATH];
		*b = 0;
		GetModuleFileName(NULL, b, MAX_PATH);
		if (*b)
			strrchr(b, '\\')[1] = 0;
		strcat(b, "xbt_tracker.conf");
		if (config.load(b))
			std::cerr << "Unable to read " << g_conf_file << std::endl;
		else
			g_conf_file = b;
	}
#else
		std::cerr << "Unable to read " << g_conf_file << std::endl;
#endif
	Cdatabase database;
	try
	{
		if (config.m_mysql_host != "-")
			database.open(config.m_mysql_host, config.m_mysql_user, config.m_mysql_password, config.m_mysql_database, true);
	}
	catch (Cdatabase::exception& e)
	{
		std::cerr << e.what() << std::endl;
		return 1;
	}
	database.set_query_log(config.m_query_log);
	return Cserver(database, config.m_mysql_table_prefix, config.m_mysql_host != "-", g_conf_file).run();
}
Esempio n. 2
0
CuserMan::CuserMan()
{
	statMaxSessions=0;
	sessionCounter=0;
	sessionMaxPerUser=1000;
	shutdown=false;

	Cconfig config;
	config.load("etc/synapse/userman.conf");

	//create groups
	for(CvarList::iterator groupI=config["groups"].list().begin(); groupI!=config["groups"].list().end(); groupI++)
	{
		addGroup(CgroupPtr(new Cgroup(*groupI)));
	}

	//create users
	for(Cvar::iterator userI=config["users"].begin(); userI!=config["users"].end(); userI++)
	{
		//create user
		CuserPtr user;
		user=CuserPtr(new Cuser(userI->first, userI->second["passwd"].str()));

		//add member groups
		for(CvarList::iterator groupI=userI->second["groups"].list().begin(); groupI!=userI->second["groups"].list().end(); groupI++)
		{
			user->addMemberGroup(getGroup(*groupI));
		}

		addUser(user);
	}

}
Esempio n. 3
0
void read_config()
{
	if (m_use_sql)
	{
		try
		{
			Csql_result result = Csql_query(m_database, "select name, value from @config where value is not null").execute();
			Cconfig config;
			while (Csql_row row = result.fetch_row())
			{
				if (config.set(row[0].s(), row[1].s()))
					std::cerr << "unknown config name: " << row[0].s() << std::endl;
			}
			config.load(m_conf_file);
			if (config.m_torrent_pass_private_key.empty())
			{
				config.m_torrent_pass_private_key = generate_random_string(27);
				Csql_query(m_database, "insert into @config (name, value) values ('torrent_pass_private_key', ?)")(config.m_torrent_pass_private_key).execute();
			}
			m_config = config;
			m_database.set_name("completed", m_config.m_column_files_completed);
			m_database.set_name("leechers", m_config.m_column_files_leechers);
			m_database.set_name("seeders", m_config.m_column_files_seeders);
			m_database.set_name("fid", m_config.m_column_files_fid);
			m_database.set_name("uid", m_config.m_column_users_uid);
			m_database.set_name("announce_log", m_config.m_table_announce_log.empty() ? m_table_prefix + "announce_log" : m_config.m_table_announce_log);
			m_database.set_name("files", m_config.m_table_torrents.empty() ? m_table_prefix + "files" : m_config.m_table_torrents);
			m_database.set_name("files_users", m_config.m_table_torrents_users.empty() ? m_table_prefix + "files_users" : m_config.m_table_torrents_users);
			m_database.set_name("scrape_log", m_config.m_table_scrape_log.empty() ? m_table_prefix + "scrape_log" : m_config.m_table_scrape_log);
			m_database.set_name("users", m_config.m_table_users.empty() ? m_table_prefix + "users" : m_config.m_table_users);
		}
		catch (bad_query&)
		{
		}
	}
	else
	{
		Cconfig config;
		if (!config.load(m_conf_file))
			m_config = config;
	}
	if (m_config.m_listen_ipas.empty())
		m_config.m_listen_ipas.insert(htonl(INADDR_ANY));
	if (m_config.m_listen_ports.empty())
		m_config.m_listen_ports.insert(2710);
	m_read_config_time = srv_time();
}
Esempio n. 4
0
int main1()
{
	srand(static_cast<int>(time(NULL)));
	Cconfig config;
	if (config.load(g_conf_file))
#ifdef WIN32
	{
		char b[MAX_PATH];
		*b = 0;
		GetModuleFileName(NULL, b, MAX_PATH);
		if (*b)
			strrchr(b, '\\')[1] = 0;
		strcat(b, "xbt_tracker.conf");
		if (config.load(b))
			std::cerr << "Unable to read " << g_conf_file << std::endl;
		else
			g_conf_file = b;
	}
#else
		std::cerr << "Unable to read " << g_conf_file << std::endl;
#endif
	try
	{
		if (config.m_mysql_host != "-")
			srv_database().open(config.m_mysql_host, config.m_mysql_user, config.m_mysql_password, config.m_mysql_database, true);
	}
	catch (bad_query& e)
	{
		std::cerr << e.what() << std::endl;
		return 1;
	}
	if (!config.m_query_log.empty())
	{
		static std::ofstream os(config.m_query_log.c_str());
		srv_database().set_query_log(&os);
	}
	return srv_run(config.m_mysql_table_prefix, config.m_mysql_host != "-", g_conf_file);
}