Пример #1
0
void TestDxArchiver::testDxArchiverCmdLineArgs()
{
    string progName("TestDxArchiverCmdLineArgs");
    int defaultSsePort(2222);
    int defaultDxPort(3333);
    string defaultSseHostname("fred-main");
    string defaultName("archiver7");
    bool defaultNoUi(false);

    DxArchiverCmdLineArgs cmdArgs(progName, 
				   defaultSseHostname,
				   defaultSsePort, 
				   defaultDxPort, 
				   defaultNoUi,
				   defaultName);

    // test usage message output
    cmdArgs.usage();
    cerr << endl;

    // check the defaults
    cu_assert (cmdArgs.getSsePort() == defaultSsePort);
    cu_assert (cmdArgs.getDxPort() == defaultDxPort);
    cu_assert (cmdArgs.getSseHostname() == defaultSseHostname);
    cu_assert (cmdArgs.getNoUi() == defaultNoUi);
    cu_assert (cmdArgs.getName() == defaultName);

    // try setting alternate parameters
    const char *argv[] = 
    { "ProgName",
      "-host", "barney",
      "-sse-port", "8888",
      "-dx-port", "8877",
      "-name", "archiver8"
    };
    const int argc = ARRAY_LENGTH(argv);

    // verify that everything parses
    cu_assert(cmdArgs.parseArgs(argc, const_cast<char **>(argv)));

    // check the values
    cu_assert (cmdArgs.getSseHostname() == "barney");
    cu_assert (cmdArgs.getSsePort() == 8888);
    cu_assert (cmdArgs.getDxPort() == 8877);
    cu_assert (cmdArgs.getName() == "archiver8");

    cout << "test a bad bort number" << endl;
    const char *argvBadPort[] = 
    { "ProgName",
      "-host",
      "matrix",
      "-sse-port",
      "badportnumber",
    };
    const int argcBadPort = ARRAY_LENGTH(argvBadPort);
    cu_assert(cmdArgs.parseArgs(argcBadPort, const_cast<char **>(argvBadPort)) == false);

}
Пример #2
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    a.setOrganizationName("Batty Bovine Productions, LLC");
    a.setOrganizationDomain("animerenderfarm.battybovine.com");
    a.setApplicationName("Anime Renderfarm");
    a.setApplicationVersion("0.1.1");

    // Handle command line arguments
    if(cmdArgs(a.arguments())) {
        // If the arguments indicate we want to run in server mode, do so
        ServerThread *st = new ServerThread();
        st->start();
    } else {
        // Otherwise, start the main window of the GUI interface
        AnimeRenderfarm w;
        w.show();
        return a.exec();
    }
}
Пример #3
0
void AdminConnection::doCmd(std::string const &cmd)
{
    (debugAdmin.enabled() ? LogNotice : LogSpam) << "AdminConnection::doCmd(" << istat::sql_quote(cmd) << ")";
    ++as_->numAdminCommands_;
    std::string left, right;
    switch (istat::split(cmd, ' ', left, right))
    {
        case 0:
            huh();
            break;
        case 1:
        case 2:
            {
                std::vector<std::string> args;
                istat::trim(left);
                istat::trim(right);
                istat::explode(right, ',', args);
                cmdArgs(left, args);
            }
            break;
    }
}
Пример #4
0
MStatus MayaToCorona::doIt( const MArgList& args)
{
	MStatus stat = MStatus::kSuccess;

	MArgDatabase argData(syntax(), args);

	if (argData.isFlagSet("-version", &stat))
	{
		MStringArray res;
		for (auto v : getFullVersionString())
			res.append(v.c_str());
		setResult(res);
		
		return MS::kSuccess;
	}

	MGlobal::displayInfo("Executing mayaToCorona...");
	setLogLevel();

	if (argData.isFlagSet("-state", &stat))
	{
		Logging::debug(MString("state: ???"));
		MayaTo::MayaToWorld::WorldRenderState rstate = MayaTo::getWorldPtr()->renderState;
		if (rstate == MayaTo::MayaToWorld::RSTATETRANSLATING)
				setResult("rstatetranslating");
		if (rstate == MayaTo::MayaToWorld::RSTATERENDERING)
			setResult("rstaterendering");
		if (rstate == MayaTo::MayaToWorld::RSTATEDONE)
			setResult("rstatedone");
		if (rstate == MayaTo::MayaToWorld::RSTATENONE)
			setResult("rstatenone");
		if (rstate == MayaTo::MayaToWorld::RSTATESTOPPED)
			setResult("rstatestopped");
		return MS::kSuccess;
	}

	if (argData.isFlagSet("-canDoIPR", &stat))
	{
		if(MayaTo::getWorldPtr()->canDoIPR())
			setResult("yes");
		else
			setResult("no");
		return MS::kSuccess;
	}

	if ( argData.isFlagSet("-stopIpr", &stat))
	{
		Logging::debug(MString("-stopIpr"));
		EventQueue::Event e;
		e.type = EventQueue::Event::IPRSTOP;
		theRenderEventQueue()->push(e);
		return MS::kSuccess;
	}

	if ( argData.isFlagSet("-pauseIpr", &stat))
	{
		Logging::debug(MString("-pauseIpr"));
		Logging::debug(MString("-stopIpr"));
		EventQueue::Event e;
		e.type = EventQueue::Event::IPRPAUSE;
		theRenderEventQueue()->push(e);
		return MS::kSuccess;
	}

	// I have to request useRenderRegion here because as soon the command is finished, what happens immediatly after the command is 
	// put into the queue, the value is set back to false.
	std::unique_ptr<MayaTo::CmdArgs> cmdArgs(new MayaTo::CmdArgs);
	MObject drg = objectFromName("defaultRenderGlobals");
	MFnDependencyNode drgfn(drg);
	cmdArgs->useRenderRegion = drgfn.findPlug("useRenderRegion").asBool();


	if ( argData.isFlagSet("-startIpr", &stat))
	{
		Logging::debug(MString("-startIpr"));
		cmdArgs->renderType = MayaTo::MayaToWorld::WorldRenderType::IPRRENDER;
	}
	
	if (argData.isFlagSet("-width", &stat))
	{
		argData.getFlagArgument("-width", 0, cmdArgs->width);
		Logging::debug(MString("width: ") + cmdArgs->width);
	}

	if (argData.isFlagSet("-height", &stat))
	{
		argData.getFlagArgument("-height", 0, cmdArgs->height);
		Logging::debug(MString("height: ") + cmdArgs->height);
	}

	if ( argData.isFlagSet("-camera", &stat))
	{
	    MDagPath camera;
        MSelectionList selectionList;
		argData.getFlagArgument("-camera", 0, selectionList);
        stat = selectionList.getDagPath(0, camera);
		camera.extendToShape();
		Logging::debug(MString("camera: ") + camera.fullPathName());
		cmdArgs->cameraDagPath = camera;
	}			
	
	EventQueue::Event e;
	e.cmdArgsData = std::move(cmdArgs);
	e.type = EventQueue::Event::INITRENDER;
	theRenderEventQueue()->push(e);
	
	//
	if (MGlobal::mayaState() == MGlobal::kBatch)
	{
		RenderQueueWorker::startRenderQueueWorker();
	}
	return MStatus::kSuccess;
}
Пример #5
0
void TestDx::testDxCmdLineArgs()
{
    string progName("TestDxCmdLineArgs");
    int defaultMainPort(9999);
    int defaultRemotePort(5555);
    string defaultHost("thisHost");
    string defaultSciDataDir("fooDir");
    string defaultSciDataPrefix("nss.p10");
    bool defaultBroadcast(false);
    bool defaultNoUi(false);
    bool defaultVaryOutputData(false);
    string defaultDxName("dxsim33");
    bool defaultRemoteMode(false);

    DxCmdLineArgs cmdArgs(progName, 
			   defaultMainPort, defaultRemotePort,
			   defaultHost,
			   defaultSciDataDir, defaultSciDataPrefix,
			   defaultBroadcast,
			   defaultNoUi,
			   defaultVaryOutputData,
			   defaultDxName,
			   defaultRemoteMode);


    // test usage message output
    cmdArgs.usage();
    cerr << endl;

    // check the defaults
    cu_assert (cmdArgs.getMainPort() == 9999);
    cu_assert (cmdArgs.getRemotePort() == 5555);
    cu_assert (cmdArgs.getHostName() == "thisHost");
    cu_assert (cmdArgs.getSciDataDir() == "fooDir");
    cu_assert (cmdArgs.getSciDataPrefix() == "nss.p10");
    cu_assert (! cmdArgs.getBroadcast());
    cu_assert (! cmdArgs.getNoUi());
    cu_assert (! cmdArgs.getVaryOutputData());
    cu_assert (cmdArgs.getDxName() == "dxsim33");
    cu_assert (! cmdArgs.getRemoteMode());


    // try setting good parameters
    const char *argv[] = 
    { "ProgName",
      "-host", "matrix",
      "-mainport", "8888",
      "-remport", "9999",
      "-sddir", "../scienceData",
      "-sdprefix", "nss.p6",
      "-broadcast",
      "-name", "dxsim127",
      "-remote",
      "-noui",
      "-vary"
    };
    const int argc = ARRAY_LENGTH(argv);

    // verify that everything parses
    cu_assert(cmdArgs.parseArgs(argc, const_cast<char **>(argv)));

    // check the values
    cu_assert (cmdArgs.getHostName() == "matrix");
    cu_assert (cmdArgs.getMainPort() == 8888);
    cu_assert (cmdArgs.getRemotePort() == 9999);
    cu_assert (cmdArgs.getSciDataDir() == "../scienceData");
    cu_assert (cmdArgs.getSciDataPrefix() == "nss.p6");
    cu_assert (cmdArgs.getBroadcast());
    cu_assert (cmdArgs.getDxName() == "dxsim127");
    cu_assert (cmdArgs.getRemoteMode());
    cu_assert (cmdArgs.getNoUi());
    cu_assert (cmdArgs.getVaryOutputData());

    cout << "Test a bad port number:" << endl;
    const char *argvBadPort[] = 
    { "ProgName",
      "-host",
      "matrix",
      "-mainport",
      "badportnumber",
    };
    const int argcBadPort = ARRAY_LENGTH(argvBadPort);
    cu_assert(cmdArgs.parseArgs(argcBadPort, const_cast<char **>(argvBadPort)) == false);

}
Пример #6
0
int main( int argc, char* argv[] )
{
	unsigned	days;
	std::string	saltStr;
	std::string	b64SaltStr;

	PO::options_description desc( "Usage:\n"
				      "  wolfpasswd -D passwordfile username\n"
				      "  wolfpasswd [-c] [-d days] passwordfile username [user info]\n"
				      "  wolfpasswd -b[c] [-d days] passwordfile username password [user info]\n"
				      "  wolfpasswd -n [-s/-S salt] [-d days] username [user info]\n"
				      "  wolfpasswd -nb [-s/-S salt] [-d days] username password [user info]\n"
				      "  wolfpasswd -h\n"
				      "Options" );
	desc.add_options()
			( "help,h", "Display this help message." )
			( "create,c", "Create the file if it doesn't exist." )
			( "salt,s", PO::value< std::string >( &saltStr ), "Use the specified plain text salt (only valid with --display-only)." )
			( "base64-salt,S", PO::value< std::string >( &b64SaltStr ), "Use the specified base64 salt (only valid with --display-only)." )
			( "days,d", PO::value< unsigned >( &days )->default_value( 0 ), "Set the password expiration after <days>." )
			( "display-only,n", "Don't update the password file; display results on stdout." )
			( "batch,b", "Use the password from the command line instead of prompting for it.")
			( "delete,D", "Delete the specified user." )
			;

	PO::options_description cmdArgs( "Arguments" );
	cmdArgs.add_options()
			( "posArgs", PO::value< std::vector<std::string> >(), "positional arguments" )
			;
	cmdArgs.add( desc );

	PO::positional_options_description posArgs;
	posArgs.add( "posArgs", -1 );

	PO::variables_map vm;
	try	{
		PO::store( PO::command_line_parser( argc, argv ).
			   options( cmdArgs ).positional( posArgs ).run(), vm );
		PO::notify( vm );
	}
	catch( std::exception& e )	{
		std::cerr << "\nERROR: " << e.what() << "\n\n";
		std::cout << desc << "\n";
		return 2;
	}

	bool	createFile = false;
	bool	displayOnly = false;
	bool	batchPwd = false;
	bool	delUser = false;

	if ( vm.count( "create" ))
		createFile = true;
	if ( vm.count( "display-only" ))
		displayOnly = true;
	if ( vm.count( "batch" ))
		batchPwd = true;
	if ( vm.count( "delete" ))
		delUser = true;

	// deal with help
	if ( vm.count( "help" ))	{
		if ( createFile || displayOnly|| batchPwd || delUser
				|| vm.count( "posArgs" ))
			std::cout << "\nWARNING: --help ignores all other flags and arguments.\n\n";
		std::cout << desc << "\n";
		return 1;
	}

	if ( !vm.count( "posArgs" ))	{
		std::cerr << "\nERROR: no arguments given.\n\n";
		std::cout << desc << "\n";
		return 2;
	}
	const std::vector<std::string>& args = vm["posArgs"].as< std::vector<std::string> >();

	_Wolframe::system::RandomGeneratorImpl rnd;

	// display only
	if ( displayOnly )	{
		bool	wrong = false;
		if ( createFile )	{
			std::cerr << "\nERROR: --create cannot be used with --display-only.";
			wrong = true;
		}
		if ( delUser )	{
			std::cerr << "\nERROR: --delete cannot be used with --display-only.";
			wrong = true;
		}
		if ( batchPwd )	{
			if ( args.size() < 2 )	{
				std::cerr << "\nERROR: too few arguments.";
				wrong = true;
			}
			else if ( args.size() > 3 )	{
				std::cerr << "\nERROR: too many arguments.";
				wrong = true;
			}
		}
		else	{
			if ( args.size() > 2 )	{
				std::cerr << "\nERROR: too many arguments.";
				wrong = true;
			}
		}
		if ( !saltStr.empty() && !b64SaltStr.empty() )	{
			std::cerr << "\nERROR: both --salt and --base64-salt arguments given.";
			wrong = true;
		}
		if ( wrong )	{
			std::cout << "\n\n" << desc << "\n";
			return 2;
		}

		// All parameters are OK
		std::string passwd;
		WA::PwdFileUser user;
		if ( ! batchPwd )	{
			passwd = WA::getPassword();
			if( args.size() == 2 )
				user.info = args[1];
		}
		else	{
			passwd = args[1];
			if( args.size() == 3 )
				user.info = args[2];
		}
		// now do the job
		WA::PasswordHash::Salt salt;
		if ( saltStr.empty() && b64SaltStr.empty() )
			salt = WA::PasswordHash::Salt( rnd );
		else	{
			if ( !saltStr.empty() )
				b64SaltStr = _Wolframe::base64::encode( saltStr.data(), saltStr.size(), 0 );
			salt = WA::PasswordHash::Salt( b64SaltStr );
		}
		WA::PasswordHash pwd( salt, passwd );

		user.user = args[0];
		user.hash = pwd.toString();
		user.expiry = 0;
		std::cout << "Password line: " << WA::PasswordFile::passwdLine( user );
	}
	// delete user
	else if ( delUser )	{
		bool	wrong = false;
		if ( createFile )	{
			std::cerr << "\nERROR: --create cannot be used with --delete.";
			wrong = true;
		}
		if ( args.size() < 2 )	{
			std::cerr << "\nERROR: too few arguments.";
			wrong = true;
		}
		else if ( args.size() > 2 )	{
			std::cerr << "\nERROR: too many arguments.";
			wrong = true;
		}
		if ( wrong )	{
			std::cout << "\n\n" << desc << "\n";
			return 2;
		}
		if ( ! saltStr.empty() )
			std::cerr << "\nWarning: --salt argument ignored.";
		if ( ! b64SaltStr.empty() )
			std::cerr << "\nWarning: --base64-salt argument ignored.";

		// All parameters are OK
		try	{
			std::string filename = WU::resolvePath( boost::filesystem::absolute( args[0] ).string());
			WA::PasswordFile pwdFile( filename );

			if ( pwdFile.delUser( args[1] ))
				std::cout << "User '" << args[1] << "' removed from password file '"
					  << filename << "'.";
			else
				std::cout << "User '" << args[1] << "' not found in password file '"
					  << filename << "'.";
		}
		catch( std::exception& e )	{
			std::cerr << "Error removing user '" << args[1] << "': " << e.what() << "\n\n";
			return 1;
		}
	}
	// normal operation
	else	{
		bool	wrong = false;
		if ( batchPwd )	{
			if ( args.size() < 3 )	{
				std::cerr << "\nERROR: too few arguments.";
				wrong = true;
			}
			else if ( args.size() > 4 )	{
				std::cerr << "\nERROR: too many arguments.";
				wrong = true;
			}
		}
		else	{
			if ( args.size() < 2 )	{
				std::cerr << "\nERROR: too few arguments.";
				wrong = true;
			}
			if ( args.size() > 3 )	{
				std::cerr << "\nERROR: too many arguments.";
				wrong = true;
			}
		}
		if ( !saltStr.empty() && !b64SaltStr.empty() )	{
			std::cerr << "\nERROR: both --salt and --base64-salt arguments given.";
			wrong = true;
		}

		if ( wrong )	{
			std::cout << "\n\n" << desc << "\n";
			return 2;
		}

		// Al parameters are OK, do the job
		bool create = false;
		if ( createFile )
			create = true;
		try	{
			std::string filename = WU::resolvePath( boost::filesystem::absolute( args[0] ).string());
			WA::PasswordFile pwdFile( filename, create );
			WA::PwdFileUser user;

			std::string passwd;
			if ( ! batchPwd )	{
				passwd = WA::getPassword();
				if( args.size() == 3 )
					user.info = args[2];
			}
			else	{
				passwd = args[2];
				if( args.size() == 4 )
					user.info = args[3];
			}
			WA::PasswordHash::Salt salt;
			if ( saltStr.empty() && b64SaltStr.empty() )
				salt = WA::PasswordHash::Salt( rnd );
			else	{
				if ( !saltStr.empty() )
					b64SaltStr = _Wolframe::base64::encode( saltStr.data(), saltStr.size(), 0 );
				salt = WA::PasswordHash::Salt( b64SaltStr );
			}
			WA::PasswordHash pwd( salt, passwd );
			user.user = args[1];
			user.hash = pwd.toString();
			user.expiry = 0;
			if ( pwdFile.addUser( user ) )
				std::cout << "User '" << args[1] << "' added to the password file '"
					  << filename << "'.";
			else
				std::cout << "Error: user '" << args[1] << "' already exists in the password file '"
					  << filename << "'.";

		}
		catch( std::exception& e )	{
			std::cerr << "Error adding user '" << args[1] << "': " << e.what() << "\n\n";
			return 1;
		}
	}
	std::cout << "\nDone.\n\n";
	return 0;
}
int ControlApplication::run()
{
  ControlCommandLine cmdLineParser;

  // Check command line for valid.
  try {
    WinCommandLineArgs cmdArgs(m_commandLine.getString());
    cmdLineParser.parse(&cmdArgs);
  } catch (CommandLineFormatException &) {
    TvnServerHelp::showUsage();
    return 1;
  }

  // Run configuration dialog and exit.
  if (cmdLineParser.hasConfigAppFlag() || cmdLineParser.hasConfigServiceFlag()) {
    return runConfigurator(cmdLineParser.hasConfigServiceFlag(), cmdLineParser.hasDontElevateFlag());
  }

  if (cmdLineParser.hasCheckServicePasswords()) {
    return checkServicePasswords(cmdLineParser.hasDontElevateFlag());
  }

  // Change passwords and exit.
  if (cmdLineParser.hasSetControlPasswordFlag() || cmdLineParser.hasSetVncPasswordFlag()) {
    Configurator::getInstance()->setServiceFlag(true);
    Configurator::getInstance()->load();
    ServerConfig *config = Configurator::getInstance()->getServerConfig();
    UINT8 cryptedPass[8];
    if (cmdLineParser.hasSetControlPasswordFlag()) {
      getCryptedPassword(cryptedPass, cmdLineParser.getControlPassword());
      config->setControlPassword((const unsigned char *)cryptedPass);
      config->useControlAuth(true);
    } else {
      getCryptedPassword(cryptedPass, cmdLineParser.getPrimaryVncPassword());
      config->setPrimaryPassword((const unsigned char *)cryptedPass);
      config->useAuthentication(true);
    }
    Configurator::getInstance()->save();
    return 0;
  }

  int retCode = 0;

  // If we are in the "-controlservice -slave" mode, make sure there are no
  // other "service slaves" in this session, exit if there is one already.

  GlobalMutex *appGlobalMutex = 0;

  if (cmdLineParser.hasControlServiceFlag() && cmdLineParser.isSlave()) {
    try {
      appGlobalMutex = new GlobalMutex(
        ServerApplicationNames::CONTROL_APP_INSTANCE_MUTEX_NAME, false, true);
    } catch (...) {
      return 1;
    }
  }

  ZombieKiller zombieKiller;

  // Connect to server.
  try {
    connect(cmdLineParser.hasControlServiceFlag(), cmdLineParser.isSlave());
  } catch (Exception &) {
    if (!cmdLineParser.isSlave() && !cmdLineParser.hasCheckServicePasswords()) {
      const TCHAR *msg = StringTable::getString(IDS_FAILED_TO_CONNECT_TO_CONTROL_SERVER);
      const TCHAR *caption = StringTable::getString(IDS_MBC_TVNCONTROL);
      MessageBox(0, msg, caption, MB_OK | MB_ICONERROR);
    }
    return 1;
  }

  // Execute command (if specified) and exit.
  if (cmdLineParser.isCommandSpecified()) {
    Command *command = 0;

    StringStorage passwordFile;
    cmdLineParser.getPasswordFile(&passwordFile);
    m_serverControl->setPasswordProperties(passwordFile.getString(), true,
                                           cmdLineParser.hasControlServiceFlag());

    if (cmdLineParser.hasKillAllFlag()) {
      command = new DisconnectAllCommand(m_serverControl);
    } else if (cmdLineParser.hasReloadFlag()) {
      command = new ReloadConfigCommand(m_serverControl);
    } else if (cmdLineParser.hasConnectFlag()) {
      StringStorage hostName;
      cmdLineParser.getConnectHostName(&hostName);
      command = new ConnectCommand(m_serverControl, hostName.getString());
    } else if (cmdLineParser.hasShutdownFlag()) {
      command = new ShutdownCommand(m_serverControl);
    } else if (cmdLineParser.hasSharePrimaryFlag()) {
      command = new SharePrimaryCommand(m_serverControl);
    } else if (cmdLineParser.hasShareDisplay()) {
      unsigned char displayNumber = cmdLineParser.getShareDisplayNumber();
      command = new ShareDisplayCommand(m_serverControl, displayNumber);
    } else if (cmdLineParser.hasShareWindow()) {
      StringStorage shareWindowName;
      cmdLineParser.getShareWindowName(&shareWindowName);
      command = new ShareWindowCommand(m_serverControl, &shareWindowName);
    } else if (cmdLineParser.hasShareRect()) {
      Rect shareRect = cmdLineParser.getShareRect();
      command = new ShareRectCommand(m_serverControl, &shareRect);
    } else if (cmdLineParser.hasShareFull()) {
      command = new ShareFullCommand(m_serverControl);
    } else if (cmdLineParser.hasShareApp()) {
      command = new ShareAppCommand(m_serverControl, cmdLineParser.getSharedAppProcessId());
    }

    retCode = runControlCommand(command);

    if (command != 0) {
      delete command;
    }
  } else {
    bool showIcon = true;

    if (cmdLineParser.isSlave()) {
      m_slaveModeEnabled = true;
      try {
        try {
          showIcon = m_serverControl->getShowTrayIconFlag();
        } catch (RemoteException &remEx) {
          notifyServerSideException(remEx.getMessage());
        }
        try {
          m_serverControl->updateTvnControlProcessId(GetCurrentProcessId());
        } catch (RemoteException &remEx) {
          notifyServerSideException(remEx.getMessage());
        }
      } catch (IOException &) {
        notifyConnectionLost();
        return 1;
      } catch (Exception &) {
        _ASSERT(FALSE);
      }
    }

    retCode = runControlInterface(showIcon);
  }

  if (appGlobalMutex != 0) {
    delete appGlobalMutex;
  }

  return retCode;
}