Exemplo n.º 1
0
void CPlugin::autoStartScriptIfNeeded()
{
  if (!m_Pref_bAutoStartScript)
    return;

  CScripter scripter;
  scripter.associate(this);

  char szFileName[_MAX_PATH];
  getModulePath(szFileName, sizeof(szFileName));
  strcat(szFileName, m_Pref_szScriptFile);

  if(scripter.createScriptFromFile(szFileName))
  {
    int iRepetitions = scripter.getCycleRepetitions();
    int iDelay = scripter.getCycleDelay();
    if(iDelay < 0)
      iDelay = 0;

    assert(pLogger != NULL);
    pLogger->resetStartTime();

    for(int i = 0; i < iRepetitions; i++)
    {
      scripter.executeScript();
      if(iDelay != 0)
        XP_Sleep(iDelay);
    }
  }
  else
  {
    MessageBox(NULL, "Script file not found or invalid", "", MB_OK | MB_ICONERROR);
  }
}
Exemplo n.º 2
0
bool TcpChannel::processAuthenticationMessages()
{
	if (!!m_processor)
	{
		do
		{
			if (!m_processor)
				return false;
			switch (m_processor->GetTransportState())
			{
			case IHttpChannelProcessor::inactive:
			case IHttpChannelProcessor::active:
			case IHttpChannelProcessor::logout:
				break;
			case IHttpChannelProcessor::login:
			{
				int len;
				tscrypto::tsCryptoData buff;

				buff.resize(1024);
#ifdef _WIN32
				len = recv(m_socket, (char*)buff.rawData(), 1023, MSG_PEEK);
#else
				len = recv((int)m_socket, (char*)buff.rawData(), 1023, MSG_PEEK);
#endif
				if (len > 0)
				{
#ifdef _WIN32
					len = recv(m_socket, (char*)buff.rawData(), len, 0);
#else
					len = recv((int)m_socket, (char*)buff.rawData(), len, 0);
#endif
					if (len > 0)
					{
						buff.resize(len);

						LOG(httpData, "recv'd" << tscrypto::endl << buff.ToHexDump());

						if (!m_processor || !m_processor->UnwrapTransport(buff))
							return false;
						if (buff.size() > 0)
							m_bufferedData << buff;
					}
					else if (len == SOCKET_ERROR)
						return false;
				}
				else if (len == SOCKET_ERROR)
					return false;
				else
				{
					XP_Sleep(100);
				}
			}
			break;
			}
		} while (!!m_processor && m_processor->GetTransportState() == IHttpChannelProcessor::login);
	}
	return !!m_processor;
}
Exemplo n.º 3
0
void CPluginBase::onNPP_DestroyStream(NPStream * pStream)
{
  // if this is a stream created by tester, reflect the fact it is destroyed
  if(pStream == m_pStream)
    m_pStream = NULL;

  // if this is a script stream, reflect the fact it is destroyed too, and execute the script
  if(pStream == m_pScriptStream)
  {
    m_pScriptStream = NULL;

    if(!XP_IsFile(m_szScriptCacheFile))
      return;

    CScripter * pScripter = new CScripter();
    pScripter->associate(this);

    if(pScripter->createScriptFromFile(m_szScriptCacheFile))
    {
      char szOutput[128];
      char szExecutingScript[] = "Executing script...";

      strcpy(szOutput, szExecutingScript);
      NPN_Status(m_pNPInstance, szOutput);

      int iRepetitions = pScripter->getCycleRepetitions();
      int iDelay = pScripter->getCycleDelay();
      if(iDelay < 0)
        iDelay = 0;

      assert(pLogger != NULL);
      pLogger->resetStartTime();

      pLogger->setLogToFileFlag(TRUE);
      pLogger->blockDumpToFile(FALSE);

      for(int i = 0; i < iRepetitions; i++)
      {
        wsprintf(szOutput, "%s %i", szExecutingScript, i);
        NPN_Status(m_pNPInstance, szOutput);

        pScripter->executeScript();
        if(iDelay != 0)
          XP_Sleep(iDelay);
      }
    }
    else
      NPN_Status(m_pNPInstance, "Cannot create script...");


    pLogger->setLogToFileFlag(FALSE);

    delete pScripter;

    m_szScriptCacheFile[0] = '\0';

    NPN_Status(m_pNPInstance, "Script execution complete");
  }
}
Exemplo n.º 4
0
static void onCommand(HWND hWnd, int id, HWND hWndCtl, USHORT codeNotify)
{
  CPlugin * pPlugin = (CPlugin *)WinQueryWindowULong(hWnd, QWL_USER);
  if(!pPlugin)
    return;

  switch (id)
  {
    case IDC_EDIT_SCRIPT_FILE_NAME:
    {
      if(codeNotify != EN_CHANGE)
        break;
      char szString[256];
      WinQueryWindowText(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), sizeof(szString), szString);
      int iLen = strlen(szString);
      WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), (iLen > 0));
      if(iLen <= 0)
        break;

      // synchronize log filename with current script filename
      char szLogFileName[256];
      char * p = strchr(szString, '.');

      if(p != NULL)
        *p = '\0';

      strcpy(szLogFileName, szString);
      strcat(szLogFileName, ".log");
      WinSetWindowText(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_EDIT_LOG_FILE_NAME), szLogFileName);

      // restore
      if(p)
        *p = '.';

      pPlugin->updatePrefs(gp_scriptfile, FALSE, szString);

      break;
    }
    /*
    case IDC_BUTTON_STOP:
      assert(pScripter != NULL);
      pScripter->setStopAutoExecFlag(TRUE);
      WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), TRUE);
      WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP), FALSE);
      break;
    */
    case IDC_BUTTON_GO:
    {
      pLogger->blockDumpToFile(FALSE);

      //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), FALSE);
      //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP), TRUE);
      //UpdateWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP));
      EnableWindowNow(WinWindowFromID(hWnd, IDC_BUTTON_GO), FALSE);

      EnableWindowNow(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), FALSE);
      EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_EDIT_LOG_FILE_NAME), FALSE);
      EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_SHOW_LOG), FALSE);
      EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FRAME), FALSE);
      EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FILE), FALSE);
      BOOL bFlashWasEnabled = FALSE;
      if(WinIsWindowEnabled(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_FLUSH)))
      {
        bFlashWasEnabled = TRUE;
        EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_FLUSH), FALSE);
      }
      EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_CLEAR), FALSE);
      EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_MANUAL), FALSE);
      EnableWindowNow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_AUTO), FALSE);
    
      if(pScripter != NULL)
        delete pScripter;

      pScripter = new CScripter();
      pScripter->associate(pPlugin);

      char szFileName[_MAX_PATH];
      pPlugin ->getModulePath(szFileName, sizeof(szFileName));

      char szFile[_MAX_PATH];
      WinQueryWindowText(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), sizeof(szFile), szFile);
      strcat(szFileName, szFile);

      if(pScripter->createScriptFromFile(szFileName))
      {
        int iRepetitions = pScripter->getCycleRepetitions();
        int iDelay = pScripter->getCycleDelay();
        if(iDelay < 0)
          iDelay = 0;

        assert(pLogger != NULL);
        pLogger->resetStartTime();

        ShowWindowNow(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LABEL), TRUE);
        char szLeft[256];

        for(int i = 0; i < iRepetitions; i++)
        {
          sprintf(szLeft, "%i", iRepetitions - i);
          WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LEFT), szLeft);
          pScripter->executeScript();
          /*
          if(pScripter->getStopAutoExecFlag())
          {
            pScripter->setStopAutoExecFlag(FALSE);
            break;
          }
          */
          if(iDelay != 0)
            XP_Sleep(iDelay);
        }
      }
      else
      {
        WinMessageBox(HWND_DESKTOP, hWnd, "Script file not found or invalid", "", 0, MB_OK | MB_ERROR);
      }

      delete pScripter;
      pScripter = NULL;

      WinSetWindowText(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LEFT), "");
      WinShowWindow(WinWindowFromID(hWnd, IDC_STATIC_REPETITIONS_LABEL), FALSE);

      //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), TRUE);
      //WinShowWindow(WinWindowFromID(hWnd, IDC_BUTTON_STOP), FALSE);
      WinEnableWindow(WinWindowFromID(hWnd, IDC_BUTTON_GO), TRUE);

      WinEnableWindow(WinWindowFromID(hWnd, IDC_EDIT_SCRIPT_FILE_NAME), TRUE);
      WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_EDIT_LOG_FILE_NAME), TRUE);
      WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_SHOW_LOG), TRUE);
      WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FRAME), TRUE);
      WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_CHECK_LOG_TO_FILE), TRUE);
      if(bFlashWasEnabled)
        WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_FLUSH), TRUE);
      WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_BUTTON_CLEAR), TRUE);
      WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_MANUAL), TRUE);
      WinEnableWindow(WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), IDC_RADIO_MODE_AUTO), TRUE);
      break;
    }
    default:
      break;
  }
}