コード例 #1
0
bool CModerateMediaAssetsBuilder::SendEmail( int iModID, int iAssetID, int iStatus, int iSiteID, CTDVString sNotes, CTDVString sCustomText,  CTDVString sEmailType, CTDVString sAuthorsEmail, CTDVString sComplainantsEmail)
{
	CEmailTemplate Email(m_InputContext);

	CTDVString sModeratorsEmail;
	CTDVString sSiteShortName;
	m_InputContext.GetEmail(EMAIL_MODERATORS, sModeratorsEmail, iSiteID);
	m_InputContext.GetShortName(sSiteShortName, iSiteID);

	bool bSuccess = true;
	if ( (iStatus == 4 || iStatus == 6) && !sEmailType.CompareText("None"))
	{
		CTDVString sAuthorEmailSubject;
		CTDVString sAuthorEmailText;
		
		if (iStatus == 4)
		{
			bSuccess = bSuccess && Email.FetchEmailText(iSiteID,
				"ContentRemovedEmail", sAuthorEmailSubject, sAuthorEmailText);
		}
		else if (iStatus == 6)
		{
			bSuccess = bSuccess && Email.FetchEmailText(iSiteID,
				"ContentFailedAndEditedEmail", sAuthorEmailSubject, sAuthorEmailText);

		}

		// do any necessary translations
		CTDVString	sURL = "http://";
		CTDVString	sSiteRootURL;

		// construct the URL for the post
		m_InputContext.GetSiteRootURL(iSiteID,sSiteRootURL);
		sURL << sSiteRootURL << "MediaAsset?id=" << iAssetID << "&action=view";

		CStoredProcedure SP;
		m_InputContext.InitialiseStoredProcedureObject(&SP);
		if ( !SP.GetMediaAsset(iAssetID) )
		{
			CTDVString sErr = "Failed to retrieve details for media asset ";
			sErr << iAssetID;
			SetDNALastError("CModerateMediaAssetsBuilder::SendEmail","SendEmail",sErr);
			return false;
		}

		CTDVString sDescription, sCaption;
		SP.GetField("Description",sDescription);
		SP.GetField("Caption",sCaption);

		sAuthorEmailSubject.Replace("++**content_type**++", "Media Asset");
		sAuthorEmailText.Replace("++**content_type**++", "Media Asset");
		sAuthorEmailText.Replace("++**add_content_method**++", "resubmit");
		sAuthorEmailText.Replace("++**content_url**++", sURL);
		sAuthorEmailSubject.Replace("++**content_subject**++", sCaption);
		sAuthorEmailText.Replace("++**content_subject**++", sCaption);
		sAuthorEmailText.Replace("++**content_text**++", sDescription);

		CXMLObject::UnEscapeXMLText(&sAuthorEmailSubject);
		CXMLObject::UnEscapeXMLText(&sAuthorEmailText);

		if (bSuccess)
		{

			//Do replacements.
			if ( !sCustomText.IsEmpty() )
			{
				sAuthorEmailText.Replace("++**inserted_text**++", sCustomText);
			}
			else
			{
				CTDVString sInsertText;
				bSuccess = bSuccess && Email.FetchInsertText(iSiteID,sEmailType, sInsertText);
				CXMLObject::UnEscapeXMLText(&sInsertText);
				sAuthorEmailText.Replace("++**inserted_text**++", sInsertText);
			}
			
			// then send the email
			bSuccess = SendMail(sAuthorsEmail, sAuthorEmailSubject, sAuthorEmailText, sModeratorsEmail, sSiteShortName);
		}

		if(!bSuccess)
		{
			CTDVString sErrorXML = "Email failed to be sent to ";
			sErrorXML <<  sAuthorsEmail;
			SetDNALastError("CModerateMediaAssetsBuilder::SendEmail","SendEmail",sErrorXML);
		}
	}

	// Send Email to complainant if complaint.
	if (sComplainantsEmail.GetLength() > 0 &&  (iStatus == 3 || iStatus == 4 || iStatus == 6))
	{
		CTDVString sComplainantEmailSubject;
		CTDVString sComplainantEmailText;

		// get the appropriate email template depending on whether it is a pass or fail
		if (iStatus == 3)
		{
			// pass => complaint was overruled
			bSuccess = bSuccess && Email.FetchEmailText(iSiteID,
				"RejectComplaintEmail", sComplainantEmailSubject, sComplainantEmailText);

		}
		else if (iStatus == 4)
		{
			// fail => complaint was upheld

			bSuccess = bSuccess && Email.FetchEmailText(iSiteID,
				"UpholdComplaintEmail", sComplainantEmailSubject, sComplainantEmailText);

		}
		else if (iStatus == 6)
		{
			// fail => complaint was upheld
		
			bSuccess = bSuccess && Email.FetchEmailText(iSiteID,
				"UpholdComplaintEditEntryEmail", sComplainantEmailSubject, 
				sComplainantEmailText);
		}

		CXMLObject::UnEscapeXMLText(&sComplainantEmailSubject);
		CXMLObject::UnEscapeXMLText(&sComplainantEmailText);

		if ( bSuccess )
		{
			// do any necessary template substitutions
			// => just putting in the complaint reference number currently
			CTDVString	sRefNumber = "MA";
			sRefNumber << iModID;
			sComplainantEmailSubject.Replace("++**reference_number**++", sRefNumber);
			sComplainantEmailText.Replace("++**reference_number**++", sRefNumber);

			// Allow rejected complaints to have some custom text
			// For now re-using the 'CustomEmailText' field since it wouldn't have
			// been used to send something to the author.
			//
			if (iStatus == 3)
			{
				sComplainantEmailText.Replace("++**inserted_text**++", sCustomText);
			}

			// send the email
			bSuccess = bSuccess && SendMail(sComplainantsEmail, 
				sComplainantEmailSubject, sComplainantEmailText, 
				sModeratorsEmail, sSiteShortName);
		}

		if( !bSuccess )
		{
			CTDVString sErrorXML = "Email failed to be sent to complainant ";
			sErrorXML << sComplainantsEmail;
			SetDNALastError("CModerateMediaAssetsBuilder::SendEmail","SendEmail",sErrorXML);
		}
	}
	return bSuccess;
}
コード例 #2
0
ファイル: SmtpTest.cpp プロジェクト: GHScan/DailyProjects
int main()
{
    SendMail("[email protected];[email protected]", "自动发送测试", "第一行\n第二行\n第三行\noyes!", "D:/Downloads/md5.h");

    return 0;
}
コード例 #3
0
/* Flush batched alerts.
 * Must be called under the protection of alert_mutex
 * release mutex ASAP if release_mutex_asap is true,
 * else: don't release it.
 */
static void FlushAlerts(bool release_mutex_asap)
{
    alert_type_t   *pcurr;
    unsigned int    alert_types = 0;
    unsigned int    mail_size = 0;
    char            title[MAIL_TITLE_MAX];
    GString        *contents = NULL;
    time_t          now;
    struct tm       date;

    /* first list scan, to determine the number of alerts, etc... */
    for (pcurr = alert_list; pcurr != NULL; pcurr = pcurr->next) {
        alert_types++;
        mail_size += pcurr->estim_size;
    }

    if (alert_count == 0) {
        if (release_mutex_asap)
            V(alert_mutex);
        return;
    }

    now = time(NULL);
    localtime_r(&now, &date);

    snprintf(title, MAIL_TITLE_MAX,
             "robinhood alert summary (%s on %s): %u alerts",
             global_config.fs_path, machine_name, alert_count);

    contents = g_string_new("");
    g_string_printf(contents, "Date: %.4d/%.2d/%.2d %.2d:%.2d:%.2d\n"
                    "Program: %s (pid %lu)\n"
                    "Host: %s\n"
                    "Filesystem: %s\n",
                    1900 + date.tm_year, date.tm_mon + 1, date.tm_mday,
                    date.tm_hour, date.tm_min, date.tm_sec, prog_name,
                    (unsigned long)getpid(), machine_name,
                    global_config.fs_path);

    g_string_append(contents, "\n===== alert summary ====\n\n");
    g_string_append_printf(contents, "%u alerts:\n", alert_count);

    for (pcurr = alert_list; pcurr != NULL; pcurr = pcurr->next) {
        g_string_append_printf(contents, "\t* %u %s\n", pcurr->count,
                               pcurr->title);
    }

    for (pcurr = alert_list; pcurr != NULL;) {
        unsigned int i;

        g_string_append_printf(contents, "\n==== alert '%s' ====\n\n",
                               pcurr->title);

        for (i = 0; i < pcurr->count; i++) {
            /* print and free */
            if (pcurr->entries[i]) {
                g_string_append_printf(contents, "%s\n", pcurr->entries[i]);
                if (log_config.alert_show_attrs)
                    g_string_append_printf(contents, "Entry info:\n%s\n",
                                           pcurr->info[i]);

                free(pcurr->entries[i]);
                free(pcurr->info[i]);
            }
        }
        /* free the list of entries */
        free(pcurr->entries);
        free(pcurr->info);

        /* set the list to the next item */
        alert_list = pcurr->next;
        /* free the item */
        free(pcurr);
        /* next item */
        pcurr = alert_list;
    }

    /* reset alert count */
    alert_count = 0;

    /* all alerts has been released, we can put the lock */
    if (release_mutex_asap)
        V(alert_mutex);

    /* send the mail and/or write the alert in alert file */
    if (!EMPTY_STRING(log_config.alert_mail))
        SendMail(log_config.alert_mail, title, contents->str);

    if (!EMPTY_STRING(log_config.alert_file)) {
        if (alert.log_type == RBH_LOG_SYSLOG) {
            /* we need to split the content after each '\n' */
            char *curr = contents->str;
            char *next = NULL;
            display_line_log_(&alert, "ALERT", "=== ALERT REPORT ===");
            do {
                next = strchr(curr, '\n');
                if (next != NULL) {
                    next[0] = '\0';
                    next++;
                }
                display_line_log_(&alert, "ALERT", curr);
                curr = next;
            } while (curr != NULL);
            display_line_log_(&alert, "ALERT", "=== END OF ALERT REPORT ===");
        } else {
            display_line_log_(&alert, "ALERT", "=== ALERT REPORT ===\n%s",
                              contents->str);
            display_line_log_(&alert, "ALERT", "=== END OF ALERT REPORT ===");
        }

        /* always flush alerts, because we don't want to lose events */
        flush_log_descr(&alert);
    }

    g_string_free(contents, TRUE);
    /* mutex already released, can go out now */

}   /*  Flush alerts */
コード例 #4
0
void CleanupDirectData(void* parameter, Uint16 followUpItemIndex)
{
	Uint16 i, j, port, virtualChannel;
	struct Mail message;

	// Check if there are any virtual channels that need to be cleared
	for(i = 0; i < NUM_PORTS; i++)
	{
		for(j = 0; j < NUM_VIRTUAL_DATA_CHANNELS; j++)
		{
			// Check if this virtual channel is active
			if(globals.processing.virtualChannels[i][j].virtualChannelBlockedCount > 0)
				globals.processing.virtualChannels[i][j].virtualChannelBlockedCount--;
		}
	}

	// Check if there are any data transfers that need to be tagged or removed
	for(i = 0; i < NUM_DATA_PACKET_LOOKUPS; i++)
	{
		// Check if this data transfer is active
		if(globals.processing.dataTransferPackets[i].transferInfo.packetID != 0)
		{
			// Decrement the time to live for the transfer
			globals.processing.dataTransferPackets[i].dataBufferInfo.timeToLive--;
			
			// Check if this transfer has expired
			if(globals.processing.dataTransferPackets[i].dataBufferInfo.timeToLive <= 0)
			{
#if TEST == TEST_PROTOCOL
				
				if(globals.processing.dataTransferPackets[i].transferInfo.packetID == protocolTestPacketIDs[0])
					receivedResponse[0] = true;
				if(globals.processing.dataTransferPackets[i].transferInfo.packetID == protocolTestPacketIDs[1])
					receivedResponse[1] = true;
				if(globals.processing.dataTransferPackets[i].transferInfo.packetID == protocolTestPacketIDs[2])
					receivedResponse[2] = true;
				if(SEM_count(&TestServiceSem) == 0)
					SEM_post(&TestServiceSem);

#elif TEST == TEST_MPI
				
				// Send a message to the MPI send service
				CreateMessage(&message, 
					NULL,
					0,
					MAIL_DATA_TRANSFER_FAILED,
					globals.processing.dataTransferPackets[i].transferInfo.packetID,
					MPI_ANY_REQUEST->requestType,
					MPI_ANY_REQUEST->requestID,
					ADDRESS_UNDEFINED,
					ADDRESS_UNDEFINED,
					TEST_SERVICE_TAG,
					TEST_SERVICE_TAG);
				SendMail(TEST_SERVICE_TAG, &message);

#endif
				port = globals.processing.dataTransferPackets[i].transferInfo.port;
				virtualChannel = globals.processing.dataTransferPackets[i].transferInfo.virtualChannel;
				ClearDataTransferLookup(globals.processing.dataTransferPackets[i].transferInfo.packetID);
				globals.processing.virtualChannels[port][virtualChannel].virtualChannelBlockedCount = VIRTUAL_CHANNEL_INITIAL_BLOCKED_COUNT;
				globals.statistics.packet.numDataTransfersExpired++;
			}
		}
	}

	// Check if there are any direct transfers that need to be tagged or removed
	for(i = 0; i < NUM_PORTS; i++)
	{
		for(j = 0; j < NUM_VIRTUAL_DATA_CHANNELS; j++)
		{
			// Check if this direct transfer is active
			if(globals.processing.directTransfers[i][j].destinationPort != PORT_UNDEFINED)
			{
				// Decrement the time to live for the transfer
				globals.processing.directTransfers[i][j].timeToLive--;
					
				// Check if this transfer has expired
				if(globals.processing.directTransfers[i][j].timeToLive <= 0)
				{
					ReleaseVirtualChannel(globals.processing.directTransfers[i][j].destinationPort,
						globals.processing.directTransfers[i][j].destinationVirtualChannel);
					globals.processing.directTransfers[i][j].destinationPort = PORT_UNDEFINED;
					globals.statistics.packet.numDirectTransfersExpired++;
				}
			}
		}
	}

	// Check if there are any direct buffers that need to be tagged or removed
	for(i = 0; i < NUM_PORTS; i++)
	{
		for(j = 0; j < NUM_VIRTUAL_DATA_CHANNELS; j++)
		{
			// Check if this direct buffer is active
			if(globals.processing.directBuffer[i][j].packet.dataBuffer != NULL)
			{
				// Decrement the time to live for the buffer
				globals.processing.directBuffer[i][j].bufferStatus.timeToLive--;
				
				// Check if this buffer has expired
				if(globals.processing.directBuffer[i][j].bufferStatus.timeToLive <= 0)
				{
					MemFree(globals.processing.directBuffer[i][j].packet.dataBuffer);
					globals.processing.directBuffer[i][j].packet.dataBuffer = NULL;
					globals.statistics.packet.numDirectBuffersExpired++;
				}
			}
		}
	}
}
コード例 #5
0
int ReadConfig(){
	char *file = "email.ini";
	ifstream fin(file);
	string line;
	int nSize = 0, ret = 0;
	char str1[64], str2[64], c;

	if(!fin.is_open()){
		MessageBox(NULL, L"配置文件打开失败", L"警告", MB_OK | MB_ICONWARNING);
		return -1;
	}
	
	while(getline(fin, line)){
		nSize = line.size();
		if(nSize < 1) continue;
		if(line[0] == '#'){
			continue;
		}else{
			ret = sscanf(line.c_str(), "%[^=]=%[^\0]", str1, str2);
			if(ret != 2) continue;

			if(strcmp(str1, "receiver") == 0){
				memcpy(receiver, str2, strlen(str2)+1);
			}else if(strcmp(str1, "sender") == 0){
				memcpy(sender, str2, strlen(str2)+1);
			}else if(strcmp(str1, "title") == 0){
				memcpy(sendtitle, str2, strlen(str2)+1);
			}else if(strcmp(str1, "serverip") == 0){
				memcpy(serverip, str2, strlen(str2)+1);
			}else if(strcmp(str1, "servername") == 0){
				memcpy(servername, str2, strlen(str2)+1);
			}else{
				continue;
			}
		}
	}

	printf("Please input password of e-mail [%s]: ", sender);
	//scanf("%s", senderpwd);
	getpwd(senderpwd);
	
	printf("\nWait...\r");
	if(SendMail("E-mail Test") == 0){
		printf("E-mail test success\n");
		flog = fopen("log.txt", "a");
		if(flog == NULL){
			printf("Log open failed\n");
		}else{
			printf("Log open success\n");
		}
		printf("Press 'y' to continue, 'n' to end: ");
		fflush(stdin);
		scanf("%c", &c);
		if(c == 'y'){
			return 0;
		}else{
			return -1;
		}
	}else{
		printf("E-mail test failed\r");
		printf("Some E-mail configuration information incorrect\n");
		return -1;
	}

	

	return 0;
}
コード例 #6
0
ファイル: sendmail.cpp プロジェクト: nikstra/cgi-mailer
int main()
{
	////////////////////////////////////////////////////////////
	// Create an instance of CGIQuery.
	CGIQuery Parser;

	////////////////////////////////////////////////////////////
	// A map to hold the form data.
	CGI_Data Data;

	try
	{
		////////////////////////////////////////////////////////////
		// Parse and decode the input from the form.
		Parser.Parse();

		////////////////////////////////////////////////////////////
		// Get the parsed data.
		Data = Parser.GetData();

		////////////////////////////////////////////////////////////
		// Verify that we are allowed to send mail to the
		// specified address.
		string address;
		ifstream MailAllow( "mail_allow", ios::in );
		if( !MailAllow.good())
			throw CGI_Error( "Couldn't verify \"To address\"" );

		bool allow = false;
		while( MailAllow.good())
		{
			MailAllow >> address;
			if( address == Data["to"] )
				allow = true;
		}
		MailAllow.close();
		if( !allow )
			throw CGI_Error( "Not allowed to send to this address!" );

		////////////////////////////////////////////////////////////
		// Check for users name and address, if empty write error
		// message to stdout.
		if( !Data["from"].length() || !Data["name"].length())
		{
			cout << CONTENT_HTML << endl
				<< "<HTML>\n<HEAD>\n<TITLE>NOT complete!</TITLE>\n</HEAD>\n"
				<< "<BODY>\n<H1>NOT complete!</H1><HR>\n<P>"
				<< "<B>You must enter both your name and E-mail address!</B>"
				<< "</P>\n<P><B><A HREF=\"JavaScript:history.back()\">"
				<< "Please, try again</A></B></P>\n</BODY>\n</HTML>" << endl;

			exit( EXIT_FAILURE );
		}

		////////////////////////////////////////////////////////////
		// CPipe holds a pair of file descriptors, fdPipe[0]
		// for reading and fdPipe[1] for writing.
		CPipe fdPipe;

		////////////////////////////////////////////////////////////
		// Create the filedescriptors, pipe() returns 0 on success
		// and -1 on failure. Throw an exception if unsuccessful.
		if( pipe( fdPipe ) != 0 )
			throw CGI_Error( "Could not open pipe" );

		////////////////////////////////////////////////////////////
		// Create a child process. fork() returns the process
		// PID or -1 on failure.
		pid_t pid;
		if(( pid = fork()) < 0 )
			throw CGI_Error( "Could not fork subprocess" );

		////////////////////////////////////////////////////////////
		// If fork() returned 0 we are the child process.
		if( pid )
		{
			////////////////////////////////////////////////////////////
			// We are the parent, close the read end of the pipe.
			close( fdPipe[READ_PIPE] );

			////////////////////////////////////////////////////////////
			// Create a stream connected to the pipe and write to it.
			ofstream SendMail( fdPipe[WRITE_PIPE] );

			////////////////////////////////////////////////////////////
			// Output the form data to the stream.
			SendMail << "To: " << Data["to"] << endl
				<< "From: " << Data["name"] << endl
				<< " <" << Data["from"] << ">" << endl
				<< "Subject: " << Data["subject"] << endl
				<< Data["text"] << endl;

			////////////////////////////////////////////////////////////
			// Output any additional data to the stream.
			SendMail << "\n*** Additional Parameters Sent ***" << endl;
			CGI_Data::iterator itr;
			for( itr = Data.begin(); itr != Data.end(); itr++ )
			{
				////////////////////////////////////////////////////////////
				// Don't output data from any reserved keys.
				if( Reserved.find(( *itr ).first ) == string::npos )
				{
					SendMail << ( *itr ).first << " = "
						<< ( *itr ).second << endl;
				}
			}

			////////////////////////////////////////////////////////////
			// Close the stream.
			SendMail.close();

			////////////////////////////////////////////////////////////
			// Wait until the child process exits.
			if( wait( 0 ) < 0 )
				throw CGI_Error( "Can't wait for my child" );

			////////////////////////////////////////////////////////////
			// Print any feedback to cout...
			if( Data["location"].length())
			{
				////////////////////////////////////////////////////////////
				// Redirects to another page.
				cout << "Location: " << Data["location"] << endl;
			}
			else
			{
				////////////////////////////////////////////////////////////
				// Prints your coustomized HTML data.
				if( Data["feedback"].length())
				{
					cout << CONTENT_HTML << endl;
					cout << Data["feedback"] << endl;
				}
			}

			////////////////////////////////////////////////////////////
			// Exit the parent process.
			exit( EXIT_SUCCESS );
		}
		else
		{
			////////////////////////////////////////////////////////////
			// We are the child, close the write end of the pipe.
			close( fdPipe[WRITE_PIPE] );

			////////////////////////////////////////////////////////////
			// Close stdin.
			close( STDIN_FILENO );

			////////////////////////////////////////////////////////////
			// Duplicate the file descriptor, redirect the pipe to cout.
			dup( fdPipe[READ_PIPE] );

			////////////////////////////////////////////////////////////
			// Close the read end of the pipe.
			close( fdPipe[READ_PIPE] );

			////////////////////////////////////////////////////////////
			// Execute the sendmail program. Not sure of the arguments??
			if( execl( SENDMAIL, SENDMAIL, SENDMAIL_OPTS, 0 ) < 0 )
				throw CGI_Error( "Can't execute sendmail" );
		}
	}
	catch( CGI_Error &e )
	{
		////////////////////////////////////////////////////////////
		// We caught an exception, print an error message in HTML
		// to cout.
		cout << CONTENT_HTML << endl
			<< "<HTML>\n<HEAD>\n<TITLE>CGI error!</TITLE>\n</HEAD>\n"
			<< "<BODY>\n<H1>CGI error!</H1><HR>\n<P>" << "Reported: <B>"
			<< e.what() << "</B></P>\n" << "<P>Please, contact the <A HREF="
			<< "\"mailto:[email protected]?subject=cgi error\">webmaster</A>"
			<< "</P>\n</BODY>\n</HTML>" << endl;

		exit( EXIT_FAILURE );
	}

	return 0;
}
コード例 #7
0
int main(int argc, char* argv[])
{
	char cmd[512];
	int ret;

	if( argc < 2 )
	{
		return PrintUsage();
	}


	// All output gets redirected to this file.
	SECURITY_ATTRIBUTES fileAttribs;
	fileAttribs.nLength = sizeof(fileAttribs);
	fileAttribs.lpSecurityDescriptor = NULL;
	fileAttribs.bInheritHandle = TRUE;

	g_hOutputFile = CreateFile( 
		"vmapbuilder.out", 
		GENERIC_WRITE,
		FILE_SHARE_READ,
		&fileAttribs,
		CREATE_ALWAYS,
		FILE_FLAG_WRITE_THROUGH|FILE_ATTRIBUTE_NORMAL,
		NULL );


	// Low priority..
	SetPriorityClass( GetCurrentProcess(), IDLE_PRIORITY_CLASS );

	bool bSave = !FindArg( "-nosave" );
	bool bNoVis = !!FindArg( "-novis" );
	bool bNoRad = !!FindArg( "-norad" );

	char const *pCFGFile = argv[1];
	while( 1 )
	{
		DWORD startTime = GetTickCount();

		CConfigFile file;
		if( file.Read( pCFGFile ) && file.m_Entries.Size() > 0 )
		{
			// Move the first entry in the file to the end.
			CConfigFile::Entry entry = file.m_Entries[0];
			file.m_Entries.Remove( 0 );
			file.m_Entries.AddToTail( entry );
			if( bSave )
			{
				file.Write( pCFGFile );
			}


			char ssCmd[256];
			_snprintf( ssCmd, sizeof(ssCmd), "%s\\win32\\ss.exe", file.m_SSDatabase );

			// Grab the SourceSafe tree.			  
			AppPrint( "\n\n-------------------------------------------------------------\n" );
			AppPrint( "Processing %s\n", entry.m_Filename );
			AppPrint( "-------------------------------------------------------------\n" );
			AppPrint( "Grabbing resources in %s\n", file.m_SSDatabase );
			
			sprintf( cmd, "ssdir=%s", file.m_SSDatabase );
			ret = _putenv( cmd );
			
			// Get the VMF.
			char vmfFilename[512];
			sprintf( vmfFilename, "%s/%s.vmf", entry.m_VMFPath, entry.m_Filename );
			sprintf( cmd, "%s get %s -I-", ssCmd, vmfFilename );
			ret = RunProcess( cmd );

			// Check the timestamp (don't reprocess if it's up-to-date).
			sprintf( vmfFilename, "%s.vmf", entry.m_Filename );
			struct _stat fileStat;
			ret = _stat( vmfFilename, &fileStat );
			long vmfTime = fileStat.st_mtime;
			if( vmfTime == entry.m_VMFTime )
			{
				AppPrint( "%s is up-to-date\n", vmfFilename );
			}
			else
			{
				char localBSPFilename[512];
				sprintf( localBSPFilename, "%s.bsp", entry.m_Filename );
				
				// Attrib the bsp if it exists.
				sprintf( cmd, "attrib -r %s", localBSPFilename );
				RunProcess( cmd );
				
				sprintf( cmd, "%s cp %s", ssCmd, file.m_SSResourcePath );
				ret = RunProcess( cmd );
				
				if( !FindArg( "-noget" ) )
				{
					sprintf( cmd, "%s get * -R -I-", ssCmd );
					ret = RunProcess( cmd );
				}

				// run each tool.
				char vbspCommand[256], vradCommand[256], vvisCommand[256];
				sprintf( vbspCommand, "bin\\vbsp -low %s", entry.m_Filename );
				
				if( entry.m_bFastVis )
					sprintf( vvisCommand, "bin\\vvis -fast -low %s", entry.m_Filename );
				else
					sprintf( vvisCommand, "bin\\vvis -low %s", entry.m_Filename );

				sprintf( vradCommand, "bin\\vrad -low %s", entry.m_Filename );
				if( !RunProcess( vbspCommand ) && 
					(bNoVis || !RunProcess( vvisCommand )) && 
					(bNoRad || !RunProcess( vradCommand )) )
				{
					// Check in the BSP file.
					char bspFilename[512];
					sprintf( bspFilename, "%s/%s.bsp", file.m_SSBSPPath, entry.m_Filename );

					// First, try to add it to SS because it may not exist yet.
					sprintf( cmd, "%s cp %s", ssCmd, file.m_SSBSPPath );
					RunProcess(cmd);
					sprintf( cmd, "%s add %s.bsp -I-", ssCmd, entry.m_Filename );
					ret = RunProcess(cmd);

					// Store off the BSP file temporarily..
					char tempFilename[512];
					sprintf( localBSPFilename, "%s.bsp", entry.m_Filename );
					
					sprintf( tempFilename, "%s.TEMP", entry.m_Filename );
					sprintf( cmd, "del /f %s", tempFilename );
					system( cmd );

					sprintf( cmd, "attrib -r %s", localBSPFilename );
					system( cmd );
					ret = MoveFile( localBSPFilename, tempFilename );
					if( ret )
					{
						char undoCmd[512];
						sprintf( undoCmd, "%s undocheckout %s -I-", ssCmd, bspFilename );

						sprintf( cmd, "%s checkout %s -I-", ssCmd, bspFilename );
						ret = RunProcess( cmd );
						if( !ret )
						{
							// Copy the new BSP file over.
							DeleteFile( localBSPFilename );
							ret = MoveFile( tempFilename, localBSPFilename );
							if( ret )
							{
								sprintf( cmd, "%s checkin %s -I-", ssCmd, bspFilename );
								ret = RunProcess( cmd );
								if( !ret )
								{
									while( !file.Read( pCFGFile ) )
									{
										Sleep( 300 );
									}

									if( bSave )
									{
										CConfigFile::Entry *pEntry = file.FindEntryByFilename( entry.m_Filename );
										if( pEntry )
										{
											pEntry->m_VMFTime = vmfTime;
											while( !file.Write( pCFGFile ) )
											{
												Sleep( 300 );
											}
										}
									}
									
									// Update the timestamp in the config file.
									AppPrint( "Completed '%s' successfully!\n", entry.m_Filename );

									// Send emails.
									char computerName[256] = {0};
									DWORD len = sizeof(computerName);
									GetComputerName( computerName, &len );

									DWORD elapsed = GetTickCount() - startTime;
									char timeStr[256];
									BuildTimeDurationString( elapsed, timeStr );

									char subject[1024];
									_snprintf( subject, sizeof(subject), "[vmapbuilder] completed '%s' on '%s' in %s", entry.m_Filename, computerName, timeStr );
									for( int e=0; e < entry.m_nEMailAddresses; e++ )
									{
										char *pAddr = entry.m_EMailAddresses[e].m_EMailAddress;
										if( !SendMail( pAddr, subject, subject ) )
										{
											AppPrint( "Unable to send confirmation email to %s\n", pAddr );
										}
									}
								}
								else
								{
									AppPrint( "ERROR: Can't checkin %s\n", bspFilename );
									RunProcess( undoCmd );
								}
							}
							else
							{
								AppPrint( "ERROR: Can't copy back the BSP file %s\n", localBSPFilename );
								RunProcess( undoCmd );
							}
						}
						else
						{
							AppPrint( "ERROR: Can't checkout %s\n", bspFilename );
						}
					}
					else
					{
						AppPrint( "ERROR: Can't create temporary file %s\n", tempFilename );
					}
				}
				else
				{
					AppPrint( "Command '%s' failed\n", cmd );
				}
			}
		}
		else
		{
			AppPrint( "Can't read maplist file: %s\n", pCFGFile );
		}

		// Sleep for a bit in case all maps are processed so we don't kill the network.
		Sleep( 2000 );
	}

	CloseHandle( g_hOutputFile );
	return 0;
}
コード例 #8
0
ファイル: main.cpp プロジェクト: astromaker/sandbox
int main()
{
	std::string s = "VXNlcm5hbWU6";
	std::string s1 = modp::b64_decode( s );
	mime_test();

	Recipient_Info recipient;
	recipient.cc_recipient.push_back( "*****@*****.**" );

	google_smtp.server = "smtp.test.com";
	google_smtp.port = 587;
	google_smtp.security = smtp_client::tls;
	google_smtp.user = "******";
	google_smtp.password = "******";

	Sender_Info sender;
	sender.mail = "*****@*****.**";

	recipient.recipient.push_back( "*****@*****.**" );
	recipient.bcc_recipient.push_back( "*****@*****.**" );

	/*
	google_smtp.server = "smtp.test.com";
	google_smtp.port = 587;//465;
	google_smtp.security = smtp_client::tls;
	google_smtp.user = "******";
	google_smtp.password = "******";

	Sender_Info sender;
	sender.mail = "*****@*****.**";
	*/

	recipient.recipient.push_back( "*****@*****.**" );
	recipient.bcc_recipient.push_back( "*****@*****.**" );

	Message_Info message;
	message.subject = "test smtp send mail";
	message.text = "�ѱ��� �ɱ�?abcedefdadfaerfdfdfadffffsdf\n�Ƹ���? ����ertyuiop\nastromaker\n";
	if( SendMail( google_smtp, sender, recipient, message ) == true )
	{
		std::cout << "Mail was send successfully.\n";
	}

	/*
	bool bError = false;

	try
	{
		smtp_client mail;

#define test_gmail_tls

#if defined(test_gmail_tls)
		mail.SetSMTPServer("smtp.gmail.com",587);
		mail.SetSecurityType(USE_TLS);
#elif defined(test_gmail_ssl)
		mail.SetSMTPServer("smtp.gmail.com",465);
		mail.SetSecurityType(USE_SSL);
#elif defined(test_hotmail_TLS)
		mail.SetSMTPServer("smtp.live.com",25);
		mail.SetSecurityType(USE_TLS);
#elif defined(test_aol_tls)
		mail.SetSMTPServer("smtp.aol.com",587);
		mail.SetSecurityType(USE_TLS);
#elif defined(test_yahoo_ssl)
		mail.SetSMTPServer("plus.smtp.mail.yahoo.com",465);
		mail.SetSecurityType(USE_SSL);
#endif

		mail.SetLogin("*****@*****.**");
		mail.SetPassword("*******");
  		mail.SetSenderName("��ȣ��");
  		mail.SetSenderMail("*****@*****.**");
  		mail.SetReplyTo("*****@*****.**");
  		mail.SetSubject("The message");
  		mail.AddRecipient("*****@*****.**");
  		mail.SetXPriority(XPRIORITY_NORMAL);
  		//mail.SetXMailer("The Bat! (v3.02) Professional");
  		mail.AddMsgLine("Helloasasasasasas,");
		mail.AddMsgLine("");
		mail.AddMsgLine("...");
		mail.AddMsgLine("How are you today?");
		mail.AddMsgLine("");
		mail.AddMsgLine("Regards");
		mail.ModMsgLine(5,"regards");
		mail.DelMsgLine(2);
		mail.AddMsgLine("User");

  		//mail.AddAttachment("../test1.jpg");
  		//mail.AddAttachment("c:\\test2.exe");
		//mail.AddAttachment("c:\\test3.txt");
		mail.Send();
	}
	catch(ECSmtp e)
	{
		std::cout << "Error: " << e.GetErrorText().c_str() << ".\n";
		bError = true;
	}
	if(!bError)
		std::cout << "Mail was send successfully.\n";
		*/

	return 0;
}
コード例 #9
0
ファイル: EventAge.c プロジェクト: trieck/source
void main()
{
    HANDLE			hEventLog;
    EVENTLOGRECORD* pEventLogRecord = 0;
    EVENTRECORD*	pER = 0;
    CHAR			szFilePath[_MAX_PATH];
    CHAR			szDate[9];
    DWORD			dwBytesRead, dwBytesNeeded;
    DWORD			dwEventLogRecords, dwTemp;
    FILE*			fp;

    // get current date
    GetCurrentDate(szDate);

    // get file path
    if (!(GetFilePath(szFilePath)))
        strcpy(szFilePath, "");

    // format file name
    sprintf(szFileName, "%s%s%s", szFilePath, szDate, ".LOG");

    // open security event log on local machine
    printf("Opening Security Event Log for Reading...\n");
    if (!(hEventLog = OpenEventLog(NULL, "Security"))) {
        printf("Error Opening Event Log.\n");
        return;
    }

    // open event file
    printf("Opening Event File %s for Writing...\n", szFileName);
    if ((fp = fopen(szFileName, "w+t")) == NULL) {
        printf("Error Opening Event File.\n");
        return;
    }

    // find the number of event log records
    GetNumberOfEventLogRecords(hEventLog, &dwEventLogRecords);

    // read data and output to file
    printf("Writing Data To File...\n");

    for (dwTemp = 1; dwTemp <= dwEventLogRecords; dwTemp++) {
        if (!(pEventLogRecord = (EVENTLOGRECORD*)malloc(16384)))
            return;

        // read records from event log
        if (!(ReadEventLog(hEventLog,		// event log handle
                           EVENTLOG_SEEK_READ |
                           EVENTLOG_FORWARDS_READ,		// get specified record
                           dwTemp,
                           pEventLogRecord,			// buffer address
                           16384,						// max size
                           &dwBytesRead,				// number of bytes read
                           &dwBytesNeeded)))			// number of bytes needed
            ShowError();

        // read record information
        if (dwBytesRead) {
            if (ShouldWriteRecord(pEventLogRecord->TimeWritten)) {
                // allocate memory for event record
                if (!(pER = (EVENTRECORD*)malloc(sizeof(EVENTRECORD)))) {
                    printf("Error allocating memory for record.\n");
                    if (pEventLogRecord) free (pEventLogRecord);
                    return;
                }

                // set event record into structure
                SetEventRecord(pEventLogRecord, pER);

                // write data to file
                fprintf(fp, "%d\t%s\t%s\t%s\t%s\n%s\n", pER->EventID, pER->szEventDate,
                        pER->szEventType, pER->szSourceName, pER->szComputerName,
                        pER->pMessage);

                // free allocated memory
                if (pER) free(pER);
            }
        }
        // free allocated buffer
        if (pEventLogRecord) free (pEventLogRecord);
    }

    printf("Closing Files...\n");

    // release event log handle
    CloseEventLog(hEventLog);

    // close event file
    _flushall();
    fclose(fp);

    // send message
    printf("Sending messages...\n");
    SendMail();
}