Ejemplo n.º 1
0
void ServerManager::run()
{
  // execute default script
  //execFile("start.txt");
  //execScript("boot.js");
  puts(" starting to boot ");
  execScript("boot.py");

}
Ejemplo n.º 2
0
t_list				*_getResponse(t_socket *client)
{
  t_list		*list = NULL;


  client->request->_project = WUNDERBAR;
  if (client->request->_POST)
    {
      client->request->_GET = client->request->_POST;
    }

  if (client->request->_GET)
    {
      // **
      // Url redirections
      // **
      if (!strncmp(client->request->_GET, "/auth", strlen("/auth")))
	{
	  printf("WunderBar :: Requested function : auth();\n");
	  free(client->request->_GET);
	  client->request->_GET = strdup("auth();");
	}
      else if (!strncmp(client->request->_GET, "/exec", strlen("/exec")))
	{
	  printf("WunderBar :: Requested function : exec();\n");
	  free(client->request->_GET);
	  client->request->_GET = strdup("exec();");
	}
      /* list = addToList(NULL, ""); */
      list = execScript(client->request->_GET, client, &list);
    }
  
  /* t_list *copy; */
  /* char *preview; */
  /* copy = list; */
  /* while (copy) */
  /*   { */
  /*     if (copy->content) */
  /* 	{ */
  /* 	  preview = strndup(copy->content, 100); */
  /* 	  /\* printf("\t Response Preview : %s[...]\n", preview); *\/ */
  /* 	  free(preview); */
  /* 	} */
  /*     copy = copy->next; */
  /*   } */
  printf("WunderBar:: Response was prepared; Returning\n");
  return list;
}
Ejemplo n.º 3
0
/**
 * process a script execution event
 * @param pEvent
 * @param result - result string that can optionally be returned
 * @param pResult - optional result object
 * @return true if success
 * **/
bool scriptExec::process( baseEvent* pEvent, std::string& result, baseEvent* &pResult ) 
{
  bool bSuccess;
  pResult = NULL;
  
  errorString.erase();
  traceTimestamp.erase();
  systemParam.erase();
  failureCause.erase();
  result.reserve( 4096 );
  
  try
  {
    bSuccess = execScript( pEvent, result );

    // try to deserialise the output of the script
    if( bSuccess && bParseResponseForObject && (result.length()>(baseEvent::FRAME_HEADER_LEN+baseEvent::BLOCK_HEADER_LEN)) )
      pResult = baseEvent::unSerialiseFromString( result );
    if( (pResult!=NULL) && (pResult->getType()==baseEvent::EV_RESULT) )
      bSuccess = pResult->isSuccess();

    if( (pResult==NULL) && pEvent->getStandardResponse() )
      parseStandardResponse( bSuccess, result );
  }
  catch( Exception e )
  {
    bSuccess = false;
    result.clear();
    result += "exception: ";
    result += e.getMessage( );
  }
  catch( std::runtime_error e )
  { // json-cpp throws runtime_error
    log.error( "process failed caught std::runtime_error:'%s' result:'%s'", e.what(),result.c_str() );
    bSuccess = false;
    result = "exception: ";
    result += e.what();
  } // catch
  catch( ... )
  {
    log.error( "process failed: caught unknown exception result:'%s'",result.c_str() );
    bSuccess = false;
    result = "exception: unknown";
  } // catch
  
  std::string queue = pEvent->getDestQueue();
  std::ostringstream oss;
  oss << "scriptExec success: " << bSuccess << " queue: '" << queue << "'";
  oss << " ref: " << pEvent->getRef( );
  if( errorString.length() > 0 ) { oss << " error: " << errorString; }
  if( traceTimestamp.length() > 0 ) { oss << " traceT: " << traceTimestamp; }
  if( systemParam.length() > 0 ) { oss << " param: " << systemParam; }
  if( failureCause.length() > 0 ) { oss << " failCause: " << failureCause; }
  if( pEvent->getTrace().length() > 0 ) { oss << " traceB|:" << pEvent->getTrace() << ":|traceE"; }
  if( pResult != NULL )
    oss << " pResult: " << pResult->toString();
  else
    oss << " result:\n" << result;
  if( !bSuccess ) { oss << " event: " << pEvent->toString(); }
  log.info( log.LOGMOSTLY ) << oss.str();
  return bSuccess;
} // process
Ejemplo n.º 4
0
int main (int argc, char ** argv, char **envp) {

  /********************************************************************
  Command line parsing begins here
  First check to see if -d is defined, and debugging messages need to be printed.
  ********************************************************************/
  int finished = 0;
  char *prompt = "swish> ";
  char cmd[MAX_INPUT_BUFF_BUFF];
  char cmdCopyPipes[MAX_INPUT_BUFF_BUFF];
//  char tokenCopy[MAX_INPUT_BUFF_BUFF];
  char cwd[MAX_INPUT_BUFF_BUFF];
  bool pipeBool = false;

//execScript("testScript.sh");
  char *extractSh;
  if (argv[1] != NULL){

    extractSh = argv[1];
    extractSh += strlen(argv[1])-3;
    if(!strncmp(extractSh,".sh",3)){

      execScript(argv[1]);
      exit(0);
    }
  }


  /********************************************************************
  Setting the commands that the shell recognizes
  ********************************************************************/
  //char *commandsNL[] = { "ls\n","cd\n","pwd\n","printenv\n","putenv\n","cat\n"};
  //char *commands[] = { "ls","cd","pwd","make"};

  /*******************************************************************
  Get the CWD path
  Add a space and a null terminator to the path
  Print the path
  Print the 'swish' prompt
  ********************************************************************/
  int rv;
  char *theCWD = getcwd(cwd,sizeof(cwd));
  char *cursor;
  cursor = theCWD + strlen(theCWD);
  *cursor = ' ';
  cursor++;
  *cursor = '\0';
  cursor =NULL ;
  rv = write(1, theCWD, strlen(theCWD));
  rv = write(1, prompt, strlen(prompt));


  while (!finished) {
    char last_char;
    int count;
    /********************************************************************
    Removing this should make the only exit occur from the proper exit.
    IE typing 'exit'.
    *********************************************************************
    if (!rv) {
    finished = 1;
    break;
  } Ends while loop */


  /* read and parse the input put it into CMD */
  for(rv = 1, count = 0, cursor = cmd, last_char = 1;rv && (++count < (MAX_INPUT_BUFF_BUFF-1)) && (last_char != '\n'); cursor++) {
    rv = read(0, cursor, 1);
    last_char = *cursor;
  }
  *cursor = '\0';
  int rv = -1;
  if ((rv = checkForCd(cmd)) == 0) {;}
  else if ((rv = checkForExit(cmd)) == 0) {;}
  else if ((rv = checkForSet(cmd)) == 0) {;}
  else if ((rv = checkForWolfie(cmd)) == 0) {;}
  else{

  //test recursive piping here
strncpy(cmdCopyPipes, cmd, strlen(cmd));
int i;
for(i = 0; i < strlen(cmdCopyPipes); i++) {
  if(cmdCopyPipes[i] == '|') {
    pipeBool = true;
  }
  if(cmdCopyPipes[i] == '\n') {
    cmdCopyPipes[i] = '\0';
    break;
  }
}

if(*cmdCopyPipes != 0 && pipeBool) {
  redirControl(cmdCopyPipes);
}
else {
  write(1, "no\n", 3);
  redirOnly(cmdCopyPipes);
}
}
  theCWD = getcwd(cwd,sizeof(cwd));
  char *cursor;
  cursor = theCWD + strlen(theCWD);
  *cursor = ' ';
  cursor++;
  *cursor = '\0';
  cursor =NULL ;
  rv = write(1, theCWD, strlen(theCWD));
  rv = write(1, prompt, strlen(prompt));
  memset(cmd,'\0',MAX_INPUT_BUFF_BUFF);
  pipeBool = false;
} /* End while */
return 0;
}
Ejemplo n.º 5
0
int MaPhp4Handler::run(MaRequest *rq)
{
	MaDataStream		*dynBuf;
	MprHashTable		*env;
	MprStringHashEntry	*vp;
	int					flags, contentLength;

	hitCount++;

	flags= rq->getFlags();
	dynBuf = rq->getDynBuf();
	rq->insertDataStream(dynBuf);
	rq->setResponseCode(200);
	rq->setHeaderFlags(MPR_HTTP_DONT_CACHE);
	rq->setPullPost();

	//
	//	Initialize PHP
	//
 	TSRMLS_FETCH();

	zend_first_try {
		phpInitialized = 0;
		func_data = rq;
		var_array = 0;

		SG(server_context) = rq;
		SG(request_info).path_translated = rq->getFileName();
		SG(request_info).request_method = rq->getMethod();
		SG(request_info).request_uri = rq->getUri();
		SG(request_info).query_string = rq->getQueryString();
		SG(request_info).content_type = rq->getRequestContentMimeType();
		SG(request_info).content_length = rq->getContentLength();
		SG(sapi_headers).http_response_code = 200;
		SG(request_info).auth_user = rq->getUser();
		SG(request_info).auth_password = rq->getPassword();

		php_request_startup(TSRMLS_C);
		CG(zend_lineno) = 0;

	} zend_catch {

		mprLog(1, log, "PHP startup failed\n");
		zend_try {
			php_request_shutdown(0);
		} zend_end_try();
		rq->requestError(MPR_HTTP_INTERNAL_SERVER_ERROR, 
			"PHP initialization failed");
		return MPR_HTTP_HANDLER_FINISHED_PROCESSING;

	} zend_end_try();

	phpInitialized = 1;
	
	//
	//	Copy the environment variables to the PHP script engine
	//
	env = rq->getEnv();
	vp = (MprStringHashEntry*) env->getFirst();
	while (vp) {
		php_register_variable(vp->getKey(), vp->getValue(), 
			var_array TSRMLS_CC);
		vp = (MprStringHashEntry*) env->getNext(vp);
	}


	//
	//	Execute the PHP script
	//
	if (execScript(rq) < 0) {
		zend_try {
			php_request_shutdown(0);
		} zend_end_try();

		rq->requestError(MPR_HTTP_INTERNAL_SERVER_ERROR, 
			"PHP script execution failed");
		return MPR_HTTP_HANDLER_FINISHED_PROCESSING;
	}