Source code of Windows XP (NT5)
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.

711 lines
13 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. fservic.cpp
  5. Abstract:
  6. FTP Service Property Page
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "fscfg.h"
  18. #include "fservic.h"
  19. #include "usersess.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24. //
  25. // Some sanity values on max connections
  26. //
  27. #define MAX_MAX_CONNECTIONS (1999999999L)
  28. #define INITIAL_MAX_CONNECTIONS ( 1000L)
  29. #define UNLIMITED_CONNECTIONS (2000000000L)
  30. #define MAX_TIMEOUT (0x7FFFFFFF)
  31. #define LIMITED_CONNECTIONS_MIN (10)
  32. #define LIMITED_CONNECTIONS_MAX (40)
  33. IMPLEMENT_DYNCREATE(CFtpServicePage, CInetPropertyPage)
  34. CFtpServicePage::CFtpServicePage(
  35. IN CInetPropertySheet * pSheet
  36. )
  37. /*++
  38. Routine Description:
  39. Constructor for FTP service property page
  40. Arguments:
  41. CInetPropertySheet * pSheet : Associated property sheet
  42. Return Value:
  43. N/A
  44. --*/
  45. : CInetPropertyPage(CFtpServicePage::IDD, pSheet)
  46. {
  47. #ifdef _DEBUG
  48. afxMemDF |= checkAlwaysMemDF;
  49. #endif // _DEBUG
  50. #if 0 // Keep Class Wizard happy
  51. //{{AFX_DATA_INIT(CFtpServicePage)
  52. m_strComment = _T("");
  53. m_nTCPPort = 20;
  54. m_nUnlimited = RADIO_LIMITED;
  55. m_nIpAddressSel = -1;
  56. m_fEnableLogging = FALSE;
  57. //}}AFX_DATA_INIT
  58. m_nMaxConnections = 50;
  59. m_nVisibleMaxConnections = 50;
  60. m_nConnectionTimeOut = 600;
  61. m_iaIpAddress = (LONG)0L;
  62. m_strDomainName = _T("");
  63. #endif // 0
  64. }
  65. CFtpServicePage::~CFtpServicePage()
  66. /*++
  67. Routine Description:
  68. Destructor
  69. Arguments:
  70. N/A
  71. Return Value:
  72. N/A
  73. --*/
  74. {
  75. }
  76. void
  77. CFtpServicePage::DoDataExchange(
  78. IN CDataExchange * pDX
  79. )
  80. /*++
  81. Routine Description:
  82. Initialise/Store control data
  83. Arguments:
  84. CDataExchange * pDX - DDX/DDV control structure
  85. Return Value:
  86. None
  87. --*/
  88. {
  89. CInetPropertyPage::DoDataExchange(pDX);
  90. if (!pDX->m_bSaveAndValidate)
  91. {
  92. m_fEnableLogging = LoggingEnabled(m_dwLogType);
  93. }
  94. //{{AFX_DATA_MAP(CFtpServicePage)
  95. DDX_Radio(pDX, IDC_RADIO_UNLIMITED, m_nUnlimited);
  96. DDX_Check(pDX, IDC_CHECK_ENABLE_LOGGING, m_fEnableLogging);
  97. DDX_Text(pDX, IDC_EDIT_COMMENT, m_strComment);
  98. DDV_MinMaxChars(pDX, m_strComment, 0, MAX_PATH);
  99. DDX_Control(pDX, IDC_EDIT_MAX_CONNECTIONS, m_edit_MaxConnections);
  100. DDX_Control(pDX, IDC_STATIC_LOG_PROMPT, m_static_LogPrompt);
  101. DDX_Control(pDX, IDC_STATIC_CONNECTIONS, m_static_Connections);
  102. DDX_Control(pDX, IDC_BUTTON_PROPERTIES, m_button_LogProperties);
  103. DDX_Control(pDX, IDC_COMBO_IP_ADDRESS, m_combo_IpAddresses);
  104. DDX_Control(pDX, IDC_COMBO_LOG_FORMATS, m_combo_LogFormats);
  105. //}}AFX_DATA_MAP
  106. DDX_Text(pDX, IDC_EDIT_TCP_PORT, m_nTCPPort);
  107. if (!IsMasterInstance())
  108. {
  109. DDV_MinMaxUInt(pDX, m_nTCPPort, 1, 65535);
  110. }
  111. if (pDX->m_bSaveAndValidate && !FetchIpAddressFromCombo(
  112. m_combo_IpAddresses,
  113. m_oblIpAddresses,
  114. m_iaIpAddress
  115. ))
  116. {
  117. pDX->Fail();
  118. }
  119. //
  120. // Private DDX/DDV Routines
  121. //
  122. int nMin = IsMasterInstance() ? 0 : 1;
  123. if (!pDX->m_bSaveAndValidate || !m_fUnlimitedConnections )
  124. {
  125. DDX_Text(pDX, IDC_EDIT_MAX_CONNECTIONS, m_nVisibleMaxConnections);
  126. }
  127. if (m_f10ConnectionLimit)
  128. {
  129. //
  130. // Special validation for unlimited connections. We use a bogus
  131. // numeric check for data validation. Number adjustment happes
  132. // later.
  133. //
  134. if (pDX->m_bSaveAndValidate &&
  135. (m_nVisibleMaxConnections < 0 ||
  136. m_nVisibleMaxConnections > UNLIMITED_CONNECTIONS))
  137. {
  138. TCHAR szMin[32];
  139. TCHAR szMax[32];
  140. wsprintf(szMin, _T("%ld"), 0);
  141. wsprintf(szMax, _T("%ld"), 40);
  142. CString prompt;
  143. AfxFormatString2(prompt, AFX_IDP_PARSE_INT_RANGE, szMin, szMax);
  144. AfxMessageBox(prompt, MB_ICONEXCLAMATION);
  145. prompt.Empty(); // exception prep
  146. pDX->Fail();
  147. }
  148. }
  149. else
  150. {
  151. DDV_MinMaxLong(pDX, m_nVisibleMaxConnections, 0, UNLIMITED_CONNECTIONS);
  152. }
  153. DDX_Text(pDX, IDC_EDIT_CONNECTION_TIMEOUT, m_nConnectionTimeOut);
  154. DDV_MinMaxLong(pDX, m_nConnectionTimeOut, nMin, MAX_TIMEOUT);
  155. if (pDX->m_bSaveAndValidate)
  156. {
  157. EnableLogging(m_dwLogType, m_fEnableLogging);
  158. }
  159. }
  160. //
  161. // Message Map
  162. //
  163. BEGIN_MESSAGE_MAP(CFtpServicePage, CInetPropertyPage)
  164. //{{AFX_MSG_MAP(CFtpServicePage)
  165. ON_BN_CLICKED(IDC_CHECK_ENABLE_LOGGING, OnCheckEnableLogging)
  166. ON_BN_CLICKED(IDC_RADIO_LIMITED, OnRadioLimited)
  167. ON_BN_CLICKED(IDC_RADIO_UNLIMITED, OnRadioUnlimited)
  168. ON_BN_CLICKED(IDC_BUTTON_CURRENT_SESSIONS, OnButtonCurrentSessions)
  169. ON_BN_CLICKED(IDC_BUTTON_PROPERTIES, OnButtonProperties)
  170. ON_WM_DESTROY()
  171. //}}AFX_MSG_MAP
  172. ON_EN_CHANGE(IDC_EDIT_TCP_PORT, OnItemChanged)
  173. ON_EN_CHANGE(IDC_EDIT_COMMENT, OnItemChanged)
  174. ON_EN_CHANGE(IDC_EDIT_MAX_CONNECTIONS, OnItemChanged)
  175. ON_EN_CHANGE(IDC_EDIT_CONNECTION_TIMEOUT, OnItemChanged)
  176. ON_CBN_EDITCHANGE(IDC_COMBO_IP_ADDRESS, OnItemChanged)
  177. ON_CBN_SELCHANGE(IDC_COMBO_IP_ADDRESS, OnItemChanged)
  178. ON_CBN_SELCHANGE(IDC_COMBO_LOG_FORMATS, OnItemChanged)
  179. END_MESSAGE_MAP()
  180. void
  181. CFtpServicePage::SetControlStates()
  182. /*++
  183. Routine Description:
  184. Set the states of the dialog control depending on its current
  185. values.
  186. Arguments:
  187. None
  188. Return Value:
  189. None
  190. --*/
  191. {
  192. if (m_edit_MaxConnections.m_hWnd)
  193. {
  194. m_edit_MaxConnections.EnableWindow(!m_fUnlimitedConnections);
  195. m_static_Connections.EnableWindow(!m_fUnlimitedConnections);
  196. }
  197. }
  198. void
  199. CFtpServicePage::PopulateKnownIpAddresses()
  200. /*++
  201. Routine Description:
  202. Fill the combo box with known ip addresses
  203. Arguments:
  204. None
  205. Return Value:
  206. None
  207. --*/
  208. {
  209. BeginWaitCursor();
  210. PopulateComboWithKnownIpAddresses(
  211. QueryServerName(),
  212. m_combo_IpAddresses,
  213. m_iaIpAddress,
  214. m_oblIpAddresses,
  215. m_nIpAddressSel
  216. );
  217. EndWaitCursor();
  218. }
  219. //
  220. // Message Handlers
  221. //
  222. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  223. BOOL
  224. CFtpServicePage::OnInitDialog()
  225. /*++
  226. Routine Description:
  227. WM_INITDIALOG handler. Initialize the dialog.
  228. Arguments:
  229. None.
  230. Return Value:
  231. TRUE if no focus is to be set automatically, FALSE if the focus
  232. is already set.
  233. --*/
  234. {
  235. CInetPropertyPage::OnInitDialog();
  236. //
  237. // Take our direction from a phony button
  238. //
  239. CRect rc(0, 0, 0, 0);
  240. m_ocx_LogProperties.Create(
  241. _T("LogUI"),
  242. WS_BORDER,
  243. rc,
  244. this,
  245. IDC_LOGUICTRL
  246. );
  247. //
  248. // Initialize the logging ocx; pass it the metabase path of the
  249. // virtual server.
  250. //
  251. m_ocx_LogProperties.SetAdminTarget(GetServerName(), QueryMetaPath());
  252. m_ocx_LogProperties.SetComboBox(m_combo_LogFormats.m_hWnd);
  253. GetDlgItem(IDC_RADIO_UNLIMITED)->EnableWindow(!m_f10ConnectionLimit);
  254. if (IS_MASTER_INSTANCE(QueryInstance()) || !HasAdminAccess())
  255. {
  256. GetDlgItem(IDC_STATIC_IPADDRESS)->EnableWindow(FALSE);
  257. GetDlgItem(IDC_STATIC_TCP_PORT)->EnableWindow(FALSE);
  258. GetDlgItem(IDC_EDIT_TCP_PORT)->EnableWindow(FALSE);
  259. m_combo_IpAddresses.EnableWindow(FALSE);
  260. }
  261. PopulateKnownIpAddresses();
  262. SetControlStates();
  263. SetLogState();
  264. GetDlgItem(IDC_BUTTON_CURRENT_SESSIONS)->EnableWindow(!IsMasterInstance());
  265. return TRUE;
  266. }
  267. /* virtual */
  268. HRESULT
  269. CFtpServicePage::FetchLoadedValues()
  270. /*++
  271. Routine Description:
  272. Move configuration data from sheet to dialog controls
  273. Arguments:
  274. None
  275. Return Value:
  276. HRESULT
  277. --*/
  278. {
  279. CError err;
  280. m_f10ConnectionLimit = Has10ConnectionLimit();
  281. BEGIN_META_INST_READ(CFtpSheet)
  282. FETCH_INST_DATA_FROM_SHEET(m_nMaxConnections);
  283. FETCH_INST_DATA_FROM_SHEET(m_nConnectionTimeOut);
  284. FETCH_INST_DATA_FROM_SHEET(m_iaIpAddress);
  285. FETCH_INST_DATA_FROM_SHEET(m_nTCPPort);
  286. FETCH_INST_DATA_FROM_SHEET(m_strDomainName);
  287. FETCH_INST_DATA_FROM_SHEET(m_strComment);
  288. FETCH_INST_DATA_FROM_SHEET(m_dwLogType);
  289. m_fUnlimitedConnections = m_nMaxConnections >= MAX_MAX_CONNECTIONS;
  290. if (m_f10ConnectionLimit)
  291. {
  292. m_fUnlimitedConnections = FALSE;
  293. if ((LONG)m_nMaxConnections > LIMITED_CONNECTIONS_MAX)
  294. {
  295. m_nMaxConnections = LIMITED_CONNECTIONS_MAX;
  296. }
  297. }
  298. m_nVisibleMaxConnections = m_fUnlimitedConnections
  299. ? INITIAL_MAX_CONNECTIONS
  300. : m_nMaxConnections;
  301. //
  302. // Set radio value
  303. //
  304. m_nUnlimited = m_fUnlimitedConnections ? RADIO_UNLIMITED : RADIO_LIMITED;
  305. m_nOldTCPPort = m_nTCPPort;
  306. END_META_INST_READ(err)
  307. return err;
  308. }
  309. HRESULT
  310. CFtpServicePage::SaveInfo()
  311. /*++
  312. Routine Description:
  313. Save the information on this property page
  314. Arguments:
  315. None
  316. Return Value:
  317. Error return code
  318. --*/
  319. {
  320. ASSERT(IsDirty());
  321. TRACEEOLID("Saving FTP service page now...");
  322. CError err;
  323. m_nMaxConnections = m_fUnlimitedConnections
  324. ? UNLIMITED_CONNECTIONS
  325. : m_nVisibleMaxConnections;
  326. //
  327. // Check to make sure we're not violating the license
  328. // agreement
  329. //
  330. if (m_f10ConnectionLimit)
  331. {
  332. if (m_nMaxConnections > LIMITED_CONNECTIONS_MAX)
  333. {
  334. ::AfxMessageBox(IDS_CONNECTION_LIMIT);
  335. m_nMaxConnections = LIMITED_CONNECTIONS_MIN;
  336. }
  337. else if (m_nMaxConnections > LIMITED_CONNECTIONS_MIN
  338. && m_nMaxConnections <= LIMITED_CONNECTIONS_MAX)
  339. {
  340. ::AfxMessageBox(IDS_WRN_CONNECTION_LIMIT);
  341. }
  342. }
  343. CString strBinding;
  344. CStringListEx m_strlBindings;
  345. CInstanceProps::BuildBinding(
  346. strBinding,
  347. m_iaIpAddress,
  348. m_nTCPPort,
  349. m_strDomainName
  350. );
  351. m_strlBindings.AddTail(strBinding);
  352. m_ocx_LogProperties.ApplyLogSelection();
  353. BeginWaitCursor();
  354. BEGIN_META_INST_WRITE(CFtpSheet)
  355. STORE_INST_DATA_ON_SHEET(m_nMaxConnections);
  356. STORE_INST_DATA_ON_SHEET(m_nMaxConnections);
  357. STORE_INST_DATA_ON_SHEET(m_nConnectionTimeOut);
  358. STORE_INST_DATA_ON_SHEET(m_dwLogType);
  359. STORE_INST_DATA_ON_SHEET(m_strComment);
  360. STORE_INST_DATA_ON_SHEET(m_strlBindings);
  361. END_META_INST_WRITE(err)
  362. EndWaitCursor();
  363. return err;
  364. }
  365. void
  366. CFtpServicePage::OnRadioLimited()
  367. /*++
  368. Routine Description:
  369. 'limited' radio button handler
  370. Arguments:
  371. None
  372. Return Value:
  373. None
  374. --*/
  375. {
  376. m_fUnlimitedConnections = FALSE;
  377. SetControlStates();
  378. m_edit_MaxConnections.SetSel(0, -1);
  379. m_edit_MaxConnections.SetFocus();
  380. OnItemChanged();
  381. }
  382. void
  383. CFtpServicePage::OnRadioUnlimited()
  384. /*++
  385. Routine Description:
  386. 'unlimited' radio button handler
  387. Arguments:
  388. None
  389. Return Value:
  390. None
  391. --*/
  392. {
  393. m_fUnlimitedConnections = TRUE;
  394. OnItemChanged();
  395. }
  396. void
  397. CFtpServicePage::OnItemChanged()
  398. /*++
  399. Routine Description:
  400. Register a change in control value on this page. Mark the page as dirty.
  401. All change messages map to this function
  402. Arguments:
  403. None
  404. Return Value:
  405. None
  406. --*/
  407. {
  408. SetControlStates();
  409. SetModified(TRUE);
  410. }
  411. void
  412. CFtpServicePage::SetLogState()
  413. /*++
  414. Routine Description:
  415. Set the enabled state of the logging controls depending on
  416. whether logging is currently enabled
  417. Arguments:
  418. None
  419. Return Value:
  420. None
  421. --*/
  422. {
  423. m_static_LogPrompt.EnableWindow(m_fEnableLogging);
  424. m_combo_LogFormats.EnableWindow(m_fEnableLogging);
  425. m_button_LogProperties.EnableWindow(m_fEnableLogging);
  426. }
  427. void
  428. CFtpServicePage::OnCheckEnableLogging()
  429. /*++
  430. Routine Description:
  431. 'Enable logging' checkbox has been toggled. Reset the state
  432. of the dialog
  433. Arguments:
  434. None
  435. Return Value:
  436. None
  437. --*/
  438. {
  439. m_fEnableLogging = !m_fEnableLogging;
  440. SetLogState();
  441. OnItemChanged();
  442. }
  443. void
  444. CFtpServicePage::OnButtonProperties()
  445. /*++
  446. Routine Description:
  447. Pass on "log properties" button click to the ocx.
  448. Arguments:
  449. None
  450. Return Value:
  451. None
  452. --*/
  453. {
  454. m_ocx_LogProperties.DoClick();
  455. }
  456. void
  457. CFtpServicePage::OnButtonCurrentSessions()
  458. /*++
  459. Routine Description:
  460. 'Current Sessions' button has been pressed. Bring up the current
  461. sessions dialog
  462. Arguments:
  463. None
  464. Return Value:
  465. None
  466. -*/
  467. {
  468. CUserSessionsDlg dlg(GetServerName(), QueryInstance(), this);
  469. dlg.DoModal();
  470. }
  471. void
  472. CFtpServicePage::OnDestroy()
  473. /*++
  474. Routine Description:
  475. WM_DESTROY handler. Clean up internal data
  476. Arguments:
  477. None
  478. Return Value:
  479. None
  480. --*/
  481. {
  482. CInetPropertyPage::OnDestroy();
  483. if (m_ocx_LogProperties.m_hWnd)
  484. {
  485. m_ocx_LogProperties.Terminate();
  486. }
  487. }