Beispiel #1
0
void HashratSignFile(char *Path, HashratCtx *Ctx)
{
STREAM *S;
char *Tempstr=NULL, *HashStr=NULL;
double pos;
THash *Hash;

S=STREAMOpenFile(Path, SF_RDWR);
if (! S) return;


Hash=HashInit(Ctx->HashType);
HashratFinishHash(&HashStr, Ctx, Hash);
pos=STREAMSeek(S,0,SEEK_END);

Tempstr=MCopyStr(Tempstr,"hashrat-placeholder---: ",GetDateStr("%Y/%m/%d %H:%M:%S",NULL)," ",Ctx->HashType,":", HashStr,"\n",NULL);
STREAMWriteLine(Tempstr,S);
STREAMFlush(S);

STREAMSeek(S,0,SEEK_SET);
Hash=HashInit(Ctx->HashType);
HashratHashFile(Ctx, Hash, FT_FILE, Path, (off_t) pos);
HashratFinishHash(&HashStr, Ctx, Hash);


Tempstr=MCopyStr(Tempstr,"hashrat-integrity-mark: ",GetDateStr("%Y/%m/%d %H:%M:%S",NULL)," ",Ctx->HashType,":", HashStr,"\n",NULL);
STREAMSeek(S,pos,SEEK_SET);
STREAMWriteLine(Tempstr,S);
STREAMFlush(S);


DestroyString(Tempstr);
DestroyString(HashStr);
}
Beispiel #2
0
//---------------------------------------------------------------------------
bool __fastcall TFormClientRep::SetSQL(TDataSet* DSet)
{
	AnsiString SQL, Tail;
	switch (DSet->Tag) {
		case 1:  SQL = "select * from Sel_Orders_Client("  + IntToStr(ClientID) + ",'" +
							GetDateStr(DT_Beg) + "','" + GetDateStr(DT_End) + "')";
					Query1->SQL->Text = SQL;
					break;
	}
	return true;
}
Beispiel #3
0
int SMTPSendMail(const char *Sender, const char *Recipient, const char *Subject, const char *Body, int Flags)
{
    char *Tempstr=NULL;
    STREAM *S;
    int result=FALSE;

    S=SMTPConnect(Sender, Recipient, Flags);
    if (S)
    {
        if (! (Flags & SMTP_NOHEADER))
        {
            Tempstr=MCopyStr(Tempstr,"Date: ", GetDateStr("%a, %d %b %Y %H:%M:%S", NULL), "\r\n", NULL);
            Tempstr=MCatStr(Tempstr,"From: ", Sender, "\r\n", NULL);
            Tempstr=MCatStr(Tempstr,"To: ", Recipient, "\r\n", NULL);
            Tempstr=MCatStr(Tempstr,"Subject: ", Subject, "\r\n\r\n", NULL);
            STREAMWriteLine(Tempstr, S);
        }
        STREAMWriteLine(Body, S);
        STREAMWriteLine("\r\n.\r\n", S);
        SMTPInteract("", S);
        SMTPInteract("QUIT\r\n", S);
        result=TRUE;

        STREAMClose(S);
    }

    DestroyString(Tempstr);
    return(result);
}
Beispiel #4
0
/*****************************************************************
** 功    能:发送信息至监控服务器
** 输入参数:
**     ptReq:      交易信息结构体
**     pszMonIp:   监控端IP地址
**     pszMonPort: 监控端端口号
** 输出参数:
**     无
** 返 回 值:
** 作    者:彭建忠
** 日    期:2013/03/13
** 调用说明:
** 修改日志:
*******************************************************************/
int SendMon(T_TransInfo *ptReq, char *pszMonIp, char *pszMonPort)
{
    int   iLen;
    char  szSendBuf[1024];
    char  szTimeStr[20];

    memset(szTimeStr, 0, sizeof(szTimeStr) );
    GetDateStr(szTimeStr, "%Y%m%d-%T", sizeof(szTimeStr)-1);

    memset(szSendBuf, 0, sizeof(szSendBuf));
    iLen = 0;
    /*
     *  监控内容:0001+流水号(50)、终端序列号(40)、交易类型(4)、交易时间(17)、
     *            区域码(15)、主应用商户号(15)、主应用终端号(8)、结果(2)、
     *		      进度条(3)、错误原因(50)
     */
    sprintf(szSendBuf, "0001%50s%40s%4s%17s%15s%15s%8s%2s000%s%n",
            ptReq->szOnlineId, ptReq->szPinPadSn, ptReq->szTransCode, 
            szTimeStr, ptReq->szRegId, ptReq->szShopNo, ptReq->szPosNo,
            ptReq->szRspCode, ptReq->szMonInfo, &iLen);
    PRINT_LOG(DEBUG_LVL, "===>start to monitor server [%s-%s],[%d] len buf=[%s]",
              pszMonIp, pszMonPort, iLen, szSendBuf);
    SendtoUdpSrv(pszMonIp, pszMonPort, szSendBuf, iLen);

    return 0;
}
Beispiel #5
0
//---------------------------------------------------------------------------
bool __fastcall TFormSummaryRep::SetSQL(TDataSet* DSet)
{
	AnsiString SQL, Tail;
	switch (DSet->Tag) {
		case 1:  SQL = "select * from Sel_Clients_Summary('" + GetDateStr(DT_Beg) +
							"','" + GetDateStr(DT_End+1) + "') order by Flag_Mes, Client_Name";
					Query1->SQL->Text = SQL;
					break;
		case 2:  SQL = "select * from Sel_Transport_Summary('" + GetDateStr(DT_Beg) +
							"','" + GetDateStr(DT_End+1) + "') order by Flag_Mes, Transport_Name";
					Query2->SQL->Text = SQL;
					break;

	}
	return true;
}
Beispiel #6
0
char *LogFileInternalGetRotateDestinationPath(char *RetStr, TLogFile *LogFile)
{
char *Tempstr=NULL;

	Tempstr=CopyStr(Tempstr, STREAMGetValue(LogFile->S,"RotatePath"));
	if (StrLen(Tempstr) && strchr(Tempstr,'$'))
	{
		STREAMSetValue(LogFile->S, "Date",GetDateStr("%Y_%m_%d",NULL));
		STREAMSetValue(LogFile->S, "Time",GetDateStr("%H:%M:%S",NULL));
		RetStr=SubstituteVarsInString(RetStr,Tempstr,LogFile->S->Values,0);
	}
	else RetStr=CopyStr(RetStr,LogFile->Path);

	DestroyString(Tempstr);

return(RetStr);
}
char *SessionSubstituteVars(char *RetStr, char *Format, TSession *Session)
{
ListNode *Vars;
char *Tempstr=NULL;

Tempstr=CopyStr(RetStr,"");
Vars=ListCreate();

Tempstr=SetStrLen(Tempstr,4096);
gethostname(Tempstr, 4096);
SetVar(Vars,"ServerHost",Tempstr);
Tempstr=FormatStr(Tempstr,"%d",Settings.Port);
SetVar(Vars,"ServerPort",Tempstr);
SetVar(Vars,"Interface",Settings.Interface);
SetVar(Vars,"Date",GetDateStr("%Y/%m/%d",NULL));
SetVar(Vars,"Date",GetDateStr("%H:%M:%S",NULL));
SetVar(Vars,"DateTime",GetDateStr("%Y/%m/%d %H:%M:%S",NULL));


//This function might be called before session setup, where all
//that we can substitute are 'interface' and 'serverhost/port' etc
if (Session)
{
	SetVar(Vars,"ClientHost",Session->ClientHost);
	SetVar(Vars,"ClientIP",Session->ClientIP);
	SetVar(Vars,"ClientMAC",Session->ClientMAC);
	SetVar(Vars,"ServerIP",Session->ServerIP);
	SetVar(Vars,"User",Session->User);
	SetVar(Vars,"RealUser",Session->RealUser);
}

Tempstr=SubstituteVarsInString(Tempstr,Format,Vars,0);

ListDestroy(Vars,DestroyString);

return(Tempstr);
}
Beispiel #8
0
void HTTPServerOptions(STREAM *S,HTTPSession *ClientHeads)
{
char *Tempstr=NULL;

STREAMWriteLine("HTTP/1.1 200 OK\r\n",S);
Tempstr=CopyStr(Tempstr,GetDateStr("Date: %a, %d %b %Y %H:%M:%S %Z\r\n",NULL));
STREAMWriteLine(Tempstr,S);
STREAMWriteLine("Content-Length: 0\r\n",S);
STREAMWriteLine("Public: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH\r\n",S);
STREAMWriteLine("Allow: OPTIONS, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH\r\n",S);
STREAMWriteLine("DASL:\r\n",S);
STREAMWriteLine("DAV: 1\r\n",S);

DestroyString(Tempstr);
}
Beispiel #9
0
/*****************************************************************
** 功    能:取当前时间的时分秒
** 输入参数:
**     iLen:    生成的日期字符串最大长度
** 输出参数:
**     pszTime:HH:MM:SS字符串
** 返 回 值:
** 作    者:唐胤曦
** 日    期:2012/11/26
** 调用说明:
** 修改日志:
*******************************************************************/
int GetTime(char *pszTime, int iLen)
{
    return (GetDateStr(pszTime, "%T", iLen));
}
Beispiel #10
0
/*****************************************************************
** 功    能:取当前时间的年月日
** 输入参数:
**     iLen:    生成的日期字符串最大长度
** 输出参数:
**     pszDate:YYYYMMDD字符串
** 返 回 值:
** 作    者:唐胤曦
** 日    期:2012/11/26
** 调用说明:
** 修改日志:
*******************************************************************/
int GetDate(char *pszDate, int iLen)
{
    return (GetDateStr(pszDate, "%Y%m%d", iLen));
}
Beispiel #11
0
bool CDateTime::GetDefaultDateStr(char *input, char *output,bool decision,char * inputformat) {
	return GetDateStr(input, "%Y-%m-%d %H:%M:%S", output,decision,inputformat);
}
Beispiel #12
0
bool CDateTime::GetDateStrCurrentTimeAsNoStyle(char *input, char *output,bool decision,char * inputformat) {
    return GetDateStr(input, "%Y%m%d%H%M%S", output,decision,inputformat);
}
Beispiel #13
0
void CDateTime::GetDefaultDateStr(char *output) {
	GetDateStr("%Y-%m-%d %H:%M:%S", output);
}
Beispiel #14
0
string CExactime::GetShowStr()
{
	return (GetDateStr() + " " + GetTimeStr() + " " + GetUSecStr());
}
Beispiel #15
0
void HTTPServerSendHeaders(STREAM *S, HTTPSession *Session, int Flags)
{
char *Tempstr=NULL;
ListNode *Curr;

Tempstr=MCopyStr(Tempstr,Session->Protocol," ",Session->ResponseCode,"\r\n",NULL);
STREAMWriteLine(Tempstr,S);
if (Settings.Flags & FLAG_LOG_VERBOSE) LogToFile(Settings.LogPath,">> %s",Tempstr);

HTTPServerSendHeader(S,"Date",GetDateStr("%a, %d %b %Y %H:%M:%S %Z",NULL));

if (Session->LastModified > 0) HTTPServerSendHeader(S,"Last-Modified",GetDateStrFromSecs("%a, %d %b %Y %H:%M:%S %Z",Session->LastModified,NULL));

if (Flags & HEADERS_AUTH) 
{
	if (Settings.AuthFlags & FLAG_AUTH_DIGEST) Tempstr=FormatStr(Tempstr,"Digest realm=\"%s\", qop=\"auth\", nonce=\"%x\"", Settings.AuthRealm, rand());
	else Tempstr=MCopyStr(Tempstr,"Basic realm=\"",Settings.AuthRealm,"\"",NULL);

	if (IsProxyMethod(Session->MethodID) ) HTTPServerSendHeader(S,"Proxy-Authenticate",Tempstr);
	else
	{
		Tempstr=MCopyStr(Tempstr,"Basic realm=\"",Settings.AuthRealm,"\"",NULL);
		HTTPServerSendHeader(S,"WWW-Authenticate",Tempstr);

		if (Settings.AuthFlags & FLAG_AUTH_DIGEST)
		{
			Tempstr=FormatStr(Tempstr,"Digest realm=\"%s\", qop=\"auth\", nonce=\"%x\"", Settings.AuthRealm, rand());
			HTTPServerSendHeader(S,"WWW-Authenticate",Tempstr);
		}
	}
}



//Special headers passed in for this transaction
Curr=ListGetNext(Session->Headers);
while (Curr)
{
	HTTPServerSendHeader(S, Curr->Tag, (char *) Curr->Item);
	Curr=ListGetNext(Curr);
}


//Custom headers defined in the config file
Curr=ListGetNext(Settings.CustomHeaders);
while (Curr)
{
	HTTPServerSendHeader(S, Curr->Tag, (char *) Curr->Item);
	Curr=ListGetNext(Curr);
}




if (Session->MethodID==METHOD_WEBSOCKET)
{
	HTTPServerSendHeader(S, "Upgrade", "WebSocket");
	HTTPServerSendHeader(S, "Connection", "Upgrade");
}
else 
{
	if ((Flags & HEADERS_USECACHE) && (Settings.DocumentCacheTime > 0))
	{
	Tempstr=FormatStr(Tempstr,"max-age=%d",Session->CacheTime);
	HTTPServerSendHeader(S, "Cache-Control", Tempstr);
	HTTPServerSendHeader(S,"Expires",GetDateStrFromSecs("%a, %d %b %Y %H:%M:%S %Z",time(NULL) + Session->CacheTime,NULL));
	}
	else 
	{
	HTTPServerSendHeader(S, "Cache-Control", "no-cache");
	HTTPServerSendHeader(S, "Pragma", "no-cache");
	}

	//Offer Upgrade to SSL if we have it
	if ((! Session->Flags & HTTP_SSL) &&  SSLAvailable()) 
	{
	HTTPServerSendHeader(S, "Upgrade", "TLS/1.0");
	}

	if ((Session->Flags & SESSION_KEEPALIVE) && (Flags & HEADERS_KEEPALIVE))
	{
		HTTPServerSendHeader(S, "Connection", "Keep-Alive");
		Session->Flags |= SESSION_REUSE;
	}
	else
	{
		HTTPServerSendHeader(S, "Connection", "close");
		Session->Flags &= ~SESSION_REUSE;
	}

	if ((Settings.AuthFlags & FLAG_AUTH_COOKIE) && (Session->Flags & SESSION_AUTHENTICATED) && (! (Session->AuthFlags & FLAG_AUTH_HASCOOKIE)))
	{
		if (StrLen(Session->UserName)) 
		{
			Tempstr=MakeAccessCookie(Tempstr, Session);
			HTTPServerSendHeader(S, "Set-Cookie", Tempstr);
		}
	}

//If we are running a CGI script, then the script will handle all headers relating to content
if (! (Flags & HEADERS_CGI)) 
{
	HTTPServerSendHeader(S, "DAV", "1");
	if (StrLen(Session->ContentType)) HTTPServerSendHeader(S,"Content-Type",Session->ContentType);
	else HTTPServerSendHeader(S,"Content-Type","octet/stream");


	if ((Session->Flags & SESSION_REUSE) || (Session->ContentSize > 0))
	{
		Tempstr=FormatStr(Tempstr,"%d",Session->ContentSize);
		HTTPServerSendHeader(S,"Content-Length",Tempstr);
	}
	
	//some clients use 'x-gzip' rather than just 'gzip'
	if (Session->Flags & SESSION_ENCODE_XGZIP) HTTPServerSendHeader(S,"Content-Encoding","x-gzip");
	else if (Session->Flags & SESSION_ENCODE_GZIP) HTTPServerSendHeader(S,"Content-Encoding", "gzip");
	
	
	//Blank line to end headers
	STREAMWriteLine("\r\n",S);
}
}

LogFileFlushAll(TRUE);
DestroyString(Tempstr);
}