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.

337 lines
7.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 -99 **/
  4. /**********************************************************************/
  5. /*
  6. ipadddlg.cpp
  7. Comment goes here
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "winssnap.h"
  12. #include "IPAddDlg.h"
  13. #include "getipadd.h"
  14. #include "getnetbi.h"
  15. #include <objpick.h> // for CGetComputer
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. // Get replication trigger partner
  22. BOOL CGetTriggerPartner::OnInitDialog()
  23. {
  24. CIPAddressDlg::OnInitDialog();
  25. CString strText;
  26. strText.LoadString(IDS_SELECT_TRIGGER_PARTNER_TITLE);
  27. // Set the title of the dialog
  28. SetWindowText(strText);
  29. // set the description text
  30. strText.LoadString(IDS_SELECT_TRIGGER_PARTNER);
  31. m_staticDescription.SetWindowText(strText);
  32. return TRUE;
  33. }
  34. // add WINS server dialog
  35. BOOL CNewWinsServer::DoExtraValidation()
  36. {
  37. // check to see if the server is in the list
  38. BOOL fIsIpInList = m_pRootHandler->IsIPInList(m_spRootNode, m_dwServerIp);
  39. BOOL fIsNameInList = m_pRootHandler->IsServerInList(m_spRootNode, m_strServerName);
  40. if (fIsIpInList && fIsNameInList)
  41. {
  42. m_editServerName.SetFocus();
  43. m_editServerName.SetSel(0, -1);
  44. AfxMessageBox(IDS_ERR_WINS_EXISTS, MB_OK);
  45. return FALSE;
  46. }
  47. return TRUE;
  48. }
  49. // add Persona Non Grata dialog
  50. BOOL CNewPersonaNonGrata::DoExtraValidation()
  51. {
  52. // check if the server already exists
  53. if (m_pRepPropDlg->IsDuplicate(m_strServerName))
  54. {
  55. m_editServerName.SetFocus();
  56. m_editServerName.SetSel(0,-1);
  57. AfxMessageBox(IDS_ERR_WINS_EXISTS, MB_OK|MB_ICONINFORMATION);
  58. return FALSE;
  59. }
  60. // check the same server is being added
  61. if (m_pRepPropDlg->IsCurrentServer(m_strServerName))
  62. {
  63. m_editServerName.SetFocus();
  64. m_editServerName.SetSel(0,-1);
  65. AfxMessageBox(IDS_LOCALSERVER, MB_OK | MB_ICONINFORMATION);
  66. return FALSE;
  67. }
  68. return TRUE;
  69. }
  70. // add new replication partner dialog
  71. BOOL CNewReplicationPartner::OnInitDialog()
  72. {
  73. CIPAddressDlg::OnInitDialog();
  74. CString strText;
  75. strText.LoadString(IDS_NEW_REPLICATION_PARTNER_TITLE);
  76. // Set the title of the dialog
  77. SetWindowText(strText);
  78. strText.LoadString(IDS_NEW_REPLICATION_PARTNER_DESC);
  79. m_staticDescription.SetWindowText(strText);
  80. return TRUE;
  81. }
  82. BOOL CNewReplicationPartner::DoExtraValidation()
  83. {
  84. // check if the same servers is being added as a rep partner
  85. SPITFSNode spServerNode;
  86. m_spRepPartNode->GetParent(&spServerNode);
  87. CWinsServerHandler *pServer = GETHANDLER(CWinsServerHandler, spServerNode);
  88. CString strThisServerName = pServer->m_strServerAddress;
  89. DWORD dwThisServerIP = pServer->m_dwIPAdd;
  90. if ( (m_dwServerIp == dwThisServerIP) && (m_strServerName.CompareNoCase(strThisServerName) == 0))
  91. {
  92. //The server is already present as replication partner
  93. AfxMessageBox(IDS_REP_PARTNER_LOCAL, MB_OK);
  94. m_editServerName.SetFocus();
  95. m_editServerName.SetSel(0,-1);
  96. return FALSE;
  97. }
  98. CIpNamePair ip;
  99. ip.SetIpAddress(m_dwServerIp);
  100. ip.SetNetBIOSName(m_strServerName);
  101. // check if the server already exists in the
  102. // list of replication folderss
  103. if ( m_pRepPartHandler->IsInList(ip, TRUE) != -1)
  104. {
  105. //The server is already present as replication partner
  106. AfxMessageBox(IDS_REP_PARTNER_EXISTS, MB_OK);
  107. m_editServerName.SetFocus();
  108. m_editServerName.SetSel(0,-1);
  109. return FALSE;
  110. }
  111. return TRUE;
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CIPAddressDlg dialog
  115. CIPAddressDlg::CIPAddressDlg(CWnd* pParent /*=NULL*/)
  116. : CBaseDialog(CIPAddressDlg::IDD, pParent),
  117. m_fNameRequired(TRUE)
  118. {
  119. //{{AFX_DATA_INIT(CIPAddressDlg)
  120. m_strNameOrIp = _T("");
  121. //}}AFX_DATA_INIT
  122. }
  123. void CIPAddressDlg::DoDataExchange(CDataExchange* pDX)
  124. {
  125. CBaseDialog::DoDataExchange(pDX);
  126. //{{AFX_DATA_MAP(CIPAddressDlg)
  127. DDX_Control(pDX, IDC_STATIC_WINS_SERVER_DESC, m_staticDescription);
  128. DDX_Control(pDX, IDC_EDIT_SERVER_NAME, m_editServerName);
  129. DDX_Control(pDX, IDOK, m_buttonOK);
  130. DDX_Text(pDX, IDC_EDIT_SERVER_NAME, m_strNameOrIp);
  131. //}}AFX_DATA_MAP
  132. }
  133. BEGIN_MESSAGE_MAP(CIPAddressDlg, CBaseDialog)
  134. //{{AFX_MSG_MAP(CIPAddressDlg)
  135. ON_EN_CHANGE(IDC_EDIT_SERVER_NAME, OnChangeEditServerName)
  136. ON_BN_CLICKED(IDC_BUTTON_BROWSE_COMPUTERS, OnButtonBrowseComputers)
  137. //}}AFX_MSG_MAP
  138. END_MESSAGE_MAP()
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CIPAddressDlg message handlers
  141. void CIPAddressDlg::OnOK()
  142. {
  143. UpdateData();
  144. m_strNameOrIp.TrimLeft();
  145. m_strNameOrIp.TrimRight();
  146. if(m_strNameOrIp.IsEmpty())
  147. return;
  148. // resolve the IP address, if not valid, return
  149. if (!ValidateIPAddress())
  150. {
  151. // set back the focus to the IP address control
  152. m_editServerName.SetFocus();
  153. m_editServerName.SetSel(0,-1);
  154. return;
  155. }
  156. CBaseDialog::OnOK();
  157. }
  158. BOOL
  159. CIPAddressDlg::ValidateIPAddress()
  160. {
  161. CString strAddress;
  162. BOOL fIp = FALSE;
  163. DWORD err = ERROR_SUCCESS;
  164. BOOL bCheck = FALSE;
  165. DWORD dwAddress;
  166. CString strServerName;
  167. strAddress = m_strNameOrIp;
  168. if (IsValidAddress(strAddress, &fIp, TRUE, TRUE))
  169. {
  170. // if not an IP adress, check if FQDN has been entered, if so
  171. // pass the letters before the first period
  172. if(!fIp)
  173. {
  174. int nPos = strAddress.Find(_T("."));
  175. if(nPos != -1)
  176. {
  177. CString strNetBIOSName = strAddress.Left(nPos);
  178. strAddress = strNetBIOSName;
  179. }
  180. }
  181. CWinsServerObj ws(NULL,"", TRUE, TRUE);
  182. strAddress.MakeUpper();
  183. // machine name specified
  184. if (fIp)
  185. ws = CWinsServerObj(CIpAddress(strAddress), "", TRUE, TRUE);
  186. // IP address specified
  187. else
  188. {
  189. ws = CWinsServerObj(CIpAddress(), strAddress, TRUE, TRUE);
  190. }
  191. BEGIN_WAIT_CURSOR
  192. err = ::VerifyWinsServer(strAddress, strServerName, dwAddress);
  193. END_WAIT_CURSOR
  194. if (err != ERROR_SUCCESS)
  195. {
  196. // The server isn't running wins. Ask user for name/ip.
  197. if (fIp && m_fNameRequired)
  198. {
  199. CGetNetBIOSNameDlg dlgGetNB(&ws);
  200. if (dlgGetNB.DoModal() == IDCANCEL)
  201. {
  202. return FALSE;
  203. }
  204. }
  205. else
  206. if (!fIp)
  207. {
  208. CGetIpAddressDlg dlgGetIP(&ws);
  209. if (dlgGetIP.DoModal() == IDCANCEL)
  210. {
  211. return FALSE;
  212. }
  213. }
  214. m_dwServerIp = (LONG) ws.QueryIpAddress();
  215. m_strServerName = ws.GetNetBIOSName();
  216. m_strServerName.MakeUpper();
  217. }
  218. else
  219. {
  220. m_dwServerIp = dwAddress;
  221. m_strServerName = strServerName;
  222. }
  223. ::MakeIPAddress(m_dwServerIp, m_strServerIp);
  224. return DoExtraValidation();
  225. }
  226. else
  227. {
  228. AfxMessageBox(IDS_SERVER_NO_EXIST, MB_OK);
  229. // set focus to the IP address comntrol
  230. m_editServerName.SetFocus();
  231. m_editServerName.SetSel(0,-1);
  232. return FALSE;
  233. }
  234. return bCheck;
  235. }
  236. BOOL CIPAddressDlg::OnInitDialog()
  237. {
  238. CBaseDialog::OnInitDialog();
  239. // set the focus to the IP address control
  240. m_editServerName.SetFocus();
  241. return TRUE;
  242. }
  243. void CIPAddressDlg::OnChangeEditServerName()
  244. {
  245. // set the ok button state here
  246. if(m_editServerName.GetWindowTextLength() == 0)
  247. m_buttonOK.EnableWindow(FALSE);
  248. else
  249. m_buttonOK.EnableWindow(TRUE);
  250. }
  251. void CIPAddressDlg::OnButtonBrowseComputers()
  252. {
  253. CGetComputer dlgGetComputer;
  254. if (!dlgGetComputer.GetComputer(::FindMMCMainWindow()))
  255. return;
  256. m_editServerName.SetWindowText(dlgGetComputer.m_strComputerName);
  257. }