Пример #1
0
TvnServer::TvnServer(bool runsInServiceContext, StringStorage vncIniDirPath /*""*/, bool runAsPortable /*=false*/ )
: Singleton<TvnServer>(),
  ListenerContainer<TvnServerListener *>(),
  m_runAsService(runsInServiceContext),
  m_runPortable(runAsPortable),
  m_rfbClientManager(0),
  m_httpServer(0), m_controlServer(0), m_rfbServer(0)
{
  Configurator *configurator = Configurator::getInstance();

  configurator->setServiceFlag(m_runAsService);
  configurator->setPortableRunFlag(m_runPortable);
  configurator->setVncIniDirectoryPath ( vncIniDirPath.getString() );

  configurator->load();

  m_config = Configurator::getInstance()->getServerConfig();

  resetLogFilePath();

  m_log.changeLevel(m_config->getLogLevel());

  Log::message(_T("TightVNC Server Build on %s"), BuildTime::DATE);

  Log::info(_T("Initialize WinSock"));

  try {
    WindowsSocket::startup(2, 1);
  } catch (Exception &ex) {
    Log::interror(_T("%s"), ex.getMessage());
  }

  ZombieKiller *zombieKiller = new ZombieKiller();

  m_rfbClientManager = new RfbClientManager(NULL);

  m_rfbClientManager->addListener(this);

  Configurator::getInstance()->addListener(this);

  {
    AutoLock l(&m_mutex);

    restartMainRfbServer();
    (void)m_extraRfbServers.reload(m_runAsService, m_rfbClientManager);
    restartHttpServer();
    restartControlServer();
  }
}
int ControlApplication::runConfigurator(bool configService, bool isRunAsRequested)
{
  // If not enough rights to configurate service, then restart application requesting
  // admin access rights.
  if (configService && (IsUserAnAdmin() == FALSE)) {
    // If admin rights already requested and application still don't have them,
    // then show error message and exit.
    if (isRunAsRequested) {
      MessageBox(0,
        StringTable::getString(IDS_ADMIN_RIGHTS_NEEDED),
        StringTable::getString(IDS_MBC_TVNCONTROL),
        MB_OK | MB_ICONERROR);
      return 0;
    }
    // Path to tvnserver binary.
    StringStorage pathToBinary;
    // Command line for child process.
    StringStorage childCommandLine;

    // Get path to tvnserver binary.
    Environment::getCurrentModulePath(&pathToBinary);
    // Set -dontelevate flag to tvncontrol know that admin rights already requested.
    childCommandLine.format(_T("%s -dontelevate"), m_commandLine.getString());

    // Start child.
    try {
      Shell::runAsAdmin(pathToBinary.getString(), childCommandLine.getString());
    } catch (SystemException &sysEx) {
      if (sysEx.getErrorCode() != ERROR_CANCELLED) {
        MessageBox(0,
          sysEx.getMessage(),
          StringTable::getString(IDS_MBC_TVNCONTROL),
          MB_OK | MB_ICONERROR);
      }
      return 1;
    } // try / catch.
    return 0;
  }

  Configurator *configurator = Configurator::getInstance();

  configurator->setServiceFlag(configService);
  configurator->load();

  ConfigDialog confDialog(configService, 0);

  return confDialog.showModal();
}