AclSet.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:10k
开发平台:

Visual C++

  1. // AclSet.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Property.h"
  5. #include "AclSet.h"
  6. //owner add
  7. #include "GuiRes.h"
  8. #include "NetTimeSheet.h"
  9. #include "SetNet.h"
  10. #include "SetTime.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. //=============================================================================================
  17. // CAclSet dialog
  18. extern CAclFile m_AclFile;
  19. CNetTimeSheet *dlgNetTimeSheet = NULL;
  20. CFileDialog *dlgFile = NULL;
  21. XACL CAclSet::m_tmpAcl;
  22. BOOL CAclSet::m_EnableComboApplication = TRUE;
  23. CString CAclSet::m_sPathName;
  24. CAclSet::CAclSet(CWnd* pParent /*=NULL*/)
  25. : CDialog(CAclSet::IDD, pParent)
  26. {
  27. //{{AFX_DATA_INIT(CAclSet)
  28. //}}AFX_DATA_INIT
  29. }
  30. void CAclSet::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CAclSet)
  34. DDX_Control(pDX, IDC_EDIT_MEMO, m_EditMemo);
  35. DDX_Control(pDX, IDC_EDIT_SERVICE_PORT, m_EditServicePort);
  36. DDX_Control(pDX, IDC_COMBO_DIRECTION, m_ComboDirection);
  37. DDX_Control(pDX, IDC_COMBO_ACCESS_TIME, m_ComboAccessTime);
  38. DDX_Control(pDX, IDC_COMBO_SERVICE_TYPE, m_ComboServiceType);
  39. DDX_Control(pDX, IDC_COMBO_ACTION, m_ComboAction);
  40. DDX_Control(pDX, IDC_COMBO_REMOTE_NET, m_ComboRemoteNet);
  41. DDX_Control(pDX, IDC_COMBO_APPLICATION, m_ComboApplication);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAclSet, CDialog)
  45. //{{AFX_MSG_MAP(CAclSet)
  46. ON_BN_CLICKED(IDC_BUTTON_NET, OnButtonNet)
  47. ON_BN_CLICKED(IDC_BUTTON_TIME, OnButtonTime)
  48. ON_BN_CLICKED(IDC_BUTTON_APPLICATION, OnButtonApplication)
  49. ON_CBN_SELCHANGE(IDC_COMBO_SERVICE_TYPE, OnSelchangeComboServiceType)
  50. ON_CBN_SELCHANGE(IDC_COMBO_APPLICATION, OnSelchangeComboApplication)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. //=============================================================================================
  54. // CAclSet message handlers
  55. void CAclSet::OnButtonNet() 
  56. {
  57. ShowNetTimeSheet(1);
  58. }
  59. void CAclSet::OnButtonTime() 
  60. {
  61. ShowNetTimeSheet(2);
  62. }
  63. void CAclSet::ShowNetTimeSheet(int nID)
  64. {
  65. int tmpNetIndex = m_ComboRemoteNet.GetCurSel();
  66. int tmpTimeIndex= m_ComboAccessTime.GetCurSel();
  67. dlgNetTimeSheet = new CNetTimeSheet(GUI_NET_TIME_SHEET_CAPTION);
  68. CSetNet mSetNet;
  69. CSetTime mSetTime;
  70. dlgNetTimeSheet->AddPage(&mSetNet);
  71. dlgNetTimeSheet->AddPage(&mSetTime);
  72. if(nID == 1)
  73. {
  74. dlgNetTimeSheet->SetActivePage(&mSetNet);
  75. m_ComboRemoteNet.GetWindowText(mSetNet.m_TreeText);
  76. }
  77. else if(nID == 2)
  78. {
  79. dlgNetTimeSheet->SetActivePage(&mSetTime);
  80. m_ComboAccessTime.GetWindowText(mSetTime.m_TreeText);
  81. }
  82. else
  83. return;
  84. int iRet = dlgNetTimeSheet->DoModal();
  85. delete dlgNetTimeSheet;
  86. dlgNetTimeSheet = NULL;
  87. if(iRet == IDCANCEL)
  88. return;
  89. if(tmpNetIndex != mSetNet.iTreeIndex)
  90. m_ComboRemoteNet.SetCurSel(mSetNet.iTreeIndex);
  91. if(tmpTimeIndex != mSetTime.m_iTreeIndex)
  92. m_ComboAccessTime.SetCurSel(mSetTime.m_iTreeIndex);
  93. }
  94. BOOL CAclSet::OnInitDialog() 
  95. {
  96. CDialog::OnInitDialog();
  97. SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
  98. InitDlgResource();
  99. if(!m_EnableComboApplication)
  100. {
  101. ModifyStyleEx(WS_EX_TOOLWINDOW, WS_EX_APPWINDOW); 
  102. ::SetWindowPos(this->m_hWnd,HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  103. }
  104. return TRUE;  
  105. }
  106. //---------------------------------------------------------------------------------------------
  107. //initialize dialog's resource
  108. void CAclSet::InitDlgResource()
  109. {
  110. SetWindowText(GUI_ACL_SET_CAPTION);
  111. SetDlgItemText(IDOK ,GUI_BUTTON_OK);
  112. SetDlgItemText(IDCANCEL ,GUI_BUTTON_CANCEL);
  113. SetDlgItemText(IDC_ACL_APPLICATION_LABLE ,GUI_ACL_APPLICATION_LABLE);
  114. SetDlgItemText(IDC_ACL_REMOTE_NET_LABLE ,GUI_ACL_REMOTE_NET_LABLE);
  115. SetDlgItemText(IDC_ACL_ACCESS_TIME_LABLE ,GUI_ACL_ACCESS_TIME_LABLE);
  116. SetDlgItemText(IDC_ACL_ACTION_LABLE ,GUI_ACL_ACTION_LABLE);
  117. SetDlgItemText(IDC_ACL_SUPER_SET_LABLE ,GUI_ACL_SUPER_SET_LABLE);
  118. SetDlgItemText(IDC_ACL_DERECTION_LABLE ,GUI_ACL_DERECTION_LABLE);
  119. SetDlgItemText(IDC_ACL_SERVICE_TYPE_LABLE ,GUI_ACL_SERVICE_TYPE_LABLE);
  120. SetDlgItemText(IDC_ACL_SERVICE_PORT_LABLE ,GUI_ACL_SERVICE_PORT_LABLE);
  121. SetDlgItemText(IDC_ACL_MEMO_LABLE ,GUI_ACL_MEMO_LABLE);
  122. m_ComboRemoteNet.InsertString(0, GUI_SET_NET_TREE_0);
  123. m_ComboRemoteNet.InsertString(1, GUI_SET_NET_TREE_1);
  124. m_ComboRemoteNet.InsertString(2, GUI_SET_NET_TREE_2);
  125. m_ComboRemoteNet.InsertString(3, GUI_SET_NET_TREE_3);
  126. m_ComboRemoteNet.InsertString(4, GUI_SET_NET_TREE_4);
  127. m_ComboAccessTime.InsertString(0, GUI_SET_TIME_TREE_0);
  128. m_ComboAccessTime.InsertString(1, GUI_SET_TIME_TREE_1);
  129. m_ComboAccessTime.InsertString(2, GUI_SET_TIME_TREE_2);
  130. m_ComboAccessTime.InsertString(3, GUI_SET_TIME_TREE_3);
  131. m_ComboAccessTime.InsertString(4, GUI_SET_TIME_TREE_4);
  132. m_ComboAccessTime.InsertString(5, GUI_SET_TIME_TREE_5);
  133. m_ComboAccessTime.InsertString(6, GUI_SET_TIME_TREE_6);
  134. m_ComboAction.InsertString(0, GUI_ACL_ACTION_0);
  135. m_ComboAction.InsertString(1, GUI_ACL_ACTION_1);
  136. m_ComboDirection.InsertString(0, GUI_ACL_DERECTION_0);
  137. m_ComboDirection.InsertString(1, GUI_ACL_DERECTION_1);
  138. m_ComboDirection.InsertString(2, GUI_ACL_DERECTION_2);
  139. m_ComboServiceType.InsertString(0, GUI_ACL_SERVICE_TYPE_0);
  140. m_ComboServiceType.InsertString(1, GUI_ACL_SERVICE_TYPE_1);
  141. m_ComboServiceType.InsertString(2, GUI_ACL_SERVICE_TYPE_2);
  142. m_ComboServiceType.InsertString(3, GUI_ACL_SERVICE_TYPE_3);
  143. m_ComboServiceType.InsertString(4, GUI_ACL_SERVICE_TYPE_4);
  144. m_ComboServiceType.InsertString(5, GUI_ACL_SERVICE_TYPE_5);
  145. m_ComboServiceType.InsertString(6, GUI_ACL_SERVICE_TYPE_6);
  146. m_ComboServiceType.InsertString(7, GUI_ACL_SERVICE_TYPE_7);
  147. m_ComboServiceType.InsertString(8, GUI_ACL_SERVICE_TYPE_8);
  148. int i, n = m_AclFile.mAclHeader.ulAclCount;
  149. for(i = 0; i < n; i++)
  150. {
  151. if(m_ComboApplication.FindString(0,m_AclFile.mpAcl[i].sApplication) != CB_ERR)
  152. continue;
  153. m_ComboApplication.InsertString(m_ComboApplication.GetCount(),m_AclFile.mpAcl[i].sApplication);
  154. }
  155. if(m_EnableComboApplication)
  156. {
  157. if(_tcscmp(m_tmpAcl.sApplication, _T("")) == 0)
  158. {
  159. SetDlgItemText(IDC_ACL_BASE_SET_LABLE, GUI_ACL_BASE_SET_LABLE);
  160. }
  161. else
  162. {
  163. SetDlgItemText(IDC_ACL_BASE_SET_LABLE, m_tmpAcl.sApplication);
  164. m_ComboApplication .SetWindowText(m_tmpAcl.sApplication);
  165. }
  166. }
  167. else
  168. {
  169. CString tmpStr;
  170. tmpStr.Format("%s %s", m_sPathName, GUI_ACL_QUERY_INFO);
  171. SetDlgItemText(IDC_ACL_BASE_SET_LABLE, tmpStr);
  172. m_ComboApplication .SetWindowText(m_sPathName);
  173. }
  174. GetDlgItem(IDC_BUTTON_APPLICATION)->EnableWindow(m_EnableComboApplication);
  175. m_ComboApplication .EnableWindow(m_EnableComboApplication);
  176. m_ComboRemoteNet .SetCurSel(m_tmpAcl.bRemoteNetType);
  177. m_ComboAccessTime .SetCurSel(m_tmpAcl.bAccessTimeType);
  178. m_ComboAction .SetCurSel(m_tmpAcl.bAction);
  179. m_ComboDirection .SetCurSel(m_tmpAcl.bDirection);
  180. m_ComboServiceType .SetCurSel(m_tmpAcl.bServiceType);
  181. OnSelchangeComboServiceType();
  182. CString tmpStr;
  183. tmpStr .Format(_T("%u"), m_tmpAcl.uiServicePort);
  184. m_EditServicePort .SetLimitText(5);
  185. m_EditServicePort .SetWindowText(tmpStr);
  186. m_EditMemo .SetLimitText(50);
  187. m_EditMemo .SetWindowText(m_tmpAcl.sMemo);
  188. }
  189. void CAclSet::OnButtonApplication() 
  190. {
  191. static TCHAR BASED_CODE szFilter[] = _T("(*.exe)|*.exe||");
  192. dlgFile =  new CFileDialog(TRUE,NULL,NULL,OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,szFilter);
  193. int iRet = dlgFile->DoModal();
  194. if(iRet == IDCANCEL)
  195. {
  196. delete dlgFile;
  197. dlgFile = NULL;
  198. return;
  199. }
  200. m_ComboApplication.SetWindowText(dlgFile->m_ofn.lpstrFile);
  201. delete  dlgFile;
  202. dlgFile = NULL;
  203. }
  204. void CAclSet::OnOK() 
  205. {
  206. CString tmpStrApp, tmpStrMemo, tmpStrPort;
  207. m_ComboApplication .GetWindowText(tmpStrApp);
  208. m_EditMemo .GetWindowText(tmpStrMemo);
  209. m_EditServicePort .GetWindowText(tmpStrPort);
  210. UINT tmpPort = _ttoi(tmpStrPort);
  211. if(tmpPort > 65535 || tmpPort < 0)
  212. {
  213. AfxMessageBox(GUI_ACL_MESSAGE_INAVALID_PORT);
  214. m_EditServicePort.SetFocus();
  215. return;
  216. }
  217. if( m_tmpAcl.bAccessTimeType== m_ComboAccessTime.GetCurSel() &&
  218. m_tmpAcl.bAction == m_ComboAction .GetCurSel() &&
  219. m_tmpAcl.bDirection == m_ComboDirection .GetCurSel() &&
  220. m_tmpAcl.bRemoteNetType == m_ComboRemoteNet .GetCurSel() &&
  221. m_tmpAcl.bServiceType == m_ComboServiceType.GetCurSel() &&
  222. m_tmpAcl.uiServicePort == tmpPort &&
  223. tmpStrApp.CompareNoCase(m_tmpAcl.sApplication) == 0 &&
  224. tmpStrMemo.Compare(m_tmpAcl.sMemo) == 0 )
  225. {
  226. CDialog::OnCancel();
  227. return;
  228. }
  229. if(tmpStrApp == "")
  230. {
  231. AfxMessageBox(GUI_ACL_MESSAGE_APP_PATH_ERROR);
  232. m_ComboApplication.SetFocus();
  233. return;
  234. }
  235. if((tmpStrApp.Right(1) == "\") || (tmpStrApp.Right(1) == ":"))
  236. {
  237. AfxMessageBox(GUI_ACL_MESSAGE_ONLY_PATH);
  238. m_ComboApplication.SetFocus();
  239. return;
  240. }
  241. if(_taccess(tmpStrApp,0) == -1)
  242. {
  243. AfxMessageBox(GUI_ACL_MESSAGE_APP_NOT_EXSITS);
  244. m_ComboApplication.SetFocus();
  245. return;
  246. }
  247. m_tmpAcl.bAccessTimeType= m_ComboAccessTime .GetCurSel();
  248. m_tmpAcl.bAction = m_ComboAction .GetCurSel();
  249. m_tmpAcl.bDirection = m_ComboDirection .GetCurSel();
  250. m_tmpAcl.bRemoteNetType = m_ComboRemoteNet .GetCurSel();
  251. m_tmpAcl.bServiceType = m_ComboServiceType.GetCurSel();
  252. m_tmpAcl.uiServicePort = tmpPort;
  253. _tcscpy(m_tmpAcl.sApplication, tmpStrApp);
  254. _tcscpy(m_tmpAcl.sMemo, tmpStrMemo);
  255. CDialog::OnOK();
  256. }
  257. void CAclSet::OnSelchangeComboServiceType() 
  258. {
  259. int iIndex = m_ComboServiceType.GetCurSel();
  260. UINT mPort = ACL_SERVICE_PORT_ALL;
  261. BOOL bEnable = TRUE;
  262. switch(iIndex)
  263. {
  264. case ACL_SERVICE_TYPE_ALL:
  265. bEnable = FALSE;
  266. break;
  267. case ACL_SERVICE_TYPE_TCP:
  268. break;
  269. case ACL_SERVICE_TYPE_UDP:
  270. break;
  271. case ACL_SERVICE_TYPE_FTP:
  272. mPort = ACL_SERVICE_PORT_FTP;
  273. bEnable = FALSE;
  274. break;
  275. case ACL_SERVICE_TYPE_TELNET:
  276. mPort = ACL_SERVICE_PORT_TELNET;
  277. bEnable = FALSE;
  278. break;
  279. case ACL_SERVICE_TYPE_HTTP:
  280. break;
  281. case ACL_SERVICE_TYPE_NNTP:
  282. mPort = ACL_SERVICE_PORT_NNTP;
  283. bEnable = FALSE;
  284. break;
  285. case ACL_SERVICE_TYPE_POP3:
  286. mPort = ACL_SERVICE_PORT_POP3;
  287. bEnable = FALSE;
  288. break;
  289. case ACL_SERVICE_TYPE_SMTP:
  290. mPort = ACL_SERVICE_PORT_SMTP;
  291. bEnable = FALSE;
  292. break;
  293. default:
  294. return;
  295. }
  296. CString tmpStr;
  297. tmpStr .Format(_T("%u"),mPort);
  298. m_EditServicePort.SetWindowText(tmpStr);
  299. m_EditServicePort.EnableWindow(bEnable);
  300. }
  301. void CAclSet::OnSelchangeComboApplication() 
  302. {
  303. CString tmpStr;
  304. m_ComboApplication.GetLBText(m_ComboApplication.GetCurSel(),tmpStr);
  305. SetDlgItemText(IDC_ACL_BASE_SET_LABLE, tmpStr);
  306. }