示例#1
0
void dosman::Entry::run()
{
    std::string dosbox("dosbox ");
    std::string conf(" -conf ");
    std::string cpath(getConfPath());
    std::string rpath(getRunConfPath());
    std::string line = dosbox + conf + cpath + conf + rpath;
    system(line.c_str());
}
示例#2
0
static int initlog(unsigned char logLevelCode){
    char fileName[30]={0x0};

    //init log information
    if( strlen(logsetting.filepath) == 0 ){
        getConfPath(NULL);
        getlogset();
    }
    
    // log level
    if((logLevelCode & logsetting.loglevelCode ) != logLevelCode || (logsetting.loglevelCode & 0x7F) == 0)
        return 0;
 
    memset(&loging, 0, sizeof(LOG));
    
    //get current system time 
    time_t timer=time(NULL);
    strftime(loging.logtime, 20, "%Y-%m-%d %H:%M:%S", localtime(&timer));
    
    // get the log file name 
    strftime(fileName,11,"%Y-%m-%d",localtime(&timer));
    strcat(fileName,".log");

    strncpy(loging.filepath, logsetting.filepath, strlen(logsetting.filepath));
    
    if( opendir(loging.filepath) == NULL ){
        mkdir(loging.filepath, S_IRUSR | S_IWUSR | S_IXUSR);
    }
    
    strcat(loging.filepath, fileName);

    // open log file 
    if(loging.fp == NULL)
        loging.fp=fopen(loging.filepath, "a+");
    
    if(loging.fp == NULL){ 
        perror("Open Log File Fail!");
        return 0;
    }
    
    // write log level and time to file 
    fprintf(loging.fp,"[%s] [%s]: ",LogLevelText[menuToidx(logLevelCode)], loging.logtime);
    return 1;
}
示例#3
0
void dosman::Entry::writeConfig(void)
{
    config->saveConfigurationFile(getConfPath());
}
bool
ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args,
                               uint32_t argCount, NPVariant *result)
/*
name : method name
args : arguments
argCount : number of arguments
result : return value
*/
{
	NPIdentifier test_id = NPN_GetStringIdentifier("test");
	if (name == test_id) {
		printf("temp = %s\n",getTemporaryPath());
		printf("home = %s\n",getHomePath());
		printf("firefox = %s\n",getFirefoxPath());
		printf("conf = %s\n",getConfPath());
		printf("classpath = %s\n",getClassPath());
		printf("spawn = %s\n",getSpawnPath());
		VOID_TO_NPVARIANT(*result);
		return true;
	}

	NPError err;
	if (!this->HasMethod(name))
		return false;
	VOID_TO_NPVARIANT(*result);

	//login.jsp test
	NPIdentifier doSignature_id = NPN_GetStringIdentifier("doSignature");
	NPIdentifier getPublicKeyContent_id = NPN_GetStringIdentifier("getPublicKeyContent");


	NPObject* sWindowNPObj;

	if ((err = NPN_GetValue(mNpp, NPNVWindowNPObject, &sWindowNPObj)) != NPERR_NO_ERROR) {
		printf("Error in getting NPNVWindowNPObject: %d\n",err);
		return false;
	}

	const char *tmpdir = getTemporaryPath();
	const char *classpath = getClassPath();
	const char *spawnpath = getSpawnPath();

	if (name == doSignature_id) {
		if ((argCount == 2) && (NPVARIANT_IS_STRING(args[0])) && (NPVARIANT_IS_STRING(args[1]))) {
			char *randomStr = NULL;
			char *tpmPass = NULL;
			NPString n_randomStr = NPVARIANT_TO_STRING(args[0]);
			NPString n_tpmPass = NPVARIANT_TO_STRING(args[1]);
			m_strFromNP(&randomStr,n_randomStr);
			m_strFromNP(&tpmPass,n_tpmPass);
			printf("input = %s, %s",randomStr, tpmPass);

			char* ret = NULL;
			char *fname = tempnam(tmpdir,"jni");
			if (fname == NULL)
				fname = "tmp";
			char* margs[12];
			margs[0] = (char*) spawn_file;
			margs[1] = "--file";
			margs[2] = fname;
			margs[3] = "--method";
			margs[4] = "doSignature";
			margs[5] = "--classpath";
			margs[6] = (char*) classpath;
			margs[7] = "--args";
			margs[8] = "2";
			margs[9] = randomStr;
			margs[10] = tpmPass;
			margs[11] = NULL;
			// in windows use registry to find Firefox directory
			// in other OS, use path _spawnvp
			int rval = _spawnv(_P_WAIT,spawnpath,margs);
			if (rval) {
				fprintf(stderr,"error = %d\n",rval);
			}
			else {
				ret = getFileContent(fname);
				if (ret) {
					STRINGZ_TO_NPVARIANT(ret,*result); 
				}
				else {
					fprintf(stderr,"cannot read output file");
				}
				unlink(fname);
			}
			free(fname);
		}
		else {
			NPString str;
			str.UTF8Characters = "alert('usage: doSignature(String, String)');";
			str.UTF8Length = strlen(str.UTF8Characters);
			NPN_Evaluate(this->mNpp, sWindowNPObj, &str, NULL);
		}
	}
	else if (name == getPublicKeyContent_id) {
		if (argCount == 0) {
			char *ret = NULL;
			char *fname = tempnam(tmpdir,"jni");
			if (fname == NULL)
				fname = "tmp";
			char* margs[8];
			margs[0] = (char*) spawn_file;
			margs[1] = "--file";
			margs[2] = fname;
			margs[3] = "--method";
			margs[4] = "getPublicKeyContent";
			margs[5] = "--classpath";
			margs[6] = (char*) classpath;
			margs[7] = NULL;
			int rval = _spawnv(_P_WAIT,spawnpath,margs);
			if (rval) {
				fprintf(stderr,"error = %d\n",rval);
			}
			else {
				ret = getFileContent(fname);
				if (ret) {
					STRINGZ_TO_NPVARIANT(ret,*result); 
				}
				else {
					fprintf(stderr,"cannot read output file");
				}
				unlink(fname);
			}
			free(fname);
		}
		else {
			NPString str;
			str.UTF8Characters = "alert('usage: getPublicKeyContent()');";
			str.UTF8Length = strlen(str.UTF8Characters);
			NPN_Evaluate(this->mNpp, sWindowNPObj, &str, NULL);
		}
	}
	NPN_ReleaseObject(sWindowNPObj);
  return true;
}