Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

437 lines
15 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #include "private.h"
  4. #include "PortsPage.h"
  5. #include "ClusterPortsDlg.h"
  6. BEGIN_MESSAGE_MAP(ClusterPortsDlg, CDialog)
  7. ON_BN_CLICKED(IDC_RADIO_DISABLED, OnRadioDisabled)
  8. ON_BN_CLICKED(IDC_RADIO_MULTIPLE, OnRadioMultiple)
  9. ON_BN_CLICKED(IDC_CHECK_PORT_RULE_ALL_VIP, OnCheckAllVIP)
  10. ON_BN_CLICKED(IDC_RADIO_SINGLE, OnRadioSingle)
  11. ON_WM_HELPINFO()
  12. ON_WM_CONTEXTMENU()
  13. END_MESSAGE_MAP()
  14. ClusterPortsDlg::ClusterPortsDlg( PortsPage::PortData& portData,
  15. CWnd* parent,
  16. const int& index
  17. )
  18. :
  19. m_portData( portData ),
  20. CDialog( ClusterPortsDlg::IDD, parent ),
  21. m_index( index )
  22. {
  23. m_parent = (PortsPage *) parent;
  24. }
  25. void
  26. ClusterPortsDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange( pDX );
  29. DDX_Control(pDX, IDC_EDIT_PORT_RULE_VIP, ipAddress);
  30. }
  31. BOOL
  32. ClusterPortsDlg::OnInitDialog()
  33. {
  34. CDialog::OnInitDialog();
  35. SetControlData();
  36. return TRUE;
  37. }
  38. void
  39. ClusterPortsDlg::OnOK()
  40. {
  41. PortsPage::PortData portData;
  42. //
  43. // get port information.
  44. //
  45. BOOL fError;
  46. long start_port = ::GetDlgItemInt (m_hWnd, IDC_EDIT_START, &fError, FALSE);
  47. if( fError == FALSE )
  48. {
  49. // some problem with the data input.
  50. // it has been left blank.
  51. wchar_t buffer[Common::BUF_SIZE];
  52. StringCbPrintf( buffer, sizeof(buffer), GETRESOURCEIDSTRING( IDS_PARM_PORT_BLANK ), CVY_MIN_PORT,CVY_MAX_PORT );
  53. MessageBox( buffer,
  54. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  55. MB_ICONSTOP | MB_OK );
  56. return;
  57. }
  58. wchar_t buf[Common::BUF_SIZE];
  59. StringCbPrintf( buf, sizeof(buf), L"%d", start_port );
  60. portData.start_port = buf;
  61. long end_port = ::GetDlgItemInt (m_hWnd, IDC_EDIT_END, &fError, FALSE);
  62. if( fError == FALSE )
  63. {
  64. // some problem with the data input.
  65. // it has been left blank.
  66. wchar_t buffer[Common::BUF_SIZE];
  67. StringCbPrintf( buffer, sizeof(buffer), GETRESOURCEIDSTRING( IDS_PARM_PORT_BLANK ), CVY_MIN_PORT,CVY_MAX_PORT );
  68. MessageBox( buffer,
  69. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  70. MB_ICONSTOP | MB_OK );
  71. return;
  72. }
  73. StringCbPrintf( buf, sizeof(buf), L"%d", end_port );
  74. portData.end_port = buf;
  75. // check if start port and end port both are in
  76. // proper range.
  77. if( !( start_port >= CVY_MIN_PORT
  78. &&
  79. start_port <= CVY_MAX_PORT
  80. &&
  81. end_port >= CVY_MIN_PORT
  82. &&
  83. end_port <= CVY_MAX_PORT )
  84. )
  85. {
  86. wchar_t buffer[Common::BUF_SIZE];
  87. StringCbPrintf( buffer, sizeof(buffer), GETRESOURCEIDSTRING( IDS_PARM_PORT_VAL ), CVY_MIN_PORT,CVY_MAX_PORT );
  88. MessageBox( buffer,
  89. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  90. MB_ICONSTOP | MB_OK );
  91. return;
  92. }
  93. // check if start port is less than or equal to end port.
  94. if( !(start_port <= end_port ) )
  95. {
  96. // start port is not less than or equal to end port.
  97. MessageBox( GETRESOURCEIDSTRING(IDS_PARM_RANGE ),
  98. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  99. MB_ICONSTOP | MB_OK );
  100. ::SetDlgItemInt(m_hWnd, IDC_EDIT_END, end_port, FALSE);
  101. return;
  102. }
  103. // get vip
  104. _bstr_t virtual_ip_addr;
  105. if (::IsDlgButtonChecked(m_hWnd, IDC_CHECK_PORT_RULE_ALL_VIP)) {
  106. // if ALL vips was checked, then set the VIP to 255.255.255.255.
  107. virtual_ip_addr = GETRESOURCEIDSTRING(IDS_REPORT_VIP_ALL);
  108. portData.virtual_ip_addr = virtual_ip_addr;
  109. } else {
  110. // otherwise, check for an empty vip.
  111. if (::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT_PORT_RULE_VIP), IPM_ISBLANK, 0, 0)) {
  112. MessageBox(GETRESOURCEIDSTRING(IDS_PARM_VIP_BLANK),
  113. GETRESOURCEIDSTRING(IDS_PARM_ERROR),
  114. MB_ICONSTOP | MB_OK);
  115. return;
  116. }
  117. virtual_ip_addr = CommonUtils::getCIPAddressCtrlString(ipAddress);
  118. portData.virtual_ip_addr = virtual_ip_addr;
  119. // validate the vip.
  120. bool isIPValid = MIPAddress::checkIfValid(virtual_ip_addr);
  121. if (isIPValid != true) {
  122. MessageBox(GETRESOURCEIDSTRING(IDS_PARM_INVAL_VIRTUAL_IP),
  123. GETRESOURCEIDSTRING(IDS_PARM_ERROR),
  124. MB_ICONSTOP | MB_OK);
  125. return;
  126. }
  127. }
  128. // check if there are are overlapped port rules.
  129. wchar_t portBuf[Common::BUF_SIZE];
  130. for( int i = 0; i < m_parent->m_portList.GetItemCount(); ++i )
  131. {
  132. if( i != m_index ) // not comparing against self
  133. {
  134. m_parent->m_portList.GetItemText( i, 1, portBuf, Common::BUF_SIZE );
  135. long start_port_existing = _wtoi( portBuf );
  136. m_parent->m_portList.GetItemText( i, 2, portBuf, Common::BUF_SIZE );
  137. long end_port_existing = _wtoi( portBuf );
  138. m_parent->m_portList.GetItemText( i, 0, portBuf, Common::BUF_SIZE );
  139. _bstr_t virtual_ip_addr_existing = portBuf;
  140. if ( (virtual_ip_addr == virtual_ip_addr_existing) &&
  141. ((start_port < start_port_existing &&
  142. end_port >= start_port_existing ) ||
  143. ( start_port >= start_port_existing &&
  144. start_port <= end_port_existing )))
  145. {
  146. MessageBox( GETRESOURCEIDSTRING(IDS_PARM_OVERLAP ),
  147. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  148. MB_ICONSTOP | MB_OK );
  149. return;
  150. }
  151. }
  152. }
  153. // get protocol
  154. if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_TCP))
  155. {
  156. portData.protocol = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_TCP );
  157. }
  158. else if( ::IsDlgButtonChecked (m_hWnd, IDC_RADIO_UDP))
  159. {
  160. portData.protocol = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_UDP );
  161. }
  162. else
  163. {
  164. portData.protocol = GETRESOURCEIDSTRING( IDS_REPORT_PROTOCOL_BOTH);
  165. }
  166. // get filtering mode
  167. if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_MULTIPLE))
  168. {
  169. portData.mode = GETRESOURCEIDSTRING( IDS_REPORT_MODE_MULTIPLE );
  170. // get affinity
  171. if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_AFF_NONE))
  172. {
  173. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_NONE );
  174. }
  175. else if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_AFF_SINGLE))
  176. {
  177. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_SINGLE );
  178. }
  179. else
  180. {
  181. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_AFFINITY_CLASSC );
  182. }
  183. // for multiple mode, priority is empty.
  184. portData.priority = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  185. }
  186. else if (::IsDlgButtonChecked (m_hWnd, IDC_RADIO_SINGLE))
  187. {
  188. portData.mode = GETRESOURCEIDSTRING( IDS_REPORT_MODE_SINGLE );
  189. portData.priority = GETRESOURCEIDSTRING( IDS_REPORT_NA );
  190. // for single mode load and affinity are empty.
  191. portData.load = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  192. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  193. }
  194. else
  195. {
  196. portData.mode = GETRESOURCEIDSTRING( IDS_REPORT_MODE_DISABLED );
  197. // for single mode priority load and affinity are empty.
  198. portData.priority = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  199. portData.load = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  200. portData.affinity = GETRESOURCEIDSTRING( IDS_REPORT_EMPTY );
  201. }
  202. // set the new port rule.
  203. m_portData = portData;
  204. EndDialog( IDOK );
  205. }
  206. void
  207. ClusterPortsDlg::SetControlData()
  208. {
  209. ::EnableWindow(GetDlgItem(IDC_CHECK_EQUAL)->m_hWnd, FALSE);
  210. ::ShowWindow(GetDlgItem(IDC_CHECK_EQUAL)->m_hWnd, SW_HIDE);
  211. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_START, EM_SETLIMITTEXT, 5, 0);
  212. ::SendDlgItemMessage(m_hWnd, IDC_EDIT_END, EM_SETLIMITTEXT, 5, 0);
  213. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_START, UDM_SETRANGE32, CVY_MIN_PORT, CVY_MAX_PORT);
  214. ::SendDlgItemMessage(m_hWnd, IDC_SPIN_END, UDM_SETRANGE32, CVY_MIN_PORT, CVY_MAX_PORT);
  215. // set the vip.
  216. if (!lstrcmpi(m_portData.virtual_ip_addr, GETRESOURCEIDSTRING(IDS_REPORT_VIP_ALL))) {
  217. ::CheckDlgButton(m_hWnd, IDC_CHECK_PORT_RULE_ALL_VIP, BST_CHECKED);
  218. ::EnableWindow(GetDlgItem(IDC_EDIT_PORT_RULE_VIP)->m_hWnd, FALSE);
  219. } else {
  220. CommonUtils::fillCIPAddressCtrlString(ipAddress, m_portData.virtual_ip_addr);
  221. ::CheckDlgButton(m_hWnd, IDC_CHECK_PORT_RULE_ALL_VIP, BST_UNCHECKED);
  222. ::EnableWindow(GetDlgItem(IDC_EDIT_PORT_RULE_VIP)->m_hWnd, TRUE);
  223. }
  224. // set the port range.
  225. ::SetDlgItemInt (m_hWnd, IDC_EDIT_START, _wtoi( m_portData.start_port), FALSE);
  226. ::SetDlgItemInt (m_hWnd, IDC_EDIT_END, _wtoi( m_portData.end_port ), FALSE);
  227. // set the protocol.
  228. if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_TCP) )
  229. {
  230. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_CHECKED );
  231. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  232. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  233. }
  234. else if( m_portData.protocol == GETRESOURCEIDSTRING(IDS_REPORT_PROTOCOL_UDP) )
  235. {
  236. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  237. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_CHECKED );
  238. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_UNCHECKED );
  239. }
  240. else
  241. {
  242. ::CheckDlgButton( m_hWnd, IDC_RADIO_TCP, BST_UNCHECKED );
  243. ::CheckDlgButton( m_hWnd, IDC_RADIO_UDP, BST_UNCHECKED );
  244. ::CheckDlgButton( m_hWnd, IDC_RADIO_BOTH, BST_CHECKED );
  245. }
  246. // set the mode.
  247. if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_MULTIPLE) )
  248. {
  249. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_CHECKED );
  250. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_UNCHECKED );
  251. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  252. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, TRUE);
  253. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, TRUE);
  254. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, TRUE);
  255. if( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_NONE ) )
  256. {
  257. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_CHECKED );
  258. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  259. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  260. }
  261. else if ( m_portData.affinity == GETRESOURCEIDSTRING(IDS_REPORT_AFFINITY_SINGLE) )
  262. {
  263. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  264. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_CHECKED );
  265. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  266. }
  267. else
  268. {
  269. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  270. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_UNCHECKED );
  271. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_CHECKED );
  272. }
  273. }
  274. else if( m_portData.mode == GETRESOURCEIDSTRING(IDS_REPORT_MODE_SINGLE) )
  275. {
  276. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_UNCHECKED );
  277. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_CHECKED );
  278. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_UNCHECKED );
  279. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  280. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  281. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  282. }
  283. else
  284. {
  285. ::CheckDlgButton( m_hWnd, IDC_RADIO_MULTIPLE, BST_UNCHECKED );
  286. ::CheckDlgButton( m_hWnd, IDC_RADIO_SINGLE, BST_UNCHECKED );
  287. ::CheckDlgButton( m_hWnd, IDC_RADIO_DISABLED, BST_CHECKED );
  288. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  289. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  290. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  291. }
  292. }
  293. void
  294. ClusterPortsDlg::OnRadioMultiple()
  295. {
  296. // TODO: Add your control notification handler code here
  297. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, TRUE);
  298. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, TRUE);
  299. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, TRUE);
  300. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_NONE, BST_UNCHECKED );
  301. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_SINGLE, BST_CHECKED );
  302. ::CheckDlgButton( m_hWnd, IDC_RADIO_AFF_CLASSC, BST_UNCHECKED );
  303. }
  304. void
  305. ClusterPortsDlg::OnCheckAllVIP()
  306. {
  307. if (::IsDlgButtonChecked(m_hWnd, IDC_CHECK_PORT_RULE_ALL_VIP))
  308. ::EnableWindow(GetDlgItem(IDC_EDIT_PORT_RULE_VIP)->m_hWnd, FALSE);
  309. else
  310. ::EnableWindow(GetDlgItem(IDC_EDIT_PORT_RULE_VIP)->m_hWnd, TRUE);
  311. }
  312. void
  313. ClusterPortsDlg::OnRadioSingle()
  314. {
  315. // TODO: Add your control notification handler code here
  316. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  317. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  318. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  319. }
  320. void
  321. ClusterPortsDlg::OnRadioDisabled()
  322. {
  323. // TODO: Add your control notification handler code here
  324. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_NONE)->m_hWnd, FALSE);
  325. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_SINGLE)->m_hWnd, FALSE);
  326. :: EnableWindow (GetDlgItem (IDC_RADIO_AFF_CLASSC)->m_hWnd, FALSE);
  327. }
  328. void ClusterPortsDlg::PrintRangeError (unsigned int ids, int low, int high)
  329. {
  330. /* Pop-up a message box. */
  331. wchar_t buffer[Common::BUF_SIZE];
  332. StringCbPrintf( buffer, sizeof(buffer), GETRESOURCEIDSTRING( ids ), low, high );
  333. MessageBox( buffer,
  334. GETRESOURCEIDSTRING( IDS_PARM_ERROR ),
  335. MB_ICONSTOP | MB_OK );
  336. }
  337. BOOL
  338. ClusterPortsDlg::OnHelpInfo (HELPINFO* helpInfo )
  339. {
  340. if( helpInfo->iContextType == HELPINFO_WINDOW )
  341. {
  342. ::WinHelp( static_cast<HWND> ( helpInfo->hItemHandle ),
  343. CVY_CTXT_HELP_FILE, HELP_WM_HELP,
  344. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_CLUSTER );
  345. }
  346. return TRUE;
  347. }
  348. void
  349. ClusterPortsDlg::OnContextMenu( CWnd* pWnd, CPoint point )
  350. {
  351. ::WinHelp( m_hWnd,
  352. CVY_CTXT_HELP_FILE,
  353. HELP_CONTEXTMENU,
  354. (ULONG_PTR ) g_aHelpIDs_IDD_PORT_RULE_PROP_CLUSTER );
  355. }