SecurityPage.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /****************************************************************/
  2. /* */
  3. /* SecurityPage.cpp */
  4. /* */
  5. /* Implementation of the CSecurityPage class. */
  6. /* This class is a part of the FTP Server. */
  7. /* */
  8. /* Programmed by LYFZ van der Meer */
  9. /* Copyright LYFZ Software Solutions 2002 */
  10. /* http://www.LYFZvandermeer.nl */
  11. /* */
  12. /* Last updated: 10 july 2002 */
  13. /* */
  14. /****************************************************************/
  15. #include "stdafx.h"
  16. #include "DBServer.h"
  17. #include "theDBServer.h"
  18. #include "SecurityPage.h"
  19. #include "AddIPDlg.h"
  20. #include "DBServerDlg.h"
  21. extern CtheDBServer theServer;
  22. #include "InputCode.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. CSecurityPage::CSecurityPage(CWnd* pParent /*=NULL*/)
  29. : CDialogResize(CSecurityPage::IDD, pParent)
  30. {
  31. //{{AFX_DATA_INIT(CSecurityPage)
  32. m_bBlockAll = FALSE;
  33. //}}AFX_DATA_INIT
  34. }
  35. void CSecurityPage::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CDialogResize::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CSecurityPage)
  39. DDX_Control(pDX, IDC_BLOCKEDLIST, m_BlockedList);
  40. DDX_Control(pDX, IDC_NONBLOCKEDLIST, m_NonBlockedList);
  41. DDX_Check(pDX, IDC_BLOCK_ALL, m_bBlockAll);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CSecurityPage, CDialogResize)
  45. //{{AFX_MSG_MAP(CSecurityPage)
  46. ON_BN_CLICKED(IDC_BLOCK_ALL, OnBlockAll)
  47. ON_WM_DESTROY()
  48. ON_BN_CLICKED(IDC_ADD_BLOCK, OnAddBlock)
  49. ON_BN_CLICKED(IDC_EDIT_BLOCK, OnEditBlock)
  50. ON_BN_CLICKED(IDC_ADD_NONBLOCK, OnAddNonblock)
  51. ON_BN_CLICKED(IDC_EDIT_NONBLOCK, OnEditNonblock)
  52. ON_BN_CLICKED(IDC_REMOVE_BLOCK, OnRemoveBlock)
  53. ON_BN_CLICKED(IDC_REMOVE_NONBLOCK, OnRemoveNonblock)
  54. ON_LBN_DBLCLK(IDC_BLOCKEDLIST, OnDblclkBlockedlist)
  55. ON_LBN_DBLCLK(IDC_NONBLOCKEDLIST, OnDblclkNonblockedlist)
  56. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  57. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  58. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  59. ON_BN_CLICKED(IDC_VIEW, OnView)
  60. ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
  61. ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. BEGIN_DLGRESIZE_MAP(CSecurityPage)
  65. DLGRESIZE_CONTROL(IDC_BLOCKEDLIST, DLSZ_SIZE_X)
  66. DLGRESIZE_CONTROL(IDC_NONBLOCKEDLIST, DLSZ_SIZE_X)
  67. END_DLGRESIZE_MAP()
  68. /********************************************************************/
  69. /* */
  70. /* Function name : OnInitDialog */
  71. /* Description : Initialize dialog */
  72. /* */
  73. /********************************************************************/
  74. BOOL CSecurityPage::OnInitDialog()
  75. {
  76. CDialogResize::OnInitDialog();
  77. if(g_bReg)GetDlgItem(IDC_VIEW)->EnableWindow(0);
  78. #ifdef CHILD_VERSION
  79. GetDlgItem(IDC_BUTTON6)->ShowWindow(SW_HIDE);
  80. #endif
  81. InitResizing(FALSE, FALSE, WS_CLIPCHILDREN);
  82. m_bBlockAll = AfxGetApp()->GetProfileInt("Settings", "BlockAll", 0);
  83. GetDlgItem(IDC_NONBLOCKEDLIST)->EnableWindow(m_bBlockAll);
  84. GetDlgItem(IDC_ADD_NONBLOCK)->EnableWindow(m_bBlockAll);
  85. GetDlgItem(IDC_EDIT_NONBLOCK)->EnableWindow(m_bBlockAll);
  86. GetDlgItem(IDC_REMOVE_NONBLOCK)->EnableWindow(m_bBlockAll);
  87. GetDlgItem(IDC_BLOCKEDLIST)->EnableWindow(!m_bBlockAll);
  88. GetDlgItem(IDC_ADD_BLOCK)->EnableWindow(!m_bBlockAll);
  89. GetDlgItem(IDC_EDIT_BLOCK)->EnableWindow(!m_bBlockAll);
  90. GetDlgItem(IDC_REMOVE_BLOCK)->EnableWindow(!m_bBlockAll);
  91. GetDlgItem(IDC_STATIC1)->EnableWindow(!m_bBlockAll);
  92. UpdateData(FALSE);
  93. CStringArray strArray;
  94. theServer.m_SecurityManager.GetBlockedList(strArray);
  95. for (int i=0; i < strArray.GetSize(); i++)
  96. {
  97. m_BlockedList.AddString(strArray[i]);
  98. }
  99. theServer.m_SecurityManager.GetNonBlockedList(strArray);
  100. for (int j=0; j < strArray.GetSize(); j++)
  101. {
  102. m_NonBlockedList.AddString(strArray[j]);
  103. }
  104. // get list of all ip addresses in use by this system (only show first two...)
  105. char szHostName[128];
  106. HOSTENT *lpHost=NULL;
  107. struct sockaddr_in sock;
  108. gethostname(szHostName, sizeof(szHostName));
  109. lpHost = gethostbyname(szHostName);
  110. if (lpHost != NULL)
  111. {
  112. for(int i=0; lpHost->h_addr_list[i] != NULL ;i++)
  113. {
  114. memcpy(&(sock.sin_addr), lpHost->h_addr_list[i], lpHost->h_length);
  115. if (i == 0)
  116. {
  117. SetDlgItemText(IDC_IPADDRESS1, inet_ntoa(sock.sin_addr));
  118. }
  119. else
  120. if (i == 1)
  121. {
  122. SetDlgItemText(IDC_IPADDRESS2, inet_ntoa(sock.sin_addr));
  123. }
  124. }
  125. }
  126. return TRUE;
  127. }
  128. /********************************************************************/
  129. /* */
  130. /* Function name : OnDestroy */
  131. /* Description : Dialog is about to be destroyed. */
  132. /* */
  133. /********************************************************************/
  134. void CSecurityPage::OnDestroy()
  135. {
  136. UpdateData();
  137. AfxGetApp()->WriteProfileInt("Settings", "BlockAll", m_bBlockAll);
  138. CDialogResize::OnDestroy();
  139. }
  140. /********************************************************************/
  141. /* */
  142. /* Function name : OnBlockAll */
  143. /* Description : Block all except... has been clicked. */
  144. /* */
  145. /********************************************************************/
  146. void CSecurityPage::OnBlockAll()
  147. {
  148. UpdateData();
  149. GetDlgItem(IDC_NONBLOCKEDLIST)->EnableWindow(m_bBlockAll);
  150. GetDlgItem(IDC_ADD_NONBLOCK)->EnableWindow(m_bBlockAll);
  151. GetDlgItem(IDC_EDIT_NONBLOCK)->EnableWindow(m_bBlockAll);
  152. GetDlgItem(IDC_REMOVE_NONBLOCK)->EnableWindow(m_bBlockAll);
  153. GetDlgItem(IDC_BLOCKEDLIST)->EnableWindow(!m_bBlockAll);
  154. GetDlgItem(IDC_ADD_BLOCK)->EnableWindow(!m_bBlockAll);
  155. GetDlgItem(IDC_EDIT_BLOCK)->EnableWindow(!m_bBlockAll);
  156. GetDlgItem(IDC_REMOVE_BLOCK)->EnableWindow(!m_bBlockAll);
  157. GetDlgItem(IDC_STATIC1)->EnableWindow(!m_bBlockAll);
  158. theServer.SetSecurityMode(!m_bBlockAll);
  159. }
  160. /********************************************************************/
  161. /* */
  162. /* Function name : OnAddBlock */
  163. /* Description : Add IP address to blocked list. */
  164. /* */
  165. /********************************************************************/
  166. void CSecurityPage::OnAddBlock()
  167. {
  168. CAddIPDlg dlg;
  169. if (dlg.DoModal() == IDOK)
  170. {
  171. for (int i=0; i < m_BlockedList.GetCount(); i++)
  172. {
  173. CString strText;
  174. m_BlockedList.GetText(i, strText);
  175. if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
  176. {
  177. // already exists !
  178. return;
  179. }
  180. }
  181. int nIndex = m_BlockedList.AddString(dlg.m_strIPaddress);
  182. m_BlockedList.SetCurSel(nIndex);
  183. UpdateSecurityData(0);
  184. }
  185. }
  186. /********************************************************************/
  187. /* */
  188. /* Function name : OnEditBlock */
  189. /* Description : Edit IP address from blocked list. */
  190. /* */
  191. /********************************************************************/
  192. void CSecurityPage::OnEditBlock()
  193. {
  194. int nIndex = m_BlockedList.GetCurSel();
  195. if (nIndex == -1)
  196. return;
  197. CAddIPDlg dlg;
  198. dlg.m_strTitle = "Edit IP address";
  199. m_BlockedList.GetText(nIndex, dlg.m_strIPaddress);
  200. if (dlg.DoModal() == IDOK)
  201. {
  202. for (int i=0; i < m_BlockedList.GetCount(); i++)
  203. {
  204. CString strText;
  205. m_BlockedList.GetText(i, strText);
  206. if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
  207. {
  208. // already exists !
  209. return;
  210. }
  211. }
  212. m_BlockedList.DeleteString(nIndex);
  213. nIndex = m_BlockedList.AddString(dlg.m_strIPaddress);
  214. m_BlockedList.SetCurSel(nIndex);
  215. UpdateSecurityData(0);
  216. }
  217. }
  218. /********************************************************************/
  219. /* */
  220. /* Function name : OnRemoveBlock */
  221. /* Description : Remove IP address from blocked list. */
  222. /* */
  223. /********************************************************************/
  224. void CSecurityPage::OnRemoveBlock()
  225. {
  226. int nIndex = m_BlockedList.GetCurSel();
  227. if (nIndex == -1)
  228. return;
  229. m_BlockedList.DeleteString(nIndex);
  230. m_BlockedList.SetCurSel(0);
  231. UpdateSecurityData(0);
  232. }
  233. /********************************************************************/
  234. /* */
  235. /* Function name : OnAddNonblock */
  236. /* Description : Add IP address to non-blocked list. */
  237. /* */
  238. /********************************************************************/
  239. void CSecurityPage::OnAddNonblock()
  240. {
  241. CAddIPDlg dlg;
  242. if (dlg.DoModal() == IDOK)
  243. {
  244. for (int i=0; i < m_NonBlockedList.GetCount(); i++)
  245. {
  246. CString strText;
  247. m_NonBlockedList.GetText(i, strText);
  248. if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
  249. {
  250. // already exists !
  251. return;
  252. }
  253. }
  254. int nIndex = m_NonBlockedList.AddString(dlg.m_strIPaddress);
  255. m_NonBlockedList.SetCurSel(nIndex);
  256. UpdateSecurityData(1);
  257. }
  258. }
  259. /********************************************************************/
  260. /* */
  261. /* Function name : OnEditNonblock */
  262. /* Description : Edit IP address from non-blocked list. */
  263. /* */
  264. /********************************************************************/
  265. void CSecurityPage::OnEditNonblock()
  266. {
  267. int nIndex = m_NonBlockedList.GetCurSel();
  268. if (nIndex == -1)
  269. return;
  270. CAddIPDlg dlg;
  271. dlg.m_strTitle = "Edit IP address";
  272. m_NonBlockedList.GetText(nIndex, dlg.m_strIPaddress);
  273. if (dlg.DoModal() == IDOK)
  274. {
  275. for (int i=0; i < m_NonBlockedList.GetCount(); i++)
  276. {
  277. CString strText;
  278. m_NonBlockedList.GetText(i, strText);
  279. if (strText.CompareNoCase(dlg.m_strIPaddress) == 0)
  280. {
  281. // already exists !
  282. return;
  283. }
  284. }
  285. m_NonBlockedList.DeleteString(nIndex);
  286. nIndex = m_NonBlockedList.AddString(dlg.m_strIPaddress);
  287. m_NonBlockedList.SetCurSel(nIndex);
  288. UpdateSecurityData(1);
  289. }
  290. }
  291. /********************************************************************/
  292. /* */
  293. /* Function name : OnRemoveNonblock */
  294. /* Description : Remove IP address from non-blocked list. */
  295. /* */
  296. /********************************************************************/
  297. void CSecurityPage::OnRemoveNonblock()
  298. {
  299. int nIndex = m_NonBlockedList.GetCurSel();
  300. if (nIndex == -1)
  301. return;
  302. m_NonBlockedList.DeleteString(nIndex);
  303. m_NonBlockedList.SetCurSel(0);
  304. UpdateSecurityData(1);
  305. }
  306. /********************************************************************/
  307. /* */
  308. /* Function name : UpdateSecurityData */
  309. /* Description : Update security data. */
  310. /* */
  311. /********************************************************************/
  312. void CSecurityPage::UpdateSecurityData(int nType)
  313. {
  314. CStringArray strArray;
  315. if (nType == 0)
  316. {
  317. for (int i=0; i < m_BlockedList.GetCount(); i++)
  318. {
  319. CString strText;
  320. m_BlockedList.GetText(i, strText);
  321. strArray.Add(strText);
  322. }
  323. theServer.m_SecurityManager.UpdateBlockedList(strArray);
  324. }
  325. else
  326. {
  327. for (int i=0; i < m_NonBlockedList.GetCount(); i++)
  328. {
  329. CString strText;
  330. m_NonBlockedList.GetText(i, strText);
  331. strArray.Add(strText);
  332. }
  333. theServer.m_SecurityManager.UpdateNonBlockedList(strArray);
  334. }
  335. }
  336. /********************************************************************/
  337. /* */
  338. /* Function name : AddIPToBlockList */
  339. /* Description : Add IP address to blocked list. */
  340. /* */
  341. /********************************************************************/
  342. void CSecurityPage::AddIPToBlockList(LPCTSTR lpszIP)
  343. {
  344. for (int i=0; i < m_BlockedList.GetCount(); i++)
  345. {
  346. CString strText;
  347. m_BlockedList.GetText(i, strText);
  348. if (strText.CompareNoCase(lpszIP) == 0)
  349. {
  350. // already exists !
  351. return;
  352. }
  353. }
  354. int nIndex = m_BlockedList.AddString(lpszIP);
  355. m_BlockedList.SetCurSel(nIndex);
  356. UpdateSecurityData(0);
  357. }
  358. /********************************************************************/
  359. /* */
  360. /* Function name : OnDblclkBlockedlist */
  361. /* Description : Edit IP address from blocked list. */
  362. /* */
  363. /********************************************************************/
  364. void CSecurityPage::OnDblclkBlockedlist()
  365. {
  366. OnEditBlock();
  367. }
  368. /********************************************************************/
  369. /* */
  370. /* Function name : OnDblclkNonblockedlist */
  371. /* Description : Edit IP address from non-blocked list. */
  372. /* */
  373. /********************************************************************/
  374. void CSecurityPage::OnDblclkNonblockedlist()
  375. {
  376. OnEditNonblock();
  377. }
  378. BOOL g_bConvertHisAll=0;
  379. extern CDBServerDlg *g_pMainWnd;
  380. void CSecurityPage::OnButton1()
  381. {
  382. // TODO: Add your control notification handler code here
  383. if(AfxMessageBox("温馨提示:此操作可能需要1-N小时, 应该在晚间无人操作软件时进行, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  384. g_bConvertHisAll=1;
  385. g_pMainWnd->CheckHistoryData();
  386. }
  387. void CSecurityPage::OnButton4()
  388. {
  389. // TODO: Add your control notification handler code here
  390. g_pMainWnd->MyExecuteSQL(&g_db, "delete from singleincomemoney where id in(select id from singleincome where sale2type='' or sale2type is null)");
  391. g_pMainWnd->MyExecuteSQL(&g_db, "delete from [singleincomemoney] where [paytype]='' or [paytype] is null");
  392. AfxMessageBox("命令已执行");
  393. }
  394. void CSecurityPage::OnButton5()
  395. {
  396. // TODO: Add your control notification handler code here
  397. g_pMainWnd->MyExecuteSQL(&g_db, "update dindanjd set bookingdate=date where bookingdate is null");
  398. g_pMainWnd->MyExecuteSQL(&g_db, "update dindanjd set bookingdate=(select time2 from dindan where dindanjd.id=dindan.id) where bookingdate is null");
  399. g_pMainWnd->MyExecuteSQL(&g_db, "update dindanjd set bookingdate=(select time2 from dindan where dindanjd.id=dindan.id) where bookingdate='' ");
  400. AfxMessageBox("命令已执行");
  401. }
  402. BOOL CSecurityPage::PreTranslateMessage(MSG* pMsg)
  403. {
  404. // TODO: Add your specialized code here and/or call the base class
  405. if(pMsg->message==WM_KEYDOWN)
  406. {
  407. switch (pMsg->wParam)
  408. {
  409. default:
  410. break;
  411. }
  412. }
  413. return CDialogResize::PreTranslateMessage(pMsg);
  414. }
  415. void CSecurityPage::OnView()
  416. {
  417. // TODO: Add your control notification handler code here
  418. InputCode dlg;
  419. dlg.DoModal ();
  420. }
  421. void CSecurityPage::OnButton6()
  422. {
  423. // TODO: Add your control notification handler code here
  424. g_pMainWnd->RestoreHQ();
  425. }
  426. //insert into client(id,name1,name2) select id,name1,name2 FROM dindan where id not in(select [id] from [db].[dbo].[client])
  427. void CSecurityPage::OnButton7()
  428. {
  429. // TODO: Add your control notification handler code here
  430. g_pMainWnd->ManagePhoto();
  431. }