Example #1
0
int bcProcGetValue_s(char *pFile,char *pVarName,char *pVarValue)
{
    int iReturn;
    char caBuffer[256];
    char *p;
    
    FILE *fp;
    fp=fopen(pFile,"r");
    if(fp==NULL) {
        printf(" Error, Can't open the file %s\n",pFile);
        return (-1);
    }
    p=fgets(caBuffer,256,fp);
    while(p) {
        if(*p!='#' && (*p)!='*' && !(ltStrIsSpaces(caBuffer))) {
            p=ltStrSkipSpaces(p);
            iReturn=strncmp(p,pVarName,strlen(pVarName));
            if(iReturn==0){
	            	p=strstr(p,":");
	            	if(p){
	            		p=p+1;
	            		p=ltStrSkipSpaces(p);
	            		sprintf(pVarValue,"%s",p);
	            		fclose(fp);
	            		return 1;
	            	}
            }
          }
          p=fgets(caBuffer,255,fp);
     }
     fclose(fp);
   
    return 0;
}
Example #2
0
int ltCnfReadConfig(char *pHand,char *caConfigFile,
               int ltCnfSaveConf(char *p1,char *pVar,char *pVal))
{
    char *p;
    char caBuffer[256];
    char caVarName[32],caOutStr[255];
    short nLineNo;
    int iReturn;
    FILE *fp;
    fp=fopen(caConfigFile,"r");
    if(fp==NULL) {
        printf(" Error, Can't open the file %s\n",caConfigFile);
        return (-1);
    }
    p=fgets(caBuffer,255,fp);
    nLineNo=1;
    while(p) {
        if(*p!='#' && (*p)!='*' && !(ltStrIsSpaces(caBuffer))) {
            p=ltStrSkipSpaces(p);
            p=ltStrGetWord(p,caVarName,32,"=");
            p=ltStrSkipSpaces(p);
            if(*p == '=') {
                if(ltStrToUpper(caVarName)==0) {
                    printf(" Error in file %s Line %d\n",
                        caConfigFile,nLineNo);
                }
                else {
                    p++;
                    p=ltStrSkipSpaces(p);
                    p=ltStrGetWord(p,caOutStr,254," \n");
                    iReturn=ltCnfSaveConf(pHand,caVarName,caOutStr);
                    if(iReturn!=0){
                        fclose(fp);
                        return iReturn;
                    }
                }
            }
            else {
                printf(" Error in Config File %s Line %d\n",
                    caConfigFile,nLineNo);
            }
        }
        nLineNo++;
        p=fgets(caBuffer,255,fp);
    }
    fclose(fp);
    return 0;
}
Example #3
0
int ltCgiCvtSaveFile(char *caFileName,char *pTempPath,char *caSaveName)
{
    register int i;
    int l,j;
    char caTemp[256];
    if(ltStrIsSpaces(caFileName)) {
        strcpy(caSaveName,"\0");
    }
    else {
        l = strlen(caFileName);
        for(i=l;i>0&&caFileName[i-1]!=92&&caFileName[i-1]!=47;i--);
        for(j=0;i<l;i++,j++) {
            if(caFileName[i] == ' ') {caTemp[j] = '.'; }
            else { caTemp[j] = caFileName[i]; }
        }
        caTemp[j] = 0;
        sprintf(caSaveName,"%s/%s",pTempPath,caTemp);
    }
    return 0;
}
Example #4
0
ltCgiEntryU *ltCgiUpLoad(FILE *fp,char *pTempPath,int *iSumVar,int *err)
{
    FILE *fpo;
    ltCgiEntryU *psCgiEntry;
    int iReturn,j;
    int iBytes,iLen,iReadLen,iFile,iUploadFlags,iMaxVar;
    char *pBuffer;
    char caBound[256];
    char caBuffer[256];
    char caVarName[64];
    char caFileName[256];
    char caVarValue[1024];
    char caContentType[64];
    char caSaveName[256];
    char caHead[512];
    char caUpLoadPath[255];
    iUploadFlags = 0;
    j=0;
    *err=0;
    iMaxVar = 32;
    psCgiEntry = (ltCgiEntryU *)malloc(iMaxVar * sizeof(ltCgiEntryU));
    if(psCgiEntry == NULL) {
        return NULL;
    }    
    strcpy(caUpLoadPath,pTempPath);

    iBytes = ltCgiFgets(caBuffer,255,&iLen,fp);
    if(iBytes != 0) {
        ltCgiFreeEntriesU(psCgiEntry,iMaxVar);         
        return NULL;
    }
    /* 查找边界字符串  */
    if(strncmp(caBuffer,"--",2)!=0) {
        free(psCgiEntry);
        return NULL;
    }
    caBound[0] = '\r';
    caBound[1] = '\n';
    strcpy(caBound+2,caBuffer);
    iReturn = 0;
    while(iReturn!=EOF) {
            /* Read Head */
        iReturn = ltCgiFReadHead(fp,caHead);
        if(iReturn == 0) {
            iReturn = ltCgiAnalyLine(caHead,caVarName,caFileName,caContentType);
            if(iReturn == 1 || iUploadFlags) { /* 普通变量  */
                pBuffer = ltCgiReadUntilSP(fp,&iReadLen,caBound,strlen(caBound));
                if(pBuffer) {

                    /* 变量 uploadpath为保留变量 */
                    if(strncmp(caVarName,"Upload",6) == 0) {  /* 上载目录  */
                        strcpy(caUpLoadPath,pBuffer);
                        if(strncmp(pBuffer,"String",6) == 0) { /* 将文件内容放在字符串中  */
                           iUploadFlags = 1;
                        }
                        else if(strncmp(pBuffer,"Void",4) == 0) { /* 将文件内容放在一个指针中 */
                            iUploadFlags = 2;
                        }
                        free(pBuffer);
                    }
                    else {  /* 一般变量  */
                        if(j>= iMaxVar) {
                            psCgiEntry = 
                                realloc(psCgiEntry,sizeof(ltCgiEntryU) * (iMaxVar + 32));
                            iMaxVar = iMaxVar + 32;
                            if(psCgiEntry == NULL) {
                            	*err=-100;
                                return NULL;
                            }
                        }
                        psCgiEntry[j].name = malloc(strlen(caVarName) + 1);
                        strcpy(psCgiEntry[j].name,caVarName);
                        psCgiEntry[j].iLen = iReadLen;
                        psCgiEntry[j].val = pBuffer;
                        if(iReturn == 7) {
                            psCgiEntry[j].iType = iUploadFlags;
                        }
                        else {
                            psCgiEntry[j].iType = 0;
                        }
                        j++;
                    }
                }
                else {
                    free(psCgiEntry);
                    return NULL;
                }
            }
            else if(iReturn == 7) { /* 文件  */
                if(j>= iMaxVar) {
                    psCgiEntry = realloc(psCgiEntry,sizeof(ltCgiEntryU) * (iMaxVar + 32));
                    iMaxVar = iMaxVar + 32;
                    if(psCgiEntry == NULL) {
                        return NULL;
                    }
                }
                psCgiEntry[j].name = malloc(strlen(caVarName) + 1);
                strcpy(psCgiEntry[j].name,caVarName);
                ltCgiCvtSaveFile(caFileName,caUpLoadPath,caSaveName);
               
                if(!ltStrIsSpaces(caSaveName)) {
                    fpo = fopen(caSaveName,"w");
                }
                else fpo = NULL;
                iReturn = ltCgiReadUntilF(fp,fpo,caBound,strlen(caBound));
                if(fpo)
                   fclose(fpo);
                else {
                    strcpy(caSaveName,"\0");
                }
                if(iReturn!=1){
                	*err=-100;
                	ltCgiFreeEntriesU(psCgiEntry,j);
                	return NULL;
                }
                sprintf(caVarValue,"%s;%s;%s",caFileName,caSaveName,caContentType);
                ltCgiPlusToSpace(caVarValue);
                ltCgiUnEscapeUrl(caVarValue);
                psCgiEntry[j].val = malloc(strlen(caVarValue) + 1);
                strcpy(psCgiEntry[j].val,caVarValue);
                j++;
                iFile++;

            }
            else {
              
                ltCgiFreeEntriesU(psCgiEntry,j);
                return NULL;
            }
        }
    }
    *iSumVar = j;
    return psCgiEntry;
}
Example #5
0
int msaReportWebLineAjaxSubmit(int confd,ltMsgHead *ltMsgPk,lt_shmHead *lt_MMHead)

{

    ltDbCursor  *tempCursor;

    LT_DBROW    tempRow;

    ltDbHeadPtr dbPtr;

    ltTablePtr  tablePtr;

    char sqlBuf[1024];

    char caSdate[32],caEdate[32],caSdate1[32],caSdate2[32];

    char *reportname=NULL;

    char *email=NULL;

    char *lt_page_content=NULL;

    char *work=NULL;

    char caTempDir[256];

    char responseDir[256];

    char caLabel[256];

    char strdayflow[32];

    char htmlpage[256];

    unsigned long long lMaxBytes=1;

    unsigned long tmpDir=0;

    unsigned long fileName=0;

    long lTime,lTime1,lTime2;

    int  iFd=-1;

    int  srvindex,step;

    step=0;

    memset(htmlpage,0,sizeof(htmlpage));

    memset(caLabel,0,sizeof(caLabel));

    memset(caTempDir,0,sizeof(caTempDir));

    memset(responseDir,0,sizeof(responseDir));

    char *dbUser;

    char *dbPass;

    char *dbName;

    dbName=_ltPubInfo->_dbname;

    dbUser=_ltPubInfo->_dbuser;

    dbPass=_ltPubInfo->_dbpass;

    G_DbCon=ltDbConnect(dbUser,dbPass,dbName);

    if(G_DbCon==NULL) {

        return 0;

    }

    if(ltMsgGetVar_s(ltMsgPk,"sdate")) {

        sprintf(caSdate,"%s",ltMsgGetVar_s(ltMsgPk,"sdate"));

    } else {

        sprintf(caSdate,"%s","");

    }

    if(ltMsgGetVar_s(ltMsgPk,"edate")) {

        sprintf(caEdate,"%s",ltMsgGetVar_s(ltMsgPk,"edate"));

    } else {

        sprintf(caEdate,"%s","");

    }

    if(ltMsgGetVar_s(ltMsgPk,"reportname")) {

        reportname=ltMsgGetVar_s(ltMsgPk,"reportname");

    }

    if(ltMsgGetVar_s(ltMsgPk,"email")) {

        email=ltMsgGetVar_s(ltMsgPk,"email");

    }

    if(ltMsgGetVar_s(ltMsgPk,"step")) {

        step=atoi(ltMsgGetVar_s(ltMsgPk,"step"));

    }

    if(ltMsgGetVar_s(ltMsgPk,"work")) {

        work=ltMsgGetVar_s(ltMsgPk,"work");

    }

    if(ltMsgGetVar_s(ltMsgPk,"filedir")) {

        fileName=atoll(ltMsgGetVar_s(ltMsgPk,"filedir"));

    }

    if(fileName==0) {

        tmpDir=ltStrGetId();

        sprintf(caTempDir,"%s%s/%lu/",_datacenterdir,_webreport,tmpDir);

        sprintf(responseDir,"%lu",tmpDir);

        printf("caTempDir:%s\n",caTempDir);

        if(ltFileIsExist(caTempDir)!=1) {

            if(mkdir(caTempDir,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)!=0) {

                ltMsgPk->msgpktype=1;

                lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0");

                ltMsgFree(ltMsgPk);

                return 0;

            }

        }

    } else {

        sprintf(caTempDir,"%s%s/%lu/",_datacenterdir,_webreport,fileName);

        sprintf(responseDir,"%lu",fileName);

    }



    lTime = time(0);

    if(!ltStrIsSpaces(caSdate)) {

        lTime1 = nasCvtLongTime(caSdate,"00:00:00");

    } else {

        lTime1 = 0;

    }

    if(!ltStrIsSpaces(caEdate)) {

        lTime2 = nasCvtLongTime(caEdate,"23:59:59");

    } else {

        lTime2 = 0;

    }



    if(lTime1 == 0) {

        lTime1 = lTime;

    }

    if(lTime2 == 0) {

        lTime2 = lTime;

    }

    if(lTime1 > lTime) {

        lTime1 = lTime;

    }

    if(lTime2>lTime) {

        lTime2=lTime;

    }



    char sDate[64],sTime[64];

    char caFile1[256];

    char caCmd[256];

    int  fdwrite=0;

    nasTimeGetDate(caSdate1,lTime);

    nasCvtStime(time(0),sDate,sTime);

    sprintf(caFile1,"%sinfo.ini",caTempDir);

    fdwrite = open(caFile1, O_APPEND | O_WRONLY | O_CREAT, 0644);

    if(fdwrite == (-1)) {

        ltMsgPk->msgpktype=1;

        lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0");

        ltMsgFree(ltMsgPk);

        return 0;

    }

    sprintf(caCmd,"date=%s_%s\n",sDate,sTime);

    write(fdwrite,caCmd,strlen(caCmd));

    sprintf(caCmd,"reportname=%s\n",reportname);

    write(fdwrite,caCmd,strlen(caCmd));

    close(fdwrite);

    sprintf(caLabel,"/bin/echo '1' > %sproccess.ini",caTempDir);

    system(caLabel);

    sprintf(caLabel,"/bin/cp %s%s/right-top-d.jpg  %s",_msahtmldir,_weblineplt,caTempDir);

    system(caLabel);

    sprintf(caLabel,"/bin/cp %s%s/right-top.jpg  %s",_msahtmldir,_weblineplt,caTempDir);

    system(caLabel);

    sprintf(caLabel,"/bin/cp %s%s/banner.jpg  %s",_msahtmldir,_weblineplt,caTempDir);

    system(caLabel);

    sprintf(caLabel,"/bin/cp %s%s/up-1.jpg  %s",_msahtmldir,_weblineplt,caTempDir);

    system(caLabel);

    sprintf(caLabel,"/bin/cp %s%s/up-2.jpg  %s",_msahtmldir,_weblineplt,caTempDir);

    system(caLabel);

    sprintf(caLabel,"/bin/cp %s%s/up-3.jpg  %s",_msahtmldir,_weblineplt,caTempDir);

    system(caLabel);



    ltMsgPk->msgpktype=1;

    lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,responseDir);

    nasTimeGetDate(caSdate1,lTime1);

    nasTimeGetDate(caSdate2,lTime2);

    if(step==1) {									//网址分类排序

        sprintf(sqlBuf,"select urlsort,sum(bytes) as abyte  from msahttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by urlsort order by abyte desc ",caSdate1,caSdate2,work);

    } else if(step==2) {						//网址流量排序

        sprintf(sqlBuf,"select host,sum(bytes) as abyte,sum(lcount) as acount,sum(ctime) as ctime from msauserhttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by host order by abyte asc",caSdate1,caSdate2,work);

    } else if(step==3) {						//top30流量人员网址访问

        sprintf(sqlBuf,"select host,sum(bytes) as abyte,sum(lcount) as acount,sum(ctime) as ctime from msauserhttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by host order by abyte asc limit %d offset 0",caSdate1,caSdate2,work,30);

    } else if(step==4) {						//网址访问次数排序

        sprintf(sqlBuf,"select host,sum(bytes) as abyte,sum(lcount) as acount,sum(ctime) as ctime from msahttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by host order by acount desc",caSdate1,caSdate2,work);

    } else if(step==5) {						//网址分类访问次数排序

        sprintf(sqlBuf,"select urlsort,sum(bytes) as abyte,sum(lcount) as acount  from msahttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by urlsort order by acount desc ",caSdate1,caSdate2,work);

    }

    printf("sql:%s\n",sqlBuf);

    tempCursor = ltDbOpenCursor(G_DbCon,sqlBuf);

    if(tempCursor == NULL) {

        sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","数据库错误,无法生成报告",caTempDir);

        system(caLabel);

        ltMsgFree(ltMsgPk);

        return 0;

    }



    srvindex=1;

    lMaxBytes=1;

    dbPtr=lt_dbinit();

    lt_db_htmlpage(dbPtr,"utf-8");

    tablePtr=lt_dbput_table(dbPtr,"list");

    tempRow= ltDbFetchRow(tempCursor);

    while(tempRow!=NULL) {

        if(step==1) {

            if(atoll(tempRow[1])>1024000) {

                sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00);

            } else {

                sprintf(strdayflow,"%0.3fKB",atoll(tempRow[1])/1024.00);

            }

            lt_dbput_recordvars(tablePtr,2,

                                "urlsort",LT_TYPE_STRING,_ltPubInfo->ltService[atol(tempRow[0])].srvName,

                                "lbyte",LT_TYPE_STRING,strdayflow

                               );

            printf("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n");

        } else if(step==2) {

            if(atoll(tempRow[1])>1024000) {

                sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00);

            } else {

                sprintf(strdayflow,"%0.3fKB",atoll(tempRow[1])/1024.00);

            }

            lt_dbput_recordvars(tablePtr,2,

                                "host",LT_TYPE_STRING,tempRow[0],

                                "lbyte",LT_TYPE_STRING,strdayflow

                               );

        } else if(step==3) {

            if(atoll(tempRow[1])>1024000) {

                sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00);

            } else {

                sprintf(strdayflow,"%0.3fK",atoll(tempRow[1])/1024.00);

            }

//						if(lMaxBytes<atoll(tempRow[1])){

//		         		lMaxBytes=atoll(tempRow[1]);

//		        }



            lt_dbput_recordvars(tablePtr,4,

                                "host",LT_TYPE_STRING,tempRow[0],

                                "srvljflow",LT_TYPE_STRING,strdayflow,

                                "srvlcount",LT_TYPE_STRING,tempRow[2],

                                "srvljtime",LT_TYPE_STRING,time2str(atoi(tempRow[3]))

                               );

        } else if(step==4) {

            if(atoll(tempRow[1])>1024000) {

                sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00);

            } else {

                sprintf(strdayflow,"%0.3fK",atoll(tempRow[1])/1024.00);

            }

            if(lMaxBytes<atoll(tempRow[1])) {

                lMaxBytes=atoll(tempRow[1]);

            }



            lt_dbput_recordvars(tablePtr,4,

                                "host",LT_TYPE_STRING,tempRow[0],

                                "srvljflow",LT_TYPE_STRING,strdayflow,

                                "srvlcount",LT_TYPE_STRING,tempRow[2],

                                "srvljtime",LT_TYPE_STRING,time2str(atoi(tempRow[3]))

                               );

        } else if(step==5) {

            if(atoll(tempRow[1])>1024000) {

                sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00);

            } else {

                sprintf(strdayflow,"%0.3fK",atoll(tempRow[1])/1024.00);

            }

            if(lMaxBytes<atoll(tempRow[1])) {

                lMaxBytes=atoll(tempRow[1]);

            }

            lt_dbput_recordvars(tablePtr,3,

                                "sorname",LT_TYPE_STRING,_ltPubInfo->ltService[atol(tempRow[0])].srvName,

                                "srvljflow",LT_TYPE_STRING,strdayflow,

                                "srvlcount",LT_TYPE_STRING,tempRow[2]

                               );

        }

        if(step==1) {

            srvindex++;

        }

        tempRow=ltDbFetchRow(tempCursor);//移动光标

    }

    ltDbCloseCursor(tempCursor);

//    if(step==1){//画图

//			  close(iFd);

//			  sprintf(caLabel,"%s/Scripts/onlinesrv-bar.pl  %sdata.ini %ssrvreport.gif %llu ",_msahtmldir,caTempDir,caTempDir,lMaxBytes);  //柱状 饼图:onlinesrv1.pl

//			  system(caLabel);

//			  lt_dbput_rootvars(dbPtr,1,"piechart","srvreport.gif" );

//	  }

    lt_dbput_rootvars(dbPtr,3,"reportname",reportname,"bdate",caSdate1,"edate",caSdate2);

    sprintf(htmlpage,"%s%s/webflow%d.htm",_msahtmldir,_weblineplt,step);

    printf("%s\n",htmlpage);

    lt_page_content=ltPltFileParse(htmlpage,dbPtr->doc,0);

    if(lt_page_content==NULL) {

        printf("11111111111111111111111111\n");

        sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","无报告数据,无法生成报告",caTempDir);

        system(caLabel);/*建立目录和正在处理标志*/

        ltMsgFree(ltMsgPk);

        lt_dbfree(dbPtr);

        return 0;

    } else {

        printf("22222222222222222222222222\n");

        lt_page_content=strstr(lt_page_content,"<!DOCTYPE");

        if(step==1) {

            sprintf(caLabel,"%sindex.htm",caTempDir);

        } else {

            sprintf(caLabel,"%spage%d.htm",caTempDir,step);

        }

        iFd = open(caLabel,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644);

        if(iFd >0) {

            write(iFd,lt_page_content,strlen(lt_page_content));

        }

        close(iFd);

    }



    if(step==5) {

        sprintf(caLabel,"%s/Scripts/html2mail  %s index.htm %sindex.mht report %s",_msahtmldir,caTempDir,caTempDir,email);

        system(caLabel);

    }

    chdir(caTempDir);

    system("rm -f report.tgz");

    system("tar -cvzf report.tgz *");

    sprintf(caLabel,"/bin/rm  %sproccess.ini",caTempDir);

    system(caLabel);

    sprintf(caLabel,"/bin/rm  %serrmsg.ini",caTempDir);

    system(caLabel);

    ltMsgFree(ltMsgPk);

    lt_dbfree(dbPtr);

    return 0;

}
Example #6
0
int msaReportUserLineAjaxSubmit(int confd,ltMsgHead *ltMsgPk,lt_shmHead *lt_MMHead)
{	
		printf("msaReportUserLineAjaxSubmit.................................\n");
    ltDbCursor  *tempCursor;
    LT_DBROW    tempRow;
    ltDbHeadPtr dbPtr;
    ltTablePtr  tablePtr;
    
    char sqlBuf[1024];    
    char caSdate[32],caEdate[32],caSdate1[32],caSdate2[32];
		char *reportname=NULL;
		char *email=NULL;
		char *step=NULL;
		long gid=-1,uid=-1;
		char *lt_page_content=NULL;
		char caTempDir[256]; 
		char responseDir[256]; 
    char caLabel[256];
    char strdayflow[32];
    unsigned long long lMaxBytes=1;
    unsigned long tmpDir=0;
    unsigned long fileName=0;
		
    long lTime,lTime1,lTime2; 
    int  iFd=-1;
    int  srvindex;
    
    
     //连接数据库
  	char *dbUser;
	  char *dbPass;
	  char *dbName;
	  dbName=_ltPubInfo->_dbname;
		dbUser=_ltPubInfo->_dbuser;
		dbPass=_ltPubInfo->_dbpass;
		G_DbCon=ltDbConnect(dbUser,dbPass,dbName);
		if(G_DbCon!=NULL){
			printf("db connect ok\n");
		}else{
			fprintf(stderr,"db connect error\n");
		}
    
    

	  /***************************ajax参数********************/
		if(ltMsgGetVar_s(ltMsgPk,"sdate")){
	  	sprintf(caSdate,"%s",ltMsgGetVar_s(ltMsgPk,"sdate"));
	  }else{
	  	sprintf(caSdate,"%s","");
	  }
printf("caSdate:%s\n",caSdate);
	  
	  if(ltMsgGetVar_s(ltMsgPk,"edate")){
	  	 sprintf(caEdate,"%s",ltMsgGetVar_s(ltMsgPk,"edate"));
	  }else{
	  	 sprintf(caEdate,"%s","");
	  }
printf("caEdate:%s\n",caEdate);
		
		if(ltMsgGetVar_s(ltMsgPk,"reportname")){	
	  	reportname=ltMsgGetVar_s(ltMsgPk,"reportname");
	  }
printf("reportname:%s\n",reportname);
	  
	  if(ltMsgGetVar_s(ltMsgPk,"email")){
	  	email=ltMsgGetVar_s(ltMsgPk,"email");
	  }
printf("email:%s\n",email);
	  
	  if(ltMsgGetVar_s(ltMsgPk,"step")){
	  	step=ltMsgGetVar_s(ltMsgPk,"step");
	  }
printf("step:%s\n",step);
    
    if(ltMsgGetVar_s(ltMsgPk,"gid")){
	  	gid=atol(ltMsgGetVar_s(ltMsgPk,"gid"));
	  }
printf("gid:%ld\n",gid);

	  if(ltMsgGetVar_s(ltMsgPk,"uid")&&atol(ltMsgGetVar_s(ltMsgPk,"uid"))!=0){
	  	uid=atol(ltMsgGetVar_s(ltMsgPk,"uid"));
	  }else{
	  	uid=-1;
	  }
printf("uid:%ld\n",uid);
    
	  if(ltMsgGetVar_s(ltMsgPk,"filedir")){	  
	  	fileName=atoll(ltMsgGetVar_s(ltMsgPk,"filedir"));
	  }else{
	  	fileName=0;
	  }
printf("fileName:%ld\n",fileName);    
    
    /****************目录生成************************/
    if(fileName==0){
		    tmpDir=ltStrGetId();
		    sprintf(caTempDir,"%s/%lu/",userreportdatacenterdir,tmpDir);
		    sprintf(responseDir,"%lu",tmpDir);	
		    if(ltFileIsExist(caTempDir)!=1){
		       if(mkdir(caTempDir,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)!=0) {
				      ltMsgPk->msgpktype=1;
							lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0");		
							ltMsgFree(ltMsgPk);
			        return 0;
       		 }
    		} 
     }else{//从第二步开始传进第一步生成的目录
    	  sprintf(caTempDir,"%s/%lu/",userreportdatacenterdir,fileName);   
    	  sprintf(responseDir,"%lu",fileName);
     } 


    /***********************日期处理*****************/
    lTime = time(0);
    if(!ltStrIsSpaces(caSdate)){
        lTime1 = nasCvtLongTime(caSdate,"00:00:00");
    }else{
        lTime1 = 0;
    } 
    if(!ltStrIsSpaces(caEdate)) {
        lTime2 = nasCvtLongTime(caEdate,"23:59:59");
    }else{
        lTime2 = 0;
    } 
    
    if(lTime1 == 0) {
         lTime1 = lTime;       
    }
	  if(lTime2 == 0) {
         lTime2 = lTime;
    }
	  if(lTime1 > lTime) {
         lTime1 = lTime;
    }
    if(lTime2>lTime){
		 		 lTime2=lTime;
	  }
	  
	  
	  /******************************拷贝模板报告文件*************************/
	  char sDate[64],sTime[64];
	  char caFile1[256];   
    char caCmd[256];
    int  fdwrite=0;
    nasTimeGetDate(caSdate1,lTime);
    nasCvtStime(time(0),sDate,sTime); 
    sprintf(caFile1,"%sinfo.ini",caTempDir);     
    fdwrite = open(caFile1, O_APPEND | O_WRONLY | O_CREAT, 0644);
		if(fdwrite == (-1)) {
			 ltMsgPk->msgpktype=1;
			 lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0");		
			 ltMsgFree(ltMsgPk);
			 return 0;
		}
		
		sprintf(caCmd,"date=%s_%s\n",sDate,sTime);
	  write(fdwrite,caCmd,strlen(caCmd));
	  sprintf(caCmd,"reportname=%s\n",reportname);
	  write(fdwrite,caCmd,strlen(caCmd));
	  close(fdwrite);
    sprintf(caLabel,"/bin/echo '1' > %sproccess.ini",caTempDir);
    system(caLabel);
	  sprintf(caLabel,"/bin/cp %s/right-top-d.jpg  %s",userlineplt,caTempDir);
    system(caLabel);
    sprintf(caLabel,"/bin/cp %s/right-top.jpg  %s",userlineplt,caTempDir);
    system(caLabel);
	  sprintf(caLabel,"/bin/cp %s/banner.jpg  %s",userlineplt,caTempDir);
    system(caLabel);
	  sprintf(caLabel,"/bin/cp %s/up-1.jpg  %s",userlineplt,caTempDir);
    system(caLabel);
	  sprintf(caLabel,"/bin/cp %s/up-2.jpg  %s",userlineplt,caTempDir);
    system(caLabel);
  	sprintf(caLabel,"/bin/cp %s/up-3.jpg  %s",userlineplt,caTempDir);
    system(caLabel);
    
    ltMsgPk->msgpktype=1;
	  lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,responseDir);		
    
    
    /*************************数据库操作***************************************/  
    nasTimeGetDate(caSdate1,lTime1);
    nasTimeGetDate(caSdate2,lTime2);
    if(atoi(step)==1){//根据时间段生成服务协议分析流量汇总报表
      sprintf(sqlBuf,"select service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 group by service order by service,abyte asc",caSdate1,caSdate2); 
printf("sqlBufno.1: %s\n",sqlBuf);
    }else if(atoi(step)==2){
    	  if(uid!=-1&&gid!=-1){
    	  	sprintf(sqlBuf,"select c.name,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld and b.userid=%ld group by c.name,service order by c.name",caSdate1,caSdate2,gid,uid); 
    	  }else if(uid==-1&&gid!=-1){
    	    sprintf(sqlBuf,"select c.name,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld group by c.name,service order by c.name",caSdate1,caSdate2,gid);    
    	  }else{
    	    sprintf(sqlBuf,"select c.name,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 group by c.name,service order by c.name",caSdate1,caSdate2);    
    	  }
printf("sqlBufno.2: %s\n",sqlBuf);
    }else if(atoi(step)==3){
    	  if(uid!=-1&&gid!=-1){
    	  	  sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld and b.userid=%ld group by c.name,b.dispname,service order by c.name,b.dispname,abyte asc",caSdate1,caSdate2,gid,uid); 
    	  }else if(uid==-1&&gid!=-1){
	    	  	sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld group by c.name,b.dispname,service order by c.name,b.dispname,abyte asc",caSdate1,caSdate2,gid);
	    	}else{
	    	  	sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 group by c.name,b.dispname,service order by c.name,b.dispname,abyte asc",caSdate1,caSdate2);
	    	}
printf("sqlBufno.3: %s\n",sqlBuf);
    }else if(atoi(step)==4){
    	  if(uid!=-1){
    	  	  sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte,onlinetime from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld and b.userid=%ld group by c.name,b.dispname,service,onlinetime order by c.name,b.dispname,onlinetime asc",caSdate1,caSdate2,gid,uid); 
    	  }else if(uid==-1&&gid!=-1){
    	  		sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte,onlinetime from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld group by c.name,b.dispname,service,onlinetime order by c.name,b.dispname,onlinetime asc",caSdate1,caSdate2,gid);
    	  }else{
    	  		sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte,onlinetime from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 group by c.name,b.dispname,service,onlinetime order by c.name,b.dispname,onlinetime asc",caSdate1,caSdate2);
    	  }
printf("sqlBufno.4: %s\n",sqlBuf);
    }else if(atoi(step)==5){
    	  if(uid!=-1){
    	  	  sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte,onlinetime from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld and b.userid=%ld group by c.name,b.dispname,service,onlinetime order by abyte desc limit 30",caSdate1,caSdate2,gid,uid); 
    	  }else if(uid==-1&&gid!=-1){
    	 		  sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte,onlinetime from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld group by c.name,b.dispname,service,onlinetime order by abyte,c.name desc limit 30",caSdate1,caSdate2,gid);
    		}else{
    	 		  sprintf(sqlBuf,"select c.name,b.dispname,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte,onlinetime from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 group by c.name,b.dispname,service,onlinetime order by abyte,c.name desc limit 30",caSdate1,caSdate2);
    		}
printf("sqlBufno.5: %s\n",sqlBuf);
    }else if(atoi(step)==6){
    	  if(uid!=-1){
    	  	  sprintf(sqlBuf,"select c.name,b.dispname,a.host,d.url,sum(ctime) as arequest from msauserhttpreport a,msauser b,msaGroup c,nasurls d where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and c.id=b.groupid0 and b.userid=a.userid and a.urlsort=d.urlsort and c.id=%ld and b.userid=%ld group by c.name,b.dispname,d.url,a.bytes,host order by c.name,arequest desc limit 30",caSdate1,caSdate2,gid,uid); 
    	  }else if(uid==-1&&gid!=-1){
    	      sprintf(sqlBuf,"select c.name,b.dispname,a.host,d.url,sum(ctime) as arequest from msauserhttpreport a,msauser b,msaGroup c,nasurls d where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and c.id=b.groupid0 and b.userid=a.userid and a.urlsort=d.urlsort and c.id=%ld group by c.name,b.dispname,d.url,a.bytes,host order by c.name,arequest desc limit 30",caSdate1,caSdate2,gid);
    	  }else{
    	      sprintf(sqlBuf,"select c.name,b.dispname,a.host,d.url,sum(ctime) as arequest from msauserhttpreport a,msauser b,msaGroup c,nasurls d where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and c.id=b.groupid0 and b.userid=a.userid and a.urlsort=d.urlsort group by c.name,b.dispname,d.url,a.bytes,host order by c.name,arequest desc limit 30",caSdate1,caSdate2);
    	      								
    	  }
printf("sqlBufno.6: %s\n",sqlBuf);
    }else if(atoi(step)==7){
    	  if(uid!=-1){
    	  	  sprintf(sqlBuf,"select sdate,c.name,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld and b.userid=%ld group by c.name,service,sdate order by sdate",caSdate1,caSdate2,gid,uid); 
    	  }else if(uid==-1&&gid!=-1){
    	 		  sprintf(sqlBuf,"select sdate,c.name,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 and c.id=%ld group by c.name,service,sdate order by sdate",caSdate1,caSdate2,gid);
    	 	}else{
    	 		  sprintf(sqlBuf,"select sdate,c.name,service,sum(ctime) as arequest,sum(ubytes+dbytes) as abyte from msasrvreport a,msauser b,msaGroup c where substring(sdate,3,8)>='%s' and substring(sdate,3,8)<='%s' and a.userid=b.userid and c.id=b.groupid0 group by c.name,service,sdate order by sdate",caSdate1,caSdate2);
    	 	}
printf("sqlBufno.7: %s\n",sqlBuf);
    }
    tempCursor = ltDbOpenCursor(G_DbCon,sqlBuf);
	  if(tempCursor == NULL){
		      sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","数据库错误,无法生成报告",caTempDir); 
	    	  system(caLabel);
	    	  ltMsgFree(ltMsgPk); 
	        return 0;
	  }
	  
	  /************图片数据存储文件****************/
	  if(atoi(step)==1){
		   sprintf(caLabel,"%sdata.ini",caTempDir);
	      iFd = open(caLabel,O_WRONLY | O_CREAT | O_TRUNC);
		    if(iFd == (-1)){
						sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","无法建立数据文件",caTempDir);
			    	system(caLabel);/*建立目录和正在处理标志*/
			      ltDbCloseCursor(tempCursor);
			      ltMsgFree(ltMsgPk);
			      return 0;
			}							
	  }
	  
	  /**********************将数据显示的HTML页面*********************************/
	  srvindex=1;
	  lMaxBytes=1;
    dbPtr=lt_dbinit();
    lt_db_htmlpage(dbPtr,"utf-8");
    tablePtr=lt_dbput_table(dbPtr,"list");
	  tempRow= ltDbFetchRow(tempCursor);
	  while(tempRow!=NULL){	      			
				/**********************模板化参数****************************************/    
					if(atoi(step)==1){
						 /***********流量单位转化*****************/
					  if(atoll(tempRow[2])>1024000){
					      sprintf(strdayflow,"%0.3fM",atoll(tempRow[2])/1024000.00);
					  }else{
					      sprintf(strdayflow,"%0.3fK",atoll(tempRow[2])/1024.00);
					  }
					  sprintf(caLabel,"%d,%lld\r\n",srvindex,atoll(tempRow[2]));
	          write(iFd, caLabel, strlen(caLabel));
					  
					  if(lMaxBytes<atoll(tempRow[2])){
		         		lMaxBytes=atoll(tempRow[2]);
		        }	
		        
						lt_dbput_recordvars(tablePtr,3,
							"srvname",LT_TYPE_STRING,_ltPubInfo->topSrvName[atol(tempRow[0])].srvname,  
			   			"srvljnum",LT_TYPE_STRING,tempRow[1],
			   			"srvljflow",LT_TYPE_STRING,strdayflow
		   		  ); 
					}else if(atoi(step)==2){
						/***********流量单位转化*****************/
					  if(atoll(tempRow[3])>1024000){
					      sprintf(strdayflow,"%0.3fM",atoll(tempRow[3])/1024000.00);
					  }else{
					      sprintf(strdayflow,"%0.3fK",atoll(tempRow[3])/1024.00);
					  }
						
						if(lMaxBytes<atoll(tempRow[3])){
		         		lMaxBytes=atoll(tempRow[3]);
		        }	
						
						lt_dbput_recordvars(tablePtr,4,
						  "srvgname",LT_TYPE_STRING,tempRow[0],
							"srvname",LT_TYPE_STRING,_ltPubInfo->topSrvName[atol(tempRow[1])].srvname,  
			   			"srvljnum",LT_TYPE_STRING,tempRow[2],
			   			"srvljflow",LT_TYPE_STRING,strdayflow
		   		  );
					}else if(atoi(step)==3){
						/***********流量单位转化*****************/
					  if(atoll(tempRow[4])>1024000){
					      sprintf(strdayflow,"%0.3fM",atoll(tempRow[4])/1024000.00);
					  }else{
					      sprintf(strdayflow,"%0.3fK",atoll(tempRow[4])/1024.00);
					  }
					  
						if(lMaxBytes<atoll(tempRow[4])){
		         		lMaxBytes=atoll(tempRow[4]);
		        }
		        
						lt_dbput_recordvars(tablePtr,5,
						  "srvgname",LT_TYPE_STRING,tempRow[0],
						  "srvuname",LT_TYPE_STRING,tempRow[1],
							"srvname",LT_TYPE_STRING,_ltPubInfo->topSrvName[atol(tempRow[2])].srvname,  
			   			"srvljnum",LT_TYPE_STRING,tempRow[3],
			   			"srvljflow",LT_TYPE_STRING,strdayflow
		   		  );
					}else if(atoi(step)==4){
						/***********流量单位转化*****************/
					  if(atoll(tempRow[4])>1024000){
					      sprintf(strdayflow,"%0.3fM",atoll(tempRow[4])/1024000.00);
					  }else{
					      sprintf(strdayflow,"%0.3fK",atoll(tempRow[4])/1024.00);
					  }
					  
						if(lMaxBytes<atoll(tempRow[4])){
		         		lMaxBytes=atoll(tempRow[4]);
		        }
		        
						lt_dbput_recordvars(tablePtr,6,
						  "srvgname",LT_TYPE_STRING,tempRow[0],
						  "srvuname",LT_TYPE_STRING,tempRow[1],
							"srvname",LT_TYPE_STRING,_ltPubInfo->topSrvName[atol(tempRow[2])].srvname,  
			   			"srvljnum",LT_TYPE_STRING,tempRow[3],
			   			"srvljflow",LT_TYPE_STRING,strdayflow,
			   			"srvonlinetime",LT_TYPE_STRING,tempRow[5]
		   		  );
					}else if(atoi(step)==5){
						/***********流量单位转化*****************/
					  if(atoll(tempRow[4])>1024000){
					      sprintf(strdayflow,"%0.3fM",atoll(tempRow[4])/1024000.00);
					  }else{
					      sprintf(strdayflow,"%0.3fK",atoll(tempRow[4])/1024.00);
					  }
					  
						if(lMaxBytes<atoll(tempRow[4])){
		         		lMaxBytes=atoll(tempRow[4]);
		        }
		        
						lt_dbput_recordvars(tablePtr,6,
						  "srvgname",LT_TYPE_STRING,tempRow[0],
						  "srvuname",LT_TYPE_STRING,tempRow[1],
							"srvname",LT_TYPE_STRING,_ltPubInfo->topSrvName[atol(tempRow[2])].srvname,  
			   			"srvljnum",LT_TYPE_STRING,tempRow[3],
			   			"srvljflow",LT_TYPE_STRING,strdayflow,
			   			"srvonlinetime",LT_TYPE_STRING,tempRow[5]
		   		  );
					}else if(atoi(step)==6){
						lt_dbput_recordvars(tablePtr,5,
						  "srvgname",LT_TYPE_STRING,tempRow[0],
						  "srvuname",LT_TYPE_STRING,tempRow[1],
							"srvnetname",LT_TYPE_STRING,tempRow[2],  
			   			"srvurlname",LT_TYPE_STRING,tempRow[3], 
			   			"srvljnum",LT_TYPE_STRING,tempRow[4]
		   		  );
		      }else if(atoi(step)==7){
						/***********流量单位转化*****************/
					  if(atoll(tempRow[4])>1024000){
					      sprintf(strdayflow,"%0.3fM",atoll(tempRow[4])/1024000.00);
					  }else{
					      sprintf(strdayflow,"%0.3fK",atoll(tempRow[4])/1024.00);
					  }
					  
						if(lMaxBytes<atoll(tempRow[4])){
		         		lMaxBytes=atoll(tempRow[4]);
		        }
		        
						lt_dbput_recordvars(tablePtr,5,
						  "srvsdate",LT_TYPE_STRING,tempRow[0],
						  "srvgname",LT_TYPE_STRING,tempRow[1],
							"srvname",LT_TYPE_STRING,_ltPubInfo->topSrvName[atol(tempRow[2])].srvname,  
			   			"srvljnum",LT_TYPE_STRING,tempRow[3],
			   			"srvljflow",LT_TYPE_STRING,strdayflow
		   		  );
		      }
	   			if(atoi(step)==1){
	          	srvindex++;
	        }
        tempRow=ltDbFetchRow(tempCursor);//移动光标
    }
    ltDbCloseCursor(tempCursor);

    if(atoi(step)==1){//画图
			  close(iFd);	 
			  sprintf(caLabel,"/app/msa/msa/htmlplt/Scripts/onlinesrv-bar.pl  %sdata.ini %ssrvreport.gif %llu ",caTempDir,caTempDir,lMaxBytes);  //柱状 饼图:onlinesrv1.pl
			  system(caLabel);	
			  lt_dbput_rootvars(dbPtr,1,"piechart","srvreport.gif" );
	  } 
	  
	  lt_dbput_rootvars(dbPtr,3,"reportname",reportname,"bdate",caSdate1,"edate",caSdate2);
	  if(atoi(step)==1){
	    lt_page_content=ltPltFileParse("/app/msa/msa/htmlplt/reportplt/userlineplt/userflow.htm",dbPtr->doc,0);
	  }else if(atoi(step)==2){
			lt_page_content=ltPltFileParse("/app/msa/msa/htmlplt/reportplt/userlineplt/userflow2.htm",dbPtr->doc,0);
	  }else if(atoi(step)==3){
			lt_page_content=ltPltFileParse("/app/msa/msa/htmlplt/reportplt/userlineplt/userflow3.htm",dbPtr->doc,0);
	  }else if(atoi(step)==4){
			lt_page_content=ltPltFileParse("/app/msa/msa/htmlplt/reportplt/userlineplt/userflow4.htm",dbPtr->doc,0);
	  }else if(atoi(step)==5){
			lt_page_content=ltPltFileParse("/app/msa/msa/htmlplt/reportplt/userlineplt/userflow5.htm",dbPtr->doc,0);
	  }else if(atoi(step)==6){
			lt_page_content=ltPltFileParse("/app/msa/msa/htmlplt/reportplt/userlineplt/userflow6.htm",dbPtr->doc,0);
	  }else if(atoi(step)==7){
			lt_page_content=ltPltFileParse("/app/msa/msa/htmlplt/reportplt/userlineplt/userflow7.htm",dbPtr->doc,0);
	  }

	  if(lt_page_content==NULL){
		    sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","无报告数据,无法生成报告",caTempDir);
	  		system(caLabel);/*建立目录和正在处理标志*/
	  		ltMsgFree(ltMsgPk);
	  		lt_dbfree(dbPtr);
     		return 0;
		}else{
			  lt_page_content=strstr(lt_page_content,"<!DOCTYPE");
			  if(atoi(step)==1){
			  	sprintf(caLabel,"%sindex.htm",caTempDir);
			  }else if(atoi(step)==2){
			  	sprintf(caLabel,"%spage2.htm",caTempDir);
			  }else if(atoi(step)==3){
			  	sprintf(caLabel,"%spage3.htm",caTempDir);
			  }else if(atoi(step)==4){
			  	sprintf(caLabel,"%spage4.htm",caTempDir);
			  }else if(atoi(step)==5){
			  	sprintf(caLabel,"%spage5.htm",caTempDir);
			  }else if(atoi(step)==6){
			  	sprintf(caLabel,"%spage6.htm",caTempDir);
			  }else{
			  	sprintf(caLabel,"%spage7.htm",caTempDir);
			  }			  
			  iFd = open(caLabel,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); 
		    if(iFd >0) {
		          write(iFd,lt_page_content,strlen(lt_page_content));
		    }
	    	close(iFd);
	  }
   	
    if(atoi(step)==7){
	    sprintf(caLabel,"/app/msa/msa/htmlplt/Scripts/html2mail  %s index.htm %sindex.mht report %s",caTempDir,caTempDir,email);
	    system(caLabel);
    }
    
    chdir(caTempDir);
	  system("rm -f report.tgz"); 
	  system("tar -cvzf report.tgz *");  
	  sprintf(caLabel,"/bin/rm  %sproccess.ini",caTempDir);
	  system(caLabel);    
	  sprintf(caLabel,"/bin/rm  %serrmsg.ini",caTempDir);
	  system(caLabel);   

	  ltMsgFree(ltMsgPk);
	  lt_dbfree(dbPtr);
	  
printf("caTempDir:::::::::%s\n",caTempDir);///datacenter/msa/report/weblinereport/71540000/
printf("responseDir:::::::::%s\n",responseDir);///datacenter/msa/report/weblinereport/71540000/
		//把web主线生成的报告备份到手动生成报告列表
		//system("cp -r -f /datacenter/msa/report/userlinereport/* /datacenter/msa/report/instantreport/");
    return 0;

}
Example #7
0
int msaReportFlowLineAjaxSubmit(int confd,ltMsgHead *ltMsgPk,lt_shmHead *lt_MMHead)
{	
    ltDbCursor  *tempCursor;
    LT_DBROW    tempRow;
    ltDbHeadPtr dbPtr;
    ltTablePtr  tablePtr;   
    stralloc strTemp;  
    char        caSdate[32],caEdate[32],caSdate1[32],caSdate2[32];
		char        *reportname=NULL;
		char        *email=NULL;
		char        *lt_page_content=NULL;
		char        *gid=NULL;
		char        *work=NULL;
		char        caTempDir[256];  
		char        responseDir[256];
    char        caLabel[256];
    char        htmlpage[256];
    char        sqlBuf[1024]; 
    char        strdayflow[32];
    char        sDate[64],sTime[64];
	  char        caFile1[256];   
    char        caCmd[256];   
    char        atime[64];
    char        srvName[255];
    char 				caTmpp[2048];
    char 				flow[128];
   	long        lTime,lTime1,lTime2;
    int         iFd,srvindex,gindex,fdwrite,step,jjj;
    unsigned long long lMaxBytes;
    unsigned long tmpDir=0;
    unsigned long fileName=0;    
    step=0;
    strTemp.s=0;
	  jjj=0;
    memset(caTempDir,0,sizeof(caTempDir));
    memset(responseDir,0,sizeof(responseDir));
    memset(caLabel,0,sizeof(caLabel));
    memset(htmlpage,0,sizeof(htmlpage));
    memset(sqlBuf,0,sizeof(sqlBuf));
    memset(atime,0,sizeof(atime));
    memset(srvName,0,sizeof(srvName));
   	memset(caTmpp,0,sizeof(caTmpp));
   	memset(flow,0,sizeof(flow));

  	char *dbUser;
	  char *dbPass;
	  char *dbName;
	  dbName=_ltPubInfo->_dbname;
		dbUser=_ltPubInfo->_dbuser;
		dbPass=_ltPubInfo->_dbpass;
		G_DbCon=ltDbConnect(dbUser,dbPass,dbName);
		if(G_DbCon==NULL){
			return 0;
		}
		if(ltMsgGetVar_s(ltMsgPk,"sdate")){
	  	sprintf(caSdate,"%s",ltMsgGetVar_s(ltMsgPk,"sdate"));
	  }else{
	  	sprintf(caSdate,"%s","");
	  }
	  if(ltMsgGetVar_s(ltMsgPk,"edate")){
	  	 sprintf(caEdate,"%s",ltMsgGetVar_s(ltMsgPk,"edate"));
	  }else{
	  	 sprintf(caEdate,"%s","");
	  }
		if(ltMsgGetVar_s(ltMsgPk,"reportname")){		
	  	reportname=ltMsgGetVar_s(ltMsgPk,"reportname");
	  }
	  if(ltMsgGetVar_s(ltMsgPk,"email")){
	  	email=ltMsgGetVar_s(ltMsgPk,"email");
	  }
	  if(ltMsgGetVar_s(ltMsgPk,"step")){
	  	step=atoi(ltMsgGetVar_s(ltMsgPk,"step"));
	  }
    if(ltMsgGetVar_s(ltMsgPk,"gid")){
	  	gid=ltMsgGetVar_s(ltMsgPk,"gid");
	  		sprintf(caTmpp,"%s","");
				stralloc_cats(&strTemp,caTmpp);		
				int i;					
				for(i=0;i<1000;i++){
					if(gid[i]=='1'){
							jjj++;
						  if(jjj==1){
								sprintf(caTmpp,"%d",i); 
				        stralloc_cats(&strTemp,caTmpp);			
		          }else{
		            sprintf(caTmpp,",%d",i);  
				        stralloc_cats(&strTemp,caTmpp);				
		          }  					
					}	
				}
				stralloc_cats(&strTemp,"");
				stralloc_0(&strTemp); 
	  }
	  if(ltMsgGetVar_s(ltMsgPk,"filedir")){	  
	  	fileName=atoll(ltMsgGetVar_s(ltMsgPk,"filedir"));
	  }
		 if(ltMsgGetVar_s(ltMsgPk,"work")){	  
	  	work=ltMsgGetVar_s(ltMsgPk,"work");
	  }

    if(fileName==0){
		    tmpDir=ltStrGetId();
		    sprintf(caTempDir,"%s%s/%lu/",_datacenterdir,_flowreport,tmpDir);
		    sprintf(responseDir,"%lu",tmpDir);	  
		    if(ltFileIsExist(caTempDir)!=1) {
		       if(mkdir(caTempDir,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)!=0) {
				      ltMsgPk->msgpktype=1;
							lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0");		
							ltMsgFree(ltMsgPk);
			        return 0;
		       }
		 		}  
    }else{			
    	  sprintf(caTempDir,"%s%s/%lu/",_datacenterdir,_flowreport,fileName);   
    	  sprintf(responseDir,"%lu",fileName);
    }    

    lTime = time(0);
    if(!ltStrIsSpaces(caSdate)) {
        lTime1 = nasCvtLongTime(caSdate,"00:00:00");
    }else{
        lTime1 = 0;
    } 
    if(!ltStrIsSpaces(caEdate)) {
        lTime2 = nasCvtLongTime(caEdate,"23:59:59");
    }else {
        lTime2 = 0;
    }   
    if(lTime1 == 0) {
         lTime1 = lTime;       
    }
	  if(lTime2 == 0) {
         lTime2 = lTime;
    }
	  if(lTime1 > lTime) {
         lTime1 = lTime;
    }
    if(lTime2>lTime){
		 		 lTime2=lTime;
	  }
	  fdwrite=-1;
	  if(step==1){
			  nasCvtStime(time(0),sDate,sTime); 
			  sprintf(caFile1,"%sinfo.ini",caTempDir);     
			  fdwrite = open(caFile1, O_APPEND | O_WRONLY | O_CREAT, 0644);
				if(fdwrite == (-1)) {
					 ltMsgPk->msgpktype=1;
					 lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0");		
					 ltMsgFree(ltMsgPk);
					 return 0;
				}			
				sprintf(caCmd,"date=%s_%s\n",sDate,sTime);
			  write(fdwrite,caCmd,strlen(caCmd));
			  sprintf(caCmd,"reportname=%s\n",reportname);
			  write(fdwrite,caCmd,strlen(caCmd));
			  close(fdwrite);
			  sprintf(caLabel,"/bin/echo '1' > %sproccess.ini",caTempDir);
			  system(caLabel);
			  sprintf(caLabel,"/bin/cp %s%s/right-top-d.jpg  %s",_msahtmldir,_flowlineplt,caTempDir);
			  system(caLabel);
			  sprintf(caLabel,"/bin/cp %s%s/right-top.jpg  %s",_msahtmldir,_flowlineplt,caTempDir);
			  system(caLabel);
			  sprintf(caLabel,"/bin/cp %s%s/banner.jpg  %s",_msahtmldir,_flowlineplt,caTempDir);
			  system(caLabel);
			  sprintf(caLabel,"/bin/cp %s%s/up-1.jpg  %s",_msahtmldir,_flowlineplt,caTempDir);
			  system(caLabel);
			  sprintf(caLabel,"/bin/cp %s%s/up-2.jpg  %s",_msahtmldir,_flowlineplt,caTempDir);
			  system(caLabel);
				sprintf(caLabel,"/bin/cp %s%s/up-3.jpg  %s",_msahtmldir,_flowlineplt,caTempDir);
			  system(caLabel);    
   }

    ltMsgPk->msgpktype=1;
	  lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,responseDir);		      
    nasTimeGetDate(caSdate1,lTime1);
    nasTimeGetDate(caSdate2,lTime2);
    if(step==1){							//服务流量报告
      sprintf(sqlBuf,"select service,sum(onlinetime) as acount,sum(bytes) as abyte from msasrvreport where sdate>='%s' and sdate<='%s' and workflag=%s group by service order by abyte desc ",caSdate1,caSdate2,work); 
    }else if(step==2){				//部门流量排序
    	sprintf(sqlBuf,"select c.name,sum(bytes)   as abyte from msasrvreport a,msauser b ,msagroup c where sdate>='%s' and sdate<='%s' and a.userid=b.userid and b.groupid0=c.id  and c.id in(%s) and workflag=%s group by c.name order by abyte desc",caSdate1,caSdate2,strTemp.s,work);    	      	       
    }else if(step==3){				//人员流量排序
			sprintf(sqlBuf,"select b.dispname,sum(bytes) as abyte from msasrvreport a,msauser b ,msagroup c where sdate>='%s' and sdate<='%s' and a.userid=b.userid and b.groupid0=c.id  and c.id in(%s) and workflag=%s group by b.dispname order by abyte desc",caSdate1,caSdate2,strTemp.s,work);
    }else if(step==4){				//网站流量排序
      sprintf(sqlBuf,"select host,sum(bytes)       as abyte from msauserhttpreport where sdate >= '%s' and sdate <= '%s' group by host order by abyte desc",caSdate1,caSdate2);			   
    }else{										//目的地址流量排序
    	 sprintf(sqlBuf,"select dip,sum(bytes)       as abyte from msaDipReport where sdate >= '%s' and sdate <= '%s' group by dip order by abyte desc ",caSdate1,caSdate2);
    }
	  printf("sql: %s\n",sqlBuf);
	  tempCursor = ltDbOpenCursor(G_DbCon,sqlBuf);
	  if(tempCursor == NULL){
		      sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","数据库错误,无法生成报告",caTempDir); 
	    	  system(caLabel);
	    	  ltMsgFree(ltMsgPk); 
	        return 0;
	  }
		iFd=-1;
	  if(step==1){
		   sprintf(caLabel,"%sdata.ini",caTempDir);
	      iFd = open(caLabel,O_WRONLY | O_CREAT | O_TRUNC);
		    if(iFd == (-1)){
						sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","无法建立数据文件",caTempDir);
			    	system(caLabel);
			      ltDbCloseCursor(tempCursor);
			      ltMsgFree(ltMsgPk);
			      return 0;
			 }							
	  }
	  
	  srvindex=1;
	  lMaxBytes=1;
	  gindex=0;
	  dbPtr=lt_dbinit();
    lt_db_htmlpage(dbPtr,"utf-8");  
    tablePtr=lt_dbput_table(dbPtr,"list"); 
	  tempRow= ltDbFetchRow(tempCursor);   
	  while(tempRow!=NULL){	      	                         	  
					if(step==1){										//服务流量报告
		   		  if(atoll(tempRow[2])>1024000){
					      sprintf(strdayflow,"%0.3fM",atoll(tempRow[2])/1024000.00);
					  }else{
					      sprintf(strdayflow,"%0.3fK",atoll(tempRow[2])/1024.00);
					  }			  
					  sprintf(caLabel,"%d,%lld\r\n",srvindex,atoll(tempRow[2]));
	          write(iFd, caLabel, strlen(caLabel));	
	          if(lMaxBytes<atoll(tempRow[2])){
	 		     		 lMaxBytes=atoll(tempRow[2]);
	          }						  	
				  	sprintf(srvName,"No%d:%s",srvindex,_ltPubInfo->topSrvName[atol(tempRow[0])].srvname);				  
						lt_dbput_recordvars(tablePtr,3,
							"srvname",LT_TYPE_STRING,srvName,  
			   			"srvljtime",LT_TYPE_STRING,tempRow[1],
			   			"srvljflow",LT_TYPE_STRING,strdayflow
		   		  ); 
					}else if(step==2){							//部门流量排序
						if(atoll(tempRow[1])>1024000){
               sprintf(flow,"%0.3fM",atoll(tempRow[1])/1024000.00);
            }else{
               sprintf(flow,"%0.3fKB",atoll(tempRow[1])/1024.00);
            }
             
		  	  	lt_dbput_recordvars(tablePtr,2,
							"groupname",LT_TYPE_STRING,tempRow[0],  
			   			"lbyte",LT_TYPE_STRING,flow
	   		    ); 	

					}else if(step==3){							//人员流量排序
						
						if(atoll(tempRow[1])>1024000){
               sprintf(flow,"%0.3fM",atoll(tempRow[1])/1024000.00);
            }else{
               sprintf(flow,"%0.3fKB",atoll(tempRow[1])/1024.00);
            }
	  	  	  lt_dbput_recordvars(tablePtr,2,
							"uname",LT_TYPE_STRING,tempRow[0],  
			   			"lbyte",LT_TYPE_STRING,flow
	   		    ); 	
		   		  
					}else if(step==4){							//网站流量排序
						if(atoll(tempRow[1])>1024000){
               sprintf(flow,"%0.3fM",atoll(tempRow[1])/1024000.00);
            }else{
               sprintf(flow,"%0.3fKB",atoll(tempRow[1])/1024.00);
            }
	  	  	  lt_dbput_recordvars(tablePtr,2,
							"host",LT_TYPE_STRING,tempRow[0],  
			   			"lbyte",LT_TYPE_STRING,flow
	   		    );
					}else{													//目的地址流量排序
						if(atoll(tempRow[1])>1024000){
               sprintf(flow,"%0.3fM",atoll(tempRow[1])/1024000.00);
            }else{
               sprintf(flow,"%0.3fKB",atoll(tempRow[1])/1024.00);
            }
	  	  	  lt_dbput_recordvars(tablePtr,2,
							"dip",LT_TYPE_STRING,tempRow[0],  
			   			"lbyte",LT_TYPE_STRING,flow
	   		    );
					}

        
	   			if(step==1){
	          	srvindex++;
	        }   			
        tempRow=ltDbFetchRow(tempCursor);
    }
    ltDbCloseCursor(tempCursor);

    if(step==1){											//画图
			  close(iFd);	 
			  sprintf(caLabel,"%s/Scripts/onlinesrv-bar.pl  %sdata.ini %ssrvreport.gif %llu ",_msahtmldir,caTempDir,caTempDir,lMaxBytes);  //柱状 饼图:onlinesrv1.pl
			  system(caLabel);	
			  lt_dbput_rootvars(dbPtr,1,"piechart","srvreport.gif" );
	  } 

	  
	  lt_dbput_rootvars(dbPtr,3,"reportname",reportname,"bdate",caSdate1,"edate",caSdate2);
	  sprintf(htmlpage,"%s%s/flow%d.htm",_msahtmldir,_flowlineplt,step);
	  printf("%s",htmlpage);
	  lt_page_content=ltPltFileParse(htmlpage,dbPtr->doc,0);
	  if(lt_page_content==NULL){
		    sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","无报告数据,无法生成报告",caTempDir);
	  		system(caLabel);
	  		ltMsgFree(ltMsgPk);
	  		lt_dbfree(dbPtr);
     		return 0;
		}else{
			  lt_page_content=strstr(lt_page_content,"<!DOCTYPE");
			  if(step==1){
			  	sprintf(caLabel,"%sindex.htm",caTempDir);
			  }else{
			  	sprintf(caLabel,"%spage%d.htm",caTempDir,step);
			  }		  
			  iFd = open(caLabel,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); 
		    if(iFd >0) {
		          write(iFd,lt_page_content,strlen(lt_page_content));
		    }
	    	close(iFd);
	  }
   	
   	
    if(step==5){
	    sprintf(caLabel,"%s/Scripts/html2mail  %s index.htm %sindex.mht report %s",_msahtmldir,caTempDir,caTempDir,email);
	    system(caLabel);
    }

    
    chdir(caTempDir);
    system("rm -f report.tgz"); 
	  system("tar -cvzf report.tgz *");  	  
	  sprintf(caLabel,"/bin/rm  %sproccess.ini",caTempDir);
	  system(caLabel);    
	  sprintf(caLabel,"/bin/rm  %serrmsg.ini",caTempDir);
	  system(caLabel);   
	  ltMsgFree(ltMsgPk);
	  lt_dbfree(dbPtr);
    return 0;
}