Example #1
0
int systemExecute(const std::wstring& commandLine)
{	
    //Calculate the commandline used for the service.
    wchar_t moduleName[MAX_PATH];
    if (!GetModuleFileName(NULL, moduleName, MAX_PATH)) return -1;
    std::wstring serviceString(L"\"");
    serviceString.append(moduleName).append(L"\" EXEC /i ").append(commandLine);
    
    //Open the SCM and create the service
    SC_HANDLE hScm = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE | STANDARD_RIGHTS_EXECUTE);
    
    //Check if a service by that name already exists and delete it if so
    SC_HANDLE hOldSvc = OpenService(hScm,serviceName, SERVICE_STOP | DELETE);
    if (hOldSvc)
    {
        SERVICE_STATUS garbage;
        ControlService(hOldSvc, SERVICE_CONTROL_STOP, &garbage);
        DeleteService(hOldSvc);
        CloseServiceHandle(hOldSvc);
    }
    
    SC_HANDLE hSvc = CreateService(hScm, serviceName, NULL, DELETE| SERVICE_START | SERVICE_QUERY_STATUS,
    SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
    serviceString.c_str(), NULL, NULL, NULL, L"LocalSystem", NULL);
    if (!hSvc)
    {
        return GetLastError();
    }
    
    //Create safe mode bindings for it
    HKEY safebootKey;
    RegCreateKeyEx(HKEY_LOCAL_MACHINE,L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Minimal\\PEVSystemStart", 0, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &safebootKey, NULL);
    RegSetValueEx(safebootKey, NULL, 0, REG_SZ, reinterpret_cast<const BYTE *>(L"Service"), 8 * sizeof(wchar_t));
    RegCloseKey(safebootKey);
    RegCreateKeyEx(HKEY_LOCAL_MACHINE,L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Network\\PEVSystemStart", 0, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &safebootKey, NULL);
    RegSetValueEx(safebootKey, NULL, 0, REG_SZ, reinterpret_cast<const BYTE *>(L"Service"), 8 * sizeof(wchar_t));
    RegCloseKey(safebootKey);
    
    int exitCode;
    exitCode = (int) StartService(hSvc, 0, NULL);
    
    SERVICE_STATUS sStatus;
    do
    {
        Sleep(100);
        QueryServiceStatus(hSvc, &sStatus);
    }
    while (sStatus.dwCurrentState != SERVICE_STOPPED);
    DeleteService(hSvc);
    CloseServiceHandle(hSvc);
    CloseServiceHandle(hScm);
    return 0;
}
void ZOSConsoleManager::_displayServiceLevel()
{
    PEG_METHOD_ENTER(TRC_SERVER,
                     "ZOSConsoleManager::_displayServiceLevel");

    // PEGASUS_ZOS_SERVICE_STRING is defined in the z/OS platform make file
    String serviceString(STRLIT_ARGS(PEGASUS_ZOS_SERVICE_STRING));

    Logger::put_l(
        Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
        MessageLoaderParms(
            "Server.ConsoleManager_zOS.VERSION.PEGASUS_OS_ZOS",
            "CIM Server Service Level: $0",
            serviceString));

    PEG_METHOD_EXIT();
}
Example #3
0
int main( int argc, char * argv[] )
{
#ifndef _MSC_VER
  qInstallMsgHandler( dummyMessageHandler );
#endif

  QgsApplication qgsapp( argc, argv, false );

  //Default prefix path may be altered by environment variable
  char* prefixPath = getenv( "QGIS_PREFIX_PATH" );
  if ( prefixPath )
  {
    QgsApplication::setPrefixPath( prefixPath, TRUE );
  }
#if !defined(Q_OS_WIN)
  else
  {
    // init QGIS's paths - true means that all path will be inited from prefix
    QgsApplication::setPrefixPath( CMAKE_INSTALL_PREFIX, TRUE );
  }
#endif

  // Instantiate the plugin directory so that providers are loaded
  QgsProviderRegistry::instance( QgsApplication::pluginPath() );
  QgsDebugMsg( "Prefix  PATH: " + QgsApplication::prefixPath() );
  QgsDebugMsg( "Plugin  PATH: " + QgsApplication::pluginPath() );
  QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() );
  QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );

  QgsDebugMsg( qgsapp.applicationDirPath() + "/qgis_wms_server.log" );

  //create config cache and search for config files in the current directory.
  //These configurations are used if no mapfile parameter is present in the request
  QString defaultConfigFilePath;
  QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs file in the server directory
  if ( projectFileInfo.exists() )
  {
    defaultConfigFilePath = projectFileInfo.absoluteFilePath();
  }
  else
  {
    QFileInfo adminSLDFileInfo = defaultAdminSLD();
    if ( adminSLDFileInfo.exists() )
    {
      defaultConfigFilePath = adminSLDFileInfo.absoluteFilePath();
    }
  }

  //create cache for capabilities XML
  QgsCapabilitiesCache capabilitiesCache;

  //creating QgsMapRenderer is expensive (access to srs.db), so we do it here before the fcgi loop
  QgsMapRenderer* theMapRenderer = new QgsMapRenderer();

  while ( fcgi_accept() >= 0 )
  {
    printRequestInfos(); //print request infos if in debug mode

    //use QgsGetRequestHandler in case of HTTP GET and QgsSOAPRequestHandler in case of HTTP POST
    QgsRequestHandler* theRequestHandler = 0;
    char* requestMethod = getenv( "REQUEST_METHOD" );
    if ( requestMethod != NULL )
    {
      if ( strcmp( requestMethod, "POST" ) == 0 )
      {
        //QgsDebugMsg( "Creating QgsSOAPRequestHandler" );
        //theRequestHandler = new QgsSOAPRequestHandler();
        theRequestHandler = new QgsPostRequestHandler();
      }
      else
      {
        QgsDebugMsg( "Creating QgsGetRequestHandler" );
        theRequestHandler = new QgsGetRequestHandler();
      }
    }
    else
    {
      QgsDebugMsg( "Creating QgsGetRequestHandler" );
      theRequestHandler = new QgsGetRequestHandler();
    }

    std::map<QString, QString> parameterMap;

    try
    {
      parameterMap = theRequestHandler->parseInput();
    }
    catch ( QgsMapServiceException& e )
    {
      QgsDebugMsg( "An exception was thrown during input parsing" );
      theRequestHandler->sendServiceException( e );
      continue;
    }

    //set admin config file to wms server object
    QString configFilePath = defaultConfigFilePath;
    std::map<QString, QString>::const_iterator mapFileIt = parameterMap.find( "MAP" );
    if ( mapFileIt != parameterMap.end() )
    {
      configFilePath = mapFileIt->second;
      QgsDebugMsg( QString( "Configuration file path set to: %1" ).arg( defaultConfigFilePath ) );
    }
    else
    {
      QgsDebugMsg( QString( "Using default configuration file path: %1" ).arg( defaultConfigFilePath ) );
    }

    QgsConfigParser* adminConfigParser = QgsConfigCache::instance()->searchConfiguration( configFilePath );
    if ( !adminConfigParser )
    {
      QgsDebugMsg( "parse error on config file " + configFilePath );
      theRequestHandler->sendServiceException( QgsMapServiceException( "", "Configuration file problem : perhaps you left off the .qgs extension?" ) );
      continue;
    }

    //sld parser might need information about request parameters
    adminConfigParser->setParameterMap( parameterMap );

    //request to WMS?
    QString serviceString( "WMS" );
    std::map<QString, QString>::const_iterator serviceIt = parameterMap.find( "SERVICE" );
    if ( serviceIt != parameterMap.end() )
    {
      serviceString = serviceIt->second;
    }
    /*else
    {
      QgsDebugMsg( "unable to find 'SERVICE' parameter, exiting..." );
      theRequestHandler->sendServiceException( QgsMapServiceException( "ServiceNotSpecified", "Service not specified. The SERVICE parameter is mandatory" ) );
      delete theRequestHandler;
      continue;
    }*/

    QgsWMSServer* theServer = 0;
    try
    {
      theServer = new QgsWMSServer( parameterMap, theMapRenderer );
    }
    catch ( QgsMapServiceException e ) //admin.sld may be invalid
    {
      theRequestHandler->sendServiceException( e );
      continue;
    }

    theServer->setAdminConfigParser( adminConfigParser );


    //request type
    std::map<QString, QString>::const_iterator requestIt = parameterMap.find( "REQUEST" );
    if ( requestIt == parameterMap.end() )
    {
      //do some error handling
      QgsDebugMsg( "unable to find 'REQUEST' parameter, exiting..." );
      theRequestHandler->sendServiceException( QgsMapServiceException( "OperationNotSupported", "Please check the value of the REQUEST parameter" ) );
      delete theRequestHandler;
      delete theServer;
      continue;
    }

    if ( requestIt->second == "GetCapabilities" )
    {
      const QDomDocument* capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath );
      if ( !capabilitiesDocument ) //capabilities xml not in cache. Create a new one
      {
        QgsDebugMsg( "Capabilities document not found in cache" );
        QDomDocument doc;
        try
        {
          doc = theServer->getCapabilities();
        }
        catch ( QgsMapServiceException& ex )
        {
          theRequestHandler->sendServiceException( ex );
          delete theRequestHandler;
          delete theServer;
          continue;
        }
        capabilitiesCache.insertCapabilitiesDocument( configFilePath, &doc );
        capabilitiesDocument = capabilitiesCache.searchCapabilitiesDocument( configFilePath );
      }
      else
      {
        QgsDebugMsg( "Found capabilities document in cache" );
      }

      if ( capabilitiesDocument )
      {
        theRequestHandler->sendGetCapabilitiesResponse( *capabilitiesDocument );
      }
      delete theRequestHandler;
      delete theServer;
      continue;
    }
    else if ( requestIt->second == "GetMap" )
    {
      QImage* result = 0;
      try
      {
        result = theServer->getMap();
      }
      catch ( QgsMapServiceException& ex )
      {
        QgsDebugMsg( "Catched exception during GetMap request" );
        theRequestHandler->sendServiceException( ex );
        delete theRequestHandler;
        delete theServer;
        continue;
      }

      if ( result )
      {
        QgsDebugMsg( "Sending GetMap response" );
        theRequestHandler->sendGetMapResponse( serviceString, result );
      }
      else
      {
        //do some error handling
        QgsDebugMsg( "result image is 0" );
      }
      delete result;
      delete theRequestHandler;
      delete theServer;
      continue;
    }
    else if ( requestIt->second == "GetFeatureInfo" )
    {
      QDomDocument featureInfoDoc;
      try
      {
        if ( theServer->getFeatureInfo( featureInfoDoc ) != 0 )
        {
          delete theRequestHandler;
          delete theServer;
          continue;
        }
      }
      catch ( QgsMapServiceException& ex )
      {
        theRequestHandler->sendServiceException( ex );
        delete theRequestHandler;
        delete theServer;
        continue;
      }

      //info format for GetFeatureInfo
      QString infoFormat;
      std::map<QString, QString>::const_iterator p_it = parameterMap.find( "INFO_FORMAT" );
      if ( p_it != parameterMap.end() )
      {
        infoFormat = p_it->second;
      }

      theRequestHandler->sendGetFeatureInfoResponse( featureInfoDoc, infoFormat );
      delete theRequestHandler;
      delete theServer;
      continue;
    }
    else if ( requestIt->second == "GetStyle" )
    {
      try
      {
        QDomDocument doc = theServer->getStyle();
        theRequestHandler->sendGetStyleResponse( doc );
      }
      catch ( QgsMapServiceException& ex )
      {
        theRequestHandler->sendServiceException( ex );
      }

      delete theRequestHandler;
      delete theServer;
      continue;
    }
    else if ( requestIt->second == "GetLegendGraphics" )
    {
      QImage* result = 0;
      try
      {
        result = theServer->getLegendGraphics();
      }
      catch ( QgsMapServiceException& ex )
      {
        theRequestHandler->sendServiceException( ex );
      }

      if ( result )
      {
        QgsDebugMsg( "Sending GetLegendGraphics response" );
        //sending is the same for GetMap and GetLegendGraphics
        theRequestHandler->sendGetMapResponse( serviceString, result );
      }
      else
      {
        //do some error handling
        QgsDebugMsg( "result image is 0" );
      }
      delete result;
      delete theRequestHandler;
      delete theServer;
      continue;

    }
    else if ( requestIt->second == "GetPrint" )
    {
      QByteArray* printOutput = 0;
      try
      {
        printOutput = theServer->getPrint( theRequestHandler->format() );
      }
      catch ( QgsMapServiceException& ex )
      {
        theRequestHandler->sendServiceException( ex );
      }

      if ( printOutput )
      {
        theRequestHandler->sendGetPrintResponse( printOutput );
      }
      delete printOutput;
      delete theRequestHandler;
      delete theServer;
      continue;
    }
    else//unknown request
    {
      QgsMapServiceException e( "OperationNotSupported", "Operation " + requestIt->second + " not supported" );
      theRequestHandler->sendServiceException( e );
      delete theRequestHandler;
      delete theServer;
    }
  }

  delete theMapRenderer;
  return 0;
}