Exemple #1
0
bool cConsole::cfAddReplacer::operator ( )()
{
    string word, word_backup, rep_word;
    GetParStr(1,word_backup);
    cReplacerWorker FWord;
    string num;
    GetParStr(2,rep_word);

    /** third parameter is the affected class */
    if(this->GetParStr(3,num)) {
        istringstream is(num);
        is >> FWord.mAfClass;
    }
bool cConsole::cfLastIp::operator ( )()
{
	string who;
	int count = 10;
	enum {eIP_ALL,eIP_WHO, eIP_COUNT};
	enum {eLAST_IP,eLAST_NICK, eLAST_RANGE};
	const char *ids[]={"ip","nick","range", NULL};
	const int ids_nums[]={eLAST_IP,eLAST_NICK, eLAST_RANGE};
	int id;

	GetIDEnum(1,id, ids, ids_nums);

	GetParStr(eIP_WHO,who);
	GetParInt(eIP_COUNT,count);

	unsigned long range_min,range_max;
	switch(id) {
		case eLAST_IP:
			GetPI()->mIPLog->GetLastIP(who, count, *mOS); break;
		case eLAST_NICK:
			GetPI()->mIPLog->GetLastNick(who, count, *mOS); break;
		case eLAST_RANGE:
			GetParIPRange(eIP_WHO,range_min,range_max);
		default:break;
	}
	return true;
}
Exemple #3
0
bool cConsole::cfDelReplacer::operator ( )()
{
    string word, word_backup;
    GetParStr(1,word_backup);
    cDCProto::UnEscapeChars(word_backup, word);

    bool isInList=false;

    for(int i = 0; i < GetPI()->mReplacer->Size(); i++)
        if((* GetPI()->mReplacer)[i]->mWord == word)
            isInList = true;

    if(!isInList) {
        (*mOS) << autosprintf(_("Word '%s' does not exist."), word_backup.c_str()) << " ";
        return false;
    }

    cReplacerWorker FWord;
    FWord.mWord = word;

    GetPI()->mReplacer->DelReplacer(FWord);
    (*mOS) << autosprintf(_("Word '%s' deleted."), word_backup.c_str()) << " ";

    GetPI()->mReplacer->LoadAll();
    return true;
}
Exemple #4
0
TStr TCpDoc::GetAllParStr() const {
  TChA ChA;
  for (int ParN=0; ParN<GetPars(); ParN++){
    if (ParN>0){ChA+=' ';}
    ChA+=GetParStr(ParN);
  }
  return ChA;
}
Exemple #5
0
/////////////////////////////////////////////////
// Compact-Document
TStr TCpDoc::GetTxtStr() const {
  TChA ChA;
  ChA+=GetTitleStr(); ChA+=". ";
  for (int ParN=0; ParN<GetPars(); ParN++){
    if (ParN>0){ChA+=' ';}
    ChA+=GetParStr(ParN);
  }
  return ChA;
}
bool cConsole::cfReloadLuaScript::operator()()
{
	string scriptfile;
	GetParStr(1, scriptfile);
	bool number = false;
	int num = 0;

	if (GetPI()->IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	} else if (scriptfile.find_first_of('/') == string::npos) {
		scriptfile = GetPI()->mScriptDir + scriptfile;
	}

	vector<cLuaInterpreter *>::iterator it;
	cLuaInterpreter *li;
	bool found = false;
	int i = 0;

	for (it = GetPI()->mLua.begin(); it != GetPI()->mLua.end(); ++it, ++i) {
		li = *it;

		if ((number && (num == i)) || (!number && (StrCompare(li->mScriptName, 0, li->mScriptName.size(), scriptfile) == 0))) {
			found = true;
			(*mOS) << autosprintf(_("Script stopped: %s"), li->mScriptName.c_str());
			scriptfile = li->mScriptName;
			delete li;
			GetPI()->mLua.erase(it);
			break;
		}
	}

	if (!found) {
		if (number)
			(*mOS) << autosprintf(_("Script not stopped because it's not loaded: #%d"), num);
		else
			(*mOS) << autosprintf(_("Script not stopped because it's not loaded: %s"), scriptfile.c_str());
	}

	cLuaInterpreter *ip = new cLuaInterpreter(scriptfile);

	if (!ip) {
		(*mOS) << " " << _("Failed to allocate new Lua interpreter.");
		return false;
	}

	if (ip->Init()) {
		(*mOS) << " " << autosprintf(_("Script is now loaded: %s"), scriptfile.c_str());
		GetPI()->AddData(ip);
		ip->Load();
		return true;
	} else {
		(*mOS) << " " << autosprintf(_("Script not found or couldn't be parsed: %s"), scriptfile.c_str());
		delete ip;
		return false;
	}
}
Exemple #7
0
bool cConsole::cfAddPerlScript::operator()()
{
	string scriptfile, pathname, filename;
	bool number = false;
	int num = 0;
	GetParStr(1, scriptfile);
	vector<cPerlInterpreter *>::iterator it;
	cPerlInterpreter *pi;

	if (IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	}
	cServerDC *server= cServerDC::sCurrentServer;
	pathname = server->mConfigBaseDir;


	if(number) {
		DIR *dir = opendir(pathname.c_str());
		int i = 0;
		if(!dir) {
			(*mOS) << autosprintf(_("Failed loading directory %s."), pathname.c_str()) << " ";
			return false;
		}
		struct dirent *dent = NULL;

		while(NULL != (dent=readdir(dir))) {

			filename = dent->d_name;
			if((filename.size() > 4) && (StrCompare(filename,filename.size()-3,3,".pl")==0)) {
				if(i == num)
					scriptfile = pathname + "/" + filename;
				i++;
			}

		}
		closedir(dir);
	}
	char *argv[] = { (char*)"", (char*)scriptfile.c_str(), NULL };
	for(it = GetPI()->mPerl.mPerl.begin(); it != GetPI()->mPerl.mPerl.end(); ++it) {
		pi = *it;
		if (StrCompare(pi->mScriptName,0,pi->mScriptName.size(),scriptfile)==0) {
			(*mOS) << autosprintf(_("Script %s is already running."), scriptfile.c_str()) << " ";
			return false;
		}
	}
	GetPI()->mPerl.Parse(2, argv);
	(*mOS) << autosprintf(_("Script %s is now running."), scriptfile.c_str()) << " ";
	return true;
}
Exemple #8
0
TStr TCpDoc::GetHtmlStr() const {
  TChA ChA;
  ChA+="<HTML>\n";
  ChA+="<HEAD><TITLE>"; ChA+=GetTitleStr(); ChA+="</TITLE></HEAD>\n";
  ChA+="<BODY>\n";
  ChA+="<H1>"; ChA+=GetTitleStr(); ChA+="</H1>\n";
  for (int ParN=0; ParN<GetPars(); ParN++){
    ChA+="<P>";
    ChA+=GetParStr(ParN);
    ChA+="</P>\n";
  }
  ChA+="</BODY>\n";
  ChA+="</HTML>\n";
  return ChA;
}
Exemple #9
0
bool cConsole::cfLogPythonScript::operator()()
{
	if (!GetPI()->online) {
		(*mOS) << _("Python interpreter is not loaded.");
		return true;
	}

	string level;
	GetParStr(1, level);
	ostringstream ss;
	ss << cpiPython::log_level;
	string oldValue = ss.str();
	ss.str("");
	ss << level;
	string newValue = ss.str();
	(*mOS) << autosprintf(_("Updated configuration %s.%s: %s -> %s"), "pi_python", "log_level", oldValue.c_str(), newValue.c_str());
	cpiPython::me->LogLevel(atoi(level.c_str()));
	return true;
}
Exemple #10
0
bool cConsole::cfDelPythonScript::operator()()
{
	if (!GetPI()->online) {
		(*mOS) << _("Python interpreter is not loaded.");
		return false;
	}

	string scriptfile;
	GetParStr(1, scriptfile);
	bool number = false;
	int num = 0;

	if (GetPI()->IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	} else if (scriptfile.find_first_of('/') == string::npos) {
		scriptfile = GetPI()->mScriptDir + scriptfile;
	}

	vector<cPythonInterpreter *>::iterator it;
	cPythonInterpreter *li;

	for (it = GetPI()->mPython.begin(); it != GetPI()->mPython.end(); ++it) {
		li = *it;

		if ((number && (num == li->id))
		|| (!number && (StrCompare(li->mScriptName, 0, li->mScriptName.size(), scriptfile) == 0))) {
			(*mOS) << autosprintf(_("Script #%d stopped: %s"), li->id, li->mScriptName.c_str());
			delete li;
			GetPI()->mPython.erase(it);
			return true;
		}
	}

	if (number)
		(*mOS) << autosprintf(_("Script not stopped because it's not loaded: #%d"), num);
	else
		(*mOS) << autosprintf(_("Script not stopped because it's not loaded: %s"), scriptfile.c_str());

	return false;
}
Exemple #11
0
bool cConsole::cfReloadPerlScript::operator()()
{
	string scriptfile;
	bool found = false, number = false;
	int i, num;
	i = num = 0;

	GetParStr(1,scriptfile);
	if (IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	}

	cPerlInterpreter *pi;
	vector<cPerlInterpreter *>::iterator it;
	for(it = GetPI()->mPerl.mPerl.begin(); it != GetPI()->mPerl.mPerl.end(); ++it, ++i) {
		pi = *it;
		if ((number && num == i) || (!number && StrCompare(pi->mScriptName,0,pi->mScriptName.size(),scriptfile)==0)) {
			found = true;
			(*mOS) << autosprintf(_("Script %s stopped."), pi->mScriptName.c_str()) << " ";
			scriptfile = pi->mScriptName;
			delete pi;
			GetPI()->mPerl.mPerl.erase(it);
			break;
		}
	}

	if(!found) {
		if(number)
			(*mOS) << autosprintf(_("Script #%s not stopped because it is not running."), scriptfile.c_str()) << " ";
		else
			(*mOS) << autosprintf(_("Script %s not stopped  because it is not running."), scriptfile.c_str()) << " ";
		return false;
	} else {
		char *argv[] = { (char*)"", (char*)scriptfile.c_str(), NULL };
		GetPI()->mPerl.Parse(2, argv);
		(*mOS) << autosprintf(_("Script %s is now running."), scriptfile.c_str()) << " ";
		return true;
	}
}
Exemple #12
0
bool cConsole::cfHistoryOf::operator ( )()
{
	string who;
	int count = 10;
	enum {eHI_ALL,eHI_WHO, eHI_COUNT};
	enum {eHIST_IP,eHIST_NICK};
	const char *ids[]={"ip","nick", NULL};
	const int ids_nums[]={eHIST_IP,eHIST_NICK};
	int id=-1;

	GetIDEnum(1,id, ids, ids_nums);

	GetParStr(eHI_WHO,who);
	GetParInt(eHI_COUNT,count);
	switch(id) {
		case eHIST_IP:
			GetPI()->mIPLog->GetIPHistory(who, count, *mOS); break;
		case eHIST_NICK:
			GetPI()->mIPLog->GetNickHistory(who, count, *mOS); break;
		default: break;
	}

	return true;
}
bool cConsole::cfAddLuaScript::operator()()
{
	string scriptfile;
	GetParStr(1, scriptfile);
	bool number = false;
	int num = 0;

	if (GetPI()->IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	} else if (scriptfile.find_first_of('/') == string::npos) {
		scriptfile = GetPI()->mScriptDir + scriptfile;
	}

	if (number) {
		DIR *dir = opendir(GetPI()->mScriptDir.c_str());

		if (!dir) {
			(*mOS) << autosprintf(_("Failed loading directory: %s"), GetPI()->mScriptDir.c_str());
			return false;
		}

		string filename;
		struct dirent *dent = NULL;
		int i = 0;

		while (NULL != (dent = readdir(dir))) {
			filename = dent->d_name;

			if ((filename.size() > 4) && (StrCompare(filename, filename.size() - 4, 4, ".lua") == 0)) {
				if (i == num) {
					scriptfile = GetPI()->mScriptDir + filename;
					break;
				}

				i++;
			}
		}

		closedir(dir);
	}

	vector<cLuaInterpreter *>::iterator it;
	cLuaInterpreter *li;

	for (it = GetPI()->mLua.begin(); it != GetPI()->mLua.end(); ++it) {
		li = *it;

		if (StrCompare(li->mScriptName, 0, li->mScriptName.size(), scriptfile) == 0) {
			(*mOS) << autosprintf(_("Script is already loaded: %s"), scriptfile.c_str());
			return false;
		}
	}

	cLuaInterpreter *ip = new cLuaInterpreter(scriptfile);

	if (!ip) {
		(*mOS) << _("Failed to allocate new Lua interpreter.");
		return false;
	}

	if (ip->Init()) {
		(*mOS) << autosprintf(_("Script is now loaded: %s"), scriptfile.c_str());
		GetPI()->AddData(ip);
		ip->Load();
		return true;
	} else {
		(*mOS) << autosprintf(_("Script not found or couldn't be parsed: %s"), scriptfile.c_str());
		delete ip;
		return false;
	}
}
Exemple #14
0
bool cConsole::cfReloadPythonScript::operator()()
{
	if (!GetPI()->online) {
		(*mOS) << _("Python interpreter is not loaded.");
		return false;
	}

	string scriptfile;
	GetParStr(1, scriptfile);
	bool number = false;
	int num = 0;
	int position = 0;

	if (GetPI()->IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	} else if (scriptfile.find_first_of('/') == string::npos) {
		scriptfile = GetPI()->mScriptDir + scriptfile;
	}

	vector<cPythonInterpreter *>::iterator it;
	cPythonInterpreter *li;
	bool found = false;

	for (it = GetPI()->mPython.begin(); it != GetPI()->mPython.end(); ++it, ++position) {
		li = *it;

		if ((number && (num == li->id))
		|| (!number && (StrCompare(li->mScriptName, 0, li->mScriptName.size(), scriptfile) == 0))) {
			found = true;
			scriptfile = li->mScriptName;
			(*mOS) << autosprintf(_("Script #%d stopped: %s"), li->id, li->mScriptName.c_str());
			delete li;
			GetPI()->mPython.erase(it);
			break;
		}
	}

	if (!found) {
		if (number)
			(*mOS) << autosprintf(_("Script not stopped because it's not loaded: #%d"), num);
		else
			(*mOS) << autosprintf(_("Script not stopped because it's not loaded: %s"), scriptfile.c_str());
	}

	cPythonInterpreter *ip = new cPythonInterpreter(scriptfile);

	if (!ip) {
		(*mOS) << " " << _("Failed to allocate new Python interpreter.");
		return false;
	}

	GetPI()->AddData(ip, position);
	if (ip->Init()) {
		(*mOS) << " " << autosprintf(_("Script #%d is now loaded: %s"), ip->id, scriptfile.c_str());
		return true;
	} else {
		(*mOS) << " " << autosprintf(_("Script not found or couldn't be parsed: %s"), scriptfile.c_str());
		GetPI()->RemoveByName(ip->mScriptName);
		return false;
	}
}
Exemple #15
0
bool cConsole::cfAddPythonScript::operator()()
{
	if (!GetPI()->online) {
		(*mOS) << _("Python interpreter is not loaded.");
		return false;
	}

	string scriptfile, filename;
	GetParStr(1, scriptfile);
	bool number = false;
	int num = 0;

	if (GetPI()->IsNumber(scriptfile.c_str())) {
		num = atoi(scriptfile.c_str());
		number = true;
	} else if (scriptfile.find_first_of('/') == string::npos) {
		scriptfile = GetPI()->mScriptDir + scriptfile;
	}

	if (number) {
		DIR *dir = opendir(GetPI()->mScriptDir.c_str());
		if (!dir) {
			(*mOS) << autosprintf(_("Failed loading directory: %s"), GetPI()->mScriptDir.c_str());
			return false;
		}
		string filename;
		struct dirent *dent = NULL;
		vector<string> filenames;

		while (NULL != (dent = readdir(dir))) {
			filename = dent->d_name;
			if ((filename.size() > 3) && (StrCompare(filename, filename.size() - 3, 3, ".py") == 0))
				filenames.push_back(filename);
		}
		closedir(dir);
		sort(filenames.begin(), filenames.end());

		if (num < 0 || (unsigned)num >= filenames.size()) {
			(*mOS) << autosprintf(_("Number %d is out of range. Get the right number using !pyfiles command or specify the script path instead."), num);
			return false;
		}
		scriptfile = GetPI()->mScriptDir + filenames[num];
	}

	vector<cPythonInterpreter *>::iterator it;
	cPythonInterpreter *li;

	for (it = GetPI()->mPython.begin(); it != GetPI()->mPython.end(); ++it) {
		li = *it;

		if (StrCompare(li->mScriptName, 0, li->mScriptName.size(), scriptfile) == 0) {
			(*mOS) << autosprintf(_("Script #%d is already loaded: %s"), li->id, scriptfile.c_str());
			return false;
		}
	}

	cPythonInterpreter *ip = new cPythonInterpreter(scriptfile);

	if (!ip) {
		(*mOS) << _("Failed to allocate new Python interpreter.");
		return false;
	}

	GetPI()->AddData(ip);
	if (ip->Init()) {
		(*mOS) << autosprintf(_("Script #%d is now loaded: %s"), ip->id, scriptfile.c_str());
		return true;
	} else {
		(*mOS) << autosprintf(_("Script not found or couldn't be parsed: %s"), scriptfile.c_str());
		GetPI()->RemoveByName(ip->mScriptName);
		return false;
	}
}