Exemplo n.º 1
0
// Find users with <ip>
vector<size_t> ipFind( database *database, string IP_ ) {
    socketTCP		socket("0.0.0.0");
    string			domain, ip, ipTmp;
	vector<size_t>	members;
	size_t			pos;
    // Resolve domain/ip
    ip      = socket.hostnameLookup( IP_ );	
    domain  = socket.ipLookup( IP_ );	

	if(!ip.size()) {

		// Remove after *
		size_t	pos = IP_.find("*");
		if(pos != string::npos) {
			
			IP_ = IP_.substr(0, pos);
		}

		ip = IP_;
	}

	// Get a list of similar ips
	StoreQueryResult			IPs = database->ipFind( ip );
	StoreQueryResult::iterator	ipIT;
	Row							IPRow;

	if( !IPs.size() )
		IPs = database->ipFind( domain );

	if(IPs.size() ) {

		// Add each matching member to the vector
		for( ipIT = IPs.begin(); ipIT != IPs.end(); ipIT++ ) {
			IPRow = *ipIT;
			members.push_back( (size_t) IPRow["memberID"] );
		}
		return members;
	}

	// Now get all IPs, resolve them all and try and match

	IPs = database->ipsRead(0);
	for( ipIT = IPs.begin(); ipIT != IPs.end(); ipIT++ ) {
		IPRow = *ipIT;
		
		ipTmp = (string) IPRow["ip"];
		if( (pos = ipTmp.find("*")) != string::npos) {
			ipTmp = ipTmp.substr(0, pos-1);
			if( ip.find( ipTmp) != string::npos )
				members.push_back( (size_t) IPRow["memberID"] );
		}

		ipTmp     = socket.hostnameLookup( ipTmp );

		if( ip == ipTmp )
			members.push_back( (size_t) IPRow["memberID"] );
	}

	return members;
}
Exemplo n.º 2
0
int _ftpEntry::checkEntryDBFolder( ) {
	Query						serverQuery = _sqlConnection->query();
	StoreQueryResult			serverResults;

	serverQuery <<  "select * from ServerFolders where serverID = " << quote << _serverID;
	serverQuery << " AND parentID = "	<< quote << _parentID;
	serverQuery << " AND name = "		<< quote << name;

	// Do the query
	serverResults	= serverQuery.store();
	
	// Folder not found?
	if( serverResults.size() == 0 )
		return 0;

	// Root dir?, Number of entrys changed?. time/date diff?, force rescan?
	if((timeModified == ""		&& name == "/")			||
	serverResults[0]["entrys"]			!= entrys		||
	serverResults[0]["modTimeDate"]		!= timeModified ||
	(int) serverResults[0]["rescanForce"]		== 1		) 
	
		return serverResults[0]["folderID"];	// Return the folderID

	return -1;
}	// checkEntryDBFolder
Exemplo n.º 3
0
int
CScheduler::getProcessNum()
{
	Query select = conn->query();
	select << "SELECT ProcessQuota FROM crawler WHERE name="
	  <<quote<<crawler;
	StoreQueryResult res = select.store();
	if (!res || res.size() == 0)
		return -1;
	return res[0]["ProcessQuota"];
}
Exemplo n.º 4
0
void _ftpEntry::checkDBFolders() {
	bool							isDone						= false;
	Query							serverQuery					= _sqlConnection->query();
	StoreQueryResult				serverResults;
	StoreQueryResult::iterator		storeQueryIT;
	vector<_ftpEntry*>::iterator	entryIT;

	// Nothing to do here...
	if( directorys.empty() )
		return;

	// Get a list of all the directorys that we parent
	serverQuery << "select * from ServerFolders where serverID = " << quote << _serverID;
	serverQuery << " AND parentID = "	<< quote << _folderID;

	// Do the query
	serverResults	= serverQuery.store();

	// None?
	if( !serverResults.size() )
		return;

	// We now have to check each DB result, against the results in directorys vector
	for(storeQueryIT = serverResults.begin(); storeQueryIT != serverResults.end(); storeQueryIT++ , isDone = false) {

		for( entryIT = directorys.begin(); entryIT != directorys.end(); entryIT++) {

			// Does this directory still exist?
			if((*entryIT)->getName() == (string) (*storeQueryIT)["name"]) {
				isDone = true;	// Yes it exists
				break;
			}	// parentID check
		}	// entryIT

		// Deleted?
		if(!isDone) {
			// Yes, remove the entry from the DB

            removeFolderChildren( (size_t) (*storeQueryIT)["folderID"] );
			serverQuery.str("");
			serverQuery << "delete from ServerFolders where folderID = "	<< quote << (*storeQueryIT)["folderID"];

			// bye bye :)
			serverQuery.execute();

		}	// !isDone

	}	// storeQueryIT

}	// checkDBFolders
Exemplo n.º 5
0
int _ftpEntry::checkEntryDBFile( ) {
	Query serverQuery = _sqlConnection->query();

	serverQuery << "select * from ServerFiles where folderID = "	<< quote << _folderID;
	serverQuery << " AND name = "									<< quote << name; 

	// Fire Scotty!
	StoreQueryResult			serverResults	= serverQuery.store();
	
	// Folder not found?
	if( serverResults.size() == 0 )
		return 0;

	return serverResults[0]["folderID"];
}	// checkEntryDBFile
Exemplo n.º 6
0
void IRCBot::actionIP ( ircChannel pChannel, irc_reply_data *hostd, string pParameters ) {
	stringstream str;

	vector<size_t>			 members = ipFind( _db, pParameters );
	vector<size_t>::iterator memberIT;
	Row			   member;
	string		   memberName;

	// 
	//
	for( memberIT = members.begin(); memberIT != members.end(); memberIT++ ) {

		StoreQueryResult Members = _db->membersRead( *memberIT );
		
		if(Members.size()) {
			member = Members[0];
			memberName = (string) member["nameUser"];

			str << "[" << memberName << "] Matches " << pParameters;
			_irc->talkMain( str.str(), pChannel);     str.str("");
		}
	}
}
Exemplo n.º 7
0
static void
print_result(StoreQueryResult& res, int index)
{
	// Show how many rows are in result, if any
	StoreQueryResult::size_type num_results = res.size();
	if (res && (num_results > 0)) {
		cout << "Result set " << index << " has " << num_results <<
				" row" << (num_results == 1 ? "" : "s") << ':' << endl;
	}
	else {
		cout << "Result set " << index << " is empty." << endl;
		return;
	}

	// Figure out the widths of the result set's columns
	IntVectorType widths;
	size_t size = res.num_fields();
	for (size_t i = 0; i < size; i++) {
		widths.push_back(max(
				res.field(i).max_length(),
				res.field_name(i).size()));
	}

	// Print result set header
	print_row_separator(widths);
	print_header(widths, res);
	print_row_separator(widths);

	// Display the result set contents
	for (StoreQueryResult::size_type i = 0; i < num_results; ++i) {
		print_row(widths, res[i]);
	}

	// Print result set footer
	print_row_separator(widths);
}
Exemplo n.º 8
0
void IRCBot::actionSearch( ircChannel pChannel, irc_reply_data *hostd, string pParameters ) {
	StoreQueryResult				 serverResults;
	StoreQueryResult::iterator		 resultIT;
	bool							 modeFiles = false;
	stringstream					 irc;
	string							 serverShort;
	if(readServerName(pParameters.substr(0, pParameters.find(" "))) != 0)
		serverShort = parameterGet(pParameters);

	string							 searchTerm = parameterGet(pParameters);
	string							 resultName, next;

	Row								 server, search, folder;

	size_t searchServerID;
	size_t serverID	= readServerName( serverShort );
	size_t folderID = 0, count = 0, parentID = 0;

	searchServerID = serverID;
	if(!searchTerm.size()) {
		speak("search", "syntax wrong, usage", pChannel);
		speak("search", "folder: !search <term>", pChannel);
		speak("search", "files:  !search <term> file", pChannel);
		speak("search", "serverSpecific: !search <server shortname> <term>", pChannel);

		return;
	}

	while(pParameters.size()) {
		next = parameterGet(pParameters);

		if(next[0] == 'f' && pParameters.size() == 0) {
			modeFiles = true;
		} else {
			searchTerm.append(" ");
			searchTerm.append(next);
		}
	}

	if(modeFiles) {
		serverResults = _db->searchFiles( searchTerm );
	} else 
		serverResults = _db->searchFolders( searchTerm, readServerName(serverShort.c_str()) );
	
	if(!serverResults.size()) {
		irc << "No results for query '" << searchTerm << "'";
		speak("search", irc, pChannel);
		return;
	}

	// Have results to parse
	for( resultIT = serverResults.begin(); resultIT != serverResults.end(); resultIT++ ) {
		irc.str("");
		search = *resultIT;

		if(count > 10)
			break;

		if(modeFiles) {
			folderID	= (size_t) search["folderID"];
			folder		= _db->folderRead( folderID );

			serverID = (size_t) folder["serverID"];
			if(searchServerID && serverID != searchServerID)
				continue;

			server = _db->serverRead( serverID );
			serverShort = (string) server["nameShort"];
			resultName  = (string) search["name"];

			irc << "[" << serverShort << "]: " << resultName << " in ";

			parentID = (size_t) folder["parentID"];


		} else {
			serverID = (size_t) search["serverID"];
			server =  _db->serverRead( serverID );
			serverShort = (string) server["nameShort"];
			resultName = (string) search["name"];
			parentID = (size_t) search["parentID"];

			folder = search;
			irc << "[" << serverShort << "]: " << resultName << " in ";
		}

		if(parentID) {
			search = _db->folderRead( parentID );
				if(!search.empty())
					if((string) search["name"] != "/")
						irc << ((string) search["name"]);

		}
		if(modeFiles)
			irc << "/" << ((string) folder["name"]);

		speak("search", irc, pChannel);
		count++;
	}

}
Exemplo n.º 9
0
void IRCBot::actionUser( ircChannel pChannel, irc_reply_data *hostd, string pParameters ) {
	stringstream	str;

	string			 name = pParameters;
	size_t			 memberID = 0;
	size_t			 memberAddedID = 0;

	client			*userClient = 0;
	moduleAuth		*modAuth	= 0;
	Row				 memberRow, memberAddedRow;
	
	memberID = atoi( pParameters.c_str() );

	if(!memberID)
		memberID = readMemberID( name );

	if(!memberID) {
		str << "[" << name << "] User not found";
		_irc->talkMain( str.str(), pChannel);
		return;
	}

	StoreQueryResult Members = _db->membersRead(memberID);
	if(!Members.size() )
		return;

	memberRow = Members[0];
	name = (string) memberRow["nameUser"];
	memberAddedID = (size_t) memberRow["addedMemberID"];
	
	StoreQueryResult memberAdded = _db->membersRead(memberAddedID);
	if(memberAdded.size() != 0)
		memberAddedRow = memberAdded[0];

	userClient = _smokingman->thepipeGet()->userClient( memberID );

	if( userClient ) {

		modAuth = userClient->moduleGet<moduleAuth>(modAUTH);

		// Online Time
		str << "[" << name << "] Time Online: " <<	timeCalc( time(0) - userClient->connectedTimeGet() );
		_irc->talkMain( str.str(), pChannel);     str.str("");

		if(modAuth) {
			// Issoria Ver, Os
			str << "[" << name << "] ";
			if( userClient->isSpidz() )
				str << "spidz v";
			else
				str << "IsSorIa v";

			str << modAuth->version() << " svn: " << modAuth->SVNRevGet() << " on ";
			str << OSNameGet( modAuth->OSGet() );
			_irc->talkMain( str.str(), pChannel);     str.str("");
		} else {
			str << "[" << name << "] moduleAuth not yet loaded.";
			_irc->talkMain( str.str(), pChannel);     str.str("");
		}

	} else {

		
		str << "[" << name << "] Not Online";
		_irc->talkMain( str.str(), pChannel);     str.str("");

		str << "[" << name << "] Last Seen: " << timeCalc( time(0) - ((time_t)memberRow["lastOnline"]));
		str << " Ago";
		_irc->talkMain( str.str(), pChannel);     str.str("");
	}

	str << "[" << name << "] Added by " << ((string) memberAddedRow["nameUser"]) << " on " << ((string) memberRow["dateJoined"]);
	_irc->talkMain( str.str(), pChannel);     str.str("");

	if( ((bool) memberRow["active"] ) == false ) {
		str << "[" << name << "] Currently is Disabled";
		_irc->talkMain( str.str(), pChannel);     str.str("");
	}

}
Exemplo n.º 10
0
bool AdUserFeatureCacheI::HasNewFile(){
    stringstream sql;
    sql << " SELECT local_file, md5 FROM user_feature_version "
        << " WHERE id = (SELECT max(id) FROM user_feature_version) "
        << " AND valid = 1 ";

    StoreQueryResult res;
    try{
        const char* DB_HOST = "10.3.23.69";
        const char* DB_NAME = "ad_strategy";
        const char* DB_USER = "******";
        const char* DB_PASSWORD = "******";

	Connection conn(DB_NAME, DB_HOST, DB_USER, DB_PASSWORD);
	Query query(&conn, true, sql.str().c_str());
	res = query.store();
    } catch (Ice::Exception& e){
        MCE_WARN("AdUserFeatureCacheI::HasNewVersion user_feature_version ice error! " << e.what());
        return false;
    } catch (std::exception& e){
        MCE_WARN("AdUserFeatureCacheI::HasNewVersion user_feature_version std error! " << e.what());
        return false;
    }

    if (!res){
        MCE_WARN("Query Result Error!");
        return false;
    }
    else if (res.empty()){
        MCE_INFO("nothing in db!");
        return false;
    }
    else if (res.size() > 1){
	MCE_WARN("There dirty data in user_feature_version.");
	return false;
    }

    string fileName = lexical_cast<string>(res.at(0)["local_file"]);
    string md5Value = lexical_cast<string>(res.at(0)["md5"]);
    //Loading Data of the newFileName now, not finished.
    if (isLoading_){
	MCE_INFO("The File: " << newFileName_ << " is loading.");
	return false;
    }

    /*1). Never Load Data Before. initOK_ == false
     *2). Already there is data in cache, and new file is ready.
     *    newFileName != data's fileName in cache,
     *    and the newFile content md5 != data's content md5 in cache.
     */  
    if ((!initOK_) 
        || ( (fileName != userFeatureDataPtr_->GetFileName())
             && (md5Value != userFeatureDataPtr_->GetMd5Value())
           )
       ){
        IceUtil::RWRecMutex::WLock lock(VERSION_MUTEX);
        {
            newFileName_ = fileName;
            newMd5Value_ = md5Value;;
        }
	return true;
    }
    return false;
}