Esempio n. 1
0
static void CPROC RefreshProc( uintptr_t psvTimer )
{
	CTEXTSTR *results;
	PODBC odbc = SQLGetODBCEx( cashball_local.DSN, cashball_local.user, cashball_local.password );

	SQLRecordQueryf( odbc, NULL, &results, NULL, "select Cashball from v_SessionCashball" );
	if( results && results[0] )
	{
		if( StrCmp( cashball_local.value, results[0] ) )
		{
			if( cashball_local.value )
			{
				Deallocate( TEXTSTR, cashball_local.value );
			}
			cashball_local.value = StrDup( results[0] );
			{
				INDEX idx;
				PSI_CONTROL pc;
				LIST_FORALL( cashball_local.timers, idx, PSI_CONTROL, pc )
					SmudgeCommon( pc );
			}
		}
	}
	else
	{
		if( cashball_local.value )
		{
			Deallocate( TEXTSTR, cashball_local.value );
			cashball_local.value = NULL;
			{
				INDEX idx;
				PSI_CONTROL pc;
				LIST_FORALL( cashball_local.timers, idx, PSI_CONTROL, pc )
					SmudgeCommon( pc );
			}
		}
	}
	SQLEndQuery( odbc );
	SQLDropODBC( odbc );
}
Esempio n. 2
0
static void InitView()
{
	CTEXTSTR *results;
	PODBC odbc = SQLGetODBCEx( cashball_local.DSN, cashball_local.user, cashball_local.password );
	SQLCommandf( odbc, "use %s", cashball_local.database );

	if( SQLRecordQueryf( odbc, NULL, &results, NULL, "select count(*) from INFORMATION_SCHEMA.VIEWS where table_name = 'v_SessionCashball'" ) )
	{
		if( results && results[0][0] == '0' )
		{
			SQLEndQuery( odbc );
			if( !SQLCommandf( odbc, "CREATE VIEW v_SessionCashball as "
				"SELECT top 1 itemprog.pri_sunball Cashball"
				" FROM   Itemprog  inner join"
				"	  (SELECT top 1  dbo.session.ses_id, dbo.session.hallid, dbo.session.ses_date, ISNULL(RTRIM(dbo.program.prg_desc) + ' - ' + RTRIM(dbo.sesslot.slt_desc)"
				"             + CASE WHEN [Session].Ses_Test = 1 THEN ' (Test)' ELSE '' END, '') AS SessionName"
				"        FROM  dbo.session\n"
				"        INNER JOIN dbo.program ON dbo.session.prg_id = dbo.program.prg_id \n"
				"         INNER JOIN dbo.sesslot ON dbo.session.slt_id = dbo.sesslot.slt_id \n"
				"        WHERE ses_status=2"
				"        ORDER BY dbo.session.ses_id desc )\n"
				"          AS SessionTemp ON itemprog.ses_id=sessionTemp.ses_id"
				) )
			{
				CTEXTSTR error;
				FetchSQLError( odbc, &error );
				lprintf( "Error : %s", error );
			}
		}
		SQLEndQuery( odbc );
	}
	else
	{
		CTEXTSTR error;
		FetchSQLError( odbc, &error );
		lprintf( "Error : %s", error );
	}
	SQLDropODBC( odbc );
}
Esempio n. 3
0
//----------------------------------------------------------------------------------------
// Timer for checking the timestamp
static uintptr_t CPROC countDown( PTHREAD thread )
{
	TEXTCHAR buf[45];
	uint8_t found = 0;	
	uint32_t startTime;   
	PODBC odbc;
	
	// Loop forever
	while( 1 )
	{
		// Get Current time
		startTime = timeGetTime();

		// Sleep to next timeout
		if( l.flags.bLogSleeps )
		{
			long x =  ( l.iIdleTime*(60)*(1000) ) - ( startTime - l.last_event_time );
			lprintf( WIDE("Sleep for... %d:%02d.%03d"), x / 60000, (x / 1000 ) %60, x % 1000 );
		}

		if( ( l.iIdleTime*(60)*(1000) ) > ( startTime - l.last_event_time ) )
			WakeableSleep( ( l.iIdleTime*(60)*(1000) ) - ( startTime - l.last_event_time ) );

		startTime = timeGetTime();
		// sleep some more if we got a new event

		if( ( l.iIdleTime*(60)*(1000) ) > ( startTime - l.last_event_time ) )
			continue;

		// Make connection to database
		odbc = SQLGetODBC( l.option_dsn );

		if( l.flags.bLogSleeps )
			lprintf( WIDE("woke up and user is %p (%d)"), HaveCurrentUser( odbc ), ( startTime - l.last_event_time ) );
		// If there is current user, else there is no active logins or processes to kill

		if( HaveCurrentUser( odbc ) )
		{
			uint32_t target_tick = startTime + ( l.iScreenSaverWaitTime * 1000 );
			int32_t remaining = ( target_tick - startTime );
			// Get time

			// Check last event, if timeout not hit go back to sleep until timeout will be hit
			if( remaining < 0 )
			{
				if( l.flags.bLogSleeps )
					lprintf( WIDE("Not enough time, go back and wait...") );

				// Close Connection to database
				SQLDropODBC( odbc );

				// not enough time has really passed... sleep more
				continue;
			}

			// Let hook know to update activity flag
			l.flags.countingDown = 1;			

			// Start countdown
			do
			{
				// Update time to check against
				remaining = ( target_tick - startTime );

				// Update Banner Message
				snprintf( buf, sizeof( buf ), WIDE(" The system will logout in %d.%03d seconds...")
						  , remaining / 1000, remaining % 1000 );
				BannerTopNoWait( buf );

				// Don't eat to much cpu time
				IdleFor( 200 );
				startTime = timeGetTime();
			}
			while( l.flags.countingDown && ( target_tick > startTime ) );

			// If countdown made it to 0
			if( ( target_tick < startTime ) )
			{
				uint32_t x;
				uint32_t y;
				// Logout users
				SQLCommandf( odbc , WIDE("update login_history set logout_whenstamp=now() where logout_whenstamp=11111111111111 and system_id=%d"), g.system_id );

				// Get current process list
				if ( !EnumProcesses( l.pidList2, sizeof( l.pidList2 ), &l.pidListLength2 ) )					
						lprintf( WIDE(" Getting Process List 2 Failed!") );

				// Kill Processes
				for( x = 0; x < l.pidListLength2; x++ )
				{
					// Check if process existed originally
					for( y = 0; y < l.pidListLength1; y++ )
					{
						if( l.pidList2[x] == l.pidList1[y] )
						{
							found = 1;
							break;
						}
					}

					// If did not exist originally kill the process
					if( !found )
					{
						TEXTCHAR cmd[25];
						snprintf( cmd, sizeof( cmd ), WIDE("pskill %d"), l.pidList2[x] );
						System( cmd, LogOutput, 0 );
					}

					found = 0;
				}

				// Give extra time to see Banner
				IdleFor( 500 );

				// Reset Data				
				l.flags.countingDown  = 0;				
			}			

			// Remove Banner
			RemoveBanner2Ex( NULL DBG_SRC  );
		}
		else
		{
			// fake an event, there was no user, so didn't do anything, just sleep more
			l.last_event_time = startTime;
		}

		// Close Connection to database
		SQLDropODBC( odbc );
	}

	return 0;
}