OnlineUsersPage.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /****************************************************************/
  2. /* */
  3. /* OnlineUsersPage.cpp */
  4. /* */
  5. /* Implementation of the COnlineUsersPage class. */
  6. /* This class is a part of the FTP Server Application */
  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 "LYFZIPReceiveApp.h"
  17. #include "LYFZIPReceive.h"
  18. #include "OnlineUsersPage.h"
  19. #include "UserAccountsDlg.h"
  20. #include "ApplicationDlg.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. extern CLYFZIPReceive theServer;
  27. IMPLEMENT_DYNCREATE(COnlineUsersPage, CDialog)
  28. COnlineUsersPage::COnlineUsersPage() : CDialog(COnlineUsersPage::IDD)
  29. {
  30. //{{AFX_DATA_INIT(COnlineUsersPage)
  31. //}}AFX_DATA_INIT
  32. }
  33. COnlineUsersPage::~COnlineUsersPage()
  34. {
  35. }
  36. void COnlineUsersPage::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CDialog::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(COnlineUsersPage)
  40. DDX_Control(pDX, IDC_ONLINE_USERS, m_OnlineUsers);
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(COnlineUsersPage, CDialog)
  44. //{{AFX_MSG_MAP(COnlineUsersPage)
  45. ON_WM_SIZE()
  46. ON_WM_CONTEXTMENU()
  47. ON_COMMAND(IDC_KICK_USER, OnKickUser)
  48. ON_COMMAND(IDC_EDIT_USER, OnEditUserAccount)
  49. ON_COMMAND(IDC_BLOCK_IP, OnBlockIp)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /********************************************************************/
  53. /* */
  54. /* Function name : OnInitDialog */
  55. /* Description : Called by the framework in response to the */
  56. /* WM_INITDIALOG message. */
  57. /* */
  58. /********************************************************************/
  59. BOOL COnlineUsersPage::OnInitDialog()
  60. {
  61. CDialog::OnInitDialog();
  62. m_OnlineUsers.InsertColumn(0, "ThreadID");
  63. m_OnlineUsers.InsertColumn(1, "̞");
  64. m_OnlineUsers.InsertColumn(2, "IPµØÖ·");
  65. m_OnlineUsers.InsertColumn(3, "µÇ½ʱ¼ä");
  66. DWORD dwStyle = m_OnlineUsers.GetExtendedStyle();
  67. dwStyle |= LVS_EX_FULLROWSELECT;
  68. m_OnlineUsers.SetExtendedStyle(dwStyle);
  69. return TRUE;
  70. }
  71. /********************************************************************/
  72. /* */
  73. /* Function name : OnSize */
  74. /* Description : Handle WM_SIZE message */
  75. /* */
  76. /********************************************************************/
  77. void COnlineUsersPage::OnSize(UINT nType, int cx, int cy)
  78. {
  79. CDialog::OnSize(nType, cx, cy);
  80. if (IsWindow(::GetDlgItem(m_hWnd, IDC_ONLINE_USERS)))
  81. {
  82. CRect rect;
  83. GetClientRect(rect);
  84. m_OnlineUsers.MoveWindow(rect);
  85. m_OnlineUsers.SetColumnWidth(0, 0);
  86. m_OnlineUsers.SetColumnWidth(1, rect.Width()/3-2);
  87. m_OnlineUsers.SetColumnWidth(2, rect.Width()/3-2);
  88. m_OnlineUsers.SetColumnWidth(3, rect.Width()/3-2);
  89. }
  90. }
  91. /********************************************************************/
  92. /* */
  93. /* Function name : AddUser */
  94. /* Description : Add new connected user to list */
  95. /* */
  96. /********************************************************************/
  97. void COnlineUsersPage::AddUser(DWORD nThreadID, LPCTSTR lpszName, LPCTSTR lpszAddress)
  98. {
  99. CString strThreadID;
  100. strThreadID.Format("%d", nThreadID);
  101. LVFINDINFO info;
  102. info.flags = LVFI_PARTIAL|LVFI_STRING;
  103. info.psz = (LPCTSTR)strThreadID;
  104. int nIndex = m_OnlineUsers.FindItem(&info);
  105. if (nIndex == -1)
  106. {
  107. nIndex = m_OnlineUsers.InsertItem(0, strThreadID);
  108. }
  109. m_OnlineUsers.SetItemText(nIndex, 1, lpszName);
  110. m_OnlineUsers.SetItemText(nIndex, 2, lpszAddress);
  111. m_OnlineUsers.SetItemText(nIndex, 3, CTime::GetCurrentTime().Format("%H:%M:%S"));
  112. }
  113. /********************************************************************/
  114. /* */
  115. /* Function name : RemoveUser */
  116. /* Description : Remove disconnected user from list */
  117. /* */
  118. /********************************************************************/
  119. void COnlineUsersPage::RemoveUser(DWORD nThreadID)
  120. {
  121. LVFINDINFO info;
  122. CString strThreadID;
  123. strThreadID.Format("%d", nThreadID);
  124. info.flags = LVFI_PARTIAL|LVFI_STRING;
  125. info.psz = (LPCTSTR)strThreadID;
  126. int nIndex = m_OnlineUsers.FindItem(&info);
  127. if (nIndex != -1)
  128. {
  129. m_OnlineUsers.DeleteItem(nIndex);
  130. }
  131. }
  132. /********************************************************************/
  133. /* */
  134. /* Function name : OnContextMenu */
  135. /* Description : Show context menu */
  136. /* */
  137. /********************************************************************/
  138. void COnlineUsersPage::OnContextMenu(CWnd* pWnd, CPoint point)
  139. {
  140. // get selected user
  141. int nIndex = m_OnlineUsers.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  142. if(nIndex == -1)
  143. return;
  144. CMenu menu;
  145. menu.LoadMenu(MAKEINTRESOURCE(IDR_ONLINE_MENU));
  146. menu.GetSubMenu(0)->TrackPopupMenu(0, point.x, point.y, this, NULL);
  147. }
  148. /********************************************************************/
  149. /* */
  150. /* Function name : OnKickUser */
  151. /* Description : Close connection for this user(s) */
  152. /* */
  153. /********************************************************************/
  154. void COnlineUsersPage::OnKickUser()
  155. {
  156. int nIndex = m_OnlineUsers.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  157. while (nIndex != -1)
  158. {
  159. CString strThreadID = m_OnlineUsers.GetItemText(nIndex, 0);
  160. PostThreadMessage(atoi(strThreadID), WM_QUIT, 0 ,0);
  161. nIndex = m_OnlineUsers.GetNextItem(nIndex, LVNI_ALL | LVNI_SELECTED);
  162. }
  163. }
  164. /********************************************************************/
  165. /* */
  166. /* Function name : OnEditUserAccount */
  167. /* Description : Change user rights of selected user */
  168. /* */
  169. /********************************************************************/
  170. void COnlineUsersPage::OnEditUserAccount()
  171. {
  172. int nIndex = m_OnlineUsers.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  173. if (nIndex != -1)
  174. {
  175. CUserAccountsDlg dlg;
  176. theServer.m_UserManager.GetUserList(dlg.m_UserArray);
  177. dlg.m_strUserName = m_OnlineUsers.GetItemText(nIndex, 1);
  178. if (dlg.DoModal() == IDOK)
  179. {
  180. theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
  181. }
  182. }
  183. }
  184. /********************************************************************/
  185. /* */
  186. /* Function name : OnBlockIp */
  187. /* Description : Change user rights of selected user */
  188. /* */
  189. /********************************************************************/
  190. void COnlineUsersPage::OnBlockIp()
  191. {
  192. int nIndex = m_OnlineUsers.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  193. if (nIndex == -1)
  194. return;
  195. while (nIndex != -1)
  196. {
  197. CString strIP = m_OnlineUsers.GetItemText(nIndex, 2);
  198. ((CApplicationDlg *)GetParent())->m_SecurityPage.AddIPToBlockList(strIP);
  199. nIndex = m_OnlineUsers.GetNextItem(nIndex, LVNI_ALL | LVNI_SELECTED);
  200. }
  201. }