123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- /****************************************************************/
- /* */
- /* SecurityPage.cpp */
- /* */
- /* Implementation of the CSecurityPage class. */
- /* This class is a part of the FTP Server. */
- /* */
- /* Programmed by LYFZ van der Meer */
- /* Copyright LYFZ Software Solutions 2002 */
- /* http://www.LYFZvandermeer.nl */
- /* */
- /* Last updated: 10 july 2002 */
- /* */
- /****************************************************************/
- #include "stdafx.h"
- #include "DBServer.h"
- #include "theDBServer.h"
- #include "SecurityPage.h"
- #include "AddIPDlg.h"
- #include "DBServerDlg.h"
- extern CtheDBServer theServer;
- #include "InputCode.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CSecurityPage::CSecurityPage(CWnd* pParent /*=NULL*/)
- : CDialogResize(CSecurityPage::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSecurityPage)
- m_bBlockAll = FALSE;
- //}}AFX_DATA_INIT
- }
- void CSecurityPage::DoDataExchange(CDataExchange* pDX)
- {
- CDialogResize::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSecurityPage)
- DDX_Control(pDX, IDC_BLOCKEDLIST, m_BlockedList);
- DDX_Control(pDX, IDC_NONBLOCKEDLIST, m_NonBlockedList);
- DDX_Check(pDX, IDC_BLOCK_ALL, m_bBlockAll);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSecurityPage, CDialogResize)
- //{{AFX_MSG_MAP(CSecurityPage)
- ON_BN_CLICKED(IDC_BLOCK_ALL, OnBlockAll)
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDC_ADD_BLOCK, OnAddBlock)
- ON_BN_CLICKED(IDC_EDIT_BLOCK, OnEditBlock)
- ON_BN_CLICKED(IDC_ADD_NONBLOCK, OnAddNonblock)
- ON_BN_CLICKED(IDC_EDIT_NONBLOCK, OnEditNonblock)
- ON_BN_CLICKED(IDC_REMOVE_BLOCK, OnRemoveBlock)
- ON_BN_CLICKED(IDC_REMOVE_NONBLOCK, OnRemoveNonblock)
- ON_LBN_DBLCLK(IDC_BLOCKEDLIST, OnDblclkBlockedlist)
- ON_LBN_DBLCLK(IDC_NONBLOCKEDLIST, OnDblclkNonblockedlist)
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
- ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
- ON_BN_CLICKED(IDC_VIEW, OnView)
- ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
- ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BEGIN_DLGRESIZE_MAP(CSecurityPage)
- DLGRESIZE_CONTROL(IDC_BLOCKEDLIST, DLSZ_SIZE_X)
- DLGRESIZE_CONTROL(IDC_NONBLOCKEDLIST, DLSZ_SIZE_X)
- END_DLGRESIZE_MAP()
- /********************************************************************/
- /* */
- /* Function name : OnInitDialog */
- /* Description : Initialize dialog */
- /* */
- /********************************************************************/
- BOOL CSecurityPage::OnInitDialog()
- {
- CDialogResize::OnInitDialog();
- if(g_bReg)GetDlgItem(IDC_VIEW)->EnableWindow(0);
- #ifdef CHILD_VERSION
- GetDlgItem(IDC_BUTTON6)->ShowWindow(SW_HIDE);
- #endif
- InitResizing(FALSE, FALSE, WS_CLIPCHILDREN);
- m_bBlockAll = AfxGetApp()->GetProfileInt("Settings", "BlockAll", 0);
- GetDlgItem(IDC_NONBLOCKEDLIST)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_ADD_NONBLOCK)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_EDIT_NONBLOCK)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_REMOVE_NONBLOCK)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_BLOCKEDLIST)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_ADD_BLOCK)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_EDIT_BLOCK)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_REMOVE_BLOCK)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_STATIC1)->EnableWindow(!m_bBlockAll);
- UpdateData(FALSE);
- CStringArray strArray;
- theServer.m_SecurityManager.GetBlockedList(strArray);
- for (int i=0; i < strArray.GetSize(); i++)
- {
- m_BlockedList.AddString(strArray[i]);
- }
- theServer.m_SecurityManager.GetNonBlockedList(strArray);
- for (int j=0; j < strArray.GetSize(); j++)
- {
- m_NonBlockedList.AddString(strArray[j]);
- }
- // get list of all ip addresses in use by this system (only show first two...)
- char szHostName[128];
- HOSTENT *lpHost=NULL;
- struct sockaddr_in sock;
- gethostname(szHostName, sizeof(szHostName));
- lpHost = gethostbyname(szHostName);
- if (lpHost != NULL)
- {
- for(int i=0; lpHost->h_addr_list[i] != NULL ;i++)
- {
- memcpy(&(sock.sin_addr), lpHost->h_addr_list[i], lpHost->h_length);
- if (i == 0)
- {
- SetDlgItemText(IDC_IPADDRESS1, inet_ntoa(sock.sin_addr));
- }
- else
- if (i == 1)
- {
- SetDlgItemText(IDC_IPADDRESS2, inet_ntoa(sock.sin_addr));
- }
- }
- }
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name : OnDestroy */
- /* Description : Dialog is about to be destroyed. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnDestroy()
- {
- UpdateData();
- AfxGetApp()->WriteProfileInt("Settings", "BlockAll", m_bBlockAll);
- CDialogResize::OnDestroy();
- }
- /********************************************************************/
- /* */
- /* Function name : OnBlockAll */
- /* Description : Block all except... has been clicked. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnBlockAll()
- {
- UpdateData();
-
- GetDlgItem(IDC_NONBLOCKEDLIST)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_ADD_NONBLOCK)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_EDIT_NONBLOCK)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_REMOVE_NONBLOCK)->EnableWindow(m_bBlockAll);
- GetDlgItem(IDC_BLOCKEDLIST)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_ADD_BLOCK)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_EDIT_BLOCK)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_REMOVE_BLOCK)->EnableWindow(!m_bBlockAll);
- GetDlgItem(IDC_STATIC1)->EnableWindow(!m_bBlockAll);
- theServer.SetSecurityMode(!m_bBlockAll);
- }
- /********************************************************************/
- /* */
- /* Function name : OnAddBlock */
- /* Description : Add IP address to blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnAddBlock()
- {
- CAddIPDlg dlg;
- if (dlg.DoModal() == IDOK)
- {
- for (int i=0; i < m_BlockedList.GetCount(); i++)
- {
- CString strText;
- m_BlockedList.GetText(i, strText);
- if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
- {
- // already exists !
- return;
- }
- }
- int nIndex = m_BlockedList.AddString(dlg.m_strIPaddress);
- m_BlockedList.SetCurSel(nIndex);
-
- UpdateSecurityData(0);
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnEditBlock */
- /* Description : Edit IP address from blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnEditBlock()
- {
- int nIndex = m_BlockedList.GetCurSel();
- if (nIndex == -1)
- return;
- CAddIPDlg dlg;
- dlg.m_strTitle = "Edit IP address";
- m_BlockedList.GetText(nIndex, dlg.m_strIPaddress);
- if (dlg.DoModal() == IDOK)
- {
- for (int i=0; i < m_BlockedList.GetCount(); i++)
- {
- CString strText;
- m_BlockedList.GetText(i, strText);
- if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
- {
- // already exists !
- return;
- }
- }
- m_BlockedList.DeleteString(nIndex);
- nIndex = m_BlockedList.AddString(dlg.m_strIPaddress);
- m_BlockedList.SetCurSel(nIndex);
-
- UpdateSecurityData(0);
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnRemoveBlock */
- /* Description : Remove IP address from blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnRemoveBlock()
- {
- int nIndex = m_BlockedList.GetCurSel();
- if (nIndex == -1)
- return;
- m_BlockedList.DeleteString(nIndex);
- m_BlockedList.SetCurSel(0);
- UpdateSecurityData(0);
- }
- /********************************************************************/
- /* */
- /* Function name : OnAddNonblock */
- /* Description : Add IP address to non-blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnAddNonblock()
- {
- CAddIPDlg dlg;
- if (dlg.DoModal() == IDOK)
- {
- for (int i=0; i < m_NonBlockedList.GetCount(); i++)
- {
- CString strText;
- m_NonBlockedList.GetText(i, strText);
- if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
- {
- // already exists !
- return;
- }
- }
- int nIndex = m_NonBlockedList.AddString(dlg.m_strIPaddress);
- m_NonBlockedList.SetCurSel(nIndex);
- UpdateSecurityData(1);
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnEditNonblock */
- /* Description : Edit IP address from non-blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnEditNonblock()
- {
- int nIndex = m_NonBlockedList.GetCurSel();
- if (nIndex == -1)
- return;
- CAddIPDlg dlg;
- dlg.m_strTitle = "Edit IP address";
- m_NonBlockedList.GetText(nIndex, dlg.m_strIPaddress);
- if (dlg.DoModal() == IDOK)
- {
- for (int i=0; i < m_NonBlockedList.GetCount(); i++)
- {
- CString strText;
- m_NonBlockedList.GetText(i, strText);
- if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
- {
- // already exists !
- return;
- }
- }
- m_NonBlockedList.DeleteString(nIndex);
- nIndex = m_NonBlockedList.AddString(dlg.m_strIPaddress);
- m_NonBlockedList.SetCurSel(nIndex);
- UpdateSecurityData(1);
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnRemoveNonblock */
- /* Description : Remove IP address from non-blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnRemoveNonblock()
- {
- int nIndex = m_NonBlockedList.GetCurSel();
- if (nIndex == -1)
- return;
- m_NonBlockedList.DeleteString(nIndex);
- m_NonBlockedList.SetCurSel(0);
- UpdateSecurityData(1);
- }
- /********************************************************************/
- /* */
- /* Function name : UpdateSecurityData */
- /* Description : Update security data. */
- /* */
- /********************************************************************/
- void CSecurityPage::UpdateSecurityData(int nType)
- {
- CStringArray strArray;
- if (nType == 0)
- {
- for (int i=0; i < m_BlockedList.GetCount(); i++)
- {
- CString strText;
- m_BlockedList.GetText(i, strText);
- strArray.Add(strText);
- }
- theServer.m_SecurityManager.UpdateBlockedList(strArray);
- }
- else
- {
- for (int i=0; i < m_NonBlockedList.GetCount(); i++)
- {
- CString strText;
- m_NonBlockedList.GetText(i, strText);
- strArray.Add(strText);
- }
- theServer.m_SecurityManager.UpdateNonBlockedList(strArray);
- }
- }
- /********************************************************************/
- /* */
- /* Function name : AddIPToBlockList */
- /* Description : Add IP address to blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::AddIPToBlockList(LPCTSTR lpszIP)
- {
- for (int i=0; i < m_BlockedList.GetCount(); i++)
- {
- CString strText;
- m_BlockedList.GetText(i, strText);
- if (strText.CompareNoCase(lpszIP) == 0)
- {
- // already exists !
- return;
- }
- }
- int nIndex = m_BlockedList.AddString(lpszIP);
- m_BlockedList.SetCurSel(nIndex);
-
- UpdateSecurityData(0);
- }
- /********************************************************************/
- /* */
- /* Function name : OnDblclkBlockedlist */
- /* Description : Edit IP address from blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnDblclkBlockedlist()
- {
- OnEditBlock();
- }
- /********************************************************************/
- /* */
- /* Function name : OnDblclkNonblockedlist */
- /* Description : Edit IP address from non-blocked list. */
- /* */
- /********************************************************************/
- void CSecurityPage::OnDblclkNonblockedlist()
- {
- OnEditNonblock();
- }
- BOOL g_bConvertHisAll=0;
- extern CDBServerDlg *g_pMainWnd;
- void CSecurityPage::OnButton1()
- {
- // TODO: Add your control notification handler code here
- if(AfxMessageBox("温馨提示:此操作可能需要1-N小时, 应该在晚间无人操作软件时进行, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- g_bConvertHisAll=1;
- g_pMainWnd->CheckHistoryData();
- }
- void CSecurityPage::OnButton4()
- {
- // TODO: Add your control notification handler code here
- g_pMainWnd->MyExecuteSQL(&g_db, "delete from singleincomemoney where id in(select id from singleincome where sale2type='' or sale2type is null)");
- g_pMainWnd->MyExecuteSQL(&g_db, "delete from [singleincomemoney] where [paytype]='' or [paytype] is null");
- AfxMessageBox("命令已执行");
- }
- void CSecurityPage::OnButton5()
- {
- // TODO: Add your control notification handler code here
- g_pMainWnd->MyExecuteSQL(&g_db, "update dindanjd set bookingdate=date where bookingdate is null");
- g_pMainWnd->MyExecuteSQL(&g_db, "update dindanjd set bookingdate=(select time2 from dindan where dindanjd.id=dindan.id) where bookingdate is null");
- g_pMainWnd->MyExecuteSQL(&g_db, "update dindanjd set bookingdate=(select time2 from dindan where dindanjd.id=dindan.id) where bookingdate='' ");
- AfxMessageBox("命令已执行");
- }
-
- BOOL CSecurityPage::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(pMsg->message==WM_KEYDOWN)
- {
- switch (pMsg->wParam)
- {
- default:
- break;
- }
- }
- return CDialogResize::PreTranslateMessage(pMsg);
- }
- void CSecurityPage::OnView()
- {
- // TODO: Add your control notification handler code here
- InputCode dlg;
- dlg.DoModal ();
- }
- void CSecurityPage::OnButton6()
- {
- // TODO: Add your control notification handler code here
- g_pMainWnd->RestoreHQ();
- }
- //insert into client(id,name1,name2) select id,name1,name2 FROM dindan where id not in(select [id] from [db].[dbo].[client])
- void CSecurityPage::OnButton7()
- {
- // TODO: Add your control notification handler code here
- g_pMainWnd->ManagePhoto();
- }
|