bool cConsole::cfFilesLuaScript::operator()()
{
	DIR *dir = opendir(GetPI()->mScriptDir.c_str());

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

	(*mOS) << autosprintf(_("Lua scripts found in: %s"), GetPI()->mScriptDir.c_str()) << "\r\n\r\n ";
	(*mOS) << setw(6) << setiosflags(ios::left) << _("ID");
	(*mOS) << toUpper(_("Script")) << "\r\n";
	(*mOS) << " " << string(6 + 20, '=') << "\r\n";
	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)) {
			(*mOS) << " " << setw(6) << setiosflags(ios::left) << i << filename << "\r\n";
			i++;
		}
	}

	closedir(dir);
	return true;
}
Beispiel #2
0
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;
}
Beispiel #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;
}
Beispiel #4
0
bool cConsole::cfFilesPythonScript::operator()()
{
	DIR *dir = opendir(GetPI()->mScriptDir.c_str());
	if (!dir) {
		(*mOS) << autosprintf(_("Failed loading directory: %s"), GetPI()->mScriptDir.c_str());
		return false;
	}
	(*mOS) << autosprintf(_("Python scripts found in: %s"), GetPI()->mScriptDir.c_str()) << "\r\n\r\n";
	(*mOS) << "\t" << _("ID");
	(*mOS) << "\t" << _("Script") << "\r\n";
	(*mOS) << "\t" << string(40, '-') << "\r\n\r\n";
	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);
	}
	sort(filenames.begin(), filenames.end());

	for (size_t i = 0; i < filenames.size(); i++)
		(*mOS) << "\t" << i << "\t" << filenames[i] << "\r\n";

	closedir(dir);
	return true;
}
Beispiel #5
0
bool cConsole::cfGetPerlScript::operator()()
{
	(*mOS) << _("Running Perl scripts:") << "\r\n";
	(*mOS) << "\n ";
	(*mOS) << setw(6) << setiosflags(ios::left) << "ID";
	(*mOS) << toUpper(_("Script")) << "\n";
	(*mOS) << " " << string(6+20,'=') << endl;
	for(int i = 0; i < GetPI()->Size(); i++) {
		(*mOS) << " " << setw(6) << setiosflags(ios::left) << i << GetPI()->mPerl.mPerl[i]->mScriptName << "\r\n";
	}
	return true;
}
bool cConsole::cfInfoLuaScript::operator()()
{
	unsigned int size = 0;

	if (GetPI()->Size() > 0)
		size = lua_gc(GetPI()->mLua[0]->mL, LUA_GCCOUNT, 0);

	(*mOS) << "\r\n [*] " << setw(PADDING) << setiosflags(ios::left) << _("Version date") << __CURR_DATE_TIME__ << "\r\n";
	(*mOS) << " [*] " << setw(PADDING) << setiosflags(ios::left) << _("Loaded scripts") << GetPI()->Size() << "\r\n";
	(*mOS) << " [*] " << setw(PADDING) << setiosflags(ios::left) << _("Memory used") << convertByte(size * 1024, false).c_str();
	return true;
}
bool cConsole::cfGetLuaScript::operator()()
{
	(*mOS) << _("Loaded Lua scripts") << ":\r\n\r\n ";
	(*mOS) << setw(6) << setiosflags(ios::left) << _("ID");
	(*mOS) << toUpper(_("Script")) << "\r\n";
	(*mOS) << " " << string(6 + 20, '=') << "\r\n";

	for (unsigned int i = 0; i < GetPI()->Size(); i++) {
		(*mOS) << " " << setw(6) << setiosflags(ios::left) << i << GetPI()->mLua[i]->mScriptName << "\r\n";
	}

	return true;
}
Beispiel #8
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;
}
Beispiel #9
0
void ProgressImages::InitializeProgressImages(CImageList& img, RgbPixel32 background, RgbPixel32 filled, RgbPixel32 unfilled)
{
  m_background = background;
  m_unfilled = unfilled;
  m_filled = filled;
  m_diameter = 14;
  m_radius = 7;
  m_pieBlurringSize = 2;
  m_perimeter = static_cast<int>(GetPI() * m_diameter);
  m_background = background;
  m_images.clear();
  m_images.reserve(m_perimeter+1);

  // add 1 for complete coverage, to be on the safe side.
  m_angles.Resize(m_radius + 1, static_cast<float>(m_perimeter), 0);// the values returned from m_angles will be in the range 0-perimeter, or in other words, 0-m_images.size().

  for(m_i = 0; m_i < m_perimeter; m_i ++)
  {
    m_bmp = new AnimBitmap<32>();
    m_bmp->SetSize(16, 16);
    m_bmp->Fill(m_background);
	FilledCircleAAG(8, 8, m_radius, this, &ProgressImages::DrawHLine, this, &ProgressImages::DrawAlphaPixel);
    // add it to the imagelist.
    HBITMAP hbm = m_bmp->DetachHandle();
    m_images.push_back(img.Add(hbm));
    DeleteObject(hbm);
    delete m_bmp;
    m_bmp = 0;
  }
}
Beispiel #10
0
bool cConsole::cfGetPythonScript::operator()()
{
	if (!GetPI()->online) {
		(*mOS) << _("Python interpreter is not loaded.");
		return true;
	}

	(*mOS) << _("Loaded Python scripts") << ":\r\n\r\n";
	(*mOS) << "\t" << _("ID");
	(*mOS) << "\t" << _("Script") << "\r\n";
	(*mOS) << "\t" << string(40, '-') << "\r\n\r\n";

	for (unsigned int i = 0; i < GetPI()->Size(); i++)
		(*mOS) << "\t" << GetPI()->mPython[i]->id << "\t" << GetPI()->mPython[i]->mScriptName << "\r\n";

	return true;
}
Beispiel #11
0
bool cConsole::cfErrLuaScript::operator()()
{
	int eclass;

	if (GetParInt(1, eclass)) {
		stringstream ss;
		ss << GetPI()->err_class;
		string oldValue = ss.str();
		ss.str("");
		ss << eclass;
		string newValue = ss.str();
		GetPI()->SetErrClass(eclass);
		(*mOS) << autosprintf(_("Updated configuration %s.%s from '%s' to '%s'."), "pi_lua", "err_class", oldValue.c_str(), newValue.c_str());
	} else {
		(*mOS) << autosprintf(_("Current error class: %d"), GetPI()->err_class);
	}

	return true;
}
Beispiel #12
0
bool cConsole::cfLogLuaScript::operator()()
{
	int level;

	if (GetParInt(1, level)) {
		stringstream ss;
		ss << GetPI()->log_level;
		string oldValue = ss.str();
		ss.str("");
		ss << level;
		string newValue = ss.str();
		GetPI()->SetLogLevel(level);
		(*mOS) << autosprintf(_("Updated configuration %s.%s from '%s' to '%s'."), "pi_lua", "log_level", oldValue.c_str(), newValue.c_str());
	} else {
		(*mOS) << autosprintf(_("Current log level: %d"), GetPI()->log_level);
	}

	return true;
}
Beispiel #13
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;
	}
}
Beispiel #14
0
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;
	}
}
Beispiel #15
0
bool cConsole::cfDelLuaScript::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;
	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))) {
			scriptfile = li->mScriptName;
			(*mOS) << autosprintf(_("Script stopped: %s"), li->mScriptName.c_str());
			delete li;
			GetPI()->mLua.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;
}
Beispiel #16
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;
}
Beispiel #17
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;
}
Beispiel #18
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;
	}
}
Beispiel #19
0
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;
	}
}
Beispiel #20
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;
	}
}