示例#1
0
bool ZoneAdminRpcExec::execute(const HttpRequestContext& requestContext,
                               UtlSList&                 params,
                               void*                     userData,
                               XmlRpcResponse&           response,
                               ExecutionStatus&          status)
{

   bool result = false;
   status = XmlRpcMethod::FAILED;

   if (2 != params.entries())
   {
      handleExtraExecuteParam(name(), response, status);
   }
   else
   {
      if (!params.at(0) || !params.at(0)->isInstanceOf(UtlString::TYPE))
      {
         handleMissingExecuteParam(name(), PARAM_NAME_CALLING_HOST, response, status);
      }
      else
      {
         if (!params.at(1) || !params.at(1)->isInstanceOf(UtlString::TYPE))
         {
            handleMissingExecuteParam(name(), PARAM_NAME_COMMAND, response, status);
         }
         else
         {
            UtlString* pCallingHostname = dynamic_cast<UtlString*>(params.at(0));
            SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData);

            if(validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name()))
            {
               UtlBool   method_result(true);
               UtlString arguments[3];
               OsPath    mWorkingDirectory = ".";
               OsPath    mExec = SipXecsService::Path(SipXecsService::LibExecDirType,"sipxzoneadmin");
               UtlString mStdOutFile;
               UtlString mStdErrFile;

               UtlString* pSubCommand = dynamic_cast<UtlString*>(params.at(1));

               if ( !buildOutputFiles(*pSubCommand, mStdOutFile, mStdErrFile))
               {
                    // Invalid request. Set a Fault.
                    response.setFault(ZoneAdminRpcMethod::FailureToLaunch, "Invalid command");
                    status = XmlRpcMethod::FAILED;
                    return result;
               }

               OsPath    mStdOutPath = SipXecsService::Path(SipXecsService::LogDirType, mStdOutFile.data());
               OsPath    mStdErrPath = SipXecsService::Path(SipXecsService::LogDirType, mStdErrFile.data());

               // Pass the argumenst to sipx-zoneadmin.sh
               arguments[0] = "-n";                 // non-interactive
               arguments[1] = pSubCommand->data();  // string "<primary server> -o <secondary server>"

               // Make sure that there is no other instance running.
               if (! duplicateProcess(ZoneAdminExec, response, status))
               {
                  // execute the command and return whether or not the launch was successful.
                  OsProcess* zoneCheck = new OsProcess();

                  // Setup the Standard Output and Standard Error files.
                  OsPath mStdInFile;   // Blank
                  int rc;
                  rc = zoneCheck->setIORedirect(mStdInFile, mStdOutPath, mStdErrPath);

                  // Launch the process but tell the parent to ignore the child's signals (especially on shutdown).
                  // It will let the system handle it to avoid a defunct process.
                  if ( (rc=zoneCheck->launch(mExec, &arguments[0], mWorkingDirectory,
                                   zoneCheck->NormalPriorityClass, FALSE,
                                   TRUE)) // Parent to ignore child signals.
                           == OS_SUCCESS )
                  {
                      // Construct and set the response.
                      UtlSList outputPaths;
                      outputPaths.insert(&mStdOutPath);
                      outputPaths.insert(&mStdErrPath);

                      // Add the file resources to Supervisor Process so they can be retrieved
                      FileResource::logFileResource( mStdOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME));
                      FileResource::logFileResource( mStdErrPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME));
                      response.setResponse(&outputPaths);
                      status = XmlRpcMethod::OK;
                      result = true;
                  }   // launch
                  else
                  {
                     // Failed to launch the command, send a fault.
                     response.setFault(ZoneAdminRpcMethod::FailureToLaunch, "Failure to launch command");
                     status = XmlRpcMethod::FAILED;
                  }

                  delete zoneCheck;
               }  // duplicateProcess
            }  // validcaller
            else
            {
               status = XmlRpcMethod::FAILED;
            }
         }  // param 1 okay
      }  // param 0 okay
   } //number of parms check

   return result;
}
示例#2
0
bool SwAdminRpcSnapshot::execute(const HttpRequestContext& requestContext,
                                 UtlSList&                 params,
                                 void*                     userData,
                                 XmlRpcResponse&           response,
                                 ExecutionStatus&          status)
{

   bool result = false;
   status = XmlRpcMethod::FAILED;

   if (2 != params.entries())
   {
      handleExtraExecuteParam(name(), response, status);
   }
   else
   {
      if (!params.at(0) || !params.at(0)->isInstanceOf(UtlString::TYPE))
      {
         handleMissingExecuteParam(name(), PARAM_NAME_CALLING_HOST, response, status);
      }
      else
      {
         UtlString* pCallingHostname = dynamic_cast<UtlString*>(params.at(0));
         SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData);

         if (!params.at(1) || !params.at(1)->isInstanceOf(UtlSList::TYPE))
         {
            handleMissingExecuteParam(name(), PARAM_NAME_COMMAND, response, status);
         }
         else
         {
            if (validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name()))
            {
               UtlSList* pArgsList = dynamic_cast<UtlSList*>(params.at(1));
               UtlSListIterator argsListIterator( *pArgsList );
               UtlString * pArg;

               // Make sure that there is no other instance running.
               if (! duplicateProcess(SwAdminSnapshot, response, status))
               {
                  UtlBool   method_result(true);
                  UtlString arguments[pArgsList->entries()+2];
                  UtlString subCommand;
                  OsPath    mWorkingDirectory = ".";
                  OsPath    mExec = SipXecsService::Path(SipXecsService::BinDirType, SwAdminSnapshot);

                  UtlString mStdOutFile(SwAdminSnapshot_cmd);
                  UtlString mStdErrFile(SwAdminSnapshot_cmd);

                  mStdOutFile.append(SwAdminStdOut_filetype);
                  mStdErrFile.append(SwAdminStdErr_filetype);

                  // Construct and set the response.
                  OsPath mStdOutPath = OsPath(SipXecsService::Path(SipXecsService::LogDirType, mStdOutFile.data()));
                  OsPath mStdErrPath = OsPath(SipXecsService::Path(SipXecsService::LogDirType, mStdErrFile.data()));
                  OsPath processOutPath = OsPath(SipXecsService::Path(SipXecsService::TmpDirType, OUTPUT_FILENAME));

                  for (int i = 0; (pArg = dynamic_cast<UtlString*>(argsListIterator())); i++)
                  {
                     XmlUnEscape(arguments[i], *pArg);
                  }

                  arguments[pArgsList->entries()] = processOutPath.data();
                  arguments[pArgsList->entries()+1] = NULL;

                  // execute the command and return whether or not the launch was successful.
                  OsProcess* swCheck = new OsProcess();

                  // Setup the Standard Output and Standard Error files.
                  OsPath mStdInFile;   // Blank
                  int rc;
                  rc = swCheck->setIORedirect(mStdInFile, mStdOutPath, mStdErrPath);

                  // Launch the process but tell the parent to ignore the child's signals (especially on shutdown).
                  // It will let the system handle it to avoid a defunct process.
                  if ( (rc=swCheck->launch(mExec, &arguments[0], mWorkingDirectory,
                                   swCheck->NormalPriorityClass, FALSE,
                                   TRUE)) // Parent to ignore child signals.
                           == OS_SUCCESS )
                  {
                     // Add the file resources to Supervisor Process so they can be retrieved
                     FileResource::logFileResource( mStdOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME));
                     FileResource::logFileResource( mStdErrPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME));
                     FileResource::logFileResource( processOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME));

                     UtlString outputFilename = processOutPath;

                     // Construct and set the response.
                     UtlSList outputPaths;
                     outputPaths.insert(&outputFilename);
                     outputPaths.insert(&mStdOutPath);
                     outputPaths.insert(&mStdErrPath);

                     response.setResponse(&outputPaths);
                     status = XmlRpcMethod::OK;
                     result = true;
                  } // launch
                  else
                  {
                     // Failed to launch the command, send a fault.
                     response.setFault(SwAdminRpcMethod::FailureToLaunch, "Failure to launch command");
                     status = XmlRpcMethod::FAILED;
                  }

                  delete swCheck;
               }  // duplicateProcess
            }  // validcaller
            else
            {
               status = XmlRpcMethod::FAILED;
            }
         }  // param 1 okay
      }  // param 0 okay
   } //number of parms check

   return result;
}