Files
HLStock/HookMsg/LogonDlg.cpp
2013-07-20 23:23:05 +00:00

267 lines
7.7 KiB
C++

// LogonDlg.cpp : implementation file
//
#include "stdafx.h"
#include "hookmsg.h"
#include "LogonDlg.h"
#include "./UtilClass/sntp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLogonDlg dialog
CLogonDlg::CLogonDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLogonDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLogonDlg)
m_strPasswd = _T("");
m_nSvr = 0;
//}}AFX_DATA_INIT
}
void CLogonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLogonDlg)
DDX_Text(pDX, IDC_AUTHENTIFICATION_EDIT, m_strPasswd);
DDV_MaxChars(pDX, m_strPasswd, 10);
DDX_Radio(pDX, IDC_RADIO_SVR1, m_nSvr);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLogonDlg, CDialog)
//{{AFX_MSG_MAP(CLogonDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLogonDlg message handlers
BOOL CLogonDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_nSvr = g_theApp.m_nLogonSvr;
CButton* pPasswdSave = (CButton*)GetDlgItem(IDC_CHECK_PASSWDSAVE);
if( g_theApp.m_bLogonPasswdSave )
pPasswdSave->SetCheck(BST_CHECKED);
else
pPasswdSave->SetCheck(BST_UNCHECKED);
m_strPasswd = g_theApp.m_strLogonPasswd;
CEdit* pEditWnd = (CEdit*)GetDlgItem(IDC_AUTHENTIFICATION_EDIT);
pEditWnd->SetWindowText(m_strPasswd);
pEditWnd->SendMessage( EM_SETSEL, 0, -1 );
pEditWnd->SetFocus();
CString strStatus = "프로그램 인증검사중...";
((CWnd*)GetDlgItem(IDC_LOGON_STATIC))->SetWindowText( strStatus );
memset( &m_systime, NULL, sizeof(SYSTEMTIME) );
//Do the actual NTP Query
CSNTPClient sntp;
NtpServerResponse response;
if (sntp.GetServerTime( "time.windows.com", response, 123 )) // time.windows.com , time.kriss.re.kr
{
_tprintf(_T("Time was successfully retreived from NTP server\n"));
SYSTEMTIME st1 = response.m_OriginateTime;
SYSTEMTIME st2 = response.m_ReceiveTime;
SYSTEMTIME st3 = response.m_TransmitTime;
SYSTEMTIME st4 = response.m_DestinationTime;
m_systime = st2;
_tprintf(_T(" DD/MM/YYYY HH:MM:SS.MS\n"));
_tprintf(_T("Client Originate Date was %02d/%02d/%04d, %02d:%02d:%02d.%03d\n"), st1.wDay, st1.wMonth, st1.wYear, st1.wHour, st1.wMinute, st1.wSecond, st1.wMilliseconds);
_tprintf(_T("Server Receive Date was %02d/%02d/%04d, %02d:%02d:%02d.%03d\n"), st2.wDay, st2.wMonth, st2.wYear, st2.wHour, st2.wMinute, st2.wSecond, st2.wMilliseconds);
_tprintf(_T("Server Transmit Date was %02d/%02d/%04d, %02d:%02d:%02d.%03d\n"), st3.wDay, st3.wMonth, st3.wYear, st3.wHour, st3.wMinute, st3.wSecond, st3.wMilliseconds);
_tprintf(_T("Client Destination Date was %02d/%02d/%04d, %02d:%02d:%02d.%03d\n"), st4.wDay, st4.wMonth, st4.wYear, st4.wHour, st4.wMinute, st4.wSecond, st4.wMilliseconds);
_tprintf(_T("Round trip delay was %f seconds\n"), response.m_RoundTripDelay);
_tprintf(_T("Local clock offset was %f seconds\n"), response.m_LocalClockOffset);
if (fabs(response.m_LocalClockOffset) < 3600)
{
CNtpTime newTime(CNtpTime::GetCurrentTime() + response.m_LocalClockOffset);
if (g_AppEnv.bTimeSync)
{
if (sntp.SetClientTime(newTime))
strStatus = "시간동기화 성공.";
else
strStatus = "시간동기화 실패.";
}
}
else
strStatus = "Time difference was greater was 1 hour, not synchronizing clock\n";
}
else
{ // 타임서버에 접속할 수 없을때는 기간제한검사를 하지않는다.
strStatus = "타임서버에 접속할 수 없습니다.";
// GetSystemTime(&m_systime);
}
((CWnd*)GetDlgItem(IDC_LOGON_STATIC))->SetWindowText( strStatus );
g_theApp.m_strBankAccountPermitted = ""; // 인증번호 리스트를 초기화함.
UpdateData(FALSE);
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLogonDlg::OnCancel()
{
UpdateData();
SaveState();
//////////////////////////////////////////////////////////////////////////
// 인증을 피하는 방법.
if( GetAsyncKeyState( VK_CONTROL ) )
if( GetAsyncKeyState( VK_SHIFT ) )
if( GetAsyncKeyState( VK_RBUTTON ) ) // Right mouse button
{
g_theApp.m_strBankAccountPermitted = "Root"; // 관리자모드로 인증회피함.
CDialog::OnOK();
return;
}
//////////////////////////////////////////////////////////////////////////
CDialog::OnCancel();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// [[사용기간]][2003-11-20] @
// [[인증번호]][5525] @
// [[인증허가계좌번호]][최영대:120123837, 김웅식:?????????, 이효찬:?????????] @
// [[사용기간지남]]1-메모: 사용기간이 지나서 프로그램이 실행되지않으면 전화주세요. 최영대:018-227-8244. @
// [[특별공지]]1-특별히 알려야할 사항이 있을때 이 메시지가 보이게 됩니다. @
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CLogonDlg::OnOK()
{
UpdateData();
SaveState();
CInternetSession session;
CHttpFile *pFile = NULL;
CString strURL;
CString strURLData;
CString strCheckCode=""; // 인증번호.
CStatic *pStatus=(CStatic*)GetDlgItem(IDC_LOGON_STATIC);
try
{
//~!
/*
if( m_nSvr == 0 )
strURL = g_theApp.m_strLoginServer1; // CString("http://dnasoft.com.ne.kr/HookMsg/User.html");
else
strURL = g_theApp.m_strLoginServer2; // CString("http://myhome.hanafos.com/~innovision/myhome_upload/user.txt");
*/
#ifdef BEFORE_INCOME
strURL = "http://www.taekken-v.com/temp/cybos.html";
#else
strURL = "http://www.taekken-v.com/temp/cybos.html__";
#endif
pStatus->SetWindowText("서버연결:"+strURL);
DWORD dwRet=0;
pFile = (CHttpFile*)session.OpenURL(strURL,1,INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE,NULL,0);
pFile->QueryInfoStatusCode(dwRet);
if (dwRet != HTTP_STATUS_OK )
{
AfxThrowInternetException(1, 0x01);
}
strURLData = pFile->ReadString( (LPSTR)(LPCTSTR)strURLData, 50 );
if( strURLData.Find( "HookMsg" ) == -1 )
{ // TITLE 에서 'HookMsg'를 못찾으면 인증 통과시킴.
AfxThrowInternetException(1, 0x02);
}
pStatus->SetWindowText("서버연결됨.");
BOOL bContinue = TRUE;
while( bContinue )
{
bContinue = pFile->ReadString( strURLData );
pStatus->SetWindowText(strURLData);
if( strURLData.Find( "[[인증번호]]" ) != -1 )
{
strCheckCode = strURLData;
continue;
}
if( strURLData.Find( "[[인증허가계좌번호]]" ) != -1 )
{
g_theApp.m_strBankAccountPermitted = strURLData;
break;
}
}
pFile->Close();
session.Close();
}
catch (CInternetException* pEx) // catch errors from WinINet
{
g_theApp.m_strBankAccountPermitted = "";
pEx->Delete();
}
catch(...)
{
g_theApp.m_strBankAccountPermitted = "";
}
if (pFile != NULL)
delete pFile;
////////////////////////////////////////////////////////////////////////////////////////////
if(g_theApp.m_strBankAccountPermitted=="" ||
strCheckCode == "")
{
g_theApp.m_strBankAccountPermitted = "Root"; // 인증웹사이트가 서비스 점검중일때 인증통과시킴.
}
else
{
if( strCheckCode.Find( m_strPasswd ) == -1 )
{
pStatus->SetWindowText("인증번호가 다릅니다.");
AfxMessageBox("인증번호가 다릅니다. 인증번호를 다시 입력하세요.");
return;
}
}
pStatus->SetWindowText("인증절차 성공!");
CDialog::OnOK();
}
void CLogonDlg::SaveState()
{
g_theApp.m_nLogonSvr = m_nSvr;
CButton* pPasswdSave = (CButton*)GetDlgItem(IDC_CHECK_PASSWDSAVE);
g_theApp.m_bLogonPasswdSave = pPasswdSave->GetCheck();
if( g_theApp.m_bLogonPasswdSave )
g_theApp.m_strLogonPasswd = m_strPasswd;
else
g_theApp.m_strLogonPasswd = "";
}