示例#1
0
int cgiMain() {
	char username[40];   //用户名
	char value[20];	     //中间值
	long sessionId;      //会话ID
	char actName[20];    //请求动作
	char result[4096];   //请求结果
	char params[500];    //请求参数
	actName[0]= NULL;    //初始化
	result[0] = NULL;    //初始化

	//解决中文乱码
	cgiHeaderContentType("text/html; charset=UTF-8");
	
	/*    获取参数   */
	cgiFormString("username",username,40);
	cgiFormString("sessionId",value,20);
	sessionId = atol(value);
	cgiFormString("actName",actName,20);
	cgiFormString("params",params,500);
	
	/*  检查session有效性   */
	//会话无效
	if(!isSessionValid(sessionId,username)){
		//提示用户未登录或会话已过期
		printf("NLogin");
		return 0;
	}
	//会话有效
	else{
		//更新session访问时间
		updateSessionService(sessionId);
	}
	
	/*    权限验证    */
	//权限不足
	if(!isAuthorityValid(actName,username)){
		//提示权限不足
		printf("NRight");
		return 0;
	}
	
	/*   调用业务层处理请求   */
	//请求处理成功
	if(userServices(params,actName,result)){
		//输出请求结果
		
		printf(result);
		
	}
	//请求处理失败
	else{
		//输出系统出错信息
		printf("actName=%s;result=false",actName);
	}
	
	return 0;
}
示例#2
0
    /** This method executes the ListInstruments algorithm
     * and fills the instrument box with instrument lists returned by ICat API
     * @return shared pointer to workspace which contains instrument names
     */
    std::vector<std::string> ICatUtils::executeListInstruments()
    {
      QString algName("CatalogListInstruments");
      const int version=-1;
      Mantid::API::IAlgorithm_sptr alg;
      try
      {
        alg = Mantid::API::AlgorithmManager::Instance().create(algName.toStdString(),version);
      }
      catch(...)
      {
        throw std::runtime_error("Error when Populating the instrument list box");

      }

      Poco::ActiveResult<bool> result(alg->executeAsync());
      while( !result.available() )
      {
        QCoreApplication::processEvents();
      }
      if(!alg->isExecuted())
      {
        //if the algorithm failed check the session id passed is valid
        if(!isSessionValid(alg))
        {
          //at this point session is invalid, popup loginbox to login
          if(login())
          {
            //now populate instrument box
            std::vector<std::string> instruments =executeListInstruments();
            return instruments;
          }
          else
          {
            throw std::runtime_error("Please Login to the information catalog using the login menu provided to do the investigation search.");
          }
        }
        else
        {
          return std::vector<std::string>();
        }
      }
      std::vector<std::string>instrlist;
      try
      {

        instrlist= alg->getProperty("InstrumentList");
      }
      catch (Mantid::Kernel::Exception::NotFoundError&)
      {
        throw;
      }
      return instrlist;

    }
示例#3
0
int cgiMain() {	
	long sessionId;            //会话ID
	char value[128];
	char username[40];         //用户名
	char actName[50];          //请求动作
	char row[100];
	char msg[1024];
	char res[128];
	FILE *log = NULL;
	boolean blSuc = true; 
	/* ==================基本校验 ====================== */
	
	/*  获取请求参数  */
	cgiFormString("sessionId",value,20); 
	sessionId = atol(value);
	cgiFormString("username",username,40);
	cgiFormString("actName",actName,50);
	/* 检查session有效性  */
	//无效
	if(!isSessionValid(sessionId,username)){
		//无效session
		sprintf(res,"NLogin");
		blSuc = false; 
		goto result;
	}
	//有效
	else{
		//更新session访问时间
		updateSessionService(sessionId);
	}
	
	/*  权限验证  */
	//权限不足
	if(!isAuthorityValid(actName,username)){
		//输出权限不足信息
		sprintf(res,"NRight");
		blSuc = false; 
		goto result;
	}
	//读取进度信息 
	log = fopen(LOGPATH,"r");
	if(!log){
		strcpy(res,"false");
		blSuc = false;
		goto result;
	}
	strcpy(msg,"");
	while(fgets(row,100,log)){
		if(strstr(row,"失败")){
			strcat(msg,"<font color=red >");
			strcat(msg,row);
			strcat(msg,"<br>");
			strcat(msg,"</font>");
		}else{
			strcat(msg,"<font color=green >");
			strcat(msg,row);
			strcat(msg,"<br>");
			strcat(msg,"</font>");
		}
	}
	fclose(log);
result:	
	/*   ==================   输出hmtl内容  ===================  */
	cgiHeaderContentType("text/html; charset=utf-8");
	if(blSuc == true){
		printf("result@true;msg@%s;",msg);
	}else{
		printf("result@%s;",res);	
	}
	return 0;
}
示例#4
0
文件: upload4.c 项目: blockey/WebCgi
int cgiMain(void){
    cgiFilePtr file;
    int targetFile;
    mode_t  mode;
    char name[128];
    char fileNameOnServer[64];
    char contentType[1024];
    char buffer[BufferLen];
    char *tmpStr=NULL;
    int size;
    int got,t;
	 char cmd[256];
	long sessionId;            //会话ID
	char value[20];            //临时变量
	char username[40];         //用户名
	char actName[50];          //请求动作
	char msg[64];					//提示信息 
	int itemId = 0;				//网元ID 
	char cardtypes[128];
	char slots[128]; 
	 /* ==================基本校验 ====================== */
	
	/*  获取请求参数  */
	cgiFormString("sessionId",value,20);
	sessionId = atol(value);
	cgiFormString("username",username,40);
	cgiFormString("actName",actName,50);
	cgiFormString("QItemId",value,50);//网元ID
	itemId = atol(value);
	cgiFormString("cardtypes",cardtypes,128);
	cgiFormString("slots",slots,128);
	/* 检查session有效性  */
	//无效
	if(!isSessionValid(sessionId,username)){
		webLog("no");
		//无效session
		sprintf(msg,"未登录或会话已过期!");
		goto FAIL;
	}
	//有效
	else{
		webLog("yes");
		//更新session访问时间
		updateSessionService(sessionId);
	}
	
	/*  权限验证  */
	//权限不足
	if(!isAuthorityValid(actName,username)){
		//输出权限不足信息
		sprintf(msg,"您无此操作权限!");
		goto FAIL;
	}
	 
	
	//清除旧文件 
//	sprintf(cmd,"rm -f /backup/app.tar.gz ");
//	system(cmd);
	  
//	sprintf(cmd,"rm -rf %s/*",UPDATEDIR);
//	system(cmd);
	 
    //取得html页面中file元素的值,应该是文件在客户机上的路径名
    if (cgiFormFileName("updatePkg", name, sizeof(name)) !=cgiFormSuccess) {
        strcpy(msg,"系统出错:无法读取上传文件");
        goto FAIL;
    }  
    cgiFormFileSize("updatePkg", &size);
    if(size >30*1024*1024){
    	strcpy(msg,"不能上传大于30M的文件");
    	goto FAIL;
    }
    //取得文件类型,不过本例中并未使用
    cgiFormFileContentType("updatePkg", contentType, sizeof(contentType));
    //目前文件存在于系统临时文件夹中,通常为/tmp,通过该命令打开临时文件。临时文件的名字与用户文件的名字不同,所以不能通过路径/tmp/userfilename的方式获得文件
    if (cgiFormFileOpen("updatePkg", &file) != cgiFormSuccess) {
        fprintf(stderr,"could not open the file\n");
        goto FAIL;
    }
    t=-1; 
    //从路径名解析出用户文件名
    while(1){
        tmpStr=strstr(name+t+1,"\\");
        if(NULL==tmpStr)
            tmpStr=strstr(name+t+1,"/");//if "\\" is not path separator, try "/"
        if(NULL!=tmpStr)
            t=(int)(tmpStr-name);
        else
            break;
    } 
    strcpy(fileNameOnServer,"/app/webapp/httpd/html/file/");
    strcat(fileNameOnServer,name+t+1);
    mode=S_IRWXU|S_IRGRP|S_IROTH;  
    
    //删除同名文件 
    sprintf(cmd,"%s",fileNameOnServer);
    remove(cmd);
      
    //在当前目录下建立新的文件,第一个参数实际上是路径名,此处的含义是在cgi程序所在的目录(当前目录))建立新文件    
    targetFile=open(fileNameOnServer,O_RDWR|O_CREAT|O_TRUNC|O_APPEND,mode);
    if(targetFile<0){
        fprintf(stderr,"could not create the new file,%s\n",fileNameOnServer);
        goto FAIL;
    }
    //从系统临时文件中读出文件内容,并放到刚创建的目标文件中 
    while (cgiFormFileRead(file, buffer, BufferLen, &got) ==cgiFormSuccess){
        if(got>0)
            write(targetFile,buffer,got);    
    }
    cgiFormFileClose(file);
    close(targetFile);
    strcpy(msg,"升级文件上传成功!");
    
    
//    sprintf(cmd,"nohup /bin/Online &");
//	 system(cmd);
//	 sleep(1);
	 SendUpdateCmd(itemId,slots,cardtypes,name+t+1);
    goto END; 
FAIL:
   cgiHeaderContentType("text/html; charset=utf-8");
	printf("<html >\n");
	printf("<head> \n");
	printf("<title>Upload Information</title> \n");
	printf("</head> \n");
	printf("<body> \n");
	printf("<script type=\"text/javascript\">");
	//提示操作信息 
	printf("alert(\"%s\");",msg);	
	//提示信息后返回原页面 
	printf("window.location.href=\"/net/update.html\";");
	printf("</script>");
	printf("</body> \n");
	printf("</html> \n");
	return 0;
END:    
   cgiHeaderContentType("text/html; charset=utf-8");
	printf("<html >\n");
	printf("<head> \n");
	printf("<title>Upload Information</title> \n");
	printf("</head> \n");
	printf("<body> \n");
	printf("<script type=\"text/javascript\">");
	//提示操作信息 
	//printf("alert(\"%s\");",msg);	
	//提示信息后返回原页面 
	printf("window.location.href=\"/net/progress.html?itemId=%d\";",itemId);
	printf("</script>");
	printf("</body> \n");
	printf("</html> \n");
	return 0;
}